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

Kaihsu Tai kaihsu.tai at bioch.ox.ac.uk
Tue Feb 7 20:48:39 CET 2006


Dear Colleagues,

Using the interface Erik provided earlier (xdrfile.c and xdrfile.h in
"http://www.gromacs.org/pipermail/gmx-developers/2003-October/000665.html"),
I am trying to write some xtc files.  Everything seems to
work with my driver (attached, xtcExport.c) except that the
coordinates are all replaced by 0.000000.  I think I am
calling the function xdrfile_write_compr_coord_float() in an
incorrect way, but need some help in rectifying this.

I have so far tried using either
xdrfile_write_compr_coord_float(coords, nAtoms, prec, xtcFile);
or
xdrfile_write_compr_coord_float(&coords, nAtoms, prec, xtcFile);
but neither worked.  It must be painfully/embarrassingly
obvious ... but any ideas on how to fix this, please?

Cheers.

Erik Lindahl, 2003-10-17 09:58:08-0700:
> Sorry for the delay - I was looking around for the specification I
> wrote for all the binary file formats, but I couldn't find it on my
> laptop. I'll ask a colleague whom I sent a copy to a while ago and get
> back with it.
>
> Still, I have attached a file to read/write binary portable and the
> compressed xtc files we use. This also works on windows since it
> contains an full implementation of all necessary XDR routines.
-------------- next part --------------
/* convert (ad hoc) text coordinate format to Gromacs xtc format */
/* http://www.gromacs.org/documentation/reference_3.2/online/xtc.html */
/* Author: Kaihsu Tai (initiated xtcExport.c 2006-02-01) */
/* $Id: xtcExport.c,v 1.11 2006/02/06 15:06:16 kaihsu Exp $ */

/*
BioSimGrid    http://biosimgrid.org/    team at biosimgrid.org

Copyright 2003, 2004, 2005, 2006 University of Oxford and University of
Southampton

If you use this software in any way, please cite:
Kaihsu Tai, Stuart Murdock, Bing Wu, Muan Hong Ng, Steven Johnston, Hans
Fangohr, Simon J. Cox, Paul Jeffreys, Jonathan W. Essex, Mark S. P.
Sansom (2004) BioSimGrid: towards a worldwide repository for
biomolecular simulations. Org. Biomol. Chem. 2:3219-3221
http://dx.doi.org/10.1039/b411352g
http://eprints.ouls.ox.ac.uk/archive/00000804/

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
http://www.fsf.org/licensing/licenses/gpl.txt
*/

#include <stdio.h>
#include "xdrfile.c"

int MAXCOORDS = 3000000;

int main(int argc, char *argv[]) {
  FILE *frameFile;
  XDRFILE* xtcFile;
  int i, iRead, nAtoms;
  float fRead, prec;
  float coords[MAXCOORDS];

  /*
  printf("this time called with:\n");
  for (i = 0; i < argc; ++i) printf("%d: %s\n", i, argv[i]);
  */

  if (argc != 3) {
  /*
    printf("convert (ad hoc) frame text format to Gromacs xtc format\n");
    printf("Usage: xtcExport frameTextFileName xtcFileName\n\n");
    printf("$Id: xtcExport.c,v 1.11 2006/02/06 15:06:16 kaihsu Exp $\n");
  */
    return -1;
  }

  /* open the text file from which to read */
  frameFile = fopen(argv[1], "r");

  /* open the Gromacs xtc file to which to append */
  xtcFile = xdrfile_open(argv[2], "a");

  /* INTEGER - magic number which should be 1995 for XTC files. */
  fscanf(frameFile, "%d", &iRead);
  xdrfile_write_int(&iRead, 1, xtcFile);

  /* INTEGER - number of atoms in the frame. */
  fscanf(frameFile, "%d", &iRead);
  nAtoms = iRead;
  xdrfile_write_int(&iRead, 1, xtcFile);

  /* INTEGER - the step number */
  fscanf(frameFile, "%d", &iRead);
  xdrfile_write_int(&iRead, 1, xtcFile);

  /* FLOAT   - time of the frame (always single precision for XTC) */
  fscanf(frameFile, "%f", &fRead);
  xdrfile_write_float(&fRead, 1, xtcFile);

  /* 9*FLOAT - the current MD box size as a 3*3 matrix. */
  for (i = 0; i < 9; i++) {
    fscanf(frameFile, "%f", &fRead);
    xdrfile_write_float(&fRead, 1, xtcFile);
  }

  /* COMPRESSED_COORDINATES */
  for (i = 0; i < (nAtoms * 3); i++) {
    fscanf(frameFile, "%f", &fRead);
    coords[i] = fRead;
    /* printf("%f ", coords[i]); */
  }
  xdrfile_write_compr_coord_float(&coords, nAtoms, prec, xtcFile);

  fclose(frameFile);
  xdrfile_close(xtcFile);

  return 0;
}

/*
$Log: xtcExport.c,v $
Revision 1.11  2006/02/06 15:06:16  kaihsu
It appears that xdrfile_write_compr_coord_float(coords, nAtoms, prec, xtcFile)
takes nAtoms rather than (3 * nAtoms) as its second argument.  To be tested.

Revision 1.10  2006/02/03 17:32:15  kaihsu
Still needs to be replaced by the Europort data compression format.
See http://rugmd4.chem.rug.nl/hoesel/xdrf.html

Revision 1.9  2006/02/03 15:27:48  kaihsu
test suite

Revision 1.8  2006/02/02 18:35:05  kaihsu
should work now; need more testing to verify that the data is not garbage/rubbish

Revision 1.7  2006/02/02 18:00:43  kaihsu
using xdrfile methods

Revision 1.6  2006/02/01 17:41:41  kaihsu
no need to flush

Revision 1.5  2006/02/01 17:19:32  kaihsu
doing it correctly: in .py, close file first, then in .c, open file

Revision 1.4  2006/02/01 16:53:37  kaihsu
flush

Revision 1.3  2006/02/01 16:51:41  kaihsu
close files

Revision 1.2  2006/02/01 15:43:48  kaihsu
almost working structurally (just have to develop content and port to xdr format)

Revision 1.1  2006/02/01 14:49:05  kaihsu
initiated the C-language part of the enterprise

*/


More information about the gromacs.org_gmx-developers mailing list