2 * This file is part of the GROMACS molecular simulation package.
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,2019, 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.
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.
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.
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.
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.
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.
37 #ifndef GMX_FILEIO_TPXIO_H
38 #define GMX_FILEIO_TPXIO_H
44 #include "gromacs/math/vectypes.h"
45 #include "gromacs/utility/arrayref.h"
46 #include "gromacs/utility/basedefinitions.h"
47 #include "gromacs/utility/real.h"
58 * First part of the TPR file structure containing information about
59 * the general aspect of the system.
63 //! Non zero if input_rec is present.
65 //! Non zero if a box is present.
67 //! Non zero if a topology is present.
69 //! Non zero if coordinates are present.
71 //! Non zero if velocities are present.
73 //! Non zero if forces are present (no longer supported, but retained so old .tpr can be read)
75 //! The total number of atoms.
77 //! The number of temperature coupling groups.
79 //! Current value of lambda.
81 //! Current value of the alchemical state - not yet printed out.
83 /*a better decision will eventually (5.0 or later) need to be made
84 on how to treat the alchemical state of the system, which can now
85 vary through a simulation, and cannot be completely described
86 though a single lambda variable, or even a single state
87 index. Eventually, should probably be a vector. MRS*/
88 //! Size of the TPR body in chars (equal to number of bytes) during I/O.
89 int64_t sizeOfTprBody = 0;
93 int fileGeneration = 0;
94 //! If the tpr file was written in double precision.
95 bool isDouble = false;
99 * Contains the partly deserialized contents of a TPR file.
101 * Convenience struct that holds a fully deserialized TPR file header,
102 * and the body of the TPR file as char buffer that can be deserialized
103 * independently from the header.
105 struct PartialDeserializedTprFile
108 TpxFileHeader header;
110 std::vector<char> body;
111 //! Flag for PBC needed by legacy implementation.
116 * These routines handle reading and writing of preprocessed
117 * topology files in any of the following formats:
118 * TPR : topology in XDR format, portable accross platforms
120 * Files are written in the precision with which the source are compiled,
121 * but double and single precision can be read by either.
125 * Read the header from a tpx file and then close it again.
127 * By setting \p canReadTopologyOnly to true, it is possible to read future
128 * versions too (we skip the changed inputrec), provided we havent
129 * changed the topology description. If it is possible to read
130 * the inputrec it will still be done even if canReadTopologyOnly is true.
132 * \param[in] fileName The name of the input file.
133 * \param[in] canReadTopologyOnly If reading the inputrec can be skipped or not.
134 * \returns An initialized and populated TPX File header object.
136 TpxFileHeader readTpxHeader(const char *fileName, bool canReadTopologyOnly);
138 void write_tpx_state(const char *fn,
139 const t_inputrec *ir, const t_state *state, const gmx_mtop_t *mtop);
140 /* Write a file, and close it again.
144 * Complete deserialization of TPR file into the individual data structures.
146 * If \p state is nullptr, only populates ir and mtop.
148 * \param[in] partialDeserializedTpr Struct with header and char buffer needed to populate system.
149 * \param[out] ir Input rec to populate.
150 * \param[out] state System state variables to populate.
151 * \param[out] x Separate vector for coordinates, deprecated.
152 * \param[out] v Separate vector for velocities, deprecated.
153 * \param[out] mtop Global topology to populate.
157 int completeTprDeserialization(PartialDeserializedTprFile *partialDeserializedTpr,
164 //! Overload for final TPR deserialization when not using state vectors.
165 int completeTprDeserialization(PartialDeserializedTprFile *partialDeserializedTpr,
170 * Read a file to set up a simulation and close it after reading.
172 * Main function used to initialize simulations. Reads the input \p fn
173 * to populate the \p state, \p ir and \p mtop needed to run a simulations.
175 * This function returns the partial deserialized TPR file
176 * that can then be communicated to set up non-master nodes to run simulations.
178 * \param[in] fn Input file name.
179 * \param[out] ir Input parameters to be set, or nullptr.
180 * \param[out] state State variables for the simulation.
181 * \param[out] mtop Global simulation topolgy.
182 * \returns Struct with header and body in char vector.
184 PartialDeserializedTprFile read_tpx_state(const char *fn,
190 * Read a file and close it again.
192 * Reads a topology input file and populates the fields if the passed
193 * variables are valid. It is possible to pass \p ir, \p natoms,
194 * \p x, \p v or \p mtop as nullptr to the function. In those cases,
195 * the variables will not be populated from the input file. Passing both
196 * \p x and \p v as nullptr is not supported. If both \p natoms and
197 * \p mtop are passed as valid objects to the function, the total atom
198 * number from \p mtop will be set in \p natoms. Otherwise \p natoms
199 * will not be changed. If \p box is valid, the box will be set from
200 * the information read in from the file.
202 * \param[in] fn Input file name.
203 * \param[out] ir Input parameters to be set, or nullptr.
204 * \param[out] box Box matrix.
205 * \param[out] natoms Total atom numbers to be set, or nullptr.
206 * \param[out] x Positions to be filled from file, or nullptr.
207 * \param[out] v Velocities to be filled from file, or nullptr.
208 * \param[out] mtop Topology to be populated, or nullptr.
209 * \returns ir->ePBC if it was read from the file.
211 int read_tpx(const char *fn,
212 t_inputrec *ir, matrix box, int *natoms,
213 rvec *x, rvec *v, gmx_mtop_t *mtop);
215 int read_tpx_top(const char *fn,
216 t_inputrec *ir, matrix box, int *natoms,
217 rvec *x, rvec *v, t_topology *top);
218 /* As read_tpx, but for the old t_topology struct */
220 gmx_bool fn2bTPX(const char *file);
221 /* return if *file is one of the TPX file types */
223 void pr_tpxheader(FILE *fp, int indent, const char *title, const TpxFileHeader *sh);