Commit a162c89e authored by Robert McGibbon's avatar Robert McGibbon
Browse files

Add by-name getters to CustomIntegrator API

parent fb95c56c
...@@ -302,6 +302,13 @@ public: ...@@ -302,6 +302,13 @@ public:
* @return the current value of the variable * @return the current value of the variable
*/ */
double getGlobalVariable(int index) const; double getGlobalVariable(int index) const;
/**
* Get the current value of a global variable, specified by name.
*
* @param name the name of the variable to get
* @return the current value of the parameter
*/
double getGlobalVariableByName(const std::string& name);
/** /**
* Set the value of a global variable. * Set the value of a global variable.
* *
...@@ -324,6 +331,14 @@ public: ...@@ -324,6 +331,14 @@ public:
* are stored into this * are stored into this
*/ */
void getPerDofVariable(int index, std::vector<Vec3>& values) const; void getPerDofVariable(int index, std::vector<Vec3>& values) const;
/**
* Get the value of a per-DOF variable, specified by name.
*
* @param name the name of the variable to get
* @param values the values of the variable for all degrees of freedom
* are stored into this
*/
void getPerDofVariableByName(const std::string& name, std::vector<Vec3>& values) const;
/** /**
* Set the value of a per-DOF variable. * Set the value of a per-DOF variable.
* *
......
...@@ -124,6 +124,15 @@ double CustomIntegrator::getGlobalVariable(int index) const { ...@@ -124,6 +124,15 @@ double CustomIntegrator::getGlobalVariable(int index) const {
return globalValues[index]; return globalValues[index];
} }
double CustomIntegrator::getGlobalVariableByName(const string& name) const {
for (int i = 0; i < (int) globalNames.size(); i++)
if (name == globalNames[i]) {
return getGlobalVariable(i);
}
}
throw OpenMMException("Illegal global variable name: "+name);
}
void CustomIntegrator::setGlobalVariable(int index, double value) { void CustomIntegrator::setGlobalVariable(int index, double value) {
ASSERT_VALID_INDEX(index, globalValues); ASSERT_VALID_INDEX(index, globalValues);
if (owner != NULL && !globalsAreCurrent) { if (owner != NULL && !globalsAreCurrent) {
...@@ -152,6 +161,16 @@ void CustomIntegrator::getPerDofVariable(int index, vector<Vec3>& values) const ...@@ -152,6 +161,16 @@ void CustomIntegrator::getPerDofVariable(int index, vector<Vec3>& values) const
kernel.getAs<const IntegrateCustomStepKernel>().getPerDofVariable(*context, index, values); kernel.getAs<const IntegrateCustomStepKernel>().getPerDofVariable(*context, index, values);
} }
void CustomIntegrator::getPerDofVariableByName(const string& name, vector<Vec3>& values) const {
for (int i = 0; i < (int) perDofNames.size(); i++)
if (name == perDofNames[i]) {
getPerDofVariable(i, values);
return;
}
}
throw OpenMMException("Illegal per-DOF variable name: "+name);
}
void CustomIntegrator::setPerDofVariable(int index, const vector<Vec3>& values) { void CustomIntegrator::setPerDofVariable(int index, const vector<Vec3>& values) {
ASSERT_VALID_INDEX(index, perDofValues); ASSERT_VALID_INDEX(index, perDofValues);
if (owner != NULL && values.size() != context->getSystem().getNumParticles()) if (owner != NULL && values.size() != context->getSystem().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