2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012,2013, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
44 #include "types/simple.h"
47 #include "nb_generic.h"
50 #include "nonbonded.h"
51 #include "nb_kernel.h"
55 gmx_nb_generic_kernel(t_nblist * nlist,
60 nb_kernel_data_t * kernel_data,
63 int nri,ntype,table_nelements,ielec,ivdw;
64 real facel,gbtabscale;
65 int n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid,nnn,n0;
67 real fscal,felec,fvdw,velec,vvdw,tx,ty,tz;
73 real rt,r,eps,eps2,Y,F,Geps,Heps2,VV,FF,Fp,fijD,fijR;
76 real vvdw_rep,vvdw_disp;
77 real ix,iy,iz,fix,fiy,fiz;
79 real dx,dy,dz,rsq,rinv;
80 real c6,c12,cexp1,cexp2,br;
94 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
96 real rcoulomb2,rvdw,rvdw2,sh_invrc6;
97 real rcutoff,rcutoff2;
98 real rswitch_elec,rswitch_vdw,d,d2,sw,dsw,rinvcorr;
99 real elec_swV3,elec_swV4,elec_swV5,elec_swF2,elec_swF3,elec_swF4;
100 real vdw_swV3,vdw_swV4,vdw_swV5,vdw_swF2,vdw_swF3,vdw_swF4;
101 gmx_bool bExactElecCutoff,bExactVdwCutoff,bExactCutoff;
105 ielec = nlist->ielec;
108 fshift = fr->fshift[0];
109 velecgrp = kernel_data->energygrp_elec;
110 vvdwgrp = kernel_data->energygrp_vdw;
111 tabscale = kernel_data->table_elec_vdw->scale;
112 VFtab = kernel_data->table_elec_vdw->data;
114 sh_ewald = fr->ic->sh_ewald;
115 ewtab = fr->ic->tabq_coul_FDV0;
116 ewtabscale = fr->ic->tabq_scale;
117 ewtabhalfspace = 0.5/ewtabscale;
119 rcoulomb2 = fr->rcoulomb*fr->rcoulomb;
122 sh_invrc6 = fr->ic->sh_invrc6;
124 if(fr->coulomb_modifier==eintmodPOTSWITCH)
126 d = fr->rcoulomb-fr->rcoulomb_switch;
127 elec_swV3 = -10.0/(d*d*d);
128 elec_swV4 = 15.0/(d*d*d*d);
129 elec_swV5 = -6.0/(d*d*d*d*d);
130 elec_swF2 = -30.0/(d*d*d);
131 elec_swF3 = 60.0/(d*d*d*d);
132 elec_swF4 = -30.0/(d*d*d*d*d);
136 /* Avoid warnings from stupid compilers (looking at you, Clang!) */
137 elec_swV3 = elec_swV4 = elec_swV5 = elec_swF2 = elec_swF3 = elec_swF4 = 0.0;
139 if(fr->vdw_modifier==eintmodPOTSWITCH)
141 d = fr->rvdw-fr->rvdw_switch;
142 vdw_swV3 = -10.0/(d*d*d);
143 vdw_swV4 = 15.0/(d*d*d*d);
144 vdw_swV5 = -6.0/(d*d*d*d*d);
145 vdw_swF2 = -30.0/(d*d*d);
146 vdw_swF3 = 60.0/(d*d*d*d);
147 vdw_swF4 = -30.0/(d*d*d*d*d);
151 /* Avoid warnings from stupid compilers (looking at you, Clang!) */
152 vdw_swV3 = vdw_swV4 = vdw_swV5 = vdw_swF2 = vdw_swF3 = vdw_swF4 = 0.0;
155 bExactElecCutoff = (fr->coulomb_modifier!=eintmodNONE) || fr->eeltype == eelRF_ZERO;
156 bExactVdwCutoff = (fr->vdw_modifier!=eintmodNONE);
157 bExactCutoff = bExactElecCutoff || bExactVdwCutoff;
161 rcutoff = ( fr->rcoulomb > fr->rvdw ) ? fr->rcoulomb : fr->rvdw;
162 rcutoff2 = rcutoff*rcutoff;
166 /* Fix warnings for stupid compilers */
167 rcutoff = rcutoff2 = 1e30;
170 /* avoid compiler warnings for cases that cannot happen */
175 /* 3 VdW parameters for buckingham, otherwise 2 */
176 nvdwparam = (ivdw==GMX_NBKERNEL_VDW_BUCKINGHAM) ? 3 : 2;
177 table_nelements = 12;
179 charge = mdatoms->chargeA;
180 type = mdatoms->typeA;
182 shiftvec = fr->shift_vec[0];
186 for(n=0; (n<nlist->nri); n++)
188 is3 = 3*nlist->shift[n];
190 shY = shiftvec[is3+1];
191 shZ = shiftvec[is3+2];
192 nj0 = nlist->jindex[n];
193 nj1 = nlist->jindex[n+1];
199 iq = facel*charge[ii];
200 nti = nvdwparam*ntype*type[ii];
207 for(k=nj0; (k<nj1); k++)
209 jnr = nlist->jjnr[k];
217 rsq = dx*dx+dy*dy+dz*dz;
218 rinv = gmx_invsqrt(rsq);
225 if(bExactCutoff && rsq>rcutoff2)
230 if(ielec==GMX_NBKERNEL_ELEC_CUBICSPLINETABLE || ivdw==GMX_NBKERNEL_VDW_CUBICSPLINETABLE)
237 nnn = table_nelements*n0;
240 /* Coulomb interaction. ielec==0 means no interaction */
241 if(ielec!=GMX_NBKERNEL_ELEC_NONE)
247 case GMX_NBKERNEL_ELEC_NONE:
250 case GMX_NBKERNEL_ELEC_COULOMB:
251 /* Vanilla cutoff coulomb */
253 felec = velec*rinvsq;
256 case GMX_NBKERNEL_ELEC_REACTIONFIELD:
258 velec = qq*(rinv+fr->k_rf*rsq-fr->c_rf);
259 felec = qq*(rinv*rinvsq-2.0*fr->k_rf);
262 case GMX_NBKERNEL_ELEC_CUBICSPLINETABLE:
263 /* Tabulated coulomb */
266 Geps = eps*VFtab[nnn+2];
267 Heps2 = eps2*VFtab[nnn+3];
270 FF = Fp+Geps+2.0*Heps2;
272 felec = -qq*FF*tabscale*rinv;
275 case GMX_NBKERNEL_ELEC_GENERALIZEDBORN:
277 gmx_fatal(FARGS,"Death & horror! GB generic interaction not implemented.\n");
280 case GMX_NBKERNEL_ELEC_EWALD:
281 ewrt = rsq*rinv*ewtabscale;
285 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
286 rinvcorr = (fr->coulomb_modifier==eintmodPOTSHIFT) ? rinv-fr->ic->sh_ewald : rinv;
287 velec = qq*(rinvcorr-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
288 felec = qq*rinv*(rinvsq-felec);
292 gmx_fatal(FARGS,"Death & horror! No generic coulomb interaction for ielec=%d.\n",ielec);
295 if(fr->coulomb_modifier==eintmodPOTSWITCH)
297 d = rsq*rinv-fr->rcoulomb_switch;
298 d = (d>0.0) ? d : 0.0;
300 sw = 1.0+d2*d*(elec_swV3+d*(elec_swV4+d*elec_swV5));
301 dsw = d2*(elec_swF2+d*(elec_swF3+d*elec_swF4));
302 /* Apply switch function. Note that felec=f/r since it will be multiplied
303 * by the i-j displacement vector. This means felec'=f'/r=-(v*sw)'/r=
304 * -(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=felec*sw-v*dsw/r
306 felec = felec*sw - rinv*velec*dsw;
307 /* Once we have used velec to update felec we can modify velec too */
312 felec = (rsq<=rcoulomb2) ? felec : 0.0;
313 velec = (rsq<=rcoulomb2) ? velec : 0.0;
316 } /* End of coulomb interactions */
319 /* VdW interaction. ivdw==0 means no interaction */
320 if(ivdw!=GMX_NBKERNEL_VDW_NONE)
322 tj = nti+nvdwparam*type[jnr];
326 case GMX_NBKERNEL_VDW_NONE:
329 case GMX_NBKERNEL_VDW_LENNARDJONES:
330 /* Vanilla Lennard-Jones cutoff */
332 c12 = vdwparam[tj+1];
333 rinvsix = rinvsq*rinvsq*rinvsq;
334 vvdw_disp = c6*rinvsix;
335 vvdw_rep = c12*rinvsix*rinvsix;
336 fvdw = (vvdw_rep-vvdw_disp)*rinvsq;
337 if(fr->vdw_modifier==eintmodPOTSHIFT)
339 vvdw = (vvdw_rep-c12*sh_invrc6*sh_invrc6)*(1.0/12.0)-(vvdw_disp-c6*sh_invrc6)*(1.0/6.0);
343 vvdw = vvdw_rep/12.0-vvdw_disp/6.0;
347 case GMX_NBKERNEL_VDW_BUCKINGHAM:
350 cexp1 = vdwparam[tj+1];
351 cexp2 = vdwparam[tj+2];
353 rinvsix = rinvsq*rinvsq*rinvsq;
354 vvdw_disp = c6*rinvsix;
356 vvdw_rep = cexp1*exp(-br);
357 fvdw = (br*vvdw_rep-vvdw_disp)*rinvsq;
358 if(fr->vdw_modifier==eintmodPOTSHIFT)
360 vvdw = (vvdw_rep-cexp1*exp(-cexp2*rvdw))-(vvdw_disp-c6*sh_invrc6)/6.0;
364 vvdw = vvdw_rep-vvdw_disp/6.0;
368 case GMX_NBKERNEL_VDW_CUBICSPLINETABLE:
371 c12 = vdwparam[tj+1];
374 Geps = eps*VFtab[nnn+6];
375 Heps2 = eps2*VFtab[nnn+7];
378 FF = Fp+Geps+2.0*Heps2;
383 Geps = eps*VFtab[nnn+10];
384 Heps2 = eps2*VFtab[nnn+11];
387 FF = Fp+Geps+2.0*Heps2;
390 fvdw = -(fijD+fijR)*tabscale*rinv;
391 vvdw = vvdw_disp + vvdw_rep;
395 gmx_fatal(FARGS,"Death & horror! No generic VdW interaction for ivdw=%d.\n",ivdw);
398 if(fr->vdw_modifier==eintmodPOTSWITCH)
400 d = rsq*rinv-fr->rvdw_switch;
401 d = (d>0.0) ? d : 0.0;
403 sw = 1.0+d2*d*(vdw_swV3+d*(vdw_swV4+d*vdw_swV5));
404 dsw = d2*(vdw_swF2+d*(vdw_swF3+d*vdw_swF4));
405 /* See coulomb interaction for the force-switch formula */
406 fvdw = fvdw*sw - rinv*vvdw*dsw;
411 fvdw = (rsq<=rvdw2) ? fvdw : 0.0;
412 vvdw = (rsq<=rvdw2) ? vvdw : 0.0;
415 } /* end VdW interactions */
425 f[j3+0] = f[j3+0] - tx;
426 f[j3+1] = f[j3+1] - ty;
427 f[j3+2] = f[j3+2] - tz;
430 f[ii3+0] = f[ii3+0] + fix;
431 f[ii3+1] = f[ii3+1] + fiy;
432 f[ii3+2] = f[ii3+2] + fiz;
433 fshift[is3] = fshift[is3]+fix;
434 fshift[is3+1] = fshift[is3+1]+fiy;
435 fshift[is3+2] = fshift[is3+2]+fiz;
436 ggid = nlist->gid[n];
437 velecgrp[ggid] += vctot;
438 vvdwgrp[ggid] += vvdwtot;
440 /* Estimate flops, average for generic kernel:
441 * 12 flops per outer iteration
442 * 50 flops per inner iteration
444 inc_nrnb(nrnb,eNR_NBKERNEL_GENERIC,nlist->nri*12 + nlist->jindex[n]*50);