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