Commit 39120086 authored by John Chodera (MSKCC)'s avatar John Chodera (MSKCC)
Browse files

Merge remote-tracking branch 'upstream/master' into forcefield

parents 87b95319 2acba7ad
...@@ -50,10 +50,36 @@ ...@@ -50,10 +50,36 @@
   
   
using namespace OpenMM; using namespace OpenMM;
using namespace std;
const double TOL = 1e-4; const double TOL = 1e-4;
   
extern "C" void registerAmoebaCudaKernelFactories(); extern "C" void registerAmoebaCudaKernelFactories();
   
static void checkFiniteDifferences(vector<Vec3> forces, Context &context, vector<Vec3> positions)
{
// Take a small step in the direction of the energy gradient and see whether the potential energy changes by the expected amount.
double norm = 0.0;
for (int i = 0; i < (int) forces.size(); ++i)
norm += forces[i].dot(forces[i]);
norm = std::sqrt(norm);
const double stepSize = 1e-3;
double step = 0.5*stepSize/norm;
vector<Vec3> positions2(forces.size()), positions3(forces.size());
for (int i = 0; i < (int) positions.size(); ++i) {
Vec3 p = positions[i];
Vec3 f = forces[i];
positions2[i] = Vec3(p[0]-f[0]*step, p[1]-f[1]*step, p[2]-f[2]*step);
positions3[i] = Vec3(p[0]+f[0]*step, p[1]+f[1]*step, p[2]+f[2]*step);
}
context.setPositions(positions2);
State state2 = context.getState(State::Energy);
context.setPositions(positions3);
State state3 = context.getState(State::Energy);
ASSERT_EQUAL_TOL(state3.getPotentialEnergy()+norm*stepSize, state2.getPotentialEnergy(), 1e-4);
}
// setup for 2 ammonia molecules // setup for 2 ammonia molecules
   
static void setupMultipoleAmmonia(System& system, AmoebaGeneralizedKirkwoodForce* amoebaGeneralizedKirkwoodForce, static void setupMultipoleAmmonia(System& system, AmoebaGeneralizedKirkwoodForce* amoebaGeneralizedKirkwoodForce,
...@@ -289,6 +315,10 @@ static void getForcesEnergyMultipoleAmmonia(Context& context, std::vector<Vec3>& ...@@ -289,6 +315,10 @@ static void getForcesEnergyMultipoleAmmonia(Context& context, std::vector<Vec3>&
State state = context.getState(State::Forces | State::Energy); State state = context.getState(State::Forces | State::Energy);
forces = state.getForces(); forces = state.getForces();
energy = state.getPotentialEnergy(); energy = state.getPotentialEnergy();
// Check that the forces and energy are consistent.
checkFiniteDifferences(forces, context, positions);
} }
   
// setup for villin // setup for villin
...@@ -6972,6 +7002,10 @@ static void setupAndGetForcesEnergyMultipoleVillin(AmoebaMultipoleForce::Polariz ...@@ -6972,6 +7002,10 @@ static void setupAndGetForcesEnergyMultipoleVillin(AmoebaMultipoleForce::Polariz
State state = context.getState(State::Forces | State::Energy); State state = context.getState(State::Forces | State::Energy);
forces = state.getForces(); forces = state.getForces();
energy = state.getPotentialEnergy(); energy = state.getPotentialEnergy();
// Check that the forces and energy are consistent.
checkFiniteDifferences(forces, context, positions);
} }
   
// compare forces and energies // compare forces and energies
...@@ -7049,6 +7083,25 @@ static void testGeneralizedKirkwoodAmmoniaDirectPolarization() { ...@@ -7049,6 +7083,25 @@ static void testGeneralizedKirkwoodAmmoniaDirectPolarization() {
compareForcesEnergy(testName, expectedEnergy, energy, expectedForces, forces, tolerance); compareForcesEnergy(testName, expectedEnergy, energy, expectedForces, forces, tolerance);
} }
   
static void testGeneralizedKirkwoodAmmoniaExtrapolatedPolarization() {
std::string testName = "testGeneralizedKirkwoodAmmoniaExtrapolatedPolarization";
int numberOfParticles = 8;
std::vector<Vec3> forces;
double energy;
System system;
AmoebaGeneralizedKirkwoodForce* amoebaGeneralizedKirkwoodForce = new AmoebaGeneralizedKirkwoodForce();
setupMultipoleAmmonia(system, amoebaGeneralizedKirkwoodForce, AmoebaMultipoleForce::Direct, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01);
Context context(system, integrator, Platform::getPlatformByName("CUDA"));
// We don't have reference values for this case, but at least check that force and energy are consistent.
getForcesEnergyMultipoleAmmonia(context, forces, energy);
}
// test GK mutual polarization for system comprised of two ammonia molecules // test GK mutual polarization for system comprised of two ammonia molecules
   
static void testGeneralizedKirkwoodAmmoniaMutualPolarization() { static void testGeneralizedKirkwoodAmmoniaMutualPolarization() {
...@@ -7765,6 +7818,19 @@ static void testGeneralizedKirkwoodVillinDirectPolarization() { ...@@ -7765,6 +7818,19 @@ static void testGeneralizedKirkwoodVillinDirectPolarization() {
compareForceNormsEnergy(testName, expectedEnergy, energy, expectedForces, forces, tolerance); compareForceNormsEnergy(testName, expectedEnergy, energy, expectedForces, forces, tolerance);
} }
   
static void testGeneralizedKirkwoodVillinExtrapolatedPolarization() {
std::string testName = "testGeneralizedKirkwoodVillinExtrapolatedPolarization";
int numberOfParticles = 596;
std::vector<Vec3> forces;
double energy;
// We don't have reference values for this case, but at least check that force and energy are consistent.
setupAndGetForcesEnergyMultipoleVillin(AmoebaMultipoleForce::Extrapolated, 0, forces, energy);
}
// test GK mutual polarization for villin system // test GK mutual polarization for villin system
   
static void testGeneralizedKirkwoodVillinMutualPolarization() { static void testGeneralizedKirkwoodVillinMutualPolarization() {
...@@ -8401,9 +8467,10 @@ int main(int argc, char* argv[]) { ...@@ -8401,9 +8467,10 @@ int main(int argc, char* argv[]) {
   
testGeneralizedKirkwoodAmmoniaDirectPolarization(); testGeneralizedKirkwoodAmmoniaDirectPolarization();
testGeneralizedKirkwoodAmmoniaMutualPolarization(); testGeneralizedKirkwoodAmmoniaMutualPolarization();
testGeneralizedKirkwoodAmmoniaExtrapolatedPolarization();
testGeneralizedKirkwoodAmmoniaMutualPolarizationWithCavityTerm(); testGeneralizedKirkwoodAmmoniaMutualPolarizationWithCavityTerm();
testGeneralizedKirkwoodVillinDirectPolarization(); testGeneralizedKirkwoodVillinDirectPolarization();
testGeneralizedKirkwoodVillinExtrapolatedPolarization();
testGeneralizedKirkwoodVillinMutualPolarization(); testGeneralizedKirkwoodVillinMutualPolarization();
   
} catch(const std::exception& e) { } catch(const std::exception& e) {
......
...@@ -565,6 +565,8 @@ void ReferenceCalcAmoebaMultipoleForceKernel::initialize(const System& system, c ...@@ -565,6 +565,8 @@ void ReferenceCalcAmoebaMultipoleForceKernel::initialize(const System& system, c
if (polarizationType == AmoebaMultipoleForce::Mutual) { if (polarizationType == AmoebaMultipoleForce::Mutual) {
mutualInducedMaxIterations = force.getMutualInducedMaxIterations(); mutualInducedMaxIterations = force.getMutualInducedMaxIterations();
mutualInducedTargetEpsilon = force.getMutualInducedTargetEpsilon(); mutualInducedTargetEpsilon = force.getMutualInducedTargetEpsilon();
} else if (polarizationType == AmoebaMultipoleForce::Extrapolated) {
extrapolationCoefficients = force.getExtrapolationCoefficients();
} }
// PME // PME
...@@ -667,6 +669,9 @@ AmoebaReferenceMultipoleForce* ReferenceCalcAmoebaMultipoleForceKernel::setupAmo ...@@ -667,6 +669,9 @@ AmoebaReferenceMultipoleForce* ReferenceCalcAmoebaMultipoleForceKernel::setupAmo
amoebaReferenceMultipoleForce->setMaximumMutualInducedDipoleIterations(mutualInducedMaxIterations); amoebaReferenceMultipoleForce->setMaximumMutualInducedDipoleIterations(mutualInducedMaxIterations);
} else if (polarizationType == AmoebaMultipoleForce::Direct) { } else if (polarizationType == AmoebaMultipoleForce::Direct) {
amoebaReferenceMultipoleForce->setPolarizationType(AmoebaReferenceMultipoleForce::Direct); amoebaReferenceMultipoleForce->setPolarizationType(AmoebaReferenceMultipoleForce::Direct);
} else if (polarizationType == AmoebaMultipoleForce::Extrapolated) {
amoebaReferenceMultipoleForce->setPolarizationType(AmoebaReferenceMultipoleForce::Extrapolated);
amoebaReferenceMultipoleForce->setExtrapolationCoefficients(extrapolationCoefficients);
} else { } else {
throw OpenMMException("Polarization type not recognzied."); throw OpenMMException("Polarization type not recognzied.");
} }
......
...@@ -432,6 +432,7 @@ private: ...@@ -432,6 +432,7 @@ private:
int mutualInducedMaxIterations; int mutualInducedMaxIterations;
RealOpenMM mutualInducedTargetEpsilon; RealOpenMM mutualInducedTargetEpsilon;
std::vector<double> extrapolationCoefficients;
bool usePme; bool usePme;
RealOpenMM alphaEwald; RealOpenMM alphaEwald;
......
...@@ -345,11 +345,16 @@ public: ...@@ -345,11 +345,16 @@ public:
*/ */
Mutual = 0, Mutual = 0,
/** /**
* Direct polarization * Direct polarization
*/ */
Direct = 1 Direct = 1,
};
/**
* Extrapolated perturbation theory
*/
Extrapolated = 2
};
/** /**
* Constructor * Constructor
...@@ -422,6 +427,15 @@ public: ...@@ -422,6 +427,15 @@ public:
*/ */
RealOpenMM getMutualInducedDipoleEpsilon() const; RealOpenMM getMutualInducedDipoleEpsilon() const;
/**
* Set the coefficients for the µ_0, µ_1, µ_2, µ_n terms in the extrapolation
* theory algorithm for induced dipoles
*
* @param optCoefficients a vector whose mth entry specifies the coefficient for µ_m
*
*/
void setExtrapolationCoefficients(const std::vector<RealOpenMM> &coefficients);
/** /**
* Set the target epsilon for converging mutual induced dipoles. * Set the target epsilon for converging mutual induced dipoles.
* *
...@@ -624,10 +638,13 @@ protected: ...@@ -624,10 +638,13 @@ protected:
* Helper class used in calculating induced dipoles * Helper class used in calculating induced dipoles
*/ */
struct UpdateInducedDipoleFieldStruct { struct UpdateInducedDipoleFieldStruct {
UpdateInducedDipoleFieldStruct(std::vector<OpenMM::RealVec>& inputFixed_E_Field, std::vector<OpenMM::RealVec>& inputInducedDipoles); UpdateInducedDipoleFieldStruct(std::vector<OpenMM::RealVec>& inputFixed_E_Field, std::vector<OpenMM::RealVec>& inputInducedDipoles, std::vector<std::vector<RealVec> >& extrapolatedDipoles, std::vector<std::vector<RealOpenMM> >& extrapolatedDipoleFieldGradient);
std::vector<OpenMM::RealVec>* fixedMultipoleField; std::vector<OpenMM::RealVec>* fixedMultipoleField;
std::vector<OpenMM::RealVec>* inducedDipoles; std::vector<OpenMM::RealVec>* inducedDipoles;
std::vector<std::vector<RealVec> >* extrapolatedDipoles;
std::vector<std::vector<RealOpenMM> >* extrapolatedDipoleFieldGradient;
std::vector<OpenMM::RealVec> inducedDipoleField; std::vector<OpenMM::RealVec> inducedDipoleField;
std::vector<std::vector<RealOpenMM> > inducedDipoleFieldGradient;
}; };
unsigned int _numParticles; unsigned int _numParticles;
...@@ -651,10 +668,17 @@ protected: ...@@ -651,10 +668,17 @@ protected:
std::vector<RealVec> _fixedMultipoleFieldPolar; std::vector<RealVec> _fixedMultipoleFieldPolar;
std::vector<RealVec> _inducedDipole; std::vector<RealVec> _inducedDipole;
std::vector<RealVec> _inducedDipolePolar; std::vector<RealVec> _inducedDipolePolar;
std::vector<std::vector<RealVec> > _ptDipoleP;
std::vector<std::vector<RealVec> > _ptDipoleD;
std::vector<std::vector<RealOpenMM> > _ptDipoleFieldGradientP;
std::vector<std::vector<RealOpenMM> > _ptDipoleFieldGradientD;
int _mutualInducedDipoleConverged; int _mutualInducedDipoleConverged;
int _mutualInducedDipoleIterations; int _mutualInducedDipoleIterations;
int _maximumMutualInducedDipoleIterations; int _maximumMutualInducedDipoleIterations;
int _maxPTOrder;
std::vector<RealOpenMM> _extrapolationCoefficients;
std::vector<RealOpenMM> _extPartCoefficients;
RealOpenMM _mutualInducedDipoleEpsilon; RealOpenMM _mutualInducedDipoleEpsilon;
RealOpenMM _mutualInducedDipoleTargetEpsilon; RealOpenMM _mutualInducedDipoleTargetEpsilon;
RealOpenMM _polarSOR; RealOpenMM _polarSOR;
...@@ -904,7 +928,7 @@ protected: ...@@ -904,7 +928,7 @@ protected:
/** /**
* Calculate fields due induced dipoles at each site. * Calculate fields due induced dipoles at each site.
* *
* @param particleI positions and parameters (charge, labFrame dipoles, quadrupoles, ...) for particle I * @param particleI positions and parameters (charge, labFrame dipoles, quadrupoles, ...) for particle I
* @param particleJ positions and parameters (charge, labFrame dipoles, quadrupoles, ...) for particle J * @param particleJ positions and parameters (charge, labFrame dipoles, quadrupoles, ...) for particle J
* @param updateInducedDipoleFields vector of UpdateInducedDipoleFieldStruct containing input induced dipoles and output fields * @param updateInducedDipoleFields vector of UpdateInducedDipoleFieldStruct containing input induced dipoles and output fields
...@@ -920,6 +944,14 @@ protected: ...@@ -920,6 +944,14 @@ protected:
*/ */
virtual void calculateInducedDipoleFields(const std::vector<MultipoleParticleData>& particleData, virtual void calculateInducedDipoleFields(const std::vector<MultipoleParticleData>& particleData,
std::vector<UpdateInducedDipoleFieldStruct>& updateInducedDipoleFields); std::vector<UpdateInducedDipoleFieldStruct>& updateInducedDipoleFields);
/**
* Calculated induced dipoles using extrapolated perturbation theory.
*
* @param particleData vector of particle positions and parameters (charge, labFrame dipoles, quadrupoles, ...)
* @param updateInducedDipoleFields vector of UpdateInducedDipoleFieldStruct containing input induced dipoles and output fields
*/
void convergeInduceDipolesByExtrapolation(const std::vector<MultipoleParticleData>& particleData,
std::vector<UpdateInducedDipoleFieldStruct>& calculateInducedDipoleField);
/** /**
* Converge induced dipoles. * Converge induced dipoles.
* *
...@@ -1191,6 +1223,10 @@ private: ...@@ -1191,6 +1223,10 @@ private:
std::vector<RealVec> _gkField; std::vector<RealVec> _gkField;
std::vector<RealVec> _inducedDipoleS; std::vector<RealVec> _inducedDipoleS;
std::vector<RealVec> _inducedDipolePolarS; std::vector<RealVec> _inducedDipolePolarS;
std::vector<std::vector<RealVec> > _ptDipolePS;
std::vector<std::vector<RealVec> > _ptDipoleDS;
std::vector<std::vector<RealOpenMM> > _ptDipoleFieldGradientPS;
std::vector<std::vector<RealOpenMM> > _ptDipoleFieldGradientDS;
int _includeCavityTerm; int _includeCavityTerm;
RealOpenMM _probeRadius; RealOpenMM _probeRadius;
......
...@@ -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) 2008-2012 Stanford University and the Authors. * * Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Authors: Mark Friedrichs * * Authors: Mark Friedrichs *
* Contributors: * * Contributors: *
* * * *
...@@ -50,11 +50,36 @@ ...@@ -50,11 +50,36 @@
   
   
using namespace OpenMM; using namespace OpenMM;
using namespace std;
   
extern "C" OPENMM_EXPORT void registerAmoebaReferenceKernelFactories(); extern "C" OPENMM_EXPORT void registerAmoebaReferenceKernelFactories();
   
const double TOL = 1e-4; const double TOL = 1e-4;
   
static void checkFiniteDifferences(vector<Vec3> forces, Context &context, vector<Vec3> positions)
{
// Take a small step in the direction of the energy gradient and see whether the potential energy changes by the expected amount.
double norm = 0.0;
for (int i = 0; i < (int) forces.size(); ++i)
norm += forces[i].dot(forces[i]);
norm = std::sqrt(norm);
const double stepSize = 1e-3;
double step = 0.5*stepSize/norm;
vector<Vec3> positions2(forces.size()), positions3(forces.size());
for (int i = 0; i < (int) positions.size(); ++i) {
Vec3 p = positions[i];
Vec3 f = forces[i];
positions2[i] = Vec3(p[0]-f[0]*step, p[1]-f[1]*step, p[2]-f[2]*step);
positions3[i] = Vec3(p[0]+f[0]*step, p[1]+f[1]*step, p[2]+f[2]*step);
}
context.setPositions(positions2);
State state2 = context.getState(State::Energy);
context.setPositions(positions3);
State state3 = context.getState(State::Energy);
ASSERT_EQUAL_TOL(norm, (state2.getPotentialEnergy()-state3.getPotentialEnergy())/stepSize, 1e-4);
}
// setup for 2 ammonia molecules // setup for 2 ammonia molecules
   
static void setupMultipoleAmmonia(System& system, AmoebaGeneralizedKirkwoodForce* amoebaGeneralizedKirkwoodForce, static void setupMultipoleAmmonia(System& system, AmoebaGeneralizedKirkwoodForce* amoebaGeneralizedKirkwoodForce,
...@@ -291,6 +316,10 @@ static void getForcesEnergyMultipoleAmmonia(Context& context, std::vector<Vec3>& ...@@ -291,6 +316,10 @@ static void getForcesEnergyMultipoleAmmonia(Context& context, std::vector<Vec3>&
State state = context.getState(State::Forces | State::Energy); State state = context.getState(State::Forces | State::Energy);
forces = state.getForces(); forces = state.getForces();
energy = state.getPotentialEnergy(); energy = state.getPotentialEnergy();
// Check that the forces and energy are consistent.
checkFiniteDifferences(forces, context, positions);
} }
   
// setup for villin // setup for villin
...@@ -6974,6 +7003,10 @@ static void setupAndGetForcesEnergyMultipoleVillin(AmoebaMultipoleForce::Polariz ...@@ -6974,6 +7003,10 @@ static void setupAndGetForcesEnergyMultipoleVillin(AmoebaMultipoleForce::Polariz
State state = context.getState(State::Forces | State::Energy); State state = context.getState(State::Forces | State::Energy);
forces = state.getForces(); forces = state.getForces();
energy = state.getPotentialEnergy(); energy = state.getPotentialEnergy();
// Check that the forces and energy are consistent.
checkFiniteDifferences(forces, context, positions);
} }
   
// compare forces and energies // compare forces and energies
...@@ -7052,6 +7085,25 @@ static void testGeneralizedKirkwoodAmmoniaDirectPolarization() { ...@@ -7052,6 +7085,25 @@ static void testGeneralizedKirkwoodAmmoniaDirectPolarization() {
compareForcesEnergy(testName, expectedEnergy, energy, expectedForces, forces, tolerance); compareForcesEnergy(testName, expectedEnergy, energy, expectedForces, forces, tolerance);
} }
   
static void testGeneralizedKirkwoodAmmoniaExtrapolatedPolarization() {
std::string testName = "testGeneralizedKirkwoodAmmoniaExtrapolatedPolarization";
int numberOfParticles = 8;
std::vector<Vec3> forces;
double energy;
System system;
AmoebaGeneralizedKirkwoodForce* amoebaGeneralizedKirkwoodForce = new AmoebaGeneralizedKirkwoodForce();
setupMultipoleAmmonia(system, amoebaGeneralizedKirkwoodForce, AmoebaMultipoleForce::Direct, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01);
Context context(system, integrator, Platform::getPlatformByName("Reference"));
// We don't have reference values for this case, but at least check that force and energy are consistent.
getForcesEnergyMultipoleAmmonia(context, forces, energy);
}
// test GK mutual polarization for system comprised of two ammonia molecules // test GK mutual polarization for system comprised of two ammonia molecules
   
static void testGeneralizedKirkwoodAmmoniaMutualPolarization() { static void testGeneralizedKirkwoodAmmoniaMutualPolarization() {
...@@ -7770,6 +7822,19 @@ static void testGeneralizedKirkwoodVillinDirectPolarization() { ...@@ -7770,6 +7822,19 @@ static void testGeneralizedKirkwoodVillinDirectPolarization() {
compareForceNormsEnergy(testName, expectedEnergy, energy, expectedForces, forces, tolerance); compareForceNormsEnergy(testName, expectedEnergy, energy, expectedForces, forces, tolerance);
} }
   
static void testGeneralizedKirkwoodVillinExtrapolatedPolarization() {
std::string testName = "testGeneralizedKirkwoodVillinExtrapolatedPolarization";
int numberOfParticles = 596;
std::vector<Vec3> forces;
double energy;
// We don't have reference values for this case, but at least check that force and energy are consistent.
setupAndGetForcesEnergyMultipoleVillin(AmoebaMultipoleForce::Extrapolated, 0, forces, energy);
}
// test GK mutual polarization for villin system // test GK mutual polarization for villin system
   
static void testGeneralizedKirkwoodVillinMutualPolarization() { static void testGeneralizedKirkwoodVillinMutualPolarization() {
...@@ -8405,8 +8470,10 @@ int main(int numberOfArguments, char* argv[]) { ...@@ -8405,8 +8470,10 @@ int main(int numberOfArguments, char* argv[]) {
   
testGeneralizedKirkwoodAmmoniaMutualPolarization(); testGeneralizedKirkwoodAmmoniaMutualPolarization();
testGeneralizedKirkwoodAmmoniaDirectPolarization(); testGeneralizedKirkwoodAmmoniaDirectPolarization();
testGeneralizedKirkwoodAmmoniaExtrapolatedPolarization();
testGeneralizedKirkwoodAmmoniaMutualPolarizationWithCavityTerm(); testGeneralizedKirkwoodAmmoniaMutualPolarizationWithCavityTerm();
testGeneralizedKirkwoodVillinDirectPolarization(); testGeneralizedKirkwoodVillinDirectPolarization();
testGeneralizedKirkwoodVillinExtrapolatedPolarization();
testGeneralizedKirkwoodVillinMutualPolarization(); testGeneralizedKirkwoodVillinMutualPolarization();
   
} }
......
...@@ -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 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -42,10 +42,11 @@ AmoebaAngleForceProxy::AmoebaAngleForceProxy() : SerializationProxy("AmoebaAngle ...@@ -42,10 +42,11 @@ AmoebaAngleForceProxy::AmoebaAngleForceProxy() : SerializationProxy("AmoebaAngle
} }
void AmoebaAngleForceProxy::serialize(const void* object, SerializationNode& node) const { void AmoebaAngleForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1); node.setIntProperty("version", 2);
const AmoebaAngleForce& force = *reinterpret_cast<const AmoebaAngleForce*>(object); const AmoebaAngleForce& force = *reinterpret_cast<const AmoebaAngleForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setDoubleProperty("cubic", force.getAmoebaGlobalAngleCubic()); node.setDoubleProperty("cubic", force.getAmoebaGlobalAngleCubic());
node.setDoubleProperty("quartic", force.getAmoebaGlobalAngleQuartic()); node.setDoubleProperty("quartic", force.getAmoebaGlobalAngleQuartic());
node.setDoubleProperty("pentic", force.getAmoebaGlobalAnglePentic()); node.setDoubleProperty("pentic", force.getAmoebaGlobalAnglePentic());
...@@ -61,11 +62,13 @@ void AmoebaAngleForceProxy::serialize(const void* object, SerializationNode& nod ...@@ -61,11 +62,13 @@ void AmoebaAngleForceProxy::serialize(const void* object, SerializationNode& nod
} }
void* AmoebaAngleForceProxy::deserialize(const SerializationNode& node) const { void* AmoebaAngleForceProxy::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");
AmoebaAngleForce* force = new AmoebaAngleForce(); AmoebaAngleForce* force = new AmoebaAngleForce();
try { try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setAmoebaGlobalAngleCubic(node.getDoubleProperty("cubic")); force->setAmoebaGlobalAngleCubic(node.getDoubleProperty("cubic"));
force->setAmoebaGlobalAngleQuartic(node.getDoubleProperty("quartic")); force->setAmoebaGlobalAngleQuartic(node.getDoubleProperty("quartic"));
force->setAmoebaGlobalAnglePentic(node.getDoubleProperty("pentic")); force->setAmoebaGlobalAnglePentic(node.getDoubleProperty("pentic"));
......
...@@ -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 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -42,9 +42,10 @@ AmoebaBondForceProxy::AmoebaBondForceProxy() : SerializationProxy("AmoebaBondFor ...@@ -42,9 +42,10 @@ AmoebaBondForceProxy::AmoebaBondForceProxy() : SerializationProxy("AmoebaBondFor
} }
void AmoebaBondForceProxy::serialize(const void* object, SerializationNode& node) const { void AmoebaBondForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1); node.setIntProperty("version", 2);
const AmoebaBondForce& force = *reinterpret_cast<const AmoebaBondForce*>(object); const AmoebaBondForce& force = *reinterpret_cast<const AmoebaBondForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setDoubleProperty("cubic", force.getAmoebaGlobalBondCubic()); node.setDoubleProperty("cubic", force.getAmoebaGlobalBondCubic());
node.setDoubleProperty("quartic", force.getAmoebaGlobalBondQuartic()); node.setDoubleProperty("quartic", force.getAmoebaGlobalBondQuartic());
...@@ -58,10 +59,13 @@ void AmoebaBondForceProxy::serialize(const void* object, SerializationNode& node ...@@ -58,10 +59,13 @@ void AmoebaBondForceProxy::serialize(const void* object, SerializationNode& node
} }
void* AmoebaBondForceProxy::deserialize(const SerializationNode& node) const { void* AmoebaBondForceProxy::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");
AmoebaBondForce* force = new AmoebaBondForce(); AmoebaBondForce* force = new AmoebaBondForce();
try { try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setAmoebaGlobalBondCubic(node.getDoubleProperty("cubic")); force->setAmoebaGlobalBondCubic(node.getDoubleProperty("cubic"));
force->setAmoebaGlobalBondQuartic(node.getDoubleProperty("quartic")); force->setAmoebaGlobalBondQuartic(node.getDoubleProperty("quartic"));
const SerializationNode& bonds = node.getChildNode("Bonds"); const SerializationNode& bonds = node.getChildNode("Bonds");
......
...@@ -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 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -42,9 +42,10 @@ AmoebaGeneralizedKirkwoodForceProxy::AmoebaGeneralizedKirkwoodForceProxy() : Ser ...@@ -42,9 +42,10 @@ AmoebaGeneralizedKirkwoodForceProxy::AmoebaGeneralizedKirkwoodForceProxy() : Ser
} }
void AmoebaGeneralizedKirkwoodForceProxy::serialize(const void* object, SerializationNode& node) const { void AmoebaGeneralizedKirkwoodForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1); node.setIntProperty("version", 2);
const AmoebaGeneralizedKirkwoodForce& force = *reinterpret_cast<const AmoebaGeneralizedKirkwoodForce*>(object); const AmoebaGeneralizedKirkwoodForce& force = *reinterpret_cast<const AmoebaGeneralizedKirkwoodForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
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());
...@@ -62,11 +63,13 @@ void AmoebaGeneralizedKirkwoodForceProxy::serialize(const void* object, Serializ ...@@ -62,11 +63,13 @@ void AmoebaGeneralizedKirkwoodForceProxy::serialize(const void* object, Serializ
} }
void* AmoebaGeneralizedKirkwoodForceProxy::deserialize(const SerializationNode& node) const { void* AmoebaGeneralizedKirkwoodForceProxy::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");
AmoebaGeneralizedKirkwoodForce* force = new AmoebaGeneralizedKirkwoodForce(); AmoebaGeneralizedKirkwoodForce* force = new AmoebaGeneralizedKirkwoodForce();
try { try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
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"));
......
...@@ -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 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -43,9 +43,10 @@ AmoebaInPlaneAngleForceProxy::AmoebaInPlaneAngleForceProxy() : SerializationProx ...@@ -43,9 +43,10 @@ AmoebaInPlaneAngleForceProxy::AmoebaInPlaneAngleForceProxy() : SerializationProx
void AmoebaInPlaneAngleForceProxy::serialize(const void* object, SerializationNode& node) const { void AmoebaInPlaneAngleForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1); node.setIntProperty("version", 2);
const AmoebaInPlaneAngleForce& force = *reinterpret_cast<const AmoebaInPlaneAngleForce*>(object); const AmoebaInPlaneAngleForce& force = *reinterpret_cast<const AmoebaInPlaneAngleForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setDoubleProperty("cubic", force.getAmoebaGlobalInPlaneAngleCubic()); node.setDoubleProperty("cubic", force.getAmoebaGlobalInPlaneAngleCubic());
node.setDoubleProperty("quartic", force.getAmoebaGlobalInPlaneAngleQuartic()); node.setDoubleProperty("quartic", force.getAmoebaGlobalInPlaneAngleQuartic());
node.setDoubleProperty("pentic", force.getAmoebaGlobalInPlaneAnglePentic()); node.setDoubleProperty("pentic", force.getAmoebaGlobalInPlaneAnglePentic());
...@@ -61,11 +62,13 @@ void AmoebaInPlaneAngleForceProxy::serialize(const void* object, SerializationNo ...@@ -61,11 +62,13 @@ void AmoebaInPlaneAngleForceProxy::serialize(const void* object, SerializationNo
} }
void* AmoebaInPlaneAngleForceProxy::deserialize(const SerializationNode& node) const { void* AmoebaInPlaneAngleForceProxy::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");
AmoebaInPlaneAngleForce* force = new AmoebaInPlaneAngleForce(); AmoebaInPlaneAngleForce* force = new AmoebaInPlaneAngleForce();
try { try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setAmoebaGlobalInPlaneAngleCubic( node.getDoubleProperty("cubic")); force->setAmoebaGlobalInPlaneAngleCubic( node.getDoubleProperty("cubic"));
force->setAmoebaGlobalInPlaneAngleQuartic(node.getDoubleProperty("quartic")); force->setAmoebaGlobalInPlaneAngleQuartic(node.getDoubleProperty("quartic"));
force->setAmoebaGlobalInPlaneAnglePentic(node.getDoubleProperty("pentic")); force->setAmoebaGlobalInPlaneAnglePentic(node.getDoubleProperty("pentic"));
......
...@@ -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 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -68,9 +68,10 @@ void loadCovalentMap(const SerializationNode& map, std::vector< int >& covalentM ...@@ -68,9 +68,10 @@ void loadCovalentMap(const SerializationNode& map, std::vector< int >& covalentM
} }
void AmoebaMultipoleForceProxy::serialize(const void* object, SerializationNode& node) const { void AmoebaMultipoleForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 2); node.setIntProperty("version", 4);
const AmoebaMultipoleForce& force = *reinterpret_cast<const AmoebaMultipoleForce*>(object); const AmoebaMultipoleForce& force = *reinterpret_cast<const AmoebaMultipoleForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setIntProperty("nonbondedMethod", force.getNonbondedMethod()); node.setIntProperty("nonbondedMethod", force.getNonbondedMethod());
node.setIntProperty("polarizationType", force.getPolarizationType()); node.setIntProperty("polarizationType", force.getPolarizationType());
//node.setIntProperty("pmeBSplineOrder", force.getPmeBSplineOrder()); //node.setIntProperty("pmeBSplineOrder", force.getPmeBSplineOrder());
...@@ -87,6 +88,14 @@ void AmoebaMultipoleForceProxy::serialize(const void* object, SerializationNode& ...@@ -87,6 +88,14 @@ void AmoebaMultipoleForceProxy::serialize(const void* object, SerializationNode&
force.getPmeGridDimensions(gridDimensions); force.getPmeGridDimensions(gridDimensions);
SerializationNode& gridDimensionsNode = node.createChildNode("MultipoleParticleGridDimension"); SerializationNode& gridDimensionsNode = node.createChildNode("MultipoleParticleGridDimension");
gridDimensionsNode.setIntProperty("d0", gridDimensions[0]).setIntProperty("d1", gridDimensions[1]).setIntProperty("d2", gridDimensions[2]); gridDimensionsNode.setIntProperty("d0", gridDimensions[0]).setIntProperty("d1", gridDimensions[1]).setIntProperty("d2", gridDimensions[2]);
SerializationNode& coefficients = node.createChildNode("ExtrapolationCoefficients");
vector<double> coeff = force.getExtrapolationCoefficients();
for (int i = 0; i < coeff.size(); i++) {
stringstream key;
key << "c" << i;
coefficients.setDoubleProperty(key.str(), coeff[i]);
}
std::vector<std::string> covalentTypes; std::vector<std::string> covalentTypes;
getCovalentTypes(covalentTypes); getCovalentTypes(covalentTypes);
...@@ -124,16 +133,17 @@ void AmoebaMultipoleForceProxy::serialize(const void* object, SerializationNode& ...@@ -124,16 +133,17 @@ void AmoebaMultipoleForceProxy::serialize(const void* object, SerializationNode&
} }
void* AmoebaMultipoleForceProxy::deserialize(const SerializationNode& node) const { void* AmoebaMultipoleForceProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") > 2) int version = node.getIntProperty("version");
if (version < 0 || version > 4)
throw OpenMMException("Unsupported version number"); throw OpenMMException("Unsupported version number");
AmoebaMultipoleForce* force = new AmoebaMultipoleForce(); AmoebaMultipoleForce* force = new AmoebaMultipoleForce();
try { try {
if (version > 3)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setNonbondedMethod(static_cast<AmoebaMultipoleForce::NonbondedMethod>(node.getIntProperty("nonbondedMethod"))); force->setNonbondedMethod(static_cast<AmoebaMultipoleForce::NonbondedMethod>(node.getIntProperty("nonbondedMethod")));
if (node.getIntProperty("version") == 2) { if (version >= 2)
force->setPolarizationType(static_cast<AmoebaMultipoleForce::PolarizationType>(node.getIntProperty("polarizationType"))); force->setPolarizationType(static_cast<AmoebaMultipoleForce::PolarizationType>(node.getIntProperty("polarizationType")));
}
//force->setPmeBSplineOrder(node.getIntProperty("pmeBSplineOrder")); //force->setPmeBSplineOrder(node.getIntProperty("pmeBSplineOrder"));
//force->setMutualInducedIterationMethod(static_cast<AmoebaMultipoleForce::MutualInducedIterationMethod>(node.getIntProperty("mutualInducedIterationMethod"))); //force->setMutualInducedIterationMethod(static_cast<AmoebaMultipoleForce::MutualInducedIterationMethod>(node.getIntProperty("mutualInducedIterationMethod")));
force->setMutualInducedMaxIterations(node.getIntProperty("mutualInducedMaxIterations")); force->setMutualInducedMaxIterations(node.getIntProperty("mutualInducedMaxIterations"));
...@@ -151,6 +161,18 @@ void* AmoebaMultipoleForceProxy::deserialize(const SerializationNode& node) cons ...@@ -151,6 +161,18 @@ void* AmoebaMultipoleForceProxy::deserialize(const SerializationNode& node) cons
gridDimensions.push_back(gridDimensionsNode.getIntProperty("d2")); gridDimensions.push_back(gridDimensionsNode.getIntProperty("d2"));
force->setPmeGridDimensions(gridDimensions); force->setPmeGridDimensions(gridDimensions);
if (version >= 3) {
const SerializationNode& coefficients = node.getChildNode("ExtrapolationCoefficients");
vector<double> coeff;
for (int i = 0; ; i++) {
stringstream key;
key << "c" << i;
if (coefficients.getProperties().find(key.str()) == coefficients.getProperties().end())
break;
coeff.push_back(coefficients.getDoubleProperty(key.str()));
}
force->setExtrapolationCoefficients(coeff);
}
std::vector<std::string> covalentTypes; std::vector<std::string> covalentTypes;
getCovalentTypes(covalentTypes); getCovalentTypes(covalentTypes);
......
...@@ -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 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -42,8 +42,9 @@ AmoebaOutOfPlaneBendForceProxy::AmoebaOutOfPlaneBendForceProxy() : Serialization ...@@ -42,8 +42,9 @@ AmoebaOutOfPlaneBendForceProxy::AmoebaOutOfPlaneBendForceProxy() : Serialization
} }
void AmoebaOutOfPlaneBendForceProxy::serialize(const void* object, SerializationNode& node) const { void AmoebaOutOfPlaneBendForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1); node.setIntProperty("version", 2);
const AmoebaOutOfPlaneBendForce& force = *reinterpret_cast<const AmoebaOutOfPlaneBendForce*>(object); const AmoebaOutOfPlaneBendForce& force = *reinterpret_cast<const AmoebaOutOfPlaneBendForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setDoubleProperty("cubic", force.getAmoebaGlobalOutOfPlaneBendCubic()); node.setDoubleProperty("cubic", force.getAmoebaGlobalOutOfPlaneBendCubic());
node.setDoubleProperty("quartic", force.getAmoebaGlobalOutOfPlaneBendQuartic()); node.setDoubleProperty("quartic", force.getAmoebaGlobalOutOfPlaneBendQuartic());
node.setDoubleProperty("pentic", force.getAmoebaGlobalOutOfPlaneBendPentic()); node.setDoubleProperty("pentic", force.getAmoebaGlobalOutOfPlaneBendPentic());
...@@ -59,11 +60,13 @@ void AmoebaOutOfPlaneBendForceProxy::serialize(const void* object, Serialization ...@@ -59,11 +60,13 @@ void AmoebaOutOfPlaneBendForceProxy::serialize(const void* object, Serialization
} }
void* AmoebaOutOfPlaneBendForceProxy::deserialize(const SerializationNode& node) const { void* AmoebaOutOfPlaneBendForceProxy::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");
AmoebaOutOfPlaneBendForce* force = new AmoebaOutOfPlaneBendForce(); AmoebaOutOfPlaneBendForce* force = new AmoebaOutOfPlaneBendForce();
try { try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setAmoebaGlobalOutOfPlaneBendCubic(node.getDoubleProperty("cubic")); force->setAmoebaGlobalOutOfPlaneBendCubic(node.getDoubleProperty("cubic"));
force->setAmoebaGlobalOutOfPlaneBendQuartic(node.getDoubleProperty("quartic")); force->setAmoebaGlobalOutOfPlaneBendQuartic(node.getDoubleProperty("quartic"));
force->setAmoebaGlobalOutOfPlaneBendPentic(node.getDoubleProperty("pentic")); force->setAmoebaGlobalOutOfPlaneBendPentic(node.getDoubleProperty("pentic"));
......
...@@ -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 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -42,8 +42,9 @@ AmoebaPiTorsionForceProxy::AmoebaPiTorsionForceProxy() : SerializationProxy("Amo ...@@ -42,8 +42,9 @@ AmoebaPiTorsionForceProxy::AmoebaPiTorsionForceProxy() : SerializationProxy("Amo
} }
void AmoebaPiTorsionForceProxy::serialize(const void* object, SerializationNode& node) const { void AmoebaPiTorsionForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1); node.setIntProperty("version", 2);
const AmoebaPiTorsionForce& force = *reinterpret_cast<const AmoebaPiTorsionForce*>(object); const AmoebaPiTorsionForce& force = *reinterpret_cast<const AmoebaPiTorsionForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
SerializationNode& bonds = node.createChildNode("PiTorsion"); SerializationNode& bonds = node.createChildNode("PiTorsion");
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumPiTorsions()); ii++) { for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumPiTorsions()); ii++) {
int particle1, particle2, particle3, particle4, particle5, particle6; int particle1, particle2, particle3, particle4, particle5, particle6;
...@@ -54,10 +55,13 @@ void AmoebaPiTorsionForceProxy::serialize(const void* object, SerializationNode& ...@@ -54,10 +55,13 @@ void AmoebaPiTorsionForceProxy::serialize(const void* object, SerializationNode&
} }
void* AmoebaPiTorsionForceProxy::deserialize(const SerializationNode& node) const { void* AmoebaPiTorsionForceProxy::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");
AmoebaPiTorsionForce* force = new AmoebaPiTorsionForce(); AmoebaPiTorsionForce* force = new AmoebaPiTorsionForce();
try { try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
const SerializationNode& bonds = node.getChildNode("PiTorsion"); const SerializationNode& bonds = node.getChildNode("PiTorsion");
for (unsigned int ii = 0; ii < bonds.getChildren().size(); ii++) { for (unsigned int ii = 0; ii < bonds.getChildren().size(); ii++) {
const SerializationNode& bond = bonds.getChildren()[ii]; const SerializationNode& bond = bonds.getChildren()[ii];
......
...@@ -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-2015 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -42,8 +42,9 @@ AmoebaStretchBendForceProxy::AmoebaStretchBendForceProxy() : SerializationProxy( ...@@ -42,8 +42,9 @@ AmoebaStretchBendForceProxy::AmoebaStretchBendForceProxy() : SerializationProxy(
} }
void AmoebaStretchBendForceProxy::serialize(const void* object, SerializationNode& node) const { void AmoebaStretchBendForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 2); node.setIntProperty("version", 3);
const AmoebaStretchBendForce& force = *reinterpret_cast<const AmoebaStretchBendForce*>(object); const AmoebaStretchBendForce& force = *reinterpret_cast<const AmoebaStretchBendForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
SerializationNode& bonds = node.createChildNode("StretchBendAngles"); SerializationNode& bonds = node.createChildNode("StretchBendAngles");
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumStretchBends()); ii++) { for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumStretchBends()); ii++) {
int particle1, particle2, particle3; int particle1, particle2, particle3;
...@@ -56,10 +57,12 @@ void AmoebaStretchBendForceProxy::serialize(const void* object, SerializationNod ...@@ -56,10 +57,12 @@ void AmoebaStretchBendForceProxy::serialize(const void* object, SerializationNod
void* AmoebaStretchBendForceProxy::deserialize(const SerializationNode& node) const { void* AmoebaStretchBendForceProxy::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");
AmoebaStretchBendForce* force = new AmoebaStretchBendForce(); AmoebaStretchBendForce* force = new AmoebaStretchBendForce();
try { try {
if (version > 2)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
const SerializationNode& bonds = node.getChildNode("StretchBendAngles"); const SerializationNode& bonds = node.getChildNode("StretchBendAngles");
for (unsigned int ii = 0; ii < (int) bonds.getChildren().size(); ii++) { for (unsigned int ii = 0; ii < (int) bonds.getChildren().size(); ii++) {
const SerializationNode& bond = bonds.getChildren()[ii]; const SerializationNode& bond = bonds.getChildren()[ii];
......
...@@ -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 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -63,8 +63,9 @@ static void loadGrid(const SerializationNode& grid, std::vector< std::vector< st ...@@ -63,8 +63,9 @@ static void loadGrid(const SerializationNode& grid, std::vector< std::vector< st
} }
void AmoebaTorsionTorsionForceProxy::serialize(const void* object, SerializationNode& node) const { void AmoebaTorsionTorsionForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1); node.setIntProperty("version", 2);
const AmoebaTorsionTorsionForce& force = *reinterpret_cast<const AmoebaTorsionTorsionForce*>(object); const AmoebaTorsionTorsionForce& force = *reinterpret_cast<const AmoebaTorsionTorsionForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
// grid[xIdx][yIdx][6 values] // grid[xIdx][yIdx][6 values]
...@@ -116,12 +117,14 @@ void AmoebaTorsionTorsionForceProxy::serialize(const void* object, Serialization ...@@ -116,12 +117,14 @@ void AmoebaTorsionTorsionForceProxy::serialize(const void* object, Serialization
void* AmoebaTorsionTorsionForceProxy::deserialize(const SerializationNode& node) const { void* AmoebaTorsionTorsionForceProxy::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");
AmoebaTorsionTorsionForce* force = new AmoebaTorsionTorsionForce(); AmoebaTorsionTorsionForce* force = new AmoebaTorsionTorsionForce();
try { try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
const SerializationNode& grids = node.getChildNode("TorsionTorsionGrids"); const SerializationNode& grids = node.getChildNode("TorsionTorsionGrids");
const std::vector<SerializationNode>& gridList = grids.getChildren(); const std::vector<SerializationNode>& gridList = grids.getChildren();
for (unsigned int ii = 0; ii < gridList.size(); ii++) { for (unsigned int ii = 0; ii < gridList.size(); ii++) {
......
...@@ -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 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -42,9 +42,10 @@ AmoebaVdwForceProxy::AmoebaVdwForceProxy() : SerializationProxy("AmoebaVdwForce" ...@@ -42,9 +42,10 @@ AmoebaVdwForceProxy::AmoebaVdwForceProxy() : SerializationProxy("AmoebaVdwForce"
} }
void AmoebaVdwForceProxy::serialize(const void* object, SerializationNode& node) const { void AmoebaVdwForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1); node.setIntProperty("version", 2);
const AmoebaVdwForce& force = *reinterpret_cast<const AmoebaVdwForce*>(object); const AmoebaVdwForce& force = *reinterpret_cast<const AmoebaVdwForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setStringProperty("SigmaCombiningRule", force.getSigmaCombiningRule()); node.setStringProperty("SigmaCombiningRule", force.getSigmaCombiningRule());
node.setStringProperty("EpsilonCombiningRule", force.getEpsilonCombiningRule()); node.setStringProperty("EpsilonCombiningRule", force.getEpsilonCombiningRule());
node.setDoubleProperty("VdwCutoff", force.getCutoff()); node.setDoubleProperty("VdwCutoff", force.getCutoff());
...@@ -72,11 +73,13 @@ void AmoebaVdwForceProxy::serialize(const void* object, SerializationNode& node) ...@@ -72,11 +73,13 @@ void AmoebaVdwForceProxy::serialize(const void* object, SerializationNode& node)
} }
void* AmoebaVdwForceProxy::deserialize(const SerializationNode& node) const { void* AmoebaVdwForceProxy::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");
AmoebaVdwForce* force = new AmoebaVdwForce(); AmoebaVdwForce* force = new AmoebaVdwForce();
try { try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setSigmaCombiningRule(node.getStringProperty("SigmaCombiningRule")); force->setSigmaCombiningRule(node.getStringProperty("SigmaCombiningRule"));
force->setEpsilonCombiningRule(node.getStringProperty("EpsilonCombiningRule")); force->setEpsilonCombiningRule(node.getStringProperty("EpsilonCombiningRule"));
force->setCutoff(node.getDoubleProperty("VdwCutoff")); force->setCutoff(node.getDoubleProperty("VdwCutoff"));
......
...@@ -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 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -42,8 +42,9 @@ AmoebaWcaDispersionForceProxy::AmoebaWcaDispersionForceProxy() : SerializationPr ...@@ -42,8 +42,9 @@ AmoebaWcaDispersionForceProxy::AmoebaWcaDispersionForceProxy() : SerializationPr
} }
void AmoebaWcaDispersionForceProxy::serialize(const void* object, SerializationNode& node) const { void AmoebaWcaDispersionForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1); 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.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());
...@@ -63,12 +64,14 @@ void AmoebaWcaDispersionForceProxy::serialize(const void* object, SerializationN ...@@ -63,12 +64,14 @@ void AmoebaWcaDispersionForceProxy::serialize(const void* object, SerializationN
} }
void* AmoebaWcaDispersionForceProxy::deserialize(const SerializationNode& node) const { void* AmoebaWcaDispersionForceProxy::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");
AmoebaWcaDispersionForce* force = new AmoebaWcaDispersionForce(); AmoebaWcaDispersionForce* force = new AmoebaWcaDispersionForce();
try { try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
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"));
......
...@@ -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 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -45,6 +45,7 @@ void testSerialization() { ...@@ -45,6 +45,7 @@ void testSerialization() {
// Create a Force. // Create a Force.
AmoebaAngleForce force1; AmoebaAngleForce force1;
force1.setForceGroup(3);
force1.setAmoebaGlobalAngleCubic(12.3); force1.setAmoebaGlobalAngleCubic(12.3);
force1.setAmoebaGlobalAngleQuartic(98.7); force1.setAmoebaGlobalAngleQuartic(98.7);
force1.setAmoebaGlobalAnglePentic(91.7); force1.setAmoebaGlobalAnglePentic(91.7);
...@@ -62,6 +63,7 @@ void testSerialization() { ...@@ -62,6 +63,7 @@ void testSerialization() {
// Compare the two forces to see if they are identical. // Compare the two forces to see if they are identical.
AmoebaAngleForce& force2 = *copy; AmoebaAngleForce& force2 = *copy;
ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup());
ASSERT_EQUAL(force1.getAmoebaGlobalAngleCubic(), force2.getAmoebaGlobalAngleCubic()); ASSERT_EQUAL(force1.getAmoebaGlobalAngleCubic(), force2.getAmoebaGlobalAngleCubic());
ASSERT_EQUAL(force1.getAmoebaGlobalAngleQuartic(), force2.getAmoebaGlobalAngleQuartic()); ASSERT_EQUAL(force1.getAmoebaGlobalAngleQuartic(), force2.getAmoebaGlobalAngleQuartic());
ASSERT_EQUAL(force1.getAmoebaGlobalAnglePentic(), force2.getAmoebaGlobalAnglePentic()); ASSERT_EQUAL(force1.getAmoebaGlobalAnglePentic(), force2.getAmoebaGlobalAnglePentic());
......
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