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