Merge release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / legacyheaders / types / forcerec.h
1 /*
2  * 
3  *                This source code is part of
4  * 
5  *                 G   R   O   M   A   C   S
6  * 
7  *          GROningen MAchine for Chemical Simulations
8  * 
9  *                        VERSION 3.2.0
10  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12  * Copyright (c) 2001-2004, The GROMACS development team,
13  * check out http://www.gromacs.org for more information.
14
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  * 
20  * If you want to redistribute modifications, please consider that
21  * scientific software is very special. Version control is crucial -
22  * bugs must be traceable. We will be happy to consider code for
23  * inclusion in the official distribution, but derived work must not
24  * be called official GROMACS. Details are found in the README & COPYING
25  * files - if they are missing, get the official version at www.gromacs.org.
26  * 
27  * To help us fund GROMACS development, we humbly ask that you cite
28  * the papers on the package - you can find them in the top README file.
29  * 
30  * For more info, check our website at http://www.gromacs.org
31  * 
32  * And Hey:
33  * GRoups of Organic Molecules in ACtion for Science
34  */
35
36 #include "ns.h"
37 #include "genborn.h"
38 #include "qmmmrec.h"
39 #include "idef.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /* Abstract type for PME that is defined only in the routine that use them. */
46 typedef struct gmx_pme *gmx_pme_t;
47
48 typedef struct {
49   real r;         /* range of the table */
50   int  n;         /* n+1 is the number of points */
51   real scale;     /* distance between two points */
52   real scale_exp; /* distance for exponential Buckingham table */
53   real *tab;      /* the actual tables, per point there are  4 numbers for
54                    * Coulomb, dispersion and repulsion (in total 12 numbers)
55                    */
56 } t_forcetable;
57
58 typedef struct {
59   t_forcetable tab;
60   /* We duplicate tables for cache optimization purposes */
61   real *coultab;      /* Coul only */
62   real *vdwtab;       /* Vdw only   */
63   /* The actual neighbor lists, short and long range, see enum above
64    * for definition of neighborlist indices.
65    */
66   t_nblist nlist_sr[eNL_NR];
67   t_nblist nlist_lr[eNL_NR];
68 } t_nblists;
69
70 /* macros for the cginfo data in forcerec */
71 /* The maximum cg size in cginfo is 255,
72  * because we only have space for 8 bits in cginfo,
73  * this cg size entry is actually only read with domain decomposition.
74  * But there is a smaller limit due to the t_excl data structure
75  * which is defined in nblist.h.
76  */
77 #define SET_CGINFO_GID(cgi,gid)      (cgi) = (((cgi)  &  ~65535)  |  (gid)   )
78 #define GET_CGINFO_GID(cgi)        ( (cgi)            &   65535)
79 #define SET_CGINFO_EXCL_INTRA(cgi)   (cgi) =  ((cgi)  |  (1<<16))
80 #define GET_CGINFO_EXCL_INTRA(cgi) ( (cgi)            &  (1<<16))
81 #define SET_CGINFO_EXCL_INTER(cgi)   (cgi) =  ((cgi)  |  (1<<17))
82 #define GET_CGINFO_EXCL_INTER(cgi) ( (cgi)            &  (1<<17))
83 #define SET_CGINFO_SOLOPT(cgi,opt)   (cgi) = (((cgi)  & ~(15<<18)) | ((opt)<<18))
84 #define GET_CGINFO_SOLOPT(cgi)     (((cgi)>>18)       &   15)
85 /* This bit is only used with bBondComm in the domain decomposition */
86 #define SET_CGINFO_BOND_INTER(cgi)   (cgi) =  ((cgi)  |  (1<<22))
87 #define GET_CGINFO_BOND_INTER(cgi) ( (cgi)            &  (1<<22))
88 #define SET_CGINFO_NATOMS(cgi,opt)   (cgi) = (((cgi)  & ~(255<<23)) | ((opt)<<23))
89 #define GET_CGINFO_NATOMS(cgi)     (((cgi)>>23)       &   255)
90
91
92 /* Value to be used in mdrun for an infinite cut-off.
93  * Since we need to compare with the cut-off squared,
94  * this value should be slighlty smaller than sqrt(GMX_FLOAT_MAX).
95  */
96 #define GMX_CUTOFF_INF 1E+18
97
98
99 enum { egCOULSR, egLJSR, egBHAMSR, egCOULLR, egLJLR, egBHAMLR,
100        egCOUL14, egLJ14, egGB, egNR };
101
102 typedef struct {
103   int  nener;        /* The number of energy group pairs     */
104   real *ener[egNR];  /* Energy terms for each pair of groups */
105 } gmx_grppairener_t;
106
107 typedef struct {
108   real term[F_NRE];    /* The energies for all different interaction types */
109   gmx_grppairener_t grpp;
110   double dvdl_lin;     /* Contributions to dvdl with linear lam-dependence */
111   double dvdl_nonlin;  /* Idem, but non-linear dependence                  */
112   int    n_lambda;
113   double *enerpart_lambda; /* Partial energy for lambda and flambda[] */
114 } gmx_enerdata_t;
115 /* The idea is that dvdl terms with linear lambda dependence will be added
116  * automatically to enerpart_lambda. Terms with non-linear lambda dependence
117  * should explicitly determine the energies at foreign lambda points
118  * when n_lambda > 0.
119  */
120
121 typedef struct {
122   int cg_start;
123   int cg_end;
124   int cg_mod;
125   int *cginfo;
126 } cginfo_mb_t;
127
128
129 /* ewald table type */
130 typedef struct ewald_tab *ewald_tab_t; 
131
132 typedef struct {
133   /* Domain Decomposition */
134   gmx_bool bDomDec;
135
136   /* PBC stuff */
137   int  ePBC;
138   gmx_bool bMolPBC;
139   int  rc_scaling;
140   rvec posres_com;
141   rvec posres_comB;
142
143   gmx_bool UseOptimizedKernels;
144
145   /* Use special N*N kernels? */
146   gmx_bool bAllvsAll;
147   /* Private work data */
148   void *AllvsAll_work;
149   void *AllvsAll_workgb;
150
151   /* Cut-Off stuff.
152    * Infinite cut-off's will be GMX_CUTOFF_INF (unlike in t_inputrec: 0).
153    */
154   real rlist,rlistlong;
155   
156   /* Dielectric constant resp. multiplication factor for charges */
157   real zsquare,temp;
158   real epsilon_r,epsilon_rf,epsfac;  
159   
160   /* Constants for reaction fields */
161   real kappa,k_rf,c_rf;
162
163   /* Charge sum and dipole for topology A/B ([0]/[1]) for Ewald corrections */
164   double qsum[2];
165   rvec   mu_tot[2];
166
167   /* Dispersion correction stuff */
168   int  eDispCorr;
169   /* The shift of the shift or user potentials */
170   real enershiftsix;
171   real enershifttwelve;
172   /* Integrated differces for energy and virial with cut-off functions */
173   real enerdiffsix;
174   real enerdifftwelve;
175   real virdiffsix;
176   real virdifftwelve;
177   /* Constant for long range dispersion correction (average dispersion)
178    * for topology A/B ([0]/[1]) */
179   real avcsix[2];
180   /* Constant for long range repulsion term. Relative difference of about 
181    * 0.1 percent with 0.8 nm cutoffs. But hey, it's cheap anyway...
182    */
183   real avctwelve[2];
184   
185   /* Fudge factors */
186   real fudgeQQ;
187
188   /* Table stuff */
189   gmx_bool bcoultab;
190   gmx_bool bvdwtab;
191   /* The normal tables are in the nblists struct(s) below */
192   t_forcetable tab14; /* for 1-4 interactions only */
193
194   /* PPPM & Shifting stuff */
195   real rcoulomb_switch,rcoulomb;
196   real *phi;
197
198   /* VdW stuff */
199   double reppow;
200   real rvdw_switch,rvdw;
201   real bham_b_max;
202
203   /* Free energy ? */
204   int  efep;
205   real sc_alpha;
206   int  sc_power;
207   real sc_sigma6_def;
208   real sc_sigma6_min;
209   gmx_bool bSepDVDL;
210
211   /* NS Stuff */
212   int  eeltype;
213   int  vdwtype;
214   int  cg0,hcg;
215   /* solvent_opt contains the enum for the most common solvent
216    * in the system, which will be optimized.
217    * It can be set to esolNO to disable all water optimization */
218   int  solvent_opt;
219   int  nWatMol;
220   gmx_bool bGrid;
221   cginfo_mb_t *cginfo_mb;
222   int  *cginfo;
223   rvec *cg_cm;
224   int  cg_nalloc;
225   rvec *shift_vec;
226
227   /* The neighborlists including tables */
228   int  nnblists;
229   int  *gid2nblists;
230   t_nblists *nblists;
231
232   /* The wall tables (if used) */
233   int  nwall;
234   t_forcetable **wall_tab;
235
236   /* This mask array of length nn determines whether or not this bit of the
237    * neighbourlists should be computed. Usually all these are true of course,
238    * but not when shells are used. During minimisation all the forces that 
239    * include shells are done, then after minimsation is converged the remaining
240    * forces are computed.
241    */
242   /* gmx_bool *bMask; */
243
244   /* The number of charge groups participating in do_force_lowlevel */
245   int ncg_force;
246   /* The number of atoms participating in do_force_lowlevel */
247   int natoms_force;
248   /* The number of atoms participating in force and constraints */
249   int natoms_force_constr;
250   /* The allocation size of vectors of size natoms_force */
251   int nalloc_force;
252
253   /* Twin Range stuff, f_twin has size natoms_force */
254   gmx_bool bTwinRange;
255   int  nlr;
256   rvec *f_twin;
257
258   /* Forces that should not enter into the virial summation:
259    * PPPM/PME/Ewald/posres
260    */
261   gmx_bool bF_NoVirSum;
262   int  f_novirsum_n;
263   int  f_novirsum_nalloc;
264   rvec *f_novirsum_alloc;
265   /* Pointer that points to f_novirsum_alloc when pressure is calcaluted,
266    * points to the normal force vectors wen pressure is not requested.
267    */
268   rvec *f_novirsum;
269
270   /* Long-range forces and virial for PPPM/PME/Ewald */
271   gmx_pme_t pmedata;
272   tensor    vir_el_recip;
273
274   /* PME/Ewald stuff */
275   gmx_bool bEwald;
276   real ewaldcoeff;
277   ewald_tab_t ewald_table;
278
279   /* Virial Stuff */
280   rvec *fshift;
281   rvec vir_diag_posres;
282   dvec vir_wall_z;
283
284   /* Non bonded Parameter lists */
285   int  ntype; /* Number of atom types */
286   gmx_bool bBHAM;
287   real *nbfp;
288
289   /* Energy group pair flags */
290   int *egp_flags;
291
292   /* xmdrun flexible constraints */
293   real fc_stepsize;
294
295   /* Generalized born implicit solvent */
296   gmx_bool bGB;
297   /* Generalized born stuff */
298   real gb_epsilon_solvent;
299   /* Table data for GB */
300   t_forcetable gbtab;
301   /* VdW radius for each atomtype (dim is thus ntype) */
302   real *atype_radius;
303   /* Effective radius (derived from effective volume) for each type */
304   real *atype_vol;
305   /* Implicit solvent - surface tension for each atomtype */
306   real *atype_surftens;
307   /* Implicit solvent - radius for GB calculation */
308   real *atype_gb_radius;
309   /* Implicit solvent - overlap for HCT model */
310   real *atype_S_hct;
311   /* Generalized born interaction data */
312   gmx_genborn_t *born;
313
314   /* Table scale for GB */
315   real gbtabscale;
316   /* Table range for GB */
317   real gbtabr;
318   /* GB neighborlists (the sr list will contain for each atom all other atoms                                            
319    * (for use in the SA calculation) and the lr list will contain                                                  
320    * for each atom all atoms 1-4 or greater (for use in the GB calculation)                                        
321    */
322   t_nblist gblist_sr;
323   t_nblist gblist_lr;
324   t_nblist gblist;
325
326   /* Inverse square root of the Born radii for implicit solvent */
327   real *invsqrta;
328   /* Derivatives of the potential with respect to the Born radii */
329   real *dvda;
330   /* Derivatives of the Born radii with respect to coordinates */
331   real *dadx;
332   real *dadx_rawptr;
333   int   nalloc_dadx; /* Allocated size of dadx */
334         
335   /* If > 0 signals Test Particle Insertion,
336    * the value is the number of atoms of the molecule to insert
337    * Only the energy difference due to the addition of the last molecule
338    * should be calculated.
339    */
340   gmx_bool n_tpi;
341
342   /* Neighbor searching stuff */
343   gmx_ns_t ns;
344
345   /* QMMM stuff */
346   gmx_bool         bQMMM;
347   t_QMMMrec    *qr;
348
349   /* QM-MM neighborlists */
350   t_nblist QMMMlist;
351
352   /* Limit for printing large forces, negative is don't print */
353   real print_force;
354
355   /* coarse load balancing time measurement */
356   double t_fnbf;
357   double t_wait;
358   int timesteps;
359
360   /* parameter needed for AdResS simulation */
361   int  adress_type;
362   gmx_bool badress_tf_full_box;
363   real adress_const_wf;
364   real adress_ex_width;
365   real adress_hy_width;
366   int  adress_icor;
367   int  adress_site;
368   rvec adress_refs;
369   int n_adress_tf_grps;
370   int * adress_tf_table_index;
371   int *adress_group_explicit;
372   t_forcetable *  atf_tabs;
373   real adress_ex_forcecap;
374   gmx_bool adress_do_hybridpairs;
375
376   /* User determined parameters, copied from the inputrec */
377   int  userint1;
378   int  userint2;
379   int  userint3;
380   int  userint4;
381   real userreal1;
382   real userreal2;
383   real userreal3;
384   real userreal4;
385 } t_forcerec;
386
387 #define C6(nbfp,ntp,ai,aj)     (nbfp)[2*((ntp)*(ai)+(aj))]
388 #define C12(nbfp,ntp,ai,aj)    (nbfp)[2*((ntp)*(ai)+(aj))+1]
389 #define BHAMC(nbfp,ntp,ai,aj)  (nbfp)[3*((ntp)*(ai)+(aj))]
390 #define BHAMA(nbfp,ntp,ai,aj)  (nbfp)[3*((ntp)*(ai)+(aj))+1]
391 #define BHAMB(nbfp,ntp,ai,aj)  (nbfp)[3*((ntp)*(ai)+(aj))+2]
392
393 #ifdef __cplusplus
394 }
395 #endif
396