SYCL: Avoid using no_init read accessor in rocFFT
[alexxy/gromacs.git] / src / gromacs / fileio / enxio.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 by the GROMACS development team.
7  * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
8  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9  * and including many others, as listed in the AUTHORS file in the
10  * top-level source directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38 #ifndef GMX_FILEIO_ENXIO_H
39 #define GMX_FILEIO_ENXIO_H
40
41 #include "gromacs/fileio/xdr_datatype.h"
42 #include "gromacs/utility/basedefinitions.h"
43 #include "gromacs/utility/real.h"
44
45 struct SimulationGroups;
46 struct t_energy;
47 struct t_enxframe;
48 struct t_fileio;
49 struct t_inputrec;
50 class t_state;
51
52 /**************************************************************
53  * These are the base datatypes + functions for reading and
54  * writing energy files (.edr). They are either called directly
55  * (as in the processing tools), or indirectly through mdebin.c
56  * during mdrun.
57  *
58  * The routines in the corresponding c-file enxio.c
59  * are based on the lower level routines in gmxfio.c.
60  * The file pointer returned from open_enx
61  * can also be used with the routines in gmxfio.h
62  *
63  **************************************************************/
64
65 typedef struct
66 {
67     char* name;
68     char* unit;
69 } gmx_enxnm_t;
70
71 /*
72  * Index for the IDs of additional blocks in the energy file.
73  * Blocks can be added without sacrificing backward and forward
74  * compatibility of the energy files.
75  *
76  * For backward compatibility, the order of these should not be changed.
77  */
78 enum
79 {
80     enxOR,    /* Time and ensemble averaged data for orientation restraints */
81     enxORI,   /* Instantaneous data for orientation restraints              */
82     enxORT,   /* Order tensor(s) for orientation restraints                 */
83     enxDISRE, /* Distance restraint blocks                                  */
84
85     enxDHCOLL, /* Data about the free energy blocks in this frame.           */
86     enxDHHIST, /* BAR histogram                                              */
87     enxDH,     /* BAR raw delta H data                                       */
88
89     enxAWH, /* AWH data */
90
91     enxNR /* Total number of extra blocks in the current code,
92            * note that the enxio code can read files written by
93            * future code which contain more blocks.
94            */
95 };
96
97 /* names for the above enum */
98 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
99 extern const char* enx_block_id_name[];
100
101
102 /* the subblocks that are contained in energy file blocks. Each of these
103    has a number of values of a single data type in a .edr file. */
104 struct t_enxsubblock
105 {
106     int         nr;   /* number of items in subblock */
107     XdrDataType type; /* the block type */
108
109     /* the values: pointers for each type */
110     float*         fval;
111     double*        dval;
112     int*           ival;
113     int64_t*       lval;
114     unsigned char* cval;
115     char**         sval;
116
117     /* the allocated sizes, defined separately.
118        (nonzero sizes can be free()d later): */
119     int fval_alloc;
120     int dval_alloc;
121     int ival_alloc;
122     int lval_alloc;
123     int cval_alloc;
124     int sval_alloc;
125 };
126
127 /* the energy file blocks. Each block contains a number of sub-blocks
128    of a single type that contain the actual data. */
129 struct t_enxblock
130 {
131     int            id;         /* block id, from the enx enums above */
132     int            nsub;       /* number of subblocks */
133     t_enxsubblock* sub;        /* the subblocks */
134     int            nsub_alloc; /* number of allocated subblocks */
135 };
136
137 /* file handle */
138 typedef struct ener_file* ener_file_t;
139
140 /*
141  * An energy file is read like this:
142  *
143  * ener_file_t fp;
144  * t_enxframe *fr;
145  *
146  * fp = open_enx(...);
147  * do_enxnms(fp,...);
148  * snew(fr,1);
149  * while (do_enx(fp,fr)) {
150  * ...
151  * }
152  * free_enxframe(fr);
153  * sfree(fr);
154  */
155 /* New energy reading and writing interface */
156
157
158 /* initialize a pre-allocated frame */
159 void init_enxframe(t_enxframe* ef);
160 /* delete a frame's memory (except the ef itself) */
161 void free_enxframe(t_enxframe* ef);
162
163
164 ener_file_t open_enx(const char* fn, const char* mode);
165
166 struct t_fileio* enx_file_pointer(const ener_file* ef);
167
168 /* Free the contents of ef */
169 void close_enx(ener_file_t ef);
170
171 /* Free the contents of ef, and ef itself */
172 void done_ener_file(ener_file_t ef);
173
174 void do_enxnms(ener_file_t ef, int* nre, gmx_enxnm_t** enms);
175
176 void free_enxnms(int n, gmx_enxnm_t* nms);
177 /* Frees nms and all strings in it */
178
179 gmx_bool do_enx(ener_file_t ef, t_enxframe* fr);
180 /* Reads enx_frames, memory in fr is (re)allocated if necessary */
181
182 void get_enx_state(const char* fn, real t, const SimulationGroups& groups, t_inputrec* ir, t_state* state);
183 /*
184  * Reads state variables from enx file fn at time t.
185  * atoms and ir are required for determining which things must be read.
186  * Currently pcoupl and tcoupl state are read from enx.
187  */
188
189
190 /* block funtions */
191
192 /* allocate n blocks to a frame (if neccesary). Don't touch existing blocks */
193 void add_blocks_enxframe(t_enxframe* ef, int n);
194
195 /* find a block by id number; if prev!=NULL, it searches from
196    that block's next block.
197    Returns NULL if no block is found with the given id. */
198 t_enxblock* find_block_id_enxframe(t_enxframe* ef, int id, t_enxblock* prev);
199
200
201 /* allocate n subblocks to a block (if neccesary). Don't touch existing
202    subbblocks. */
203 void add_subblocks_enxblock(t_enxblock* eb, int n);
204
205 void comp_enx(const char* fn1, const char* fn2, real ftol, real abstol, const char* lastener);
206 /* Compare two binary energy files */
207
208 #endif