* To help us fund GROMACS development, we humbly ask that you cite
* the research papers on the package. Check out http://www.gromacs.org.
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
#include <math.h>
-#include "vec.h"
-#include "typedefs.h"
-#include "nonbonded.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/legacyheaders/nonbonded.h"
#include "nb_kernel.h"
-#include "nrnb.h"
-#include "macros.h"
+#include "gromacs/legacyheaders/nrnb.h"
+#include "gromacs/legacyheaders/macros.h"
#include "nb_free_energy.h"
-#include "gmx_fatal.h"
+#include "gromacs/utility/fatalerror.h"
void
gmx_nb_free_energy_kernel(const t_nblist * gmx_restrict nlist,
#define NSTATES 2
int i, j, n, ii, is3, ii3, k, nj0, nj1, jnr, j3, ggid;
real shX, shY, shZ;
- real Fscal, FscalC[NSTATES], FscalV[NSTATES], tx, ty, tz;
- real Vcoul[NSTATES], Vvdw[NSTATES];
+ real tx, ty, tz, Fscal;
+ double FscalC[NSTATES], FscalV[NSTATES]; /* Needs double for sc_power==48 */
+ double Vcoul[NSTATES], Vvdw[NSTATES]; /* Needs double for sc_power==48 */
real rinv6, r, rt, rtC, rtV;
real iqA, iqB;
real qq[NSTATES], vctot, krsq;
double dvdl_coul, dvdl_vdw;
real lfac_coul[NSTATES], dlfac_coul[NSTATES], lfac_vdw[NSTATES], dlfac_vdw[NSTATES];
real sigma6[NSTATES], alpha_vdw_eff, alpha_coul_eff, sigma2_def, sigma2_min;
- real rp, rpm2, rC, rV, rinvC, rpinvC, rinvV, rpinvV;
+ double rp, rpm2, rC, rV, rinvC, rpinvC, rinvV, rpinvV; /* Needs double for sc_power==48 */
real sigma2[NSTATES], sigma_pow[NSTATES], sigma_powm2[NSTATES], rs, rs2;
int do_tab, tab_elemsize;
int n0, n1C, n1V, nnn;
const real * chargeB;
real sigma6_min, sigma6_def, lam_power, sc_power, sc_r_power;
real alpha_coul, alpha_vdw, lambda_coul, lambda_vdw, ewc_lj;
+ real ewcljrsq, ewclj, ewclj2, exponent, poly, vvdw_disp, vvdw_rep, sh_lj_ewald;
+ real ewclj6;
const real * nbfp, *nbfp_grid;
real * dvdl;
real * Vv;
bDoPotential = kernel_data->flags & GMX_NONBONDED_DO_POTENTIAL;
rcoulomb = fr->rcoulomb;
- sh_ewald = fr->ic->sh_ewald;
rvdw = fr->rvdw;
sh_invrc6 = fr->ic->sh_invrc6;
+ sh_lj_ewald = fr->ic->sh_lj_ewald;
+ ewclj = fr->ewaldcoeff_lj;
+ ewclj2 = ewclj*ewclj;
+ ewclj6 = ewclj2*ewclj2*ewclj2;
if (fr->coulomb_modifier == eintmodPOTSWITCH)
{
*/
bConvertLJEwaldToLJ6 = (bEwaldLJ && (fr->vdw_modifier != eintmodPOTSWITCH));
+ /* We currently don't implement exclusion correction, needed with the Verlet cut-off scheme, without conversion */
+ if (fr->cutoff_scheme == ecutsVERLET &&
+ ((bEwald && !bConvertEwaldToCoulomb) ||
+ (bEwaldLJ && !bConvertLJEwaldToLJ6)))
+ {
+ gmx_incons("Unimplemented non-bonded setup");
+ }
+
/* fix compiler warnings */
nj1 = 0;
n1C = n1V = 0;
Vcoul[i] = qq[i]*rinvC;
FscalC[i] = Vcoul[i];
/* The shift for the Coulomb potential is stored in
- * the RF parameter c_rf, which is 0 without shift
+ * the RF parameter c_rf, which is 0 without shift.
*/
Vcoul[i] -= qq[i]*fr->ic->c_rf;
break;
switch (ivdw)
{
case GMX_NBKERNEL_VDW_LENNARDJONES:
- case GMX_NBKERNEL_VDW_LJEWALD:
/* cutoff LJ */
if (sc_r_power == 6.0)
{
}
else
{
- rinv6 = pow(rinvV, 6.0);
+ rinv6 = rinvV*rinvV;
+ rinv6 = rinv6*rinv6*rinv6;
}
Vvdw6 = c6[i]*rinv6;
Vvdw12 = c12[i]*rinv6*rinv6;
- if (fr->vdw_modifier == eintmodPOTSHIFT)
- {
- Vvdw[i] = ( (Vvdw12-c12[i]*sh_invrc6*sh_invrc6)*(1.0/12.0)
- -(Vvdw6-c6[i]*sh_invrc6)*(1.0/6.0));
- }
- else
- {
- Vvdw[i] = Vvdw12*(1.0/12.0) - Vvdw6*(1.0/6.0);
- }
+
+ Vvdw[i] = ( (Vvdw12 - c12[i]*sh_invrc6*sh_invrc6)*(1.0/12.0)
+ - (Vvdw6 - c6[i]*sh_invrc6)*(1.0/6.0));
FscalV[i] = Vvdw12 - Vvdw6;
break;
FscalV[i] -= c12[i]*tabscale*FF*rV;
break;
+ case GMX_NBKERNEL_VDW_LJEWALD:
+ if (sc_r_power == 6.0)
+ {
+ rinv6 = rpinvV;
+ }
+ else
+ {
+ rinv6 = rinvV*rinvV;
+ rinv6 = rinv6*rinv6*rinv6;
+ }
+ c6grid = nbfp_grid[tj[i]];
+
+ if (bConvertLJEwaldToLJ6)
+ {
+ /* cutoff LJ */
+ Vvdw6 = c6[i]*rinv6;
+ Vvdw12 = c12[i]*rinv6*rinv6;
+
+ Vvdw[i] = ( (Vvdw12 - c12[i]*sh_invrc6*sh_invrc6)*(1.0/12.0)
+ - (Vvdw6 - c6[i]*sh_invrc6 - c6grid*sh_lj_ewald)*(1.0/6.0));
+ FscalV[i] = Vvdw12 - Vvdw6;
+ }
+ else
+ {
+ /* Normal LJ-PME */
+ ewcljrsq = ewclj2*rV*rV;
+ exponent = exp(-ewcljrsq);
+ poly = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
+ vvdw_disp = (c6[i]-c6grid*(1.0-poly))*rinv6;
+ vvdw_rep = c12[i]*rinv6*rinv6;
+ FscalV[i] = vvdw_rep - vvdw_disp - c6grid*(1.0/6.0)*exponent*ewclj6;
+ Vvdw[i] = (vvdw_rep - c12[i]*sh_invrc6*sh_invrc6)/12.0 - (vvdw_disp - c6[i]*sh_invrc6 - c6grid*sh_lj_ewald)/6.0;
+ }
+ break;
+
case GMX_NBKERNEL_VDW_NONE:
Vvdw[i] = 0.0;
FscalV[i] = 0.0;
v_lr = (ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+f_lr));
f_lr *= rinv;
+ /* Note that any possible Ewald shift has already been applied in
+ * the normal interaction part above.
+ */
+
if (ii == jnr)
{
/* If we get here, the i particle (ii) has itself (jnr)
* the softcore to the entire VdW interaction,
* including the reciprocal-space component.
*/
+ /* We could also use the analytical form here
+ * iso a table, but that can cause issues for
+ * r close to 0 for non-interacting pairs.
+ */
real rs, frac, f_lr;
int ri;
ri = (int)rs;
frac = rs - ri;
f_lr = (1 - frac)*tab_ewald_F_lj[ri] + frac*tab_ewald_F_lj[ri+1];
- FF = f_lr*rinv;
- VV = tab_ewald_V_lj[ri] - ewtabhalfspace*frac*(tab_ewald_F_lj[ri] + f_lr);
+ /* TODO: Currently the Ewald LJ table does not contain
+ * the factor 1/6, we should add this.
+ */
+ FF = f_lr*rinv/6.0;
+ VV = (tab_ewald_V_lj[ri] - ewtabhalfspace*frac*(tab_ewald_F_lj[ri] + f_lr))/6.0;
if (ii == jnr)
{
for (i = 0; i < NSTATES; i++)
{
c6grid = nbfp_grid[tj[i]];
- vvtot += LFV[i]*c6grid*VV*(1.0/6.0);
- Fscal += LFV[i]*c6grid*FF*(1.0/6.0);
- dvdl_vdw += (DLF[i]*c6grid)*VV*(1.0/6.0);
+ vvtot += LFV[i]*c6grid*VV;
+ Fscal += LFV[i]*c6grid*FF;
+ dvdl_vdw += (DLF[i]*c6grid)*VV;
}
-
}
if (bDoForces)