Commit 77ea3bb6 authored by peastman's avatar peastman
Browse files

Merge pull request #627 from rmcgibbo/integrator-by-name

CustomIntegrator::get*VariableByName
parents 392a7b04 8ab5b907
......@@ -302,6 +302,13 @@ public:
* @return the current value of the variable
*/
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) const;
/**
* Set the value of a global variable.
*
......@@ -324,6 +331,14 @@ public:
* are stored into this
*/
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.
*
......
......@@ -124,6 +124,15 @@ double CustomIntegrator::getGlobalVariable(int index) const {
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) {
ASSERT_VALID_INDEX(index, globalValues);
if (owner != NULL && !globalsAreCurrent) {
......@@ -152,6 +161,16 @@ void CustomIntegrator::getPerDofVariable(int index, vector<Vec3>& values) const
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) {
ASSERT_VALID_INDEX(index, perDofValues);
if (owner != NULL && values.size() != context->getSystem().getNumParticles())
......
......@@ -161,6 +161,7 @@ UNITS = {
("*", "getEwaldErrorTolerance") : (None, ()),
("*", "getFriction") : ("1/unit.picosecond", ()),
("*", "getGlobalVariable") : (None, ()),
("*", "getGlobalVariableByName") : (None, ()),
("*", "getIntegrator") : (None, ()),
("*", "getMapParameters") : (None, ()),
("*", "getName") : (None, ()),
......
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