Unverified Commit 86f07082 authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Fixed error in barostats (#4049)

parent 729c0990
...@@ -111,7 +111,7 @@ void MonteCarloAnisotropicBarostatImpl::updateContextState(ContextImpl& context) ...@@ -111,7 +111,7 @@ void MonteCarloAnisotropicBarostatImpl::updateContextState(ContextImpl& context)
context.getOwner().setPeriodicBoxVectors(Vec3(box[0][0]*lengthScale[0], box[0][1]*lengthScale[1], box[0][2]*lengthScale[2]), context.getOwner().setPeriodicBoxVectors(Vec3(box[0][0]*lengthScale[0], box[0][1]*lengthScale[1], box[0][2]*lengthScale[2]),
Vec3(box[1][0]*lengthScale[0], box[1][1]*lengthScale[1], box[1][2]*lengthScale[2]), Vec3(box[1][0]*lengthScale[0], box[1][1]*lengthScale[1], box[1][2]*lengthScale[2]),
Vec3(box[2][0]*lengthScale[0], box[2][1]*lengthScale[1], box[2][2]*lengthScale[2])); Vec3(box[2][0]*lengthScale[0], box[2][1]*lengthScale[1], box[2][2]*lengthScale[2]));
// Compute the energy of the modified system. // Compute the energy of the modified system.
double finalEnergy = context.getOwner().getState(State::Energy, false, groups).getPotentialEnergy(); double finalEnergy = context.getOwner().getState(State::Energy, false, groups).getPotentialEnergy();
...@@ -120,8 +120,8 @@ void MonteCarloAnisotropicBarostatImpl::updateContextState(ContextImpl& context) ...@@ -120,8 +120,8 @@ void MonteCarloAnisotropicBarostatImpl::updateContextState(ContextImpl& context)
if (w > 0 && SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber() > exp(-w/kT)) { if (w > 0 && SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber() > exp(-w/kT)) {
// Reject the step. // Reject the step.
kernel.getAs<ApplyMonteCarloBarostatKernel>().restoreCoordinates(context);
context.getOwner().setPeriodicBoxVectors(box[0], box[1], box[2]); context.getOwner().setPeriodicBoxVectors(box[0], box[1], box[2]);
kernel.getAs<ApplyMonteCarloBarostatKernel>().restoreCoordinates(context);
} }
else else
numAccepted[axis]++; numAccepted[axis]++;
......
...@@ -90,8 +90,8 @@ void MonteCarloBarostatImpl::updateContextState(ContextImpl& context, bool& forc ...@@ -90,8 +90,8 @@ void MonteCarloBarostatImpl::updateContextState(ContextImpl& context, bool& forc
if (w > 0 && SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber() > exp(-w/kT)) { if (w > 0 && SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber() > exp(-w/kT)) {
// Reject the step. // Reject the step.
kernel.getAs<ApplyMonteCarloBarostatKernel>().restoreCoordinates(context);
context.getOwner().setPeriodicBoxVectors(box[0], box[1], box[2]); context.getOwner().setPeriodicBoxVectors(box[0], box[1], box[2]);
kernel.getAs<ApplyMonteCarloBarostatKernel>().restoreCoordinates(context);
} }
else { else {
numAccepted++; numAccepted++;
......
...@@ -115,8 +115,8 @@ void MonteCarloFlexibleBarostatImpl::updateContextState(ContextImpl& context, bo ...@@ -115,8 +115,8 @@ void MonteCarloFlexibleBarostatImpl::updateContextState(ContextImpl& context, bo
if (w > 0 && SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber() > exp(-w/kT)) { if (w > 0 && SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber() > exp(-w/kT)) {
// Reject the step. // Reject the step.
kernel.getAs<ApplyMonteCarloBarostatKernel>().restoreCoordinates(context);
context.getOwner().setPeriodicBoxVectors(box[0], box[1], box[2]); context.getOwner().setPeriodicBoxVectors(box[0], box[1], box[2]);
kernel.getAs<ApplyMonteCarloBarostatKernel>().restoreCoordinates(context);
} }
else { else {
numAccepted++; numAccepted++;
......
...@@ -121,8 +121,8 @@ void MonteCarloMembraneBarostatImpl::updateContextState(ContextImpl& context) { ...@@ -121,8 +121,8 @@ void MonteCarloMembraneBarostatImpl::updateContextState(ContextImpl& context) {
if (w > 0 && SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber() > exp(-w/kT)) { if (w > 0 && SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber() > exp(-w/kT)) {
// Reject the step. // Reject the step.
kernel.getAs<ApplyMonteCarloBarostatKernel>().restoreCoordinates(context);
context.getOwner().setPeriodicBoxVectors(box[0], box[1], box[2]); context.getOwner().setPeriodicBoxVectors(box[0], box[1], box[2]);
kernel.getAs<ApplyMonteCarloBarostatKernel>().restoreCoordinates(context);
} }
else else
numAccepted[axis]++; numAccepted[axis]++;
......
...@@ -7217,7 +7217,7 @@ void CommonIntegrateCustomStepKernel::execute(ContextImpl& context, CustomIntegr ...@@ -7217,7 +7217,7 @@ void CommonIntegrateCustomStepKernel::execute(ContextImpl& context, CustomIntegr
energy = savedEnergy[forceGroups]; energy = savedEnergy[forceGroups];
if (needsGlobals[step] && !deviceGlobalsAreCurrent) { if (needsGlobals[step] && !deviceGlobalsAreCurrent) {
// Upload the global values to the device. // Upload the global values to the device.
globalValues.upload(localGlobalValues, true); globalValues.upload(localGlobalValues, true);
deviceGlobalsAreCurrent = true; deviceGlobalsAreCurrent = true;
} }
...@@ -7781,13 +7781,13 @@ void CommonApplyMonteCarloBarostatKernel::scaleCoordinates(ContextImpl& context, ...@@ -7781,13 +7781,13 @@ void CommonApplyMonteCarloBarostatKernel::scaleCoordinates(ContextImpl& context,
cc.getLongForceBuffer().copyTo(savedLongForces); cc.getLongForceBuffer().copyTo(savedLongForces);
if (savedFloatForces.isInitialized()) if (savedFloatForces.isInitialized())
cc.getFloatForceBuffer().copyTo(savedFloatForces); cc.getFloatForceBuffer().copyTo(savedFloatForces);
lastPosCellOffsets = cc.getPosCellOffsets();
kernel->setArg(0, (float) scaleX); kernel->setArg(0, (float) scaleX);
kernel->setArg(1, (float) scaleY); kernel->setArg(1, (float) scaleY);
kernel->setArg(2, (float) scaleZ); kernel->setArg(2, (float) scaleZ);
setPeriodicBoxArgs(cc, kernel, 4); setPeriodicBoxArgs(cc, kernel, 4);
kernel->execute(cc.getNumAtoms()); kernel->execute(cc.getNumAtoms());
lastAtomOrder = cc.getAtomIndex(); lastAtomOrder = cc.getAtomIndex();
lastPosCellOffsets = cc.getPosCellOffsets();
} }
void CommonApplyMonteCarloBarostatKernel::restoreCoordinates(ContextImpl& context) { void CommonApplyMonteCarloBarostatKernel::restoreCoordinates(ContextImpl& context) {
......
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