Commit c0687411 authored by Yutong Zhao's avatar Yutong Zhao
Browse files

Support for serialization of Integrator base class, and two derived classes:...

Support for serialization of Integrator base class, and two derived classes: LangevinIntegrator and VerletIntegrator. Also added support for python serialization via a single deserializeIntegrator()
parent 9bf57c0b
/* -------------------------------------------------------------------------- *
* 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, *
* 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/IntegratorProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include <OpenMM.h>
using namespace std;
using namespace OpenMM;
IntegratorProxy::IntegratorProxy() : SerializationProxy("Integrator") {
}
void IntegratorProxy::serialize(const void* object, SerializationNode& node) const {
node.createChildNode("Integrator", reinterpret_cast<const Integrator *>(object));
}
void* IntegratorProxy::deserialize(const SerializationNode& node) const {
return node.decodeObject<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 *
* 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/LangevinIntegratorProxy.h"
#include <OpenMM.h>
using namespace std;
using namespace OpenMM;
LangevinIntegratorProxy::LangevinIntegratorProxy() : SerializationProxy("LangevinIntegrator") {
}
void LangevinIntegratorProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1);
const LangevinIntegrator& integrator = *reinterpret_cast<const LangevinIntegrator*>(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* LangevinIntegratorProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2)
throw OpenMMException("Unsupported version number");
LangevinIntegrator *integrator = new LangevinIntegrator(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
......@@ -49,6 +49,8 @@
#include "openmm/PeriodicTorsionForce.h"
#include "openmm/RBTorsionForce.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "openmm/LangevinIntegrator.h"
#include "openmm/serialization/SerializationProxy.h"
#include "openmm/serialization/AndersenThermostatProxy.h"
#include "openmm/serialization/CMAPTorsionForceProxy.h"
......@@ -71,6 +73,9 @@
#include "openmm/serialization/RBTorsionForceProxy.h"
#include "openmm/serialization/SystemProxy.h"
#include "openmm/serialization/StateProxy.h"
#include "openmm/serialization/VerletIntegratorProxy.h"
#include "openmm/serialization/LangevinIntegratorProxy.h"
#include "openmm/serialization/IntegratorProxy.h"
#if defined(WIN32)
#include <windows.h>
......@@ -108,4 +113,7 @@ extern "C" void registerSerializationProxies() {
SerializationProxy::registerProxy(typeid(RBTorsionForce), new RBTorsionForceProxy());
SerializationProxy::registerProxy(typeid(System), new SystemProxy());
SerializationProxy::registerProxy(typeid(State), new StateProxy());
SerializationProxy::registerProxy(typeid(VerletIntegrator), new VerletIntegratorProxy());
SerializationProxy::registerProxy(typeid(LangevinIntegrator), new LangevinIntegratorProxy());
SerializationProxy::registerProxy(typeid(Integrator), new IntegratorProxy());
}
\ 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, *
* 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/VerletIntegratorProxy.h"
#include <OpenMM.h>
using namespace std;
using namespace OpenMM;
VerletIntegratorProxy::VerletIntegratorProxy() : SerializationProxy("VerletIntegrator") {
}
void VerletIntegratorProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1);
const VerletIntegrator& integrator = *reinterpret_cast<const VerletIntegrator*>(object);
node.setDoubleProperty("stepSizeInPs", integrator.getStepSize());
node.setDoubleProperty("constraintTolerance", integrator.getConstraintTolerance());
}
void* VerletIntegratorProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2)
throw OpenMMException("Unsupported version number");
double stepSize = node.getDoubleProperty("stepSizeInPs");
double constraintTol = node.getDoubleProperty("constraintTolerance");
VerletIntegrator *integrator = new VerletIntegrator(stepSize);
integrator->setConstraintTolerance(constraintTol);
return integrator;
}
\ No newline at end of file
......@@ -401,6 +401,17 @@ class SwigInputBuilder:
extendString += " ss << inputString;\n"
extendString += " return XmlSerializer::deserialize<OpenMM::System>( ss );\n"
extendString += " }\n"
extendString += " static std::string serializeIntegrator( const OpenMM::Integrator *object ){\n"
extendString += " std::stringstream ss;\n"
extendString += " XmlSerializer::serialize<OpenMM::Integrator>( object, \"Integrator\", ss );\n"
extendString += " return ss.str();\n"
extendString += " }\n"
extendString += "\n"
extendString += " static OpenMM::Integrator* deserializeIntegrator( const char* inputString ){\n"
extendString += " std::stringstream ss;\n"
extendString += " ss << inputString;\n"
extendString += " return XmlSerializer::deserialize<OpenMM::Integrator>( ss );\n"
extendString += " }\n"
extendString += " };\n"
self.fOut.write("%s%s\n" % (INDENT, extendString))
......
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