Update copyright statements and change license to LGPL
[alexxy/gromacs.git] / include / types / state.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  * check out http://www.gromacs.org for more information.
7  * Copyright (c) 2012, by the GROMACS development team, led by
8  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9  * others, as listed in the AUTHORS file in the top-level source
10  * 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 _state_h_
39 #define _state_h_
40
41
42 #include "simple.h"
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 /*
49  * The t_state struct should contain all the (possibly) non-static
50  * information required to define the state of the system.
51  * Currently the random seeds for SD and BD are missing.
52  */
53
54 /* for now, define the length of the NH chains here */
55 #define NHCHAINLENGTH 10
56 #define MAXLAMBDAS 1024
57
58 /* These enums are used in flags as (1<<est...).
59  * The order of these enums should not be changed,
60  * since that affects the checkpoint (.cpt) file format.
61  */
62   enum { estLAMBDA,
63          estBOX, estBOX_REL, estBOXV, estPRES_PREV, estNH_XI,  estTC_INT,
64          estX,   estV,       estSDX,  estCGP,       estLD_RNG, estLD_RNGI, 
65          estDISRE_INITF, estDISRE_RM3TAV,
66          estORIRE_INITF, estORIRE_DTAV,
67          estSVIR_PREV, estNH_VXI, estVETA, estVOL0, estNHPRES_XI, estNHPRES_VXI, estFVIR_PREV,
68          estFEPSTATE, estMC_RNG, estMC_RNGI,
69          estNR };
70
71 #define EST_DISTR(e) (!(((e) >= estLAMBDA && (e) <= estTC_INT) || ((e) >= estSVIR_PREV && (e) <= estMC_RNGI)))
72
73 /* The names of the state entries, defined in src/gmxlib/checkpoint.c */
74 extern const char *est_names[estNR];
75
76 typedef struct
77 {
78   real disre_initf;    /* The scaling factor for initializing the time av. */
79   int  ndisrepairs;    /* The number of distance restraints                */
80   real *disre_rm3tav;  /* The r^-3 time averaged pair distances            */
81   real orire_initf;    /* The scaling factor for initializing the time av. */
82   int  norire_Dtav;    /* The number of matrix element in dtav (npair*5)   */
83   real *orire_Dtav;    /* The time averaged orientation tensors            */
84 } history_t;
85
86 /* Struct used for checkpointing only.
87  * This struct would not be required with unlimited precision.
88  * But because of limited precision, the COM motion removal implementation
89  * can cause the kinetic energy in the MD loop to differ by a few bits from
90  * the kinetic energy one would determine from state.v.
91  */
92 typedef struct
93 {
94   gmx_bool     bUpToDate;
95   int      ekin_n;
96   tensor  *ekinh;
97   tensor  *ekinf;
98   tensor  *ekinh_old;
99   tensor   ekin_total;
100   double  *ekinscalef_nhc;
101   double  *ekinscaleh_nhc;
102   double  *vscale_nhc;
103   real     dekindl;
104   real     mvcos;
105 } ekinstate_t;
106
107 /* energy history for delta_h histograms */
108 typedef struct
109 {
110     int nndh;           /* the number of energy difference lists */
111     int  *ndh;          /* the number in each energy difference list */
112     real **dh;          /* the energy difference lists */
113
114     double start_time;     /* the start time of these energy diff blocks */
115     double start_lambda;   /* lambda at start time */
116
117     gmx_bool start_lambda_set; /* whether the lambda value is set. Here
118                                   For backward-compatibility. */
119 } delta_h_history_t; 
120
121 typedef struct
122 {
123   int nlambda;               /* total number of lambda states - for history*/
124
125   gmx_bool bEquil;           /* reached equilibration */
126   int  *n_at_lam;            /* number of points observed at each lambda */
127   real *wl_histo;            /* histogram for WL flatness determination */
128   real wl_delta;             /* current wang-landau delta */
129
130   real *sum_weights;         /* weights of the states */
131   real *sum_dg;              /* free energies of the states -- not actually used for weighting, but informational */
132   real *sum_minvar;          /* corrections to weights for minimum variance */
133   real *sum_variance;        /* variances of the states */
134
135   real **accum_p;            /* accumulated bennett weights for n+1 */
136   real **accum_m;            /* accumulated bennett weights for n-1 */
137   real **accum_p2;           /* accumulated squared bennett weights for n+1 */
138   real **accum_m2;           /* accumulated squared bennett weights for n-1 */
139
140   real **Tij;                /* transition matrix */
141   real **Tij_empirical;      /* Empirical transition matrix */
142 } df_history_t;
143
144 typedef struct
145 {
146   gmx_large_int_t nsteps;       /* The number of steps in the history            */
147   gmx_large_int_t nsum;         /* The nr. of steps in the ener_ave and ener_sum */
148   double *   ener_ave;     /* Energy term history sum to get fluctuations   */
149   double *   ener_sum;     /* Energy term history sum to get fluctuations   */
150   int        nener;        /* Number of energy terms in two previous arrays */
151   gmx_large_int_t nsteps_sim;   /* The number of steps in ener_sum_sim      */
152   gmx_large_int_t nsum_sim;     /* The number of frames in ener_sum_sim     */
153   double *   ener_sum_sim; /* Energy term history sum of the whole sim      */
154
155   delta_h_history_t *dht;  /* The BAR energy differences */
156 }
157 energyhistory_t;
158
159 typedef struct
160 {
161   int           natoms;
162   int           ngtc;
163   int           nnhpres;
164   int           nhchainlength; /* number of nose-hoover chains               */
165   int           nrng;
166   int           nrngi;
167   int           flags;  /* Flags telling which entries are present      */
168   int           fep_state; /* indicates which of the alchemical states we are in                 */
169   real          *lambda; /* lambda vector                               */
170   matrix        box;    /* box vector coordinates                       */
171   matrix        box_rel; /* Relitaive box vectors to preserve shape     */
172   matrix        boxv;   /* box velocitites for Parrinello-Rahman pcoupl */
173   matrix        pres_prev; /* Pressure of the previous step for pcoupl  */
174   matrix        svir_prev; /* Shake virial for previous step for pcoupl */
175   matrix        fvir_prev; /* Force virial of the previous step for pcoupl  */
176   double        *nosehoover_xi;  /* for Nose-Hoover tcoupl (ngtc)       */
177   double        *nosehoover_vxi; /* for N-H tcoupl (ngtc)               */
178   double        *nhpres_xi;  /* for Nose-Hoover pcoupl for barostat     */
179   double        *nhpres_vxi; /* for Nose-Hoover pcoupl for barostat     */
180   double        *therm_integral; /* for N-H/V-rescale tcoupl (ngtc)     */
181   real          veta; /* trotter based isotropic P-coupling             */
182   real          vol0; /* initial volume,required for computing NPT conserverd quantity */
183   int           nalloc; /* Allocation size for x, v and sd_x when !=NULL*/
184   rvec          *x;     /* the coordinates (natoms)                     */
185   rvec          *v;     /* the velocities (natoms)                      */
186   rvec          *sd_X;  /* random part of the x update for stoch. dyn.  */
187   rvec          *cg_p;  /* p vector for conjugate gradient minimization */
188
189   unsigned int  *ld_rng;  /* RNG random state                           */
190   int           *ld_rngi; /* RNG index                                  */
191
192   int           nmcrng;   /* number of RNG states                       */
193   unsigned int  *mc_rng;  /* lambda MC RNG random state                 */
194   int           *mc_rngi; /* lambda MC RNG index                        */
195
196   history_t     hist;   /* Time history for restraints                  */
197
198   ekinstate_t   ekinstate; /* The state of the kinetic energy data      */
199
200   energyhistory_t  enerhist; /* Energy history for statistics           */
201   df_history_t  dfhist; /*Free energy history for free energy analysis  */
202
203   int           ddp_count; /* The DD partitioning count for this state  */
204   int           ddp_count_cg_gl; /* The DD part. count for index_gl     */
205   int           ncg_gl; /* The number of local charge groups            */
206   int           *cg_gl; /* The global cg number of the local cgs        */
207   int           cg_gl_nalloc; /* Allocation size of cg_gl;              */
208 } t_state;
209
210 typedef struct 
211
212   double *Qinv;  /* inverse mass of thermostat -- computed from inputs, but a good place to store */
213   double *QPinv; /* inverse mass of thermostat for barostat -- computed from inputs, but a good place to store */
214   double Winv;   /* Pressure mass inverse -- computed, not input, but a good place to store. Need to make a matrix later */
215   tensor Winvm;  /* inverse pressure mass tensor, computed       */       
216 } t_extmass;
217
218
219 typedef struct
220
221   real veta;   
222   double rscale;
223   double vscale;
224   double rvscale;
225   double alpha;
226   double *vscale_nhc;
227 } t_vetavars;
228
229 #ifdef __cplusplus
230 }
231 #endif
232
233
234 #endif /* _state_h_ */