"src/vscode:/vscode.git/clone" did not exist on "d6310a273ce9442d93faecf01eab8a847df290f5"
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 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -65,9 +65,7 @@ public:
*
* @param temp the temperature of the heat bath, measured in Kelvin.
*/
void setTemperature(double temp) {
temperature = temp;
}
void setTemperature(double temp);
/**
* Get the friction coefficient which determines how strongly the system is coupled to
* the heat bath (in inverse ps).
......@@ -83,9 +81,7 @@ public:
*
* @param coeff the friction coefficient, measured in 1/ps
*/
void setFriction(double coeff) {
friction = coeff;
}
void setFriction(double coeff);
/**
* Get the random number seed. See setRandomNumberSeed() for details.
*/
......
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -58,9 +58,7 @@ public:
/**
* Set the frequency (in time steps) at which center of mass motion should be removed
*/
void setFrequency(int freq) {
frequency = freq;
}
void setFrequency(int freq);
/**
* Returns whether or not this force makes use of periodic boundary
* conditions.
......
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -65,9 +65,7 @@ public:
*
* @param temp the temperature of the heat bath, measured in Kelvin
*/
void setTemperature(double temp) {
temperature = temp;
}
void setTemperature(double temp);
/**
* Get the friction coefficient which determines how strongly the system is coupled to
* the heat bath (in inverse ps).
......@@ -83,9 +81,7 @@ public:
*
* @param coeff the friction coefficient, measured in 1/ps
*/
void setFriction(double coeff) {
friction = coeff;
}
void setFriction(double coeff);
/**
* Get the random number seed. See setRandomNumberSeed() for details.
*/
......
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -74,9 +74,7 @@ public:
*
* @param temp the temperature of the heat bath, measured in Kelvin
*/
void setTemperature(double temp) {
temperature = temp;
}
void setTemperature(double temp);
/**
* Get the friction coefficient which determines how strongly the system is coupled to
* the heat bath (in inverse ps).
......@@ -92,9 +90,7 @@ public:
*
* @param coeff the friction coefficient, measured in 1/ps
*/
void setFriction(double coeff) {
friction = coeff;
}
void setFriction(double coeff);
/**
* Get the random number seed. See setRandomNumberSeed() for details.
*/
......
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -114,9 +114,7 @@ public:
*
* @param pressure the default pressure acting on the system, measured in bar.
*/
void setDefaultPressure(const Vec3& pressure) {
defaultPressure = pressure;
}
void setDefaultPressure(const Vec3& pressure);
/**
* Get whether to allow the X dimension of the periodic box to change size.
*/
......@@ -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
* 0, the barostat is disabled.
*/
void setFrequency(int freq) {
frequency = freq;
}
void setFrequency(int freq);
/**
* Get the default temperature at which the system is being maintained, measured in Kelvin.
*/
......@@ -161,9 +157,7 @@ public:
*
* @param temp the system temperature, measured in Kelvin.
*/
void setDefaultTemperature(double temp) {
defaultTemperature = temp;
}
void setDefaultTemperature(double temp);
/**
* Get the random number seed. See setRandomNumberSeed() for details.
*/
......
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -88,9 +88,7 @@ public:
*
* @param pressure the default pressure acting on the system, measured in bar.
*/
void setDefaultPressure(double pressure) {
defaultPressure = pressure;
}
void setDefaultPressure(double pressure);
/**
* 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.
......@@ -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
* 0, the barostat is disabled.
*/
void setFrequency(int freq) {
frequency = freq;
}
void setFrequency(int freq);
/**
* Get the default temperature at which the system is being maintained, measured in Kelvin.
*/
......@@ -117,9 +113,7 @@ public:
*
* @param temp the system temperature, measured in Kelvin.
*/
void setDefaultTemperature(double temp) {
defaultTemperature = temp;
}
void setDefaultTemperature(double temp);
/**
* Get the random number seed. See setRandomNumberSeed() for details.
*/
......
......@@ -101,9 +101,7 @@ public:
*
* @param pressure the default pressure acting on the system, measured in bar.
*/
void setDefaultPressure(double pressure) {
defaultPressure = pressure;
}
void setDefaultPressure(double pressure);
/**
* 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.
......@@ -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
* 0, the barostat is disabled.
*/
void setFrequency(int freq) {
frequency = freq;
}
void setFrequency(int freq);
/**
* Get the default temperature at which the system is being maintained, measured in Kelvin.
*/
......@@ -130,9 +126,7 @@ public:
*
* @param temp the system temperature, measured in Kelvin.
*/
void setDefaultTemperature(double temp) {
defaultTemperature = temp;
}
void setDefaultTemperature(double temp);
/**
* Get the random number seed. See setRandomNumberSeed() for details.
*/
......
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -144,9 +144,7 @@ public:
*
* @param pressure the default pressure acting on the system, measured in bar.
*/
void setDefaultPressure(double pressure) {
defaultPressure = pressure;
}
void setDefaultPressure(double pressure);
/**
* Get the default surface tension acting on the system (in bar*nm).
*
......@@ -161,9 +159,7 @@ public:
*
* @param surfaceTension the default surface tension acting on the system, measured in bar.
*/
void setDefaultSurfaceTension(double surfaceTension) {
defaultSurfaceTension = surfaceTension;
}
void setDefaultSurfaceTension(double surfaceTension);
/**
* 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.
......@@ -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
* 0, the barostat is disabled.
*/
void setFrequency(int freq) {
frequency = freq;
}
void setFrequency(int freq);
/**
* Get the default temperature at which the system is being maintained, measured in Kelvin.
*/
......@@ -190,9 +184,7 @@ public:
*
* @param temp the system temperature, measured in Kelvin.
*/
void setDefaultTemperature(double temp) {
defaultTemperature = temp;
}
void setDefaultTemperature(double temp);
/**
* Get the mode specifying the behavior of the X and Y axes.
*/
......
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -79,9 +79,7 @@ public:
*
* @param temp the temperature of the heat bath, measured in Kelvin
*/
void setTemperature(double temp) {
temperature = temp;
}
void setTemperature(double temp);
/**
* Get the friction coefficient which determines how strongly the system is coupled to
* the heat bath (in inverse ps).
......@@ -97,9 +95,7 @@ public:
*
* @param coeff the friction coefficient, measured in 1/ps
*/
void setFriction(double coeff) {
friction = coeff;
}
void setFriction(double coeff);
/**
* Get the error tolerance.
*/
......@@ -109,9 +105,7 @@ public:
/**
* Set the error tolerance.
*/
void setErrorTolerance(double tol) {
errorTol = tol;
}
void setErrorTolerance(double tol);
/**
* 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.
......@@ -123,9 +117,7 @@ public:
* 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.
*/
void setMaximumStepSize(double size) {
maxStepSize = size;
}
void setMaximumStepSize(double size);
/**
* Get the random number seed. See setRandomNumberSeed() for details.
*/
......
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -79,9 +79,7 @@ public:
/**
* Set the error tolerance.
*/
void setErrorTolerance(double tol) {
errorTol = tol;
}
void setErrorTolerance(double tol);
/**
* 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.
......@@ -93,9 +91,7 @@ public:
* 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.
*/
void setMaximumStepSize(double size) {
maxStepSize = size;
}
void setMaximumStepSize(double size);
/**
* Advance a simulation through time by taking a series of time steps.
*
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -32,6 +32,7 @@
#include "openmm/internal/AndersenThermostatImpl.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/Integrator.h"
#include "openmm/OpenMMException.h"
#include "openmm/System.h"
#include "openmm/kernels.h"
#include <vector>
......@@ -43,6 +44,10 @@ AndersenThermostatImpl::AndersenThermostatImpl(const AndersenThermostat& owner)
}
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.getAs<ApplyAndersenThermostatKernel>().initialize(context.getSystem(), owner);
}
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -57,6 +57,18 @@ void BrownianIntegrator::initialize(ContextImpl& contextRef) {
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() {
kernel = Kernel();
}
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -37,6 +37,7 @@
#include "openmm/internal/SplineFitter.h"
#include "openmm/kernels.h"
#include <cmath>
#include <sstream>
using namespace OpenMM;
using namespace std;
......@@ -48,6 +49,25 @@ CMAPTorsionForceImpl::~CMAPTorsionForceImpl() {
}
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.getAs<CalcCMAPTorsionForceKernel>().initialize(context.getSystem(), owner);
}
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -30,11 +30,19 @@
* -------------------------------------------------------------------------- */
#include "openmm/CMMotionRemover.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/CMMotionRemoverImpl.h"
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 {
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -57,25 +57,15 @@ void CustomAngleForceImpl::initialize(ContextImpl& context) {
vector<double> parameters;
int numParameters = owner.getNumPerAngleParameters();
for (int i = 0; i < owner.getNumAngles(); i++) {
int particle1, particle2, particle3;
owner.getAngleParameters(i, particle1, particle2, particle3, parameters);
if (particle1 < 0 || particle1 >= system.getNumParticles()) {
int particle[3];
owner.getAngleParameters(i, particle[0], particle[1], particle[2], parameters);
for (int j = 0; j < 3; j++) {
if (particle[j] < 0 || particle[j] >= system.getNumParticles()) {
stringstream msg;
msg << "CustomAngleForce: Illegal particle index for an angle: ";
msg << particle1;
msg << particle[j];
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) {
stringstream msg;
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -58,19 +58,15 @@ void CustomBondForceImpl::initialize(ContextImpl& context) {
vector<double> parameters;
int numParameters = owner.getNumPerBondParameters();
for (int i = 0; i < owner.getNumBonds(); i++) {
int particle1, particle2;
owner.getBondParameters(i, particle1, particle2, parameters);
if (particle1 < 0 || particle1 >= system.getNumParticles()) {
int particle[2];
owner.getBondParameters(i, particle[0], particle[1], parameters);
for (int j = 0; j < 2; j++) {
if (particle[j] < 0 || particle[j] >= system.getNumParticles()) {
stringstream msg;
msg << "CustomBondForce: Illegal particle index for a bond: ";
msg << particle1;
msg << particle[j];
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) {
stringstream msg;
......
......@@ -58,31 +58,15 @@ void CustomTorsionForceImpl::initialize(ContextImpl& context) {
vector<double> parameters;
int numParameters = owner.getNumPerTorsionParameters();
for (int i = 0; i < owner.getNumTorsions(); i++) {
int particle1, particle2, particle3, particle4;
owner.getTorsionParameters(i, particle1, particle2, particle3, particle4, parameters);
if (particle1 < 0 || particle1 >= system.getNumParticles()) {
int particle[4];
owner.getTorsionParameters(i, particle[0], particle[1], particle[2], particle[3], parameters);
for (int j = 0; j < 4; j++) {
if (particle[j] < 0 || particle[j] >= system.getNumParticles()) {
stringstream msg;
msg << "CustomTorsionForce: Illegal particle index for an torsion: ";
msg << particle1;
msg << "CustomTorsionForce: Illegal particle index for a torsion: ";
msg << particle[j];
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) {
stringstream msg;
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -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])
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);
}
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -73,34 +73,42 @@ void GayBerneForceImpl::initialize(ContextImpl& context) {
msg << yparticle;
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());
for (int i = 0; i < owner.getNumExceptions(); i++) {
int particle1, particle2;
int particle[2];
double sigma, epsilon;
owner.getExceptionParameters(i, particle1, particle2, sigma, epsilon);
if (particle1 < 0 || particle1 >= owner.getNumParticles()) {
owner.getExceptionParameters(i, particle[0], particle[1], sigma, epsilon);
for (int j = 0; j < 2; j++) {
if (particle[j] < 0 || particle[j] >= owner.getNumParticles()) {
stringstream msg;
msg << "GayBerneForce: Illegal particle index for an exception: ";
msg << particle1;
msg << particle[j];
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;
msg << "GayBerneForce: Multiple exceptions are specified for particles ";
msg << particle1;
msg << particle[0];
msg << " and ";
msg << particle2;
msg << particle[1];
throw OpenMMException(msg.str());
}
exceptions[particle1].insert(particle2);
exceptions[particle2].insert(particle1);
if (sigma < 0)
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) {
Vec3 boxVectors[3];
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -29,14 +29,18 @@
* 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/HarmonicAngleForceImpl.h"
#include "openmm/kernels.h"
#include <cmath>
#include <sstream>
using namespace OpenMM;
using std::pair;
using std::vector;
using std::set;
using namespace std;
HarmonicAngleForceImpl::HarmonicAngleForceImpl(const HarmonicAngleForce& owner) : owner(owner) {
}
......@@ -45,6 +49,24 @@ HarmonicAngleForceImpl::~HarmonicAngleForceImpl() {
}
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.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