Made gmx_rmpbc_t object functions not segfault
[gromacs.git] / include / constr.h
blobbc0419e42803004073a315d75913c51aed322be3
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
37 #include "typedefs.h"
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
43 enum
45 econqCoord, /* Constrain coordinates (mass weighted) */
46 econqVeloc, /* Constrain velocities (mass weighted) */
47 econqDeriv, /* Constrain a derivative (mass weighted), *
48 * for instance velocity or acceleration, *
49 * constraint virial can not be calculated. */
50 econqDeriv_FlexCon, /* As econqDeriv, but only output flex. con. */
51 econqForce, /* Constrain forces (non mass-weighted) */
52 econqForceDispl /* Constrain forces (mass-weighted 1/0 for freeze) */
55 int n_flexible_constraints(struct gmx_constr *constr);
56 /* Returns the total number of flexible constraints in the system */
58 void too_many_constraint_warnings(int eConstrAlg,int warncount);
59 /* Generate a fatal error because of too many LINCS/SETTLE warnings */
61 gmx_shakedata_t shake_init();
62 /* Initializes and return the SHAKE data structure */
64 gmx_bool bshakef(FILE *log, /* Log file */
65 gmx_shakedata_t shaked, /* SHAKE data */
66 int natoms, /* Total number of atoms */
67 real invmass[], /* Atomic masses */
68 int nblocks, /* The number of shake blocks */
69 int sblock[], /* The shake blocks */
70 t_idef *idef, /* The interaction def */
71 t_inputrec *ir, /* Input record */
72 matrix box, /* The box */
73 rvec x_s[], /* Coords before update */
74 rvec prime[], /* Output coords */
75 t_nrnb *nrnb, /* Performance measure */
76 real *lagr, /* The Lagrange multipliers */
77 real lambda, /* FEP lambda */
78 real *dvdlambda, /* FEP force */
79 real invdt, /* 1/delta_t */
80 rvec *v, /* Also constrain v if v!=NULL */
81 gmx_bool bCalcVir, /* Calculate r x m delta_r */
82 tensor rmdr, /* sum r x m delta_r */
83 gmx_bool bDumpOnError, /* Dump debugging stuff on error*/
84 int econq, /* which type of constrainint is occurring */
85 t_vetavars *vetavar); /* veta for pressure control */
86 /* Shake all the atoms blockwise. It is assumed that all the constraints
87 * in the idef->shakes field are sorted, to ascending block nr. The
88 * sblock array points into the idef->shakes.iatoms field, with block 0
89 * starting
90 * at sblock[0] and running to ( < ) sblock[1], block n running from
91 * sblock[n] to sblock[n+1]. Array sblock should be large enough.
92 * Return TRUE when OK, FALSE when shake-error
95 gmx_settledata_t settle_init(real mO,real mH,real invmO,real invmH,
96 real dOH,real dHH);
97 /* Initializes and returns a structure with SETTLE parameters */
99 void csettle(gmx_settledata_t settled,
100 int nsettle, /* Number of settles */
101 t_iatom iatoms[], /* The settle iatom list */
102 real b4[], /* Old coordinates */
103 real after[], /* New coords, to be settled */
104 real invdt, /* 1/delta_t */
105 real *v, /* Also constrain v if v!=NULL */
106 gmx_bool bCalcVir, /* Calculate r x m delta_r */
107 tensor rmdr, /* sum r x m delta_r */
108 int *xerror,
109 t_vetavars *vetavar /* variables for pressure control */
112 void settle_proj(FILE *fp,
113 gmx_settledata_t settled,int econq,
114 int nsettle, t_iatom iatoms[],rvec x[],
115 rvec *der,rvec *derp,
116 gmx_bool bCalcVir,tensor rmdder, t_vetavars *vetavar);
117 /* Analytical algorithm to subtract the components of derivatives
118 * of coordinates working on settle type constraint.
121 void cshake(atom_id iatom[],int ncon,int *nnit,int maxnit,
122 real dist2[],real xp[],real rij[],real m2[],real omega,
123 real invmass[],real tt[],real lagr[],int *nerror);
124 /* Regular iterative shake */
126 void crattle(atom_id iatom[],int ncon,int *nnit,int maxnit,
127 real dist2[],real vp[],real rij[],real m2[],real omega,
128 real invmass[],real tt[],real lagr[],int *nerror,real invdt,t_vetavars *vetavar);
130 gmx_bool constrain(FILE *log,gmx_bool bLog,gmx_bool bEner,
131 gmx_constr_t constr,
132 t_idef *idef,
133 t_inputrec *ir,
134 gmx_ekindata_t *ekind,
135 t_commrec *cr,
136 gmx_large_int_t step,int delta_step,
137 t_mdatoms *md,
138 rvec *x,rvec *xprime,rvec *min_proj,matrix box,
139 real lambda,real *dvdlambda,
140 rvec *v,tensor *vir,
141 t_nrnb *nrnb,int econq, gmx_bool bPscal, real veta, real vetanew);
143 * When econq=econqCoord constrains coordinates xprime using th
144 * directions in x, min_proj is not used.
146 * When econq=econqDeriv, calculates the components xprime in
147 * the constraint directions and subtracts these components from min_proj.
148 * So when min_proj=xprime, the constraint components are projected out.
150 * When econq=econqDeriv_FlexCon, the same is done as with econqDeriv,
151 * but only the components of the flexible constraints are stored.
153 * delta_step is used for determining the constraint reference lengths
154 * when lenA != lenB or will the pull code with a pulling rate.
155 * step + delta_step is the step at which the final configuration
156 * is meant to be; for update delta_step = 1.
158 * If v!=NULL also constrain v by adding the constraint corrections / dt.
160 * If vir!=NULL calculate the constraint virial.
162 * if veta != NULL, constraints are done assuming isotropic pressure control
163 * (i.e. constraining rdot.r = (v + veta*r).r = 0 instead of v
165 * Init_constraints must have be called once, before calling constrain.
167 * Return TRUE if OK, FALSE in case of shake error
171 gmx_constr_t init_constraints(FILE *log,
172 gmx_mtop_t *mtop,t_inputrec *ir,
173 gmx_edsam_t ed,t_state *state,
174 t_commrec *cr);
175 /* Initialize constraints stuff */
177 void set_constraints(gmx_constr_t constr,
178 gmx_localtop_t *top,
179 t_inputrec *ir,
180 t_mdatoms *md,
181 t_commrec *cr);
182 /* Set up all the local constraints for the node */
184 /* The at2con t_blocka struct returned by the routines below
185 * contains a list of constraints per atom.
186 * The F_CONSTRNC constraints in this structure number consecutively
187 * after the F_CONSTR constraints.
190 t_blocka make_at2con(int start,int natoms,
191 t_ilist *ilist,t_iparams *iparams,
192 gmx_bool bDynamics,int *nflexiblecons);
193 /* Returns a block struct to go from atoms to constraints */
195 t_blocka *atom2constraints_moltype(gmx_constr_t constr);
196 /* Returns the an arry of atom to constraints lists for the moltypes */
198 #define constr_iatomptr(nconstr,iatom_constr,iatom_constrnc,con) ((con) < (nconstr) ? (iatom_constr)+(con)*3 : (iatom_constrnc)+(con-nconstr)*3)
199 /* Macro for getting the constraint iatoms for a constraint number con
200 * which comes from a list where F_CONSTR and F_CONSTRNC constraints
201 * are concatenated.
204 gmx_bool inter_charge_group_constraints(gmx_mtop_t *mtop);
205 /* Returns if there are inter charge group constraints */
207 real *constr_rmsd_data(gmx_constr_t constr);
208 /* Return the data for determining constraint RMS relative deviations.
209 * Returns NULL when LINCS is not used.
212 real constr_rmsd(gmx_constr_t constr,gmx_bool bSD2);
213 /* Return the RMSD of the constraint, bSD2 selects the second SD step */
215 real *lincs_rmsd_data(gmx_lincsdata_t lincsd);
216 /* Return the data for determining constraint RMS relative deviations */
218 real lincs_rmsd(gmx_lincsdata_t lincsd,gmx_bool bSD2);
219 /* Return the RMSD of the constraint, bSD2 selects the second SD step */
221 gmx_lincsdata_t init_lincs(FILE *fplog,gmx_mtop_t *mtop,
222 int nflexcon_global,t_blocka *at2con,
223 gmx_bool bPLINCS,int nIter,int nProjOrder);
224 /* Initializes and returns the lincs data struct */
226 void set_lincs(t_idef *idef,t_mdatoms *md,
227 gmx_bool bDynamics,t_commrec *cr,
228 gmx_lincsdata_t li);
229 /* Initialize lincs stuff */
231 void set_lincs_matrix(gmx_lincsdata_t li,real *invmass,real lambda);
232 /* Sets the elements of the LINCS constraint coupling matrix */
234 real constr_r_max(FILE *fplog,gmx_mtop_t *mtop,t_inputrec *ir);
235 /* Returns an estimate of the maximum distance between atoms
236 * required for LINCS.
239 gmx_bool constrain_lincs(FILE *log,gmx_bool bLog,gmx_bool bEner,
240 t_inputrec *ir,
241 gmx_large_int_t step,
242 gmx_lincsdata_t lincsd,t_mdatoms *md,
243 t_commrec *cr,
244 rvec *x,rvec *xprime,rvec *min_proj,matrix box,
245 real lambda,real *dvdlambda,
246 real invdt,rvec *v,
247 gmx_bool bCalcVir,tensor rmdr,
248 int econ,
249 t_nrnb *nrnb,
250 int maxwarn,int *warncount);
251 /* Returns if the constraining succeeded */
253 #ifdef __cplusplus
255 #endif