Unverified Commit 4c6cf680 authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Added name property to Forces (#3049)

parent 7c2e5991
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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) 2008-2012 Stanford University and the Authors. * * Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "internal/windowsExport.h" #include "internal/windowsExport.h"
#include <string>
namespace OpenMM { namespace OpenMM {
...@@ -78,6 +79,16 @@ public: ...@@ -78,6 +79,16 @@ public:
* @param group the group index. Legal values are between 0 and 31 (inclusive). * @param group the group index. Legal values are between 0 and 31 (inclusive).
*/ */
void setForceGroup(int group); void setForceGroup(int group);
/**
* Get the name of this Force. This is an arbitrary, user modifiable identifier.
* By default it equals the class name, but you can change it to anything useful.
*/
const std::string& getName() const;
/**
* Set the name of this Force. This is an arbitrary, user modifiable identifier.
* By default it equals the class name, but you can change it to anything useful.
*/
void setName(const std::string& name);
/** /**
* Returns whether or not this force makes use of periodic boundary * Returns whether or not this force makes use of periodic boundary
* conditions. This method should be overridden for all Force subclasses, or * conditions. This method should be overridden for all Force subclasses, or
...@@ -108,6 +119,7 @@ protected: ...@@ -108,6 +119,7 @@ protected:
ContextImpl& getContextImpl(Context& context); ContextImpl& getContextImpl(Context& context);
private: private:
int forceGroup; int forceGroup;
std::string name;
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -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) 2012 Stanford University and the Authors. * * Portions copyright (c) 2012-2021 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h" #include "openmm/internal/ContextImpl.h"
#include "openmm/internal/ForceImpl.h" #include "openmm/internal/ForceImpl.h"
#include "openmm/serialization/SerializationProxy.h"
#include <vector> #include <vector>
using namespace OpenMM; using namespace OpenMM;
...@@ -49,6 +50,28 @@ void Force::setForceGroup(int group) { ...@@ -49,6 +50,28 @@ void Force::setForceGroup(int group) {
forceGroup = group; forceGroup = group;
} }
const string& Force::getName() const {
if (name.size() == 0) {
// The name hasn't been set yet, so initialize it to the class name. We first
// try to use a SerializationProxy to get the name. If none is registered,
// we use the mangled name generated by the compiler. (We can't do this in the
// constructor, because typeid() doesn't work properly in constructors.)
Force& thisRef = *const_cast<Force*>(this);
try {
thisRef.name = SerializationProxy::getProxy(typeid(*this)).getTypeName();
}
catch (...) {
thisRef.name = typeid(*this).name();
}
}
return name;
}
void Force::setName(const string& name) {
this->name = name;
}
bool Force::usesPeriodicBoundaryConditions() const { bool Force::usesPeriodicBoundaryConditions() const {
throw OpenMMException("usesPeriodicBoundaryConditions is not implemented"); throw OpenMMException("usesPeriodicBoundaryConditions is not implemented");
} }
......
...@@ -46,6 +46,7 @@ void AmoebaGeneralizedKirkwoodForceProxy::serialize(const void* object, Serializ ...@@ -46,6 +46,7 @@ void AmoebaGeneralizedKirkwoodForceProxy::serialize(const void* object, Serializ
const AmoebaGeneralizedKirkwoodForce& force = *reinterpret_cast<const AmoebaGeneralizedKirkwoodForce*>(object); const AmoebaGeneralizedKirkwoodForce& force = *reinterpret_cast<const AmoebaGeneralizedKirkwoodForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setStringProperty("name", force.getName());
node.setDoubleProperty("GeneralizedKirkwoodSolventDielectric", force.getSolventDielectric()); node.setDoubleProperty("GeneralizedKirkwoodSolventDielectric", force.getSolventDielectric());
node.setDoubleProperty("GeneralizedKirkwoodSoluteDielectric", force.getSoluteDielectric()); node.setDoubleProperty("GeneralizedKirkwoodSoluteDielectric", force.getSoluteDielectric());
//node.setDoubleProperty("GeneralizedKirkwoodDielectricOffset", force.getDielectricOffset()); //node.setDoubleProperty("GeneralizedKirkwoodDielectricOffset", force.getDielectricOffset());
...@@ -68,8 +69,8 @@ void* AmoebaGeneralizedKirkwoodForceProxy::deserialize(const SerializationNode& ...@@ -68,8 +69,8 @@ void* AmoebaGeneralizedKirkwoodForceProxy::deserialize(const SerializationNode&
throw OpenMMException("Unsupported version number"); throw OpenMMException("Unsupported version number");
AmoebaGeneralizedKirkwoodForce* force = new AmoebaGeneralizedKirkwoodForce(); AmoebaGeneralizedKirkwoodForce* force = new AmoebaGeneralizedKirkwoodForce();
try { try {
if (version > 1) force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setForceGroup(node.getIntProperty("forceGroup", 0)); force->setName(node.getStringProperty("name", force->getName()));
force->setSolventDielectric( node.getDoubleProperty("GeneralizedKirkwoodSolventDielectric")); force->setSolventDielectric( node.getDoubleProperty("GeneralizedKirkwoodSolventDielectric"));
force->setSoluteDielectric( node.getDoubleProperty("GeneralizedKirkwoodSoluteDielectric")); force->setSoluteDielectric( node.getDoubleProperty("GeneralizedKirkwoodSoluteDielectric"));
//force->setDielectricOffset( node.getDoubleProperty("GeneralizedKirkwoodDielectricOffset")); //force->setDielectricOffset( node.getDoubleProperty("GeneralizedKirkwoodDielectricOffset"));
......
...@@ -72,6 +72,7 @@ void AmoebaMultipoleForceProxy::serialize(const void* object, SerializationNode& ...@@ -72,6 +72,7 @@ void AmoebaMultipoleForceProxy::serialize(const void* object, SerializationNode&
const AmoebaMultipoleForce& force = *reinterpret_cast<const AmoebaMultipoleForce*>(object); const AmoebaMultipoleForce& force = *reinterpret_cast<const AmoebaMultipoleForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setStringProperty("name", force.getName());
node.setIntProperty("nonbondedMethod", force.getNonbondedMethod()); node.setIntProperty("nonbondedMethod", force.getNonbondedMethod());
node.setIntProperty("polarizationType", force.getPolarizationType()); node.setIntProperty("polarizationType", force.getPolarizationType());
node.setIntProperty("mutualInducedMaxIterations", force.getMutualInducedMaxIterations()); node.setIntProperty("mutualInducedMaxIterations", force.getMutualInducedMaxIterations());
...@@ -137,8 +138,8 @@ void* AmoebaMultipoleForceProxy::deserialize(const SerializationNode& node) cons ...@@ -137,8 +138,8 @@ void* AmoebaMultipoleForceProxy::deserialize(const SerializationNode& node) cons
AmoebaMultipoleForce* force = new AmoebaMultipoleForce(); AmoebaMultipoleForce* force = new AmoebaMultipoleForce();
try { try {
if (version > 3) force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setForceGroup(node.getIntProperty("forceGroup", 0)); force->setName(node.getStringProperty("name", force->getName()));
force->setNonbondedMethod(static_cast<AmoebaMultipoleForce::NonbondedMethod>(node.getIntProperty("nonbondedMethod"))); force->setNonbondedMethod(static_cast<AmoebaMultipoleForce::NonbondedMethod>(node.getIntProperty("nonbondedMethod")));
if (version >= 2) if (version >= 2)
force->setPolarizationType(static_cast<AmoebaMultipoleForce::PolarizationType>(node.getIntProperty("polarizationType"))); force->setPolarizationType(static_cast<AmoebaMultipoleForce::PolarizationType>(node.getIntProperty("polarizationType")));
......
...@@ -66,6 +66,7 @@ void AmoebaTorsionTorsionForceProxy::serialize(const void* object, Serialization ...@@ -66,6 +66,7 @@ void AmoebaTorsionTorsionForceProxy::serialize(const void* object, Serialization
node.setIntProperty("version", 3); node.setIntProperty("version", 3);
const AmoebaTorsionTorsionForce& force = *reinterpret_cast<const AmoebaTorsionTorsionForce*>(object); const AmoebaTorsionTorsionForce& force = *reinterpret_cast<const AmoebaTorsionTorsionForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setStringProperty("name", force.getName());
node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions()); node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
// grid[xIdx][yIdx][6 values] // grid[xIdx][yIdx][6 values]
...@@ -123,8 +124,8 @@ void* AmoebaTorsionTorsionForceProxy::deserialize(const SerializationNode& node) ...@@ -123,8 +124,8 @@ void* AmoebaTorsionTorsionForceProxy::deserialize(const SerializationNode& node)
AmoebaTorsionTorsionForce* force = new AmoebaTorsionTorsionForce(); AmoebaTorsionTorsionForce* force = new AmoebaTorsionTorsionForce();
try { try {
if (version > 1) force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setForceGroup(node.getIntProperty("forceGroup", 0)); force->setName(node.getStringProperty("name", force->getName()));
if (version > 2) if (version > 2)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic")); force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& grids = node.getChildNode("TorsionTorsionGrids"); const SerializationNode& grids = node.getChildNode("TorsionTorsionGrids");
......
...@@ -47,6 +47,7 @@ void AmoebaVdwForceProxy::serialize(const void* object, SerializationNode& node) ...@@ -47,6 +47,7 @@ void AmoebaVdwForceProxy::serialize(const void* object, SerializationNode& node)
bool useTypes = force.getUseParticleTypes(); bool useTypes = force.getUseParticleTypes();
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setStringProperty("name", force.getName());
node.setStringProperty("SigmaCombiningRule", force.getSigmaCombiningRule()); node.setStringProperty("SigmaCombiningRule", force.getSigmaCombiningRule());
node.setStringProperty("EpsilonCombiningRule", force.getEpsilonCombiningRule()); node.setStringProperty("EpsilonCombiningRule", force.getEpsilonCombiningRule());
node.setDoubleProperty("VdwCutoff", force.getCutoffDistance()); node.setDoubleProperty("VdwCutoff", force.getCutoffDistance());
...@@ -101,8 +102,8 @@ void* AmoebaVdwForceProxy::deserialize(const SerializationNode& node) const { ...@@ -101,8 +102,8 @@ void* AmoebaVdwForceProxy::deserialize(const SerializationNode& node) const {
throw OpenMMException("Unsupported version number"); throw OpenMMException("Unsupported version number");
AmoebaVdwForce* force = new AmoebaVdwForce(); AmoebaVdwForce* force = new AmoebaVdwForce();
try { try {
if (version > 1) force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setForceGroup(node.getIntProperty("forceGroup", 0)); force->setName(node.getStringProperty("name", force->getName()));
force->setSigmaCombiningRule(node.getStringProperty("SigmaCombiningRule")); force->setSigmaCombiningRule(node.getStringProperty("SigmaCombiningRule"));
force->setEpsilonCombiningRule(node.getStringProperty("EpsilonCombiningRule")); force->setEpsilonCombiningRule(node.getStringProperty("EpsilonCombiningRule"));
force->setCutoffDistance(node.getDoubleProperty("VdwCutoff")); force->setCutoffDistance(node.getDoubleProperty("VdwCutoff"));
......
...@@ -45,6 +45,7 @@ void AmoebaWcaDispersionForceProxy::serialize(const void* object, SerializationN ...@@ -45,6 +45,7 @@ void AmoebaWcaDispersionForceProxy::serialize(const void* object, SerializationN
node.setIntProperty("version", 2); node.setIntProperty("version", 2);
const AmoebaWcaDispersionForce& force = *reinterpret_cast<const AmoebaWcaDispersionForce*>(object); const AmoebaWcaDispersionForce& force = *reinterpret_cast<const AmoebaWcaDispersionForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setStringProperty("name", force.getName());
node.setDoubleProperty("Epso", force.getEpso()); node.setDoubleProperty("Epso", force.getEpso());
node.setDoubleProperty("Epsh", force.getEpsh()); node.setDoubleProperty("Epsh", force.getEpsh());
node.setDoubleProperty("Rmino", force.getRmino()); node.setDoubleProperty("Rmino", force.getRmino());
...@@ -70,8 +71,8 @@ void* AmoebaWcaDispersionForceProxy::deserialize(const SerializationNode& node) ...@@ -70,8 +71,8 @@ void* AmoebaWcaDispersionForceProxy::deserialize(const SerializationNode& node)
AmoebaWcaDispersionForce* force = new AmoebaWcaDispersionForce(); AmoebaWcaDispersionForce* force = new AmoebaWcaDispersionForce();
try { try {
if (version > 1) force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setForceGroup(node.getIntProperty("forceGroup", 0)); force->setName(node.getStringProperty("name", force->getName()));
force->setEpso( node.getDoubleProperty("Epso")); force->setEpso( node.getDoubleProperty("Epso"));
force->setEpsh( node.getDoubleProperty("Epsh")); force->setEpsh( node.getDoubleProperty("Epsh"));
force->setRmino( node.getDoubleProperty("Rmino")); force->setRmino( node.getDoubleProperty("Rmino"));
......
...@@ -46,6 +46,7 @@ void HippoNonbondedForceProxy::serialize(const void* object, SerializationNode& ...@@ -46,6 +46,7 @@ void HippoNonbondedForceProxy::serialize(const void* object, SerializationNode&
const HippoNonbondedForce& force = *reinterpret_cast<const HippoNonbondedForce*>(object); const HippoNonbondedForce& force = *reinterpret_cast<const HippoNonbondedForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setStringProperty("name", force.getName());
node.setIntProperty("nonbondedMethod", force.getNonbondedMethod()); node.setIntProperty("nonbondedMethod", force.getNonbondedMethod());
node.setDoubleProperty("cutoffDistance", force.getCutoffDistance()); node.setDoubleProperty("cutoffDistance", force.getCutoffDistance());
node.setDoubleProperty("switchingDistance", force.getSwitchingDistance()); node.setDoubleProperty("switchingDistance", force.getSwitchingDistance());
...@@ -122,6 +123,7 @@ void* HippoNonbondedForceProxy::deserialize(const SerializationNode& node) const ...@@ -122,6 +123,7 @@ void* HippoNonbondedForceProxy::deserialize(const SerializationNode& node) const
HippoNonbondedForce* force = new HippoNonbondedForce(); HippoNonbondedForce* force = new HippoNonbondedForce();
try { try {
force->setForceGroup(node.getIntProperty("forceGroup", 0)); force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setName(node.getStringProperty("name", force->getName()));
force->setNonbondedMethod(static_cast<HippoNonbondedForce::NonbondedMethod>(node.getIntProperty("nonbondedMethod"))); force->setNonbondedMethod(static_cast<HippoNonbondedForce::NonbondedMethod>(node.getIntProperty("nonbondedMethod")));
force->setCutoffDistance(node.getDoubleProperty("cutoffDistance")); force->setCutoffDistance(node.getDoubleProperty("cutoffDistance"));
force->setSwitchingDistance(node.getDoubleProperty("switchingDistance")); force->setSwitchingDistance(node.getDoubleProperty("switchingDistance"));
......
...@@ -46,6 +46,7 @@ void testSerialization() { ...@@ -46,6 +46,7 @@ void testSerialization() {
AmoebaGeneralizedKirkwoodForce force1; AmoebaGeneralizedKirkwoodForce force1;
force1.setForceGroup(3); force1.setForceGroup(3);
force1.setName("custom name");
force1.setSolventDielectric( 80.0); force1.setSolventDielectric( 80.0);
force1.setSoluteDielectric( 1.0); force1.setSoluteDielectric( 1.0);
//force1.setDielectricOffset( 0.09); //force1.setDielectricOffset( 0.09);
...@@ -66,6 +67,7 @@ void testSerialization() { ...@@ -66,6 +67,7 @@ void testSerialization() {
// Compare the two forces to see if they are identical. // Compare the two forces to see if they are identical.
AmoebaGeneralizedKirkwoodForce& force2 = *copy; AmoebaGeneralizedKirkwoodForce& force2 = *copy;
ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup()); ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup());
ASSERT_EQUAL(force1.getName(), force2.getName());
ASSERT_EQUAL(force1.getSolventDielectric(), force2.getSolventDielectric()); ASSERT_EQUAL(force1.getSolventDielectric(), force2.getSolventDielectric());
ASSERT_EQUAL(force1.getSoluteDielectric(), force2.getSoluteDielectric()); ASSERT_EQUAL(force1.getSoluteDielectric(), force2.getSoluteDielectric());
//ASSERT_EQUAL(force1.getDielectricOffset(), force2.getDielectricOffset()); //ASSERT_EQUAL(force1.getDielectricOffset(), force2.getDielectricOffset());
......
...@@ -60,6 +60,7 @@ void testSerialization() { ...@@ -60,6 +60,7 @@ void testSerialization() {
AmoebaMultipoleForce force1; AmoebaMultipoleForce force1;
force1.setForceGroup(3); force1.setForceGroup(3);
force1.setName("custom name");
force1.setNonbondedMethod(AmoebaMultipoleForce::NoCutoff); force1.setNonbondedMethod(AmoebaMultipoleForce::NoCutoff);
force1.setCutoffDistance(0.9); force1.setCutoffDistance(0.9);
force1.setAEwald(0.544); force1.setAEwald(0.544);
...@@ -111,6 +112,7 @@ void testSerialization() { ...@@ -111,6 +112,7 @@ void testSerialization() {
AmoebaMultipoleForce& force2 = *copy; AmoebaMultipoleForce& force2 = *copy;
ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup()); ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup());
ASSERT_EQUAL(force1.getName(), force2.getName());
ASSERT_EQUAL(force1.getCutoffDistance(), force2.getCutoffDistance()); ASSERT_EQUAL(force1.getCutoffDistance(), force2.getCutoffDistance());
ASSERT_EQUAL(force1.getNonbondedMethod(), force2.getNonbondedMethod()); ASSERT_EQUAL(force1.getNonbondedMethod(), force2.getNonbondedMethod());
ASSERT_EQUAL(force1.getAEwald(), force2.getAEwald()); ASSERT_EQUAL(force1.getAEwald(), force2.getAEwald());
......
...@@ -82,6 +82,7 @@ void testSerialization() { ...@@ -82,6 +82,7 @@ void testSerialization() {
AmoebaTorsionTorsionForce force1; AmoebaTorsionTorsionForce force1;
force1.setForceGroup(3); force1.setForceGroup(3);
force1.setName("custom name");
for (unsigned int ii = 0; ii < 5; ii++) { for (unsigned int ii = 0; ii < 5; ii++) {
std::vector< std::vector< std::vector<double> > > gridVector; std::vector< std::vector< std::vector<double> > > gridVector;
loadTorsionTorsionGrid(gridVector); loadTorsionTorsionGrid(gridVector);
...@@ -102,6 +103,7 @@ void testSerialization() { ...@@ -102,6 +103,7 @@ void testSerialization() {
AmoebaTorsionTorsionForce & force2 = *copy; AmoebaTorsionTorsionForce & force2 = *copy;
ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup()); ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup());
ASSERT_EQUAL(force1.getName(), force2.getName());
ASSERT_EQUAL(force1.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions()); ASSERT_EQUAL(force1.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions());
ASSERT_EQUAL(force1.getNumTorsionTorsions(), force2.getNumTorsionTorsions()); ASSERT_EQUAL(force1.getNumTorsionTorsions(), force2.getNumTorsionTorsions());
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force1.getNumTorsionTorsions()); ii++) { for (unsigned int ii = 0; ii < static_cast<unsigned int>(force1.getNumTorsionTorsions()); ii++) {
......
...@@ -46,6 +46,7 @@ void testSerialization() { ...@@ -46,6 +46,7 @@ void testSerialization() {
AmoebaVdwForce force1; AmoebaVdwForce force1;
force1.setForceGroup(3); force1.setForceGroup(3);
force1.setName("custom name");
force1.setSigmaCombiningRule("GEOMETRIC"); force1.setSigmaCombiningRule("GEOMETRIC");
force1.setEpsilonCombiningRule("GEOMETRIC"); force1.setEpsilonCombiningRule("GEOMETRIC");
force1.setCutoff(0.9); force1.setCutoff(0.9);
...@@ -74,6 +75,7 @@ void testSerialization() { ...@@ -74,6 +75,7 @@ void testSerialization() {
AmoebaVdwForce& force2 = *copy; AmoebaVdwForce& force2 = *copy;
ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup()); ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup());
ASSERT_EQUAL(force1.getName(), force2.getName());
ASSERT_EQUAL(force1.getSigmaCombiningRule(), force2.getSigmaCombiningRule()); ASSERT_EQUAL(force1.getSigmaCombiningRule(), force2.getSigmaCombiningRule());
ASSERT_EQUAL(force1.getEpsilonCombiningRule(), force2.getEpsilonCombiningRule()); ASSERT_EQUAL(force1.getEpsilonCombiningRule(), force2.getEpsilonCombiningRule());
ASSERT_EQUAL(force1.getCutoff(), force2.getCutoff()); ASSERT_EQUAL(force1.getCutoff(), force2.getCutoff());
......
...@@ -46,6 +46,7 @@ void testSerialization() { ...@@ -46,6 +46,7 @@ void testSerialization() {
AmoebaWcaDispersionForce force1; AmoebaWcaDispersionForce force1;
force1.setForceGroup(3); force1.setForceGroup(3);
force1.setName("custom name");
force1.setEpso( 1.0); force1.setEpso( 1.0);
force1.setEpsh( 1.1); force1.setEpsh( 1.1);
force1.setRmino( 1.2); force1.setRmino( 1.2);
...@@ -70,6 +71,7 @@ void testSerialization() { ...@@ -70,6 +71,7 @@ void testSerialization() {
AmoebaWcaDispersionForce& force2 = *copy; AmoebaWcaDispersionForce& force2 = *copy;
ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup()); ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup());
ASSERT_EQUAL(force1.getName(), force2.getName());
ASSERT_EQUAL(force1.getEpso(), force2.getEpso()); ASSERT_EQUAL(force1.getEpso(), force2.getEpso());
ASSERT_EQUAL(force1.getEpsh(), force2.getEpsh()); ASSERT_EQUAL(force1.getEpsh(), force2.getEpsh());
ASSERT_EQUAL(force1.getRmino(), force2.getRmino()); ASSERT_EQUAL(force1.getRmino(), force2.getRmino());
......
...@@ -48,6 +48,7 @@ void testSerialization() { ...@@ -48,6 +48,7 @@ void testSerialization() {
HippoNonbondedForce force1; HippoNonbondedForce force1;
force1.setForceGroup(3); force1.setForceGroup(3);
force1.setName("custom name");
force1.setNonbondedMethod(HippoNonbondedForce::PME); force1.setNonbondedMethod(HippoNonbondedForce::PME);
force1.setCutoffDistance(0.7); force1.setCutoffDistance(0.7);
force1.setSwitchingDistance(0.6); force1.setSwitchingDistance(0.6);
...@@ -79,6 +80,7 @@ void testSerialization() { ...@@ -79,6 +80,7 @@ void testSerialization() {
HippoNonbondedForce& force2 = *copy; HippoNonbondedForce& force2 = *copy;
ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup()); ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup());
ASSERT_EQUAL(force1.getName(), force2.getName());
ASSERT_EQUAL(force1.getNonbondedMethod(), force2.getNonbondedMethod()); ASSERT_EQUAL(force1.getNonbondedMethod(), force2.getNonbondedMethod());
ASSERT_EQUAL(force1.getCutoffDistance(), force2.getCutoffDistance()); ASSERT_EQUAL(force1.getCutoffDistance(), force2.getCutoffDistance());
ASSERT_EQUAL(force1.getSwitchingDistance(), force2.getSwitchingDistance()); ASSERT_EQUAL(force1.getSwitchingDistance(), force2.getSwitchingDistance());
......
...@@ -44,6 +44,8 @@ DrudeForceProxy::DrudeForceProxy() : SerializationProxy("DrudeForce") { ...@@ -44,6 +44,8 @@ DrudeForceProxy::DrudeForceProxy() : SerializationProxy("DrudeForce") {
void DrudeForceProxy::serialize(const void* object, SerializationNode& node) const { void DrudeForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1); node.setIntProperty("version", 1);
const DrudeForce& force = *reinterpret_cast<const DrudeForce*>(object); const DrudeForce& force = *reinterpret_cast<const DrudeForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setStringProperty("name", force.getName());
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++) {
int p, p1, p2, p3, p4; int p, p1, p2, p3, p4;
...@@ -66,6 +68,8 @@ void* DrudeForceProxy::deserialize(const SerializationNode& node) const { ...@@ -66,6 +68,8 @@ void* DrudeForceProxy::deserialize(const SerializationNode& node) const {
throw OpenMMException("Unsupported version number"); throw OpenMMException("Unsupported version number");
DrudeForce* force = new DrudeForce(); DrudeForce* force = new DrudeForce();
try { try {
force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setName(node.getStringProperty("name", force->getName()));
const SerializationNode& particles = node.getChildNode("Particles"); const SerializationNode& particles = node.getChildNode("Particles");
for (auto& particle : particles.getChildren()) for (auto& particle : particles.getChildren())
force->addParticle(particle.getIntProperty("p"), particle.getIntProperty("p1"), particle.getIntProperty("p2"), particle.getIntProperty("p3"), particle.getIntProperty("p4"), force->addParticle(particle.getIntProperty("p"), particle.getIntProperty("p1"), particle.getIntProperty("p2"), particle.getIntProperty("p3"), particle.getIntProperty("p4"),
......
...@@ -45,6 +45,8 @@ void testSerialization() { ...@@ -45,6 +45,8 @@ void testSerialization() {
// Create a Force. // Create a Force.
DrudeForce force1; DrudeForce force1;
force1.setForceGroup(3);
force1.setName("custom name");
force1.addParticle(0, 1, 2, 3, 4, 0.5, 1.0, 1.5, 2.0); force1.addParticle(0, 1, 2, 3, 4, 0.5, 1.0, 1.5, 2.0);
force1.addParticle(2, 3, 7, 8, 9, 0.1, 1e-4, 1.0, 0.9); force1.addParticle(2, 3, 7, 8, 9, 0.1, 1e-4, 1.0, 0.9);
force1.addParticle(5, 6, -1, -1, -1, 0.2, 0.1, 1.0, 1.0); force1.addParticle(5, 6, -1, -1, -1, 0.2, 0.1, 1.0, 1.0);
...@@ -59,6 +61,8 @@ void testSerialization() { ...@@ -59,6 +61,8 @@ void testSerialization() {
// Compare the two forces to see if they are identical. // Compare the two forces to see if they are identical.
DrudeForce& force2 = *copy; DrudeForce& force2 = *copy;
ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup());
ASSERT_EQUAL(force1.getName(), force2.getName());
ASSERT_EQUAL(force1.getNumParticles(), force2.getNumParticles()); ASSERT_EQUAL(force1.getNumParticles(), force2.getNumParticles());
for (int i = 0; i < (int) force1.getNumParticles(); i++) { for (int i = 0; i < (int) force1.getNumParticles(); i++) {
int a1, a2, a3, a4, a5, b1, b2, b3, b4, b5; int a1, a2, a3, a4, a5, b1, b2, b3, b4, b5;
......
...@@ -48,6 +48,7 @@ void AndersenThermostatProxy::serialize(const void* object, SerializationNode& n ...@@ -48,6 +48,7 @@ void AndersenThermostatProxy::serialize(const void* object, SerializationNode& n
node.setDoubleProperty("frequency", force.getDefaultCollisionFrequency()); node.setDoubleProperty("frequency", force.getDefaultCollisionFrequency());
node.setIntProperty("randomSeed", force.getRandomNumberSeed()); node.setIntProperty("randomSeed", force.getRandomNumberSeed());
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setStringProperty("name", force.getName());
} }
void* AndersenThermostatProxy::deserialize(const SerializationNode& node) const { void* AndersenThermostatProxy::deserialize(const SerializationNode& node) const {
...@@ -57,6 +58,7 @@ void* AndersenThermostatProxy::deserialize(const SerializationNode& node) const ...@@ -57,6 +58,7 @@ void* AndersenThermostatProxy::deserialize(const SerializationNode& node) const
try { try {
AndersenThermostat* force = new AndersenThermostat(node.getDoubleProperty("temperature"), node.getDoubleProperty("frequency")); AndersenThermostat* force = new AndersenThermostat(node.getDoubleProperty("temperature"), node.getDoubleProperty("frequency"));
force->setForceGroup(node.getIntProperty("forceGroup", 0)); force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setName(node.getStringProperty("name", force->getName()));
force->setRandomNumberSeed(node.getIntProperty("randomSeed")); force->setRandomNumberSeed(node.getIntProperty("randomSeed"));
return force; return force;
} }
......
...@@ -45,6 +45,7 @@ void CMAPTorsionForceProxy::serialize(const void* object, SerializationNode& nod ...@@ -45,6 +45,7 @@ void CMAPTorsionForceProxy::serialize(const void* object, SerializationNode& nod
node.setIntProperty("version", 2); node.setIntProperty("version", 2);
const CMAPTorsionForce& force = *reinterpret_cast<const CMAPTorsionForce*>(object); const CMAPTorsionForce& force = *reinterpret_cast<const CMAPTorsionForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setStringProperty("name", force.getName());
node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions()); node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
SerializationNode& maps = node.createChildNode("Maps"); SerializationNode& maps = node.createChildNode("Maps");
for (int i = 0; i < force.getNumMaps(); i++) { for (int i = 0; i < force.getNumMaps(); i++) {
...@@ -70,6 +71,7 @@ void* CMAPTorsionForceProxy::deserialize(const SerializationNode& node) const { ...@@ -70,6 +71,7 @@ void* CMAPTorsionForceProxy::deserialize(const SerializationNode& node) const {
CMAPTorsionForce* force = new CMAPTorsionForce(); CMAPTorsionForce* force = new CMAPTorsionForce();
try { try {
force->setForceGroup(node.getIntProperty("forceGroup", 0)); force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setName(node.getStringProperty("name", force->getName()));
if (version > 1) if (version > 1)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic")); force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& maps = node.getChildNode("Maps"); const SerializationNode& maps = node.getChildNode("Maps");
......
...@@ -45,6 +45,7 @@ void CMMotionRemoverProxy::serialize(const void* object, SerializationNode& node ...@@ -45,6 +45,7 @@ void CMMotionRemoverProxy::serialize(const void* object, SerializationNode& node
node.setIntProperty("version", 1); node.setIntProperty("version", 1);
const CMMotionRemover& force = *reinterpret_cast<const CMMotionRemover*>(object); const CMMotionRemover& force = *reinterpret_cast<const CMMotionRemover*>(object);
node.setIntProperty("forceGroup", force.getForceGroup()); node.setIntProperty("forceGroup", force.getForceGroup());
node.setStringProperty("name", force.getName());
node.setIntProperty("frequency", force.getFrequency()); node.setIntProperty("frequency", force.getFrequency());
} }
...@@ -55,6 +56,7 @@ void* CMMotionRemoverProxy::deserialize(const SerializationNode& node) const { ...@@ -55,6 +56,7 @@ void* CMMotionRemoverProxy::deserialize(const SerializationNode& node) const {
try { try {
CMMotionRemover* force = new CMMotionRemover(node.getIntProperty("frequency")); CMMotionRemover* force = new CMMotionRemover(node.getIntProperty("frequency"));
force->setForceGroup(node.getIntProperty("forceGroup", 0)); force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setName(node.getStringProperty("name", force->getName()));
return force; return force;
} }
catch (...) { catch (...) {
......
...@@ -45,6 +45,7 @@ void CustomAngleForceProxy::serialize(const void* object, SerializationNode& nod ...@@ -45,6 +45,7 @@ void CustomAngleForceProxy::serialize(const void* object, SerializationNode& nod
node.setIntProperty("version", 3); 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.setStringProperty("name", force.getName());
node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions()); node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
node.setStringProperty("energy", force.getEnergyFunction()); node.setStringProperty("energy", force.getEnergyFunction());
SerializationNode& perAngleParams = node.createChildNode("PerAngleParameters"); SerializationNode& perAngleParams = node.createChildNode("PerAngleParameters");
...@@ -82,6 +83,7 @@ void* CustomAngleForceProxy::deserialize(const SerializationNode& node) const { ...@@ -82,6 +83,7 @@ void* CustomAngleForceProxy::deserialize(const SerializationNode& node) const {
try { try {
CustomAngleForce* force = new CustomAngleForce(node.getStringProperty("energy")); CustomAngleForce* force = new CustomAngleForce(node.getStringProperty("energy"));
force->setForceGroup(node.getIntProperty("forceGroup", 0)); force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setName(node.getStringProperty("name", force->getName()));
if (version > 1) if (version > 1)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic")); force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& perAngleParams = node.getChildNode("PerAngleParameters"); const SerializationNode& perAngleParams = node.getChildNode("PerAngleParameters");
......
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