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
......@@ -47,10 +47,10 @@ namespace OpenMM {
class PeriodicTorsionForceImpl : public ForceImpl {
public:
PeriodicTorsionForceImpl(PeriodicTorsionForce& owner);
PeriodicTorsionForceImpl(const PeriodicTorsionForce& owner);
~PeriodicTorsionForceImpl();
void initialize(ContextImpl& context);
PeriodicTorsionForce& getOwner() {
const PeriodicTorsionForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -63,7 +63,7 @@ public:
std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context);
private:
PeriodicTorsionForce& owner;
const PeriodicTorsionForce& owner;
Kernel kernel;
};
......
......@@ -47,10 +47,10 @@ namespace OpenMM {
class RBTorsionForceImpl : public ForceImpl {
public:
RBTorsionForceImpl(RBTorsionForce& owner);
RBTorsionForceImpl(const RBTorsionForce& owner);
~RBTorsionForceImpl();
void initialize(ContextImpl& context);
RBTorsionForce& getOwner() {
const RBTorsionForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
......@@ -63,7 +63,7 @@ public:
std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context);
private:
RBTorsionForce& owner;
const RBTorsionForce& owner;
Kernel kernel;
};
......
......@@ -40,6 +40,6 @@ AndersenThermostat::AndersenThermostat(double defaultTemperature, double default
setRandomNumberSeed((int) time(NULL));
}
ForceImpl* AndersenThermostat::createImpl() {
ForceImpl* AndersenThermostat::createImpl() const {
return new AndersenThermostatImpl(*this);
}
......@@ -39,7 +39,7 @@
using namespace OpenMM;
using std::vector;
AndersenThermostatImpl::AndersenThermostatImpl(AndersenThermostat& owner) : owner(owner) {
AndersenThermostatImpl::AndersenThermostatImpl(const AndersenThermostat& owner) : owner(owner) {
}
void AndersenThermostatImpl::initialize(ContextImpl& context) {
......
......@@ -92,7 +92,7 @@ void CMAPTorsionForce::setTorsionParameters(int index, int map, int a1, int a2,
torsions[index].b4 = b4;
}
ForceImpl* CMAPTorsionForce::createImpl() {
ForceImpl* CMAPTorsionForce::createImpl() const {
return new CMAPTorsionForceImpl(*this);
}
......@@ -41,7 +41,7 @@
using namespace OpenMM;
using namespace std;
CMAPTorsionForceImpl::CMAPTorsionForceImpl(CMAPTorsionForce& owner) : owner(owner) {
CMAPTorsionForceImpl::CMAPTorsionForceImpl(const CMAPTorsionForce& owner) : owner(owner) {
}
CMAPTorsionForceImpl::~CMAPTorsionForceImpl() {
......
......@@ -37,6 +37,6 @@ using namespace OpenMM;
CMMotionRemover::CMMotionRemover(int frequency) : frequency(frequency) {
}
ForceImpl* CMMotionRemover::createImpl() {
ForceImpl* CMMotionRemover::createImpl() const {
return new CMMotionRemoverImpl(*this);
}
......@@ -39,7 +39,7 @@
using namespace OpenMM;
using std::vector;
CMMotionRemoverImpl::CMMotionRemoverImpl(CMMotionRemover& owner) : owner(owner) {
CMMotionRemoverImpl::CMMotionRemoverImpl(const CMMotionRemover& owner) : owner(owner) {
}
void CMMotionRemoverImpl::initialize(ContextImpl& context) {
......
......@@ -40,15 +40,15 @@
using namespace OpenMM;
using namespace std;
Context::Context(System& system, Integrator& integrator) : properties(map<string, string>()) {
Context::Context(const System& system, Integrator& integrator) : properties(map<string, string>()) {
impl = new ContextImpl(*this, system, integrator, 0, properties);
}
Context::Context(System& system, Integrator& integrator, Platform& platform) : properties(map<string, string>()) {
Context::Context(const System& system, Integrator& integrator, Platform& platform) : properties(map<string, string>()) {
impl = new ContextImpl(*this, system, integrator, &platform, properties);
}
Context::Context(System& system, Integrator& integrator, Platform& platform, const map<string, string>& properties) : properties(properties) {
Context::Context(const System& system, Integrator& integrator, Platform& platform, const map<string, string>& properties) : properties(properties) {
impl = new ContextImpl(*this, system, integrator, &platform, properties);
}
......@@ -61,10 +61,6 @@ const System& Context::getSystem() const {
}
System& Context::getSystem() {
return impl->getSystem();
}
const Integrator& Context::getIntegrator() const {
return impl->getIntegrator();
}
......@@ -204,7 +200,7 @@ void Context::setVelocities(const vector<Vec3>& velocities) {
}
void Context::setVelocitiesToTemperature(double temperature, int randomSeed) {
System& system = impl->getSystem();
const System& system = impl->getSystem();
// Generate the list of Gaussian random numbers.
......@@ -263,7 +259,7 @@ void Context::computeVirtualSites() {
}
void Context::reinitialize() {
System& system = impl->getSystem();
const System& system = impl->getSystem();
Integrator& integrator = impl->getIntegrator();
Platform& platform = impl->getPlatform();
integrator.cleanup();
......
......@@ -47,7 +47,7 @@
using namespace OpenMM;
using namespace std;
ContextImpl::ContextImpl(Context& owner, System& system, Integrator& integrator, Platform* platform, const map<string, string>& properties) :
ContextImpl::ContextImpl(Context& owner, const System& system, Integrator& integrator, Platform* platform, const map<string, string>& properties) :
owner(owner), system(system), integrator(integrator), hasInitializedForces(false), hasSetPositions(false), integratorIsDeleted(false),
lastForceGroups(-1), platform(platform), platformData(NULL) {
if (system.getNumParticles() == 0)
......
......@@ -116,7 +116,7 @@ void CustomAngleForce::setAngleParameters(int index, int particle1, int particle
angles[index].particle3 = particle3;
}
ForceImpl* CustomAngleForce::createImpl() {
ForceImpl* CustomAngleForce::createImpl() const {
return new CustomAngleForceImpl(*this);
}
......
......@@ -43,7 +43,7 @@ using std::set;
using std::string;
using std::stringstream;
CustomAngleForceImpl::CustomAngleForceImpl(CustomAngleForce& owner) : owner(owner) {
CustomAngleForceImpl::CustomAngleForceImpl(const CustomAngleForce& owner) : owner(owner) {
}
CustomAngleForceImpl::~CustomAngleForceImpl() {
......@@ -53,8 +53,7 @@ void CustomAngleForceImpl::initialize(ContextImpl& context) {
kernel = context.getPlatform().createKernel(CalcCustomAngleForceKernel::Name(), context);
// Check for errors in the specification of bonds.
System& system = context.getSystem();
const System& system = context.getSystem();
vector<double> parameters;
int numParameters = owner.getNumPerAngleParameters();
for (int i = 0; i < owner.getNumAngles(); i++) {
......
......@@ -114,7 +114,7 @@ void CustomBondForce::setBondParameters(int index, int particle1, int particle2,
bonds[index].particle2 = particle2;
}
ForceImpl* CustomBondForce::createImpl() {
ForceImpl* CustomBondForce::createImpl() const {
return new CustomBondForceImpl(*this);
}
......
......@@ -43,7 +43,7 @@ using std::set;
using std::string;
using std::stringstream;
CustomBondForceImpl::CustomBondForceImpl(CustomBondForce& owner) : owner(owner) {
CustomBondForceImpl::CustomBondForceImpl(const CustomBondForce& owner) : owner(owner) {
}
CustomBondForceImpl::~CustomBondForceImpl() {
......@@ -54,7 +54,7 @@ void CustomBondForceImpl::initialize(ContextImpl& context) {
// Check for errors in the specification of bonds.
System& system = context.getSystem();
const System& system = context.getSystem();
vector<double> parameters;
int numParameters = owner.getNumPerBondParameters();
for (int i = 0; i < owner.getNumBonds(); i++) {
......
......@@ -149,7 +149,7 @@ void CustomCompoundBondForce::setFunctionParameters(int index, const std::string
functions[index].max = max;
}
ForceImpl* CustomCompoundBondForce::createImpl() {
ForceImpl* CustomCompoundBondForce::createImpl() const {
return new CustomCompoundBondForceImpl(*this);
}
......
......@@ -71,7 +71,7 @@ public:
}
};
CustomCompoundBondForceImpl::CustomCompoundBondForceImpl(CustomCompoundBondForce& owner) : owner(owner) {
CustomCompoundBondForceImpl::CustomCompoundBondForceImpl(const CustomCompoundBondForce& owner) : owner(owner) {
}
CustomCompoundBondForceImpl::~CustomCompoundBondForceImpl() {
......@@ -82,7 +82,7 @@ void CustomCompoundBondForceImpl::initialize(ContextImpl& context) {
// Check for errors in the specification of parameters and exclusions.
System& system = context.getSystem();
const System& system = context.getSystem();
vector<int> particles;
vector<double> parameters;
int numBondParameters = owner.getNumPerBondParameters();
......
......@@ -112,7 +112,7 @@ void CustomExternalForce::setParticleParameters(int index, int particle, const v
particles[index].particle = particle;
}
ForceImpl* CustomExternalForce::createImpl() {
ForceImpl* CustomExternalForce::createImpl() const {
return new CustomExternalForceImpl(*this);
}
......
......@@ -43,7 +43,7 @@ using std::set;
using std::string;
using std::stringstream;
CustomExternalForceImpl::CustomExternalForceImpl(CustomExternalForce& owner) : owner(owner) {
CustomExternalForceImpl::CustomExternalForceImpl(const CustomExternalForce& owner) : owner(owner) {
}
CustomExternalForceImpl::~CustomExternalForceImpl() {
......@@ -54,7 +54,7 @@ void CustomExternalForceImpl::initialize(ContextImpl& context) {
// Check for errors in the specification of bonds.
System& system = context.getSystem();
const System& system = context.getSystem();
vector<double> parameters;
int numParameters = owner.getNumPerParticleParameters();
for (int i = 0; i < owner.getNumParticles(); i++) {
......
......@@ -202,7 +202,7 @@ void CustomGBForce::setFunctionParameters(int index, const std::string& name, co
functions[index].max = max;
}
ForceImpl* CustomGBForce::createImpl() {
ForceImpl* CustomGBForce::createImpl() const {
return new CustomGBForceImpl(*this);
}
......
......@@ -43,7 +43,7 @@ using std::set;
using std::string;
using std::stringstream;
CustomGBForceImpl::CustomGBForceImpl(CustomGBForce& owner) : owner(owner) {
CustomGBForceImpl::CustomGBForceImpl(const CustomGBForce& owner) : owner(owner) {
}
CustomGBForceImpl::~CustomGBForceImpl() {
......@@ -54,7 +54,7 @@ void CustomGBForceImpl::initialize(ContextImpl& context) {
// Check for errors in the specification of parameters and exclusions.
System& system = context.getSystem();
const System& system = context.getSystem();
if (owner.getNumParticles() != system.getNumParticles())
throw OpenMMException("CustomGBForce must have exactly as many particles as the System it belongs to.");
vector<set<int> > exclusions(owner.getNumParticles());
......
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