Commit 1f7866ad authored by peastman's avatar peastman Committed by GitHub
Browse files

Merge pull request #1547 from peastman/paramderivs

Energy derivatives with respect to global parameters
parents 37787af9 7851bad8
/* Portions copyright (c) 2009-2013 Stanford University and Simbios. /* Portions copyright (c) 2009-2016 Stanford University and Simbios.
* Contributors: Peter Eastman * Contributors: Peter Eastman
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
...@@ -44,23 +44,20 @@ using namespace OpenMM; ...@@ -44,23 +44,20 @@ using namespace OpenMM;
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceCustomNonbondedIxn::ReferenceCustomNonbondedIxn(const Lepton::CompiledExpression& energyExpression, ReferenceCustomNonbondedIxn::ReferenceCustomNonbondedIxn(const Lepton::CompiledExpression& energyExpression,
const Lepton::CompiledExpression& forceExpression, const vector<string>& parameterNames) : const Lepton::CompiledExpression& forceExpression, const vector<string>& parameterNames,
cutoff(false), useSwitch(false), periodic(false), energyExpression(energyExpression), forceExpression(forceExpression), paramNames(parameterNames) { const vector<Lepton::CompiledExpression> energyParamDerivExpressions) :
cutoff(false), useSwitch(false), periodic(false), energyExpression(energyExpression), forceExpression(forceExpression),
// --------------------------------------------------------------------------------------- paramNames(parameterNames), energyParamDerivExpressions(energyParamDerivExpressions) {
expressionSet.registerExpression(this->energyExpression);
// static const char* methodName = "\nReferenceCustomNonbondedIxn::ReferenceCustomNonbondedIxn"; expressionSet.registerExpression(this->forceExpression);
for (int i = 0; i < this->energyParamDerivExpressions.size(); i++)
// --------------------------------------------------------------------------------------- expressionSet.registerExpression(this->energyParamDerivExpressions[i]);
rIndex = expressionSet.getVariableIndex("r");
energyR = ReferenceForce::getVariablePointer(this->energyExpression, "r");
forceR = ReferenceForce::getVariablePointer(this->forceExpression, "r");
for (int i = 0; i < (int) paramNames.size(); i++) { for (int i = 0; i < (int) paramNames.size(); i++) {
for (int j = 1; j < 3; j++) { for (int j = 1; j < 3; j++) {
stringstream name; stringstream name;
name << paramNames[i] << j; name << paramNames[i] << j;
energyParticleParams.push_back(ReferenceForce::getVariablePointer(this->energyExpression, name.str())); particleParamIndex.push_back(expressionSet.getVariableIndex(name.str()));
forceParticleParams.push_back(ReferenceForce::getVariablePointer(this->forceExpression, name.str()));
} }
} }
} }
...@@ -167,12 +164,10 @@ void ReferenceCustomNonbondedIxn::setUseSwitchingFunction(RealOpenMM distance) { ...@@ -167,12 +164,10 @@ void ReferenceCustomNonbondedIxn::setUseSwitchingFunction(RealOpenMM distance) {
void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<RealVec>& atomCoordinates, void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<RealVec>& atomCoordinates,
RealOpenMM** atomParameters, vector<set<int> >& exclusions, RealOpenMM** atomParameters, vector<set<int> >& exclusions,
RealOpenMM* fixedParameters, const map<string, double>& globalParameters, vector<RealVec>& forces, RealOpenMM* fixedParameters, const map<string, double>& globalParameters, vector<RealVec>& forces,
RealOpenMM* energyByAtom, RealOpenMM* totalEnergy) { RealOpenMM* energyByAtom, RealOpenMM* totalEnergy, double* energyParamDerivs) {
for (map<string, double>::const_iterator iter = globalParameters.begin(); iter != globalParameters.end(); ++iter) { for (map<string, double>::const_iterator iter = globalParameters.begin(); iter != globalParameters.end(); ++iter)
ReferenceForce::setVariable(ReferenceForce::getVariablePointer(energyExpression, iter->first), iter->second); expressionSet.setVariable(expressionSet.getVariableIndex(iter->first), iter->second);
ReferenceForce::setVariable(ReferenceForce::getVariablePointer(forceExpression, iter->first), iter->second);
}
if (interactionGroups.size() > 0) { if (interactionGroups.size() > 0) {
// The user has specified interaction groups, so compute only the requested interactions. // The user has specified interaction groups, so compute only the requested interactions.
...@@ -186,12 +181,10 @@ void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<Rea ...@@ -186,12 +181,10 @@ void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<Rea
if (*atom1 > *atom2 && set1.find(*atom2) != set1.end() && set2.find(*atom1) != set2.end()) if (*atom1 > *atom2 && set1.find(*atom2) != set1.end() && set2.find(*atom1) != set2.end())
continue; // Both atoms are in both sets, so skip duplicate interactions. continue; // Both atoms are in both sets, so skip duplicate interactions.
for (int j = 0; j < (int) paramNames.size(); j++) { for (int j = 0; j < (int) paramNames.size(); j++) {
ReferenceForce::setVariable(energyParticleParams[j*2], atomParameters[*atom1][j]); expressionSet.setVariable(particleParamIndex[j*2], atomParameters[*atom1][j]);
ReferenceForce::setVariable(energyParticleParams[j*2+1], atomParameters[*atom2][j]); expressionSet.setVariable(particleParamIndex[j*2+1], atomParameters[*atom2][j]);
ReferenceForce::setVariable(forceParticleParams[j*2], atomParameters[*atom1][j]);
ReferenceForce::setVariable(forceParticleParams[j*2+1], atomParameters[*atom2][j]);
} }
calculateOneIxn(*atom1, *atom2, atomCoordinates, forces, energyByAtom, totalEnergy); calculateOneIxn(*atom1, *atom2, atomCoordinates, forces, energyByAtom, totalEnergy, energyParamDerivs);
} }
} }
} }
...@@ -202,12 +195,10 @@ void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<Rea ...@@ -202,12 +195,10 @@ void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<Rea
for (int i = 0; i < (int) neighborList->size(); i++) { for (int i = 0; i < (int) neighborList->size(); i++) {
OpenMM::AtomPair pair = (*neighborList)[i]; OpenMM::AtomPair pair = (*neighborList)[i];
for (int j = 0; j < (int) paramNames.size(); j++) { for (int j = 0; j < (int) paramNames.size(); j++) {
ReferenceForce::setVariable(energyParticleParams[j*2], atomParameters[pair.first][j]); expressionSet.setVariable(particleParamIndex[j*2], atomParameters[pair.first][j]);
ReferenceForce::setVariable(energyParticleParams[j*2+1], atomParameters[pair.second][j]); expressionSet.setVariable(particleParamIndex[j*2+1], atomParameters[pair.second][j]);
ReferenceForce::setVariable(forceParticleParams[j*2], atomParameters[pair.first][j]);
ReferenceForce::setVariable(forceParticleParams[j*2+1], atomParameters[pair.second][j]);
} }
calculateOneIxn(pair.first, pair.second, atomCoordinates, forces, energyByAtom, totalEnergy); calculateOneIxn(pair.first, pair.second, atomCoordinates, forces, energyByAtom, totalEnergy, energyParamDerivs);
} }
} }
else { else {
...@@ -217,12 +208,10 @@ void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<Rea ...@@ -217,12 +208,10 @@ void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<Rea
for (int jj = ii+1; jj < numberOfAtoms; jj++) { for (int jj = ii+1; jj < numberOfAtoms; jj++) {
if (exclusions[jj].find(ii) == exclusions[jj].end()) { if (exclusions[jj].find(ii) == exclusions[jj].end()) {
for (int j = 0; j < (int) paramNames.size(); j++) { for (int j = 0; j < (int) paramNames.size(); j++) {
ReferenceForce::setVariable(energyParticleParams[j*2], atomParameters[ii][j]); expressionSet.setVariable(particleParamIndex[j*2], atomParameters[ii][j]);
ReferenceForce::setVariable(energyParticleParams[j*2+1], atomParameters[jj][j]); expressionSet.setVariable(particleParamIndex[j*2+1], atomParameters[jj][j]);
ReferenceForce::setVariable(forceParticleParams[j*2], atomParameters[ii][j]);
ReferenceForce::setVariable(forceParticleParams[j*2+1], atomParameters[jj][j]);
} }
calculateOneIxn(ii, jj, atomCoordinates, forces, energyByAtom, totalEnergy); calculateOneIxn(ii, jj, atomCoordinates, forces, energyByAtom, totalEnergy, energyParamDerivs);
} }
} }
} }
...@@ -244,24 +233,7 @@ void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<Rea ...@@ -244,24 +233,7 @@ void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<Rea
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceCustomNonbondedIxn::calculateOneIxn(int ii, int jj, vector<RealVec>& atomCoordinates, vector<RealVec>& forces, void ReferenceCustomNonbondedIxn::calculateOneIxn(int ii, int jj, vector<RealVec>& atomCoordinates, vector<RealVec>& forces,
RealOpenMM* energyByAtom, RealOpenMM* totalEnergy) { RealOpenMM* energyByAtom, RealOpenMM* totalEnergy, double* energyParamDerivs) {
// ---------------------------------------------------------------------------------------
static const std::string methodName = "\nReferenceCustomNonbondedIxn::calculateOneIxn";
// ---------------------------------------------------------------------------------------
// constants -- reduce Visual Studio warnings regarding conversions between float & double
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
static const RealOpenMM two = 2.0;
static const RealOpenMM three = 3.0;
static const RealOpenMM six = 6.0;
static const RealOpenMM twelve = 12.0;
static const RealOpenMM oneM = -1.0;
// get deltaR, R2, and R between 2 atoms // get deltaR, R2, and R between 2 atoms
RealOpenMM deltaR[ReferenceForce::LastDeltaRIndex]; RealOpenMM deltaR[ReferenceForce::LastDeltaRIndex];
...@@ -275,14 +247,14 @@ void ReferenceCustomNonbondedIxn::calculateOneIxn(int ii, int jj, vector<RealVec ...@@ -275,14 +247,14 @@ void ReferenceCustomNonbondedIxn::calculateOneIxn(int ii, int jj, vector<RealVec
// accumulate forces // accumulate forces
ReferenceForce::setVariable(energyR, r); expressionSet.setVariable(rIndex, r);
ReferenceForce::setVariable(forceR, r);
RealOpenMM dEdR = (RealOpenMM) (forceExpression.evaluate()/(deltaR[ReferenceForce::RIndex])); RealOpenMM dEdR = (RealOpenMM) (forceExpression.evaluate()/(deltaR[ReferenceForce::RIndex]));
RealOpenMM energy = (RealOpenMM) energyExpression.evaluate(); RealOpenMM energy = (RealOpenMM) energyExpression.evaluate();
RealOpenMM switchValue = 1.0;
if (useSwitch) { if (useSwitch) {
if (r > switchingDistance) { if (r > switchingDistance) {
RealOpenMM t = (r-switchingDistance)/(cutoffDistance-switchingDistance); RealOpenMM t = (r-switchingDistance)/(cutoffDistance-switchingDistance);
RealOpenMM switchValue = 1+t*t*t*(-10+t*(15-t*6)); switchValue = 1+t*t*t*(-10+t*(15-t*6));
RealOpenMM switchDeriv = t*t*(-30+t*(60-t*30))/(cutoffDistance-switchingDistance); RealOpenMM switchDeriv = t*t*(-30+t*(60-t*30))/(cutoffDistance-switchingDistance);
dEdR = switchValue*dEdR + energy*switchDeriv/r; dEdR = switchValue*dEdR + energy*switchDeriv/r;
energy *= switchValue; energy *= switchValue;
...@@ -293,6 +265,8 @@ void ReferenceCustomNonbondedIxn::calculateOneIxn(int ii, int jj, vector<RealVec ...@@ -293,6 +265,8 @@ void ReferenceCustomNonbondedIxn::calculateOneIxn(int ii, int jj, vector<RealVec
forces[ii][kk] += force; forces[ii][kk] += force;
forces[jj][kk] -= force; forces[jj][kk] -= force;
} }
for (int i = 0; i < energyParamDerivExpressions.size(); i++)
energyParamDerivs[i] += switchValue*energyParamDerivExpressions[i].evaluate();
// accumulate energies // accumulate energies
......
...@@ -38,20 +38,19 @@ using namespace OpenMM; ...@@ -38,20 +38,19 @@ using namespace OpenMM;
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceCustomTorsionIxn::ReferenceCustomTorsionIxn(const Lepton::CompiledExpression& energyExpression, ReferenceCustomTorsionIxn::ReferenceCustomTorsionIxn(const Lepton::CompiledExpression& energyExpression,
const Lepton::CompiledExpression& forceExpression, const vector<string>& parameterNames, map<string, double> globalParameters) : const Lepton::CompiledExpression& forceExpression, const vector<string>& parameterNames, map<string, double> globalParameters,
energyExpression(energyExpression), forceExpression(forceExpression), usePeriodic(false) { const vector<Lepton::CompiledExpression> energyParamDerivExpressions) :
energyExpression(energyExpression), forceExpression(forceExpression), usePeriodic(false), energyParamDerivExpressions(energyParamDerivExpressions) {
energyTheta = ReferenceForce::getVariablePointer(this->energyExpression, "theta"); expressionSet.registerExpression(this->energyExpression);
forceTheta = ReferenceForce::getVariablePointer(this->forceExpression, "theta"); expressionSet.registerExpression(this->forceExpression);
for (int i = 0; i < this->energyParamDerivExpressions.size(); i++)
expressionSet.registerExpression(this->energyParamDerivExpressions[i]);
thetaIndex = expressionSet.getVariableIndex("theta");
numParameters = parameterNames.size(); numParameters = parameterNames.size();
for (int i = 0; i < (int) numParameters; i++) { for (int i = 0; i < (int) numParameters; i++)
energyParams.push_back(ReferenceForce::getVariablePointer(this->energyExpression, parameterNames[i])); torsionParamIndex.push_back(expressionSet.getVariableIndex(parameterNames[i]));
forceParams.push_back(ReferenceForce::getVariablePointer(this->forceExpression, parameterNames[i])); for (map<string, double>::const_iterator iter = globalParameters.begin(); iter != globalParameters.end(); ++iter)
} expressionSet.setVariable(expressionSet.getVariableIndex(iter->first), iter->second);
for (map<string, double>::const_iterator iter = globalParameters.begin(); iter != globalParameters.end(); ++iter) {
ReferenceForce::setVariable(ReferenceForce::getVariablePointer(this->energyExpression, iter->first), iter->second);
ReferenceForce::setVariable(ReferenceForce::getVariablePointer(this->forceExpression, iter->first), iter->second);
}
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -86,18 +85,10 @@ void ReferenceCustomTorsionIxn::calculateBondIxn(int* atomIndices, ...@@ -86,18 +85,10 @@ void ReferenceCustomTorsionIxn::calculateBondIxn(int* atomIndices,
vector<RealVec>& atomCoordinates, vector<RealVec>& atomCoordinates,
RealOpenMM* parameters, RealOpenMM* parameters,
vector<RealVec>& forces, vector<RealVec>& forces,
RealOpenMM* totalEnergy) const { RealOpenMM* totalEnergy, double* energyParamDerivs) {
static const std::string methodName = "\nReferenceCustomTorsionIxn::calculateTorsionIxn";
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
RealOpenMM deltaR[3][ReferenceForce::LastDeltaRIndex]; RealOpenMM deltaR[3][ReferenceForce::LastDeltaRIndex];
for (int i = 0; i < numParameters; i++) { for (int i = 0; i < numParameters; i++)
ReferenceForce::setVariable(energyParams[i], parameters[i]); expressionSet.setVariable(torsionParamIndex[i], parameters[i]);
ReferenceForce::setVariable(forceParams[i], parameters[i]);
}
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -130,8 +121,7 @@ void ReferenceCustomTorsionIxn::calculateBondIxn(int* atomIndices, ...@@ -130,8 +121,7 @@ void ReferenceCustomTorsionIxn::calculateBondIxn(int* atomIndices,
RealOpenMM dotDihedral; RealOpenMM dotDihedral;
RealOpenMM signOfAngle; RealOpenMM signOfAngle;
RealOpenMM angle = getDihedralAngleBetweenThreeVectors(deltaR[0], deltaR[1], deltaR[2], crossProduct, &dotDihedral, deltaR[0], &signOfAngle, 1); RealOpenMM angle = getDihedralAngleBetweenThreeVectors(deltaR[0], deltaR[1], deltaR[2], crossProduct, &dotDihedral, deltaR[0], &signOfAngle, 1);
ReferenceForce::setVariable(energyTheta, angle); expressionSet.setVariable(thetaIndex, angle);
ReferenceForce::setVariable(forceTheta, angle);
// evaluate delta angle, dE/d(angle) // evaluate delta angle, dE/d(angle)
...@@ -174,6 +164,11 @@ void ReferenceCustomTorsionIxn::calculateBondIxn(int* atomIndices, ...@@ -174,6 +164,11 @@ void ReferenceCustomTorsionIxn::calculateBondIxn(int* atomIndices,
forces[atomDIndex][ii] += internalF[3][ii]; forces[atomDIndex][ii] += internalF[3][ii];
} }
// Record parameter derivatives.
for (int i = 0; i < energyParamDerivExpressions.size(); i++)
energyParamDerivs[i] += energyParamDerivExpressions[i].evaluate();
// accumulate energies // accumulate energies
if (totalEnergy != NULL) if (totalEnergy != NULL)
......
...@@ -74,7 +74,7 @@ void ReferenceHarmonicBondIxn::calculateBondIxn(int* atomIndices, ...@@ -74,7 +74,7 @@ void ReferenceHarmonicBondIxn::calculateBondIxn(int* atomIndices,
vector<RealVec>& atomCoordinates, vector<RealVec>& atomCoordinates,
RealOpenMM* parameters, RealOpenMM* parameters,
vector<RealVec>& forces, vector<RealVec>& forces,
RealOpenMM* totalEnergy) const { RealOpenMM* totalEnergy, double* energyParamDerivs) {
static const std::string methodName = "\nReferenceHarmonicBondIxn::calculateBondIxn"; static const std::string methodName = "\nReferenceHarmonicBondIxn::calculateBondIxn";
......
/* Portions copyright (c) 2006 Stanford University and Simbios. /* Portions copyright (c) 2006-2016 Stanford University and Simbios.
* Contributors: Pande Group * Contributors: Pande Group
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
...@@ -81,7 +81,7 @@ ReferenceLJCoulomb14::~ReferenceLJCoulomb14() { ...@@ -81,7 +81,7 @@ ReferenceLJCoulomb14::~ReferenceLJCoulomb14() {
void ReferenceLJCoulomb14::calculateBondIxn(int* atomIndices, vector<RealVec>& atomCoordinates, void ReferenceLJCoulomb14::calculateBondIxn(int* atomIndices, vector<RealVec>& atomCoordinates,
RealOpenMM* parameters, vector<RealVec>& forces, RealOpenMM* parameters, vector<RealVec>& forces,
RealOpenMM* totalEnergy) const { RealOpenMM* totalEnergy, double* energyParamDerivs) {
static const std::string methodName = "\nReferenceLJCoulomb14::calculateBondIxn"; static const std::string methodName = "\nReferenceLJCoulomb14::calculateBondIxn";
......
...@@ -75,7 +75,7 @@ void ReferenceProperDihedralBond::calculateBondIxn(int* atomIndices, ...@@ -75,7 +75,7 @@ void ReferenceProperDihedralBond::calculateBondIxn(int* atomIndices,
vector<RealVec>& atomCoordinates, vector<RealVec>& atomCoordinates,
RealOpenMM* parameters, RealOpenMM* parameters,
vector<RealVec>& forces, vector<RealVec>& forces,
RealOpenMM* totalEnergy) const { RealOpenMM* totalEnergy, double* energyParamDerivs) {
static const std::string methodName = "\nReferenceProperDihedralBond::calculateBondIxn"; static const std::string methodName = "\nReferenceProperDihedralBond::calculateBondIxn";
......
...@@ -73,7 +73,7 @@ void ReferenceRbDihedralBond::calculateBondIxn(int* atomIndices, ...@@ -73,7 +73,7 @@ void ReferenceRbDihedralBond::calculateBondIxn(int* atomIndices,
vector<RealVec>& atomCoordinates, vector<RealVec>& atomCoordinates,
RealOpenMM* parameters, RealOpenMM* parameters,
vector<RealVec>& forces, vector<RealVec>& forces,
RealOpenMM* totalEnergy) const { RealOpenMM* totalEnergy, double* energyParamDerivs) {
static const std::string methodName = "\nReferenceRbDihedralBond::calculateBondIxn"; static const std::string methodName = "\nReferenceRbDihedralBond::calculateBondIxn";
......
...@@ -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];
......
...@@ -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 @@ CustomNonbondedForceProxy::CustomNonbondedForceProxy() : SerializationProxy("Cus ...@@ -42,7 +42,7 @@ CustomNonbondedForceProxy::CustomNonbondedForceProxy() : SerializationProxy("Cus
} }
void CustomNonbondedForceProxy::serialize(const void* object, SerializationNode& node) const { void CustomNonbondedForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1); node.setIntProperty("version", 2);
const CustomNonbondedForce& force = *reinterpret_cast<const CustomNonbondedForce*>(object); const CustomNonbondedForce& force = *reinterpret_cast<const CustomNonbondedForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setStringProperty("energy", force.getEnergyFunction()); node.setStringProperty("energy", force.getEnergyFunction());
...@@ -59,6 +59,10 @@ void CustomNonbondedForceProxy::serialize(const void* object, SerializationNode& ...@@ -59,6 +59,10 @@ void CustomNonbondedForceProxy::serialize(const void* object, SerializationNode&
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& particles = node.createChildNode("Particles"); SerializationNode& particles = node.createChildNode("Particles");
for (int i = 0; i < force.getNumParticles(); i++) { for (int i = 0; i < force.getNumParticles(); i++) {
vector<double> params; vector<double> params;
...@@ -97,7 +101,8 @@ void CustomNonbondedForceProxy::serialize(const void* object, SerializationNode& ...@@ -97,7 +101,8 @@ void CustomNonbondedForceProxy::serialize(const void* object, SerializationNode&
} }
void* CustomNonbondedForceProxy::deserialize(const SerializationNode& node) const { void* CustomNonbondedForceProxy::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");
CustomNonbondedForce* force = NULL; CustomNonbondedForce* force = NULL;
try { try {
...@@ -118,6 +123,13 @@ void* CustomNonbondedForceProxy::deserialize(const SerializationNode& node) cons ...@@ -118,6 +123,13 @@ void* CustomNonbondedForceProxy::deserialize(const SerializationNode& node) cons
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& particles = node.getChildNode("Particles"); const SerializationNode& particles = node.getChildNode("Particles");
vector<double> params(force->getNumPerParticleParameters()); vector<double> params(force->getNumPerParticleParameters());
for (int i = 0; i < (int) particles.getChildren().size(); i++) { for (int i = 0; i < (int) particles.getChildren().size(); 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;
......
...@@ -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: *
* * * *
...@@ -51,6 +51,7 @@ void testSerialization() { ...@@ -51,6 +51,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");
vector<double> params(1); vector<double> params(1);
params[0] = 1.0; params[0] = 1.0;
force.addParticle(params); force.addParticle(params);
...@@ -94,6 +95,9 @@ void testSerialization() { ...@@ -94,6 +95,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.getNumParticles(), force2.getNumParticles()); ASSERT_EQUAL(force.getNumParticles(), force2.getNumParticles());
for (int i = 0; i < force.getNumParticles(); i++) { for (int i = 0; i < force.getNumParticles(); i++) {
vector<double> params1, params2; vector<double> params1, params2;
......
...@@ -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