Unverified Commit 75d4f299 authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Fixed periodic box changing from rectangular to triclinic (#4618)

parent 68fd0f67
...@@ -352,6 +352,9 @@ void CommonUpdateStateDataKernel::getPeriodicBoxVectors(ContextImpl& context, Ve ...@@ -352,6 +352,9 @@ void CommonUpdateStateDataKernel::getPeriodicBoxVectors(ContextImpl& context, Ve
} }
void CommonUpdateStateDataKernel::setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) { void CommonUpdateStateDataKernel::setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) {
if (!cc.getBoxIsTriclinic() && (b[0] != 0 || c[0] != 0 || c[1] != 0))
throw OpenMMException("The box shape has changed from rectangular to triclinic. To do this, you must call setDefaultPeriodicBoxVectors() on the System to specify a triclinic default box, then reinitialize the Context.");
// If any particles have been wrapped to the first periodic box, we need to unwrap them // If any particles have been wrapped to the first periodic box, we need to unwrap them
// to avoid changing their positions. // to avoid changing their positions.
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,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) 2009-2023 Stanford University and the Authors. * * Portions copyright (c) 2009-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "openmm/common/ComputeArray.h" #include "openmm/common/ComputeArray.h"
#include "openmm/common/ContextSelector.h" #include "openmm/common/ContextSelector.h"
#include "SHA1.h" #include "SHA1.h"
#include "openmm/MonteCarloFlexibleBarostat.h"
#include "openmm/Platform.h" #include "openmm/Platform.h"
#include "openmm/System.h" #include "openmm/System.h"
#include "openmm/VirtualSite.h" #include "openmm/VirtualSite.h"
...@@ -292,6 +293,9 @@ CudaContext::CudaContext(const System& system, int deviceIndex, bool useBlocking ...@@ -292,6 +293,9 @@ CudaContext::CudaContext(const System& system, int deviceIndex, bool useBlocking
boxIsTriclinic = (boxVectors[0][1] != 0.0 || boxVectors[0][2] != 0.0 || boxIsTriclinic = (boxVectors[0][1] != 0.0 || boxVectors[0][2] != 0.0 ||
boxVectors[1][0] != 0.0 || boxVectors[1][2] != 0.0 || boxVectors[1][0] != 0.0 || boxVectors[1][2] != 0.0 ||
boxVectors[2][0] != 0.0 || boxVectors[2][1] != 0.0); boxVectors[2][0] != 0.0 || boxVectors[2][1] != 0.0);
for (int i = 0; i < system.getNumForces(); i++)
if (dynamic_cast<const MonteCarloFlexibleBarostat*>(&system.getForce(i)) != NULL)
boxIsTriclinic = true;
if (boxIsTriclinic) { if (boxIsTriclinic) {
compilationDefines["APPLY_PERIODIC_TO_DELTA(delta)"] = compilationDefines["APPLY_PERIODIC_TO_DELTA(delta)"] =
"{" "{"
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,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) 2009-2023 Stanford University and the Authors. * * Portions copyright (c) 2009-2024 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "OpenCLNonbondedUtilities.h" #include "OpenCLNonbondedUtilities.h"
#include "OpenCLProgram.h" #include "OpenCLProgram.h"
#include "openmm/common/ComputeArray.h" #include "openmm/common/ComputeArray.h"
#include "openmm/MonteCarloFlexibleBarostat.h"
#include "openmm/Platform.h" #include "openmm/Platform.h"
#include "openmm/System.h" #include "openmm/System.h"
#include "openmm/VirtualSite.h" #include "openmm/VirtualSite.h"
...@@ -439,6 +440,9 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device ...@@ -439,6 +440,9 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device
boxIsTriclinic = (boxVectors[0][1] != 0.0 || boxVectors[0][2] != 0.0 || boxIsTriclinic = (boxVectors[0][1] != 0.0 || boxVectors[0][2] != 0.0 ||
boxVectors[1][0] != 0.0 || boxVectors[1][2] != 0.0 || boxVectors[1][0] != 0.0 || boxVectors[1][2] != 0.0 ||
boxVectors[2][0] != 0.0 || boxVectors[2][1] != 0.0); boxVectors[2][0] != 0.0 || boxVectors[2][1] != 0.0);
for (int i = 0; i < system.getNumForces(); i++)
if (dynamic_cast<const MonteCarloFlexibleBarostat*>(&system.getForce(i)) != NULL)
boxIsTriclinic = true;
if (boxIsTriclinic) { if (boxIsTriclinic) {
compilationDefines["APPLY_PERIODIC_TO_DELTA(delta)"] = compilationDefines["APPLY_PERIODIC_TO_DELTA(delta)"] =
"{" "{"
......
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