Use full path for legacyheaders
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecRFCut_VdwBhamSw_GeomW3P1_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, 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 "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
46
47 /*
48  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwBhamSw_GeomW3P1_VF_c
49  * Electrostatics interaction: ReactionField
50  * VdW interaction:            Buckingham
51  * Geometry:                   Water3-Particle
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecRFCut_VdwBhamSw_GeomW3P1_VF_c
56                     (t_nblist                    * gmx_restrict       nlist,
57                      rvec                        * gmx_restrict          xx,
58                      rvec                        * gmx_restrict          ff,
59                      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              vdwioffset1;
73     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
74     int              vdwioffset2;
75     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
76     int              vdwjidx0;
77     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
78     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
79     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
80     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
81     real             velec,felec,velecsum,facel,crf,krf,krf2;
82     real             *charge;
83     int              nvdwtype;
84     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
85     int              *vdwtype;
86     real             *vdwparam;
87     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
88
89     x                = xx[0];
90     f                = ff[0];
91
92     nri              = nlist->nri;
93     iinr             = nlist->iinr;
94     jindex           = nlist->jindex;
95     jjnr             = nlist->jjnr;
96     shiftidx         = nlist->shift;
97     gid              = nlist->gid;
98     shiftvec         = fr->shift_vec[0];
99     fshift           = fr->fshift[0];
100     facel            = fr->epsfac;
101     charge           = mdatoms->chargeA;
102     krf              = fr->ic->k_rf;
103     krf2             = krf*2.0;
104     crf              = fr->ic->c_rf;
105     nvdwtype         = fr->ntype;
106     vdwparam         = fr->nbfp;
107     vdwtype          = mdatoms->typeA;
108
109     /* Setup water-specific parameters */
110     inr              = nlist->iinr[0];
111     iq0              = facel*charge[inr+0];
112     iq1              = facel*charge[inr+1];
113     iq2              = facel*charge[inr+2];
114     vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
115
116     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
117     rcutoff          = fr->rcoulomb;
118     rcutoff2         = rcutoff*rcutoff;
119
120     rswitch          = fr->rvdw_switch;
121     /* Setup switch parameters */
122     d                = rcutoff-rswitch;
123     swV3             = -10.0/(d*d*d);
124     swV4             =  15.0/(d*d*d*d);
125     swV5             =  -6.0/(d*d*d*d*d);
126     swF2             = -30.0/(d*d*d);
127     swF3             =  60.0/(d*d*d*d);
128     swF4             = -30.0/(d*d*d*d*d);
129
130     outeriter        = 0;
131     inneriter        = 0;
132
133     /* Start outer loop over neighborlists */
134     for(iidx=0; iidx<nri; iidx++)
135     {
136         /* Load shift vector for this list */
137         i_shift_offset   = DIM*shiftidx[iidx];
138         shX              = shiftvec[i_shift_offset+XX];
139         shY              = shiftvec[i_shift_offset+YY];
140         shZ              = shiftvec[i_shift_offset+ZZ];
141
142         /* Load limits for loop over neighbors */
143         j_index_start    = jindex[iidx];
144         j_index_end      = jindex[iidx+1];
145
146         /* Get outer coordinate index */
147         inr              = iinr[iidx];
148         i_coord_offset   = DIM*inr;
149
150         /* Load i particle coords and add shift vector */
151         ix0              = shX + x[i_coord_offset+DIM*0+XX];
152         iy0              = shY + x[i_coord_offset+DIM*0+YY];
153         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
154         ix1              = shX + x[i_coord_offset+DIM*1+XX];
155         iy1              = shY + x[i_coord_offset+DIM*1+YY];
156         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
157         ix2              = shX + x[i_coord_offset+DIM*2+XX];
158         iy2              = shY + x[i_coord_offset+DIM*2+YY];
159         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
160
161         fix0             = 0.0;
162         fiy0             = 0.0;
163         fiz0             = 0.0;
164         fix1             = 0.0;
165         fiy1             = 0.0;
166         fiz1             = 0.0;
167         fix2             = 0.0;
168         fiy2             = 0.0;
169         fiz2             = 0.0;
170
171         /* Reset potential sums */
172         velecsum         = 0.0;
173         vvdwsum          = 0.0;
174
175         /* Start inner kernel loop */
176         for(jidx=j_index_start; jidx<j_index_end; jidx++)
177         {
178             /* Get j neighbor index, and coordinate index */
179             jnr              = jjnr[jidx];
180             j_coord_offset   = DIM*jnr;
181
182             /* load j atom coordinates */
183             jx0              = x[j_coord_offset+DIM*0+XX];
184             jy0              = x[j_coord_offset+DIM*0+YY];
185             jz0              = x[j_coord_offset+DIM*0+ZZ];
186
187             /* Calculate displacement vector */
188             dx00             = ix0 - jx0;
189             dy00             = iy0 - jy0;
190             dz00             = iz0 - jz0;
191             dx10             = ix1 - jx0;
192             dy10             = iy1 - jy0;
193             dz10             = iz1 - jz0;
194             dx20             = ix2 - jx0;
195             dy20             = iy2 - jy0;
196             dz20             = iz2 - jz0;
197
198             /* Calculate squared distance and things based on it */
199             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
200             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
201             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
202
203             rinv00           = gmx_invsqrt(rsq00);
204             rinv10           = gmx_invsqrt(rsq10);
205             rinv20           = gmx_invsqrt(rsq20);
206
207             rinvsq00         = rinv00*rinv00;
208             rinvsq10         = rinv10*rinv10;
209             rinvsq20         = rinv20*rinv20;
210
211             /* Load parameters for j particles */
212             jq0              = charge[jnr+0];
213             vdwjidx0         = 3*vdwtype[jnr+0];
214
215             /**************************
216              * CALCULATE INTERACTIONS *
217              **************************/
218
219             if (rsq00<rcutoff2)
220             {
221
222             r00              = rsq00*rinv00;
223
224             qq00             = iq0*jq0;
225             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
226             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
227             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
228
229             /* REACTION-FIELD ELECTROSTATICS */
230             velec            = qq00*(rinv00+krf*rsq00-crf);
231             felec            = qq00*(rinv00*rinvsq00-krf2);
232
233             /* BUCKINGHAM DISPERSION/REPULSION */
234             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
235             vvdw6            = c6_00*rinvsix;
236             br               = cexp2_00*r00;
237             vvdwexp          = cexp1_00*exp(-br);
238             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
239             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
240
241             d                = r00-rswitch;
242             d                = (d>0.0) ? d : 0.0;
243             d2               = d*d;
244             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
245
246             dsw              = d2*(swF2+d*(swF3+d*swF4));
247
248             /* Evaluate switch function */
249             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
250             fvdw             = fvdw*sw - rinv00*vvdw*dsw;
251             vvdw            *= sw;
252
253             /* Update potential sums from outer loop */
254             velecsum        += velec;
255             vvdwsum         += vvdw;
256
257             fscal            = felec+fvdw;
258
259             /* Calculate temporary vectorial force */
260             tx               = fscal*dx00;
261             ty               = fscal*dy00;
262             tz               = fscal*dz00;
263
264             /* Update vectorial force */
265             fix0            += tx;
266             fiy0            += ty;
267             fiz0            += tz;
268             f[j_coord_offset+DIM*0+XX] -= tx;
269             f[j_coord_offset+DIM*0+YY] -= ty;
270             f[j_coord_offset+DIM*0+ZZ] -= tz;
271
272             }
273
274             /**************************
275              * CALCULATE INTERACTIONS *
276              **************************/
277
278             if (rsq10<rcutoff2)
279             {
280
281             qq10             = iq1*jq0;
282
283             /* REACTION-FIELD ELECTROSTATICS */
284             velec            = qq10*(rinv10+krf*rsq10-crf);
285             felec            = qq10*(rinv10*rinvsq10-krf2);
286
287             /* Update potential sums from outer loop */
288             velecsum        += velec;
289
290             fscal            = felec;
291
292             /* Calculate temporary vectorial force */
293             tx               = fscal*dx10;
294             ty               = fscal*dy10;
295             tz               = fscal*dz10;
296
297             /* Update vectorial force */
298             fix1            += tx;
299             fiy1            += ty;
300             fiz1            += tz;
301             f[j_coord_offset+DIM*0+XX] -= tx;
302             f[j_coord_offset+DIM*0+YY] -= ty;
303             f[j_coord_offset+DIM*0+ZZ] -= tz;
304
305             }
306
307             /**************************
308              * CALCULATE INTERACTIONS *
309              **************************/
310
311             if (rsq20<rcutoff2)
312             {
313
314             qq20             = iq2*jq0;
315
316             /* REACTION-FIELD ELECTROSTATICS */
317             velec            = qq20*(rinv20+krf*rsq20-crf);
318             felec            = qq20*(rinv20*rinvsq20-krf2);
319
320             /* Update potential sums from outer loop */
321             velecsum        += velec;
322
323             fscal            = felec;
324
325             /* Calculate temporary vectorial force */
326             tx               = fscal*dx20;
327             ty               = fscal*dy20;
328             tz               = fscal*dz20;
329
330             /* Update vectorial force */
331             fix2            += tx;
332             fiy2            += ty;
333             fiz2            += tz;
334             f[j_coord_offset+DIM*0+XX] -= tx;
335             f[j_coord_offset+DIM*0+YY] -= ty;
336             f[j_coord_offset+DIM*0+ZZ] -= tz;
337
338             }
339
340             /* Inner loop uses 153 flops */
341         }
342         /* End of innermost loop */
343
344         tx = ty = tz = 0;
345         f[i_coord_offset+DIM*0+XX] += fix0;
346         f[i_coord_offset+DIM*0+YY] += fiy0;
347         f[i_coord_offset+DIM*0+ZZ] += fiz0;
348         tx                         += fix0;
349         ty                         += fiy0;
350         tz                         += fiz0;
351         f[i_coord_offset+DIM*1+XX] += fix1;
352         f[i_coord_offset+DIM*1+YY] += fiy1;
353         f[i_coord_offset+DIM*1+ZZ] += fiz1;
354         tx                         += fix1;
355         ty                         += fiy1;
356         tz                         += fiz1;
357         f[i_coord_offset+DIM*2+XX] += fix2;
358         f[i_coord_offset+DIM*2+YY] += fiy2;
359         f[i_coord_offset+DIM*2+ZZ] += fiz2;
360         tx                         += fix2;
361         ty                         += fiy2;
362         tz                         += fiz2;
363         fshift[i_shift_offset+XX]  += tx;
364         fshift[i_shift_offset+YY]  += ty;
365         fshift[i_shift_offset+ZZ]  += tz;
366
367         ggid                        = gid[iidx];
368         /* Update potential energies */
369         kernel_data->energygrp_elec[ggid] += velecsum;
370         kernel_data->energygrp_vdw[ggid] += vvdwsum;
371
372         /* Increment number of inner iterations */
373         inneriter                  += j_index_end - j_index_start;
374
375         /* Outer loop uses 32 flops */
376     }
377
378     /* Increment number of outer iterations */
379     outeriter        += nri;
380
381     /* Update outer/inner flops */
382
383     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*153);
384 }
385 /*
386  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwBhamSw_GeomW3P1_F_c
387  * Electrostatics interaction: ReactionField
388  * VdW interaction:            Buckingham
389  * Geometry:                   Water3-Particle
390  * Calculate force/pot:        Force
391  */
392 void
393 nb_kernel_ElecRFCut_VdwBhamSw_GeomW3P1_F_c
394                     (t_nblist                    * gmx_restrict       nlist,
395                      rvec                        * gmx_restrict          xx,
396                      rvec                        * gmx_restrict          ff,
397                      t_forcerec                  * gmx_restrict          fr,
398                      t_mdatoms                   * gmx_restrict     mdatoms,
399                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
400                      t_nrnb                      * gmx_restrict        nrnb)
401 {
402     int              i_shift_offset,i_coord_offset,j_coord_offset;
403     int              j_index_start,j_index_end;
404     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
405     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
406     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
407     real             *shiftvec,*fshift,*x,*f;
408     int              vdwioffset0;
409     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
410     int              vdwioffset1;
411     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
412     int              vdwioffset2;
413     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
414     int              vdwjidx0;
415     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
416     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
417     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
418     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
419     real             velec,felec,velecsum,facel,crf,krf,krf2;
420     real             *charge;
421     int              nvdwtype;
422     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
423     int              *vdwtype;
424     real             *vdwparam;
425     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
426
427     x                = xx[0];
428     f                = ff[0];
429
430     nri              = nlist->nri;
431     iinr             = nlist->iinr;
432     jindex           = nlist->jindex;
433     jjnr             = nlist->jjnr;
434     shiftidx         = nlist->shift;
435     gid              = nlist->gid;
436     shiftvec         = fr->shift_vec[0];
437     fshift           = fr->fshift[0];
438     facel            = fr->epsfac;
439     charge           = mdatoms->chargeA;
440     krf              = fr->ic->k_rf;
441     krf2             = krf*2.0;
442     crf              = fr->ic->c_rf;
443     nvdwtype         = fr->ntype;
444     vdwparam         = fr->nbfp;
445     vdwtype          = mdatoms->typeA;
446
447     /* Setup water-specific parameters */
448     inr              = nlist->iinr[0];
449     iq0              = facel*charge[inr+0];
450     iq1              = facel*charge[inr+1];
451     iq2              = facel*charge[inr+2];
452     vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
453
454     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
455     rcutoff          = fr->rcoulomb;
456     rcutoff2         = rcutoff*rcutoff;
457
458     rswitch          = fr->rvdw_switch;
459     /* Setup switch parameters */
460     d                = rcutoff-rswitch;
461     swV3             = -10.0/(d*d*d);
462     swV4             =  15.0/(d*d*d*d);
463     swV5             =  -6.0/(d*d*d*d*d);
464     swF2             = -30.0/(d*d*d);
465     swF3             =  60.0/(d*d*d*d);
466     swF4             = -30.0/(d*d*d*d*d);
467
468     outeriter        = 0;
469     inneriter        = 0;
470
471     /* Start outer loop over neighborlists */
472     for(iidx=0; iidx<nri; iidx++)
473     {
474         /* Load shift vector for this list */
475         i_shift_offset   = DIM*shiftidx[iidx];
476         shX              = shiftvec[i_shift_offset+XX];
477         shY              = shiftvec[i_shift_offset+YY];
478         shZ              = shiftvec[i_shift_offset+ZZ];
479
480         /* Load limits for loop over neighbors */
481         j_index_start    = jindex[iidx];
482         j_index_end      = jindex[iidx+1];
483
484         /* Get outer coordinate index */
485         inr              = iinr[iidx];
486         i_coord_offset   = DIM*inr;
487
488         /* Load i particle coords and add shift vector */
489         ix0              = shX + x[i_coord_offset+DIM*0+XX];
490         iy0              = shY + x[i_coord_offset+DIM*0+YY];
491         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
492         ix1              = shX + x[i_coord_offset+DIM*1+XX];
493         iy1              = shY + x[i_coord_offset+DIM*1+YY];
494         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
495         ix2              = shX + x[i_coord_offset+DIM*2+XX];
496         iy2              = shY + x[i_coord_offset+DIM*2+YY];
497         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
498
499         fix0             = 0.0;
500         fiy0             = 0.0;
501         fiz0             = 0.0;
502         fix1             = 0.0;
503         fiy1             = 0.0;
504         fiz1             = 0.0;
505         fix2             = 0.0;
506         fiy2             = 0.0;
507         fiz2             = 0.0;
508
509         /* Start inner kernel loop */
510         for(jidx=j_index_start; jidx<j_index_end; jidx++)
511         {
512             /* Get j neighbor index, and coordinate index */
513             jnr              = jjnr[jidx];
514             j_coord_offset   = DIM*jnr;
515
516             /* load j atom coordinates */
517             jx0              = x[j_coord_offset+DIM*0+XX];
518             jy0              = x[j_coord_offset+DIM*0+YY];
519             jz0              = x[j_coord_offset+DIM*0+ZZ];
520
521             /* Calculate displacement vector */
522             dx00             = ix0 - jx0;
523             dy00             = iy0 - jy0;
524             dz00             = iz0 - jz0;
525             dx10             = ix1 - jx0;
526             dy10             = iy1 - jy0;
527             dz10             = iz1 - jz0;
528             dx20             = ix2 - jx0;
529             dy20             = iy2 - jy0;
530             dz20             = iz2 - jz0;
531
532             /* Calculate squared distance and things based on it */
533             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
534             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
535             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
536
537             rinv00           = gmx_invsqrt(rsq00);
538             rinv10           = gmx_invsqrt(rsq10);
539             rinv20           = gmx_invsqrt(rsq20);
540
541             rinvsq00         = rinv00*rinv00;
542             rinvsq10         = rinv10*rinv10;
543             rinvsq20         = rinv20*rinv20;
544
545             /* Load parameters for j particles */
546             jq0              = charge[jnr+0];
547             vdwjidx0         = 3*vdwtype[jnr+0];
548
549             /**************************
550              * CALCULATE INTERACTIONS *
551              **************************/
552
553             if (rsq00<rcutoff2)
554             {
555
556             r00              = rsq00*rinv00;
557
558             qq00             = iq0*jq0;
559             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
560             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
561             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
562
563             /* REACTION-FIELD ELECTROSTATICS */
564             felec            = qq00*(rinv00*rinvsq00-krf2);
565
566             /* BUCKINGHAM DISPERSION/REPULSION */
567             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
568             vvdw6            = c6_00*rinvsix;
569             br               = cexp2_00*r00;
570             vvdwexp          = cexp1_00*exp(-br);
571             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
572             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
573
574             d                = r00-rswitch;
575             d                = (d>0.0) ? d : 0.0;
576             d2               = d*d;
577             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
578
579             dsw              = d2*(swF2+d*(swF3+d*swF4));
580
581             /* Evaluate switch function */
582             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
583             fvdw             = fvdw*sw - rinv00*vvdw*dsw;
584
585             fscal            = felec+fvdw;
586
587             /* Calculate temporary vectorial force */
588             tx               = fscal*dx00;
589             ty               = fscal*dy00;
590             tz               = fscal*dz00;
591
592             /* Update vectorial force */
593             fix0            += tx;
594             fiy0            += ty;
595             fiz0            += tz;
596             f[j_coord_offset+DIM*0+XX] -= tx;
597             f[j_coord_offset+DIM*0+YY] -= ty;
598             f[j_coord_offset+DIM*0+ZZ] -= tz;
599
600             }
601
602             /**************************
603              * CALCULATE INTERACTIONS *
604              **************************/
605
606             if (rsq10<rcutoff2)
607             {
608
609             qq10             = iq1*jq0;
610
611             /* REACTION-FIELD ELECTROSTATICS */
612             felec            = qq10*(rinv10*rinvsq10-krf2);
613
614             fscal            = felec;
615
616             /* Calculate temporary vectorial force */
617             tx               = fscal*dx10;
618             ty               = fscal*dy10;
619             tz               = fscal*dz10;
620
621             /* Update vectorial force */
622             fix1            += tx;
623             fiy1            += ty;
624             fiz1            += tz;
625             f[j_coord_offset+DIM*0+XX] -= tx;
626             f[j_coord_offset+DIM*0+YY] -= ty;
627             f[j_coord_offset+DIM*0+ZZ] -= tz;
628
629             }
630
631             /**************************
632              * CALCULATE INTERACTIONS *
633              **************************/
634
635             if (rsq20<rcutoff2)
636             {
637
638             qq20             = iq2*jq0;
639
640             /* REACTION-FIELD ELECTROSTATICS */
641             felec            = qq20*(rinv20*rinvsq20-krf2);
642
643             fscal            = felec;
644
645             /* Calculate temporary vectorial force */
646             tx               = fscal*dx20;
647             ty               = fscal*dy20;
648             tz               = fscal*dz20;
649
650             /* Update vectorial force */
651             fix2            += tx;
652             fiy2            += ty;
653             fiz2            += tz;
654             f[j_coord_offset+DIM*0+XX] -= tx;
655             f[j_coord_offset+DIM*0+YY] -= ty;
656             f[j_coord_offset+DIM*0+ZZ] -= tz;
657
658             }
659
660             /* Inner loop uses 136 flops */
661         }
662         /* End of innermost loop */
663
664         tx = ty = tz = 0;
665         f[i_coord_offset+DIM*0+XX] += fix0;
666         f[i_coord_offset+DIM*0+YY] += fiy0;
667         f[i_coord_offset+DIM*0+ZZ] += fiz0;
668         tx                         += fix0;
669         ty                         += fiy0;
670         tz                         += fiz0;
671         f[i_coord_offset+DIM*1+XX] += fix1;
672         f[i_coord_offset+DIM*1+YY] += fiy1;
673         f[i_coord_offset+DIM*1+ZZ] += fiz1;
674         tx                         += fix1;
675         ty                         += fiy1;
676         tz                         += fiz1;
677         f[i_coord_offset+DIM*2+XX] += fix2;
678         f[i_coord_offset+DIM*2+YY] += fiy2;
679         f[i_coord_offset+DIM*2+ZZ] += fiz2;
680         tx                         += fix2;
681         ty                         += fiy2;
682         tz                         += fiz2;
683         fshift[i_shift_offset+XX]  += tx;
684         fshift[i_shift_offset+YY]  += ty;
685         fshift[i_shift_offset+ZZ]  += tz;
686
687         /* Increment number of inner iterations */
688         inneriter                  += j_index_end - j_index_start;
689
690         /* Outer loop uses 30 flops */
691     }
692
693     /* Increment number of outer iterations */
694     outeriter        += nri;
695
696     /* Update outer/inner flops */
697
698     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*136);
699 }