Merge release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / fileio / tpxio.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team,
6  * Copyright (c) 2013, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37
38 #ifndef GMX_FILEIO_TPXIO_H
39 #define GMX_FILEIO_TPXIO_H
40
41
42 /**************************************************************
43  *
44  * The routines in the corresponding c-file tpxio.c
45  * are based on the lower level routines in gmxfio.c
46  * The integer file pointer returned from open_tpx
47  * can also be used with the routines in gmxfio.h
48  *
49  **************************************************************/
50 #include "../legacyheaders/typedefs.h"
51 #include "gmxfio.h"
52
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56
57 typedef struct
58 {
59     int   bIr;       /* Non zero if input_rec is present                */
60     int   bBox;      /* Non zero if a box is present                    */
61     int   bTop;      /* Non zero if a topology is present               */
62     int   bX;        /* Non zero if coordinates are present             */
63     int   bV;        /* Non zero if velocities are present              */
64     int   bF;        /* Non zero if forces are present          */
65
66     int   natoms;    /* The total number of atoms                       */
67     int   ngtc;      /* The number of temperature coupling groups    */
68     real  lambda;    /* Current value of lambda                 */
69     int   fep_state; /* Current value of the alchemical state --
70                       * not yet printed out.  */
71     /*a better decision will eventually (5.0 or later) need to be made
72        on how to treat the alchemical state of the system, which can now
73        vary through a simulation, and cannot be completely described
74        though a single lambda variable, or even a single state
75        index. Eventually, should probably be a vector. MRS*/
76 } t_tpxheader;
77
78 /*
79  * These routines handle reading and writing of preprocessed
80  * topology files in any of the following formats:
81  * TPR : topology in XDR format, portable accross platforms
82  * TPB : binary topology, not portable accross platforms
83  * TPA : ascii topology (possibbly huge)
84  * TRR : trajectory in XDR format (non compressed)
85  * TRJ : trajectory in binary format
86  *
87  * Files are written in the precision with which the source are compiled,
88  * but double and single precision can be read by either.
89  */
90
91 t_fileio *open_tpx(const char *fn, const char *mode);
92 /* Return an file pointer corresponding to the file you have just opened */
93
94 void close_tpx(t_fileio *fio);
95 /*  Close the file corresponding to fio */
96
97 void read_tpxheader(const char *fn, t_tpxheader *tpx, gmx_bool TopOnlyOK,
98                     int *version, int *generation);
99 /* Read the header from a tpx file and then close it again.
100  * By setting TopOnlyOK to true, it is possible to read future
101  * versions too (we skip the changed inputrec), provided we havent
102  * changed the topology description. If it is possible to read
103  * the inputrec it will still be done even if TopOnlyOK is TRUE.
104  *
105  * The version and generation if the topology (see top of tpxio.c)
106  * are returned in the two last arguments.
107  */
108
109 void write_tpx_state(const char *fn,
110                      t_inputrec *ir, t_state *state, gmx_mtop_t *mtop);
111 /* Write a file, and close it again.
112  * If fn == NULL, an efTPA file will be written to stdout (which
113  * will not be closed afterwards)
114  */
115
116 void read_tpx_state(const char *fn,
117                     t_inputrec *ir, t_state *state, rvec *f,
118                     gmx_mtop_t *mtop);
119 int read_tpx(const char *fn,
120              t_inputrec *ir, matrix box, int *natoms,
121              rvec *x, rvec *v, rvec *f, gmx_mtop_t *mtop);
122 /* Read a file, and close it again.
123  * If fn == NULL, an efTPA file will be read from stdin (which
124  * will not be closed afterwards)
125  * When step, t or lambda are NULL they will not be stored.
126  * Returns ir->ePBC, if it could be read from the file.
127  */
128
129 int read_tpx_top(const char *fn,
130                  t_inputrec *ir, matrix box, int *natoms,
131                  rvec *x, rvec *v, rvec *f, t_topology *top);
132 /* As read_tpx, but for the old t_topology struct */
133
134 gmx_bool fn2bTPX(const char *file);
135 /* return if *file is one of the TPX file types */
136
137 gmx_bool read_tps_conf(const char *infile, char *title, t_topology *top,
138                        int *ePBC, rvec **x, rvec **v, matrix box, gmx_bool bMass);
139 /* Read title, top.atoms, x, v (if not NULL) and box from an STX file,
140  * memory for atoms, x and v will be allocated.
141  * Return TRUE if a complete topology was read.
142  * If infile is a TPX file read the whole top,
143  * else if bMass=TRUE, read the masses into top.atoms from the mass database.
144  */
145
146 void tpx_make_chain_identifiers(t_atoms *atoms, t_block *mols);
147
148 #ifdef __cplusplus
149 }
150 #endif
151
152 #endif