Using VMD
Getting Started
About VMD
Visual Molecular Dynamics (VMD) is an application for Windows, macOS, and Linux that allows researchers to view molecular structures and simulation trajectories. VMD itself has many useful features for selecting and drawing different parts of a molecule, but it can be enhanced through various plugins and user-made scripts. In addition to viewing molecular structures, VMD provides a variety of methods to export images that can be used in publications and movies. The homepage to VMD can be accessed here.
Obtaining VMD
An up-to-date version of VMD can be downloaded here. As of this writing the current version is 1.9.3.
Referencing VMD
Please be sure to cite the developers of VMD when it is used to create figures/movies that are used in publications and presentations. A bibtek file with the proper citations can be found here. At a minimum, users should include the following citation in their works (also found in the bibtek file):
Loading a Molecular System
The first step to using VMD is to load a molecular system file that tells VMD how many atoms exist, what type each atom is, and how each atom is connected to other atoms. For simple protein structures, the user can usually just load a PDB file (since VMD can assume atomic connectivity based on the protein sequence). For more complicated systems or even coarse-grain systems (like Gō-models), the connectivity cannot be inferred from just a PDB, so the user must first load a PSF file and then add atomic coordinates to that.
Loading a PDB File
Once VMD is open, a molecular system is loaded by going to File > New Molecule and selecting the desired PDB file from the computer directory.
Loading a PSF and Coordinate File
Go to File > New Molecule and select the desired PSF file from the computer directory.
NOTE: simul.psf files for TheCode are not compatible with VMD.
Typically, VMD will not show anything after a PSF is loaded, although the new molecular system will be listed in the main window with the total number of atoms. To see atom positions, load a coordinate (PDB, XYZ, CRD) or trajectory file (TRR, DCD). NOTE: when selecting a CRD file, the user must change the file type in the Molecule File Browser
to "CHARMM CRD" since VMD always defaults to "Amber CRD". For instructions on how to load files see next section
Loading a Simulation Trajectory
Once a molecular system has been set up, additional coordinate information can be added to it. For example, if a PDB was loaded, the user can then add TRR, DCD, or lammps_traj data to the molecule to view molecular motions. To do so, the user selects the molecule in the VMD Main
window, right-clicks and selects Load Data into Molecule...
The user then finds and selects the desired trajectory file and clicks open. This takes the user back to the Molecule File Browser
where the user has the option of telling VMD which frames from the trajectory file they wish to load and how they want them loaded. The radial buttons are important:
- "Load in background" tells VMD to read the trajectory frame-by-frame and to draw each frame after loading. For large files do not do this as it will take a very long time.
- "Load all at once" tells VMD to silently load the trajectory data into RAM all at once. For large trajectory files do this.
Multiple trajectory files can be loaded in series to produce a longer movie. Please note that movie trajectories start at frame 0. The coordinates of a loaded PDB file will count as a frame 0, so remember this if you load an additional trajectory file and need to extract data from a specific frame in that file or reference that frame later on.
Trajectory File Formats
Trajectory files are composed of "frames" where each frame contains, at a minimum, the x, y, z coordinates of each atom in the simulation. Some formats, like TRR, can also save x, y, z velocity components for each atom as well.
- TRR -- Comes from the GROMACS simulation package and is used in Dr. Knotts' TheCode. It is a binary file, so it can't be read directly by humans. TRR files are quite forgiving, in that if a simulation terminates early the file will still be readable.
- DCD -- Comes from the CHARMM simulation package and is also used by LAMMPS. It is a binary file, but it doesn't seem as forgiving as TRR.
- ❗️TIP: DCD files saved in Unix don't natively work in Windows because of carriage return/newline differences, so to view these it is best to stick with a Unix/Linux-based system.
- lammps_traj -- A LAMMPS-specific trajectory format that is a text file. While it's human-readable, it quickly grows in size and becomes unwieldy to open, even with text editors like
vim
(check out theless
editor in Linux if you need to open a huge text file).
💡While TRR and DCD files cannot be read directly by humans, the coordinate data in them can be accessed through the Python package MDAnalysis
.
Basic Display Settings
The display menu, found in the VMD Main
window, provides access to commands that affect the entire scene that VMD draws. Some of the settings are specialty effects while others are simple but important to know.
Quick Controls
The following is a list of keyboard shortcuts and quick contols you can use to manipulate the image display. All can be found in the "Mouse" section:
- r Rotate mode; Default mode when opening VMD, switch to this mode to rotate the molecule about the center atom
- t Translation mode; 2D translate across the molecule in your camera's current plane of reference
- s Scale mode; left-click + mouse movement zooms in or out if you move your mouse right or left,respectively
- mouse scroll Accomplishes coarse zooms in all previously mentions modes
- c Center selection; The next selected atom will now be defined as the "center atom" where you will rotate your view around
- 0 Query selection; The next selected atom will produce information about that site in your bash shell
- Mouse > Label > Atom/Bond/Angle/Dihedral Label these parameters in your display with consecutive atom selections
- Graphics > Labels... Opens a menu to manage Labels. Also displays atom information
Display Setting Changes
For most simulation images there are a couple of changes to the default VMD display settings that yield a better looking image. These changes include:
- Display > Perspective vs Orthographic -- This radial button defaults to perspective, but orthographic provides a better image overall. With perspective enabled (as it must be if a stage is turned on) the viewer sees the molecule as if it were some ginormous thing that would fade to a single point in the distance. Orthographic instead renders the molecule as if it were something small enough to sit on your desk.
- Display > Depth Cueing -- Enables a "fog" that makes parts of the molecule further away from the camera appear washed out or darker. Again, it doesn't produce a nice image, so typically you will uncheck this option.
- Dispaly > Axes -- Allows the user to enable/move the position of the x, y, z arrows on screen. For publication quality images this should be turned off, but it can help diagnose simulation problems when simulations involve a planar surface at z = 0.
- Dispaly > Stage -- Draws a stage on a specified part of the VMD
Display
window. This can be used to make a "surface" on which surface-bound molecules can be placed so they're not just floating in space. - Graphics > Colors; then selecting the "Display" option; then selecting "Background" -- Allows the user the change the background color
Creating Representations
What are Representations?
Once a molecular system has been loaded the user can then change the way that it is displayed to suit their purposes. At the most basic level, a "Graphical Representation" consists of an atom selection, a coloring method, and a drawing method. A molecule can have many representations; for example, one representation may display water molecules around a protein while a second displays the cartoon structure and a third highlights important side chain atoms.
Creating a Representation
Representations are edited by going to the VMD Main
window and selecting Graphics > Representations to open the Graphical Representations
window (have you noticed yet that VMD opens lots of windows?). The prominent window at the top lists all of the representations for a molecule. An individual representation can be toggled on/off by double clicking it here. Above this window are buttons to create a new representation (which simply copies the currently selected representation) and to delete the currently selected representation (cannot be undone).
The next major window below is the Selected Atoms
text box, where the user can tell VMD which atoms are to be included in the selected representation above. Below this are a series of tabs, the most commonly used of which is the Drawing Style
tab. Here, the Coloring Method
and Drawing Method
drop-down menus are found along with their associated options.
Making an Atom Selection
With a representation selected, the first task to creating the desired image is to tell VMD which atoms to show. The Selected Atoms
box is powerful, but also super finicky. Some key words that are particularly useful include:
- segname -- PDB, PSF, and CRD files can contain 4-letter segment identifiers that can be used to select groups of atoms.
- To select a segment:
segname ATNB
- Selections don't have to be 4 letters long, example:
segname FAB
- To select a segment:
- chain -- for protein and DNA structures selecting atoms by chain can be simple and useful, like using the segname selection
- To select a single chain:
chain A
- To select multiple chains:
chain A or chain C or chain E
- To select a single chain:
- index -- base 0, this allows the user to select single atoms or a group of atoms (and yes, the base 0 will mess with your brain endlessly...)
- To select a single atom use:
index 237
- To select a group of sequential atoms:
index 115 to 768
- To select a group of nonsequential atoms:
index 389 or index 712 or index 954 or index...
- To select a single atom use:
- name -- selects an atom type, such as alpha-carbons, amine hydrogens, etc.
- Example:
name CA
- Example:
- resname -- selects all molecule groups with a given name, such as amino acids, nucleic acids, or water molecules
- To select all cysteine amino acids:
resname CYS
- To select all water molecules:
resname HOH
- To select all cysteine amino acids:
Keywords and their selections can be combined using ( and boolean operators:
- and -- atoms must have all specified properties to be in the selection
- Example:
segname 0001 and name CA
- Example:
- or -- allows atoms with different properties to be in the selection
- Example:
name N or name CA or name C
- Example:
- not -- prevents atoms with the specified properties from being part of the selection
- Example:
not hydrogen
,segname 1BDD and not sidechain
- Example:
- ( or ) -- allows the user to group selections together
- Example:
segname ANTB or segname ANTG and ( not hydrogen or not resname HOH )
- Example:
Additional selection keywords, many of which are suited toward biological molecules, can be found in the Selections
tab next to Draw Style
Adding Colors
Once a representation has been made, the user can color the atoms in that selection through a variety of ways. Like atom selections, some coloring methods are complex (i.e., will use different colors for different atoms within a given selection) while others are very simple.
- ColorID -- The most simple, but most direct way of adding color, it simply colors all atoms/objects with the same color, which is selected in the dropdown menu that appears to the side of
Coloring Method
- Molecule -- Colors all atoms in the current molecule with the same color. Each additional molecule is assigned a different color. The color for each molecule can be changed in
VMD Main
Graphics > Colors... - SegName -- Colors all atoms in each segment identifier with the same color, but each segment is a different color. This is a quick way to color a molecular system if the PDB, PSF, and CRD files have the proper
segname
s listed
Choosing a Drawing Method
The final major component of a representation is to decide how the atoms you've selected will be displayed. There are many drawing method options, which can be mixed and matched to achieve the desired final result. Some of the common methods are:
- Lines -- Typically the default setup, this treats atoms and points and draws lines between them. It's very fast, so for large systems (like 100,000+ atoms) this is the only real way of moving the viewpoint around without significant lag.
- CPK -- This creates a ball-and-stick drawing for atomistic models and isolated spheres for coarse-grain models. The sphere scale can be adjusted to make the atoms take up more or less space.
- 💡TIP: for Gō-like models a good representation is to use CPK with a sphere scale of 12. The spheres will appear to take up about as much space as they really do during simulations.
- Trace -- Draws unconnected cylinders between backbone atoms in proteins. It is often paired with CPK to made a bead-on-a-string representation of Gō-like models.
- 💡TIP: the bond radius (cylinder diameter) can be increased or decreased to make the trace fit better with the chosen CPK sphere scale.
- New Cartoon -- Draws the alpha-helix and beta-sheet shapes for proteins often seen in molecular biology.
- VDW -- Draws a surface over the molecule as if it were plastic wrapped. This helps highlight gaps and indents in the structure but can easily become power-consuming with enough detail.
- Licorice -- Draws connected, capped cylinders connecting all atoms.
- 💡TIP: use licorice to highlight side chains on amino acids that are otherwise represented using the New Cartoon method.
- Dynamic Bonds -- A quick-and-dirty method of preventing bonds from being drawn across the simulation box when periodic boundaries were used. However, it also has the tendency to draw unrealistic bonds, too.
Selecting a Drawing Material
The final representation option that is sometimes changed is the material. This controls how light interacts with the selected representation. While there are many options, really only a few are typically used:
- Opaque -- This is the default, makes objects appear to be made out of shiny plastic.
- Transparent -- Draws the object like normal but allows the background to pass through. A large bunch of atoms is just as transparent as individual atoms, so their partial opacities aren't additive.
- 💡TIP: This option works best with a white background
- Goodsell -- Recreates the famous (?) flattened protein drawing developed by David Goodsell. It can make for an awesome figure, but it appears that the VMD version needs some more work.
The rest of the different material options don't look good in VMD, but they're probably more useful for figures that will be rendered in POV-RAY.
Rendering Figures
Once the representations are set up and the viewpoint has been moved so that the image is ready for saving, VMD has several methods for saving what you see in the Display
window. The File Render Controls
window can be accessed by going to the VMD Main
window and selecting File > Render...
Rendering Methods
To begin rendering go to File > Render... The top box in the File Render Controls
is a dropdown menu with different render engines. While several options exist, only two or 3 of them are typically used in our group:
- Snapshot -- The default, it uses some built in program that saves exactly what you see in the
Display
window to a file. This is good for quickly making images and setting up figures, but it isn't sufficient for publication-quality images.- 💡TIP: While this renderer acts like it can save images in several different formats, it doesn't seem to do it properly, so make sure you give your image file the proper extension for your system (for macOS this is .tga).
- POV-RAY -- This option writes a command file for the POV-RAY application instead of producing human-viewable image. Select this renderer when preparing publication-quality images.
- IMPORTANT: Make sure you read and understand the "Using POV-RAY" section before you prematurely render your POV-RAY image. NOTE: As described below, if you want to remove your background, the image background much be white.
- 💡TIP: The POV-RAY file remembers the
Display
window dimensions, so be careful with what shape you give it. For example, usingdisplay resize 660 510
in the VMD terminal window makes a landscape image that is proportional to an 8.5" x 11" piece of paper. - 💡TIP: POV-RAY files are just text files, but can take up a lot of space, especially if you use VDW as your representation. However, they are highly compressible (i.e., a 300 MB .pov file compresses to about 18 MB with
tar -Jcf
).
- Tachyon (internal) -- In newer versions of VMD (1.9.3+) this is a built-in ray tracer that can produce publication quality images. Although it doesn't require that the user post process a .pov file with POV-RAY, it can be CPU-intensive and it doesn't provide an option (at least that I know of) to make the background transparent, as can be done in POV-RAY.
- 💡TIP: It is relatively easy to use shadows, ambient occlusion lighting, and depth of field effects with the Tachyon renderer, which can produce stunning images with high-quality, 3D effects.
Rendered Filename
While this box is self-explanatory, there is one key thing to remember: You must write out the full file extension! VMD does not autofill the extension for you, so if you forget to add it, you will end up with a "file" that, while still valid, will be hard for Windows or macOS to know what to do with.
Render Command
This is normally left alone, since even when working with POV-RAY the commands can be changed later on in that program.
Special Effects
POV-RAY can support special rendering effects that can create stunning, high-quality images with a strong 3D appearance. While these can be used with VMD's built-in Tachyon renderer, they should also be available for POV-RAY, so long as they are enabled in VMD before generating the .pov file. NOTE: enabling these effects does not change what you will see in the VMD Display
window. Some of these effects include:
- Shadows -- Allows atoms to cast shadows onto other atoms (yeah ok, we know light doesn't behave that way at the atomic scale, but it's still a cool effect!).
- Amb. Occl - Enables ambient occlusion lighting, which produces diffuse, omnidirectional light that helps to produce a 3D effect. It also allows light to bounce off of one atom and onto another atom.
- DoF -- Enables depth of field, or focal length, effects. This allows atoms at a particular distance from the camera to be in focus while those in the foreground or background are blurred. This helps to center the viewer's focus on the part of the image that's clear.
- 💡This setting isn't required to make high-quality 3D images, but it can be the frosting on top of an already awesome picture.
Using POV-RAY
POV-RAY is a ray tracing program that can produce life-like images from a computer model of a scene. It can be downloaded free of charge here. It is currently unavailable on macOS, but can be installed on Linux and Windows systems. The Windows version has the added benefit that it can use multiple cores at the same time, which greatly speeds up complex scenes (e.g., 100,000's of atoms with transparency). In our group POV-RAY is used to create publication-quality images from simulation data.
POV-RAY Commands
Given POV-RAY's power, it is very easy to use and the settings don't have to change often for the kinds of images typically made from molecular simulations. The basic set of commands to use on Linux is this:
povray +W3300 +H2550 -I<file_name> -O<file_name> +Q11 +J +A +FN +UA
The elements of this command are as follows:
- +W -- This tells POV-RAY how wide the final image will be in units of pixels. For .pov files from VMD, this value needs to be proportional to the VMD
Display
window at the time the .pov file was created.- The values used in VMD for +W and +H can be found by opening the .pov file created in VMD in a text editor. They are located in one of the comment lines at the top of the file.
- 💡3300 pixels is a good default for publication-quality images because it allows the image to be scaled up to 8.5" x 11" and still be at 300 DPI
- +H -- Tells POV-RAY how tall the final image will be in units of pixels. Like +W, the number needs to be proportional to the VMD display window.
- The values used in VMD for +W and +H can be found by opening the .pov file created in VMD in a text editor. They are located in one of the comment lines at the top of the file.
- 💡2550 pixels is a good default to get 300 DPI for a 8.5" x 11" image.
- 💡The values for +W and +H can be interchanged if an image needs to be drawn as a portrait, but remember that the original .pov must be set up that way or the final image will be skewed.
- -I -- Tells POV-RAY the name of the .pov file. You most likely need to include the file extension for this to work.
- -O -- Tells POV-RAY the name of the final image, which will usually end up being something like
image_name.pov.png
on Linux systems. - +Q11 -- Tells POV-RAY the overall quality of the resulting image. 11 is the maximum level, but since molecular system images are usually quite simple this hardly impacts the rendering time.
- +J -- Tells POV-RAY to enable jittering, or to "shake" the light source as it ray traces, to diffuse the light source (usually a point source). This helps with anti-aliasing to make highlights and edges smoother.
- +A -- Tells POV-RAY to enable anti-aliasing, which feathers sharp lines to make the image look more realistic.
- +F -- Tells POV-RAY the file type of the final image. "FN" means save to a .png file, which is useful for our publication images because PNGs support transparency.
- +UA -- Tells POV-RAY to make the background transparent. This is especially important for publication-quality images because it allows the molecules to be placed on hand-drawn surfaces or next to other molecule images in programs such as Adobe Illustrator.
- ❗️Note: In order for POV-RAY to remove the background the VMD background must be white. If you leave it default black, this command will not execute properly and the background will not become transparent. To change the background color go to: Graphics -> Colors, select Display -> Background, then choose the desired color.
The Windows version of POV-RAY has a GUI, so the user does not need to use the command "povray" to run the program. Once the program is opened the .pov file can be opened and the remaining commands are placed in a text box near the top by the menu bar.