From: Axel Kohlmeyer (
Date: Tue Oct 13 2009 - 08:59:59 CDT

On Tue, 2009-10-13 at 13:05 +0100, Matt Watkins wrote:
> Hi all,

hi matt,

> I'm running in to some problems writing trr files with the gromacs
> molfile plugin. My cell is hexagonal, with the main symmetry axis

i don't think this is a good idea to begin with. VMD has only a very
limited view on non-orthogonal cells, i.e. it doesn't store the cell
vectors, but only the relative lengths and angles thus leaving the
orientation of the cell undefined. so you only have support for
triclinic cells in a specific orientation (a-vector along x-axis,
b-vector in xy-plane, and c-vector chose to give a right handed
coordinate system).

> along the z direction. The cell vectors are read correctly, however,
> on writing in trr format the cell angles become cubic and the "B" cell
> vectors are incorrect - test case below.
> It looks to me as if there is an inconsistency between lines 520 of
> Gromacs.h and line 459 on gromacsplugin.C (but my C is terrible, I
> may well be have missed other internal rotations done by VMD and I've
> failed to get recompiled plugins to work with my vmd to check).

VMD does not do any rotations unless you ask for it, some molfile
plugins that support reading non-orthogonal cells with any orientation
rotate cell and coordinates according to the needs of VMD. i remember
implementing this in the cube plugin a long time ago and then copying
it to a few other and other people picking the code up in their plugins.

i just looked up the changelog and it looks as if the trr write code
is something that i wrote over four years ago (i don't recall it...).
the code in gromacsplugin.C looks ok to me. the one in Gromacs.h
is less thorough, as it does not check whether the cell is properly
oriented, but _if_ the cell is properly oriented, it should work.

the gromacs plugin has not been updated in quite a while and i have
been thinking to rewrite it to use the libxdrfile library that has been
split off of gromacs and put under BSD license.

> So,
> does anyone agree that the axes get distorted in the gromacs plugin,
> and is the fix as simple as changing the dot product in the gromacs
> plugin?

the question is what are your initial cell _vectors_,
if they do not conform to what VMD assumes internally,
you have to change the corresponding _reader_ plugin to
rotate all your coordinates so they match the assumptions
about the periodicity and the cell orientation that VMD makes.
check out the cubeplugin for an example.

> How do I link recompiled molfile plugins into vmd - do I need to
> recompile vmd itself?

no. all you need to do is to crank up the minor version number,
compile a shared version of the plugin and copy it over the existing
shared version of the plugin.

compiling a shared plugin object on linux is as simple as:

gcc -o -shared -I$PATH_TO_PLUGIN_SOURCES/include \
  -fpic -I. -Wall -O2 gromacsplugin.C -lm

> Cheers,
> Matt
> Example problem file
> Load in pdb format save in trr, reload pdb and trr and pbc get.
> CRYST1 30.754 30.754 70.000 90.00 90.00 60.00 P 1
> 1
> ATOM 1 F F X 2 29.790 11.630 8.670 0.00 0.00
> p.s. apologies if this appears twice, I tried previously and think the
> message got bounced.

Dr. Axel Kohlmeyer 
Institute for Computational Molecular Science
College of Science and Technology
Temple University, Philadelphia PA, USA.