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() { ...@@ -64,7 +64,7 @@ vector<string> VariableLangevinIntegrator::getKernelNames() {
void VariableLangevinIntegrator::step(int steps) { void VariableLangevinIntegrator::step(int steps) {
for (int i = 0; i < steps; ++i) { for (int i = 0; i < steps; ++i) {
context->updateContextState(); context->updateContextState();
context->calcForces(); context->calcForcesAndEnergy(true, false);
dynamic_cast<IntegrateVariableLangevinStepKernel&>(kernel.getImpl()).execute(*context, *this, std::numeric_limits<double>::infinity()); dynamic_cast<IntegrateVariableLangevinStepKernel&>(kernel.getImpl()).execute(*context, *this, std::numeric_limits<double>::infinity());
} }
} }
...@@ -72,7 +72,7 @@ void VariableLangevinIntegrator::step(int steps) { ...@@ -72,7 +72,7 @@ void VariableLangevinIntegrator::step(int steps) {
void VariableLangevinIntegrator::stepTo(double time) { void VariableLangevinIntegrator::stepTo(double time) {
while (time > context->getTime()) { while (time > context->getTime()) {
context->updateContextState(); context->updateContextState();
context->calcForces(); context->calcForcesAndEnergy(true, false);
dynamic_cast<IntegrateVariableLangevinStepKernel&>(kernel.getImpl()).execute(*context, *this, time); dynamic_cast<IntegrateVariableLangevinStepKernel&>(kernel.getImpl()).execute(*context, *this, time);
} }
} }
...@@ -59,7 +59,7 @@ vector<string> VariableVerletIntegrator::getKernelNames() { ...@@ -59,7 +59,7 @@ vector<string> VariableVerletIntegrator::getKernelNames() {
void VariableVerletIntegrator::step(int steps) { void VariableVerletIntegrator::step(int steps) {
for (int i = 0; i < steps; ++i) { for (int i = 0; i < steps; ++i) {
context->updateContextState(); context->updateContextState();
context->calcForces(); context->calcForcesAndEnergy(true, false);
dynamic_cast<IntegrateVariableVerletStepKernel&>(kernel.getImpl()).execute(*context, *this, std::numeric_limits<double>::infinity()); dynamic_cast<IntegrateVariableVerletStepKernel&>(kernel.getImpl()).execute(*context, *this, std::numeric_limits<double>::infinity());
} }
} }
...@@ -67,7 +67,7 @@ void VariableVerletIntegrator::step(int steps) { ...@@ -67,7 +67,7 @@ void VariableVerletIntegrator::step(int steps) {
void VariableVerletIntegrator::stepTo(double time) { void VariableVerletIntegrator::stepTo(double time) {
while (time > context->getTime()) { while (time > context->getTime()) {
context->updateContextState(); context->updateContextState();
context->calcForces(); context->calcForcesAndEnergy(true, false);
dynamic_cast<IntegrateVariableVerletStepKernel&>(kernel.getImpl()).execute(*context, *this, time); dynamic_cast<IntegrateVariableVerletStepKernel&>(kernel.getImpl()).execute(*context, *this, time);
} }
} }
...@@ -59,7 +59,7 @@ vector<string> VerletIntegrator::getKernelNames() { ...@@ -59,7 +59,7 @@ vector<string> VerletIntegrator::getKernelNames() {
void VerletIntegrator::step(int steps) { void VerletIntegrator::step(int steps) {
for (int i = 0; i < steps; ++i) { for (int i = 0; i < steps; ++i) {
context->updateContextState(); context->updateContextState();
context->calcForces(); context->calcForcesAndEnergy(true, false);
dynamic_cast<IntegrateVerletStepKernel&>(kernel.getImpl()).execute(*context, *this); dynamic_cast<IntegrateVerletStepKernel&>(kernel.getImpl()).execute(*context, *this);
} }
} }
...@@ -44,49 +44,23 @@ using namespace std; ...@@ -44,49 +44,23 @@ using namespace std;
void CudaCalcForcesAndEnergyKernel::initialize(const System& system) { void CudaCalcForcesAndEnergyKernel::initialize(const System& system) {
} }
void CudaCalcForcesAndEnergyKernel::beginForceComputation(ContextImpl& context) { void CudaCalcForcesAndEnergyKernel::beginComputation(ContextImpl& context, bool includeForces, bool includeEnergy) {
_gpuContext* gpu = data.gpu; _gpuContext* gpu = data.gpu;
if (data.nonbondedMethod != NO_CUTOFF && data.computeForceCount%100 == 0) if (data.nonbondedMethod != NO_CUTOFF && data.computeForceCount%100 == 0)
gpuReorderAtoms(gpu); gpuReorderAtoms(gpu);
data.computeForceCount++; if (includeForces)
data.computeForceCount++;
if (gpu->bIncludeGBSA || gpu->bIncludeGBVI) if (gpu->bIncludeGBSA || gpu->bIncludeGBVI)
kClearBornSumAndForces(gpu); kClearBornSumAndForces(gpu);
else else if (includeForces)
kClearForces(gpu); kClearForces(gpu);
} if (includeEnergy) {
data.stepCount++;
void CudaCalcForcesAndEnergyKernel::finishForceComputation(ContextImpl& context) { kClearEnergy(gpu);
_gpuContext* gpu = data.gpu;
if (gpu->bIncludeGBSA || gpu->bIncludeGBVI) {
gpu->bRecalculateBornRadii = true;
kCalculateCDLJObcGbsaForces1(gpu);
kReduceObcGbsaBornForces(gpu);
if (gpu->bIncludeGBSA ) {
kCalculateObcGbsaForces2(gpu);
} else {
kCalculateGBVIForces2(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; _gpuContext* gpu = data.gpu;
if (gpu->bIncludeGBSA || gpu->bIncludeGBVI) { if (gpu->bIncludeGBSA || gpu->bIncludeGBVI) {
gpu->bRecalculateBornRadii = true; gpu->bRecalculateBornRadii = true;
...@@ -103,9 +77,14 @@ double CudaCalcForcesAndEnergyKernel::finishEnergyComputation(ContextImpl& conte ...@@ -103,9 +77,14 @@ double CudaCalcForcesAndEnergyKernel::finishEnergyComputation(ContextImpl& conte
if (data.hasCustomNonbonded) if (data.hasCustomNonbonded)
kCalculateCustomNonbondedForces(gpu, data.hasNonbonded); kCalculateCustomNonbondedForces(gpu, data.hasNonbonded);
kCalculateLocalForces(gpu); kCalculateLocalForces(gpu);
double energy = kReduceEnergy(gpu)+data.ewaldSelfEnergy; if (includeForces)
if (data.dispersionCoefficient != 0.0) kReduceForces(gpu);
energy += data.dispersionCoefficient/(gpu->sim.periodicBoxSizeX*gpu->sim.periodicBoxSizeY*gpu->sim.periodicBoxSizeZ); 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; return energy;
} }
...@@ -226,10 +205,7 @@ void CudaCalcHarmonicBondForceKernel::initialize(const System& system, const Har ...@@ -226,10 +205,7 @@ void CudaCalcHarmonicBondForceKernel::initialize(const System& system, const Har
gpuSetBondParameters(data.gpu, particle1, particle2, length, k); gpuSetBondParameters(data.gpu, particle1, particle2, length, k);
} }
void CudaCalcHarmonicBondForceKernel::executeForces(ContextImpl& context) { double CudaCalcHarmonicBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
}
double CudaCalcHarmonicBondForceKernel::executeEnergy(ContextImpl& context) {
return 0.0; return 0.0;
} }
...@@ -257,12 +233,7 @@ void CudaCalcCustomBondForceKernel::initialize(const System& system, const Custo ...@@ -257,12 +233,7 @@ void CudaCalcCustomBondForceKernel::initialize(const System& system, const Custo
SetCustomBondGlobalParams(globalParamValues); SetCustomBondGlobalParams(globalParamValues);
} }
void CudaCalcCustomBondForceKernel::executeForces(ContextImpl& context) { double CudaCalcCustomBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
updateGlobalParams(context);
kCalculateCustomBondForces(data.gpu);
}
double CudaCalcCustomBondForceKernel::executeEnergy(ContextImpl& context) {
updateGlobalParams(context); updateGlobalParams(context);
kCalculateCustomBondForces(data.gpu); kCalculateCustomBondForces(data.gpu);
return 0.0; return 0.0;
...@@ -301,10 +272,7 @@ void CudaCalcHarmonicAngleForceKernel::initialize(const System& system, const Ha ...@@ -301,10 +272,7 @@ void CudaCalcHarmonicAngleForceKernel::initialize(const System& system, const Ha
gpuSetBondAngleParameters(data.gpu, particle1, particle2, particle3, angle, k); gpuSetBondAngleParameters(data.gpu, particle1, particle2, particle3, angle, k);
} }
void CudaCalcHarmonicAngleForceKernel::executeForces(ContextImpl& context) { double CudaCalcHarmonicAngleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
}
double CudaCalcHarmonicAngleForceKernel::executeEnergy(ContextImpl& context) {
return 0.0; return 0.0;
} }
...@@ -333,12 +301,7 @@ void CudaCalcCustomAngleForceKernel::initialize(const System& system, const Cust ...@@ -333,12 +301,7 @@ void CudaCalcCustomAngleForceKernel::initialize(const System& system, const Cust
SetCustomAngleGlobalParams(globalParamValues); SetCustomAngleGlobalParams(globalParamValues);
} }
void CudaCalcCustomAngleForceKernel::executeForces(ContextImpl& context) { double CudaCalcCustomAngleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
updateGlobalParams(context);
kCalculateCustomAngleForces(data.gpu);
}
double CudaCalcCustomAngleForceKernel::executeEnergy(ContextImpl& context) {
updateGlobalParams(context); updateGlobalParams(context);
kCalculateCustomAngleForces(data.gpu); kCalculateCustomAngleForces(data.gpu);
return 0.0; return 0.0;
...@@ -379,10 +342,7 @@ void CudaCalcPeriodicTorsionForceKernel::initialize(const System& system, const ...@@ -379,10 +342,7 @@ void CudaCalcPeriodicTorsionForceKernel::initialize(const System& system, const
gpuSetDihedralParameters(data.gpu, particle1, particle2, particle3, particle4, k, phase, periodicity); gpuSetDihedralParameters(data.gpu, particle1, particle2, particle3, particle4, k, phase, periodicity);
} }
void CudaCalcPeriodicTorsionForceKernel::executeForces(ContextImpl& context) { double CudaCalcPeriodicTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
}
double CudaCalcPeriodicTorsionForceKernel::executeEnergy(ContextImpl& context) {
return 0.0; return 0.0;
} }
...@@ -415,10 +375,7 @@ void CudaCalcRBTorsionForceKernel::initialize(const System& system, const RBTors ...@@ -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); gpuSetRbDihedralParameters(data.gpu, particle1, particle2, particle3, particle4, c0, c1, c2, c3, c4, c5);
} }
void CudaCalcRBTorsionForceKernel::executeForces(ContextImpl& context) { double CudaCalcRBTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
}
double CudaCalcRBTorsionForceKernel::executeEnergy(ContextImpl& context) {
return 0.0; return 0.0;
} }
...@@ -483,11 +440,7 @@ void CudaCalcCMAPTorsionForceKernel::initialize(const System& system, const CMAP ...@@ -483,11 +440,7 @@ void CudaCalcCMAPTorsionForceKernel::initialize(const System& system, const CMAP
data.gpu->sim.outputBuffers = maxBuffers; data.gpu->sim.outputBuffers = maxBuffers;
} }
void CudaCalcCMAPTorsionForceKernel::executeForces(ContextImpl& context) { double CudaCalcCMAPTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
kCalculateCMAPTorsionForces(data.gpu, *coefficients, *mapPositions, *torsionIndices, *torsionMaps);
}
double CudaCalcCMAPTorsionForceKernel::executeEnergy(ContextImpl& context) {
kCalculateCMAPTorsionForces(data.gpu, *coefficients, *mapPositions, *torsionIndices, *torsionMaps); kCalculateCMAPTorsionForces(data.gpu, *coefficients, *mapPositions, *torsionIndices, *torsionMaps);
return 0.0; return 0.0;
} }
...@@ -518,12 +471,7 @@ void CudaCalcCustomTorsionForceKernel::initialize(const System& system, const Cu ...@@ -518,12 +471,7 @@ void CudaCalcCustomTorsionForceKernel::initialize(const System& system, const Cu
SetCustomTorsionGlobalParams(globalParamValues); SetCustomTorsionGlobalParams(globalParamValues);
} }
void CudaCalcCustomTorsionForceKernel::executeForces(ContextImpl& context) { double CudaCalcCustomTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
updateGlobalParams(context);
kCalculateCustomTorsionForces(data.gpu);
}
double CudaCalcCustomTorsionForceKernel::executeEnergy(ContextImpl& context) {
updateGlobalParams(context); updateGlobalParams(context);
kCalculateCustomTorsionForces(data.gpu); kCalculateCustomTorsionForces(data.gpu);
return 0.0; return 0.0;
...@@ -650,10 +598,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon ...@@ -650,10 +598,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon
} }
} }
void CudaCalcNonbondedForceKernel::executeForces(ContextImpl& context) { double CudaCalcNonbondedForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
}
double CudaCalcNonbondedForceKernel::executeEnergy(ContextImpl& context) {
return 0.0; return 0.0;
} }
...@@ -716,11 +661,7 @@ void CudaCalcCustomNonbondedForceKernel::initialize(const System& system, const ...@@ -716,11 +661,7 @@ void CudaCalcCustomNonbondedForceKernel::initialize(const System& system, const
SetCustomNonbondedGlobalParams(globalParamValues); SetCustomNonbondedGlobalParams(globalParamValues);
} }
void CudaCalcCustomNonbondedForceKernel::executeForces(ContextImpl& context) { double CudaCalcCustomNonbondedForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
updateGlobalParams(context);
}
double CudaCalcCustomNonbondedForceKernel::executeEnergy(ContextImpl& context) {
updateGlobalParams(context); updateGlobalParams(context);
return 0.0; return 0.0;
} }
...@@ -757,7 +698,8 @@ void CudaCalcGBSAOBCForceKernel::initialize(const System& system, const GBSAOBCF ...@@ -757,7 +698,8 @@ void CudaCalcGBSAOBCForceKernel::initialize(const System& system, const GBSAOBCF
gpuSetObcParameters(gpu, (float) force.getSoluteDielectric(), (float) force.getSolventDielectric(), radius, scale, charge); 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() { CudaCalcGBVIForceKernel::~CudaCalcGBVIForceKernel() {
...@@ -785,10 +727,7 @@ void CudaCalcGBVIForceKernel::initialize(const System& system, const GBVIForce& ...@@ -785,10 +727,7 @@ void CudaCalcGBVIForceKernel::initialize(const System& system, const GBVIForce&
radius, gammas, scaledRadii ); radius, gammas, scaledRadii );
} }
void CudaCalcGBVIForceKernel::executeForces(ContextImpl& context) { double CudaCalcGBVIForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
}
double CudaCalcGBVIForceKernel::executeEnergy(ContextImpl& context) {
return 0.0; return 0.0;
} }
...@@ -815,12 +754,7 @@ void CudaCalcCustomExternalForceKernel::initialize(const System& system, const C ...@@ -815,12 +754,7 @@ void CudaCalcCustomExternalForceKernel::initialize(const System& system, const C
SetCustomExternalGlobalParams(globalParamValues); SetCustomExternalGlobalParams(globalParamValues);
} }
void CudaCalcCustomExternalForceKernel::executeForces(ContextImpl& context) { double CudaCalcCustomExternalForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
updateGlobalParams(context);
kCalculateCustomExternalForces(data.gpu);
}
double CudaCalcCustomExternalForceKernel::executeEnergy(ContextImpl& context) {
updateGlobalParams(context); updateGlobalParams(context);
kCalculateCustomExternalForces(data.gpu); kCalculateCustomExternalForces(data.gpu);
return 0.0; return 0.0;
...@@ -900,10 +834,6 @@ void OPENMMCUDA_EXPORT OpenMM::cudaOpenMMInitializeIntegration(const System& sys ...@@ -900,10 +834,6 @@ void OPENMMCUDA_EXPORT OpenMM::cudaOpenMMInitializeIntegration(const System& sys
cudaThreadSynchronize(); cudaThreadSynchronize();
} }
double CudaCalcGBSAOBCForceKernel::executeEnergy(ContextImpl& context) {
return 0.0;
}
CudaIntegrateVerletStepKernel::~CudaIntegrateVerletStepKernel() { CudaIntegrateVerletStepKernel::~CudaIntegrateVerletStepKernel() {
} }
......
...@@ -59,36 +59,26 @@ public: ...@@ -59,36 +59,26 @@ public:
*/ */
void initialize(const System& system); 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. * 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
void beginForceComputation(ContextImpl& context); * @param includeEnergy true if potential energy should be computed
/**
* 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); void beginComputation(ContextImpl& context, bool includeForce, bool includeEnergy);
/** /**
* This is called at the beginning of each energy computation, before calcEnergy() has been called on * This is called at the end of each force/energy computation, after calcForcesAndEnergy() 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. * 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' * @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. * 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: private:
CudaPlatform::PlatformData& data; CudaPlatform::PlatformData& data;
}; };
...@@ -209,18 +199,14 @@ public: ...@@ -209,18 +199,14 @@ public:
*/ */
void initialize(const System& system, const HarmonicBondForce& force); void initialize(const System& system, const HarmonicBondForce& 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
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
int numBonds; int numBonds;
CudaPlatform::PlatformData& data; CudaPlatform::PlatformData& data;
...@@ -244,18 +230,14 @@ public: ...@@ -244,18 +230,14 @@ public:
*/ */
void initialize(const System& system, const CustomBondForce& force); 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
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @return the potential energy due to the CustomBondForce * @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: private:
void updateGlobalParams(ContextImpl& context); void updateGlobalParams(ContextImpl& context);
int numBonds; int numBonds;
...@@ -281,18 +263,14 @@ public: ...@@ -281,18 +263,14 @@ public:
*/ */
void initialize(const System& system, const HarmonicAngleForce& force); void initialize(const System& system, const HarmonicAngleForce& 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
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
int numAngles; int numAngles;
CudaPlatform::PlatformData& data; CudaPlatform::PlatformData& data;
...@@ -316,18 +294,14 @@ public: ...@@ -316,18 +294,14 @@ public:
*/ */
void initialize(const System& system, const CustomAngleForce& force); 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); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
/**
* 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);
private: private:
void updateGlobalParams(ContextImpl& context); void updateGlobalParams(ContextImpl& context);
int numAngles; int numAngles;
...@@ -353,18 +327,14 @@ public: ...@@ -353,18 +327,14 @@ public:
*/ */
void initialize(const System& system, const PeriodicTorsionForce& force); void initialize(const System& system, const PeriodicTorsionForce& 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
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
int numTorsions; int numTorsions;
CudaPlatform::PlatformData& data; CudaPlatform::PlatformData& data;
...@@ -387,18 +357,14 @@ public: ...@@ -387,18 +357,14 @@ public:
*/ */
void initialize(const System& system, const RBTorsionForce& force); void initialize(const System& system, const RBTorsionForce& 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
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
int numTorsions; int numTorsions;
CudaPlatform::PlatformData& data; CudaPlatform::PlatformData& data;
...@@ -423,18 +389,14 @@ public: ...@@ -423,18 +389,14 @@ public:
*/ */
void initialize(const System& system, const CMAPTorsionForce& force); 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
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @return the potential energy due to the CMAPTorsionForce * @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: private:
CudaPlatform::PlatformData& data; CudaPlatform::PlatformData& data;
System& system; System& system;
...@@ -462,18 +424,14 @@ public: ...@@ -462,18 +424,14 @@ public:
*/ */
void initialize(const System& system, const CustomTorsionForce& force); 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); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
/**
* 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);
private: private:
void updateGlobalParams(ContextImpl& context); void updateGlobalParams(ContextImpl& context);
int numTorsions; int numTorsions;
...@@ -499,18 +457,14 @@ public: ...@@ -499,18 +457,14 @@ public:
*/ */
void initialize(const System& system, const NonbondedForce& force); 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 * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
CudaPlatform::PlatformData& data; CudaPlatform::PlatformData& data;
int numParticles; int numParticles;
...@@ -533,18 +487,14 @@ public: ...@@ -533,18 +487,14 @@ public:
*/ */
void initialize(const System& system, const CustomNonbondedForce& force); 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); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
/**
* 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);
private: private:
void updateGlobalParams(ContextImpl& context); void updateGlobalParams(ContextImpl& context);
CudaPlatform::PlatformData& data; CudaPlatform::PlatformData& data;
...@@ -570,18 +520,14 @@ public: ...@@ -570,18 +520,14 @@ public:
*/ */
void initialize(const System& system, const GBSAOBCForce& force); 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 * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
CudaPlatform::PlatformData& data; CudaPlatform::PlatformData& data;
}; };
...@@ -603,18 +549,14 @@ public: ...@@ -603,18 +549,14 @@ public:
*/ */
void initialize(const System& system, const GBVIForce& force, const std::vector<double> & scaledRadii); void initialize(const System& system, const GBVIForce& force, const std::vector<double> & scaledRadii);
/** /**
* 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
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
CudaPlatform::PlatformData& data; CudaPlatform::PlatformData& data;
}; };
...@@ -636,18 +578,14 @@ public: ...@@ -636,18 +578,14 @@ public:
*/ */
void initialize(const System& system, const CustomExternalForce& force); 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 * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
void updateGlobalParams(ContextImpl& context); void updateGlobalParams(ContextImpl& context);
int numParticles; int numParticles;
......
...@@ -70,7 +70,7 @@ static bool isZeroExpression(const Lepton::ParsedExpression& expression) { ...@@ -70,7 +70,7 @@ static bool isZeroExpression(const Lepton::ParsedExpression& expression) {
void OpenCLCalcForcesAndEnergyKernel::initialize(const System& system) { 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) if (cl.getNonbondedUtilities().getUseCutoff() && cl.getComputeForceCount()%100 == 0)
cl.reorderAtoms(); cl.reorderAtoms();
cl.setComputeForceCount(cl.getComputeForceCount()+1); cl.setComputeForceCount(cl.getComputeForceCount()+1);
...@@ -78,26 +78,17 @@ void OpenCLCalcForcesAndEnergyKernel::beginForceComputation(ContextImpl& context ...@@ -78,26 +78,17 @@ void OpenCLCalcForcesAndEnergyKernel::beginForceComputation(ContextImpl& context
cl.getNonbondedUtilities().prepareInteractions(); cl.getNonbondedUtilities().prepareInteractions();
} }
void OpenCLCalcForcesAndEnergyKernel::finishForceComputation(ContextImpl& context) { double OpenCLCalcForcesAndEnergyKernel::finishComputation(ContextImpl& context, bool includeForces, bool includeEnergy) {
cl.getNonbondedUtilities().computeInteractions(); cl.getNonbondedUtilities().computeInteractions();
cl.reduceBuffer(cl.getForceBuffers(), cl.getNumForceBuffers()); if (includeForces)
} 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();
double sum = 0.0f; double sum = 0.0f;
for (int i = 0; i < energy.getSize(); i++) if (includeEnergy) {
sum += energy[i]; OpenCLArray<cl_float>& energy = cl.getEnergyBuffer();
energy.download();
for (int i = 0; i < energy.getSize(); i++)
sum += energy[i];
}
return sum; return sum;
} }
...@@ -257,9 +248,9 @@ void OpenCLCalcHarmonicBondForceKernel::initialize(const System& system, const H ...@@ -257,9 +248,9 @@ void OpenCLCalcHarmonicBondForceKernel::initialize(const System& system, const H
kernel = cl::Kernel(program, "calcHarmonicBondForce"); kernel = cl::Kernel(program, "calcHarmonicBondForce");
} }
void OpenCLCalcHarmonicBondForceKernel::executeForces(ContextImpl& context) { double OpenCLCalcHarmonicBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numBonds == 0) if (numBonds == 0)
return; return 0.0;
if (!hasInitializedKernel) { if (!hasInitializedKernel) {
hasInitializedKernel = true; hasInitializedKernel = true;
kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms()); kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms());
...@@ -271,10 +262,6 @@ void OpenCLCalcHarmonicBondForceKernel::executeForces(ContextImpl& context) { ...@@ -271,10 +262,6 @@ void OpenCLCalcHarmonicBondForceKernel::executeForces(ContextImpl& context) {
kernel.setArg<cl::Buffer>(6, indices->getDeviceBuffer()); kernel.setArg<cl::Buffer>(6, indices->getDeviceBuffer());
} }
cl.executeKernel(kernel, numBonds); cl.executeKernel(kernel, numBonds);
}
double OpenCLCalcHarmonicBondForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0; return 0.0;
} }
...@@ -390,9 +377,9 @@ void OpenCLCalcCustomBondForceKernel::initialize(const System& system, const Cus ...@@ -390,9 +377,9 @@ void OpenCLCalcCustomBondForceKernel::initialize(const System& system, const Cus
kernel = cl::Kernel(program, "computeCustomBondForces"); kernel = cl::Kernel(program, "computeCustomBondForces");
} }
void OpenCLCalcCustomBondForceKernel::executeForces(ContextImpl& context) { double OpenCLCalcCustomBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numBonds == 0) if (numBonds == 0)
return; return 0.0;
if (globals != NULL) { if (globals != NULL) {
bool changed = false; bool changed = false;
for (int i = 0; i < (int) globalParamNames.size(); i++) { for (int i = 0; i < (int) globalParamNames.size(); i++) {
...@@ -421,10 +408,6 @@ void OpenCLCalcCustomBondForceKernel::executeForces(ContextImpl& context) { ...@@ -421,10 +408,6 @@ void OpenCLCalcCustomBondForceKernel::executeForces(ContextImpl& context) {
} }
} }
cl.executeKernel(kernel, numBonds); cl.executeKernel(kernel, numBonds);
}
double OpenCLCalcCustomBondForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0; return 0.0;
} }
...@@ -490,9 +473,9 @@ void OpenCLCalcHarmonicAngleForceKernel::initialize(const System& system, const ...@@ -490,9 +473,9 @@ void OpenCLCalcHarmonicAngleForceKernel::initialize(const System& system, const
kernel = cl::Kernel(program, "calcHarmonicAngleForce"); kernel = cl::Kernel(program, "calcHarmonicAngleForce");
} }
void OpenCLCalcHarmonicAngleForceKernel::executeForces(ContextImpl& context) { double OpenCLCalcHarmonicAngleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numAngles == 0) if (numAngles == 0)
return; return 0.0;
if (!hasInitializedKernel) { if (!hasInitializedKernel) {
hasInitializedKernel = true; hasInitializedKernel = true;
kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms()); kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms());
...@@ -504,10 +487,6 @@ void OpenCLCalcHarmonicAngleForceKernel::executeForces(ContextImpl& context) { ...@@ -504,10 +487,6 @@ void OpenCLCalcHarmonicAngleForceKernel::executeForces(ContextImpl& context) {
kernel.setArg<cl::Buffer>(6, indices->getDeviceBuffer()); kernel.setArg<cl::Buffer>(6, indices->getDeviceBuffer());
} }
cl.executeKernel(kernel, numAngles); cl.executeKernel(kernel, numAngles);
}
double OpenCLCalcHarmonicAngleForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0; return 0.0;
} }
...@@ -625,9 +604,9 @@ void OpenCLCalcCustomAngleForceKernel::initialize(const System& system, const Cu ...@@ -625,9 +604,9 @@ void OpenCLCalcCustomAngleForceKernel::initialize(const System& system, const Cu
kernel = cl::Kernel(program, "computeCustomAngleForces"); kernel = cl::Kernel(program, "computeCustomAngleForces");
} }
void OpenCLCalcCustomAngleForceKernel::executeForces(ContextImpl& context) { double OpenCLCalcCustomAngleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numAngles == 0) if (numAngles == 0)
return; return 0.0;
if (globals != NULL) { if (globals != NULL) {
bool changed = false; bool changed = false;
for (int i = 0; i < (int) globalParamNames.size(); i++) { for (int i = 0; i < (int) globalParamNames.size(); i++) {
...@@ -656,10 +635,6 @@ void OpenCLCalcCustomAngleForceKernel::executeForces(ContextImpl& context) { ...@@ -656,10 +635,6 @@ void OpenCLCalcCustomAngleForceKernel::executeForces(ContextImpl& context) {
} }
} }
cl.executeKernel(kernel, numAngles); cl.executeKernel(kernel, numAngles);
}
double OpenCLCalcCustomAngleForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0; return 0.0;
} }
...@@ -726,9 +701,9 @@ void OpenCLCalcPeriodicTorsionForceKernel::initialize(const System& system, cons ...@@ -726,9 +701,9 @@ void OpenCLCalcPeriodicTorsionForceKernel::initialize(const System& system, cons
kernel = cl::Kernel(program, "calcPeriodicTorsionForce"); kernel = cl::Kernel(program, "calcPeriodicTorsionForce");
} }
void OpenCLCalcPeriodicTorsionForceKernel::executeForces(ContextImpl& context) { double OpenCLCalcPeriodicTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numTorsions == 0) if (numTorsions == 0)
return; return 0.0;
if (!hasInitializedKernel) { if (!hasInitializedKernel) {
hasInitializedKernel = true; hasInitializedKernel = true;
kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms()); kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms());
...@@ -740,10 +715,6 @@ void OpenCLCalcPeriodicTorsionForceKernel::executeForces(ContextImpl& context) { ...@@ -740,10 +715,6 @@ void OpenCLCalcPeriodicTorsionForceKernel::executeForces(ContextImpl& context) {
kernel.setArg<cl::Buffer>(6, indices->getDeviceBuffer()); kernel.setArg<cl::Buffer>(6, indices->getDeviceBuffer());
} }
cl.executeKernel(kernel, numTorsions); cl.executeKernel(kernel, numTorsions);
}
double OpenCLCalcPeriodicTorsionForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0; return 0.0;
} }
...@@ -810,9 +781,9 @@ void OpenCLCalcRBTorsionForceKernel::initialize(const System& system, const RBTo ...@@ -810,9 +781,9 @@ void OpenCLCalcRBTorsionForceKernel::initialize(const System& system, const RBTo
kernel = cl::Kernel(program, "calcRBTorsionForce"); kernel = cl::Kernel(program, "calcRBTorsionForce");
} }
void OpenCLCalcRBTorsionForceKernel::executeForces(ContextImpl& context) { double OpenCLCalcRBTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numTorsions == 0) if (numTorsions == 0)
return; return 0.0;
if (!hasInitializedKernel) { if (!hasInitializedKernel) {
hasInitializedKernel = true; hasInitializedKernel = true;
kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms()); kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms());
...@@ -824,10 +795,6 @@ void OpenCLCalcRBTorsionForceKernel::executeForces(ContextImpl& context) { ...@@ -824,10 +795,6 @@ void OpenCLCalcRBTorsionForceKernel::executeForces(ContextImpl& context) {
kernel.setArg<cl::Buffer>(6, indices->getDeviceBuffer()); kernel.setArg<cl::Buffer>(6, indices->getDeviceBuffer());
} }
cl.executeKernel(kernel, numTorsions); cl.executeKernel(kernel, numTorsions);
}
double OpenCLCalcRBTorsionForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0; return 0.0;
} }
...@@ -926,9 +893,9 @@ void OpenCLCalcCMAPTorsionForceKernel::initialize(const System& system, const CM ...@@ -926,9 +893,9 @@ void OpenCLCalcCMAPTorsionForceKernel::initialize(const System& system, const CM
kernel = cl::Kernel(program, "computeCMAPTorsionForces"); kernel = cl::Kernel(program, "computeCMAPTorsionForces");
} }
void OpenCLCalcCMAPTorsionForceKernel::executeForces(ContextImpl& context) { double OpenCLCalcCMAPTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numTorsions == 0) if (numTorsions == 0)
return; return 0.0;
if (!hasInitializedKernel) { if (!hasInitializedKernel) {
hasInitializedKernel = true; hasInitializedKernel = true;
kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms()); kernel.setArg<cl_int>(0, cl.getPaddedNumAtoms());
...@@ -942,10 +909,6 @@ void OpenCLCalcCMAPTorsionForceKernel::executeForces(ContextImpl& context) { ...@@ -942,10 +909,6 @@ void OpenCLCalcCMAPTorsionForceKernel::executeForces(ContextImpl& context) {
kernel.setArg<cl::Buffer>(8, torsionMaps->getDeviceBuffer()); kernel.setArg<cl::Buffer>(8, torsionMaps->getDeviceBuffer());
} }
cl.executeKernel(kernel, numTorsions); cl.executeKernel(kernel, numTorsions);
}
double OpenCLCalcCMAPTorsionForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0; return 0.0;
} }
...@@ -1065,9 +1028,9 @@ void OpenCLCalcCustomTorsionForceKernel::initialize(const System& system, const ...@@ -1065,9 +1028,9 @@ void OpenCLCalcCustomTorsionForceKernel::initialize(const System& system, const
kernel = cl::Kernel(program, "computeCustomTorsionForces"); kernel = cl::Kernel(program, "computeCustomTorsionForces");
} }
void OpenCLCalcCustomTorsionForceKernel::executeForces(ContextImpl& context) { double OpenCLCalcCustomTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (numTorsions == 0) if (numTorsions == 0)
return; return 0.0;
if (globals != NULL) { if (globals != NULL) {
bool changed = false; bool changed = false;
for (int i = 0; i < (int) globalParamNames.size(); i++) { for (int i = 0; i < (int) globalParamNames.size(); i++) {
...@@ -1096,10 +1059,6 @@ void OpenCLCalcCustomTorsionForceKernel::executeForces(ContextImpl& context) { ...@@ -1096,10 +1059,6 @@ void OpenCLCalcCustomTorsionForceKernel::executeForces(ContextImpl& context) {
} }
} }
cl.executeKernel(kernel, numTorsions); cl.executeKernel(kernel, numTorsions);
}
double OpenCLCalcCustomTorsionForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0; return 0.0;
} }
...@@ -1398,7 +1357,7 @@ void OpenCLCalcNonbondedForceKernel::initialize(const System& system, const Nonb ...@@ -1398,7 +1357,7 @@ void OpenCLCalcNonbondedForceKernel::initialize(const System& system, const Nonb
exceptionsKernel = cl::Kernel(program, "computeNonbondedExceptions"); exceptionsKernel = cl::Kernel(program, "computeNonbondedExceptions");
} }
void OpenCLCalcNonbondedForceKernel::executeForces(ContextImpl& context) { double OpenCLCalcNonbondedForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (!hasInitializedKernel) { if (!hasInitializedKernel) {
hasInitializedKernel = true; hasInitializedKernel = true;
if (exceptionIndices != NULL) { if (exceptionIndices != NULL) {
...@@ -1484,10 +1443,6 @@ void OpenCLCalcNonbondedForceKernel::executeForces(ContextImpl& context) { ...@@ -1484,10 +1443,6 @@ void OpenCLCalcNonbondedForceKernel::executeForces(ContextImpl& context) {
pmeInterpolateForceKernel.setArg<mm_float4>(6, invBoxSize); pmeInterpolateForceKernel.setArg<mm_float4>(6, invBoxSize);
cl.executeKernel(pmeInterpolateForceKernel, cl.getNumAtoms()); cl.executeKernel(pmeInterpolateForceKernel, cl.getNumAtoms());
} }
}
double OpenCLCalcNonbondedForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
double energy = ewaldSelfEnergy; double energy = ewaldSelfEnergy;
if (dispersionCoefficient != 0.0) { if (dispersionCoefficient != 0.0) {
mm_float4 boxSize = cl.getPeriodicBoxSize(); mm_float4 boxSize = cl.getPeriodicBoxSize();
...@@ -1644,7 +1599,7 @@ void OpenCLCalcCustomNonbondedForceKernel::initialize(const System& system, cons ...@@ -1644,7 +1599,7 @@ void OpenCLCalcCustomNonbondedForceKernel::initialize(const System& system, cons
cl.addForce(new OpenCLCustomNonbondedForceInfo(cl.getNonbondedUtilities().getNumForceBuffers(), force)); 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) { if (globals != NULL) {
bool changed = false; bool changed = false;
for (int i = 0; i < (int) globalParamNames.size(); i++) { for (int i = 0; i < (int) globalParamNames.size(); i++) {
...@@ -1656,10 +1611,6 @@ void OpenCLCalcCustomNonbondedForceKernel::executeForces(ContextImpl& context) { ...@@ -1656,10 +1611,6 @@ void OpenCLCalcCustomNonbondedForceKernel::executeForces(ContextImpl& context) {
if (changed) if (changed)
globals->upload(globalParamValues); globals->upload(globalParamValues);
} }
}
double OpenCLCalcCustomNonbondedForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0; return 0.0;
} }
...@@ -1722,7 +1673,7 @@ void OpenCLCalcGBSAOBCForceKernel::initialize(const System& system, const GBSAOB ...@@ -1722,7 +1673,7 @@ void OpenCLCalcGBSAOBCForceKernel::initialize(const System& system, const GBSAOB
cl.addAutoclearBuffer(bornForce->getDeviceBuffer(), bornForce->getSize()); cl.addAutoclearBuffer(bornForce->getDeviceBuffer(), bornForce->getSize());
} }
void OpenCLCalcGBSAOBCForceKernel::executeForces(ContextImpl& context) { double OpenCLCalcGBSAOBCForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
OpenCLNonbondedUtilities& nb = cl.getNonbondedUtilities(); OpenCLNonbondedUtilities& nb = cl.getNonbondedUtilities();
if (!hasCreatedKernels) { if (!hasCreatedKernels) {
// These Kernels cannot be created in initialize(), because the OpenCLNonbondedUtilities has not been initialized yet then. // 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) { ...@@ -1805,10 +1756,6 @@ void OpenCLCalcGBSAOBCForceKernel::executeForces(ContextImpl& context) {
cl.executeKernel(reduceBornSumKernel, cl.getPaddedNumAtoms()); cl.executeKernel(reduceBornSumKernel, cl.getPaddedNumAtoms());
cl.executeKernel(force1Kernel, nb.getTiles().getSize()*OpenCLContext::TileSize); cl.executeKernel(force1Kernel, nb.getTiles().getSize()*OpenCLContext::TileSize);
cl.executeKernel(reduceBornForceKernel, cl.getPaddedNumAtoms()); cl.executeKernel(reduceBornForceKernel, cl.getPaddedNumAtoms());
}
double OpenCLCalcGBSAOBCForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0; return 0.0;
} }
...@@ -2434,7 +2381,7 @@ void OpenCLCalcCustomGBForceKernel::initialize(const System& system, const Custo ...@@ -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(); OpenCLNonbondedUtilities& nb = cl.getNonbondedUtilities();
if (!hasInitializedKernels) { if (!hasInitializedKernels) {
hasInitializedKernels = true; hasInitializedKernels = true;
...@@ -2584,10 +2531,6 @@ void OpenCLCalcCustomGBForceKernel::executeForces(ContextImpl& context) { ...@@ -2584,10 +2531,6 @@ void OpenCLCalcCustomGBForceKernel::executeForces(ContextImpl& context) {
cl.executeKernel(perParticleEnergyKernel, cl.getPaddedNumAtoms()); cl.executeKernel(perParticleEnergyKernel, cl.getPaddedNumAtoms());
if (needParameterGradient) if (needParameterGradient)
cl.executeKernel(gradientChainRuleKernel, cl.getPaddedNumAtoms()); cl.executeKernel(gradientChainRuleKernel, cl.getPaddedNumAtoms());
}
double OpenCLCalcCustomGBForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0; return 0.0;
} }
...@@ -2704,7 +2647,7 @@ void OpenCLCalcCustomExternalForceKernel::initialize(const System& system, const ...@@ -2704,7 +2647,7 @@ void OpenCLCalcCustomExternalForceKernel::initialize(const System& system, const
kernel = cl::Kernel(program, "computeCustomExternalForces"); kernel = cl::Kernel(program, "computeCustomExternalForces");
} }
void OpenCLCalcCustomExternalForceKernel::executeForces(ContextImpl& context) { double OpenCLCalcCustomExternalForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (globals != NULL) { if (globals != NULL) {
bool changed = false; bool changed = false;
for (int i = 0; i < (int) globalParamNames.size(); i++) { for (int i = 0; i < (int) globalParamNames.size(); i++) {
...@@ -2732,10 +2675,6 @@ void OpenCLCalcCustomExternalForceKernel::executeForces(ContextImpl& context) { ...@@ -2732,10 +2675,6 @@ void OpenCLCalcCustomExternalForceKernel::executeForces(ContextImpl& context) {
} }
} }
cl.executeKernel(kernel, numParticles); cl.executeKernel(kernel, numParticles);
}
double OpenCLCalcCustomExternalForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0; return 0.0;
} }
...@@ -3166,7 +3105,7 @@ void OpenCLCalcCustomHbondForceKernel::initialize(const System& system, const Cu ...@@ -3166,7 +3105,7 @@ void OpenCLCalcCustomHbondForceKernel::initialize(const System& system, const Cu
acceptorKernel = cl::Kernel(program, "computeAcceptorForces"); acceptorKernel = cl::Kernel(program, "computeAcceptorForces");
} }
void OpenCLCalcCustomHbondForceKernel::executeForces(ContextImpl& context) { double OpenCLCalcCustomHbondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (globals != NULL) { if (globals != NULL) {
bool changed = false; bool changed = false;
for (int i = 0; i < (int) globalParamNames.size(); i++) { for (int i = 0; i < (int) globalParamNames.size(); i++) {
...@@ -3237,10 +3176,6 @@ void OpenCLCalcCustomHbondForceKernel::executeForces(ContextImpl& context) { ...@@ -3237,10 +3176,6 @@ void OpenCLCalcCustomHbondForceKernel::executeForces(ContextImpl& context) {
acceptorKernel.setArg<mm_float4>(8, cl.getPeriodicBoxSize()); acceptorKernel.setArg<mm_float4>(8, cl.getPeriodicBoxSize());
acceptorKernel.setArg<mm_float4>(9, cl.getInvPeriodicBoxSize()); acceptorKernel.setArg<mm_float4>(9, cl.getInvPeriodicBoxSize());
cl.executeKernel(acceptorKernel, std::max(numDonors, numAcceptors)); cl.executeKernel(acceptorKernel, std::max(numDonors, numAcceptors));
}
double OpenCLCalcCustomHbondForceKernel::executeEnergy(ContextImpl& context) {
executeForces(context);
return 0.0; return 0.0;
} }
......
...@@ -54,36 +54,26 @@ public: ...@@ -54,36 +54,26 @@ public:
*/ */
void initialize(const System& system); 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. * 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
void beginForceComputation(ContextImpl& context); * @param includeEnergy true if potential energy should be computed
/**
* 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
*/ */
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. * 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' * @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. * 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: private:
OpenCLContext& cl; OpenCLContext& cl;
}; };
...@@ -205,18 +195,14 @@ public: ...@@ -205,18 +195,14 @@ public:
*/ */
void initialize(const System& system, const HarmonicBondForce& force); void initialize(const System& system, const HarmonicBondForce& 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 * @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicBondForce * @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: private:
int numBonds; int numBonds;
bool hasInitializedKernel; bool hasInitializedKernel;
...@@ -244,18 +230,14 @@ public: ...@@ -244,18 +230,14 @@ public:
*/ */
void initialize(const System& system, const CustomBondForce& force); 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); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
/**
* 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);
private: private:
int numBonds; int numBonds;
bool hasInitializedKernel; bool hasInitializedKernel;
...@@ -286,18 +268,14 @@ public: ...@@ -286,18 +268,14 @@ public:
*/ */
void initialize(const System& system, const HarmonicAngleForce& force); void initialize(const System& system, const HarmonicAngleForce& 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 * @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicAngleForce * @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: private:
int numAngles; int numAngles;
bool hasInitializedKernel; bool hasInitializedKernel;
...@@ -325,18 +303,14 @@ public: ...@@ -325,18 +303,14 @@ public:
*/ */
void initialize(const System& system, const CustomAngleForce& force); 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
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @return the potential energy due to the CustomAngleForce * @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: private:
int numAngles; int numAngles;
bool hasInitializedKernel; bool hasInitializedKernel;
...@@ -367,18 +341,14 @@ public: ...@@ -367,18 +341,14 @@ public:
*/ */
void initialize(const System& system, const PeriodicTorsionForce& force); void initialize(const System& system, const PeriodicTorsionForce& 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 * @param context the context in which to execute this kernel
* @return the potential energy due to the PeriodicTorsionForce * @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: private:
int numTorsions; int numTorsions;
bool hasInitializedKernel; bool hasInitializedKernel;
...@@ -406,18 +376,14 @@ public: ...@@ -406,18 +376,14 @@ public:
*/ */
void initialize(const System& system, const RBTorsionForce& force); void initialize(const System& system, const RBTorsionForce& 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 * @param context the context in which to execute this kernel
* @return the potential energy due to the RBTorsionForce * @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: private:
int numTorsions; int numTorsions;
bool hasInitializedKernel; bool hasInitializedKernel;
...@@ -445,18 +411,14 @@ public: ...@@ -445,18 +411,14 @@ public:
*/ */
void initialize(const System& system, const CMAPTorsionForce& force); 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
*/
void executeForces(ContextImpl& context);
/**
* Execute the kernel to calculate the energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @return the potential energy due to the CMAPTorsionForce * @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: private:
int numTorsions; int numTorsions;
bool hasInitializedKernel; bool hasInitializedKernel;
...@@ -486,18 +448,14 @@ public: ...@@ -486,18 +448,14 @@ public:
*/ */
void initialize(const System& system, const CustomTorsionForce& force); 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
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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: private:
int numTorsions; int numTorsions;
bool hasInitializedKernel; bool hasInitializedKernel;
...@@ -530,18 +488,14 @@ public: ...@@ -530,18 +488,14 @@ public:
*/ */
void initialize(const System& system, const NonbondedForce& force); 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 * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
OpenCLContext& cl; OpenCLContext& cl;
bool hasInitializedKernel; bool hasInitializedKernel;
...@@ -591,18 +545,14 @@ public: ...@@ -591,18 +545,14 @@ public:
*/ */
void initialize(const System& system, const CustomNonbondedForce& force); 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
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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: private:
bool hasInitializedKernel; bool hasInitializedKernel;
OpenCLContext& cl; OpenCLContext& cl;
...@@ -631,18 +581,14 @@ public: ...@@ -631,18 +581,14 @@ public:
*/ */
void initialize(const System& system, const GBSAOBCForce& force); 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 * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
double prefactor; double prefactor;
bool hasCreatedKernels; bool hasCreatedKernels;
...@@ -676,18 +622,14 @@ public: ...@@ -676,18 +622,14 @@ public:
*/ */
void initialize(const System& system, const CustomGBForce& force); 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
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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: private:
bool hasInitializedKernels, needParameterGradient; bool hasInitializedKernels, needParameterGradient;
OpenCLContext& cl; OpenCLContext& cl;
...@@ -721,18 +663,14 @@ public: ...@@ -721,18 +663,14 @@ public:
*/ */
void initialize(const System& system, const CustomExternalForce& force); 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 * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
int numParticles; int numParticles;
bool hasInitializedKernel; bool hasInitializedKernel;
...@@ -765,18 +703,14 @@ public: ...@@ -765,18 +703,14 @@ public:
*/ */
void initialize(const System& system, const CustomHbondForce& force); 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 * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
int numDonors, numAcceptors; int numDonors, numAcceptors;
bool hasInitializedKernel; bool hasInitializedKernel;
......
...@@ -68,36 +68,26 @@ public: ...@@ -68,36 +68,26 @@ public:
*/ */
void initialize(const System& system); 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. * 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. * 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
void finishForceComputation(ContextImpl& context); * @param includeEnergy true if potential energy should be computed
/**
* 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
* @return the potential energy of the system. This value is added to all values returned by ForceImpls' * @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. * 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: ...@@ -224,18 +214,14 @@ public:
*/ */
void initialize(const System& system, const HarmonicBondForce& force); void initialize(const System& system, const HarmonicBondForce& 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
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
int numBonds; int numBonds;
int **bondIndexArray; int **bondIndexArray;
...@@ -258,18 +244,14 @@ public: ...@@ -258,18 +244,14 @@ public:
*/ */
void initialize(const System& system, const CustomBondForce& force); 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); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
/**
* 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);
private: private:
int numBonds; int numBonds;
int **bondIndexArray; int **bondIndexArray;
...@@ -294,18 +276,14 @@ public: ...@@ -294,18 +276,14 @@ public:
*/ */
void initialize(const System& system, const HarmonicAngleForce& force); void initialize(const System& system, const HarmonicAngleForce& 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
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
int numAngles; int numAngles;
int **angleIndexArray; int **angleIndexArray;
...@@ -328,18 +306,14 @@ public: ...@@ -328,18 +306,14 @@ public:
*/ */
void initialize(const System& system, const CustomAngleForce& force); 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); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
/**
* 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);
private: private:
int numAngles; int numAngles;
int **angleIndexArray; int **angleIndexArray;
...@@ -364,18 +338,14 @@ public: ...@@ -364,18 +338,14 @@ public:
*/ */
void initialize(const System& system, const PeriodicTorsionForce& force); void initialize(const System& system, const PeriodicTorsionForce& 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
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
int numTorsions; int numTorsions;
int **torsionIndexArray; int **torsionIndexArray;
...@@ -398,18 +368,14 @@ public: ...@@ -398,18 +368,14 @@ public:
*/ */
void initialize(const System& system, const RBTorsionForce& force); void initialize(const System& system, const RBTorsionForce& 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
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
int numTorsions; int numTorsions;
int **torsionIndexArray; int **torsionIndexArray;
...@@ -431,18 +397,14 @@ public: ...@@ -431,18 +397,14 @@ public:
*/ */
void initialize(const System& system, const CMAPTorsionForce& force); 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); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
/**
* 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);
private: private:
std::vector<std::vector<std::vector<RealOpenMM> > > coeff; std::vector<std::vector<std::vector<RealOpenMM> > > coeff;
std::vector<int> torsionMaps; std::vector<int> torsionMaps;
...@@ -465,18 +427,14 @@ public: ...@@ -465,18 +427,14 @@ public:
*/ */
void initialize(const System& system, const CustomTorsionForce& force); 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); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
/**
* 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);
private: private:
int numTorsions; int numTorsions;
int **torsionIndexArray; int **torsionIndexArray;
...@@ -501,18 +459,14 @@ public: ...@@ -501,18 +459,14 @@ public:
*/ */
void initialize(const System& system, const NonbondedForce& force); 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 * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
int numParticles, num14; int numParticles, num14;
int **exclusionArray, **bonded14IndexArray; int **exclusionArray, **bonded14IndexArray;
...@@ -540,18 +494,14 @@ public: ...@@ -540,18 +494,14 @@ public:
*/ */
void initialize(const System& system, const CustomNonbondedForce& force); 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 * @param context the context in which to execute this kernel
* @return the potential energy due to the CustomNonbondedForce * @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: private:
int numParticles; int numParticles;
int **exclusionArray; int **exclusionArray;
...@@ -580,18 +530,14 @@ public: ...@@ -580,18 +530,14 @@ public:
*/ */
void initialize(const System& system, const GBSAOBCForce& force); 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 * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
CpuObc* obc; CpuObc* obc;
std::vector<RealOpenMM> charges; std::vector<RealOpenMM> charges;
...@@ -615,18 +561,14 @@ public: ...@@ -615,18 +561,14 @@ public:
*/ */
void initialize(const System& system, const GBVIForce& force, const std::vector<double> & scaledRadii); void initialize(const System& system, const GBVIForce& force, const std::vector<double> & scaledRadii);
/** /**
* 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
void executeForces(ContextImpl& context); * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
double executeEnergy(ContextImpl& context); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private: private:
CpuGBVI * gbvi; CpuGBVI * gbvi;
std::vector<RealOpenMM> charges; std::vector<RealOpenMM> charges;
...@@ -649,18 +591,14 @@ public: ...@@ -649,18 +591,14 @@ public:
*/ */
void initialize(const System& system, const CustomGBForce& force); 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); double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
/**
* 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);
private: private:
int numParticles; int numParticles;
bool isPeriodic; bool isPeriodic;
...@@ -696,18 +634,14 @@ public: ...@@ -696,18 +634,14 @@ public:
*/ */
void initialize(const System& system, const CustomExternalForce& force); 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 * @param context the context in which to execute this kernel
* @return the potential energy due to the CustomExternalForce * @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: private:
int numParticles; int numParticles;
std::vector<int> particles; std::vector<int> particles;
...@@ -732,18 +666,14 @@ public: ...@@ -732,18 +666,14 @@ public:
*/ */
void initialize(const System& system, const CustomHbondForce& force); 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 * @param context the context in which to execute this kernel
* @return the potential energy due to the CustomHbondForce * @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: private:
int numDonors, numAcceptors, numParticles; int numDonors, numAcceptors, numParticles;
bool isPeriodic; 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: ...@@ -61,18 +61,14 @@ public:
*/ */
virtual void initialize(const System& system, const AmoebaHarmonicBondForce& force) = 0; virtual void initialize(const System& system, const AmoebaHarmonicBondForce& force) = 0;
/** /**
* 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
virtual void executeForces(ContextImpl& context) = 0; * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* Execute the kernel to calculate the energy. */
* virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
* @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicBondForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
}; };
/** /**
...@@ -93,18 +89,14 @@ public: ...@@ -93,18 +89,14 @@ public:
*/ */
virtual void initialize(const System& system, const AmoebaHarmonicAngleForce& force) = 0; virtual void initialize(const System& system, const AmoebaHarmonicAngleForce& force) = 0;
/** /**
* 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
virtual void executeForces(ContextImpl& context) = 0; * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
virtual double executeEnergy(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
}; };
/** /**
...@@ -125,18 +117,14 @@ public: ...@@ -125,18 +117,14 @@ public:
*/ */
virtual void initialize(const System& system, const AmoebaHarmonicInPlaneAngleForce& force) = 0; virtual void initialize(const System& system, const AmoebaHarmonicInPlaneAngleForce& force) = 0;
/** /**
* 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
*/ */
virtual void executeForces(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 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;
}; };
/** /**
...@@ -157,18 +145,14 @@ public: ...@@ -157,18 +145,14 @@ public:
*/ */
virtual void initialize(const System& system, const AmoebaTorsionForce& force) = 0; virtual void initialize(const System& system, const AmoebaTorsionForce& force) = 0;
/** /**
* 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
*/ */
virtual void executeForces(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 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;
}; };
/** /**
...@@ -189,18 +173,14 @@ public: ...@@ -189,18 +173,14 @@ public:
*/ */
virtual void initialize(const System& system, const AmoebaPiTorsionForce& force) = 0; virtual void initialize(const System& system, const AmoebaPiTorsionForce& force) = 0;
/** /**
* 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
virtual void executeForces(ContextImpl& context) = 0; * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
virtual double executeEnergy(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
}; };
/** /**
...@@ -221,18 +201,14 @@ public: ...@@ -221,18 +201,14 @@ public:
*/ */
virtual void initialize(const System& system, const AmoebaStretchBendForce& force) = 0; virtual void initialize(const System& system, const AmoebaStretchBendForce& force) = 0;
/** /**
* 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
virtual void executeForces(ContextImpl& context) = 0; * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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
*/ */
virtual double executeEnergy(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
}; };
/** /**
...@@ -253,18 +229,14 @@ public: ...@@ -253,18 +229,14 @@ public:
*/ */
virtual void initialize(const System& system, const AmoebaOutOfPlaneBendForce& force) = 0; virtual void initialize(const System& system, const AmoebaOutOfPlaneBendForce& force) = 0;
/** /**
* 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
*/ */
virtual void executeForces(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 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;
}; };
/** /**
...@@ -285,18 +257,14 @@ public: ...@@ -285,18 +257,14 @@ public:
*/ */
virtual void initialize(const System& system, const AmoebaTorsionTorsionForce& force) = 0; virtual void initialize(const System& system, const AmoebaTorsionTorsionForce& force) = 0;
/** /**
* 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
*/ */
virtual void executeForces(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 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;
}; };
/** /**
...@@ -317,18 +285,14 @@ public: ...@@ -317,18 +285,14 @@ public:
*/ */
virtual void initialize(const System& system, const AmoebaMultipoleForce& force) = 0; virtual void initialize(const System& system, const AmoebaMultipoleForce& force) = 0;
/** /**
* 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
*/ */
virtual void executeForces(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 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;
}; };
/** /**
...@@ -350,18 +314,14 @@ public: ...@@ -350,18 +314,14 @@ public:
*/ */
virtual void initialize(const System& system, const AmoebaGeneralizedKirkwoodForce& force) = 0; virtual void initialize(const System& system, const AmoebaGeneralizedKirkwoodForce& force) = 0;
/** /**
* 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
virtual void executeForces(ContextImpl& context) = 0; * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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;
}; };
/** /**
...@@ -383,18 +343,14 @@ public: ...@@ -383,18 +343,14 @@ public:
*/ */
virtual void initialize(const System& system, const AmoebaSASAForce& force) = 0; virtual void initialize(const System& system, const AmoebaSASAForce& force) = 0;
/** /**
* 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
*/ */
virtual void executeForces(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 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;
}; };
/** /**
...@@ -416,18 +372,14 @@ public: ...@@ -416,18 +372,14 @@ public:
*/ */
virtual void initialize(const System& system, const AmoebaVdwForce& force) = 0; virtual void initialize(const System& system, const AmoebaVdwForce& force) = 0;
/** /**
* 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
*/ */
virtual void executeForces(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 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;
}; };
/** /**
...@@ -449,18 +401,14 @@ public: ...@@ -449,18 +401,14 @@ public:
*/ */
virtual void initialize(const System& system, const AmoebaWcaDispersionForce& force) = 0; virtual void initialize(const System& system, const AmoebaWcaDispersionForce& force) = 0;
/** /**
* 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
virtual void executeForces(ContextImpl& context) = 0; * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* 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;
}; };
} // namespace OpenMM } // 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: ...@@ -53,8 +53,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
......
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context ); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
......
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context ); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
......
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context ); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
......
...@@ -55,8 +55,7 @@ public: ...@@ -55,8 +55,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context ); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
......
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context ); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
......
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context ); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
......
...@@ -53,8 +53,7 @@ public: ...@@ -53,8 +53,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. 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