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

Constraint tolerance is now adjustable

parent 0107f59f
...@@ -66,6 +66,18 @@ public: ...@@ -66,6 +66,18 @@ public:
void setStepSize(double size) { void setStepSize(double size) {
stepSize = size; stepSize = size;
} }
/**
* Get the distance tolerance within which constraints are maintained, measured in nm.
*/
double getConstraintTolerance() const {
return constraintTol;
}
/**
* Set the distance tolerance within which constraints are maintained, measured in nm.
*/
void setConstraintTolerance(double tol) {
constraintTol = tol;
}
/** /**
* Advance a simulation through time by taking a series of time steps. * Advance a simulation through time by taking a series of time steps.
* *
...@@ -85,7 +97,7 @@ protected: ...@@ -85,7 +97,7 @@ protected:
*/ */
virtual std::vector<std::string> getKernelNames() = 0; virtual std::vector<std::string> getKernelNames() = 0;
private: private:
double stepSize; double stepSize, constraintTol;
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -46,7 +46,7 @@ class OPENMM_EXPORT Force; ...@@ -46,7 +46,7 @@ class OPENMM_EXPORT Force;
* <ol> * <ol>
* <li>The set of particles in the system</li> * <li>The set of particles in the system</li>
* <li>The forces acting on them</li> * <li>The forces acting on them</li>
* <li>Pairs of particles whose separation should be connstrained to a fixed value</li> * <li>Pairs of particles whose separation should be constrained to a fixed value</li>
* </ol> * </ol>
* *
* The particles and constraints are defined directly by the System object. * The particles and constraints are defined directly by the System object.
......
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
* @param stepSize the step size with which to integrator the system (in picoseconds) * @param stepSize the step size with which to integrator the system (in picoseconds)
*/ */
VerletIntegrator(double stepSize); VerletIntegrator(double stepSize);
/** /**
* Advance a simulation through time by taking a series of time steps. * Advance a simulation through time by taking a series of time steps.
* *
* @param steps the number of time steps to take * @param steps the number of time steps to take
......
...@@ -43,26 +43,13 @@ BrownianIntegrator::BrownianIntegrator(double temperature, double frictionCoeff, ...@@ -43,26 +43,13 @@ BrownianIntegrator::BrownianIntegrator(double temperature, double frictionCoeff,
setTemperature(temperature); setTemperature(temperature);
setFriction(frictionCoeff); setFriction(frictionCoeff);
setStepSize(stepSize); setStepSize(stepSize);
setConstraintTolerance(1e-4);
} }
void BrownianIntegrator::initialize(OpenMMContextImpl& contextRef) { void BrownianIntegrator::initialize(OpenMMContextImpl& contextRef) {
context = &contextRef; context = &contextRef;
kernel = context->getPlatform().createKernel(IntegrateBrownianStepKernel::Name(), contextRef); kernel = context->getPlatform().createKernel(IntegrateBrownianStepKernel::Name(), contextRef);
const System& system = context->getSystem(); dynamic_cast<IntegrateBrownianStepKernel&>(kernel.getImpl()).initialize(contextRef.getSystem(), *this);
vector<double> masses(system.getNumParticles());
vector<std::vector<int> > constraintIndices(system.getNumConstraints());
vector<double> constraintLengths(system.getNumConstraints());
for (int i = 0; i < system.getNumParticles(); ++i)
masses[i] = system.getParticleMass(i);
for (int i = 0; i < system.getNumConstraints(); ++i) {
int particle1, particle2;
double distance;
system.getConstraintParameters(i, particle1, particle2, distance);
constraintIndices[i].push_back(particle1);
constraintIndices[i].push_back(particle2);
constraintLengths[i] = distance;
}
dynamic_cast<IntegrateBrownianStepKernel&>(kernel.getImpl()).initialize(system, *this);
} }
vector<string> BrownianIntegrator::getKernelNames() { vector<string> BrownianIntegrator::getKernelNames() {
......
...@@ -43,6 +43,7 @@ LangevinIntegrator::LangevinIntegrator(double temperature, double frictionCoeff, ...@@ -43,6 +43,7 @@ LangevinIntegrator::LangevinIntegrator(double temperature, double frictionCoeff,
setTemperature(temperature); setTemperature(temperature);
setFriction(frictionCoeff); setFriction(frictionCoeff);
setStepSize(stepSize); setStepSize(stepSize);
setConstraintTolerance(1e-4);
} }
void LangevinIntegrator::initialize(OpenMMContextImpl& contextRef) { void LangevinIntegrator::initialize(OpenMMContextImpl& contextRef) {
......
...@@ -41,6 +41,7 @@ using std::vector; ...@@ -41,6 +41,7 @@ using std::vector;
VerletIntegrator::VerletIntegrator(double stepSize) { VerletIntegrator::VerletIntegrator(double stepSize) {
setStepSize(stepSize); setStepSize(stepSize);
setConstraintTolerance(1e-4);
} }
void VerletIntegrator::initialize(OpenMMContextImpl& contextRef) { void VerletIntegrator::initialize(OpenMMContextImpl& contextRef) {
......
...@@ -311,7 +311,7 @@ void CudaCalcGBSAOBCForceKernel::initialize(const System& system, const GBSAOBCF ...@@ -311,7 +311,7 @@ void CudaCalcGBSAOBCForceKernel::initialize(const System& system, const GBSAOBCF
void CudaCalcGBSAOBCForceKernel::executeForces(OpenMMContextImpl& context) { void CudaCalcGBSAOBCForceKernel::executeForces(OpenMMContextImpl& context) {
} }
static void initializeIntegration(const System& system, CudaPlatform::PlatformData& data) { static void initializeIntegration(const System& system, CudaPlatform::PlatformData& data, const Integrator& integrator) {
// Set masses. // Set masses.
...@@ -340,7 +340,7 @@ static void initializeIntegration(const System& system, CudaPlatform::PlatformDa ...@@ -340,7 +340,7 @@ static void initializeIntegration(const System& system, CudaPlatform::PlatformDa
invMass1[i] = 1.0f/mass[particle1Index]; invMass1[i] = 1.0f/mass[particle1Index];
invMass2[i] = 1.0f/mass[particle2Index]; invMass2[i] = 1.0f/mass[particle2Index];
} }
gpuSetShakeParameters(gpu, particle1, particle2, distance, invMass1, invMass2); gpuSetShakeParameters(gpu, particle1, particle2, distance, invMass1, invMass2, integrator.getConstraintTolerance());
// Initialize any terms that haven't already been handled by a Force. // Initialize any terms that haven't already been handled by a Force.
...@@ -377,7 +377,7 @@ CudaIntegrateVerletStepKernel::~CudaIntegrateVerletStepKernel() { ...@@ -377,7 +377,7 @@ CudaIntegrateVerletStepKernel::~CudaIntegrateVerletStepKernel() {
} }
void CudaIntegrateVerletStepKernel::initialize(const System& system, const VerletIntegrator& integrator) { void CudaIntegrateVerletStepKernel::initialize(const System& system, const VerletIntegrator& integrator) {
initializeIntegration(system, data); initializeIntegration(system, data, integrator);
prevStepSize = -1.0; prevStepSize = -1.0;
} }
...@@ -406,7 +406,7 @@ CudaIntegrateLangevinStepKernel::~CudaIntegrateLangevinStepKernel() { ...@@ -406,7 +406,7 @@ CudaIntegrateLangevinStepKernel::~CudaIntegrateLangevinStepKernel() {
} }
void CudaIntegrateLangevinStepKernel::initialize(const System& system, const LangevinIntegrator& integrator) { void CudaIntegrateLangevinStepKernel::initialize(const System& system, const LangevinIntegrator& integrator) {
initializeIntegration(system, data); initializeIntegration(system, data, integrator);
prevStepSize = -1.0; prevStepSize = -1.0;
} }
...@@ -441,7 +441,7 @@ CudaIntegrateBrownianStepKernel::~CudaIntegrateBrownianStepKernel() { ...@@ -441,7 +441,7 @@ CudaIntegrateBrownianStepKernel::~CudaIntegrateBrownianStepKernel() {
} }
void CudaIntegrateBrownianStepKernel::initialize(const System& system, const BrownianIntegrator& integrator) { void CudaIntegrateBrownianStepKernel::initialize(const System& system, const BrownianIntegrator& integrator) {
initializeIntegration(system, data); initializeIntegration(system, data, integrator);
prevStepSize = -1.0; prevStepSize = -1.0;
} }
......
...@@ -477,6 +477,7 @@ void ReferenceIntegrateVerletStepKernel::execute(OpenMMContextImpl& context, con ...@@ -477,6 +477,7 @@ void ReferenceIntegrateVerletStepKernel::execute(OpenMMContextImpl& context, con
dynamics->setReferenceShakeAlgorithm(shake); dynamics->setReferenceShakeAlgorithm(shake);
prevStepSize = stepSize; prevStepSize = stepSize;
} }
shake->setTolerance(integrator.getConstraintTolerance());
dynamics->update(context.getSystem().getNumParticles(), posData, velData, forceData, masses); dynamics->update(context.getSystem().getNumParticles(), posData, velData, forceData, masses);
} }
...@@ -537,6 +538,7 @@ void ReferenceIntegrateLangevinStepKernel::execute(OpenMMContextImpl& context, c ...@@ -537,6 +538,7 @@ void ReferenceIntegrateLangevinStepKernel::execute(OpenMMContextImpl& context, c
prevFriction = friction; prevFriction = friction;
prevStepSize = stepSize; prevStepSize = stepSize;
} }
shake->setTolerance(integrator.getConstraintTolerance());
dynamics->update(context.getSystem().getNumParticles(), posData, velData, forceData, masses); dynamics->update(context.getSystem().getNumParticles(), posData, velData, forceData, masses);
} }
...@@ -596,6 +598,7 @@ void ReferenceIntegrateBrownianStepKernel::execute(OpenMMContextImpl& context, c ...@@ -596,6 +598,7 @@ void ReferenceIntegrateBrownianStepKernel::execute(OpenMMContextImpl& context, c
prevFriction = friction; prevFriction = friction;
prevStepSize = stepSize; prevStepSize = stepSize;
} }
shake->setTolerance(integrator.getConstraintTolerance());
dynamics->update(context.getSystem().getNumParticles(), posData, velData, forceData, masses); dynamics->update(context.getSystem().getNumParticles(), posData, velData, forceData, masses);
} }
......
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