Unverified Commit 13b93e62 authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Prevent molecules from accidentally getting wrapped by barostat (#4034)

parent 4a26bca4
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2008-2022 Stanford University and the Authors. * * Portions copyright (c) 2008-2023 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -1576,6 +1576,7 @@ private: ...@@ -1576,6 +1576,7 @@ private:
ComputeArray moleculeStartIndex; ComputeArray moleculeStartIndex;
ComputeKernel kernel; ComputeKernel kernel;
std::vector<int> lastAtomOrder; std::vector<int> lastAtomOrder;
std::vector<mm_int4> lastPosCellOffsets;
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2019-2022 Stanford University and the Authors. * * Portions copyright (c) 2019-2023 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -397,6 +397,12 @@ public: ...@@ -397,6 +397,12 @@ public:
std::vector<mm_int4>& getPosCellOffsets() { std::vector<mm_int4>& getPosCellOffsets() {
return posCellOffsets; return posCellOffsets;
} }
/**
* Set the number of cells by which the positions are offset.
*/
void setPosCellOffsets(std::vector<mm_int4>& offsets) {
posCellOffsets = offsets;
}
/** /**
* Replace all occurrences of a list of substrings. * Replace all occurrences of a list of substrings.
* *
......
...@@ -7787,12 +7787,14 @@ void CommonApplyMonteCarloBarostatKernel::scaleCoordinates(ContextImpl& context, ...@@ -7787,12 +7787,14 @@ void CommonApplyMonteCarloBarostatKernel::scaleCoordinates(ContextImpl& context,
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) {
ContextSelector selector(cc); ContextSelector selector(cc);
savedPositions.copyTo(cc.getPosq()); savedPositions.copyTo(cc.getPosq());
savedLongForces.copyTo(cc.getLongForceBuffer()); savedLongForces.copyTo(cc.getLongForceBuffer());
cc.setPosCellOffsets(lastPosCellOffsets);
if (savedFloatForces.isInitialized()) if (savedFloatForces.isInitialized())
savedFloatForces.copyTo(cc.getFloatForceBuffer()); savedFloatForces.copyTo(cc.getFloatForceBuffer());
} }
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