67f15f5d3a01b1ebbc7581f0f611b7c41778ca19
[alexxy/gromacs.git] / include / update.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 _update_h
37 #define _update_h
38 #include "visibility.h"
39 #include "typedefs.h"
40 #include "mshift.h"
41 #include "tgroup.h"
42 #include "network.h"
43 #include "force.h"
44 #include "pull.h"
45 #include "gmx_random.h"
46 #include "maths.h"
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52 /* Abstract type for stochastic dynamics */
53 typedef struct gmx_update *gmx_update_t;
54
55 /* Initialize the stochastic dynamics struct */
56 gmx_update_t init_update(FILE *fplog,t_inputrec *ir);
57
58 /* Store the random state from sd in state */
59 GMX_LIBMD_EXPORT
60 void get_stochd_state(gmx_update_t sd,t_state *state);
61
62 /* Set the random in sd from state */
63 GMX_LIBMD_EXPORT
64 void set_stochd_state(gmx_update_t sd,t_state *state);
65
66 /* Store the box at step step
67  * as a reference state for simulations with box deformation.
68  */
69 GMX_LIBMD_EXPORT
70 void set_deform_reference_box(gmx_update_t upd,
71                                      gmx_large_int_t step,matrix box);
72
73 GMX_LIBMD_EXPORT
74 void update_tcouple(FILE         *fplog,
75                            gmx_large_int_t   step,
76                            t_inputrec   *inputrec,   
77                            t_state      *state,
78                            gmx_ekindata_t *ekind,
79                            gmx_wallcycle_t wcycle,
80                            gmx_update_t upd,
81                            t_extmass    *MassQ,
82                            t_mdatoms    *md
83 );
84
85 GMX_LIBMD_EXPORT
86 void update_pcouple(FILE         *fplog,
87                            gmx_large_int_t   step,
88                            t_inputrec   *inputrec,   
89                            t_state      *state,
90                            matrix       pcoupl_mu,
91                            matrix       M,
92                            gmx_wallcycle_t wcycle,
93                            gmx_update_t upd,
94                            gmx_bool         bInitStep);
95
96 GMX_LIBMD_EXPORT
97 void update_coords(FILE         *fplog,
98                           gmx_large_int_t   step,
99                           t_inputrec   *inputrec,  /* input record and box stuff        */
100                           t_mdatoms    *md,
101                           t_state      *state,
102                           gmx_bool     bMolPBC,
103                           rvec         *f,    /* forces on home particles */
104                           gmx_bool         bDoLR,
105                           rvec         *f_lr,
106                           t_fcdata     *fcd,
107                           gmx_ekindata_t *ekind,
108                           matrix       M,
109                           gmx_wallcycle_t wcycle,
110                           gmx_update_t upd,
111                           gmx_bool         bInitStep,
112                           int          bUpdatePart,
113                           t_commrec    *cr,  /* these shouldn't be here -- need to think about it */
114                           t_nrnb       *nrnb,
115                           gmx_constr_t constr,
116                           t_idef       *idef);
117
118 /* Return TRUE if OK, FALSE in case of Shake Error */
119
120 GMX_LIBMD_EXPORT
121 extern gmx_bool update_randomize_velocities(t_inputrec *ir, gmx_large_int_t step, t_mdatoms *md, t_state *state, gmx_update_t upd, t_idef *idef, gmx_constr_t constr);
122
123 GMX_LIBMD_EXPORT
124 void update_constraints(FILE         *fplog,
125                                gmx_large_int_t   step,
126                                real         *dvdlambda, /* FEP stuff */
127                                t_inputrec   *inputrec,  /* input record and box stuff   */
128                                gmx_ekindata_t *ekind,
129                                t_mdatoms    *md,
130                                t_state      *state,
131                                gmx_bool     bMolPBC,
132                                t_graph      *graph,     
133                                rvec         force[],    /* forces on home particles */
134                                t_idef       *idef,
135                                tensor       vir_part,
136                                tensor       vir,
137                                t_commrec    *cr,
138                                t_nrnb       *nrnb,
139                                gmx_wallcycle_t wcycle,
140                                gmx_update_t upd,
141                                gmx_constr_t constr,
142                                gmx_bool         bInitStep,
143                                gmx_bool         bFirstHalf,
144                                gmx_bool         bCalcVir,
145                                real         vetanew);
146
147 /* Return TRUE if OK, FALSE in case of Shake Error */
148
149 GMX_LIBMD_EXPORT
150 void update_box(FILE         *fplog,
151                        gmx_large_int_t   step,
152                        t_inputrec   *inputrec,  /* input record and box stuff   */
153                        t_mdatoms    *md,
154                        t_state      *state,
155                        t_graph      *graph,
156                        rvec         force[],    /* forces on home particles */
157                        matrix       *scale_tot,
158                        matrix       pcoupl_mu,              
159                        t_nrnb       *nrnb,
160                        gmx_wallcycle_t wcycle,
161                        gmx_update_t upd,
162                        gmx_bool         bInitStep,
163                        gmx_bool         bFirstHalf);
164 /* Return TRUE if OK, FALSE in case of Shake Error */
165
166 void calc_ke_part(t_state *state,t_grpopts *opts,t_mdatoms *md,
167                          gmx_ekindata_t *ekind,t_nrnb *nrnb,gmx_bool bEkinAveVel, gmx_bool bSaveOld);
168 /*
169  * Compute the partial kinetic energy for home particles;
170  * will be accumulated in the calling routine.
171  * The tensor is
172  *
173  * Ekin = SUM(i) 0.5 m[i] v[i] (x) v[i]
174  *    
175  *     use v[i] = v[i] - u[i] when calculating temperature
176  *
177  * u must be accumulated already.
178  *
179  * Now also computes the contribution of the kinetic energy to the
180  * free energy
181  *
182  */
183
184
185 void
186 init_ekinstate(ekinstate_t *ekinstate,const t_inputrec *ir);
187
188 GMX_LIBMD_EXPORT
189 void
190 update_ekinstate(ekinstate_t *ekinstate,gmx_ekindata_t *ekind);
191
192 void
193 restore_ekinstate_from_state(t_commrec *cr,
194                              gmx_ekindata_t *ekind,ekinstate_t *ekinstate);
195
196 void berendsen_tcoupl(t_inputrec *ir,gmx_ekindata_t *ekind,real dt);
197
198 void andersen_tcoupl(t_inputrec *ir,t_mdatoms *md,t_state *state, gmx_rng_t rng, real rate, t_idef *idef, int nblocks, int *sblock,gmx_bool *randatom, int *randatom_list, gmx_bool *randomize, real *boltzfac);
199
200 void nosehoover_tcoupl(t_grpopts *opts,gmx_ekindata_t *ekind,real dt,
201                               double xi[],double vxi[],t_extmass *MassQ);
202
203 GMX_LIBMD_EXPORT
204 t_state *init_bufstate(const t_state *template_state);
205
206 void destroy_bufstate(t_state *state);
207
208 GMX_LIBMD_EXPORT
209 void trotter_update(t_inputrec *ir, gmx_large_int_t step, gmx_ekindata_t *ekind, 
210                            gmx_enerdata_t *enerd, t_state *state, tensor vir, t_mdatoms *md, 
211                            t_extmass *MassQ, int **trotter_seqlist, int trotter_seqno);
212
213 GMX_LIBMD_EXPORT
214 int **init_npt_vars(t_inputrec *ir, t_state *state, t_extmass *Mass, gmx_bool bTrotter); 
215
216 real NPT_energy(t_inputrec *ir, t_state *state, t_extmass *MassQ);
217 /* computes all the pressure/tempertature control energy terms to get a conserved energy */
218
219 void NBaroT_trotter(t_grpopts *opts, real dt,
220                            double xi[],double vxi[],real *veta, t_extmass *MassQ);
221
222 void vrescale_tcoupl(t_inputrec *ir,gmx_ekindata_t *ekind,real dt,
223                             double therm_integral[],
224                             gmx_rng_t rng);
225 /* Compute temperature scaling. For V-rescale it is done in update. */
226
227 real vrescale_energy(t_grpopts *opts,double therm_integral[]);
228 /* Returns the V-rescale contribution to the conserved energy */
229
230 void rescale_velocities(gmx_ekindata_t *ekind,t_mdatoms *mdatoms,
231                                int start,int end,rvec v[]);
232 /* Rescale the velocities with the scaling factor in ekind */
233
234 GMX_LIBMD_EXPORT
235 void update_annealing_target_temp(t_grpopts *opts,real t); 
236 /* Set reference temp for simulated annealing at time t*/
237
238 real calc_temp(real ekin,real nrdf);
239 /* Calculate the temperature */
240
241 real calc_pres(int ePBC,int nwall,matrix box,tensor ekin,tensor vir,
242                tensor pres);
243 /* Calculate the pressure tensor, returns the scalar pressure.
244  * The unit of pressure is bar.
245  */
246
247 void parrinellorahman_pcoupl(FILE *fplog,gmx_large_int_t step,
248                                     t_inputrec *ir,real dt,tensor pres,
249                                     tensor box,tensor box_rel,tensor boxv,
250                                     tensor M,matrix mu,
251                                     gmx_bool bFirstStep);
252   
253 void berendsen_pcoupl(FILE *fplog,gmx_large_int_t step,
254                              t_inputrec *ir,real dt,tensor pres,matrix box,
255                              matrix mu);
256
257
258 void berendsen_pscale(t_inputrec *ir,matrix mu,
259                              matrix box,matrix box_rel,
260                              int start,int nr_atoms,
261                              rvec x[],unsigned short cFREEZE[],
262                              t_nrnb *nrnb);
263
264 void correct_ekin(FILE *log,int start,int end,rvec v[],
265                          rvec vcm,real mass[],real tmass,tensor ekin);
266 /* Correct ekin for vcm */
267
268
269 #ifdef __cplusplus
270 }
271 #endif
272
273 #endif  /* _update_h */
274