Version bumps after new release
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecGB_VdwBham_GeomP1P1_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013, 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 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
46 #include "vec.h"
47 #include "nrnb.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecGB_VdwBham_GeomP1P1_VF_c
51  * Electrostatics interaction: GeneralizedBorn
52  * VdW interaction:            Buckingham
53  * Geometry:                   Particle-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecGB_VdwBham_GeomP1P1_VF_c
58                     (t_nblist                    * gmx_restrict       nlist,
59                      rvec                        * gmx_restrict          xx,
60                      rvec                        * gmx_restrict          ff,
61                      t_forcerec                  * gmx_restrict          fr,
62                      t_mdatoms                   * gmx_restrict     mdatoms,
63                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64                      t_nrnb                      * gmx_restrict        nrnb)
65 {
66     int              i_shift_offset,i_coord_offset,j_coord_offset;
67     int              j_index_start,j_index_end;
68     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
69     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
70     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
71     real             *shiftvec,*fshift,*x,*f;
72     int              vdwioffset0;
73     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
74     int              vdwjidx0;
75     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
76     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
77     real             velec,felec,velecsum,facel,crf,krf,krf2;
78     real             *charge;
79     int              gbitab;
80     real             vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,dvdatmp;
81     real             *invsqrta,*dvda,*gbtab;
82     int              nvdwtype;
83     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
84     int              *vdwtype;
85     real             *vdwparam;
86     int              vfitab;
87     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
88     real             *vftab;
89
90     x                = xx[0];
91     f                = ff[0];
92
93     nri              = nlist->nri;
94     iinr             = nlist->iinr;
95     jindex           = nlist->jindex;
96     jjnr             = nlist->jjnr;
97     shiftidx         = nlist->shift;
98     gid              = nlist->gid;
99     shiftvec         = fr->shift_vec[0];
100     fshift           = fr->fshift[0];
101     facel            = fr->epsfac;
102     charge           = mdatoms->chargeA;
103     nvdwtype         = fr->ntype;
104     vdwparam         = fr->nbfp;
105     vdwtype          = mdatoms->typeA;
106
107     invsqrta         = fr->invsqrta;
108     dvda             = fr->dvda;
109     gbtabscale       = fr->gbtab.scale;
110     gbtab            = fr->gbtab.data;
111     gbinvepsdiff     = (1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent);
112
113     outeriter        = 0;
114     inneriter        = 0;
115
116     /* Start outer loop over neighborlists */
117     for(iidx=0; iidx<nri; iidx++)
118     {
119         /* Load shift vector for this list */
120         i_shift_offset   = DIM*shiftidx[iidx];
121         shX              = shiftvec[i_shift_offset+XX];
122         shY              = shiftvec[i_shift_offset+YY];
123         shZ              = shiftvec[i_shift_offset+ZZ];
124
125         /* Load limits for loop over neighbors */
126         j_index_start    = jindex[iidx];
127         j_index_end      = jindex[iidx+1];
128
129         /* Get outer coordinate index */
130         inr              = iinr[iidx];
131         i_coord_offset   = DIM*inr;
132
133         /* Load i particle coords and add shift vector */
134         ix0              = shX + x[i_coord_offset+DIM*0+XX];
135         iy0              = shY + x[i_coord_offset+DIM*0+YY];
136         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
137
138         fix0             = 0.0;
139         fiy0             = 0.0;
140         fiz0             = 0.0;
141
142         /* Load parameters for i particles */
143         iq0              = facel*charge[inr+0];
144         isai0            = invsqrta[inr+0];
145         vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
146
147         /* Reset potential sums */
148         velecsum         = 0.0;
149         vgbsum           = 0.0;
150         vvdwsum          = 0.0;
151         dvdasum          = 0.0;
152
153         /* Start inner kernel loop */
154         for(jidx=j_index_start; jidx<j_index_end; jidx++)
155         {
156             /* Get j neighbor index, and coordinate index */
157             jnr              = jjnr[jidx];
158             j_coord_offset   = DIM*jnr;
159
160             /* load j atom coordinates */
161             jx0              = x[j_coord_offset+DIM*0+XX];
162             jy0              = x[j_coord_offset+DIM*0+YY];
163             jz0              = x[j_coord_offset+DIM*0+ZZ];
164
165             /* Calculate displacement vector */
166             dx00             = ix0 - jx0;
167             dy00             = iy0 - jy0;
168             dz00             = iz0 - jz0;
169
170             /* Calculate squared distance and things based on it */
171             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
172
173             rinv00           = gmx_invsqrt(rsq00);
174
175             rinvsq00         = rinv00*rinv00;
176
177             /* Load parameters for j particles */
178             jq0              = charge[jnr+0];
179             isaj0           = invsqrta[jnr+0];
180             vdwjidx0         = 3*vdwtype[jnr+0];
181
182             /**************************
183              * CALCULATE INTERACTIONS *
184              **************************/
185
186             r00              = rsq00*rinv00;
187
188             qq00             = iq0*jq0;
189             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
190             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
191             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
192
193             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
194             isaprod          = isai0*isaj0;
195             gbqqfactor       = isaprod*(-qq00)*gbinvepsdiff;
196             gbscale          = isaprod*gbtabscale;
197             dvdaj            = dvda[jnr+0];
198
199             /* Calculate generalized born table index - this is a separate table from the normal one,
200              * but we use the same procedure by multiplying r with scale and truncating to integer.
201              */
202             rt               = r00*gbscale;
203             gbitab           = rt;
204             gbeps            = rt-gbitab;
205             gbitab           = 4*gbitab;
206
207             Y                = gbtab[gbitab];
208             F                = gbtab[gbitab+1];
209             Geps             = gbeps*gbtab[gbitab+2];
210             Heps2            = gbeps*gbeps*gbtab[gbitab+3];
211             Fp               = F+Geps+Heps2;
212             VV               = Y+gbeps*Fp;
213             vgb              = gbqqfactor*VV;
214
215             FF               = Fp+Geps+2.0*Heps2;
216             fgb              = gbqqfactor*FF*gbscale;
217             dvdatmp          = -0.5*(vgb+fgb*r00);
218             dvdasum          = dvdasum + dvdatmp;
219             dvda[jnr]        = dvdaj+dvdatmp*isaj0*isaj0;
220             velec            = qq00*rinv00;
221             felec            = (velec*rinv00-fgb)*rinv00;
222
223             /* BUCKINGHAM DISPERSION/REPULSION */
224             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
225             vvdw6            = c6_00*rinvsix;
226             br               = cexp2_00*r00;
227             vvdwexp          = cexp1_00*exp(-br);
228             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
229             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
230
231             /* Update potential sums from outer loop */
232             velecsum        += velec;
233             vgbsum          += vgb;
234             vvdwsum         += vvdw;
235
236             fscal            = felec+fvdw;
237
238             /* Calculate temporary vectorial force */
239             tx               = fscal*dx00;
240             ty               = fscal*dy00;
241             tz               = fscal*dz00;
242
243             /* Update vectorial force */
244             fix0            += tx;
245             fiy0            += ty;
246             fiz0            += tz;
247             f[j_coord_offset+DIM*0+XX] -= tx;
248             f[j_coord_offset+DIM*0+YY] -= ty;
249             f[j_coord_offset+DIM*0+ZZ] -= tz;
250
251             /* Inner loop uses 97 flops */
252         }
253         /* End of innermost loop */
254
255         tx = ty = tz = 0;
256         f[i_coord_offset+DIM*0+XX] += fix0;
257         f[i_coord_offset+DIM*0+YY] += fiy0;
258         f[i_coord_offset+DIM*0+ZZ] += fiz0;
259         tx                         += fix0;
260         ty                         += fiy0;
261         tz                         += fiz0;
262         fshift[i_shift_offset+XX]  += tx;
263         fshift[i_shift_offset+YY]  += ty;
264         fshift[i_shift_offset+ZZ]  += tz;
265
266         ggid                        = gid[iidx];
267         /* Update potential energies */
268         kernel_data->energygrp_elec[ggid] += velecsum;
269         kernel_data->energygrp_polarization[ggid] += vgbsum;
270         kernel_data->energygrp_vdw[ggid] += vvdwsum;
271         dvda[inr]                   = dvda[inr] + dvdasum*isai0*isai0;
272
273         /* Increment number of inner iterations */
274         inneriter                  += j_index_end - j_index_start;
275
276         /* Outer loop uses 16 flops */
277     }
278
279     /* Increment number of outer iterations */
280     outeriter        += nri;
281
282     /* Update outer/inner flops */
283
284     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*16 + inneriter*97);
285 }
286 /*
287  * Gromacs nonbonded kernel:   nb_kernel_ElecGB_VdwBham_GeomP1P1_F_c
288  * Electrostatics interaction: GeneralizedBorn
289  * VdW interaction:            Buckingham
290  * Geometry:                   Particle-Particle
291  * Calculate force/pot:        Force
292  */
293 void
294 nb_kernel_ElecGB_VdwBham_GeomP1P1_F_c
295                     (t_nblist                    * gmx_restrict       nlist,
296                      rvec                        * gmx_restrict          xx,
297                      rvec                        * gmx_restrict          ff,
298                      t_forcerec                  * gmx_restrict          fr,
299                      t_mdatoms                   * gmx_restrict     mdatoms,
300                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
301                      t_nrnb                      * gmx_restrict        nrnb)
302 {
303     int              i_shift_offset,i_coord_offset,j_coord_offset;
304     int              j_index_start,j_index_end;
305     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
306     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
307     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
308     real             *shiftvec,*fshift,*x,*f;
309     int              vdwioffset0;
310     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
311     int              vdwjidx0;
312     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
313     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
314     real             velec,felec,velecsum,facel,crf,krf,krf2;
315     real             *charge;
316     int              gbitab;
317     real             vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,dvdatmp;
318     real             *invsqrta,*dvda,*gbtab;
319     int              nvdwtype;
320     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
321     int              *vdwtype;
322     real             *vdwparam;
323     int              vfitab;
324     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
325     real             *vftab;
326
327     x                = xx[0];
328     f                = ff[0];
329
330     nri              = nlist->nri;
331     iinr             = nlist->iinr;
332     jindex           = nlist->jindex;
333     jjnr             = nlist->jjnr;
334     shiftidx         = nlist->shift;
335     gid              = nlist->gid;
336     shiftvec         = fr->shift_vec[0];
337     fshift           = fr->fshift[0];
338     facel            = fr->epsfac;
339     charge           = mdatoms->chargeA;
340     nvdwtype         = fr->ntype;
341     vdwparam         = fr->nbfp;
342     vdwtype          = mdatoms->typeA;
343
344     invsqrta         = fr->invsqrta;
345     dvda             = fr->dvda;
346     gbtabscale       = fr->gbtab.scale;
347     gbtab            = fr->gbtab.data;
348     gbinvepsdiff     = (1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent);
349
350     outeriter        = 0;
351     inneriter        = 0;
352
353     /* Start outer loop over neighborlists */
354     for(iidx=0; iidx<nri; iidx++)
355     {
356         /* Load shift vector for this list */
357         i_shift_offset   = DIM*shiftidx[iidx];
358         shX              = shiftvec[i_shift_offset+XX];
359         shY              = shiftvec[i_shift_offset+YY];
360         shZ              = shiftvec[i_shift_offset+ZZ];
361
362         /* Load limits for loop over neighbors */
363         j_index_start    = jindex[iidx];
364         j_index_end      = jindex[iidx+1];
365
366         /* Get outer coordinate index */
367         inr              = iinr[iidx];
368         i_coord_offset   = DIM*inr;
369
370         /* Load i particle coords and add shift vector */
371         ix0              = shX + x[i_coord_offset+DIM*0+XX];
372         iy0              = shY + x[i_coord_offset+DIM*0+YY];
373         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
374
375         fix0             = 0.0;
376         fiy0             = 0.0;
377         fiz0             = 0.0;
378
379         /* Load parameters for i particles */
380         iq0              = facel*charge[inr+0];
381         isai0            = invsqrta[inr+0];
382         vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
383
384         dvdasum          = 0.0;
385
386         /* Start inner kernel loop */
387         for(jidx=j_index_start; jidx<j_index_end; jidx++)
388         {
389             /* Get j neighbor index, and coordinate index */
390             jnr              = jjnr[jidx];
391             j_coord_offset   = DIM*jnr;
392
393             /* load j atom coordinates */
394             jx0              = x[j_coord_offset+DIM*0+XX];
395             jy0              = x[j_coord_offset+DIM*0+YY];
396             jz0              = x[j_coord_offset+DIM*0+ZZ];
397
398             /* Calculate displacement vector */
399             dx00             = ix0 - jx0;
400             dy00             = iy0 - jy0;
401             dz00             = iz0 - jz0;
402
403             /* Calculate squared distance and things based on it */
404             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
405
406             rinv00           = gmx_invsqrt(rsq00);
407
408             rinvsq00         = rinv00*rinv00;
409
410             /* Load parameters for j particles */
411             jq0              = charge[jnr+0];
412             isaj0           = invsqrta[jnr+0];
413             vdwjidx0         = 3*vdwtype[jnr+0];
414
415             /**************************
416              * CALCULATE INTERACTIONS *
417              **************************/
418
419             r00              = rsq00*rinv00;
420
421             qq00             = iq0*jq0;
422             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
423             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
424             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
425
426             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
427             isaprod          = isai0*isaj0;
428             gbqqfactor       = isaprod*(-qq00)*gbinvepsdiff;
429             gbscale          = isaprod*gbtabscale;
430             dvdaj            = dvda[jnr+0];
431
432             /* Calculate generalized born table index - this is a separate table from the normal one,
433              * but we use the same procedure by multiplying r with scale and truncating to integer.
434              */
435             rt               = r00*gbscale;
436             gbitab           = rt;
437             gbeps            = rt-gbitab;
438             gbitab           = 4*gbitab;
439
440             Y                = gbtab[gbitab];
441             F                = gbtab[gbitab+1];
442             Geps             = gbeps*gbtab[gbitab+2];
443             Heps2            = gbeps*gbeps*gbtab[gbitab+3];
444             Fp               = F+Geps+Heps2;
445             VV               = Y+gbeps*Fp;
446             vgb              = gbqqfactor*VV;
447
448             FF               = Fp+Geps+2.0*Heps2;
449             fgb              = gbqqfactor*FF*gbscale;
450             dvdatmp          = -0.5*(vgb+fgb*r00);
451             dvdasum          = dvdasum + dvdatmp;
452             dvda[jnr]        = dvdaj+dvdatmp*isaj0*isaj0;
453             velec            = qq00*rinv00;
454             felec            = (velec*rinv00-fgb)*rinv00;
455
456             /* BUCKINGHAM DISPERSION/REPULSION */
457             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
458             vvdw6            = c6_00*rinvsix;
459             br               = cexp2_00*r00;
460             vvdwexp          = cexp1_00*exp(-br);
461             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
462
463             fscal            = felec+fvdw;
464
465             /* Calculate temporary vectorial force */
466             tx               = fscal*dx00;
467             ty               = fscal*dy00;
468             tz               = fscal*dz00;
469
470             /* Update vectorial force */
471             fix0            += tx;
472             fiy0            += ty;
473             fiz0            += tz;
474             f[j_coord_offset+DIM*0+XX] -= tx;
475             f[j_coord_offset+DIM*0+YY] -= ty;
476             f[j_coord_offset+DIM*0+ZZ] -= tz;
477
478             /* Inner loop uses 92 flops */
479         }
480         /* End of innermost loop */
481
482         tx = ty = tz = 0;
483         f[i_coord_offset+DIM*0+XX] += fix0;
484         f[i_coord_offset+DIM*0+YY] += fiy0;
485         f[i_coord_offset+DIM*0+ZZ] += fiz0;
486         tx                         += fix0;
487         ty                         += fiy0;
488         tz                         += fiz0;
489         fshift[i_shift_offset+XX]  += tx;
490         fshift[i_shift_offset+YY]  += ty;
491         fshift[i_shift_offset+ZZ]  += tz;
492
493         dvda[inr]                   = dvda[inr] + dvdasum*isai0*isai0;
494
495         /* Increment number of inner iterations */
496         inneriter                  += j_index_end - j_index_start;
497
498         /* Outer loop uses 13 flops */
499     }
500
501     /* Increment number of outer iterations */
502     outeriter        += nri;
503
504     /* Update outer/inner flops */
505
506     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*92);
507 }