Import GROMACS coordinate files into Mathematica
Edan Scriven and Tyrone Curtis
GROMACS is a suite of molecular dynamics tools used to perform simulations of chemical systems at the molecular level. GROMACS handles input and output of atomic co-ordinates using the .gro file format, which is in plain text. Edan Scriven and Tyrone Curtis developed a Mathematica package to import these .gro files (and associated .top GROMACS topology files) for processing, analysis and visualisation.
The utility is capable of reading
atomic co-ordinates and velocities from a .gro file, and the atomic
mass, charge, and bonding information from a .top (topology) file. An
example of the visualisation capabilities of the package is shown
below. The molecule used in the example picture below (and which is
available for download at the bottom of the page) is lac21, a
fragment of the lac repressor protein.
The data was obtained from
Adam Fairley's Mathematics Honours research thesis, titled “Molecular
Dynamics Simulations of the Self-Assembly of the Lac21 and Lac28
peptides for Bio-Nano Applications”,
in collaboration with Prof. Anton Middelberg of the Australian
Institute for Bioengineering & Nanotechnology.

Figure: The lac21 molecule, showing atomic co-ordinates and bonds,
as imported from a GROMACS .gro file, and rendered in Mathematica
Below is a Mathematica .nb file which demonstrates the import utility in action. The .nb file is the demonstration notebook, and the .m file is a package that contains the import functionality. To install the package, create a directory under AddOns/Applications called Gromacs, and copy Gromacs.m into this Gromacs directory. You may need to right-click the link and select Save As... to download the file. Also available are the files needed to visualise the lac21 protein fragment. Note that the GROMACS import utility makes use of the StringSplit[ ] function, which is new to Mathematica 5.1, and consequently, these functions must be replaced with less elegant string manipulation functions in order to allow the package to work with earlier versions of Mathematica. For example, the line
ToExpression[StringSplit[groData[[-1]]]]
which is used to extract the box dimensions from the last line of the .gro file must be replaced with something like
Off[Syntax::com]
Select[ToExpression["{"
<> StringReplace[groData[[-1]]," "->","]
<> "}"], NumberQ]
A typical example of the data on which this code operates is this (whitespace included):
7.78470 9.30790 3.99145
What the new code does is replace every space character in the line with a comma, then concatenate braces onto the start and end of the new string, so that the data is now:
{,,,,,,7.78470,,,9.30790,,,3.99145}
ToExpression[ ] evaluates the string as if it were a line of Mathematica executable code. This effectively converts the string into a list. However, Syntax::com generates warnings when ToExpression[ ] is evaluated, becaues the list contains Null elements. That's why Syntax::com has been turned off. Select[list, NumberQ] selects only those list elements which are of type Number, effectively removing all of these Null elements. The remainder is:
{7.78470, 9.30790, 3.99145}
Downloadable files
