42ef1d83867788cf54774ed32717aac419824096
[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,2014,2015,2016,2017,2018, 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 #ifndef GMX_FILEIO_TPXIO_H
38 #define GMX_FILEIO_TPXIO_H
39
40 #include <cstdio>
41
42 #include "gromacs/math/vectypes.h"
43 #include "gromacs/utility/basedefinitions.h"
44 #include "gromacs/utility/real.h"
45
46 struct gmx_mtop_t;
47 struct t_atoms;
48 struct t_block;
49 struct t_inputrec;
50 class t_state;
51 struct t_topology;
52
53 struct t_tpxheader
54 {
55     bool  bIr;       /* Non zero if input_rec is present                */
56     bool  bBox;      /* Non zero if a box is present                    */
57     bool  bTop;      /* Non zero if a topology is present               */
58     bool  bX;        /* Non zero if coordinates are present             */
59     bool  bV;        /* Non zero if velocities are present              */
60     bool  bF;        /* Non zero if forces are present (no longer
61                         supported, but retained so old .tpr can be read) */
62
63     int   natoms;    /* The total number of atoms                       */
64     int   ngtc;      /* The number of temperature coupling groups    */
65     real  lambda;    /* Current value of lambda                 */
66     int   fep_state; /* Current value of the alchemical state --
67                       * not yet printed out.  */
68     /*a better decision will eventually (5.0 or later) need to be made
69        on how to treat the alchemical state of the system, which can now
70        vary through a simulation, and cannot be completely described
71        though a single lambda variable, or even a single state
72        index. Eventually, should probably be a vector. MRS*/
73 };
74
75 /*
76  * These routines handle reading and writing of preprocessed
77  * topology files in any of the following formats:
78  * TPR : topology in XDR format, portable accross platforms
79  *
80  * Files are written in the precision with which the source are compiled,
81  * but double and single precision can be read by either.
82  */
83
84 void read_tpxheader(const char *fn, t_tpxheader *tpx, gmx_bool TopOnlyOK);
85 /* Read the header from a tpx file and then close it again.
86  * By setting TopOnlyOK to true, it is possible to read future
87  * versions too (we skip the changed inputrec), provided we havent
88  * changed the topology description. If it is possible to read
89  * the inputrec it will still be done even if TopOnlyOK is TRUE.
90  */
91
92 void write_tpx_state(const char *fn,
93                      const t_inputrec *ir, const t_state *state, const gmx_mtop_t *mtop);
94 /* Write a file, and close it again.
95  */
96
97 void read_tpx_state(const char *fn,
98                     t_inputrec *ir, t_state *state,
99                     gmx_mtop_t *mtop);
100
101 /*! \brief
102  * Read a file and close it again.
103  *
104  * Reads a topology input file and populates the fields if the passed
105  * variables are valid. It is possible to pass \p ir, \p natoms,
106  * \p x, \p v or \p mtop as nullptr to the function. In those cases,
107  * the variables will not be populated from the input file. Passing both
108  * \p x and \p v as nullptr is not supported. If both \p natoms and
109  * \p mtop are passed as valid objects to the function, the total atom
110  * number from \p mtop will be set in \p natoms. Otherwise \p natoms
111  * will not be changed. If \p box is valid, the box will be set from
112  * the information read in from the file.
113  *
114  * \param[in] fn Input file name.
115  * \param[out] ir Input parameters to be set, or nullptr.
116  * \param[out] box Box matrix.
117  * \param[out] natoms Total atom numbers to be set, or nullptr.
118  * \param[out] x Positions to be filled from file, or nullptr.
119  * \param[out] v Velocities to be filled from file, or nullptr.
120  * \param[out] mtop Topology to be populated, or nullptr.
121  * \returns ir->ePBC if it was read from the file.
122  */
123 int read_tpx(const char *fn,
124              t_inputrec *ir, matrix box, int *natoms,
125              rvec *x, rvec *v, gmx_mtop_t *mtop);
126
127 int read_tpx_top(const char *fn,
128                  t_inputrec *ir, matrix box, int *natoms,
129                  rvec *x, rvec *v, t_topology *top);
130 /* As read_tpx, but for the old t_topology struct */
131
132 gmx_bool fn2bTPX(const char *file);
133 /* return if *file is one of the TPX file types */
134
135 void pr_tpxheader(FILE *fp, int indent, const char *title, const t_tpxheader *sh);
136
137 #endif