92dc1797f2ea13bf201d21fabf81208dccfd7c41
[alexxy/gromacs.git] / include / tpxio.h
1 /*
2  * $Id$
3  * 
4  *       This source code is part of
5  * 
6  *        G   R   O   M   A   C   S
7  * 
8  * GROningen MAchine for Chemical Simulations
9  * 
10  *               VERSION 2.0
11  * 
12  * Copyright (c) 1991-1999
13  * BIOSON Research Institute, Dept. of Biophysical Chemistry
14  * University of Groningen, The Netherlands
15  * 
16  * Please refer to:
17  * GROMACS: A message-passing parallel molecular dynamics implementation
18  * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19  * Comp. Phys. Comm. 91, 43-56 (1995)
20  * 
21  * Also check out our WWW page:
22  * http://md.chem.rug.nl/~gmx
23  * or e-mail to:
24  * gromacs@chem.rug.nl
25  * 
26  * And Hey:
27  * Green Red Orange Magenta Azure Cyan Skyblue
28  */
29
30 #ifndef _tpxio_h
31 #define _tpxio_h
32
33 static char *SRCID_tpxio_h = "$Id$";
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #ifdef CPLUSPLUS 
40 extern "C" {
41 #endif
42
43   /**************************************************************
44    *
45    * The routines in the corresponding c-file tpxio.c
46    * are based on the lower level routines in gmxfio.c
47    * The integer file pointer returned from open_tpx
48    * can also be used with the routines in gmxfio.h
49    *
50    **************************************************************/
51 #include "typedefs.h"
52 #include "xdrf.h"
53
54 typedef struct
55 {
56   int   bIr;            /* Non zero if input_rec is present             */
57   int   bBox;           /* Non zero if a box is present                 */
58   int   bTop;           /* Non zero if a topology is present            */
59   int   bX;             /* Non zero if coordinates are present          */
60   int   bV;             /* Non zero if velocities are present           */
61   int   bF;             /* Non zero if forces are present               */
62
63   int   natoms;         /* The total number of atoms                    */
64   int   step;           /* Current step number                          */
65   real  t;              /* Current time                                 */
66   real  lambda;         /* Current value of lambda                      */
67 } t_tpxheader;
68
69 /* 
70  * These routines handle reading and writing of preprocessed
71  * topology files in any of the following formats:
72  * TPR : topology in XDR format, portable accross platforms
73  * TPB : binary topology, not portable accross platforms
74  * TPA : ascii topology (possibbly huge)
75  * TRR : trajectory in XDR format (non compressed)
76  * TRJ : trajectory in binary format
77  *
78  * Files are written in the precision with which the source are compiled,
79  * but double and single precision can be read by either.
80  */
81
82 extern int open_tpx(char *fn,char *mode);
83 /* Return an integer corresponding to the file you have just opened */
84   
85 extern void close_tpx(int fp);
86 /*  Close the file corresponding to fp */
87   
88 extern void read_tpxheader(char *fn,t_tpxheader *tpx);
89 /* Read the header from a tpx file and then close it again */
90
91 extern void write_tpx(char *fn,int step,real t,real lambda,
92                       t_inputrec *ir,rvec *box,int natoms,
93                       rvec *x,rvec *v,rvec *f,t_topology *top);
94 /* Write a file, and close it again. 
95  * If fn == NULL, an efTPA file will be written to stdout (which
96  * will not be closed afterwards)
97  */
98
99 extern void read_tpx(char *fn,int *step,real *t,real *lambda,
100                      t_inputrec *ir,rvec *box,int *natoms,
101                      rvec *x,rvec *v,rvec *f,t_topology *top);
102 /* Read a file, and close it again. 
103  * If fn == NULL, an efTPA file will be read from stdin (which
104  * will not be closed afterwards)
105  */
106
107 extern void fwrite_tpx(int fp,int step,real t,real lambda,
108                        t_inputrec *ir,rvec *box,int natoms,
109                        rvec *x,rvec *v,rvec *f,t_topology *top);
110 /* Write a file, and do not close it */
111
112 extern void fread_tpx(int fp,int *step,real *t,real *lambda,
113                       t_inputrec *ir,rvec *box,int *natoms,
114                       rvec *x,rvec *v,rvec *f,t_topology *top);
115 /* Read a file, and do not close it */
116
117 extern bool fn2bTPX(char *file);
118 /* return if *file is one of the TPX file types */ 
119
120 extern bool read_tps_conf(char *infile,char *title,t_topology *top,
121                           rvec **x,rvec **v,matrix box,bool bMass);
122 /* Read title, top.atoms, x, v (if not NULL) and box from an STX file,
123  * memory for atoms, x and v will be allocated.  
124  * Return TRUE if a complete topology was read. 
125  * If infile is a TPX file read the whole top,
126  * else if bMass=TRUE, read the masses into top.atoms from the mass database.
127  */
128
129 #ifdef CPLUSPLUS
130 }
131 #endif
132
133 #endif