Unverified Commit 1e42b8be authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Replaced several AMOEBA bonded forces with custom forces (#3046)

* Replaced several AMOEBA bonded forces with custom forces

* Deleted obsolete AMOEBA forces

* Replaced AmoebaPiTorsionForce with custom force
parent 014797f4
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
/**
* This tests the Reference implementation of ReferenceAmoebaOutOfPlaneBendForce.
*/
#include "openmm/internal/AssertionUtilities.h"
//#include "AmoebaTinkerParameterFile.h"
#include "openmm/Context.h"
#include "OpenMMAmoeba.h"
#include "openmm/System.h"
#include "openmm/LangevinIntegrator.h"
#include "SimTKOpenMMRealType.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
extern "C" OPENMM_EXPORT void registerAmoebaReferenceKernelFactories();
const double TOL = 1e-3;
/* ---------------------------------------------------------------------------------------
Compute cross product of two 3-vectors and place in 3rd vector
vectorZ = vectorX x vectorY
@param vectorX x-vector
@param vectorY y-vector
@param vectorZ z-vector
@return vector is vectorZ
--------------------------------------------------------------------------------------- */
static void crossProductVector3(double* vectorX, double* vectorY, double* vectorZ) {
vectorZ[0] = vectorX[1]*vectorY[2] - vectorX[2]*vectorY[1];
vectorZ[1] = vectorX[2]*vectorY[0] - vectorX[0]*vectorY[2];
vectorZ[2] = vectorX[0]*vectorY[1] - vectorX[1]*vectorY[0];
return;
}
static double dotVector3(double* vectorX, double* vectorY) {
return vectorX[0]*vectorY[0] + vectorX[1]*vectorY[1] + vectorX[2]*vectorY[2];
}
static void computeAmoebaOutOfPlaneBendForce(int bondIndex, std::vector<Vec3>& positions, AmoebaOutOfPlaneBendForce& amoebaOutOfPlaneBendForce,
std::vector<Vec3>& forces, double* energy) {
double kAngleCubic = amoebaOutOfPlaneBendForce.getAmoebaGlobalOutOfPlaneBendCubic();
double kAngleQuartic = amoebaOutOfPlaneBendForce.getAmoebaGlobalOutOfPlaneBendQuartic();
double kAnglePentic = amoebaOutOfPlaneBendForce.getAmoebaGlobalOutOfPlaneBendPentic();
double kAngleSextic = amoebaOutOfPlaneBendForce.getAmoebaGlobalOutOfPlaneBendSextic();
int particle1, particle2, particle3, particle4;
double kAngleQuadratic;
amoebaOutOfPlaneBendForce.getOutOfPlaneBendParameters(bondIndex, particle1, particle2, particle3, particle4, kAngleQuadratic);
enum { A, B, C, D, LastAtomIndex };
enum { AB, CB, DB, AD, CD, LastDeltaIndex };
// ---------------------------------------------------------------------------------------
// get deltaR between various combinations of the 4 atoms
// and various intermediate terms
double deltaR[LastDeltaIndex][6];
for (int ii = 0; ii < 3; ii++) {
deltaR[AB][ii] = positions[particle1][ii] - positions[particle2][ii];
deltaR[CB][ii] = positions[particle3][ii] - positions[particle2][ii];
deltaR[DB][ii] = positions[particle4][ii] - positions[particle2][ii];
deltaR[AD][ii] = positions[particle1][ii] - positions[particle4][ii];
deltaR[CD][ii] = positions[particle3][ii] - positions[particle4][ii];
}
double rDB2 = dotVector3(deltaR[DB], deltaR[DB]);
double rAD2 = dotVector3(deltaR[AD], deltaR[AD]);
double rCD2 = dotVector3(deltaR[CD], deltaR[CD]);
double tempVector[3];
crossProductVector3(deltaR[CB], deltaR[DB], tempVector);
double eE = dotVector3(deltaR[AB], tempVector);
double dot = dotVector3(deltaR[AD], deltaR[CD]);
double cc = rAD2*rCD2 - dot*dot;
if (rDB2 <= 0.0 || cc == 0.0) {
return;
}
double bkk2 = rDB2 - eE*eE/cc;
double cosine = sqrt(bkk2/rDB2);
double angle;
if (cosine >= 1.0) {
angle = 0.0;
}
else if (cosine <= -1.0) {
angle = PI_M;
}
else {
angle = RADIAN*acos(cosine);
}
// chain rule
double dt = angle;
double dt2 = dt*dt;
double dt3 = dt2*dt;
double dt4 = dt2*dt2;
double dEdDt = 2.0 + 3.0*kAngleCubic*dt + 4.0*kAngleQuartic*dt2 + 5.0*kAnglePentic *dt3 + 6.0*kAngleSextic *dt4;
dEdDt *= kAngleQuadratic*dt*RADIAN;
double dEdCos;
dEdCos = dEdDt/sqrt(cc*bkk2);
if (eE > 0.0) {
dEdCos *= -1.0;
}
double term = eE/cc;
double dccd[LastAtomIndex][3];
for (int ii = 0; ii < 3; ii++) {
dccd[A][ii] = (deltaR[AD][ii]*rCD2 - deltaR[CD][ii]*dot)*term;
dccd[C][ii] = (deltaR[CD][ii]*rAD2 - deltaR[AD][ii]*dot)*term;
dccd[D][ii] = -1.0*(dccd[A][ii] + dccd[C][ii]);
}
double deed[LastAtomIndex][3];
crossProductVector3(deltaR[DB], deltaR[CB], deed[A]);
crossProductVector3(deltaR[AB], deltaR[DB], deed[C]);
crossProductVector3(deltaR[CB], deltaR[AB], deed[D]);
term = eE/rDB2;
deed[D][0] += deltaR[DB][0]*term;
deed[D][1] += deltaR[DB][1]*term;
deed[D][2] += deltaR[DB][2]*term;
// ---------------------------------------------------------------------------------------
// forces
// calculate forces for atoms a, c, d
// the force for b is then -(a+ c + d)
double subForce[LastAtomIndex][3];
for (int jj = 0; jj < LastAtomIndex; jj++) {
// A, C, D
for (int ii = 0; ii < 3; ii++) {
subForce[jj][ii] = dEdCos*(dccd[jj][ii] + deed[jj][ii]);
}
if (jj == 0)jj++; // skip B
// now compute B
if (jj == 3) {
for (int ii = 0; ii < 3; ii++) {
subForce[1][ii] = -1.0*(subForce[0][ii] + subForce[2][ii] + subForce[3][ii]);
}
}
}
// accumulate forces and energy
forces[particle1][0] -= subForce[0][0];
forces[particle1][1] -= subForce[0][1];
forces[particle1][2] -= subForce[0][2];
forces[particle2][0] -= subForce[1][0];
forces[particle2][1] -= subForce[1][1];
forces[particle2][2] -= subForce[1][2];
forces[particle3][0] -= subForce[2][0];
forces[particle3][1] -= subForce[2][1];
forces[particle3][2] -= subForce[2][2];
forces[particle4][0] -= subForce[3][0];
forces[particle4][1] -= subForce[3][1];
forces[particle4][2] -= subForce[3][2];
// ---------------------------------------------------------------------------------------
// calculate energy if 'energy' is set
double energyTerm = 1.0 + kAngleCubic *dt +
kAngleQuartic*dt2 +
kAnglePentic *dt3 +
kAngleSextic *dt4;
energyTerm *= kAngleQuadratic*dt2;
*energy += energyTerm;
return;
}
static void computeAmoebaOutOfPlaneBendForces(Context& context, AmoebaOutOfPlaneBendForce& amoebaOutOfPlaneBendForce,
std::vector<Vec3>& expectedForces, double* expectedEnergy) {
// get positions and zero forces
State state = context.getState(State::Positions);
std::vector<Vec3> positions = state.getPositions();
expectedForces.resize(positions.size());
for (unsigned int ii = 0; ii < expectedForces.size(); ii++) {
expectedForces[ii][0] = expectedForces[ii][1] = expectedForces[ii][2] = 0.0;
}
// calculates forces/energy
*expectedEnergy = 0.0;
for (int ii = 0; ii < amoebaOutOfPlaneBendForce.getNumOutOfPlaneBends(); ii++) {
computeAmoebaOutOfPlaneBendForce(ii, positions, amoebaOutOfPlaneBendForce, expectedForces, expectedEnergy);
}
}
void compareWithExpectedForceAndEnergy(Context& context, AmoebaOutOfPlaneBendForce& amoebaOutOfPlaneBendForce,
double tolerance, const std::string& idString) {
std::vector<Vec3> expectedForces;
double expectedEnergy;
computeAmoebaOutOfPlaneBendForces(context, amoebaOutOfPlaneBendForce, expectedForces, &expectedEnergy);
State state = context.getState(State::Forces | State::Energy);
const std::vector<Vec3> forces = state.getForces();
for (unsigned int ii = 0; ii < forces.size(); ii++) {
ASSERT_EQUAL_VEC(expectedForces[ii], forces[ii], tolerance);
}
ASSERT_EQUAL_TOL(expectedEnergy, state.getPotentialEnergy(), tolerance);
}
void testOneOutOfPlaneBend() {
System system;
int numberOfParticles = 4;
for (int ii = 0; ii < numberOfParticles; ii++) {
system.addParticle(1.0);
}
LangevinIntegrator integrator(0.0, 0.1, 0.01);
AmoebaOutOfPlaneBendForce* amoebaOutOfPlaneBendForce = new AmoebaOutOfPlaneBendForce();
amoebaOutOfPlaneBendForce->setAmoebaGlobalOutOfPlaneBendCubic( -0.1400000E-01);
amoebaOutOfPlaneBendForce->setAmoebaGlobalOutOfPlaneBendQuartic(0.5600000E-04);
amoebaOutOfPlaneBendForce->setAmoebaGlobalOutOfPlaneBendPentic(-0.7000000E-06);
amoebaOutOfPlaneBendForce->setAmoebaGlobalOutOfPlaneBendSextic( 0.2200000E-07);
double kOutOfPlaneBend = 0.328682196E-01;
amoebaOutOfPlaneBendForce->addOutOfPlaneBend(0, 1, 2, 3, kOutOfPlaneBend);
system.addForce(amoebaOutOfPlaneBendForce);
ASSERT(!amoebaOutOfPlaneBendForce->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, Platform::getPlatformByName("Reference"));
std::vector<Vec3> positions(numberOfParticles);
positions[0] = Vec3(0.262660000E+02, 0.254130000E+02, 0.284200000E+01);
positions[1] = Vec3(0.269130000E+02, 0.266390000E+02, 0.353100000E+01);
positions[2] = Vec3(0.278860000E+02, 0.264630000E+02, 0.426300000E+01);
positions[3] = Vec3(0.245568230E+02, 0.250215290E+02, 0.796852800E+01);
context.setPositions(positions);
compareWithExpectedForceAndEnergy(context, *amoebaOutOfPlaneBendForce, TOL, "testOneOutOfPlaneBend");
// Try changing the bend parameters and make sure it's still correct.
amoebaOutOfPlaneBendForce->setOutOfPlaneBendParameters(0, 0, 1, 2, 3, 1.1*kOutOfPlaneBend);
bool exceptionThrown = false;
try {
// This should throw an exception.
compareWithExpectedForceAndEnergy(context, *amoebaOutOfPlaneBendForce, TOL, "testOneOutOfPlaneBend");
}
catch (std::exception ex) {
exceptionThrown = true;
}
ASSERT(exceptionThrown);
amoebaOutOfPlaneBendForce->updateParametersInContext(context);
compareWithExpectedForceAndEnergy(context, *amoebaOutOfPlaneBendForce, TOL, "testOneOutOfPlaneBend");
}
void testOneOutOfPlaneBend2(int setId) {
System system;
int numberOfParticles = 4;
for (int ii = 0; ii < numberOfParticles; ii++) {
system.addParticle(1.0);
}
LangevinIntegrator integrator(0.0, 0.1, 0.01);
AmoebaOutOfPlaneBendForce* amoebaOutOfPlaneBendForce = new AmoebaOutOfPlaneBendForce();
amoebaOutOfPlaneBendForce->setAmoebaGlobalOutOfPlaneBendCubic( -0.1400000E-01);
amoebaOutOfPlaneBendForce->setAmoebaGlobalOutOfPlaneBendQuartic(0.5600000E-04);
amoebaOutOfPlaneBendForce->setAmoebaGlobalOutOfPlaneBendPentic(-0.7000000E-06);
amoebaOutOfPlaneBendForce->setAmoebaGlobalOutOfPlaneBendSextic( 0.2200000E-07);
/*
285 441 442 443 444 0.328682196E-01
286 441 442 444 443 0.164493407E-01
287 443 442 444 441 0.636650407E-02
288 442 444 447 448 0.392956472E-02
289 442 444 448 447 0.392956472E-02
290 447 444 448 442 0.214755281E-01
441 0.893800000E+01 0.439800000E+01 0.343100000E+01
442 0.779100000E+01 0.614600000E+01 0.390100000E+01
443 0.915400000E+01 0.683900000E+01 0.389400000E+01
444 0.101770000E+02 0.619000000E+01 0.379900000E+01
445 0.921000000E+01 0.813800000E+01 0.398600000E+01
446 0.708500000E+01 0.672900000E+01 0.332700000E+01
447 0.744300000E+01 0.605200000E+01 0.491900000E+01
448 0.100820000E+02 0.859300000E+01 0.398200000E+01
449 0.838000000E+01 0.866100000E+01 0.406000000E+01
*/
std::map<int,Vec3> coordinates;
coordinates[440] = Vec3(0.893800000E+01, 0.439800000E+01, 0.343100000E+01);
coordinates[441] = Vec3(0.779100000E+01, 0.614600000E+01, 0.390100000E+01);
coordinates[442] = Vec3(0.915400000E+01, 0.683900000E+01, 0.389400000E+01);
coordinates[443] = Vec3(0.101770000E+02, 0.619000000E+01, 0.379900000E+01);
coordinates[444] = Vec3(0.921000000E+01, 0.813800000E+01, 0.398600000E+01);
coordinates[445] = Vec3(0.708500000E+01, 0.672900000E+01, 0.332700000E+01);
coordinates[446] = Vec3(0.744300000E+01, 0.605200000E+01, 0.491900000E+01);
coordinates[447] = Vec3(0.100820000E+02, 0.859300000E+01, 0.398200000E+01);
coordinates[448] = Vec3(0.838000000E+01, 0.866100000E+01, 0.406000000E+01);
double kOutOfPlaneBend = 0.328682196E-01;
std::vector<int> particleIndices;
if (setId == 1) {
particleIndices.push_back(441);
particleIndices.push_back(442);
particleIndices.push_back(443);
particleIndices.push_back(444);
kOutOfPlaneBend = 0.328682196E-01;
}
else if (setId == 2) {
particleIndices.push_back(441);
particleIndices.push_back(442);
particleIndices.push_back(444);
particleIndices.push_back(443);
kOutOfPlaneBend = 0.164493407E-01;
}
else if (setId == 3) {
particleIndices.push_back(443);
particleIndices.push_back(442);
particleIndices.push_back(444);
particleIndices.push_back(441);
kOutOfPlaneBend = 0.636650407E-02;
}
else if (setId == 4) {
particleIndices.push_back(442);
particleIndices.push_back(444);
particleIndices.push_back(447);
particleIndices.push_back(448);
kOutOfPlaneBend = 0.392956472E-02;
}
else if (setId == 5) {
particleIndices.push_back(442);
particleIndices.push_back(444);
particleIndices.push_back(448);
particleIndices.push_back(447);
kOutOfPlaneBend = 0.392956472E-02;
}
else if (setId == 6) {
particleIndices.push_back(447);
particleIndices.push_back(444);
particleIndices.push_back(448);
particleIndices.push_back(442);
kOutOfPlaneBend = 0.214755281E-01;
}
else {
std::stringstream buffer;
buffer << "Set id " << setId << " not recognized.";
throw OpenMMException(buffer.str());
}
amoebaOutOfPlaneBendForce->addOutOfPlaneBend(0, 1, 2, 3, kOutOfPlaneBend);
system.addForce(amoebaOutOfPlaneBendForce);
Context context(system, integrator, Platform::getPlatformByName("Reference"));
std::vector<Vec3> positions(numberOfParticles);
for (unsigned int ii = 0; ii < static_cast<unsigned int>(numberOfParticles); ii++) {
if (coordinates.find(particleIndices[ii]) == coordinates.end()) {
std::stringstream buffer;
buffer << "Coordinates " << particleIndices[ii] << " not loaded.";
throw OpenMMException(buffer.str());
}
positions[ii] = coordinates[particleIndices[ii]];
}
context.setPositions(positions);
compareWithExpectedForceAndEnergy(context, *amoebaOutOfPlaneBendForce, TOL, "testOneOutOfPlaneBend");
static int iter = 0;
static std::map<int,Vec3> totalForces;
static double totalEnergy;
if (iter == 0) {
totalForces[441] = Vec3(0.0, 0.0, 0.0);
totalForces[442] = Vec3(0.0, 0.0, 0.0);
totalForces[443] = Vec3(0.0, 0.0, 0.0);
totalForces[444] = Vec3(0.0, 0.0, 0.0);
totalForces[445] = Vec3(0.0, 0.0, 0.0);
totalForces[446] = Vec3(0.0, 0.0, 0.0);
totalForces[447] = Vec3(0.0, 0.0, 0.0);
totalForces[448] = Vec3(0.0, 0.0, 0.0);
totalForces[449] = Vec3(0.0, 0.0, 0.0);
totalEnergy = 0.0;
}
iter++;
std::vector<Vec3> forces;
forces.resize(numberOfParticles);
double energy;
computeAmoebaOutOfPlaneBendForce(0, positions, *amoebaOutOfPlaneBendForce, forces, &energy);
totalEnergy += energy;
for (unsigned int ii = 0; ii < static_cast<unsigned int>(numberOfParticles); ii++) {
for (unsigned int jj = 0; jj < 3; jj++) {
totalForces[particleIndices[ii]][jj] += forces[ii][jj];
}
}
}
void testPeriodic() {
// Create a force that uses periodic boundary conditions.
System system;
system.setDefaultPeriodicBoxVectors(Vec3(3, 0, 0), Vec3(0, 3, 0), Vec3(0, 0, 3));
int numberOfParticles = 4;
for (int ii = 0; ii < numberOfParticles; ii++)
system.addParticle(1.0);
LangevinIntegrator integrator(0.0, 0.1, 0.01);
AmoebaOutOfPlaneBendForce* amoebaOutOfPlaneBendForce = new AmoebaOutOfPlaneBendForce();
amoebaOutOfPlaneBendForce->setAmoebaGlobalOutOfPlaneBendCubic( -0.1400000E-01);
amoebaOutOfPlaneBendForce->setAmoebaGlobalOutOfPlaneBendQuartic(0.5600000E-04);
amoebaOutOfPlaneBendForce->setAmoebaGlobalOutOfPlaneBendPentic(-0.7000000E-06);
amoebaOutOfPlaneBendForce->setAmoebaGlobalOutOfPlaneBendSextic( 0.2200000E-07);
double kOutOfPlaneBend = 0.328682196E-01;
amoebaOutOfPlaneBendForce->addOutOfPlaneBend(0, 1, 2, 3, kOutOfPlaneBend);
amoebaOutOfPlaneBendForce->setUsesPeriodicBoundaryConditions(true);
system.addForce(amoebaOutOfPlaneBendForce);
Context context(system, integrator, Platform::getPlatformByName("Reference"));
std::vector<Vec3> positions(numberOfParticles);
positions[0] = Vec3(0, 0, 0);
positions[1] = Vec3(1, 0, 0);
positions[2] = Vec3(0, 1, 0);
positions[3] = Vec3(0, 0, 1);
context.setPositions(positions);
State s1 = context.getState(State::Forces | State::Energy);
// Move one atom to a position that should give identical results.
positions[3] = Vec3(0, 0, -2);
context.setPositions(positions);
State s2 = context.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(s1.getPotentialEnergy(), s2.getPotentialEnergy(), 1e-5);
for (int i = 0; i < numberOfParticles; i++)
ASSERT_EQUAL_VEC(s1.getForces()[i], s2.getForces()[i], 1e-5);
}
int main(int numberOfArguments, char* argv[]) {
try {
std::cout << "TestReferenceAmoebaOutOfPlaneBendForce running test..." << std::endl;
registerAmoebaReferenceKernelFactories();
testOneOutOfPlaneBend();
testPeriodic();
//testOneOutOfPlaneBend2(atoi(argv[1]));
//for (int ii = 1; ii <= 6; ii++) {
// testOneOutOfPlaneBend2(ii);
//}
}
catch(const std::exception& e) {
std::cout << "exception: " << e.what() << std::endl;
std::cout << "FAIL - ERROR. Test failed." << std::endl;
return 1;
}
//std::cout << "PASS - Test succeeded." << std::endl;
std::cout << "Done" << std::endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
/**
* This tests the Reference implementation of ReferenceAmoebaPiTorsionForce.
*/
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "OpenMMAmoeba.h"
#include "openmm/System.h"
#include "openmm/LangevinIntegrator.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
extern "C" OPENMM_EXPORT void registerAmoebaReferenceKernelFactories();
const double TOL = 1e-5;
/* ---------------------------------------------------------------------------------------
Compute cross product of two 3-vectors and place in 3rd vector
vectorZ = vectorX x vectorY
@param vectorX x-vector
@param vectorY y-vector
@param vectorZ z-vector
@return vector is vectorZ
--------------------------------------------------------------------------------------- */
static void crossProductVector3(double* vectorX, double* vectorY, double* vectorZ) {
vectorZ[0] = vectorX[1]*vectorY[2] - vectorX[2]*vectorY[1];
vectorZ[1] = vectorX[2]*vectorY[0] - vectorX[0]*vectorY[2];
vectorZ[2] = vectorX[0]*vectorY[1] - vectorX[1]*vectorY[0];
return;
}
static double dotVector3(double* vectorX, double* vectorY) {
return vectorX[0]*vectorY[0] + vectorX[1]*vectorY[1] + vectorX[2]*vectorY[2];
}
static void computeAmoebaPiTorsionForce(int bondIndex, std::vector<Vec3>& positions, AmoebaPiTorsionForce& amoebaPiTorsionForce,
std::vector<Vec3>& forces, double* energy) {
int particle1, particle2, particle3, particle4, particle5, particle6;
double kTorsion;
amoebaPiTorsionForce.getPiTorsionParameters(bondIndex, particle1, particle2, particle3, particle4, particle5, particle6, kTorsion);
enum { AD, BD, EC, FC, P, Q, CP, DC, QD, T, U, TU, DP, QC, dT, dU, dP, dQ, dC1, dC2, dD1, dD2, LastDeltaIndex };
double deltaR[LastDeltaIndex][3];
enum { A, B, C, D, E, F, LastAtomIndex };
double d[LastAtomIndex][3];
for (int ii = 0; ii < 3; ii++) {
deltaR[AD][ii] = positions[particle1][ii] - positions[particle4][ii];
deltaR[BD][ii] = positions[particle2][ii] - positions[particle4][ii];
deltaR[EC][ii] = positions[particle5][ii] - positions[particle3][ii];
deltaR[FC][ii] = positions[particle6][ii] - positions[particle3][ii];
}
crossProductVector3(deltaR[AD], deltaR[BD], deltaR[P]);
crossProductVector3(deltaR[EC], deltaR[FC], deltaR[Q]);
for (int ii = 0; ii < 3; ii++) {
deltaR[CP][ii] = -deltaR[P][ii];
deltaR[DC][ii] = positions[particle4][ii] - positions[particle3][ii];
deltaR[QD][ii] = deltaR[Q][ii];
deltaR[P][ii] += positions[particle3][ii];
deltaR[Q][ii] += positions[particle4][ii];
}
crossProductVector3(deltaR[CP], deltaR[DC], deltaR[T]);
crossProductVector3(deltaR[DC], deltaR[QD], deltaR[U]);
crossProductVector3(deltaR[T], deltaR[U], deltaR[TU]);
double rT2 = dotVector3(deltaR[T], deltaR[T]);
double rU2 = dotVector3(deltaR[U], deltaR[U]);
double rTrU = sqrt(rT2*rU2);
if (rTrU <= 0.0) {
return;
}
double rDC = dotVector3(deltaR[DC], deltaR[DC]);
rDC = sqrt(rDC);
double cosine = dotVector3(deltaR[T], deltaR[U]);
cosine /= rTrU;
double sine = dotVector3(deltaR[DC], deltaR[TU]);
sine /= (rDC*rTrU);
double cosine2 = cosine*cosine - sine*sine;
double sine2 = 2.0*cosine*sine;
double phi2 = 1.0 - cosine2;
double dphi2 = 2.0*sine2;
double dedphi = kTorsion*dphi2;
for (int ii = 0; ii < 3; ii++) {
deltaR[DP][ii] = positions[particle4][ii] - deltaR[P][ii];
deltaR[QC][ii] = deltaR[Q][ii] - positions[particle3][ii];
}
double factorT = dedphi/(rDC*rT2);
double factorU = -dedphi/(rDC*rU2);
crossProductVector3(deltaR[T], deltaR[DC], deltaR[dT]);
crossProductVector3(deltaR[U], deltaR[DC], deltaR[dU]);
for (int ii = 0; ii < 3; ii++) {
deltaR[dT][ii] *= factorT;
deltaR[dU][ii] *= factorU;
}
crossProductVector3(deltaR[dT], deltaR[DC], deltaR[dP] );
crossProductVector3(deltaR[dU], deltaR[DC], deltaR[dQ] );
crossProductVector3(deltaR[DP], deltaR[dT], deltaR[dC1]);
crossProductVector3(deltaR[dU], deltaR[QD], deltaR[dC2]);
crossProductVector3(deltaR[dT], deltaR[CP], deltaR[dD1]);
crossProductVector3(deltaR[QC], deltaR[dU], deltaR[dD2]);
crossProductVector3(deltaR[BD], deltaR[dP], d[A] );
crossProductVector3(deltaR[dP], deltaR[AD], d[B] );
crossProductVector3(deltaR[FC], deltaR[dQ], d[E] );
crossProductVector3(deltaR[dQ], deltaR[EC], d[F] );
for (int ii = 0; ii < 3; ii++) {
d[C][ii] = deltaR[dC1][ii] + deltaR[dC2][ii] + deltaR[dP][ii] - d[E][ii] - d[F][ii];
d[D][ii] = deltaR[dD1][ii] + deltaR[dD2][ii] + deltaR[dQ][ii] - d[A][ii] - d[B][ii];
}
// ---------------------------------------------------------------------------------------
// accumulate forces and energy
forces[particle1][0] -= d[0][0];
forces[particle1][1] -= d[0][1];
forces[particle1][2] -= d[0][2];
forces[particle2][0] -= d[1][0];
forces[particle2][1] -= d[1][1];
forces[particle2][2] -= d[1][2];
forces[particle3][0] -= d[2][0];
forces[particle3][1] -= d[2][1];
forces[particle3][2] -= d[2][2];
forces[particle4][0] -= d[3][0];
forces[particle4][1] -= d[3][1];
forces[particle4][2] -= d[3][2];
forces[particle5][0] -= d[4][0];
forces[particle5][1] -= d[4][1];
forces[particle5][2] -= d[4][2];
forces[particle6][0] -= d[5][0];
forces[particle6][1] -= d[5][1];
forces[particle6][2] -= d[5][2];
*energy += kTorsion*phi2;
return;
}
static void computeAmoebaPiTorsionForces(Context& context, AmoebaPiTorsionForce& amoebaPiTorsionForce,
std::vector<Vec3>& expectedForces, double* expectedEnergy) {
// get positions and zero forces
State state = context.getState(State::Positions);
std::vector<Vec3> positions = state.getPositions();
expectedForces.resize(positions.size());
for (unsigned int ii = 0; ii < expectedForces.size(); ii++) {
expectedForces[ii][0] = expectedForces[ii][1] = expectedForces[ii][2] = 0.0;
}
// calculates forces/energy
*expectedEnergy = 0.0;
for (int ii = 0; ii < amoebaPiTorsionForce.getNumPiTorsions(); ii++) {
computeAmoebaPiTorsionForce(ii, positions, amoebaPiTorsionForce, expectedForces, expectedEnergy);
}
}
void compareWithExpectedForceAndEnergy(Context& context, AmoebaPiTorsionForce& amoebaPiTorsionForce,
double tolerance, const std::string& idString) {
std::vector<Vec3> expectedForces;
double expectedEnergy;
computeAmoebaPiTorsionForces(context, amoebaPiTorsionForce, expectedForces, &expectedEnergy);
State state = context.getState(State::Forces | State::Energy);
const std::vector<Vec3> forces = state.getForces();
for (unsigned int ii = 0; ii < forces.size(); ii++) {
ASSERT_EQUAL_VEC(expectedForces[ii], forces[ii], tolerance);
}
ASSERT_EQUAL_TOL(expectedEnergy, state.getPotentialEnergy(), tolerance);
}
void testOnePiTorsion() {
System system;
int numberOfParticles = 6;
for (int ii = 0; ii < numberOfParticles; ii++) {
system.addParticle(1.0);
}
LangevinIntegrator integrator(0.0, 0.1, 0.01);
AmoebaPiTorsionForce* amoebaPiTorsionForce = new AmoebaPiTorsionForce();
double kTorsion = 6.85;
amoebaPiTorsionForce->addPiTorsion(0, 1, 2, 3, 4, 5, kTorsion);
system.addForce(amoebaPiTorsionForce);
ASSERT(!amoebaPiTorsionForce->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, Platform::getPlatformByName("Reference"));
std::vector<Vec3> positions(numberOfParticles);
positions[0] = Vec3(0.262660000E+02, 0.254130000E+02, 0.284200000E+01);
positions[1] = Vec3(0.278860000E+02, 0.264630000E+02, 0.426300000E+01);
positions[2] = Vec3(0.269130000E+02, 0.266390000E+02, 0.353100000E+01);
positions[3] = Vec3(0.245568230E+02, 0.250215290E+02, 0.796852800E+01);
positions[4] = Vec3(0.261000000E+02, 0.292530000E+02, 0.520200000E+01);
positions[5] = Vec3(0.254124630E+02, 0.234691880E+02, 0.773335400E+01);
context.setPositions(positions);
compareWithExpectedForceAndEnergy(context, *amoebaPiTorsionForce, TOL, "testOnePiTorsion");
// Try changing the torsion parameters and make sure it's still correct.
amoebaPiTorsionForce->setPiTorsionParameters(0, 0, 1, 2, 3, 4, 5, 1.2*kTorsion);
bool exceptionThrown = false;
try {
// This should throw an exception.
compareWithExpectedForceAndEnergy(context, *amoebaPiTorsionForce, TOL, "testOnePiTorsion");
}
catch (std::exception ex) {
exceptionThrown = true;
}
ASSERT(exceptionThrown);
amoebaPiTorsionForce->updateParametersInContext(context);
compareWithExpectedForceAndEnergy(context, *amoebaPiTorsionForce, TOL, "testOnePiTorsion");
}
void testPeriodic() {
// Create a force that uses periodic boundary conditions.
System system;
system.setDefaultPeriodicBoxVectors(Vec3(3, 0, 0), Vec3(0, 3, 0), Vec3(0, 0, 3));
int numberOfParticles = 6;
for (int ii = 0; ii < numberOfParticles; ii++)
system.addParticle(1.0);
LangevinIntegrator integrator(0.0, 0.1, 0.01);
AmoebaPiTorsionForce* amoebaPiTorsionForce = new AmoebaPiTorsionForce();
double kTorsion = 6.85;
amoebaPiTorsionForce->addPiTorsion(0, 1, 2, 3, 4, 5, kTorsion);
amoebaPiTorsionForce->setUsesPeriodicBoundaryConditions(true);
system.addForce(amoebaPiTorsionForce);
Context context(system, integrator, Platform::getPlatformByName("Reference"));
std::vector<Vec3> positions(numberOfParticles);
positions[0] = Vec3(0, 1, 0);
positions[1] = Vec3(0, 0, 0);
positions[2] = Vec3(0, 0, 0.5);
positions[3] = Vec3(0.4, 0.4, 0.4);
positions[4] = Vec3(1, 0, 1);
positions[5] = Vec3(1, 1, 0);
context.setPositions(positions);
State s1 = context.getState(State::Forces | State::Energy);
// Move one atom to a position that should give identical results.
positions[0] = Vec3(0, -2, 0);
context.setPositions(positions);
State s2 = context.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(s1.getPotentialEnergy(), s2.getPotentialEnergy(), 1e-5);
for (int i = 0; i < numberOfParticles; i++)
ASSERT_EQUAL_VEC(s1.getForces()[i], s2.getForces()[i], 1e-5);
}
int main(int numberOfArguments, char* argv[]) {
try {
std::cout << "TestReferenceAmoebaPiTorsionForce running test..." << std::endl;
registerAmoebaReferenceKernelFactories();
testOnePiTorsion();
testPeriodic();
}
catch(const std::exception& e) {
std::cout << "exception: " << e.what() << std::endl;
std::cout << "FAIL - ERROR. Test failed." << std::endl;
return 1;
}
//std::cout << "PASS - Test succeeded." << std::endl;
std::cout << "Done" << std::endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
/**
* This tests the Reference implementation of ReferenceAmoebaStretchBendForce.
*/
#include "openmm/internal/AssertionUtilities.h"
//#include "AmoebaTinkerParameterFile.h"
#include "openmm/Context.h"
#include "OpenMMAmoeba.h"
#include "openmm/System.h"
#include "openmm/LangevinIntegrator.h"
#include "SimTKOpenMMRealType.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
extern "C" OPENMM_EXPORT void registerAmoebaReferenceKernelFactories();
const double TOL = 1e-4;
const double DegreesToRadians = (M_PI/180.0);
/* ---------------------------------------------------------------------------------------
Compute cross product of two 3-vectors and place in 3rd vector
vectorZ = vectorX x vectorY
@param vectorX x-vector
@param vectorY y-vector
@param vectorZ z-vector
@return vector is vectorZ
--------------------------------------------------------------------------------------- */
static void crossProductVector3(double* vectorX, double* vectorY, double* vectorZ) {
vectorZ[0] = vectorX[1]*vectorY[2] - vectorX[2]*vectorY[1];
vectorZ[1] = vectorX[2]*vectorY[0] - vectorX[0]*vectorY[2];
vectorZ[2] = vectorX[0]*vectorY[1] - vectorX[1]*vectorY[0];
return;
}
static double dotVector3(double* vectorX, double* vectorY) {
return vectorX[0]*vectorY[0] + vectorX[1]*vectorY[1] + vectorX[2]*vectorY[2];
}
static void computeAmoebaStretchBendForce(int bondIndex, std::vector<Vec3>& positions, AmoebaStretchBendForce& amoebaStretchBendForce,
std::vector<Vec3>& forces, double* energy) {
int particle1, particle2, particle3;
double abBondLength, cbBondLength, angleStretchBend, kStretchBend, k2StretchBend;
amoebaStretchBendForce.getStretchBendParameters(bondIndex, particle1, particle2, particle3, abBondLength, cbBondLength, angleStretchBend, kStretchBend, k2StretchBend);
angleStretchBend *= RADIAN;
enum { A, B, C, LastAtomIndex };
enum { AB, CB, CBxAB, ABxP, CBxP, LastDeltaIndex };
// ---------------------------------------------------------------------------------------
// get deltaR between various combinations of the 3 atoms
// and various intermediate terms
double deltaR[LastDeltaIndex][3];
double rAB2 = 0.0;
double rCB2 = 0.0;
for (int ii = 0; ii < 3; ii++) {
deltaR[AB][ii] = positions[particle1][ii] - positions[particle2][ii];
rAB2 += deltaR[AB][ii]*deltaR[AB][ii];
deltaR[CB][ii] = positions[particle3][ii] - positions[particle2][ii];
rCB2 += deltaR[CB][ii]*deltaR[CB][ii];
}
double rAB = sqrt(rAB2);
double rCB = sqrt(rCB2);
crossProductVector3(deltaR[CB], deltaR[AB], deltaR[CBxAB]);
double rP = dotVector3(deltaR[CBxAB], deltaR[CBxAB]);
rP = sqrt(rP);
if (rP <= 0.0) {
return;
}
double dot = dotVector3(deltaR[CB], deltaR[AB]);
double cosine = dot/(rAB*rCB);
double angle;
if (cosine >= 1.0) {
angle = 0.0;
}
else if (cosine <= -1.0) {
angle = PI_M;
}
else {
angle = RADIAN*acos(cosine);
}
double termA = -RADIAN/(rAB2*rP);
double termC = RADIAN/(rCB2*rP);
// P = CBxAB
crossProductVector3(deltaR[AB], deltaR[CBxAB], deltaR[ABxP]);
crossProductVector3(deltaR[CB], deltaR[CBxAB], deltaR[CBxP]);
for (int ii = 0; ii < 3; ii++) {
deltaR[ABxP][ii] *= termA;
deltaR[CBxP][ii] *= termC;
}
double dr1 = rAB - abBondLength;
double dr2 = rCB - cbBondLength;
termA = 1.0/rAB;
termC = 1.0/rCB;
double drkk = dr1 * kStretchBend + dr2 * k2StretchBend;
// ---------------------------------------------------------------------------------------
// forces
// calculate forces for atoms a, b, c
// the force for b is then -(a + c)
double subForce[LastAtomIndex][3];
double dt = angle - angleStretchBend;
for (int jj = 0; jj < 3; jj++) {
subForce[A][jj] = kStretchBend*dt*termA*deltaR[AB][jj] + drkk*deltaR[ABxP][jj];
subForce[C][jj] = k2StretchBend*dt*termC*deltaR[CB][jj] + drkk*deltaR[CBxP][jj];
subForce[B][jj] = -(subForce[A][jj] + subForce[C][jj]);
}
// ---------------------------------------------------------------------------------------
// accumulate forces and energy
forces[particle1][0] -= subForce[0][0];
forces[particle1][1] -= subForce[0][1];
forces[particle1][2] -= subForce[0][2];
forces[particle2][0] -= subForce[1][0];
forces[particle2][1] -= subForce[1][1];
forces[particle2][2] -= subForce[1][2];
forces[particle3][0] -= subForce[2][0];
forces[particle3][1] -= subForce[2][1];
forces[particle3][2] -= subForce[2][2];
*energy += dt*drkk;
}
static void computeAmoebaStretchBendForces(Context& context, AmoebaStretchBendForce& amoebaStretchBendForce,
std::vector<Vec3>& expectedForces, double* expectedEnergy) {
// get positions and zero forces
State state = context.getState(State::Positions);
std::vector<Vec3> positions = state.getPositions();
expectedForces.resize(positions.size());
for (unsigned int ii = 0; ii < expectedForces.size(); ii++) {
expectedForces[ii][0] = expectedForces[ii][1] = expectedForces[ii][2] = 0.0;
}
// calculates forces/energy
*expectedEnergy = 0.0;
for (int ii = 0; ii < amoebaStretchBendForce.getNumStretchBends(); ii++) {
computeAmoebaStretchBendForce(ii, positions, amoebaStretchBendForce, expectedForces, expectedEnergy);
}
}
void compareWithExpectedForceAndEnergy(Context& context, AmoebaStretchBendForce& amoebaStretchBendForce,
double tolerance, const std::string& idString) {
std::vector<Vec3> expectedForces;
double expectedEnergy;
computeAmoebaStretchBendForces(context, amoebaStretchBendForce, expectedForces, &expectedEnergy);
State state = context.getState(State::Forces | State::Energy);
const std::vector<Vec3> forces = state.getForces();
for (unsigned int ii = 0; ii < forces.size(); ii++) {
ASSERT_EQUAL_VEC(expectedForces[ii], forces[ii], tolerance);
}
ASSERT_EQUAL_TOL(expectedEnergy, state.getPotentialEnergy(), tolerance);
}
void testOneStretchBend() {
System system;
int numberOfParticles = 3;
for (int ii = 0; ii < numberOfParticles; ii++) {
system.addParticle(1.0);
}
LangevinIntegrator integrator(0.0, 0.1, 0.01);
AmoebaStretchBendForce* amoebaStretchBendForce = new AmoebaStretchBendForce();
double abLength = 0.144800000E+01;
double cbLength = 0.101500000E+01;
double angleStretchBend = 0.108500000E+03*DegreesToRadians;
//double kStretchBend = 0.750491578E-01;
double kStretchBend = 1.0;
amoebaStretchBendForce->addStretchBend(0, 1, 2, abLength, cbLength, angleStretchBend, kStretchBend, kStretchBend);
system.addForce(amoebaStretchBendForce);
ASSERT(!amoebaStretchBendForce->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, Platform::getPlatformByName("Reference"));
std::vector<Vec3> positions(numberOfParticles);
positions[0] = Vec3(0.262660000E+02, 0.254130000E+02, 0.284200000E+01);
positions[1] = Vec3(0.273400000E+02, 0.244300000E+02, 0.261400000E+01);
positions[2] = Vec3(0.269573220E+02, 0.236108860E+02, 0.216376800E+01);
context.setPositions(positions);
compareWithExpectedForceAndEnergy(context, *amoebaStretchBendForce, TOL, "testOneStretchBend");
// Try changing the stretch-bend parameters and make sure it's still correct.
amoebaStretchBendForce->setStretchBendParameters(0, 0, 1, 2, 1.1*abLength, 1.2*cbLength, 1.3*angleStretchBend, 1.4*kStretchBend, 1.4*kStretchBend);
bool exceptionThrown = false;
try {
// This should throw an exception.
compareWithExpectedForceAndEnergy(context, *amoebaStretchBendForce, TOL, "testOneStretchBend");
}
catch (std::exception ex) {
exceptionThrown = true;
}
ASSERT(exceptionThrown);
amoebaStretchBendForce->updateParametersInContext(context);
compareWithExpectedForceAndEnergy(context, *amoebaStretchBendForce, TOL, "testOneStretchBend");
}
void testPeriodic() {
// Create a force that uses periodic boundary conditions.
System system;
system.setDefaultPeriodicBoxVectors(Vec3(3, 0, 0), Vec3(0, 3, 0), Vec3(0, 0, 3));
int numberOfParticles = 3;
for (int ii = 0; ii < numberOfParticles; ii++)
system.addParticle(1.0);
LangevinIntegrator integrator(0.0, 0.1, 0.01);
AmoebaStretchBendForce* amoebaStretchBendForce = new AmoebaStretchBendForce();
double abLength = 0.144800000E+01;
double cbLength = 0.101500000E+01;
double angleStretchBend = 0.108500000E+03*DegreesToRadians;
double kStretchBend = 1.0;
amoebaStretchBendForce->addStretchBend(0, 1, 2, abLength, cbLength, angleStretchBend, kStretchBend, kStretchBend);
amoebaStretchBendForce->setUsesPeriodicBoundaryConditions(true);
system.addForce(amoebaStretchBendForce);
Context context(system, integrator, Platform::getPlatformByName("Reference"));
std::vector<Vec3> positions(numberOfParticles);
positions[0] = Vec3(0, 1, 0);
positions[1] = Vec3(0, 0, 0);
positions[2] = Vec3(0, 0, 1);
context.setPositions(positions);
State s1 = context.getState(State::Forces | State::Energy);
// Move one atom to a position that should give identical results.
positions[2] = Vec3(0, 0, -2);
context.setPositions(positions);
State s2 = context.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(s1.getPotentialEnergy(), s2.getPotentialEnergy(), 1e-5);
for (int i = 0; i < numberOfParticles; i++)
ASSERT_EQUAL_VEC(s1.getForces()[i], s2.getForces()[i], 1e-5);
}
int main(int numberOfArguments, char* argv[]) {
try {
std::cout << "TestReferenceAmoebaStretchBendForce running test..." << std::endl;
registerAmoebaReferenceKernelFactories();
testOneStretchBend();
testPeriodic();
}
catch(const std::exception& e) {
std::cout << "exception: " << e.what() << std::endl;
std::cout << "FAIL - ERROR. Test failed." << std::endl;
return 1;
}
//std::cout << "PASS - Test succeeded." << std::endl;
std::cout << "Done" << std::endl;
return 0;
}
#ifndef OPENMM_AMOEBA_ANGLE_FORCE_PROXY_H_
#define OPENMM_AMOEBA_ANGLE_FORCE_PROXY_H_
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/windowsExportAmoeba.h"
#include "openmm/serialization/SerializationProxy.h"
namespace OpenMM {
/**
* This is a proxy for serializing AmoebaAngleForce objects.
*/
class OPENMM_EXPORT_AMOEBA AmoebaAngleForceProxy : public SerializationProxy {
public:
AmoebaAngleForceProxy();
void serialize(const void* object, SerializationNode& node) const;
void* deserialize(const SerializationNode& node) const;
};
} // namespace OpenMM
#endif /*OPENMM_AMOEBA_ANGLE_FORCE_PROXY_H_*/
#ifndef OPENMM_AMOEBA_BOND_FORCE_PROXY_H_
#define OPENMM_AMOEBA_BOND_FORCE_PROXY_H_
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/windowsExportAmoeba.h"
#include "openmm/serialization/SerializationProxy.h"
namespace OpenMM {
/**
* This is a proxy for serializing AmoebaBondForce objects.
*/
class OPENMM_EXPORT_AMOEBA AmoebaBondForceProxy : public SerializationProxy {
public:
AmoebaBondForceProxy();
void serialize(const void* object, SerializationNode& node) const;
void* deserialize(const SerializationNode& node) const;
};
} // namespace OpenMM
#endif /*OPENMM_AMOEBA_BOND_FORCE_PROXY_H_*/
#ifndef OPENMM_AMOEBA_IN_PLANE_ANGLE_FORCE_PROXY_H_
#define OPENMM_AMOEBA_IN_PLANE_ANGLE_FORCE_PROXY_H_
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/windowsExportAmoeba.h"
#include "openmm/serialization/SerializationProxy.h"
namespace OpenMM {
/**
* This is a proxy for serializing AmoebaInPlaneAngleForce objects.
*/
class OPENMM_EXPORT_AMOEBA AmoebaInPlaneAngleForceProxy : public SerializationProxy {
public:
AmoebaInPlaneAngleForceProxy();
void serialize(const void* object, SerializationNode& node) const;
void* deserialize(const SerializationNode& node) const;
};
} // namespace OpenMM
#endif /*OPENMM_AMOEBA_IN_PLANE_ANGLE_FORCE_PROXY_H_*/
#ifndef OPENMM_AMOEBA_OUT_OF_PLANE_BEND_FORCE_PROXY_H_
#define OPENMM_AMOEBA_OUT_OF_PLANE_BEND_FORCE_PROXY_H_
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/windowsExportAmoeba.h"
#include "openmm/serialization/SerializationProxy.h"
namespace OpenMM {
/**
* This is a proxy for serializing AmoebaOutOfPlaneBendForce objects.
*/
class OPENMM_EXPORT_AMOEBA AmoebaOutOfPlaneBendForceProxy : public SerializationProxy {
public:
AmoebaOutOfPlaneBendForceProxy();
void serialize(const void* object, SerializationNode& node) const;
void* deserialize(const SerializationNode& node) const;
};
} // namespace OpenMM
#endif /*OPENMM_AMOEBA_OUT_OF_PLANE_BEND_FORCE_PROXY_H_*/
#ifndef OPENMM_AMOEBA_PI_TORSION_FORCE_PROXY_H_
#define OPENMM_AMOEBA_PI_TORSION_FORCE_PROXY_H_
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/windowsExportAmoeba.h"
#include "openmm/serialization/SerializationProxy.h"
namespace OpenMM {
/**
* This is a proxy for serializing AmoebaPiTorsionForce objects.
*/
class OPENMM_EXPORT_AMOEBA AmoebaPiTorsionForceProxy : public SerializationProxy {
public:
AmoebaPiTorsionForceProxy();
void serialize(const void* object, SerializationNode& node) const;
void* deserialize(const SerializationNode& node) const;
};
} // namespace OpenMM
#endif /*OPENMM_AMOEBA_PI_TORSION_FORCE_PROXY_H_*/
#ifndef OPENMM_AMOEBA_STRETCH_BEND_FORCE_PROXY_H_
#define OPENMM_AMOEBA_STRETCH_BEND_FORCE_PROXY_H_
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/windowsExportAmoeba.h"
#include "openmm/serialization/SerializationProxy.h"
namespace OpenMM {
/**
* This is a proxy for serializing AmoebaStretchBendForce objects.
*/
class OPENMM_EXPORT_AMOEBA AmoebaStretchBendForceProxy : public SerializationProxy {
public:
AmoebaStretchBendForceProxy();
void serialize(const void* object, SerializationNode& node) const;
void* deserialize(const SerializationNode& node) const;
};
} // namespace OpenMM
#endif /*OPENMM_AMOEBA_STRETCH_BEND_FORCE_PROXY_H_*/
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/serialization/AmoebaAngleForceProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include "openmm/Force.h"
#include "openmm/AmoebaAngleForce.h"
#include <sstream>
using namespace OpenMM;
using namespace std;
AmoebaAngleForceProxy::AmoebaAngleForceProxy() : SerializationProxy("AmoebaAngleForce") {
}
void AmoebaAngleForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 3);
const AmoebaAngleForce& force = *reinterpret_cast<const AmoebaAngleForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
node.setDoubleProperty("cubic", force.getAmoebaGlobalAngleCubic());
node.setDoubleProperty("quartic", force.getAmoebaGlobalAngleQuartic());
node.setDoubleProperty("pentic", force.getAmoebaGlobalAnglePentic());
node.setDoubleProperty("sextic", force.getAmoebaGlobalAngleSextic());
SerializationNode& bonds = node.createChildNode("Angles");
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumAngles()); ii++) {
int particle1, particle2, particle3;
double distance, k;
force.getAngleParameters(ii, particle1, particle2, particle3, distance, k);
bonds.createChildNode("Angle").setIntProperty("p1", particle1).setIntProperty("p2", particle2).setIntProperty("p3", particle3).setDoubleProperty("d", distance).setDoubleProperty("k", k);
}
}
void* AmoebaAngleForceProxy::deserialize(const SerializationNode& node) const {
int version = node.getIntProperty("version");
if (version < 1 || version > 3)
throw OpenMMException("Unsupported version number");
AmoebaAngleForce* force = new AmoebaAngleForce();
try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
if (version > 2)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
force->setAmoebaGlobalAngleCubic(node.getDoubleProperty("cubic"));
force->setAmoebaGlobalAngleQuartic(node.getDoubleProperty("quartic"));
force->setAmoebaGlobalAnglePentic(node.getDoubleProperty("pentic"));
force->setAmoebaGlobalAngleSextic(node.getDoubleProperty("sextic"));
const SerializationNode& bonds = node.getChildNode("Angles");
for (unsigned int ii = 0; ii < bonds.getChildren().size(); ii++) {
const SerializationNode& bond = bonds.getChildren()[ii];
force->addAngle(bond.getIntProperty("p1"), bond.getIntProperty("p2"), bond.getIntProperty("p3"), bond.getDoubleProperty("d"), bond.getDoubleProperty("k"));
}
}
catch (...) {
delete force;
throw;
}
return force;
}
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/serialization/AmoebaBondForceProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include "openmm/Force.h"
#include "openmm/AmoebaBondForce.h"
#include <sstream>
using namespace OpenMM;
using namespace std;
AmoebaBondForceProxy::AmoebaBondForceProxy() : SerializationProxy("AmoebaBondForce") {
}
void AmoebaBondForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 3);
const AmoebaBondForce& force = *reinterpret_cast<const AmoebaBondForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
node.setDoubleProperty("cubic", force.getAmoebaGlobalBondCubic());
node.setDoubleProperty("quartic", force.getAmoebaGlobalBondQuartic());
SerializationNode& bonds = node.createChildNode("Bonds");
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumBonds()); ii++) {
int particle1, particle2;
double distance, k;
force.getBondParameters(ii, particle1, particle2, distance, k);
bonds.createChildNode("Bond").setIntProperty("p1", particle1).setIntProperty("p2", particle2).setDoubleProperty("d", distance).setDoubleProperty("k", k);
}
}
void* AmoebaBondForceProxy::deserialize(const SerializationNode& node) const {
int version = node.getIntProperty("version");
if (version < 1 || version > 3)
throw OpenMMException("Unsupported version number");
AmoebaBondForce* force = new AmoebaBondForce();
try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
if (version > 2)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
force->setAmoebaGlobalBondCubic(node.getDoubleProperty("cubic"));
force->setAmoebaGlobalBondQuartic(node.getDoubleProperty("quartic"));
const SerializationNode& bonds = node.getChildNode("Bonds");
for (auto& bond : bonds.getChildren())
force->addBond(bond.getIntProperty("p1"), bond.getIntProperty("p2"), bond.getDoubleProperty("d"), bond.getDoubleProperty("k"));
}
catch (...) {
delete force;
throw;
}
return force;
}
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/serialization/AmoebaInPlaneAngleForceProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include "openmm/Force.h"
#include "openmm/AmoebaInPlaneAngleForce.h"
#include <sstream>
using namespace OpenMM;
using namespace std;
AmoebaInPlaneAngleForceProxy::AmoebaInPlaneAngleForceProxy() : SerializationProxy("AmoebaInPlaneAngleForce") {
}
void AmoebaInPlaneAngleForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 3);
const AmoebaInPlaneAngleForce& force = *reinterpret_cast<const AmoebaInPlaneAngleForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
node.setDoubleProperty("cubic", force.getAmoebaGlobalInPlaneAngleCubic());
node.setDoubleProperty("quartic", force.getAmoebaGlobalInPlaneAngleQuartic());
node.setDoubleProperty("pentic", force.getAmoebaGlobalInPlaneAnglePentic());
node.setDoubleProperty("sextic", force.getAmoebaGlobalInPlaneAngleSextic());
SerializationNode& bonds = node.createChildNode("InPlaneAngles");
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumAngles()); ii++) {
int particle1, particle2, particle3, particle4;
double distance, k;
force.getAngleParameters(ii, particle1, particle2, particle3, particle4, distance, k);
bonds.createChildNode("InPlaneAngle").setIntProperty("p1", particle1).setIntProperty("p2", particle2).setIntProperty("p3", particle3).setIntProperty("p4", particle4).setDoubleProperty("d", distance).setDoubleProperty("k", k);
}
}
void* AmoebaInPlaneAngleForceProxy::deserialize(const SerializationNode& node) const {
int version = node.getIntProperty("version");
if (version < 1 || version > 3)
throw OpenMMException("Unsupported version number");
AmoebaInPlaneAngleForce* force = new AmoebaInPlaneAngleForce();
try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
if (version > 2)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
force->setAmoebaGlobalInPlaneAngleCubic( node.getDoubleProperty("cubic"));
force->setAmoebaGlobalInPlaneAngleQuartic(node.getDoubleProperty("quartic"));
force->setAmoebaGlobalInPlaneAnglePentic(node.getDoubleProperty("pentic"));
force->setAmoebaGlobalInPlaneAngleSextic(node.getDoubleProperty("sextic"));
const SerializationNode& bonds = node.getChildNode("InPlaneAngles");
for (unsigned int ii = 0; ii < bonds.getChildren().size(); ii++) {
const SerializationNode& bond = bonds.getChildren()[ii];
force->addAngle(bond.getIntProperty("p1"), bond.getIntProperty("p2"), bond.getIntProperty("p3"), bond.getIntProperty("p4"), bond.getDoubleProperty("d"), bond.getDoubleProperty("k"));
}
}
catch (...) {
delete force;
throw;
}
return force;
}
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/serialization/AmoebaOutOfPlaneBendForceProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include "openmm/Force.h"
#include "openmm/AmoebaOutOfPlaneBendForce.h"
#include <sstream>
using namespace OpenMM;
using namespace std;
AmoebaOutOfPlaneBendForceProxy::AmoebaOutOfPlaneBendForceProxy() : SerializationProxy("AmoebaOutOfPlaneBendForce") {
}
void AmoebaOutOfPlaneBendForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 3);
const AmoebaOutOfPlaneBendForce& force = *reinterpret_cast<const AmoebaOutOfPlaneBendForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
node.setDoubleProperty("cubic", force.getAmoebaGlobalOutOfPlaneBendCubic());
node.setDoubleProperty("quartic", force.getAmoebaGlobalOutOfPlaneBendQuartic());
node.setDoubleProperty("pentic", force.getAmoebaGlobalOutOfPlaneBendPentic());
node.setDoubleProperty("sextic", force.getAmoebaGlobalOutOfPlaneBendSextic());
SerializationNode& bonds = node.createChildNode("OutOfPlaneBend");
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumOutOfPlaneBends()); ii++) {
int particle1, particle2, particle3, particle4;
double k;
force.getOutOfPlaneBendParameters(ii, particle1, particle2, particle3, particle4, k);
bonds.createChildNode("OutOfPlaneBend").setIntProperty("p1", particle1).setIntProperty("p2", particle2).setIntProperty("p3", particle3).setIntProperty("p4", particle4).setDoubleProperty("k", k);
}
}
void* AmoebaOutOfPlaneBendForceProxy::deserialize(const SerializationNode& node) const {
int version = node.getIntProperty("version");
if (version < 1 || version > 3)
throw OpenMMException("Unsupported version number");
AmoebaOutOfPlaneBendForce* force = new AmoebaOutOfPlaneBendForce();
try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
if (version > 2)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
force->setAmoebaGlobalOutOfPlaneBendCubic(node.getDoubleProperty("cubic"));
force->setAmoebaGlobalOutOfPlaneBendQuartic(node.getDoubleProperty("quartic"));
force->setAmoebaGlobalOutOfPlaneBendPentic(node.getDoubleProperty("pentic"));
force->setAmoebaGlobalOutOfPlaneBendSextic(node.getDoubleProperty("sextic"));
const SerializationNode& bonds = node.getChildNode("OutOfPlaneBend");
for (unsigned int ii = 0; ii < bonds.getChildren().size(); ii++) {
const SerializationNode& bond = bonds.getChildren()[ii];
force->addOutOfPlaneBend(bond.getIntProperty("p1"), bond.getIntProperty("p2"), bond.getIntProperty("p3"), bond.getIntProperty("p4"), bond.getDoubleProperty("k"));
}
}
catch (...) {
delete force;
throw;
}
return force;
}
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/serialization/AmoebaPiTorsionForceProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include "openmm/Force.h"
#include "openmm/AmoebaPiTorsionForce.h"
#include <sstream>
using namespace OpenMM;
using namespace std;
AmoebaPiTorsionForceProxy::AmoebaPiTorsionForceProxy() : SerializationProxy("AmoebaPiTorsionForce") {
}
void AmoebaPiTorsionForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 3);
const AmoebaPiTorsionForce& force = *reinterpret_cast<const AmoebaPiTorsionForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
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;
double k;
force.getPiTorsionParameters(ii, particle1, particle2, particle3, particle4, particle5, particle6, k);
bonds.createChildNode("PiTorsion").setIntProperty("p1", particle1).setIntProperty("p2", particle2).setIntProperty("p3", particle3).setIntProperty("p4", particle4).setIntProperty("p5", particle5).setIntProperty("p6", particle6).setDoubleProperty("k", k);
}
}
void* AmoebaPiTorsionForceProxy::deserialize(const SerializationNode& node) const {
int version = node.getIntProperty("version");
if (version < 1 || version > 3)
throw OpenMMException("Unsupported version number");
AmoebaPiTorsionForce* force = new AmoebaPiTorsionForce();
try {
if (version > 1)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
if (version > 2)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& bonds = node.getChildNode("PiTorsion");
for (unsigned int ii = 0; ii < bonds.getChildren().size(); ii++) {
const SerializationNode& bond = bonds.getChildren()[ii];
force->addPiTorsion(bond.getIntProperty("p1"), bond.getIntProperty("p2"), bond.getIntProperty("p3"), bond.getIntProperty("p4"), bond.getIntProperty("p5"), bond.getIntProperty("p6"), bond.getDoubleProperty("k"));
}
}
catch (...) {
delete force;
throw;
}
return force;
}
......@@ -41,13 +41,7 @@
#include "openmm/OpenMMException.h"
#include "openmm/AmoebaGeneralizedKirkwoodForce.h"
#include "openmm/AmoebaBondForce.h"
#include "openmm/AmoebaAngleForce.h"
#include "openmm/AmoebaInPlaneAngleForce.h"
#include "openmm/AmoebaMultipoleForce.h"
#include "openmm/AmoebaOutOfPlaneBendForce.h"
#include "openmm/AmoebaPiTorsionForce.h"
#include "openmm/AmoebaStretchBendForce.h"
#include "openmm/AmoebaTorsionTorsionForce.h"
#include "openmm/AmoebaVdwForce.h"
#include "openmm/AmoebaWcaDispersionForce.h"
......@@ -56,13 +50,7 @@
#include "openmm/serialization/SerializationProxy.h"
#include "openmm/serialization/AmoebaGeneralizedKirkwoodForceProxy.h"
#include "openmm/serialization/AmoebaBondForceProxy.h"
#include "openmm/serialization/AmoebaAngleForceProxy.h"
#include "openmm/serialization/AmoebaInPlaneAngleForceProxy.h"
#include "openmm/serialization/AmoebaMultipoleForceProxy.h"
#include "openmm/serialization/AmoebaOutOfPlaneBendForceProxy.h"
#include "openmm/serialization/AmoebaPiTorsionForceProxy.h"
#include "openmm/serialization/AmoebaStretchBendForceProxy.h"
#include "openmm/serialization/AmoebaTorsionTorsionForceProxy.h"
#include "openmm/serialization/AmoebaVdwForceProxy.h"
#include "openmm/serialization/AmoebaWcaDispersionForceProxy.h"
......@@ -84,13 +72,7 @@ using namespace OpenMM;
extern "C" OPENMM_EXPORT_AMOEBA void registerAmoebaSerializationProxies() {
SerializationProxy::registerProxy(typeid(AmoebaGeneralizedKirkwoodForce), new AmoebaGeneralizedKirkwoodForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaBondForce), new AmoebaBondForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaAngleForce), new AmoebaAngleForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaInPlaneAngleForce), new AmoebaInPlaneAngleForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaMultipoleForce), new AmoebaMultipoleForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaOutOfPlaneBendForce), new AmoebaOutOfPlaneBendForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaPiTorsionForce), new AmoebaPiTorsionForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaStretchBendForce), new AmoebaStretchBendForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaTorsionTorsionForce), new AmoebaTorsionTorsionForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaVdwForce), new AmoebaVdwForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaWcaDispersionForce), new AmoebaWcaDispersionForceProxy());
......
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/serialization/AmoebaStretchBendForceProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include "openmm/Force.h"
#include "openmm/AmoebaStretchBendForce.h"
#include <sstream>
using namespace OpenMM;
using namespace std;
AmoebaStretchBendForceProxy::AmoebaStretchBendForceProxy() : SerializationProxy("AmoebaStretchBendForce") {
}
void AmoebaStretchBendForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 4);
const AmoebaStretchBendForce& force = *reinterpret_cast<const AmoebaStretchBendForce*>(object);
node.setIntProperty("forceGroup", force.getForceGroup());
node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
SerializationNode& bonds = node.createChildNode("StretchBendAngles");
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumStretchBends()); ii++) {
int particle1, particle2, particle3;
double distanceAB, distanceCB, angle, k1, k2;
force.getStretchBendParameters(ii, particle1, particle2, particle3, distanceAB, distanceCB, angle, k1, k2);
bonds.createChildNode("StretchBendAngle").setIntProperty("p1", particle1).setIntProperty("p2", particle2).setIntProperty("p3", particle3).setDoubleProperty("dAB", distanceAB).setDoubleProperty("dCB", distanceCB).setDoubleProperty("angle", angle).setDoubleProperty("k1", k1).setDoubleProperty("k2", k2);
}
}
void* AmoebaStretchBendForceProxy::deserialize(const SerializationNode& node) const {
int version = node.getIntProperty("version");
if (version < 1 || version > 4)
throw OpenMMException("Unsupported version number");
AmoebaStretchBendForce* force = new AmoebaStretchBendForce();
try {
if (version > 2)
force->setForceGroup(node.getIntProperty("forceGroup", 0));
if (version > 3)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& bonds = node.getChildNode("StretchBendAngles");
for (auto& bond : bonds.getChildren()) {
double k1, k2;
if (version == 1)
k1 = k2 = bond.getDoubleProperty("k");
else {
k1 = bond.getDoubleProperty("k1");
k2 = bond.getDoubleProperty("k2");
}
force->addStretchBend(bond.getIntProperty("p1"), bond.getIntProperty("p2"), bond.getIntProperty("p3"), bond.getDoubleProperty("dAB"), bond.getDoubleProperty("dCB"), bond.getDoubleProperty("angle"), k1, k2);
}
}
catch (...) {
delete force;
throw;
}
return force;
}
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/Platform.h"
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/AmoebaAngleForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using namespace OpenMM;
using namespace std;
extern "C" void registerAmoebaSerializationProxies();
void testSerialization() {
// Create a Force.
AmoebaAngleForce force1;
force1.setForceGroup(3);
force1.setAmoebaGlobalAngleCubic(12.3);
force1.setAmoebaGlobalAngleQuartic(98.7);
force1.setAmoebaGlobalAnglePentic(91.7);
force1.setAmoebaGlobalAngleSextic(93.7);
force1.addAngle(0, 1, 3, 1.0, 2.0);
force1.addAngle(0, 2, 3, 2.0, 2.1);
force1.addAngle(2, 3, 5, 3.0, 2.2);
force1.addAngle(5, 1, 8, 4.0, 2.3);
force1.setUsesPeriodicBoundaryConditions(true);
// Serialize and then deserialize it.
stringstream buffer;
XmlSerializer::serialize<AmoebaAngleForce>(&force1, "Force", buffer);
AmoebaAngleForce* copy = XmlSerializer::deserialize<AmoebaAngleForce>(buffer);
// Compare the two forces to see if they are identical.
AmoebaAngleForce& force2 = *copy;
ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup());
ASSERT_EQUAL(force1.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions());
ASSERT_EQUAL(force1.getAmoebaGlobalAngleCubic(), force2.getAmoebaGlobalAngleCubic());
ASSERT_EQUAL(force1.getAmoebaGlobalAngleQuartic(), force2.getAmoebaGlobalAngleQuartic());
ASSERT_EQUAL(force1.getAmoebaGlobalAnglePentic(), force2.getAmoebaGlobalAnglePentic());
ASSERT_EQUAL(force1.getAmoebaGlobalAngleSextic(), force2.getAmoebaGlobalAngleSextic());
ASSERT_EQUAL(force1.getNumAngles(), force2.getNumAngles());
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force1.getNumAngles()); ii++) {
int a1, a2, a3, b1, b2, b3;
double da, db, ka, kb;
force1.getAngleParameters(ii, a1, a2, a3, da, ka);
force2.getAngleParameters(ii, b1, b2, b3, db, kb);
ASSERT_EQUAL(a1, b1);
ASSERT_EQUAL(a2, b2);
ASSERT_EQUAL(a3, b3);
ASSERT_EQUAL(da, db);
ASSERT_EQUAL(ka, kb);
}
}
int main() {
try {
registerAmoebaSerializationProxies();
testSerialization();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/Platform.h"
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/AmoebaBondForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using namespace OpenMM;
using namespace std;
extern "C" void registerAmoebaSerializationProxies();
void testSerialization() {
// Create a Force.
AmoebaBondForce force1;
force1.setForceGroup(3);
force1.setAmoebaGlobalBondCubic(12.3);
force1.setAmoebaGlobalBondQuartic(98.7);
force1.addBond(0, 1, 1.0, 2.0);
force1.addBond(0, 2, 2.0, 2.1);
force1.addBond(2, 3, 3.0, 2.2);
force1.addBond(5, 1, 4.0, 2.3);
force1.setUsesPeriodicBoundaryConditions(true);
// Serialize and then deserialize it.
stringstream buffer;
XmlSerializer::serialize<AmoebaBondForce>(&force1, "Force", buffer);
AmoebaBondForce* copy = XmlSerializer::deserialize<AmoebaBondForce>(buffer);
// Compare the two forces to see if they are identical.
AmoebaBondForce& force2 = *copy;
ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup());
ASSERT_EQUAL(force1.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions());
ASSERT_EQUAL(force1.getAmoebaGlobalBondCubic(), force2.getAmoebaGlobalBondCubic());
ASSERT_EQUAL(force1.getAmoebaGlobalBondQuartic(), force2.getAmoebaGlobalBondQuartic());
ASSERT_EQUAL(force1.getNumBonds(), force2.getNumBonds());
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force1.getNumBonds()); ii++) {
int a1, a2, b1, b2;
double da, db, ka, kb;
force1.getBondParameters(ii, a1, a2, da, ka);
force2.getBondParameters(ii, b1, b2, db, kb);
ASSERT_EQUAL(a1, b1);
ASSERT_EQUAL(a2, b2);
ASSERT_EQUAL(da, db);
ASSERT_EQUAL(ka, kb);
}
}
int main() {
try {
registerAmoebaSerializationProxies();
testSerialization();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/Platform.h"
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/AmoebaInPlaneAngleForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using namespace OpenMM;
using namespace std;
extern "C" void registerAmoebaSerializationProxies();
void testSerialization() {
// Create a Force.
AmoebaInPlaneAngleForce force1;
force1.setForceGroup(3);
force1.setAmoebaGlobalInPlaneAngleCubic(12.3);
force1.setAmoebaGlobalInPlaneAngleQuartic(98.7);
force1.setAmoebaGlobalInPlaneAnglePentic(91.7);
force1.setAmoebaGlobalInPlaneAngleSextic(93.7);
force1.addAngle(0, 1, 3, 4, 1.0, 2.0);
force1.addAngle(0, 2, 3, 5, 2.0, 2.1);
force1.addAngle(2, 3, 5, 6, 3.0, 2.2);
force1.addAngle(5, 1, 8, 8, 4.0, 2.3);
force1.setUsesPeriodicBoundaryConditions(true);
// Serialize and then deserialize it.
stringstream buffer;
XmlSerializer::serialize<AmoebaInPlaneAngleForce>(&force1, "Force", buffer);
AmoebaInPlaneAngleForce* copy = XmlSerializer::deserialize<AmoebaInPlaneAngleForce>(buffer);
// Compare the two forces to see if they are identical.
AmoebaInPlaneAngleForce& force2 = *copy;
ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup());
ASSERT_EQUAL(force1.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions());
ASSERT_EQUAL(force1.getAmoebaGlobalInPlaneAngleCubic(), force2.getAmoebaGlobalInPlaneAngleCubic());
ASSERT_EQUAL(force1.getAmoebaGlobalInPlaneAngleQuartic(), force2.getAmoebaGlobalInPlaneAngleQuartic());
ASSERT_EQUAL(force1.getAmoebaGlobalInPlaneAnglePentic(), force2.getAmoebaGlobalInPlaneAnglePentic());
ASSERT_EQUAL(force1.getAmoebaGlobalInPlaneAngleSextic(), force2.getAmoebaGlobalInPlaneAngleSextic());
ASSERT_EQUAL(force1.getNumAngles(), force2.getNumAngles());
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force1.getNumAngles()); ii++) {
int a1, a2, a3, a4, b1, b2, b3, b4;
double da, db, ka, kb;
force1.getAngleParameters(ii, a1, a2, a3, a4, da, ka);
force2.getAngleParameters(ii, b1, b2, b3, b4, db, kb);
ASSERT_EQUAL(a1, b1);
ASSERT_EQUAL(a2, b2);
ASSERT_EQUAL(a3, b3);
ASSERT_EQUAL(a4, b4);
ASSERT_EQUAL(da, db);
ASSERT_EQUAL(ka, kb);
}
}
int main() {
try {
registerAmoebaSerializationProxies();
testSerialization();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/Platform.h"
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/AmoebaOutOfPlaneBendForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using namespace OpenMM;
using namespace std;
extern "C" void registerAmoebaSerializationProxies();
void testSerialization() {
// Create a Force.
AmoebaOutOfPlaneBendForce force1;
force1.setForceGroup(3);
force1.setAmoebaGlobalOutOfPlaneBendCubic(12.3);
force1.setAmoebaGlobalOutOfPlaneBendQuartic(98.7);
force1.setAmoebaGlobalOutOfPlaneBendPentic(91.7);
force1.setAmoebaGlobalOutOfPlaneBendSextic(93.7);
force1.addOutOfPlaneBend(0, 1, 3, 4, 2.0);
force1.addOutOfPlaneBend(0, 2, 3, 5, 2.1);
force1.addOutOfPlaneBend(2, 3, 5, 6, 2.2);
force1.addOutOfPlaneBend(5, 1, 8, 8, 2.3);
force1.setUsesPeriodicBoundaryConditions(true);
// Serialize and then deserialize it.
stringstream buffer;
XmlSerializer::serialize<AmoebaOutOfPlaneBendForce>(&force1, "Force", buffer);
AmoebaOutOfPlaneBendForce* copy = XmlSerializer::deserialize<AmoebaOutOfPlaneBendForce>(buffer);
// Compare the two forces to see if they are identical.
AmoebaOutOfPlaneBendForce& force2 = *copy;
ASSERT_EQUAL(force1.getForceGroup(), force2.getForceGroup());
ASSERT_EQUAL(force1.usesPeriodicBoundaryConditions(), force2.usesPeriodicBoundaryConditions());
ASSERT_EQUAL(force1.getAmoebaGlobalOutOfPlaneBendCubic(), force2.getAmoebaGlobalOutOfPlaneBendCubic());
ASSERT_EQUAL(force1.getAmoebaGlobalOutOfPlaneBendQuartic(), force2.getAmoebaGlobalOutOfPlaneBendQuartic());
ASSERT_EQUAL(force1.getAmoebaGlobalOutOfPlaneBendPentic(), force2.getAmoebaGlobalOutOfPlaneBendPentic());
ASSERT_EQUAL(force1.getAmoebaGlobalOutOfPlaneBendSextic(), force2.getAmoebaGlobalOutOfPlaneBendSextic());
ASSERT_EQUAL(force1.getNumOutOfPlaneBends(), force2.getNumOutOfPlaneBends());
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force1.getNumOutOfPlaneBends()); ii++) {
int a1, a2, a3, a4, b1, b2, b3, b4;
double ka, kb;
force1.getOutOfPlaneBendParameters(ii, a1, a2, a3, a4, ka);
force2.getOutOfPlaneBendParameters(ii, b1, b2, b3, b4, kb);
ASSERT_EQUAL(a1, b1);
ASSERT_EQUAL(a2, b2);
ASSERT_EQUAL(a3, b3);
ASSERT_EQUAL(a4, b4);
ASSERT_EQUAL(ka, kb);
}
}
int main() {
try {
registerAmoebaSerializationProxies();
testSerialization();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment