Commit 1db349e5 authored by Peter Eastman's avatar Peter Eastman
Browse files

Major cleanup of the AMOEBA API

parent a919f305
......@@ -176,7 +176,6 @@ public:
@param numParticles number of particles
@param particlePositions Cartesian coordinates of particles
@param indexIVs position index for associated reducing particle
@param indexClasses class index for combining sigmas/epsilons (not currently used)
@param sigmas particle sigmas
@param epsilons particle epsilons
@param reductions particle reduction factors
......@@ -189,7 +188,6 @@ public:
RealOpenMM calculateForceAndEnergy( int numParticles, const std::vector<OpenMM::RealVec>& particlePositions,
const std::vector<int>& indexIVs,
const std::vector<int>& indexClasses,
const std::vector<RealOpenMM>& sigmas, const std::vector<RealOpenMM>& epsilons,
const std::vector<RealOpenMM>& reductions,
const std::vector< std::vector<int> >& vdwExclusions,
......@@ -255,7 +253,6 @@ private:
@param numParticles number of particles
@param particlePositions Cartesian coordinates of particles
@param indexIVs position index for associated reducing particle
@param indexClasses class index for combining sigmas/epsilons (not currently used)
@param sigmas particle sigmas
@param epsilons particle epsilons
@param reductions particle reduction factors
......@@ -268,7 +265,6 @@ private:
RealOpenMM calculateForceAndEnergyNoCutoff( int numParticles, const std::vector<OpenMM::RealVec>& particlePositions,
const std::vector<int>& indexIVs,
const std::vector<int>& indexClasses,
const std::vector<RealOpenMM>& sigmas, const std::vector<RealOpenMM>& epsilons,
const std::vector<RealOpenMM>& reductions,
const std::vector< std::vector<int> >& vdwExclusions,
......@@ -281,7 +277,6 @@ private:
@param numParticles number of particles
@param particlePositions Cartesian coordinates of particles
@param indexIVs position index for associated reducing particle
@param indexClasses class index for combining sigmas/epsilons (not currently used)
@param sigmas particle sigmas
@param epsilons particle epsilons
@param reductions particle reduction factors
......@@ -294,7 +289,6 @@ private:
RealOpenMM calculateForceAndEnergyApplyCutoff( int numParticles, const std::vector<OpenMM::RealVec>& particlePositions,
const std::vector<int>& indexIVs,
const std::vector<int>& indexClasses,
const std::vector<RealOpenMM>& sigmas, const std::vector<RealOpenMM>& epsilons,
const std::vector<RealOpenMM>& reductions,
const std::vector< std::vector<int> >& vdwExclusions,
......
/* -------------------------------------------------------------------------- *
* 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 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 ReferenceAmoebaTorsionForce.
*/
#include "openmm/internal/AssertionUtilities.h"
//#include "AmoebaTinkerParameterFile.h"
#include "openmm/Context.h"
#include "OpenMMAmoeba.h"
#include "openmm/System.h"
#include "openmm/LangevinIntegrator.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
const double TOL = 1e-3;
#define PI_M 3.141592653589
#define RADIAN 57.29577951308
/* ---------------------------------------------------------------------------------------
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 computeAmoebaTorsionForce(int bondIndex, std::vector<Vec3>& positions, AmoebaTorsionForce& amoebaTorsionForce,
std::vector<Vec3>& forces, double* energy, FILE* log ) {
int particle1, particle2, particle3, particle4;
std::vector<double> torsion1;
std::vector<double> torsion2;
std::vector<double> torsion3;
torsion1.resize(3);
torsion2.resize(3);
torsion3.resize(3);
amoebaTorsionForce.getTorsionParameters(bondIndex, particle1, particle2, particle3, particle4, torsion1, torsion2, torsion3);
std::vector< std::vector<double> > torsions;
torsions.push_back( torsion1 );
torsions.push_back( torsion2 );
torsions.push_back( torsion3 );
#ifdef AMOEBA_DEBUG
if( log ){
(void) fprintf( log, "computeAmoebaTorsionForce: bond %d [%d %d %d %d]\n",
bondIndex, particle1, particle2, particle3, particle4 );
for( unsigned int ii = 0; ii < 3; ii++ ){
(void) fprintf( log, " [%10.3e %10.3e %10.3e]\n", torsions[ii][0], torsions[ii][1], torsions[ii][2] );
}
(void) fflush( log );
}
#endif
enum { BA, CB, DC, CA, DB, LastDeltaIndex };
double deltaR[LastDeltaIndex][3];
for( int ii = 0; ii < 3; ii++ ){
deltaR[BA][ii] = positions[particle2][ii] - positions[particle1][ii];
deltaR[CB][ii] = positions[particle3][ii] - positions[particle2][ii];
deltaR[DC][ii] = positions[particle4][ii] - positions[particle3][ii];
deltaR[CA][ii] = positions[particle3][ii] - positions[particle1][ii];
deltaR[DB][ii] = positions[particle4][ii] - positions[particle2][ii];
}
enum { Xt, Xu, Xtu, LastXtIndex };
double crossProducts[LastXtIndex][3];
crossProductVector3( deltaR[BA], deltaR[CB], crossProducts[Xt] );
crossProductVector3( deltaR[CB], deltaR[DC], crossProducts[Xu] );
crossProductVector3( crossProducts[Xt], crossProducts[Xu], crossProducts[Xtu] );
double rT2 = dotVector3( crossProducts[Xt], crossProducts[Xt] );
double rU2 = dotVector3( crossProducts[Xu], crossProducts[Xu] );
double rTrU = sqrt( rT2*rU2 );
if( rTrU <= 0.0 ){
return;
}
double rCB = dotVector3( deltaR[CB], deltaR[CB] );
rCB = sqrt( rCB );
// ---------------------------------------------------------------------------------------
// cos(w), cos(2w), cos(3w), ...
// sin(w), sin(2w), sin(3w), ...
double cosine[6], sine[6];
cosine[0] = dotVector3( crossProducts[Xt], crossProducts[Xu] );
cosine[0] /= rTrU;
sine[0] = dotVector3( deltaR[CB], crossProducts[Xtu] );
sine[0] /= (rCB*rTrU);
for( int ii = 1; ii < 3; ii++ ){
cosine[ii] = cosine[0]*cosine[ii-1] - sine[0]* sine[ii-1];
sine[ii] = cosine[0]* sine[ii-1] + sine[0]*cosine[ii-1];
}
// ---------------------------------------------------------------------------------------
// dEdPhi prefactor
double dEdPhi = 0.0;
for( int ii = 0; ii < 3; ii++ ){
dEdPhi += torsions[ii][0]*((double) (ii+1))*( cosine[ii]*sin( torsions[ii][1] ) - sine[ii]*cos( torsions[ii][1] ) );
}
// ---------------------------------------------------------------------------------------
// dEdtu[0] = dEdT
// dEdtu[1] = dEdU
// tempVector[0] == dEdA: dEdT x CB
// tempVector[1] == dEdB: (CA x dEdT) + (dEdU x DC)
// tempVector[2] == dEdC: (dEdT x BA) + (DB x dEdU)
// tempVector[3] == dEdD: (dEdU x CB)
double dEdtu[2][3];
double tempVector[6][3];
// dEdT & dEdU
crossProductVector3( crossProducts[Xt], deltaR[CB], tempVector[0] );
crossProductVector3( crossProducts[Xu], deltaR[CB], tempVector[1] );
double norm[2] = { dEdPhi/(rT2*rCB ), -dEdPhi/(rU2*rCB ) };
for( int jj = 0; jj < 2; jj++ ){
for( int ii = 0; ii < 3; ii++ ){
dEdtu[jj][ii] = norm[jj]*tempVector[jj][ii];
}
}
// dEdA
crossProductVector3( dEdtu[0], deltaR[CB], tempVector[0] );
// dEdB
crossProductVector3( deltaR[CA], dEdtu[0], tempVector[4] );
crossProductVector3( dEdtu[1], deltaR[DC], tempVector[1] );
// dEdC
crossProductVector3( dEdtu[0], deltaR[BA], tempVector[5] );
crossProductVector3( deltaR[DB], dEdtu[1], tempVector[2] );
for( int jj = 0; jj < 3; jj++ ){
tempVector[1][jj] += tempVector[4][jj];
tempVector[2][jj] += tempVector[5][jj];
}
// dEdD
crossProductVector3( dEdtu[1], deltaR[CB], tempVector[3] );
// ---------------------------------------------------------------------------------------
// accumulate forces and energy
forces[particle1][0] -= tempVector[0][0];
forces[particle1][1] -= tempVector[0][1];
forces[particle1][2] -= tempVector[0][2];
forces[particle2][0] -= tempVector[1][0];
forces[particle2][1] -= tempVector[1][1];
forces[particle2][2] -= tempVector[1][2];
forces[particle3][0] -= tempVector[2][0];
forces[particle3][1] -= tempVector[2][1];
forces[particle3][2] -= tempVector[2][2];
forces[particle4][0] -= tempVector[3][0];
forces[particle4][1] -= tempVector[3][1];
forces[particle4][2] -= tempVector[3][2];
double energyTerm = 0.0;
for( int ii = 0; ii < 3; ii++ ){
energyTerm += torsions[ii][0]*( 1.0 + cosine[ii]*cos( torsions[ii][1] ) + sine[ii]*sin( torsions[ii][1] ) );
}
*energy += energyTerm;
}
static void computeAmoebaTorsionForces( Context& context, AmoebaTorsionForce& amoebaTorsionForce,
std::vector<Vec3>& expectedForces, double* expectedEnergy, FILE* log ) {
// 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 < amoebaTorsionForce.getNumTorsions(); ii++ ){
computeAmoebaTorsionForce(ii, positions, amoebaTorsionForce, expectedForces, expectedEnergy, log );
}
#ifdef AMOEBA_DEBUG
if( log ){
(void) fprintf( log, "computeAmoebaTorsionForces: expected energy=%14.7e\n", *expectedEnergy );
for( unsigned int ii = 0; ii < positions.size(); ii++ ){
(void) fprintf( log, "%6u [%14.7e %14.7e %14.7e]\n", ii, expectedForces[ii][0], expectedForces[ii][1], expectedForces[ii][2] );
}
(void) fflush( log );
}
#endif
return;
}
void compareWithExpectedForceAndEnergy( Context& context, AmoebaTorsionForce& amoebaTorsionForce,
double tolerance, const std::string& idString, FILE* log) {
std::vector<Vec3> expectedForces;
double expectedEnergy;
computeAmoebaTorsionForces( context, amoebaTorsionForce, expectedForces, &expectedEnergy, log );
State state = context.getState(State::Forces | State::Energy);
const std::vector<Vec3> forces = state.getForces();
#ifdef AMOEBA_DEBUG
if( log ){
(void) fprintf( log, "computeAmoebaTorsionForces: expected energy=%14.7e %14.7e\n", expectedEnergy, state.getPotentialEnergy() );
for( unsigned int ii = 0; ii < forces.size(); ii++ ){
(void) fprintf( log, "%6u [%14.7e %14.7e %14.7e] [%14.7e %14.7e %14.7e]\n", ii,
expectedForces[ii][0], expectedForces[ii][1], expectedForces[ii][2], forces[ii][0], forces[ii][1], forces[ii][2] );
}
(void) fflush( log );
}
#endif
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 testOneTorsion( FILE* log ) {
System system;
int numberOfParticles = 4;
for( int ii = 0; ii < numberOfParticles; ii++ ){
system.addParticle(1.0);
}
LangevinIntegrator integrator(0.0, 0.1, 0.01);
AmoebaTorsionForce* amoebaTorsionForce = new AmoebaTorsionForce();
std::vector<double> torsion1;
torsion1.push_back( 0.619500000E+00 );
torsion1.push_back( 0.000000000E+00 );
std::vector<double> torsion2;
torsion2.push_back( -0.202500000E+00 );
torsion2.push_back( 0.180000000E+03 );
std::vector<double> torsion3;
torsion3.push_back( 0.175000000E-01 );
torsion3.push_back( 0.000000000E+00 );
amoebaTorsionForce->addTorsion(0, 1, 2, 3, torsion1, torsion2, torsion3 );
system.addForce(amoebaTorsionForce);
Context context(system, integrator, Platform::getPlatformByName( "Reference"));
std::vector<Vec3> positions(numberOfParticles);
positions[0] = Vec3( 0.278860000E+01, 0.264630000E+01, 0.426300000E+00 );
positions[1] = Vec3( 0.273400000E+01, 0.244300000E+01, 0.261400000E+00 );
positions[2] = Vec3( 0.262660000E+01, 0.254130000E+01, 0.284200000E+00 );
positions[3] = Vec3( 0.269130000E+01, 0.266390000E+01, 0.353100000E+00 );
context.setPositions(positions);
compareWithExpectedForceAndEnergy( context, *amoebaTorsionForce, TOL, "testOneTorsion", log );
}
int main( int numberOfArguments, char* argv[] ) {
try {
std::cout << "TestReferenceAmoebaTorsionForce running test..." << std::endl;
Platform::loadPluginsFromDirectory( Platform::getDefaultPluginsDirectory() );
//FILE* log = stderr;
FILE* log = NULL;
//FILE* log = fopen( "AmoebaTorsionForce.log", "w" );;
testOneTorsion( log );
#ifdef AMOEBA_DEBUG
if( log && log != stderr )
(void) fclose( log );
#endif
}
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 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 Cuda implementation of UreyBradleyForce.
*/
#include "openmm/internal/AssertionUtilities.h"
//#include "AmoebaTinkerParameterFile.h"
#include "openmm/Context.h"
#include "OpenMMAmoeba.h"
#include "openmm/System.h"
#include "openmm/LangevinIntegrator.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
const double TOL = 1e-5;
static void computeAmoebaUreyBradleyForce(int bondIndex, std::vector<Vec3>& positions, AmoebaUreyBradleyForce& amoebaUreyBradleyForce,
std::vector<Vec3>& forces, double* energy ) {
int particle1, particle2;
double bondLength;
double quadraticK;
double cubicK = amoebaUreyBradleyForce.getAmoebaGlobalUreyBradleyCubic();
double quarticK = amoebaUreyBradleyForce.getAmoebaGlobalUreyBradleyQuartic();
amoebaUreyBradleyForce.getUreyBradleyParameters(bondIndex, particle1, particle2, bondLength, quadraticK );
double deltaR[3];
double r2 = 0.0;
for( int ii = 0; ii < 3; ii++ ){
deltaR[ii] = positions[particle2][ii] - positions[particle1][ii];
r2 += deltaR[ii]*deltaR[ii];
}
double r = sqrt( r2 );
double bondDelta = (r - bondLength);
double bondDelta2 = bondDelta*bondDelta;
double dEdR = 1.0 + 1.5*cubicK*bondDelta + 2.0*quarticK*bondDelta2;
dEdR *= (r > 0.0) ? (2.0*quadraticK*bondDelta)/r : 0.0;
forces[particle1][0] += dEdR*deltaR[0];
forces[particle1][1] += dEdR*deltaR[1];
forces[particle1][2] += dEdR*deltaR[2];
forces[particle2][0] -= dEdR*deltaR[0];
forces[particle2][1] -= dEdR*deltaR[1];
forces[particle2][2] -= dEdR*deltaR[2];
*energy += (1.0f + cubicK*bondDelta + quarticK*bondDelta2)*quadraticK*bondDelta2;
}
static void computeAmoebaUreyBradleyForces( Context& context, AmoebaUreyBradleyForce& amoebaUreyBradleyForce,
std::vector<Vec3>& expectedForces, double* expectedEnergy, FILE* log ) {
// 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 < amoebaUreyBradleyForce.getNumInteractions(); ii++ ){
computeAmoebaUreyBradleyForce(ii, positions, amoebaUreyBradleyForce, expectedForces, expectedEnergy );
}
#ifdef AMOEBA_DEBUG
if( log ){
(void) fprintf( log, "computeAmoebaUreyBradleyForces: expected energy=%15.7e\n", *expectedEnergy );
for( unsigned int ii = 0; ii < positions.size(); ii++ ){
(void) fprintf( log, "%6u [%15.7e %15.7e %15.7e]\n", ii, expectedForces[ii][0], expectedForces[ii][1], expectedForces[ii][2] );
}
(void) fflush( log );
}
#endif
return;
}
void compareWithExpectedForceAndEnergy( Context& context, AmoebaUreyBradleyForce& amoebaUreyBradleyForce, double tolerance, const std::string& idString, FILE* log) {
std::vector<Vec3> expectedForces;
double expectedEnergy;
computeAmoebaUreyBradleyForces( context, amoebaUreyBradleyForce, expectedForces, &expectedEnergy, NULL );
State state = context.getState(State::Forces | State::Energy);
const std::vector<Vec3> forces = state.getForces();
#ifdef AMOEBA_DEBUG
if( log ){
(void) fprintf( log, "computeAmoebaUreyBradleyForces: expected energy=%15.7e %15.7e\n", expectedEnergy, state.getPotentialEnergy() );
for( unsigned int ii = 0; ii < forces.size(); ii++ ){
(void) fprintf( log, "%6u [%15.7e %15.7e %15.7e] [%15.7e %15.7e %15.7e]\n", ii,
expectedForces[ii][0], expectedForces[ii][1], expectedForces[ii][2], forces[ii][0], forces[ii][1], forces[ii][2] );
}
(void) fflush( log );
}
#endif
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 testOneBond( FILE* log ) {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
LangevinIntegrator integrator(0.0, 0.1, 0.01);
AmoebaUreyBradleyForce* amoebaUreyBradleyForce = new AmoebaUreyBradleyForce();
double bondLength = 1.5;
double quadraticK = 1.0;
double cubicK = 2.0;
double quarticicK = 3.0;
amoebaUreyBradleyForce->setAmoebaGlobalUreyBradleyCubic( cubicK );
amoebaUreyBradleyForce->setAmoebaGlobalUreyBradleyQuartic( quarticicK );
amoebaUreyBradleyForce->addUreyBradley(0, 1, bondLength, quadraticK);
system.addForce(amoebaUreyBradleyForce);
Context context(system, integrator, Platform::getPlatformByName( "Reference"));
std::vector<Vec3> positions(2);
positions[0] = Vec3(0, 1, 0);
positions[1] = Vec3(0, 0, 0);
context.setPositions(positions);
compareWithExpectedForceAndEnergy( context, *amoebaUreyBradleyForce, TOL, "testOneBond", log );
}
void testTwoBond( FILE* log ) {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
system.addParticle(1.0);
LangevinIntegrator integrator(0.0, 0.1, 0.01);
AmoebaUreyBradleyForce* amoebaUreyBradleyForce = new AmoebaUreyBradleyForce();
double bondLength = 1.5;
double quadraticK = 1.0;
double cubicK = 2.0;
double quarticicK = 3.0;
amoebaUreyBradleyForce->setAmoebaGlobalUreyBradleyCubic( cubicK );
amoebaUreyBradleyForce->setAmoebaGlobalUreyBradleyQuartic( quarticicK );
amoebaUreyBradleyForce->addUreyBradley(0, 1, bondLength, quadraticK);
amoebaUreyBradleyForce->addUreyBradley(1, 2, bondLength, quadraticK);
system.addForce(amoebaUreyBradleyForce);
Context context(system, integrator, Platform::getPlatformByName( "Reference"));
std::vector<Vec3> positions(3);
positions[0] = Vec3(0, 1, 0);
positions[1] = Vec3(0, 0, 0);
positions[2] = Vec3(1, 0, 1);
context.setPositions(positions);
compareWithExpectedForceAndEnergy( context, *amoebaUreyBradleyForce, TOL, "testTwoBond", log );
}
int main( int numberOfArguments, char* argv[] ) {
try {
std::cout << "TestCudaAmoebaUreyBradleyForce running test..." << std::endl;
Platform::loadPluginsFromDirectory( Platform::getDefaultPluginsDirectory() );
FILE* log = NULL;
//FILE* log = stderr;
//testOneBond( log );
testTwoBond( log );
#ifdef AMOEBA_DEBUG
if( log && log != stderr )
(void) fclose( log );
#endif
}
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;
}
......@@ -62,7 +62,6 @@ void testVdw( FILE* log ) {
std::string epsilonCombiningRule = std::string("HHG");
amoebaVdwForce->setEpsilonCombiningRule( epsilonCombiningRule );
int classIndex = 0;
for( int ii = 0; ii < numberOfParticles; ii++ ){
int indexIV;
double mass, sigma, epsilon, reduction;
......@@ -93,7 +92,7 @@ void testVdw( FILE* log ) {
exclusions.push_back ( 5 );
}
system.addParticle(mass);
amoebaVdwForce->addParticle( indexIV, classIndex, sigma, epsilon, reduction );
amoebaVdwForce->addParticle( indexIV, sigma, epsilon, reduction );
amoebaVdwForce->setParticleExclusions( ii, exclusions );
}
LangevinIntegrator integrator(0.0, 0.1, 0.01);
......@@ -135,12 +134,11 @@ void testVdw( FILE* log ) {
}
for( int ii = 0; ii < amoebaVdwForce->getNumParticles(); ii++ ){
int indexIV;
int classIndex;
double sigma, epsilon, reduction;
amoebaVdwForce->getParticleParameters( ii, indexIV, classIndex, sigma, epsilon, reduction );
amoebaVdwForce->getParticleParameters( ii, indexIV, sigma, epsilon, reduction );
sigma *= AngstromToNm;
epsilon *= CalToJoule;
amoebaVdwForce->setParticleParameters( ii, indexIV, classIndex, sigma, epsilon, reduction );
amoebaVdwForce->setParticleParameters( ii, indexIV, sigma, epsilon, reduction );
}
platformName = "Reference";
Context context(system, integrator, Platform::getPlatformByName( platformName ) );
......@@ -185,44 +183,42 @@ void setupAndGetForcesEnergyVdwAmmonia( const std::string& sigmaCombiningRule, c
int numberOfParticles = 8;
amoebaVdwForce->setSigmaCombiningRule( sigmaCombiningRule );
amoebaVdwForce->setEpsilonCombiningRule( epsilonCombiningRule );
amoebaVdwForce->setUseNeighborList( 1 );
amoebaVdwForce->setCutoff( cutoff );
if( boxDimension > 0.0 ){
Vec3 a( boxDimension, 0.0, 0.0 );
Vec3 b( 0.0, boxDimension, 0.0 );
Vec3 c( 0.0, 0.0, boxDimension );
system.setDefaultPeriodicBoxVectors( a, b, c );
amoebaVdwForce->setPBC( 1 );
amoebaVdwForce->setNonbondedMethod(AmoebaVdwForce::CutoffPeriodic);
} else {
amoebaVdwForce->setPBC( 0 );
amoebaVdwForce->setNonbondedMethod(AmoebaVdwForce::NoCutoff);
}
// addParticle: ivIndex, radius, epsilon, reductionFactor
int classIndex = 0;
system.addParticle( 1.4007000e+01 );
amoebaVdwForce->addParticle( 0, classIndex, 1.8550000e-01, 4.3932000e-01, 0.0000000e+00 );
amoebaVdwForce->addParticle( 0, 1.8550000e-01, 4.3932000e-01, 0.0000000e+00 );
system.addParticle( 1.0080000e+00 );
amoebaVdwForce->addParticle( 0, classIndex, 1.3500000e-01, 8.3680000e-02, 9.1000000e-01 );
amoebaVdwForce->addParticle( 0, 1.3500000e-01, 8.3680000e-02, 9.1000000e-01 );
system.addParticle( 1.0080000e+00 );
amoebaVdwForce->addParticle( 0, classIndex, 1.3500000e-01, 8.3680000e-02, 9.1000000e-01 );
amoebaVdwForce->addParticle( 0, 1.3500000e-01, 8.3680000e-02, 9.1000000e-01 );
system.addParticle( 1.0080000e+00 );
amoebaVdwForce->addParticle( 0, classIndex, 1.3500000e-01, 8.3680000e-02, 9.1000000e-01 );
amoebaVdwForce->addParticle( 0, 1.3500000e-01, 8.3680000e-02, 9.1000000e-01 );
system.addParticle( 1.4007000e+01 );
amoebaVdwForce->addParticle( 4, classIndex, 1.8550000e-01, 4.3932000e-01, 0.0000000e+00 );
amoebaVdwForce->addParticle( 4, 1.8550000e-01, 4.3932000e-01, 0.0000000e+00 );
system.addParticle( 1.0080000e+00 );
amoebaVdwForce->addParticle( 4, classIndex, 1.3500000e-01, 8.3680000e-02, 9.1000000e-01 );
amoebaVdwForce->addParticle( 4, 1.3500000e-01, 8.3680000e-02, 9.1000000e-01 );
system.addParticle( 1.0080000e+00 );
amoebaVdwForce->addParticle( 4, classIndex, 1.3500000e-01, 8.3680000e-02, 9.1000000e-01 );
amoebaVdwForce->addParticle( 4, 1.3500000e-01, 8.3680000e-02, 9.1000000e-01 );
system.addParticle( 1.0080000e+00 );
amoebaVdwForce->addParticle( 4, classIndex, 1.3500000e-01, 8.3680000e-02, 9.1000000e-01 );
amoebaVdwForce->addParticle( 4, 1.3500000e-01, 8.3680000e-02, 9.1000000e-01 );
// ParticleExclusions
......@@ -457,7 +453,7 @@ void testVdwTaper( FILE* log ) {
std::string testName = "testVdwTaper";
int numberOfParticles = 8;
double boxDimension = -1.0;
double boxDimension = 50.0;
double cutoff = 0.25;
std::vector<Vec3> forces;
......
......@@ -38,7 +38,7 @@
namespace OpenMM {
/**
* This is a proxy for serializing AmoebaUreyBradleyForce objects.
* This is a proxy for serializing AmoebaGeneralizedKirkwoodForce objects.
*/
class OPENMM_EXPORT AmoebaGeneralizedKirkwoodForceProxy : public SerializationProxy {
......
......@@ -38,7 +38,7 @@
namespace OpenMM {
/**
* This is a proxy for serializing AmoebaUreyBradleyForce objects.
* This is a proxy for serializing AmoebaMultipoleForce objects.
*/
class OPENMM_EXPORT AmoebaMultipoleForceProxy : public SerializationProxy {
......@@ -50,4 +50,4 @@ public:
} // namespace OpenMM
#endif /*OPENMM_AMOEBA_UREY_BRADLEY_FORCE_PROXY_H_*/
#endif /*OPENMM_AMOEBA_MULTIPOLE_FORCE_PROXY_H_*/
......@@ -38,7 +38,7 @@
namespace OpenMM {
/**
* This is a proxy for serializing AmoebaUreyBradleyForce objects.
* This is a proxy for serializing AmoebaStretchBendForce objects.
*/
class OPENMM_EXPORT AmoebaStretchBendForceProxy : public SerializationProxy {
......
#ifndef OPENMM_AMOEBA_TORSION_FORCE_PROXY_H_
#define OPENMM_AMOEBA_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/windowsExport.h"
#include "openmm/serialization/SerializationProxy.h"
namespace OpenMM {
/**
* This is a proxy for serializing AmoebaTorsionForce objects.
*/
class OPENMM_EXPORT AmoebaTorsionForceProxy : public SerializationProxy {
public:
AmoebaTorsionForceProxy();
void serialize(const void* object, SerializationNode& node) const;
void* deserialize(const SerializationNode& node) const;
};
} // namespace OpenMM
#endif /*OPENMM_AMOEBA_TORSION_FORCE_PROXY_H_*/
#ifndef OPENMM_AMOEBA_UREY_BRADLEY_FORCE_PROXY_H_
#define OPENMM_AMOEBA_UREY_BRADLEY_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/windowsExport.h"
#include "openmm/serialization/SerializationProxy.h"
namespace OpenMM {
/**
* This is a proxy for serializing AmoebaUreyBradleyForce objects.
*/
class OPENMM_EXPORT AmoebaUreyBradleyForceProxy : public SerializationProxy {
public:
AmoebaUreyBradleyForceProxy();
void serialize(const void* object, SerializationNode& node) const;
void* deserialize(const SerializationNode& node) const;
};
} // namespace OpenMM
#endif /*OPENMM_AMOEBA_UREY_BRADLEY_FORCE_PROXY_H_*/
......@@ -38,7 +38,7 @@
namespace OpenMM {
/**
* This is a proxy for serializing AmoebaUreyBradleyForce objects.
* This is a proxy for serializing AmoebaVdwForce objects.
*/
class OPENMM_EXPORT AmoebaVdwForceProxy : public SerializationProxy {
......
......@@ -38,7 +38,7 @@
namespace OpenMM {
/**
* This is a proxy for serializing AmoebaUreyBradleyForce objects.
* This is a proxy for serializing AmoebaWcaDispersionForce objects.
*/
class OPENMM_EXPORT AmoebaWcaDispersionForceProxy : public SerializationProxy {
......
......@@ -132,9 +132,9 @@ void* AmoebaMultipoleForceProxy::deserialize(const SerializationNode& node) cons
try {
force->setNonbondedMethod( static_cast<AmoebaMultipoleForce::AmoebaNonbondedMethod>(node.getIntProperty( "nonbondedMethod" )) );
force->setNonbondedMethod( static_cast<AmoebaMultipoleForce::NonbondedMethod>(node.getIntProperty( "nonbondedMethod" )) );
if( node.getIntProperty("version") == 2 ){
force->setPolarizationType( static_cast<AmoebaMultipoleForce::AmoebaPolarizationType>(node.getIntProperty( "polarizationType" )) );
force->setPolarizationType( static_cast<AmoebaMultipoleForce::PolarizationType>(node.getIntProperty( "polarizationType" )) );
}
//force->setPmeBSplineOrder( node.getIntProperty( "pmeBSplineOrder" ) );
//force->setMutualInducedIterationMethod( static_cast<AmoebaMultipoleForce::MutualInducedIterationMethod>(node.getIntProperty( "mutualInducedIterationMethod" ) ) );
......
......@@ -48,9 +48,7 @@
#include "openmm/AmoebaOutOfPlaneBendForce.h"
#include "openmm/AmoebaPiTorsionForce.h"
#include "openmm/AmoebaStretchBendForce.h"
#include "openmm/AmoebaTorsionForce.h"
#include "openmm/AmoebaTorsionTorsionForce.h"
#include "openmm/AmoebaUreyBradleyForce.h"
#include "openmm/AmoebaVdwForce.h"
#include "openmm/AmoebaWcaDispersionForce.h"
......@@ -64,9 +62,7 @@
#include "openmm/serialization/AmoebaOutOfPlaneBendForceProxy.h"
#include "openmm/serialization/AmoebaPiTorsionForceProxy.h"
#include "openmm/serialization/AmoebaStretchBendForceProxy.h"
#include "openmm/serialization/AmoebaTorsionForceProxy.h"
#include "openmm/serialization/AmoebaTorsionTorsionForceProxy.h"
#include "openmm/serialization/AmoebaUreyBradleyForceProxy.h"
#include "openmm/serialization/AmoebaVdwForceProxy.h"
#include "openmm/serialization/AmoebaWcaDispersionForceProxy.h"
......@@ -93,9 +89,7 @@ extern "C" void registerAmoebaSerializationProxies() {
SerializationProxy::registerProxy(typeid(AmoebaOutOfPlaneBendForce), new AmoebaOutOfPlaneBendForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaPiTorsionForce), new AmoebaPiTorsionForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaStretchBendForce), new AmoebaStretchBendForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaTorsionForce), new AmoebaTorsionForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaTorsionTorsionForce), new AmoebaTorsionTorsionForceProxy());
SerializationProxy::registerProxy(typeid(AmoebaUreyBradleyForce), new AmoebaUreyBradleyForceProxy());
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 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/AmoebaTorsionForceProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include "openmm/Force.h"
#include "openmm/AmoebaTorsionForce.h"
#include <sstream>
using namespace OpenMM;
using namespace std;
AmoebaTorsionForceProxy::AmoebaTorsionForceProxy() : SerializationProxy("AmoebaTorsionForce") {
}
static void addTorsionValues( SerializationNode& torsion, const std::vector<double>& torsionValues ){
for (unsigned int jj = 0; jj < torsionValues.size(); jj++) {
torsion.createChildNode("Value").setDoubleProperty("v", torsionValues[jj]);
}
}
static void loadTorsionValues( SerializationNode& torsion, std::vector<double>& torsionValues ){
int size = torsion.getIntProperty("size");
torsionValues.resize(size);
for (unsigned int jj = 0; jj < static_cast<unsigned int>(size); jj++) {
torsionValues[jj] = ( torsion.getChildren()[jj].getDoubleProperty("v") );
}
}
void AmoebaTorsionForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1);
const AmoebaTorsionForce& force = *reinterpret_cast<const AmoebaTorsionForce*>(object);
SerializationNode& bonds = node.createChildNode("Torsion").setIntProperty("size", force.getNumTorsions() );
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumTorsions()); ii++) {
int particle1, particle2, particle3, particle4;
std::vector<double> torsion1;
std::vector<double> torsion2;
std::vector<double> torsion3;
force.getTorsionParameters(ii, particle1, particle2, particle3, particle4, torsion1, torsion2, torsion3);
SerializationNode& torsionBond = bonds.createChildNode("Torsion");
torsionBond.setIntProperty("p1", particle1).setIntProperty("p2", particle2).setIntProperty("p3", particle3).setIntProperty("p4", particle4);
SerializationNode& torsionVector1 = torsionBond.createChildNode("Torsion1").setIntProperty("size", torsion1.size());
addTorsionValues( torsionVector1, torsion1 );
SerializationNode& torsionVector2 = torsionBond.createChildNode("Torsion2").setIntProperty("size", torsion2.size());
addTorsionValues( torsionVector2, torsion2 );
SerializationNode& torsionVector3 = torsionBond.createChildNode("Torsion3").setIntProperty("size", torsion3.size());
addTorsionValues( torsionVector3, torsion3 );
}
}
void* AmoebaTorsionForceProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1)
throw OpenMMException("Unsupported version number");
AmoebaTorsionForce* force = new AmoebaTorsionForce();
try {
const SerializationNode& bonds = node.getChildNode("Torsion");
vector<SerializationNode> children = bonds.getChildren();
for (unsigned int i = 0; i < children.size(); i++) {
SerializationNode& bond = children[i];
std::vector<double> torsion1;
std::vector<double> torsion2;
std::vector<double> torsion3;
SerializationNode& torsionNode1 = bond.getChildNode("Torsion1");
loadTorsionValues( torsionNode1, torsion1 );
SerializationNode& torsionNode2 = bond.getChildNode("Torsion2");
loadTorsionValues( torsionNode2, torsion2 );
SerializationNode& torsionNode3 = bond.getChildNode("Torsion3");
loadTorsionValues( torsionNode3, torsion3 );
force->addTorsion(bond.getIntProperty("p1"), bond.getIntProperty("p2"), bond.getIntProperty("p3"), bond.getIntProperty("p4"), torsion1, torsion2, torsion3 );
}
}
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 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/AmoebaUreyBradleyForceProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include "openmm/Force.h"
#include "openmm/AmoebaUreyBradleyForce.h"
#include <sstream>
using namespace OpenMM;
using namespace std;
AmoebaUreyBradleyForceProxy::AmoebaUreyBradleyForceProxy() : SerializationProxy("AmoebaUreyBradleyForce") {
}
void AmoebaUreyBradleyForceProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1);
const AmoebaUreyBradleyForce& force = *reinterpret_cast<const AmoebaUreyBradleyForce*>(object);
node.setDoubleProperty("UreyBradleyCubic", force.getAmoebaGlobalUreyBradleyCubic());
node.setDoubleProperty("UreyBradleyQuartic", force.getAmoebaGlobalUreyBradleyQuartic());
SerializationNode& bonds = node.createChildNode("UreyBradley").setIntProperty( "size", force.getNumInteractions() );
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumInteractions()); ii++) {
int particle1, particle2;
double distance, k;
force.getUreyBradleyParameters(ii, particle1, particle2, distance, k);
bonds.createChildNode("Ixn").setIntProperty( "index", ii ).setIntProperty("p1", particle1).setIntProperty("p2", particle2).setDoubleProperty("d", distance).setDoubleProperty("k", k);
}
}
void* AmoebaUreyBradleyForceProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1)
throw OpenMMException("Unsupported version number");
AmoebaUreyBradleyForce* force = new AmoebaUreyBradleyForce();
try {
force->setAmoebaGlobalUreyBradleyCubic(node.getDoubleProperty( "UreyBradleyCubic"));
force->setAmoebaGlobalUreyBradleyQuartic(node.getDoubleProperty("UreyBradleyQuartic"));
const SerializationNode& bonds = node.getChildNode("UreyBradley");
for (unsigned int ii = 0; ii < bonds.getChildren().size(); ii++) {
const SerializationNode& bond = bonds.getChildren()[ii];
force->addUreyBradley(bond.getIntProperty("p1"), bond.getIntProperty("p2"), bond.getDoubleProperty("d"), bond.getDoubleProperty("k"));
}
}
catch (...) {
delete force;
throw;
}
return force;
}
......@@ -45,22 +45,21 @@ void AmoebaVdwForceProxy::serialize(const void* object, SerializationNode& node)
node.setIntProperty("version", 1);
const AmoebaVdwForce& force = *reinterpret_cast<const AmoebaVdwForce*>(object);
node.setStringProperty("SigmaCombiningRule", force.getSigmaCombiningRule());
node.setStringProperty("EpsilonCombiningRule", force.getEpsilonCombiningRule());
node.setDoubleProperty("VdwCutoff", force.getCutoff());
node.setStringProperty("SigmaCombiningRule", force.getSigmaCombiningRule());
node.setStringProperty("EpsilonCombiningRule", force.getEpsilonCombiningRule());
node.setDoubleProperty("VdwCutoff", force.getCutoff());
node.setIntProperty( "VdwUseNeighborList", force.getUseNeighborList());
node.setIntProperty( "VdwPBC", force.getPBC());
node.setIntProperty("method", (int) force.getNonbondedMethod());
SerializationNode& particles = node.createChildNode("VdwParticles").setIntProperty("size", force.getNumParticles() );
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumParticles()); ii++) {
int ivIndex, classIndex;
int ivIndex;
double sigma, epsilon, reductionFactor;
force.getParticleParameters( ii, ivIndex, classIndex, sigma, epsilon, reductionFactor );
force.getParticleParameters( ii, ivIndex, sigma, epsilon, reductionFactor );
SerializationNode& particle = particles.createChildNode("Particle");
particle.setIntProperty("index", ii).setIntProperty("ivIndex", ivIndex).setIntProperty("classIndex", classIndex).setDoubleProperty("sigma", sigma).setDoubleProperty("epsilon", epsilon).setDoubleProperty("reductionFactor", reductionFactor);
particle.setIntProperty("index", ii).setIntProperty("ivIndex", ivIndex).setDoubleProperty("sigma", sigma).setDoubleProperty("epsilon", epsilon).setDoubleProperty("reductionFactor", reductionFactor);
std::vector< int > exclusions;
force.getParticleExclusions( ii, exclusions );
......@@ -80,16 +79,15 @@ void* AmoebaVdwForceProxy::deserialize(const SerializationNode& node) const {
AmoebaVdwForce* force = new AmoebaVdwForce();
try {
force->setSigmaCombiningRule( node.getStringProperty( "SigmaCombiningRule" ) );
force->setEpsilonCombiningRule( node.getStringProperty( "EpsilonCombiningRule" ) );
force->setCutoff( node.getDoubleProperty( "VdwCutoff" ) );
force->setUseNeighborList( node.getIntProperty( "VdwUseNeighborList" ) );
force->setPBC( node.getIntProperty( "VdwPBC" ) );
force->setSigmaCombiningRule(node.getStringProperty( "SigmaCombiningRule" ) );
force->setEpsilonCombiningRule(node.getStringProperty( "EpsilonCombiningRule" ) );
force->setCutoff(node.getDoubleProperty( "VdwCutoff" ) );
force->setNonbondedMethod((AmoebaVdwForce::NonbondedMethod) node.getIntProperty("method"));
const SerializationNode& particles = node.getChildNode("VdwParticles");
for (unsigned int ii = 0; ii < particles.getChildren().size(); ii++) {
const SerializationNode& particle = particles.getChildren()[ii];
force->addParticle(particle.getIntProperty("ivIndex"), particle.getIntProperty("classIndex"), particle.getDoubleProperty("sigma"), particle.getDoubleProperty("epsilon"), particle.getDoubleProperty("reductionFactor"));
force->addParticle(particle.getIntProperty("ivIndex"), particle.getDoubleProperty("sigma"), particle.getDoubleProperty("epsilon"), particle.getDoubleProperty("reductionFactor"));
// exclusions
......
/* -------------------------------------------------------------------------- *
* 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/AssertionUtilities.h"
#include "openmm/AmoebaTorsionForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using namespace OpenMM;
using namespace std;
void loadTorsion( std::vector<double>& torsion, double offset ){
torsion.push_back( offset + 1.0 );
torsion.push_back( offset + 2.0 );
// torsion.push_back( offset + 3.0 );
// torsion.push_back( offset + 4.0 );
}
void compareTorsion( std::vector<double> torsionA, std::vector<double> torsionB ){
ASSERT_EQUAL(torsionA.size(), torsionB.size());
for (unsigned int ii = 0; ii < torsionA.size(); ii++) {
ASSERT_EQUAL(torsionA[ii], torsionB[ii]);
}
}
void testSerialization() {
// Create a Force.
AmoebaTorsionForce force1;
for( unsigned int ii = 0; ii < 5; ii++ ){
std::vector<double> torsion1;
std::vector<double> torsion2;
std::vector<double> torsion3;
loadTorsion( torsion1, static_cast<double>(5*ii) + 11.1);
loadTorsion( torsion2, static_cast<double>(5*ii) + 21.2);
loadTorsion( torsion3, static_cast<double>(5*ii) + 31.3);
force1.addTorsion( ii, ii+1,ii+3, ii+4, torsion1, torsion2, torsion3 );
}
// Serialize and then deserialize it.
stringstream buffer;
XmlSerializer::serialize<AmoebaTorsionForce>(&force1, "Force", buffer);
#ifdef AMOEBA_DEBUG
if( 0 ){
FILE* filePtr = fopen("Torsion.xml", "w" );
(void) fprintf( filePtr, "%s", buffer.str().c_str() );
(void) fclose( filePtr );
}
#endif
AmoebaTorsionForce* copy = XmlSerializer::deserialize<AmoebaTorsionForce>(buffer);
// Compare the two forces to see if they are identical.
AmoebaTorsionForce& force2 = *copy;
ASSERT_EQUAL(force1.getNumTorsions(), force2.getNumTorsions());
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force1.getNumTorsions()); ii++) {
int a1, a2, a3, a4, b1, b2, b3, b4;
std::vector<double> torsion1a;
std::vector<double> torsion2a;
std::vector<double> torsion3a;
std::vector<double> torsion1b;
std::vector<double> torsion2b;
std::vector<double> torsion3b;
force1.getTorsionParameters( ii, a1, a2, a3, a4, torsion1a, torsion2a, torsion3a);
force2.getTorsionParameters( ii, b1, b2, b3, b4, torsion1b, torsion2b, torsion3b);
ASSERT_EQUAL(a1, b1);
ASSERT_EQUAL(a2, b2);
ASSERT_EQUAL(a3, b3);
ASSERT_EQUAL(a4, b4);
compareTorsion( torsion1a, torsion1b );
compareTorsion( torsion2a, torsion2b );
compareTorsion( torsion3a, torsion3b );
}
}
int main() {
try {
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 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/AssertionUtilities.h"
#include "openmm/AmoebaUreyBradleyForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using namespace OpenMM;
using namespace std;
void testSerialization() {
// Create a Force.
AmoebaUreyBradleyForce force1;
force1.setAmoebaGlobalUreyBradleyCubic( 12.3 );
force1.setAmoebaGlobalUreyBradleyQuartic( 98.7 );
force1.addUreyBradley(0, 1, 1.0, 2.0);
force1.addUreyBradley(0, 2, 2.0, 2.1);
force1.addUreyBradley(2, 3, 3.0, 2.2);
force1.addUreyBradley(5, 1, 4.0, 2.3);
// Serialize and then deserialize it.
stringstream buffer;
XmlSerializer::serialize<AmoebaUreyBradleyForce>(&force1, "Force", buffer);
AmoebaUreyBradleyForce* copy = XmlSerializer::deserialize<AmoebaUreyBradleyForce>(buffer);
// Compare the two forces to see if they are identical.
AmoebaUreyBradleyForce& force2 = *copy;
ASSERT_EQUAL(force1.getAmoebaGlobalUreyBradleyCubic(), force2.getAmoebaGlobalUreyBradleyCubic());
ASSERT_EQUAL(force1.getAmoebaGlobalUreyBradleyQuartic(), force2.getAmoebaGlobalUreyBradleyQuartic());
ASSERT_EQUAL(force1.getNumInteractions(), force2.getNumInteractions());
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force1.getNumInteractions()); ii++) {
int a1, a2, b1, b2;
double da, db, ka, kb;
force1.getUreyBradleyParameters(ii, a1, a2, da, ka);
force2.getUreyBradleyParameters(ii, b1, b2, db, kb);
ASSERT_EQUAL(a1, b1);
ASSERT_EQUAL(a2, b2);
ASSERT_EQUAL(da, db);
ASSERT_EQUAL(ka, kb);
}
}
int main() {
try {
testSerialization();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
......@@ -45,12 +45,11 @@ void testSerialization() {
force1.setSigmaCombiningRule( "GEOMETRIC" );
force1.setEpsilonCombiningRule( "GEOMETRIC" );
force1.setCutoff( 0.9 );
force1.setUseNeighborList( 1 );
force1.setPBC( 1 );
force1.setNonbondedMethod(AmoebaVdwForce::CutoffPeriodic);
force1.addParticle(0, 1, 1.0, 2.0, 0.9);
force1.addParticle(1, 0, 1.1, 2.1, 0.9);
force1.addParticle(2, 3, 1.3, 4.1, 0.9);
force1.addParticle(0, 1.0, 2.0, 0.9);
force1.addParticle(1, 1.1, 2.1, 0.9);
force1.addParticle(2, 1.3, 4.1, 0.9);
for( unsigned int ii = 0; ii < 3; ii++ ){
std::vector< int > exclusions;
exclusions.push_back( ii );
......@@ -79,24 +78,22 @@ void testSerialization() {
ASSERT_EQUAL(force1.getSigmaCombiningRule(), force2.getSigmaCombiningRule());
ASSERT_EQUAL(force1.getEpsilonCombiningRule(), force2.getEpsilonCombiningRule());
ASSERT_EQUAL(force1.getCutoff(), force2.getCutoff());
ASSERT_EQUAL(force1.getUseNeighborList(), force2.getUseNeighborList());
ASSERT_EQUAL(force1.getPBC(), force2.getPBC());
ASSERT_EQUAL(force1.getNonbondedMethod(), force2.getNonbondedMethod());
ASSERT_EQUAL(force1.getNumParticles(), force2.getNumParticles());
for (unsigned int ii = 0; ii < static_cast<unsigned int>(force1.getNumParticles()); ii++) {
int ivIndex1, classIndex1;
int ivIndex2, classIndex2;
int ivIndex1;
int ivIndex2;
double sigma1, epsilon1, reductionFactor1;
double sigma2, epsilon2, reductionFactor2;
force1.getParticleParameters( ii, ivIndex1, classIndex1, sigma1, epsilon1, reductionFactor1 );
force2.getParticleParameters( ii, ivIndex2, classIndex2, sigma2, epsilon2, reductionFactor2 );
force1.getParticleParameters( ii, ivIndex1, sigma1, epsilon1, reductionFactor1 );
force2.getParticleParameters( ii, ivIndex2, sigma2, epsilon2, reductionFactor2 );
ASSERT_EQUAL(ivIndex1, ivIndex2 );
ASSERT_EQUAL(classIndex1, classIndex2 );
ASSERT_EQUAL(sigma1, sigma2);
ASSERT_EQUAL(epsilon1, epsilon2);
ASSERT_EQUAL(reductionFactor1, reductionFactor2);
......
......@@ -2716,7 +2716,6 @@ class AmoebaVdwGenerator:
values = [float(atom.attrib['sigma']), float(atom.attrib['epsilon']), float(atom.attrib['reduction'])]
classType = atom.attrib['class']
if (generator.radiustype == 'SIGMA'):
values[0] *= two_six
......@@ -2724,8 +2723,6 @@ class AmoebaVdwGenerator:
if (generator.radiussize == 'DIAMETER'):
values[0] *= 0.5
values.append(classType)
for t in types[0]:
generator.typeMap[t] = values
......@@ -2804,8 +2801,7 @@ class AmoebaVdwGenerator:
force.setUseDispersionCorrection(int(args['useDispersionCorrection']))
if (nonbondedMethod == PME):
force.setPBC(1)
force.setUseNeighborList(1)
force.setNonbondedMethod(mm.AmoebaVdwForce.CutoffPeriodic)
else:
force = existing[0]
......@@ -2818,7 +2814,6 @@ class AmoebaVdwGenerator:
if t in self.typeMap:
values = self.typeMap[t]
classIndex = int(values[3])
# ivIndex = index of bonded partner for hydrogens; otherwise ivIndex = particle index
......@@ -2831,7 +2826,7 @@ class AmoebaVdwGenerator:
else:
ivIndex = data.bonds[bondIndex].atom1
force.addParticle(ivIndex, classIndex, values[0], values[1], values[2])
force.addParticle(ivIndex, values[0], values[1], values[2])
else:
raise ValueError('No vdw type for atom %s' % (atom.name))
......
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