Commit 0307a0db authored by Yutong Zhao's avatar Yutong Zhao
Browse files

Context constructor now uses const System&, guaranteeing that System won't be modified.

parent 19757775
......@@ -118,7 +118,7 @@ public:
*/
void updateParametersInContext(Context& context);
protected:
ForceImpl* createImpl();
ForceImpl* createImpl() const;
private:
class RBTorsionInfo;
std::vector<RBTorsionInfo> rbTorsions;
......
......@@ -47,9 +47,9 @@ class System;
class OPENMM_EXPORT AndersenThermostatImpl : public ForceImpl {
public:
AndersenThermostatImpl(AndersenThermostat& owner);
AndersenThermostatImpl(const AndersenThermostat& owner);
void initialize(ContextImpl& context);
AndersenThermostat& getOwner() {
const AndersenThermostat& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context);
......@@ -66,7 +66,7 @@ public:
static std::vector<std::vector<int> > calcParticleGroups(const System& system);
private:
static void tagParticlesInGroup(int particle, int group, std::vector<int>& particleGroup, std::vector<std::vector<int> >& particleConstraints);
AndersenThermostat& owner;
const AndersenThermostat& owner;
Kernel kernel;
};
......
......@@ -46,10 +46,10 @@ namespace OpenMM {
class OPENMM_EXPORT CMAPTorsionForceImpl : public ForceImpl {
public:
CMAPTorsionForceImpl(CMAPTorsionForce& owner);
CMAPTorsionForceImpl(const CMAPTorsionForce& owner);
~CMAPTorsionForceImpl();
void initialize(ContextImpl& context);
CMAPTorsionForce& getOwner() {
const CMAPTorsionForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -65,7 +65,7 @@ public:
*/
static void calcMapDerivatives(int size, const std::vector<double>& energy, std::vector<std::vector<double> >& c);
private:
CMAPTorsionForce& owner;
const CMAPTorsionForce& owner;
Kernel kernel;
};
......
......@@ -44,9 +44,9 @@ namespace OpenMM {
class CMMotionRemoverImpl : public ForceImpl {
public:
CMMotionRemoverImpl(CMMotionRemover& owner);
CMMotionRemoverImpl(const CMMotionRemover& owner);
void initialize(ContextImpl& context);
CMMotionRemover& getOwner() {
const CMMotionRemover& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context);
......@@ -59,7 +59,7 @@ public:
}
std::vector<std::string> getKernelNames();
private:
CMMotionRemover& owner;
const CMMotionRemover& owner;
Kernel kernel;
};
......
......@@ -55,7 +55,7 @@ public:
/**
* Create an ContextImpl for a Context;
*/
ContextImpl(Context& owner, System& system, Integrator& integrator, Platform* platform, const std::map<std::string, std::string>& properties);
ContextImpl(Context& owner, const System& system, Integrator& integrator, Platform* platform, const std::map<std::string, std::string>& properties);
~ContextImpl();
/**
* Get the Context for which this is the implementation.
......@@ -66,7 +66,7 @@ public:
/**
* Get System being simulated in this context.
*/
System& getSystem() {
const System& getSystem() const {
return system;
}
/**
......@@ -254,7 +254,7 @@ private:
friend class Context;
static void tagParticlesInMolecule(int particle, int molecule, std::vector<int>& particleMolecule, std::vector<std::vector<int> >& particleBonds);
Context& owner;
System& system;
const System& system;
Integrator& integrator;
std::vector<ForceImpl*> forceImpls;
std::map<std::string, double> parameters;
......
......@@ -47,10 +47,10 @@ namespace OpenMM {
class CustomAngleForceImpl : public ForceImpl {
public:
CustomAngleForceImpl(CustomAngleForce& owner);
CustomAngleForceImpl(const CustomAngleForce& owner);
~CustomAngleForceImpl();
void initialize(ContextImpl& context);
CustomAngleForce& getOwner() {
const CustomAngleForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -61,7 +61,7 @@ public:
std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context);
private:
CustomAngleForce& owner;
const CustomAngleForce& owner;
Kernel kernel;
};
......
......@@ -47,10 +47,10 @@ namespace OpenMM {
class CustomBondForceImpl : public ForceImpl {
public:
CustomBondForceImpl(CustomBondForce& owner);
CustomBondForceImpl(const CustomBondForce& owner);
~CustomBondForceImpl();
void initialize(ContextImpl& context);
CustomBondForce& getOwner() {
const CustomBondForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -62,7 +62,7 @@ public:
std::vector<std::pair<int, int> > getBondedParticles() const;
void updateParametersInContext(ContextImpl& context);
private:
CustomBondForce& owner;
const CustomBondForce& owner;
Kernel kernel;
};
......
......@@ -50,10 +50,10 @@ namespace OpenMM {
class OPENMM_EXPORT CustomCompoundBondForceImpl : public ForceImpl {
public:
CustomCompoundBondForceImpl(CustomCompoundBondForce& owner);
CustomCompoundBondForceImpl(const CustomCompoundBondForce& owner);
~CustomCompoundBondForceImpl();
void initialize(ContextImpl& context);
CustomCompoundBondForce& getOwner() {
const CustomCompoundBondForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -84,7 +84,7 @@ private:
static Lepton::ExpressionTreeNode replaceFunctions(const Lepton::ExpressionTreeNode& node, std::map<std::string, int> atoms,
std::map<std::string, std::vector<int> >& distances, std::map<std::string, std::vector<int> >& angles,
std::map<std::string, std::vector<int> >& dihedrals);
CustomCompoundBondForce& owner;
const CustomCompoundBondForce& owner;
Kernel kernel;
};
......
......@@ -47,10 +47,10 @@ namespace OpenMM {
class CustomExternalForceImpl : public ForceImpl {
public:
CustomExternalForceImpl(CustomExternalForce& owner);
CustomExternalForceImpl(const CustomExternalForce& owner);
~CustomExternalForceImpl();
void initialize(ContextImpl& context);
CustomExternalForce& getOwner() {
const CustomExternalForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -61,7 +61,7 @@ public:
std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context);
private:
CustomExternalForce& owner;
const CustomExternalForce& owner;
Kernel kernel;
};
......
......@@ -47,10 +47,10 @@ namespace OpenMM {
class CustomGBForceImpl : public ForceImpl {
public:
CustomGBForceImpl(CustomGBForce& owner);
CustomGBForceImpl(const CustomGBForce& owner);
~CustomGBForceImpl();
void initialize(ContextImpl& context);
CustomGBForce& getOwner() {
const CustomGBForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -61,7 +61,7 @@ public:
std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context);
private:
CustomGBForce& owner;
const CustomGBForce& owner;
Kernel kernel;
};
......
......@@ -50,10 +50,10 @@ namespace OpenMM {
class OPENMM_EXPORT CustomHbondForceImpl : public ForceImpl {
public:
CustomHbondForceImpl(CustomHbondForce& owner);
CustomHbondForceImpl(const CustomHbondForce& owner);
~CustomHbondForceImpl();
void initialize(ContextImpl& context);
CustomHbondForce& getOwner() {
const CustomHbondForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -85,7 +85,7 @@ private:
static Lepton::ExpressionTreeNode replaceFunctions(const Lepton::ExpressionTreeNode& node, std::map<std::string, int> atoms,
std::map<std::string, std::vector<int> >& distances, std::map<std::string, std::vector<int> >& angles,
std::map<std::string, std::vector<int> >& dihedrals);
CustomHbondForce& owner;
const CustomHbondForce& owner;
Kernel kernel;
};
......
......@@ -47,10 +47,10 @@ namespace OpenMM {
class CustomNonbondedForceImpl : public ForceImpl {
public:
CustomNonbondedForceImpl(CustomNonbondedForce& owner);
CustomNonbondedForceImpl(const CustomNonbondedForce& owner);
~CustomNonbondedForceImpl();
void initialize(ContextImpl& context);
CustomNonbondedForce& getOwner() {
const CustomNonbondedForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -61,7 +61,7 @@ public:
std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context);
private:
CustomNonbondedForce& owner;
const CustomNonbondedForce& owner;
Kernel kernel;
};
......
......@@ -47,10 +47,10 @@ namespace OpenMM {
class CustomTorsionForceImpl : public ForceImpl {
public:
CustomTorsionForceImpl(CustomTorsionForce& owner);
CustomTorsionForceImpl(const CustomTorsionForce& owner);
~CustomTorsionForceImpl();
void initialize(ContextImpl& context);
CustomTorsionForce& getOwner() {
const CustomTorsionForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -61,7 +61,7 @@ public:
std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context);
private:
CustomTorsionForce& owner;
const CustomTorsionForce& owner;
Kernel kernel;
};
......
......@@ -66,7 +66,7 @@ public:
/**
* Get the Force object from which this ForceImpl was created.
*/
virtual Force& getOwner() = 0;
virtual const Force& getOwner() const = 0;
/**
* This method is called at the beginning of each time step. It give the ForceImpl a chance
* to modify the state variables (positions, velocities, and parameters) stored in the
......
......@@ -45,9 +45,9 @@ namespace OpenMM {
class GBSAOBCForceImpl : public ForceImpl {
public:
GBSAOBCForceImpl(GBSAOBCForce& owner);
GBSAOBCForceImpl(const GBSAOBCForce& owner);
void initialize(ContextImpl& context);
GBSAOBCForce& getOwner() {
const GBSAOBCForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -60,7 +60,7 @@ public:
std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context);
private:
GBSAOBCForce& owner;
const GBSAOBCForce& owner;
Kernel kernel;
};
......
......@@ -45,9 +45,9 @@ namespace OpenMM {
class GBVIForceImpl : public ForceImpl {
public:
GBVIForceImpl(GBVIForce& owner);
GBVIForceImpl(const GBVIForce& owner);
void initialize(ContextImpl& context);
GBVIForce& getOwner() {
const GBVIForce& getOwner() const {
return owner;
}
......@@ -68,7 +68,7 @@ public:
}
std::vector<std::string> getKernelNames();
private:
GBVIForce& owner;
const GBVIForce& owner;
Kernel kernel;
};
......
......@@ -47,10 +47,10 @@ namespace OpenMM {
class HarmonicAngleForceImpl : public ForceImpl {
public:
HarmonicAngleForceImpl(HarmonicAngleForce& owner);
HarmonicAngleForceImpl(const HarmonicAngleForce& owner);
~HarmonicAngleForceImpl();
void initialize(ContextImpl& context);
HarmonicAngleForce& getOwner() {
const HarmonicAngleForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -63,7 +63,7 @@ public:
std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context);
private:
HarmonicAngleForce& owner;
const HarmonicAngleForce& owner;
Kernel kernel;
};
......
......@@ -47,10 +47,10 @@ namespace OpenMM {
class HarmonicBondForceImpl : public ForceImpl {
public:
HarmonicBondForceImpl(HarmonicBondForce& owner);
HarmonicBondForceImpl(const HarmonicBondForce& owner);
~HarmonicBondForceImpl();
void initialize(ContextImpl& context);
HarmonicBondForce& getOwner() {
const HarmonicBondForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -64,7 +64,7 @@ public:
std::vector<std::pair<int, int> > getBondedParticles() const;
void updateParametersInContext(ContextImpl& context);
private:
HarmonicBondForce& owner;
const HarmonicBondForce& owner;
Kernel kernel;
};
......
......@@ -46,9 +46,9 @@ namespace OpenMM {
class MonteCarloBarostatImpl : public ForceImpl {
public:
MonteCarloBarostatImpl(MonteCarloBarostat& owner);
MonteCarloBarostatImpl(const MonteCarloBarostat& owner);
void initialize(ContextImpl& context);
MonteCarloBarostat& getOwner() {
const MonteCarloBarostat& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context);
......@@ -59,7 +59,7 @@ public:
std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames();
private:
MonteCarloBarostat& owner;
const MonteCarloBarostat& owner;
int step, numAttempted, numAccepted;
double volumeScale;
OpenMM_SFMT::SFMT random;
......
......@@ -49,10 +49,10 @@ class System;
class OPENMM_EXPORT NonbondedForceImpl : public ForceImpl {
public:
NonbondedForceImpl(NonbondedForce& owner);
NonbondedForceImpl(const NonbondedForce& owner);
~NonbondedForceImpl();
void initialize(ContextImpl& context);
NonbondedForce& getOwner() {
const NonbondedForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -83,7 +83,7 @@ private:
class ErrorFunction;
class EwaldErrorFunction;
static int findZero(const ErrorFunction& f, int initialGuess);
NonbondedForce& owner;
const NonbondedForce& owner;
Kernel kernel;
};
......
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