Basic: using a script to load a molecule

introduction

  • a script is a file (filename.tcl) which contains a procedure or "proc" which is a list of instructions for vmd.
  • the general method is that you start by "loading" the Tcl script file (only done once) and then "playing" the procedure (as many times as you want). This is achieved by typing in the vmd console source script.tcl then procedure name
  • now you should have a go at doing this, the following is a very simple script called load which sets some display options, loads a molecule input file (methane.xyz) into the VMD viewer, and then displays it using the CPK (balls and sticks) representation. Copy this script into a file called load.tcl
    Tcl script for VMD:
    proc load {} {
    #
    # setup some display settings first
    display projection   Orthographic
    display depthcue   off
    axes location off
    #
    # read in the molecule
    mol new methane.xyz type xyz
    #
    # change the molecule representation so we can see it
    mol representation CPK 1.100000 0.300000 20.000000 16.000000
    mol addrep top
    }
    
  • we also need a molecule to load, so copy the methane geometry file below into a file called methane.xyz
    xyz molecule input file:
    5
    methane
    6   0.000000    0.000000    0.000000
    1   0.629587    0.629587    0.629587
    1  -0.629587   -0.629587    0.629587
    1  -0.629587    0.629587   -0.629587
    1   0.629587   -0.629587   -0.629587
    
  • in this case open VMD, make sure you are in the directory that contains these files by using the "cd" command, then type into the VMD console source load.tcl then load
  • a molecule of methane should appear in the VMD window
    methane

details

  • now that you have made a script loaded and played it, lets discuss in a bit more detail what the format of the input file is and what this script does.
  • VMD can read in many types of format, but an easy option is to just produce the basic xyz file, this has the following format
    number of atoms
    title
    atom x y z
    
    where atom can be the atomic symbol or atomic number, and you must have as many atom x y z lines as you have number of atoms
  • VMD sets some default options that are not optimal for viewing molecules, for example the default representation is lines, which is very difficult to see, so I typically change these default options in the first part of the .tcl script. We didn't set the background in the script above, but you can alter your script to do this by adding the background command. Typically a black background is good for on-screen but if you want to put a snapshot image in a presentation a ligher background works better.
    # setup some display settings first
    color Display Background iceblue	::set the background colour
    display projection   Orthographic	::all atoms same size=orthographic
    display depthcue   off			::turn off the depth shading
    axes location off			::turn off the axes
    
  • in VMD anything to do with the molecule is via the "mol" keyword, in this case we want to read in and display a new moleule and the input file type is xyz.
    # read in the molecule
    mol new mol.xyz type xyz
    
  • now we want to add a new representation of this molecule in the CPK format. First we define that format we want, in this case I have specified particular settings for the CPK representation, these are the sphere_scale then bond_radius then sphere_resolution then bond_resolution. Typically you can play around with these options using the graphical interface, identify those you like and then hard code them into the script. Finally after defining the representation format we add it to the display with the mol addrep command
    # change the molecule representation so we can see it
    mol representation CPK 1.100000 0.300000 20.000000 16.000000
    mol addrep top
    

resources