fe4d70927b1327ed99ca5a2a033fe42f61d5a846
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEw_VdwBham_GeomW4P1_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
46
47 /*
48  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwBham_GeomW4P1_VF_c
49  * Electrostatics interaction: Ewald
50  * VdW interaction:            Buckingham
51  * Geometry:                   Water4-Particle
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecEw_VdwBham_GeomW4P1_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     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
81     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
82     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
83     real             dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
84     real             velec,felec,velecsum,facel,crf,krf,krf2;
85     real             *charge;
86     int              nvdwtype;
87     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
88     int              *vdwtype;
89     real             *vdwparam;
90     int              ewitab;
91     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
92     real             *ewtab;
93
94     x                = xx[0];
95     f                = ff[0];
96
97     nri              = nlist->nri;
98     iinr             = nlist->iinr;
99     jindex           = nlist->jindex;
100     jjnr             = nlist->jjnr;
101     shiftidx         = nlist->shift;
102     gid              = nlist->gid;
103     shiftvec         = fr->shift_vec[0];
104     fshift           = fr->fshift[0];
105     facel            = fr->epsfac;
106     charge           = mdatoms->chargeA;
107     nvdwtype         = fr->ntype;
108     vdwparam         = fr->nbfp;
109     vdwtype          = mdatoms->typeA;
110
111     sh_ewald         = fr->ic->sh_ewald;
112     ewtab            = fr->ic->tabq_coul_FDV0;
113     ewtabscale       = fr->ic->tabq_scale;
114     ewtabhalfspace   = 0.5/ewtabscale;
115
116     /* Setup water-specific parameters */
117     inr              = nlist->iinr[0];
118     iq1              = facel*charge[inr+1];
119     iq2              = facel*charge[inr+2];
120     iq3              = facel*charge[inr+3];
121     vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
122
123     outeriter        = 0;
124     inneriter        = 0;
125
126     /* Start outer loop over neighborlists */
127     for(iidx=0; iidx<nri; iidx++)
128     {
129         /* Load shift vector for this list */
130         i_shift_offset   = DIM*shiftidx[iidx];
131         shX              = shiftvec[i_shift_offset+XX];
132         shY              = shiftvec[i_shift_offset+YY];
133         shZ              = shiftvec[i_shift_offset+ZZ];
134
135         /* Load limits for loop over neighbors */
136         j_index_start    = jindex[iidx];
137         j_index_end      = jindex[iidx+1];
138
139         /* Get outer coordinate index */
140         inr              = iinr[iidx];
141         i_coord_offset   = DIM*inr;
142
143         /* Load i particle coords and add shift vector */
144         ix0              = shX + x[i_coord_offset+DIM*0+XX];
145         iy0              = shY + x[i_coord_offset+DIM*0+YY];
146         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
147         ix1              = shX + x[i_coord_offset+DIM*1+XX];
148         iy1              = shY + x[i_coord_offset+DIM*1+YY];
149         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
150         ix2              = shX + x[i_coord_offset+DIM*2+XX];
151         iy2              = shY + x[i_coord_offset+DIM*2+YY];
152         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
153         ix3              = shX + x[i_coord_offset+DIM*3+XX];
154         iy3              = shY + x[i_coord_offset+DIM*3+YY];
155         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
156
157         fix0             = 0.0;
158         fiy0             = 0.0;
159         fiz0             = 0.0;
160         fix1             = 0.0;
161         fiy1             = 0.0;
162         fiz1             = 0.0;
163         fix2             = 0.0;
164         fiy2             = 0.0;
165         fiz2             = 0.0;
166         fix3             = 0.0;
167         fiy3             = 0.0;
168         fiz3             = 0.0;
169
170         /* Reset potential sums */
171         velecsum         = 0.0;
172         vvdwsum          = 0.0;
173
174         /* Start inner kernel loop */
175         for(jidx=j_index_start; jidx<j_index_end; jidx++)
176         {
177             /* Get j neighbor index, and coordinate index */
178             jnr              = jjnr[jidx];
179             j_coord_offset   = DIM*jnr;
180
181             /* load j atom coordinates */
182             jx0              = x[j_coord_offset+DIM*0+XX];
183             jy0              = x[j_coord_offset+DIM*0+YY];
184             jz0              = x[j_coord_offset+DIM*0+ZZ];
185
186             /* Calculate displacement vector */
187             dx00             = ix0 - jx0;
188             dy00             = iy0 - jy0;
189             dz00             = iz0 - jz0;
190             dx10             = ix1 - jx0;
191             dy10             = iy1 - jy0;
192             dz10             = iz1 - jz0;
193             dx20             = ix2 - jx0;
194             dy20             = iy2 - jy0;
195             dz20             = iz2 - jz0;
196             dx30             = ix3 - jx0;
197             dy30             = iy3 - jy0;
198             dz30             = iz3 - jz0;
199
200             /* Calculate squared distance and things based on it */
201             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
202             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
203             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
204             rsq30            = dx30*dx30+dy30*dy30+dz30*dz30;
205
206             rinv00           = gmx_invsqrt(rsq00);
207             rinv10           = gmx_invsqrt(rsq10);
208             rinv20           = gmx_invsqrt(rsq20);
209             rinv30           = gmx_invsqrt(rsq30);
210
211             rinvsq00         = rinv00*rinv00;
212             rinvsq10         = rinv10*rinv10;
213             rinvsq20         = rinv20*rinv20;
214             rinvsq30         = rinv30*rinv30;
215
216             /* Load parameters for j particles */
217             jq0              = charge[jnr+0];
218             vdwjidx0         = 3*vdwtype[jnr+0];
219
220             /**************************
221              * CALCULATE INTERACTIONS *
222              **************************/
223
224             r00              = rsq00*rinv00;
225
226             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
227             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
228             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
229
230             /* BUCKINGHAM DISPERSION/REPULSION */
231             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
232             vvdw6            = c6_00*rinvsix;
233             br               = cexp2_00*r00;
234             vvdwexp          = cexp1_00*exp(-br);
235             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
236             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
237
238             /* Update potential sums from outer loop */
239             vvdwsum         += vvdw;
240
241             fscal            = fvdw;
242
243             /* Calculate temporary vectorial force */
244             tx               = fscal*dx00;
245             ty               = fscal*dy00;
246             tz               = fscal*dz00;
247
248             /* Update vectorial force */
249             fix0            += tx;
250             fiy0            += ty;
251             fiz0            += tz;
252             f[j_coord_offset+DIM*0+XX] -= tx;
253             f[j_coord_offset+DIM*0+YY] -= ty;
254             f[j_coord_offset+DIM*0+ZZ] -= tz;
255
256             /**************************
257              * CALCULATE INTERACTIONS *
258              **************************/
259
260             r10              = rsq10*rinv10;
261
262             qq10             = iq1*jq0;
263
264             /* EWALD ELECTROSTATICS */
265
266             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
267             ewrt             = r10*ewtabscale;
268             ewitab           = ewrt;
269             eweps            = ewrt-ewitab;
270             ewitab           = 4*ewitab;
271             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
272             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
273             felec            = qq10*rinv10*(rinvsq10-felec);
274
275             /* Update potential sums from outer loop */
276             velecsum        += velec;
277
278             fscal            = felec;
279
280             /* Calculate temporary vectorial force */
281             tx               = fscal*dx10;
282             ty               = fscal*dy10;
283             tz               = fscal*dz10;
284
285             /* Update vectorial force */
286             fix1            += tx;
287             fiy1            += ty;
288             fiz1            += tz;
289             f[j_coord_offset+DIM*0+XX] -= tx;
290             f[j_coord_offset+DIM*0+YY] -= ty;
291             f[j_coord_offset+DIM*0+ZZ] -= tz;
292
293             /**************************
294              * CALCULATE INTERACTIONS *
295              **************************/
296
297             r20              = rsq20*rinv20;
298
299             qq20             = iq2*jq0;
300
301             /* EWALD ELECTROSTATICS */
302
303             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
304             ewrt             = r20*ewtabscale;
305             ewitab           = ewrt;
306             eweps            = ewrt-ewitab;
307             ewitab           = 4*ewitab;
308             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
309             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
310             felec            = qq20*rinv20*(rinvsq20-felec);
311
312             /* Update potential sums from outer loop */
313             velecsum        += velec;
314
315             fscal            = felec;
316
317             /* Calculate temporary vectorial force */
318             tx               = fscal*dx20;
319             ty               = fscal*dy20;
320             tz               = fscal*dz20;
321
322             /* Update vectorial force */
323             fix2            += tx;
324             fiy2            += ty;
325             fiz2            += tz;
326             f[j_coord_offset+DIM*0+XX] -= tx;
327             f[j_coord_offset+DIM*0+YY] -= ty;
328             f[j_coord_offset+DIM*0+ZZ] -= tz;
329
330             /**************************
331              * CALCULATE INTERACTIONS *
332              **************************/
333
334             r30              = rsq30*rinv30;
335
336             qq30             = iq3*jq0;
337
338             /* EWALD ELECTROSTATICS */
339
340             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
341             ewrt             = r30*ewtabscale;
342             ewitab           = ewrt;
343             eweps            = ewrt-ewitab;
344             ewitab           = 4*ewitab;
345             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
346             velec            = qq30*(rinv30-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
347             felec            = qq30*rinv30*(rinvsq30-felec);
348
349             /* Update potential sums from outer loop */
350             velecsum        += velec;
351
352             fscal            = felec;
353
354             /* Calculate temporary vectorial force */
355             tx               = fscal*dx30;
356             ty               = fscal*dy30;
357             tz               = fscal*dz30;
358
359             /* Update vectorial force */
360             fix3            += tx;
361             fiy3            += ty;
362             fiz3            += tz;
363             f[j_coord_offset+DIM*0+XX] -= tx;
364             f[j_coord_offset+DIM*0+YY] -= ty;
365             f[j_coord_offset+DIM*0+ZZ] -= tz;
366
367             /* Inner loop uses 184 flops */
368         }
369         /* End of innermost loop */
370
371         tx = ty = tz = 0;
372         f[i_coord_offset+DIM*0+XX] += fix0;
373         f[i_coord_offset+DIM*0+YY] += fiy0;
374         f[i_coord_offset+DIM*0+ZZ] += fiz0;
375         tx                         += fix0;
376         ty                         += fiy0;
377         tz                         += fiz0;
378         f[i_coord_offset+DIM*1+XX] += fix1;
379         f[i_coord_offset+DIM*1+YY] += fiy1;
380         f[i_coord_offset+DIM*1+ZZ] += fiz1;
381         tx                         += fix1;
382         ty                         += fiy1;
383         tz                         += fiz1;
384         f[i_coord_offset+DIM*2+XX] += fix2;
385         f[i_coord_offset+DIM*2+YY] += fiy2;
386         f[i_coord_offset+DIM*2+ZZ] += fiz2;
387         tx                         += fix2;
388         ty                         += fiy2;
389         tz                         += fiz2;
390         f[i_coord_offset+DIM*3+XX] += fix3;
391         f[i_coord_offset+DIM*3+YY] += fiy3;
392         f[i_coord_offset+DIM*3+ZZ] += fiz3;
393         tx                         += fix3;
394         ty                         += fiy3;
395         tz                         += fiz3;
396         fshift[i_shift_offset+XX]  += tx;
397         fshift[i_shift_offset+YY]  += ty;
398         fshift[i_shift_offset+ZZ]  += tz;
399
400         ggid                        = gid[iidx];
401         /* Update potential energies */
402         kernel_data->energygrp_elec[ggid] += velecsum;
403         kernel_data->energygrp_vdw[ggid] += vvdwsum;
404
405         /* Increment number of inner iterations */
406         inneriter                  += j_index_end - j_index_start;
407
408         /* Outer loop uses 41 flops */
409     }
410
411     /* Increment number of outer iterations */
412     outeriter        += nri;
413
414     /* Update outer/inner flops */
415
416     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*41 + inneriter*184);
417 }
418 /*
419  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwBham_GeomW4P1_F_c
420  * Electrostatics interaction: Ewald
421  * VdW interaction:            Buckingham
422  * Geometry:                   Water4-Particle
423  * Calculate force/pot:        Force
424  */
425 void
426 nb_kernel_ElecEw_VdwBham_GeomW4P1_F_c
427                     (t_nblist                    * gmx_restrict       nlist,
428                      rvec                        * gmx_restrict          xx,
429                      rvec                        * gmx_restrict          ff,
430                      t_forcerec                  * gmx_restrict          fr,
431                      t_mdatoms                   * gmx_restrict     mdatoms,
432                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
433                      t_nrnb                      * gmx_restrict        nrnb)
434 {
435     int              i_shift_offset,i_coord_offset,j_coord_offset;
436     int              j_index_start,j_index_end;
437     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
438     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
439     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
440     real             *shiftvec,*fshift,*x,*f;
441     int              vdwioffset0;
442     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
443     int              vdwioffset1;
444     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
445     int              vdwioffset2;
446     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
447     int              vdwioffset3;
448     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
449     int              vdwjidx0;
450     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
451     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
452     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
453     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
454     real             dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
455     real             velec,felec,velecsum,facel,crf,krf,krf2;
456     real             *charge;
457     int              nvdwtype;
458     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
459     int              *vdwtype;
460     real             *vdwparam;
461     int              ewitab;
462     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
463     real             *ewtab;
464
465     x                = xx[0];
466     f                = ff[0];
467
468     nri              = nlist->nri;
469     iinr             = nlist->iinr;
470     jindex           = nlist->jindex;
471     jjnr             = nlist->jjnr;
472     shiftidx         = nlist->shift;
473     gid              = nlist->gid;
474     shiftvec         = fr->shift_vec[0];
475     fshift           = fr->fshift[0];
476     facel            = fr->epsfac;
477     charge           = mdatoms->chargeA;
478     nvdwtype         = fr->ntype;
479     vdwparam         = fr->nbfp;
480     vdwtype          = mdatoms->typeA;
481
482     sh_ewald         = fr->ic->sh_ewald;
483     ewtab            = fr->ic->tabq_coul_F;
484     ewtabscale       = fr->ic->tabq_scale;
485     ewtabhalfspace   = 0.5/ewtabscale;
486
487     /* Setup water-specific parameters */
488     inr              = nlist->iinr[0];
489     iq1              = facel*charge[inr+1];
490     iq2              = facel*charge[inr+2];
491     iq3              = facel*charge[inr+3];
492     vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
493
494     outeriter        = 0;
495     inneriter        = 0;
496
497     /* Start outer loop over neighborlists */
498     for(iidx=0; iidx<nri; iidx++)
499     {
500         /* Load shift vector for this list */
501         i_shift_offset   = DIM*shiftidx[iidx];
502         shX              = shiftvec[i_shift_offset+XX];
503         shY              = shiftvec[i_shift_offset+YY];
504         shZ              = shiftvec[i_shift_offset+ZZ];
505
506         /* Load limits for loop over neighbors */
507         j_index_start    = jindex[iidx];
508         j_index_end      = jindex[iidx+1];
509
510         /* Get outer coordinate index */
511         inr              = iinr[iidx];
512         i_coord_offset   = DIM*inr;
513
514         /* Load i particle coords and add shift vector */
515         ix0              = shX + x[i_coord_offset+DIM*0+XX];
516         iy0              = shY + x[i_coord_offset+DIM*0+YY];
517         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
518         ix1              = shX + x[i_coord_offset+DIM*1+XX];
519         iy1              = shY + x[i_coord_offset+DIM*1+YY];
520         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
521         ix2              = shX + x[i_coord_offset+DIM*2+XX];
522         iy2              = shY + x[i_coord_offset+DIM*2+YY];
523         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
524         ix3              = shX + x[i_coord_offset+DIM*3+XX];
525         iy3              = shY + x[i_coord_offset+DIM*3+YY];
526         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
527
528         fix0             = 0.0;
529         fiy0             = 0.0;
530         fiz0             = 0.0;
531         fix1             = 0.0;
532         fiy1             = 0.0;
533         fiz1             = 0.0;
534         fix2             = 0.0;
535         fiy2             = 0.0;
536         fiz2             = 0.0;
537         fix3             = 0.0;
538         fiy3             = 0.0;
539         fiz3             = 0.0;
540
541         /* Start inner kernel loop */
542         for(jidx=j_index_start; jidx<j_index_end; jidx++)
543         {
544             /* Get j neighbor index, and coordinate index */
545             jnr              = jjnr[jidx];
546             j_coord_offset   = DIM*jnr;
547
548             /* load j atom coordinates */
549             jx0              = x[j_coord_offset+DIM*0+XX];
550             jy0              = x[j_coord_offset+DIM*0+YY];
551             jz0              = x[j_coord_offset+DIM*0+ZZ];
552
553             /* Calculate displacement vector */
554             dx00             = ix0 - jx0;
555             dy00             = iy0 - jy0;
556             dz00             = iz0 - jz0;
557             dx10             = ix1 - jx0;
558             dy10             = iy1 - jy0;
559             dz10             = iz1 - jz0;
560             dx20             = ix2 - jx0;
561             dy20             = iy2 - jy0;
562             dz20             = iz2 - jz0;
563             dx30             = ix3 - jx0;
564             dy30             = iy3 - jy0;
565             dz30             = iz3 - jz0;
566
567             /* Calculate squared distance and things based on it */
568             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
569             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
570             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
571             rsq30            = dx30*dx30+dy30*dy30+dz30*dz30;
572
573             rinv00           = gmx_invsqrt(rsq00);
574             rinv10           = gmx_invsqrt(rsq10);
575             rinv20           = gmx_invsqrt(rsq20);
576             rinv30           = gmx_invsqrt(rsq30);
577
578             rinvsq00         = rinv00*rinv00;
579             rinvsq10         = rinv10*rinv10;
580             rinvsq20         = rinv20*rinv20;
581             rinvsq30         = rinv30*rinv30;
582
583             /* Load parameters for j particles */
584             jq0              = charge[jnr+0];
585             vdwjidx0         = 3*vdwtype[jnr+0];
586
587             /**************************
588              * CALCULATE INTERACTIONS *
589              **************************/
590
591             r00              = rsq00*rinv00;
592
593             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
594             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
595             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
596
597             /* BUCKINGHAM DISPERSION/REPULSION */
598             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
599             vvdw6            = c6_00*rinvsix;
600             br               = cexp2_00*r00;
601             vvdwexp          = cexp1_00*exp(-br);
602             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
603
604             fscal            = fvdw;
605
606             /* Calculate temporary vectorial force */
607             tx               = fscal*dx00;
608             ty               = fscal*dy00;
609             tz               = fscal*dz00;
610
611             /* Update vectorial force */
612             fix0            += tx;
613             fiy0            += ty;
614             fiz0            += tz;
615             f[j_coord_offset+DIM*0+XX] -= tx;
616             f[j_coord_offset+DIM*0+YY] -= ty;
617             f[j_coord_offset+DIM*0+ZZ] -= tz;
618
619             /**************************
620              * CALCULATE INTERACTIONS *
621              **************************/
622
623             r10              = rsq10*rinv10;
624
625             qq10             = iq1*jq0;
626
627             /* EWALD ELECTROSTATICS */
628
629             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
630             ewrt             = r10*ewtabscale;
631             ewitab           = ewrt;
632             eweps            = ewrt-ewitab;
633             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
634             felec            = qq10*rinv10*(rinvsq10-felec);
635
636             fscal            = felec;
637
638             /* Calculate temporary vectorial force */
639             tx               = fscal*dx10;
640             ty               = fscal*dy10;
641             tz               = fscal*dz10;
642
643             /* Update vectorial force */
644             fix1            += tx;
645             fiy1            += ty;
646             fiz1            += tz;
647             f[j_coord_offset+DIM*0+XX] -= tx;
648             f[j_coord_offset+DIM*0+YY] -= ty;
649             f[j_coord_offset+DIM*0+ZZ] -= tz;
650
651             /**************************
652              * CALCULATE INTERACTIONS *
653              **************************/
654
655             r20              = rsq20*rinv20;
656
657             qq20             = iq2*jq0;
658
659             /* EWALD ELECTROSTATICS */
660
661             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
662             ewrt             = r20*ewtabscale;
663             ewitab           = ewrt;
664             eweps            = ewrt-ewitab;
665             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
666             felec            = qq20*rinv20*(rinvsq20-felec);
667
668             fscal            = felec;
669
670             /* Calculate temporary vectorial force */
671             tx               = fscal*dx20;
672             ty               = fscal*dy20;
673             tz               = fscal*dz20;
674
675             /* Update vectorial force */
676             fix2            += tx;
677             fiy2            += ty;
678             fiz2            += tz;
679             f[j_coord_offset+DIM*0+XX] -= tx;
680             f[j_coord_offset+DIM*0+YY] -= ty;
681             f[j_coord_offset+DIM*0+ZZ] -= tz;
682
683             /**************************
684              * CALCULATE INTERACTIONS *
685              **************************/
686
687             r30              = rsq30*rinv30;
688
689             qq30             = iq3*jq0;
690
691             /* EWALD ELECTROSTATICS */
692
693             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
694             ewrt             = r30*ewtabscale;
695             ewitab           = ewrt;
696             eweps            = ewrt-ewitab;
697             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
698             felec            = qq30*rinv30*(rinvsq30-felec);
699
700             fscal            = felec;
701
702             /* Calculate temporary vectorial force */
703             tx               = fscal*dx30;
704             ty               = fscal*dy30;
705             tz               = fscal*dz30;
706
707             /* Update vectorial force */
708             fix3            += tx;
709             fiy3            += ty;
710             fiz3            += tz;
711             f[j_coord_offset+DIM*0+XX] -= tx;
712             f[j_coord_offset+DIM*0+YY] -= ty;
713             f[j_coord_offset+DIM*0+ZZ] -= tz;
714
715             /* Inner loop uses 160 flops */
716         }
717         /* End of innermost loop */
718
719         tx = ty = tz = 0;
720         f[i_coord_offset+DIM*0+XX] += fix0;
721         f[i_coord_offset+DIM*0+YY] += fiy0;
722         f[i_coord_offset+DIM*0+ZZ] += fiz0;
723         tx                         += fix0;
724         ty                         += fiy0;
725         tz                         += fiz0;
726         f[i_coord_offset+DIM*1+XX] += fix1;
727         f[i_coord_offset+DIM*1+YY] += fiy1;
728         f[i_coord_offset+DIM*1+ZZ] += fiz1;
729         tx                         += fix1;
730         ty                         += fiy1;
731         tz                         += fiz1;
732         f[i_coord_offset+DIM*2+XX] += fix2;
733         f[i_coord_offset+DIM*2+YY] += fiy2;
734         f[i_coord_offset+DIM*2+ZZ] += fiz2;
735         tx                         += fix2;
736         ty                         += fiy2;
737         tz                         += fiz2;
738         f[i_coord_offset+DIM*3+XX] += fix3;
739         f[i_coord_offset+DIM*3+YY] += fiy3;
740         f[i_coord_offset+DIM*3+ZZ] += fiz3;
741         tx                         += fix3;
742         ty                         += fiy3;
743         tz                         += fiz3;
744         fshift[i_shift_offset+XX]  += tx;
745         fshift[i_shift_offset+YY]  += ty;
746         fshift[i_shift_offset+ZZ]  += tz;
747
748         /* Increment number of inner iterations */
749         inneriter                  += j_index_end - j_index_start;
750
751         /* Outer loop uses 39 flops */
752     }
753
754     /* Increment number of outer iterations */
755     outeriter        += nri;
756
757     /* Update outer/inner flops */
758
759     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*39 + inneriter*160);
760 }