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
......@@ -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-2015 Stanford University and the Authors. *
* Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -74,6 +74,24 @@ void DrudeLangevinIntegrator::initialize(ContextImpl& contextRef) {
kernel.getAs<IntegrateDrudeLangevinStepKernel>().initialize(contextRef.getSystem(), *this, *force);
}
void DrudeLangevinIntegrator::setTemperature(double temp) {
if (temp < 0)
throw OpenMMException("Temperature cannot be negative");
temperature = temp;
}
void DrudeLangevinIntegrator::setFriction(double coeff) {
if (coeff < 0)
throw OpenMMException("Friction cannot be negative");
friction = coeff;
}
void DrudeLangevinIntegrator::setDrudeFriction(double coeff) {
if (coeff < 0)
throw OpenMMException("Friction cannot be negative");
drudeFriction = coeff;
}
void DrudeLangevinIntegrator::cleanup() {
kernel = Kernel();
}
......
......@@ -70,6 +70,12 @@ void DrudeSCFIntegrator::initialize(ContextImpl& contextRef) {
kernel.getAs<IntegrateDrudeSCFStepKernel>().initialize(contextRef.getSystem(), *this, *force);
}
void DrudeSCFIntegrator::setMinimizationErrorTolerance(double tol) {
if (tol <= 0)
throw OpenMMException("Minimization error tolerance must be positive");
tolerance = tol;
}
void DrudeSCFIntegrator::cleanup() {
kernel = Kernel();
}
......
......@@ -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-2015 Stanford University and the Authors. *
* Portions copyright (c) 2010-2021 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -76,9 +76,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.
......@@ -90,9 +88,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 random number seed. See setRandomNumberSeed() for details.
*/
......
......@@ -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: *
* *
......@@ -34,11 +34,24 @@
using namespace OpenMM;
RPMDMonteCarloBarostat::RPMDMonteCarloBarostat(double defaultPressure, int frequency) :
defaultPressure(defaultPressure), frequency(frequency) {
RPMDMonteCarloBarostat::RPMDMonteCarloBarostat(double defaultPressure, int frequency) {
setDefaultPressure(defaultPressure);
setFrequency(frequency);
setRandomNumberSeed(0);
}
void RPMDMonteCarloBarostat::setDefaultPressure(double pressure) {
if (pressure < 0)
throw OpenMMException("Pressure cannot be negative");
defaultPressure = pressure;
}
void RPMDMonteCarloBarostat::setFrequency(int freq) {
if (freq <= 0)
throw OpenMMException("Frequency must be positive");
frequency = freq;
}
ForceImpl* RPMDMonteCarloBarostat::createImpl() const {
return new RPMDMonteCarloBarostatImpl(*this);
}
......@@ -351,7 +351,7 @@ int makeDimerBox(System& system, std::vector<Vec3>& positions, bool constrain=tr
int particle2 = system.addParticle(mass);
forceField->addParticle(0.0, 0.1, 1.0);
forceField->addParticle(0.0, 0.1, 1.0);
forceField->addException(particle1, particle2, 0, 0, 0);
forceField->addException(particle1, particle2, 0, 1, 0);
bondForce->addBond(particle1, particle2, bondLength, bondForceConstant);
numDOF += 6;
if (constrain) {
......
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