Merge release-4-6 into release-5-0
[alexxy/gromacs.git] / src / gromacs / legacyheaders / constr.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 _constr_h
39 #define _constr_h
40 #include "typedefs.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,       /* Total number of atoms */
69                  real            invmass[],    /* Atomic masses         */
70                  int             nblocks,      /* The number of shake blocks    */
71                  int             sblock[],     /* The shake blocks             */
72                  t_idef         *idef,         /* The interaction def           */
73                  t_inputrec     *ir,           /* Input record                  */
74                  rvec            x_s[],        /* Coords before update          */
75                  rvec            prime[],      /* Output coords         */
76                  t_nrnb         *nrnb,         /* Performance measure          */
77                  real           *lagr,         /* The Lagrange multipliers     */
78                  real            lambda,       /* FEP lambda                   */
79                  real           *dvdlambda,    /* FEP force                    */
80                  real            invdt,        /* 1/delta_t                    */
81                  rvec           *v,            /* Also constrain v if v!=NULL  */
82                  gmx_bool        bCalcVir,     /* Calculate r x m delta_r      */
83                  tensor          vir_r_m_dr,   /* sum r x m delta_r            */
84                  gmx_bool        bDumpOnError, /* Dump debugging stuff on error*/
85                  int             econq,        /* which type of constrainint is occurring */
86                  t_vetavars     *vetavar);     /* veta for pressure control */
87 /* Shake all the atoms blockwise. It is assumed that all the constraints
88  * in the idef->shakes field are sorted, to ascending block nr. The
89  * sblock array points into the idef->shakes.iatoms field, with block 0
90  * starting
91  * at sblock[0] and running to ( < ) sblock[1], block n running from
92  * sblock[n] to sblock[n+1]. Array sblock should be large enough.
93  * Return TRUE when OK, FALSE when shake-error
94  */
95
96 gmx_settledata_t settle_init(real mO, real mH, real invmO, real invmH,
97                              real dOH, real dHH);
98 /* Initializes and returns a structure with SETTLE parameters */
99
100 void csettle(gmx_settledata_t settled,
101              int              nsettle,          /* Number of settles            */
102              t_iatom          iatoms[],         /* The settle iatom list        */
103              const t_pbc     *pbc,              /* PBC data pointer, can be NULL  */
104              real             b4[],             /* Old coordinates              */
105              real             after[],          /* New coords, to be settled    */
106              real             invdt,            /* 1/delta_t                    */
107              real            *v,                /* Also constrain v if v!=NULL  */
108              int              calcvir_atom_end, /* Calculate r x m delta_r up to this atom */
109              tensor           vir_r_m_dr,       /* sum r x m delta_r            */
110              int             *xerror,
111              t_vetavars      *vetavar           /* variables for pressure control */
112              );
113
114 void settle_proj(gmx_settledata_t settled, int econq,
115                  int nsettle, t_iatom iatoms[],
116                  const t_pbc *pbc,   /* PBC data pointer, can be NULL  */
117                  rvec x[],
118                  rvec *der, rvec *derp,
119                  int CalcVirAtomEnd, tensor vir_r_m_dder,
120                  t_vetavars *vetavar);
121 /* Analytical algorithm to subtract the components of derivatives
122  * of coordinates working on settle type constraint.
123  */
124
125 void cshake(atom_id iatom[], int ncon, int *nnit, int maxnit,
126             real dist2[], real xp[], real rij[], real m2[], real omega,
127             real invmass[], real tt[], real lagr[], int *nerror);
128 /* Regular iterative shake */
129
130 void crattle(atom_id iatom[], int ncon, int *nnit, int maxnit,
131              real dist2[], real vp[], real rij[], real m2[], real omega,
132              real invmass[], real tt[], real lagr[], int *nerror, real invdt, t_vetavars *vetavar);
133
134 gmx_bool constrain(FILE *log, gmx_bool bLog, gmx_bool bEner,
135                    gmx_constr_t constr,
136                    t_idef *idef,
137                    t_inputrec *ir,
138                    gmx_ekindata_t *ekind,
139                    t_commrec *cr,
140                    gmx_int64_t step, int delta_step,
141                    t_mdatoms *md,
142                    rvec *x, rvec *xprime, rvec *min_proj,
143                    gmx_bool bMolPBC, matrix box,
144                    real lambda, real *dvdlambda,
145                    rvec *v, tensor *vir,
146                    t_nrnb *nrnb, int econq, gmx_bool bPscal, real veta, real vetanew);
147 /*
148  * When econq=econqCoord constrains coordinates xprime using th
149  * directions in x, min_proj is not used.
150  *
151  * When econq=econqDeriv, calculates the components xprime in
152  * the constraint directions and subtracts these components from min_proj.
153  * So when min_proj=xprime, the constraint components are projected out.
154  *
155  * When econq=econqDeriv_FlexCon, the same is done as with econqDeriv,
156  * but only the components of the flexible constraints are stored.
157  *
158  * When bMolPBC=TRUE, assume that molecules might be broken: correct PBC.
159  *
160  * delta_step is used for determining the constraint reference lengths
161  * when lenA != lenB or will the pull code with a pulling rate.
162  * step + delta_step is the step at which the final configuration
163  * is meant to be; for update delta_step = 1.
164  *
165  * If v!=NULL also constrain v by adding the constraint corrections / dt.
166  *
167  * If vir!=NULL calculate the constraint virial.
168  *
169  * if veta != NULL, constraints are done assuming isotropic pressure control
170  * (i.e. constraining rdot.r = (v + veta*r).r = 0 instead of v
171  *
172  * Init_constraints must have be called once, before calling constrain.
173  *
174  * Return TRUE if OK, FALSE in case of shake error
175  *
176  */
177
178 gmx_constr_t init_constraints(FILE *log,
179                               gmx_mtop_t *mtop, t_inputrec *ir,
180                               gmx_edsam_t ed, t_state *state,
181                               t_commrec *cr);
182 /* Initialize constraints stuff */
183
184 void set_constraints(gmx_constr_t    constr,
185                      gmx_localtop_t *top,
186                      t_inputrec     *ir,
187                      t_mdatoms      *md,
188                      t_commrec      *cr);
189 /* Set up all the local constraints for the node */
190
191 /* The at2con t_blocka struct returned by the routines below
192  * contains a list of constraints per atom.
193  * The F_CONSTRNC constraints in this structure number consecutively
194  * after the F_CONSTR constraints.
195  */
196
197 t_blocka make_at2con(int start, int natoms,
198                      t_ilist *ilist, t_iparams *iparams,
199                      gmx_bool bDynamics, int *nflexiblecons);
200 /* Returns a block struct to go from atoms to constraints */
201
202 const t_blocka *atom2constraints_moltype(gmx_constr_t constr);
203 /* Returns the an array of atom to constraints lists for the moltypes */
204
205 const int **atom2settle_moltype(gmx_constr_t constr);
206 /* Returns the an array of atom to settle for the moltypes */
207
208 #define constr_iatomptr(nconstr, iatom_constr, iatom_constrnc, con) ((con) < (nconstr) ? (iatom_constr)+(con)*3 : (iatom_constrnc)+(con-nconstr)*3)
209 /* Macro for getting the constraint iatoms for a constraint number con
210  * which comes from a list where F_CONSTR and F_CONSTRNC constraints
211  * are concatenated.
212  */
213
214 gmx_bool inter_charge_group_constraints(const gmx_mtop_t *mtop);
215 /* Returns if there are inter charge group constraints */
216
217 gmx_bool inter_charge_group_settles(const gmx_mtop_t *mtop);
218 /* Returns if there are inter charge group settles */
219
220 real *constr_rmsd_data(gmx_constr_t constr);
221 /* Return the data for determining constraint RMS relative deviations.
222  * Returns NULL when LINCS is not used.
223  */
224
225 real constr_rmsd(gmx_constr_t constr, gmx_bool bSD2);
226 /* Return the RMSD of the constraint, bSD2 selects the second SD step */
227
228 real *lincs_rmsd_data(gmx_lincsdata_t lincsd);
229 /* Return the data for determining constraint RMS relative deviations */
230
231 real lincs_rmsd(gmx_lincsdata_t lincsd, gmx_bool bSD2);
232 /* Return the RMSD of the constraint, bSD2 selects the second SD step */
233
234 gmx_lincsdata_t init_lincs(FILE *fplog, gmx_mtop_t *mtop,
235                            int nflexcon_global, t_blocka *at2con,
236                            gmx_bool bPLINCS, int nIter, int nProjOrder);
237 /* Initializes and returns the lincs data struct */
238
239 void set_lincs(t_idef *idef, t_mdatoms *md,
240                gmx_bool bDynamics, t_commrec *cr,
241                gmx_lincsdata_t li);
242 /* Initialize lincs stuff */
243
244 void set_lincs_matrix(gmx_lincsdata_t li, real *invmass, real lambda);
245 /* Sets the elements of the LINCS constraint coupling matrix */
246
247 real constr_r_max(FILE *fplog, gmx_mtop_t *mtop, t_inputrec *ir);
248 /* Returns an estimate of the maximum distance between atoms
249  * required for LINCS.
250  */
251
252 gmx_bool
253 constrain_lincs(FILE *log, gmx_bool bLog, gmx_bool bEner,
254                 t_inputrec *ir,
255                 gmx_int64_t step,
256                 gmx_lincsdata_t lincsd, t_mdatoms *md,
257                 t_commrec *cr,
258                 rvec *x, rvec *xprime, rvec *min_proj,
259                 matrix box, t_pbc *pbc,
260                 real lambda, real *dvdlambda,
261                 real invdt, rvec *v,
262                 gmx_bool bCalcVir, tensor vir_r_m_dr,
263                 int econ,
264                 t_nrnb *nrnb,
265                 int maxwarn, int *warncount);
266 /* Returns if the constraining succeeded */
267
268
269 /* helper functions for andersen temperature control, because the
270  * gmx_constr construct is only defined in constr.c. Return the list
271  * of blocks (get_sblock) and the number of blocks (get_nblocks).  */
272
273 int *get_sblock(struct gmx_constr *constr);
274
275 int get_nblocks(struct gmx_constr *constr);
276
277 #ifdef __cplusplus
278 }
279 #endif
280 #endif