Remove some include order dependencies
[alexxy/gromacs.git] / src / gromacs / mdlib / mdebin_bar.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, 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 _mdebin_bar_h
39 #define _mdebin_bar_h
40
41 #include "gromacs/legacyheaders/mdebin.h"
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47
48 /* The functions & data structures here describe writing
49    energy differences (or their histogram )for use with g_bar */
50
51 /* Data for one foreign lambda, or derivative. */
52 typedef struct
53 {
54     real        *dh;                    /* the raw energy data. */
55     float       *dhf;                   /* raw difference data -- in floats, for storage. */
56     unsigned int ndh;                   /* number of data points */
57     unsigned int ndhmax;                /* the maximum number of points */
58
59     int          nhist;                 /* the number of histograms. There can either be
60                                            0 (for no histograms)
61                                            1 (for 'foreign lambda' histograms)
62                                            2 (for derivative histograms: there's
63                                               a 'forward' and 'backward' histogram
64                                               containing the minimum and maximum
65                                               values, respectively). */
66     int            *bin[2];             /* the histogram(s) */
67     double          dx;                 /* the histogram spacing in kJ/mol. This is the
68                                            same for the two histograms? */
69     unsigned int    nbins;              /* the number of bins in the histograms*/
70     gmx_int64_t     x0[2];              /* the starting point in units of spacing
71                                                of the histogram */
72     unsigned int    maxbin[2];          /* highest bin number with data */
73
74     int             type;               /* the block type according to dhbtDH, etc. */
75     int             derivative;         /* The derivative direction (as an index in the lambda
76                                            vector) if this delta_h contains derivatives */
77     double         *lambda;             /* lambda vector (or NULL if not applicable) */
78     int             nlambda;            /* length of the lambda vector */
79     gmx_bool        written;            /* whether this data has already been written out */
80
81     gmx_int64_t     subblock_meta_l[5]; /* metadata for an mdebin subblock for
82                                                I/O: for histogram counts, etc.*/
83     double         *subblock_meta_d;    /* metadata subblock for I/O, used for
84                                            communicating doubles (i.e. the lambda
85                                            vector) */
86     int subblock_meta_i[4];             /* metadata subblock for I/O, used for
87                                            communicating ints (i.e. derivative indices,
88                                            etc.) */
89 } t_mde_delta_h;
90
91 /* the type definition is in mdebin_bar.h */
92 struct t_mde_delta_h_coll
93 {
94     t_mde_delta_h *dh;                 /* the delta h data */
95     int            ndh;                /* the number of delta_h structures */
96
97     int            nlambda;            /* number of bar dU delta_h structures */
98     t_mde_delta_h *dh_du;              /* the delta h data (pointer into dh) */
99
100     int            ndhdl;              /* number of bar dU delta_h structures */
101     t_mde_delta_h *dh_dhdl;            /* the dhdl data (pointer into dh) */
102
103     t_mde_delta_h *dh_energy;          /* energy output block (pointer into dh) */
104     t_mde_delta_h *dh_pv;              /* pV output block (pointer into dh) */
105     t_mde_delta_h *dh_expanded;        /* expanded ensemble output block (pointer
106                                           into dh) */
107
108     double   start_time;               /* start time of the current dh collection */
109     double   delta_time;               /* time difference between samples */
110     gmx_bool start_time_set;           /* whether the start time has been set */
111     double   start_lambda;             /* starting lambda for continuous motion of state*/
112     double   delta_lambda;             /* delta lambda, for continuous motion of state */
113     double   temperature;              /* the temperature of the samples*/
114
115     double  *native_lambda_vec;        /* The lambda vector describing the current
116                                           lambda state if it is set (NULL otherwise) */
117     int      n_lambda_vec;             /* the size of the native lambda vector */
118     int     *native_lambda_components; /* the native lambda (and by extension,
119                                           foreign lambda) components in terms
120                                           of efptFEP, efptMASS, etc. */
121     int     lambda_index;              /* the lambda_fep_state */
122
123     double *subblock_d;                /* for writing a metadata mdebin subblock for I/O */
124     int    *subblock_i;                /* for writing a metadata mdebin subblock for I/O */
125
126     double *lambda_vec_subblock;       /* native lambda vector data subblock for
127                                           I/O */
128     int    *lambda_index_subblock;     /* lambda vector index data subblock for I/O */
129 };
130
131
132
133 /* initialize a collection of delta h histograms/sets
134     dhc = the collection
135     ir = the input record */
136
137 void mde_delta_h_coll_init(t_mde_delta_h_coll *dhc,
138                            const t_inputrec   *ir);
139
140 /* add a bunch of samples to the delta_h collection
141     dhc = the collection
142     dhdl = the hamiltonian derivatives
143     U = the array with energies: from enerd->enerpart_lambda.
144     time = the current simulation time.
145     current_lambda = current lambda values : primarily useful for continuous processes
146     fep_state = current fep_state
147  */
148
149 /* add a bunch of samples - note fep_state is double to allow for better data storage */
150 void mde_delta_h_coll_add_dh(t_mde_delta_h_coll *dhc,
151                              double              fep_state,
152                              double              energy,
153                              double              pV,
154                              double             *dhdl,
155                              double             *foreign_dU,
156                              double              time);
157
158 /* write the data associated with the du blocks collection as a collection
159     of mdebin blocks.
160     dhc = the collection
161     fr = the enxio frame
162     nblock = the current number of blocks */
163 void mde_delta_h_coll_handle_block(t_mde_delta_h_coll *dhc,
164                                    t_enxframe *fr, int nblock);
165
166
167 /* reset the collection of delta_h buffers for a new round of
168    data gathering */
169 void mde_delta_h_coll_reset(t_mde_delta_h_coll *dhc);
170
171
172 /* set the energyhistory variables to save state */
173 void mde_delta_h_coll_update_energyhistory(t_mde_delta_h_coll *dhc,
174                                            energyhistory_t    *enerhist);
175
176 /* restore the variables from an energyhistory */
177 void mde_delta_h_coll_restore_energyhistory(t_mde_delta_h_coll *dhc,
178                                             energyhistory_t    *enerhist);
179
180
181 #ifdef __cplusplus
182 }
183 #endif
184
185 #endif  /* _mdebin_bar_h */