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