[gmx-developers] Re: Python interface connecting Gromacs and BioSimGrid

Kaihsu Tai kaihsu at biop.ox.ac.uk
Tue Oct 14 17:56:34 CEST 2003

All right: Attached is my attempt at writing a GROMACS
'.gro'-file parser for BioSimGrid, after a few short days of
Python-learning.  Certainly I cannot carry on like this, so
the objective is to torture you with my primitive Python
code until you give me yours!!!  Bwahahaha!!!

Seriously, I would really appreciate if someone could please
provide parsers for '.gro' and '.xtc' files in Python.  That
will speed up the BioSimGrid work greatly.

(By the way, I think my colleague Stuart Murdock talked with
David van der Spoel at Cecam.  Hope that bettered our mutual

Erik Lindahl, 2003-10-07 09:32:24-0700:
> >We are currently looking into building an automated
> >interface to deposit trajectories from GROMACS (and from
> >other simulation code) into BioSimGrid, whose backend is a
> >commodity relational database.
> Great - that sounds exciting!
> >Several options are worth considering:
> >3) Involving Python.
> >Since we already use Python on the analyses front of our
> >project, we are interested in exploring option 3.  Rumour
> >has it that there is a Python interface to GROMACS being
> >developed.  Would you please tell us more about it?
> Sure, although it still isn't finished. The main idea is to use the
> ability of C to interface with Python (see e.g. pymol for an excellent
> example). Each program (and several other routines) will be converted
> into a reasonably clean C function with arguments for all files and
> options. We will then write small python wrapper scripts for all the
> current analysis tools, so they work in almost the same way.
> David is the main force behind this, but if you want to help he might
> need a hand with converting functions. Drop him a line at
> spoel at xray.bmc.uu.se (I think he's at a conference this week).
United Nations Day is 24 October.  http://www.un.org/events/unday/
-------------- next part --------------
groName = '/home/kaihsu/ompla/OMPLA5/md_prod0.gro'
groFile = file(groName)
groDesc = groFile.readline()
nAtoms = int(groFile.readline())
print nAtoms

atoms = {}
residues = {}
for iAtom in range(0,nAtoms):
  line = groFile.readline()
  rSnum = int(line[0:5])
  name = line[9:15].strip()
  snum = int(line[15:20])
  atoms[snum] = (name, rSnum)
  if not residues.has_key(rSnum):
    residues[rSnum] = line[5:9].strip()

boxList = groFile.readline().split()
boxX = boxList[0]
boxY = boxList[1]
boxZ = boxList[2]

# At this time,
# 'groDesc' is a description from the .gro file;
# 'nAtoms' is the number of atoms;
# 'atoms' is a dictionary of atoms, with key being serial number,
#   and the tuple having the atom name and the residue serial number;
# 'residues' is a dictionary of residues, with key being serial number;
# 'boxX', 'boxY', and 'boxZ' are the box dimensions.
# There is no error checking!!

More information about the gromacs.org_gmx-developers mailing list