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