Added option to gmx nmeig to print ZPE.
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecRFCut_VdwBhamSw_GeomP1P1_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014.2015,2017, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
46
47 /*
48  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwBhamSw_GeomP1P1_VF_c
49  * Electrostatics interaction: ReactionField
50  * VdW interaction:            Buckingham
51  * Geometry:                   Particle-Particle
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecRFCut_VdwBhamSw_GeomP1P1_VF_c
56                     (t_nblist                    * gmx_restrict       nlist,
57                      rvec                        * gmx_restrict          xx,
58                      rvec                        * gmx_restrict          ff,
59                      struct t_forcerec           * gmx_restrict          fr,
60                      t_mdatoms                   * gmx_restrict     mdatoms,
61                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
62                      t_nrnb                      * gmx_restrict        nrnb)
63 {
64     int              i_shift_offset,i_coord_offset,j_coord_offset;
65     int              j_index_start,j_index_end;
66     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
67     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
68     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
69     real             *shiftvec,*fshift,*x,*f;
70     int              vdwioffset0;
71     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
72     int              vdwjidx0;
73     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
74     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
75     real             velec,felec,velecsum,facel,crf,krf,krf2;
76     real             *charge;
77     int              nvdwtype;
78     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
79     int              *vdwtype;
80     real             *vdwparam;
81     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
82
83     x                = xx[0];
84     f                = ff[0];
85
86     nri              = nlist->nri;
87     iinr             = nlist->iinr;
88     jindex           = nlist->jindex;
89     jjnr             = nlist->jjnr;
90     shiftidx         = nlist->shift;
91     gid              = nlist->gid;
92     shiftvec         = fr->shift_vec[0];
93     fshift           = fr->fshift[0];
94     facel            = fr->ic->epsfac;
95     charge           = mdatoms->chargeA;
96     krf              = fr->ic->k_rf;
97     krf2             = krf*2.0;
98     crf              = fr->ic->c_rf;
99     nvdwtype         = fr->ntype;
100     vdwparam         = fr->nbfp;
101     vdwtype          = mdatoms->typeA;
102
103     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
104     rcutoff          = fr->ic->rcoulomb;
105     rcutoff2         = rcutoff*rcutoff;
106
107     rswitch          = fr->ic->rvdw_switch;
108     /* Setup switch parameters */
109     d                = rcutoff-rswitch;
110     swV3             = -10.0/(d*d*d);
111     swV4             =  15.0/(d*d*d*d);
112     swV5             =  -6.0/(d*d*d*d*d);
113     swF2             = -30.0/(d*d*d);
114     swF3             =  60.0/(d*d*d*d);
115     swF4             = -30.0/(d*d*d*d*d);
116
117     outeriter        = 0;
118     inneriter        = 0;
119
120     /* Start outer loop over neighborlists */
121     for(iidx=0; iidx<nri; iidx++)
122     {
123         /* Load shift vector for this list */
124         i_shift_offset   = DIM*shiftidx[iidx];
125         shX              = shiftvec[i_shift_offset+XX];
126         shY              = shiftvec[i_shift_offset+YY];
127         shZ              = shiftvec[i_shift_offset+ZZ];
128
129         /* Load limits for loop over neighbors */
130         j_index_start    = jindex[iidx];
131         j_index_end      = jindex[iidx+1];
132
133         /* Get outer coordinate index */
134         inr              = iinr[iidx];
135         i_coord_offset   = DIM*inr;
136
137         /* Load i particle coords and add shift vector */
138         ix0              = shX + x[i_coord_offset+DIM*0+XX];
139         iy0              = shY + x[i_coord_offset+DIM*0+YY];
140         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
141
142         fix0             = 0.0;
143         fiy0             = 0.0;
144         fiz0             = 0.0;
145
146         /* Load parameters for i particles */
147         iq0              = facel*charge[inr+0];
148         vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
149
150         /* Reset potential sums */
151         velecsum         = 0.0;
152         vvdwsum          = 0.0;
153
154         /* Start inner kernel loop */
155         for(jidx=j_index_start; jidx<j_index_end; jidx++)
156         {
157             /* Get j neighbor index, and coordinate index */
158             jnr              = jjnr[jidx];
159             j_coord_offset   = DIM*jnr;
160
161             /* load j atom coordinates */
162             jx0              = x[j_coord_offset+DIM*0+XX];
163             jy0              = x[j_coord_offset+DIM*0+YY];
164             jz0              = x[j_coord_offset+DIM*0+ZZ];
165
166             /* Calculate displacement vector */
167             dx00             = ix0 - jx0;
168             dy00             = iy0 - jy0;
169             dz00             = iz0 - jz0;
170
171             /* Calculate squared distance and things based on it */
172             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
173
174             rinv00           = 1.0/sqrt(rsq00);
175
176             rinvsq00         = rinv00*rinv00;
177
178             /* Load parameters for j particles */
179             jq0              = charge[jnr+0];
180             vdwjidx0         = 3*vdwtype[jnr+0];
181
182             /**************************
183              * CALCULATE INTERACTIONS *
184              **************************/
185
186             if (rsq00<rcutoff2)
187             {
188
189             r00              = rsq00*rinv00;
190
191             qq00             = iq0*jq0;
192             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
193             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
194             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
195
196             /* REACTION-FIELD ELECTROSTATICS */
197             velec            = qq00*(rinv00+krf*rsq00-crf);
198             felec            = qq00*(rinv00*rinvsq00-krf2);
199
200             /* BUCKINGHAM DISPERSION/REPULSION */
201             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
202             vvdw6            = c6_00*rinvsix;
203             br               = cexp2_00*r00;
204             vvdwexp          = cexp1_00*exp(-br);
205             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
206             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
207
208             d                = r00-rswitch;
209             d                = (d>0.0) ? d : 0.0;
210             d2               = d*d;
211             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
212
213             dsw              = d2*(swF2+d*(swF3+d*swF4));
214
215             /* Evaluate switch function */
216             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
217             fvdw             = fvdw*sw - rinv00*vvdw*dsw;
218             vvdw            *= sw;
219
220             /* Update potential sums from outer loop */
221             velecsum        += velec;
222             vvdwsum         += vvdw;
223
224             fscal            = felec+fvdw;
225
226             /* Calculate temporary vectorial force */
227             tx               = fscal*dx00;
228             ty               = fscal*dy00;
229             tz               = fscal*dz00;
230
231             /* Update vectorial force */
232             fix0            += tx;
233             fiy0            += ty;
234             fiz0            += tz;
235             f[j_coord_offset+DIM*0+XX] -= tx;
236             f[j_coord_offset+DIM*0+YY] -= ty;
237             f[j_coord_offset+DIM*0+ZZ] -= tz;
238
239             }
240
241             /* Inner loop uses 89 flops */
242         }
243         /* End of innermost loop */
244
245         tx = ty = tz = 0;
246         f[i_coord_offset+DIM*0+XX] += fix0;
247         f[i_coord_offset+DIM*0+YY] += fiy0;
248         f[i_coord_offset+DIM*0+ZZ] += fiz0;
249         tx                         += fix0;
250         ty                         += fiy0;
251         tz                         += fiz0;
252         fshift[i_shift_offset+XX]  += tx;
253         fshift[i_shift_offset+YY]  += ty;
254         fshift[i_shift_offset+ZZ]  += tz;
255
256         ggid                        = gid[iidx];
257         /* Update potential energies */
258         kernel_data->energygrp_elec[ggid] += velecsum;
259         kernel_data->energygrp_vdw[ggid] += vvdwsum;
260
261         /* Increment number of inner iterations */
262         inneriter                  += j_index_end - j_index_start;
263
264         /* Outer loop uses 15 flops */
265     }
266
267     /* Increment number of outer iterations */
268     outeriter        += nri;
269
270     /* Update outer/inner flops */
271
272     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*15 + inneriter*89);
273 }
274 /*
275  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwBhamSw_GeomP1P1_F_c
276  * Electrostatics interaction: ReactionField
277  * VdW interaction:            Buckingham
278  * Geometry:                   Particle-Particle
279  * Calculate force/pot:        Force
280  */
281 void
282 nb_kernel_ElecRFCut_VdwBhamSw_GeomP1P1_F_c
283                     (t_nblist                    * gmx_restrict       nlist,
284                      rvec                        * gmx_restrict          xx,
285                      rvec                        * gmx_restrict          ff,
286                      struct t_forcerec           * gmx_restrict          fr,
287                      t_mdatoms                   * gmx_restrict     mdatoms,
288                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
289                      t_nrnb                      * gmx_restrict        nrnb)
290 {
291     int              i_shift_offset,i_coord_offset,j_coord_offset;
292     int              j_index_start,j_index_end;
293     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
294     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
295     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
296     real             *shiftvec,*fshift,*x,*f;
297     int              vdwioffset0;
298     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
299     int              vdwjidx0;
300     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
301     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
302     real             velec,felec,velecsum,facel,crf,krf,krf2;
303     real             *charge;
304     int              nvdwtype;
305     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
306     int              *vdwtype;
307     real             *vdwparam;
308     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
309
310     x                = xx[0];
311     f                = ff[0];
312
313     nri              = nlist->nri;
314     iinr             = nlist->iinr;
315     jindex           = nlist->jindex;
316     jjnr             = nlist->jjnr;
317     shiftidx         = nlist->shift;
318     gid              = nlist->gid;
319     shiftvec         = fr->shift_vec[0];
320     fshift           = fr->fshift[0];
321     facel            = fr->ic->epsfac;
322     charge           = mdatoms->chargeA;
323     krf              = fr->ic->k_rf;
324     krf2             = krf*2.0;
325     crf              = fr->ic->c_rf;
326     nvdwtype         = fr->ntype;
327     vdwparam         = fr->nbfp;
328     vdwtype          = mdatoms->typeA;
329
330     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
331     rcutoff          = fr->ic->rcoulomb;
332     rcutoff2         = rcutoff*rcutoff;
333
334     rswitch          = fr->ic->rvdw_switch;
335     /* Setup switch parameters */
336     d                = rcutoff-rswitch;
337     swV3             = -10.0/(d*d*d);
338     swV4             =  15.0/(d*d*d*d);
339     swV5             =  -6.0/(d*d*d*d*d);
340     swF2             = -30.0/(d*d*d);
341     swF3             =  60.0/(d*d*d*d);
342     swF4             = -30.0/(d*d*d*d*d);
343
344     outeriter        = 0;
345     inneriter        = 0;
346
347     /* Start outer loop over neighborlists */
348     for(iidx=0; iidx<nri; iidx++)
349     {
350         /* Load shift vector for this list */
351         i_shift_offset   = DIM*shiftidx[iidx];
352         shX              = shiftvec[i_shift_offset+XX];
353         shY              = shiftvec[i_shift_offset+YY];
354         shZ              = shiftvec[i_shift_offset+ZZ];
355
356         /* Load limits for loop over neighbors */
357         j_index_start    = jindex[iidx];
358         j_index_end      = jindex[iidx+1];
359
360         /* Get outer coordinate index */
361         inr              = iinr[iidx];
362         i_coord_offset   = DIM*inr;
363
364         /* Load i particle coords and add shift vector */
365         ix0              = shX + x[i_coord_offset+DIM*0+XX];
366         iy0              = shY + x[i_coord_offset+DIM*0+YY];
367         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
368
369         fix0             = 0.0;
370         fiy0             = 0.0;
371         fiz0             = 0.0;
372
373         /* Load parameters for i particles */
374         iq0              = facel*charge[inr+0];
375         vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
376
377         /* Start inner kernel loop */
378         for(jidx=j_index_start; jidx<j_index_end; jidx++)
379         {
380             /* Get j neighbor index, and coordinate index */
381             jnr              = jjnr[jidx];
382             j_coord_offset   = DIM*jnr;
383
384             /* load j atom coordinates */
385             jx0              = x[j_coord_offset+DIM*0+XX];
386             jy0              = x[j_coord_offset+DIM*0+YY];
387             jz0              = x[j_coord_offset+DIM*0+ZZ];
388
389             /* Calculate displacement vector */
390             dx00             = ix0 - jx0;
391             dy00             = iy0 - jy0;
392             dz00             = iz0 - jz0;
393
394             /* Calculate squared distance and things based on it */
395             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
396
397             rinv00           = 1.0/sqrt(rsq00);
398
399             rinvsq00         = rinv00*rinv00;
400
401             /* Load parameters for j particles */
402             jq0              = charge[jnr+0];
403             vdwjidx0         = 3*vdwtype[jnr+0];
404
405             /**************************
406              * CALCULATE INTERACTIONS *
407              **************************/
408
409             if (rsq00<rcutoff2)
410             {
411
412             r00              = rsq00*rinv00;
413
414             qq00             = iq0*jq0;
415             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
416             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
417             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
418
419             /* REACTION-FIELD ELECTROSTATICS */
420             felec            = qq00*(rinv00*rinvsq00-krf2);
421
422             /* BUCKINGHAM DISPERSION/REPULSION */
423             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
424             vvdw6            = c6_00*rinvsix;
425             br               = cexp2_00*r00;
426             vvdwexp          = cexp1_00*exp(-br);
427             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
428             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
429
430             d                = r00-rswitch;
431             d                = (d>0.0) ? d : 0.0;
432             d2               = d*d;
433             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
434
435             dsw              = d2*(swF2+d*(swF3+d*swF4));
436
437             /* Evaluate switch function */
438             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
439             fvdw             = fvdw*sw - rinv00*vvdw*dsw;
440
441             fscal            = felec+fvdw;
442
443             /* Calculate temporary vectorial force */
444             tx               = fscal*dx00;
445             ty               = fscal*dy00;
446             tz               = fscal*dz00;
447
448             /* Update vectorial force */
449             fix0            += tx;
450             fiy0            += ty;
451             fiz0            += tz;
452             f[j_coord_offset+DIM*0+XX] -= tx;
453             f[j_coord_offset+DIM*0+YY] -= ty;
454             f[j_coord_offset+DIM*0+ZZ] -= tz;
455
456             }
457
458             /* Inner loop uses 82 flops */
459         }
460         /* End of innermost loop */
461
462         tx = ty = tz = 0;
463         f[i_coord_offset+DIM*0+XX] += fix0;
464         f[i_coord_offset+DIM*0+YY] += fiy0;
465         f[i_coord_offset+DIM*0+ZZ] += fiz0;
466         tx                         += fix0;
467         ty                         += fiy0;
468         tz                         += fiz0;
469         fshift[i_shift_offset+XX]  += tx;
470         fshift[i_shift_offset+YY]  += ty;
471         fshift[i_shift_offset+ZZ]  += tz;
472
473         /* Increment number of inner iterations */
474         inneriter                  += j_index_end - j_index_start;
475
476         /* Outer loop uses 13 flops */
477     }
478
479     /* Increment number of outer iterations */
480     outeriter        += nri;
481
482     /* Update outer/inner flops */
483
484     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*82);
485 }