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, 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_adress.h"
49 #define ALMOST_ZERO 1e-30
50 #define ALMOST_ONE 1-(1e-30)
52 gmx_nb_generic_adress_kernel(t_nblist * nlist,
66 int nri,ntype,table_nelements,ielec,ivdw;
67 real facel,gbtabscale;
68 int n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid,nnn,n0;
73 real qq,vcoul,krsq,vctot;
76 real rt,r,eps,eps2,Y,F,Geps,Heps2,VV,FF,Fp,fijD,fijR;
79 real Vvdw_rep,Vvdw_disp;
80 real ix,iy,iz,fix,fiy,fiz;
82 real dx,dy,dz,rsq,rinv;
83 real c6,c12,cexp1,cexp2,br;
94 real hybscal; /* the multiplicator to the force for hybrid interactions*/
95 gmx_bool bHybrid; /*Are we in the hybrid zone ?*/
100 force_cap = fr->adress_ex_forcecap;
102 ielec = nlist->ielec;
105 /* avoid compiler warnings for cases that cannot happen */
111 /* 3 VdW parameters for buckingham, otherwise 2 */
112 nvdwparam = (nlist->ivdw==2) ? 3 : 2;
113 table_nelements = (ielec==3) ? 4 : 0;
114 table_nelements += (ivdw==3) ? 8 : 0;
116 charge = mdatoms->chargeA;
117 type = mdatoms->typeA;
119 shiftvec = fr->shift_vec[0];
126 for(n=0; (n<nlist->nri); n++)
128 is3 = 3*nlist->shift[n];
130 shY = shiftvec[is3+1];
131 shZ = shiftvec[is3+2];
132 nj0 = nlist->jindex[n];
133 nj1 = nlist->jindex[n+1];
139 iq = facel*charge[ii];
140 nti = nvdwparam*ntype*type[ii];
149 /* TODO: why does this line her not speed up things ?
150 * if ((!bCG) && weight_cg1 < ALMOST_ZERO) continue;
152 for(k=nj0; (k<nj1); k++)
154 jnr = nlist->jjnr[k];
155 weight_cg2 = wf[jnr];
157 weight_product = weight_cg1*weight_cg2;
159 if (weight_product < ALMOST_ZERO)
161 /* if it's a explicit loop, skip this atom */
166 else /* if it's a coarse grained loop, include this atom */
172 else if (weight_product >= ALMOST_ONE)
175 /* if it's a explicit loop, include this atom */
181 else /* if it's a coarse grained loop, skip this atom */
186 /* both have double identity, get hybrid scaling factor */
190 hybscal = weight_product;
194 hybscal = 1.0 - hybscal;
206 rsq = dx*dx+dy*dy+dz*dz;
207 rinv = gmx_invsqrt(rsq);
213 if(ielec==3 || ivdw==3)
220 nnn = table_nelements*n0;
223 /* Coulomb interaction. ielec==0 means no interaction */
231 /* Vanilla cutoff coulomb */
233 fscal = vcoul*rinvsq;
239 vcoul = qq*(rinv+krsq-fr->c_rf);
240 fscal = qq*(rinv-2.0*krsq)*rinvsq;
244 /* Tabulated coulomb */
247 Geps = eps*VFtab[nnn+2];
248 Heps2 = eps2*VFtab[nnn+3];
252 FF = Fp+Geps+2.0*Heps2;
254 fscal = -qq*FF*tabscale*rinv;
259 gmx_fatal(FARGS,"Death & horror! GB generic interaction not implemented.\n");
263 gmx_fatal(FARGS,"Death & horror! No generic coulomb interaction for ielec=%d.\n",ielec);
267 } /* End of coulomb interactions */
269 /* VdW interaction. ivdw==0 means no interaction */
272 tj = nti+nvdwparam*type[jnr];
277 /* Vanilla Lennard-Jones cutoff */
279 c12 = vdwparam[tj+1];
281 rinvsix = rinvsq*rinvsq*rinvsq;
282 Vvdw_disp = c6*rinvsix;
283 Vvdw_rep = c12*rinvsix*rinvsix;
284 fscal += (12.0*Vvdw_rep-6.0*Vvdw_disp)*rinvsq;
285 Vvdwtot = Vvdwtot+Vvdw_rep-Vvdw_disp;
291 cexp1 = vdwparam[tj+1];
292 cexp2 = vdwparam[tj+2];
294 rinvsix = rinvsq*rinvsq*rinvsq;
295 Vvdw_disp = c6*rinvsix;
297 Vvdw_rep = cexp1*exp(-br);
298 fscal += (br*Vvdw_rep-6.0*Vvdw_disp)*rinvsq;
299 Vvdwtot = Vvdwtot+Vvdw_rep-Vvdw_disp;
305 c12 = vdwparam[tj+1];
309 Geps = eps*VFtab[nnn+2];
310 Heps2 = eps2*VFtab[nnn+3];
313 FF = Fp+Geps+2.0*Heps2;
319 Geps = eps*VFtab[nnn+2];
320 Heps2 = eps2*VFtab[nnn+3];
323 FF = Fp+Geps+2.0*Heps2;
326 fscal += -(fijD+fijR)*tabscale*rinv;
327 Vvdwtot = Vvdwtot + Vvdw_disp + Vvdw_rep;
328 if(!bCG && force_cap>0 && (fabs(fscal)> force_cap))
330 fscal=force_cap*fscal/fabs(fscal);
335 gmx_fatal(FARGS,"Death & horror! No generic VdW interaction for ivdw=%d.\n",ivdw);
338 } /* end VdW interactions */
340 /* force weight is one anyway */
352 f[j3+0] = f[j3+0] - tx;
353 f[j3+1] = f[j3+1] - ty;
354 f[j3+2] = f[j3+2] - tz;
357 f[ii3+0] = f[ii3+0] + fix;
358 f[ii3+1] = f[ii3+1] + fiy;
359 f[ii3+2] = f[ii3+2] + fiz;
360 fshift[is3] = fshift[is3]+fix;
361 fshift[is3+1] = fshift[is3+1]+fiy;
362 fshift[is3+2] = fshift[is3+2]+fiz;
363 ggid = nlist->gid[n];
364 Vc[ggid] = Vc[ggid] + vctot;
365 Vvdw[ggid] = Vvdw[ggid] + Vvdwtot;
368 *outeriter = nlist->nri;
369 *inneriter = nlist->jindex[n];