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

Changed how kernels get initialized. StandardMMForceField now has you set the...

Changed how kernels get initialized.  StandardMMForceField now has you set the 1-4 interactions explicitly.  CMMotionRemover allows the removal frequency to be set.
parent bf93e42f
...@@ -32,8 +32,16 @@ ...@@ -32,8 +32,16 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * * USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "AndersenThermostat.h"
#include "BrownianIntegrator.h"
#include "CMMotionRemover.h"
#include "GBSAOBCForceField.h"
#include "KernelImpl.h" #include "KernelImpl.h"
#include "LangevinIntegrator.h"
#include "StandardMMForceField.h"
#include "Stream.h" #include "Stream.h"
#include "System.h"
#include "VerletIntegrator.h"
#include <set> #include <set>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -56,50 +64,28 @@ public: ...@@ -56,50 +64,28 @@ public:
CalcStandardMMForceFieldKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) { CalcStandardMMForceFieldKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the values of all the force field parameters. * Initialize the kernel.
* *
* @param bondIndices the two atoms connected by each bond term * @param system the System this kernel will be applied to
* @param bondParameters the force parameters (length, k) for each bond term * @param force the StandardMMForceField this kernel will be used for
* @param angleIndices the three atoms connected by each angle term * @param exclusions the i'th element lists the indices of all atoms with which the i'th atom should not interact through
* @param angleParameters the force parameters (angle, k) for each angle term * nonbonded forces. Bonded 1-4 pairs are also included in this list, since they should be omitted from
* @param periodicTorsionIndices the four atoms connected by each periodic torsion term * the standard nonbonded calculation.
* @param periodicTorsionParameters the force parameters (k, phase, periodicity) for each periodic torsion term
* @param rbTorsionIndices the four atoms connected by each Ryckaert-Bellemans torsion term
* @param rbTorsionParameters the coefficients (in order of increasing powers) for each Ryckaert-Bellemans torsion term
* @param bonded14Indices each element contains the indices of two atoms whose nonbonded interactions should be reduced since
* they form a bonded 1-4 pair
* @param lj14Scale the factor by which van der Waals interactions should be reduced for bonded 1-4 pairs
* @param coulomb14Scale the factor by which Coulomb interactions should be reduced for bonded 1-4 pairs
* @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
* the standard nonbonded calculation.
* @param nonbondedParameters the nonbonded force parameters (charge, sigma, epsilon) for each atom
* @param nonbondedMethod the method to use for handling long range nonbonded interactions
* @param nonbondedCutoff the cutoff distance for nonbonded interactions (if nonbondedMethod involves a cutoff)
* @param periodicBoxSize the size of the periodic box (if nonbondedMethod involves a periodic boundary conditions)
*/ */
virtual void initialize(const std::vector<std::vector<int> >& bondIndices, const std::vector<std::vector<double> >& bondParameters, virtual void initialize(const System& system, const StandardMMForceField& force, const std::vector<std::set<int> >& exclusions) = 0;
const std::vector<std::vector<int> >& angleIndices, const std::vector<std::vector<double> >& angleParameters,
const std::vector<std::vector<int> >& periodicTorsionIndices, const std::vector<std::vector<double> >& periodicTorsionParameters,
const std::vector<std::vector<int> >& rbTorsionIndices, const std::vector<std::vector<double> >& rbTorsionParameters,
const std::vector<std::vector<int> >& bonded14Indices, double lj14Scale, double coulomb14Scale,
const std::vector<std::set<int> >& exclusions, const std::vector<std::vector<double> >& nonbondedParameters,
NonbondedMethod nonbondedMethod, double nonbondedCutoff, double periodicBoxSize[3]) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces.
* *
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom * @param context the context in which to execute this kernel
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom. On entry, this contains the forces that
* have been calculated so far. The kernel should add its own forces to the values already in the stream.
*/ */
virtual void executeForces(const Stream& positions, Stream& forces) = 0; virtual void executeForces(OpenMMContextImpl& context) = 0;
/** /**
* Execute the kernel to calculate the energy. * Execute the kernel to calculate the energy.
* *
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom * @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 StandardMMForceField
*/ */
virtual double executeEnergy(const Stream& positions) = 0; virtual double executeEnergy(OpenMMContextImpl& context) = 0;
}; };
/** /**
...@@ -113,28 +99,25 @@ public: ...@@ -113,28 +99,25 @@ public:
CalcGBSAOBCForceFieldKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) { CalcGBSAOBCForceFieldKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the values of all the force field parameters. * Initialize the kernel.
* *
* @param atomParameters the force parameters (charge, atomic radius, scaling factor) for each atom * @param system the System this kernel will be applied to
* @param solventDielectric the dielectric constant of the solvent * @param force the GBSAOBCForceField this kernel will be used for
* @param soluteDielectric the dielectric constant of the solute
*/ */
virtual void initialize(const std::vector<std::vector<double> >& atomParameters, double solventDielectric, double soluteDielectric) = 0; virtual void initialize(const System& system, const GBSAOBCForceField& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces.
* *
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom * @param context the context in which to execute this kernel
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom. On entry, this contains the forces that
* have been calculated so far. The kernel should add its own forces to the values already in the stream.
*/ */
virtual void executeForces(const Stream& positions, Stream& forces) = 0; virtual void executeForces(OpenMMContextImpl& context) = 0;
/** /**
* Execute the kernel to calculate the energy. * Execute the kernel to calculate the energy.
* *
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom * @param context the context in which to execute this kernel
* @return the potential energy due to the GBSAOBCForceField * @return the potential energy due to the GBSAOBCForceField
*/ */
virtual double executeEnergy(const Stream& positions) = 0; virtual double executeEnergy(OpenMMContextImpl& context) = 0;
}; };
/** /**
...@@ -148,23 +131,19 @@ public: ...@@ -148,23 +131,19 @@ public:
IntegrateVerletStepKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) { IntegrateVerletStepKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up all parameters related to integrator. * Initialize the kernel.
* *
* @param masses the mass of each atom * @param system the System this kernel will be applied to
* @param constraintIndices each element contains the indices of two atoms whose distance should be constrained * @param integrator the VerletIntegrator this kernel will be used for
* @param constraintLengths the required distance between each pair of constrained atoms
*/ */
virtual void initialize(const std::vector<double>& masses, const std::vector<std::vector<int> >& constraintIndices, virtual void initialize(const System& system, const VerletIntegrator& integrator) = 0;
const std::vector<double>& constraintLengths) = 0;
/** /**
* Execute the kernel. * Execute the kernel.
* *
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom * @param context the context in which to execute this kernel
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom * @param integrator the VerletIntegrator this kernel is being used for
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom
* @param stepSize the integration step size
*/ */
virtual void execute(Stream& positions, Stream& velocities, const Stream& forces, double stepSize) = 0; virtual void execute(OpenMMContextImpl& context, const VerletIntegrator& integrator) = 0;
}; };
/** /**
...@@ -178,25 +157,19 @@ public: ...@@ -178,25 +157,19 @@ public:
IntegrateLangevinStepKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) { IntegrateLangevinStepKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up all parameters related to integrator. * Initialize the kernel.
* *
* @param masses the mass of each atom * @param system the System this kernel will be applied to
* @param constraintIndices each element contains the indices of two atoms whose distance should be constrained * @param integrator the LangevinIntegrator this kernel will be used for
* @param constraintLengths the required distance between each pair of constrained atoms
*/ */
virtual void initialize(const std::vector<double>& masses, const std::vector<std::vector<int> >& constraintIndices, virtual void initialize(const System& system, const LangevinIntegrator& integrator) = 0;
const std::vector<double>& constraintLengths) = 0;
/** /**
* Execute the kernel. * Execute the kernel.
* *
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom * @param context the context in which to execute this kernel
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom * @param integrator the LangevinIntegrator this kernel is being used for
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom
* @param temperature the temperature of the heat bath
* @param friction the friction coefficient coupling the system to the heat bath
* @param stepSize the integration step size
*/ */
virtual void execute(Stream& positions, Stream& velocities, const Stream& forces, double temperature, double friction, double stepSize) = 0; virtual void execute(OpenMMContextImpl& context, const LangevinIntegrator& integrator) = 0;
}; };
/** /**
...@@ -210,25 +183,19 @@ public: ...@@ -210,25 +183,19 @@ public:
IntegrateBrownianStepKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) { IntegrateBrownianStepKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up all parameters related to integrator. * Initialize the kernel.
* *
* @param masses the mass of each atom * @param system the System this kernel will be applied to
* @param constraintIndices each element contains the indices of two atoms whose distance should be constrained * @param integrator the BrownianIntegrator this kernel will be used for
* @param constraintLengths the required distance between each pair of constrained atoms
*/ */
virtual void initialize(const std::vector<double>& masses, const std::vector<std::vector<int> >& constraintIndices, virtual void initialize(const System& system, const BrownianIntegrator& integrator) = 0;
const std::vector<double>& constraintLengths) = 0;
/** /**
* Execute the kernel. * Execute the kernel.
* *
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom * @param context the context in which to execute this kernel
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom * @param integrator the BrownianIntegrator this kernel is being used for
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom
* @param temperature the temperature of the heat bath
* @param friction the friction coefficient coupling the system to the heat bath
* @param stepSize the integration step size
*/ */
virtual void execute(Stream& positions, Stream& velocities, const Stream& forces, double temperature, double friction, double stepSize) = 0; virtual void execute(OpenMMContextImpl& context, const BrownianIntegrator& integrator) = 0;
}; };
/** /**
...@@ -242,20 +209,18 @@ public: ...@@ -242,20 +209,18 @@ public:
ApplyAndersenThermostatKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) { ApplyAndersenThermostatKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the values of unchanging parameters. * Initialize the kernel.
* *
* @param masses the mass of each atom * @param system the System this kernel will be applied to
* @param thermostat the AndersenThermostat this kernel will be used for
*/ */
virtual void initialize(const std::vector<double>& masses) = 0; virtual void initialize(const System& system, const AndersenThermostat& thermostat) = 0;
/** /**
* Execute the kernel. * Execute the kernel.
* *
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom * @param context the context in which to execute this kernel
* @param temperature the temperature of the heat bath
* @param collisionFrequency the frequency at which atom collide with particles in the heat bath
* @param stepSize the integration step size
*/ */
virtual void execute(Stream& velocities, double temperature, double collisionFrequency, double stepSize) = 0; virtual void execute(OpenMMContextImpl& context) = 0;
}; };
/** /**
...@@ -269,18 +234,17 @@ public: ...@@ -269,18 +234,17 @@ public:
CalcKineticEnergyKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) { CalcKineticEnergyKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the atomic masses. * Initialize the kernel.
* *
* @param masses the mass of each atom * @param system the System this kernel will be applied to
*/ */
virtual void initialize(const std::vector<double>& masses) = 0; virtual void initialize(const System& system) = 0;
/** /**
* Execute the kernel. * Execute the kernel.
* *
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom * @param context the context in which to execute this kernel
* @return the kinetic energy of the system
*/ */
virtual double execute(const Stream& velocities) = 0; virtual double execute(OpenMMContextImpl& context) = 0;
}; };
/** /**
...@@ -294,17 +258,18 @@ public: ...@@ -294,17 +258,18 @@ public:
RemoveCMMotionKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) { RemoveCMMotionKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the atomic masses. * Initialize the kernel.
* *
* @param masses the mass of each atom * @param system the System this kernel will be applied to
* @param force the CMMotionRemover this kernel will be used for
*/ */
virtual void initialize(const std::vector<double>& masses) = 0; virtual void initialize(const System& system, const CMMotionRemover& force) = 0;
/** /**
* Execute the kernel. * Execute the kernel.
* *
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom * @param context the context in which to execute this kernel
*/ */
virtual void execute(Stream& velocities) = 0; virtual void execute(OpenMMContextImpl& context) = 0;
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -48,9 +48,23 @@ public: ...@@ -48,9 +48,23 @@ public:
/** /**
* Create a CMMotionRemover. * Create a CMMotionRemover.
*/ */
CMMotionRemover(); CMMotionRemover(int frequency = 1);
/**
* Get the frequency (in time steps) at which center of mass motion should be removed
*/
int getFrequency() const {
return frequency;
}
/**
* Set the frequency (in time steps) at which center of mass motion should be removed
*/
void setFrequency(int freq) {
frequency = freq;
}
protected: protected:
ForceImpl* createImpl(); ForceImpl* createImpl();
private:
int frequency;
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -80,8 +80,9 @@ public: ...@@ -80,8 +80,9 @@ public:
* @param numAngles the number of harmonic bond angle 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 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 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
*/ */
StandardMMForceField(int numAtoms, int numBonds, int numAngles, int numPeriodicTorsions, int numRBTorsions); StandardMMForceField(int numAtoms, int numBonds, int numAngles, int numPeriodicTorsions, int numRBTorsions, int numNonbonded14);
/** /**
* Get the number of atoms in the system. * Get the number of atoms in the system.
*/ */
...@@ -112,10 +113,16 @@ public: ...@@ -112,10 +113,16 @@ public:
int getNumRBTorsions() const { int getNumRBTorsions() const {
return rbTorsions.size(); return rbTorsions.size();
} }
/**
* Get the number of nonbonded 1-4 terms in the potential function
*/
int getNumNonbonded14() const {
return nb14s.size();
}
/** /**
* Get the method used for handling long range nonbonded interactions. * Get the method used for handling long range nonbonded interactions.
*/ */
NonbondedMethod getNonbondedMethod(); NonbondedMethod getNonbondedMethod() const;
/** /**
* Set the method used for handling long range nonbonded interactions. * Set the method used for handling long range nonbonded interactions.
*/ */
...@@ -124,7 +131,7 @@ public: ...@@ -124,7 +131,7 @@ public:
* Get the cutoff distance (in nm) being used for nonbonded interactions. If the NonbondedMethod in use * Get the cutoff distance (in nm) being used for nonbonded interactions. If the NonbondedMethod in use
* does not use cutoffs, this value will have no effect. * does not use cutoffs, this value will have no effect.
*/ */
double getCutoffDistance(); double getCutoffDistance() const;
/** /**
* Set the cutoff distance (in nm) being used for nonbonded interactions. If the NonbondedMethod in use * Set the cutoff distance (in nm) being used for nonbonded interactions. If the NonbondedMethod in use
* does not use cutoffs, this value will have no effect. * does not use cutoffs, this value will have no effect.
...@@ -138,7 +145,7 @@ public: ...@@ -138,7 +145,7 @@ public:
* @param y on exit, this contains the width of the periodic box along the y axis * @param y on exit, this contains the width of the periodic box along the y axis
* @param z on exit, this contains the width of the periodic box along the z axis * @param z on exit, this contains the width of the periodic box along the z axis
*/ */
void getPeriodicBoxSize(double& x, double& y, double& z); void getPeriodicBoxSize(double& x, double& y, double& z) const;
/** /**
* Set the dimensions of the periodic box (in nm). If the NonbondedMethod in use does not use periodic * Set the dimensions of the periodic box (in nm). If the NonbondedMethod in use does not use periodic
* boundary conditions, these values will have no effect. * boundary conditions, these values will have no effect.
...@@ -266,6 +273,28 @@ public: ...@@ -266,6 +273,28 @@ public:
* @param c5 the coefficient of the 5th 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); 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.
*
* @param index the index of the interaction for which to get parameters
* @param atom1 the index of the first atom involved in the interaction
* @param atom2 the index of the second atom involved in the interaction
* @param charge the scaled product of the atomic charges (i.e. the strength of the Coulomb interaction), measured in units of the proton charge
* @param radius the van der Waals radius of the atom (sigma in the Lennard Jones potential), measured in nm
* @param depth the well depth of the van der Waals interaction (epsilon in the Lennard Jones potential), measured in kJ/mol
*/
void getNonbonded14Parameters(int index, int& atom1, int& atom2, double& charge, double& radius, double& depth) const;
/**
* Set the force field parameters for a nonbonded 1-4 term.
*
* @param index the index of the interaction for which to get parameters
* @param atom1 the index of the first atom involved in the interaction
* @param atom2 the index of the second atom involved in the interaction
* @param charge the scaled product of the atomic charges (i.e. the strength of the Coulomb interaction), measured in units of the proton charge
* @param radius the van der Waals radius of the atom (sigma in the Lennard Jones potential), measured in nm
* @param depth the well depth of the van der Waals interaction (epsilon in the Lennard Jones potential), measured in kJ/mol
*/
void setNonbonded14Parameters(int index, int atom1, int atom2, double charge, double radius, double depth);
protected: protected:
ForceImpl* createImpl(); ForceImpl* createImpl();
private: private:
...@@ -274,6 +303,7 @@ private: ...@@ -274,6 +303,7 @@ private:
class AngleInfo; class AngleInfo;
class PeriodicTorsionInfo; class PeriodicTorsionInfo;
class RBTorsionInfo; class RBTorsionInfo;
class NB14Info;
NonbondedMethod nonbondedMethod; NonbondedMethod nonbondedMethod;
double cutoffDistance; double cutoffDistance;
double periodicBoxSize[3]; double periodicBoxSize[3];
...@@ -291,6 +321,7 @@ private: ...@@ -291,6 +321,7 @@ private:
std::vector<AngleInfo> angles; std::vector<AngleInfo> angles;
std::vector<PeriodicTorsionInfo> periodicTorsions; std::vector<PeriodicTorsionInfo> periodicTorsions;
std::vector<RBTorsionInfo> rbTorsions; std::vector<RBTorsionInfo> rbTorsions;
std::vector<NB14Info> nb14s;
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(pop) #pragma warning(pop)
...@@ -347,6 +378,16 @@ public: ...@@ -347,6 +378,16 @@ public:
} }
}; };
class StandardMMForceField::NB14Info {
public:
int atom1, atom2;
double charge, radius, depth;
NB14Info() {
atom1 = atom2 = -1;
charge = radius = depth = 0.0;
}
};
} // namespace OpenMM } // namespace OpenMM
#endif /*OPENMM_STANDARDMMFORCEFIELD_H_*/ #endif /*OPENMM_STANDARDMMFORCEFIELD_H_*/
...@@ -44,16 +44,11 @@ AndersenThermostatImpl::AndersenThermostatImpl(AndersenThermostat& owner) : owne ...@@ -44,16 +44,11 @@ AndersenThermostatImpl::AndersenThermostatImpl(AndersenThermostat& owner) : owne
void AndersenThermostatImpl::initialize(OpenMMContextImpl& context) { void AndersenThermostatImpl::initialize(OpenMMContextImpl& context) {
kernel = context.getPlatform().createKernel(ApplyAndersenThermostatKernel::Name(), context); kernel = context.getPlatform().createKernel(ApplyAndersenThermostatKernel::Name(), context);
const System& system = context.getSystem(); dynamic_cast<ApplyAndersenThermostatKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner);
vector<double> masses(system.getNumAtoms());
for (int i = 0; i < system.getNumAtoms(); ++i)
masses[i] = system.getAtomMass(i);
dynamic_cast<ApplyAndersenThermostatKernel&>(kernel.getImpl()).initialize(masses);
} }
void AndersenThermostatImpl::updateContextState(OpenMMContextImpl& context) { void AndersenThermostatImpl::updateContextState(OpenMMContextImpl& context) {
dynamic_cast<ApplyAndersenThermostatKernel&>(kernel.getImpl()).execute(context.getVelocities(), context.getParameter(AndersenThermostat::Temperature), dynamic_cast<ApplyAndersenThermostatKernel&>(kernel.getImpl()).execute(context);
context.getParameter(AndersenThermostat::CollisionFrequency), context.getIntegrator().getStepSize());
} }
std::map<std::string, double> AndersenThermostatImpl::getDefaultParameters() { std::map<std::string, double> AndersenThermostatImpl::getDefaultParameters() {
......
...@@ -62,7 +62,7 @@ void BrownianIntegrator::initialize(OpenMMContextImpl& contextRef) { ...@@ -62,7 +62,7 @@ void BrownianIntegrator::initialize(OpenMMContextImpl& contextRef) {
constraintIndices[i].push_back(atom2); constraintIndices[i].push_back(atom2);
constraintLengths[i] = distance; constraintLengths[i] = distance;
} }
dynamic_cast<IntegrateBrownianStepKernel&>(kernel.getImpl()).initialize(masses, constraintIndices, constraintLengths); dynamic_cast<IntegrateBrownianStepKernel&>(kernel.getImpl()).initialize(system, *this);
} }
vector<string> BrownianIntegrator::getKernelNames() { vector<string> BrownianIntegrator::getKernelNames() {
...@@ -75,8 +75,7 @@ void BrownianIntegrator::step(int steps) { ...@@ -75,8 +75,7 @@ void BrownianIntegrator::step(int steps) {
for (int i = 0; i < steps; ++i) { for (int i = 0; i < steps; ++i) {
context->updateContextState(); context->updateContextState();
context->calcForces(); context->calcForces();
dynamic_cast<IntegrateBrownianStepKernel&>(kernel.getImpl()).execute(context->getPositions(), context->getVelocities(), context->getForces(), temperature, dynamic_cast<IntegrateBrownianStepKernel&>(kernel.getImpl()).execute(*context, *this);
friction, getStepSize());
context->setTime(context->getTime()+getStepSize()); context->setTime(context->getTime()+getStepSize());
} }
} }
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
using namespace OpenMM; using namespace OpenMM;
CMMotionRemover::CMMotionRemover() { CMMotionRemover::CMMotionRemover(int frequency) : frequency(frequency) {
} }
ForceImpl* CMMotionRemover::createImpl() { ForceImpl* CMMotionRemover::createImpl() {
......
...@@ -45,14 +45,11 @@ CMMotionRemoverImpl::CMMotionRemoverImpl(CMMotionRemover& owner) : owner(owner) ...@@ -45,14 +45,11 @@ CMMotionRemoverImpl::CMMotionRemoverImpl(CMMotionRemover& owner) : owner(owner)
void CMMotionRemoverImpl::initialize(OpenMMContextImpl& context) { void CMMotionRemoverImpl::initialize(OpenMMContextImpl& context) {
kernel = context.getPlatform().createKernel(RemoveCMMotionKernel::Name(), context); kernel = context.getPlatform().createKernel(RemoveCMMotionKernel::Name(), context);
const System& system = context.getSystem(); const System& system = context.getSystem();
vector<double> masses(system.getNumAtoms()); dynamic_cast<RemoveCMMotionKernel&>(kernel.getImpl()).initialize(system, owner);
for (int i = 0; i < system.getNumAtoms(); ++i)
masses[i] = system.getAtomMass(i);
dynamic_cast<RemoveCMMotionKernel&>(kernel.getImpl()).initialize(masses);
} }
void CMMotionRemoverImpl::updateContextState(OpenMMContextImpl& context) { void CMMotionRemoverImpl::updateContextState(OpenMMContextImpl& context) {
dynamic_cast<RemoveCMMotionKernel&>(kernel.getImpl()).execute(context.getVelocities()); dynamic_cast<RemoveCMMotionKernel&>(kernel.getImpl()).execute(context);
} }
std::vector<std::string> CMMotionRemoverImpl::getKernelNames() { std::vector<std::string> CMMotionRemoverImpl::getKernelNames() {
......
...@@ -42,23 +42,15 @@ GBSAOBCForceFieldImpl::GBSAOBCForceFieldImpl(GBSAOBCForceField& owner) : owner(o ...@@ -42,23 +42,15 @@ GBSAOBCForceFieldImpl::GBSAOBCForceFieldImpl(GBSAOBCForceField& owner) : owner(o
void GBSAOBCForceFieldImpl::initialize(OpenMMContextImpl& context) { void GBSAOBCForceFieldImpl::initialize(OpenMMContextImpl& context) {
kernel = context.getPlatform().createKernel(CalcGBSAOBCForceFieldKernel::Name(), context); kernel = context.getPlatform().createKernel(CalcGBSAOBCForceFieldKernel::Name(), context);
vector<vector<double> > atomParameters(owner.getNumAtoms()); dynamic_cast<CalcGBSAOBCForceFieldKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner);
for (int i = 0; i < owner.getNumAtoms(); ++i) {
double charge, radius, scalingFactor;
owner.getAtomParameters(i, charge, radius, scalingFactor);
atomParameters[i].push_back(charge);
atomParameters[i].push_back(radius);
atomParameters[i].push_back(scalingFactor);
}
dynamic_cast<CalcGBSAOBCForceFieldKernel&>(kernel.getImpl()).initialize(atomParameters, owner.getSolventDielectric(), owner.getSoluteDielectric());
} }
void GBSAOBCForceFieldImpl::calcForces(OpenMMContextImpl& context, Stream& forces) { void GBSAOBCForceFieldImpl::calcForces(OpenMMContextImpl& context, Stream& forces) {
dynamic_cast<CalcGBSAOBCForceFieldKernel&>(kernel.getImpl()).executeForces(context.getPositions(), forces); dynamic_cast<CalcGBSAOBCForceFieldKernel&>(kernel.getImpl()).executeForces(context);
} }
double GBSAOBCForceFieldImpl::calcEnergy(OpenMMContextImpl& context) { double GBSAOBCForceFieldImpl::calcEnergy(OpenMMContextImpl& context) {
return dynamic_cast<CalcGBSAOBCForceFieldKernel&>(kernel.getImpl()).executeEnergy(context.getPositions()); return dynamic_cast<CalcGBSAOBCForceFieldKernel&>(kernel.getImpl()).executeEnergy(context);
} }
std::vector<std::string> GBSAOBCForceFieldImpl::getKernelNames() { std::vector<std::string> GBSAOBCForceFieldImpl::getKernelNames() {
......
...@@ -48,21 +48,7 @@ LangevinIntegrator::LangevinIntegrator(double temperature, double frictionCoeff, ...@@ -48,21 +48,7 @@ LangevinIntegrator::LangevinIntegrator(double temperature, double frictionCoeff,
void LangevinIntegrator::initialize(OpenMMContextImpl& contextRef) { void LangevinIntegrator::initialize(OpenMMContextImpl& contextRef) {
context = &contextRef; context = &contextRef;
kernel = context->getPlatform().createKernel(IntegrateLangevinStepKernel::Name(), contextRef); kernel = context->getPlatform().createKernel(IntegrateLangevinStepKernel::Name(), contextRef);
const System& system = context->getSystem(); dynamic_cast<IntegrateLangevinStepKernel&>(kernel.getImpl()).initialize(contextRef.getSystem(), *this);
vector<double> masses(system.getNumAtoms());
vector<std::vector<int> > constraintIndices(system.getNumConstraints());
vector<double> constraintLengths(system.getNumConstraints());
for (int i = 0; i < system.getNumAtoms(); ++i)
masses[i] = system.getAtomMass(i);
for (int i = 0; i < system.getNumConstraints(); ++i) {
int atom1, atom2;
double distance;
system.getConstraintParameters(i, atom1, atom2, distance);
constraintIndices[i].push_back(atom1);
constraintIndices[i].push_back(atom2);
constraintLengths[i] = distance;
}
dynamic_cast<IntegrateLangevinStepKernel&>(kernel.getImpl()).initialize(masses, constraintIndices, constraintLengths);
} }
vector<string> LangevinIntegrator::getKernelNames() { vector<string> LangevinIntegrator::getKernelNames() {
...@@ -75,8 +61,7 @@ void LangevinIntegrator::step(int steps) { ...@@ -75,8 +61,7 @@ void LangevinIntegrator::step(int steps) {
for (int i = 0; i < steps; ++i) { for (int i = 0; i < steps; ++i) {
context->updateContextState(); context->updateContextState();
context->calcForces(); context->calcForces();
dynamic_cast<IntegrateLangevinStepKernel&>(kernel.getImpl()).execute(context->getPositions(), context->getVelocities(), context->getForces(), temperature, dynamic_cast<IntegrateLangevinStepKernel&>(kernel.getImpl()).execute(*context, *this);
friction, getStepSize());
context->setTime(context->getTime()+getStepSize()); context->setTime(context->getTime()+getStepSize());
} }
} }
...@@ -70,7 +70,7 @@ OpenMMContextImpl::OpenMMContextImpl(OpenMMContext& owner, System& system, Integ ...@@ -70,7 +70,7 @@ OpenMMContextImpl::OpenMMContextImpl(OpenMMContext& owner, System& system, Integ
vector<double> masses(system.getNumAtoms()); vector<double> masses(system.getNumAtoms());
for (size_t i = 0; i < masses.size(); ++i) for (size_t i = 0; i < masses.size(); ++i)
masses[i] = system.getAtomMass(i); masses[i] = system.getAtomMass(i);
dynamic_cast<CalcKineticEnergyKernel&>(kineticEnergyKernel.getImpl()).initialize(masses); dynamic_cast<CalcKineticEnergyKernel&>(kineticEnergyKernel.getImpl()).initialize(system);
for (size_t i = 0; i < forceImpls.size(); ++i) for (size_t i = 0; i < forceImpls.size(); ++i)
forceImpls[i]->initialize(*this); forceImpls[i]->initialize(*this);
integrator.initialize(*this); integrator.initialize(*this);
...@@ -107,7 +107,7 @@ void OpenMMContextImpl::calcForces() { ...@@ -107,7 +107,7 @@ void OpenMMContextImpl::calcForces() {
} }
double OpenMMContextImpl::calcKineticEnergy() { double OpenMMContextImpl::calcKineticEnergy() {
return dynamic_cast<CalcKineticEnergyKernel&>(kineticEnergyKernel.getImpl()).execute(velocities); return dynamic_cast<CalcKineticEnergyKernel&>(kineticEnergyKernel.getImpl()).execute(*this);
} }
double OpenMMContextImpl::calcPotentialEnergy() { double OpenMMContextImpl::calcPotentialEnergy() {
......
...@@ -36,13 +36,13 @@ ...@@ -36,13 +36,13 @@
using namespace OpenMM; using namespace OpenMM;
StandardMMForceField::StandardMMForceField(int numAtoms, int numBonds, int numAngles, int numPeriodicTorsions, int numRBTorsions) : StandardMMForceField::StandardMMForceField(int numAtoms, int numBonds, int numAngles, int numPeriodicTorsions, int numRBTorsions, int numNonbonded14) :
atoms(numAtoms), bonds(numBonds), angles(numAngles), periodicTorsions(numPeriodicTorsions), rbTorsions(numRBTorsions), atoms(numAtoms), bonds(numBonds), angles(numAngles), periodicTorsions(numPeriodicTorsions), rbTorsions(numRBTorsions), nb14s(numNonbonded14),
nonbondedMethod(NoCutoff), cutoffDistance(1.0) { nonbondedMethod(NoCutoff), cutoffDistance(1.0) {
periodicBoxSize[0] = periodicBoxSize[1] = periodicBoxSize[2] = 2.0; periodicBoxSize[0] = periodicBoxSize[1] = periodicBoxSize[2] = 2.0;
} }
StandardMMForceField::NonbondedMethod StandardMMForceField::getNonbondedMethod() { StandardMMForceField::NonbondedMethod StandardMMForceField::getNonbondedMethod() const {
return nonbondedMethod; return nonbondedMethod;
} }
...@@ -50,7 +50,7 @@ void StandardMMForceField::setNonbondedMethod(NonbondedMethod method) { ...@@ -50,7 +50,7 @@ void StandardMMForceField::setNonbondedMethod(NonbondedMethod method) {
nonbondedMethod = method; nonbondedMethod = method;
} }
double StandardMMForceField::getCutoffDistance() { double StandardMMForceField::getCutoffDistance() const {
return cutoffDistance; return cutoffDistance;
} }
...@@ -58,7 +58,7 @@ void StandardMMForceField::setCutoffDistance(double distance) { ...@@ -58,7 +58,7 @@ void StandardMMForceField::setCutoffDistance(double distance) {
cutoffDistance = distance; cutoffDistance = distance;
} }
void StandardMMForceField::getPeriodicBoxSize(double& x, double& y, double& z) { void StandardMMForceField::getPeriodicBoxSize(double& x, double& y, double& z) const {
x = periodicBoxSize[0]; x = periodicBoxSize[0];
y = periodicBoxSize[1]; y = periodicBoxSize[1];
z = periodicBoxSize[2]; z = periodicBoxSize[2];
...@@ -158,6 +158,22 @@ void StandardMMForceField::setRBTorsionParameters(int index, int atom1, int atom ...@@ -158,6 +158,22 @@ void StandardMMForceField::setRBTorsionParameters(int index, int atom1, int atom
rbTorsions[index].c[5] = c5; 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;
atom2 = nb14s[index].atom2;
charge = nb14s[index].charge;
radius = nb14s[index].radius;
depth = nb14s[index].depth;
}
void StandardMMForceField::setNonbonded14Parameters(int index, int atom1, int atom2, double charge, double radius, double depth) {
nb14s[index].atom1 = atom1;
nb14s[index].atom2 = atom2;
nb14s[index].charge = charge;
nb14s[index].radius = radius;
nb14s[index].depth = depth;
}
ForceImpl* StandardMMForceField::createImpl() { ForceImpl* StandardMMForceField::createImpl() {
return new StandardMMForceFieldImpl(*this); return new StandardMMForceFieldImpl(*this);
} }
...@@ -46,91 +46,26 @@ StandardMMForceFieldImpl::~StandardMMForceFieldImpl() { ...@@ -46,91 +46,26 @@ StandardMMForceFieldImpl::~StandardMMForceFieldImpl() {
void StandardMMForceFieldImpl::initialize(OpenMMContextImpl& context) { void StandardMMForceFieldImpl::initialize(OpenMMContextImpl& context) {
kernel = context.getPlatform().createKernel(CalcStandardMMForceFieldKernel::Name(), context); kernel = context.getPlatform().createKernel(CalcStandardMMForceFieldKernel::Name(), context);
vector<vector<int> > bondIndices(owner.getNumBonds());
vector<vector<double> > bondParameters(owner.getNumBonds());
vector<vector<int> > angleIndices(owner.getNumAngles());
vector<vector<double> > angleParameters(owner.getNumAngles());
vector<vector<int> > periodicTorsionIndices(owner.getNumPeriodicTorsions());
vector<vector<double> > periodicTorsionParameters(owner.getNumPeriodicTorsions());
vector<vector<int> > rbTorsionIndices(owner.getNumRBTorsions());
vector<vector<double> > rbTorsionParameters(owner.getNumRBTorsions());
vector<vector<int> > bonded14Indices;
vector<set<int> > exclusions(owner.getNumAtoms()); vector<set<int> > exclusions(owner.getNumAtoms());
vector<vector<double> > nonbondedParameters(owner.getNumAtoms()); vector<vector<int> > bondIndices(owner.getNumBonds());
set<pair<int, int> > bonded14set;
for (int i = 0; i < owner.getNumBonds(); ++i) { for (int i = 0; i < owner.getNumBonds(); ++i) {
int atom1, atom2; int atom1, atom2;
double length, k; double length, k;
owner.getBondParameters(i, atom1, atom2, length, k); owner.getBondParameters(i, atom1, atom2, length, k);
bondIndices[i].push_back(atom1); bondIndices[i].push_back(atom1);
bondIndices[i].push_back(atom2); bondIndices[i].push_back(atom2);
bondParameters[i].push_back(length);
bondParameters[i].push_back(k);
}
for (int i = 0; i < owner.getNumAngles(); ++i) {
int atom1, atom2, atom3;
double angle, k;
owner.getAngleParameters(i, atom1, atom2, atom3, angle, k);
angleIndices[i].push_back(atom1);
angleIndices[i].push_back(atom2);
angleIndices[i].push_back(atom3);
angleParameters[i].push_back(angle);
angleParameters[i].push_back(k);
}
for (int i = 0; i < owner.getNumPeriodicTorsions(); ++i) {
int atom1, atom2, atom3, atom4, periodicity;
double phase, k;
owner.getPeriodicTorsionParameters(i, atom1, atom2, atom3, atom4, periodicity, phase, k);
periodicTorsionIndices[i].push_back(atom1);
periodicTorsionIndices[i].push_back(atom2);
periodicTorsionIndices[i].push_back(atom3);
periodicTorsionIndices[i].push_back(atom4);
periodicTorsionParameters[i].push_back(k);
periodicTorsionParameters[i].push_back(phase);
periodicTorsionParameters[i].push_back(periodicity);
} }
for (int i = 0; i < owner.getNumRBTorsions(); ++i) {
int atom1, atom2, atom3, atom4;
double c0, c1, c2, c3, c4, c5;
owner.getRBTorsionParameters(i, atom1, atom2, atom3, atom4, c0, c1, c2, c3, c4, c5);
rbTorsionIndices[i].push_back(atom1);
rbTorsionIndices[i].push_back(atom2);
rbTorsionIndices[i].push_back(atom3);
rbTorsionIndices[i].push_back(atom4);
rbTorsionParameters[i].push_back(c0);
rbTorsionParameters[i].push_back(c1);
rbTorsionParameters[i].push_back(c2);
rbTorsionParameters[i].push_back(c3);
rbTorsionParameters[i].push_back(c4);
rbTorsionParameters[i].push_back(c5);
}
for (int i = 0; i < owner.getNumAtoms(); ++i) {
double charge, radius, depth;
owner.getAtomParameters(i, charge, radius, depth);
nonbondedParameters[i].push_back(charge);
nonbondedParameters[i].push_back(radius);
nonbondedParameters[i].push_back(depth);
}
set<pair<int, int> > bonded14set;
findExclusions(bondIndices, exclusions, bonded14set); findExclusions(bondIndices, exclusions, bonded14set);
bonded14Indices.resize(bonded14set.size()); dynamic_cast<CalcStandardMMForceFieldKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner, exclusions);
int index = 0;
for (set<pair<int, int> >::const_iterator iter = bonded14set.begin(); iter != bonded14set.end(); ++iter) {
bonded14Indices[index].push_back(iter->first);
bonded14Indices[index++].push_back(iter->second);
}
double boxSize[3];
owner.getPeriodicBoxSize(boxSize[0], boxSize[1], boxSize[2]);
dynamic_cast<CalcStandardMMForceFieldKernel&>(kernel.getImpl()).initialize(bondIndices, bondParameters, angleIndices, angleParameters,
periodicTorsionIndices, periodicTorsionParameters, rbTorsionIndices, rbTorsionParameters, bonded14Indices, 0.5, 1.0/1.2, exclusions,
nonbondedParameters, CalcStandardMMForceFieldKernel::NonbondedMethod(owner.getNonbondedMethod()), owner.getCutoffDistance(), boxSize);
} }
void StandardMMForceFieldImpl::calcForces(OpenMMContextImpl& context, Stream& forces) { void StandardMMForceFieldImpl::calcForces(OpenMMContextImpl& context, Stream& forces) {
dynamic_cast<CalcStandardMMForceFieldKernel&>(kernel.getImpl()).executeForces(context.getPositions(), forces); dynamic_cast<CalcStandardMMForceFieldKernel&>(kernel.getImpl()).executeForces(context);
} }
double StandardMMForceFieldImpl::calcEnergy(OpenMMContextImpl& context) { double StandardMMForceFieldImpl::calcEnergy(OpenMMContextImpl& context) {
return dynamic_cast<CalcStandardMMForceFieldKernel&>(kernel.getImpl()).executeEnergy(context.getPositions()); return dynamic_cast<CalcStandardMMForceFieldKernel&>(kernel.getImpl()).executeEnergy(context);
} }
std::vector<std::string> StandardMMForceFieldImpl::getKernelNames() { std::vector<std::string> StandardMMForceFieldImpl::getKernelNames() {
......
...@@ -46,21 +46,7 @@ VerletIntegrator::VerletIntegrator(double stepSize) { ...@@ -46,21 +46,7 @@ VerletIntegrator::VerletIntegrator(double stepSize) {
void VerletIntegrator::initialize(OpenMMContextImpl& contextRef) { void VerletIntegrator::initialize(OpenMMContextImpl& contextRef) {
context = &contextRef; context = &contextRef;
kernel = context->getPlatform().createKernel(IntegrateVerletStepKernel::Name(), contextRef); kernel = context->getPlatform().createKernel(IntegrateVerletStepKernel::Name(), contextRef);
const System& system = context->getSystem(); dynamic_cast<IntegrateVerletStepKernel&>(kernel.getImpl()).initialize(contextRef.getSystem(), *this);
vector<double> masses(system.getNumAtoms());
vector<std::vector<int> > constraintIndices(system.getNumConstraints());
vector<double> constraintLengths(system.getNumConstraints());
for (int i = 0; i < system.getNumAtoms(); ++i)
masses[i] = system.getAtomMass(i);
for (int i = 0; i < system.getNumConstraints(); ++i) {
int atom1, atom2;
double distance;
system.getConstraintParameters(i, atom1, atom2, distance);
constraintIndices[i].push_back(atom1);
constraintIndices[i].push_back(atom2);
constraintLengths[i] = distance;
}
dynamic_cast<IntegrateVerletStepKernel&>(kernel.getImpl()).initialize(masses, constraintIndices, constraintLengths);
} }
vector<string> VerletIntegrator::getKernelNames() { vector<string> VerletIntegrator::getKernelNames() {
...@@ -73,7 +59,7 @@ void VerletIntegrator::step(int steps) { ...@@ -73,7 +59,7 @@ void VerletIntegrator::step(int steps) {
for (int i = 0; i < steps; ++i) { for (int i = 0; i < steps; ++i) {
context->updateContextState(); context->updateContextState();
context->calcForces(); context->calcForces();
dynamic_cast<IntegrateVerletStepKernel&>(kernel.getImpl()).execute(context->getPositions(), context->getVelocities(), context->getForces(), getStepSize()); dynamic_cast<IntegrateVerletStepKernel&>(kernel.getImpl()).execute(*context, *this);
context->setTime(context->getTime()+getStepSize()); context->setTime(context->getTime()+getStepSize());
} }
} }
...@@ -68,6 +68,7 @@ public: ...@@ -68,6 +68,7 @@ public:
_gpuContext* gpu; _gpuContext* gpu;
bool removeCM; bool removeCM;
bool useOBC; bool useOBC;
int cmMotionFrequency;
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "CudaStreamImpl.h" #include "CudaStreamImpl.h"
#include "LangevinIntegrator.h" #include "LangevinIntegrator.h"
#include "ReferencePlatform.h" #include "ReferencePlatform.h"
#include "internal/OpenMMContextImpl.h"
#include "kernels/gputypes.h" #include "kernels/gputypes.h"
#include "kernels/cudaKernels.h" #include "kernels/cudaKernels.h"
#include <cmath> #include <cmath>
...@@ -47,19 +48,13 @@ using namespace std; ...@@ -47,19 +48,13 @@ using namespace std;
CudaCalcStandardMMForceFieldKernel::~CudaCalcStandardMMForceFieldKernel() { CudaCalcStandardMMForceFieldKernel::~CudaCalcStandardMMForceFieldKernel() {
} }
void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >& bondIndices, const vector<vector<double> >& bondParameters, void CudaCalcStandardMMForceFieldKernel::initialize(const System& system, const StandardMMForceField& force, const std::vector<std::set<int> >& exclusions) {
const vector<vector<int> >& angleIndices, const vector<vector<double> >& angleParameters, numAtoms = force.getNumAtoms();
const vector<vector<int> >& periodicTorsionIndices, const vector<vector<double> >& periodicTorsionParameters, numBonds = force.getNumBonds();
const vector<vector<int> >& rbTorsionIndices, const vector<vector<double> >& rbTorsionParameters, numAngles = force.getNumAngles();
const vector<vector<int> >& bonded14Indices, double lj14Scale, double coulomb14Scale, numPeriodicTorsions = force.getNumPeriodicTorsions();
const vector<set<int> >& exclusions, const vector<vector<double> >& nonbondedParameters, numRBTorsions = force.getNumRBTorsions();
NonbondedMethod nonbondedMethod, double nonbondedCutoff, double periodicBoxSize[3]) { num14 = force.getNumNonbonded14();
numAtoms = nonbondedParameters.size();
numBonds = bondIndices.size();
numAngles = angleIndices.size();
numPeriodicTorsions = periodicTorsionIndices.size();
numRBTorsions = rbTorsionIndices.size();
num14 = bonded14Indices.size();
const float RadiansToDegrees = 180.0/3.14159265; const float RadiansToDegrees = 180.0/3.14159265;
_gpuContext* gpu = data.gpu; _gpuContext* gpu = data.gpu;
...@@ -71,10 +66,10 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >& ...@@ -71,10 +66,10 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >&
vector<float> length(numBonds); vector<float> length(numBonds);
vector<float> k(numBonds); vector<float> k(numBonds);
for (int i = 0; i < numBonds; i++) { for (int i = 0; i < numBonds; i++) {
atom1[i] = bondIndices[i][0]; double lengthValue, kValue;
atom2[i] = bondIndices[i][1]; force.getBondParameters(i, atom1[i], atom2[i], lengthValue, kValue);
length[i] = (float) bondParameters[i][0]; length[i] = (float) lengthValue;
k[i] = (float) bondParameters[i][1]; k[i] = (float) kValue;
} }
gpuSetBondParameters(gpu, atom1, atom2, length, k); gpuSetBondParameters(gpu, atom1, atom2, length, k);
} }
...@@ -88,11 +83,10 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >& ...@@ -88,11 +83,10 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >&
vector<float> angle(numAngles); vector<float> angle(numAngles);
vector<float> k(numAngles); vector<float> k(numAngles);
for (int i = 0; i < numAngles; i++) { for (int i = 0; i < numAngles; i++) {
atom1[i] = angleIndices[i][0]; double angleValue, kValue;
atom2[i] = angleIndices[i][1]; force.getAngleParameters(i, atom1[i], atom2[i], atom3[i], angleValue, kValue);
atom3[i] = angleIndices[i][2]; angle[i] = (float) (angleValue*RadiansToDegrees);
angle[i] = (float) (angleParameters[i][0]*RadiansToDegrees); k[i] = (float) kValue;
k[i] = (float) angleParameters[i][1];
} }
gpuSetBondAngleParameters(gpu, atom1, atom2, atom3, angle, k); gpuSetBondAngleParameters(gpu, atom1, atom2, atom3, angle, k);
} }
...@@ -108,13 +102,10 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >& ...@@ -108,13 +102,10 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >&
vector<float> phase(numPeriodicTorsions); vector<float> phase(numPeriodicTorsions);
vector<int> periodicity(numPeriodicTorsions); vector<int> periodicity(numPeriodicTorsions);
for (int i = 0; i < numPeriodicTorsions; i++) { for (int i = 0; i < numPeriodicTorsions; i++) {
atom1[i] = periodicTorsionIndices[i][0]; double kValue, phaseValue;
atom2[i] = periodicTorsionIndices[i][1]; force.getPeriodicTorsionParameters(i, atom1[i], atom2[i], atom3[i], atom4[i], periodicity[i], phaseValue, kValue);
atom3[i] = periodicTorsionIndices[i][2]; k[i] = (float) kValue;
atom4[i] = periodicTorsionIndices[i][3]; phase[i] = (float) (phaseValue*RadiansToDegrees);
k[i] = (float) periodicTorsionParameters[i][0];
phase[i] = (float) (periodicTorsionParameters[i][1]*RadiansToDegrees);
periodicity[i] = (int) periodicTorsionParameters[i][2];
} }
gpuSetDihedralParameters(gpu, atom1, atom2, atom3, atom4, k, phase, periodicity); gpuSetDihedralParameters(gpu, atom1, atom2, atom3, atom4, k, phase, periodicity);
} }
...@@ -133,16 +124,14 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >& ...@@ -133,16 +124,14 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >&
vector<float> c4(numRBTorsions); vector<float> c4(numRBTorsions);
vector<float> c5(numRBTorsions); vector<float> c5(numRBTorsions);
for (int i = 0; i < numRBTorsions; i++) { for (int i = 0; i < numRBTorsions; i++) {
atom1[i] = rbTorsionIndices[i][0]; double c[6];
atom2[i] = rbTorsionIndices[i][1]; force.getRBTorsionParameters(i, atom1[i], atom2[i], atom3[i], atom4[i], c[0], c[1], c[2], c[3], c[4], c[5]);
atom3[i] = rbTorsionIndices[i][2]; c0[i] = (float) c[0];
atom4[i] = rbTorsionIndices[i][3]; c1[i] = (float) c[1];
c0[i] = (float) rbTorsionParameters[i][0]; c2[i] = (float) c[2];
c1[i] = (float) rbTorsionParameters[i][1]; c3[i] = (float) c[3];
c2[i] = (float) rbTorsionParameters[i][2]; c4[i] = (float) c[4];
c3[i] = (float) rbTorsionParameters[i][3]; c5[i] = (float) c[5];
c4[i] = (float) rbTorsionParameters[i][4];
c5[i] = (float) rbTorsionParameters[i][5];
} }
gpuSetRbDihedralParameters(gpu, atom1, atom2, atom3, atom4, c0, c1, c2, c3, c4, c5); gpuSetRbDihedralParameters(gpu, atom1, atom2, atom3, atom4, c0, c1, c2, c3, c4, c5);
} }
...@@ -157,10 +146,12 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >& ...@@ -157,10 +146,12 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >&
vector<char> symbol; vector<char> symbol;
vector<vector<int> > exclusionList(numAtoms); vector<vector<int> > exclusionList(numAtoms);
for (int i = 0; i < numAtoms; i++) { for (int i = 0; i < numAtoms; i++) {
double charge, radius, depth;
force.getAtomParameters(i, charge, radius, depth);
atom[i] = i; atom[i] = i;
q[i] = (float) nonbondedParameters[i][0]; q[i] = (float) charge;
c6[i] = (float) (4*nonbondedParameters[i][2]*pow(nonbondedParameters[i][1], 6.0)); c6[i] = (float) (4*depth*pow(radius, 6.0));
c12[i] = (float) (4*nonbondedParameters[i][2]*pow(nonbondedParameters[i][1], 12.0)); c12[i] = (float) (4*depth*pow(radius, 12.0));
exclusionList[i] = vector<int>(exclusions[i].begin(), exclusions[i].end()); exclusionList[i] = vector<int>(exclusions[i].begin(), exclusions[i].end());
exclusionList[i].push_back(i); exclusionList[i].push_back(i);
} }
...@@ -177,20 +168,19 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >& ...@@ -177,20 +168,19 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >&
vector<float> q1(num14); vector<float> q1(num14);
vector<float> q2(num14); vector<float> q2(num14);
for (int i = 0; i < num14; i++) { for (int i = 0; i < num14; i++) {
atom1[i] = bonded14Indices[i][0]; double charge, sig, eps;
atom2[i] = bonded14Indices[i][1]; force.getNonbonded14Parameters(i, atom1[i], atom2[i], charge, sig, eps);
double sig = 0.5*(nonbondedParameters[atom1[i]][1]+nonbondedParameters[atom2[i]][1]); c6[i] = (float) (4*eps*pow(sig, 6.0));
double eps = sqrt(nonbondedParameters[atom1[i]][2]*nonbondedParameters[atom2[i]][2]); c12[i] = (float) (4*eps*pow(sig, 12.0));
c6[i] = (float) (4*eps*pow(sig, 6.0)*lj14Scale); float q = (float) std::sqrt(charge);
c12[i] = (float) (4*eps*pow(sig, 12.0)*lj14Scale); q1[i] = q;
q1[i] = (float) nonbondedParameters[atom1[i]][0]; q2[i] = q;
q2[i] = (float) nonbondedParameters[atom2[i]][0];
} }
gpuSetLJ14Parameters(gpu, 138.935485f, (float) coulomb14Scale, atom1, atom2, c6, c12, q1, q2); gpuSetLJ14Parameters(gpu, 138.935485f, 1.0f, atom1, atom2, c6, c12, q1, q2);
} }
} }
void CudaCalcStandardMMForceFieldKernel::executeForces(const Stream& positions, Stream& forces) { void CudaCalcStandardMMForceFieldKernel::executeForces(OpenMMContextImpl& context) {
_gpuContext* gpu = data.gpu; _gpuContext* gpu = data.gpu;
if (data.useOBC) { if (data.useOBC) {
kCalculateCDLJObcGbsaForces1(gpu); kCalculateCDLJObcGbsaForces1(gpu);
...@@ -205,84 +195,90 @@ void CudaCalcStandardMMForceFieldKernel::executeForces(const Stream& positions, ...@@ -205,84 +195,90 @@ void CudaCalcStandardMMForceFieldKernel::executeForces(const Stream& positions,
kReduceBornSumAndForces(gpu); kReduceBornSumAndForces(gpu);
} }
double CudaCalcStandardMMForceFieldKernel::executeEnergy(const Stream& positions) { double CudaCalcStandardMMForceFieldKernel::executeEnergy(OpenMMContextImpl& context) {
// We don't currently have GPU kernels to calculate energy, so instead we have the reference // We don't currently have GPU kernels to calculate energy, so instead we have the reference
// platform do it. This is VERY slow. // platform do it. This is VERY slow.
LangevinIntegrator integrator(0.0, 1.0, 0.0); LangevinIntegrator integrator(0.0, 1.0, 0.0);
ReferencePlatform platform; ReferencePlatform platform;
OpenMMContext context(system, integrator, platform); OpenMMContext refContext(system, integrator, platform);
const Stream& positions = context.getPositions();
double* posData = new double[positions.getSize()*3]; double* posData = new double[positions.getSize()*3];
positions.saveToArray(posData); positions.saveToArray(posData);
vector<Vec3> pos(positions.getSize()); vector<Vec3> pos(positions.getSize());
for (int i = 0; i < pos.size(); i++) for (int i = 0; i < pos.size(); i++)
pos[i] = Vec3(posData[3*i], posData[3*i+1], posData[3*i+2]); pos[i] = Vec3(posData[3*i], posData[3*i+1], posData[3*i+2]);
delete[] posData; delete[] posData;
context.setPositions(pos); refContext.setPositions(pos);
return context.getState(State::Energy).getPotentialEnergy(); return refContext.getState(State::Energy).getPotentialEnergy();
} }
CudaCalcGBSAOBCForceFieldKernel::~CudaCalcGBSAOBCForceFieldKernel() { CudaCalcGBSAOBCForceFieldKernel::~CudaCalcGBSAOBCForceFieldKernel() {
} }
void CudaCalcGBSAOBCForceFieldKernel::initialize(const vector<vector<double> >& atomParameters, double solventDielectric, double soluteDielectric) { void CudaCalcGBSAOBCForceFieldKernel::initialize(const System& system, const GBSAOBCForceField& force) {
int numAtoms = atomParameters.size(); int numAtoms = system.getNumAtoms();
_gpuContext* gpu = data.gpu; _gpuContext* gpu = data.gpu;
vector<int> atom(numAtoms); vector<int> atom(numAtoms);
vector<float> radius(numAtoms); vector<float> radius(numAtoms);
vector<float> scale(numAtoms); vector<float> scale(numAtoms);
for (int i = 0; i < numAtoms; i++) { for (int i = 0; i < numAtoms; i++) {
double charge, atomRadius, scalingFactor;
force.getAtomParameters(i, charge, atomRadius, scalingFactor);
atom[i] = i; atom[i] = i;
radius[i] = (float) atomParameters[i][1]; radius[i] = (float) atomRadius;
scale[i] = (float) atomParameters[i][2]; scale[i] = (float) scalingFactor;
} }
gpuSetObcParameters(gpu, soluteDielectric, solventDielectric, atom, radius, scale); gpuSetObcParameters(gpu, force.getSoluteDielectric(), force.getSolventDielectric(), atom, radius, scale);
data.useOBC = true; data.useOBC = true;
} }
void CudaCalcGBSAOBCForceFieldKernel::executeForces(const Stream& positions, Stream& forces) { void CudaCalcGBSAOBCForceFieldKernel::executeForces(OpenMMContextImpl& context) {
} }
double CudaCalcGBSAOBCForceFieldKernel::executeEnergy(const Stream& positions) { double CudaCalcGBSAOBCForceFieldKernel::executeEnergy(OpenMMContextImpl& context) {
} }
//CudaIntegrateVerletStepKernel::~CudaIntegrateVerletStepKernel() { //CudaIntegrateVerletStepKernel::~CudaIntegrateVerletStepKernel() {
//} //}
// //
//void CudaIntegrateVerletStepKernel::initialize(const vector<double>& masses, const vector<vector<int> >& constraintIndices, //void CudaIntegrateVerletStepKernel::initialize(const System& system, const VerletIntegrator& integrator) {
//} //}
// //
//void CudaIntegrateVerletStepKernel::execute(Stream& positions, Stream& velocities, const Stream& forces, double stepSize) { //void CudaIntegrateVerletStepKernel::execute(OpenMMContextImpl& context, const VerletIntegrator& integrator) {
//} //}
CudaIntegrateLangevinStepKernel::~CudaIntegrateLangevinStepKernel() { CudaIntegrateLangevinStepKernel::~CudaIntegrateLangevinStepKernel() {
} }
void CudaIntegrateLangevinStepKernel::initialize(const vector<double>& masses, const vector<vector<int> >& constraintIndices, void CudaIntegrateLangevinStepKernel::initialize(const System& system, const LangevinIntegrator& integrator) {
const vector<double>& constraintLengths) {
// Set masses. // Set masses.
_gpuContext* gpu = data.gpu; _gpuContext* gpu = data.gpu;
vector<float> mass(masses.size()); int numAtoms = system.getNumAtoms();
for (int i = 0; i < (int) mass.size(); i++) vector<float> mass(numAtoms);
mass[i] = (float) masses[i]; for (int i = 0; i < numAtoms; i++)
mass[i] = (float) system.getAtomMass(i);
gpuSetMass(gpu, mass); gpuSetMass(gpu, mass);
// Set constraints. // Set constraints.
int numConstraints = constraintLengths.size(); int numConstraints = system.getNumConstraints();
vector<int> atom1(numConstraints); vector<int> atom1(numConstraints);
vector<int> atom2(numConstraints); vector<int> atom2(numConstraints);
vector<float> distance(numConstraints); vector<float> distance(numConstraints);
vector<float> invMass1(numConstraints); vector<float> invMass1(numConstraints);
vector<float> invMass2(numConstraints); vector<float> invMass2(numConstraints);
for (int i = 0; i < numConstraints; i++) { for (int i = 0; i < numConstraints; i++) {
atom1[i] = constraintIndices[i][0]; int atom1Index, atom2Index;
atom2[i] = constraintIndices[i][1]; double constraintDistance;
distance[i] = (float) constraintLengths[i]; system.getConstraintParameters(i, atom1Index, atom2Index, constraintDistance);
invMass1[i] = 1.0f/mass[atom1[i]]; atom1[i] = atom1Index;
invMass2[i] = 1.0f/mass[atom2[i]]; atom2[i] = atom2Index;
distance[i] = (float) constraintDistance;
invMass1[i] = 1.0f/mass[atom1Index];
invMass2[i] = 1.0f/mass[atom2Index];
} }
gpuSetShakeParameters(gpu, atom1, atom2, distance, invMass1, invMass2); gpuSetShakeParameters(gpu, atom1, atom2, distance, invMass1, invMass2);
gpuBuildThreadBlockWorkList(gpu); gpuBuildThreadBlockWorkList(gpu);
...@@ -297,8 +293,11 @@ void CudaIntegrateLangevinStepKernel::initialize(const vector<double>& masses, c ...@@ -297,8 +293,11 @@ void CudaIntegrateLangevinStepKernel::initialize(const vector<double>& masses, c
prevStepSize = -1.0; prevStepSize = -1.0;
} }
void CudaIntegrateLangevinStepKernel::execute(Stream& positions, Stream& velocities, const Stream& forces, double temperature, double friction, double stepSize) { void CudaIntegrateLangevinStepKernel::execute(OpenMMContextImpl& context, const LangevinIntegrator& integrator) {
_gpuContext* gpu = data.gpu; _gpuContext* gpu = data.gpu;
double temperature = integrator.getTemperature();
double friction = integrator.getFriction();
double stepSize = integrator.getStepSize();
if (temperature != prevTemp || friction != prevFriction || stepSize != prevStepSize) { if (temperature != prevTemp || friction != prevFriction || stepSize != prevStepSize) {
// Initialize the GPU parameters. // Initialize the GPU parameters.
...@@ -312,8 +311,11 @@ void CudaIntegrateLangevinStepKernel::execute(Stream& positions, Stream& velocit ...@@ -312,8 +311,11 @@ void CudaIntegrateLangevinStepKernel::execute(Stream& positions, Stream& velocit
} }
kUpdatePart1(gpu); kUpdatePart1(gpu);
kApplyFirstShake(gpu); kApplyFirstShake(gpu);
if (data.removeCM) if (data.removeCM) {
gpu->bCalculateCM = true; int step = context.getTime()/stepSize;
if (step%data.cmMotionFrequency == 0)
gpu->bCalculateCM = true;
}
kUpdatePart2(gpu); kUpdatePart2(gpu);
kApplySecondShake(gpu); kApplySecondShake(gpu);
} }
...@@ -321,30 +323,33 @@ void CudaIntegrateLangevinStepKernel::execute(Stream& positions, Stream& velocit ...@@ -321,30 +323,33 @@ void CudaIntegrateLangevinStepKernel::execute(Stream& positions, Stream& velocit
//CudaIntegrateBrownianStepKernel::~CudaIntegrateBrownianStepKernel() { //CudaIntegrateBrownianStepKernel::~CudaIntegrateBrownianStepKernel() {
//} //}
// //
//void CudaIntegrateBrownianStepKernel::initialize(const vector<double>& masses, const vector<vector<int> >& constraintIndices, //void CudaIntegrateBrownianStepKernel::initialize(const System& system, const BrownianIntegrator& integrator) {
// const vector<double>& constraintLengths) {
//} //}
// //
//void CudaIntegrateBrownianStepKernel::execute(Stream& positions, Stream& velocities, const Stream& forces, double temperature, double friction, double stepSize) { //void CudaIntegrateBrownianStepKernel::execute(OpenMMContextImpl& context, const BrownianIntegrator& integrator) {
//} //}
// //
//CudaApplyAndersenThermostatKernel::~CudaApplyAndersenThermostatKernel() { //CudaApplyAndersenThermostatKernel::~CudaApplyAndersenThermostatKernel() {
//} //}
// //
//void CudaApplyAndersenThermostatKernel::initialize(const vector<double>& masses) { //void CudaApplyAndersenThermostatKernel::initialize(const System& system, const AndersenThermostat& thermostat) {
//} //}
// //
//void CudaApplyAndersenThermostatKernel::execute(Stream& velocities, double temperature, double collisionFrequency, double stepSize) { //void CudaApplyAndersenThermostatKernel::execute(OpenMMContextImpl& context) {
//} //}
void CudaCalcKineticEnergyKernel::initialize(const vector<double>& masses) { void CudaCalcKineticEnergyKernel::initialize(const System& system) {
this->masses = masses; int numAtoms = system.getNumAtoms();
masses.resize(numAtoms);
for (size_t i = 0; i < numAtoms; ++i)
masses[i] = system.getAtomMass(i);
} }
double CudaCalcKineticEnergyKernel::execute(const Stream& velocities) { double CudaCalcKineticEnergyKernel::execute(OpenMMContextImpl& context) {
// We don't currently have a GPU kernel to do this, so we retrieve the velocities and calculate the energy // We don't currently have a GPU kernel to do this, so we retrieve the velocities and calculate the energy
// on the CPU. // on the CPU.
const Stream& velocities = context.getVelocities();
double* v = new double[velocities.getSize()*3]; double* v = new double[velocities.getSize()*3];
velocities.saveToArray(v); velocities.saveToArray(v);
double energy = 0.0; double energy = 0.0;
...@@ -354,9 +359,10 @@ double CudaCalcKineticEnergyKernel::execute(const Stream& velocities) { ...@@ -354,9 +359,10 @@ double CudaCalcKineticEnergyKernel::execute(const Stream& velocities) {
return 0.5*energy; return 0.5*energy;
} }
void CudaRemoveCMMotionKernel::initialize(const vector<double>& masses) { void CudaRemoveCMMotionKernel::initialize(const System& system, const CMMotionRemover& force) {
data.removeCM = true; data.removeCM = true;
data.cmMotionFrequency = force.getFrequency();
} }
void CudaRemoveCMMotionKernel::execute(Stream& velocities) { void CudaRemoveCMMotionKernel::execute(OpenMMContextImpl& context) {
} }
...@@ -54,47 +54,28 @@ public: ...@@ -54,47 +54,28 @@ public:
} }
~CudaCalcStandardMMForceFieldKernel(); ~CudaCalcStandardMMForceFieldKernel();
/** /**
* Initialize the kernel, setting up the values of all the force field parameters. * Initialize the kernel.
* *
* @param bondIndices the two atoms connected by each bond term * @param system the System this kernel will be applied to
* @param bondParameters the force parameters (length, k) for each bond term * @param force the StandardMMForceField this kernel will be used for
* @param angleIndices the three atoms connected by each angle term * @param exclusions the i'th element lists the indices of all atoms with which the i'th atom should not interact through
* @param angleParameters the force parameters (angle, k) for each angle term * nonbonded forces. Bonded 1-4 pairs are also included in this list, since they should be omitted from
* @param periodicTorsionIndices the four atoms connected by each periodic torsion term * the standard nonbonded calculation.
* @param periodicTorsionParameters the force parameters (k, phase, periodicity) for each periodic torsion term
* @param rbTorsionIndices the four atoms connected by each Ryckaert-Bellemans torsion term
* @param rbTorsionParameters the coefficients (in order of increasing powers) for each Ryckaert-Bellemans torsion term
* @param bonded14Indices each element contains the indices of two atoms whose nonbonded interactions should be reduced since
* they form a bonded 1-4 pair
* @param lj14Scale the factor by which van der Waals interactions should be reduced for bonded 1-4 pairs
* @param coulomb14Scale the factor by which Coulomb interactions should be reduced for bonded 1-4 pairs
* @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
* the standard nonbonded calculation.
* @param nonbondedParameters the nonbonded force parameters (charge, sigma, epsilon) for each atom
*/ */
void initialize(const std::vector<std::vector<int> >& bondIndices, const std::vector<std::vector<double> >& bondParameters, void initialize(const System& system, const StandardMMForceField& force, const std::vector<std::set<int> >& exclusions);
const std::vector<std::vector<int> >& angleIndices, const std::vector<std::vector<double> >& angleParameters,
const std::vector<std::vector<int> >& periodicTorsionIndices, const std::vector<std::vector<double> >& periodicTorsionParameters,
const std::vector<std::vector<int> >& rbTorsionIndices, const std::vector<std::vector<double> >& rbTorsionParameters,
const std::vector<std::vector<int> >& bonded14Indices, double lj14Scale, double coulomb14Scale,
const std::vector<std::set<int> >& exclusions, const std::vector<std::vector<double> >& nonbondedParameters,
NonbondedMethod nonbondedMethod, double nonbondedCutoff, double periodicBoxSize[3]);
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces.
* *
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom * @param context the context in which to execute this kernel
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom. On entry, this contains the forces that
* have been calculated so far. The kernel should add its own forces to the values already in the stream.
*/ */
void executeForces(const Stream& positions, Stream& forces); void executeForces(OpenMMContextImpl& context);
/** /**
* Execute the kernel to calculate the energy. * Execute the kernel to calculate the energy.
* *
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom * @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 StandardMMForceField
*/ */
double executeEnergy(const Stream& positions); double executeEnergy(OpenMMContextImpl& context);
private: private:
CudaPlatform::PlatformData& data; CudaPlatform::PlatformData& data;
int numAtoms, numBonds, numAngles, numPeriodicTorsions, numRBTorsions, num14; int numAtoms, numBonds, numAngles, numPeriodicTorsions, numRBTorsions, num14;
...@@ -110,28 +91,25 @@ public: ...@@ -110,28 +91,25 @@ public:
} }
~CudaCalcGBSAOBCForceFieldKernel(); ~CudaCalcGBSAOBCForceFieldKernel();
/** /**
* Initialize the kernel, setting up the values of all the force field parameters. * Initialize the kernel.
* *
* @param atomParameters the force parameters (charge, atomic radius, scaling factor) for each atom * @param system the System this kernel will be applied to
* @param solventDielectric the dielectric constant of the solvent * @param force the GBSAOBCForceField this kernel will be used for
* @param soluteDielectric the dielectric constant of the solute
*/ */
void initialize(const std::vector<std::vector<double> >& atomParameters, double solventDielectric, double soluteDielectric); void initialize(const System& system, const GBSAOBCForceField& force);
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces.
* *
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom * @param context the context in which to execute this kernel
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom. On entry, this contains the forces that
* have been calculated so far. The kernel should add its own forces to the values already in the stream.
*/ */
void executeForces(const Stream& positions, Stream& forces); void executeForces(OpenMMContextImpl& context);
/** /**
* Execute the kernel to calculate the energy. * Execute the kernel to calculate the energy.
* *
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom * @param context the context in which to execute this kernel
* @return the potential energy due to the GBSAOBCForceField * @return the potential energy due to the GBSAOBCForceField
*/ */
double executeEnergy(const Stream& positions); double executeEnergy(OpenMMContextImpl& context);
private: private:
CudaPlatform::PlatformData& data; CudaPlatform::PlatformData& data;
}; };
...@@ -146,23 +124,19 @@ private: ...@@ -146,23 +124,19 @@ private:
// } // }
// ~CudaIntegrateVerletStepKernel(); // ~CudaIntegrateVerletStepKernel();
// /** // /**
// * Initialize the kernel, setting up all parameters related to integrator. // * Initialize the kernel.
// * // *
// * @param masses the mass of each atom // * @param system the System this kernel will be applied to
// * @param constraintIndices each element contains the indices of two atoms whose distance should be constrained // * @param integrator the VerletIntegrator this kernel will be used for
// * @param constraintLengths the required distance between each pair of constrained atoms
// */ // */
// void initialize(const std::vector<double>& masses, const std::vector<std::vector<int> >& constraintIndices, // void initialize(const System& system, const VerletIntegrator& integrator);
// const std::vector<double>& constraintLengths);
// /** // /**
// * Execute the kernel. // * Execute the kernel.
// * // *
// * @param positions a Stream of type Double3 containing the position (x, y, z) of each atom // * @param context the context in which to execute this kernel
// * @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom // * @param integrator the VerletIntegrator this kernel is being used for
// * @param forces a Stream of type Double3 containing the force (x, y, z) on each atom
// * @param stepSize the integration step size
// */ // */
// void execute(Stream& positions, Stream& velocities, const Stream& forces, double stepSize); // void execute(OpenMMContextImpl& context, const VerletIntegrator& integrator);
//private: //private:
// CudaVerletDynamics* dynamics; // CudaVerletDynamics* dynamics;
// CudaShakeAlgorithm* shake; // CudaShakeAlgorithm* shake;
...@@ -182,25 +156,19 @@ public: ...@@ -182,25 +156,19 @@ public:
} }
~CudaIntegrateLangevinStepKernel(); ~CudaIntegrateLangevinStepKernel();
/** /**
* Initialize the kernel, setting up all parameters related to integrator. * Initialize the kernel, setting up the atomic masses.
* *
* @param masses the mass of each atom * @param system the System this kernel will be applied to
* @param constraintIndices each element contains the indices of two atoms whose distance should be constrained * @param integrator the LangevinIntegrator this kernel will be used for
* @param constraintLengths the required distance between each pair of constrained atoms
*/ */
void initialize(const std::vector<double>& masses, const std::vector<std::vector<int> >& constraintIndices, void initialize(const System& system, const LangevinIntegrator& integrator);
const std::vector<double>& constraintLengths);
/** /**
* Execute the kernel. * Execute the kernel.
* *
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom * @param context the context in which to execute this kernel
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom * @param integrator the LangevinIntegrator this kernel is being used for
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom
* @param temperature the temperature of the heat bath
* @param friction the friction coefficient coupling the system to the heat bath
* @param stepSize the integration step size
*/ */
void execute(Stream& positions, Stream& velocities, const Stream& forces, double temperature, double friction, double stepSize); void execute(OpenMMContextImpl& context, const LangevinIntegrator& integrator);
private: private:
CudaPlatform::PlatformData& data; CudaPlatform::PlatformData& data;
double prevTemp, prevFriction, prevStepSize; double prevTemp, prevFriction, prevStepSize;
...@@ -216,25 +184,19 @@ private: ...@@ -216,25 +184,19 @@ private:
// } // }
// ~CudaIntegrateBrownianStepKernel(); // ~CudaIntegrateBrownianStepKernel();
// /** // /**
// * Initialize the kernel, setting up all parameters related to integrator. // * Initialize the kernel.
// * // *
// * @param masses the mass of each atom // * @param system the System this kernel will be applied to
// * @param constraintIndices each element contains the indices of two atoms whose distance should be constrained // * @param integrator the BrownianIntegrator this kernel will be used for
// * @param constraintLengths the required distance between each pair of constrained atoms
// */ // */
// void initialize(const std::vector<double>& masses, const std::vector<std::vector<int> >& constraintIndices, // void initialize(const System& system, const BrownianIntegrator& integrator);
// const std::vector<double>& constraintLengths);
// /** // /**
// * Execute the kernel. // * Execute the kernel.
// * // *
// * @param positions a Stream of type Double3 containing the position (x, y, z) of each atom // * @param context the context in which to execute this kernel
// * @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom // * @param integrator the BrownianIntegrator this kernel is being used for
// * @param forces a Stream of type Double3 containing the force (x, y, z) on each atom
// * @param temperature the temperature of the heat bath
// * @param friction the friction coefficient coupling the system to the heat bath
// * @param stepSize the integration step size
// */ // */
// void execute(Stream& positions, Stream& velocities, const Stream& forces, double temperature, double friction, double stepSize); // void execute(OpenMMContextImpl& context, const BrownianIntegrator& integrator);
//private: //private:
// CudaBrownianDynamics* dynamics; // CudaBrownianDynamics* dynamics;
// CudaShakeAlgorithm* shake; // CudaShakeAlgorithm* shake;
...@@ -254,20 +216,18 @@ private: ...@@ -254,20 +216,18 @@ private:
// } // }
// ~CudaApplyAndersenThermostatKernel(); // ~CudaApplyAndersenThermostatKernel();
// /** // /**
// * Initialize the kernel, setting up the values of unchanging parameters. // * Initialize the kernel.
// * // *
// * @param masses the mass of each atom // * @param system the System this kernel will be applied to
// * @param thermostat the AndersenThermostat this kernel will be used for
// */ // */
// void initialize(const std::vector<double>& masses); // void initialize(const System& system, const AndersenThermostat& thermostat);
// /** // /**
// * Execute the kernel. // * Execute the kernel.
// * // *
// * @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom // * @param context the context in which to execute this kernel
// * @param temperature the temperature of the heat bath
// * @param collisionFrequency the frequency at which atom collide with particles in the heat bath
// * @param stepSize the integration step size
// */ // */
// void execute(Stream& velocities, double temperature, double collisionFrequency, double stepSize); // void execute(OpenMMContextImpl& context);
//private: //private:
// CudaAndersenThermostat* thermostat; // CudaAndersenThermostat* thermostat;
// RealOpenMM* masses; // RealOpenMM* masses;
...@@ -281,18 +241,17 @@ public: ...@@ -281,18 +241,17 @@ public:
CudaCalcKineticEnergyKernel(std::string name, const Platform& platform) : CalcKineticEnergyKernel(name, platform) { CudaCalcKineticEnergyKernel(std::string name, const Platform& platform) : CalcKineticEnergyKernel(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the atomic masses. * Initialize the kernel.
* *
* @param masses the mass of each atom * @param system the System this kernel will be applied to
*/ */
void initialize(const std::vector<double>& masses); void initialize(const System& system);
/** /**
* Execute the kernel. * Execute the kernel.
* *
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom * @param context the context in which to execute this kernel
* @return the kinetic energy of the system
*/ */
double execute(const Stream& velocities); double execute(OpenMMContextImpl& context);
private: private:
std::vector<double> masses; std::vector<double> masses;
}; };
...@@ -307,15 +266,16 @@ public: ...@@ -307,15 +266,16 @@ public:
/** /**
* Initialize the kernel, setting up the atomic masses. * Initialize the kernel, setting up the atomic masses.
* *
* @param masses the mass of each atom * @param system the System this kernel will be applied to
* @param force the CMMotionRemover this kernel will be used for
*/ */
void initialize(const std::vector<double>& masses); void initialize(const System& system, const CMMotionRemover& force);
/** /**
* Execute the kernel. * Execute the kernel.
* *
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom * @param context the context in which to execute this kernel
*/ */
void execute(Stream& velocities); void execute(OpenMMContextImpl& context);
private: private:
CudaPlatform::PlatformData& data; CudaPlatform::PlatformData& data;
}; };
......
...@@ -63,7 +63,7 @@ void testMotionRemoval() { ...@@ -63,7 +63,7 @@ void testMotionRemoval() {
CudaPlatform platform; CudaPlatform platform;
System system(numAtoms, 0); System system(numAtoms, 0);
LangevinIntegrator integrator(0.0, 1e-5, 0.01); LangevinIntegrator integrator(0.0, 1e-5, 0.01);
StandardMMForceField* forceField = new StandardMMForceField(numAtoms, 1, 0, 0, 0); StandardMMForceField* forceField = new StandardMMForceField(numAtoms, 1, 0, 0, 0, 0);
for (int i = 0; i < numAtoms; ++i) { for (int i = 0; i < numAtoms; ++i) {
system.setAtomMass(i, i+1); system.setAtomMass(i, i+1);
forceField->setAtomParameters(i, (i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0); forceField->setAtomParameters(i, (i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
......
...@@ -58,7 +58,7 @@ void testSingleAtom() { ...@@ -58,7 +58,7 @@ void testSingleAtom() {
GBSAOBCForceField* forceField = new GBSAOBCForceField(1); GBSAOBCForceField* forceField = new GBSAOBCForceField(1);
forceField->setAtomParameters(0, 0.5, 0.15, 1); forceField->setAtomParameters(0, 0.5, 0.15, 1);
system.addForce(forceField); system.addForce(forceField);
system.addForce(new StandardMMForceField(1, 0, 0, 0, 0)); system.addForce(new StandardMMForceField(1, 0, 0, 0, 0, 0));
OpenMMContext context(system, integrator, platform); OpenMMContext context(system, integrator, platform);
vector<Vec3> positions(1); vector<Vec3> positions(1);
positions[0] = Vec3(0, 0, 0); positions[0] = Vec3(0, 0, 0);
...@@ -81,7 +81,7 @@ void testForce() { ...@@ -81,7 +81,7 @@ void testForce() {
for (int i = 0; i < numAtoms; ++i) for (int i = 0; i < numAtoms; ++i)
forceField->setAtomParameters(i, i%2 == 0 ? -1 : 1, 0.15, 1); forceField->setAtomParameters(i, i%2 == 0 ? -1 : 1, 0.15, 1);
system.addForce(forceField); system.addForce(forceField);
system.addForce(new StandardMMForceField(numAtoms, 0, 0, 0, 0)); system.addForce(new StandardMMForceField(numAtoms, 0, 0, 0, 0, 0));
OpenMMContext context(system, integrator, platform); OpenMMContext context(system, integrator, platform);
// Set random positions for all the atoms. // Set random positions for all the atoms.
......
...@@ -55,7 +55,7 @@ void testSingleBond() { ...@@ -55,7 +55,7 @@ void testSingleBond() {
system.setAtomMass(0, 2.0); system.setAtomMass(0, 2.0);
system.setAtomMass(1, 2.0); system.setAtomMass(1, 2.0);
LangevinIntegrator integrator(0, 0.1, 0.01); LangevinIntegrator integrator(0, 0.1, 0.01);
StandardMMForceField* forceField = new StandardMMForceField(2, 1, 0, 0, 0); StandardMMForceField* forceField = new StandardMMForceField(2, 1, 0, 0, 0, 0);
forceField->setBondParameters(0, 0, 1, 1.5, 1); forceField->setBondParameters(0, 0, 1, 1.5, 1);
system.addForce(forceField); system.addForce(forceField);
OpenMMContext context(system, integrator, platform); OpenMMContext context(system, integrator, platform);
...@@ -99,7 +99,7 @@ void testTemperature() { ...@@ -99,7 +99,7 @@ void testTemperature() {
CudaPlatform platform; CudaPlatform platform;
System system(numAtoms, 0); System system(numAtoms, 0);
LangevinIntegrator integrator(temp, 2.0, 0.01); LangevinIntegrator integrator(temp, 2.0, 0.01);
StandardMMForceField* forceField = new StandardMMForceField(numAtoms, 0, 0, 0, 0); StandardMMForceField* forceField = new StandardMMForceField(numAtoms, 0, 0, 0, 0, 0);
for (int i = 0; i < numAtoms; ++i) { for (int i = 0; i < numAtoms; ++i) {
system.setAtomMass(i, 2.0); system.setAtomMass(i, 2.0);
forceField->setAtomParameters(i, (i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0); forceField->setAtomParameters(i, (i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
...@@ -135,7 +135,7 @@ void testConstraints() { ...@@ -135,7 +135,7 @@ void testConstraints() {
CudaPlatform platform; CudaPlatform platform;
System system(numAtoms, numConstraints); System system(numAtoms, numConstraints);
LangevinIntegrator integrator(temp, 2.0, 0.01); LangevinIntegrator integrator(temp, 2.0, 0.01);
StandardMMForceField* forceField = new StandardMMForceField(numAtoms, 0, 0, 0, 0); StandardMMForceField* forceField = new StandardMMForceField(numAtoms, 0, 0, 0, 0, 0);
for (int i = 0; i < numAtoms; ++i) { for (int i = 0; i < numAtoms; ++i) {
system.setAtomMass(i, 10.0); system.setAtomMass(i, 10.0);
forceField->setAtomParameters(i, (i%2 == 0 ? 0.2 : -0.2), 0.5, 5.0); forceField->setAtomParameters(i, (i%2 == 0 ? 0.2 : -0.2), 0.5, 5.0);
......
...@@ -52,7 +52,7 @@ void testBonds() { ...@@ -52,7 +52,7 @@ void testBonds() {
CudaPlatform platform; CudaPlatform platform;
System system(3, 0); System system(3, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01); LangevinIntegrator integrator(0.0, 0.1, 0.01);
StandardMMForceField* forceField = new StandardMMForceField(3, 2, 0, 0, 0); StandardMMForceField* forceField = new StandardMMForceField(3, 2, 0, 0, 0, 0);
forceField->setBondParameters(0, 0, 1, 1.5, 0.8); forceField->setBondParameters(0, 0, 1, 1.5, 0.8);
forceField->setBondParameters(1, 1, 2, 1.2, 0.7); forceField->setBondParameters(1, 1, 2, 1.2, 0.7);
system.addForce(forceField); system.addForce(forceField);
...@@ -74,7 +74,7 @@ void testAngles() { ...@@ -74,7 +74,7 @@ void testAngles() {
CudaPlatform platform; CudaPlatform platform;
System system(4, 0); System system(4, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01); LangevinIntegrator integrator(0.0, 0.1, 0.01);
StandardMMForceField* forceField = new StandardMMForceField(4, 0, 2, 0, 0); StandardMMForceField* forceField = new StandardMMForceField(4, 0, 2, 0, 0, 0);
forceField->setAngleParameters(0, 0, 1, 2, PI_M/3, 1.1); forceField->setAngleParameters(0, 0, 1, 2, PI_M/3, 1.1);
forceField->setAngleParameters(1, 1, 2, 3, PI_M/2, 1.2); forceField->setAngleParameters(1, 1, 2, 3, PI_M/2, 1.2);
system.addForce(forceField); system.addForce(forceField);
...@@ -99,7 +99,7 @@ void testPeriodicTorsions() { ...@@ -99,7 +99,7 @@ void testPeriodicTorsions() {
CudaPlatform platform; CudaPlatform platform;
System system(4, 0); System system(4, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01); LangevinIntegrator integrator(0.0, 0.1, 0.01);
StandardMMForceField* forceField = new StandardMMForceField(4, 0, 0, 1, 0); StandardMMForceField* forceField = new StandardMMForceField(4, 0, 0, 1, 0, 0);
forceField->setPeriodicTorsionParameters(0, 0, 1, 2, 3, 2, PI_M/3, 1.1); forceField->setPeriodicTorsionParameters(0, 0, 1, 2, 3, 2, PI_M/3, 1.1);
system.addForce(forceField); system.addForce(forceField);
OpenMMContext context(system, integrator, platform); OpenMMContext context(system, integrator, platform);
...@@ -122,7 +122,7 @@ void testRBTorsions() { ...@@ -122,7 +122,7 @@ void testRBTorsions() {
CudaPlatform platform; CudaPlatform platform;
System system(4, 0); System system(4, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01); LangevinIntegrator integrator(0.0, 0.1, 0.01);
StandardMMForceField* forceField = new StandardMMForceField(4, 0, 0, 0, 1); StandardMMForceField* forceField = new StandardMMForceField(4, 0, 0, 0, 1, 0);
forceField->setRBTorsionParameters(0, 0, 1, 2, 3, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6); forceField->setRBTorsionParameters(0, 0, 1, 2, 3, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6);
system.addForce(forceField); system.addForce(forceField);
OpenMMContext context(system, integrator, platform); OpenMMContext context(system, integrator, platform);
...@@ -155,7 +155,7 @@ void testCoulomb() { ...@@ -155,7 +155,7 @@ void testCoulomb() {
CudaPlatform platform; CudaPlatform platform;
System system(2, 0); System system(2, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01); LangevinIntegrator integrator(0.0, 0.1, 0.01);
StandardMMForceField* forceField = new StandardMMForceField(2, 0, 0, 0, 0); StandardMMForceField* forceField = new StandardMMForceField(2, 0, 0, 0, 0, 0);
forceField->setAtomParameters(0, 0.5, 1, 0); forceField->setAtomParameters(0, 0.5, 1, 0);
forceField->setAtomParameters(1, -1.5, 1, 0); forceField->setAtomParameters(1, -1.5, 1, 0);
system.addForce(forceField); system.addForce(forceField);
...@@ -176,7 +176,7 @@ void testLJ() { ...@@ -176,7 +176,7 @@ void testLJ() {
CudaPlatform platform; CudaPlatform platform;
System system(2, 0); System system(2, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01); LangevinIntegrator integrator(0.0, 0.1, 0.01);
StandardMMForceField* forceField = new StandardMMForceField(2, 0, 0, 0, 0); StandardMMForceField* forceField = new StandardMMForceField(2, 0, 0, 0, 0, 0);
forceField->setAtomParameters(0, 0, 1.2, 1); forceField->setAtomParameters(0, 0, 1.2, 1);
forceField->setAtomParameters(1, 0, 1.4, 2); forceField->setAtomParameters(1, 0, 1.4, 2);
system.addForce(forceField); system.addForce(forceField);
...@@ -199,7 +199,7 @@ void testExclusionsAnd14() { ...@@ -199,7 +199,7 @@ void testExclusionsAnd14() {
CudaPlatform platform; CudaPlatform platform;
System system(5, 0); System system(5, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01); LangevinIntegrator integrator(0.0, 0.1, 0.01);
StandardMMForceField* forceField = new StandardMMForceField(5, 4, 0, 0, 0); StandardMMForceField* forceField = new StandardMMForceField(5, 4, 0, 0, 0, 2);
forceField->setBondParameters(0, 0, 1, 1, 0); forceField->setBondParameters(0, 0, 1, 1, 0);
forceField->setBondParameters(1, 1, 2, 1, 0); forceField->setBondParameters(1, 1, 2, 1, 0);
forceField->setBondParameters(2, 2, 3, 1, 0); forceField->setBondParameters(2, 2, 3, 1, 0);
...@@ -217,6 +217,8 @@ void testExclusionsAnd14() { ...@@ -217,6 +217,8 @@ void testExclusionsAnd14() {
} }
forceField->setAtomParameters(0, 0, 1.5, 1); forceField->setAtomParameters(0, 0, 1.5, 1);
forceField->setAtomParameters(i, 0, 1.5, 1); forceField->setAtomParameters(i, 0, 1.5, 1);
forceField->setNonbonded14Parameters(0, 0, 3, 0, 1.5, i == 3 ? 0.5 : 0.0);
forceField->setNonbonded14Parameters(1, 1, 4, 0, 1.5, 0.0);
positions[i] = Vec3(r, 0, 0); positions[i] = Vec3(r, 0, 0);
OpenMMContext context(system, integrator, platform); OpenMMContext context(system, integrator, platform);
context.setPositions(positions); context.setPositions(positions);
...@@ -242,6 +244,8 @@ void testExclusionsAnd14() { ...@@ -242,6 +244,8 @@ void testExclusionsAnd14() {
forceField->setAtomParameters(0, 2, 1.5, 0); forceField->setAtomParameters(0, 2, 1.5, 0);
forceField->setAtomParameters(i, 2, 1.5, 0); forceField->setAtomParameters(i, 2, 1.5, 0);
forceField->setNonbonded14Parameters(0, 0, 3, i == 3 ? 4/1.2 : 0, 1.5, 0);
forceField->setNonbonded14Parameters(1, 1, 4, 0, 1.5, 0);
OpenMMContext context2(system, integrator, platform); OpenMMContext context2(system, integrator, platform);
context2.setPositions(positions); context2.setPositions(positions);
state = context2.getState(State::Forces | State::Energy); state = context2.getState(State::Forces | State::Energy);
...@@ -266,7 +270,7 @@ void testCutoff() { ...@@ -266,7 +270,7 @@ void testCutoff() {
CudaPlatform platform; CudaPlatform platform;
System system(3, 0); System system(3, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01); LangevinIntegrator integrator(0.0, 0.1, 0.01);
StandardMMForceField* forceField = new StandardMMForceField(3, 0, 0, 0, 0); StandardMMForceField* forceField = new StandardMMForceField(3, 0, 0, 0, 0, 0);
forceField->setAtomParameters(0, 1.0, 1, 0); forceField->setAtomParameters(0, 1.0, 1, 0);
forceField->setAtomParameters(1, 1.0, 1, 0); forceField->setAtomParameters(1, 1.0, 1, 0);
forceField->setAtomParameters(2, 1.0, 1, 0); forceField->setAtomParameters(2, 1.0, 1, 0);
...@@ -299,7 +303,7 @@ void testCutoff14() { ...@@ -299,7 +303,7 @@ void testCutoff14() {
CudaPlatform platform; CudaPlatform platform;
System system(5, 0); System system(5, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01); LangevinIntegrator integrator(0.0, 0.1, 0.01);
StandardMMForceField* forceField = new StandardMMForceField(5, 4, 0, 0, 0); StandardMMForceField* forceField = new StandardMMForceField(5, 4, 0, 0, 0, 2);
forceField->setBondParameters(0, 0, 1, 1, 0); forceField->setBondParameters(0, 0, 1, 1, 0);
forceField->setBondParameters(1, 1, 2, 1, 0); forceField->setBondParameters(1, 1, 2, 1, 0);
forceField->setBondParameters(2, 2, 3, 1, 0); forceField->setBondParameters(2, 2, 3, 1, 0);
...@@ -323,6 +327,8 @@ void testCutoff14() { ...@@ -323,6 +327,8 @@ void testCutoff14() {
for (int j = 1; j < 5; ++j) for (int j = 1; j < 5; ++j)
forceField->setAtomParameters(j, 0, 1.5, 0); forceField->setAtomParameters(j, 0, 1.5, 0);
forceField->setAtomParameters(i, 0, 1.5, 1); forceField->setAtomParameters(i, 0, 1.5, 1);
forceField->setNonbonded14Parameters(0, 0, 3, 0, 1.5, i == 3 ? 0.5 : 0.0);
forceField->setNonbonded14Parameters(1, 1, 4, 0, 1.5, 0.0);
context.reinitialize(); context.reinitialize();
context.setPositions(positions); context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy); State state = context.getState(State::Forces | State::Energy);
...@@ -349,6 +355,8 @@ void testCutoff14() { ...@@ -349,6 +355,8 @@ void testCutoff14() {
const double q = 0.7; const double q = 0.7;
forceField->setAtomParameters(0, q, 1.5, 0); forceField->setAtomParameters(0, q, 1.5, 0);
forceField->setAtomParameters(i, q, 1.5, 0); forceField->setAtomParameters(i, q, 1.5, 0);
forceField->setNonbonded14Parameters(0, 0, 3, i == 3 ? q*q/1.2 : 0, 1.5, 0);
forceField->setNonbonded14Parameters(1, 1, 4, 0, 1.5, 0);
context.reinitialize(); context.reinitialize();
context.setPositions(positions); context.setPositions(positions);
state = context.getState(State::Forces | State::Energy); state = context.getState(State::Forces | State::Energy);
...@@ -376,7 +384,7 @@ void testPeriodic() { ...@@ -376,7 +384,7 @@ void testPeriodic() {
CudaPlatform platform; CudaPlatform platform;
System system(3, 0); System system(3, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01); LangevinIntegrator integrator(0.0, 0.1, 0.01);
StandardMMForceField* forceField = new StandardMMForceField(3, 1, 0, 0, 0); StandardMMForceField* forceField = new StandardMMForceField(3, 1, 0, 0, 0, 0);
forceField->setAtomParameters(0, 1.0, 1, 0); forceField->setAtomParameters(0, 1.0, 1, 0);
forceField->setAtomParameters(1, 1.0, 1, 0); forceField->setAtomParameters(1, 1.0, 1, 0);
forceField->setAtomParameters(2, 1.0, 1, 0); forceField->setAtomParameters(2, 1.0, 1, 0);
......
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