Merge release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / legacyheaders / constr.h
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
2  *
3  *
4  *                This source code is part of
5  *
6  *                 G   R   O   M   A   C   S
7  *
8  *          GROningen MAchine for Chemical Simulations
9  *
10  *                        VERSION 3.2.0
11  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13  * Copyright (c) 2001-2004, The GROMACS development team,
14  * check out http://www.gromacs.org for more information.
15
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  *
21  * If you want to redistribute modifications, please consider that
22  * scientific software is very special. Version control is crucial -
23  * bugs must be traceable. We will be happy to consider code for
24  * inclusion in the official distribution, but derived work must not
25  * be called official GROMACS. Details are found in the README & COPYING
26  * files - if they are missing, get the official version at www.gromacs.org.
27  *
28  * To help us fund GROMACS development, we humbly ask that you cite
29  * the papers on the package - you can find them in the top README file.
30  *
31  * For more info, check our website at http://www.gromacs.org
32  *
33  * And Hey:
34  * Gromacs Runs On Most of All Computer Systems
35  */
36
37 #ifndef _constr_h
38 #define _constr_h
39 #include "typedefs.h"
40 #include "types/commrec.h"
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 enum
47 {
48     econqCoord,         /* Constrain coordinates (mass weighted)           */
49     econqVeloc,         /* Constrain velocities (mass weighted)            */
50     econqDeriv,         /* Constrain a derivative (mass weighted),         *
51                          * for instance velocity or acceleration,          *
52                          * constraint virial can not be calculated.        */
53     econqDeriv_FlexCon, /* As econqDeriv, but only output flex. con.       */
54     econqForce,         /* Constrain forces (non mass-weighted)            */
55     econqForceDispl     /* Constrain forces (mass-weighted 1/0 for freeze) */
56 };
57
58 int n_flexible_constraints(struct gmx_constr *constr);
59 /* Returns the total number of flexible constraints in the system */
60
61 void too_many_constraint_warnings(int eConstrAlg, int warncount);
62 /* Generate a fatal error because of too many LINCS/SETTLE warnings */
63
64 gmx_shakedata_t shake_init();
65 /* Initializes and return the SHAKE data structure */
66
67 gmx_bool bshakef(FILE           *log,          /* Log file                      */
68                  gmx_shakedata_t shaked,       /* SHAKE data */
69                  int             natoms,       /* Total number of atoms */
70                  real            invmass[],    /* Atomic masses         */
71                  int             nblocks,      /* The number of shake blocks    */
72                  int             sblock[],     /* The shake blocks             */
73                  t_idef         *idef,         /* The interaction def           */
74                  t_inputrec     *ir,           /* Input record                  */
75                  rvec            x_s[],        /* Coords before update          */
76                  rvec            prime[],      /* Output coords         */
77                  t_nrnb         *nrnb,         /* Performance measure          */
78                  real           *lagr,         /* The Lagrange multipliers     */
79                  real            lambda,       /* FEP lambda                   */
80                  real           *dvdlambda,    /* FEP force                    */
81                  real            invdt,        /* 1/delta_t                    */
82                  rvec           *v,            /* Also constrain v if v!=NULL  */
83                  gmx_bool        bCalcVir,     /* Calculate r x m delta_r      */
84                  tensor          vir_r_m_dr,   /* sum r x m delta_r            */
85                  gmx_bool        bDumpOnError, /* Dump debugging stuff on error*/
86                  int             econq,        /* which type of constrainint is occurring */
87                  t_vetavars     *vetavar);     /* veta for pressure control */
88 /* Shake all the atoms blockwise. It is assumed that all the constraints
89  * in the idef->shakes field are sorted, to ascending block nr. The
90  * sblock array points into the idef->shakes.iatoms field, with block 0
91  * starting
92  * at sblock[0] and running to ( < ) sblock[1], block n running from
93  * sblock[n] to sblock[n+1]. Array sblock should be large enough.
94  * Return TRUE when OK, FALSE when shake-error
95  */
96
97 gmx_settledata_t settle_init(real mO, real mH, real invmO, real invmH,
98                              real dOH, real dHH);
99 /* Initializes and returns a structure with SETTLE parameters */
100
101 void csettle(gmx_settledata_t settled,
102              int              nsettle,          /* Number of settles            */
103              t_iatom          iatoms[],         /* The settle iatom list        */
104              const t_pbc     *pbc,              /* PBC data pointer, can be NULL  */
105              real             b4[],             /* Old coordinates              */
106              real             after[],          /* New coords, to be settled    */
107              real             invdt,            /* 1/delta_t                    */
108              real            *v,                /* Also constrain v if v!=NULL  */
109              int              calcvir_atom_end, /* Calculate r x m delta_r up to this atom */
110              tensor           vir_r_m_dr,       /* sum r x m delta_r            */
111              int             *xerror,
112              t_vetavars      *vetavar           /* variables for pressure control */
113              );
114
115 void settle_proj(FILE *fp,
116                  gmx_settledata_t settled, int econq,
117                  int nsettle, t_iatom iatoms[],
118                  const t_pbc *pbc,   /* PBC data pointer, can be NULL  */
119                  rvec x[],
120                  rvec *der, rvec *derp,
121                  int CalcVirAtomEnd, tensor vir_r_m_dder,
122                  t_vetavars *vetavar);
123 /* Analytical algorithm to subtract the components of derivatives
124  * of coordinates working on settle type constraint.
125  */
126
127 void cshake(atom_id iatom[], int ncon, int *nnit, int maxnit,
128             real dist2[], real xp[], real rij[], real m2[], real omega,
129             real invmass[], real tt[], real lagr[], int *nerror);
130 /* Regular iterative shake */
131
132 void crattle(atom_id iatom[], int ncon, int *nnit, int maxnit,
133              real dist2[], real vp[], real rij[], real m2[], real omega,
134              real invmass[], real tt[], real lagr[], int *nerror, real invdt, t_vetavars *vetavar);
135
136 gmx_bool constrain(FILE *log, gmx_bool bLog, gmx_bool bEner,
137                    gmx_constr_t constr,
138                    t_idef *idef,
139                    t_inputrec *ir,
140                    gmx_ekindata_t *ekind,
141                    t_commrec *cr,
142                    gmx_large_int_t step, int delta_step,
143                    t_mdatoms *md,
144                    rvec *x, rvec *xprime, rvec *min_proj,
145                    gmx_bool bMolPBC, matrix box,
146                    real lambda, real *dvdlambda,
147                    rvec *v, tensor *vir,
148                    t_nrnb *nrnb, int econq, gmx_bool bPscal, real veta, real vetanew);
149 /*
150  * When econq=econqCoord constrains coordinates xprime using th
151  * directions in x, min_proj is not used.
152  *
153  * When econq=econqDeriv, calculates the components xprime in
154  * the constraint directions and subtracts these components from min_proj.
155  * So when min_proj=xprime, the constraint components are projected out.
156  *
157  * When econq=econqDeriv_FlexCon, the same is done as with econqDeriv,
158  * but only the components of the flexible constraints are stored.
159  *
160  * When bMolPBC=TRUE, assume that molecules might be broken: correct PBC.
161  *
162  * delta_step is used for determining the constraint reference lengths
163  * when lenA != lenB or will the pull code with a pulling rate.
164  * step + delta_step is the step at which the final configuration
165  * is meant to be; for update delta_step = 1.
166  *
167  * If v!=NULL also constrain v by adding the constraint corrections / dt.
168  *
169  * If vir!=NULL calculate the constraint virial.
170  *
171  * if veta != NULL, constraints are done assuming isotropic pressure control
172  * (i.e. constraining rdot.r = (v + veta*r).r = 0 instead of v
173  *
174  * Init_constraints must have be called once, before calling constrain.
175  *
176  * Return TRUE if OK, FALSE in case of shake error
177  *
178  */
179
180 gmx_constr_t init_constraints(FILE *log,
181                               gmx_mtop_t *mtop, t_inputrec *ir,
182                               gmx_edsam_t ed, t_state *state,
183                               t_commrec *cr);
184 /* Initialize constraints stuff */
185
186 void set_constraints(gmx_constr_t    constr,
187                      gmx_localtop_t *top,
188                      t_inputrec     *ir,
189                      t_mdatoms      *md,
190                      t_commrec      *cr);
191 /* Set up all the local constraints for the node */
192
193 /* The at2con t_blocka struct returned by the routines below
194  * contains a list of constraints per atom.
195  * The F_CONSTRNC constraints in this structure number consecutively
196  * after the F_CONSTR constraints.
197  */
198
199 t_blocka make_at2con(int start, int natoms,
200                      t_ilist *ilist, t_iparams *iparams,
201                      gmx_bool bDynamics, int *nflexiblecons);
202 /* Returns a block struct to go from atoms to constraints */
203
204 const t_blocka *atom2constraints_moltype(gmx_constr_t constr);
205 /* Returns the an array of atom to constraints lists for the moltypes */
206
207 const int **atom2settle_moltype(gmx_constr_t constr);
208 /* Returns the an array of atom to settle for the moltypes */
209
210 #define constr_iatomptr(nconstr, iatom_constr, iatom_constrnc, con) ((con) < (nconstr) ? (iatom_constr)+(con)*3 : (iatom_constrnc)+(con-nconstr)*3)
211 /* Macro for getting the constraint iatoms for a constraint number con
212  * which comes from a list where F_CONSTR and F_CONSTRNC constraints
213  * are concatenated.
214  */
215
216 gmx_bool inter_charge_group_constraints(const gmx_mtop_t *mtop);
217 /* Returns if there are inter charge group constraints */
218
219 gmx_bool inter_charge_group_settles(const gmx_mtop_t *mtop);
220 /* Returns if there are inter charge group settles */
221
222 real *constr_rmsd_data(gmx_constr_t constr);
223 /* Return the data for determining constraint RMS relative deviations.
224  * Returns NULL when LINCS is not used.
225  */
226
227 real constr_rmsd(gmx_constr_t constr, gmx_bool bSD2);
228 /* Return the RMSD of the constraint, bSD2 selects the second SD step */
229
230 real *lincs_rmsd_data(gmx_lincsdata_t lincsd);
231 /* Return the data for determining constraint RMS relative deviations */
232
233 real lincs_rmsd(gmx_lincsdata_t lincsd, gmx_bool bSD2);
234 /* Return the RMSD of the constraint, bSD2 selects the second SD step */
235
236 gmx_lincsdata_t init_lincs(FILE *fplog, gmx_mtop_t *mtop,
237                            int nflexcon_global, t_blocka *at2con,
238                            gmx_bool bPLINCS, int nIter, int nProjOrder);
239 /* Initializes and returns the lincs data struct */
240
241 void set_lincs(t_idef *idef, t_mdatoms *md,
242                gmx_bool bDynamics, t_commrec *cr,
243                gmx_lincsdata_t li);
244 /* Initialize lincs stuff */
245
246 void set_lincs_matrix(gmx_lincsdata_t li, real *invmass, real lambda);
247 /* Sets the elements of the LINCS constraint coupling matrix */
248
249 real constr_r_max(FILE *fplog, gmx_mtop_t *mtop, t_inputrec *ir);
250 /* Returns an estimate of the maximum distance between atoms
251  * required for LINCS.
252  */
253
254 gmx_bool
255 constrain_lincs(FILE *log, gmx_bool bLog, gmx_bool bEner,
256                 t_inputrec *ir,
257                 gmx_large_int_t step,
258                 gmx_lincsdata_t lincsd, t_mdatoms *md,
259                 t_commrec *cr,
260                 rvec *x, rvec *xprime, rvec *min_proj,
261                 matrix box, t_pbc *pbc,
262                 real lambda, real *dvdlambda,
263                 real invdt, rvec *v,
264                 gmx_bool bCalcVir, tensor vir_r_m_dr,
265                 int econ,
266                 t_nrnb *nrnb,
267                 int maxwarn, int *warncount);
268 /* Returns if the constraining succeeded */
269
270
271 /* helper functions for andersen temperature control, because the
272  * gmx_constr construct is only defined in constr.c. Return the list
273  * of blocks (get_sblock) and the number of blocks (get_nblocks).  */
274
275 int *get_sblock(struct gmx_constr *constr);
276
277 int get_nblocks(struct gmx_constr *constr);
278
279 #ifdef __cplusplus
280 }
281 #endif
282 #endif