
#How to Use Visual Molecular Dynamics (VMD)

This is a very basic introduction to VMD.

So, what is VMD? In the words of its developers:

> [VMD](http://www.ks.uiuc.edu/Research/vmd/) (Visual Molecular Dynamics) is a molecular visualization and analysis program designed for biological systems such as proteins, nucleic acids, lipid bilayer assemblies, etc.

It is developed by the Theoretical and Computational Biophysics Group at the University of Illinois at Urbana-Champaign. Among molecular graphics programs, VMD is unique in its ability to efficiently operate on multi-gigabyte molecular dynamics trajectories, its interoperability with a large number of molecular dynamics simulation packages, and its integration of structure and sequence information.

The aim of this tutorial is to very quickly get you familiar enough with VMD to be able to view individual protein structures and the sorts of trajectories containing many structures that are produced by molecular dynamics and other simulation techniques.
This document is deliberately designed to cover only the most basic features of VMD.
Excellent tutorials teaching the full range of the functionality provided by the program can be found at the VMD website, [here](http://www.ks.uiuc.edu/Research/vmd/vmd-1.9.2/docs.html).


## Some Information About Filetypes

VMD specializes in the visualization of data from molecular simulations.
In addition to [PDBs](http://www.wwpdb.org/documentation/file-format) several other formats are widely used to describe molecular systems.
In this tutorial we focus on those associated with simulations using the [CHARMM forcefield](http://mackerell.umaryland.edu/charmm_ff.shtml).

### PSF - Forcefield Structure Files

A [PSF](http://www.ks.uiuc.edu/Training/TutorialsOverview/namd/namd-tutorial-html/node23.html), protein structure file, contains all of the molecule-specific information necessary to describe a particular molecular system using the CHARMM force field.
Contains information about the atom types, residues, covalent bonds, and selections of atoms used to determine force terms in molecular dynamics or Monte Carlo simulations (such as angle and dihedral terms) but **NOT** coordinates.

### PDB - Standard Structure Files

A PDB file contains atomic coordinates and type alongside information about how they are organized into residues.
For non-standard residues connectivity can be specified using [CONECT](http://www.bmsc.washington.edu/CrystaLinks/man/pdb/part_69.html) records, however VMD ignores these and if no PSF is provided explicitly defining connectivity bonds are assigned using a distance cut off.
PDB files may contain multiple sets of coordinates for the same system.

### DCD - Trajectory Files

[DCDs](http://www.ks.uiuc.edu/Research/namd/2.9/ug/node11.html) contain **ONLY** coordinates and no information about atoms or their connectivity.
They are binary files and consequently much more efficient than PDBs for storing large numbers of coordinate sets.
DCD files must be used in conjunction with a structure file.


## Prerequisites

This tutorial assumes:

1. Access to the following two files (<b> located in the $HOME/Desktop/aps_2016/exercises/lab_I directory </b>):
    * a PDB single structure file: <b> dbd.pdb </b>
    * a DCD multiple structure trajectory file: <b> dbd-short-traj.dcd </b>
2. VMD is installed on your computer.


## Running VMD

To start the program:

* OS X: Double click on the VMD icon in the Applications directory.
* Linux: Type vmd in a terminal window.
* Windows: Select *Start*  -> *Programs*  -> *VMD*.

Upon opening VMD opens three windows (Figure 1): the Main, OpenGL Display and Console (or Terminal on OS X) windows.
To end a VMD session, go to the Main window, and choose *File*  ->  *Quit*. 
You can also quit VMD by closing the Console or Main window.

![Figure 1. The three initial windows opened by VMD.](images/vmd-three-windows.png)



#1. Viewing Single Molecules/Trajectories

In this section we will load a single structure from a PDB and learn how to view it from different angles and to alter the way it is rendered on screen.

## Loading a Molecule

1. From the menubar in the Main window select *File* -> *New Molecule...* (Figure 2).

	![Figure 2. Selecting the *New Molecule...* menu option.](images/vmd-new-molecule.png)

2. A Molecule File Browser window similar to that shown in Figure 3 should now open.
Select the *Browse..* button (circled in red in Figure 3). 
This will open a file selection dialog.
Navigate to the PDB file, dbd.pdb, which you downloaded earlier, select it and click *Open*.

	![Figure 3. The Molecule File Browser Window used to load new molecules.](images/vmd-molecule-file-browser.png)

3. You should now have been returned to the Molecule File Browser window (the structure will not yet have been loaded).
To load the file you need to click the *Load* button (circled in blue in Figure 3).
The structure should now be loaded and the OpenGL Display window look something like Figure 4.

![Figure 4. The dbd.pdb structure as displayed in VMD when first loaded.](images/vmd-dbd-lines.png)

Notice that once the molecule is loaded basic information including the name of the file and number of atoms appear in the Main window.

Once the structure is loaded you can close the Molecule File Browser at any time.

### Altering Your Viewpoint

From the menubar in the Main window select *Mouse* (Figure 5).

![Figure 5. The options available for changing the viewpoint with the mouse.](images/vmd-mouse-options.png)

A larger array of options for how the mouse interacts with the molecule shown in the OpenGL Display. 
We will concentrate on the first four options: rotate mode, translate mode, scale mode and center.
The keyboard shortcut for each option is shown next to the choice in the menu (for example pressing 't' when the OpenGL windows is selected will change into translate mode).
By default VMD uses the rotate mode.

Generally, to change the viewpoint you need select the OpenGL Display windows, hold the left mouse button and move the mouse (the right mouse button can be used in rotate mode, see below).
Have a play with all of the modes below until you feel comfortable changing the view and switching between the various modes.
You can easily tell which mode you are in because each one has a distinctive cursor (Figure 6).

![Figure 6. Different viewpoint changing modes are indicated by different cursor styles.](images/vmd-cursors.png)

**Rotate mode**: With the left mouse button held moving the mouse horizontally rotates the molecule around the vertical axis, up and down around a horizontal one.
When the right mouse button is held then the rotation is performed around an axis running into and out of (i.e. perpendicular to) the screen.

**Translate mode**: When you hold down the left mouse button you can now move the molecule up, down, left or right in the viewing plane.

**Scale mode**: Moving the mouse left or right whilst holding the left mouse button zooms in and out.

**Center**: The centre option is not a direct method for altering the view point. 
It is used to pick a point about which to perform a rotation.
Once you have selected a center point change to Rotate mode to perform the rotation.

At any point you can reset the view by pressing '=' whilst the OpenGL Display is selected (you can also use the menu option *Display* -> *Reset View*.

### Changing the Appearance of the Molecule

1. Select *Graphics* -> *Representations...* from the menubar of the Main window.
A new Graphical Representations window will open looking like Figure 7.
Section Figure 7 (a) shows the current representation being highlighted.
It shows the style of the representation (in this case Lines), the colouring method (Name) and the selection of atoms to which this representation is applied. 
The selection is determined by the contents of the input box shown in Figure 7 (b).
The current selection is for all atoms.
The language used to select atoms in VMD is documented in the section of the user guide [here](http://www.ks.uiuc.edu/Research/vmd/vmd-1.9.2/ug/node89.html).

	![Figure 7. Graphical Representations window.](images/vmd-graphical-reps.png)

2. Try changing the Coloring Method by choosing different options from the drop down menu shown as Figure 7 (c).
3. Alter the Drawing Method of the graphics used to display the molecule with the drop down menu shown as Figure 7 (d).
A good choice is 'New Cartoon' which highlights different elements of protein secondary structure (shown in Figure 8).
Notice how the region indicated by Figure 7 (e) changes to give you different customization options for the different Drawing Methods.

![Figure 8. The dbd.pdb structure as displayed in the New Cartoon style, and colored using Secondary Structure.](images/vmd-dbd-cartoon.png)


## Working With Trajectories

When dealing with simulations multiple structures are commonly saved together in files called 'trajectories'.
An example of a trajectory format is DCD (used by NAMD and CHARMM).
Such files contain only coordinates and no information about which atoms are represented.
In order to vizualize the atomic structure represented by a trajectory it has to be combined with a file containing structural information.
PDB files contain both structural and coordinate information and can perform this role, other filetypes such as PSF files contain only structural information and no coordinates.

The trajectory from this point assumes that you have already loaded the dbd.pdb PDB files into VMD.
If that is not the case go through the instructions for [Loading a Molecule].

### Loading a Trajectory

In the Main window either select *File* -> *Load Data into Molecule...* or right click on the line for dbd.pdb and select *Load Data into Molecule...* from the menu (see Figure 9a below).

![Figure 9. Loading data into an already loaded structure.](images/vmd-load-into-molecule.png)

Like when we loaded a PDB previously a Molecule File Browser window should appear. 
*Browse* to the dbd-short-traj.dcd and *Load* it.

As the trajectory loads you will see the number of frames increase in the Main windows and the structure in the OpenGL Display update.

If you are loading a DCD file with a large number of trajectories, it will load faster if you choose the *Load all at once* option in the Molecule File Browser as shown in Figure 9b below.

![Figure 9b. Load all at once.](images/vmd-load-all-at-once.png)

### Trajectory Animation


The Main window should now look something like it does in Figure 10 below, where the current frame is circled in red.

![Figure 10. Main window with a trajectory loaded.](images/vmd-main-trajectory.png)

**Note that frames are counted from zero in VMD. In this case, frame zero is the structure loaded from the PDB.
However, if you load a structure information only file, such as a PSF, instead of a PDB, then frame zero will be the first frame of the DCD.**

You can use the slider highlighted in blue in Figure 10 to move to any frame you desire.
It is also possible to type in a specific frame number in the current frame region.

Beneath these controls are the animation controls (highlighted in green in Figure 10).
These allow you to play through the frames of the trajectory.
Forwards and backwards play buttons can be found at either end of the controls.
Between these are controls which alter the way the animation plays.
The 'step' controls the gap between the frames which are displayed and 'speed' is self explanitory.
The animation type drop down menu controls what happens when the animation has played the last frame in the current direction:

**Once**: The animation terminates.

**Loop**: The animation plays again from the start (opposite end).

**Rock**: The animation reverses direction.

Play with these controls until you are happy you understand how they work.


#2. Viewing Multiple Molecules/Trajectories

This tutorial describes how to load and visualize simulation topology and trajectory files in VMD.

Files needed for this tutorial (<b> located in the $HOME/Desktop/aps_2016/exercises/lab_I directory </b>):

* A CHARMM PSF: <b> dbd.psf </b>
* A trajectory file (DCD): <b> dbd-short-traj.dcd </b>
* A single structure file (PDB): <b> dbd.pdb </b>


## Loading Multiple Molecules

In this section we will load coordinates into two molecules.
The first will contain a trajectory obtained from a Monte Carlo simulation and the second the PDB structure used to start that simulation.

### Loading the Trajectory

This time we will load the trajectory using the structure information in the PSF file.

1. From the menubar in the Main window select *File* -> *New Molecule...* .

2. From the Molecule File Browser window *Browse* to the <b> dbd.psf </b>.
The file type should be automatically detected as 'CHARMM, NAMD, XPLOR PSF'.

3. Click 'Load'.
No molecule will appear in the OpenGL display but the VMD logo should disappear as shown in Figure 11 below.
The Structural connectivity information has been loaded without any coordinates.

	![Figure 11: Changes in the OpenGL display induced by loading a PSF file.](images/vmd-loaded-psf.png)

	In the Main window you should see an entry with an ID of 0 and a Molecule name of dbd.psf with 1855 atoms, but 0 frames, as shown in Figure 12a below.

	![Figure 12a: Main window with dbd.psf loaded.](images/vmd-psf-main.png)

4. Now we need to load coordinated into our molecule from a DCD.
Right click on the line for dbd.psf and select *Load Data into Molecule...* from the menu.
Just as for the PSF a Molecule File Browser window should appear.
*Browse* to the <b> dbd-short-traj.dcd </b> and *Load* it.

	Now a structure should be visible in the OpenGL display and now the dbd.psf ID 0 entry should have 1520 frames as shown in Figure 12b below.

	![Figure 12b: Main window with dbd.psf and dbd-short-traj.dcd loaded.](images/vmd-psf-dcd.png)
	
**Since we loaded a structure information only PSF file in this case, frame zero is the first frame of the DCD.**
		

### Loading the Second Structure

1. From the menubar in the Main window select *File* -> *New Molecule...* .

2. From the Molecule File Browser window *Browse* to the <b> dbd.pdb </b> file you downloaded earlier.
The file type should be automatically detected as 'PDB'.
The OpenGL window should now look like Figure 13 below.

	![Figure 13: Open GL window showing two molecules loaded.](images/vmd-two-struct-lines.png)

	There should now be entries for two molecules (ID 0 for dbd.psf and 1 for dbd.pdb) in the Main window (see Figure 14 below).
Both should have the same number of atoms but differ in the number of frames.

	![Figure 14: Main window showing two molecules loaded.](images/vmd-two-struct.png)

## Altering the Appearance of Multiple Molecules

1. Select *Graphics* -> *Representations...* from the menubar of the Main window.

2. A new Graphical Representations window will open.

	Set the following settings:
  	* Coloring Method = Molecule
  	* Drawing Method = NewCartoon
  	
  	One of the molecules (1: dbd.pdb) should have changed appearance to a cartoon in the OpenGL window.
    
3. Switch molecules by clicking on the down arrow at the end of the Selected Molecule box and choosing '0: dbd.psf' from the menu list that appears (see Figure 15 below).

	![Figure 15: List of molecules in the Graphical Representation window.](images/vmd-change-mol-rep.png)

4. Alter the Coloring Method and Drawing Method to the same setting as teh previous molecule.

	Your OpenGL window should now look like Figure 16 below.

	![Figure 16: Open GL window showing two molecules as cartoons.](images/vmd-two-struct-cartoon.png)

Try to animate the trajectory by moving the Frame Slider at the bottom of the Main window.
You should not be able to change the visualization.
In the next section we will see why not and right this terrible injustice.

### Setting Molecule Status

In Figure 17 below, three columns in the Main window information panel are highlighted.
These columns provide toggles for the various statuses that can be assigned to molecules.

![Figure 17: Main window showing two molecules loaded, with the status columns highlighted.](images/vmd-two-structs.png)

The three letters each indicate a different status setting for each molecule:

**(T)op molecule** - indicates the default molecule for all actions (only one moelcule can have this status)

**(A)ctive** - if set the trajectory of the molecule will be updated in any animation

**(D)rawn** - indicates if the molecule is being displayed in the OpenGL window

The reason that we cannot animate our trajectory is that molecule 1 (<b> dbd.pdb </b>) has the (T)op status and has only one frame.
To change the top molecule double click on the T column region of molecule 0 (<b> dbd.psf </b>), the location to click is shown in Figure 18 below.

![Figure 18: Region of the Main window to click to change the Top molecule.](images/vmd-select-top.png)

Now try to animate the trajectory by moving the Frame Slider at the bottom of the Main window.
You should now see the variation over the trajectory compared to the static PDB.

Try toggling the (D)rawn status of different molecules.


### Deleting Molecules

To delete a molecule right click on it on it in the Main window and select Delete Molecule (see Figure 19 below).

![Figure 19: Selecting molecule to delete.](images/vmd-delete-mol.png)



## Want to Know More About VMD?

VMD is not only a molecular viewer but also allows you to analyse structures and trajectories, convert file format, render graphics for publication and many more things well beyond the scope of this tutorial.
When you want to try out these features best place to start is the [User Guide](http://www.ks.uiuc.edu/Research/vmd/vmd-1.9.2/ug/ug.html).

When you, inevtiably, run into difficulties a good first port of call is the [mailing list](http://www.ks.uiuc.edu/Research/vmd/mailing_list/).


<footer>
  <ul>
  Support via CCP-SAS a joint EPSRC (EP/K039121/1) and NSF (CHE-1265821) grant
  </ul>
</footer> 

