"csrc/vscode:/vscode.git/clone" did not exist on "8a34a9bdf28c412856f3be019a653c78b456da2e"
Commit ad75a390 authored by Peter Eastman's avatar Peter Eastman
Browse files

Split StandardMMForceField into separate classes for each force term.

parent 8078c417
...@@ -36,9 +36,13 @@ ...@@ -36,9 +36,13 @@
#include "BrownianIntegrator.h" #include "BrownianIntegrator.h"
#include "CMMotionRemover.h" #include "CMMotionRemover.h"
#include "GBSAOBCForceField.h" #include "GBSAOBCForceField.h"
#include "HarmonicAngleForce.h"
#include "HarmonicBondForce.h"
#include "KernelImpl.h" #include "KernelImpl.h"
#include "LangevinIntegrator.h" #include "LangevinIntegrator.h"
#include "StandardMMForceField.h" #include "PeriodicTorsionForce.h"
#include "RBTorsionForce.h"
#include "NonbondedForce.h"
#include "Stream.h" #include "Stream.h"
#include "System.h" #include "System.h"
#include "VerletIntegrator.h" #include "VerletIntegrator.h"
...@@ -49,9 +53,137 @@ ...@@ -49,9 +53,137 @@
namespace OpenMM { namespace OpenMM {
/** /**
* This kernel is invoked by StandardMMForceField to calculate the forces acting on the system and the energy of the system. * This kernel is invoked by HarmonicBondForce to calculate the forces acting on the system and the energy of the system.
*/ */
class CalcStandardMMForceFieldKernel : public KernelImpl { class CalcHarmonicBondForceKernel : public KernelImpl {
public:
static std::string Name() {
return "CalcHarmonicBondForce";
}
CalcHarmonicBondForceKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
}
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param force the HarmonicBondForce this kernel will be used for
*/
virtual void initialize(const System& system, const HarmonicBondForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(OpenMMContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicBondForce
*/
virtual double executeEnergy(OpenMMContextImpl& context) = 0;
};
/**
* This kernel is invoked by HarmonicAngleForce to calculate the forces acting on the system and the energy of the system.
*/
class CalcHarmonicAngleForceKernel : public KernelImpl {
public:
static std::string Name() {
return "CalcHarmonicAngleForce";
}
CalcHarmonicAngleForceKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
}
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param force the HarmonicAngleForce this kernel will be used for
*/
virtual void initialize(const System& system, const HarmonicAngleForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(OpenMMContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicAngleForce
*/
virtual double executeEnergy(OpenMMContextImpl& context) = 0;
};
/**
* This kernel is invoked by PeriodicTorsionForce to calculate the forces acting on the system and the energy of the system.
*/
class CalcPeriodicTorsionForceKernel : public KernelImpl {
public:
static std::string Name() {
return "CalcPeriodicTorsionForce";
}
CalcPeriodicTorsionForceKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
}
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param force the PeriodicTorsionForce this kernel will be used for
*/
virtual void initialize(const System& system, const PeriodicTorsionForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(OpenMMContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the PeriodicTorsionForce
*/
virtual double executeEnergy(OpenMMContextImpl& context) = 0;
};
/**
* This kernel is invoked by RBTorsionForce to calculate the forces acting on the system and the energy of the system.
*/
class CalcRBTorsionForceKernel : public KernelImpl {
public:
static std::string Name() {
return "CalcRBTorsionForce";
}
CalcRBTorsionForceKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
}
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param force the RBTorsionForce this kernel will be used for
*/
virtual void initialize(const System& system, const RBTorsionForce& force) = 0;
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(OpenMMContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the RBTorsionForce
*/
virtual double executeEnergy(OpenMMContextImpl& context) = 0;
};
/**
* This kernel is invoked by NonbondedForce to calculate the forces acting on the system and the energy of the system.
*/
class CalcNonbondedForceKernel : public KernelImpl {
public: public:
enum NonbondedMethod { enum NonbondedMethod {
NoCutoff = 0, NoCutoff = 0,
...@@ -59,20 +191,20 @@ public: ...@@ -59,20 +191,20 @@ public:
CutoffPeriodic = 2 CutoffPeriodic = 2
}; };
static std::string Name() { static std::string Name() {
return "CalcStandardMMForceField"; return "CalcNonbondedForce";
} }
CalcStandardMMForceFieldKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) { CalcNonbondedForceKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel. * Initialize the kernel.
* *
* @param system the System this kernel will be applied to * @param system the System this kernel will be applied to
* @param force the StandardMMForceField this kernel will be used for * @param force the NonbondedForce this kernel will be used for
* @param exclusions the i'th element lists the indices of all atoms with which the i'th atom should not interact through * @param exclusions the i'th element lists the indices of all atoms with which the i'th atom should not interact through
* nonbonded forces. Bonded 1-4 pairs are also included in this list, since they should be omitted from * nonbonded forces. Bonded 1-4 pairs are also included in this list, since they should be omitted from
* the standard nonbonded calculation. * the standard nonbonded calculation.
*/ */
virtual void initialize(const System& system, const StandardMMForceField& force, const std::vector<std::set<int> >& exclusions) = 0; virtual void initialize(const System& system, const NonbondedForce& force, const std::vector<std::set<int> >& exclusions) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces.
* *
...@@ -83,7 +215,7 @@ public: ...@@ -83,7 +215,7 @@ public:
* Execute the kernel to calculate the energy. * Execute the kernel to calculate the energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @return the potential energy due to the StandardMMForceField * @return the potential energy due to the NonbondedForce
*/ */
virtual double executeEnergy(OpenMMContextImpl& context) = 0; virtual double executeEnergy(OpenMMContextImpl& context) = 0;
}; };
......
#ifndef OPENMM_HARMONICANGLEFORCE_H_
#define OPENMM_HARMONICANGLEFORCE_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 "Vec3.h"
#include <map>
#include <vector>
#include "internal/windowsExport.h"
namespace OpenMM {
/**
* This class implements an interaction between groups of three atoms that varies harmonically with the angle
* between them. When creating a HarmonicAngleForce, you specify the number of angle as an argument to the
* constructor, then loop over them and call setAngleParameters() to set the force field parameters for each one.
*/
class OPENMM_EXPORT HarmonicAngleForce : public Force {
public:
/**
* Create a HarmonicAngleForce.
*
* @param numAngles the number of harmonic bond angle terms in the potential function
*/
HarmonicAngleForce(int numAngles);
/**
* Get the number of harmonic bond angle terms in the potential function
*/
int getNumAngles() const {
return angles.size();
}
/**
* 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);
protected:
ForceImpl* createImpl();
private:
class AngleInfo;
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::vector<AngleInfo> angles;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};
class HarmonicAngleForce::AngleInfo {
public:
int atom1, atom2, atom3;
double angle, k;
AngleInfo() {
atom1 = atom2 = atom3 = -1;
angle = k = 0.0;
}
};
} // namespace OpenMM
#endif /*OPENMM_HARMONICANGLEFORCE_H_*/
#ifndef OPENMM_HARMONICBONDFORCE_H_
#define OPENMM_HARMONICBONDFORCE_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 "Vec3.h"
#include <map>
#include <vector>
#include "internal/windowsExport.h"
namespace OpenMM {
/**
* This class implements an interaction between pairs of atoms that varies harmonically with the distance
* between them. When creating a HarmonicBondForce, you specify the number of bonds as an argument to the
* constructor, then loop over them and call setBondParameters() to set the force field parameters for each one.
*/
class OPENMM_EXPORT HarmonicBondForce : public Force {
public:
/**
* Create a HarmonicBondForce.
*
* @param numBonds the number of harmonic bond stretch terms in the potential function
*/
HarmonicBondForce(int numBonds);
/**
* Get the number of harmonic bond stretch terms in the potential function
*/
int getNumBonds() const {
return bonds.size();
}
/**
* 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 nm
* @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 nm
* @param k the harmonic force constant for the bond
*/
void setBondParameters(int index, int atom1, int atom2, double length, double k);
protected:
ForceImpl* createImpl();
private:
class BondInfo;
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::vector<BondInfo> bonds;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};
class HarmonicBondForce::BondInfo {
public:
int atom1, atom2;
double length, k;
BondInfo() {
atom1 = atom2 = -1;
length = k = 0.0;
}
};
} // namespace OpenMM
#endif /*OPENMM_HARMONICBONDFORCE_H_*/
#ifndef OPENMM_STANDARDMMFORCEFIELD_H_ #ifndef OPENMM_NONBONDEDFORCE_H_
#define OPENMM_STANDARDMMFORCEFIELD_H_ #define OPENMM_NONBONDEDFORCE_H_
/* -------------------------------------------------------------------------- * /* -------------------------------------------------------------------------- *
* OpenMM * * OpenMM *
...@@ -41,16 +41,22 @@ ...@@ -41,16 +41,22 @@
namespace OpenMM { namespace OpenMM {
/** /**
* This class can be used for a variety of standard molecular mechanics force fields. It includes * This class implements nonbonded interactions between particles, including a Coulomb force to represent
* terms for Coulomb and Lennard-Jones nonbonded interactions, and harmonic terms for the following * electrostatics and a Lennard-Jones force to represent van der Waals interactions. It optionally supports
* types of bonded interactions: bond length, bond angle, and torsion (both periodic and Ryckaert-Bellemans). * periodic boundary conditions and cutoffs for long range interactions.
* *
* To create a StandardMMForceField, you specify the number of atoms and the number of each type * If the System also contains a HarmonicBondForce, nonbonded interactions are automatically excluded between
* of bonded term to the constructor. Then loop over them and call the appropriate setXXXParameter() * particles which are separated by three or fewer bonds. Most molecular force fields omit Coulomb and
* method to set the force field parameters for each one. * Lennard-Jones interactions between particles separated by one or two bonds, while using modified parameters
* for those separated by three bonds (known as "1-4 interactions"). This class lets you provide a list of
* 1-4 interactions to include in the potential, along with the parameters to use for each one.
*
* When creating a NonbondedForce, you specify the number of atoms and the number of 1-4 interactions as
* arguments to the constructor. You then loop over them and call setAtomParameters() for each atom and
* setNonbond14Parameters() for each 1-4 interaction.
*/ */
class OPENMM_EXPORT StandardMMForceField : public Force { class OPENMM_EXPORT NonbondedForce : public Force {
public: public:
/** /**
* This is an enumeration of the different methods that may be used for handling long range nonbonded forces. * This is an enumeration of the different methods that may be used for handling long range nonbonded forces.
...@@ -58,62 +64,34 @@ public: ...@@ -58,62 +64,34 @@ public:
enum NonbondedMethod { enum NonbondedMethod {
/** /**
* No cutoff is applied to nonbonded interactions. The full set of N^2 interactions is computed exactly. * No cutoff is applied to nonbonded interactions. The full set of N^2 interactions is computed exactly.
* This necessarily means that periodic boundary conditions cannot be used. * This necessarily means that periodic boundary conditions cannot be used. This is the default.
*/ */
NoCutoff = 0, NoCutoff = 0,
/** /**
* Interactions beyond the cutoff distance are ignored. Coulomb interactions closer than the cutoff distance * Interactions beyond the cutoff distance are ignored. Coulomb interactions closer than the cutoff distance
* are modified based using the reaction field method. * are modified using the reaction field method.
*/ */
CutoffNonPeriodic = 1, CutoffNonPeriodic = 1,
/** /**
* Periodic boundary conditions are used, so that each atom interacts only with the nearest periodic copy of * Periodic boundary conditions are used, so that each atom interacts only with the nearest periodic copy of
* each other atom. Interactions beyond the cutoff distance are ignored. Coulomb interactions closer than the * each other atom. Interactions beyond the cutoff distance are ignored. Coulomb interactions closer than the
* cutoff distance are modified based using the reaction field method. * cutoff distance are modified using the reaction field method.
*/ */
CutoffPeriodic = 2 CutoffPeriodic = 2
}; };
/** /**
* Create a StandardMMForceField. * Create a NonbondedForce.
* *
* @param numAtoms the number of atoms in the system * @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
* @param numNonbonded14 the number of nonbonded 1-4 terms in the potential function * @param numNonbonded14 the number of nonbonded 1-4 terms in the potential function
*/ */
StandardMMForceField(int numAtoms, int numBonds, int numAngles, int numPeriodicTorsions, int numRBTorsions, int numNonbonded14); NonbondedForce(int numAtoms, int numNonbonded14);
/** /**
* Get the number of atoms in the system. * Get the number of atoms in the system.
*/ */
int getNumAtoms() const { int getNumAtoms() const {
return atoms.size(); 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 number of nonbonded 1-4 terms in the potential function * Get the number of nonbonded 1-4 terms in the potential function
*/ */
...@@ -180,106 +158,6 @@ public: ...@@ -180,106 +158,6 @@ public:
* @param depth the well depth of the van der Waals interaction (epsilon in the Lennard Jones potential), measured in kJ/mol * @param depth the well depth of the van der Waals interaction (epsilon in the Lennard Jones potential), measured in kJ/mol
*/ */
void setAtomParameters(int index, double charge, double radius, double depth); 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 nm
* @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 nm
* @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);
/** /**
* Get the force field parameters for a nonbonded 1-4 term. * Get the force field parameters for a nonbonded 1-4 term.
* *
...@@ -306,10 +184,6 @@ protected: ...@@ -306,10 +184,6 @@ protected:
ForceImpl* createImpl(); ForceImpl* createImpl();
private: private:
class AtomInfo; class AtomInfo;
class BondInfo;
class AngleInfo;
class PeriodicTorsionInfo;
class RBTorsionInfo;
class NB14Info; class NB14Info;
NonbondedMethod nonbondedMethod; NonbondedMethod nonbondedMethod;
double cutoffDistance; double cutoffDistance;
...@@ -322,21 +196,15 @@ private: ...@@ -322,21 +196,15 @@ private:
#pragma warning(push) #pragma warning(push)
#pragma warning(disable:4251) #pragma warning(disable:4251)
#endif #endif
std::vector<AtomInfo> atoms; std::vector<AtomInfo> atoms;
std::vector<BondInfo> bonds;
std::vector<AngleInfo> angles;
std::vector<PeriodicTorsionInfo> periodicTorsions;
std::vector<RBTorsionInfo> rbTorsions;
std::vector<NB14Info> nb14s; std::vector<NB14Info> nb14s;
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(pop) #pragma warning(pop)
#endif #endif
}; };
class StandardMMForceField::AtomInfo { class NonbondedForce::AtomInfo {
public: public:
double charge, radius, depth; double charge, radius, depth;
AtomInfo() { AtomInfo() {
...@@ -344,48 +212,7 @@ public: ...@@ -344,48 +212,7 @@ public:
} }
}; };
class StandardMMForceField::AngleInfo { class NonbondedForce::NB14Info {
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[6];
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;
}
};
class StandardMMForceField::NB14Info {
public: public:
int atom1, atom2; int atom1, atom2;
double charge, radius, depth; double charge, radius, depth;
...@@ -397,4 +224,4 @@ public: ...@@ -397,4 +224,4 @@ public:
} // namespace OpenMM } // namespace OpenMM
#endif /*OPENMM_STANDARDMMFORCEFIELD_H_*/ #endif /*OPENMM_NONBONDEDFORCE_H_*/
#ifndef OPENMM_PERIODICTORSIONFORCE_H_
#define OPENMM_PERIODICTORSIONFORCE_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 "Vec3.h"
#include <map>
#include <vector>
#include "internal/windowsExport.h"
namespace OpenMM {
/**
* This class implements an interaction between groups of four atoms that varies periodically with the torsion angle
* between them. When creating a PeriodicTorsionForce, you specify the number of torsions as an argument to the
* constructor, then loop over them and call setTorsionParameters() to set the force field parameters for each one.
*/
class OPENMM_EXPORT PeriodicTorsionForce : public Force {
public:
/**
* Create a PeriodicTorsionForce.
*
* @param numTorsions the number of periodic torsion terms in the potential function
*/
PeriodicTorsionForce(int numTorsions);
/**
* Get the number of periodic torsion terms in the potential function
*/
int getNumTorsions() const {
return periodicTorsions.size();
}
/**
* 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 getTorsionParameters(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 setTorsionParameters(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
*/
protected:
ForceImpl* createImpl();
private:
class PeriodicTorsionInfo;
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::vector<PeriodicTorsionInfo> periodicTorsions;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};
class PeriodicTorsionForce::PeriodicTorsionInfo {
public:
int atom1, atom2, atom3, atom4, periodicity;
double phase, k;
PeriodicTorsionInfo() {
atom1 = atom2 = atom3 = atom4 = -1;
periodicity = 1;
phase = k = 0.0;
}
};
} // namespace OpenMM
#endif /*OPENMM_PERIODICTORSIONFORCE_H_*/
#ifndef OPENMM_RBTORSIONFORCE_H_
#define OPENMM_RBTORSIONFORCE_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 "Vec3.h"
#include <map>
#include <vector>
#include "internal/windowsExport.h"
namespace OpenMM {
/**
* This class implements an interaction between groups of four atoms that varies with the torsion angle between them
* according to the Ryckaert-Bellemans potential. When creating an RBTorsionForce, you specify the number of torsions
* as an argument to the constructor, then loop over them and call setTorsionParameters() to set the force field
* parameters for each one.
*/
class OPENMM_EXPORT RBTorsionForce : public Force {
public:
/**
* Create a RBTorsionForce.
*
* @param numTorsions the number of torsion terms in the potential function
*/
RBTorsionForce(int numTorsions);
/**
* Get the number of Ryckaert-Bellemans torsion terms in the potential function
*/
int getNumTorsions() const {
return rbTorsions.size();
}
/**
* 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 getTorsionParameters(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 setTorsionParameters(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();
private:
class RBTorsionInfo;
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::vector<RBTorsionInfo> rbTorsions;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};
class RBTorsionForce::RBTorsionInfo {
public:
int atom1, atom2, atom3, atom4;
double c[6];
RBTorsionInfo() {
atom1 = atom2 = atom3 = atom4 = -1;
c[0] = c[1] = c[2] = c[3] = c[4] = c[5] = 0.0;
}
};
} // namespace OpenMM
#endif /*OPENMM_RBTORSIONFORCE_H_*/
#ifndef OPENMM_HARMONICANGLEFORCEIMPL_H_
#define OPENMM_HARMONICANGLEFORCEIMPL_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 "HarmonicAngleForce.h"
#include "Kernel.h"
#include <utility>
#include <set>
#include <string>
namespace OpenMM {
/**
* This is the internal implementation of HarmonicAngleForce.
*/
class HarmonicAngleForceImpl : public ForceImpl {
public:
HarmonicAngleForceImpl(HarmonicAngleForce& owner);
~HarmonicAngleForceImpl();
void initialize(OpenMMContextImpl& context);
HarmonicAngleForce& 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:
HarmonicAngleForce& owner;
Kernel kernel;
};
} // namespace OpenMM
#endif /*OPENMM_HARMONICANGLEFORCEIMPL_H_*/
#ifndef OPENMM_HARMONICBONDFORCEIMPL_H_
#define OPENMM_HARMONICBONDFORCEIMPL_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 "HarmonicBondForce.h"
#include "Kernel.h"
#include <utility>
#include <set>
#include <string>
namespace OpenMM {
/**
* This is the internal implementation of HarmonicBondForce.
*/
class HarmonicBondForceImpl : public ForceImpl {
public:
HarmonicBondForceImpl(HarmonicBondForce& owner);
~HarmonicBondForceImpl();
void initialize(OpenMMContextImpl& context);
HarmonicBondForce& 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:
HarmonicBondForce& owner;
Kernel kernel;
};
} // namespace OpenMM
#endif /*OPENMM_HARMONICBONDFORCEIMPL_H_*/
#ifndef OPENMM_STANDARDMMFORCEFIELDIMPL_H_ #ifndef OPENMM_NONBONDEDFORCEIMPL_H_
#define OPENMM_STANDARDMMFORCEFIELDIMPL_H_ #define OPENMM_NONBONDEDFORCEIMPL_H_
/* -------------------------------------------------------------------------- * /* -------------------------------------------------------------------------- *
* OpenMM * * OpenMM *
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "ForceImpl.h" #include "ForceImpl.h"
#include "StandardMMForceField.h" #include "NonbondedForce.h"
#include "Kernel.h" #include "Kernel.h"
#include <utility> #include <utility>
#include <set> #include <set>
...@@ -42,15 +42,15 @@ ...@@ -42,15 +42,15 @@
namespace OpenMM { namespace OpenMM {
/** /**
* This is the internal implementation of StandardMMForceField. * This is the internal implementation of NonbondedForce.
*/ */
class StandardMMForceFieldImpl : public ForceImpl { class NonbondedForceImpl : public ForceImpl {
public: public:
StandardMMForceFieldImpl(StandardMMForceField& owner); NonbondedForceImpl(NonbondedForce& owner);
~StandardMMForceFieldImpl(); ~NonbondedForceImpl();
void initialize(OpenMMContextImpl& context); void initialize(OpenMMContextImpl& context);
StandardMMForceField& getOwner() { NonbondedForce& getOwner() {
return owner; return owner;
} }
void updateContextState(OpenMMContextImpl& context) { void updateContextState(OpenMMContextImpl& context) {
...@@ -65,10 +65,10 @@ public: ...@@ -65,10 +65,10 @@ public:
private: 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 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 baseAtom, int fromAtom, int currentLevel) const; void addExclusionsToSet(const std::vector<std::set<int> >& bonded12, std::set<int>& exclusions, int baseAtom, int fromAtom, int currentLevel) const;
StandardMMForceField& owner; NonbondedForce& owner;
Kernel kernel; Kernel kernel;
}; };
} // namespace OpenMM } // namespace OpenMM
#endif /*OPENMM_STANDARDMMFORCEFIELDIMPL_H_*/ #endif /*OPENMM_NONBONDEDFORCEIMPL_H_*/
#ifndef OPENMM_PERIODICTORSIONFORCEIMPL_H_
#define OPENMM_PERIODICTORSIONFORCEIMPL_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 "PeriodicTorsionForce.h"
#include "Kernel.h"
#include <utility>
#include <set>
#include <string>
namespace OpenMM {
/**
* This is the internal implementation of PeriodicTorsionForce.
*/
class PeriodicTorsionForceImpl : public ForceImpl {
public:
PeriodicTorsionForceImpl(PeriodicTorsionForce& owner);
~PeriodicTorsionForceImpl();
void initialize(OpenMMContextImpl& context);
PeriodicTorsionForce& 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:
PeriodicTorsionForce& owner;
Kernel kernel;
};
} // namespace OpenMM
#endif /*OPENMM_PERIODICTORSIONFORCEIMPL_H_*/
#ifndef OPENMM_RBTORSIONFORCEIMPL_H_
#define OPENMM_RBTORSIONFORCEIMPL_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 "RBTorsionForce.h"
#include "Kernel.h"
#include <utility>
#include <set>
#include <string>
namespace OpenMM {
/**
* This is the internal implementation of RBTorsionForce.
*/
class RBTorsionForceImpl : public ForceImpl {
public:
RBTorsionForceImpl(RBTorsionForce& owner);
~RBTorsionForceImpl();
void initialize(OpenMMContextImpl& context);
RBTorsionForce& 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:
RBTorsionForce& owner;
Kernel kernel;
};
} // namespace OpenMM
#endif /*OPENMM_RBTORSIONFORCEIMPL_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 "OpenMMException.h"
#include "HarmonicAngleForce.h"
#include "internal/HarmonicAngleForceImpl.h"
using namespace OpenMM;
HarmonicAngleForce::HarmonicAngleForce(int numAngles) : angles(numAngles) {
}
void HarmonicAngleForce::getAngleParameters(int index, int& atom1, int& atom2, int& atom3, double& angle, double& k) const {
atom1 = angles[index].atom1;
atom2 = angles[index].atom2;
atom3 = angles[index].atom3;
angle = angles[index].angle;
k = angles[index].k;
}
void HarmonicAngleForce::setAngleParameters(int index, int atom1, int atom2, int atom3, double angle, double k) {
angles[index].atom1 = atom1;
angles[index].atom2 = atom2;
angles[index].atom3 = atom3;
angles[index].angle = angle;
angles[index].k = k;
}
ForceImpl* HarmonicAngleForce::createImpl() {
return new HarmonicAngleForceImpl(*this);
}
/* -------------------------------------------------------------------------- *
* 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/OpenMMContextImpl.h"
#include "internal/HarmonicAngleForceImpl.h"
#include "kernels.h"
using namespace OpenMM;
using std::pair;
using std::vector;
using std::set;
HarmonicAngleForceImpl::HarmonicAngleForceImpl(HarmonicAngleForce& owner) : owner(owner) {
}
HarmonicAngleForceImpl::~HarmonicAngleForceImpl() {
}
void HarmonicAngleForceImpl::initialize(OpenMMContextImpl& context) {
kernel = context.getPlatform().createKernel(CalcHarmonicAngleForceKernel::Name(), context);
dynamic_cast<CalcHarmonicAngleForceKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner);
}
void HarmonicAngleForceImpl::calcForces(OpenMMContextImpl& context, Stream& forces) {
dynamic_cast<CalcHarmonicAngleForceKernel&>(kernel.getImpl()).executeForces(context);
}
double HarmonicAngleForceImpl::calcEnergy(OpenMMContextImpl& context) {
return dynamic_cast<CalcHarmonicAngleForceKernel&>(kernel.getImpl()).executeEnergy(context);
}
std::vector<std::string> HarmonicAngleForceImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(CalcHarmonicAngleForceKernel::Name());
return names;
}
/* -------------------------------------------------------------------------- *
* 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 "OpenMMException.h"
#include "HarmonicBondForce.h"
#include "internal/HarmonicBondForceImpl.h"
using namespace OpenMM;
HarmonicBondForce::HarmonicBondForce(int numBonds) : bonds(numBonds) {
}
void HarmonicBondForce::getBondParameters(int index, int& atom1, int& atom2, double& length, double& k) const {
atom1 = bonds[index].atom1;
atom2 = bonds[index].atom2;
length = bonds[index].length;
k = bonds[index].k;
}
void HarmonicBondForce::setBondParameters(int index, int atom1, int atom2, double length, double k) {
bonds[index].atom1 = atom1;
bonds[index].atom2 = atom2;
bonds[index].length = length;
bonds[index].k = k;
}
ForceImpl* HarmonicBondForce::createImpl() {
return new HarmonicBondForceImpl(*this);
}
/* -------------------------------------------------------------------------- *
* 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/OpenMMContextImpl.h"
#include "internal/HarmonicBondForceImpl.h"
#include "kernels.h"
using namespace OpenMM;
using std::pair;
using std::vector;
using std::set;
HarmonicBondForceImpl::HarmonicBondForceImpl(HarmonicBondForce& owner) : owner(owner) {
}
HarmonicBondForceImpl::~HarmonicBondForceImpl() {
}
void HarmonicBondForceImpl::initialize(OpenMMContextImpl& context) {
kernel = context.getPlatform().createKernel(CalcHarmonicBondForceKernel::Name(), context);
dynamic_cast<CalcHarmonicBondForceKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner);
}
void HarmonicBondForceImpl::calcForces(OpenMMContextImpl& context, Stream& forces) {
dynamic_cast<CalcHarmonicBondForceKernel&>(kernel.getImpl()).executeForces(context);
}
double HarmonicBondForceImpl::calcEnergy(OpenMMContextImpl& context) {
return dynamic_cast<CalcHarmonicBondForceKernel&>(kernel.getImpl()).executeEnergy(context);
}
std::vector<std::string> HarmonicBondForceImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(CalcHarmonicBondForceKernel::Name());
return names;
}
...@@ -31,42 +31,41 @@ ...@@ -31,42 +31,41 @@
#include "Force.h" #include "Force.h"
#include "OpenMMException.h" #include "OpenMMException.h"
#include "StandardMMForceField.h" #include "NonbondedForce.h"
#include "internal/StandardMMForceFieldImpl.h" #include "internal/NonbondedForceImpl.h"
using namespace OpenMM; using namespace OpenMM;
StandardMMForceField::StandardMMForceField(int numAtoms, int numBonds, int numAngles, int numPeriodicTorsions, int numRBTorsions, int numNonbonded14) : NonbondedForce::NonbondedForce(int numAtoms, int numNonbonded14) : atoms(numAtoms), nb14s(numNonbonded14),
atoms(numAtoms), bonds(numBonds), angles(numAngles), periodicTorsions(numPeriodicTorsions), rbTorsions(numRBTorsions), nb14s(numNonbonded14),
nonbondedMethod(NoCutoff), cutoffDistance(1.0) { nonbondedMethod(NoCutoff), cutoffDistance(1.0) {
periodicBoxVectors[0] = Vec3(2, 0, 0); periodicBoxVectors[0] = Vec3(2, 0, 0);
periodicBoxVectors[1] = Vec3(0, 2, 0); periodicBoxVectors[1] = Vec3(0, 2, 0);
periodicBoxVectors[2] = Vec3(0, 0, 2); periodicBoxVectors[2] = Vec3(0, 0, 2);
} }
StandardMMForceField::NonbondedMethod StandardMMForceField::getNonbondedMethod() const { NonbondedForce::NonbondedMethod NonbondedForce::getNonbondedMethod() const {
return nonbondedMethod; return nonbondedMethod;
} }
void StandardMMForceField::setNonbondedMethod(NonbondedMethod method) { void NonbondedForce::setNonbondedMethod(NonbondedMethod method) {
nonbondedMethod = method; nonbondedMethod = method;
} }
double StandardMMForceField::getCutoffDistance() const { double NonbondedForce::getCutoffDistance() const {
return cutoffDistance; return cutoffDistance;
} }
void StandardMMForceField::setCutoffDistance(double distance) { void NonbondedForce::setCutoffDistance(double distance) {
cutoffDistance = distance; cutoffDistance = distance;
} }
void StandardMMForceField::getPeriodicBoxVectors(Vec3& a, Vec3& b, Vec3& c) const { void NonbondedForce::getPeriodicBoxVectors(Vec3& a, Vec3& b, Vec3& c) const {
a = periodicBoxVectors[0]; a = periodicBoxVectors[0];
b = periodicBoxVectors[1]; b = periodicBoxVectors[1];
c = periodicBoxVectors[2]; c = periodicBoxVectors[2];
} }
void StandardMMForceField::setPeriodicBoxVectors(Vec3 a, Vec3 b, Vec3 c) { void NonbondedForce::setPeriodicBoxVectors(Vec3 a, Vec3 b, Vec3 c) {
if (a[1] != 0.0 || a[2] != 0.0) if (a[1] != 0.0 || a[2] != 0.0)
throw OpenMMException("First periodic box vector must be parallel to x."); throw OpenMMException("First periodic box vector must be parallel to x.");
if (b[0] != 0.0 || b[2] != 0.0) if (b[0] != 0.0 || b[2] != 0.0)
...@@ -78,95 +77,19 @@ void StandardMMForceField::setPeriodicBoxVectors(Vec3 a, Vec3 b, Vec3 c) { ...@@ -78,95 +77,19 @@ void StandardMMForceField::setPeriodicBoxVectors(Vec3 a, Vec3 b, Vec3 c) {
periodicBoxVectors[2] = c; periodicBoxVectors[2] = c;
} }
void StandardMMForceField::getAtomParameters(int index, double& charge, double& radius, double& depth) const { void NonbondedForce::getAtomParameters(int index, double& charge, double& radius, double& depth) const {
charge = atoms[index].charge; charge = atoms[index].charge;
radius = atoms[index].radius; radius = atoms[index].radius;
depth = atoms[index].depth; depth = atoms[index].depth;
} }
void StandardMMForceField::setAtomParameters(int index, double charge, double radius, double depth) { void NonbondedForce::setAtomParameters(int index, double charge, double radius, double depth) {
atoms[index].charge = charge; atoms[index].charge = charge;
atoms[index].radius = radius; atoms[index].radius = radius;
atoms[index].depth = depth; atoms[index].depth = depth;
} }
void StandardMMForceField::getBondParameters(int index, int& atom1, int& atom2, double& length, double& k) const { void NonbondedForce::getNonbonded14Parameters(int index, int& atom1, int& atom2, double& charge, double& radius, double& depth) const {
atom1 = bonds[index].atom1;
atom2 = bonds[index].atom2;
length = bonds[index].length;
k = bonds[index].k;
}
void StandardMMForceField::setBondParameters(int index, int atom1, int atom2, double length, double k) {
bonds[index].atom1 = atom1;
bonds[index].atom2 = atom2;
bonds[index].length = length;
bonds[index].k = k;
}
void StandardMMForceField::getAngleParameters(int index, int& atom1, int& atom2, int& atom3, double& angle, double& k) const {
atom1 = angles[index].atom1;
atom2 = angles[index].atom2;
atom3 = angles[index].atom3;
angle = angles[index].angle;
k = angles[index].k;
}
void StandardMMForceField::setAngleParameters(int index, int atom1, int atom2, int atom3, double angle, double k) {
angles[index].atom1 = atom1;
angles[index].atom2 = atom2;
angles[index].atom3 = atom3;
angles[index].angle = angle;
angles[index].k = k;
}
void StandardMMForceField::getPeriodicTorsionParameters(int index, int& atom1, int& atom2, int& atom3, int& atom4, int& periodicity, double& phase, double& k) const {
atom1 = periodicTorsions[index].atom1;
atom2 = periodicTorsions[index].atom2;
atom3 = periodicTorsions[index].atom3;
atom4 = periodicTorsions[index].atom4;
periodicity = periodicTorsions[index].periodicity;
phase = periodicTorsions[index].phase;
k = periodicTorsions[index].k;
}
void StandardMMForceField::setPeriodicTorsionParameters(int index, int atom1, int atom2, int atom3, int atom4, int periodicity, double phase, double k) {
periodicTorsions[index].atom1 = atom1;
periodicTorsions[index].atom2 = atom2;
periodicTorsions[index].atom3 = atom3;
periodicTorsions[index].atom4 = atom4;
periodicTorsions[index].periodicity = periodicity;
periodicTorsions[index].phase = phase;
periodicTorsions[index].k = k;
}
void StandardMMForceField::getRBTorsionParameters(int index, int& atom1, int& atom2, int& atom3, int& atom4, double& c0, double& c1, double& c2, double& c3, double& c4, double& c5) const {
atom1 = rbTorsions[index].atom1;
atom2 = rbTorsions[index].atom2;
atom3 = rbTorsions[index].atom3;
atom4 = rbTorsions[index].atom4;
c0 = rbTorsions[index].c[0];
c1 = rbTorsions[index].c[1];
c2 = rbTorsions[index].c[2];
c3 = rbTorsions[index].c[3];
c4 = rbTorsions[index].c[4];
c5 = rbTorsions[index].c[5];
}
void StandardMMForceField::setRBTorsionParameters(int index, int atom1, int atom2, int atom3, int atom4, double c0, double c1, double c2, double c3, double c4, double c5) {
rbTorsions[index].atom1 = atom1;
rbTorsions[index].atom2 = atom2;
rbTorsions[index].atom3 = atom3;
rbTorsions[index].atom4 = atom4;
rbTorsions[index].c[0] = c0;
rbTorsions[index].c[1] = c1;
rbTorsions[index].c[2] = c2;
rbTorsions[index].c[3] = c3;
rbTorsions[index].c[4] = c4;
rbTorsions[index].c[5] = c5;
}
void StandardMMForceField::getNonbonded14Parameters(int index, int& atom1, int& atom2, double& charge, double& radius, double& depth) const {
atom1 = nb14s[index].atom1; atom1 = nb14s[index].atom1;
atom2 = nb14s[index].atom2; atom2 = nb14s[index].atom2;
charge = nb14s[index].charge; charge = nb14s[index].charge;
...@@ -174,7 +97,7 @@ void StandardMMForceField::getNonbonded14Parameters(int index, int& atom1, int& ...@@ -174,7 +97,7 @@ void StandardMMForceField::getNonbonded14Parameters(int index, int& atom1, int&
depth = nb14s[index].depth; depth = nb14s[index].depth;
} }
void StandardMMForceField::setNonbonded14Parameters(int index, int atom1, int atom2, double charge, double radius, double depth) { void NonbondedForce::setNonbonded14Parameters(int index, int atom1, int atom2, double charge, double radius, double depth) {
nb14s[index].atom1 = atom1; nb14s[index].atom1 = atom1;
nb14s[index].atom2 = atom2; nb14s[index].atom2 = atom2;
nb14s[index].charge = charge; nb14s[index].charge = charge;
...@@ -182,6 +105,6 @@ void StandardMMForceField::setNonbonded14Parameters(int index, int atom1, int at ...@@ -182,6 +105,6 @@ void StandardMMForceField::setNonbonded14Parameters(int index, int atom1, int at
nb14s[index].depth = depth; nb14s[index].depth = depth;
} }
ForceImpl* StandardMMForceField::createImpl() { ForceImpl* NonbondedForce::createImpl() {
return new StandardMMForceFieldImpl(*this); return new NonbondedForceImpl(*this);
} }
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "internal/OpenMMContextImpl.h" #include "internal/OpenMMContextImpl.h"
#include "internal/StandardMMForceFieldImpl.h" #include "internal/NonbondedForceImpl.h"
#include "kernels.h" #include "kernels.h"
using namespace OpenMM; using namespace OpenMM;
...@@ -38,43 +38,52 @@ using std::pair; ...@@ -38,43 +38,52 @@ using std::pair;
using std::vector; using std::vector;
using std::set; using std::set;
StandardMMForceFieldImpl::StandardMMForceFieldImpl(StandardMMForceField& owner) : owner(owner) { NonbondedForceImpl::NonbondedForceImpl(NonbondedForce& owner) : owner(owner) {
} }
StandardMMForceFieldImpl::~StandardMMForceFieldImpl() { NonbondedForceImpl::~NonbondedForceImpl() {
} }
void StandardMMForceFieldImpl::initialize(OpenMMContextImpl& context) { void NonbondedForceImpl::initialize(OpenMMContextImpl& context) {
kernel = context.getPlatform().createKernel(CalcStandardMMForceFieldKernel::Name(), context); kernel = context.getPlatform().createKernel(CalcNonbondedForceKernel::Name(), context);
// See if the system contains a HarmonicBondForce. If so, use it to identify exclusions.
System& system = context.getSystem();
vector<set<int> > exclusions(owner.getNumAtoms()); vector<set<int> > exclusions(owner.getNumAtoms());
vector<vector<int> > bondIndices(owner.getNumBonds()); for (int i = 0; i < system.getNumForces(); i++) {
set<pair<int, int> > bonded14set; if (dynamic_cast<HarmonicBondForce*>(&system.getForce(i)) != NULL) {
for (int i = 0; i < owner.getNumBonds(); ++i) { const HarmonicBondForce& force = dynamic_cast<const HarmonicBondForce&>(system.getForce(i));
int atom1, atom2; vector<vector<int> > bondIndices(force.getNumBonds());
double length, k; set<pair<int, int> > bonded14set;
owner.getBondParameters(i, atom1, atom2, length, k); for (int i = 0; i < force.getNumBonds(); ++i) {
bondIndices[i].push_back(atom1); int atom1, atom2;
bondIndices[i].push_back(atom2); double length, k;
force.getBondParameters(i, atom1, atom2, length, k);
bondIndices[i].push_back(atom1);
bondIndices[i].push_back(atom2);
}
findExclusions(bondIndices, exclusions, bonded14set);
}
} }
findExclusions(bondIndices, exclusions, bonded14set); dynamic_cast<CalcNonbondedForceKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner, exclusions);
dynamic_cast<CalcStandardMMForceFieldKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner, exclusions);
} }
void StandardMMForceFieldImpl::calcForces(OpenMMContextImpl& context, Stream& forces) { void NonbondedForceImpl::calcForces(OpenMMContextImpl& context, Stream& forces) {
dynamic_cast<CalcStandardMMForceFieldKernel&>(kernel.getImpl()).executeForces(context); dynamic_cast<CalcNonbondedForceKernel&>(kernel.getImpl()).executeForces(context);
} }
double StandardMMForceFieldImpl::calcEnergy(OpenMMContextImpl& context) { double NonbondedForceImpl::calcEnergy(OpenMMContextImpl& context) {
return dynamic_cast<CalcStandardMMForceFieldKernel&>(kernel.getImpl()).executeEnergy(context); return dynamic_cast<CalcNonbondedForceKernel&>(kernel.getImpl()).executeEnergy(context);
} }
std::vector<std::string> StandardMMForceFieldImpl::getKernelNames() { std::vector<std::string> NonbondedForceImpl::getKernelNames() {
std::vector<std::string> names; std::vector<std::string> names;
names.push_back(CalcStandardMMForceFieldKernel::Name()); names.push_back(CalcNonbondedForceKernel::Name());
return names; return names;
} }
void StandardMMForceFieldImpl::findExclusions(const vector<vector<int> >& bondIndices, vector<set<int> >& exclusions, set<pair<int, int> >& bonded14Indices) const { void NonbondedForceImpl::findExclusions(const vector<vector<int> >& bondIndices, vector<set<int> >& exclusions, set<pair<int, int> >& bonded14Indices) const {
vector<set<int> > bonded12(exclusions.size()); vector<set<int> > bonded12(exclusions.size());
for (int i = 0; i < (int) bondIndices.size(); ++i) { for (int i = 0; i < (int) bondIndices.size(); ++i) {
bonded12[bondIndices[i][0]].insert(bondIndices[i][1]); bonded12[bondIndices[i][0]].insert(bondIndices[i][1]);
...@@ -91,7 +100,7 @@ void StandardMMForceFieldImpl::findExclusions(const vector<vector<int> >& bondIn ...@@ -91,7 +100,7 @@ void StandardMMForceFieldImpl::findExclusions(const vector<vector<int> >& bondIn
} }
} }
void StandardMMForceFieldImpl::addExclusionsToSet(const vector<set<int> >& bonded12, set<int>& exclusions, int baseAtom, int fromAtom, int currentLevel) const { void NonbondedForceImpl::addExclusionsToSet(const vector<set<int> >& bonded12, set<int>& exclusions, int baseAtom, int fromAtom, int currentLevel) const {
for (set<int>::const_iterator iter = bonded12[fromAtom].begin(); iter != bonded12[fromAtom].end(); ++iter) { for (set<int>::const_iterator iter = bonded12[fromAtom].begin(); iter != bonded12[fromAtom].end(); ++iter) {
if (*iter != baseAtom) if (*iter != baseAtom)
exclusions.insert(*iter); exclusions.insert(*iter);
......
/* -------------------------------------------------------------------------- *
* 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 "OpenMMException.h"
#include "PeriodicTorsionForce.h"
#include "internal/PeriodicTorsionForceImpl.h"
using namespace OpenMM;
PeriodicTorsionForce::PeriodicTorsionForce(int numTorsions) : periodicTorsions(numTorsions) {
}
void PeriodicTorsionForce::getTorsionParameters(int index, int& atom1, int& atom2, int& atom3, int& atom4, int& periodicity, double& phase, double& k) const {
atom1 = periodicTorsions[index].atom1;
atom2 = periodicTorsions[index].atom2;
atom3 = periodicTorsions[index].atom3;
atom4 = periodicTorsions[index].atom4;
periodicity = periodicTorsions[index].periodicity;
phase = periodicTorsions[index].phase;
k = periodicTorsions[index].k;
}
void PeriodicTorsionForce::setTorsionParameters(int index, int atom1, int atom2, int atom3, int atom4, int periodicity, double phase, double k) {
periodicTorsions[index].atom1 = atom1;
periodicTorsions[index].atom2 = atom2;
periodicTorsions[index].atom3 = atom3;
periodicTorsions[index].atom4 = atom4;
periodicTorsions[index].periodicity = periodicity;
periodicTorsions[index].phase = phase;
periodicTorsions[index].k = k;
}
ForceImpl* PeriodicTorsionForce::createImpl() {
return new PeriodicTorsionForceImpl(*this);
}
/* -------------------------------------------------------------------------- *
* 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/OpenMMContextImpl.h"
#include "internal/PeriodicTorsionForceImpl.h"
#include "kernels.h"
using namespace OpenMM;
using std::pair;
using std::vector;
using std::set;
PeriodicTorsionForceImpl::PeriodicTorsionForceImpl(PeriodicTorsionForce& owner) : owner(owner) {
}
PeriodicTorsionForceImpl::~PeriodicTorsionForceImpl() {
}
void PeriodicTorsionForceImpl::initialize(OpenMMContextImpl& context) {
kernel = context.getPlatform().createKernel(CalcPeriodicTorsionForceKernel::Name(), context);
dynamic_cast<CalcPeriodicTorsionForceKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner);
}
void PeriodicTorsionForceImpl::calcForces(OpenMMContextImpl& context, Stream& forces) {
dynamic_cast<CalcPeriodicTorsionForceKernel&>(kernel.getImpl()).executeForces(context);
}
double PeriodicTorsionForceImpl::calcEnergy(OpenMMContextImpl& context) {
return dynamic_cast<CalcPeriodicTorsionForceKernel&>(kernel.getImpl()).executeEnergy(context);
}
std::vector<std::string> PeriodicTorsionForceImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(CalcPeriodicTorsionForceKernel::Name());
return names;
}
/* -------------------------------------------------------------------------- *
* 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 "OpenMMException.h"
#include "RBTorsionForce.h"
#include "internal/RBTorsionForceImpl.h"
using namespace OpenMM;
RBTorsionForce::RBTorsionForce(int numTorsions) : rbTorsions(numTorsions) {
}
void RBTorsionForce::getTorsionParameters(int index, int& atom1, int& atom2, int& atom3, int& atom4, double& c0, double& c1, double& c2, double& c3, double& c4, double& c5) const {
atom1 = rbTorsions[index].atom1;
atom2 = rbTorsions[index].atom2;
atom3 = rbTorsions[index].atom3;
atom4 = rbTorsions[index].atom4;
c0 = rbTorsions[index].c[0];
c1 = rbTorsions[index].c[1];
c2 = rbTorsions[index].c[2];
c3 = rbTorsions[index].c[3];
c4 = rbTorsions[index].c[4];
c5 = rbTorsions[index].c[5];
}
void RBTorsionForce::setTorsionParameters(int index, int atom1, int atom2, int atom3, int atom4, double c0, double c1, double c2, double c3, double c4, double c5) {
rbTorsions[index].atom1 = atom1;
rbTorsions[index].atom2 = atom2;
rbTorsions[index].atom3 = atom3;
rbTorsions[index].atom4 = atom4;
rbTorsions[index].c[0] = c0;
rbTorsions[index].c[1] = c1;
rbTorsions[index].c[2] = c2;
rbTorsions[index].c[3] = c3;
rbTorsions[index].c[4] = c4;
rbTorsions[index].c[5] = c5;
}
ForceImpl* RBTorsionForce::createImpl() {
return new RBTorsionForceImpl(*this);
}
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