Commit e9a2857a authored by Peter Eastman's avatar Peter Eastman
Browse files

Fixed inconsistency in computing Ewald self energy

parent 81bad1bc
...@@ -2117,7 +2117,8 @@ double CudaCalcNonbondedForceKernel::execute(ContextImpl& context, bool includeF ...@@ -2117,7 +2117,8 @@ double CudaCalcNonbondedForceKernel::execute(ContextImpl& context, bool includeF
cuEventRecord(paramsSyncEvent, cu.getCurrentStream()); cuEventRecord(paramsSyncEvent, cu.getCurrentStream());
cuStreamWaitEvent(pmeStream, paramsSyncEvent, 0); cuStreamWaitEvent(pmeStream, paramsSyncEvent, 0);
} }
energy = 0.0; // The Ewald self energy was computed in the kernel. if (hasOffsets)
energy = 0.0; // The Ewald self energy was computed in the kernel.
recomputeParams = false; recomputeParams = false;
} }
...@@ -2348,10 +2349,12 @@ void CudaCalcNonbondedForceKernel::copyParametersToContext(ContextImpl& context, ...@@ -2348,10 +2349,12 @@ void CudaCalcNonbondedForceKernel::copyParametersToContext(ContextImpl& context,
ewaldSelfEnergy = 0.0; ewaldSelfEnergy = 0.0;
if (nonbondedMethod == Ewald || nonbondedMethod == PME || nonbondedMethod == LJPME) { if (nonbondedMethod == Ewald || nonbondedMethod == PME || nonbondedMethod == LJPME) {
for (int i = 0; i < force.getNumParticles(); i++) { if (cu.getContextIndex() == 0) {
ewaldSelfEnergy -= baseParticleParamVec[i].x*baseParticleParamVec[i].x*ONE_4PI_EPS0*alpha/sqrt(M_PI); for (int i = 0; i < force.getNumParticles(); i++) {
if (doLJPME) ewaldSelfEnergy -= baseParticleParamVec[i].x*baseParticleParamVec[i].x*ONE_4PI_EPS0*alpha/sqrt(M_PI);
ewaldSelfEnergy += baseParticleParamVec[i].z*pow(baseParticleParamVec[i].y*dispersionAlpha, 6)/3.0; if (doLJPME)
ewaldSelfEnergy += baseParticleParamVec[i].z*pow(baseParticleParamVec[i].y*dispersionAlpha, 6)/3.0;
}
} }
} }
if (force.getUseDispersionCorrection() && cu.getContextIndex() == 0 && (nonbondedMethod == CutoffPeriodic || nonbondedMethod == Ewald || nonbondedMethod == PME)) if (force.getUseDispersionCorrection() && cu.getContextIndex() == 0 && (nonbondedMethod == CutoffPeriodic || nonbondedMethod == Ewald || nonbondedMethod == PME))
......
...@@ -31,12 +31,14 @@ extern "C" __global__ void computeParameters(mixed* __restrict__ energyBuffer, b ...@@ -31,12 +31,14 @@ extern "C" __global__ void computeParameters(mixed* __restrict__ energyBuffer, b
charge[i] = params.x; charge[i] = params.x;
#endif #endif
sigmaEpsilon[i] = make_float2(0.5f*params.y, 2*SQRT(params.z)); sigmaEpsilon[i] = make_float2(0.5f*params.y, 2*SQRT(params.z));
#ifdef INCLUDE_EWALD #ifdef HAS_OFFSETS
#ifdef INCLUDE_EWALD
energy -= EWALD_SELF_ENERGY_SCALE*params.x*params.x; energy -= EWALD_SELF_ENERGY_SCALE*params.x*params.x;
#endif #endif
#ifdef INCLUDE_LJPME #ifdef INCLUDE_LJPME
real sig3 = params.y*params.y*params.y; real sig3 = params.y*params.y*params.y;
energy += LJPME_SELF_ENERGY_SCALE*sig3*sig3*params.z; energy += LJPME_SELF_ENERGY_SCALE*sig3*sig3*params.z;
#endif
#endif #endif
} }
......
...@@ -2181,7 +2181,8 @@ double OpenCLCalcNonbondedForceKernel::execute(ContextImpl& context, bool includ ...@@ -2181,7 +2181,8 @@ double OpenCLCalcNonbondedForceKernel::execute(ContextImpl& context, bool includ
cl.getQueue().enqueueMarker(&events[0]); cl.getQueue().enqueueMarker(&events[0]);
pmeQueue.enqueueWaitForEvents(events); pmeQueue.enqueueWaitForEvents(events);
} }
energy = 0.0; // The Ewald self energy was computed in the kernel. if (hasOffsets)
energy = 0.0; // The Ewald self energy was computed in the kernel.
recomputeParams = false; recomputeParams = false;
} }
...@@ -2487,10 +2488,12 @@ void OpenCLCalcNonbondedForceKernel::copyParametersToContext(ContextImpl& contex ...@@ -2487,10 +2488,12 @@ void OpenCLCalcNonbondedForceKernel::copyParametersToContext(ContextImpl& contex
ewaldSelfEnergy = 0.0; ewaldSelfEnergy = 0.0;
if (nonbondedMethod == Ewald || nonbondedMethod == PME || nonbondedMethod == LJPME) { if (nonbondedMethod == Ewald || nonbondedMethod == PME || nonbondedMethod == LJPME) {
for (int i = 0; i < force.getNumParticles(); i++) { if (cl.getContextIndex() == 0) {
ewaldSelfEnergy -= baseParticleParamVec[i].x*baseParticleParamVec[i].x*ONE_4PI_EPS0*alpha/sqrt(M_PI); for (int i = 0; i < force.getNumParticles(); i++) {
if (doLJPME) ewaldSelfEnergy -= baseParticleParamVec[i].x*baseParticleParamVec[i].x*ONE_4PI_EPS0*alpha/sqrt(M_PI);
ewaldSelfEnergy += baseParticleParamVec[i].z*pow(baseParticleParamVec[i].y*dispersionAlpha, 6)/3.0; if (doLJPME)
ewaldSelfEnergy += baseParticleParamVec[i].z*pow(baseParticleParamVec[i].y*dispersionAlpha, 6)/3.0;
}
} }
} }
if (force.getUseDispersionCorrection() && cl.getContextIndex() == 0 && (nonbondedMethod == CutoffPeriodic || nonbondedMethod == Ewald || nonbondedMethod == PME)) if (force.getUseDispersionCorrection() && cl.getContextIndex() == 0 && (nonbondedMethod == CutoffPeriodic || nonbondedMethod == Ewald || nonbondedMethod == PME))
......
...@@ -31,12 +31,14 @@ __kernel void computeParameters(__global mixed* restrict energyBuffer, int inclu ...@@ -31,12 +31,14 @@ __kernel void computeParameters(__global mixed* restrict energyBuffer, int inclu
charge[i] = params.x; charge[i] = params.x;
#endif #endif
sigmaEpsilon[i] = (float2) (0.5f*params.y, 2*SQRT(params.z)); sigmaEpsilon[i] = (float2) (0.5f*params.y, 2*SQRT(params.z));
#ifdef INCLUDE_EWALD #ifdef HAS_OFFSETS
#ifdef INCLUDE_EWALD
energy -= EWALD_SELF_ENERGY_SCALE*params.x*params.x; energy -= EWALD_SELF_ENERGY_SCALE*params.x*params.x;
#endif #endif
#ifdef INCLUDE_LJPME #ifdef INCLUDE_LJPME
real sig3 = params.y*params.y*params.y; real sig3 = params.y*params.y*params.y;
energy += LJPME_SELF_ENERGY_SCALE*sig3*sig3*params.z; energy += LJPME_SELF_ENERGY_SCALE*sig3*sig3*params.z;
#endif
#endif #endif
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment