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 @@
 
 
using namespace OpenMM;
using namespace std;
const double TOL = 1e-4;
 
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
 
static void setupMultipoleAmmonia(System& system, AmoebaGeneralizedKirkwoodForce* amoebaGeneralizedKirkwoodForce,
......@@ -289,6 +315,10 @@ static void getForcesEnergyMultipoleAmmonia(Context& context, std::vector<Vec3>&
State state = context.getState(State::Forces | State::Energy);
forces = state.getForces();
energy = state.getPotentialEnergy();
// Check that the forces and energy are consistent.
checkFiniteDifferences(forces, context, positions);
}
 
// setup for villin
......@@ -6972,6 +7002,10 @@ static void setupAndGetForcesEnergyMultipoleVillin(AmoebaMultipoleForce::Polariz
State state = context.getState(State::Forces | State::Energy);
forces = state.getForces();
energy = state.getPotentialEnergy();
// Check that the forces and energy are consistent.
checkFiniteDifferences(forces, context, positions);
}
 
// compare forces and energies
......@@ -7049,6 +7083,25 @@ static void testGeneralizedKirkwoodAmmoniaDirectPolarization() {
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
 
static void testGeneralizedKirkwoodAmmoniaMutualPolarization() {
......@@ -7765,6 +7818,19 @@ static void testGeneralizedKirkwoodVillinDirectPolarization() {
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
 
static void testGeneralizedKirkwoodVillinMutualPolarization() {
......@@ -8401,9 +8467,10 @@ int main(int argc, char* argv[]) {
 
testGeneralizedKirkwoodAmmoniaDirectPolarization();
testGeneralizedKirkwoodAmmoniaMutualPolarization();
testGeneralizedKirkwoodAmmoniaExtrapolatedPolarization();
testGeneralizedKirkwoodAmmoniaMutualPolarizationWithCavityTerm();
testGeneralizedKirkwoodVillinDirectPolarization();
testGeneralizedKirkwoodVillinExtrapolatedPolarization();
testGeneralizedKirkwoodVillinMutualPolarization();
 
} catch(const std::exception& e) {
......
......@@ -565,6 +565,8 @@ void ReferenceCalcAmoebaMultipoleForceKernel::initialize(const System& system, c
if (polarizationType == AmoebaMultipoleForce::Mutual) {
mutualInducedMaxIterations = force.getMutualInducedMaxIterations();
mutualInducedTargetEpsilon = force.getMutualInducedTargetEpsilon();
} else if (polarizationType == AmoebaMultipoleForce::Extrapolated) {
extrapolationCoefficients = force.getExtrapolationCoefficients();
}
// PME
......@@ -667,6 +669,9 @@ AmoebaReferenceMultipoleForce* ReferenceCalcAmoebaMultipoleForceKernel::setupAmo
amoebaReferenceMultipoleForce->setMaximumMutualInducedDipoleIterations(mutualInducedMaxIterations);
} else if (polarizationType == AmoebaMultipoleForce::Direct) {
amoebaReferenceMultipoleForce->setPolarizationType(AmoebaReferenceMultipoleForce::Direct);
} else if (polarizationType == AmoebaMultipoleForce::Extrapolated) {
amoebaReferenceMultipoleForce->setPolarizationType(AmoebaReferenceMultipoleForce::Extrapolated);
amoebaReferenceMultipoleForce->setExtrapolationCoefficients(extrapolationCoefficients);
} else {
throw OpenMMException("Polarization type not recognzied.");
}
......
......@@ -432,6 +432,7 @@ private:
int mutualInducedMaxIterations;
RealOpenMM mutualInducedTargetEpsilon;
std::vector<double> extrapolationCoefficients;
bool usePme;
RealOpenMM alphaEwald;
......
......@@ -345,11 +345,16 @@ public:
*/
Mutual = 0,
/**
/**
* Direct polarization
*/
Direct = 1
};
Direct = 1,
/**
* Extrapolated perturbation theory
*/
Extrapolated = 2
};
/**
* Constructor
......@@ -422,6 +427,15 @@ public:
*/
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.
*
......@@ -624,10 +638,13 @@ protected:
* Helper class used in calculating induced dipoles
*/
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>* inducedDipoles;
std::vector<std::vector<RealVec> >* extrapolatedDipoles;
std::vector<std::vector<RealOpenMM> >* extrapolatedDipoleFieldGradient;
std::vector<OpenMM::RealVec> inducedDipoleField;
std::vector<std::vector<RealOpenMM> > inducedDipoleFieldGradient;
};
unsigned int _numParticles;
......@@ -651,10 +668,17 @@ protected:
std::vector<RealVec> _fixedMultipoleFieldPolar;
std::vector<RealVec> _inducedDipole;
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 _mutualInducedDipoleIterations;
int _maximumMutualInducedDipoleIterations;
int _maxPTOrder;
std::vector<RealOpenMM> _extrapolationCoefficients;
std::vector<RealOpenMM> _extPartCoefficients;
RealOpenMM _mutualInducedDipoleEpsilon;
RealOpenMM _mutualInducedDipoleTargetEpsilon;
RealOpenMM _polarSOR;
......@@ -904,7 +928,7 @@ protected:
/**
* Calculate fields due induced dipoles at each site.
*
*
* @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 updateInducedDipoleFields vector of UpdateInducedDipoleFieldStruct containing input induced dipoles and output fields
......@@ -920,6 +944,14 @@ protected:
*/
virtual void calculateInducedDipoleFields(const std::vector<MultipoleParticleData>& particleData,
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.
*
......@@ -1191,6 +1223,10 @@ private:
std::vector<RealVec> _gkField;
std::vector<RealVec> _inducedDipoleS;
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;
RealOpenMM _probeRadius;
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -50,11 +50,36 @@
 
 
using namespace OpenMM;
using namespace std;
 
extern "C" OPENMM_EXPORT void registerAmoebaReferenceKernelFactories();
 
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
 
static void setupMultipoleAmmonia(System& system, AmoebaGeneralizedKirkwoodForce* amoebaGeneralizedKirkwoodForce,
......@@ -291,6 +316,10 @@ static void getForcesEnergyMultipoleAmmonia(Context& context, std::vector<Vec3>&
State state = context.getState(State::Forces | State::Energy);
forces = state.getForces();
energy = state.getPotentialEnergy();
// Check that the forces and energy are consistent.
checkFiniteDifferences(forces, context, positions);
}
 
// setup for villin
......@@ -6974,6 +7003,10 @@ static void setupAndGetForcesEnergyMultipoleVillin(AmoebaMultipoleForce::Polariz
State state = context.getState(State::Forces | State::Energy);
forces = state.getForces();
energy = state.getPotentialEnergy();
// Check that the forces and energy are consistent.
checkFiniteDifferences(forces, context, positions);
}
 
// compare forces and energies
......@@ -7052,6 +7085,25 @@ static void testGeneralizedKirkwoodAmmoniaDirectPolarization() {
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
 
static void testGeneralizedKirkwoodAmmoniaMutualPolarization() {
......@@ -7770,6 +7822,19 @@ static void testGeneralizedKirkwoodVillinDirectPolarization() {
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
 
static void testGeneralizedKirkwoodVillinMutualPolarization() {
......@@ -8405,8 +8470,10 @@ int main(int numberOfArguments, char* argv[]) {
 
testGeneralizedKirkwoodAmmoniaMutualPolarization();
testGeneralizedKirkwoodAmmoniaDirectPolarization();
testGeneralizedKirkwoodAmmoniaExtrapolatedPolarization();
testGeneralizedKirkwoodAmmoniaMutualPolarizationWithCavityTerm();
testGeneralizedKirkwoodVillinDirectPolarization();
testGeneralizedKirkwoodVillinExtrapolatedPolarization();
testGeneralizedKirkwoodVillinMutualPolarization();
 
}
......
......@@ -6,7 +6,7 @@
* 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. *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -42,10 +42,11 @@ AmoebaAngleForceProxy::AmoebaAngleForceProxy() : SerializationProxy("AmoebaAngle
}
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);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setDoubleProperty("cubic", force.getAmoebaGlobalAngleCubic());
node.setDoubleProperty("quartic", force.getAmoebaGlobalAngleQuartic());
node.setDoubleProperty("pentic", force.getAmoebaGlobalAnglePentic());
......@@ -61,11 +62,13 @@ void AmoebaAngleForceProxy::serialize(const void* object, SerializationNode& nod
}
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");
AmoebaAngleForce* force = new AmoebaAngleForce();
try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setAmoebaGlobalAngleCubic(node.getDoubleProperty("cubic"));
force->setAmoebaGlobalAngleQuartic(node.getDoubleProperty("quartic"));
force->setAmoebaGlobalAnglePentic(node.getDoubleProperty("pentic"));
......
......@@ -6,7 +6,7 @@
* 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. *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -42,9 +42,10 @@ AmoebaBondForceProxy::AmoebaBondForceProxy() : SerializationProxy("AmoebaBondFor
}
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);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setDoubleProperty("cubic", force.getAmoebaGlobalBondCubic());
node.setDoubleProperty("quartic", force.getAmoebaGlobalBondQuartic());
......@@ -58,10 +59,13 @@ void AmoebaBondForceProxy::serialize(const void* object, SerializationNode& node
}
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");
AmoebaBondForce* force = new AmoebaBondForce();
try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setAmoebaGlobalBondCubic(node.getDoubleProperty("cubic"));
force->setAmoebaGlobalBondQuartic(node.getDoubleProperty("quartic"));
const SerializationNode& bonds = node.getChildNode("Bonds");
......
......@@ -6,7 +6,7 @@
* 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. *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -42,9 +42,10 @@ AmoebaGeneralizedKirkwoodForceProxy::AmoebaGeneralizedKirkwoodForceProxy() : Ser
}
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);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setDoubleProperty("GeneralizedKirkwoodSolventDielectric", force.getSolventDielectric());
node.setDoubleProperty("GeneralizedKirkwoodSoluteDielectric", force.getSoluteDielectric());
//node.setDoubleProperty("GeneralizedKirkwoodDielectricOffset", force.getDielectricOffset());
......@@ -62,11 +63,13 @@ void AmoebaGeneralizedKirkwoodForceProxy::serialize(const void* object, Serializ
}
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");
AmoebaGeneralizedKirkwoodForce* force = new AmoebaGeneralizedKirkwoodForce();
try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setSolventDielectric( node.getDoubleProperty("GeneralizedKirkwoodSolventDielectric"));
force->setSoluteDielectric( node.getDoubleProperty("GeneralizedKirkwoodSoluteDielectric"));
//force->setDielectricOffset( node.getDoubleProperty("GeneralizedKirkwoodDielectricOffset"));
......
......@@ -6,7 +6,7 @@
* 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. *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -43,9 +43,10 @@ AmoebaInPlaneAngleForceProxy::AmoebaInPlaneAngleForceProxy() : SerializationProx
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);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setDoubleProperty("cubic", force.getAmoebaGlobalInPlaneAngleCubic());
node.setDoubleProperty("quartic", force.getAmoebaGlobalInPlaneAngleQuartic());
node.setDoubleProperty("pentic", force.getAmoebaGlobalInPlaneAnglePentic());
......@@ -61,11 +62,13 @@ void AmoebaInPlaneAngleForceProxy::serialize(const void* object, SerializationNo
}
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");
AmoebaInPlaneAngleForce* force = new AmoebaInPlaneAngleForce();
try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setAmoebaGlobalInPlaneAngleCubic( node.getDoubleProperty("cubic"));
force->setAmoebaGlobalInPlaneAngleQuartic(node.getDoubleProperty("quartic"));
force->setAmoebaGlobalInPlaneAnglePentic(node.getDoubleProperty("pentic"));
......
......@@ -6,7 +6,7 @@
* 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. *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -68,9 +68,10 @@ void loadCovalentMap(const SerializationNode& map, std::vector< int >& covalentM
}
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);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setIntProperty("nonbondedMethod", force.getNonbondedMethod());
node.setIntProperty("polarizationType", force.getPolarizationType());
//node.setIntProperty("pmeBSplineOrder", force.getPmeBSplineOrder());
......@@ -87,6 +88,14 @@ void AmoebaMultipoleForceProxy::serialize(const void* object, SerializationNode&
force.getPmeGridDimensions(gridDimensions);
SerializationNode& gridDimensionsNode = node.createChildNode("MultipoleParticleGridDimension");
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;
getCovalentTypes(covalentTypes);
......@@ -124,16 +133,17 @@ void AmoebaMultipoleForceProxy::serialize(const void* object, SerializationNode&
}
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");
AmoebaMultipoleForce* force = new AmoebaMultipoleForce();
try {
if (version > 3)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
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->setPmeBSplineOrder(node.getIntProperty("pmeBSplineOrder"));
//force->setMutualInducedIterationMethod(static_cast<AmoebaMultipoleForce::MutualInducedIterationMethod>(node.getIntProperty("mutualInducedIterationMethod")));
force->setMutualInducedMaxIterations(node.getIntProperty("mutualInducedMaxIterations"));
......@@ -151,6 +161,18 @@ void* AmoebaMultipoleForceProxy::deserialize(const SerializationNode& node) cons
gridDimensions.push_back(gridDimensionsNode.getIntProperty("d2"));
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;
getCovalentTypes(covalentTypes);
......
......@@ -6,7 +6,7 @@
* 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. *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -42,8 +42,9 @@ AmoebaOutOfPlaneBendForceProxy::AmoebaOutOfPlaneBendForceProxy() : Serialization
}
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);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setDoubleProperty("cubic", force.getAmoebaGlobalOutOfPlaneBendCubic());
node.setDoubleProperty("quartic", force.getAmoebaGlobalOutOfPlaneBendQuartic());
node.setDoubleProperty("pentic", force.getAmoebaGlobalOutOfPlaneBendPentic());
......@@ -59,11 +60,13 @@ void AmoebaOutOfPlaneBendForceProxy::serialize(const void* object, Serialization
}
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");
AmoebaOutOfPlaneBendForce* force = new AmoebaOutOfPlaneBendForce();
try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setAmoebaGlobalOutOfPlaneBendCubic(node.getDoubleProperty("cubic"));
force->setAmoebaGlobalOutOfPlaneBendQuartic(node.getDoubleProperty("quartic"));
force->setAmoebaGlobalOutOfPlaneBendPentic(node.getDoubleProperty("pentic"));
......
......@@ -6,7 +6,7 @@
* 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. *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -42,8 +42,9 @@ AmoebaPiTorsionForceProxy::AmoebaPiTorsionForceProxy() : SerializationProxy("Amo
}
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);
node.setIntProperty("forceGroup", force.getForceGroup());
SerializationNode& bonds = node.createChildNode("PiTorsion");
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumPiTorsions()); ii++) {
int particle1, particle2, particle3, particle4, particle5, particle6;
......@@ -54,10 +55,13 @@ void AmoebaPiTorsionForceProxy::serialize(const void* object, SerializationNode&
}
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");
AmoebaPiTorsionForce* force = new AmoebaPiTorsionForce();
try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
const SerializationNode& bonds = node.getChildNode("PiTorsion");
for (unsigned int ii = 0; ii < bonds.getChildren().size(); ii++) {
const SerializationNode& bond = bonds.getChildren()[ii];
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* 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 *
* Contributors: *
* *
......@@ -42,8 +42,9 @@ AmoebaStretchBendForceProxy::AmoebaStretchBendForceProxy() : SerializationProxy(
}
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);
node.setIntProperty("forceGroup", force.getForceGroup());
SerializationNode& bonds = node.createChildNode("StretchBendAngles");
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumStretchBends()); ii++) {
int particle1, particle2, particle3;
......@@ -56,10 +57,12 @@ void AmoebaStretchBendForceProxy::serialize(const void* object, SerializationNod
void* AmoebaStretchBendForceProxy::deserialize(const SerializationNode& node) const {
int version = node.getIntProperty("version");
if (version != 1 && version != 2)
if (version < 1 || version > 3)
throw OpenMMException("Unsupported version number");
AmoebaStretchBendForce* force = new AmoebaStretchBendForce();
try {
if (version > 2)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
const SerializationNode& bonds = node.getChildNode("StretchBendAngles");
for (unsigned int ii = 0; ii < (int) bonds.getChildren().size(); ii++) {
const SerializationNode& bond = bonds.getChildren()[ii];
......
......@@ -6,7 +6,7 @@
* 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. *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -63,8 +63,9 @@ static void loadGrid(const SerializationNode& grid, std::vector< std::vector< st
}
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);
node.setIntProperty("forceGroup", force.getForceGroup());
// grid[xIdx][yIdx][6 values]
......@@ -116,12 +117,14 @@ void AmoebaTorsionTorsionForceProxy::serialize(const void* object, Serialization
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");
AmoebaTorsionTorsionForce* force = new AmoebaTorsionTorsionForce();
try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
const SerializationNode& grids = node.getChildNode("TorsionTorsionGrids");
const std::vector<SerializationNode>& gridList = grids.getChildren();
for (unsigned int ii = 0; ii < gridList.size(); ii++) {
......
......@@ -6,7 +6,7 @@
* 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. *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -42,9 +42,10 @@ AmoebaVdwForceProxy::AmoebaVdwForceProxy() : SerializationProxy("AmoebaVdwForce"
}
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);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setStringProperty("SigmaCombiningRule", force.getSigmaCombiningRule());
node.setStringProperty("EpsilonCombiningRule", force.getEpsilonCombiningRule());
node.setDoubleProperty("VdwCutoff", force.getCutoff());
......@@ -72,11 +73,13 @@ void AmoebaVdwForceProxy::serialize(const void* object, SerializationNode& node)
}
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");
AmoebaVdwForce* force = new AmoebaVdwForce();
try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setSigmaCombiningRule(node.getStringProperty("SigmaCombiningRule"));
force->setEpsilonCombiningRule(node.getStringProperty("EpsilonCombiningRule"));
force->setCutoff(node.getDoubleProperty("VdwCutoff"));
......
......@@ -6,7 +6,7 @@
* 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. *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -42,8 +42,9 @@ AmoebaWcaDispersionForceProxy::AmoebaWcaDispersionForceProxy() : SerializationPr
}
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);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setDoubleProperty("Epso", force.getEpso());
node.setDoubleProperty("Epsh", force.getEpsh());
node.setDoubleProperty("Rmino", force.getRmino());
......@@ -63,12 +64,14 @@ void AmoebaWcaDispersionForceProxy::serialize(const void* object, SerializationN
}
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");
AmoebaWcaDispersionForce* force = new AmoebaWcaDispersionForce();
try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
force->setEpso( node.getDoubleProperty("Epso"));
force->setEpsh( node.getDoubleProperty("Epsh"));
force->setRmino( node.getDoubleProperty("Rmino"));
......
......@@ -6,7 +6,7 @@
* 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. *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -45,6 +45,7 @@ void testSerialization() {
// Create a Force.
AmoebaAngleForce force1;
force1.setForceGroup(3);
force1.setAmoebaGlobalAngleCubic(12.3);
force1.setAmoebaGlobalAngleQuartic(98.7);
force1.setAmoebaGlobalAnglePentic(91.7);
......@@ -62,6 +63,7 @@ void testSerialization() {
// Compare the two forces to see if they are identical.
AmoebaAngleForce& force2 = *copy;
ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup());
ASSERT_EQUAL(force1.getAmoebaGlobalAngleCubic(), force2.getAmoebaGlobalAngleCubic());
ASSERT_EQUAL(force1.getAmoebaGlobalAngleQuartic(), force2.getAmoebaGlobalAngleQuartic());
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