JavaScript Menu, DHTML Menu Powered By Milonic

The Molecular Modeling Nerd Corner

This tutorial introduces the student to the practice of Molecular Dynamics (MD) simulations of proteins. The protocol used is a suitable starting point for investigation of proteins, provided that the system does not contain non-standard groups. At the end of the tutorial, the student should know the steps involved in setting up and running a simulation, including some reflection on the choices made at different stages. Besides, the student should know how to perform quality assurance checks on the simulation results and have a feel for methods of analysis to retrieve information.

Install Gromacs with MPI support

For those who know how to get around in Linux, it may be worth installing Gromacs yourself. In fact, you might want to install it from source. It's really one of the few programs that will compile with little else than ./configure and make.


But then again, it does pay off to install a library for doing Fourier transformations. So, first get FFTW and install that:


tar xvzf fftw-3.2.1.tar.gz

cd fftw-3.2.1 && ./configure --enable-float --prefix=$HOME/fftw && make && make install


Now it's time to get Gromacs. For this tutorial, we use version 4.0.5. Feel free to (also) install another (newer) version, but be aware that some steps in the tutorial might need to be changed a bit then.


tar xvzf gromacs-4.0.5.tar.gz

cd gromacs-4.0.5

Time for business! Set the environment variables CPPFLAGS and LDFLAGS to point to the FFTW directories. Then compile Gromacs. Setting the environment variables in the following way will work for bash/sh as well as for (t)csh, but since you went to this page, you'll know which part of the command to take.

setenv CPPFLAGS -I$HOME/fftw/include || export CPPFLAGS=-I$HOME/fftw/include

setenv LDFLAGS -L$HOME/fftw/lib || export LDFLAGS=-L$HOME/fftw/lib

./configure --prefix=$HOME/GMX/GMX405 && make && make install

Just a last thing to do: automatically load the Gromacs environnement paramaters and librairies. This can be done by adding this line to your ~/.cshrc or ~/.bashrc file as follows:

cat "source $HOME/GMX/GMX405/bin/GMXRC" >> ~/.cshrc


Well, there you have it! But then again, this doesn't give you MPI support yet. To achieve that, you'll also have to fetch an MPI library and compiler.


tar xvjf lam-7.1.4.tar.bz2

cd lam-7.1.4 && ./configure --prefix=$HOME/lam714 && make && make install


That should've done the trick. If it didn't, you'll probably have to resolve some dependencies. Assuming you got this one right (in the end), let's compile gromacs' mdrun with MPI support. Go to the gromacs directory and type

make clean

setenv MPICC $HOME/lam714/bin/mpicc || export MPICC=$HOME/lam714/bin/mpicc

./configure --prefix=$HOME/GMX/GMX405 --enable-mpi --program-suffix="_mpi"

make mdrun && make install-mdrun


So, that should do it. Now you ought to be able to run your simulations on all two/four/eight or dedicate your home-made network to something else than FPSs. You can run a simulation on four processors/cores with:


$HOME/lam714/bin/mpirun -np 4 mdrun_mpi -s topol.tpr -c -g -e -x -o -cpi -append -cpo


A bit of SED trickery

Sometimes it's just convenient to modify text files without actually opening them. Especially when writing scripts to automate tasks, including setting up simulations, it will frequently occur that you have to modify the contents of some file. Now, if you know what to change and how to change it, there's a good chance you can do it with just one or a few lines of code. Changing a single parameter in the simulation parameter file is one of these cases. For instance, we can change the pbc setting from 'none' to 'xyz' in the file minim.mdp using

sed -i /^pbc/s/no/xyz/ minim.mdp

This calls the program 'sed', the "stream editor", which is a powerful tool to handle text files or streams and offers many options for editing automatically. In the present case, the flag -i calls sed in interactive mode, which means that the file(s) on the command line are changed, rather than giving the edited stream as output to stdout. The next part tells sed what to do:
/^pbc/ is an address specifier. It tells sed to look for lines starting with the string 'pbc'. On those lines, the following will be executed:
s/none/xyz/ substitutes the part matching the first regexp, simply 'no' in this case, with the string specified in the second part, 'xyz'.

More SED trickery

The previous sed trick showed how to replace a word in a line starting with "pbc". sed can also be used to operate on blocks of text, by using two address specifiers; one for start and one for stop. The objective is simple: print the part of the file that starts with "Total NODE time". To indicate the end of the file, the special address specifier "$" is used. The command for printing is "p", so that makes the sed line '/Total NODE time/,$p'. But the common behaviour of sed is to print every line. To diasable that, the command line option -n is used:

sed -ne '/^Total NODE time'/,$p' md0.log

As a side note, we could also want a couple of lines following a line containing a specific piece of text. For instance, we are mainly interested in the performance. This is summarized in the four lines following "NODE (s)   Real (s)      (%)". To get these lines and print them, we seek the line containing "NODE (s)", print it (p) and read in the next line (n) and print it, repeating the last two commands three times. To group a set of commands to be executed at one address, use curly braces and semicolons:

sed -ne '/NODE (s)/{p;n;p;n;p;n;p;n;p}' md0.log

Pretty pictures with POV-Ray

The built-in raytracer of Pymol does a fair job producing images. In fact, it is now widely used for generating images for publications. In most cases the general settings are kept default and with a bit of training one will easily recognize which images were created with Pymol, VMD or molmol. Okay, but in most cases not standing out in terms of graphics. To make more from an image, it pays off to export the file to a format that can be read with a ray-tracing engine such as POV-Ray. One might argue that it makes no sense to do so, but an attractive image may draw attention to your work, especially if it stands out in one sense or the other.

For the following POV-Ray should be installed on your computer. Try the command 'povray' and if it doesn't show you a page of help, but rather "command not found", first install it. For other reasons than this tutorial to install POV-Ray, have a look at the sample page

Now download the Pymol script and start Pymol, loading your protein. Then, load the script using:


Set up the scene just the way you want it, changing colours, representation, etc. A lot of settings relating to the view can be changed in POV-Ray, but it doesn't allow you to view the results as quickly, since you have to ray-trace before you can get it on the screen. Also, colours can be changed in POV-Ray, but requires a bit of work (using sed). Best is to use Pymol to set everything up as nicely as you can and use POV-Ray for the polishing. If you're satisfied with the scene, export it to POV-Ray format using the command "make_pov" that was added to Pymol by the script, and then quit.

make_pov myprot.pov


Now open the file myprot.pov in your favourite editor. It will probably look something like this:

camera {direction<0.0,0.0,  -2.835>
 location <0.0 , 0.0 , 0.0>
 right 1.3333334607*x up y 
#default { finish{phong   -1.000 ambient    0.500 diffuse    0.450 
phong_size 13.750000}}
light_source{<4000.0001,4000.0001,9893.0252>  rgb<1.0,1.0,1.0>}
plane{z , -182.9770 
 pigment{color rgb<0.0000,0.0000,0.0000>}
 finish{phong 0 specular 0 diffuse 0 ambient 1.0}}

// Uncomment the following lines if you have the include file and want to use it.
#include ""
PYMOL_VIEW(   -0.57029,   -0.52722,   -0.62992,
              -0.79048,    0.14367,    0.59540,
              -0.22341,    0.83750,   -0.49869,
              -0.00001,    0.00001, -138.40367,
             -18.41776,    7.04160,   10.14061,
             106.97485,  169.83109,    0.00000 )

#include ""

Without further editing, this file can be raytraced as a 1000x500 pixel, 8 bits/colour PNG image file using:

povray +Imyprot.pov +Onormal.png +FN8 +W700 +H500 +Q9 +A0.3 +ua

The option +Q sets the quality (9 is full), +A sets the anti-aliasing and +ua sets the transparent background. This gives the following image:

File rendered using standard settings

Cute, but Pymol does a better job than that. One thing that is not so nice is the sharpness of the shadows. This is due to the use of a single light source, like what you get in space with the light from the sun. On earth, light is scattered, making shadows look softer, just as if the light was coming from an area rather than a point. In POV-Ray we can mimick this by adding an array of lights, rather than a single light source. Note that this, jsut like any of the subsequent steps, increases the complexity of the scene, and consequently increases the rendering time. Replace the line specifying the light source with

  rgb 1
  area_light <40,0,0>,<0,40,0>,5,5
  adaptive 1

This gives the following image. Notice the softer shadows.

File rendered with area_light for softer 

Better, but the colours still look a bit dull. I like a glossy, shining plastic like appearance. Actually, I like to use that as the default appearance of surfaces. Replace the current #default statement with the following one and render again.

#default { finish {
        ambient .15
        diffuse .5
        specular 1
        roughness .001
        reflection {

File rendered with glossy finish

Now you can see the side chains reflecting in the surface of the helices :) But it should be a bit brighter. To make the colours more vivid, we can increase the intensity of the light. In the light_source statement, the color of the light is specified as 1, which is shorthand for <1,1,1>: 100% of red, green and blue. Let's just set it to two, increasing the light intensity twofold.

File rendered with glossy finish, but 
light intensity increased to 200%, giving brighter colours

Let's take a step further. One characteristic of photographic images is that they have focal blurring. With POV-Ray, we can add this effect to our image. Change the camera statement so that it reads:

camera {direction<0.0,0.0,  -2.835>
  location <0.0 , 0.0 , 0.0>
  right 2*x up y 
  focal_point < 0.0, 0.0, -140 >
  aperture 40
  blur_samples 20

The rendering will now take a bit longer, but this does add a dimension to the picture. You may have to tune the focal point and the aperture. An aperture of 40 is bit overdone, but it does illustrate the effect.

File rendered with focal blur

Focal blur also really helps making grayscale images stand out. Here's an example from Dr. Tsjerk A. Wassenaar's thesis, showing hemoglobin in stereo view.

Hemoglobin rendered in grayscale with 
focal blur