Commit df07fbe9 authored by peastman's avatar peastman
Browse files

Serialization of parameter derivatives

parent ff8cac54
...@@ -42,7 +42,7 @@ CustomAngleForceProxy::CustomAngleForceProxy() : SerializationProxy("CustomAngle ...@@ -42,7 +42,7 @@ CustomAngleForceProxy::CustomAngleForceProxy() : SerializationProxy("CustomAngle
} }
void CustomAngleForceProxy::serialize(const void* object, SerializationNode& node) const { void CustomAngleForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 2); node.setIntProperty("version", 3);
const CustomAngleForce& force = *reinterpret_cast<const CustomAngleForce*>(object); const CustomAngleForce& force = *reinterpret_cast<const CustomAngleForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions()); node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
...@@ -55,6 +55,10 @@ void CustomAngleForceProxy::serialize(const void* object, SerializationNode& nod ...@@ -55,6 +55,10 @@ void CustomAngleForceProxy::serialize(const void* object, SerializationNode& nod
for (int i = 0; i < force.getNumGlobalParameters(); i++) { for (int i = 0; i < force.getNumGlobalParameters(); i++) {
globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i)); globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i));
} }
SerializationNode& energyDerivs = node.createChildNode("EnergyParameterDerivatives");
for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++) {
energyDerivs.createChildNode("Parameter").setStringProperty("name", force.getEnergyParameterDerivativeName(i));
}
SerializationNode& angles = node.createChildNode("Angles"); SerializationNode& angles = node.createChildNode("Angles");
for (int i = 0; i < force.getNumAngles(); i++) { for (int i = 0; i < force.getNumAngles(); i++) {
int p1, p2, p3; int p1, p2, p3;
...@@ -72,7 +76,7 @@ void CustomAngleForceProxy::serialize(const void* object, SerializationNode& nod ...@@ -72,7 +76,7 @@ void CustomAngleForceProxy::serialize(const void* object, SerializationNode& nod
void* CustomAngleForceProxy::deserialize(const SerializationNode& node) const { void* CustomAngleForceProxy::deserialize(const SerializationNode& node) const {
int version = node.getIntProperty("version"); int version = node.getIntProperty("version");
if (version < 1 || version > 2) if (version < 1 || version > 3)
throw OpenMMException("Unsupported version number"); throw OpenMMException("Unsupported version number");
CustomAngleForce* force = NULL; CustomAngleForce* force = NULL;
try { try {
...@@ -90,6 +94,13 @@ void* CustomAngleForceProxy::deserialize(const SerializationNode& node) const { ...@@ -90,6 +94,13 @@ void* CustomAngleForceProxy::deserialize(const SerializationNode& node) const {
const SerializationNode& parameter = globalParams.getChildren()[i]; const SerializationNode& parameter = globalParams.getChildren()[i];
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default")); force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
} }
if (version > 2) {
const SerializationNode& energyDerivs = node.getChildNode("EnergyParameterDerivatives");
for (int i = 0; i < (int) energyDerivs.getChildren().size(); i++) {
const SerializationNode& parameter = energyDerivs.getChildren()[i];
force->addEnergyParameterDerivative(parameter.getStringProperty("name"));
}
}
const SerializationNode& angles = node.getChildNode("Angles"); const SerializationNode& angles = node.getChildNode("Angles");
vector<double> params(force->getNumPerAngleParameters()); vector<double> params(force->getNumPerAngleParameters());
for (int i = 0; i < (int) angles.getChildren().size(); i++) { for (int i = 0; i < (int) angles.getChildren().size(); i++) {
......
...@@ -42,7 +42,7 @@ CustomBondForceProxy::CustomBondForceProxy() : SerializationProxy("CustomBondFor ...@@ -42,7 +42,7 @@ CustomBondForceProxy::CustomBondForceProxy() : SerializationProxy("CustomBondFor
} }
void CustomBondForceProxy::serialize(const void* object, SerializationNode& node) const { void CustomBondForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 2); node.setIntProperty("version", 3);
const CustomBondForce& force = *reinterpret_cast<const CustomBondForce*>(object); const CustomBondForce& force = *reinterpret_cast<const CustomBondForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions()); node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
...@@ -55,6 +55,10 @@ void CustomBondForceProxy::serialize(const void* object, SerializationNode& node ...@@ -55,6 +55,10 @@ void CustomBondForceProxy::serialize(const void* object, SerializationNode& node
for (int i = 0; i < force.getNumGlobalParameters(); i++) { for (int i = 0; i < force.getNumGlobalParameters(); i++) {
globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i)); globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i));
} }
SerializationNode& energyDerivs = node.createChildNode("EnergyParameterDerivatives");
for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++) {
energyDerivs.createChildNode("Parameter").setStringProperty("name", force.getEnergyParameterDerivativeName(i));
}
SerializationNode& bonds = node.createChildNode("Bonds"); SerializationNode& bonds = node.createChildNode("Bonds");
for (int i = 0; i < force.getNumBonds(); i++) { for (int i = 0; i < force.getNumBonds(); i++) {
int p1, p2; int p1, p2;
...@@ -72,7 +76,7 @@ void CustomBondForceProxy::serialize(const void* object, SerializationNode& node ...@@ -72,7 +76,7 @@ void CustomBondForceProxy::serialize(const void* object, SerializationNode& node
void* CustomBondForceProxy::deserialize(const SerializationNode& node) const { void* CustomBondForceProxy::deserialize(const SerializationNode& node) const {
int version = node.getIntProperty("version"); int version = node.getIntProperty("version");
if (version < 1 || version > 2) if (version < 1 || version > 3)
throw OpenMMException("Unsupported version number"); throw OpenMMException("Unsupported version number");
CustomBondForce* force = NULL; CustomBondForce* force = NULL;
try { try {
...@@ -90,6 +94,13 @@ void* CustomBondForceProxy::deserialize(const SerializationNode& node) const { ...@@ -90,6 +94,13 @@ void* CustomBondForceProxy::deserialize(const SerializationNode& node) const {
const SerializationNode& parameter = globalParams.getChildren()[i]; const SerializationNode& parameter = globalParams.getChildren()[i];
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default")); force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
} }
if (version > 2) {
const SerializationNode& energyDerivs = node.getChildNode("EnergyParameterDerivatives");
for (int i = 0; i < (int) energyDerivs.getChildren().size(); i++) {
const SerializationNode& parameter = energyDerivs.getChildren()[i];
force->addEnergyParameterDerivative(parameter.getStringProperty("name"));
}
}
const SerializationNode& bonds = node.getChildNode("Bonds"); const SerializationNode& bonds = node.getChildNode("Bonds");
vector<double> params(force->getNumPerBondParameters()); vector<double> params(force->getNumPerBondParameters());
for (int i = 0; i < (int) bonds.getChildren().size(); i++) { for (int i = 0; i < (int) bonds.getChildren().size(); i++) {
......
...@@ -42,7 +42,7 @@ CustomCentroidBondForceProxy::CustomCentroidBondForceProxy() : SerializationProx ...@@ -42,7 +42,7 @@ CustomCentroidBondForceProxy::CustomCentroidBondForceProxy() : SerializationProx
} }
void CustomCentroidBondForceProxy::serialize(const void* object, SerializationNode& node) const { void CustomCentroidBondForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 2); node.setIntProperty("version", 3);
const CustomCentroidBondForce& force = *reinterpret_cast<const CustomCentroidBondForce*>(object); const CustomCentroidBondForce& force = *reinterpret_cast<const CustomCentroidBondForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions()); node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
...@@ -56,6 +56,10 @@ void CustomCentroidBondForceProxy::serialize(const void* object, SerializationNo ...@@ -56,6 +56,10 @@ void CustomCentroidBondForceProxy::serialize(const void* object, SerializationNo
for (int i = 0; i < force.getNumGlobalParameters(); i++) { for (int i = 0; i < force.getNumGlobalParameters(); i++) {
globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i)); globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i));
} }
SerializationNode& energyDerivs = node.createChildNode("EnergyParameterDerivatives");
for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++) {
energyDerivs.createChildNode("Parameter").setStringProperty("name", force.getEnergyParameterDerivativeName(i));
}
SerializationNode& groups = node.createChildNode("Groups"); SerializationNode& groups = node.createChildNode("Groups");
for (int i = 0; i < force.getNumGroups(); i++) { for (int i = 0; i < force.getNumGroups(); i++) {
vector<int> particles; vector<int> particles;
...@@ -95,7 +99,7 @@ void CustomCentroidBondForceProxy::serialize(const void* object, SerializationNo ...@@ -95,7 +99,7 @@ void CustomCentroidBondForceProxy::serialize(const void* object, SerializationNo
void* CustomCentroidBondForceProxy::deserialize(const SerializationNode& node) const { void* CustomCentroidBondForceProxy::deserialize(const SerializationNode& node) const {
int version = node.getIntProperty("version"); int version = node.getIntProperty("version");
if (version < 1 || version > 2) if (version < 1 || version > 3)
throw OpenMMException("Unsupported version number"); throw OpenMMException("Unsupported version number");
CustomCentroidBondForce* force = NULL; CustomCentroidBondForce* force = NULL;
try { try {
...@@ -113,6 +117,13 @@ void* CustomCentroidBondForceProxy::deserialize(const SerializationNode& node) c ...@@ -113,6 +117,13 @@ void* CustomCentroidBondForceProxy::deserialize(const SerializationNode& node) c
const SerializationNode& parameter = globalParams.getChildren()[i]; const SerializationNode& parameter = globalParams.getChildren()[i];
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default")); force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
} }
if (version > 2) {
const SerializationNode& energyDerivs = node.getChildNode("EnergyParameterDerivatives");
for (int i = 0; i < (int) energyDerivs.getChildren().size(); i++) {
const SerializationNode& parameter = energyDerivs.getChildren()[i];
force->addEnergyParameterDerivative(parameter.getStringProperty("name"));
}
}
const SerializationNode& groups = node.getChildNode("Groups"); const SerializationNode& groups = node.getChildNode("Groups");
for (int i = 0; i < (int) groups.getChildren().size(); i++) { for (int i = 0; i < (int) groups.getChildren().size(); i++) {
const SerializationNode& group = groups.getChildren()[i]; const SerializationNode& group = groups.getChildren()[i];
......
...@@ -42,7 +42,7 @@ CustomCompoundBondForceProxy::CustomCompoundBondForceProxy() : SerializationProx ...@@ -42,7 +42,7 @@ CustomCompoundBondForceProxy::CustomCompoundBondForceProxy() : SerializationProx
} }
void CustomCompoundBondForceProxy::serialize(const void* object, SerializationNode& node) const { void CustomCompoundBondForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 2); node.setIntProperty("version", 3);
const CustomCompoundBondForce& force = *reinterpret_cast<const CustomCompoundBondForce*>(object); const CustomCompoundBondForce& force = *reinterpret_cast<const CustomCompoundBondForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions()); node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
...@@ -56,6 +56,10 @@ void CustomCompoundBondForceProxy::serialize(const void* object, SerializationNo ...@@ -56,6 +56,10 @@ void CustomCompoundBondForceProxy::serialize(const void* object, SerializationNo
for (int i = 0; i < force.getNumGlobalParameters(); i++) { for (int i = 0; i < force.getNumGlobalParameters(); i++) {
globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i)); globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i));
} }
SerializationNode& energyDerivs = node.createChildNode("EnergyParameterDerivatives");
for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++) {
energyDerivs.createChildNode("Parameter").setStringProperty("name", force.getEnergyParameterDerivativeName(i));
}
SerializationNode& bonds = node.createChildNode("Bonds"); SerializationNode& bonds = node.createChildNode("Bonds");
for (int i = 0; i < force.getNumBonds(); i++) { for (int i = 0; i < force.getNumBonds(); i++) {
vector<int> particles; vector<int> particles;
...@@ -82,7 +86,7 @@ void CustomCompoundBondForceProxy::serialize(const void* object, SerializationNo ...@@ -82,7 +86,7 @@ void CustomCompoundBondForceProxy::serialize(const void* object, SerializationNo
void* CustomCompoundBondForceProxy::deserialize(const SerializationNode& node) const { void* CustomCompoundBondForceProxy::deserialize(const SerializationNode& node) const {
int version = node.getIntProperty("version"); int version = node.getIntProperty("version");
if (version < 1 || version > 2) if (version < 1 || version > 3)
throw OpenMMException("Unsupported version number"); throw OpenMMException("Unsupported version number");
CustomCompoundBondForce* force = NULL; CustomCompoundBondForce* force = NULL;
try { try {
...@@ -100,6 +104,13 @@ void* CustomCompoundBondForceProxy::deserialize(const SerializationNode& node) c ...@@ -100,6 +104,13 @@ void* CustomCompoundBondForceProxy::deserialize(const SerializationNode& node) c
const SerializationNode& parameter = globalParams.getChildren()[i]; const SerializationNode& parameter = globalParams.getChildren()[i];
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default")); force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
} }
if (version > 2) {
const SerializationNode& energyDerivs = node.getChildNode("EnergyParameterDerivatives");
for (int i = 0; i < (int) energyDerivs.getChildren().size(); i++) {
const SerializationNode& parameter = energyDerivs.getChildren()[i];
force->addEnergyParameterDerivative(parameter.getStringProperty("name"));
}
}
const SerializationNode& bonds = node.getChildNode("Bonds"); const SerializationNode& bonds = node.getChildNode("Bonds");
vector<int> particles(force->getNumParticlesPerBond()); vector<int> particles(force->getNumParticlesPerBond());
vector<double> params(force->getNumPerBondParameters()); vector<double> params(force->getNumPerBondParameters());
......
...@@ -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-2014 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -42,7 +42,7 @@ CustomGBForceProxy::CustomGBForceProxy() : SerializationProxy("CustomGBForce") { ...@@ -42,7 +42,7 @@ CustomGBForceProxy::CustomGBForceProxy() : SerializationProxy("CustomGBForce") {
} }
void CustomGBForceProxy::serialize(const void* object, SerializationNode& node) const { void CustomGBForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1); node.setIntProperty("version", 2);
const CustomGBForce& force = *reinterpret_cast<const CustomGBForce*>(object); const CustomGBForce& force = *reinterpret_cast<const CustomGBForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setIntProperty("method", (int) force.getNonbondedMethod()); node.setIntProperty("method", (int) force.getNonbondedMethod());
...@@ -55,6 +55,10 @@ void CustomGBForceProxy::serialize(const void* object, SerializationNode& node) ...@@ -55,6 +55,10 @@ void CustomGBForceProxy::serialize(const void* object, SerializationNode& node)
for (int i = 0; i < force.getNumGlobalParameters(); i++) { for (int i = 0; i < force.getNumGlobalParameters(); i++) {
globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i)); globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i));
} }
SerializationNode& energyDerivs = node.createChildNode("EnergyParameterDerivatives");
for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++) {
energyDerivs.createChildNode("Parameter").setStringProperty("name", force.getEnergyParameterDerivativeName(i));
}
SerializationNode& computedValues = node.createChildNode("ComputedValues"); SerializationNode& computedValues = node.createChildNode("ComputedValues");
for (int i = 0; i < force.getNumComputedValues(); i++) { for (int i = 0; i < force.getNumComputedValues(); i++) {
string name, expression; string name, expression;
...@@ -93,7 +97,8 @@ void CustomGBForceProxy::serialize(const void* object, SerializationNode& node) ...@@ -93,7 +97,8 @@ void CustomGBForceProxy::serialize(const void* object, SerializationNode& node)
} }
void* CustomGBForceProxy::deserialize(const SerializationNode& node) const { void* CustomGBForceProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1) int version = node.getIntProperty("version");
if (version < 1 || version > 2)
throw OpenMMException("Unsupported version number"); throw OpenMMException("Unsupported version number");
CustomGBForce* force = NULL; CustomGBForce* force = NULL;
try { try {
...@@ -111,6 +116,13 @@ void* CustomGBForceProxy::deserialize(const SerializationNode& node) const { ...@@ -111,6 +116,13 @@ void* CustomGBForceProxy::deserialize(const SerializationNode& node) const {
const SerializationNode& parameter = globalParams.getChildren()[i]; const SerializationNode& parameter = globalParams.getChildren()[i];
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default")); force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
} }
if (version > 1) {
const SerializationNode& energyDerivs = node.getChildNode("EnergyParameterDerivatives");
for (int i = 0; i < (int) energyDerivs.getChildren().size(); i++) {
const SerializationNode& parameter = energyDerivs.getChildren()[i];
force->addEnergyParameterDerivative(parameter.getStringProperty("name"));
}
}
const SerializationNode& computedValues = node.getChildNode("ComputedValues"); const SerializationNode& computedValues = node.getChildNode("ComputedValues");
for (int i = 0; i < (int) computedValues.getChildren().size(); i++) { for (int i = 0; i < (int) computedValues.getChildren().size(); i++) {
const SerializationNode& value = computedValues.getChildren()[i]; const SerializationNode& value = computedValues.getChildren()[i];
......
...@@ -42,7 +42,7 @@ CustomTorsionForceProxy::CustomTorsionForceProxy() : SerializationProxy("CustomT ...@@ -42,7 +42,7 @@ CustomTorsionForceProxy::CustomTorsionForceProxy() : SerializationProxy("CustomT
} }
void CustomTorsionForceProxy::serialize(const void* object, SerializationNode& node) const { void CustomTorsionForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 2); node.setIntProperty("version", 3);
const CustomTorsionForce& force = *reinterpret_cast<const CustomTorsionForce*>(object); const CustomTorsionForce& force = *reinterpret_cast<const CustomTorsionForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions()); node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
...@@ -55,6 +55,10 @@ void CustomTorsionForceProxy::serialize(const void* object, SerializationNode& n ...@@ -55,6 +55,10 @@ void CustomTorsionForceProxy::serialize(const void* object, SerializationNode& n
for (int i = 0; i < force.getNumGlobalParameters(); i++) { for (int i = 0; i < force.getNumGlobalParameters(); i++) {
globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i)); globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i));
} }
SerializationNode& energyDerivs = node.createChildNode("EnergyParameterDerivatives");
for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++) {
energyDerivs.createChildNode("Parameter").setStringProperty("name", force.getEnergyParameterDerivativeName(i));
}
SerializationNode& torsions = node.createChildNode("Torsions"); SerializationNode& torsions = node.createChildNode("Torsions");
for (int i = 0; i < force.getNumTorsions(); i++) { for (int i = 0; i < force.getNumTorsions(); i++) {
int p1, p2, p3, p4; int p1, p2, p3, p4;
...@@ -72,7 +76,7 @@ void CustomTorsionForceProxy::serialize(const void* object, SerializationNode& n ...@@ -72,7 +76,7 @@ void CustomTorsionForceProxy::serialize(const void* object, SerializationNode& n
void* CustomTorsionForceProxy::deserialize(const SerializationNode& node) const { void* CustomTorsionForceProxy::deserialize(const SerializationNode& node) const {
int version = node.getIntProperty("version"); int version = node.getIntProperty("version");
if (version < 1 || version > 2) if (version < 1 || version > 3)
throw OpenMMException("Unsupported version number"); throw OpenMMException("Unsupported version number");
CustomTorsionForce* force = NULL; CustomTorsionForce* force = NULL;
try { try {
...@@ -90,6 +94,13 @@ void* CustomTorsionForceProxy::deserialize(const SerializationNode& node) const ...@@ -90,6 +94,13 @@ void* CustomTorsionForceProxy::deserialize(const SerializationNode& node) const
const SerializationNode& parameter = globalParams.getChildren()[i]; const SerializationNode& parameter = globalParams.getChildren()[i];
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default")); force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
} }
if (version > 2) {
const SerializationNode& energyDerivs = node.getChildNode("EnergyParameterDerivatives");
for (int i = 0; i < (int) energyDerivs.getChildren().size(); i++) {
const SerializationNode& parameter = energyDerivs.getChildren()[i];
force->addEnergyParameterDerivative(parameter.getStringProperty("name"));
}
}
const SerializationNode& torsions = node.getChildNode("Torsions"); const SerializationNode& torsions = node.getChildNode("Torsions");
vector<double> params(force->getNumPerTorsionParameters()); vector<double> params(force->getNumPerTorsionParameters());
for (int i = 0; i < (int) torsions.getChildren().size(); i++) { for (int i = 0; i < (int) torsions.getChildren().size(); i++) {
......
...@@ -46,6 +46,7 @@ void testSerialization() { ...@@ -46,6 +46,7 @@ void testSerialization() {
force.addGlobalParameter("x", 1.3); force.addGlobalParameter("x", 1.3);
force.addGlobalParameter("y", 2.221); force.addGlobalParameter("y", 2.221);
force.addPerAngleParameter("z"); force.addPerAngleParameter("z");
force.addEnergyParameterDerivative("y");
vector<double> params(1); vector<double> params(1);
params[0] = 1.0; params[0] = 1.0;
force.addAngle(1, 2, 3, params); force.addAngle(1, 2, 3, params);
...@@ -74,6 +75,9 @@ void testSerialization() { ...@@ -74,6 +75,9 @@ void testSerialization() {
ASSERT_EQUAL(force.getGlobalParameterName(i), force2.getGlobalParameterName(i)); ASSERT_EQUAL(force.getGlobalParameterName(i), force2.getGlobalParameterName(i));
ASSERT_EQUAL(force.getGlobalParameterDefaultValue(i), force2.getGlobalParameterDefaultValue(i)); ASSERT_EQUAL(force.getGlobalParameterDefaultValue(i), force2.getGlobalParameterDefaultValue(i));
} }
ASSERT_EQUAL(force.getNumEnergyParameterDerivatives(), force2.getNumEnergyParameterDerivatives());
for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++)
ASSERT_EQUAL(force.getEnergyParameterDerivativeName(i), force2.getEnergyParameterDerivativeName(i));
ASSERT_EQUAL(force.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions()); ASSERT_EQUAL(force.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions());
ASSERT_EQUAL(force.getNumAngles(), force2.getNumAngles()); ASSERT_EQUAL(force.getNumAngles(), force2.getNumAngles());
for (int i = 0; i < force.getNumAngles(); i++) { for (int i = 0; i < force.getNumAngles(); i++) {
......
...@@ -46,6 +46,7 @@ void testSerialization() { ...@@ -46,6 +46,7 @@ void testSerialization() {
force.addGlobalParameter("x", 1.3); force.addGlobalParameter("x", 1.3);
force.addGlobalParameter("y", 2.221); force.addGlobalParameter("y", 2.221);
force.addPerBondParameter("z"); force.addPerBondParameter("z");
force.addEnergyParameterDerivative("y");
vector<double> params(1); vector<double> params(1);
params[0] = 1.0; params[0] = 1.0;
force.addBond(1, 2, params); force.addBond(1, 2, params);
...@@ -74,6 +75,9 @@ void testSerialization() { ...@@ -74,6 +75,9 @@ void testSerialization() {
ASSERT_EQUAL(force.getGlobalParameterName(i), force2.getGlobalParameterName(i)); ASSERT_EQUAL(force.getGlobalParameterName(i), force2.getGlobalParameterName(i));
ASSERT_EQUAL(force.getGlobalParameterDefaultValue(i), force2.getGlobalParameterDefaultValue(i)); ASSERT_EQUAL(force.getGlobalParameterDefaultValue(i), force2.getGlobalParameterDefaultValue(i));
} }
ASSERT_EQUAL(force.getNumEnergyParameterDerivatives(), force2.getNumEnergyParameterDerivatives());
for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++)
ASSERT_EQUAL(force.getEnergyParameterDerivativeName(i), force2.getEnergyParameterDerivativeName(i));
ASSERT_EQUAL(force.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions()); ASSERT_EQUAL(force.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions());
ASSERT_EQUAL(force.getNumBonds(), force2.getNumBonds()); ASSERT_EQUAL(force.getNumBonds(), force2.getNumBonds());
for (int i = 0; i < force.getNumBonds(); i++) { for (int i = 0; i < force.getNumBonds(); i++) {
......
...@@ -46,6 +46,7 @@ void testSerialization() { ...@@ -46,6 +46,7 @@ void testSerialization() {
force.addGlobalParameter("x", 1.3); force.addGlobalParameter("x", 1.3);
force.addGlobalParameter("y", 2.221); force.addGlobalParameter("y", 2.221);
force.addPerBondParameter("z"); force.addPerBondParameter("z");
force.addEnergyParameterDerivative("y");
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
vector<int> particles; vector<int> particles;
vector<double> weights; vector<double> weights;
...@@ -99,6 +100,9 @@ void testSerialization() { ...@@ -99,6 +100,9 @@ void testSerialization() {
ASSERT_EQUAL(force.getGlobalParameterName(i), force2.getGlobalParameterName(i)); ASSERT_EQUAL(force.getGlobalParameterName(i), force2.getGlobalParameterName(i));
ASSERT_EQUAL(force.getGlobalParameterDefaultValue(i), force2.getGlobalParameterDefaultValue(i)); ASSERT_EQUAL(force.getGlobalParameterDefaultValue(i), force2.getGlobalParameterDefaultValue(i));
} }
ASSERT_EQUAL(force.getNumEnergyParameterDerivatives(), force2.getNumEnergyParameterDerivatives());
for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++)
ASSERT_EQUAL(force.getEnergyParameterDerivativeName(i), force2.getEnergyParameterDerivativeName(i));
ASSERT_EQUAL(force.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions()); ASSERT_EQUAL(force.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions());
ASSERT_EQUAL(force.getNumGroups(), force2.getNumGroups()); ASSERT_EQUAL(force.getNumGroups(), force2.getNumGroups());
for (int i = 0; i < force.getNumGroups(); i++) { for (int i = 0; i < force.getNumGroups(); i++) {
......
...@@ -46,6 +46,7 @@ void testSerialization() { ...@@ -46,6 +46,7 @@ void testSerialization() {
force.addGlobalParameter("x", 1.3); force.addGlobalParameter("x", 1.3);
force.addGlobalParameter("y", 2.221); force.addGlobalParameter("y", 2.221);
force.addPerBondParameter("z"); force.addPerBondParameter("z");
force.addEnergyParameterDerivative("y");
vector<int> particles(3); vector<int> particles(3);
vector<double> params(1); vector<double> params(1);
particles[0] = 0; particles[0] = 0;
...@@ -89,6 +90,9 @@ void testSerialization() { ...@@ -89,6 +90,9 @@ void testSerialization() {
ASSERT_EQUAL(force.getGlobalParameterName(i), force2.getGlobalParameterName(i)); ASSERT_EQUAL(force.getGlobalParameterName(i), force2.getGlobalParameterName(i));
ASSERT_EQUAL(force.getGlobalParameterDefaultValue(i), force2.getGlobalParameterDefaultValue(i)); ASSERT_EQUAL(force.getGlobalParameterDefaultValue(i), force2.getGlobalParameterDefaultValue(i));
} }
ASSERT_EQUAL(force.getNumEnergyParameterDerivatives(), force2.getNumEnergyParameterDerivatives());
for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++)
ASSERT_EQUAL(force.getEnergyParameterDerivativeName(i), force2.getEnergyParameterDerivativeName(i));
ASSERT_EQUAL(force.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions()); ASSERT_EQUAL(force.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions());
ASSERT_EQUAL(force.getNumBonds(), force2.getNumBonds()); ASSERT_EQUAL(force.getNumBonds(), force2.getNumBonds());
for (int i = 0; i < force.getNumBonds(); i++) { for (int i = 0; i < force.getNumBonds(); 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-2014 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -48,6 +48,7 @@ void testSerialization() { ...@@ -48,6 +48,7 @@ void testSerialization() {
force.addGlobalParameter("x", 1.3); force.addGlobalParameter("x", 1.3);
force.addGlobalParameter("y", 2.221); force.addGlobalParameter("y", 2.221);
force.addPerParticleParameter("z"); force.addPerParticleParameter("z");
force.addEnergyParameterDerivative("y");
force.addComputedValue("a", "x+1", CustomGBForce::ParticlePairNoExclusions); force.addComputedValue("a", "x+1", CustomGBForce::ParticlePairNoExclusions);
force.addComputedValue("b", "y-1", CustomGBForce::SingleParticle); force.addComputedValue("b", "y-1", CustomGBForce::SingleParticle);
force.addEnergyTerm("a*b", CustomGBForce::SingleParticle); force.addEnergyTerm("a*b", CustomGBForce::SingleParticle);
...@@ -86,6 +87,9 @@ void testSerialization() { ...@@ -86,6 +87,9 @@ void testSerialization() {
ASSERT_EQUAL(force.getGlobalParameterName(i), force2.getGlobalParameterName(i)); ASSERT_EQUAL(force.getGlobalParameterName(i), force2.getGlobalParameterName(i));
ASSERT_EQUAL(force.getGlobalParameterDefaultValue(i), force2.getGlobalParameterDefaultValue(i)); ASSERT_EQUAL(force.getGlobalParameterDefaultValue(i), force2.getGlobalParameterDefaultValue(i));
} }
ASSERT_EQUAL(force.getNumEnergyParameterDerivatives(), force2.getNumEnergyParameterDerivatives());
for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++)
ASSERT_EQUAL(force.getEnergyParameterDerivativeName(i), force2.getEnergyParameterDerivativeName(i));
ASSERT_EQUAL(force.getNumComputedValues(), force2.getNumComputedValues()); ASSERT_EQUAL(force.getNumComputedValues(), force2.getNumComputedValues());
for (int i = 0; i < force.getNumComputedValues(); i++) { for (int i = 0; i < force.getNumComputedValues(); i++) {
string name1, name2, expression1, expression2; string name1, name2, expression1, expression2;
......
...@@ -46,6 +46,7 @@ void testSerialization() { ...@@ -46,6 +46,7 @@ void testSerialization() {
force.addGlobalParameter("x", 1.3); force.addGlobalParameter("x", 1.3);
force.addGlobalParameter("y", 2.221); force.addGlobalParameter("y", 2.221);
force.addPerTorsionParameter("z"); force.addPerTorsionParameter("z");
force.addEnergyParameterDerivative("y");
vector<double> params(1); vector<double> params(1);
params[0] = 1.0; params[0] = 1.0;
force.addTorsion(1, 2, 3, 4, params); force.addTorsion(1, 2, 3, 4, params);
...@@ -74,6 +75,9 @@ void testSerialization() { ...@@ -74,6 +75,9 @@ void testSerialization() {
ASSERT_EQUAL(force.getGlobalParameterName(i), force2.getGlobalParameterName(i)); ASSERT_EQUAL(force.getGlobalParameterName(i), force2.getGlobalParameterName(i));
ASSERT_EQUAL(force.getGlobalParameterDefaultValue(i), force2.getGlobalParameterDefaultValue(i)); ASSERT_EQUAL(force.getGlobalParameterDefaultValue(i), force2.getGlobalParameterDefaultValue(i));
} }
ASSERT_EQUAL(force.getNumEnergyParameterDerivatives(), force2.getNumEnergyParameterDerivatives());
for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++)
ASSERT_EQUAL(force.getEnergyParameterDerivativeName(i), force2.getEnergyParameterDerivativeName(i));
ASSERT_EQUAL(force.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions()); ASSERT_EQUAL(force.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions());
ASSERT_EQUAL(force.getNumTorsions(), force2.getNumTorsions()); ASSERT_EQUAL(force.getNumTorsions(), force2.getNumTorsions());
for (int i = 0; i < force.getNumTorsions(); i++) { for (int i = 0; i < force.getNumTorsions(); i++) {
......
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