Commit d099819a authored by Peter Eastman's avatar Peter Eastman
Browse files

Global parameters defined by CustomNonbondedForce can have default values

parent 3ea53872
......@@ -187,9 +187,10 @@ public:
* Add a new global parmeter that the interaction may depend on.
*
* @param name the name of the parameter
* @param defaultValue the default value of the parameter
* @return the index of the parameter that was added
*/
int addGlobalParameter(const std::string& name);
int addGlobalParameter(const std::string& name, double defaultValue);
/**
* Get the name of a global parameter.
*
......@@ -204,6 +205,20 @@ public:
* @param name the name of the parameter
*/
void setGlobalParameterName(int index, const std::string& name);
/**
* Get the default value of a global parameter.
*
* @param index the index of the parameter for which to get the default value
* @return the parameter default value
*/
double getGlobalParameterDefaultValue(int index) const;
/**
* Set the default value of a global parameter.
*
* @param index the index of the parameter for which to set the default value
* @param name the default value of the parameter
*/
void setGlobalParameterDefaultValue(int index, double defaultValue);
/**
* Add the nonbonded force parameters for a particle. This should be called once for each particle
* in the System. When it is called for the i'th time, it specifies the parameters for the i'th particle.
......@@ -263,13 +278,14 @@ protected:
private:
class ParticleInfo;
class ParameterInfo;
class GlobalParameterInfo;
class ExceptionInfo;
NonbondedMethod nonbondedMethod;
double cutoffDistance;
Vec3 periodicBoxVectors[3];
std::string energyExpression;
std::vector<ParameterInfo> parameters;
std::vector<std::string> globalParameters;
std::vector<GlobalParameterInfo> globalParameters;
std::vector<ParticleInfo> particles;
std::vector<ExceptionInfo> exceptions;
std::map<std::pair<int, int>, int> exceptionMap;
......@@ -293,6 +309,16 @@ public:
}
};
class CustomNonbondedForce::GlobalParameterInfo {
public:
std::string name;
double defaultValue;
GlobalParameterInfo() {
}
GlobalParameterInfo(const std::string& name, double defaultValue) : name(name), defaultValue(defaultValue) {
}
};
class CustomNonbondedForce::ExceptionInfo {
public:
int particle1, particle2;
......
......@@ -55,7 +55,7 @@ class ForceImpl;
class OPENMM_EXPORT Force {
public:
Force() {}
Force() {}
virtual ~Force() {
}
protected:
......@@ -68,8 +68,8 @@ protected:
virtual ForceImpl* createImpl() = 0;
private:
Force& operator=(const Force& rhs);
Force(const Force& rhs);
Force& operator=(const Force& rhs);
Force(const Force& rhs);
};
} // namespace OpenMM
......
......@@ -115,17 +115,25 @@ void CustomNonbondedForce::setParameterCombiningRule(int index, const string& co
parameters[index].combiningRule = combiningRule;
}
int CustomNonbondedForce::addGlobalParameter(const string& name) {
globalParameters.push_back(name);
int CustomNonbondedForce::addGlobalParameter(const string& name, double defaultValue) {
globalParameters.push_back(GlobalParameterInfo(name, defaultValue));
return globalParameters.size()-1;
}
const string& CustomNonbondedForce::getGlobalParameterName(int index) const {
return globalParameters[index];
return globalParameters[index].name;
}
void CustomNonbondedForce::setGlobalParameterName(int index, const string& name) {
globalParameters[index] = name;
globalParameters[index].name = name;
}
double CustomNonbondedForce::getGlobalParameterDefaultValue(int index) const {
return globalParameters[index].defaultValue;
}
void CustomNonbondedForce::setGlobalParameterDefaultValue(int index, double defaultValue) {
globalParameters[index].defaultValue = defaultValue;
}
int CustomNonbondedForce::addParticle(const vector<double>& parameters) {
......
......@@ -121,6 +121,6 @@ vector<string> CustomNonbondedForceImpl::getKernelNames() {
map<string, double> CustomNonbondedForceImpl::getDefaultParameters() {
map<string, double> parameters;
for (int i = 0; i < owner.getNumGlobalParameters(); i++)
parameters[owner.getGlobalParameterName(i)] = 0.0;
parameters[owner.getGlobalParameterName(i)] = owner.getGlobalParameterDefaultValue(i);
return parameters;
}
......@@ -80,8 +80,8 @@ void testParameters() {
CustomNonbondedForce* forceField = new CustomNonbondedForce("scale*a*(r*b)^3");
forceField->addParameter("a", "a1*a2");
forceField->addParameter("b", "c+b1+b2");
forceField->addGlobalParameter("scale");
forceField->addGlobalParameter("c");
forceField->addGlobalParameter("scale", 3.0);
forceField->addGlobalParameter("c", -1.0);
vector<double> params(2);
params[0] = 1.5;
params[1] = 2.0;
......
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