Trajectory conversion

Gromacs can work with a number of trajectory file formats. The two most important are TRR Files and XTC Files. You can get more information on trajectory file types (popup). All trajectory conversions can be performed with the Gromacs tool trjconv.
Create a trajectory file containing only protein atoms (select the protein group):

gmx trjconv -f md.xtc -s md.tpr -o md_protein.xtc -center -ur compact -pbc mol

We also need a *.gro or *.pdb file that contains the exact particles as the trajectory, so other programs know how to interpret the numbers in the trajectory. It is possible to dump the first frame at time 0 into a *.pdb file:

gmx trjconv -f md.xtc -s md.tpr -o md_protein.pdb -center -ur compact -pbc mol -dump 0

For many Gromacs analysis tools it is handy to have a trajectory input file (*.tpr) with the exact same particles (protein atoms in this case), as it contains explicit information on bonds and enables Gromacs tools to handle artifacts that are produced by molecules that cross periodic boundary conditions:

gmx convert-tpr -s md.tpr -o md_protein.tpr

Secondary Structure & DSSP

Before doing any analysis, you should have a look at the data in md.edr and of course view the trajectory in VMD. Play around with it and test different representations. Unfortunately, VMD does not automatically update secondary structure information of proteins on its own, but you can download a script for VMD that updates secondary structure. Save the file in the directory where you opened VMD. Enter source sscache.tcl into the VMD console to load the script, followed by start_sscache top to start updating the secondary structure information for the currently active molecule. Now you should see the secondary structure change.
It is also possible to generate a plot of the secondary structure per residue versus time using Gromacs. You first need to make sure that the program DSSP is either installed on your computer (just try to run the command dssp and check if it works) or download it from the DSSP website. Now you need to export a variable that contains the full path to your dssp executable:

export DSSP=/full/path/to/dssp

You can get the full path to dssp by running the command which dssp. This step is only necessary to enable Gromacs to find the dssp executable. Now execute these three commands in order:

gmx do_dssp -f md_protein.xtc -s md_protein.tpr -o ss.xpm

gmx xpm2ps -f ss.xpm -o ss.eps -bx 1 -by 30

ps2pdf -sPAPERSIZE=ledger ss.eps ss.pdf

Depending on the actual number of frames in your trajectory you might want to pass the -dt parameter to do_dssp together with a time in ps to extract only a subset of frames. If the ps2pdf tool is not installed, google to find a way to open an eps file directly. Open the obtained file ss.pdf with a pdf reader of your choice. You should obtain a plot that shows how the secondary structure of [KIGAKI]3 evolves with time, similar to the figure to the right.

Measuring distances

Gromacs can also measure all kinds of distances between atoms and atom groups for the trajectory. You will have noticed by now, that Gromacs knows about several standard groups that you can often select when you work with the tools. Some standard groups are protein atoms, solvent atoms, or only Cα atoms. Now we are interested in how the distance between the Cα atoms of the N- and C-terminal residues evolves with time. Gromacs needs to now the indices of these atoms in the trajectory. We could look them up manually in one of the structure files, but there is a more comfortable way. The tool make_ndx can create index files with non-standard groups. You can run it with

gmx make_ndx -f md_protein.tpr -o NC_distance.ndx

A selection text will be required from you. The selection language is quite cryptic, but simple things are simple to achieve. We want the Cα atoms of the N- and C-terminal residues. These residues have the indices 1 and 18. We can create a new group containing these atoms by selecting the intersection of the group that contains only Cα atoms (group 3) with the group that contains only atoms of residues 1 and 18. You must enter:

3 & ri 1 18

Then type enter again to list the defined groups. The new group will appear at the end. You can write everything to the previously specified file NC_distance.ndx by entering q.
Now we can use our newly defined group to plot the distance of these two atoms versus time. This is done with the tool distance:

gmx distance -f md_protein.xtc -s md_protein.tpr -oall NC_dist.xvg -oh NC_disthist.xvg -n NC_distance.ndx -tu ns -len 2 -binw 0.01

We pass the trajectory and structure files, together with output filenames for a distance plot and a histogram. A time unit can be specified with -tu ns, in this case nanoseconds. The -len and -binw arguments specify the center of the histogram and the width of the bins. Both output files can be viewed with xmgrace. Your outputs should look similar to the plots to the right.


This tutorial is relatively new and has not been tested much in real life learning situation. Therefore we have to rely on your feedback to improve it. Please take a few minutes at the end to send some words of feedback about problems you encountered, or things you did not like by e-mail to Oliver Schillinger.