[gmx-users] C++ xtc interface

Adriaan Riet aar93 at case.edu
Mon Oct 2 23:23:01 CEST 2017


Hello,

I would like to do some work with xtc output files, but I'm having trouble.
The documentation <http://manual.gromacs.org/online/xtc.html> has the
following functions:

/* All functions return 1 if successful, 0 otherwise */

extern int open_xtc(XDR *xd,char *filename,char *mode);
/* Open a file for xdr I/O */

extern void close_xtc(XDR *xd);
/* Close the file for xdr I/O */

extern int read_first_xtc(XDR *xd,char *filename,
			  int *natoms,int *step,real *time,
			  matrix box,rvec **x,real *prec);


while the header file exposes the following signatures:

struct t_fileio *open_xtc(const char *filename, const char *mode);
/* Open a file for xdr I/O */

void close_xtc(struct t_fileio *fio);
/* Close the file for xdr I/O */

int read_first_xtc(struct t_fileio *fio,
                   int *natoms, gmx_int64_t *step, real *time,
                   matrix box, rvec **x, real *prec, gmx_bool *bOK);
/* Open xtc file, read xtc file first time, allocate memory for x */

Further, the documentation mentions that you should link to -lgmx, but the
only library I see for gromacs >=5.1 is -lgromacs (or -lgromacs_d). I
assumed the function signature of the header file was correct, and made a
small test case:

#include<iostream>
#include "gromacs/fileio/xtcio.h"
int main(int argc, char* argv[]){
  const char
filename[]={"$HOME/Documents/Research/gromacs/oakley/june2017Test/2017/09-21/10-06_angle0.42impConc0T1873.xtc"};
  const char mode[]={'r'};
  t_fileio *xdrFile = open_xtc(filename,mode);
  int *natoms;
  gmx_int64_t *step;
  real *time;
  matrix box;
  rvec **x;
  real *prec;
  gmx_bool *bOK;
  int answer=read_first_xtc(xdrFile,natoms,step,time,box,x,prec,bOK);
  std::cout<<filename<<'\t'<<natoms<<std::endl;
  if(answer){
    std::cout<<"I'm having a good day "<<std::endl;
  }

  return 0;
}

I'm compiling and linking fine, and make it through the "open_xtc"
function, but I'm segfaulting at the "read_first_xtc" function (i.e. not
having a good day). My xtc file probably doesn't fit in memory. Has anyone
had success using this interface? Is there a defined structure for the
t_file_io struct?

Thanks,
Adriaan Riet


More information about the gromacs.org_gmx-users mailing list