"...src/ssh:/git@developer.sourcefind.cn:2222/tsoc/openmm.git" did not exist on "7d7490ea425a3fdd44ccee77aa228056a5b63aa6"
Commit a6882a28 authored by Yutong Zhao's avatar Yutong Zhao
Browse files

Completed support for serialization of all integrator types. Modified...

Completed support for serialization of all integrator types. Modified Assertion utilities to allow ASSERT_EQUAL to work on strings. Updated unit tests for testSerializeIntegrators. 
parent 0ea02ab9
...@@ -47,6 +47,12 @@ void OPENMM_EXPORT throwException(const char* file, int line, const std::string& ...@@ -47,6 +47,12 @@ void OPENMM_EXPORT throwException(const char* file, int line, const std::string&
} // namespace OpenMM } // namespace OpenMM
static inline bool operator==(const std::string& lhs, const std::string &rhs) {
if(lhs.compare(rhs) == 0)
return true;
return false;
}
#define ASSERT(cond) {if (!(cond)) throwException(__FILE__, __LINE__, "");}; #define ASSERT(cond) {if (!(cond)) throwException(__FILE__, __LINE__, "");};
#define ASSERT_EQUAL(expected, found) {if (!((expected) == (found))) {std::stringstream details; details << "Expected "<<(expected)<<", found "<<(found); throwException(__FILE__, __LINE__, details.str());}}; #define ASSERT_EQUAL(expected, found) {if (!((expected) == (found))) {std::stringstream details; details << "Expected "<<(expected)<<", found "<<(found); throwException(__FILE__, __LINE__, details.str());}};
......
...@@ -154,7 +154,7 @@ void CustomIntegrator::getPerDofVariable(int index, vector<Vec3>& values) const ...@@ -154,7 +154,7 @@ void CustomIntegrator::getPerDofVariable(int index, vector<Vec3>& values) const
void CustomIntegrator::setPerDofVariable(int index, const vector<Vec3>& values) { void CustomIntegrator::setPerDofVariable(int index, const vector<Vec3>& values) {
ASSERT_VALID_INDEX(index, perDofValues); ASSERT_VALID_INDEX(index, perDofValues);
if (values.size() != context->getSystem().getNumParticles()) if (owner != NULL && values.size() != context->getSystem().getNumParticles())
throw OpenMMException("setPerDofVariable() called with wrong number of values"); throw OpenMMException("setPerDofVariable() called with wrong number of values");
if (owner == NULL) if (owner == NULL)
perDofValues[index] = values; perDofValues[index] = values;
......
#ifndef OPENMM_BROWNIAN_INTEGRATOR_PROXY_H_
#define OPENMM_BROWNIAN_INTEGRATOR_PROXY_H_
#include "openmm/serialization/XmlSerializer.h"
namespace OpenMM {
class BrownianIntegratorProxy : public SerializationProxy {
public:
BrownianIntegratorProxy();
void serialize(const void* object, SerializationNode& node) const;
void* deserialize(const SerializationNode& node) const;
};
}
#endif /*OPENMM_BROWNIAN_INTEGRATOR_PROXY_H_*/
\ No newline at end of file
#ifndef OPENMM_CUSTOM_INTEGRATOR_PROXY_H_
#define OPENMM_CUSTOM_INTEGRATOR_PROXY_H_
#include "openmm/serialization/XmlSerializer.h"
namespace OpenMM {
class CustomIntegratorProxy : public SerializationProxy {
public:
CustomIntegratorProxy();
void serialize(const void* object, SerializationNode& node) const;
void* deserialize(const SerializationNode& node) const;
};
}
#endif /*OPENMM_CUSTOM_INTEGRATOR_PROXY_H_*/
\ No newline at end of file
#ifndef OPENMM_VARIABLE_LANGEVIN_INTEGRATOR_PROXY_H_
#define OPENMM_VARIABLE_LANGEVIN_INTEGRATOR_PROXY_H_
#include "openmm/serialization/XmlSerializer.h"
namespace OpenMM {
class VariableLangevinIntegratorProxy : public SerializationProxy {
public:
VariableLangevinIntegratorProxy();
void serialize(const void* object, SerializationNode& node) const;
void* deserialize(const SerializationNode& node) const;
};
}
#endif /*OPENMM_VARIABLE_LANGEVIN_INTEGRATOR_PROXY_H_*/
\ No newline at end of file
#ifndef OPENMM_VARIABLE_VERLET_INTEGRATOR_PROXY_H_
#define OPENMM_VARIABLE_VERLET_INTEGRATOR_PROXY_H_
#include "openmm/serialization/XmlSerializer.h"
namespace OpenMM {
class VariableVerletIntegratorProxy : public SerializationProxy {
public:
VariableVerletIntegratorProxy();
void serialize(const void* object, SerializationNode& node) const;
void* deserialize(const SerializationNode& node) const;
};
}
#endif /*OPENMM_VARIABLE_VERLET_INTEGRATOR_PROXY_H_*/
\ No newline at end of file
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman, Yutong Zhao *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/serialization/BrownianIntegratorProxy.h"
#include <OpenMM.h>
using namespace std;
using namespace OpenMM;
BrownianIntegratorProxy::BrownianIntegratorProxy() : SerializationProxy("BrownianIntegrator") {
}
void BrownianIntegratorProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1);
const BrownianIntegrator& integrator = *reinterpret_cast<const BrownianIntegrator*>(object);
node.setDoubleProperty("stepSizeInPs", integrator.getStepSize());
node.setDoubleProperty("constraintTolerance", integrator.getConstraintTolerance());
node.setDoubleProperty("temperature", integrator.getTemperature());
node.setDoubleProperty("friction", integrator.getFriction());
node.setIntProperty("randomSeed", integrator.getRandomNumberSeed());
}
void* BrownianIntegratorProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2)
throw OpenMMException("Unsupported version number");
BrownianIntegrator *integrator = new BrownianIntegrator(node.getDoubleProperty("temperature"),
node.getDoubleProperty("friction"),
node.getDoubleProperty("stepSizeInPs"));
integrator->setConstraintTolerance(node.getDoubleProperty("constraintTolerance"));
integrator->setRandomNumberSeed(node.getIntProperty("randomSeed"));
return integrator;
}
\ No newline at end of file
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman, Yutong Zhao *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/serialization/CustomIntegratorProxy.h"
#include <OpenMM.h>
using namespace std;
using namespace OpenMM;
CustomIntegratorProxy::CustomIntegratorProxy() : SerializationProxy("CustomIntegrator") {
}
void CustomIntegratorProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1);
const CustomIntegrator& integrator = *reinterpret_cast<const CustomIntegrator*>(object);
SerializationNode& globalVariablesNode = node.createChildNode("GlobalVariables");
for(int i=0; i<integrator.getNumGlobalVariables(); i++) {
globalVariablesNode.setDoubleProperty(integrator.getGlobalVariableName(i), integrator.getGlobalVariable(i));
}
SerializationNode& perDofVariablesNode = node.createChildNode("PerDofVariables");
for(int i=0; i<integrator.getNumPerDofVariables(); i++) {
SerializationNode& perDofValuesNode = perDofVariablesNode.createChildNode(integrator.getPerDofVariableName(i));
vector<Vec3> perDofValues; integrator.getPerDofVariable(i, perDofValues);
for(int j=0; j<perDofValues.size(); j++) {
perDofValuesNode.createChildNode("Value").setDoubleProperty("x",perDofValues[j][0]).setDoubleProperty("y",perDofValues[j][1]).setDoubleProperty("z",perDofValues[j][2]);
}
}
SerializationNode& computationsNode = node.createChildNode("Computations");
for(int i=0; i<integrator.getNumComputations(); i++) {
CustomIntegrator::ComputationType computationType;
string computationVariable;
string computationExpression;
integrator.getComputationStep(i, computationType, computationVariable, computationExpression);
computationsNode.createChildNode("Computation").setIntProperty("computationType",static_cast<int>(computationType))
.setStringProperty("computationVariable",computationVariable).setStringProperty("computationExpression",computationExpression);
}
node.setStringProperty("kineticEnergyExpression",integrator.getKineticEnergyExpression());
node.setIntProperty("randomSeed",integrator.getRandomNumberSeed());
node.setDoubleProperty("stepSizeInPs",integrator.getStepSize());
node.setDoubleProperty("constraintTolerance",integrator.getConstraintTolerance());
}
void* CustomIntegratorProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2)
throw OpenMMException("Unsupported version number");
CustomIntegrator* integrator = new CustomIntegrator(node.getDoubleProperty("stepSizeInPs"));
const SerializationNode& globalVariablesNode = node.getChildNode("GlobalVariables");
const map<string, string> &globalVariableProp = globalVariablesNode.getProperties();
for(map<string, string>::const_iterator cit = globalVariableProp.begin(); cit != globalVariableProp.end(); cit++) {
integrator->addGlobalVariable(cit->first, globalVariablesNode.getDoubleProperty(cit->first));
}
const SerializationNode& perDofVariablesNode = node.getChildNode("PerDofVariables");
const vector<SerializationNode>& perDofVariableList = perDofVariablesNode.getChildren();
int count = 0;
for(vector<SerializationNode>::const_iterator cit=perDofVariableList.begin(); cit != perDofVariableList.end(); cit++, count++) {
const vector<SerializationNode>& perDofVariableVector = cit->getChildren();
integrator->addPerDofVariable(cit->getName(),0);
vector<Vec3> perDofValues;
for(vector<SerializationNode>::const_iterator dit=perDofVariableVector.begin(); dit!=perDofVariableVector.end(); dit++) {
perDofValues.push_back(Vec3(dit->getDoubleProperty("x"),dit->getDoubleProperty("y"),dit->getDoubleProperty("z")));
}
integrator->setPerDofVariable(count, perDofValues);
}
const SerializationNode& computationsNode = node.getChildNode("Computations");
const vector<SerializationNode>& computationsList = computationsNode.getChildren();
for(vector<SerializationNode>::const_iterator cit = computationsList.begin(); cit != computationsList.end(); cit++) {
CustomIntegrator::ComputationType computationType = static_cast<CustomIntegrator::ComputationType>(cit->getIntProperty("computationType"));
// make sure that the int casts to a valid enum
if(computationType == CustomIntegrator::ComputationType::ComputeGlobal) {
integrator->addComputeGlobal(cit->getStringProperty("computationVariable"), cit->getStringProperty("computationExpression"));
} else if(computationType == CustomIntegrator::ComputationType::ComputePerDof) {
integrator->addComputePerDof(cit->getStringProperty("computationVariable"), cit->getStringProperty("computationExpression"));
} else if(computationType == CustomIntegrator::ComputationType::ComputeSum) {
integrator->addComputeSum(cit->getStringProperty("computationVariable"), cit->getStringProperty("computationExpression"));
} else if(computationType == CustomIntegrator::ComputationType::ConstrainPositions) {
integrator->addConstrainPositions();
} else if(computationType == CustomIntegrator::ComputationType::ConstrainVelocities) {
integrator->addConstrainVelocities();
} else if(computationType == CustomIntegrator::ComputationType::UpdateContextState) {
integrator->addConstrainVelocities();
} else {
throw(OpenMMException("Custom Integrator Deserialization: Unknown computation type"));
}
}
integrator->setKineticEnergyExpression(node.getStringProperty("kineticEnergyExpression"));
integrator->setRandomNumberSeed(node.getIntProperty("randomSeed"));
integrator->setStepSize(node.getDoubleProperty("stepSizeInPs"));
integrator->setConstraintTolerance(node.getDoubleProperty("constraintTolerance"));
return integrator;
}
\ No newline at end of file
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2010 Stanford University and the Authors. * * Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman, Yutong Zhao *
* Contributors: * * Contributors: *
* * * *
* Permission is hereby granted, free of charge, to any person obtaining a * * Permission is hereby granted, free of charge, to any person obtaining a *
......
...@@ -49,8 +49,14 @@ ...@@ -49,8 +49,14 @@
#include "openmm/PeriodicTorsionForce.h" #include "openmm/PeriodicTorsionForce.h"
#include "openmm/RBTorsionForce.h" #include "openmm/RBTorsionForce.h"
#include "openmm/System.h" #include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "openmm/BrownianIntegrator.h"
#include "openmm/CustomIntegrator.h"
#include "openmm/LangevinIntegrator.h" #include "openmm/LangevinIntegrator.h"
#include "openmm/VariableLangevinIntegrator.h"
#include "openmm/VariableVerletIntegrator.h"
#include "openmm/VerletIntegrator.h"
#include "openmm/serialization/SerializationProxy.h" #include "openmm/serialization/SerializationProxy.h"
#include "openmm/serialization/AndersenThermostatProxy.h" #include "openmm/serialization/AndersenThermostatProxy.h"
#include "openmm/serialization/CMAPTorsionForceProxy.h" #include "openmm/serialization/CMAPTorsionForceProxy.h"
...@@ -72,9 +78,15 @@ ...@@ -72,9 +78,15 @@
#include "openmm/serialization/PeriodicTorsionForceProxy.h" #include "openmm/serialization/PeriodicTorsionForceProxy.h"
#include "openmm/serialization/RBTorsionForceProxy.h" #include "openmm/serialization/RBTorsionForceProxy.h"
#include "openmm/serialization/SystemProxy.h" #include "openmm/serialization/SystemProxy.h"
#include "openmm/serialization/StateProxy.h" #include "openmm/serialization/StateProxy.h"
#include "openmm/serialization/VerletIntegratorProxy.h"
#include "openmm/serialization/BrownianIntegratorProxy.h"
#include "openmm/serialization/CustomIntegratorProxy.h"
#include "openmm/serialization/LangevinIntegratorProxy.h" #include "openmm/serialization/LangevinIntegratorProxy.h"
#include "openmm/serialization/VariableLangevinIntegratorProxy.h"
#include "openmm/serialization/VariableVerletIntegratorProxy.h"
#include "openmm/serialization/VerletIntegratorProxy.h"
#if defined(WIN32) #if defined(WIN32)
#include <windows.h> #include <windows.h>
...@@ -112,6 +124,10 @@ extern "C" void registerSerializationProxies() { ...@@ -112,6 +124,10 @@ extern "C" void registerSerializationProxies() {
SerializationProxy::registerProxy(typeid(RBTorsionForce), new RBTorsionForceProxy()); SerializationProxy::registerProxy(typeid(RBTorsionForce), new RBTorsionForceProxy());
SerializationProxy::registerProxy(typeid(System), new SystemProxy()); SerializationProxy::registerProxy(typeid(System), new SystemProxy());
SerializationProxy::registerProxy(typeid(State), new StateProxy()); SerializationProxy::registerProxy(typeid(State), new StateProxy());
SerializationProxy::registerProxy(typeid(VerletIntegrator), new VerletIntegratorProxy()); SerializationProxy::registerProxy(typeid(BrownianIntegrator), new BrownianIntegratorProxy());
SerializationProxy::registerProxy(typeid(CustomIntegrator), new CustomIntegratorProxy());
SerializationProxy::registerProxy(typeid(LangevinIntegrator), new LangevinIntegratorProxy()); SerializationProxy::registerProxy(typeid(LangevinIntegrator), new LangevinIntegratorProxy());
SerializationProxy::registerProxy(typeid(VariableLangevinIntegrator), new VariableLangevinIntegratorProxy());
SerializationProxy::registerProxy(typeid(VariableVerletIntegrator), new VariableVerletIntegratorProxy());
SerializationProxy::registerProxy(typeid(VerletIntegrator), new VerletIntegratorProxy());
} }
\ No newline at end of file
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman, Yutong Zhao *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/serialization/VariableLangevinIntegratorProxy.h"
#include <OpenMM.h>
using namespace std;
using namespace OpenMM;
VariableLangevinIntegratorProxy::VariableLangevinIntegratorProxy() : SerializationProxy("VariableLangevinIntegrator") {
}
void VariableLangevinIntegratorProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1);
const VariableLangevinIntegrator& integrator = *reinterpret_cast<const VariableLangevinIntegrator*>(object);
node.setDoubleProperty("stepSizeInPs", integrator.getStepSize());
node.setDoubleProperty("constraintTolerance", integrator.getConstraintTolerance());
node.setDoubleProperty("temperature", integrator.getTemperature());
node.setDoubleProperty("friction", integrator.getFriction());
node.setDoubleProperty("errorTol", integrator.getErrorTolerance());
node.setIntProperty("randomSeed", integrator.getRandomNumberSeed());
}
void* VariableLangevinIntegratorProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2)
throw OpenMMException("Unsupported version number");
VariableLangevinIntegrator *integrator = new VariableLangevinIntegrator(node.getDoubleProperty("temperature"),
node.getDoubleProperty("friction"),
node.getDoubleProperty("errorTol"));
integrator->setStepSize(node.getDoubleProperty("stepSizeInPs"));
integrator->setConstraintTolerance(node.getDoubleProperty("constraintTolerance"));
integrator->setRandomNumberSeed(node.getIntProperty("randomSeed"));
return integrator;
}
\ No newline at end of file
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman, Yutong Zhao *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/serialization/VariableVerletIntegratorProxy.h"
#include <OpenMM.h>
using namespace std;
using namespace OpenMM;
VariableVerletIntegratorProxy::VariableVerletIntegratorProxy() : SerializationProxy("VariableVerletIntegrator") {
}
void VariableVerletIntegratorProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1);
const VariableVerletIntegrator& integrator = *reinterpret_cast<const VariableVerletIntegrator*>(object);
node.setDoubleProperty("errorTol", integrator.getErrorTolerance());
node.setDoubleProperty("stepSizeInPs", integrator.getStepSize());
node.setDoubleProperty("constraintTolerance", integrator.getConstraintTolerance());
}
void* VariableVerletIntegratorProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2)
throw OpenMMException("Unsupported version number");
VariableVerletIntegrator *integrator = new VariableVerletIntegrator(node.getDoubleProperty("errorTol"));
integrator->setStepSize(node.getDoubleProperty("stepSizeInPs"));
integrator->setConstraintTolerance(node.getDoubleProperty("constraintTolerance"));
return integrator;
}
\ No newline at end of file
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2010 Stanford University and the Authors. * * Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman, * * Authors: Peter Eastman, Yutong Zhao *
* Contributors: * * Contributors: *
* * * *
* Permission is hereby granted, free of charge, to any person obtaining a * * Permission is hereby granted, free of charge, to any person obtaining a *
...@@ -49,9 +49,7 @@ void VerletIntegratorProxy::serialize(const void* object, SerializationNode& nod ...@@ -49,9 +49,7 @@ void VerletIntegratorProxy::serialize(const void* object, SerializationNode& nod
void* VerletIntegratorProxy::deserialize(const SerializationNode& node) const { void* VerletIntegratorProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2) if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2)
throw OpenMMException("Unsupported version number"); throw OpenMMException("Unsupported version number");
double stepSize = node.getDoubleProperty("stepSizeInPs"); VerletIntegrator *integrator = new VerletIntegrator(node.getDoubleProperty("stepSizeInPs"));
double constraintTol = node.getDoubleProperty("constraintTolerance"); integrator->setConstraintTolerance(node.getDoubleProperty("constraintTolerance"));
VerletIntegrator *integrator = new VerletIntegrator(stepSize);
integrator->setConstraintTolerance(constraintTol);
return integrator; return integrator;
} }
\ No newline at end of file
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2010 Stanford University and the Authors. * * Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman, Yutong Zhao *
* Contributors: * * Contributors: *
* * * *
* Permission is hereby granted, free of charge, to any person obtaining a * * Permission is hereby granted, free of charge, to any person obtaining a *
...@@ -30,8 +30,14 @@ ...@@ -30,8 +30,14 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h" #include "openmm/internal/AssertionUtilities.h"
#include "openmm/BrownianIntegrator.h"
#include "openmm/CustomIntegrator.h"
#include "openmm/LangevinIntegrator.h" #include "openmm/LangevinIntegrator.h"
#include "openmm/VariableLangevinIntegrator.h"
#include "openmm/VariableVerletIntegrator.h"
#include "openmm/VerletIntegrator.h" #include "openmm/VerletIntegrator.h"
#include "openmm/serialization/XmlSerializer.h" #include "openmm/serialization/XmlSerializer.h"
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
...@@ -42,41 +48,149 @@ ...@@ -42,41 +48,149 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
void testSerialization() { void testSerializeVerletIntegrator() {
VerletIntegrator *intg = new VerletIntegrator(0.00342);
stringstream ss;
XmlSerializer::serialize<Integrator>(intg, "VerletIntegrator", ss);
VerletIntegrator *intg2 = dynamic_cast<VerletIntegrator*>(XmlSerializer::deserialize<Integrator>(ss));
ASSERT_EQUAL(intg->getConstraintTolerance(), intg2->getConstraintTolerance());
ASSERT_EQUAL(intg->getStepSize(), intg2->getStepSize());
delete intg;
delete intg2;
}
void testSerializeLangevinIntegrator() {
LangevinIntegrator *intg = new LangevinIntegrator(372.4, 1.234, 0.0018);
stringstream ss;
XmlSerializer::serialize<Integrator>(intg, "LangevinIntegrator", ss);
LangevinIntegrator *intg2 = dynamic_cast<LangevinIntegrator*>(XmlSerializer::deserialize<Integrator>(ss));
ASSERT_EQUAL(intg->getConstraintTolerance(), intg2->getConstraintTolerance());
ASSERT_EQUAL(intg->getStepSize(), intg2->getStepSize());
ASSERT_EQUAL(intg->getTemperature(), intg2->getTemperature());
ASSERT_EQUAL(intg->getFriction(), intg2->getFriction());
ASSERT_EQUAL(intg->getRandomNumberSeed(), intg2->getRandomNumberSeed());
delete intg;
delete intg2;
}
void testSerializeBrownianIntegrator() {
BrownianIntegrator *intg = new BrownianIntegrator(243.1, 3.234, 0.0021);
stringstream ss;
XmlSerializer::serialize<Integrator>(intg, "BrownianIntegrator", ss);
BrownianIntegrator *intg2 = dynamic_cast<BrownianIntegrator*>(XmlSerializer::deserialize<Integrator>(ss));
ASSERT_EQUAL(intg->getConstraintTolerance(), intg2->getConstraintTolerance());
ASSERT_EQUAL(intg->getStepSize(), intg2->getStepSize());
ASSERT_EQUAL(intg->getTemperature(), intg2->getTemperature());
ASSERT_EQUAL(intg->getFriction(), intg2->getFriction());
ASSERT_EQUAL(intg->getRandomNumberSeed(), intg2->getRandomNumberSeed());
delete intg;
delete intg2;
}
void testSerializeVariableVerletIntegrator() {
VariableVerletIntegrator *intg = new VariableVerletIntegrator(0.04234);
stringstream ss;
XmlSerializer::serialize<Integrator>(intg, "VariableVerletIntegrator", ss);
VariableVerletIntegrator *intg2 = dynamic_cast<VariableVerletIntegrator*>(XmlSerializer::deserialize<Integrator>(ss));
ASSERT_EQUAL(intg->getConstraintTolerance(), intg2->getConstraintTolerance());
ASSERT_EQUAL(intg->getStepSize(), intg2->getStepSize());
ASSERT_EQUAL(intg->getErrorTolerance(), intg2->getErrorTolerance());
delete intg;
delete intg2;
}
void testSerializeVariableLangevinIntegrator() {
VariableLangevinIntegrator *intg = new VariableLangevinIntegrator(243.1, 3.234, 0.0021);
stringstream ss;
XmlSerializer::serialize<Integrator>(intg, "VariableLangevinIntegrator", ss);
VariableLangevinIntegrator *intg2 = dynamic_cast<VariableLangevinIntegrator*>(XmlSerializer::deserialize<Integrator>(ss));
ASSERT_EQUAL(intg->getConstraintTolerance(), intg2->getConstraintTolerance());
ASSERT_EQUAL(intg->getStepSize(), intg2->getStepSize());
ASSERT_EQUAL(intg->getErrorTolerance(), intg2->getErrorTolerance());
ASSERT_EQUAL(intg->getFriction(), intg2->getFriction());
ASSERT_EQUAL(intg->getTemperature(), intg2->getTemperature());
ASSERT_EQUAL(intg->getRandomNumberSeed(), intg2->getRandomNumberSeed());
delete intg;
delete intg2;
}
{ void testSerializeCustomIntegrator() {
VerletIntegrator *vInt = new VerletIntegrator(0.00342); CustomIntegrator *intg = new CustomIntegrator(0.002234);
stringstream ss; intg->addPerDofVariable("temp",0);
XmlSerializer::serialize<Integrator>(vInt, "VerletIntegrator", ss); vector<Vec3> initialValues(123);
VerletIntegrator *vInt2 = dynamic_cast<VerletIntegrator*>(XmlSerializer::deserialize<Integrator>(ss)); for(int i = 0; i < 123; i++)
ASSERT_EQUAL(vInt->getConstraintTolerance(), vInt2->getConstraintTolerance()); initialValues[i] = Vec3(i+0.1, i+0.2, i+0.3);
ASSERT_EQUAL(vInt->getStepSize(), vInt2->getStepSize()); intg->setPerDofVariable(0, initialValues);
delete vInt; intg->addPerDofVariable("oldx", 0);
delete vInt2; intg->addComputePerDof("v", "v+dt*f/m");
} intg->addComputePerDof("oldx", "x");
{ intg->addComputePerDof("x", "x+dt*v");
LangevinIntegrator *lInt = new LangevinIntegrator(372.4, 1.234, 0.0018); intg->addConstrainPositions();
stringstream ss; intg->addComputePerDof("v", "(x-oldx)/dt");
XmlSerializer::serialize<Integrator>(lInt, "LangevinIntegrator", ss); intg->addPerDofVariable("outf", 0);
LangevinIntegrator *lInt2 = dynamic_cast<LangevinIntegrator*>(XmlSerializer::deserialize<Integrator>(ss)); intg->addPerDofVariable("outf1", 0);
ASSERT_EQUAL(lInt->getConstraintTolerance(), lInt2->getConstraintTolerance()); intg->addPerDofVariable("outf2", 0);
ASSERT_EQUAL(lInt->getStepSize(), lInt2->getStepSize()); intg->addGlobalVariable("oute", 0);
ASSERT_EQUAL(lInt->getTemperature(), lInt2->getTemperature()); intg->addGlobalVariable("oute1", 0);
ASSERT_EQUAL(lInt->getFriction(), lInt2->getFriction()); intg->addGlobalVariable("oute2", 0);
delete lInt; intg->addComputePerDof("outf", "f");
delete lInt2; intg->addComputePerDof("outf1", "f1");
} intg->addComputePerDof("outf2", "f2");
intg->addComputeGlobal("oute", "energy");
intg->addComputeGlobal("oute1", "energy1");
intg->addComputeGlobal("oute2", "energy2");
intg->setConstraintTolerance(1e-5);
intg->setKineticEnergyExpression("m*v1*v1/2; v1=v+0.5*dt*f/m");
stringstream ss;
XmlSerializer::serialize<Integrator>(intg, "CustomIntegrator", ss);
CustomIntegrator *intg2 = dynamic_cast<CustomIntegrator*>(XmlSerializer::deserialize<Integrator>(ss));
ASSERT_EQUAL(intg->getNumGlobalVariables(), intg->getNumGlobalVariables());
for(int i=0; i < intg->getNumGlobalVariables(); i++) {
ASSERT_EQUAL(intg->getGlobalVariable(i), intg2->getGlobalVariable(i));
ASSERT_EQUAL(intg->getGlobalVariableName(i), intg2->getGlobalVariableName(i));
}
ASSERT_EQUAL(intg->getNumPerDofVariables(), intg2->getNumPerDofVariables());
for(int i=0; i<intg->getNumPerDofVariables(); i++) {
vector<Vec3> vars1; intg->getPerDofVariable(i, vars1);
vector<Vec3> vars2; intg2->getPerDofVariable(i, vars2);
ASSERT_EQUAL(vars1.size(),vars2.size());
for(int j=0; j<vars1.size(); j++) {
ASSERT_EQUAL(vars1[j][0], vars2[j][0]);
ASSERT_EQUAL(vars1[j][1], vars2[j][1]);
ASSERT_EQUAL(vars1[j][2], vars2[j][2]);
}
}
ASSERT_EQUAL(intg->getNumComputations(), intg2->getNumComputations());
for(int i=0; i<intg->getNumComputations(); i++) {
CustomIntegrator::ComputationType type1, type2;
string variable1, variable2;
string expression1, expression2;
intg->getComputationStep(i, type1, variable1, expression1);
intg2->getComputationStep(i, type2, variable2, expression2);
ASSERT_EQUAL(type1, type2);
ASSERT_EQUAL(variable1, variable2);
ASSERT_EQUAL(expression1, expression2);
}
ASSERT_EQUAL(intg->getKineticEnergyExpression(), intg2->getKineticEnergyExpression());
ASSERT_EQUAL(intg->getRandomNumberSeed(), intg2->getRandomNumberSeed());
ASSERT_EQUAL(intg->getStepSize(), intg2->getStepSize());
ASSERT_EQUAL(intg->getConstraintTolerance(), intg2->getConstraintTolerance());
delete intg;
delete intg2;
} }
int main() { int main() {
try { try {
testSerialization(); testSerializeBrownianIntegrator();
testSerializeCustomIntegrator();
testSerializeVerletIntegrator();
testSerializeVariableLangevinIntegrator();
testSerializeVariableVerletIntegrator();
testSerializeLangevinIntegrator();
} }
catch(const exception& e) { catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1; return 1;
} }
cout << "Done" << endl;
return 0; return 0;
} }
......
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