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