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

Fixed error in applying constraints

parent 4cd3207e
...@@ -51,6 +51,7 @@ using namespace OpenMM; ...@@ -51,6 +51,7 @@ using namespace OpenMM;
ReferenceCustomDynamics::ReferenceCustomDynamics(int numberOfAtoms, const CustomIntegrator& integrator) : ReferenceCustomDynamics::ReferenceCustomDynamics(int numberOfAtoms, const CustomIntegrator& integrator) :
ReferenceDynamics(numberOfAtoms, integrator.getStepSize(), 0.0), integrator(integrator) { ReferenceDynamics(numberOfAtoms, integrator.getStepSize(), 0.0), integrator(integrator) {
sumBuffer.resize(numberOfAtoms); sumBuffer.resize(numberOfAtoms);
oldPos.resize(numberOfAtoms);
stepType.resize(integrator.getNumComputations()); stepType.resize(integrator.getNumComputations());
stepVariable.resize(integrator.getNumComputations()); stepVariable.resize(integrator.getNumComputations());
stepExpression.resize(integrator.getNumComputations()); stepExpression.resize(integrator.getNumComputations());
...@@ -92,6 +93,7 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve ...@@ -92,6 +93,7 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve
map<string, RealOpenMM>& globals, vector<vector<RealVec> >& perDof, bool& forcesAreValid){ map<string, RealOpenMM>& globals, vector<vector<RealVec> >& perDof, bool& forcesAreValid){
int numSteps = stepType.size(); int numSteps = stepType.size();
globals.insert(context.getParameters().begin(), context.getParameters().end()); globals.insert(context.getParameters().begin(), context.getParameters().end());
oldPos = atomCoordinates;
if (invalidatesForces.size() == 0) { if (invalidatesForces.size() == 0) {
// The first time this is called, work out when to recompute forces and energy. First build a // The first time this is called, work out when to recompute forces and energy. First build a
// list of every step that invalidates the forces. // list of every step that invalidates the forces.
...@@ -227,11 +229,12 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve ...@@ -227,11 +229,12 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve
break; break;
} }
case CustomIntegrator::ConstrainPositions: { case CustomIntegrator::ConstrainPositions: {
getReferenceConstraintAlgorithm()->apply(numberOfAtoms, atomCoordinates, atomCoordinates, inverseMasses); getReferenceConstraintAlgorithm()->apply(numberOfAtoms, oldPos, atomCoordinates, inverseMasses);
oldPos = atomCoordinates;
break; break;
} }
case CustomIntegrator::ConstrainVelocities: { case CustomIntegrator::ConstrainVelocities: {
getReferenceConstraintAlgorithm()->applyToVelocities(numberOfAtoms, atomCoordinates, velocities, inverseMasses); getReferenceConstraintAlgorithm()->applyToVelocities(numberOfAtoms, oldPos, velocities, inverseMasses);
break; break;
} }
case CustomIntegrator::UpdateContextState: { case CustomIntegrator::UpdateContextState: {
......
...@@ -41,7 +41,7 @@ private: ...@@ -41,7 +41,7 @@ private:
const OpenMM::CustomIntegrator& integrator; const OpenMM::CustomIntegrator& integrator;
std::vector<RealOpenMM> inverseMasses; std::vector<RealOpenMM> inverseMasses;
std::vector<OpenMM::RealVec> sumBuffer; std::vector<OpenMM::RealVec> sumBuffer, oldPos;
std::vector<OpenMM::CustomIntegrator::ComputationType> stepType; std::vector<OpenMM::CustomIntegrator::ComputationType> stepType;
std::vector<std::string> stepVariable, forceName; std::vector<std::string> stepVariable, forceName;
std::vector<Lepton::ExpressionProgram> stepExpression; std::vector<Lepton::ExpressionProgram> stepExpression;
......
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