Commit 6ddebdb2 authored by Peter Eastman's avatar Peter Eastman
Browse files

Reorganization of the OpenMM source code

parent 0e879806
#ifndef OPENMM_ANDERSENTHERMOSTAT_H_
#define OPENMM_ANDERSENTHERMOSTAT_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 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 "Force.h"
#include <string>
namespace OpenMM {
/**
* This class uses the Andersen method to maintain constant temperature.
*/
class AndersenThermostat : public Force {
public:
/**
* This is the name of the parameter which stores the current temperature of the
* heat bath (in Kelvin).
*/
static const std::string Temperature;
/**
* This is the name of the parameter which store the current collision frequency (in 1/ps).
*/
static const std::string CollisionFrequency;
/**
* Create an AndersenThermostat.
*
* @param defaultTemperature the default temperature of the heat bath (in Kelvin)
* @param defaultCollisionFrequency the default collision frequency (in 1/ps)
*/
AndersenThermostat(double defaultTemperature, double defaultCollisionFrequency);
/**
* Get the default temperature of the heat bath (in Kelvin).
*/
double getDefaultTemperature() {
return defaultTemp;
}
/**
* Get the default collision frequency (in 1/ps).
*/
double getDefaultCollisionFrequency() {
return defaultFreq;
}
protected:
ForceImpl* createImpl(OpenMMContextImpl& context);
private:
double defaultTemp, defaultFreq;
};
} // namespace OpenMM
#endif /*OPENMM_ANDERSENTHERMOSTAT_H_*/
#ifndef OPENMM_BROWNIANINTEGRATOR_H_
#define OPENMM_BROWNIANINTEGRATOR_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 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 "Kernel.h"
namespace OpenMM {
/**
* This is an Integrator which simulates a System using Brownian dynamics.
*/
class BrownianIntegrator : public Integrator {
public:
/**
* Create a BrownianIntegrator.
*
* @param temperature the temperature of the heat bath (in Kelvin)
* @param frictionCoeff the friction coefficient which couples the system to the heat bath
* @param stepSize the step size with which to integrator the system (in picoseconds)
*/
BrownianIntegrator(double temperature, double frictionCoeff, double stepSize);
/**
* Get the temperature of the heat bath (in Kelvin).
*/
double getTemperature() const {
return temperature;
}
/**
* Set the temperature of the heat bath (in Kelvin).
*/
void setTemperature(double temp) {
temperature = temp;
}
/**
* Get the friction coefficient which determines how strongly the system is coupled to
* the heat bath.
*/
double getFriction() const {
return friction;
}
/**
* Set the friction coefficient which determines how strongly the system is coupled to
* the heat bath.
*/
void setFriction(double coeff) {
friction = coeff;
}
/**
* 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 OpenMMContext 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 OpenMMContext.
*/
void initialize(OpenMMContextImpl& context);
/**
* Get the names of all Kernels used by this Integrator.
*/
std::vector<std::string> getKernelNames();
private:
double temperature, friction;
OpenMMContextImpl* context;
Kernel kernel;
};
} // namespace OpenMM
#endif /*OPENMM_BROWNIANINTEGRATOR_H_*/
#ifndef OPENMM_FORCE_H_
#define OPENMM_FORCE_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 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. *
* -------------------------------------------------------------------------- */
namespace OpenMM {
class ForceImpl;
/**
* Force objects apply forces to the atoms in a System, or alter their behavior in other
* ways. This is an abstract class. Subclasses define particular forces.
*
* More specifically, a Force object can do any or all of the following:
*
* <ul>
* <li>Add a contribution to the force on each atom</li>
* <li>Add a contribution to the potential energy of the System</li>
* <li>Modify the positions and velocities of atoms at the start of each time step</li>
* <li>Define parameters which are stored in the OpenMMContext and can be modified by the user</li>
* <li>Change the values of parameters defined by other Force objects at the start of each time step</li>
* </ul>
*/
class Force {
public:
virtual ~Force() {
}
protected:
friend class OpenMMContextImpl;
/**
* When an OpenMMContext is created, it invokes this method on each Force in the System.
* It should create a new ForceImpl object which can be used by the context for calculating forces.
* The ForceImpl will be deleted automatically when the OpenMMContext is deleted.
*/
virtual ForceImpl* createImpl(OpenMMContextImpl& context) = 0;
};
} // namespace OpenMM
#endif /*OPENMM_FORCE_H_*/
#ifndef OPENMM_GBSAOBCFORCEFIELD_H_
#define OPENMM_GBSAOBCFORCEFIELD_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 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 "Force.h"
#include <vector>
namespace OpenMM {
/**
* This class implements an implicit solvation force using the GBSA-OBC model.
*/
class GBSAOBCForceField : public Force {
public:
/*
* Create a GBSAOBCForceField.
*
* @param numAtoms the number of atoms in the system
*/
GBSAOBCForceField(int numAtoms);
/**
* Get the number of atoms in the system.
*/
int getNumAtoms() const {
return atoms.size();
}
/**
* Get the force field parameters for an atom.
*
* @param index the index of the atom for which to get parameters
* @param charge the charge of the atom, measured in units of the proton charge
* @param radius the GBSA radius of the atom, measured in angstroms
* @param scalingFactor the OBC scaling factor for the atom
*/
void getAtomParameters(int index, double& charge, double& radius, double& scalingFactor) const;
/**
* Set the force field parameters for an atom.
*
* @param index the index of the atom for which to set parameters
* @param charge the charge of the atom, measured in units of the proton charge
* @param radius the GBSA radius of the atom, measured in angstroms
* @param scalingFactor the OBC scaling factor for the atom
*/
void setAtomParameters(int index, double charge, double radius, double scalingFactor);
/**
* Get the dielectric constant for the solvent.
*/
double getSolventDielectric() const {
return solventDielectric;
}
/**
* Set the dielectric constant for the solvent.
*/
void setSolventDielectric(double dielectric) {
solventDielectric = dielectric;
}
/**
* Get the dielectric constant for the solute.
*/
double getSoluteDielectric() const {
return soluteDielectric;
}
/**
* Set the dielectric constant for the solute.
*/
void setSoluteDielectric(double dielectric) {
soluteDielectric = dielectric;
}
protected:
ForceImpl* createImpl(OpenMMContextImpl& context);
private:
class AtomInfo;
double solventDielectric, soluteDielectric;
std::vector<AtomInfo> atoms;
};
class GBSAOBCForceField::AtomInfo {
public:
double charge, radius, scalingFactor;
AtomInfo() {
charge = radius = scalingFactor = 0.0;
}
};
} // namespace OpenMM
#endif /*OPENMM_GBSAOBCFORCEFIELD_H_*/
#ifndef OPENMM_INTEGRATOR_H_
#define OPENMM_INTEGRATOR_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 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 "Vec3.h"
#include <map>
#include <vector>
namespace OpenMM {
class OpenMMContext;
/**
* An Integrator defines a method for simulating a System by integrating the equations of motion.
* This is an abstract class. Subclasses define particular integration methods.
*
* Each Integrator object is bound to a particular OpenMMContext which it integrates. This connection
* is specified by passing the Integrator as an argument to the constructor of the OpenMMContext.
*/
class Integrator {
public:
virtual ~Integrator() {
}
/**
* Get the size of each time step, in picoseconds.
*/
double getStepSize() const {
return stepSize;
}
/**
* Set the size of each time step, in picoseconds.
*/
void setStepSize(double size) {
stepSize = size;
}
/**
* Advance a simulation through time by taking a series of time steps.
*
* @param steps the number of time steps to take
*/
virtual void step(int steps) = 0;
protected:
friend class OpenMMContextImpl;
/**
* This will be called by the OpenMMContext 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 OpenMMContext.
*/
virtual void initialize(OpenMMContextImpl& context) = 0;
/**
* Get the names of all Kernels used by this Integrator.
*/
virtual std::vector<std::string> getKernelNames() = 0;
private:
double stepSize;
};
} // namespace OpenMM
#endif /*OPENMM_INTEGRATOR_H_*/
#ifndef OPENMM_LANGEVININTEGRATOR_H_
#define OPENMM_LANGEVININTEGRATOR_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 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 "Kernel.h"
namespace OpenMM {
/**
* This is an Integrator which simulates a System using Langevin dynamics.
*/
class LangevinIntegrator : public Integrator {
public:
/**
* Create a LangevinIntegrator.
*
* @param temperature the temperature of the heat bath (in Kelvin)
* @param frictionCoeff the friction coefficient which couples the system to the heat bath
* @param stepSize the step size with which to integrator the system (in picoseconds)
*/
LangevinIntegrator(double temperature, double frictionCoeff, double stepSize);
/**
* Get the temperature of the heat bath (in Kelvin).
*/
double getTemperature() const {
return temperature;
}
/**
* Set the temperature of the heat bath (in Kelvin).
*/
void setTemperature(double temp) {
temperature = temp;
}
/**
* Get the friction coefficient which determines how strongly the system is coupled to
* the heat bath.
*/
double getFriction() const {
return friction;
}
/**
* Set the friction coefficient which determines how strongly the system is coupled to
* the heat bath.
*/
void setFriction(double coeff) {
friction = coeff;
}
/**
* 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 OpenMMContext 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 OpenMMContext.
*/
void initialize(OpenMMContextImpl& context);
/**
* Get the names of all Kernels used by this Integrator.
*/
std::vector<std::string> getKernelNames();
private:
double temperature, friction;
OpenMMContextImpl* context;
Kernel kernel;
};
} // namespace OpenMM
#endif /*OPENMM_LANGEVININTEGRATOR_H_*/
#ifndef OPENMM_OPENMMCONTEXT_H_
#define OPENMM_OPENMMCONTEXT_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 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 "State.h"
#include "System.h"
#include <string>
#include <vector>
class thalweg_ARRAY;
namespace OpenMM {
class OpenMMContextImpl;
class Vec3;
/**
* An OpenMMContext stores the complete state of a simulation. More specifically, it includes:
*
* <ul>
* <li>The current time</li>
* <li>The position of each atom</li>
* <li>The velocity of each atom</li>
* <li>The values of configurable parameters defined by Force objects in the System</li>
* </ul>
*
* You can retrieve a snapshot of the current state at any time by calling getState(). This
* allows you to record the state of the simulation at various points, either for analysis
* or for checkpointing. getState() can also be used to retrieve the current forces on each
* atom and the current energy of the System.
*/
class OpenMMContext {
public:
/**
* Construct a new OpenMMContext in which to run a simulation.
*
* @param system the System which will be simulated
* @param integrator the Integrator which will be used to simulate the System
*/
OpenMMContext(System& system, Integrator& integrator);
/**
* Get System being simulated in this context.
*/
const System& getSystem() const;
/**
* Get System being simulated in this context.
*/
System& getSystem();
/**
* Get Integrator being used to by this context.
*/
const Integrator& getIntegrator() const;
/**
* Get Integrator being used to by this context.
*/
Integrator& getIntegrator();
/**
* Get a State object recording the current state information stored in this context.
*
* @param types the set of data types which should be stored in the State object. This
* should be a union of DataType values, e.g. (State::Positions | State::Velocities).
*/
State getState(State::DataType types) const;
/**
* Get the current time of the simulation (in picoseconds).
*/
double getTime();
/**
* Set the current time of the simulation (in picoseconds).
*/
void setTime(double time);
/**
* Set the positions of all atoms in the System (measured in angstroms).
*
* @param a vector whose length equals the number of atoms in the System. The i'th element
* contains the position of the i'th atom.
*/
void setPositions(const std::vector<Vec3>& positions);
/**
* Set the velocities of all atoms in the System (measured in angstroms/picosecond).
*
* @param a vector whose length equals the number of atoms in the System. The i'th element
* contains the velocity of the i'th atom.
*/
void setVelocities(const std::vector<Vec3>& velocities);
/**
* Get the value of an adjustable parameter defined by a Force object in the System.
*
* @param name the name of the parameter to get
*/
double getParameter(std::string name);
/**
* Set the value of an adjustable parameter defined by a Force object in the System.
*
* @param name the name of the parameter to set
* @param value the value of the parameter
*/
void setParameter(std::string name, double value);
/**
* When an OpenMMContext is created, it may cache information about the System being simulated
* and the Force objects contained in it. This means that, if the System or Forces are then
* modified, the OpenMMContext might not see all of the changes. Call reinitialize() to force
* the OpenMMContext to rebuild its internal representation of the System and pick up any changes
* that have been made.
*
* This is an expensive operation, so you should try to avoid calling it too frequently.
*/
void reinitialize();
private:
OpenMMContextImpl* impl;
};
} // namespace OpenMM
#endif /*OPENMM_OPENMMCONTEXT_H_*/
#ifndef OPENMM_OPENMMEXCEPTION_H_
#define OPENMM_OPENMMEXCEPTION_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 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 <exception>
#include <string>
namespace OpenMM {
/**
* This class is used for all exceptions thrown by OpenMM.
*/
class OpenMMException : public std::exception {
public:
OpenMMException(std::string message) : message(message) {
}
~OpenMMException() throw() {
}
const char* what() const throw() {
return message.c_str();
}
private:
std::string message;
};
} // namespace OpenMM
#endif /*OPENMM_OPENMMEXCEPTION_H_*/
#ifndef OPENMM_STANDARDMMFORCEFIELD_H_
#define OPENMM_STANDARDMMFORCEFIELD_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 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 "Force.h"
#include <map>
#include <vector>
namespace OpenMM {
/**
* This class can be used for a variety of standard molecular mechanics force fields. It includes
* terms for Coulomb and Lennard-Jones nonbonded interactions, and harmonic terms for the following
* types of bonded interactions: bond length, bond angle, and torsion (both periodic and Ryckaert-Bellemans).
*
* To create a StandardMMForceField, you specify the number of atoms and the number of each type
* of bonded term to the constructor. Then loop over them and call the appropriate setXXXParameter()
* method to set the force field parameters for each one.
*/
class StandardMMForceField : public Force {
public:
/**
* Create a StandardMMForceField.
*
* @param numAtoms the number of atoms in the system
* @param numBonds the number of harmonic bond stretch terms in the potential function
* @param numAngles the number of harmonic bond angle terms in the potential function
* @param numPeriodicTorsions the number of periodic torsion terms in the potential function
* @param numRBTorsions the number of Ryckaert-Bellemans torsion terms in the potential function
*/
StandardMMForceField(int numAtoms, int numBonds, int numAngles, int numPeriodicTorsions, int numRBTorsions);
/**
* Get the number of atoms in the system.
*/
int getNumAtoms() const {
return atoms.size();
}
/**
* Get the number of harmonic bond stretch terms in the potential function
*/
int getNumBonds() const {
return bonds.size();
}
/**
* Get the number of harmonic bond angle terms in the potential function
*/
int getNumAngles() const {
return angles.size();
}
/**
* Get the number of periodic torsion terms in the potential function
*/
int getNumPeriodicTorsions() const {
return periodicTorsions.size();
}
/**
* Get the number of Ryckaert-Bellemans torsion terms in the potential function
*/
int getNumRBTorsions() const {
return rbTorsions.size();
}
/**
* Get the nonbonded force parameters for an atom.
*
* @param index the index of the atom for which to get parameters
* @param charge the charge of the atom, measured in units of the proton charge
* @param radius the van der Waals radius of the atom, measured in angstroms
* @param depth the well depth of the van der Waals interaction, measured in kcal/mol
*/
void getAtomParameters(int index, double& charge, double& radius, double& depth) const;
/**
* Set the nonbonded force parameters for an atom.
*
* @param index the index of the atom for which to set parameters
* @param charge the charge of the atom, measured in units of the proton charge
* @param radius the van der Waals radius of the atom, measured in angstroms
* @param depth the well depth of the van der Waals interaction, measured in kcal/mol
*/
void setAtomParameters(int index, double charge, double radius, double depth);
/**
* Get the force field parameters for a bond term.
*
* @param index the index of the bond for which to get parameters
* @param atom1 the index of the first atom connected by the bond
* @param atom2 the index of the second atom connected by the bond
* @param length the equilibrium length of the bond, measured in angstroms
* @param k the harmonic force constant for the bond
*/
void getBondParameters(int index, int& atom1, int& atom2, double& length, double& k) const;
/**
* Set the force field parameters for a bond term.
*
* @param index the index of the bond for which to set parameters
* @param atom1 the index of the first atom connected by the bond
* @param atom2 the index of the second atom connected by the bond
* @param length the equilibrium length of the bond, measured in angstroms
* @param k the harmonic force constant for the bond
*/
void setBondParameters(int index, int atom1, int atom2, double length, double k);
/**
* Get the force field parameters for an angle term.
*
* @param index the index of the angle for which to get parameters
* @param atom1 the index of the first atom forming the angle
* @param atom2 the index of the second atom forming the angle
* @param atom3 the index of the third atom forming the angle
* @param length the equilibrium angle, measured in radians
* @param k the harmonic force constant for the angle
*/
void getAngleParameters(int index, int& atom1, int& atom2, int& atom3, double& angle, double& k) const;
/**
* Set the force field parameters for an angle term.
*
* @param index the index of the angle for which to set parameters
* @param atom1 the index of the first atom forming the angle
* @param atom2 the index of the second atom forming the angle
* @param atom3 the index of the third atom forming the angle
* @param length the equilibrium angle, measured in radians
* @param k the harmonic force constant for the angle
*/
void setAngleParameters(int index, int atom1, int atom2, int atom3, double angle, double k);
/**
* Get the force field parameters for a periodic torsion term.
*
* @param index the index of the torsion for which to get parameters
* @param atom1 the index of the first atom forming the torsion
* @param atom2 the index of the second atom forming the torsion
* @param atom3 the index of the third atom forming the torsion
* @param atom3 the index of the fourth atom forming the torsion
* @param periodicity the periodicity of the torsion
* @param phase the phase offset of the torsion, measured in radians
* @param k the force constant for the torsion
*/
void getPeriodicTorsionParameters(int index, int& atom1, int& atom2, int& atom3, int& atom4, int& periodicity, double& phase, double& k) const;
/**
* Set the force field parameters for a periodic torsion term.
*
* @param index the index of the torsion for which to set parameters
* @param atom1 the index of the first atom forming the torsion
* @param atom2 the index of the second atom forming the torsion
* @param atom3 the index of the third atom forming the torsion
* @param atom3 the index of the fourth atom forming the torsion
* @param periodicity the periodicity of the torsion
* @param phase the phase offset of the torsion, measured in radians
* @param k the force constant for the torsion
*/
void setPeriodicTorsionParameters(int index, int atom1, int atom2, int atom3, int atom4, int periodicity, double phase, double k);
/**
* Get the force field parameters for a Ryckaert-Bellemans torsion term.
*
* @param index the index of the torsion for which to get parameters
* @param atom1 the index of the first atom forming the torsion
* @param atom2 the index of the second atom forming the torsion
* @param atom3 the index of the third atom forming the torsion
* @param atom3 the index of the fourth atom forming the torsion
* @param c0 the coefficient of the constant term
* @param c1 the coefficient of the 1st order term
* @param c2 the coefficient of the 2nd order term
* @param c3 the coefficient of the 3rd order term
* @param c4 the coefficient of the 4th order term
* @param c5 the coefficient of the 5th order term
*/
void getRBTorsionParameters(int index, int& atom1, int& atom2, int& atom3, int& atom4, double& c0, double& c1, double& c2, double& c3, double& c4, double& c5) const;
/**
* Set the force field parameters for a Ryckaert-Bellemans torsion term.
*
* @param index the index of the torsion for which to set parameters
* @param atom1 the index of the first atom forming the torsion
* @param atom2 the index of the second atom forming the torsion
* @param atom3 the index of the third atom forming the torsion
* @param atom3 the index of the fourth atom forming the torsion
* @param c0 the coefficient of the constant term
* @param c1 the coefficient of the 1st order term
* @param c2 the coefficient of the 2nd order term
* @param c3 the coefficient of the 3rd order term
* @param c4 the coefficient of the 4th order term
* @param c5 the coefficient of the 5th order term
*/
void setRBTorsionParameters(int index, int atom1, int atom2, int atom3, int atom4, double c0, double c1, double c2, double c3, double c4, double c5);
protected:
ForceImpl* createImpl(OpenMMContextImpl& context);
private:
class AtomInfo;
class BondInfo;
class AngleInfo;
class PeriodicTorsionInfo;
class RBTorsionInfo;
std::vector<AtomInfo> atoms;
std::vector<BondInfo> bonds;
std::vector<AngleInfo> angles;
std::vector<PeriodicTorsionInfo> periodicTorsions;
std::vector<RBTorsionInfo> rbTorsions;
};
class StandardMMForceField::AtomInfo {
public:
double charge, radius, depth;
AtomInfo() {
charge = radius = depth = 0.0;
}
};
class StandardMMForceField::AngleInfo {
public:
int atom1, atom2, atom3;
double angle, k;
AngleInfo() {
atom1 = atom2 = atom3 = -1;
angle = k = 0.0;
}
};
class StandardMMForceField::PeriodicTorsionInfo {
public:
int atom1, atom2, atom3, atom4, periodicity;
double phase, k;
PeriodicTorsionInfo() {
atom1 = atom2 = atom3 = atom4 = -1;
periodicity = 1;
phase = k = 0.0;
}
};
class StandardMMForceField::RBTorsionInfo {
public:
int atom1, atom2, atom3, atom4;
double c[5];
RBTorsionInfo() {
atom1 = atom2 = atom3 = atom4 = -1;
c[0] = c[1] = c[2] = c[3] = c[4] = c[5] = 0.0;
}
};
class StandardMMForceField::BondInfo {
public:
int atom1, atom2;
double length, k;
BondInfo() {
atom1 = atom2 = -1;
length = k = 0.0;
}
};
} // namespace OpenMM
#endif /*OPENMM_STANDARDMMFORCEFIELD_H_*/
#ifndef OPENMM_STATE_H_
#define OPENMM_STATE_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 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 "Vec3.h"
#include <map>
#include <vector>
namespace OpenMM {
/**
* A State object records a snapshot of the current state of a simulation at a point in time.
* You create it by calling getState() on an OpenMMContext.
*
* When a State is created, you specify what information should be stored in it. This saves
* time and memory by only copying in the information that you actually want. This is especially
* important for forces and energies, since they may need to be calculated. If you query a
* State object for a piece of information which is not available (because it was not requested
* when the State was created), it will throw an exception.
*/
class State {
public:
/**
* This is an enumeration of the types of data which may be stored in a State. When you create
* a State, use these values to specify which data types it should contain.
*/
enum DataType {Positions=1, Velocities=2, Forces=4, Energy=8, Parameters=16};
/**
* Get the time for which this State was created.
*/
double getTime() const;
/**
* Get the position of each atom. If this State does not contain positions, this will throw an exception.
*/
const std::vector<Vec3>& getPositions() const;
/**
* Get the velocity of each atom. If this State does not contain velocities, this will throw an exception.
*/
const std::vector<Vec3>& getVelocities() const;
/**
* Get the force acting on each atom. If this State does not contain forces, this will throw an exception.
*/
const std::vector<Vec3>& getForces() const;
/**
* Get the total kinetic energy of the system. If this State does not contain energies, this will throw an exception.
*/
double getKineticEnergy() const;
/**
* Get the total potential energy of the system. If this State does not contain energies, this will throw an exception.
*/
double getPotentialEnergy() const;
/**
* Get a map containing the values of all parameters. If this State does not contain parameters, this will throw an exception.
*/
const std::map<std::string, double>& getParameters() const;
private:
friend class OpenMMContext;
State(double time, int numAtoms, DataType types);
std::vector<Vec3>& updPositions();
std::vector<Vec3>& updVelocities();
std::vector<Vec3>& updForces();
std::map<std::string, double>& updParameters();
void setEnergy(double ke, double pe);
DataType types;
double time, ke, pe;
std::vector<Vec3> positions;
std::vector<Vec3> velocities;
std::vector<Vec3> forces;
std::map<std::string, double> parameters;
};
} // namespace OpenMM
#endif /*OPENMM_STATE_H_*/
#ifndef OPENMM_SYSTEM_H_
#define OPENMM_SYSTEM_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 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 <vector>
namespace OpenMM {
class Force;
/**
* This class represents a molecular system. The definition of a System involves
* three elements:
*
* <ol>
* <li>The set of atoms in the system</li>
* <li>The forces acting on them</li>
* <li>Pairs of atoms whose separation should be connstrained to a fixed value</li>
* </ol>
*
* The atoms and constraints are defined directly by the System object.
* The forces are defined by objects that extend the Force class. The System
* stores a list of Force objects that determine the motion of the atoms.
*/
class System {
public:
/**
* Create a new System.
*
* @param numAtoms the number of atoms in the System
* @param numConstraints the number of distance constraints in the System.
*/
System(int numAtoms, int numConstraints);
~System();
/**
* Get the number of atoms in this System.
*/
int getNumAtoms() const {
return masses.size();
}
/**
* Get the mass (in atomic mass units) of an atom.
*
* @param index the index of the atom for which to get the mass
*/
double getAtomMass(int index) const {
return masses[index];
}
/**
* Set the mass (in atomic mass units) of an atom.
*
* @param index the index of the atom for which to set the mass
* @param mass the mass of the atom
*/
void setAtomMass(int index, double mass) {
masses[index] = mass;
}
/**
* Get the number of distance constraints in this System.
*/
int getNumConstraints() const {
return constraints.size();
}
/**
* Get the parameters defining a distance constraint.
*
* @param index the index of the constraint for which to get parameters
* @param atom1 the index of the first atom involved in the constraint
* @param atom2 the index of the second atom involved in the constraint
* @param distance the required distance between the two atoms, measured in angstroms
*/
void getConstraintParameters(int index, int& atom1, int& atom2, double& distance) const;
/**
* Set the parameters defining a distance constraint.
*
* @param index the index of the constraint for which to set parameters
* @param atom1 the index of the first atom involved in the constraint
* @param atom2 the index of the second atom involved in the constraint
* @param distance the required distance between the two atoms, measured in angstroms
*/
void setConstraintParameters(int index, int atom1, int atom2, double distance);
/**
* Add a Force to the System. The Force should have been created on the heap with the
* "new" operator. The System takes over ownership of it, and deletes the Force when the
* System itself is deleted.
*/
void addForce(Force* force) {
forces.push_back(force);
}
/**
* Get the number of Force objects that have been added to the System.
*/
int getNumForces() const {
return forces.size();
}
/**
* Get a reference to one of the Forces in this System.
*
* @param index the index of the Force to get
*/
Force& getForce(int index) {
return *forces[index];
}
private:
class ConstraintInfo;
std::vector<int> masses;
std::vector<ConstraintInfo> constraints;
std::vector<Force*> forces;
};
class System::ConstraintInfo {
public:
int atom1, atom2;
double distance;
ConstraintInfo() {
atom1 = atom2 = -1;
distance = 0.0;
}
};
} // namespace OpenMM
#endif /*OPENMM_SYSTEM_H_*/
#ifndef OPENMM_VEC3_H_
#define OPENMM_VEC3_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 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 <cassert>
namespace OpenMM {
/**
* This class represents a three component vector. It is used for storing positions,
* velocities, and forces.
*/
class Vec3 {
public:
/**
* Create a Vec3 whose elements are all 0.
*/
Vec3() {
data[0] = data[1] = data[2] = 0.0;
}
/**
* Create a Vec3 with specified x, y, and z components.
*/
Vec3(double x, double y, double z) {
data[0] = x;
data[1] = y;
data[2] = z;
}
double operator[](int index) const {
assert(index >= 0 && index < 3);
return data[index];
}
double& operator[](int index) {
assert(index >= 0 && index < 3);
return data[index];
}
private:
double data[3];
};
} // namespace OpenMM
#endif /*OPENMM_VEC3_H_*/
#ifndef OPENMM_VERLETINTEGRATOR_H_
#define OPENMM_VERLETINTEGRATOR_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 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 "Kernel.h"
namespace OpenMM {
/**
* This is an Integrator which simulates a System using the velocity Verlet algorithm.
*/
class VerletIntegrator : public Integrator {
public:
/**
* Create a VerletIntegrator.
*
* @param stepSize the step size with which to integrator the system (in picoseconds)
*/
VerletIntegrator(double stepSize);
/**
* 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 OpenMMContext 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 OpenMMContext.
*/
void initialize(OpenMMContextImpl& context);
/**
* Get the names of all Kernels used by this Integrator.
*/
std::vector<std::string> getKernelNames();
private:
OpenMMContextImpl* context;
Kernel kernel;
};
} // namespace OpenMM
#endif /*OPENMM_VERLETINTEGRATOR_H_*/
#ifndef OPENMM_ANDERSENTHERMOSTATIMPL_H_
#define OPENMM_ANDERSENTHERMOSTATIMPL_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 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 "ForceImpl.h"
#include "AndersenThermostat.h"
#include "Kernel.h"
#include <string>
namespace OpenMM {
/**
* This is the internal implementation of AndersenThermostat.
*/
class AndersenThermostatImpl : public ForceImpl {
public:
AndersenThermostatImpl(AndersenThermostat& owner, OpenMMContextImpl& context);
AndersenThermostat& getOwner() {
return owner;
}
void updateContextState(OpenMMContextImpl& context);
void calcForces(OpenMMContextImpl& context, Stream& forces) {
// This force doesn't apply forces to atoms.
}
double calcEnergy(OpenMMContextImpl& context) {
return 0.0; // This force doesn't contribute to the potential energy.
}
std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames();
private:
AndersenThermostat& owner;
Kernel kernel;
};
} // namespace OpenMM
#endif /*OPENMM_ANDERSENTHERMOSTATIMPL_H_*/
#ifndef OPENMM_FORCEIMPL_H_
#define OPENMM_FORCEIMPL_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 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 <map>
#include <vector>
namespace OpenMM {
class Force;
class OpenMMContextImpl;
class Stream;
/**
* A ForceImpl provides the internal implementation of a Force. When an OpenMMContext is
* created for a System, it creates a ForceImpl for each Force in the System. The ForceImpl
* is permitted to cache information from the Force or System which is needed to apply the
* force efficiently. If the user calls reinitialize() on the OpenMMContext, all ForceImpl
* objects it had previously created are deleted and recreated from scratch.
*
* This is an abstract class. Each Force subclass is responsible for defining its own
* ForceImpl subclass.
*/
class ForceImpl {
public:
virtual ~ForceImpl() {
}
/**
* Get the Force object from which this ForceImpl was created.
*/
virtual Force& getOwner() = 0;
/**
* This method is called at the beginning of each time step. It give the ForceImpl a chance
* to modify the state variables (positions, velocities, and parameters) stored in the
* OpenMMContext in arbitrary ways before integration is performed.
*
* @param context the context in which the system is being simulated
*/
virtual void updateContextState(OpenMMContextImpl& context) = 0;
/**
* Calculate the force on each atom generated by this ForceImpl. The forces should be <i>added</i>
* to the values already present in the array that is passed in. If this ForceImpl does not generate
* any new forces, it should simply return without modifying the array.
*
* @param context the context in which the system is being simulated
* @param forces new forces should be added to the value already stored in this
*/
virtual void calcForces(OpenMMContextImpl& context, Stream& forces) = 0;
/**
* Calculate this ForceImpl's contribution to the potential energy of the system.
*
* @param context the context in which the system is being simulated
* @return this force's contribution to the potential energy of the system, or 0 if this
* force does not contribute to potential energy
*/
virtual double calcEnergy(OpenMMContextImpl& context) = 0;
/**
* Get a map containing the default values for all adjustable parameters defined by this ForceImpl. These
* parameters and their default values will automatically be added to the OpenMMContext.
*/
virtual std::map<std::string, double> getDefaultParameters() = 0;
/**
* Get the names of all Kernels used by this Force.
*/
virtual std::vector<std::string> getKernelNames() = 0;
};
} // namespace OpenMM
#endif /*OPENMM_FORCEIMPL_H_*/
#ifndef OPENMM_GBSAOBCFORCEFIELDIMPL_H_
#define OPENMM_GBSAOBCFORCEFIELDIMPL_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 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 "ForceImpl.h"
#include "GBSAOBCForceField.h"
#include "Kernel.h"
#include <string>
namespace OpenMM {
/**
* This is the internal implementation of GBSAOBCForceField.
*/
class GBSAOBCForceFieldImpl : public ForceImpl {
public:
GBSAOBCForceFieldImpl(GBSAOBCForceField& owner, OpenMMContextImpl& context);
GBSAOBCForceField& getOwner() {
return owner;
}
void updateContextState(OpenMMContextImpl& context) {
// This force field doesn't update the state directly.
}
void calcForces(OpenMMContextImpl& context, Stream& forces);
double calcEnergy(OpenMMContextImpl& context);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
std::vector<std::string> getKernelNames();
private:
void initialize(OpenMMContextImpl& context);
GBSAOBCForceField& owner;
Kernel forceKernel, energyKernel;
bool hasInitialized;
};
} // namespace OpenMM
#endif /*OPENMM_GBSAOBCFORCEFIELDIMPL_H_*/
#ifndef OPENMM_OPENMMCONTEXTIMPL_H_
#define OPENMM_OPENMMCONTEXTIMPL_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 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 "Kernel.h"
#include "Platform.h"
#include "Stream.h"
#include <map>
#include <vector>
namespace OpenMM {
class ForceImpl;
class Integrator;
class OpenMMContext;
class System;
/**
* This is the internal implementation of an OpenMMContext.
*/
class OpenMMContextImpl {
public:
/**
* Create an OpenMMContextImpl for an OpenMMContext;
*/
OpenMMContextImpl(OpenMMContext& owner, System& system, Integrator& integrator);
~OpenMMContextImpl();
/**
* Get the OpenMMContext for which this is the implementation.
*/
OpenMMContext& getOwner() {
return owner;
}
/**
* Get System being simulated in this context.
*/
System& getSystem() {
return system;
}
/**
* Get Integrator being used to by this context.
*/
Integrator& getIntegrator() {
return integrator;
}
/**
* Get the Platform implementation being used for computations.
*/
Platform& getPlatform() {
return *platform;
}
/**
* Get the Stream containing the current position of each atom.
*/
Stream& getPositions() {
return positions;
}
/**
* Get the Stream containing the current velocity of each atom.
*/
Stream& getVelocities() {
return velocities;
}
/**
* Get the Stream containing the force on each atom that was calculated by
* the most recent call to calcForces().
*/
Stream& getForces() {
return forces;
}
/**
* Get the current time (in picoseconds).
*/
double getTime() const {
return time;
}
/**
* Set the current time (in picoseconds).
*/
void setTime(double t) {
time = t;
}
/**
* Get the value of an adjustable parameter. If there is no parameter with the specified name, this
* throws an exception.
*
* @param name the name of the parameter to get
*/
double getParameter(std::string name);
/**
* Set the value of an adjustable parameter. If there is no parameter with the specified name, this
* throws an exception.
*
* @param name the name of the parameter to set
* @param value the value of the parameter
*/
void setParameter(std::string name, double value);
/**
* Recalculate all of the forces in the system. After calling this, use getForces() to retrieve
* the forces that were calculated.
*/
void calcForces();
/**
* Calculate the kinetic energy of the system (in kcal/mol).
*/
double calcKineticEnergy();
/**
* Calculate the potential energy of the system (in kcal/mol).
*/
double calcPotentialEnergy();
/**
* This should be called at the start of each time step. It calls updateContextState() on each
* ForceImpl in the system, allowing them to modify the values of state variables.
*/
void updateContextState();
/**
* Delete all ForceImpl objects that have been created and create new ones.
*/
void reinitialize();
private:
friend class OpenMMContext;
OpenMMContext& owner;
System& system;
Integrator& integrator;
std::vector<ForceImpl*> forceImpls;
double time;
std::map<std::string, double> parameters;
Platform* platform;
Stream positions, velocities, forces;
Kernel kineticEnergyKernel;
};
} // namespace OpenMM
#endif /*OPENMM_OPENMMCONTEXTIMPL_H_*/
#ifndef OPENMM_STANDARDMMFORCEFIELDIMPL_H_
#define OPENMM_STANDARDMMFORCEFIELDIMPL_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 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 "ForceImpl.h"
#include "StandardMMForceField.h"
#include "Kernel.h"
#include <utility>
#include <set>
#include <string>
namespace OpenMM {
/**
* This is the internal implementation of StandardMMForceField.
*/
class StandardMMForceFieldImpl : public ForceImpl {
public:
StandardMMForceFieldImpl(StandardMMForceField& owner, OpenMMContextImpl& context);
~StandardMMForceFieldImpl();
StandardMMForceField& getOwner() {
return owner;
}
void updateContextState(OpenMMContextImpl& context) {
// This force field doesn't update the state directly.
}
void calcForces(OpenMMContextImpl& context, Stream& forces);
double calcEnergy(OpenMMContextImpl& context);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
std::vector<std::string> getKernelNames();
private:
void findExclusions(const std::vector<std::vector<int> >& bondIndices, std::vector<std::set<int> >& exclusions, std::set<std::pair<int, int> >& bonded14Indices) const;
void addExclusionsToSet(const std::vector<std::set<int> >& bonded12, std::set<int>& exclusions, int fromAtom, int currentLevel) const;
StandardMMForceField& owner;
Kernel forceKernel, energyKernel;
};
} // namespace OpenMM
#endif /*OPENMM_STANDARDMMFORCEFIELDIMPL_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 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 "AndersenThermostat.h"
#include "internal/AndersenThermostatImpl.h"
using namespace OpenMM;
const std::string AndersenThermostat::Temperature = "AndersenTemperature";
const std::string AndersenThermostat::CollisionFrequency = "AndersenCollisionFrequency";
AndersenThermostat::AndersenThermostat(double defaultTemperature, double defaultCollisionFrequency) :
defaultTemp(defaultTemperature), defaultFreq(defaultCollisionFrequency) {
}
ForceImpl* AndersenThermostat::createImpl(OpenMMContextImpl& context) {
return new AndersenThermostatImpl(*this, context);
}
/* -------------------------------------------------------------------------- *
* 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 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 "internal/AndersenThermostatImpl.h"
#include "internal/OpenMMContextImpl.h"
#include "Integrator.h"
#include "kernels.h"
using namespace OpenMM;
AndersenThermostatImpl::AndersenThermostatImpl(AndersenThermostat& owner, OpenMMContextImpl& context) : owner(owner) {
kernel = context.getPlatform().createKernel(ApplyAndersenThermostatKernel::Name());
}
void AndersenThermostatImpl::updateContextState(OpenMMContextImpl& context) {
dynamic_cast<ApplyAndersenThermostatKernel&>(kernel.getImpl()).execute(context.getVelocities(), context.getParameter(AndersenThermostat::Temperature),
context.getParameter(AndersenThermostat::CollisionFrequency), context.getIntegrator().getStepSize());
}
std::map<std::string, double> AndersenThermostatImpl::getDefaultParameters() {
std::map<std::string, double> parameters;
parameters[AndersenThermostat::Temperature] = getOwner().getDefaultTemperature();
parameters[AndersenThermostat::CollisionFrequency] = getOwner().getDefaultCollisionFrequency();
return parameters;
}
std::vector<std::string> AndersenThermostatImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(ApplyAndersenThermostatKernel::Name());
return names;
}
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