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