Unverified Commit 610e92fa authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Added lots of checks for invalid parameter values (#3286)

* Added lots of checks for invalid parameter values

* Fixed test failures

* More checks for incorrect parameters

* Fixed test failures
parent 9270d590
...@@ -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-2019 Stanford University and the Authors. * * Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -65,9 +65,7 @@ public: ...@@ -65,9 +65,7 @@ public:
* *
* @param temp the temperature of the heat bath, measured in Kelvin. * @param temp the temperature of the heat bath, measured in Kelvin.
*/ */
void setTemperature(double temp) { void setTemperature(double temp);
temperature = temp;
}
/** /**
* Get the friction coefficient which determines how strongly the system is coupled to * Get the friction coefficient which determines how strongly the system is coupled to
* the heat bath (in inverse ps). * the heat bath (in inverse ps).
...@@ -83,9 +81,7 @@ public: ...@@ -83,9 +81,7 @@ public:
* *
* @param coeff the friction coefficient, measured in 1/ps * @param coeff the friction coefficient, measured in 1/ps
*/ */
void setFriction(double coeff) { void setFriction(double coeff);
friction = coeff;
}
/** /**
* Get the random number seed. See setRandomNumberSeed() for details. * Get the random number seed. See setRandomNumberSeed() for details.
*/ */
......
...@@ -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 Stanford University and the Authors. * * Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -58,9 +58,7 @@ public: ...@@ -58,9 +58,7 @@ public:
/** /**
* Set the frequency (in time steps) at which center of mass motion should be removed * Set the frequency (in time steps) at which center of mass motion should be removed
*/ */
void setFrequency(int freq) { void setFrequency(int freq);
frequency = freq;
}
/** /**
* Returns whether or not this force makes use of periodic boundary * Returns whether or not this force makes use of periodic boundary
* conditions. * conditions.
......
...@@ -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-2020 Stanford University and the Authors. * * Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -65,9 +65,7 @@ public: ...@@ -65,9 +65,7 @@ public:
* *
* @param temp the temperature of the heat bath, measured in Kelvin * @param temp the temperature of the heat bath, measured in Kelvin
*/ */
void setTemperature(double temp) { void setTemperature(double temp);
temperature = temp;
}
/** /**
* Get the friction coefficient which determines how strongly the system is coupled to * Get the friction coefficient which determines how strongly the system is coupled to
* the heat bath (in inverse ps). * the heat bath (in inverse ps).
...@@ -83,9 +81,7 @@ public: ...@@ -83,9 +81,7 @@ public:
* *
* @param coeff the friction coefficient, measured in 1/ps * @param coeff the friction coefficient, measured in 1/ps
*/ */
void setFriction(double coeff) { void setFriction(double coeff);
friction = coeff;
}
/** /**
* Get the random number seed. See setRandomNumberSeed() for details. * Get the random number seed. See setRandomNumberSeed() for details.
*/ */
......
...@@ -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-2020 Stanford University and the Authors. * * Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -74,9 +74,7 @@ public: ...@@ -74,9 +74,7 @@ public:
* *
* @param temp the temperature of the heat bath, measured in Kelvin * @param temp the temperature of the heat bath, measured in Kelvin
*/ */
void setTemperature(double temp) { void setTemperature(double temp);
temperature = temp;
}
/** /**
* Get the friction coefficient which determines how strongly the system is coupled to * Get the friction coefficient which determines how strongly the system is coupled to
* the heat bath (in inverse ps). * the heat bath (in inverse ps).
...@@ -92,9 +90,7 @@ public: ...@@ -92,9 +90,7 @@ public:
* *
* @param coeff the friction coefficient, measured in 1/ps * @param coeff the friction coefficient, measured in 1/ps
*/ */
void setFriction(double coeff) { void setFriction(double coeff);
friction = coeff;
}
/** /**
* Get the random number seed. See setRandomNumberSeed() for details. * Get the random number seed. See setRandomNumberSeed() for details.
*/ */
......
...@@ -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) 2010-2016 Stanford University and the Authors. * * Portions copyright (c) 2010-2021 Stanford University and the Authors. *
* Authors: Peter Eastman, Lee-Ping Wang * * Authors: Peter Eastman, Lee-Ping Wang *
* Contributors: * * Contributors: *
* * * *
...@@ -114,9 +114,7 @@ public: ...@@ -114,9 +114,7 @@ public:
* *
* @param pressure the default pressure acting on the system, measured in bar. * @param pressure the default pressure acting on the system, measured in bar.
*/ */
void setDefaultPressure(const Vec3& pressure) { void setDefaultPressure(const Vec3& pressure);
defaultPressure = pressure;
}
/** /**
* Get whether to allow the X dimension of the periodic box to change size. * Get whether to allow the X dimension of the periodic box to change size.
*/ */
...@@ -146,9 +144,7 @@ public: ...@@ -146,9 +144,7 @@ public:
* Set the frequency (in time steps) at which Monte Carlo pressure changes should be attempted. If this is set to * Set the frequency (in time steps) at which Monte Carlo pressure changes should be attempted. If this is set to
* 0, the barostat is disabled. * 0, the barostat is disabled.
*/ */
void setFrequency(int freq) { void setFrequency(int freq);
frequency = freq;
}
/** /**
* Get the default temperature at which the system is being maintained, measured in Kelvin. * Get the default temperature at which the system is being maintained, measured in Kelvin.
*/ */
...@@ -161,9 +157,7 @@ public: ...@@ -161,9 +157,7 @@ public:
* *
* @param temp the system temperature, measured in Kelvin. * @param temp the system temperature, measured in Kelvin.
*/ */
void setDefaultTemperature(double temp) { void setDefaultTemperature(double temp);
defaultTemperature = temp;
}
/** /**
* Get the random number seed. See setRandomNumberSeed() for details. * Get the random number seed. See setRandomNumberSeed() for details.
*/ */
......
...@@ -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) 2010-2016 Stanford University and the Authors. * * Portions copyright (c) 2010-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -88,9 +88,7 @@ public: ...@@ -88,9 +88,7 @@ public:
* *
* @param pressure the default pressure acting on the system, measured in bar. * @param pressure the default pressure acting on the system, measured in bar.
*/ */
void setDefaultPressure(double pressure) { void setDefaultPressure(double pressure);
defaultPressure = pressure;
}
/** /**
* Get the frequency (in time steps) at which Monte Carlo pressure changes should be attempted. If this is set to * Get the frequency (in time steps) at which Monte Carlo pressure changes should be attempted. If this is set to
* 0, the barostat is disabled. * 0, the barostat is disabled.
...@@ -102,9 +100,7 @@ public: ...@@ -102,9 +100,7 @@ public:
* Set the frequency (in time steps) at which Monte Carlo pressure changes should be attempted. If this is set to * Set the frequency (in time steps) at which Monte Carlo pressure changes should be attempted. If this is set to
* 0, the barostat is disabled. * 0, the barostat is disabled.
*/ */
void setFrequency(int freq) { void setFrequency(int freq);
frequency = freq;
}
/** /**
* Get the default temperature at which the system is being maintained, measured in Kelvin. * Get the default temperature at which the system is being maintained, measured in Kelvin.
*/ */
...@@ -117,9 +113,7 @@ public: ...@@ -117,9 +113,7 @@ public:
* *
* @param temp the system temperature, measured in Kelvin. * @param temp the system temperature, measured in Kelvin.
*/ */
void setDefaultTemperature(double temp) { void setDefaultTemperature(double temp);
defaultTemperature = temp;
}
/** /**
* Get the random number seed. See setRandomNumberSeed() for details. * Get the random number seed. See setRandomNumberSeed() for details.
*/ */
......
...@@ -101,9 +101,7 @@ public: ...@@ -101,9 +101,7 @@ public:
* *
* @param pressure the default pressure acting on the system, measured in bar. * @param pressure the default pressure acting on the system, measured in bar.
*/ */
void setDefaultPressure(double pressure) { void setDefaultPressure(double pressure);
defaultPressure = pressure;
}
/** /**
* Get the frequency (in time steps) at which Monte Carlo pressure changes should be attempted. If this is set to * Get the frequency (in time steps) at which Monte Carlo pressure changes should be attempted. If this is set to
* 0, the barostat is disabled. * 0, the barostat is disabled.
...@@ -115,9 +113,7 @@ public: ...@@ -115,9 +113,7 @@ public:
* Set the frequency (in time steps) at which Monte Carlo pressure changes should be attempted. If this is set to * Set the frequency (in time steps) at which Monte Carlo pressure changes should be attempted. If this is set to
* 0, the barostat is disabled. * 0, the barostat is disabled.
*/ */
void setFrequency(int freq) { void setFrequency(int freq);
frequency = freq;
}
/** /**
* Get the default temperature at which the system is being maintained, measured in Kelvin. * Get the default temperature at which the system is being maintained, measured in Kelvin.
*/ */
...@@ -130,9 +126,7 @@ public: ...@@ -130,9 +126,7 @@ public:
* *
* @param temp the system temperature, measured in Kelvin. * @param temp the system temperature, measured in Kelvin.
*/ */
void setDefaultTemperature(double temp) { void setDefaultTemperature(double temp);
defaultTemperature = temp;
}
/** /**
* Get the random number seed. See setRandomNumberSeed() for details. * Get the random number seed. See setRandomNumberSeed() for details.
*/ */
......
...@@ -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) 2010-2016 Stanford University and the Authors. * * Portions copyright (c) 2010-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -144,9 +144,7 @@ public: ...@@ -144,9 +144,7 @@ public:
* *
* @param pressure the default pressure acting on the system, measured in bar. * @param pressure the default pressure acting on the system, measured in bar.
*/ */
void setDefaultPressure(double pressure) { void setDefaultPressure(double pressure);
defaultPressure = pressure;
}
/** /**
* Get the default surface tension acting on the system (in bar*nm). * Get the default surface tension acting on the system (in bar*nm).
* *
...@@ -161,9 +159,7 @@ public: ...@@ -161,9 +159,7 @@ public:
* *
* @param surfaceTension the default surface tension acting on the system, measured in bar. * @param surfaceTension the default surface tension acting on the system, measured in bar.
*/ */
void setDefaultSurfaceTension(double surfaceTension) { void setDefaultSurfaceTension(double surfaceTension);
defaultSurfaceTension = surfaceTension;
}
/** /**
* Get the frequency (in time steps) at which Monte Carlo volume changes should be attempted. If this is set to * Get the frequency (in time steps) at which Monte Carlo volume changes should be attempted. If this is set to
* 0, the barostat is disabled. * 0, the barostat is disabled.
...@@ -175,9 +171,7 @@ public: ...@@ -175,9 +171,7 @@ public:
* Set the frequency (in time steps) at which Monte Carlo volume changes should be attempted. If this is set to * Set the frequency (in time steps) at which Monte Carlo volume changes should be attempted. If this is set to
* 0, the barostat is disabled. * 0, the barostat is disabled.
*/ */
void setFrequency(int freq) { void setFrequency(int freq);
frequency = freq;
}
/** /**
* Get the default temperature at which the system is being maintained, measured in Kelvin. * Get the default temperature at which the system is being maintained, measured in Kelvin.
*/ */
...@@ -190,9 +184,7 @@ public: ...@@ -190,9 +184,7 @@ public:
* *
* @param temp the system temperature, measured in Kelvin. * @param temp the system temperature, measured in Kelvin.
*/ */
void setDefaultTemperature(double temp) { void setDefaultTemperature(double temp);
defaultTemperature = temp;
}
/** /**
* Get the mode specifying the behavior of the X and Y axes. * Get the mode specifying the behavior of the X and Y axes.
*/ */
......
...@@ -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-2019 Stanford University and the Authors. * * Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -79,9 +79,7 @@ public: ...@@ -79,9 +79,7 @@ public:
* *
* @param temp the temperature of the heat bath, measured in Kelvin * @param temp the temperature of the heat bath, measured in Kelvin
*/ */
void setTemperature(double temp) { void setTemperature(double temp);
temperature = temp;
}
/** /**
* Get the friction coefficient which determines how strongly the system is coupled to * Get the friction coefficient which determines how strongly the system is coupled to
* the heat bath (in inverse ps). * the heat bath (in inverse ps).
...@@ -97,9 +95,7 @@ public: ...@@ -97,9 +95,7 @@ public:
* *
* @param coeff the friction coefficient, measured in 1/ps * @param coeff the friction coefficient, measured in 1/ps
*/ */
void setFriction(double coeff) { void setFriction(double coeff);
friction = coeff;
}
/** /**
* Get the error tolerance. * Get the error tolerance.
*/ */
...@@ -109,9 +105,7 @@ public: ...@@ -109,9 +105,7 @@ public:
/** /**
* Set the error tolerance. * Set the error tolerance.
*/ */
void setErrorTolerance(double tol) { void setErrorTolerance(double tol);
errorTol = tol;
}
/** /**
* Get the maximum step size the integrator will ever use, in ps. If this * Get the maximum step size the integrator will ever use, in ps. If this
* is 0 (the default), no limit will be applied to step sizes. * is 0 (the default), no limit will be applied to step sizes.
...@@ -123,9 +117,7 @@ public: ...@@ -123,9 +117,7 @@ public:
* Set the maximum step size the integrator will ever use, in ps. If this * Set the maximum step size the integrator will ever use, in ps. If this
* is 0 (the default), no limit will be applied to step sizes. * is 0 (the default), no limit will be applied to step sizes.
*/ */
void setMaximumStepSize(double size) { void setMaximumStepSize(double size);
maxStepSize = size;
}
/** /**
* Get the random number seed. See setRandomNumberSeed() for details. * Get the random number seed. See setRandomNumberSeed() for details.
*/ */
......
...@@ -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-2019 Stanford University and the Authors. * * Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -79,9 +79,7 @@ public: ...@@ -79,9 +79,7 @@ public:
/** /**
* Set the error tolerance. * Set the error tolerance.
*/ */
void setErrorTolerance(double tol) { void setErrorTolerance(double tol);
errorTol = tol;
}
/** /**
* Get the maximum step size the integrator will ever use, in ps. If this * Get the maximum step size the integrator will ever use, in ps. If this
* is 0 (the default), no limit will be applied to step sizes. * is 0 (the default), no limit will be applied to step sizes.
...@@ -93,9 +91,7 @@ public: ...@@ -93,9 +91,7 @@ public:
* Set the maximum step size the integrator will ever use, in ps. If this * Set the maximum step size the integrator will ever use, in ps. If this
* is 0 (the default), no limit will be applied to step sizes. * is 0 (the default), no limit will be applied to step sizes.
*/ */
void setMaximumStepSize(double size) { void setMaximumStepSize(double size);
maxStepSize = size;
}
/** /**
* Advance a simulation through time by taking a series of time steps. * Advance a simulation through time by taking a series of time steps.
* *
......
...@@ -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) 2008-2010 Stanford University and the Authors. * * Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "openmm/internal/AndersenThermostatImpl.h" #include "openmm/internal/AndersenThermostatImpl.h"
#include "openmm/internal/ContextImpl.h" #include "openmm/internal/ContextImpl.h"
#include "openmm/Integrator.h" #include "openmm/Integrator.h"
#include "openmm/OpenMMException.h"
#include "openmm/System.h" #include "openmm/System.h"
#include "openmm/kernels.h" #include "openmm/kernels.h"
#include <vector> #include <vector>
...@@ -43,6 +44,10 @@ AndersenThermostatImpl::AndersenThermostatImpl(const AndersenThermostat& owner) ...@@ -43,6 +44,10 @@ AndersenThermostatImpl::AndersenThermostatImpl(const AndersenThermostat& owner)
} }
void AndersenThermostatImpl::initialize(ContextImpl& context) { void AndersenThermostatImpl::initialize(ContextImpl& context) {
if (owner.getDefaultTemperature() < 0)
throw OpenMMException("AndersenThermostat: temperature cannot be negative");
if (owner.getDefaultCollisionFrequency() < 0)
throw OpenMMException("AndersenThermostat: collision frequency cannot be negative");
kernel = context.getPlatform().createKernel(ApplyAndersenThermostatKernel::Name(), context); kernel = context.getPlatform().createKernel(ApplyAndersenThermostatKernel::Name(), context);
kernel.getAs<ApplyAndersenThermostatKernel>().initialize(context.getSystem(), owner); kernel.getAs<ApplyAndersenThermostatKernel>().initialize(context.getSystem(), owner);
} }
......
...@@ -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) 2008-2020 Stanford University and the Authors. * * Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -57,6 +57,18 @@ void BrownianIntegrator::initialize(ContextImpl& contextRef) { ...@@ -57,6 +57,18 @@ void BrownianIntegrator::initialize(ContextImpl& contextRef) {
kernel.getAs<IntegrateBrownianStepKernel>().initialize(contextRef.getSystem(), *this); kernel.getAs<IntegrateBrownianStepKernel>().initialize(contextRef.getSystem(), *this);
} }
void BrownianIntegrator::setTemperature(double temp) {
if (temp < 0)
throw OpenMMException("Temperature cannot be negative");
temperature = temp;
}
void BrownianIntegrator::setFriction(double coeff) {
if (coeff <= 0)
throw OpenMMException("Friction must be positive");
friction = coeff;
}
void BrownianIntegrator::cleanup() { void BrownianIntegrator::cleanup() {
kernel = Kernel(); kernel = Kernel();
} }
......
...@@ -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) 2010-2015 Stanford University and the Authors. * * Portions copyright (c) 2010-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "openmm/internal/SplineFitter.h" #include "openmm/internal/SplineFitter.h"
#include "openmm/kernels.h" #include "openmm/kernels.h"
#include <cmath> #include <cmath>
#include <sstream>
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
...@@ -48,6 +49,25 @@ CMAPTorsionForceImpl::~CMAPTorsionForceImpl() { ...@@ -48,6 +49,25 @@ CMAPTorsionForceImpl::~CMAPTorsionForceImpl() {
} }
void CMAPTorsionForceImpl::initialize(ContextImpl& context) { void CMAPTorsionForceImpl::initialize(ContextImpl& context) {
const System& system = context.getSystem();
for (int i = 0; i < owner.getNumTorsions(); i++) {
int particle[8], map;
owner.getTorsionParameters(i, map, particle[0], particle[1], particle[2], particle[3], particle[4], particle[5], particle[6], particle[7]);
if (map < 0 || map >= owner.getNumMaps()) {
stringstream msg;
msg << "CMAPTorsionForce: Illegal map index for a torsion: ";
msg << map;
throw OpenMMException(msg.str());
}
for (int j = 0; j < 8; j++) {
if (particle[j] < 0 || particle[j] >= system.getNumParticles()) {
stringstream msg;
msg << "CMAPTorsionForce: Illegal particle index for a torsion: ";
msg << particle[j];
throw OpenMMException(msg.str());
}
}
}
kernel = context.getPlatform().createKernel(CalcCMAPTorsionForceKernel::Name(), context); kernel = context.getPlatform().createKernel(CalcCMAPTorsionForceKernel::Name(), context);
kernel.getAs<CalcCMAPTorsionForceKernel>().initialize(context.getSystem(), owner); kernel.getAs<CalcCMAPTorsionForceKernel>().initialize(context.getSystem(), owner);
} }
......
...@@ -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) 2008 Stanford University and the Authors. * * Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -30,11 +30,19 @@ ...@@ -30,11 +30,19 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "openmm/CMMotionRemover.h" #include "openmm/CMMotionRemover.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/CMMotionRemoverImpl.h" #include "openmm/internal/CMMotionRemoverImpl.h"
using namespace OpenMM; using namespace OpenMM;
CMMotionRemover::CMMotionRemover(int frequency) : frequency(frequency) { CMMotionRemover::CMMotionRemover(int frequency) {
setFrequency(frequency);
}
void CMMotionRemover::setFrequency(int freq) {
if (freq <= 0)
throw OpenMMException("CMMotionRemover: frequency must be positive");
frequency = freq;
} }
ForceImpl* CMMotionRemover::createImpl() const { ForceImpl* CMMotionRemover::createImpl() const {
......
...@@ -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) 2010-2012 Stanford University and the Authors. * * Portions copyright (c) 2010-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -57,25 +57,15 @@ void CustomAngleForceImpl::initialize(ContextImpl& context) { ...@@ -57,25 +57,15 @@ void CustomAngleForceImpl::initialize(ContextImpl& context) {
vector<double> parameters; vector<double> parameters;
int numParameters = owner.getNumPerAngleParameters(); int numParameters = owner.getNumPerAngleParameters();
for (int i = 0; i < owner.getNumAngles(); i++) { for (int i = 0; i < owner.getNumAngles(); i++) {
int particle1, particle2, particle3; int particle[3];
owner.getAngleParameters(i, particle1, particle2, particle3, parameters); owner.getAngleParameters(i, particle[0], particle[1], particle[2], parameters);
if (particle1 < 0 || particle1 >= system.getNumParticles()) { for (int j = 0; j < 3; j++) {
if (particle[j] < 0 || particle[j] >= system.getNumParticles()) {
stringstream msg; stringstream msg;
msg << "CustomAngleForce: Illegal particle index for an angle: "; msg << "CustomAngleForce: Illegal particle index for an angle: ";
msg << particle1; msg << particle[j];
throw OpenMMException(msg.str()); throw OpenMMException(msg.str());
} }
if (particle2 < 0 || particle2 >= system.getNumParticles()) {
stringstream msg;
msg << "CustomAngleForce: Illegal particle index for an angle: ";
msg << particle2;
throw OpenMMException(msg.str());
}
if (particle3 < 0 || particle3 >= system.getNumParticles()) {
stringstream msg;
msg << "CustomAngleForce: Illegal particle index for an angle: ";
msg << particle3;
throw OpenMMException(msg.str());
} }
if (parameters.size() != numParameters) { if (parameters.size() != numParameters) {
stringstream msg; stringstream msg;
......
...@@ -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) 2008-2012 Stanford University and the Authors. * * Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -58,19 +58,15 @@ void CustomBondForceImpl::initialize(ContextImpl& context) { ...@@ -58,19 +58,15 @@ void CustomBondForceImpl::initialize(ContextImpl& context) {
vector<double> parameters; vector<double> parameters;
int numParameters = owner.getNumPerBondParameters(); int numParameters = owner.getNumPerBondParameters();
for (int i = 0; i < owner.getNumBonds(); i++) { for (int i = 0; i < owner.getNumBonds(); i++) {
int particle1, particle2; int particle[2];
owner.getBondParameters(i, particle1, particle2, parameters); owner.getBondParameters(i, particle[0], particle[1], parameters);
if (particle1 < 0 || particle1 >= system.getNumParticles()) { for (int j = 0; j < 2; j++) {
if (particle[j] < 0 || particle[j] >= system.getNumParticles()) {
stringstream msg; stringstream msg;
msg << "CustomBondForce: Illegal particle index for a bond: "; msg << "CustomBondForce: Illegal particle index for a bond: ";
msg << particle1; msg << particle[j];
throw OpenMMException(msg.str()); throw OpenMMException(msg.str());
} }
if (particle2 < 0 || particle2 >= system.getNumParticles()) {
stringstream msg;
msg << "CustomBondForce: Illegal particle index for a bond: ";
msg << particle2;
throw OpenMMException(msg.str());
} }
if (parameters.size() != numParameters) { if (parameters.size() != numParameters) {
stringstream msg; stringstream msg;
......
...@@ -58,31 +58,15 @@ void CustomTorsionForceImpl::initialize(ContextImpl& context) { ...@@ -58,31 +58,15 @@ void CustomTorsionForceImpl::initialize(ContextImpl& context) {
vector<double> parameters; vector<double> parameters;
int numParameters = owner.getNumPerTorsionParameters(); int numParameters = owner.getNumPerTorsionParameters();
for (int i = 0; i < owner.getNumTorsions(); i++) { for (int i = 0; i < owner.getNumTorsions(); i++) {
int particle1, particle2, particle3, particle4; int particle[4];
owner.getTorsionParameters(i, particle1, particle2, particle3, particle4, parameters); owner.getTorsionParameters(i, particle[0], particle[1], particle[2], particle[3], parameters);
if (particle1 < 0 || particle1 >= system.getNumParticles()) { for (int j = 0; j < 4; j++) {
if (particle[j] < 0 || particle[j] >= system.getNumParticles()) {
stringstream msg; stringstream msg;
msg << "CustomTorsionForce: Illegal particle index for an torsion: "; msg << "CustomTorsionForce: Illegal particle index for a torsion: ";
msg << particle1; msg << particle[j];
throw OpenMMException(msg.str()); throw OpenMMException(msg.str());
} }
if (particle2 < 0 || particle2 >= system.getNumParticles()) {
stringstream msg;
msg << "CustomTorsionForce: Illegal particle index for an torsion: ";
msg << particle2;
throw OpenMMException(msg.str());
}
if (particle3 < 0 || particle3 >= system.getNumParticles()) {
stringstream msg;
msg << "CustomTorsionForce: Illegal particle index for an torsion: ";
msg << particle3;
throw OpenMMException(msg.str());
}
if (particle4 < 0 || particle4 >= system.getNumParticles()) {
stringstream msg;
msg << "CustomTorsionForce: Illegal particle index for an torsion: ";
msg << particle4;
throw OpenMMException(msg.str());
} }
if (parameters.size() != numParameters) { if (parameters.size() != numParameters) {
stringstream msg; stringstream msg;
......
...@@ -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) 2008 Stanford University and the Authors. * * Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -52,6 +52,14 @@ void GBSAOBCForceImpl::initialize(ContextImpl& context) { ...@@ -52,6 +52,14 @@ void GBSAOBCForceImpl::initialize(ContextImpl& context) {
if (cutoff > 0.5*boxVectors[0][0] || cutoff > 0.5*boxVectors[1][1] || cutoff > 0.5*boxVectors[2][2]) if (cutoff > 0.5*boxVectors[0][0] || cutoff > 0.5*boxVectors[1][1] || cutoff > 0.5*boxVectors[2][2])
throw OpenMMException("GBSAOBCForce: The cutoff distance cannot be greater than half the periodic box size."); throw OpenMMException("GBSAOBCForce: The cutoff distance cannot be greater than half the periodic box size.");
} }
for (int i = 0; i < owner.getNumParticles(); i++) {
double charge, radius, scalingFactor;
owner.getParticleParameters(i, charge, radius, scalingFactor);
if (radius <= 0)
throw OpenMMException("GBSAOBCForce: particle radius must be positive");
if (scalingFactor <= 0)
throw OpenMMException("GBSAOBCForce: particle scaling factor must be positive");
}
kernel.getAs<CalcGBSAOBCForceKernel>().initialize(context.getSystem(), owner); kernel.getAs<CalcGBSAOBCForceKernel>().initialize(context.getSystem(), owner);
} }
......
...@@ -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) 2008-2016 Stanford University and the Authors. * * Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -73,34 +73,42 @@ void GayBerneForceImpl::initialize(ContextImpl& context) { ...@@ -73,34 +73,42 @@ void GayBerneForceImpl::initialize(ContextImpl& context) {
msg << yparticle; msg << yparticle;
throw OpenMMException(msg.str()); throw OpenMMException(msg.str());
} }
if (sigma < 0)
throw OpenMMException("GayBerneForce: sigma for a particle cannot be negative");
if (epsilon < 0)
throw OpenMMException("GayBerneForce: epsilon for a particle cannot be negative");
if (rx <= 0 || ry <= 0 || rz <= 0)
throw OpenMMException("GayBerneForce: radii for a particle must be positive");
if (ex <= 0 || ey <= 0 || ez <= 0)
throw OpenMMException("GayBerneForce: scale factors for a particle must be positive");
} }
vector<set<int> > exceptions(owner.getNumParticles()); vector<set<int> > exceptions(owner.getNumParticles());
for (int i = 0; i < owner.getNumExceptions(); i++) { for (int i = 0; i < owner.getNumExceptions(); i++) {
int particle1, particle2; int particle[2];
double sigma, epsilon; double sigma, epsilon;
owner.getExceptionParameters(i, particle1, particle2, sigma, epsilon); owner.getExceptionParameters(i, particle[0], particle[1], sigma, epsilon);
if (particle1 < 0 || particle1 >= owner.getNumParticles()) { for (int j = 0; j < 2; j++) {
if (particle[j] < 0 || particle[j] >= owner.getNumParticles()) {
stringstream msg; stringstream msg;
msg << "GayBerneForce: Illegal particle index for an exception: "; msg << "GayBerneForce: Illegal particle index for an exception: ";
msg << particle1; msg << particle[j];
throw OpenMMException(msg.str()); throw OpenMMException(msg.str());
} }
if (particle2 < 0 || particle2 >= owner.getNumParticles()) {
stringstream msg;
msg << "GayBerneForce: Illegal particle index for an exception: ";
msg << particle2;
throw OpenMMException(msg.str());
} }
if (exceptions[particle1].count(particle2) > 0 || exceptions[particle2].count(particle1) > 0) { if (exceptions[particle[0]].count(particle[1]) > 0 || exceptions[particle[1]].count(particle[0]) > 0) {
stringstream msg; stringstream msg;
msg << "GayBerneForce: Multiple exceptions are specified for particles "; msg << "GayBerneForce: Multiple exceptions are specified for particles ";
msg << particle1; msg << particle[0];
msg << " and "; msg << " and ";
msg << particle2; msg << particle[1];
throw OpenMMException(msg.str()); throw OpenMMException(msg.str());
} }
exceptions[particle1].insert(particle2); if (sigma < 0)
exceptions[particle2].insert(particle1); throw OpenMMException("GayBerneForce: sigma for an exception cannot be negative");
if (epsilon < 0)
throw OpenMMException("GayBerneForce: epsilon for an exception cannot be negative");
exceptions[particle[0]].insert(particle[1]);
exceptions[particle[1]].insert(particle[0]);
} }
if (owner.getNonbondedMethod() == GayBerneForce::CutoffPeriodic) { if (owner.getNonbondedMethod() == GayBerneForce::CutoffPeriodic) {
Vec3 boxVectors[3]; Vec3 boxVectors[3];
......
...@@ -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) 2008-2012 Stanford University and the Authors. * * Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -29,14 +29,18 @@ ...@@ -29,14 +29,18 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * * USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#ifdef WIN32
#define _USE_MATH_DEFINES // Needed to get M_PI
#endif
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h" #include "openmm/internal/ContextImpl.h"
#include "openmm/internal/HarmonicAngleForceImpl.h" #include "openmm/internal/HarmonicAngleForceImpl.h"
#include "openmm/kernels.h" #include "openmm/kernels.h"
#include <cmath>
#include <sstream>
using namespace OpenMM; using namespace OpenMM;
using std::pair; using namespace std;
using std::vector;
using std::set;
HarmonicAngleForceImpl::HarmonicAngleForceImpl(const HarmonicAngleForce& owner) : owner(owner) { HarmonicAngleForceImpl::HarmonicAngleForceImpl(const HarmonicAngleForce& owner) : owner(owner) {
} }
...@@ -45,6 +49,24 @@ HarmonicAngleForceImpl::~HarmonicAngleForceImpl() { ...@@ -45,6 +49,24 @@ HarmonicAngleForceImpl::~HarmonicAngleForceImpl() {
} }
void HarmonicAngleForceImpl::initialize(ContextImpl& context) { void HarmonicAngleForceImpl::initialize(ContextImpl& context) {
const System& system = context.getSystem();
for (int i = 0; i < owner.getNumAngles(); i++) {
int particle[3];
double angle, k;
owner.getAngleParameters(i, particle[0], particle[1], particle[2], angle, k);
for (int j = 0; j < 3; j++) {
if (particle[j] < 0 || particle[j] >= system.getNumParticles()) {
stringstream msg;
msg << "HarmonicAngleForce: Illegal particle index for an angle: ";
msg << particle[j];
throw OpenMMException(msg.str());
}
}
if (angle < 0 || angle > M_PI*1.000001)
throw OpenMMException("HarmonicAngleForce: angle must be between 0 and pi");
if (k < 0)
throw OpenMMException("HarmonicAngleForce: force constant cannot be negative");
}
kernel = context.getPlatform().createKernel(CalcHarmonicAngleForceKernel::Name(), context); kernel = context.getPlatform().createKernel(CalcHarmonicAngleForceKernel::Name(), context);
kernel.getAs<CalcHarmonicAngleForceKernel>().initialize(context.getSystem(), owner); kernel.getAs<CalcHarmonicAngleForceKernel>().initialize(context.getSystem(), owner);
} }
......
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