changed reading hint
[gromacs/adressmacs.git] / share / html / online / xtc.html
blobaa07802974b7cb09c37ada983cb2e5733aeba90b
1 <title>xtc file format</title>
2 <body>
3 <h2>xtc file format</h2>
4 The xtc format is a <b>portable</b> format for trajectories.
5 It uses the <i>xdr</i> routines for writing and reading
6 data which was created for the Unix NFS system. The trajectories
7 are written using a reduced precision algorithm which works
8 in the following way: the coordinates (in nm) are multiplied by a scale
9 factor, typically 1000, so that you have coordinates in pm.
10 These are rounded to integer values. Then several other tricks are
11 performed, for instance making use of the fact that atoms close
12 in sequence are usually close in space too (e.g. a water molecule).
13 To this end, the <i>xdr</i> library is extended with a special routine
14 to write 3-D float coordinates. This routine was written by Frans van Hoesel
15 as part of an Europort project, and can be obtianed through <a href="http://rugmd0.chem.rug.nl:80/~hoesel/xdrf.html">this link</a>.
16 <p>
17 All the data is stored using calls to <i>xdr</i> routines.
19 <dl>
20 <dt><b>int</b> magic
21 <dd>A magic number, for the current file version its value is 1995.
22 <dt><b>int</b> natoms
23 <dd>The number of atoms in the trajectory.
24 <dt><b>int</b> step
25 <dd>The simulation step.
26 <dt><b>float</b> time
27 <dd>The simulation time.
28 <dt><b>float</b> box[3][3]
29 <dd>The computational box which is stored as a set of three basis
30 vectors, to allow for triclinic PBC. For a rectangular box the
31 box edges are stored on the diagonal of the matrix.
32 <dt><b>3dfcoord</b> x[natoms]
33 <dd>The coordinates themselves stored in reduced precision.
34 Please note that when the number of atoms is smaller than 9
35 no reduced precision is used.
36 </dl>
38 <h3>Using xtc in your "C" programs</h3>
39 To read and write these files the following "C" routines are available:
40 <pre>
41 /* All functions return 1 if succesfull, 0 otherwise */
43 extern int open_xtc(XDR *xd,char *filename,char *mode);
44 /* Open a file for xdr I/O */
46 extern void close_xtc(XDR *xd);
47 /* Close the file for xdr I/O */
49 extern int read_first_xtc(XDR *xd,char *filename,
50 int *natoms,int *step,real *time,
51 matrix box,rvec **x,real *prec);
52 /* Open xtc file, read xtc file first time, allocate memory for x */
54 extern int read_next_xtc(XDR *xd,
55 int *natoms,int *step,real *time,
56 matrix box,rvec *x,real *prec);
57 /* Read subsequent frames */
59 extern int write_xtc(XDR *xd,
60 int natoms,int step,real time,
61 matrix box,rvec *x,real prec);
62 /* Write a frame to xtc file */
63 </pre>
64 To use the library function include <tt>"xtcio.h"</tt>
65 in your file and link with <tt>-lgmx.$(CPU)</tt>
66 <p>
68 <h3>Using xtc in your FORTRAN programs</h3>
69 To read and write these in a FORTRAN program use the calls to
70 <tt>readxtc</tt> and <tt>writextc</tt> as in the following sample program
71 which reads and xtc file and copies it to a new one:
72 <pre>
73 program testxtc
75 parameter (maxatom=10000,maxx=3*maxatom)
76 integer xd,xd2,natoms,step,ret,i
77 real time,box(9),x(maxx)
79 call xdrfopen(xd,"test.xtc","r",ret)
80 print *,'opened test.xtc, ret=',ret
81 call xdrfopen(xd2,"testout.xtc","w",ret)
82 print *,'opened testout.xtc, ret=',ret
84 10 call readxtc(xd,natoms,step,time,box,x,prec,ret)
86 if ( ret .eq. 1 ) then
87 call writextc(xd2,natoms,step,time,box,x,prec,ret)
88 else
89 print *,'Error reading xtc'
90 endif
92 stop
93 end
94 </pre>
95 To link your program use <tt>-L$(GMXHOME)/lib/$(CPU) -lxtcf</tt>
96 on your linker command line.
97 The source for this test can be found in file
98 <tt>$(GMXHOME)/src/gmxlib/testxtcf.f</ff>.
100 </body>