Commit f18fa49c authored by Peter Eastman's avatar Peter Eastman
Browse files

Fixed failing test cases. Increased default minimizer tolerance to 10.

parent 73be43c5
...@@ -1222,9 +1222,9 @@ specify if you want further control over the minimization. First, you can ...@@ -1222,9 +1222,9 @@ specify if you want further control over the minimization. First, you can
specify a tolerance for when the energy should be considered to have converged: specify a tolerance for when the energy should be considered to have converged:
:: ::
simulation.minimizeEnergy(tolerance=10*kilojoule/mole) simulation.minimizeEnergy(tolerance=5*kilojoule/mole)
If you do not specify this parameter, a default tolerance of 1 kJ/mole is used. If you do not specify this parameter, a default tolerance of 10 kJ/mole is used.
Second, you can specify a maximum number of iterations: Second, you can specify a maximum number of iterations:
:: ::
......
...@@ -54,12 +54,12 @@ public: ...@@ -54,12 +54,12 @@ public:
* @param context a Context specifying the System to minimize and the initial particle positions * @param context a Context specifying the System to minimize and the initial particle positions
* @param tolerance this specifies how precisely the energy minimum must be located. Minimization * @param tolerance this specifies how precisely the energy minimum must be located. Minimization
* will be halted once the root-mean-square value of all force components reaches * will be halted once the root-mean-square value of all force components reaches
* this tolerance. The default value is 1. * this tolerance. The default value is 10.
* @param maxIterations the maximum number of iterations to perform. If this is 0, minimation is continued * @param maxIterations the maximum number of iterations to perform. If this is 0, minimation is continued
* until the results converge without regard to how many iterations it takes. The * until the results converge without regard to how many iterations it takes. The
* default value is 0. * default value is 0.
*/ */
static void minimize(Context& context, double tolerance = 1, int maxIterations = 0); static void minimize(Context& context, double tolerance = 10, int maxIterations = 0);
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,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-2014 Stanford University and the Authors. * * Portions copyright (c) 2010-2015 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -81,7 +81,7 @@ void testLargeSystem() { ...@@ -81,7 +81,7 @@ void testLargeSystem() {
const int numParticles = numMolecules*2; const int numParticles = numMolecules*2;
const double cutoff = 2.0; const double cutoff = 2.0;
const double boxSize = 4.0; const double boxSize = 4.0;
const double tolerance = 5; const double tolerance = 10;
System system; System system;
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize)); system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
NonbondedForce* nonbonded = new NonbondedForce(); NonbondedForce* nonbonded = new NonbondedForce();
...@@ -114,7 +114,7 @@ void testLargeSystem() { ...@@ -114,7 +114,7 @@ void testLargeSystem() {
State finalState = context.getState(State::Forces | State::Energy | State::Positions); State finalState = context.getState(State::Forces | State::Energy | State::Positions);
ASSERT(finalState.getPotentialEnergy() < initialState.getPotentialEnergy()); ASSERT(finalState.getPotentialEnergy() < initialState.getPotentialEnergy());
// Compute the force magnitude, substracting off any component parallel to a constraint, and // Compute the force magnitude, subtracting off any component parallel to a constraint, and
// check that it satisfies the requested tolerance. // check that it satisfies the requested tolerance.
double forceNorm = 0.0; double forceNorm = 0.0;
...@@ -129,8 +129,8 @@ void testLargeSystem() { ...@@ -129,8 +129,8 @@ void testLargeSystem() {
f -= dir*dir.dot(f); f -= dir*dir.dot(f);
forceNorm += f.dot(f); forceNorm += f.dot(f);
} }
forceNorm = sqrt(forceNorm/(4*numMolecules)); forceNorm = sqrt(forceNorm/(5*numMolecules));
ASSERT(forceNorm < 3*tolerance); ASSERT(forceNorm < 2*tolerance);
} }
void testVirtualSites() { void testVirtualSites() {
...@@ -138,7 +138,7 @@ void testVirtualSites() { ...@@ -138,7 +138,7 @@ void testVirtualSites() {
const int numParticles = numMolecules*3; const int numParticles = numMolecules*3;
const double cutoff = 2.0; const double cutoff = 2.0;
const double boxSize = 4.0; const double boxSize = 4.0;
const double tolerance = 5; const double tolerance = 10;
System system; System system;
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize)); system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
NonbondedForce* nonbonded = new NonbondedForce(); NonbondedForce* nonbonded = new NonbondedForce();
...@@ -195,8 +195,8 @@ void testVirtualSites() { ...@@ -195,8 +195,8 @@ void testVirtualSites() {
ASSERT_EQUAL_VEC((finalState.getPositions()[i+1]+finalState.getPositions()[i])*0.5, finalState.getPositions()[i+2], 1e-5); ASSERT_EQUAL_VEC((finalState.getPositions()[i+1]+finalState.getPositions()[i])*0.5, finalState.getPositions()[i+2], 1e-5);
} }
forceNorm = sqrt(forceNorm/(4*numMolecules)); forceNorm = sqrt(forceNorm/(5*numMolecules));
ASSERT(forceNorm < 3*tolerance); ASSERT(forceNorm < 2*tolerance);
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,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-2014 Stanford University and the Authors. * * Portions copyright (c) 2010-2015 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -81,7 +81,7 @@ void testLargeSystem() { ...@@ -81,7 +81,7 @@ void testLargeSystem() {
const int numParticles = numMolecules*2; const int numParticles = numMolecules*2;
const double cutoff = 2.0; const double cutoff = 2.0;
const double boxSize = 4.0; const double boxSize = 4.0;
const double tolerance = 5; const double tolerance = 10;
System system; System system;
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize)); system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
NonbondedForce* nonbonded = new NonbondedForce(); NonbondedForce* nonbonded = new NonbondedForce();
...@@ -114,7 +114,7 @@ void testLargeSystem() { ...@@ -114,7 +114,7 @@ void testLargeSystem() {
State finalState = context.getState(State::Forces | State::Energy | State::Positions); State finalState = context.getState(State::Forces | State::Energy | State::Positions);
ASSERT(finalState.getPotentialEnergy() < initialState.getPotentialEnergy()); ASSERT(finalState.getPotentialEnergy() < initialState.getPotentialEnergy());
// Compute the force magnitude, substracting off any component parallel to a constraint, and // Compute the force magnitude, subtracting off any component parallel to a constraint, and
// check that it satisfies the requested tolerance. // check that it satisfies the requested tolerance.
double forceNorm = 0.0; double forceNorm = 0.0;
...@@ -129,8 +129,8 @@ void testLargeSystem() { ...@@ -129,8 +129,8 @@ void testLargeSystem() {
f -= dir*dir.dot(f); f -= dir*dir.dot(f);
forceNorm += f.dot(f); forceNorm += f.dot(f);
} }
forceNorm = sqrt(forceNorm/(4*numMolecules)); forceNorm = sqrt(forceNorm/(5*numMolecules));
ASSERT(forceNorm < 3*tolerance); ASSERT(forceNorm < 2*tolerance);
} }
void testVirtualSites() { void testVirtualSites() {
...@@ -138,7 +138,7 @@ void testVirtualSites() { ...@@ -138,7 +138,7 @@ void testVirtualSites() {
const int numParticles = numMolecules*3; const int numParticles = numMolecules*3;
const double cutoff = 2.0; const double cutoff = 2.0;
const double boxSize = 4.0; const double boxSize = 4.0;
const double tolerance = 5; const double tolerance = 10;
System system; System system;
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize)); system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
NonbondedForce* nonbonded = new NonbondedForce(); NonbondedForce* nonbonded = new NonbondedForce();
...@@ -195,8 +195,8 @@ void testVirtualSites() { ...@@ -195,8 +195,8 @@ void testVirtualSites() {
ASSERT_EQUAL_VEC((finalState.getPositions()[i+1]+finalState.getPositions()[i])*0.5, finalState.getPositions()[i+2], 1e-5); ASSERT_EQUAL_VEC((finalState.getPositions()[i+1]+finalState.getPositions()[i])*0.5, finalState.getPositions()[i+2], 1e-5);
} }
forceNorm = sqrt(forceNorm/(4*numMolecules)); forceNorm = sqrt(forceNorm/(5*numMolecules));
ASSERT(forceNorm < 3*tolerance); ASSERT(forceNorm < 2*tolerance);
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,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-2014 Stanford University and the Authors. * * Portions copyright (c) 2010-2015 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -129,8 +129,8 @@ void testLargeSystem() { ...@@ -129,8 +129,8 @@ void testLargeSystem() {
f -= dir*dir.dot(f); f -= dir*dir.dot(f);
forceNorm += f.dot(f); forceNorm += f.dot(f);
} }
forceNorm = sqrt(forceNorm/(4*numMolecules)); forceNorm = sqrt(forceNorm/(5*numMolecules));
ASSERT(forceNorm < 3*tolerance); ASSERT(forceNorm < 2*tolerance);
} }
void testVirtualSites() { void testVirtualSites() {
...@@ -195,8 +195,8 @@ void testVirtualSites() { ...@@ -195,8 +195,8 @@ void testVirtualSites() {
ASSERT_EQUAL_VEC((finalState.getPositions()[i+1]+finalState.getPositions()[i])*0.5, finalState.getPositions()[i+2], 1e-5); ASSERT_EQUAL_VEC((finalState.getPositions()[i+1]+finalState.getPositions()[i])*0.5, finalState.getPositions()[i+2], 1e-5);
} }
forceNorm = sqrt(forceNorm/(4*numMolecules)); forceNorm = sqrt(forceNorm/(5*numMolecules));
ASSERT(forceNorm < 3*tolerance); ASSERT(forceNorm < 2*tolerance);
} }
int main() { int main() {
......
...@@ -78,11 +78,11 @@ class Simulation(object): ...@@ -78,11 +78,11 @@ class Simulation(object):
else: else:
self.context = mm.Context(system, integrator, platform, platformProperties) self.context = mm.Context(system, integrator, platform, platformProperties)
def minimizeEnergy(self, tolerance=1*unit.kilojoule/unit.mole, maxIterations=0): def minimizeEnergy(self, tolerance=10*unit.kilojoule/unit.mole, maxIterations=0):
"""Perform a local energy minimization on the system. """Perform a local energy minimization on the system.
Parameters: Parameters:
- tolerance (energy=1*kilojoule/mole) The energy tolerance to which the system should be minimized - tolerance (energy=10*kilojoules/mole) The energy tolerance to which the system should be minimized
- maxIterations (int=0) The maximum number of iterations to perform. If this is 0, minimization is continued - maxIterations (int=0) The maximum number of iterations to perform. If this is 0, minimization is continued
until the results converge without regard to how many iterations it takes. until the results converge without regard to how many iterations it takes.
""" """
......
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