Jump to content

Talk:Mod:Hunt Research Group/VmdScriptsLoad

From ChemWiki

Using scripts in VMD

how to execute a script

  • scripts can be a list of instructions
in the vmd console type "play script"
  • or they can contain procedures
in the vmd console type "source script" then "procedure name"
  • scripts are written in Tcl
  • a good web-page for Tcl link
  • VMD has some of its own language
  • the script has to be in the directory you execute from

a simple script to load and define the representation for a molecule

  • it is best to first set the display settings
set the background colour
all atoms same size=orthographic depth=perspective
turn off the depth shading
turn off the axes
color Display Background iceblue
display projection   Orthographic
display nearclip set 0.000000
display farclip  set 10.000000
display depthcue   off
axes location off
  • reading in the structure
VMD will read a .xyz file of the following format:
number of atoms
title
atom x y z
where atom=atomic_symbol or atom=atomic_number
using the GUI => file:new molecule
using a script
# read in new molecule
mol new mol.xyz type xyz
  • the first representation on loading is always lines
delete the top representation
mol delrep 0 top
  • for a standard CPK representation on everything
CPK is VDW and bonds
the order of the next arguments is important
sphere_scale bond_radius sphere_resoluyion bond_resolution
select how colours are determined in this case via atomic name
we want opaque atoms as the material
apply the changes
mol selection {all}
mol representation CPK 1.100000 0.300000 20.000000 16.000000
mol color Name
mol material Opaque
mol add rep top
  • set specific atom colours and sizes
do this by changing colour redrawing the item
must do it for each item individually
must also respecify CPK to make the bonds the right colour
this is only added OVER the existing representation
all items will be this colour until the colour is changed again
colorID0=blue
colorID1=red
colorID2=grey
colorID7=green
colorID8=white
mol selection {name C}
mol representation CPK 1.100000 0.300000 20.000000 16.000000
mol color ColorID 2
mol addrep top
  • changing VDW defaults slightly to draw larger atom
VDW arguments are radius_size vdw_resolution
mol selection {name C}
mol color ColorID 2
mol representation VDW 0.3 30.0
mol addrep top
  • changing bond defaults slightly to draw fatter bonds
problem is that this only changes X-X bonds for atom X and not any others
so some of the bonds won't change colour properly
BOND arguments are bond_size bond_resolution
mol selection {name C}
mol color ColorID 2
mol representation bonds 0.3 16.0
mol add rep top

a simple script to load and define the representation for a trajectory

  • load a trajectory
# read in trajectory
mol new traj.xyz type xyz
  • CPK does not always work because of bonds across the cell
so we add dynamic bonds and make all the atoms VDW
for example to make the Oxygen red and Hydrogen white
#dynamic bonds
 mol selupdate 0 0 1
 mol representation DynamicBonds 1.4 0.1 6.0
 mol color Name
 mol material Opaque
 mol addrep top
# make water oxygen red
mol selection {name O}
mol color ColorID 1
mol representation VDW 0.20 30.0
mol addrep top
# make water hydrogen white
mol selection {name H}
mol color ColorID 8
mol representation VDW 0.20 30.0
mol add rep top
  • To add H-bonds:
add the HBonds representation with the following arguments
distance cut-off, angle cut-off, line thickness
here the bonds are coloured white (rather than the default red)
# add in H-bonds
mol selection {all}
mol color ColorID 8
mol representation HBonds 3.0 30.0 3.0
mol add rep top
  • Choose an individual molecule and change its representation
selecting a molecule does not work, so you have to do it by atom index
you will need to change the index numbers to those for your molecule
click on the Mouse:Query in the menu and then on the molecule screen, click on the atom
then look on the VMD terminal window, a list will appear relating to that atom and this will list the index no of the atom
in this case I have made one water molecule blue and enlarged the VDW spheres to make it stand out
mol selection {index 42 44 43}
mol color ColorID 0
mol representation VDW 0.5 30.0
mol add rep top