6aafb317b1a068d6980a69a9b9d5755f2af7789d
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEwSw_VdwBhamSw_GeomW3W3_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_ElecEwSw_VdwBhamSw_GeomW3W3_VF_c
49  * Electrostatics interaction: Ewald
50  * VdW interaction:            Buckingham
51  * Geometry:                   Water3-Water3
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecEwSw_VdwBhamSw_GeomW3W3_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     int              vdwjidx1;
79     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
80     int              vdwjidx2;
81     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
82     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
83     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
84     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
85     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
86     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
87     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
88     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
89     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
90     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
91     real             velec,felec,velecsum,facel,crf,krf,krf2;
92     real             *charge;
93     int              nvdwtype;
94     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
95     int              *vdwtype;
96     real             *vdwparam;
97     int              ewitab;
98     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
99     real             *ewtab;
100     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
101
102     x                = xx[0];
103     f                = ff[0];
104
105     nri              = nlist->nri;
106     iinr             = nlist->iinr;
107     jindex           = nlist->jindex;
108     jjnr             = nlist->jjnr;
109     shiftidx         = nlist->shift;
110     gid              = nlist->gid;
111     shiftvec         = fr->shift_vec[0];
112     fshift           = fr->fshift[0];
113     facel            = fr->epsfac;
114     charge           = mdatoms->chargeA;
115     nvdwtype         = fr->ntype;
116     vdwparam         = fr->nbfp;
117     vdwtype          = mdatoms->typeA;
118
119     sh_ewald         = fr->ic->sh_ewald;
120     ewtab            = fr->ic->tabq_coul_FDV0;
121     ewtabscale       = fr->ic->tabq_scale;
122     ewtabhalfspace   = 0.5/ewtabscale;
123
124     /* Setup water-specific parameters */
125     inr              = nlist->iinr[0];
126     iq0              = facel*charge[inr+0];
127     iq1              = facel*charge[inr+1];
128     iq2              = facel*charge[inr+2];
129     vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
130
131     jq0              = charge[inr+0];
132     jq1              = charge[inr+1];
133     jq2              = charge[inr+2];
134     vdwjidx0         = 3*vdwtype[inr+0];
135     qq00             = iq0*jq0;
136     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
137     cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
138     cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
139     qq01             = iq0*jq1;
140     qq02             = iq0*jq2;
141     qq10             = iq1*jq0;
142     qq11             = iq1*jq1;
143     qq12             = iq1*jq2;
144     qq20             = iq2*jq0;
145     qq21             = iq2*jq1;
146     qq22             = iq2*jq2;
147
148     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
149     rcutoff          = fr->rcoulomb;
150     rcutoff2         = rcutoff*rcutoff;
151
152     rswitch          = fr->rcoulomb_switch;
153     /* Setup switch parameters */
154     d                = rcutoff-rswitch;
155     swV3             = -10.0/(d*d*d);
156     swV4             =  15.0/(d*d*d*d);
157     swV5             =  -6.0/(d*d*d*d*d);
158     swF2             = -30.0/(d*d*d);
159     swF3             =  60.0/(d*d*d*d);
160     swF4             = -30.0/(d*d*d*d*d);
161
162     outeriter        = 0;
163     inneriter        = 0;
164
165     /* Start outer loop over neighborlists */
166     for(iidx=0; iidx<nri; iidx++)
167     {
168         /* Load shift vector for this list */
169         i_shift_offset   = DIM*shiftidx[iidx];
170         shX              = shiftvec[i_shift_offset+XX];
171         shY              = shiftvec[i_shift_offset+YY];
172         shZ              = shiftvec[i_shift_offset+ZZ];
173
174         /* Load limits for loop over neighbors */
175         j_index_start    = jindex[iidx];
176         j_index_end      = jindex[iidx+1];
177
178         /* Get outer coordinate index */
179         inr              = iinr[iidx];
180         i_coord_offset   = DIM*inr;
181
182         /* Load i particle coords and add shift vector */
183         ix0              = shX + x[i_coord_offset+DIM*0+XX];
184         iy0              = shY + x[i_coord_offset+DIM*0+YY];
185         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
186         ix1              = shX + x[i_coord_offset+DIM*1+XX];
187         iy1              = shY + x[i_coord_offset+DIM*1+YY];
188         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
189         ix2              = shX + x[i_coord_offset+DIM*2+XX];
190         iy2              = shY + x[i_coord_offset+DIM*2+YY];
191         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
192
193         fix0             = 0.0;
194         fiy0             = 0.0;
195         fiz0             = 0.0;
196         fix1             = 0.0;
197         fiy1             = 0.0;
198         fiz1             = 0.0;
199         fix2             = 0.0;
200         fiy2             = 0.0;
201         fiz2             = 0.0;
202
203         /* Reset potential sums */
204         velecsum         = 0.0;
205         vvdwsum          = 0.0;
206
207         /* Start inner kernel loop */
208         for(jidx=j_index_start; jidx<j_index_end; jidx++)
209         {
210             /* Get j neighbor index, and coordinate index */
211             jnr              = jjnr[jidx];
212             j_coord_offset   = DIM*jnr;
213
214             /* load j atom coordinates */
215             jx0              = x[j_coord_offset+DIM*0+XX];
216             jy0              = x[j_coord_offset+DIM*0+YY];
217             jz0              = x[j_coord_offset+DIM*0+ZZ];
218             jx1              = x[j_coord_offset+DIM*1+XX];
219             jy1              = x[j_coord_offset+DIM*1+YY];
220             jz1              = x[j_coord_offset+DIM*1+ZZ];
221             jx2              = x[j_coord_offset+DIM*2+XX];
222             jy2              = x[j_coord_offset+DIM*2+YY];
223             jz2              = x[j_coord_offset+DIM*2+ZZ];
224
225             /* Calculate displacement vector */
226             dx00             = ix0 - jx0;
227             dy00             = iy0 - jy0;
228             dz00             = iz0 - jz0;
229             dx01             = ix0 - jx1;
230             dy01             = iy0 - jy1;
231             dz01             = iz0 - jz1;
232             dx02             = ix0 - jx2;
233             dy02             = iy0 - jy2;
234             dz02             = iz0 - jz2;
235             dx10             = ix1 - jx0;
236             dy10             = iy1 - jy0;
237             dz10             = iz1 - jz0;
238             dx11             = ix1 - jx1;
239             dy11             = iy1 - jy1;
240             dz11             = iz1 - jz1;
241             dx12             = ix1 - jx2;
242             dy12             = iy1 - jy2;
243             dz12             = iz1 - jz2;
244             dx20             = ix2 - jx0;
245             dy20             = iy2 - jy0;
246             dz20             = iz2 - jz0;
247             dx21             = ix2 - jx1;
248             dy21             = iy2 - jy1;
249             dz21             = iz2 - jz1;
250             dx22             = ix2 - jx2;
251             dy22             = iy2 - jy2;
252             dz22             = iz2 - jz2;
253
254             /* Calculate squared distance and things based on it */
255             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
256             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
257             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
258             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
259             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
260             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
261             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
262             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
263             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
264
265             rinv00           = gmx_invsqrt(rsq00);
266             rinv01           = gmx_invsqrt(rsq01);
267             rinv02           = gmx_invsqrt(rsq02);
268             rinv10           = gmx_invsqrt(rsq10);
269             rinv11           = gmx_invsqrt(rsq11);
270             rinv12           = gmx_invsqrt(rsq12);
271             rinv20           = gmx_invsqrt(rsq20);
272             rinv21           = gmx_invsqrt(rsq21);
273             rinv22           = gmx_invsqrt(rsq22);
274
275             rinvsq00         = rinv00*rinv00;
276             rinvsq01         = rinv01*rinv01;
277             rinvsq02         = rinv02*rinv02;
278             rinvsq10         = rinv10*rinv10;
279             rinvsq11         = rinv11*rinv11;
280             rinvsq12         = rinv12*rinv12;
281             rinvsq20         = rinv20*rinv20;
282             rinvsq21         = rinv21*rinv21;
283             rinvsq22         = rinv22*rinv22;
284
285             /**************************
286              * CALCULATE INTERACTIONS *
287              **************************/
288
289             if (rsq00<rcutoff2)
290             {
291
292             r00              = rsq00*rinv00;
293
294             /* EWALD ELECTROSTATICS */
295
296             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
297             ewrt             = r00*ewtabscale;
298             ewitab           = ewrt;
299             eweps            = ewrt-ewitab;
300             ewitab           = 4*ewitab;
301             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
302             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
303             felec            = qq00*rinv00*(rinvsq00-felec);
304
305             /* BUCKINGHAM DISPERSION/REPULSION */
306             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
307             vvdw6            = c6_00*rinvsix;
308             br               = cexp2_00*r00;
309             vvdwexp          = cexp1_00*exp(-br);
310             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
311             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
312
313             d                = r00-rswitch;
314             d                = (d>0.0) ? d : 0.0;
315             d2               = d*d;
316             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
317
318             dsw              = d2*(swF2+d*(swF3+d*swF4));
319
320             /* Evaluate switch function */
321             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
322             felec            = felec*sw - rinv00*velec*dsw;
323             fvdw             = fvdw*sw - rinv00*vvdw*dsw;
324             velec           *= sw;
325             vvdw            *= sw;
326
327             /* Update potential sums from outer loop */
328             velecsum        += velec;
329             vvdwsum         += vvdw;
330
331             fscal            = felec+fvdw;
332
333             /* Calculate temporary vectorial force */
334             tx               = fscal*dx00;
335             ty               = fscal*dy00;
336             tz               = fscal*dz00;
337
338             /* Update vectorial force */
339             fix0            += tx;
340             fiy0            += ty;
341             fiz0            += tz;
342             f[j_coord_offset+DIM*0+XX] -= tx;
343             f[j_coord_offset+DIM*0+YY] -= ty;
344             f[j_coord_offset+DIM*0+ZZ] -= tz;
345
346             }
347
348             /**************************
349              * CALCULATE INTERACTIONS *
350              **************************/
351
352             if (rsq01<rcutoff2)
353             {
354
355             r01              = rsq01*rinv01;
356
357             /* EWALD ELECTROSTATICS */
358
359             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
360             ewrt             = r01*ewtabscale;
361             ewitab           = ewrt;
362             eweps            = ewrt-ewitab;
363             ewitab           = 4*ewitab;
364             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
365             velec            = qq01*(rinv01-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
366             felec            = qq01*rinv01*(rinvsq01-felec);
367
368             d                = r01-rswitch;
369             d                = (d>0.0) ? d : 0.0;
370             d2               = d*d;
371             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
372
373             dsw              = d2*(swF2+d*(swF3+d*swF4));
374
375             /* Evaluate switch function */
376             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
377             felec            = felec*sw - rinv01*velec*dsw;
378             velec           *= sw;
379
380             /* Update potential sums from outer loop */
381             velecsum        += velec;
382
383             fscal            = felec;
384
385             /* Calculate temporary vectorial force */
386             tx               = fscal*dx01;
387             ty               = fscal*dy01;
388             tz               = fscal*dz01;
389
390             /* Update vectorial force */
391             fix0            += tx;
392             fiy0            += ty;
393             fiz0            += tz;
394             f[j_coord_offset+DIM*1+XX] -= tx;
395             f[j_coord_offset+DIM*1+YY] -= ty;
396             f[j_coord_offset+DIM*1+ZZ] -= tz;
397
398             }
399
400             /**************************
401              * CALCULATE INTERACTIONS *
402              **************************/
403
404             if (rsq02<rcutoff2)
405             {
406
407             r02              = rsq02*rinv02;
408
409             /* EWALD ELECTROSTATICS */
410
411             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
412             ewrt             = r02*ewtabscale;
413             ewitab           = ewrt;
414             eweps            = ewrt-ewitab;
415             ewitab           = 4*ewitab;
416             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
417             velec            = qq02*(rinv02-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
418             felec            = qq02*rinv02*(rinvsq02-felec);
419
420             d                = r02-rswitch;
421             d                = (d>0.0) ? d : 0.0;
422             d2               = d*d;
423             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
424
425             dsw              = d2*(swF2+d*(swF3+d*swF4));
426
427             /* Evaluate switch function */
428             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
429             felec            = felec*sw - rinv02*velec*dsw;
430             velec           *= sw;
431
432             /* Update potential sums from outer loop */
433             velecsum        += velec;
434
435             fscal            = felec;
436
437             /* Calculate temporary vectorial force */
438             tx               = fscal*dx02;
439             ty               = fscal*dy02;
440             tz               = fscal*dz02;
441
442             /* Update vectorial force */
443             fix0            += tx;
444             fiy0            += ty;
445             fiz0            += tz;
446             f[j_coord_offset+DIM*2+XX] -= tx;
447             f[j_coord_offset+DIM*2+YY] -= ty;
448             f[j_coord_offset+DIM*2+ZZ] -= tz;
449
450             }
451
452             /**************************
453              * CALCULATE INTERACTIONS *
454              **************************/
455
456             if (rsq10<rcutoff2)
457             {
458
459             r10              = rsq10*rinv10;
460
461             /* EWALD ELECTROSTATICS */
462
463             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
464             ewrt             = r10*ewtabscale;
465             ewitab           = ewrt;
466             eweps            = ewrt-ewitab;
467             ewitab           = 4*ewitab;
468             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
469             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
470             felec            = qq10*rinv10*(rinvsq10-felec);
471
472             d                = r10-rswitch;
473             d                = (d>0.0) ? d : 0.0;
474             d2               = d*d;
475             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
476
477             dsw              = d2*(swF2+d*(swF3+d*swF4));
478
479             /* Evaluate switch function */
480             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
481             felec            = felec*sw - rinv10*velec*dsw;
482             velec           *= sw;
483
484             /* Update potential sums from outer loop */
485             velecsum        += velec;
486
487             fscal            = felec;
488
489             /* Calculate temporary vectorial force */
490             tx               = fscal*dx10;
491             ty               = fscal*dy10;
492             tz               = fscal*dz10;
493
494             /* Update vectorial force */
495             fix1            += tx;
496             fiy1            += ty;
497             fiz1            += tz;
498             f[j_coord_offset+DIM*0+XX] -= tx;
499             f[j_coord_offset+DIM*0+YY] -= ty;
500             f[j_coord_offset+DIM*0+ZZ] -= tz;
501
502             }
503
504             /**************************
505              * CALCULATE INTERACTIONS *
506              **************************/
507
508             if (rsq11<rcutoff2)
509             {
510
511             r11              = rsq11*rinv11;
512
513             /* EWALD ELECTROSTATICS */
514
515             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
516             ewrt             = r11*ewtabscale;
517             ewitab           = ewrt;
518             eweps            = ewrt-ewitab;
519             ewitab           = 4*ewitab;
520             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
521             velec            = qq11*(rinv11-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
522             felec            = qq11*rinv11*(rinvsq11-felec);
523
524             d                = r11-rswitch;
525             d                = (d>0.0) ? d : 0.0;
526             d2               = d*d;
527             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
528
529             dsw              = d2*(swF2+d*(swF3+d*swF4));
530
531             /* Evaluate switch function */
532             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
533             felec            = felec*sw - rinv11*velec*dsw;
534             velec           *= sw;
535
536             /* Update potential sums from outer loop */
537             velecsum        += velec;
538
539             fscal            = felec;
540
541             /* Calculate temporary vectorial force */
542             tx               = fscal*dx11;
543             ty               = fscal*dy11;
544             tz               = fscal*dz11;
545
546             /* Update vectorial force */
547             fix1            += tx;
548             fiy1            += ty;
549             fiz1            += tz;
550             f[j_coord_offset+DIM*1+XX] -= tx;
551             f[j_coord_offset+DIM*1+YY] -= ty;
552             f[j_coord_offset+DIM*1+ZZ] -= tz;
553
554             }
555
556             /**************************
557              * CALCULATE INTERACTIONS *
558              **************************/
559
560             if (rsq12<rcutoff2)
561             {
562
563             r12              = rsq12*rinv12;
564
565             /* EWALD ELECTROSTATICS */
566
567             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
568             ewrt             = r12*ewtabscale;
569             ewitab           = ewrt;
570             eweps            = ewrt-ewitab;
571             ewitab           = 4*ewitab;
572             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
573             velec            = qq12*(rinv12-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
574             felec            = qq12*rinv12*(rinvsq12-felec);
575
576             d                = r12-rswitch;
577             d                = (d>0.0) ? d : 0.0;
578             d2               = d*d;
579             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
580
581             dsw              = d2*(swF2+d*(swF3+d*swF4));
582
583             /* Evaluate switch function */
584             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
585             felec            = felec*sw - rinv12*velec*dsw;
586             velec           *= sw;
587
588             /* Update potential sums from outer loop */
589             velecsum        += velec;
590
591             fscal            = felec;
592
593             /* Calculate temporary vectorial force */
594             tx               = fscal*dx12;
595             ty               = fscal*dy12;
596             tz               = fscal*dz12;
597
598             /* Update vectorial force */
599             fix1            += tx;
600             fiy1            += ty;
601             fiz1            += tz;
602             f[j_coord_offset+DIM*2+XX] -= tx;
603             f[j_coord_offset+DIM*2+YY] -= ty;
604             f[j_coord_offset+DIM*2+ZZ] -= tz;
605
606             }
607
608             /**************************
609              * CALCULATE INTERACTIONS *
610              **************************/
611
612             if (rsq20<rcutoff2)
613             {
614
615             r20              = rsq20*rinv20;
616
617             /* EWALD ELECTROSTATICS */
618
619             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
620             ewrt             = r20*ewtabscale;
621             ewitab           = ewrt;
622             eweps            = ewrt-ewitab;
623             ewitab           = 4*ewitab;
624             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
625             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
626             felec            = qq20*rinv20*(rinvsq20-felec);
627
628             d                = r20-rswitch;
629             d                = (d>0.0) ? d : 0.0;
630             d2               = d*d;
631             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
632
633             dsw              = d2*(swF2+d*(swF3+d*swF4));
634
635             /* Evaluate switch function */
636             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
637             felec            = felec*sw - rinv20*velec*dsw;
638             velec           *= sw;
639
640             /* Update potential sums from outer loop */
641             velecsum        += velec;
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             /**************************
661              * CALCULATE INTERACTIONS *
662              **************************/
663
664             if (rsq21<rcutoff2)
665             {
666
667             r21              = rsq21*rinv21;
668
669             /* EWALD ELECTROSTATICS */
670
671             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
672             ewrt             = r21*ewtabscale;
673             ewitab           = ewrt;
674             eweps            = ewrt-ewitab;
675             ewitab           = 4*ewitab;
676             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
677             velec            = qq21*(rinv21-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
678             felec            = qq21*rinv21*(rinvsq21-felec);
679
680             d                = r21-rswitch;
681             d                = (d>0.0) ? d : 0.0;
682             d2               = d*d;
683             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
684
685             dsw              = d2*(swF2+d*(swF3+d*swF4));
686
687             /* Evaluate switch function */
688             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
689             felec            = felec*sw - rinv21*velec*dsw;
690             velec           *= sw;
691
692             /* Update potential sums from outer loop */
693             velecsum        += velec;
694
695             fscal            = felec;
696
697             /* Calculate temporary vectorial force */
698             tx               = fscal*dx21;
699             ty               = fscal*dy21;
700             tz               = fscal*dz21;
701
702             /* Update vectorial force */
703             fix2            += tx;
704             fiy2            += ty;
705             fiz2            += tz;
706             f[j_coord_offset+DIM*1+XX] -= tx;
707             f[j_coord_offset+DIM*1+YY] -= ty;
708             f[j_coord_offset+DIM*1+ZZ] -= tz;
709
710             }
711
712             /**************************
713              * CALCULATE INTERACTIONS *
714              **************************/
715
716             if (rsq22<rcutoff2)
717             {
718
719             r22              = rsq22*rinv22;
720
721             /* EWALD ELECTROSTATICS */
722
723             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
724             ewrt             = r22*ewtabscale;
725             ewitab           = ewrt;
726             eweps            = ewrt-ewitab;
727             ewitab           = 4*ewitab;
728             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
729             velec            = qq22*(rinv22-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
730             felec            = qq22*rinv22*(rinvsq22-felec);
731
732             d                = r22-rswitch;
733             d                = (d>0.0) ? d : 0.0;
734             d2               = d*d;
735             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
736
737             dsw              = d2*(swF2+d*(swF3+d*swF4));
738
739             /* Evaluate switch function */
740             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
741             felec            = felec*sw - rinv22*velec*dsw;
742             velec           *= sw;
743
744             /* Update potential sums from outer loop */
745             velecsum        += velec;
746
747             fscal            = felec;
748
749             /* Calculate temporary vectorial force */
750             tx               = fscal*dx22;
751             ty               = fscal*dy22;
752             tz               = fscal*dz22;
753
754             /* Update vectorial force */
755             fix2            += tx;
756             fiy2            += ty;
757             fiz2            += tz;
758             f[j_coord_offset+DIM*2+XX] -= tx;
759             f[j_coord_offset+DIM*2+YY] -= ty;
760             f[j_coord_offset+DIM*2+ZZ] -= tz;
761
762             }
763
764             /* Inner loop uses 564 flops */
765         }
766         /* End of innermost loop */
767
768         tx = ty = tz = 0;
769         f[i_coord_offset+DIM*0+XX] += fix0;
770         f[i_coord_offset+DIM*0+YY] += fiy0;
771         f[i_coord_offset+DIM*0+ZZ] += fiz0;
772         tx                         += fix0;
773         ty                         += fiy0;
774         tz                         += fiz0;
775         f[i_coord_offset+DIM*1+XX] += fix1;
776         f[i_coord_offset+DIM*1+YY] += fiy1;
777         f[i_coord_offset+DIM*1+ZZ] += fiz1;
778         tx                         += fix1;
779         ty                         += fiy1;
780         tz                         += fiz1;
781         f[i_coord_offset+DIM*2+XX] += fix2;
782         f[i_coord_offset+DIM*2+YY] += fiy2;
783         f[i_coord_offset+DIM*2+ZZ] += fiz2;
784         tx                         += fix2;
785         ty                         += fiy2;
786         tz                         += fiz2;
787         fshift[i_shift_offset+XX]  += tx;
788         fshift[i_shift_offset+YY]  += ty;
789         fshift[i_shift_offset+ZZ]  += tz;
790
791         ggid                        = gid[iidx];
792         /* Update potential energies */
793         kernel_data->energygrp_elec[ggid] += velecsum;
794         kernel_data->energygrp_vdw[ggid] += vvdwsum;
795
796         /* Increment number of inner iterations */
797         inneriter                  += j_index_end - j_index_start;
798
799         /* Outer loop uses 32 flops */
800     }
801
802     /* Increment number of outer iterations */
803     outeriter        += nri;
804
805     /* Update outer/inner flops */
806
807     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*32 + inneriter*564);
808 }
809 /*
810  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSw_VdwBhamSw_GeomW3W3_F_c
811  * Electrostatics interaction: Ewald
812  * VdW interaction:            Buckingham
813  * Geometry:                   Water3-Water3
814  * Calculate force/pot:        Force
815  */
816 void
817 nb_kernel_ElecEwSw_VdwBhamSw_GeomW3W3_F_c
818                     (t_nblist                    * gmx_restrict       nlist,
819                      rvec                        * gmx_restrict          xx,
820                      rvec                        * gmx_restrict          ff,
821                      t_forcerec                  * gmx_restrict          fr,
822                      t_mdatoms                   * gmx_restrict     mdatoms,
823                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
824                      t_nrnb                      * gmx_restrict        nrnb)
825 {
826     int              i_shift_offset,i_coord_offset,j_coord_offset;
827     int              j_index_start,j_index_end;
828     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
829     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
830     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
831     real             *shiftvec,*fshift,*x,*f;
832     int              vdwioffset0;
833     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
834     int              vdwioffset1;
835     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
836     int              vdwioffset2;
837     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
838     int              vdwjidx0;
839     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
840     int              vdwjidx1;
841     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
842     int              vdwjidx2;
843     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
844     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
845     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
846     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
847     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
848     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
849     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
850     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
851     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
852     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
853     real             velec,felec,velecsum,facel,crf,krf,krf2;
854     real             *charge;
855     int              nvdwtype;
856     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
857     int              *vdwtype;
858     real             *vdwparam;
859     int              ewitab;
860     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
861     real             *ewtab;
862     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
863
864     x                = xx[0];
865     f                = ff[0];
866
867     nri              = nlist->nri;
868     iinr             = nlist->iinr;
869     jindex           = nlist->jindex;
870     jjnr             = nlist->jjnr;
871     shiftidx         = nlist->shift;
872     gid              = nlist->gid;
873     shiftvec         = fr->shift_vec[0];
874     fshift           = fr->fshift[0];
875     facel            = fr->epsfac;
876     charge           = mdatoms->chargeA;
877     nvdwtype         = fr->ntype;
878     vdwparam         = fr->nbfp;
879     vdwtype          = mdatoms->typeA;
880
881     sh_ewald         = fr->ic->sh_ewald;
882     ewtab            = fr->ic->tabq_coul_FDV0;
883     ewtabscale       = fr->ic->tabq_scale;
884     ewtabhalfspace   = 0.5/ewtabscale;
885
886     /* Setup water-specific parameters */
887     inr              = nlist->iinr[0];
888     iq0              = facel*charge[inr+0];
889     iq1              = facel*charge[inr+1];
890     iq2              = facel*charge[inr+2];
891     vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
892
893     jq0              = charge[inr+0];
894     jq1              = charge[inr+1];
895     jq2              = charge[inr+2];
896     vdwjidx0         = 3*vdwtype[inr+0];
897     qq00             = iq0*jq0;
898     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
899     cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
900     cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
901     qq01             = iq0*jq1;
902     qq02             = iq0*jq2;
903     qq10             = iq1*jq0;
904     qq11             = iq1*jq1;
905     qq12             = iq1*jq2;
906     qq20             = iq2*jq0;
907     qq21             = iq2*jq1;
908     qq22             = iq2*jq2;
909
910     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
911     rcutoff          = fr->rcoulomb;
912     rcutoff2         = rcutoff*rcutoff;
913
914     rswitch          = fr->rcoulomb_switch;
915     /* Setup switch parameters */
916     d                = rcutoff-rswitch;
917     swV3             = -10.0/(d*d*d);
918     swV4             =  15.0/(d*d*d*d);
919     swV5             =  -6.0/(d*d*d*d*d);
920     swF2             = -30.0/(d*d*d);
921     swF3             =  60.0/(d*d*d*d);
922     swF4             = -30.0/(d*d*d*d*d);
923
924     outeriter        = 0;
925     inneriter        = 0;
926
927     /* Start outer loop over neighborlists */
928     for(iidx=0; iidx<nri; iidx++)
929     {
930         /* Load shift vector for this list */
931         i_shift_offset   = DIM*shiftidx[iidx];
932         shX              = shiftvec[i_shift_offset+XX];
933         shY              = shiftvec[i_shift_offset+YY];
934         shZ              = shiftvec[i_shift_offset+ZZ];
935
936         /* Load limits for loop over neighbors */
937         j_index_start    = jindex[iidx];
938         j_index_end      = jindex[iidx+1];
939
940         /* Get outer coordinate index */
941         inr              = iinr[iidx];
942         i_coord_offset   = DIM*inr;
943
944         /* Load i particle coords and add shift vector */
945         ix0              = shX + x[i_coord_offset+DIM*0+XX];
946         iy0              = shY + x[i_coord_offset+DIM*0+YY];
947         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
948         ix1              = shX + x[i_coord_offset+DIM*1+XX];
949         iy1              = shY + x[i_coord_offset+DIM*1+YY];
950         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
951         ix2              = shX + x[i_coord_offset+DIM*2+XX];
952         iy2              = shY + x[i_coord_offset+DIM*2+YY];
953         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
954
955         fix0             = 0.0;
956         fiy0             = 0.0;
957         fiz0             = 0.0;
958         fix1             = 0.0;
959         fiy1             = 0.0;
960         fiz1             = 0.0;
961         fix2             = 0.0;
962         fiy2             = 0.0;
963         fiz2             = 0.0;
964
965         /* Start inner kernel loop */
966         for(jidx=j_index_start; jidx<j_index_end; jidx++)
967         {
968             /* Get j neighbor index, and coordinate index */
969             jnr              = jjnr[jidx];
970             j_coord_offset   = DIM*jnr;
971
972             /* load j atom coordinates */
973             jx0              = x[j_coord_offset+DIM*0+XX];
974             jy0              = x[j_coord_offset+DIM*0+YY];
975             jz0              = x[j_coord_offset+DIM*0+ZZ];
976             jx1              = x[j_coord_offset+DIM*1+XX];
977             jy1              = x[j_coord_offset+DIM*1+YY];
978             jz1              = x[j_coord_offset+DIM*1+ZZ];
979             jx2              = x[j_coord_offset+DIM*2+XX];
980             jy2              = x[j_coord_offset+DIM*2+YY];
981             jz2              = x[j_coord_offset+DIM*2+ZZ];
982
983             /* Calculate displacement vector */
984             dx00             = ix0 - jx0;
985             dy00             = iy0 - jy0;
986             dz00             = iz0 - jz0;
987             dx01             = ix0 - jx1;
988             dy01             = iy0 - jy1;
989             dz01             = iz0 - jz1;
990             dx02             = ix0 - jx2;
991             dy02             = iy0 - jy2;
992             dz02             = iz0 - jz2;
993             dx10             = ix1 - jx0;
994             dy10             = iy1 - jy0;
995             dz10             = iz1 - jz0;
996             dx11             = ix1 - jx1;
997             dy11             = iy1 - jy1;
998             dz11             = iz1 - jz1;
999             dx12             = ix1 - jx2;
1000             dy12             = iy1 - jy2;
1001             dz12             = iz1 - jz2;
1002             dx20             = ix2 - jx0;
1003             dy20             = iy2 - jy0;
1004             dz20             = iz2 - jz0;
1005             dx21             = ix2 - jx1;
1006             dy21             = iy2 - jy1;
1007             dz21             = iz2 - jz1;
1008             dx22             = ix2 - jx2;
1009             dy22             = iy2 - jy2;
1010             dz22             = iz2 - jz2;
1011
1012             /* Calculate squared distance and things based on it */
1013             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
1014             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
1015             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
1016             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
1017             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
1018             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
1019             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
1020             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
1021             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
1022
1023             rinv00           = gmx_invsqrt(rsq00);
1024             rinv01           = gmx_invsqrt(rsq01);
1025             rinv02           = gmx_invsqrt(rsq02);
1026             rinv10           = gmx_invsqrt(rsq10);
1027             rinv11           = gmx_invsqrt(rsq11);
1028             rinv12           = gmx_invsqrt(rsq12);
1029             rinv20           = gmx_invsqrt(rsq20);
1030             rinv21           = gmx_invsqrt(rsq21);
1031             rinv22           = gmx_invsqrt(rsq22);
1032
1033             rinvsq00         = rinv00*rinv00;
1034             rinvsq01         = rinv01*rinv01;
1035             rinvsq02         = rinv02*rinv02;
1036             rinvsq10         = rinv10*rinv10;
1037             rinvsq11         = rinv11*rinv11;
1038             rinvsq12         = rinv12*rinv12;
1039             rinvsq20         = rinv20*rinv20;
1040             rinvsq21         = rinv21*rinv21;
1041             rinvsq22         = rinv22*rinv22;
1042
1043             /**************************
1044              * CALCULATE INTERACTIONS *
1045              **************************/
1046
1047             if (rsq00<rcutoff2)
1048             {
1049
1050             r00              = rsq00*rinv00;
1051
1052             /* EWALD ELECTROSTATICS */
1053
1054             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1055             ewrt             = r00*ewtabscale;
1056             ewitab           = ewrt;
1057             eweps            = ewrt-ewitab;
1058             ewitab           = 4*ewitab;
1059             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1060             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1061             felec            = qq00*rinv00*(rinvsq00-felec);
1062
1063             /* BUCKINGHAM DISPERSION/REPULSION */
1064             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
1065             vvdw6            = c6_00*rinvsix;
1066             br               = cexp2_00*r00;
1067             vvdwexp          = cexp1_00*exp(-br);
1068             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
1069             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
1070
1071             d                = r00-rswitch;
1072             d                = (d>0.0) ? d : 0.0;
1073             d2               = d*d;
1074             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1075
1076             dsw              = d2*(swF2+d*(swF3+d*swF4));
1077
1078             /* Evaluate switch function */
1079             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1080             felec            = felec*sw - rinv00*velec*dsw;
1081             fvdw             = fvdw*sw - rinv00*vvdw*dsw;
1082
1083             fscal            = felec+fvdw;
1084
1085             /* Calculate temporary vectorial force */
1086             tx               = fscal*dx00;
1087             ty               = fscal*dy00;
1088             tz               = fscal*dz00;
1089
1090             /* Update vectorial force */
1091             fix0            += tx;
1092             fiy0            += ty;
1093             fiz0            += tz;
1094             f[j_coord_offset+DIM*0+XX] -= tx;
1095             f[j_coord_offset+DIM*0+YY] -= ty;
1096             f[j_coord_offset+DIM*0+ZZ] -= tz;
1097
1098             }
1099
1100             /**************************
1101              * CALCULATE INTERACTIONS *
1102              **************************/
1103
1104             if (rsq01<rcutoff2)
1105             {
1106
1107             r01              = rsq01*rinv01;
1108
1109             /* EWALD ELECTROSTATICS */
1110
1111             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1112             ewrt             = r01*ewtabscale;
1113             ewitab           = ewrt;
1114             eweps            = ewrt-ewitab;
1115             ewitab           = 4*ewitab;
1116             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1117             velec            = qq01*(rinv01-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1118             felec            = qq01*rinv01*(rinvsq01-felec);
1119
1120             d                = r01-rswitch;
1121             d                = (d>0.0) ? d : 0.0;
1122             d2               = d*d;
1123             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1124
1125             dsw              = d2*(swF2+d*(swF3+d*swF4));
1126
1127             /* Evaluate switch function */
1128             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1129             felec            = felec*sw - rinv01*velec*dsw;
1130
1131             fscal            = felec;
1132
1133             /* Calculate temporary vectorial force */
1134             tx               = fscal*dx01;
1135             ty               = fscal*dy01;
1136             tz               = fscal*dz01;
1137
1138             /* Update vectorial force */
1139             fix0            += tx;
1140             fiy0            += ty;
1141             fiz0            += tz;
1142             f[j_coord_offset+DIM*1+XX] -= tx;
1143             f[j_coord_offset+DIM*1+YY] -= ty;
1144             f[j_coord_offset+DIM*1+ZZ] -= tz;
1145
1146             }
1147
1148             /**************************
1149              * CALCULATE INTERACTIONS *
1150              **************************/
1151
1152             if (rsq02<rcutoff2)
1153             {
1154
1155             r02              = rsq02*rinv02;
1156
1157             /* EWALD ELECTROSTATICS */
1158
1159             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1160             ewrt             = r02*ewtabscale;
1161             ewitab           = ewrt;
1162             eweps            = ewrt-ewitab;
1163             ewitab           = 4*ewitab;
1164             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1165             velec            = qq02*(rinv02-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1166             felec            = qq02*rinv02*(rinvsq02-felec);
1167
1168             d                = r02-rswitch;
1169             d                = (d>0.0) ? d : 0.0;
1170             d2               = d*d;
1171             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1172
1173             dsw              = d2*(swF2+d*(swF3+d*swF4));
1174
1175             /* Evaluate switch function */
1176             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1177             felec            = felec*sw - rinv02*velec*dsw;
1178
1179             fscal            = felec;
1180
1181             /* Calculate temporary vectorial force */
1182             tx               = fscal*dx02;
1183             ty               = fscal*dy02;
1184             tz               = fscal*dz02;
1185
1186             /* Update vectorial force */
1187             fix0            += tx;
1188             fiy0            += ty;
1189             fiz0            += tz;
1190             f[j_coord_offset+DIM*2+XX] -= tx;
1191             f[j_coord_offset+DIM*2+YY] -= ty;
1192             f[j_coord_offset+DIM*2+ZZ] -= tz;
1193
1194             }
1195
1196             /**************************
1197              * CALCULATE INTERACTIONS *
1198              **************************/
1199
1200             if (rsq10<rcutoff2)
1201             {
1202
1203             r10              = rsq10*rinv10;
1204
1205             /* EWALD ELECTROSTATICS */
1206
1207             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1208             ewrt             = r10*ewtabscale;
1209             ewitab           = ewrt;
1210             eweps            = ewrt-ewitab;
1211             ewitab           = 4*ewitab;
1212             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1213             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1214             felec            = qq10*rinv10*(rinvsq10-felec);
1215
1216             d                = r10-rswitch;
1217             d                = (d>0.0) ? d : 0.0;
1218             d2               = d*d;
1219             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1220
1221             dsw              = d2*(swF2+d*(swF3+d*swF4));
1222
1223             /* Evaluate switch function */
1224             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1225             felec            = felec*sw - rinv10*velec*dsw;
1226
1227             fscal            = felec;
1228
1229             /* Calculate temporary vectorial force */
1230             tx               = fscal*dx10;
1231             ty               = fscal*dy10;
1232             tz               = fscal*dz10;
1233
1234             /* Update vectorial force */
1235             fix1            += tx;
1236             fiy1            += ty;
1237             fiz1            += tz;
1238             f[j_coord_offset+DIM*0+XX] -= tx;
1239             f[j_coord_offset+DIM*0+YY] -= ty;
1240             f[j_coord_offset+DIM*0+ZZ] -= tz;
1241
1242             }
1243
1244             /**************************
1245              * CALCULATE INTERACTIONS *
1246              **************************/
1247
1248             if (rsq11<rcutoff2)
1249             {
1250
1251             r11              = rsq11*rinv11;
1252
1253             /* EWALD ELECTROSTATICS */
1254
1255             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1256             ewrt             = r11*ewtabscale;
1257             ewitab           = ewrt;
1258             eweps            = ewrt-ewitab;
1259             ewitab           = 4*ewitab;
1260             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1261             velec            = qq11*(rinv11-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1262             felec            = qq11*rinv11*(rinvsq11-felec);
1263
1264             d                = r11-rswitch;
1265             d                = (d>0.0) ? d : 0.0;
1266             d2               = d*d;
1267             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1268
1269             dsw              = d2*(swF2+d*(swF3+d*swF4));
1270
1271             /* Evaluate switch function */
1272             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1273             felec            = felec*sw - rinv11*velec*dsw;
1274
1275             fscal            = felec;
1276
1277             /* Calculate temporary vectorial force */
1278             tx               = fscal*dx11;
1279             ty               = fscal*dy11;
1280             tz               = fscal*dz11;
1281
1282             /* Update vectorial force */
1283             fix1            += tx;
1284             fiy1            += ty;
1285             fiz1            += tz;
1286             f[j_coord_offset+DIM*1+XX] -= tx;
1287             f[j_coord_offset+DIM*1+YY] -= ty;
1288             f[j_coord_offset+DIM*1+ZZ] -= tz;
1289
1290             }
1291
1292             /**************************
1293              * CALCULATE INTERACTIONS *
1294              **************************/
1295
1296             if (rsq12<rcutoff2)
1297             {
1298
1299             r12              = rsq12*rinv12;
1300
1301             /* EWALD ELECTROSTATICS */
1302
1303             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1304             ewrt             = r12*ewtabscale;
1305             ewitab           = ewrt;
1306             eweps            = ewrt-ewitab;
1307             ewitab           = 4*ewitab;
1308             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1309             velec            = qq12*(rinv12-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1310             felec            = qq12*rinv12*(rinvsq12-felec);
1311
1312             d                = r12-rswitch;
1313             d                = (d>0.0) ? d : 0.0;
1314             d2               = d*d;
1315             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1316
1317             dsw              = d2*(swF2+d*(swF3+d*swF4));
1318
1319             /* Evaluate switch function */
1320             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1321             felec            = felec*sw - rinv12*velec*dsw;
1322
1323             fscal            = felec;
1324
1325             /* Calculate temporary vectorial force */
1326             tx               = fscal*dx12;
1327             ty               = fscal*dy12;
1328             tz               = fscal*dz12;
1329
1330             /* Update vectorial force */
1331             fix1            += tx;
1332             fiy1            += ty;
1333             fiz1            += tz;
1334             f[j_coord_offset+DIM*2+XX] -= tx;
1335             f[j_coord_offset+DIM*2+YY] -= ty;
1336             f[j_coord_offset+DIM*2+ZZ] -= tz;
1337
1338             }
1339
1340             /**************************
1341              * CALCULATE INTERACTIONS *
1342              **************************/
1343
1344             if (rsq20<rcutoff2)
1345             {
1346
1347             r20              = rsq20*rinv20;
1348
1349             /* EWALD ELECTROSTATICS */
1350
1351             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1352             ewrt             = r20*ewtabscale;
1353             ewitab           = ewrt;
1354             eweps            = ewrt-ewitab;
1355             ewitab           = 4*ewitab;
1356             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1357             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1358             felec            = qq20*rinv20*(rinvsq20-felec);
1359
1360             d                = r20-rswitch;
1361             d                = (d>0.0) ? d : 0.0;
1362             d2               = d*d;
1363             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1364
1365             dsw              = d2*(swF2+d*(swF3+d*swF4));
1366
1367             /* Evaluate switch function */
1368             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1369             felec            = felec*sw - rinv20*velec*dsw;
1370
1371             fscal            = felec;
1372
1373             /* Calculate temporary vectorial force */
1374             tx               = fscal*dx20;
1375             ty               = fscal*dy20;
1376             tz               = fscal*dz20;
1377
1378             /* Update vectorial force */
1379             fix2            += tx;
1380             fiy2            += ty;
1381             fiz2            += tz;
1382             f[j_coord_offset+DIM*0+XX] -= tx;
1383             f[j_coord_offset+DIM*0+YY] -= ty;
1384             f[j_coord_offset+DIM*0+ZZ] -= tz;
1385
1386             }
1387
1388             /**************************
1389              * CALCULATE INTERACTIONS *
1390              **************************/
1391
1392             if (rsq21<rcutoff2)
1393             {
1394
1395             r21              = rsq21*rinv21;
1396
1397             /* EWALD ELECTROSTATICS */
1398
1399             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1400             ewrt             = r21*ewtabscale;
1401             ewitab           = ewrt;
1402             eweps            = ewrt-ewitab;
1403             ewitab           = 4*ewitab;
1404             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1405             velec            = qq21*(rinv21-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1406             felec            = qq21*rinv21*(rinvsq21-felec);
1407
1408             d                = r21-rswitch;
1409             d                = (d>0.0) ? d : 0.0;
1410             d2               = d*d;
1411             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1412
1413             dsw              = d2*(swF2+d*(swF3+d*swF4));
1414
1415             /* Evaluate switch function */
1416             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1417             felec            = felec*sw - rinv21*velec*dsw;
1418
1419             fscal            = felec;
1420
1421             /* Calculate temporary vectorial force */
1422             tx               = fscal*dx21;
1423             ty               = fscal*dy21;
1424             tz               = fscal*dz21;
1425
1426             /* Update vectorial force */
1427             fix2            += tx;
1428             fiy2            += ty;
1429             fiz2            += tz;
1430             f[j_coord_offset+DIM*1+XX] -= tx;
1431             f[j_coord_offset+DIM*1+YY] -= ty;
1432             f[j_coord_offset+DIM*1+ZZ] -= tz;
1433
1434             }
1435
1436             /**************************
1437              * CALCULATE INTERACTIONS *
1438              **************************/
1439
1440             if (rsq22<rcutoff2)
1441             {
1442
1443             r22              = rsq22*rinv22;
1444
1445             /* EWALD ELECTROSTATICS */
1446
1447             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1448             ewrt             = r22*ewtabscale;
1449             ewitab           = ewrt;
1450             eweps            = ewrt-ewitab;
1451             ewitab           = 4*ewitab;
1452             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1453             velec            = qq22*(rinv22-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1454             felec            = qq22*rinv22*(rinvsq22-felec);
1455
1456             d                = r22-rswitch;
1457             d                = (d>0.0) ? d : 0.0;
1458             d2               = d*d;
1459             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1460
1461             dsw              = d2*(swF2+d*(swF3+d*swF4));
1462
1463             /* Evaluate switch function */
1464             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1465             felec            = felec*sw - rinv22*velec*dsw;
1466
1467             fscal            = felec;
1468
1469             /* Calculate temporary vectorial force */
1470             tx               = fscal*dx22;
1471             ty               = fscal*dy22;
1472             tz               = fscal*dz22;
1473
1474             /* Update vectorial force */
1475             fix2            += tx;
1476             fiy2            += ty;
1477             fiz2            += tz;
1478             f[j_coord_offset+DIM*2+XX] -= tx;
1479             f[j_coord_offset+DIM*2+YY] -= ty;
1480             f[j_coord_offset+DIM*2+ZZ] -= tz;
1481
1482             }
1483
1484             /* Inner loop uses 544 flops */
1485         }
1486         /* End of innermost loop */
1487
1488         tx = ty = tz = 0;
1489         f[i_coord_offset+DIM*0+XX] += fix0;
1490         f[i_coord_offset+DIM*0+YY] += fiy0;
1491         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1492         tx                         += fix0;
1493         ty                         += fiy0;
1494         tz                         += fiz0;
1495         f[i_coord_offset+DIM*1+XX] += fix1;
1496         f[i_coord_offset+DIM*1+YY] += fiy1;
1497         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1498         tx                         += fix1;
1499         ty                         += fiy1;
1500         tz                         += fiz1;
1501         f[i_coord_offset+DIM*2+XX] += fix2;
1502         f[i_coord_offset+DIM*2+YY] += fiy2;
1503         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1504         tx                         += fix2;
1505         ty                         += fiy2;
1506         tz                         += fiz2;
1507         fshift[i_shift_offset+XX]  += tx;
1508         fshift[i_shift_offset+YY]  += ty;
1509         fshift[i_shift_offset+ZZ]  += tz;
1510
1511         /* Increment number of inner iterations */
1512         inneriter                  += j_index_end - j_index_start;
1513
1514         /* Outer loop uses 30 flops */
1515     }
1516
1517     /* Increment number of outer iterations */
1518     outeriter        += nri;
1519
1520     /* Update outer/inner flops */
1521
1522     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*30 + inneriter*544);
1523 }