"platforms/reference/include/ReferenceCustomNonbondedIxn.h" did not exist on "a63645c0913af551f99b77f7d82982e654a0274d"
Commit f8c52d1b authored by John Chodera (MSKCC)'s avatar John Chodera (MSKCC)
Browse files

Added serialization of more properties, as well as unit test extensions for these additions.

parent 4255709b
......@@ -152,6 +152,28 @@ public:
* @param value the value to set for the property
*/
SerializationNode& setIntProperty(const std::string& name, int value);
/**
* Get the property with a particular name, specified as an bool. If there is no property with
* the specified name, an exception is thrown.
*
* @param name the name of the property to get
*/
int getBoolProperty(const std::string& name) const;
/**
* Get the property with a particular name, specified as a bool. If there is no property with
* the specified name, a default value is returned instead.
*
* @param name the name of the property to get
* @param defaultValue the value to return if the specified property does not exist
*/
int getBoolProperty(const std::string& name, bool defaultValue) const;
/**
* Set the value of a property, specified as a bool.
*
* @param name the name of the property to set
* @param value the value to set for the property
*/
SerializationNode& setBoolProperty(const std::string& name, bool value);
/**
* Get the property with a particular name, specified as a double. If there is no property with
* the specified name, an exception is thrown.
......
......@@ -90,7 +90,7 @@ void CustomNonbondedForceProxy::serialize(const void* object, SerializationNode&
for (std::set<int>::iterator it = set1.begin(); it != set1.end(); ++it)
set1node.createChildNode("Particle").setIntProperty("index", *it);
SerializationNode& set2node = interactionGroup.createChildNode("Set2");
for (std::set<int>::iterator it = set1.begin(); it != set1.end(); ++it)
for (std::set<int>::iterator it = set2.begin(); it != set2.end(); ++it)
set2node.createChildNode("Particle").setIntProperty("index", *it);
}
}
......
......@@ -121,6 +121,32 @@ SerializationNode& SerializationNode::setIntProperty(const string& name, int val
return *this;
}
int SerializationNode::getBoolProperty(const string& name) const {
map<string, string>::const_iterator iter = properties.find(name);
if (iter == properties.end())
throw OpenMMException("Unknown property '"+name+"' in node '"+getName()+"'");
bool value;
stringstream(iter->second) >> value;
return value;
}
int SerializationNode::getBoolProperty(const string& name, bool defaultValue) const {
map<string, string>::const_iterator iter = properties.find(name);
if (iter == properties.end())
return defaultValue;
bool value;
stringstream(iter->second) >> value;
return value;
}
SerializationNode& SerializationNode::setBoolProperty(const string& name, bool value) {
stringstream s;
s << value;
properties[name] = s.str();
return *this;
}
double SerializationNode::getDoubleProperty(const string& name) const {
map<string, string>::const_iterator iter = properties.find(name);
if (iter == properties.end())
......
......@@ -38,6 +38,12 @@
using namespace OpenMM;
using namespace std;
void show_set(std::set<int> &set) {
for(std::set<int>::iterator it = set.begin(); it != set.end(); it++)
cout << *it << " ";
cout << endl;
}
void testSerialization() {
// Create a Force.
......@@ -124,6 +130,8 @@ void testSerialization() {
ASSERT_EQUAL(force.getNumInteractionGroups(), force2.getNumInteractionGroups());
std::set<int> set1c, set2c;
force2.getInteractionGroupParameters(0, set1c, set2c);
ASSERT_EQUAL_CONTAINERS(set1, set1c);
ASSERT_EQUAL_CONTAINERS(set2, set2c);
}
int main() {
......
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