Redefine the default boolean type to gmx_bool.
[alexxy/gromacs.git] / include / 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 #include "typedefs.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 enum
44 {
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) */
53 };
54
55 int n_flexible_constraints(struct gmx_constr *constr);
56 /* Returns the total number of flexible constraints in the system */
57
58 void too_many_constraint_warnings(int eConstrAlg,int warncount);
59 /* Generate a fatal error because of too many LINCS/SETTLE warnings */
60
61 gmx_shakedata_t shake_init();
62 /* Initializes and return the SHAKE data structure */
63
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
93  */
94
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 */
98
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 */   
110     );
111
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.
119  */
120
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 */
125
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);
129
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);
142 /*
143  * When econq=econqCoord constrains coordinates xprime using th
144  * directions in x, min_proj is not used.
145  *
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.
149  *
150  * When econq=econqDeriv_FlexCon, the same is done as with econqDeriv,
151  * but only the components of the flexible constraints are stored.
152  *
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.
157  *
158  * If v!=NULL also constrain v by adding the constraint corrections / dt.
159  *
160  * If vir!=NULL calculate the constraint virial.
161  *
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 
164  *
165  * Init_constraints must have be called once, before calling constrain.
166  *
167  * Return TRUE if OK, FALSE in case of shake error
168  *
169  */
170
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 */
176
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 */
183
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.
188  */
189
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 */
194
195 t_blocka *atom2constraints_moltype(gmx_constr_t constr);
196 /* Returns the an arry of atom to constraints lists for the moltypes */
197
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.
202  */
203
204 gmx_bool inter_charge_group_constraints(gmx_mtop_t *mtop);
205 /* Returns if there are inter charge group constraints */
206
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.
210  */
211
212 real constr_rmsd(gmx_constr_t constr,gmx_bool bSD2);
213 /* Return the RMSD of the constraint, bSD2 selects the second SD step */
214
215 real *lincs_rmsd_data(gmx_lincsdata_t lincsd);
216 /* Return the data for determining constraint RMS relative deviations */
217
218 real lincs_rmsd(gmx_lincsdata_t lincsd,gmx_bool bSD2);
219 /* Return the RMSD of the constraint, bSD2 selects the second SD step */
220
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 */
225
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 */
230
231 void set_lincs_matrix(gmx_lincsdata_t li,real *invmass,real lambda);
232 /* Sets the elements of the LINCS constraint coupling matrix */
233
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.
237  */
238
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 */
252
253 #ifdef __cplusplus
254 }
255 #endif