945489eb5d76f4872b6c18ecefabeea34b515755
[alexxy/gromacs.git] / src / gromacs / fileio / trrio.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,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.
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_TRRIO_H
38 #define GMX_FILEIO_TRRIO_H
39
40 #include "gromacs/math/vectypes.h"
41 #include "gromacs/utility/basedefinitions.h"
42 #include "gromacs/utility/real.h"
43
44 /**************************************************************
45  *
46  * These routines handle trr (trajectory) I/O, they read and
47  * write trr files. The routines should be able to read single
48  * and double precision files without the user noting it.
49  * The files are backward compatible, therefore the header holds
50  * some unused variables.
51  *
52  * The routines in the corresponding c-file trrio.cpp
53  * are based on the lower level routines in gmxfio.cpp
54  * The file handle returned from gmx_trr_open()
55  * can also be used with the routines in gmxfio.h
56  *
57  * Note that TRR was designed to represent a step number as a default
58  * integer, which depends on the implementation, but is typically and
59  * 32 bit. We didn't design the format to be extensible, so we can't
60  * fix the fact that after 2^31 frames, step numbers will wrap to be
61  * negative. Fortunately, this tends not to cause serious problems,
62  * and we've fixed it in TNG. Meanwhile, the implementation pretends
63  * to the rest of GROMACS that it functions with int64_t like all
64  * other step numbers, but the actual range in practice depends on the
65  * defaults of the implementation in use now (or when the file was
66  * written).
67  *
68  **************************************************************/
69
70 struct t_fileio;
71
72 /* This struct describes the order and the  */
73 /* sizes of the structs in a trr file, sizes are given in bytes. */
74 typedef struct gmx_trr_header_t
75 {
76     gmx_bool bDouble;   /* Double precision?                   */
77     int      ir_size;   /* Backward compatibility              */
78     int      e_size;    /* Backward compatibility              */
79     int      box_size;  /* Non zero if a box is present        */
80     int      vir_size;  /* Backward compatibility              */
81     int      pres_size; /* Backward compatibility              */
82     int      top_size;  /* Backward compatibility              */
83     int      sym_size;  /* Backward compatibility              */
84     int      x_size;    /* Non zero if coordinates are present */
85     int      v_size;    /* Non zero if velocities are present  */
86     int      f_size;    /* Non zero if forces are present      */
87
88     int     natoms;    /* The total number of atoms           */
89     int64_t step;      /* Current step number                 */
90     int     nre;       /* Backward compatibility              */
91     real    t;         /* Current time                        */
92     real    lambda;    /* Current value of lambda             */
93     int     fep_state; /* Current value of alchemical state   */
94 } gmx_trr_header_t;
95
96 struct t_fileio* gmx_trr_open(const char* fn, const char* mode);
97 /* Open a trr file */
98
99 void gmx_trr_close(struct t_fileio* fio);
100 /* Close it */
101
102 gmx_bool gmx_trr_read_frame_header(struct t_fileio* fio, gmx_trr_header_t* header, gmx_bool* bOK);
103 /* Read the header of a trr file. Return FALSE if there is no frame.
104  * bOK will be FALSE when the header is incomplete.
105  */
106
107 gmx_bool gmx_trr_read_frame_data(struct t_fileio* fio, gmx_trr_header_t* sh, rvec* box, rvec* x, rvec* v, rvec* f);
108 /* Extern read a frame except the header (that should be pre-read,
109  * using routine gmx_trr_read_frame_header(), see above) from a trr file.
110  * Return FALSE on error
111  */
112
113 gmx_bool gmx_trr_read_frame(struct t_fileio* fio,
114                             int64_t*         step,
115                             real*            t,
116                             real*            lambda,
117                             rvec*            box,
118                             int*             natoms,
119                             rvec*            x,
120                             rvec*            v,
121                             rvec*            f);
122 /* Read a trr frame, including the header from fp. box, x, v, f may
123  * be NULL, in which case the data will be skipped over.
124  * return FALSE on error
125  */
126
127 void gmx_trr_write_frame(struct t_fileio* fio,
128                          int64_t          step,
129                          real             t,
130                          real             lambda,
131                          const rvec*      box,
132                          int              natoms,
133                          const rvec*      x,
134                          const rvec*      v,
135                          const rvec*      f);
136 /* Write a trr frame to file fp, box, x, v, f may be NULL */
137
138 void gmx_trr_read_single_header(const char* fn, gmx_trr_header_t* header);
139 /* Read the header of a trr file from fn, and close the file afterwards.
140  */
141
142 void gmx_trr_read_single_frame(const char* fn,
143                                int64_t*    step,
144                                real*       t,
145                                real*       lambda,
146                                rvec*       box,
147                                int*        natoms,
148                                rvec*       x,
149                                rvec*       v,
150                                rvec*       f);
151 /* Read a single trr frame from file fn, which is closed afterwards
152  */
153
154 void gmx_trr_write_single_frame(const char* fn,
155                                 int64_t     step,
156                                 real        t,
157                                 real        lambda,
158                                 const rvec* box,
159                                 int         natoms,
160                                 const rvec* x,
161                                 const rvec* v,
162                                 const rvec* f);
163 /* Write a single trr frame to file fn, which is closed afterwards */
164
165
166 #endif