Commit 202c24d9 authored by peastman's avatar peastman
Browse files

Fixed a bug in serializing CustomCentroidBondForce

parent 71de4b1b
...@@ -64,7 +64,8 @@ void CustomCentroidBondForceProxy::serialize(const void* object, SerializationNo ...@@ -64,7 +64,8 @@ void CustomCentroidBondForceProxy::serialize(const void* object, SerializationNo
for (int j = 0; j < (int) particles.size(); j++) { for (int j = 0; j < (int) particles.size(); j++) {
SerializationNode& node = group.createChildNode("Particle"); SerializationNode& node = group.createChildNode("Particle");
node.setIntProperty("p", particles[j]); node.setIntProperty("p", particles[j]);
node.setDoubleProperty("weight", weights[j]); if (j < weights.size())
node.setDoubleProperty("weight", weights[j]);
} }
} }
SerializationNode& bonds = node.createChildNode("Bonds"); SerializationNode& bonds = node.createChildNode("Bonds");
...@@ -115,7 +116,8 @@ void* CustomCentroidBondForceProxy::deserialize(const SerializationNode& node) c ...@@ -115,7 +116,8 @@ void* CustomCentroidBondForceProxy::deserialize(const SerializationNode& node) c
vector<double> weights; vector<double> weights;
for (int j = 0; j < (int) group.getChildren().size(); j++) { for (int j = 0; j < (int) group.getChildren().size(); j++) {
particles.push_back(group.getChildren()[j].getIntProperty("p")); particles.push_back(group.getChildren()[j].getIntProperty("p"));
weights.push_back(group.getChildren()[j].getDoubleProperty("weight")); if (group.getChildren()[j].hasProperty("weight"))
weights.push_back(group.getChildren()[j].getDoubleProperty("weight"));
} }
force->addGroup(particles, weights); force->addGroup(particles, weights);
} }
......
...@@ -51,7 +51,8 @@ void testSerialization() { ...@@ -51,7 +51,8 @@ void testSerialization() {
vector<double> weights; vector<double> weights;
for (int j = 0; j < i+1; j++) { for (int j = 0; j < i+1; j++) {
particles.push_back(i+j); particles.push_back(i+j);
weights.push_back(1.0/(i+1)); if (i < 2)
weights.push_back(1.0/(i+1));
} }
force.addGroup(particles, weights); force.addGroup(particles, weights);
} }
......
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