Unverified Commit 8dd60914 authored by Tristan Croll's avatar Tristan Croll Committed by GitHub
Browse files

Merge pull request #3 from openmm/master

Sync with official repo
parents 3475b790 75c1fcb6
...@@ -6,7 +6,7 @@ from sys import stdout ...@@ -6,7 +6,7 @@ from sys import stdout
prmtop = AmberPrmtopFile('input.prmtop') prmtop = AmberPrmtopFile('input.prmtop')
inpcrd = AmberInpcrdFile('input.inpcrd') inpcrd = AmberInpcrdFile('input.inpcrd')
system = prmtop.createSystem(nonbondedMethod=PME, nonbondedCutoff=1*nanometer, constraints=HBonds) system = prmtop.createSystem(nonbondedMethod=PME, nonbondedCutoff=1*nanometer, constraints=HBonds)
integrator = LangevinIntegrator(300*kelvin, 1/picosecond, 0.002*picoseconds) integrator = BAOABLangevinIntegrator(300*kelvin, 1/picosecond, 0.002*picoseconds)
simulation = Simulation(prmtop.topology, system, integrator) simulation = Simulation(prmtop.topology, system, integrator)
simulation.context.setPositions(inpcrd.positions) simulation.context.setPositions(inpcrd.positions)
if inpcrd.boxVectors is not None: if inpcrd.boxVectors is not None:
......
...@@ -22,7 +22,7 @@ params = CharmmParameterSet('charmm22.rtf', 'charmm22.par') ...@@ -22,7 +22,7 @@ params = CharmmParameterSet('charmm22.rtf', 'charmm22.par')
# Instantiate the system # Instantiate the system
system = psf.createSystem(params, nonbondedMethod=NoCutoff, system = psf.createSystem(params, nonbondedMethod=NoCutoff,
nonbondedCutoff=None) nonbondedCutoff=None)
integrator = LangevinIntegrator(300*kelvin, 1/picosecond, 0.002*picoseconds) integrator = BAOABLangevinIntegrator(300*kelvin, 1/picosecond, 0.002*picoseconds)
simulation = Simulation(psf.topology, system, integrator) simulation = Simulation(psf.topology, system, integrator)
simulation.context.setPositions(pdb.getPositions()) simulation.context.setPositions(pdb.getPositions())
simulation.minimizeEnergy() simulation.minimizeEnergy()
......
...@@ -6,7 +6,7 @@ from sys import stdout ...@@ -6,7 +6,7 @@ from sys import stdout
gro = GromacsGroFile('input.gro') gro = GromacsGroFile('input.gro')
top = GromacsTopFile('input.top', periodicBoxVectors=gro.getPeriodicBoxVectors()) top = GromacsTopFile('input.top', periodicBoxVectors=gro.getPeriodicBoxVectors())
system = top.createSystem(nonbondedMethod=PME, nonbondedCutoff=1*nanometer, constraints=HBonds) system = top.createSystem(nonbondedMethod=PME, nonbondedCutoff=1*nanometer, constraints=HBonds)
integrator = LangevinIntegrator(300*kelvin, 1/picosecond, 0.002*picoseconds) integrator = BAOABLangevinIntegrator(300*kelvin, 1/picosecond, 0.002*picoseconds)
simulation = Simulation(top.topology, system, integrator) simulation = Simulation(top.topology, system, integrator)
simulation.context.setPositions(gro.positions) simulation.context.setPositions(gro.positions)
simulation.minimizeEnergy() simulation.minimizeEnergy()
......
...@@ -6,7 +6,7 @@ from sys import stdout ...@@ -6,7 +6,7 @@ from sys import stdout
pdb = PDBFile('input.pdb') pdb = PDBFile('input.pdb')
forcefield = ForceField('amber14-all.xml', 'amber14/tip3pfb.xml') forcefield = ForceField('amber14-all.xml', 'amber14/tip3pfb.xml')
system = forcefield.createSystem(pdb.topology, nonbondedMethod=PME, nonbondedCutoff=1*nanometer, constraints=HBonds) system = forcefield.createSystem(pdb.topology, nonbondedMethod=PME, nonbondedCutoff=1*nanometer, constraints=HBonds)
integrator = LangevinIntegrator(300*kelvin, 1/picosecond, 0.002*picoseconds) integrator = BAOABLangevinIntegrator(300*kelvin, 1/picosecond, 0.002*picoseconds)
simulation = Simulation(pdb.topology, system, integrator) simulation = Simulation(pdb.topology, system, integrator)
simulation.context.setPositions(pdb.positions) simulation.context.setPositions(pdb.positions)
simulation.minimizeEnergy() simulation.minimizeEnergy()
......
...@@ -213,12 +213,17 @@ public: ...@@ -213,12 +213,17 @@ public:
*/ */
static void loadPluginLibrary(const std::string& file); static void loadPluginLibrary(const std::string& file);
/** /**
* Load multiple dynamic libraries (DLLs) which contain OpenMM plugins from a single directory. * Load multiple dynamic libraries (DLLs) which contain OpenMM plugins from one or more directories.
* This method loops over every file contained in the specified directory and calls loadPluginLibrary() * Multiple fully-qualified paths can be joined together with ':' on unix-like systems
* (or ';' on windows-like systems); each will be searched for plugins, in-order. For example,
* '/foo/plugins:/bar/plugins' will search both `/foo/plugins` and `/bar/plugins`. If an
* identically-named plugin is encountered twice it will be loaded at both points; be careful!!!
*
* This method loops over every file contained in the specified directories and calls loadPluginLibrary()
* for each one. If an error occurs while trying to load a particular file, that file is simply * for each one. If an error occurs while trying to load a particular file, that file is simply
* ignored. You can retrieve a list of all such errors by calling getPluginLoadFailures(). * ignored. You can retrieve a list of all such errors by calling getPluginLoadFailures().
* *
* @param directory the path to the directory containing libraries to load * @param directory a ':' (unix) or ';' (windows) deliminated list of paths containing libraries to load
* @return the names of all files which were successfully loaded as libraries * @return the names of all files which were successfully loaded as libraries
*/ */
static std::vector<std::string> loadPluginsFromDirectory(const std::string& directory); static std::vector<std::string> loadPluginsFromDirectory(const std::string& directory);
......
...@@ -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-2018 Stanford University and the Authors. * * Portions copyright (c) 2008-2019 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "openmm/AndersenThermostat.h" #include "openmm/AndersenThermostat.h"
#include "openmm/BAOABLangevinIntegrator.h"
#include "openmm/BrownianIntegrator.h" #include "openmm/BrownianIntegrator.h"
#include "openmm/CMAPTorsionForce.h" #include "openmm/CMAPTorsionForce.h"
#include "openmm/CMMotionRemover.h" #include "openmm/CMMotionRemover.h"
...@@ -1090,6 +1091,43 @@ public: ...@@ -1090,6 +1091,43 @@ public:
virtual double computeKineticEnergy(ContextImpl& context, const LangevinIntegrator& integrator) = 0; virtual double computeKineticEnergy(ContextImpl& context, const LangevinIntegrator& integrator) = 0;
}; };
/**
* This kernel is invoked by BAOABLangevinIntegrator to take one time step.
*/
class IntegrateBAOABStepKernel : public KernelImpl {
public:
static std::string Name() {
return "IntegrateBAOABStep";
}
IntegrateBAOABStepKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
}
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param integrator the BAOABLangevinIntegrator this kernel will be used for
*/
virtual void initialize(const System& system, const BAOABLangevinIntegrator& integrator) = 0;
/**
* Execute the kernel.
*
* @param context the context in which to execute this kernel
* @param integrator the BAOABLangevinIntegrator this kernel is being used for
* @param forcesAreValid if the context has been modified since the last time step, this will be
* false to show that cached forces are invalid and must be recalculated.
* On exit, this should specify whether the cached forces are valid at the
* end of the step.
*/
virtual void execute(ContextImpl& context, const BAOABLangevinIntegrator& integrator, bool& forcesAreValid) = 0;
/**
* Compute the kinetic energy.
*
* @param context the context in which to execute this kernel
* @param integrator the BAOABLangevinIntegrator this kernel is being used for
*/
virtual double computeKineticEnergy(ContextImpl& context, const BAOABLangevinIntegrator& integrator) = 0;
};
/** /**
* This kernel is invoked by BrownianIntegrator to take one time step. * This kernel is invoked by BrownianIntegrator to take one time step.
*/ */
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "openmm/internal/ContextImpl.h" #include "openmm/internal/ContextImpl.h"
#ifdef WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
#include <sstream>
#else #else
#ifndef __PNACL__ #ifndef __PNACL__
#include <dlfcn.h> #include <dlfcn.h>
...@@ -45,6 +44,7 @@ ...@@ -45,6 +44,7 @@
#include <dirent.h> #include <dirent.h>
#include <cstdlib> #include <cstdlib>
#endif #endif
#include <sstream>
#include <set> #include <set>
#include <algorithm> #include <algorithm>
...@@ -261,31 +261,42 @@ void Platform::loadPluginLibrary(const string& file) { ...@@ -261,31 +261,42 @@ void Platform::loadPluginLibrary(const string& file) {
vector<string> Platform::loadPluginsFromDirectory(const string& directory) { vector<string> Platform::loadPluginsFromDirectory(const string& directory) {
vector<string> files; vector<string> files;
char dirSeparator; char dirSeparator;
char pathSeparator;
stringstream sdirectory(directory);
#ifdef WIN32 #ifdef WIN32
dirSeparator = '\\'; dirSeparator = '\\';
pathSeparator = ';';
WIN32_FIND_DATA fileInfo; WIN32_FIND_DATA fileInfo;
string filePattern(directory + dirSeparator + "*.dll");
for (string path; std::getline(sdirectory, path, pathSeparator);) {
string filePattern(path + dirSeparator + "*.dll");
HANDLE findHandle = FindFirstFile(filePattern.c_str(), &fileInfo); HANDLE findHandle = FindFirstFile(filePattern.c_str(), &fileInfo);
if (findHandle != INVALID_HANDLE_VALUE) { if (findHandle != INVALID_HANDLE_VALUE) {
do { do {
if (fileInfo.cFileName[0] != '.') if (fileInfo.cFileName[0] != '.')
files.push_back(string(fileInfo.cFileName)); files.push_back(path+dirSeparator+string(fileInfo.cFileName));
} while (FindNextFile(findHandle, &fileInfo)); } while (FindNextFile(findHandle, &fileInfo));
FindClose(findHandle); FindClose(findHandle);
} }
}
vector<HMODULE> plugins; vector<HMODULE> plugins;
#else #else
dirSeparator = '/';
DIR* dir; DIR* dir;
dirSeparator = '/';
pathSeparator = ':';
struct dirent *entry; struct dirent *entry;
dir = opendir(directory.c_str());
for (string path; std::getline(sdirectory, path, pathSeparator);) {
dir = opendir(path.c_str());
if (dir != NULL) { if (dir != NULL) {
while ((entry = readdir(dir)) != NULL) { while ((entry = readdir(dir)) != NULL) {
if (entry->d_name[0] != '.') if (entry->d_name[0] != '.')
files.push_back(string(entry->d_name)); files.push_back(path+dirSeparator+string(entry->d_name));
} }
closedir(dir); closedir(dir);
} }
}
vector<void*> plugins; vector<void*> plugins;
#endif #endif
vector<string> loadedLibraries; vector<string> loadedLibraries;
...@@ -294,7 +305,7 @@ vector<string> Platform::loadPluginsFromDirectory(const string& directory) { ...@@ -294,7 +305,7 @@ vector<string> Platform::loadPluginsFromDirectory(const string& directory) {
for (unsigned int i = 0; i < files.size(); ++i) { for (unsigned int i = 0; i < files.size(); ++i) {
try { try {
plugins.push_back(loadOneLibrary(directory+dirSeparator+files[i])); plugins.push_back(loadOneLibrary(files[i]));
loadedLibraries.push_back(files[i]); loadedLibraries.push_back(files[i]);
} catch (OpenMMException& ex) { } catch (OpenMMException& ex) {
pluginLoadFailures.push_back(ex.what()); pluginLoadFailures.push_back(ex.what());
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "openmm/AndersenThermostat.h" #include "openmm/AndersenThermostat.h"
#include "openmm/BAOABLangevinIntegrator.h"
#include "openmm/BrownianIntegrator.h" #include "openmm/BrownianIntegrator.h"
#include "openmm/CMAPTorsionForce.h" #include "openmm/CMAPTorsionForce.h"
#include "openmm/CMMotionRemover.h" #include "openmm/CMMotionRemover.h"
......
#ifndef OPENMM_BAOABLANGEVININTEGRATOR_H_
#define OPENMM_BAOABLANGEVININTEGRATOR_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* 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. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "Integrator.h"
#include "openmm/Kernel.h"
#include "internal/windowsExport.h"
namespace OpenMM {
/**
* This is an Integrator which simulates a System using Langevin dynamics, with
* the BAOAB discretization of Leimkuhler and Matthews (http://dx.doi.org/10.1093/amrx/abs010).
* This method tend to produce more accurate configurational sampling than other
* discretizations, such as the one used in LangevinIntegrator.
*/
class OPENMM_EXPORT BAOABLangevinIntegrator : public Integrator {
public:
/**
* Create a BAOABLangevinIntegrator.
*
* @param temperature the temperature of the heat bath (in Kelvin)
* @param frictionCoeff the friction coefficient which couples the system to the heat bath (in inverse picoseconds)
* @param stepSize the step size with which to integrate the system (in picoseconds)
*/
BAOABLangevinIntegrator(double temperature, double frictionCoeff, double stepSize);
/**
* Get the temperature of the heat bath (in Kelvin).
*
* @return the temperature of the heat bath, measured in Kelvin
*/
double getTemperature() const {
return temperature;
}
/**
* Set the temperature of the heat bath (in Kelvin).
*
* @param temp the temperature of the heat bath, measured in Kelvin
*/
void setTemperature(double temp) {
temperature = temp;
}
/**
* Get the friction coefficient which determines how strongly the system is coupled to
* the heat bath (in inverse ps).
*
* @return the friction coefficient, measured in 1/ps
*/
double getFriction() const {
return friction;
}
/**
* Set the friction coefficient which determines how strongly the system is coupled to
* the heat bath (in inverse ps).
*
* @param coeff the friction coefficient, measured in 1/ps
*/
void setFriction(double coeff) {
friction = coeff;
}
/**
* Get the random number seed. See setRandomNumberSeed() for details.
*/
int getRandomNumberSeed() const {
return randomNumberSeed;
}
/**
* Set the random number seed. The precise meaning of this parameter is undefined, and is left up
* to each Platform to interpret in an appropriate way. It is guaranteed that if two simulations
* are run with different random number seeds, the sequence of random forces will be different. On
* the other hand, no guarantees are made about the behavior of simulations that use the same seed.
* In particular, Platforms are permitted to use non-deterministic algorithms which produce different
* results on successive runs, even if those runs were initialized identically.
*
* If seed is set to 0 (which is the default value assigned), a unique seed is chosen when a Context
* is created from this Integrator. This is done to ensure that each Context receives unique random seeds
* without you needing to set them explicitly.
*/
void setRandomNumberSeed(int seed) {
randomNumberSeed = seed;
}
/**
* Advance a simulation through time by taking a series of time steps.
*
* @param steps the number of time steps to take
*/
void step(int steps);
protected:
/**
* This will be called by the Context when it is created. It informs the Integrator
* of what context it will be integrating, and gives it a chance to do any necessary initialization.
* It will also get called again if the application calls reinitialize() on the Context.
*/
void initialize(ContextImpl& context);
/**
* This will be called by the Context when it is destroyed to let the Integrator do any necessary
* cleanup. It will also get called again if the application calls reinitialize() on the Context.
*/
void cleanup();
/**
* When the user modifies the state, we need to mark that the forces need to be recalculated.
*/
void stateChanged(State::DataType changed);
/**
* Get the names of all Kernels used by this Integrator.
*/
std::vector<std::string> getKernelNames();
/**
* Compute the kinetic energy of the system at the current time.
*/
double computeKineticEnergy();
/**
* Computing kinetic energy for this integrator does not require forces.
*/
bool kineticEnergyRequiresForce() const;
private:
double temperature, friction;
int randomNumberSeed;
bool forcesAreValid;
Kernel kernel;
};
} // namespace OpenMM
#endif /*OPENMM_BAOABLANGEVININTEGRATOR_H_*/
...@@ -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-2012 Stanford University and the Authors. * * Portions copyright (c) 2008-2019 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -133,6 +133,10 @@ protected: ...@@ -133,6 +133,10 @@ protected:
* Compute the kinetic energy of the system at the current time. * Compute the kinetic energy of the system at the current time.
*/ */
double computeKineticEnergy(); double computeKineticEnergy();
/**
* Computing kinetic energy for this integrator does not require forces.
*/
bool kineticEnergyRequiresForce() const;
private: private:
double temperature, friction; double temperature, friction;
int randomNumberSeed; int randomNumberSeed;
......
...@@ -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) 2011-2018 Stanford University and the Authors. * * Portions copyright (c) 2011-2019 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -627,6 +627,10 @@ protected: ...@@ -627,6 +627,10 @@ protected:
* Compute the kinetic energy of the system at the current time. * Compute the kinetic energy of the system at the current time.
*/ */
double computeKineticEnergy(); double computeKineticEnergy();
/**
* Get whether computeKineticEnergy() expects forces to have been computed.
*/
bool kineticEnergyRequiresForce() const;
private: private:
class ComputationInfo; class ComputationInfo;
class FunctionInfo; class FunctionInfo;
...@@ -639,7 +643,7 @@ private: ...@@ -639,7 +643,7 @@ private:
std::string kineticEnergy; std::string kineticEnergy;
mutable bool globalsAreCurrent; mutable bool globalsAreCurrent;
int randomNumberSeed; int randomNumberSeed;
bool forcesAreValid; bool forcesAreValid, keNeedsForce;
Kernel kernel; Kernel kernel;
}; };
......
...@@ -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-2015 Stanford University and the Authors. * * Portions copyright (c) 2008-2019 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -120,8 +120,19 @@ protected: ...@@ -120,8 +120,19 @@ protected:
* Compute the kinetic energy of the system at the current time. This may be different from simply * Compute the kinetic energy of the system at the current time. This may be different from simply
* mv<sup>2</sup>/2. For example, a leapfrog integrator will store velocities offset by half a step, * mv<sup>2</sup>/2. For example, a leapfrog integrator will store velocities offset by half a step,
* but the kinetic energy should be computed at the current time, not delayed by half a step. * but the kinetic energy should be computed at the current time, not delayed by half a step.
*
* If kineticEnergyRequiresForce() returns true, this method can assume that valid forces
* have already been computed.
*/ */
virtual double computeKineticEnergy() = 0; virtual double computeKineticEnergy() = 0;
/**
* Get whether computeKineticEnergy() expects forces to have been computed. The default
* implementation returns true to be safe. Non-leapfrog integrators can override this to
* return false, which makes calling getState() to query the energy less expensive.
*/
virtual bool kineticEnergyRequiresForce() const {
return true;
}
private: private:
double stepSize, constraintTol; double stepSize, constraintTol;
}; };
......
...@@ -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-2012 Stanford University and the Authors. * * Portions copyright (c) 2008-2019 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
namespace OpenMM { namespace OpenMM {
/** /**
* This is an error contolled, variable time step Integrator that simulates a System using Langevin * This is an error controlled, variable time step Integrator that simulates a System using Langevin
* dynamics. It compares the result of the Langevin integrator to that of an * dynamics. It compares the result of the Langevin integrator to that of an
* explicit Euler integrator, takes the difference between the two as a measure of the integration * explicit Euler integrator, takes the difference between the two as a measure of the integration
* error in each time step, and continuously adjusts the step size to keep the error below a * error in each time step, and continuously adjusts the step size to keep the error below a
...@@ -50,6 +50,10 @@ namespace OpenMM { ...@@ -50,6 +50,10 @@ namespace OpenMM {
* adjustable parameter that affects the step size and integration accuracy. You * adjustable parameter that affects the step size and integration accuracy. You
* should try different values to find the largest one that produces a trajectory sufficiently * should try different values to find the largest one that produces a trajectory sufficiently
* accurate for your purposes. 0.001 is often a good starting point. * accurate for your purposes. 0.001 is often a good starting point.
*
* You can optionally set a maximum step size it will ever use. This is useful to prevent it
* from taking excessively large steps in usual situations, such as when the system is right at
* a local energy minimum.
*/ */
class OPENMM_EXPORT VariableLangevinIntegrator : public Integrator { class OPENMM_EXPORT VariableLangevinIntegrator : public Integrator {
...@@ -108,6 +112,20 @@ public: ...@@ -108,6 +112,20 @@ public:
void setErrorTolerance(double tol) { void setErrorTolerance(double tol) {
errorTol = tol; errorTol = 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.
*/
double getMaximumStepSize() const {
return maxStepSize;
}
/**
* 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;
}
/** /**
* Get the random number seed. See setRandomNumberSeed() for details. * Get the random number seed. See setRandomNumberSeed() for details.
*/ */
...@@ -165,7 +183,7 @@ protected: ...@@ -165,7 +183,7 @@ protected:
*/ */
double computeKineticEnergy(); double computeKineticEnergy();
private: private:
double temperature, friction, errorTol; double temperature, friction, errorTol, maxStepSize;
int randomNumberSeed; int randomNumberSeed;
Kernel kernel; Kernel kernel;
}; };
......
...@@ -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-2012 Stanford University and the Authors. * * Portions copyright (c) 2008-2019 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
namespace OpenMM { namespace OpenMM {
/** /**
* This is an error contolled, variable time step Integrator that simulates a System using the * This is an error controlled, variable time step Integrator that simulates a System using the
* leap-frog Verlet algorithm. It compares the result of the Verlet integrator to that of an * leap-frog Verlet algorithm. It compares the result of the Verlet integrator to that of an
* explicit Euler integrator, takes the difference between the two as a measure of the integration * explicit Euler integrator, takes the difference between the two as a measure of the integration
* error in each time step, and continuously adjusts the step size to keep the error below a * error in each time step, and continuously adjusts the step size to keep the error below a
...@@ -56,6 +56,10 @@ namespace OpenMM { ...@@ -56,6 +56,10 @@ namespace OpenMM {
* This makes it most appropriate for constant temperate simulations. In constant energy simulations * This makes it most appropriate for constant temperate simulations. In constant energy simulations
* where precise energy conservation over long time periods is important, a fixed step size Verlet * where precise energy conservation over long time periods is important, a fixed step size Verlet
* integrator may be more appropriate. * integrator may be more appropriate.
*
* You can optionally set a maximum step size it will ever use. This is useful to prevent it
* from taking excessively large steps in usual situations, such as when the system is right at
* a local energy minimum.
*/ */
class OPENMM_EXPORT VariableVerletIntegrator : public Integrator { class OPENMM_EXPORT VariableVerletIntegrator : public Integrator {
...@@ -78,6 +82,20 @@ public: ...@@ -78,6 +82,20 @@ public:
void setErrorTolerance(double tol) { void setErrorTolerance(double tol) {
errorTol = tol; errorTol = 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.
*/
double getMaximumStepSize() const {
return maxStepSize;
}
/**
* 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;
}
/** /**
* Advance a simulation through time by taking a series of time steps. * Advance a simulation through time by taking a series of time steps.
* *
...@@ -114,7 +132,7 @@ protected: ...@@ -114,7 +132,7 @@ protected:
*/ */
double computeKineticEnergy(); double computeKineticEnergy();
private: private:
double errorTol; double errorTol, maxStepSize;
Kernel kernel; Kernel kernel;
}; };
......
...@@ -112,7 +112,7 @@ public: ...@@ -112,7 +112,7 @@ public:
* @param particle3 the index of the third particle * @param particle3 the index of the third particle
* @param weight1 the weight factor (between 0 and 1) for the first particle * @param weight1 the weight factor (between 0 and 1) for the first particle
* @param weight2 the weight factor (between 0 and 1) for the second particle * @param weight2 the weight factor (between 0 and 1) for the second particle
* @param weight2 the weight factor (between 0 and 1) for the third particle * @param weight3 the weight factor (between 0 and 1) for the third particle
*/ */
ThreeParticleAverageSite(int particle1, int particle2, int particle3, double weight1, double weight2, double weight3); ThreeParticleAverageSite(int particle1, int particle2, int particle3, double weight1, double weight2, double weight3);
/** /**
......
...@@ -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 Stanford University and the Authors. * * Portions copyright (c) 2010-2019 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include "ForceImpl.h" #include "ForceImpl.h"
#include "openmm/MonteCarloAnisotropicBarostat.h" #include "openmm/MonteCarloAnisotropicBarostat.h"
#include "openmm/Kernel.h" #include "openmm/Kernel.h"
#include "sfmt/SFMT.h"
#include <string> #include <string>
namespace OpenMM { namespace OpenMM {
...@@ -62,7 +61,6 @@ private: ...@@ -62,7 +61,6 @@ private:
const MonteCarloAnisotropicBarostat& owner; const MonteCarloAnisotropicBarostat& owner;
int step, numAttempted[3], numAccepted[3]; int step, numAttempted[3], numAccepted[3];
double volumeScale[3]; double volumeScale[3];
OpenMM_SFMT::SFMT random;
Kernel kernel; Kernel kernel;
}; };
......
...@@ -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 Stanford University and the Authors. * * Portions copyright (c) 2010-2019 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include "ForceImpl.h" #include "ForceImpl.h"
#include "openmm/MonteCarloBarostat.h" #include "openmm/MonteCarloBarostat.h"
#include "openmm/Kernel.h" #include "openmm/Kernel.h"
#include "sfmt/SFMT.h"
#include <string> #include <string>
namespace OpenMM { namespace OpenMM {
...@@ -62,7 +61,6 @@ private: ...@@ -62,7 +61,6 @@ private:
const MonteCarloBarostat& owner; const MonteCarloBarostat& owner;
int step, numAttempted, numAccepted; int step, numAttempted, numAccepted;
double volumeScale; double volumeScale;
OpenMM_SFMT::SFMT random;
Kernel kernel; Kernel kernel;
}; };
......
...@@ -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-2014 Stanford University and the Authors. * * Portions copyright (c) 2010-2019 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include "ForceImpl.h" #include "ForceImpl.h"
#include "openmm/MonteCarloMembraneBarostat.h" #include "openmm/MonteCarloMembraneBarostat.h"
#include "openmm/Kernel.h" #include "openmm/Kernel.h"
#include "sfmt/SFMT.h"
#include <string> #include <string>
namespace OpenMM { namespace OpenMM {
...@@ -62,7 +61,6 @@ private: ...@@ -62,7 +61,6 @@ private:
const MonteCarloMembraneBarostat& owner; const MonteCarloMembraneBarostat& owner;
int step, numAttempted[3], numAccepted[3]; int step, numAttempted[3], numAccepted[3];
double volumeScale[3]; double volumeScale[3];
OpenMM_SFMT::SFMT random;
Kernel kernel; Kernel kernel;
}; };
......
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* 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. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/BAOABLangevinIntegrator.h"
#include "openmm/Context.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/kernels.h"
#include <string>
using namespace OpenMM;
using std::string;
using std::vector;
BAOABLangevinIntegrator::BAOABLangevinIntegrator(double temperature, double frictionCoeff, double stepSize) {
setTemperature(temperature);
setFriction(frictionCoeff);
setStepSize(stepSize);
setConstraintTolerance(1e-5);
setRandomNumberSeed(0);
forcesAreValid = false;
}
void BAOABLangevinIntegrator::initialize(ContextImpl& contextRef) {
if (owner != NULL && &contextRef.getOwner() != owner)
throw OpenMMException("This Integrator is already bound to a context");
context = &contextRef;
owner = &contextRef.getOwner();
kernel = context->getPlatform().createKernel(IntegrateBAOABStepKernel::Name(), contextRef);
kernel.getAs<IntegrateBAOABStepKernel>().initialize(contextRef.getSystem(), *this);
}
void BAOABLangevinIntegrator::cleanup() {
kernel = Kernel();
}
void BAOABLangevinIntegrator::stateChanged(State::DataType changed) {
forcesAreValid = false;
}
vector<string> BAOABLangevinIntegrator::getKernelNames() {
std::vector<std::string> names;
names.push_back(IntegrateBAOABStepKernel::Name());
return names;
}
double BAOABLangevinIntegrator::computeKineticEnergy() {
return kernel.getAs<IntegrateBAOABStepKernel>().computeKineticEnergy(*context, *this);
}
bool BAOABLangevinIntegrator::kineticEnergyRequiresForce() const {
return false;
}
void BAOABLangevinIntegrator::step(int steps) {
if (context == NULL)
throw OpenMMException("This Integrator is not bound to a context!");
for (int i = 0; i < steps; ++i) {
context->updateContextState();
kernel.getAs<IntegrateBAOABStepKernel>().execute(*context, *this, forcesAreValid);
}
}
...@@ -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-2019 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -71,6 +71,10 @@ double BrownianIntegrator::computeKineticEnergy() { ...@@ -71,6 +71,10 @@ double BrownianIntegrator::computeKineticEnergy() {
return kernel.getAs<IntegrateBrownianStepKernel>().computeKineticEnergy(*context, *this); return kernel.getAs<IntegrateBrownianStepKernel>().computeKineticEnergy(*context, *this);
} }
bool BrownianIntegrator::kineticEnergyRequiresForce() const {
return false;
}
void BrownianIntegrator::step(int steps) { void BrownianIntegrator::step(int steps) {
if (context == NULL) if (context == NULL)
throw OpenMMException("This Integrator is not bound to a context!"); throw OpenMMException("This Integrator is not bound to a context!");
......
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