Merge commit '4d39dbdaa88b63df182fb3ca1d9133f2809277c1' into cpp-migration
[alexxy/gromacs.git] / src / gromacs / mdlib / mdebin_bar.h
1 /*
2  * 
3  *                This source code is part of
4  * 
5  *                 G   R   O   M   A   C   S
6  * 
7  *          GROningen MAchine for Chemical Simulations
8  * 
9  *                        VERSION 3.2.0
10  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12  * Copyright (c) 2001-2004, The GROMACS development team,
13  * check out http://www.gromacs.org for more information.
14
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  * 
20  * If you want to redistribute modifications, please consider that
21  * scientific software is very special. Version control is crucial -
22  * bugs must be traceable. We will be happy to consider code for
23  * inclusion in the official distribution, but derived work must not
24  * be called official GROMACS. Details are found in the README & COPYING
25  * files - if they are missing, get the official version at www.gromacs.org.
26  * 
27  * To help us fund GROMACS development, we humbly ask that you cite
28  * the papers on the package - you can find them in the top README file.
29  * 
30  * For more info, check our website at http://www.gromacs.org
31  * 
32  * And Hey:
33  * Gromacs Runs On Most of All Computer Systems
34  */
35
36 #ifndef _mdebin_bar_h
37 #define _mdebin_bar_h
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /* The functions & data structures here describe writing 
44    energy differences (or their histogram )for use with g_bar */
45
46 /* Data for one foreign lambda, or derivative. */
47 typedef struct 
48 {
49     real *dh; /* the raw energy differences */
50     unsigned int ndh; /* number of data points */
51     unsigned int ndhmax; /* the maximum number of points */
52
53     int nhist; /* the number of histograms. There can either be
54                   0 (for no histograms)
55                   1 (for 'foreign lambda' histograms)
56                   2 (for derivative histograms: there's
57                      a 'forward' and 'backward' histogram
58                      containing the minimum and maximum
59                      values, respectively). */
60     int *bin[2]; /* the histogram(s) */
61     double dx; /* the histogram spacing in kJ/mol. This is the
62                   same for the two histograms */
63     unsigned int nbins; /* the number of bins */
64     gmx_large_int_t x0[2]; /* the starting point in units of spacing 
65                               of the histogram */
66     unsigned int maxbin[2]; /* highest bin number with data */
67
68     gmx_bool derivative; /* whether this delta_h contains derivatives */
69     double lambda; /* the 'foreign' lambda value associated with this delta H */
70     gmx_bool written; /* whether this data has already been written out */
71
72     double subblock_d[4]; /* data for an mdebin subblock for I/O. */
73     gmx_large_int_t subblock_l[4]; /* data for an mdebin subblock for I/O.  */
74     int subblock_i[4]; /* data for an mdebin subblock for I/O.  */
75 } t_mde_delta_h;
76
77 /* the type definition is in mdebin.h */
78 struct t_mde_delta_h_coll
79 {
80     t_mde_delta_h *dh; /* the delta hs */
81     int ndh; /* the number of delta_h structures */
82     int ndhdl; /* number of derivative delta_hs */
83
84     double start_time; /* start time of the current dh collection */
85     double delta_time; /* time difference between samples */
86     gmx_bool start_time_set; /* whether the start time has been set */
87
88     double start_lambda; /* the native lambda associated with the free energy 
89                            calculations (at the time of the first sample) */
90     double delta_lambda; /* lambda difference between samples */
91
92     double temp; /* the temperature */
93     double subblock_d[5]; /* data for writing an mdebin subblock for I/O */
94 };
95
96
97
98 /* initialize a collection of delta h histograms/sets 
99     dhc = the collection
100     ir = the input record */
101 void mde_delta_h_coll_init(t_mde_delta_h_coll *dhc,
102                            const t_inputrec *ir);
103
104 /* add a bunch of samples to the delta_h collection
105     dhc = the collection
106     dhdl = the hamiltonian derivative
107     U = the array with energies: from enerd->enerpart_lambda.
108     time = the current simulation time. */
109 void mde_delta_h_coll_add_dh(t_mde_delta_h_coll *dhc, 
110                              double dhdl,
111                              double *U, double time,
112                              double native_lambda);
113
114 /* write the data associated with the du blocks collection as a collection
115     of mdebin blocks.
116     dhc = the collection
117     fr = the enxio frame
118     nblock = the current number of blocks */
119 void mde_delta_h_coll_handle_block(t_mde_delta_h_coll *dhc,   
120                                    t_enxframe *fr, int nblock);
121
122
123 /* reset the collection of delta_h buffers for a new round of 
124    data gathering */
125 void mde_delta_h_coll_reset(t_mde_delta_h_coll *dhc);
126
127
128 /* set the energyhistory variables to save state */
129 void mde_delta_h_coll_update_energyhistory(t_mde_delta_h_coll *dhc, 
130                                            energyhistory_t *enerhist);
131
132 /* restore the variables from an energyhistory */
133 void mde_delta_h_coll_restore_energyhistory(t_mde_delta_h_coll *dhc, 
134                                             energyhistory_t *enerhist);
135
136
137 #ifdef __cplusplus
138 }
139 #endif
140
141 #endif  /* _mdebin_bar_h */
142