VMD Workshop

Jeff Ulrich and Andrew Dalke

Feb. 6, 1997

1 Basic Loading and Viewing of Molecules

To Make a Menu Appear: There are at least two ways to do this. One method is to click in the GL Display window with the rightmost mouse button. A popup menu will appear. While holding down on the right mouse button, drag down to the ”Show Form” option. A list of check boxes will appear, allowing you to activate a number of common menus. A second way to access this menu list is through VMD’s main form. This main form is probably on your screen already (look for the bank of radio buttons with the blue ”VMD” at the top). If it is not, you can make it visible via the ”Show Form” option described above.

To Make a Menu Disappear: Just click on the blue-lettered bar at the top of the menu.

To Load a Molecule (i.e. bR): Activate the Mol menu as described above. Click on the button labeled ”Load From Files.” This will bring up another form from which you can specify the type of the file to load. By default VMD expects a PSF structure file and a coordinate set in PDB format. But for our purposes, a PDB file alone will do. Click on the ”pdb only” option in the blue browser list. Notice that the pink text entry blanks change to reflect the new file type. Click on the ”Select pdb” button next to this pink text box. The FileSelector menu which appears will allow you to specify the directory in which VMD is to search for the data file. First type /nfs/cairo/workshop for the directory and then choose segbR.pdb in the browser list which appears. Click ”Ready” and then click ”Load Molecule” in the files menu to finish loading the protein bacteriorhodopsin (bR).

To Scale, Rotate, or Translate: There are three basic mouse modes in VMD: Scaling, Rotating, and Translating. To switch amongst them, simply hit ’r’, ’s’, or ’t’ on the keyboard while the mouse is in the GL Display. Experiment with these modes and note how the cursor changes to indicate the current operation. For rotations, the left mouse button controls rotation about axes parallel to the screen while the right mouse button controls rotation about the axis perpendicular to the screen. In translation mode, the left mouse button controls translation parallel to the screen, while the middle button controls translation in and out of the screen. Finally, in scaling mode, both the left and middle buttons control global scaling when the mouse is moved left or right, but the middle button causes larger changes.

To Change Drawing Methods: If necessary, activate the Graphics menu as described above. Click on the drop down menu next to the words ”Drawing Method.” Choose your desired representation.

To Change Coloring Methods: If necessary, activate the Graphics menu as described above. Click on the drop down menu next to the words ”Coloring Method.” Choose your desired coloring scheme.

2 Advanced Viewing

To Develop Multiple Renderings: This description should be read alongside that for the next item discussing atom selection. The two concepts work hand in hand. First activate the Graphics form. All renderings for your molecule will be summarized in the blue browser list found on that form. To add a new rendering, click on the ”Create New” button on the bottom of this graphics menu. Notice that an extra line appears in the browser listing. In the text entry blank under the words ”Selected Atoms”, type in an expression which describes the atoms that you would like to represent in a different style. For example, type segname RET in the entry blank. Then using the drop down menu next to the words ”Drawing Method”, choose a new representation for your selection. For example, choose ”Licorice.” You will notice that all retinal atoms in the bR protein change in the GL Display. However the rest of the protein will appear unaltered, since you have not replaced the original rendering style, you have just added a new definition to it.

Using Atom Selection: VMD has a powerful atom selection syntax from which you can describe groups of atoms in a variety of ways. Your first exposure to this syntax will probably come through the text entry box on the graphics menu. For beginners, remembering the details of this syntax can often be a chore, so we recommend that you click on the ”Atom Name Lists” button in the graphics menu to help you out. If you do so you will be greeted with two browser windows listing properties from which you can identify groups of atoms. The items in the ”Keyword” browser are part of the selection syntax. If you click on one of these keywords, you will notice that available options for that keyword show up in the browser at the right. For example, click on the keyword ”segname.” You will see that you can choose from the seven alpha helices, the retinal, water, and other bR atoms. For a beginner, the best way to use these browser windows is as follows: First hit the ”Clear Changes” button at the bottom of the form. Then double-click on the keyword you will use. You will notice that this keyword appears in the text entry blank. Next, single-click each ”Value” you would like to include as an option to this keyword. If you hit the ”Apply Changes” button at the bottom of the graphics menu, your request will be updated. As a concrete example, hit ”Clear Changes,” double-click ”segname”, and single-click HEL1 and HEL2. You should see segname HEL1 HEL2 in the text entry box. If you do, hit Apply Changes and you will notice that only the first two alpha helices of the bacteriorhodopsin remain visible in the representation you are working with. Remember to hit the ”Image Controls” button to get back to controls for drawing and coloring methods.

To Change Colors: First activate the color menu. You will notice two browser windows in the upper left corner of this form. These two windows (labeled ”Category” and ”Names”) are your way of specifying items that should have their color changed. For instance, suppose your present coloring method is by segname (i.e. in the graphics form, the drop down menu next to the words ”Coloring Method” is set to ”SegName.”) Also suppose that you really hate the present color of the sixth alpha helix. In the color menu you can change this awful color by clicking on the ”Segname” entry in Category and the ”HEL6” entry in the Names browser. A list of available colors will pop up in a third browser window on the form. Select your favorite color and VMD will update the status of the sixth helix automatically.

How do I Switch Between Orthographic and Perspective Viewing: With the rightmost mouse button, click and hold in the GL Display window to reveal the popup menu. Drag down to ”Display Modes” and choose the appropriate setting.

How do I Display Objects as Wireframes: This can be done by means of the display menu. Open it and click on the drop down menu to the right of the word ”Detail.” Several options will appear, one of which is wireframe. Try experimenting with other options in the display form to familiarize yourself with available VMD features.

How do I Make an Object Transparent: On the graphics form there is a button marked ”Transparent.” Clicking it will make the ”current” representation transparent.

How do I Pick an Atom: If you simply click on an atom in the GL Display, you will notice that a label for that atom pops up on the screen. Many times these labels are useful, but too many of them tend to clutter the view. To delete them, use the popup menu. Hold down the rightmost mouse button in the GL Display window and drag down to ”Labels” for options on deleting labels.

How do I Save: Hold down on the rightmost mouse button in the GL Display window. Drag down to the ”Save Config” option. Type a file name in the box which appears and click Ready.

3 Animation

One of VMD’s unique features is its ability to playback trajectories from molecular dynamics simulations. We will explore this powerful feature with the help of a bR trajectory file provided by Barry Isralewitz of the University of Illinois. VMD has two main forms for controlling animations: the Animate form and the Edit form. The former offers VCR-like controls for playback, while the latter is used to append or delete frames to the animation. At this time you should have the PDB file of the bacteriorhodopsin loaded and on screen. We wish to append additional frames of an animation to this set of coordinates. Thus we will use the edit menu. Once you have activated this menu, be sure that the Action setting is ”Read File,” the Amount is ”All”, and the File Type is DCD. This file type is supported by many common molecular dynamics programs such as NAMD and X-PLOR. One DCD file usually contains many animation frames.

Go ahead and click the ”Read” button on the edit form. In the FileSelector which appears, make sure the directory is /nfs/cairo/workshop and choose bR.dcd. Click Ready and you will begin reading in the simulation frames. As it loads, you will notice that the retinal is being pulled out from the center of the bacteriorhodopsin through a hole between two of the alpha helices. The objective of Isralewitz’s study was to test whether or not this hole provides a possible route through which retinal can enter the bR protein. If pulling it out through this hole keeps the structure intact, then the reverse entry process may also be feasible. Try representing the retinal as ”licorice” to make it easier to see this happening. (Use segname ”RET” to select all atoms of the retinal.)

To control the playback of the trajectory, activate the animate form. You will see familiar looking forward, rewind, and stop buttons. Go ahead and play with these controls and the other options on the animate menu to see how they affect playback. Also notice that the total number of frames and the current frame counter are printed in the right hand corner of this menu.

The ability to visualize trajectories is a powerful tool in itself, but its benefits can be even more pronounced when combined with other VMD features. Let’s look at an example. As the retinal leaves its binding pocket, it seems as though it gets hung up along several points of its exit path. It is likely that hydrogen bonds are forming and breaking in these locations. VMD can emulate this hydrogen bonding network using the HBonds drawing method. To see how this works, open the graphics menu and generate three different representations. (Remember, to generate multiple representations, use the ”Create New” button at the bottom of the menu. To delete representations, use the corresponding delete button.) Click on the first representation (i.e. the top line in the blue browser window) and type segname RET in the atom selection box. For the other two representations we will take advantage of VMD’s ”within” command to select all atoms within five Angstroms of the retinal. These are the atoms likely to be involved in hydrogen bonding. Click on the second line of the blue browser window and type within 5 of segname RET in the text entry box. Choose Lines as the drawing method. Click on the third line of the blue browser window and again type within 5 of segname RET. This time, however, choose HBonds as the drawing method. At the bottom of the graphics menu you will see options which determine how hydrogen bonds are calculated and displayed. The Angle option has a rather conservative value. We suggest you bump it up to 25. Finally, scale the image in the display window so that the dashed hydrogen bonds are clearly visible to you. To see how this hydrogen bonding network changes over the course of the simulation, go back to the animate form and hit the play button.

4 Picking Modes

You have already seen that VMD can label individual atoms by simply clicking on them with the mouse. In addition, VMD supports several other picking modes. For a listing of them, hold down the rightmost mouse button in the GL Display to reveal the popup menu. Drag down to the Pick Item Mode submenu. By default, VMD is in the ”Query” mode, allowing you to pick atoms and display labels. If you switch to ”Center” mode and choose an atom in the display, then subsequent rotations will be performed about this atom position. In essence you will have picked a new center of rotation. Another useful picking mode is ”Bonds.” If you select this option and click on two atoms in the display window, a dashed line will be drawn between them and the distance separating them will be calculated. To familiarize yourself with this option, try clicking on two atoms of the bR retinal residue. Choose one atom from the segment which remains in the binding pocket, and the second atom from the cleaved portion which is pulled outward. If you then animate the system, you will see how the distance between the two retinal pieces increases over the course of the simulation. If you would like a graph of this distance over time, try this: hold the rightmost mouse button down in the GL Display window. Drag down to ”Show Form” in the popup menu and choose ”labels”. In the upper left corner of labels, change the Category to Bonds. Click on one of the entries which appears in the blue browser window and hit the ”Graph” button. A plot of the bond length over the course of the simulation will appear.

Similar in spirit to the ”Bonds” picking mode are ”Angles” and ”Dihedrals.” In these modes, you should click on three or four atoms respectively to calculate the angles defined by those collections of objects.

Finally there are the Move options. If you choose MoveAtom and select an atom in the display window, you will be allowed to drag it about the screen to change its position. For instance, suppose you wanted to refine a bond length by hand in VMD. One would first choose the ”Bonds” picking mode and calculate the distance between the two atoms forming the bond. Then you would select ”MoveAtom” and drag one of the atoms to the desired bond length. The distance will be updated and displayed on the screen automatically. A similar strategy could be used to modify bond or dihedral angles by hand.

When one does a lot of picking in VMD, the display tends to get cluttered. You can selectively delete output from picking actions by using the popup menu’s ”Labels” option.

5 RMSD Calculations

Now that you have learned a bit more about picking, lets try to apply this knowledge in our study of bR. Recall that the goal of the simulation was to determine if the retinal could be pulled through the hole without destroying the structural character of the rest of the protein. One way to test whether or not this was accomplished is through an RMSD calculation. This will quantify the difference between the first and last structures of the animation.

Until now we have worked exclusively with just one molecule in VMD. However, if we are to compare the first and last frames of the simulation, we must have a way to simultaneously load two structures. It turns out that this is very easy to do in VMD, as will be demonstrated with an example. First go to the animate menu and click on the button marked ”End.” This will allow you to specify the last frame of the simulation as one of the molecules forming the basis for the RMSD. Now we must simultaneously load the first frame of the simulation. Open the molecules form and load the ”pdb only” file segbR.pdb again. It may be difficult to tell the two molecules apart on screen, so we also recommend that you go to the graphics menu and choose the Coloring Method ”Molecule” as well. This will increase the contrast between the two coordinate sets. Now that the two molecules are loaded, the rest is a snap. Hold down on the rightmost mouse button in the GL Display to reveal the popup menu. Drag down to the Fit option and choose ”Two Molecules: CA Atoms” in the submenus. You have now specified that an RMSD calculation involving all carbon alpha atoms of two molecules should be applied. However, you must still tell VMD which two molecules should be used. It is true that there only two molecules presently on the screen, but there could just as well be five or ten. VMD has no limit on the number of molecules which may be simultaneously displayed. For this reason you will have to explicity indicate which two molecules to compare. This can be done by ”picking” one atom in each of the two molecules. Try experimenting with other fitting options to learn more about this VMD feature.

6 Rendering

6.1 Quick Output Using Snapshot

By now you are probably wondering how to produce a printout of what you see on the screen. To do this, you will have to generate a PostScript version of the display window. Presently, this is a two step process involving both VMD and an external program such as display. The process begins with the render menu. If you activate this form, you will see a browser listing of several rendering options available from VMD. A few of these will be discussed in more detail in the next section, but the one which interests us at the moment is ”snapshot.” If you click on this option and hit ”Go,” VMD will use the SGI screen capture program snapshot to generate an RGB rendering of the display window. By default this RGB rendering is stored in a file called snap.rgb, but this can be changed in the render menu if necessary. To convert snap.rgb to a printable PostScript file, you should type exec display snap.rgb in the VMD console window. This will launch the graphics program display. The RGB picture will pop up on the screen. In this picture, press down with the rightmost mouse button to bring up xv controls. Click the Save option and choose PostScript as the output format. You will now have a printable file called snap.ps in your directory.

6.2 Another Example: Raster3D

VMD provides a number of other rendering alternatives for your images. All options are listed in the render menu. One of the most popular techniques is to use Raster3D. If you click on this entry and hit the ”Go” button, VMD will convert its data to a form suitable for Raster3D and will then call this program to process your image. Try it, but be patient. It takes Raster3D time to do its calculations.

7 The VMD Command Language

For this section of the tutorial, we ask that you launch netscape and visit the URL: http://www.ks.uiuc.edu/Research/vmd/ug/node74.html This will allow you to cut and paste code examples into the VMD console.

8 Making a Movie

This section describes how to take a sequence of images from the display and combine them to form a movie. There are several steps to this process, including:

• Deciding what to put in your movie

• Writing an animation sequence from VMD

• Saving each still image to a file

• Using another program to convert the images to a correct movie format

Please note that this section can be viewed online at: http://www.ks.uiuc.edu/ ulrich/movie.txt If you launch netscape and visit this page, you will be able to cut and paste code examples into the VMD console.

8.1 What will you show?

There are many aspects of your research which might benefit from a movie of your system. You could, for instance, rotate the model around the Y axis to lend a sense of depth that a single image doesn’t give. You could also show the results of an MD simulation or change transparency parameters to dissolve a molecular surface slowly from the display. These examples will be shown below, and there are are many other possible movies you might want to make.

8.2 Writing Animation Frames and Merging Them into a Movie

Once you’ve come up with a concept, you’ll need some way to schedule the sequence of events in your movie. You could try to do it by hand, but that would get very tedious. Another alternative is to record a log file and play it back, but this is rarely smooth. The best bet is to come up with a script that does what you want automatically.

For example, here is a simple script to rotate the molecule around the screen vertical (the ”Y” axis), 20 degrees at a time, returning to its original position at the beginning.

        for {set i 0} {$i < 360} {incr i 20}  {
                rotate y by 20
        }

For each of these rotations, you’ll want to save the image on the screen to a file. This is done with the rendering commands. The fastest option is to take the image directly from the screen with the snapshot renderer. After you have the full sequence of images, you can then use one of several external programs to produce the movie. These programs usually require that the image file names fit the pattern <prefix><index><suffix> where the prefix and suffix don’t change, and the <index> is a zero-filled value starting at 0 and increasing by 1 for each image. In other words, these are valid:

        snap.0000.rgb  snap.0001.rgb ... snap.0242.rgb
        i0.rle  i1.rle  i2.rle  i3.rle

but these are usually not

        snap.0000.rgb  snap.0002.rgb ....
        i0.rle  i1.rle  ... i9.rle  i10.rle   (i.e. 1 digit to 2)
        a.gif b.gif c.gif

Also, if you stay with the recommended form, then you can always sort your list without a problem. For example, you might otherwise get a list of files like ”i1.rle, i10.rle, i2.rle, ....” since alphabetically 1 ¡ 10 ¡ 2.

You can write files from VMD in this format using the format command. It uses a convention from C that will automatically generate zero-filled numbers if you tell it how many digits are available. You’ll almost never generate more than 9999 images, so lets assume there are 4. Then an example of the format command is:

vmd > format "%04d" 5
Info) 0005

The following script adds the code needed to keep track of successive filenames. You can still see the original example in it, but there are four more lines added to keep track of the frame number and generate the filename.

        set frame 0
        for {set i 0} {$i < 360} {incr i 20} {
                set filename snap.[format "%04d" $frame].rgb
                render snapshot $filename
                incr frame
                rotate y by 20
        }

If you enter this code into VMD and then type ls snap.*.rgb you should see a list of the 18 images just created.

snap.0000.rgb  snap.0004.rgb  snap.0008.rgb  snap.0012.rgb  snap.0016.rgb
snap.0001.rgb  snap.0005.rgb  snap.0009.rgb  snap.0013.rgb  snap.0017.rgb
snap.0002.rgb  snap.0006.rgb  snap.0010.rgb  snap.0014.rgb
snap.0003.rgb  snap.0007.rgb  snap.0011.rgb  snap.0015.rgb

You could also use programs like display, xv, or ipaste to look at a few of the files and verify that they have different images.

Lets turn this into a QuickTime movie using SGI’s mediaconvert program. Start it up. Under File choose Select Input File. A file browser will appear. Choose snap.0000.rgb. Once the browser closes, click on Numbered Images. New options will be displayed, which are used to select the desired images to turn into a movie.

Here’s where the file naming convention comes into play. On the entry box for File Template: replace the 0000 with ####. This will tell the program that those characters are the ones that can change. Your 18 images are numbered from 0 to 17, so change the value of End: to 17.

Now go over to File Format: in the center of the right side and choose QuickTime. There are different ways of setting up a QuickTime file so click on the arrow to the right of Video Parameters. A new menu will appear so that you may choose the compression method. Choose RLE, since we believe it compresses best for computer graphics. (Anyone want to suggest otherwise?) There’s a slider there that lets you choose the degree of compression – the more compressed it is, the worse the image but the smaller the final movie file. Don’t worry about this now, but you might want to see which values get better or worse results for you.

All that is left is to press the Start button in the lower right and wait for the file outfile.mov to be created. To view the file, use movieplayer on the SGIs or xanim. The latter is available on most X-based machines. That’s it, you’ve made a movie!

8.3 Putting Movies on the World Wide Web

Now that you have put together an interesting movie, you may want to see it on a web page as an inline animated GIF. There are many ways to do this, but the easiest is to use convert from the ImageMagick tools.

        convert -delay 10 -loop 4 snap.*.rgb movie.gif

This routine produces a file called movie.gif with the option that when it is finished it will loop back to the beginning. Actually, it will loop four times and stop, except that Netscape doesn’t stop looping. The delay value is the amount of time to wait between updates, in 1/100ths of a second, so the delay here is 1/10 of a second.

The image file can be used and viewed just like any other GIF file, but the best way to see it is in a web viewer like Netscape Navigator. Create the file movie.html and

add the line This is an image: <img src=movie.gif> to it. Use the browser

to open the HTML file, and you should see the rotating image.

The downfall with this image is that it is too large, so the display is slow. You can use one of many graphics tools to reduce the size of the images, or you could start the whole process over again but with a smaller display.

8.4 Other Helpful Movie Scripts

Here are some other standard scripts you might want to test out. As a note, remember that when you write these scripts you don’t have to be too concerned about speed as that can easily be increased when piecing together the final images into the movie.

Suppose you want to make a movie of the complete trajectory for the top molecule. The following is a script that steps through each of the frames, one by one.

        # get the number of frames in the movie
        set num [molinfo top get numframes]
        # loop through the frames
        for {set i 0} {$i < $num} {incr i} {
                # go to the given frame

                animate goto $i
        }

Adding two lines of commands to save the image on the screen yields:

        # get the number of frames in the movie
        set num [molinfo top get numframes]
        # loop through the frames
        for {set i 0} {$i < $num} {incr i} {
                # go to the given frame
                animate goto $i
                # take the picture
                set filename snap.[format "%04d" $i].rgb
                render snapshot $filename
        }

However, once you start changing code to take the pictures and save them to disk, you will probably start to wish there was a better way, since otherwise you have to keep track of the current frame number, the current filename, etc. Luckily there is a better way. We’ve written a routine called take picture which simplifies the example code to:

        # get the number of frames in the movie
        set num [molinfo top get numframes]
        # loop through the frames
        for {set i 0} {$i < $num} {incr i} {
                # go to the given frame
                animate goto $i
                # take the picture
                take_picture
        }

Every time take picture is called, it takes a picture and saves it to a file using the current picture number. It then increments that value by 1. The default setting of take picture uses the snapshot renderer option, but it can be made to call any of the other renderers. Since some of these renderers require another step to turn the information into an image, another parameter lets you run a UNIX command to process the output file. Finally, the default parameter for the format command is animate.%04d.rgb but that can also be changed if necessary. Below is the script itself, followed by some examples of how to use the different parameters. You’ll want to copy and paste this into the VMD text window, or save it in a file and source it when needed.

proc take_picture {args} {
global take_picture
# when called with no parameter, render the image
if {$args == {}} {
set f [format $take_picture(format) $take_picture(frame)]
# take 1 out of every modulo images
if { [expr $take_picture(frame) % $take_picture(modulo)] == 0 } {
  render $take_picture(method) $f
  # call any unix command, if specified
  if { $take_picture(exec) != {} } {
    set f [format $take_picture(exec) $f $f $f $f $f $f $f $f $f $f]
    eval "exec $f"
  }
}
# increase the count by one
incr take_picture(frame)
return
}
lassign $args arg1 arg2
# reset the options to their initial stat
# (remember to delete the files yourself
if {$arg1 == "reset"} {
set take_picture(frame)  0
set take_picture(format) "./animate.%04d.rgb"
set take_picture(method) snapshot
set take_picture(modulo) 1
set take_picture(exec)    {}
return
}
# set one of the parameters
if [info exists take_picture($arg1)] {
if { [llength $args] == 1} {
  return "$arg1 is $take_picture($arg1)"
}
set take_picture($arg1) $arg2
return
}
# otherwise, there was an error
error {take_picture: [ | reset | frame <number>| format <string> | \
method <renderer> | modulo <number>]}

}
# to complete the initialization, this must be the first function
# called.  Do so automatically.
take_picture reset

The current pattern for the file format is ./animate.%04d.rgb but if you need more than 9999 images you should change the 4 to be the maximum number of digits you’ll need (and we would like to know if you are making any movies with that many images). For instance, if the files should be called image.00000.rgb through image.12345.rgb then you should change the pattern as follows:

        take_picture format image.%05d.rgb

You can also use this option to specify the directory for the output files. This is important because the images might take up a lot of space and you’ll want to use a scratch space with more room.

        take_picture format /scratch/disk2/snap.%04d.rgb

Suppose you wanted to use Raster3D to make the images instead of just taking the snapshot. Before any of the other calls to take picture, you’ll want to do something like:

        take_picture format animate.%04d.r3d
        take_picture method Raster3d
        take_picture exec {render < %s -sgi %s.rgb}

The first line changes the file extension to .r3d so it is less confusing when you see the file name some time in the future. The second line changes the rendering method to Raster3D.

Of course, this just produces a Raster3D input file, which itself still needs to be rendered. The third line is used after the Raster3D information is saved to a file so that it will be automatically converted to an image file. The %s is automatically replaced by the current filename (just like in the Render form) and the whole string is executed by the UNIX shell. In this case, it calls the Raster3D renderer to convert the .r3d file into a .rgb file.

There are several other options, but the only other one you might use is,

        take_picture reset

which returns all options to their default values, eg. resets the image number to 0, returns the rendering method to snapshot, etc.

8.5 Examples

Now that the take picture script has been explained, here are a couple more interesting ways to make movies that might prove useful.

Here’s something I thought was fun. It starts off with a full surface representation that fades away to show an underlying tube representation. It works by changing the value of the transparency from 1 to 0. The surface color is transparent, but since the value is 1, it is really opaque. As the value decreases, the opaque tube in the center appears.

Since this depends on having two different representations, here is the code to set up the example structure. It uses the remote downloading feature of VMD to get the BPTI structure from the PDB FTP server. If this doesn’t work, just use any structure you have handy.

        # if this doesn't work, use one of your own structures
        mol pdbload 9pti
        mol modselect 0 top protein
        mol modcolor 0 top index
        mol modstyle 0 top tube
        mol addrep top
        mol modselect 1 top protein
        mol modcolor 1 top resname transparent
        mol modstyle 1 top surf

Now that everything is loaded, here’s the script to make the movie

        # take control of the updating
        display update off
        for {set i 1.0} {$i >= 0.0} {set i [expr $i - 0.05]} {
                # change the opacity of the transparent colors
                for {set color 17} {$color < 34} {incr color} {
                        color change alpha $color [expr $i*$i]
                }
                # and of the color scale
                for {set color 66} {$color < 98} {incr color} {
                        color change alpha $color [expr $i*$i]
                }
                # force the update
                display update

                # and take the picture
                take_picture
        }
        # return the alpha values to the default value
        for {set color 17} {$color < 34} {incr color} {
                color change alpha $color 0.3
        }
        # for the color scale as well
        for {set color 66} {$color < 98} {incr color} {
                color change alpha $color 0.3
        }
        # turn the normal updating back on
        display update on

Experienced script writers may ask why we used ”[expr $i*$i]” instead of $i ? This was purely an esthetic choice based on our belief that the colors were not becoming transparent quickly enough.

9 User Defined Graphics

Sometimes you may want to display graphics other than the standard molecular graphics. You may want to draw a box around a molecule, or an arrow between two atoms, or place a text label somewhere in space, or test a new method for visualizing a molecule. Because of the wide range of objects which can be displayed, VMD cannot be pre-programmed to display them all. Instead, it does offer a way to build up a new object from simple graphical items, including: points, lines, cylinders, cones, spheres, triangles (both with and without specified normals), and text. This chapter describes how to use the text interface to add new graphics to VMD. This text and additional examples can be found at the URL: http://www.ks.uiuc.edu/Research/vmd/ug/node80.html You may want to launch netscape and visit this page now. You will then be able to cut and paste code examples into the VMD console.

9.1 Introduction

There are ten type of basic graphical items built into VMD. These are:

• point x y z

draws a point at the given position • line x1 y1 z1 x2 y2 z2 [width w] [style (solid—dashed)]

draws either a solid or dashed line of the given width from the first point to the second. By default, this is a solid line of width 1.

• cylinder x1 y1 z1 x2 y2 z2 [radius r] [resolution n] [filled (yes—no)]

draws a cylinder of the given radius (default r=1) from the first point to the second. The cylinder is actually drawn as an n sided polygon. If the filled option is true, the ends are capped with flat disks, otherwise the cylinder is hollow.

• cone basex basey basez tipz tipy tipz [radius r] [resolution n]

draw a cone with the center of the base as the first point and the tip at the second. The radius(default r=1) determines the width of the base. As with cylinder, the resolution determines the number of polygons used in the approximation.

• triangle x1 y1 z1 x2 y2 z3 x3 y3 z3

draws a triangle with endpoints at each of the three verticies

• trinorm x1 y1 z1 x2 y2 z3 x3 y3 z3 nx1 y1 z1 nx2 ny2 nz3 nx3 ny3 nz3

draws a triangle with endpoints at each of the first three points. The second group of three values specify the normals for the three points. This is used for making a smooth shading across the triangle.

• sphere x y z [radius r] [resolution n]

draws a sphere of the given radius (default r=1) centered at the vertex. The resolution (default n=6) determines how many polygons are used in the approximation of a sphere.

• text x y z “text string”

displays the text string with the bottom left of the string starting at the given vertex.

• color colorid

• color name

• color trans name

Each of the above geometrical objects are drawn using the current color. Initially, that color is blue, which has the colorid of 0. The color command changes the current color, and stays info effect until the next color command. Thus, to draw a red cylinder then a red sphere, first use the command color red command to change the color, then use the cylinder and sphere commands.

9.2 Examples

We’ll start with some basic examples. Load VMD and enter:

  draw cylinder {0 0 0} {5 0 0} radius 0.2

VMD will print:

  Info) Loading new molecule ...

because of the way graphics are implemented (don’t worry about the details yet) and draw a blue cylinder on the screen.

Now change the color to red and draw another two cylinders:

  draw color red
  draw cylinder {4 1 0} {5 0 0} radius 0.1
  draw cylinder {4 -1 0} {5 0 0} radius 0.1

You might want to reset the view. Since the original scene had no data, a default size was chosen. Now that there is data, a reset view will center the graphics just as if it was a regular molecule (in fact, the implementation is a molecule with no atoms and only graphics).

You now have a simple arrow.

I’ll make a nicer looking one now. First, remove all the graphics:

  draw delete all

and make a cylinder with a cone on the end

  draw cylinder {0 0 0} {4 0 0} radius 0.1
  draw cone {4 0 0} {5 0 0} radius 0.15

Note that the widest part of the cone is at the first point. As long as we’re at it, let’s add some text to the end of the arrow in green

  draw color green
  draw text {5 0 0} "This way"

Cool, eh?

Of course, more things are available than a cylinder, cone, and text. How about a sphere?

  draw sphere {0 0 0} radius 0.3
  draw sphere {0 2 0} radius 0.2

The color of the spheres are green because that was the previously assigned color. The color doesn’t change until explicitly specified with the color option. The default color is blue.

And some lines, first, a dotted line connecting the spheres

  draw line {0 0 0} {0 2 0} style dashed

then a solid one from the second sphere to the end of the arrow

  draw line {0 2 0} {5 0 0}

Now, reset the view and move things around a bit. You may be surprised to see the lines appear and disappear. This is because the lines have a ”material property”; which means they are affected by the lights. For some things, this may be useful, but usually if you want to draw lines, you’ll need to turn materials off.

  draw materials off

10 Using VMD for Molecular Analysis

In this section of the tutorial, we ask that you launch netscape and visit the URL: http://www.ks.uiuc.edu/Research/vmd/ug/node92.html You will then be able to cut and paste examples of code.