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

Refactored ForceImpl, lots of KernelImpl subclasses, and other related classes...

Refactored ForceImpl, lots of KernelImpl subclasses, and other related classes to avoid redundant calculations when requesting a State with both forces and energies
parent 767ea1bd
......@@ -64,7 +64,7 @@ vector<string> VariableLangevinIntegrator::getKernelNames() {
void VariableLangevinIntegrator::step(int steps) {
for (int i = 0; i < steps; ++i) {
context->updateContextState();
context->calcForces();
context->calcForcesAndEnergy(true, false);
dynamic_cast<IntegrateVariableLangevinStepKernel&>(kernel.getImpl()).execute(*context, *this, std::numeric_limits<double>::infinity());
}
}
......@@ -72,7 +72,7 @@ void VariableLangevinIntegrator::step(int steps) {
void VariableLangevinIntegrator::stepTo(double time) {
while (time > context->getTime()) {
context->updateContextState();
context->calcForces();
context->calcForcesAndEnergy(true, false);
dynamic_cast<IntegrateVariableLangevinStepKernel&>(kernel.getImpl()).execute(*context, *this, time);
}
}
......@@ -59,7 +59,7 @@ vector<string> VariableVerletIntegrator::getKernelNames() {
void VariableVerletIntegrator::step(int steps) {
for (int i = 0; i < steps; ++i) {
context->updateContextState();
context->calcForces();
context->calcForcesAndEnergy(true, false);
dynamic_cast<IntegrateVariableVerletStepKernel&>(kernel.getImpl()).execute(*context, *this, std::numeric_limits<double>::infinity());
}
}
......@@ -67,7 +67,7 @@ void VariableVerletIntegrator::step(int steps) {
void VariableVerletIntegrator::stepTo(double time) {
while (time > context->getTime()) {
context->updateContextState();
context->calcForces();
context->calcForcesAndEnergy(true, false);
dynamic_cast<IntegrateVariableVerletStepKernel&>(kernel.getImpl()).execute(*context, *this, time);
}
}
......@@ -59,7 +59,7 @@ vector<string> VerletIntegrator::getKernelNames() {
void VerletIntegrator::step(int steps) {
for (int i = 0; i < steps; ++i) {
context->updateContextState();
context->calcForces();
context->calcForcesAndEnergy(true, false);
dynamic_cast<IntegrateVerletStepKernel&>(kernel.getImpl()).execute(*context, *this);
}
}
......@@ -44,49 +44,23 @@ using namespace std;
void CudaCalcForcesAndEnergyKernel::initialize(const System& system) {
}
void CudaCalcForcesAndEnergyKernel::beginForceComputation(ContextImpl& context) {
void CudaCalcForcesAndEnergyKernel::beginComputation(ContextImpl& context, bool includeForces, bool includeEnergy) {
_gpuContext* gpu = data.gpu;
if (data.nonbondedMethod != NO_CUTOFF && data.computeForceCount%100 == 0)
gpuReorderAtoms(gpu);
data.computeForceCount++;
if (includeForces)
data.computeForceCount++;
if (gpu->bIncludeGBSA || gpu->bIncludeGBVI)
kClearBornSumAndForces(gpu);
else
else if (includeForces)
kClearForces(gpu);
}
void CudaCalcForcesAndEnergyKernel::finishForceComputation(ContextImpl& context) {
_gpuContext* gpu = data.gpu;
if (gpu->bIncludeGBSA || gpu->bIncludeGBVI) {
gpu->bRecalculateBornRadii = true;
kCalculateCDLJObcGbsaForces1(gpu);
kReduceObcGbsaBornForces(gpu);
if (gpu->bIncludeGBSA ) {
kCalculateObcGbsaForces2(gpu);
} else {
kCalculateGBVIForces2(gpu);
}
if (includeEnergy) {
data.stepCount++;
kClearEnergy(gpu);
}
else if (data.hasNonbonded)
kCalculateCDLJForces(gpu);
if (data.hasCustomNonbonded)
kCalculateCustomNonbondedForces(gpu, data.hasNonbonded);
kCalculateLocalForces(gpu);
kReduceForces(gpu);
}
void CudaCalcForcesAndEnergyKernel::beginEnergyComputation(ContextImpl& context) {
_gpuContext* gpu = data.gpu;
if (data.nonbondedMethod != NO_CUTOFF && data.stepCount%100 == 0)
gpuReorderAtoms(gpu);
data.stepCount++;
kClearEnergy(gpu);
if (gpu->bIncludeGBSA || gpu->bIncludeGBVI)
kClearBornSumAndForces(gpu);
}
double CudaCalcForcesAndEnergyKernel::finishEnergyComputation(ContextImpl& context) {
double CudaCalcForcesAndEnergyKernel::finishComputation(ContextImpl& context, bool includeForces, bool includeEnergy) {
_gpuContext* gpu = data.gpu;
if (gpu->bIncludeGBSA || gpu->bIncludeGBVI) {
gpu->bRecalculateBornRadii = true;
......@@ -103,9 +77,14 @@ double CudaCalcForcesAndEnergyKernel::finishEnergyComputation(ContextImpl& conte
if (data.hasCustomNonbonded)
kCalculateCustomNonbondedForces(gpu, data.hasNonbonded);
kCalculateLocalForces(gpu);
double energy = kReduceEnergy(gpu)+data.ewaldSelfEnergy;
if (data.dispersionCoefficient != 0.0)
energy += data.dispersionCoefficient/(gpu->sim.periodicBoxSizeX*gpu->sim.periodicBoxSizeY*gpu->sim.periodicBoxSizeZ);
if (includeForces)
kReduceForces(gpu);
double energy = 0.0;
if (includeEnergy) {
energy = kReduceEnergy(gpu)+data.ewaldSelfEnergy;
if (data.dispersionCoefficient != 0.0)
energy += data.dispersionCoefficient/(gpu->sim.periodicBoxSizeX*gpu->sim.periodicBoxSizeY*gpu->sim.periodicBoxSizeZ);
}
return energy;
}
......@@ -226,10 +205,7 @@ void CudaCalcHarmonicBondForceKernel::initialize(const System& system, const Har
gpuSetBondParameters(data.gpu, particle1, particle2, length, k);
}
void CudaCalcHarmonicBondForceKernel::executeForces(ContextImpl& context) {
}
double CudaCalcHarmonicBondForceKernel::executeEnergy(ContextImpl& context) {
double CudaCalcHarmonicBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
return 0.0;
}
......@@ -257,12 +233,7 @@ void CudaCalcCustomBondForceKernel::initialize(const System& system, const Custo
SetCustomBondGlobalParams(globalParamValues);
}
void CudaCalcCustomBondForceKernel::executeForces(ContextImpl& context) {
updateGlobalParams(context);
kCalculateCustomBondForces(data.gpu);
}
double CudaCalcCustomBondForceKernel::executeEnergy(ContextImpl& context) {
double CudaCalcCustomBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
updateGlobalParams(context);
kCalculateCustomBondForces(data.gpu);
return 0.0;
......@@ -301,10 +272,7 @@ void CudaCalcHarmonicAngleForceKernel::initialize(const System& system, const Ha
gpuSetBondAngleParameters(data.gpu, particle1, particle2, particle3, angle, k);
}
void CudaCalcHarmonicAngleForceKernel::executeForces(ContextImpl& context) {
}
double CudaCalcHarmonicAngleForceKernel::executeEnergy(ContextImpl& context) {
double CudaCalcHarmonicAngleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
return 0.0;
}
......@@ -333,12 +301,7 @@ void CudaCalcCustomAngleForceKernel::initialize(const System& system, const Cust
SetCustomAngleGlobalParams(globalParamValues);
}
void CudaCalcCustomAngleForceKernel::executeForces(ContextImpl& context) {
updateGlobalParams(context);
kCalculateCustomAngleForces(data.gpu);
}
double CudaCalcCustomAngleForceKernel::executeEnergy(ContextImpl& context) {
double CudaCalcCustomAngleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
updateGlobalParams(context);
kCalculateCustomAngleForces(data.gpu);
return 0.0;
......@@ -379,10 +342,7 @@ void CudaCalcPeriodicTorsionForceKernel::initialize(const System& system, const
gpuSetDihedralParameters(data.gpu, particle1, particle2, particle3, particle4, k, phase, periodicity);
}
void CudaCalcPeriodicTorsionForceKernel::executeForces(ContextImpl& context) {
}
double CudaCalcPeriodicTorsionForceKernel::executeEnergy(ContextImpl& context) {
double CudaCalcPeriodicTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
return 0.0;
}
......@@ -415,10 +375,7 @@ void CudaCalcRBTorsionForceKernel::initialize(const System& system, const RBTors
gpuSetRbDihedralParameters(data.gpu, particle1, particle2, particle3, particle4, c0, c1, c2, c3, c4, c5);
}
void CudaCalcRBTorsionForceKernel::executeForces(ContextImpl& context) {
}
double CudaCalcRBTorsionForceKernel::executeEnergy(ContextImpl& context) {
double CudaCalcRBTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
return 0.0;
}
......@@ -483,11 +440,7 @@ void CudaCalcCMAPTorsionForceKernel::initialize(const System& system, const CMAP
data.gpu->sim.outputBuffers = maxBuffers;
}
void CudaCalcCMAPTorsionForceKernel::executeForces(ContextImpl& context) {
kCalculateCMAPTorsionForces(data.gpu, *coefficients, *mapPositions, *torsionIndices, *torsionMaps);
}
double CudaCalcCMAPTorsionForceKernel::executeEnergy(ContextImpl& context) {
double CudaCalcCMAPTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
kCalculateCMAPTorsionForces(data.gpu, *coefficients, *mapPositions, *torsionIndices, *torsionMaps);
return 0.0;
}
......@@ -518,12 +471,7 @@ void CudaCalcCustomTorsionForceKernel::initialize(const System& system, const Cu
SetCustomTorsionGlobalParams(globalParamValues);
}
void CudaCalcCustomTorsionForceKernel::executeForces(ContextImpl& context) {
updateGlobalParams(context);
kCalculateCustomTorsionForces(data.gpu);
}
double CudaCalcCustomTorsionForceKernel::executeEnergy(ContextImpl& context) {
double CudaCalcCustomTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
updateGlobalParams(context);
kCalculateCustomTorsionForces(data.gpu);
return 0.0;
......@@ -650,10 +598,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon
}
}
void CudaCalcNonbondedForceKernel::executeForces(ContextImpl& context) {
}
double CudaCalcNonbondedForceKernel::executeEnergy(ContextImpl& context) {
double CudaCalcNonbondedForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
return 0.0;
}
......@@ -716,11 +661,7 @@ void CudaCalcCustomNonbondedForceKernel::initialize(const System& system, const
SetCustomNonbondedGlobalParams(globalParamValues);
}
void CudaCalcCustomNonbondedForceKernel::executeForces(ContextImpl& context) {
updateGlobalParams(context);
}
double CudaCalcCustomNonbondedForceKernel::executeEnergy(ContextImpl& context) {
double CudaCalcCustomNonbondedForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
updateGlobalParams(context);
return 0.0;
}
......@@ -757,7 +698,8 @@ void CudaCalcGBSAOBCForceKernel::initialize(const System& system, const GBSAOBCF
gpuSetObcParameters(gpu, (float) force.getSoluteDielectric(), (float) force.getSolventDielectric(), radius, scale, charge);
}
void CudaCalcGBSAOBCForceKernel::executeForces(ContextImpl& context) {
double CudaCalcGBSAOBCForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
return 0.0;
}
CudaCalcGBVIForceKernel::~CudaCalcGBVIForceKernel() {
......@@ -785,10 +727,7 @@ void CudaCalcGBVIForceKernel::initialize(const System& system, const GBVIForce&
radius, gammas, scaledRadii );
}
void CudaCalcGBVIForceKernel::executeForces(ContextImpl& context) {
}
double CudaCalcGBVIForceKernel::executeEnergy(ContextImpl& context) {
double CudaCalcGBVIForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
return 0.0;
}
......@@ -815,12 +754,7 @@ void CudaCalcCustomExternalForceKernel::initialize(const System& system, const C
SetCustomExternalGlobalParams(globalParamValues);
}
void CudaCalcCustomExternalForceKernel::executeForces(ContextImpl& context) {
updateGlobalParams(context);
kCalculateCustomExternalForces(data.gpu);
}
double CudaCalcCustomExternalForceKernel::executeEnergy(ContextImpl& context) {
double CudaCalcCustomExternalForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
updateGlobalParams(context);
kCalculateCustomExternalForces(data.gpu);
return 0.0;
......@@ -900,10 +834,6 @@ void OPENMMCUDA_EXPORT OpenMM::cudaOpenMMInitializeIntegration(const System& sys
cudaThreadSynchronize();
}
double CudaCalcGBSAOBCForceKernel::executeEnergy(ContextImpl& context) {
return 0.0;
}
CudaIntegrateVerletStepKernel::~CudaIntegrateVerletStepKernel() {
}
......
......@@ -59,36 +59,26 @@ public:
*/
void initialize(const System& system);
/**
* This is called at the beginning of each force computation, before calcForces() has been called on
* This is called at the beginning of each force/energy computation, before calcForcesAndEnergy() has been called on
* any ForceImpl.
*
* @param context the context in which to execute this kernel
*/
void beginForceComputation(ContextImpl& context);
/**
* This is called at the end of each force computation, after calcForces() has been called on
* every ForceImpl.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForce true if forces should be computed
* @param includeEnergy true if potential energy should be computed
*/
void finishForceComputation(ContextImpl& context);
void beginComputation(ContextImpl& context, bool includeForce, bool includeEnergy);
/**
* This is called at the beginning of each energy computation, before calcEnergy() has been called on
* any ForceImpl.
*
* @param context the context in which to execute this kernel
*/
void beginEnergyComputation(ContextImpl& context);
/**
* This is called at the end of each energy computation, after calcEnergy() has been called on
* This is called at the end of each force/energy computation, after calcForcesAndEnergy() has been called on
* every ForceImpl.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForce true if forces should be computed
* @param includeEnergy true if potential energy should be computed
* @return the potential energy of the system. This value is added to all values returned by ForceImpls'
* calcEnergy() methods. That is, each force kernel may <i>either</i> return its contribution to the
* calcForcesAndEnergy() methods. That is, each force kernel may <i>either</i> return its contribution to the
* energy directly, <i>or</i> add it to an internal buffer so that it will be included here.
*/
double finishEnergyComputation(ContextImpl& context);
double finishComputation(ContextImpl& context, bool includeForce, bool includeEnergy);
private:
CudaPlatform::PlatformData& data;
};
......@@ -209,18 +199,14 @@ public:
*/
void initialize(const System& system, const HarmonicBondForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicBondForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numBonds;
CudaPlatform::PlatformData& data;
......@@ -244,18 +230,14 @@ public:
*/
void initialize(const System& system, const CustomBondForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomBondForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
void updateGlobalParams(ContextImpl& context);
int numBonds;
......@@ -281,18 +263,14 @@ public:
*/
void initialize(const System& system, const HarmonicAngleForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicAngleForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numAngles;
CudaPlatform::PlatformData& data;
......@@ -316,18 +294,14 @@ public:
*/
void initialize(const System& system, const CustomAngleForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomAngleForce
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
void updateGlobalParams(ContextImpl& context);
int numAngles;
......@@ -353,18 +327,14 @@ public:
*/
void initialize(const System& system, const PeriodicTorsionForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the PeriodicTorsionForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numTorsions;
CudaPlatform::PlatformData& data;
......@@ -387,18 +357,14 @@ public:
*/
void initialize(const System& system, const RBTorsionForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the RBTorsionForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numTorsions;
CudaPlatform::PlatformData& data;
......@@ -423,18 +389,14 @@ public:
*/
void initialize(const System& system, const CMAPTorsionForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CMAPTorsionForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
CudaPlatform::PlatformData& data;
System& system;
......@@ -462,18 +424,14 @@ public:
*/
void initialize(const System& system, const CustomTorsionForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomTorsionForce
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
void updateGlobalParams(ContextImpl& context);
int numTorsions;
......@@ -499,18 +457,14 @@ public:
*/
void initialize(const System& system, const NonbondedForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the NonbondedForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
CudaPlatform::PlatformData& data;
int numParticles;
......@@ -533,18 +487,14 @@ public:
*/
void initialize(const System& system, const CustomNonbondedForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomNonbondedForce
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
void updateGlobalParams(ContextImpl& context);
CudaPlatform::PlatformData& data;
......@@ -570,18 +520,14 @@ public:
*/
void initialize(const System& system, const GBSAOBCForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the GBSAOBCForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
CudaPlatform::PlatformData& data;
};
......@@ -603,18 +549,14 @@ public:
*/
void initialize(const System& system, const GBVIForce& force, const std::vector<double> & scaledRadii);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the GBVIForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
CudaPlatform::PlatformData& data;
};
......@@ -636,18 +578,14 @@ public:
*/
void initialize(const System& system, const CustomExternalForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomExternalForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
void updateGlobalParams(ContextImpl& context);
int numParticles;
......
......@@ -70,7 +70,7 @@ static bool isZeroExpression(const Lepton::ParsedExpression& expression) {
void OpenCLCalcForcesAndEnergyKernel::initialize(const System& system) {
}
void OpenCLCalcForcesAndEnergyKernel::beginForceComputation(ContextImpl& context) {
void OpenCLCalcForcesAndEnergyKernel::beginComputation(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (cl.getNonbondedUtilities().getUseCutoff() && cl.getComputeForceCount()%100 == 0)
cl.reorderAtoms();
cl.setComputeForceCount(cl.getComputeForceCount()+1);
......@@ -78,26 +78,17 @@ void OpenCLCalcForcesAndEnergyKernel::beginForceComputation(ContextImpl& context
cl.getNonbondedUtilities().prepareInteractions();
}
void OpenCLCalcForcesAndEnergyKernel::finishForceComputation(ContextImpl& context) {
double OpenCLCalcForcesAndEnergyKernel::finishComputation(ContextImpl& context, bool includeForces, bool includeEnergy) {
cl.getNonbondedUtilities().computeInteractions();
cl.reduceBuffer(cl.getForceBuffers(), cl.getNumForceBuffers());
}
void OpenCLCalcForcesAndEnergyKernel::beginEnergyComputation(ContextImpl& context) {
if (cl.getNonbondedUtilities().getUseCutoff() && cl.getComputeForceCount()%100 == 0)
cl.reorderAtoms();
cl.setComputeForceCount(cl.getComputeForceCount()+1);
cl.clearAutoclearBuffers();
cl.getNonbondedUtilities().prepareInteractions();
}
double OpenCLCalcForcesAndEnergyKernel::finishEnergyComputation(ContextImpl& context) {
cl.getNonbondedUtilities().computeInteractions();
OpenCLArray<cl_float>& energy = cl.getEnergyBuffer();
energy.download();
if (includeForces)
cl.reduceBuffer(cl.getForceBuffers(), cl.getNumForceBuffers());
double sum = 0.0f;
for (int i = 0; i < energy.getSize(); i++)
sum += energy[i];
if (includeEnergy) {
OpenCLArray<cl_float>& energy = cl.getEnergyBuffer();
energy.download();
for (int i = 0; i < energy.getSize(); i++)
sum += energy[i];
}
return sum;
}
......@@ -257,9 +248,9 @@ void OpenCLCalcHarmonicBondForceKernel::initialize(const System& system, const H
kernel = cl::Kernel(program, "calcHarmonicBondForce");
}
void OpenCLCalcHarmonicBondForceKernel::executeForces(ContextImpl& context) {
double OpenCLCalcHarmonicBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numBonds == 0)
return;
return 0.0;
if (!hasInitializedKernel) {
hasInitializedKernel = true;
kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms());
......@@ -271,10 +262,6 @@ void OpenCLCalcHarmonicBondForceKernel::executeForces(ContextImpl& context) {
kernel.setArg<cl::Buffer>(6, indices->getDeviceBuffer());
}
cl.executeKernel(kernel, numBonds);
}
double OpenCLCalcHarmonicBondForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0;
}
......@@ -390,9 +377,9 @@ void OpenCLCalcCustomBondForceKernel::initialize(const System& system, const Cus
kernel = cl::Kernel(program, "computeCustomBondForces");
}
void OpenCLCalcCustomBondForceKernel::executeForces(ContextImpl& context) {
double OpenCLCalcCustomBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numBonds == 0)
return;
return 0.0;
if (globals != NULL) {
bool changed = false;
for (int i = 0; i < (int) globalParamNames.size(); i++) {
......@@ -421,10 +408,6 @@ void OpenCLCalcCustomBondForceKernel::executeForces(ContextImpl& context) {
}
}
cl.executeKernel(kernel, numBonds);
}
double OpenCLCalcCustomBondForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0;
}
......@@ -490,9 +473,9 @@ void OpenCLCalcHarmonicAngleForceKernel::initialize(const System& system, const
kernel = cl::Kernel(program, "calcHarmonicAngleForce");
}
void OpenCLCalcHarmonicAngleForceKernel::executeForces(ContextImpl& context) {
double OpenCLCalcHarmonicAngleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numAngles == 0)
return;
return 0.0;
if (!hasInitializedKernel) {
hasInitializedKernel = true;
kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms());
......@@ -504,10 +487,6 @@ void OpenCLCalcHarmonicAngleForceKernel::executeForces(ContextImpl& context) {
kernel.setArg<cl::Buffer>(6, indices->getDeviceBuffer());
}
cl.executeKernel(kernel, numAngles);
}
double OpenCLCalcHarmonicAngleForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0;
}
......@@ -625,9 +604,9 @@ void OpenCLCalcCustomAngleForceKernel::initialize(const System& system, const Cu
kernel = cl::Kernel(program, "computeCustomAngleForces");
}
void OpenCLCalcCustomAngleForceKernel::executeForces(ContextImpl& context) {
double OpenCLCalcCustomAngleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numAngles == 0)
return;
return 0.0;
if (globals != NULL) {
bool changed = false;
for (int i = 0; i < (int) globalParamNames.size(); i++) {
......@@ -656,10 +635,6 @@ void OpenCLCalcCustomAngleForceKernel::executeForces(ContextImpl& context) {
}
}
cl.executeKernel(kernel, numAngles);
}
double OpenCLCalcCustomAngleForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0;
}
......@@ -726,9 +701,9 @@ void OpenCLCalcPeriodicTorsionForceKernel::initialize(const System& system, cons
kernel = cl::Kernel(program, "calcPeriodicTorsionForce");
}
void OpenCLCalcPeriodicTorsionForceKernel::executeForces(ContextImpl& context) {
double OpenCLCalcPeriodicTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numTorsions == 0)
return;
return 0.0;
if (!hasInitializedKernel) {
hasInitializedKernel = true;
kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms());
......@@ -740,10 +715,6 @@ void OpenCLCalcPeriodicTorsionForceKernel::executeForces(ContextImpl& context) {
kernel.setArg<cl::Buffer>(6, indices->getDeviceBuffer());
}
cl.executeKernel(kernel, numTorsions);
}
double OpenCLCalcPeriodicTorsionForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0;
}
......@@ -810,9 +781,9 @@ void OpenCLCalcRBTorsionForceKernel::initialize(const System& system, const RBTo
kernel = cl::Kernel(program, "calcRBTorsionForce");
}
void OpenCLCalcRBTorsionForceKernel::executeForces(ContextImpl& context) {
double OpenCLCalcRBTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numTorsions == 0)
return;
return 0.0;
if (!hasInitializedKernel) {
hasInitializedKernel = true;
kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms());
......@@ -824,10 +795,6 @@ void OpenCLCalcRBTorsionForceKernel::executeForces(ContextImpl& context) {
kernel.setArg<cl::Buffer>(6, indices->getDeviceBuffer());
}
cl.executeKernel(kernel, numTorsions);
}
double OpenCLCalcRBTorsionForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0;
}
......@@ -926,9 +893,9 @@ void OpenCLCalcCMAPTorsionForceKernel::initialize(const System& system, const CM
kernel = cl::Kernel(program, "computeCMAPTorsionForces");
}
void OpenCLCalcCMAPTorsionForceKernel::executeForces(ContextImpl& context) {
double OpenCLCalcCMAPTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numTorsions == 0)
return;
return 0.0;
if (!hasInitializedKernel) {
hasInitializedKernel = true;
kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms());
......@@ -942,10 +909,6 @@ void OpenCLCalcCMAPTorsionForceKernel::executeForces(ContextImpl& context) {
kernel.setArg<cl::Buffer>(8, torsionMaps->getDeviceBuffer());
}
cl.executeKernel(kernel, numTorsions);
}
double OpenCLCalcCMAPTorsionForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0;
}
......@@ -1065,9 +1028,9 @@ void OpenCLCalcCustomTorsionForceKernel::initialize(const System& system, const
kernel = cl::Kernel(program, "computeCustomTorsionForces");
}
void OpenCLCalcCustomTorsionForceKernel::executeForces(ContextImpl& context) {
double OpenCLCalcCustomTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numTorsions == 0)
return;
return 0.0;
if (globals != NULL) {
bool changed = false;
for (int i = 0; i < (int) globalParamNames.size(); i++) {
......@@ -1096,10 +1059,6 @@ void OpenCLCalcCustomTorsionForceKernel::executeForces(ContextImpl& context) {
}
}
cl.executeKernel(kernel, numTorsions);
}
double OpenCLCalcCustomTorsionForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0;
}
......@@ -1398,7 +1357,7 @@ void OpenCLCalcNonbondedForceKernel::initialize(const System& system, const Nonb
exceptionsKernel = cl::Kernel(program, "computeNonbondedExceptions");
}
void OpenCLCalcNonbondedForceKernel::executeForces(ContextImpl& context) {
double OpenCLCalcNonbondedForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (!hasInitializedKernel) {
hasInitializedKernel = true;
if (exceptionIndices != NULL) {
......@@ -1484,10 +1443,6 @@ void OpenCLCalcNonbondedForceKernel::executeForces(ContextImpl& context) {
pmeInterpolateForceKernel.setArg<mm_float4>(6, invBoxSize);
cl.executeKernel(pmeInterpolateForceKernel, cl.getNumAtoms());
}
}
double OpenCLCalcNonbondedForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
double energy = ewaldSelfEnergy;
if (dispersionCoefficient != 0.0) {
mm_float4 boxSize = cl.getPeriodicBoxSize();
......@@ -1644,7 +1599,7 @@ void OpenCLCalcCustomNonbondedForceKernel::initialize(const System& system, cons
cl.addForce(new OpenCLCustomNonbondedForceInfo(cl.getNonbondedUtilities().getNumForceBuffers(), force));
}
void OpenCLCalcCustomNonbondedForceKernel::executeForces(ContextImpl& context) {
double OpenCLCalcCustomNonbondedForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (globals != NULL) {
bool changed = false;
for (int i = 0; i < (int) globalParamNames.size(); i++) {
......@@ -1656,10 +1611,6 @@ void OpenCLCalcCustomNonbondedForceKernel::executeForces(ContextImpl& context) {
if (changed)
globals->upload(globalParamValues);
}
}
double OpenCLCalcCustomNonbondedForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0;
}
......@@ -1722,7 +1673,7 @@ void OpenCLCalcGBSAOBCForceKernel::initialize(const System& system, const GBSAOB
cl.addAutoclearBuffer(bornForce->getDeviceBuffer(), bornForce->getSize());
}
void OpenCLCalcGBSAOBCForceKernel::executeForces(ContextImpl& context) {
double OpenCLCalcGBSAOBCForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
OpenCLNonbondedUtilities& nb = cl.getNonbondedUtilities();
if (!hasCreatedKernels) {
// These Kernels cannot be created in initialize(), because the OpenCLNonbondedUtilities has not been initialized yet then.
......@@ -1805,10 +1756,6 @@ void OpenCLCalcGBSAOBCForceKernel::executeForces(ContextImpl& context) {
cl.executeKernel(reduceBornSumKernel, cl.getPaddedNumAtoms());
cl.executeKernel(force1Kernel, nb.getTiles().getSize()*OpenCLContext::TileSize);
cl.executeKernel(reduceBornForceKernel, cl.getPaddedNumAtoms());
}
double OpenCLCalcGBSAOBCForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0;
}
......@@ -2434,7 +2381,7 @@ void OpenCLCalcCustomGBForceKernel::initialize(const System& system, const Custo
}
}
void OpenCLCalcCustomGBForceKernel::executeForces(ContextImpl& context) {
double OpenCLCalcCustomGBForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
OpenCLNonbondedUtilities& nb = cl.getNonbondedUtilities();
if (!hasInitializedKernels) {
hasInitializedKernels = true;
......@@ -2584,10 +2531,6 @@ void OpenCLCalcCustomGBForceKernel::executeForces(ContextImpl& context) {
cl.executeKernel(perParticleEnergyKernel, cl.getPaddedNumAtoms());
if (needParameterGradient)
cl.executeKernel(gradientChainRuleKernel, cl.getPaddedNumAtoms());
}
double OpenCLCalcCustomGBForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0;
}
......@@ -2704,7 +2647,7 @@ void OpenCLCalcCustomExternalForceKernel::initialize(const System& system, const
kernel = cl::Kernel(program, "computeCustomExternalForces");
}
void OpenCLCalcCustomExternalForceKernel::executeForces(ContextImpl& context) {
double OpenCLCalcCustomExternalForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (globals != NULL) {
bool changed = false;
for (int i = 0; i < (int) globalParamNames.size(); i++) {
......@@ -2732,10 +2675,6 @@ void OpenCLCalcCustomExternalForceKernel::executeForces(ContextImpl& context) {
}
}
cl.executeKernel(kernel, numParticles);
}
double OpenCLCalcCustomExternalForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0;
}
......@@ -3166,7 +3105,7 @@ void OpenCLCalcCustomHbondForceKernel::initialize(const System& system, const Cu
acceptorKernel = cl::Kernel(program, "computeAcceptorForces");
}
void OpenCLCalcCustomHbondForceKernel::executeForces(ContextImpl& context) {
double OpenCLCalcCustomHbondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (globals != NULL) {
bool changed = false;
for (int i = 0; i < (int) globalParamNames.size(); i++) {
......@@ -3237,10 +3176,6 @@ void OpenCLCalcCustomHbondForceKernel::executeForces(ContextImpl& context) {
acceptorKernel.setArg<mm_float4>(8, cl.getPeriodicBoxSize());
acceptorKernel.setArg<mm_float4>(9, cl.getInvPeriodicBoxSize());
cl.executeKernel(acceptorKernel, std::max(numDonors, numAcceptors));
}
double OpenCLCalcCustomHbondForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0;
}
......
......@@ -54,36 +54,26 @@ public:
*/
void initialize(const System& system);
/**
* This is called at the beginning of each force computation, before calcForces() has been called on
* This is called at the beginning of each force/energy computation, before calcForcesAndEnergy() has been called on
* any ForceImpl.
*
* @param context the context in which to execute this kernel
*/
void beginForceComputation(ContextImpl& context);
/**
* This is called at the end of each force computation, after calcForces() has been called on
* every ForceImpl.
*
* @param context the context in which to execute this kernel
*/
void finishForceComputation(ContextImpl& context);
/**
* This is called at the beginning of each energy computation, before calcEnergy() has been called on
* any ForceImpl.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForce true if forces should be computed
* @param includeEnergy true if potential energy should be computed
*/
void beginEnergyComputation(ContextImpl& context);
void beginComputation(ContextImpl& context, bool includeForce, bool includeEnergy);
/**
* This is called at the end of each energy computation, after calcEnergy() has been called on
* This is called at the end of each force/energy computation, after calcForcesAndEnergy() has been called on
* every ForceImpl.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForce true if forces should be computed
* @param includeEnergy true if potential energy should be computed
* @return the potential energy of the system. This value is added to all values returned by ForceImpls'
* calcEnergy() methods. That is, each force kernel may <i>either</i> return its contribution to the
* calcForcesAndEnergy() methods. That is, each force kernel may <i>either</i> return its contribution to the
* energy directly, <i>or</i> add it to an internal buffer so that it will be included here.
*/
double finishEnergyComputation(ContextImpl& context);
double finishComputation(ContextImpl& context, bool includeForce, bool includeEnergy);
private:
OpenCLContext& cl;
};
......@@ -205,18 +195,14 @@ public:
*/
void initialize(const System& system, const HarmonicBondForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicBondForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numBonds;
bool hasInitializedKernel;
......@@ -244,18 +230,14 @@ public:
*/
void initialize(const System& system, const CustomBondForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomBondForce
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numBonds;
bool hasInitializedKernel;
......@@ -286,18 +268,14 @@ public:
*/
void initialize(const System& system, const HarmonicAngleForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicAngleForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numAngles;
bool hasInitializedKernel;
......@@ -325,18 +303,14 @@ public:
*/
void initialize(const System& system, const CustomAngleForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomAngleForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numAngles;
bool hasInitializedKernel;
......@@ -367,18 +341,14 @@ public:
*/
void initialize(const System& system, const PeriodicTorsionForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the PeriodicTorsionForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numTorsions;
bool hasInitializedKernel;
......@@ -406,18 +376,14 @@ public:
*/
void initialize(const System& system, const RBTorsionForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the RBTorsionForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numTorsions;
bool hasInitializedKernel;
......@@ -445,18 +411,14 @@ public:
*/
void initialize(const System& system, const CMAPTorsionForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CMAPTorsionForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numTorsions;
bool hasInitializedKernel;
......@@ -486,18 +448,14 @@ public:
*/
void initialize(const System& system, const CustomTorsionForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomTorsionForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numTorsions;
bool hasInitializedKernel;
......@@ -530,18 +488,14 @@ public:
*/
void initialize(const System& system, const NonbondedForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the NonbondedForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
OpenCLContext& cl;
bool hasInitializedKernel;
......@@ -591,18 +545,14 @@ public:
*/
void initialize(const System& system, const CustomNonbondedForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomNonbondedForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
bool hasInitializedKernel;
OpenCLContext& cl;
......@@ -631,18 +581,14 @@ public:
*/
void initialize(const System& system, const GBSAOBCForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the GBSAOBCForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
double prefactor;
bool hasCreatedKernels;
......@@ -676,18 +622,14 @@ public:
*/
void initialize(const System& system, const CustomGBForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomGBForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
bool hasInitializedKernels, needParameterGradient;
OpenCLContext& cl;
......@@ -721,18 +663,14 @@ public:
*/
void initialize(const System& system, const CustomExternalForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomExternalForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numParticles;
bool hasInitializedKernel;
......@@ -765,18 +703,14 @@ public:
*/
void initialize(const System& system, const CustomHbondForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomHbondForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numDonors, numAcceptors;
bool hasInitializedKernel;
......
......@@ -68,36 +68,26 @@ public:
*/
void initialize(const System& system);
/**
* This is called at the beginning of each force computation, before calcForces() has been called on
* This is called at the beginning of each force/energy computation, before calcForcesAndEnergy() has been called on
* any ForceImpl.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForce true if forces should be computed
* @param includeEnergy true if potential energy should be computed
*/
void beginForceComputation(ContextImpl& context);
void beginComputation(ContextImpl& context, bool includeForce, bool includeEnergy);
/**
* This is called at the end of each force computation, after calcForces() has been called on
* This is called at the end of each force/energy computation, after calcForcesAndEnergy() has been called on
* every ForceImpl.
*
* @param context the context in which to execute this kernel
*/
void finishForceComputation(ContextImpl& context);
/**
* This is called at the beginning of each energy computation, before calcEnergy() has been called on
* any ForceImpl.
*
* @param context the context in which to execute this kernel
*/
void beginEnergyComputation(ContextImpl& context);
/**
* This is called at the end of each energy computation, after calcEnergy() has been called on
* every ForceImpl.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForce true if forces should be computed
* @param includeEnergy true if potential energy should be computed
* @return the potential energy of the system. This value is added to all values returned by ForceImpls'
* calcEnergy() methods. That is, each force kernel may <i>either</i> return its contribution to the
* calcForcesAndEnergy() methods. That is, each force kernel may <i>either</i> return its contribution to the
* energy directly, <i>or</i> add it to an internal buffer so that it will be included here.
*/
double finishEnergyComputation(ContextImpl& context);
double finishComputation(ContextImpl& context, bool includeForce, bool includeEnergy);
};
/**
......@@ -224,18 +214,14 @@ public:
*/
void initialize(const System& system, const HarmonicBondForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicBondForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numBonds;
int **bondIndexArray;
......@@ -258,18 +244,14 @@ public:
*/
void initialize(const System& system, const CustomBondForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomBondForce
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numBonds;
int **bondIndexArray;
......@@ -294,18 +276,14 @@ public:
*/
void initialize(const System& system, const HarmonicAngleForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicAngleForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numAngles;
int **angleIndexArray;
......@@ -328,18 +306,14 @@ public:
*/
void initialize(const System& system, const CustomAngleForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomAngleForce
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numAngles;
int **angleIndexArray;
......@@ -364,18 +338,14 @@ public:
*/
void initialize(const System& system, const PeriodicTorsionForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the PeriodicTorsionForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numTorsions;
int **torsionIndexArray;
......@@ -398,18 +368,14 @@ public:
*/
void initialize(const System& system, const RBTorsionForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the RBTorsionForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numTorsions;
int **torsionIndexArray;
......@@ -431,18 +397,14 @@ public:
*/
void initialize(const System& system, const CMAPTorsionForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CMAPTorsionForce
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
std::vector<std::vector<std::vector<RealOpenMM> > > coeff;
std::vector<int> torsionMaps;
......@@ -465,18 +427,14 @@ public:
*/
void initialize(const System& system, const CustomTorsionForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomTorsionForce
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numTorsions;
int **torsionIndexArray;
......@@ -501,18 +459,14 @@ public:
*/
void initialize(const System& system, const NonbondedForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the NonbondedForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numParticles, num14;
int **exclusionArray, **bonded14IndexArray;
......@@ -540,18 +494,14 @@ public:
*/
void initialize(const System& system, const CustomNonbondedForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomNonbondedForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numParticles;
int **exclusionArray;
......@@ -580,18 +530,14 @@ public:
*/
void initialize(const System& system, const GBSAOBCForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the GBSAOBCForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
CpuObc* obc;
std::vector<RealOpenMM> charges;
......@@ -615,18 +561,14 @@ public:
*/
void initialize(const System& system, const GBVIForce& force, const std::vector<double> & scaledRadii);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the GBVIForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
CpuGBVI * gbvi;
std::vector<RealOpenMM> charges;
......@@ -649,18 +591,14 @@ public:
*/
void initialize(const System& system, const CustomGBForce& force);
/**
* Execute the kernel to calculate the forces.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomGBForce
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numParticles;
bool isPeriodic;
......@@ -696,18 +634,14 @@ public:
*/
void initialize(const System& system, const CustomExternalForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomExternalForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numParticles;
std::vector<int> particles;
......@@ -732,18 +666,14 @@ public:
*/
void initialize(const System& system, const CustomHbondForce& force);
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomHbondForce
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
double executeEnergy(ContextImpl& context);
double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
int numDonors, numAcceptors, numParticles;
bool isPeriodic;
......
#ifndef AMOEBA_OPENMM_GBSA_OBC_FORCE_FIELD_H_
#define AMOEBA_OPENMM_GBSA_OBC_FORCE_FIELD_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2009 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/Force.h"
#include <vector>
#include "openmm/internal/windowsExport.h"
namespace OpenMM {
/**
* This class implements an implicit solvation force using the GBSA-OBC model.
* <p>
* To use this class, create a AmoebaGBSAOBCForce object, then call addParticle() once for each particle in the
* System to define its parameters. The number of particles for which you define GBSA parameters must
* be exactly equal to the number of particles in the System, or else an exception will be thrown when you
* try to create a Context. After a particle has been added, you can modify its force field parameters
* by calling setParticleParameters().
*/
class OPENMM_EXPORT AmoebaGBSAOBCForce : public Force {
public:
/**
* This is an enumeration of the different methods that may be used for handling long range nonbonded forces.
*/
enum NonbondedMethod {
/**
* No cutoff is applied to nonbonded interactions. The full set of N^2 interactions is computed exactly.
* This necessarily means that periodic boundary conditions cannot be used. This is the default.
*/
NoCutoff = 0,
/**
* Interactions beyond the cutoff distance are ignored.
*/
CutoffNonPeriodic = 1,
/**
* Periodic boundary conditions are used, so that each particle interacts only with the nearest periodic copy of
* each other particle. Interactions beyond the cutoff distance are ignored.
*/
CutoffPeriodic = 2,
};
/*
* Create a AmoebaGBSAOBCForce.
*/
AmoebaGBSAOBCForce();
/**
* Get the number of particles in the system.
*/
int getNumParticles() const {
return particles.size();
}
/**
* Add the GBSA parameters for a particle. This should be called once for each particle
* in the System. When it is called for the i'th time, it specifies the parameters for the i'th particle.
*
* @param charge the charge of the particle, measured in units of the proton charge
* @param radius the GBSA radius of the particle, measured in nm
* @param scalingFactor the OBC scaling factor for the particle
* @return the index of the particle that was added
*/
int addParticle(double charge, double radius, double scalingFactor);
/**
* Get the force field parameters for a particle.
*
* @param index the index of the particle for which to get parameters
* @param charge the charge of the particle, measured in units of the proton charge
* @param radius the GBSA radius of the particle, measured in nm
* @param scalingFactor the OBC scaling factor for the particle
*/
void getParticleParameters(int index, double& charge, double& radius, double& scalingFactor) const;
/**
* Set the force field parameters for a particle.
*
* @param index the index of the particle for which to set parameters
* @param charge the charge of the particle, measured in units of the proton charge
* @param radius the GBSA radius of the particle, measured in nm
* @param scalingFactor the OBC scaling factor for the particle
*/
void setParticleParameters(int index, double charge, double radius, double scalingFactor);
/**
* Get the dielectric constant for the solvent.
*/
double getSolventDielectric() const {
return solventDielectric;
}
/**
* Set the dielectric constant for the solvent.
*/
void setSolventDielectric(double dielectric) {
solventDielectric = dielectric;
}
/**
* Get the dielectric constant for the solute.
*/
double getSoluteDielectric() const {
return soluteDielectric;
}
/**
* Set the dielectric constant for the solute.
*/
void setSoluteDielectric(double dielectric) {
soluteDielectric = dielectric;
}
/**
* Get the method used for handling long range nonbonded interactions.
*/
NonbondedMethod getNonbondedMethod() const;
/**
* Set the method used for handling long range nonbonded interactions.
*/
void setNonbondedMethod(NonbondedMethod method);
/**
* Get the cutoff distance (in nm) being used for nonbonded interactions. If the NonbondedMethod in use
* is NoCutoff, this value will have no effect.
*/
double getCutoffDistance() const;
/**
* Set the cutoff distance (in nm) being used for nonbonded interactions. If the NonbondedMethod in use
* is NoCutoff, this value will have no effect.
*/
void setCutoffDistance(double distance);
protected:
ForceImpl* createImpl();
private:
class ParticleInfo;
NonbondedMethod nonbondedMethod;
double cutoffDistance, solventDielectric, soluteDielectric;
std::vector<ParticleInfo> particles;
};
class AmoebaGBSAOBCForce::ParticleInfo {
public:
double charge, radius, scalingFactor;
ParticleInfo() {
charge = radius = scalingFactor = 0.0;
}
ParticleInfo(double charge, double radius, double scalingFactor) :
charge(charge), radius(radius), scalingFactor(scalingFactor) {
}
};
} // namespace OpenMM
#endif /*AMOEBA_OPENMM_GBSA_OBC_FORCE_FIELD_H_*/
......@@ -61,18 +61,14 @@ public:
*/
virtual void initialize(const System& system, const AmoebaHarmonicBondForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicBondForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
};
/**
......@@ -93,18 +89,14 @@ public:
*/
virtual void initialize(const System& system, const AmoebaHarmonicAngleForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicAngleForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
virtual double executeEnergy(ContextImpl& context) = 0;
virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
};
/**
......@@ -125,18 +117,14 @@ public:
*/
virtual void initialize(const System& system, const AmoebaHarmonicInPlaneAngleForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicInPlaneAngleForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
};
/**
......@@ -157,18 +145,14 @@ public:
*/
virtual void initialize(const System& system, const AmoebaTorsionForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the TorsionForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
};
/**
......@@ -189,18 +173,14 @@ public:
*/
virtual void initialize(const System& system, const AmoebaPiTorsionForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the PiTorsionForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
virtual double executeEnergy(ContextImpl& context) = 0;
virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
};
/**
......@@ -221,18 +201,14 @@ public:
*/
virtual void initialize(const System& system, const AmoebaStretchBendForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the StretchBendForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
virtual double executeEnergy(ContextImpl& context) = 0;
virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
};
/**
......@@ -253,18 +229,14 @@ public:
*/
virtual void initialize(const System& system, const AmoebaOutOfPlaneBendForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the OutOfPlaneBendForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
};
/**
......@@ -285,18 +257,14 @@ public:
*/
virtual void initialize(const System& system, const AmoebaTorsionTorsionForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the TorsionTorsionForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
};
/**
......@@ -317,18 +285,14 @@ public:
*/
virtual void initialize(const System& system, const AmoebaMultipoleForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the MultipoleForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
};
/**
......@@ -350,18 +314,14 @@ public:
*/
virtual void initialize(const System& system, const AmoebaGeneralizedKirkwoodForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the GBSAOBCForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
virtual double executeEnergy(ContextImpl& context) = 0;
virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
};
/**
......@@ -383,18 +343,14 @@ public:
*/
virtual void initialize(const System& system, const AmoebaSASAForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the GBSAOBCForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
};
/**
......@@ -416,18 +372,14 @@ public:
*/
virtual void initialize(const System& system, const AmoebaVdwForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the GBSAOBCForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
};
/**
......@@ -449,18 +401,14 @@ public:
*/
virtual void initialize(const System& system, const AmoebaWcaDispersionForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the GBSAOBCForce
* Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/
virtual double executeEnergy(ContextImpl& context) = 0;
virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
};
} // namespace OpenMM
......
#ifndef OPENMM_AMOEBA_GBSA_OBC_FORCE_FIELD_IMPL_H_
#define OPENMM_AMOEBA_GBSA_OBC_FORCE_FIELD_IMPL_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/ForceImpl.h"
#include "AmoebaGBSAOBCForce.h"
#include "openmm/Kernel.h"
#include <string>
namespace OpenMM {
/**
* This is the internal implementation of AmoebaGBSAOBCForce.
*/
class AmoebaGBSAOBCForceImpl : public ForceImpl {
public:
AmoebaGBSAOBCForceImpl(AmoebaGBSAOBCForce& owner);
void initialize(ContextImpl& context);
AmoebaGBSAOBCForce& getOwner() {
return owner;
}
void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly.
}
void calcForces(ContextImpl& context);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
std::vector<std::string> getKernelNames();
private:
AmoebaGBSAOBCForce& owner;
Kernel kernel;
};
} // namespace OpenMM
#endif /*OPENMM_AMOEBA_GBSA_OBC_FORCE_FIELD_IMPL_H_*/
......@@ -53,8 +53,7 @@ public:
void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly.
}
void calcForces(ContextImpl& context);
double calcEnergy(ContextImpl& context);
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
......
......@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly.
}
void calcForces(ContextImpl& context );
double calcEnergy(ContextImpl& context);
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
......
......@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly.
}
void calcForces(ContextImpl& context );
double calcEnergy(ContextImpl& context);
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
......
......@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly.
}
void calcForces(ContextImpl& context );
double calcEnergy(ContextImpl& context);
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
......
......@@ -55,8 +55,7 @@ public:
void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly.
}
void calcForces(ContextImpl& context );
double calcEnergy(ContextImpl& context);
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
......
......@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly.
}
void calcForces(ContextImpl& context );
double calcEnergy(ContextImpl& context);
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
......
......@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly.
}
void calcForces(ContextImpl& context );
double calcEnergy(ContextImpl& context);
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
......
......@@ -53,8 +53,7 @@ public:
void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly.
}
void calcForces(ContextImpl& context);
double calcEnergy(ContextImpl& context);
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
......
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