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