bool CustomIntegratorUtilities::usesVariable(const Lepton::ExpressionTreeNode& node, const string& variable) { const Lepton::Operation& op = node.getOperation(); if (op.getId() == Lepton::Operation::VARIABLE && op.getName() == variable) return true; for (int i = 0; i < (int) node.getChildren().size(); i++) if (usesVariable(node.getChildren()[i], variable)) return true; return false; }
void CustomIntegratorUtilities::validateDerivatives(const Lepton::ExpressionTreeNode& node, const vector<string>& derivNames) { const Lepton::Operation& op = node.getOperation(); if (op.getId() == Lepton::Operation::CUSTOM && op.getName() == "deriv") { const Lepton::Operation& child = node.getChildren()[0].getOperation(); if (child.getId() != Lepton::Operation::VARIABLE || find(derivNames.begin(), derivNames.end(), child.getName()) == derivNames.end()) throw OpenMMException("The first argument to deriv() must be an energy variable"); if (node.getChildren()[1].getOperation().getId() != Lepton::Operation::VARIABLE) throw OpenMMException("The second argument to deriv() must be a context parameter"); } else { for (int i = 0; i < node.getChildren().size(); i++) validateDerivatives(node.getChildren()[i], derivNames); } }