Merge branch 'master' of git.gromacs.org:gromacs
[gromacs/rigid-bodies.git] / include / constr.h
blobad13212db39cc2972c0d9c5782bf26a41833b779
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
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.
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.
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.
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.
31 * For more info, check our website at http://www.gromacs.org
33 * And Hey:
34 * Gromacs Runs On Most of All Computer Systems
36 #ifdef HAVE_CONFIG_H
37 #include<config.h>
38 #endif
40 #include "typedefs.h"
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
46 enum
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) */
58 extern int n_flexible_constraints(struct gmx_constr *constr);
59 /* Returns the total number of flexible constraints in the system */
61 extern void too_many_constraint_warnings(int eConstrAlg,int warncount);
62 /* Generate a fatal error because of too many LINCS/SETTLE warnings */
64 extern gmx_shakedata_t shake_init();
65 /* Initializes and return the SHAKE data structure */
67 extern 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 matrix box, /* The box */
76 rvec x_s[], /* Coords before update */
77 rvec prime[], /* Output coords */
78 t_nrnb *nrnb, /* Performance measure */
79 real *lagr, /* The Lagrange multipliers */
80 real lambda, /* FEP lambda */
81 real *dvdlambda, /* FEP force */
82 real invdt, /* 1/delta_t */
83 rvec *v, /* Also constrain v if v!=NULL */
84 bool bCalcVir, /* Calculate r x m delta_r */
85 tensor rmdr, /* sum r x m delta_r */
86 bool bDumpOnError, /* Dump debugging stuff on error*/
87 int econq, /* which type of constrainint is occurring */
88 t_vetavars *vetavar); /* veta for pressure control */
89 /* Shake all the atoms blockwise. It is assumed that all the constraints
90 * in the idef->shakes field are sorted, to ascending block nr. The
91 * sblock array points into the idef->shakes.iatoms field, with block 0
92 * starting
93 * at sblock[0] and running to ( < ) sblock[1], block n running from
94 * sblock[n] to sblock[n+1]. Array sblock should be large enough.
95 * Return TRUE when OK, FALSE when shake-error
98 extern gmx_settledata_t settle_init(real mO,real mH,real invmO,real invmH,
99 real dOH,real dHH);
100 /* Initializes and returns a structure with SETTLE parameters */
102 extern void csettle(gmx_settledata_t settled,
103 int nsettle, /* Number of settles */
104 t_iatom iatoms[], /* The settle iatom list */
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 bool bCalcVir, /* Calculate r x m delta_r */
110 tensor rmdr, /* sum r x m delta_r */
111 int *xerror,
112 t_vetavars *vetavar /* variables for pressure control */
115 extern void settle_proj(FILE *fp,
116 gmx_settledata_t settled,int econq,
117 int nsettle, t_iatom iatoms[],rvec x[],
118 rvec *der,rvec *derp,
119 bool bCalcVir,tensor rmdder, t_vetavars *vetavar);
120 /* Analytical algorithm to subtract the components of derivatives
121 * of coordinates working on settle type constraint.
124 extern void cshake(atom_id iatom[],int ncon,int *nnit,int maxnit,
125 real dist2[],real xp[],real rij[],real m2[],real omega,
126 real invmass[],real tt[],real lagr[],int *nerror);
127 /* Regular iterative shake */
129 extern void crattle(atom_id iatom[],int ncon,int *nnit,int maxnit,
130 real dist2[],real vp[],real rij[],real m2[],real omega,
131 real invmass[],real tt[],real lagr[],int *nerror,real invdt,t_vetavars *vetavar);
133 extern bool constrain(FILE *log,bool bLog,bool bEner,
134 gmx_constr_t constr,
135 t_idef *idef,
136 t_inputrec *ir,
137 gmx_ekindata_t *ekind,
138 t_commrec *cr,
139 gmx_large_int_t step,int delta_step,
140 t_mdatoms *md,
141 rvec *x,rvec *xprime,rvec *min_proj,matrix box,
142 real lambda,real *dvdlambda,
143 rvec *v,tensor *vir,
144 t_nrnb *nrnb,int econq, bool bPscal, real veta, real vetanew);
146 * When econq=econqCoord constrains coordinates xprime using th
147 * directions in x, min_proj is not used.
149 * When econq=econqDeriv, calculates the components xprime in
150 * the constraint directions and subtracts these components from min_proj.
151 * So when min_proj=xprime, the constraint components are projected out.
153 * When econq=econqDeriv_FlexCon, the same is done as with econqDeriv,
154 * but only the components of the flexible constraints are stored.
156 * delta_step is used for determining the constraint reference lengths
157 * when lenA != lenB or will the pull code with a pulling rate.
158 * step + delta_step is the step at which the final configuration
159 * is meant to be; for update delta_step = 1.
161 * If v!=NULL also constrain v by adding the constraint corrections / dt.
163 * If vir!=NULL calculate the constraint virial.
165 * if veta != NULL, constraints are done assuming isotropic pressure control
166 * (i.e. constraining rdot.r = (v + veta*r).r = 0 instead of v
168 * Init_constraints must have be called once, before calling constrain.
170 * Return TRUE if OK, FALSE in case of shake error
174 extern gmx_constr_t init_constraints(FILE *log,
175 gmx_mtop_t *mtop,t_inputrec *ir,
176 gmx_edsam_t ed,t_state *state,
177 t_commrec *cr);
178 /* Initialize constraints stuff */
180 extern void set_constraints(gmx_constr_t constr,
181 gmx_localtop_t *top,
182 t_inputrec *ir,
183 t_mdatoms *md,
184 t_commrec *cr);
185 /* Set up all the local constraints for the node */
187 /* The at2con t_blocka struct returned by the routines below
188 * contains a list of constraints per atom.
189 * The F_CONSTRNC constraints in this structure number consecutively
190 * after the F_CONSTR constraints.
193 extern t_blocka make_at2con(int start,int natoms,
194 t_ilist *ilist,t_iparams *iparams,
195 bool bDynamics,int *nflexiblecons);
196 /* Returns a block struct to go from atoms to constraints */
198 extern t_blocka *atom2constraints_moltype(gmx_constr_t constr);
199 /* Returns the an arry of atom to constraints lists for the moltypes */
201 #define constr_iatomptr(nconstr,iatom_constr,iatom_constrnc,con) ((con) < (nconstr) ? (iatom_constr)+(con)*3 : (iatom_constrnc)+(con-nconstr)*3)
202 /* Macro for getting the constraint iatoms for a constraint number con
203 * which comes from a list where F_CONSTR and F_CONSTRNC constraints
204 * are concatenated.
207 extern bool inter_charge_group_constraints(gmx_mtop_t *mtop);
208 /* Returns if there are inter charge group constraints */
210 extern real *constr_rmsd_data(gmx_constr_t constr);
211 /* Return the data for determining constraint RMS relative deviations.
212 * Returns NULL when LINCS is not used.
215 extern real constr_rmsd(gmx_constr_t constr,bool bSD2);
216 /* Return the RMSD of the constraint, bSD2 selects the second SD step */
218 extern real *lincs_rmsd_data(gmx_lincsdata_t lincsd);
219 /* Return the data for determining constraint RMS relative deviations */
221 extern real lincs_rmsd(gmx_lincsdata_t lincsd,bool bSD2);
222 /* Return the RMSD of the constraint, bSD2 selects the second SD step */
224 gmx_lincsdata_t init_lincs(FILE *fplog,gmx_mtop_t *mtop,
225 int nflexcon_global,t_blocka *at2con,
226 bool bPLINCS,int nIter,int nProjOrder);
227 /* Initializes and returns the lincs data struct */
229 extern void set_lincs(t_idef *idef,t_mdatoms *md,
230 bool bDynamics,t_commrec *cr,
231 gmx_lincsdata_t li);
232 /* Initialize lincs stuff */
234 extern void set_lincs_matrix(gmx_lincsdata_t li,real *invmass,real lambda);
235 /* Sets the elements of the LINCS constraint coupling matrix */
237 extern real constr_r_max(FILE *fplog,gmx_mtop_t *mtop,t_inputrec *ir);
238 /* Returns an estimate of the maximum distance between atoms
239 * required for LINCS.
242 extern bool constrain_lincs(FILE *log,bool bLog,bool bEner,
243 t_inputrec *ir,
244 gmx_large_int_t step,
245 gmx_lincsdata_t lincsd,t_mdatoms *md,
246 t_commrec *cr,
247 rvec *x,rvec *xprime,rvec *min_proj,matrix box,
248 real lambda,real *dvdlambda,
249 real invdt,rvec *v,
250 bool bCalcVir,tensor rmdr,
251 int econ,
252 t_nrnb *nrnb,
253 int maxwarn,int *warncount);
254 /* Returns if the constraining succeeded */
256 #ifdef __cplusplus
258 #endif