Commit 780bbf8f authored by peastman's avatar peastman
Browse files

Merge pull request #412 from peastman/master

Cleanup to the recent serialization code changes
parents 436d542d 7a6f4b2f
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2010 Stanford University and the Authors. * * Portions copyright (c) 2010-2014 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -82,16 +82,16 @@ void CustomNonbondedForceProxy::serialize(const void* object, SerializationNode& ...@@ -82,16 +82,16 @@ void CustomNonbondedForceProxy::serialize(const void* object, SerializationNode&
SerializationNode& interactionGroups = node.createChildNode("InteractionGroups"); SerializationNode& interactionGroups = node.createChildNode("InteractionGroups");
for (int i = 0; i < force.getNumInteractionGroups(); i++) { for (int i = 0; i < force.getNumInteractionGroups(); i++) {
SerializationNode& interactionGroup = interactionGroups.createChildNode("InteractionGroup"); SerializationNode& interactionGroup = interactionGroups.createChildNode("InteractionGroup");
std::set<int> set1; std::set<int> set1;
std::set<int> set2; std::set<int> set2;
force.getInteractionGroupParameters(i, set1, set2); force.getInteractionGroupParameters(i, set1, set2);
SerializationNode& set1node = interactionGroup.createChildNode("Set1"); SerializationNode& set1node = interactionGroup.createChildNode("Set1");
for (std::set<int>::iterator it = set1.begin(); it != set1.end(); ++it) for (std::set<int>::iterator it = set1.begin(); it != set1.end(); ++it)
set1node.createChildNode("Particle").setIntProperty("index", *it); set1node.createChildNode("Particle").setIntProperty("index", *it);
SerializationNode& set2node = interactionGroup.createChildNode("Set2"); SerializationNode& set2node = interactionGroup.createChildNode("Set2");
for (std::set<int>::iterator it = set2.begin(); it != set2.end(); ++it) for (std::set<int>::iterator it = set2.begin(); it != set2.end(); ++it)
set2node.createChildNode("Particle").setIntProperty("index", *it); set2node.createChildNode("Particle").setIntProperty("index", *it);
} }
} }
...@@ -102,7 +102,7 @@ void* CustomNonbondedForceProxy::deserialize(const SerializationNode& node) cons ...@@ -102,7 +102,7 @@ void* CustomNonbondedForceProxy::deserialize(const SerializationNode& node) cons
try { try {
CustomNonbondedForce* force = new CustomNonbondedForce(node.getStringProperty("energy")); CustomNonbondedForce* force = new CustomNonbondedForce(node.getStringProperty("energy"));
force->setNonbondedMethod((CustomNonbondedForce::NonbondedMethod) node.getIntProperty("method")); force->setNonbondedMethod((CustomNonbondedForce::NonbondedMethod) node.getIntProperty("method"));
force->setCutoffDistance(node.getDoubleProperty("cutoff", 1.0)); force->setCutoffDistance(node.getDoubleProperty("cutoff"));
force->setUseSwitchingFunction(node.getBoolProperty("useSwitchingFunction", false)); force->setUseSwitchingFunction(node.getBoolProperty("useSwitchingFunction", false));
force->setSwitchingDistance(node.getDoubleProperty("switchingDistance", -1.0)); force->setSwitchingDistance(node.getDoubleProperty("switchingDistance", -1.0));
force->setUseLongRangeCorrection(node.getBoolProperty("useLongRangeCorrection", false)); force->setUseLongRangeCorrection(node.getBoolProperty("useLongRangeCorrection", false));
...@@ -149,25 +149,27 @@ void* CustomNonbondedForceProxy::deserialize(const SerializationNode& node) cons ...@@ -149,25 +149,27 @@ void* CustomNonbondedForceProxy::deserialize(const SerializationNode& node) cons
force->addTabulatedFunction(function.getStringProperty("name"), new Continuous1DFunction(values, function.getDoubleProperty("min"), function.getDoubleProperty("max"))); force->addTabulatedFunction(function.getStringProperty("name"), new Continuous1DFunction(values, function.getDoubleProperty("min"), function.getDoubleProperty("max")));
} }
} }
// Catch exceptions if InteractionGroups node is missing, in order to give backwards compatibility. bool hasInteractionGroups = false; // Older files will be missing this block.
try{ for (int i = 0; i < (int) node.getChildren().size(); i++) {
const SerializationNode& interactionGroups = node.getChildNode("InteractionGroups"); if (node.getChildren()[i].getName() == "InteractionGroups")
for (int i = 0; i < (int) interactionGroups.getChildren().size(); i++) { hasInteractionGroups = true;
const SerializationNode& interactionGroup = interactionGroups.getChildren()[i]; }
// Get set 1. if (hasInteractionGroups) {
const SerializationNode& set1node = interactionGroup.getChildNode("Set1"); const SerializationNode& interactionGroups = node.getChildNode("InteractionGroups");
std::set<int> set1; for (int i = 0; i < (int) interactionGroups.getChildren().size(); i++) {
for (int j = 0; j < (int) set1node.getChildren().size(); j++) const SerializationNode& interactionGroup = interactionGroups.getChildren()[i];
set1.insert(set1node.getChildren()[j].getIntProperty("index")); // Get set 1.
// Get set 2. const SerializationNode& set1node = interactionGroup.getChildNode("Set1");
const SerializationNode& set2node = interactionGroup.getChildNode("Set2"); std::set<int> set1;
std::set<int> set2; for (int j = 0; j < (int) set1node.getChildren().size(); j++)
for (int j = 0; j < (int) set2node.getChildren().size(); j++) set1.insert(set1node.getChildren()[j].getIntProperty("index"));
set2.insert(set2node.getChildren()[j].getIntProperty("index")); // Get set 2.
force->addInteractionGroup(set1, set2); const SerializationNode& set2node = interactionGroup.getChildNode("Set2");
} std::set<int> set2;
} catch (...) { for (int j = 0; j < (int) set2node.getChildren().size(); j++)
// do nothing to allow backwards-compatibility set2.insert(set2node.getChildren()[j].getIntProperty("index"));
force->addInteractionGroup(set1, set2);
}
} }
return force; return force;
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2010 Stanford University and the Authors. * * Portions copyright (c) 2010-2014 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -80,20 +80,18 @@ void* NonbondedForceProxy::deserialize(const SerializationNode& node) const { ...@@ -80,20 +80,18 @@ void* NonbondedForceProxy::deserialize(const SerializationNode& node) const {
NonbondedForce* force = new NonbondedForce(); NonbondedForce* force = new NonbondedForce();
try { try {
force->setNonbondedMethod((NonbondedForce::NonbondedMethod) node.getIntProperty("method")); force->setNonbondedMethod((NonbondedForce::NonbondedMethod) node.getIntProperty("method"));
force->setCutoffDistance(node.getDoubleProperty("cutoff",1.0)); force->setCutoffDistance(node.getDoubleProperty("cutoff"));
force->setUseSwitchingFunction(node.getBoolProperty("useSwitchingFunction",false)); force->setUseSwitchingFunction(node.getBoolProperty("useSwitchingFunction", false));
force->setSwitchingDistance(node.getDoubleProperty("switchingDistance",-1.0)); force->setSwitchingDistance(node.getDoubleProperty("switchingDistance", -1.0));
force->setEwaldErrorTolerance(node.getDoubleProperty("ewaldTolerance",5e-4)); force->setEwaldErrorTolerance(node.getDoubleProperty("ewaldTolerance"));
force->setReactionFieldDielectric(node.getDoubleProperty("rfDielectric",78.3)); force->setReactionFieldDielectric(node.getDoubleProperty("rfDielectric"));
force->setUseDispersionCorrection(node.getIntProperty("dispersionCorrection",true)); force->setUseDispersionCorrection(node.getIntProperty("dispersionCorrection"));
double alpha; double alpha = node.getDoubleProperty("alpha", 0.0);
int nx, ny, nz; int nx = node.getIntProperty("nx", 0);
alpha = node.getDoubleProperty("alpha",0.0); int ny = node.getIntProperty("ny", 0);
nx = node.getIntProperty("nx",0); int nz = node.getIntProperty("nz", 0);
ny = node.getIntProperty("ny",0);
nz = node.getIntProperty("nz",0);
force->setPMEParameters(alpha, nx, ny, nz); force->setPMEParameters(alpha, nx, ny, nz);
force->setReciprocalSpaceForceGroup(node.getIntProperty("recipForceGroup",-1)); force->setReciprocalSpaceForceGroup(node.getIntProperty("recipForceGroup", -1));
const SerializationNode& particles = node.getChildNode("Particles"); const SerializationNode& particles = node.getChildNode("Particles");
for (int i = 0; i < (int) particles.getChildren().size(); i++) { for (int i = 0; i < (int) particles.getChildren().size(); i++) {
const SerializationNode& particle = particles.getChildren()[i]; const SerializationNode& particle = particles.getChildren()[i];
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2010 Stanford University and the Authors. * * Portions copyright (c) 2010-2014 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -66,6 +66,7 @@ void testSerialization() { ...@@ -66,6 +66,7 @@ void testSerialization() {
std::set<int> set1, set2; std::set<int> set1, set2;
set1.insert(0); set1.insert(0);
set2.insert(1); set2.insert(1);
set2.insert(2);
force.addInteractionGroup(set1, set2); force.addInteractionGroup(set1, set2);
// Serialize and then deserialize it. // Serialize and then deserialize it.
......
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