3b7ce598f0029d648cdfeb0b39a14826ff003b5d
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecCSTab_VdwBham_GeomW4W4_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 "types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "nrnb.h"
46
47 /*
48  * Gromacs nonbonded kernel:   nb_kernel_ElecCSTab_VdwBham_GeomW4W4_VF_c
49  * Electrostatics interaction: CubicSplineTable
50  * VdW interaction:            Buckingham
51  * Geometry:                   Water4-Water4
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecCSTab_VdwBham_GeomW4W4_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              vdwioffset3;
77     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
78     int              vdwjidx0;
79     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
80     int              vdwjidx1;
81     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
82     int              vdwjidx2;
83     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
84     int              vdwjidx3;
85     real             jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
86     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
87     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
88     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
89     real             dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13,cexp1_13,cexp2_13;
90     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
91     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
92     real             dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23,cexp1_23,cexp2_23;
93     real             dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31,cexp1_31,cexp2_31;
94     real             dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32,cexp1_32,cexp2_32;
95     real             dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33,cexp1_33,cexp2_33;
96     real             velec,felec,velecsum,facel,crf,krf,krf2;
97     real             *charge;
98     int              nvdwtype;
99     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
100     int              *vdwtype;
101     real             *vdwparam;
102     int              vfitab;
103     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
104     real             *vftab;
105
106     x                = xx[0];
107     f                = ff[0];
108
109     nri              = nlist->nri;
110     iinr             = nlist->iinr;
111     jindex           = nlist->jindex;
112     jjnr             = nlist->jjnr;
113     shiftidx         = nlist->shift;
114     gid              = nlist->gid;
115     shiftvec         = fr->shift_vec[0];
116     fshift           = fr->fshift[0];
117     facel            = fr->epsfac;
118     charge           = mdatoms->chargeA;
119     nvdwtype         = fr->ntype;
120     vdwparam         = fr->nbfp;
121     vdwtype          = mdatoms->typeA;
122
123     vftab            = kernel_data->table_elec->data;
124     vftabscale       = kernel_data->table_elec->scale;
125
126     /* Setup water-specific parameters */
127     inr              = nlist->iinr[0];
128     iq1              = facel*charge[inr+1];
129     iq2              = facel*charge[inr+2];
130     iq3              = facel*charge[inr+3];
131     vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
132
133     jq1              = charge[inr+1];
134     jq2              = charge[inr+2];
135     jq3              = charge[inr+3];
136     vdwjidx0         = 3*vdwtype[inr+0];
137     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
138     cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
139     cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
140     qq11             = iq1*jq1;
141     qq12             = iq1*jq2;
142     qq13             = iq1*jq3;
143     qq21             = iq2*jq1;
144     qq22             = iq2*jq2;
145     qq23             = iq2*jq3;
146     qq31             = iq3*jq1;
147     qq32             = iq3*jq2;
148     qq33             = iq3*jq3;
149
150     outeriter        = 0;
151     inneriter        = 0;
152
153     /* Start outer loop over neighborlists */
154     for(iidx=0; iidx<nri; iidx++)
155     {
156         /* Load shift vector for this list */
157         i_shift_offset   = DIM*shiftidx[iidx];
158         shX              = shiftvec[i_shift_offset+XX];
159         shY              = shiftvec[i_shift_offset+YY];
160         shZ              = shiftvec[i_shift_offset+ZZ];
161
162         /* Load limits for loop over neighbors */
163         j_index_start    = jindex[iidx];
164         j_index_end      = jindex[iidx+1];
165
166         /* Get outer coordinate index */
167         inr              = iinr[iidx];
168         i_coord_offset   = DIM*inr;
169
170         /* Load i particle coords and add shift vector */
171         ix0              = shX + x[i_coord_offset+DIM*0+XX];
172         iy0              = shY + x[i_coord_offset+DIM*0+YY];
173         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
174         ix1              = shX + x[i_coord_offset+DIM*1+XX];
175         iy1              = shY + x[i_coord_offset+DIM*1+YY];
176         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
177         ix2              = shX + x[i_coord_offset+DIM*2+XX];
178         iy2              = shY + x[i_coord_offset+DIM*2+YY];
179         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
180         ix3              = shX + x[i_coord_offset+DIM*3+XX];
181         iy3              = shY + x[i_coord_offset+DIM*3+YY];
182         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
183
184         fix0             = 0.0;
185         fiy0             = 0.0;
186         fiz0             = 0.0;
187         fix1             = 0.0;
188         fiy1             = 0.0;
189         fiz1             = 0.0;
190         fix2             = 0.0;
191         fiy2             = 0.0;
192         fiz2             = 0.0;
193         fix3             = 0.0;
194         fiy3             = 0.0;
195         fiz3             = 0.0;
196
197         /* Reset potential sums */
198         velecsum         = 0.0;
199         vvdwsum          = 0.0;
200
201         /* Start inner kernel loop */
202         for(jidx=j_index_start; jidx<j_index_end; jidx++)
203         {
204             /* Get j neighbor index, and coordinate index */
205             jnr              = jjnr[jidx];
206             j_coord_offset   = DIM*jnr;
207
208             /* load j atom coordinates */
209             jx0              = x[j_coord_offset+DIM*0+XX];
210             jy0              = x[j_coord_offset+DIM*0+YY];
211             jz0              = x[j_coord_offset+DIM*0+ZZ];
212             jx1              = x[j_coord_offset+DIM*1+XX];
213             jy1              = x[j_coord_offset+DIM*1+YY];
214             jz1              = x[j_coord_offset+DIM*1+ZZ];
215             jx2              = x[j_coord_offset+DIM*2+XX];
216             jy2              = x[j_coord_offset+DIM*2+YY];
217             jz2              = x[j_coord_offset+DIM*2+ZZ];
218             jx3              = x[j_coord_offset+DIM*3+XX];
219             jy3              = x[j_coord_offset+DIM*3+YY];
220             jz3              = x[j_coord_offset+DIM*3+ZZ];
221
222             /* Calculate displacement vector */
223             dx00             = ix0 - jx0;
224             dy00             = iy0 - jy0;
225             dz00             = iz0 - jz0;
226             dx11             = ix1 - jx1;
227             dy11             = iy1 - jy1;
228             dz11             = iz1 - jz1;
229             dx12             = ix1 - jx2;
230             dy12             = iy1 - jy2;
231             dz12             = iz1 - jz2;
232             dx13             = ix1 - jx3;
233             dy13             = iy1 - jy3;
234             dz13             = iz1 - jz3;
235             dx21             = ix2 - jx1;
236             dy21             = iy2 - jy1;
237             dz21             = iz2 - jz1;
238             dx22             = ix2 - jx2;
239             dy22             = iy2 - jy2;
240             dz22             = iz2 - jz2;
241             dx23             = ix2 - jx3;
242             dy23             = iy2 - jy3;
243             dz23             = iz2 - jz3;
244             dx31             = ix3 - jx1;
245             dy31             = iy3 - jy1;
246             dz31             = iz3 - jz1;
247             dx32             = ix3 - jx2;
248             dy32             = iy3 - jy2;
249             dz32             = iz3 - jz2;
250             dx33             = ix3 - jx3;
251             dy33             = iy3 - jy3;
252             dz33             = iz3 - jz3;
253
254             /* Calculate squared distance and things based on it */
255             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
256             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
257             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
258             rsq13            = dx13*dx13+dy13*dy13+dz13*dz13;
259             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
260             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
261             rsq23            = dx23*dx23+dy23*dy23+dz23*dz23;
262             rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
263             rsq32            = dx32*dx32+dy32*dy32+dz32*dz32;
264             rsq33            = dx33*dx33+dy33*dy33+dz33*dz33;
265
266             rinv00           = gmx_invsqrt(rsq00);
267             rinv11           = gmx_invsqrt(rsq11);
268             rinv12           = gmx_invsqrt(rsq12);
269             rinv13           = gmx_invsqrt(rsq13);
270             rinv21           = gmx_invsqrt(rsq21);
271             rinv22           = gmx_invsqrt(rsq22);
272             rinv23           = gmx_invsqrt(rsq23);
273             rinv31           = gmx_invsqrt(rsq31);
274             rinv32           = gmx_invsqrt(rsq32);
275             rinv33           = gmx_invsqrt(rsq33);
276
277             rinvsq00         = rinv00*rinv00;
278
279             /**************************
280              * CALCULATE INTERACTIONS *
281              **************************/
282
283             r00              = rsq00*rinv00;
284
285             /* BUCKINGHAM DISPERSION/REPULSION */
286             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
287             vvdw6            = c6_00*rinvsix;
288             br               = cexp2_00*r00;
289             vvdwexp          = cexp1_00*exp(-br);
290             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
291             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
292
293             /* Update potential sums from outer loop */
294             vvdwsum         += vvdw;
295
296             fscal            = fvdw;
297
298             /* Calculate temporary vectorial force */
299             tx               = fscal*dx00;
300             ty               = fscal*dy00;
301             tz               = fscal*dz00;
302
303             /* Update vectorial force */
304             fix0            += tx;
305             fiy0            += ty;
306             fiz0            += tz;
307             f[j_coord_offset+DIM*0+XX] -= tx;
308             f[j_coord_offset+DIM*0+YY] -= ty;
309             f[j_coord_offset+DIM*0+ZZ] -= tz;
310
311             /**************************
312              * CALCULATE INTERACTIONS *
313              **************************/
314
315             r11              = rsq11*rinv11;
316
317             /* Calculate table index by multiplying r with table scale and truncate to integer */
318             rt               = r11*vftabscale;
319             vfitab           = rt;
320             vfeps            = rt-vfitab;
321             vfitab           = 1*4*vfitab;
322
323             /* CUBIC SPLINE TABLE ELECTROSTATICS */
324             Y                = vftab[vfitab];
325             F                = vftab[vfitab+1];
326             Geps             = vfeps*vftab[vfitab+2];
327             Heps2            = vfeps*vfeps*vftab[vfitab+3];
328             Fp               = F+Geps+Heps2;
329             VV               = Y+vfeps*Fp;
330             velec            = qq11*VV;
331             FF               = Fp+Geps+2.0*Heps2;
332             felec            = -qq11*FF*vftabscale*rinv11;
333
334             /* Update potential sums from outer loop */
335             velecsum        += velec;
336
337             fscal            = felec;
338
339             /* Calculate temporary vectorial force */
340             tx               = fscal*dx11;
341             ty               = fscal*dy11;
342             tz               = fscal*dz11;
343
344             /* Update vectorial force */
345             fix1            += tx;
346             fiy1            += ty;
347             fiz1            += tz;
348             f[j_coord_offset+DIM*1+XX] -= tx;
349             f[j_coord_offset+DIM*1+YY] -= ty;
350             f[j_coord_offset+DIM*1+ZZ] -= tz;
351
352             /**************************
353              * CALCULATE INTERACTIONS *
354              **************************/
355
356             r12              = rsq12*rinv12;
357
358             /* Calculate table index by multiplying r with table scale and truncate to integer */
359             rt               = r12*vftabscale;
360             vfitab           = rt;
361             vfeps            = rt-vfitab;
362             vfitab           = 1*4*vfitab;
363
364             /* CUBIC SPLINE TABLE ELECTROSTATICS */
365             Y                = vftab[vfitab];
366             F                = vftab[vfitab+1];
367             Geps             = vfeps*vftab[vfitab+2];
368             Heps2            = vfeps*vfeps*vftab[vfitab+3];
369             Fp               = F+Geps+Heps2;
370             VV               = Y+vfeps*Fp;
371             velec            = qq12*VV;
372             FF               = Fp+Geps+2.0*Heps2;
373             felec            = -qq12*FF*vftabscale*rinv12;
374
375             /* Update potential sums from outer loop */
376             velecsum        += velec;
377
378             fscal            = felec;
379
380             /* Calculate temporary vectorial force */
381             tx               = fscal*dx12;
382             ty               = fscal*dy12;
383             tz               = fscal*dz12;
384
385             /* Update vectorial force */
386             fix1            += tx;
387             fiy1            += ty;
388             fiz1            += tz;
389             f[j_coord_offset+DIM*2+XX] -= tx;
390             f[j_coord_offset+DIM*2+YY] -= ty;
391             f[j_coord_offset+DIM*2+ZZ] -= tz;
392
393             /**************************
394              * CALCULATE INTERACTIONS *
395              **************************/
396
397             r13              = rsq13*rinv13;
398
399             /* Calculate table index by multiplying r with table scale and truncate to integer */
400             rt               = r13*vftabscale;
401             vfitab           = rt;
402             vfeps            = rt-vfitab;
403             vfitab           = 1*4*vfitab;
404
405             /* CUBIC SPLINE TABLE ELECTROSTATICS */
406             Y                = vftab[vfitab];
407             F                = vftab[vfitab+1];
408             Geps             = vfeps*vftab[vfitab+2];
409             Heps2            = vfeps*vfeps*vftab[vfitab+3];
410             Fp               = F+Geps+Heps2;
411             VV               = Y+vfeps*Fp;
412             velec            = qq13*VV;
413             FF               = Fp+Geps+2.0*Heps2;
414             felec            = -qq13*FF*vftabscale*rinv13;
415
416             /* Update potential sums from outer loop */
417             velecsum        += velec;
418
419             fscal            = felec;
420
421             /* Calculate temporary vectorial force */
422             tx               = fscal*dx13;
423             ty               = fscal*dy13;
424             tz               = fscal*dz13;
425
426             /* Update vectorial force */
427             fix1            += tx;
428             fiy1            += ty;
429             fiz1            += tz;
430             f[j_coord_offset+DIM*3+XX] -= tx;
431             f[j_coord_offset+DIM*3+YY] -= ty;
432             f[j_coord_offset+DIM*3+ZZ] -= tz;
433
434             /**************************
435              * CALCULATE INTERACTIONS *
436              **************************/
437
438             r21              = rsq21*rinv21;
439
440             /* Calculate table index by multiplying r with table scale and truncate to integer */
441             rt               = r21*vftabscale;
442             vfitab           = rt;
443             vfeps            = rt-vfitab;
444             vfitab           = 1*4*vfitab;
445
446             /* CUBIC SPLINE TABLE ELECTROSTATICS */
447             Y                = vftab[vfitab];
448             F                = vftab[vfitab+1];
449             Geps             = vfeps*vftab[vfitab+2];
450             Heps2            = vfeps*vfeps*vftab[vfitab+3];
451             Fp               = F+Geps+Heps2;
452             VV               = Y+vfeps*Fp;
453             velec            = qq21*VV;
454             FF               = Fp+Geps+2.0*Heps2;
455             felec            = -qq21*FF*vftabscale*rinv21;
456
457             /* Update potential sums from outer loop */
458             velecsum        += velec;
459
460             fscal            = felec;
461
462             /* Calculate temporary vectorial force */
463             tx               = fscal*dx21;
464             ty               = fscal*dy21;
465             tz               = fscal*dz21;
466
467             /* Update vectorial force */
468             fix2            += tx;
469             fiy2            += ty;
470             fiz2            += tz;
471             f[j_coord_offset+DIM*1+XX] -= tx;
472             f[j_coord_offset+DIM*1+YY] -= ty;
473             f[j_coord_offset+DIM*1+ZZ] -= tz;
474
475             /**************************
476              * CALCULATE INTERACTIONS *
477              **************************/
478
479             r22              = rsq22*rinv22;
480
481             /* Calculate table index by multiplying r with table scale and truncate to integer */
482             rt               = r22*vftabscale;
483             vfitab           = rt;
484             vfeps            = rt-vfitab;
485             vfitab           = 1*4*vfitab;
486
487             /* CUBIC SPLINE TABLE ELECTROSTATICS */
488             Y                = vftab[vfitab];
489             F                = vftab[vfitab+1];
490             Geps             = vfeps*vftab[vfitab+2];
491             Heps2            = vfeps*vfeps*vftab[vfitab+3];
492             Fp               = F+Geps+Heps2;
493             VV               = Y+vfeps*Fp;
494             velec            = qq22*VV;
495             FF               = Fp+Geps+2.0*Heps2;
496             felec            = -qq22*FF*vftabscale*rinv22;
497
498             /* Update potential sums from outer loop */
499             velecsum        += velec;
500
501             fscal            = felec;
502
503             /* Calculate temporary vectorial force */
504             tx               = fscal*dx22;
505             ty               = fscal*dy22;
506             tz               = fscal*dz22;
507
508             /* Update vectorial force */
509             fix2            += tx;
510             fiy2            += ty;
511             fiz2            += tz;
512             f[j_coord_offset+DIM*2+XX] -= tx;
513             f[j_coord_offset+DIM*2+YY] -= ty;
514             f[j_coord_offset+DIM*2+ZZ] -= tz;
515
516             /**************************
517              * CALCULATE INTERACTIONS *
518              **************************/
519
520             r23              = rsq23*rinv23;
521
522             /* Calculate table index by multiplying r with table scale and truncate to integer */
523             rt               = r23*vftabscale;
524             vfitab           = rt;
525             vfeps            = rt-vfitab;
526             vfitab           = 1*4*vfitab;
527
528             /* CUBIC SPLINE TABLE ELECTROSTATICS */
529             Y                = vftab[vfitab];
530             F                = vftab[vfitab+1];
531             Geps             = vfeps*vftab[vfitab+2];
532             Heps2            = vfeps*vfeps*vftab[vfitab+3];
533             Fp               = F+Geps+Heps2;
534             VV               = Y+vfeps*Fp;
535             velec            = qq23*VV;
536             FF               = Fp+Geps+2.0*Heps2;
537             felec            = -qq23*FF*vftabscale*rinv23;
538
539             /* Update potential sums from outer loop */
540             velecsum        += velec;
541
542             fscal            = felec;
543
544             /* Calculate temporary vectorial force */
545             tx               = fscal*dx23;
546             ty               = fscal*dy23;
547             tz               = fscal*dz23;
548
549             /* Update vectorial force */
550             fix2            += tx;
551             fiy2            += ty;
552             fiz2            += tz;
553             f[j_coord_offset+DIM*3+XX] -= tx;
554             f[j_coord_offset+DIM*3+YY] -= ty;
555             f[j_coord_offset+DIM*3+ZZ] -= tz;
556
557             /**************************
558              * CALCULATE INTERACTIONS *
559              **************************/
560
561             r31              = rsq31*rinv31;
562
563             /* Calculate table index by multiplying r with table scale and truncate to integer */
564             rt               = r31*vftabscale;
565             vfitab           = rt;
566             vfeps            = rt-vfitab;
567             vfitab           = 1*4*vfitab;
568
569             /* CUBIC SPLINE TABLE ELECTROSTATICS */
570             Y                = vftab[vfitab];
571             F                = vftab[vfitab+1];
572             Geps             = vfeps*vftab[vfitab+2];
573             Heps2            = vfeps*vfeps*vftab[vfitab+3];
574             Fp               = F+Geps+Heps2;
575             VV               = Y+vfeps*Fp;
576             velec            = qq31*VV;
577             FF               = Fp+Geps+2.0*Heps2;
578             felec            = -qq31*FF*vftabscale*rinv31;
579
580             /* Update potential sums from outer loop */
581             velecsum        += velec;
582
583             fscal            = felec;
584
585             /* Calculate temporary vectorial force */
586             tx               = fscal*dx31;
587             ty               = fscal*dy31;
588             tz               = fscal*dz31;
589
590             /* Update vectorial force */
591             fix3            += tx;
592             fiy3            += ty;
593             fiz3            += tz;
594             f[j_coord_offset+DIM*1+XX] -= tx;
595             f[j_coord_offset+DIM*1+YY] -= ty;
596             f[j_coord_offset+DIM*1+ZZ] -= tz;
597
598             /**************************
599              * CALCULATE INTERACTIONS *
600              **************************/
601
602             r32              = rsq32*rinv32;
603
604             /* Calculate table index by multiplying r with table scale and truncate to integer */
605             rt               = r32*vftabscale;
606             vfitab           = rt;
607             vfeps            = rt-vfitab;
608             vfitab           = 1*4*vfitab;
609
610             /* CUBIC SPLINE TABLE ELECTROSTATICS */
611             Y                = vftab[vfitab];
612             F                = vftab[vfitab+1];
613             Geps             = vfeps*vftab[vfitab+2];
614             Heps2            = vfeps*vfeps*vftab[vfitab+3];
615             Fp               = F+Geps+Heps2;
616             VV               = Y+vfeps*Fp;
617             velec            = qq32*VV;
618             FF               = Fp+Geps+2.0*Heps2;
619             felec            = -qq32*FF*vftabscale*rinv32;
620
621             /* Update potential sums from outer loop */
622             velecsum        += velec;
623
624             fscal            = felec;
625
626             /* Calculate temporary vectorial force */
627             tx               = fscal*dx32;
628             ty               = fscal*dy32;
629             tz               = fscal*dz32;
630
631             /* Update vectorial force */
632             fix3            += tx;
633             fiy3            += ty;
634             fiz3            += tz;
635             f[j_coord_offset+DIM*2+XX] -= tx;
636             f[j_coord_offset+DIM*2+YY] -= ty;
637             f[j_coord_offset+DIM*2+ZZ] -= tz;
638
639             /**************************
640              * CALCULATE INTERACTIONS *
641              **************************/
642
643             r33              = rsq33*rinv33;
644
645             /* Calculate table index by multiplying r with table scale and truncate to integer */
646             rt               = r33*vftabscale;
647             vfitab           = rt;
648             vfeps            = rt-vfitab;
649             vfitab           = 1*4*vfitab;
650
651             /* CUBIC SPLINE TABLE ELECTROSTATICS */
652             Y                = vftab[vfitab];
653             F                = vftab[vfitab+1];
654             Geps             = vfeps*vftab[vfitab+2];
655             Heps2            = vfeps*vfeps*vftab[vfitab+3];
656             Fp               = F+Geps+Heps2;
657             VV               = Y+vfeps*Fp;
658             velec            = qq33*VV;
659             FF               = Fp+Geps+2.0*Heps2;
660             felec            = -qq33*FF*vftabscale*rinv33;
661
662             /* Update potential sums from outer loop */
663             velecsum        += velec;
664
665             fscal            = felec;
666
667             /* Calculate temporary vectorial force */
668             tx               = fscal*dx33;
669             ty               = fscal*dy33;
670             tz               = fscal*dz33;
671
672             /* Update vectorial force */
673             fix3            += tx;
674             fiy3            += ty;
675             fiz3            += tz;
676             f[j_coord_offset+DIM*3+XX] -= tx;
677             f[j_coord_offset+DIM*3+YY] -= ty;
678             f[j_coord_offset+DIM*3+ZZ] -= tz;
679
680             /* Inner loop uses 430 flops */
681         }
682         /* End of innermost loop */
683
684         tx = ty = tz = 0;
685         f[i_coord_offset+DIM*0+XX] += fix0;
686         f[i_coord_offset+DIM*0+YY] += fiy0;
687         f[i_coord_offset+DIM*0+ZZ] += fiz0;
688         tx                         += fix0;
689         ty                         += fiy0;
690         tz                         += fiz0;
691         f[i_coord_offset+DIM*1+XX] += fix1;
692         f[i_coord_offset+DIM*1+YY] += fiy1;
693         f[i_coord_offset+DIM*1+ZZ] += fiz1;
694         tx                         += fix1;
695         ty                         += fiy1;
696         tz                         += fiz1;
697         f[i_coord_offset+DIM*2+XX] += fix2;
698         f[i_coord_offset+DIM*2+YY] += fiy2;
699         f[i_coord_offset+DIM*2+ZZ] += fiz2;
700         tx                         += fix2;
701         ty                         += fiy2;
702         tz                         += fiz2;
703         f[i_coord_offset+DIM*3+XX] += fix3;
704         f[i_coord_offset+DIM*3+YY] += fiy3;
705         f[i_coord_offset+DIM*3+ZZ] += fiz3;
706         tx                         += fix3;
707         ty                         += fiy3;
708         tz                         += fiz3;
709         fshift[i_shift_offset+XX]  += tx;
710         fshift[i_shift_offset+YY]  += ty;
711         fshift[i_shift_offset+ZZ]  += tz;
712
713         ggid                        = gid[iidx];
714         /* Update potential energies */
715         kernel_data->energygrp_elec[ggid] += velecsum;
716         kernel_data->energygrp_vdw[ggid] += vvdwsum;
717
718         /* Increment number of inner iterations */
719         inneriter                  += j_index_end - j_index_start;
720
721         /* Outer loop uses 41 flops */
722     }
723
724     /* Increment number of outer iterations */
725     outeriter        += nri;
726
727     /* Update outer/inner flops */
728
729     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_VF,outeriter*41 + inneriter*430);
730 }
731 /*
732  * Gromacs nonbonded kernel:   nb_kernel_ElecCSTab_VdwBham_GeomW4W4_F_c
733  * Electrostatics interaction: CubicSplineTable
734  * VdW interaction:            Buckingham
735  * Geometry:                   Water4-Water4
736  * Calculate force/pot:        Force
737  */
738 void
739 nb_kernel_ElecCSTab_VdwBham_GeomW4W4_F_c
740                     (t_nblist                    * gmx_restrict       nlist,
741                      rvec                        * gmx_restrict          xx,
742                      rvec                        * gmx_restrict          ff,
743                      t_forcerec                  * gmx_restrict          fr,
744                      t_mdatoms                   * gmx_restrict     mdatoms,
745                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
746                      t_nrnb                      * gmx_restrict        nrnb)
747 {
748     int              i_shift_offset,i_coord_offset,j_coord_offset;
749     int              j_index_start,j_index_end;
750     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
751     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
752     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
753     real             *shiftvec,*fshift,*x,*f;
754     int              vdwioffset0;
755     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
756     int              vdwioffset1;
757     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
758     int              vdwioffset2;
759     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
760     int              vdwioffset3;
761     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
762     int              vdwjidx0;
763     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
764     int              vdwjidx1;
765     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
766     int              vdwjidx2;
767     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
768     int              vdwjidx3;
769     real             jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
770     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
771     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
772     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
773     real             dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13,cexp1_13,cexp2_13;
774     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
775     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
776     real             dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23,cexp1_23,cexp2_23;
777     real             dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31,cexp1_31,cexp2_31;
778     real             dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32,cexp1_32,cexp2_32;
779     real             dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33,cexp1_33,cexp2_33;
780     real             velec,felec,velecsum,facel,crf,krf,krf2;
781     real             *charge;
782     int              nvdwtype;
783     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
784     int              *vdwtype;
785     real             *vdwparam;
786     int              vfitab;
787     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
788     real             *vftab;
789
790     x                = xx[0];
791     f                = ff[0];
792
793     nri              = nlist->nri;
794     iinr             = nlist->iinr;
795     jindex           = nlist->jindex;
796     jjnr             = nlist->jjnr;
797     shiftidx         = nlist->shift;
798     gid              = nlist->gid;
799     shiftvec         = fr->shift_vec[0];
800     fshift           = fr->fshift[0];
801     facel            = fr->epsfac;
802     charge           = mdatoms->chargeA;
803     nvdwtype         = fr->ntype;
804     vdwparam         = fr->nbfp;
805     vdwtype          = mdatoms->typeA;
806
807     vftab            = kernel_data->table_elec->data;
808     vftabscale       = kernel_data->table_elec->scale;
809
810     /* Setup water-specific parameters */
811     inr              = nlist->iinr[0];
812     iq1              = facel*charge[inr+1];
813     iq2              = facel*charge[inr+2];
814     iq3              = facel*charge[inr+3];
815     vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
816
817     jq1              = charge[inr+1];
818     jq2              = charge[inr+2];
819     jq3              = charge[inr+3];
820     vdwjidx0         = 3*vdwtype[inr+0];
821     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
822     cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
823     cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
824     qq11             = iq1*jq1;
825     qq12             = iq1*jq2;
826     qq13             = iq1*jq3;
827     qq21             = iq2*jq1;
828     qq22             = iq2*jq2;
829     qq23             = iq2*jq3;
830     qq31             = iq3*jq1;
831     qq32             = iq3*jq2;
832     qq33             = iq3*jq3;
833
834     outeriter        = 0;
835     inneriter        = 0;
836
837     /* Start outer loop over neighborlists */
838     for(iidx=0; iidx<nri; iidx++)
839     {
840         /* Load shift vector for this list */
841         i_shift_offset   = DIM*shiftidx[iidx];
842         shX              = shiftvec[i_shift_offset+XX];
843         shY              = shiftvec[i_shift_offset+YY];
844         shZ              = shiftvec[i_shift_offset+ZZ];
845
846         /* Load limits for loop over neighbors */
847         j_index_start    = jindex[iidx];
848         j_index_end      = jindex[iidx+1];
849
850         /* Get outer coordinate index */
851         inr              = iinr[iidx];
852         i_coord_offset   = DIM*inr;
853
854         /* Load i particle coords and add shift vector */
855         ix0              = shX + x[i_coord_offset+DIM*0+XX];
856         iy0              = shY + x[i_coord_offset+DIM*0+YY];
857         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
858         ix1              = shX + x[i_coord_offset+DIM*1+XX];
859         iy1              = shY + x[i_coord_offset+DIM*1+YY];
860         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
861         ix2              = shX + x[i_coord_offset+DIM*2+XX];
862         iy2              = shY + x[i_coord_offset+DIM*2+YY];
863         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
864         ix3              = shX + x[i_coord_offset+DIM*3+XX];
865         iy3              = shY + x[i_coord_offset+DIM*3+YY];
866         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
867
868         fix0             = 0.0;
869         fiy0             = 0.0;
870         fiz0             = 0.0;
871         fix1             = 0.0;
872         fiy1             = 0.0;
873         fiz1             = 0.0;
874         fix2             = 0.0;
875         fiy2             = 0.0;
876         fiz2             = 0.0;
877         fix3             = 0.0;
878         fiy3             = 0.0;
879         fiz3             = 0.0;
880
881         /* Start inner kernel loop */
882         for(jidx=j_index_start; jidx<j_index_end; jidx++)
883         {
884             /* Get j neighbor index, and coordinate index */
885             jnr              = jjnr[jidx];
886             j_coord_offset   = DIM*jnr;
887
888             /* load j atom coordinates */
889             jx0              = x[j_coord_offset+DIM*0+XX];
890             jy0              = x[j_coord_offset+DIM*0+YY];
891             jz0              = x[j_coord_offset+DIM*0+ZZ];
892             jx1              = x[j_coord_offset+DIM*1+XX];
893             jy1              = x[j_coord_offset+DIM*1+YY];
894             jz1              = x[j_coord_offset+DIM*1+ZZ];
895             jx2              = x[j_coord_offset+DIM*2+XX];
896             jy2              = x[j_coord_offset+DIM*2+YY];
897             jz2              = x[j_coord_offset+DIM*2+ZZ];
898             jx3              = x[j_coord_offset+DIM*3+XX];
899             jy3              = x[j_coord_offset+DIM*3+YY];
900             jz3              = x[j_coord_offset+DIM*3+ZZ];
901
902             /* Calculate displacement vector */
903             dx00             = ix0 - jx0;
904             dy00             = iy0 - jy0;
905             dz00             = iz0 - jz0;
906             dx11             = ix1 - jx1;
907             dy11             = iy1 - jy1;
908             dz11             = iz1 - jz1;
909             dx12             = ix1 - jx2;
910             dy12             = iy1 - jy2;
911             dz12             = iz1 - jz2;
912             dx13             = ix1 - jx3;
913             dy13             = iy1 - jy3;
914             dz13             = iz1 - jz3;
915             dx21             = ix2 - jx1;
916             dy21             = iy2 - jy1;
917             dz21             = iz2 - jz1;
918             dx22             = ix2 - jx2;
919             dy22             = iy2 - jy2;
920             dz22             = iz2 - jz2;
921             dx23             = ix2 - jx3;
922             dy23             = iy2 - jy3;
923             dz23             = iz2 - jz3;
924             dx31             = ix3 - jx1;
925             dy31             = iy3 - jy1;
926             dz31             = iz3 - jz1;
927             dx32             = ix3 - jx2;
928             dy32             = iy3 - jy2;
929             dz32             = iz3 - jz2;
930             dx33             = ix3 - jx3;
931             dy33             = iy3 - jy3;
932             dz33             = iz3 - jz3;
933
934             /* Calculate squared distance and things based on it */
935             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
936             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
937             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
938             rsq13            = dx13*dx13+dy13*dy13+dz13*dz13;
939             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
940             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
941             rsq23            = dx23*dx23+dy23*dy23+dz23*dz23;
942             rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
943             rsq32            = dx32*dx32+dy32*dy32+dz32*dz32;
944             rsq33            = dx33*dx33+dy33*dy33+dz33*dz33;
945
946             rinv00           = gmx_invsqrt(rsq00);
947             rinv11           = gmx_invsqrt(rsq11);
948             rinv12           = gmx_invsqrt(rsq12);
949             rinv13           = gmx_invsqrt(rsq13);
950             rinv21           = gmx_invsqrt(rsq21);
951             rinv22           = gmx_invsqrt(rsq22);
952             rinv23           = gmx_invsqrt(rsq23);
953             rinv31           = gmx_invsqrt(rsq31);
954             rinv32           = gmx_invsqrt(rsq32);
955             rinv33           = gmx_invsqrt(rsq33);
956
957             rinvsq00         = rinv00*rinv00;
958
959             /**************************
960              * CALCULATE INTERACTIONS *
961              **************************/
962
963             r00              = rsq00*rinv00;
964
965             /* BUCKINGHAM DISPERSION/REPULSION */
966             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
967             vvdw6            = c6_00*rinvsix;
968             br               = cexp2_00*r00;
969             vvdwexp          = cexp1_00*exp(-br);
970             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
971
972             fscal            = fvdw;
973
974             /* Calculate temporary vectorial force */
975             tx               = fscal*dx00;
976             ty               = fscal*dy00;
977             tz               = fscal*dz00;
978
979             /* Update vectorial force */
980             fix0            += tx;
981             fiy0            += ty;
982             fiz0            += tz;
983             f[j_coord_offset+DIM*0+XX] -= tx;
984             f[j_coord_offset+DIM*0+YY] -= ty;
985             f[j_coord_offset+DIM*0+ZZ] -= tz;
986
987             /**************************
988              * CALCULATE INTERACTIONS *
989              **************************/
990
991             r11              = rsq11*rinv11;
992
993             /* Calculate table index by multiplying r with table scale and truncate to integer */
994             rt               = r11*vftabscale;
995             vfitab           = rt;
996             vfeps            = rt-vfitab;
997             vfitab           = 1*4*vfitab;
998
999             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1000             F                = vftab[vfitab+1];
1001             Geps             = vfeps*vftab[vfitab+2];
1002             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1003             Fp               = F+Geps+Heps2;
1004             FF               = Fp+Geps+2.0*Heps2;
1005             felec            = -qq11*FF*vftabscale*rinv11;
1006
1007             fscal            = felec;
1008
1009             /* Calculate temporary vectorial force */
1010             tx               = fscal*dx11;
1011             ty               = fscal*dy11;
1012             tz               = fscal*dz11;
1013
1014             /* Update vectorial force */
1015             fix1            += tx;
1016             fiy1            += ty;
1017             fiz1            += tz;
1018             f[j_coord_offset+DIM*1+XX] -= tx;
1019             f[j_coord_offset+DIM*1+YY] -= ty;
1020             f[j_coord_offset+DIM*1+ZZ] -= tz;
1021
1022             /**************************
1023              * CALCULATE INTERACTIONS *
1024              **************************/
1025
1026             r12              = rsq12*rinv12;
1027
1028             /* Calculate table index by multiplying r with table scale and truncate to integer */
1029             rt               = r12*vftabscale;
1030             vfitab           = rt;
1031             vfeps            = rt-vfitab;
1032             vfitab           = 1*4*vfitab;
1033
1034             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1035             F                = vftab[vfitab+1];
1036             Geps             = vfeps*vftab[vfitab+2];
1037             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1038             Fp               = F+Geps+Heps2;
1039             FF               = Fp+Geps+2.0*Heps2;
1040             felec            = -qq12*FF*vftabscale*rinv12;
1041
1042             fscal            = felec;
1043
1044             /* Calculate temporary vectorial force */
1045             tx               = fscal*dx12;
1046             ty               = fscal*dy12;
1047             tz               = fscal*dz12;
1048
1049             /* Update vectorial force */
1050             fix1            += tx;
1051             fiy1            += ty;
1052             fiz1            += tz;
1053             f[j_coord_offset+DIM*2+XX] -= tx;
1054             f[j_coord_offset+DIM*2+YY] -= ty;
1055             f[j_coord_offset+DIM*2+ZZ] -= tz;
1056
1057             /**************************
1058              * CALCULATE INTERACTIONS *
1059              **************************/
1060
1061             r13              = rsq13*rinv13;
1062
1063             /* Calculate table index by multiplying r with table scale and truncate to integer */
1064             rt               = r13*vftabscale;
1065             vfitab           = rt;
1066             vfeps            = rt-vfitab;
1067             vfitab           = 1*4*vfitab;
1068
1069             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1070             F                = vftab[vfitab+1];
1071             Geps             = vfeps*vftab[vfitab+2];
1072             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1073             Fp               = F+Geps+Heps2;
1074             FF               = Fp+Geps+2.0*Heps2;
1075             felec            = -qq13*FF*vftabscale*rinv13;
1076
1077             fscal            = felec;
1078
1079             /* Calculate temporary vectorial force */
1080             tx               = fscal*dx13;
1081             ty               = fscal*dy13;
1082             tz               = fscal*dz13;
1083
1084             /* Update vectorial force */
1085             fix1            += tx;
1086             fiy1            += ty;
1087             fiz1            += tz;
1088             f[j_coord_offset+DIM*3+XX] -= tx;
1089             f[j_coord_offset+DIM*3+YY] -= ty;
1090             f[j_coord_offset+DIM*3+ZZ] -= tz;
1091
1092             /**************************
1093              * CALCULATE INTERACTIONS *
1094              **************************/
1095
1096             r21              = rsq21*rinv21;
1097
1098             /* Calculate table index by multiplying r with table scale and truncate to integer */
1099             rt               = r21*vftabscale;
1100             vfitab           = rt;
1101             vfeps            = rt-vfitab;
1102             vfitab           = 1*4*vfitab;
1103
1104             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1105             F                = vftab[vfitab+1];
1106             Geps             = vfeps*vftab[vfitab+2];
1107             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1108             Fp               = F+Geps+Heps2;
1109             FF               = Fp+Geps+2.0*Heps2;
1110             felec            = -qq21*FF*vftabscale*rinv21;
1111
1112             fscal            = felec;
1113
1114             /* Calculate temporary vectorial force */
1115             tx               = fscal*dx21;
1116             ty               = fscal*dy21;
1117             tz               = fscal*dz21;
1118
1119             /* Update vectorial force */
1120             fix2            += tx;
1121             fiy2            += ty;
1122             fiz2            += tz;
1123             f[j_coord_offset+DIM*1+XX] -= tx;
1124             f[j_coord_offset+DIM*1+YY] -= ty;
1125             f[j_coord_offset+DIM*1+ZZ] -= tz;
1126
1127             /**************************
1128              * CALCULATE INTERACTIONS *
1129              **************************/
1130
1131             r22              = rsq22*rinv22;
1132
1133             /* Calculate table index by multiplying r with table scale and truncate to integer */
1134             rt               = r22*vftabscale;
1135             vfitab           = rt;
1136             vfeps            = rt-vfitab;
1137             vfitab           = 1*4*vfitab;
1138
1139             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1140             F                = vftab[vfitab+1];
1141             Geps             = vfeps*vftab[vfitab+2];
1142             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1143             Fp               = F+Geps+Heps2;
1144             FF               = Fp+Geps+2.0*Heps2;
1145             felec            = -qq22*FF*vftabscale*rinv22;
1146
1147             fscal            = felec;
1148
1149             /* Calculate temporary vectorial force */
1150             tx               = fscal*dx22;
1151             ty               = fscal*dy22;
1152             tz               = fscal*dz22;
1153
1154             /* Update vectorial force */
1155             fix2            += tx;
1156             fiy2            += ty;
1157             fiz2            += tz;
1158             f[j_coord_offset+DIM*2+XX] -= tx;
1159             f[j_coord_offset+DIM*2+YY] -= ty;
1160             f[j_coord_offset+DIM*2+ZZ] -= tz;
1161
1162             /**************************
1163              * CALCULATE INTERACTIONS *
1164              **************************/
1165
1166             r23              = rsq23*rinv23;
1167
1168             /* Calculate table index by multiplying r with table scale and truncate to integer */
1169             rt               = r23*vftabscale;
1170             vfitab           = rt;
1171             vfeps            = rt-vfitab;
1172             vfitab           = 1*4*vfitab;
1173
1174             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1175             F                = vftab[vfitab+1];
1176             Geps             = vfeps*vftab[vfitab+2];
1177             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1178             Fp               = F+Geps+Heps2;
1179             FF               = Fp+Geps+2.0*Heps2;
1180             felec            = -qq23*FF*vftabscale*rinv23;
1181
1182             fscal            = felec;
1183
1184             /* Calculate temporary vectorial force */
1185             tx               = fscal*dx23;
1186             ty               = fscal*dy23;
1187             tz               = fscal*dz23;
1188
1189             /* Update vectorial force */
1190             fix2            += tx;
1191             fiy2            += ty;
1192             fiz2            += tz;
1193             f[j_coord_offset+DIM*3+XX] -= tx;
1194             f[j_coord_offset+DIM*3+YY] -= ty;
1195             f[j_coord_offset+DIM*3+ZZ] -= tz;
1196
1197             /**************************
1198              * CALCULATE INTERACTIONS *
1199              **************************/
1200
1201             r31              = rsq31*rinv31;
1202
1203             /* Calculate table index by multiplying r with table scale and truncate to integer */
1204             rt               = r31*vftabscale;
1205             vfitab           = rt;
1206             vfeps            = rt-vfitab;
1207             vfitab           = 1*4*vfitab;
1208
1209             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1210             F                = vftab[vfitab+1];
1211             Geps             = vfeps*vftab[vfitab+2];
1212             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1213             Fp               = F+Geps+Heps2;
1214             FF               = Fp+Geps+2.0*Heps2;
1215             felec            = -qq31*FF*vftabscale*rinv31;
1216
1217             fscal            = felec;
1218
1219             /* Calculate temporary vectorial force */
1220             tx               = fscal*dx31;
1221             ty               = fscal*dy31;
1222             tz               = fscal*dz31;
1223
1224             /* Update vectorial force */
1225             fix3            += tx;
1226             fiy3            += ty;
1227             fiz3            += tz;
1228             f[j_coord_offset+DIM*1+XX] -= tx;
1229             f[j_coord_offset+DIM*1+YY] -= ty;
1230             f[j_coord_offset+DIM*1+ZZ] -= tz;
1231
1232             /**************************
1233              * CALCULATE INTERACTIONS *
1234              **************************/
1235
1236             r32              = rsq32*rinv32;
1237
1238             /* Calculate table index by multiplying r with table scale and truncate to integer */
1239             rt               = r32*vftabscale;
1240             vfitab           = rt;
1241             vfeps            = rt-vfitab;
1242             vfitab           = 1*4*vfitab;
1243
1244             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1245             F                = vftab[vfitab+1];
1246             Geps             = vfeps*vftab[vfitab+2];
1247             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1248             Fp               = F+Geps+Heps2;
1249             FF               = Fp+Geps+2.0*Heps2;
1250             felec            = -qq32*FF*vftabscale*rinv32;
1251
1252             fscal            = felec;
1253
1254             /* Calculate temporary vectorial force */
1255             tx               = fscal*dx32;
1256             ty               = fscal*dy32;
1257             tz               = fscal*dz32;
1258
1259             /* Update vectorial force */
1260             fix3            += tx;
1261             fiy3            += ty;
1262             fiz3            += tz;
1263             f[j_coord_offset+DIM*2+XX] -= tx;
1264             f[j_coord_offset+DIM*2+YY] -= ty;
1265             f[j_coord_offset+DIM*2+ZZ] -= tz;
1266
1267             /**************************
1268              * CALCULATE INTERACTIONS *
1269              **************************/
1270
1271             r33              = rsq33*rinv33;
1272
1273             /* Calculate table index by multiplying r with table scale and truncate to integer */
1274             rt               = r33*vftabscale;
1275             vfitab           = rt;
1276             vfeps            = rt-vfitab;
1277             vfitab           = 1*4*vfitab;
1278
1279             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1280             F                = vftab[vfitab+1];
1281             Geps             = vfeps*vftab[vfitab+2];
1282             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1283             Fp               = F+Geps+Heps2;
1284             FF               = Fp+Geps+2.0*Heps2;
1285             felec            = -qq33*FF*vftabscale*rinv33;
1286
1287             fscal            = felec;
1288
1289             /* Calculate temporary vectorial force */
1290             tx               = fscal*dx33;
1291             ty               = fscal*dy33;
1292             tz               = fscal*dz33;
1293
1294             /* Update vectorial force */
1295             fix3            += tx;
1296             fiy3            += ty;
1297             fiz3            += tz;
1298             f[j_coord_offset+DIM*3+XX] -= tx;
1299             f[j_coord_offset+DIM*3+YY] -= ty;
1300             f[j_coord_offset+DIM*3+ZZ] -= tz;
1301
1302             /* Inner loop uses 391 flops */
1303         }
1304         /* End of innermost loop */
1305
1306         tx = ty = tz = 0;
1307         f[i_coord_offset+DIM*0+XX] += fix0;
1308         f[i_coord_offset+DIM*0+YY] += fiy0;
1309         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1310         tx                         += fix0;
1311         ty                         += fiy0;
1312         tz                         += fiz0;
1313         f[i_coord_offset+DIM*1+XX] += fix1;
1314         f[i_coord_offset+DIM*1+YY] += fiy1;
1315         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1316         tx                         += fix1;
1317         ty                         += fiy1;
1318         tz                         += fiz1;
1319         f[i_coord_offset+DIM*2+XX] += fix2;
1320         f[i_coord_offset+DIM*2+YY] += fiy2;
1321         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1322         tx                         += fix2;
1323         ty                         += fiy2;
1324         tz                         += fiz2;
1325         f[i_coord_offset+DIM*3+XX] += fix3;
1326         f[i_coord_offset+DIM*3+YY] += fiy3;
1327         f[i_coord_offset+DIM*3+ZZ] += fiz3;
1328         tx                         += fix3;
1329         ty                         += fiy3;
1330         tz                         += fiz3;
1331         fshift[i_shift_offset+XX]  += tx;
1332         fshift[i_shift_offset+YY]  += ty;
1333         fshift[i_shift_offset+ZZ]  += tz;
1334
1335         /* Increment number of inner iterations */
1336         inneriter                  += j_index_end - j_index_start;
1337
1338         /* Outer loop uses 39 flops */
1339     }
1340
1341     /* Increment number of outer iterations */
1342     outeriter        += nri;
1343
1344     /* Update outer/inner flops */
1345
1346     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*39 + inneriter*391);
1347 }