Commit 047934e2 authored by Rafal P. Wiewiora's avatar Rafal P. Wiewiora
Browse files

Merge remote-tracking branch 'upstream/master'

parents ce3a5dc0 d12c9bd1
......@@ -3131,6 +3131,98 @@ void testTriclinic() {
ASSERT_EQUAL_TOL(expectedPotential[i], potential[i], 1e-4);
}
void testZBisect() {
System system;
for (int i = 0; i < 7; i++)
system.addParticle(1.0);
system.setDefaultPeriodicBoxVectors(Vec3(4, 0, 0), Vec3(0, 4, 0), Vec3(0, 0, 4));
AmoebaMultipoleForce* force = new AmoebaMultipoleForce();
system.addForce(force);
force->setNonbondedMethod(AmoebaMultipoleForce::PME);
force->setCutoffDistance(1.2);
double charge[] = {-1.01875, 0, 0, 0, -0.51966, 0.25983, 0.25983};
double dipole[7][3] = {
{0.06620218576365969, 0.056934176095985306, 0.06298584667720743},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0.007556121391156931},
{-0.05495981592297553, 0, -0.0030787530116780605},
{-0.05495981592297553, 0, -0.0030787530116780605}};
double quadrupole[7][9] = {
{-0.0004042865090302655, 0.0010450291005955025, -0.0010871640586155112, 0.0010450291005955025, 0.0002512789255424535, -0.0009504541350087216, -0.0010871640586155112, -0.0009504541350087216, 0.00015300758348781198},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0.00035403072392177476, 0.009334284009749387, 0, 0.009334284009749387, -0.00039025708016361216, 0, 0, 0, 3.622635624183737e-05},
{-3.42848251678095e-05, 0.07374084367702016, -1.894859653979126e-06, 0.07374084367702016, -0.00010024087598069868, 0, -1.894859653979126e-06, 0, 0.00013452570114850818},
{-3.42848251678095e-05, 0.07374084367702016, -1.894859653979126e-06, 0.07374084367702016, -0.00010024087598069868, 0, -1.894859653979126e-06, 0, 0.00013452570114850818}
};
int axis[7][4] = {
{2, 2, 1, 3},
{5, -1, -1, -1},
{5, -1, -1, -1},
{5, -1, -1, -1},
{1, 5, 6, -1},
{0, 4, 6, -1},
{0, 4, 5, -1}
};
double thole = 0.39;
double damping[] = {0.33178695365189015, 0.33178695365189015, 0.33178695365189015, 0.33178695365189015, 0.306987653777382, 0.2813500172269554, 0.2813500172269554};
double polarity[] = {0.001334, 0.001334, 0.001334, 0.001334, 0.000837, 0.000496, 0.000496};
for (int i = 0; i < 7; i++) {
vector<double> d, q;
for (int j = 0; j < 3; j++)
d.push_back(dipole[i][j]);
for (int j = 0; j < 9; j++)
q.push_back(quadrupole[i][j]);
force->addMultipole(charge[i], d, q, axis[i][0], axis[i][1], axis[i][2], axis[i][3], thole, damping[i], polarity[i]);
}
for (int i = 0; i < 4; i++) {
vector<int> map;
if (i != 0) map.push_back(0);
force->setCovalentMap(i, AmoebaMultipoleForce::Covalent12, map);
map.clear();
if (i != 1) map.push_back(1);
if (i != 2) map.push_back(2);
if (i != 3) map.push_back(3);
force->setCovalentMap(i, AmoebaMultipoleForce::Covalent13, map);
map.clear();
map.push_back(0);
map.push_back(1);
map.push_back(2);
map.push_back(3);
force->setCovalentMap(i, AmoebaMultipoleForce::PolarizationCovalent11, map);
}
for (int i = 4; i < 7; i++) {
vector<int> map;
if (i != 4) map.push_back(4);
force->setCovalentMap(i, AmoebaMultipoleForce::Covalent12, map);
map.clear();
if (i != 5) map.push_back(5);
if (i != 6) map.push_back(6);
force->setCovalentMap(i, AmoebaMultipoleForce::Covalent13, map);
map.clear();
map.push_back(4);
map.push_back(5);
map.push_back(6);
force->setCovalentMap(i, AmoebaMultipoleForce::PolarizationCovalent11, map);
}
LangevinIntegrator integrator(0.0, 0.1, 0.01);
Context context(system, integrator, Platform::getPlatformByName("CUDA"));
vector<Vec3> positions;
positions.push_back(Vec3(-0.06317711175870899, -0.04905009196658128, 0.0767217));
positions.push_back(Vec3(-0.049166918626451395, -0.20747614470348363, 0.03979849999999996));
positions.push_back(Vec3(-0.19317150000000005, -0.05811762921948427, 0.1632788999999999));
positions.push_back(Vec3(0.04465103038516016, -0.018345116763806235, 0.18531239999999993));
positions.push_back(Vec3(0.005630299999999998, 0.40965770000000035, 0.5731495));
positions.push_back(Vec3(0.036148100000000016, 0.3627041999999996, 0.49299430000000033));
positions.push_back(Vec3(0.07781149999999992, 0.4178183000000004, 0.6355703000000004));
context.setPositions(positions);
State state = context.getState(State::Energy);
ASSERT_EQUAL_TOL(-84.1532, state.getPotentialEnergy(), 0.01);
}
int main(int argc, char* argv[]) {
try {
std::cout << "TestCudaAmoebaMultipoleForce running test..." << std::endl;
......@@ -3183,6 +3275,10 @@ int main(int argc, char* argv[]) {
// triclinic box of water
testTriclinic();
// test the ZBisect axis type.
testZBisect();
} catch(const std::exception& e) {
std::cout << "exception: " << e.what() << std::endl;
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2013 Stanford University and the Authors. *
* Portions copyright (c) 2008-2016 Stanford University and the Authors. *
* Authors: Mark Friedrichs, Peter Eastman *
* Contributors: *
* *
......@@ -32,10 +32,18 @@
using namespace OpenMM;
#ifdef OPENMM_BUILDING_STATIC_LIBRARY
static void registerPlatforms() {
#else
extern "C" OPENMM_EXPORT void registerPlatforms() {
#endif
}
#ifdef OPENMM_BUILDING_STATIC_LIBRARY
static void registerKernelFactories() {
#else
extern "C" OPENMM_EXPORT void registerKernelFactories() {
#endif
for (int i = 0; i < Platform::getNumPlatforms(); i++) {
Platform& platform = Platform::getPlatform(i);
if (dynamic_cast<ReferencePlatform*>(&platform) != NULL) {
......@@ -98,4 +106,4 @@ KernelImpl* AmoebaReferenceKernelFactory::createKernelImpl(std::string name, con
return new ReferenceCalcAmoebaWcaDispersionForceKernel(name, platform, context.getSystem());
throw OpenMMException((std::string("Tried to create kernel with illegal kernel name '")+name+"'").c_str());
}
}
\ No newline at end of file
......@@ -54,29 +54,29 @@
using namespace OpenMM;
using namespace std;
static vector<RealVec>& extractPositions(ContextImpl& context) {
static vector<Vec3>& extractPositions(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<RealVec>*) data->positions);
return *((vector<Vec3>*) data->positions);
}
static vector<RealVec>& extractVelocities(ContextImpl& context) {
static vector<Vec3>& extractVelocities(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<RealVec>*) data->velocities);
return *((vector<Vec3>*) data->velocities);
}
static vector<RealVec>& extractForces(ContextImpl& context) {
static vector<Vec3>& extractForces(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<RealVec>*) data->forces);
return *((vector<Vec3>*) data->forces);
}
static RealVec& extractBoxSize(ContextImpl& context) {
static Vec3& extractBoxSize(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *(RealVec*) data->periodicBoxSize;
return *(Vec3*) data->periodicBoxSize;
}
static RealVec* extractBoxVectors(ContextImpl& context) {
static Vec3* extractBoxVectors(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return (RealVec*) data->periodicBoxVectors;
return (Vec3*) data->periodicBoxVectors;
}
// ***************************************************************************
......@@ -99,23 +99,23 @@ void ReferenceCalcAmoebaBondForceKernel::initialize(const System& system, const
particle1.push_back(particle1Index);
particle2.push_back(particle2Index);
length.push_back(static_cast<RealOpenMM>(lengthValue));
kQuadratic.push_back(static_cast<RealOpenMM>(kValue));
length.push_back(static_cast<double>(lengthValue));
kQuadratic.push_back(kValue);
}
globalBondCubic = static_cast<RealOpenMM>(force.getAmoebaGlobalBondCubic());
globalBondQuartic = static_cast<RealOpenMM>(force.getAmoebaGlobalBondQuartic());
globalBondCubic = force.getAmoebaGlobalBondCubic();
globalBondQuartic = force.getAmoebaGlobalBondQuartic();
usePeriodic = force.usesPeriodicBoundaryConditions();
}
double ReferenceCalcAmoebaBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context);
vector<Vec3>& posData = extractPositions(context);
vector<Vec3>& forceData = extractForces(context);
AmoebaReferenceBondForce amoebaReferenceBondForce;
if (usePeriodic)
amoebaReferenceBondForce.setPeriodic(extractBoxVectors(context));
RealOpenMM energy = amoebaReferenceBondForce.calculateForceAndEnergy(numBonds, posData, particle1, particle2, length, kQuadratic,
globalBondCubic, globalBondQuartic,
forceData);
double energy = amoebaReferenceBondForce.calculateForceAndEnergy(numBonds, posData, particle1, particle2, length, kQuadratic,
globalBondCubic, globalBondQuartic,
forceData);
return static_cast<double>(energy);
}
......@@ -131,8 +131,8 @@ void ReferenceCalcAmoebaBondForceKernel::copyParametersToContext(ContextImpl& co
force.getBondParameters(i, particle1Index, particle2Index, lengthValue, kValue);
if (particle1Index != particle1[i] || particle2Index != particle2[i])
throw OpenMMException("updateParametersInContext: The set of particles in a bond has changed");
length[i] = (RealOpenMM) lengthValue;
kQuadratic[i] = (RealOpenMM) kValue;
length[i] = lengthValue;
kQuadratic[i] = kValue;
}
}
......@@ -156,23 +156,23 @@ void ReferenceCalcAmoebaAngleForceKernel::initialize(const System& system, const
particle1.push_back(particle1Index);
particle2.push_back(particle2Index);
particle3.push_back(particle3Index);
angle.push_back(static_cast<RealOpenMM>(angleValue));
kQuadratic.push_back(static_cast<RealOpenMM>(k));
angle.push_back(angleValue);
kQuadratic.push_back(k);
}
globalAngleCubic = static_cast<RealOpenMM>(force.getAmoebaGlobalAngleCubic());
globalAngleQuartic = static_cast<RealOpenMM>(force.getAmoebaGlobalAngleQuartic());
globalAnglePentic = static_cast<RealOpenMM>(force.getAmoebaGlobalAnglePentic());
globalAngleSextic = static_cast<RealOpenMM>(force.getAmoebaGlobalAngleSextic());
globalAngleCubic = force.getAmoebaGlobalAngleCubic();
globalAngleQuartic = force.getAmoebaGlobalAngleQuartic();
globalAnglePentic = force.getAmoebaGlobalAnglePentic();
globalAngleSextic = force.getAmoebaGlobalAngleSextic();
usePeriodic = force.usesPeriodicBoundaryConditions();
}
double ReferenceCalcAmoebaAngleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context);
vector<Vec3>& posData = extractPositions(context);
vector<Vec3>& forceData = extractForces(context);
AmoebaReferenceAngleForce amoebaReferenceAngleForce;
if (usePeriodic)
amoebaReferenceAngleForce.setPeriodic(extractBoxVectors(context));
RealOpenMM energy = amoebaReferenceAngleForce.calculateForceAndEnergy(numAngles,
double energy = amoebaReferenceAngleForce.calculateForceAndEnergy(numAngles,
posData, particle1, particle2, particle3, angle, kQuadratic, globalAngleCubic, globalAngleQuartic, globalAnglePentic, globalAngleSextic, forceData);
return static_cast<double>(energy);
}
......@@ -189,8 +189,8 @@ void ReferenceCalcAmoebaAngleForceKernel::copyParametersToContext(ContextImpl& c
force.getAngleParameters(i, particle1Index, particle2Index, particle3Index, angleValue, k);
if (particle1Index != particle1[i] || particle2Index != particle2[i] || particle3Index != particle3[i])
throw OpenMMException("updateParametersInContext: The set of particles in an angle has changed");
angle[i] = (RealOpenMM) angleValue;
kQuadratic[i] = (RealOpenMM) k;
angle[i] = angleValue;
kQuadratic[i] = k;
}
}
......@@ -212,26 +212,26 @@ void ReferenceCalcAmoebaInPlaneAngleForceKernel::initialize(const System& system
particle2.push_back(particle2Index);
particle3.push_back(particle3Index);
particle4.push_back(particle4Index);
angle.push_back(static_cast<RealOpenMM>(angleValue));
kQuadratic.push_back(static_cast<RealOpenMM>(k));
angle.push_back(angleValue);
kQuadratic.push_back(k);
}
globalInPlaneAngleCubic = static_cast<RealOpenMM>(force.getAmoebaGlobalInPlaneAngleCubic());
globalInPlaneAngleQuartic = static_cast<RealOpenMM>(force.getAmoebaGlobalInPlaneAngleQuartic());
globalInPlaneAnglePentic = static_cast<RealOpenMM>(force.getAmoebaGlobalInPlaneAnglePentic());
globalInPlaneAngleSextic = static_cast<RealOpenMM>(force.getAmoebaGlobalInPlaneAngleSextic());
globalInPlaneAngleCubic = force.getAmoebaGlobalInPlaneAngleCubic();
globalInPlaneAngleQuartic = force.getAmoebaGlobalInPlaneAngleQuartic();
globalInPlaneAnglePentic = force.getAmoebaGlobalInPlaneAnglePentic();
globalInPlaneAngleSextic = force.getAmoebaGlobalInPlaneAngleSextic();
usePeriodic = force.usesPeriodicBoundaryConditions();
}
double ReferenceCalcAmoebaInPlaneAngleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context);
vector<Vec3>& posData = extractPositions(context);
vector<Vec3>& forceData = extractForces(context);
AmoebaReferenceInPlaneAngleForce amoebaReferenceInPlaneAngleForce;
if (usePeriodic)
amoebaReferenceInPlaneAngleForce.setPeriodic(extractBoxVectors(context));
RealOpenMM energy = amoebaReferenceInPlaneAngleForce.calculateForceAndEnergy(numAngles, posData, particle1, particle2, particle3, particle4,
angle, kQuadratic, globalInPlaneAngleCubic, globalInPlaneAngleQuartic,
globalInPlaneAnglePentic, globalInPlaneAngleSextic, forceData);
double energy = amoebaReferenceInPlaneAngleForce.calculateForceAndEnergy(numAngles, posData, particle1, particle2, particle3, particle4,
angle, kQuadratic, globalInPlaneAngleCubic, globalInPlaneAngleQuartic,
globalInPlaneAnglePentic, globalInPlaneAngleSextic, forceData);
return static_cast<double>(energy);
}
......@@ -247,8 +247,8 @@ void ReferenceCalcAmoebaInPlaneAngleForceKernel::copyParametersToContext(Context
force.getAngleParameters(i, particle1Index, particle2Index, particle3Index, particle4Index, angleValue, k);
if (particle1Index != particle1[i] || particle2Index != particle2[i] || particle3Index != particle3[i] || particle4Index != particle4[i])
throw OpenMMException("updateParametersInContext: The set of particles in an angle has changed");
angle[i] = (RealOpenMM) angleValue;
kQuadratic[i] = (RealOpenMM) k;
angle[i] = angleValue;
kQuadratic[i] = k;
}
}
......@@ -273,18 +273,18 @@ void ReferenceCalcAmoebaPiTorsionForceKernel::initialize(const System& system, c
particle4.push_back(particle4Index);
particle5.push_back(particle5Index);
particle6.push_back(particle6Index);
kTorsion.push_back(static_cast<RealOpenMM>(kTorsionParameter));
kTorsion.push_back(kTorsionParameter);
}
usePeriodic = force.usesPeriodicBoundaryConditions();
}
double ReferenceCalcAmoebaPiTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context);
vector<Vec3>& posData = extractPositions(context);
vector<Vec3>& forceData = extractForces(context);
AmoebaReferencePiTorsionForce amoebaReferencePiTorsionForce;
if (usePeriodic)
amoebaReferencePiTorsionForce.setPeriodic(extractBoxVectors(context));
RealOpenMM energy = amoebaReferencePiTorsionForce.calculateForceAndEnergy(numPiTorsions, posData, particle1, particle2,
double energy = amoebaReferencePiTorsionForce.calculateForceAndEnergy(numPiTorsions, posData, particle1, particle2,
particle3, particle4, particle5, particle6,
kTorsion, forceData);
return static_cast<double>(energy);
......@@ -303,7 +303,7 @@ void ReferenceCalcAmoebaPiTorsionForceKernel::copyParametersToContext(ContextImp
if (particle1Index != particle1[i] || particle2Index != particle2[i] || particle3Index != particle3[i] ||
particle4Index != particle4[i] || particle5Index != particle5[i] || particle6Index != particle6[i])
throw OpenMMException("updateParametersInContext: The set of particles in a torsion has changed");
kTorsion[i] = (RealOpenMM) kTorsionParameter;
kTorsion[i] = kTorsionParameter;
}
}
......@@ -324,22 +324,22 @@ void ReferenceCalcAmoebaStretchBendForceKernel::initialize(const System& system,
particle1.push_back(particle1Index);
particle2.push_back(particle2Index);
particle3.push_back(particle3Index);
lengthABParameters.push_back(static_cast<RealOpenMM>(lengthAB));
lengthCBParameters.push_back(static_cast<RealOpenMM>(lengthCB));
angleParameters.push_back(static_cast<RealOpenMM>(angle));
k1Parameters.push_back(static_cast<RealOpenMM>(k1));
k2Parameters.push_back(static_cast<RealOpenMM>(k2));
lengthABParameters.push_back(lengthAB);
lengthCBParameters.push_back(lengthCB);
angleParameters.push_back(angle);
k1Parameters.push_back(k1);
k2Parameters.push_back(k2);
}
usePeriodic = force.usesPeriodicBoundaryConditions();
}
double ReferenceCalcAmoebaStretchBendForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context);
vector<Vec3>& posData = extractPositions(context);
vector<Vec3>& forceData = extractForces(context);
AmoebaReferenceStretchBendForce amoebaReferenceStretchBendForce;
if (usePeriodic)
amoebaReferenceStretchBendForce.setPeriodic(extractBoxVectors(context));
RealOpenMM energy = amoebaReferenceStretchBendForce.calculateForceAndEnergy(numStretchBends, posData, particle1, particle2, particle3,
double energy = amoebaReferenceStretchBendForce.calculateForceAndEnergy(numStretchBends, posData, particle1, particle2, particle3,
lengthABParameters, lengthCBParameters, angleParameters, k1Parameters,
k2Parameters, forceData);
return static_cast<double>(energy);
......@@ -357,11 +357,11 @@ void ReferenceCalcAmoebaStretchBendForceKernel::copyParametersToContext(ContextI
force.getStretchBendParameters(i, particle1Index, particle2Index, particle3Index, lengthAB, lengthCB, angle, k1, k2);
if (particle1Index != particle1[i] || particle2Index != particle2[i] || particle3Index != particle3[i])
throw OpenMMException("updateParametersInContext: The set of particles in a stretch-bend has changed");
lengthABParameters[i] = (RealOpenMM) lengthAB;
lengthCBParameters[i] = (RealOpenMM) lengthCB;
angleParameters[i] = (RealOpenMM) angle;
k1Parameters[i] = (RealOpenMM) k1;
k2Parameters[i] = (RealOpenMM) k2;
lengthABParameters[i] = lengthAB;
lengthCBParameters[i] = lengthCB;
angleParameters[i] = angle;
k1Parameters[i] = k1;
k2Parameters[i] = k2;
}
}
......@@ -385,28 +385,28 @@ void ReferenceCalcAmoebaOutOfPlaneBendForceKernel::initialize(const System& syst
particle2.push_back(particle2Index);
particle3.push_back(particle3Index);
particle4.push_back(particle4Index);
kParameters.push_back(static_cast<RealOpenMM>(k));
kParameters.push_back(k);
}
globalOutOfPlaneBendAngleCubic = static_cast<RealOpenMM>(force.getAmoebaGlobalOutOfPlaneBendCubic());
globalOutOfPlaneBendAngleQuartic = static_cast<RealOpenMM>(force.getAmoebaGlobalOutOfPlaneBendQuartic());
globalOutOfPlaneBendAnglePentic = static_cast<RealOpenMM>(force.getAmoebaGlobalOutOfPlaneBendPentic());
globalOutOfPlaneBendAngleSextic = static_cast<RealOpenMM>(force.getAmoebaGlobalOutOfPlaneBendSextic());
globalOutOfPlaneBendAngleCubic = force.getAmoebaGlobalOutOfPlaneBendCubic();
globalOutOfPlaneBendAngleQuartic = force.getAmoebaGlobalOutOfPlaneBendQuartic();
globalOutOfPlaneBendAnglePentic = force.getAmoebaGlobalOutOfPlaneBendPentic();
globalOutOfPlaneBendAngleSextic = force.getAmoebaGlobalOutOfPlaneBendSextic();
usePeriodic = force.usesPeriodicBoundaryConditions();
}
double ReferenceCalcAmoebaOutOfPlaneBendForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context);
vector<Vec3>& posData = extractPositions(context);
vector<Vec3>& forceData = extractForces(context);
AmoebaReferenceOutOfPlaneBendForce amoebaReferenceOutOfPlaneBendForce;
if (usePeriodic)
amoebaReferenceOutOfPlaneBendForce.setPeriodic(extractBoxVectors(context));
RealOpenMM energy = amoebaReferenceOutOfPlaneBendForce.calculateForceAndEnergy(numOutOfPlaneBends, posData,
particle1, particle2, particle3, particle4,
kParameters,
globalOutOfPlaneBendAngleCubic,
globalOutOfPlaneBendAngleQuartic,
globalOutOfPlaneBendAnglePentic,
globalOutOfPlaneBendAngleSextic, forceData);
double energy = amoebaReferenceOutOfPlaneBendForce.calculateForceAndEnergy(numOutOfPlaneBends, posData,
particle1, particle2, particle3, particle4,
kParameters,
globalOutOfPlaneBendAngleCubic,
globalOutOfPlaneBendAngleQuartic,
globalOutOfPlaneBendAnglePentic,
globalOutOfPlaneBendAngleSextic, forceData);
return static_cast<double>(energy);
}
......@@ -422,7 +422,7 @@ void ReferenceCalcAmoebaOutOfPlaneBendForceKernel::copyParametersToContext(Conte
force.getOutOfPlaneBendParameters(i, particle1Index, particle2Index, particle3Index, particle4Index, k);
if (particle1Index != particle1[i] || particle2Index != particle2[i] || particle3Index != particle3[i] || particle4Index != particle4[i])
throw OpenMMException("updateParametersInContext: The set of particles in an out-of-plane bend has changed");
kParameters[i] = (RealOpenMM) k;
kParameters[i] = k;
}
}
......@@ -479,11 +479,11 @@ void ReferenceCalcAmoebaTorsionTorsionForceKernel::initialize(const System& syst
torsionTorsionGrids[ii][kk][jj].resize(grid[kk][jj].size());
if (reorder) {
for (unsigned int ll = 0; ll < grid[ll][jj].size(); ll++) {
torsionTorsionGrids[ii][kk][jj][ll] = static_cast<RealOpenMM>(reorderedGrid[kk][jj][ll]);
torsionTorsionGrids[ii][kk][jj][ll] = reorderedGrid[kk][jj][ll];
}
} else {
for (unsigned int ll = 0; ll < grid[ll][jj].size(); ll++) {
torsionTorsionGrids[ii][kk][jj][ll] = static_cast<RealOpenMM>(grid[kk][jj][ll]);
torsionTorsionGrids[ii][kk][jj][ll] = grid[kk][jj][ll];
}
}
}
......@@ -493,12 +493,12 @@ void ReferenceCalcAmoebaTorsionTorsionForceKernel::initialize(const System& syst
double ReferenceCalcAmoebaTorsionTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context);
vector<Vec3>& posData = extractPositions(context);
vector<Vec3>& forceData = extractForces(context);
AmoebaReferenceTorsionTorsionForce amoebaReferenceTorsionTorsionForce;
if (usePeriodic)
amoebaReferenceTorsionTorsionForce.setPeriodic(extractBoxVectors(context));
RealOpenMM energy = amoebaReferenceTorsionTorsionForce.calculateForceAndEnergy(numTorsionTorsions, posData,
double energy = amoebaReferenceTorsionTorsionForce.calculateForceAndEnergy(numTorsionTorsions, posData,
particle1, particle2, particle3, particle4, particle5,
chiralCheckAtom, gridIndices, torsionTorsionGrids, forceData);
return static_cast<double>(energy);
......@@ -535,7 +535,6 @@ void ReferenceCalcAmoebaMultipoleForceKernel::initialize(const System& system, c
int dipoleIndex = 0;
int quadrupoleIndex = 0;
int maxCovalentRange = 0;
double totalCharge = 0.0;
for (int ii = 0; ii < numMultipoles; ii++) {
......@@ -554,24 +553,24 @@ void ReferenceCalcAmoebaMultipoleForceKernel::initialize(const System& system, c
multipoleAtomXs[ii] = multipoleAtomX;
multipoleAtomYs[ii] = multipoleAtomY;
charges[ii] = static_cast<RealOpenMM>(charge);
tholes[ii] = static_cast<RealOpenMM>(tholeD);
dampingFactors[ii] = static_cast<RealOpenMM>(dampingFactorD);
polarity[ii] = static_cast<RealOpenMM>(polarityD);
charges[ii] = charge;
tholes[ii] = tholeD;
dampingFactors[ii] = dampingFactorD;
polarity[ii] = polarityD;
dipoles[dipoleIndex++] = static_cast<RealOpenMM>(dipolesD[0]);
dipoles[dipoleIndex++] = static_cast<RealOpenMM>(dipolesD[1]);
dipoles[dipoleIndex++] = static_cast<RealOpenMM>(dipolesD[2]);
dipoles[dipoleIndex++] = dipolesD[0];
dipoles[dipoleIndex++] = dipolesD[1];
dipoles[dipoleIndex++] = dipolesD[2];
quadrupoles[quadrupoleIndex++] = static_cast<RealOpenMM>(quadrupolesD[0]);
quadrupoles[quadrupoleIndex++] = static_cast<RealOpenMM>(quadrupolesD[1]);
quadrupoles[quadrupoleIndex++] = static_cast<RealOpenMM>(quadrupolesD[2]);
quadrupoles[quadrupoleIndex++] = static_cast<RealOpenMM>(quadrupolesD[3]);
quadrupoles[quadrupoleIndex++] = static_cast<RealOpenMM>(quadrupolesD[4]);
quadrupoles[quadrupoleIndex++] = static_cast<RealOpenMM>(quadrupolesD[5]);
quadrupoles[quadrupoleIndex++] = static_cast<RealOpenMM>(quadrupolesD[6]);
quadrupoles[quadrupoleIndex++] = static_cast<RealOpenMM>(quadrupolesD[7]);
quadrupoles[quadrupoleIndex++] = static_cast<RealOpenMM>(quadrupolesD[8]);
quadrupoles[quadrupoleIndex++] = quadrupolesD[0];
quadrupoles[quadrupoleIndex++] = quadrupolesD[1];
quadrupoles[quadrupoleIndex++] = quadrupolesD[2];
quadrupoles[quadrupoleIndex++] = quadrupolesD[3];
quadrupoles[quadrupoleIndex++] = quadrupolesD[4];
quadrupoles[quadrupoleIndex++] = quadrupolesD[5];
quadrupoles[quadrupoleIndex++] = quadrupolesD[6];
quadrupoles[quadrupoleIndex++] = quadrupolesD[7];
quadrupoles[quadrupoleIndex++] = quadrupolesD[8];
// covalent info
......@@ -602,7 +601,7 @@ void ReferenceCalcAmoebaMultipoleForceKernel::initialize(const System& system, c
nb.setEwaldErrorTolerance(force.getEwaldErrorTolerance());
nb.setCutoffDistance(force.getCutoffDistance());
int gridSizeX, gridSizeY, gridSizeZ;
NonbondedForceImpl::calcPMEParameters(system, nb, alphaEwald, gridSizeX, gridSizeY, gridSizeZ);
NonbondedForceImpl::calcPMEParameters(system, nb, alphaEwald, gridSizeX, gridSizeY, gridSizeZ, false);
pmeGridDimension[0] = gridSizeX;
pmeGridDimension[1] = gridSizeY;
pmeGridDimension[2] = gridSizeZ;
......@@ -646,7 +645,7 @@ AmoebaReferenceMultipoleForce* ReferenceCalcAmoebaMultipoleForceKernel::setupAmo
amoebaReferenceGeneralizedKirkwoodForce->setIncludeCavityTerm(gkKernel->getIncludeCavityTerm());
amoebaReferenceGeneralizedKirkwoodForce->setDirectPolarization(gkKernel->getDirectPolarization());
vector<RealOpenMM> parameters;
vector<double> parameters;
gkKernel->getAtomicRadii(parameters);
amoebaReferenceGeneralizedKirkwoodForce->setAtomicRadii(parameters);
......@@ -658,7 +657,7 @@ AmoebaReferenceMultipoleForce* ReferenceCalcAmoebaMultipoleForceKernel::setupAmo
// calculate Grycuk Born radii
vector<RealVec>& posData = extractPositions(context);
vector<Vec3>& posData = extractPositions(context);
amoebaReferenceGeneralizedKirkwoodForce->calculateGrycukBornRadii(posData);
amoebaReferenceMultipoleForce = new AmoebaReferenceGeneralizedKirkwoodMultipoleForce(amoebaReferenceGeneralizedKirkwoodForce);
......@@ -669,7 +668,7 @@ AmoebaReferenceMultipoleForce* ReferenceCalcAmoebaMultipoleForceKernel::setupAmo
amoebaReferencePmeMultipoleForce->setAlphaEwald(alphaEwald);
amoebaReferencePmeMultipoleForce->setCutoffDistance(cutoffDistance);
amoebaReferencePmeMultipoleForce->setPmeGridDimensions(pmeGridDimension);
RealVec* boxVectors = extractBoxVectors(context);
Vec3* boxVectors = extractBoxVectors(context);
double minAllowedSize = 1.999999*cutoffDistance;
if (boxVectors[0][0] < minAllowedSize || boxVectors[1][1] < minAllowedSize || boxVectors[2][2] < minAllowedSize) {
throw OpenMMException("The periodic box size has decreased to less than twice the nonbonded cutoff.");
......@@ -704,12 +703,12 @@ double ReferenceCalcAmoebaMultipoleForceKernel::execute(ContextImpl& context, bo
AmoebaReferenceMultipoleForce* amoebaReferenceMultipoleForce = setupAmoebaReferenceMultipoleForce(context);
vector<RealVec>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context);
RealOpenMM energy = amoebaReferenceMultipoleForce->calculateForceAndEnergy(posData, charges, dipoles, quadrupoles, tholes,
dampingFactors, polarity, axisTypes,
multipoleAtomZs, multipoleAtomXs, multipoleAtomYs,
multipoleAtomCovalentInfo, forceData);
vector<Vec3>& posData = extractPositions(context);
vector<Vec3>& forceData = extractForces(context);
double energy = amoebaReferenceMultipoleForce->calculateForceAndEnergy(posData, charges, dipoles, quadrupoles, tholes,
dampingFactors, polarity, axisTypes,
multipoleAtomZs, multipoleAtomXs, multipoleAtomYs,
multipoleAtomCovalentInfo, forceData);
delete amoebaReferenceMultipoleForce;
......@@ -723,11 +722,11 @@ void ReferenceCalcAmoebaMultipoleForceKernel::getInducedDipoles(ContextImpl& con
// Create an AmoebaReferenceMultipoleForce to do the calculation.
AmoebaReferenceMultipoleForce* amoebaReferenceMultipoleForce = setupAmoebaReferenceMultipoleForce(context);
vector<RealVec>& posData = extractPositions(context);
vector<Vec3>& posData = extractPositions(context);
// Retrieve the induced dipoles.
vector<RealVec> inducedDipoles;
vector<Vec3> inducedDipoles;
amoebaReferenceMultipoleForce->calculateInducedDipoles(posData, charges, dipoles, quadrupoles, tholes,
dampingFactors, polarity, axisTypes, multipoleAtomZs, multipoleAtomXs, multipoleAtomYs, multipoleAtomCovalentInfo, inducedDipoles);
for (int i = 0; i < numParticles; i++)
......@@ -742,11 +741,11 @@ void ReferenceCalcAmoebaMultipoleForceKernel::getLabFramePermanentDipoles(Contex
// Create an AmoebaReferenceMultipoleForce to do the calculation.
AmoebaReferenceMultipoleForce* amoebaReferenceMultipoleForce = setupAmoebaReferenceMultipoleForce(context);
vector<RealVec>& posData = extractPositions(context);
vector<Vec3>& posData = extractPositions(context);
// Retrieve the permanent dipoles in the lab frame.
vector<RealVec> labFramePermanentDipoles;
vector<Vec3> labFramePermanentDipoles;
amoebaReferenceMultipoleForce->calculateLabFramePermanentDipoles(posData, charges, dipoles, quadrupoles, tholes,
dampingFactors, polarity, axisTypes, multipoleAtomZs, multipoleAtomXs, multipoleAtomYs, multipoleAtomCovalentInfo, labFramePermanentDipoles);
for (int i = 0; i < numParticles; i++)
......@@ -762,11 +761,11 @@ void ReferenceCalcAmoebaMultipoleForceKernel::getTotalDipoles(ContextImpl& conte
// Create an AmoebaReferenceMultipoleForce to do the calculation.
AmoebaReferenceMultipoleForce* amoebaReferenceMultipoleForce = setupAmoebaReferenceMultipoleForce(context);
vector<RealVec>& posData = extractPositions(context);
vector<Vec3>& posData = extractPositions(context);
// Retrieve the permanent dipoles in the lab frame.
vector<RealVec> totalDipoles;
vector<Vec3> totalDipoles;
amoebaReferenceMultipoleForce->calculateTotalDipoles(posData, charges, dipoles, quadrupoles, tholes,
dampingFactors, polarity, axisTypes, multipoleAtomZs, multipoleAtomXs, multipoleAtomYs, multipoleAtomCovalentInfo, totalDipoles);
......@@ -781,9 +780,9 @@ void ReferenceCalcAmoebaMultipoleForceKernel::getElectrostaticPotential(ContextI
std::vector< double >& outputElectrostaticPotential) {
AmoebaReferenceMultipoleForce* amoebaReferenceMultipoleForce = setupAmoebaReferenceMultipoleForce(context);
vector<RealVec>& posData = extractPositions(context);
vector<RealVec> grid(inputGrid.size());
vector<RealOpenMM> potential(inputGrid.size());
vector<Vec3>& posData = extractPositions(context);
vector<Vec3> grid(inputGrid.size());
vector<double> potential(inputGrid.size());
for (unsigned int ii = 0; ii < inputGrid.size(); ii++) {
grid[ii] = inputGrid[ii];
}
......@@ -805,13 +804,13 @@ void ReferenceCalcAmoebaMultipoleForceKernel::getSystemMultipoleMoments(ContextI
// retrieve masses
const System& system = context.getSystem();
vector<RealOpenMM> masses;
vector<double> masses;
for (int i = 0; i < system.getNumParticles(); ++i) {
masses.push_back(static_cast<RealOpenMM>(system.getParticleMass(i)));
masses.push_back(system.getParticleMass(i));
}
AmoebaReferenceMultipoleForce* amoebaReferenceMultipoleForce = setupAmoebaReferenceMultipoleForce(context);
vector<RealVec>& posData = extractPositions(context);
vector<Vec3>& posData = extractPositions(context);
amoebaReferenceMultipoleForce->calculateAmoebaSystemMultipoleMoments(masses, posData, charges, dipoles, quadrupoles, tholes,
dampingFactors, polarity, axisTypes,
multipoleAtomZs, multipoleAtomXs, multipoleAtomYs,
......@@ -838,22 +837,22 @@ void ReferenceCalcAmoebaMultipoleForceKernel::copyParametersToContext(ContextImp
multipoleAtomZs[i] = multipoleAtomZ;
multipoleAtomXs[i] = multipoleAtomX;
multipoleAtomYs[i] = multipoleAtomY;
charges[i] = (RealOpenMM) charge;
tholes[i] = (RealOpenMM) tholeD;
dampingFactors[i] = (RealOpenMM) dampingFactorD;
polarity[i] = (RealOpenMM) polarityD;
dipoles[dipoleIndex++] = (RealOpenMM) dipolesD[0];
dipoles[dipoleIndex++] = (RealOpenMM) dipolesD[1];
dipoles[dipoleIndex++] = (RealOpenMM) dipolesD[2];
quadrupoles[quadrupoleIndex++] = (RealOpenMM) quadrupolesD[0];
quadrupoles[quadrupoleIndex++] = (RealOpenMM) quadrupolesD[1];
quadrupoles[quadrupoleIndex++] = (RealOpenMM) quadrupolesD[2];
quadrupoles[quadrupoleIndex++] = (RealOpenMM) quadrupolesD[3];
quadrupoles[quadrupoleIndex++] = (RealOpenMM) quadrupolesD[4];
quadrupoles[quadrupoleIndex++] = (RealOpenMM) quadrupolesD[5];
quadrupoles[quadrupoleIndex++] = (RealOpenMM) quadrupolesD[6];
quadrupoles[quadrupoleIndex++] = (RealOpenMM) quadrupolesD[7];
quadrupoles[quadrupoleIndex++] = (RealOpenMM) quadrupolesD[8];
charges[i] = charge;
tholes[i] = tholeD;
dampingFactors[i] = dampingFactorD;
polarity[i] = polarityD;
dipoles[dipoleIndex++] = dipolesD[0];
dipoles[dipoleIndex++] = dipolesD[1];
dipoles[dipoleIndex++] = dipolesD[2];
quadrupoles[quadrupoleIndex++] = quadrupolesD[0];
quadrupoles[quadrupoleIndex++] = quadrupolesD[1];
quadrupoles[quadrupoleIndex++] = quadrupolesD[2];
quadrupoles[quadrupoleIndex++] = quadrupolesD[3];
quadrupoles[quadrupoleIndex++] = quadrupolesD[4];
quadrupoles[quadrupoleIndex++] = quadrupolesD[5];
quadrupoles[quadrupoleIndex++] = quadrupolesD[6];
quadrupoles[quadrupoleIndex++] = quadrupolesD[7];
quadrupoles[quadrupoleIndex++] = quadrupolesD[8];
}
}
......@@ -889,37 +888,37 @@ int ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getDirectPolarization() c
return directPolarization;
}
RealOpenMM ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getSoluteDielectric() const {
double ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getSoluteDielectric() const {
return soluteDielectric;
}
RealOpenMM ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getSolventDielectric() const {
double ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getSolventDielectric() const {
return solventDielectric;
}
RealOpenMM ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getDielectricOffset() const {
double ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getDielectricOffset() const {
return dielectricOffset;
}
RealOpenMM ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getProbeRadius() const {
double ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getProbeRadius() const {
return probeRadius;
}
RealOpenMM ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getSurfaceAreaFactor() const {
double ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getSurfaceAreaFactor() const {
return surfaceAreaFactor;
}
void ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getAtomicRadii(vector<RealOpenMM>& outputAtomicRadii) const {
void ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getAtomicRadii(vector<double>& outputAtomicRadii) const {
outputAtomicRadii.resize(atomicRadii.size());
copy(atomicRadii.begin(), atomicRadii.end(), outputAtomicRadii.begin());
}
void ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getScaleFactors(vector<RealOpenMM>& outputScaleFactors) const {
void ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getScaleFactors(vector<double>& outputScaleFactors) const {
outputScaleFactors.resize(scaleFactors.size());
copy(scaleFactors.begin(), scaleFactors.end(), outputScaleFactors.begin());
}
void ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getCharges(vector<RealOpenMM>& outputCharges) const {
void ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::getCharges(vector<double>& outputCharges) const {
outputCharges.resize(charges.size());
copy(charges.begin(), charges.end(), outputCharges.begin());
}
......@@ -947,9 +946,9 @@ void ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::initialize(const System&
double particleCharge, particleRadius, scalingFactor;
force.getParticleParameters(ii, particleCharge, particleRadius, scalingFactor);
atomicRadii.push_back(static_cast<RealOpenMM>(particleRadius));
scaleFactors.push_back(static_cast<RealOpenMM>(scalingFactor));
charges.push_back(static_cast<RealOpenMM>(particleCharge));
atomicRadii.push_back(particleRadius);
scaleFactors.push_back(scalingFactor);
charges.push_back(particleCharge);
// Make sure the charge matches the one specified by the AmoebaMultipoleForce.
......@@ -963,11 +962,11 @@ void ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel::initialize(const System&
}
includeCavityTerm = force.getIncludeCavityTerm();
soluteDielectric = static_cast<RealOpenMM>(force.getSoluteDielectric());
solventDielectric = static_cast<RealOpenMM>(force.getSolventDielectric());
dielectricOffset = static_cast<RealOpenMM>(0.009);
probeRadius = static_cast<RealOpenMM>(force.getProbeRadius()),
surfaceAreaFactor = static_cast<RealOpenMM>(force.getSurfaceAreaFactor());
soluteDielectric = force.getSoluteDielectric();
solventDielectric = force.getSolventDielectric();
dielectricOffset = 0.009;
probeRadius = force.getProbeRadius(),
surfaceAreaFactor = force.getSurfaceAreaFactor();
directPolarization = amoebaMultipoleForce->getPolarizationType() == AmoebaMultipoleForce::Direct ? 1 : 0;
}
......@@ -1030,9 +1029,9 @@ void ReferenceCalcAmoebaVdwForceKernel::initialize(const System& system, const A
}
indexIVs[ii] = indexIV;
sigmas[ii] = static_cast<RealOpenMM>(sigma);
epsilons[ii] = static_cast<RealOpenMM>(epsilon);
reductions[ii] = static_cast<RealOpenMM>(reduction);
sigmas[ii] = sigma;
epsilons[ii] = epsilon;
reductions[ii] = reduction;
}
sigmaCombiningRule = force.getSigmaCombiningRule();
epsilonCombiningRule = force.getEpsilonCombiningRule();
......@@ -1046,16 +1045,16 @@ void ReferenceCalcAmoebaVdwForceKernel::initialize(const System& system, const A
double ReferenceCalcAmoebaVdwForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context);
vector<Vec3>& posData = extractPositions(context);
vector<Vec3>& forceData = extractForces(context);
AmoebaReferenceVdwForce vdwForce(sigmaCombiningRule, epsilonCombiningRule);
RealOpenMM energy;
double energy;
if (useCutoff) {
vdwForce.setCutoff(cutoff);
computeNeighborListVoxelHash(*neighborList, numParticles, posData, allExclusions, extractBoxVectors(context), usePBC, cutoff, 0.0);
if (usePBC) {
vdwForce.setNonbondedMethod(AmoebaReferenceVdwForce::CutoffPeriodic);
RealVec* boxVectors = extractBoxVectors(context);
Vec3* boxVectors = extractBoxVectors(context);
double minAllowedSize = 1.999999*cutoff;
if (boxVectors[0][0] < minAllowedSize || boxVectors[1][1] < minAllowedSize || boxVectors[2][2] < minAllowedSize) {
throw OpenMMException("The periodic box size has decreased to less than twice the cutoff.");
......@@ -1084,9 +1083,9 @@ void ReferenceCalcAmoebaVdwForceKernel::copyParametersToContext(ContextImpl& con
double sigma, epsilon, reduction;
force.getParticleParameters(i, indexIV, sigma, epsilon, reduction);
indexIVs[i] = indexIV;
sigmas[i] = (RealOpenMM) sigma;
epsilons[i] = (RealOpenMM) epsilon;
reductions[i]= (RealOpenMM) reduction;
sigmas[i] = sigma;
epsilons[i] = epsilon;
reductions[i]= reduction;
}
}
......@@ -1113,27 +1112,27 @@ void ReferenceCalcAmoebaWcaDispersionForceKernel::initialize(const System& syste
double radius, epsilon;
force.getParticleParameters(ii, radius, epsilon);
radii[ii] = static_cast<RealOpenMM>(radius);
epsilons[ii] = static_cast<RealOpenMM>(epsilon);
radii[ii] = radius;
epsilons[ii] = epsilon;
}
totalMaximumDispersionEnergy = static_cast<RealOpenMM>(AmoebaWcaDispersionForceImpl::getTotalMaximumDispersionEnergy(force));
totalMaximumDispersionEnergy = AmoebaWcaDispersionForceImpl::getTotalMaximumDispersionEnergy(force);
epso = static_cast<RealOpenMM>(force.getEpso());
epsh = static_cast<RealOpenMM>(force.getEpsh());
rmino = static_cast<RealOpenMM>(force.getRmino());
rminh = static_cast<RealOpenMM>(force.getRminh());
awater = static_cast<RealOpenMM>(force.getAwater());
shctd = static_cast<RealOpenMM>(force.getShctd());
dispoff = static_cast<RealOpenMM>(force.getDispoff());
slevy = static_cast<RealOpenMM>(force.getSlevy());
epso = force.getEpso();
epsh = force.getEpsh();
rmino = force.getRmino();
rminh = force.getRminh();
awater = force.getAwater();
shctd = force.getShctd();
dispoff = force.getDispoff();
slevy = force.getSlevy();
}
double ReferenceCalcAmoebaWcaDispersionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context);
vector<Vec3>& posData = extractPositions(context);
vector<Vec3>& forceData = extractForces(context);
AmoebaReferenceWcaDispersionForce amoebaReferenceWcaDispersionForce(epso, epsh, rmino, rminh, awater, shctd, dispoff, slevy);
RealOpenMM energy = amoebaReferenceWcaDispersionForce.calculateForceAndEnergy(numParticles, posData, radii, epsilons, totalMaximumDispersionEnergy, forceData);
double energy = amoebaReferenceWcaDispersionForce.calculateForceAndEnergy(numParticles, posData, radii, epsilons, totalMaximumDispersionEnergy, forceData);
return static_cast<double>(energy);
}
......@@ -1146,8 +1145,8 @@ void ReferenceCalcAmoebaWcaDispersionForceKernel::copyParametersToContext(Contex
for (int i = 0; i < numParticles; ++i) {
double radius, epsilon;
force.getParticleParameters(i, radius, epsilon);
radii[i] = (RealOpenMM) radius;
epsilons[i] = (RealOpenMM) epsilon;
radii[i] = radius;
epsilons[i] = epsilon;
}
totalMaximumDispersionEnergy = (RealOpenMM) AmoebaWcaDispersionForceImpl::getTotalMaximumDispersionEnergy(force);
totalMaximumDispersionEnergy = AmoebaWcaDispersionForceImpl::getTotalMaximumDispersionEnergy(force);
}
......@@ -72,10 +72,10 @@ private:
int numBonds;
std::vector<int> particle1;
std::vector<int> particle2;
std::vector<RealOpenMM> length;
std::vector<RealOpenMM> kQuadratic;
RealOpenMM globalBondCubic;
RealOpenMM globalBondQuartic;
std::vector<double> length;
std::vector<double> kQuadratic;
double globalBondCubic;
double globalBondQuartic;
const System& system;
bool usePeriodic;
};
......@@ -115,12 +115,12 @@ private:
std::vector<int> particle1;
std::vector<int> particle2;
std::vector<int> particle3;
std::vector<RealOpenMM> angle;
std::vector<RealOpenMM> kQuadratic;
RealOpenMM globalAngleCubic;
RealOpenMM globalAngleQuartic;
RealOpenMM globalAnglePentic;
RealOpenMM globalAngleSextic;
std::vector<double> angle;
std::vector<double> kQuadratic;
double globalAngleCubic;
double globalAngleQuartic;
double globalAnglePentic;
double globalAngleSextic;
const System& system;
bool usePeriodic;
};
......@@ -161,12 +161,12 @@ private:
std::vector<int> particle2;
std::vector<int> particle3;
std::vector<int> particle4;
std::vector<RealOpenMM> angle;
std::vector<RealOpenMM> kQuadratic;
RealOpenMM globalInPlaneAngleCubic;
RealOpenMM globalInPlaneAngleQuartic;
RealOpenMM globalInPlaneAnglePentic;
RealOpenMM globalInPlaneAngleSextic;
std::vector<double> angle;
std::vector<double> kQuadratic;
double globalInPlaneAngleCubic;
double globalInPlaneAngleQuartic;
double globalInPlaneAnglePentic;
double globalInPlaneAngleSextic;
const System& system;
bool usePeriodic;
};
......@@ -209,7 +209,7 @@ private:
std::vector<int> particle4;
std::vector<int> particle5;
std::vector<int> particle6;
std::vector<RealOpenMM> kTorsion;
std::vector<double> kTorsion;
const System& system;
bool usePeriodic;
};
......@@ -249,11 +249,11 @@ private:
std::vector<int> particle1;
std::vector<int> particle2;
std::vector<int> particle3;
std::vector<RealOpenMM> lengthABParameters;
std::vector<RealOpenMM> lengthCBParameters;
std::vector<RealOpenMM> angleParameters;
std::vector<RealOpenMM> k1Parameters;
std::vector<RealOpenMM> k2Parameters;
std::vector<double> lengthABParameters;
std::vector<double> lengthCBParameters;
std::vector<double> angleParameters;
std::vector<double> k1Parameters;
std::vector<double> k2Parameters;
const System& system;
bool usePeriodic;
};
......@@ -294,11 +294,11 @@ private:
std::vector<int> particle2;
std::vector<int> particle3;
std::vector<int> particle4;
std::vector<RealOpenMM> kParameters;
RealOpenMM globalOutOfPlaneBendAngleCubic;
RealOpenMM globalOutOfPlaneBendAngleQuartic;
RealOpenMM globalOutOfPlaneBendAnglePentic;
RealOpenMM globalOutOfPlaneBendAngleSextic;
std::vector<double> kParameters;
double globalOutOfPlaneBendAngleCubic;
double globalOutOfPlaneBendAngleQuartic;
double globalOutOfPlaneBendAnglePentic;
double globalOutOfPlaneBendAngleSextic;
const System& system;
bool usePeriodic;
};
......@@ -337,7 +337,7 @@ private:
std::vector<int> gridIndices;
int numTorsionTorsionGrids;
std::vector< std::vector< std::vector< std::vector<RealOpenMM> > > > torsionTorsionGrids;
std::vector< std::vector< std::vector< std::vector<double> > > > torsionTorsionGrids;
const System& system;
bool usePeriodic;
......@@ -439,12 +439,12 @@ private:
int numMultipoles;
AmoebaMultipoleForce::NonbondedMethod nonbondedMethod;
AmoebaMultipoleForce::PolarizationType polarizationType;
std::vector<RealOpenMM> charges;
std::vector<RealOpenMM> dipoles;
std::vector<RealOpenMM> quadrupoles;
std::vector<RealOpenMM> tholes;
std::vector<RealOpenMM> dampingFactors;
std::vector<RealOpenMM> polarity;
std::vector<double> charges;
std::vector<double> dipoles;
std::vector<double> quadrupoles;
std::vector<double> tholes;
std::vector<double> dampingFactors;
std::vector<double> polarity;
std::vector<int> axisTypes;
std::vector<int> multipoleAtomZs;
std::vector<int> multipoleAtomXs;
......@@ -452,12 +452,12 @@ private:
std::vector< std::vector< std::vector<int> > > multipoleAtomCovalentInfo;
int mutualInducedMaxIterations;
RealOpenMM mutualInducedTargetEpsilon;
double mutualInducedTargetEpsilon;
std::vector<double> extrapolationCoefficients;
bool usePme;
RealOpenMM alphaEwald;
RealOpenMM cutoffDistance;
double alphaEwald;
double cutoffDistance;
std::vector<int> pmeGridDimension;
const System& system;
......@@ -501,9 +501,9 @@ private:
double dispersionCoefficient;
std::vector<int> indexIVs;
std::vector< std::set<int> > allExclusions;
std::vector<RealOpenMM> sigmas;
std::vector<RealOpenMM> epsilons;
std::vector<RealOpenMM> reductions;
std::vector<double> sigmas;
std::vector<double> epsilons;
std::vector<double> reductions;
std::string sigmaCombiningRule;
std::string epsilonCombiningRule;
const System& system;
......@@ -543,17 +543,17 @@ public:
private:
int numParticles;
std::vector<RealOpenMM> radii;
std::vector<RealOpenMM> epsilons;
RealOpenMM epso;
RealOpenMM epsh;
RealOpenMM rmino;
RealOpenMM rminh;
RealOpenMM awater;
RealOpenMM shctd;
RealOpenMM dispoff;
RealOpenMM slevy;
RealOpenMM totalMaximumDispersionEnergy;
std::vector<double> radii;
std::vector<double> epsilons;
double epso;
double epsh;
double rmino;
double rminh;
double awater;
double shctd;
double dispoff;
double slevy;
double totalMaximumDispersionEnergy;
const System& system;
};
......@@ -609,7 +609,7 @@ public:
* @return soluteDielectric
*
*/
RealOpenMM getSoluteDielectric() const;
double getSoluteDielectric() const;
/**
* Get the solvent dielectric.
......@@ -617,7 +617,7 @@ public:
* @return solventDielectric
*
*/
RealOpenMM getSolventDielectric() const;
double getSolventDielectric() const;
/**
* Get the dielectric offset.
......@@ -625,7 +625,7 @@ public:
* @return dielectricOffset
*
*/
RealOpenMM getDielectricOffset() const;
double getDielectricOffset() const;
/**
* Get the probe radius.
......@@ -633,7 +633,7 @@ public:
* @return probeRadius
*
*/
RealOpenMM getProbeRadius() const;
double getProbeRadius() const;
/**
* Get the surface area factor.
......@@ -641,7 +641,7 @@ public:
* @return surfaceAreaFactor
*
*/
RealOpenMM getSurfaceAreaFactor() const;
double getSurfaceAreaFactor() const;
/**
* Get the vector of particle radii.
......@@ -649,7 +649,7 @@ public:
* @param atomicRadii vector of atomic radii
*
*/
void getAtomicRadii(std::vector<RealOpenMM>& atomicRadii) const;
void getAtomicRadii(std::vector<double>& atomicRadii) const;
/**
* Get the vector of scale factors.
......@@ -657,7 +657,7 @@ public:
* @param scaleFactors vector of scale factors
*
*/
void getScaleFactors(std::vector<RealOpenMM>& scaleFactors) const;
void getScaleFactors(std::vector<double>& scaleFactors) const;
/**
* Get the vector of charges.
......@@ -665,7 +665,7 @@ public:
* @param charges vector of charges
*
*/
void getCharges(std::vector<RealOpenMM>& charges) const;
void getCharges(std::vector<double>& charges) const;
/**
* Copy changed parameters over to a context.
......@@ -678,14 +678,14 @@ public:
private:
int numParticles;
std::vector<RealOpenMM> atomicRadii;
std::vector<RealOpenMM> scaleFactors;
std::vector<RealOpenMM> charges;
RealOpenMM soluteDielectric;
RealOpenMM solventDielectric;
RealOpenMM dielectricOffset;
RealOpenMM probeRadius;
RealOpenMM surfaceAreaFactor;
std::vector<double> atomicRadii;
std::vector<double> scaleFactors;
std::vector<double> charges;
double soluteDielectric;
double solventDielectric;
double dielectricOffset;
double probeRadius;
double surfaceAreaFactor;
int includeCavityTerm;
int directPolarization;
const System& system;
......
......@@ -24,11 +24,12 @@
#include "AmoebaReferenceForce.h"
#include "AmoebaReferenceAngleForce.h"
#include "SimTKOpenMMRealType.h"
using std::vector;
using namespace OpenMM;
void AmoebaReferenceAngleForce::setPeriodic(OpenMM::RealVec* vectors) {
void AmoebaReferenceAngleForce::setPeriodic(OpenMM::Vec3* vectors) {
usePeriodic = true;
boxVectors[0] = vectors[0];
boxVectors[1] = vectors[1];
......@@ -53,49 +54,35 @@ void AmoebaReferenceAngleForce::setPeriodic(OpenMM::RealVec* vectors) {
--------------------------------------------------------------------------------------- */
RealOpenMM AmoebaReferenceAngleForce::getPrefactorsGivenAngleCosine(RealOpenMM cosine,
RealOpenMM idealAngle, RealOpenMM angleK,
RealOpenMM angleCubic, RealOpenMM angleQuartic,
RealOpenMM anglePentic, RealOpenMM angleSextic,
RealOpenMM* dEdR) const {
double AmoebaReferenceAngleForce::getPrefactorsGivenAngleCosine(double cosine,
double idealAngle, double angleK,
double angleCubic, double angleQuartic,
double anglePentic, double angleSextic,
double* dEdR) const {
// ---------------------------------------------------------------------------------------
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
static const RealOpenMM two = 2.0;
static const RealOpenMM three = 3.0;
static const RealOpenMM four = 4.0;
static const RealOpenMM five = 5.0;
static const RealOpenMM six = 6.0;
// static const std::string methodName = "AmoebaReferenceAngleForce::getPrefactorsGivenAngleCosine";
// ---------------------------------------------------------------------------------------
RealOpenMM angle;
if (cosine >= one) {
angle = zero;
} else if (cosine <= -one) {
double angle;
if (cosine >= 1.0) {
angle = 0.0;
} else if (cosine <= -1.0) {
angle = RADIAN*PI_M;
} else {
angle = RADIAN*ACOS(cosine);
}
RealOpenMM deltaIdeal = angle - idealAngle;
RealOpenMM deltaIdeal2 = deltaIdeal*deltaIdeal;
RealOpenMM deltaIdeal3 = deltaIdeal*deltaIdeal2;
RealOpenMM deltaIdeal4 = deltaIdeal2*deltaIdeal2;
double deltaIdeal = angle - idealAngle;
double deltaIdeal2 = deltaIdeal*deltaIdeal;
double deltaIdeal3 = deltaIdeal*deltaIdeal2;
double deltaIdeal4 = deltaIdeal2*deltaIdeal2;
*dEdR = (two + three*angleCubic*deltaIdeal +
four*angleQuartic*deltaIdeal2 +
five*anglePentic*deltaIdeal3 +
six*angleSextic*deltaIdeal4);
*dEdR = (2.0 + 3.0*angleCubic*deltaIdeal +
4.0*angleQuartic*deltaIdeal2 +
5.0*anglePentic*deltaIdeal3 +
6.0*angleSextic*deltaIdeal4);
*dEdR *= RADIAN*angleK*deltaIdeal;
*dEdR *= RADIAN*angleK*deltaIdeal;
RealOpenMM energy = 1.0f + angleCubic*deltaIdeal + angleQuartic*deltaIdeal2 +
anglePentic*deltaIdeal3 + angleSextic*deltaIdeal4;
energy *= angleK*deltaIdeal2;
double energy = 1.0f + angleCubic*deltaIdeal + angleQuartic*deltaIdeal2 +
anglePentic*deltaIdeal3 + angleSextic*deltaIdeal4;
energy *= angleK*deltaIdeal2;
return energy;
......@@ -120,60 +107,49 @@ RealOpenMM AmoebaReferenceAngleForce::getPrefactorsGivenAngleCosine(RealOpenMM c
--------------------------------------------------------------------------------------- */
RealOpenMM AmoebaReferenceAngleForce::calculateAngleIxn(const RealVec& positionAtomA, const RealVec& positionAtomB,
const RealVec& positionAtomC,
RealOpenMM angle, RealOpenMM angleK,
RealOpenMM angleCubic, RealOpenMM angleQuartic,
RealOpenMM anglePentic, RealOpenMM angleSextic,
RealVec* forces) const {
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "AmoebaReferenceAngleForce::calculateAngleIxn";
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
static const RealOpenMM onePt5 = 1.5;
static const RealOpenMM two = 2.0;
// ---------------------------------------------------------------------------------------
double AmoebaReferenceAngleForce::calculateAngleIxn(const Vec3& positionAtomA, const Vec3& positionAtomB,
const Vec3& positionAtomC,
double angle, double angleK,
double angleCubic, double angleQuartic,
double anglePentic, double angleSextic,
Vec3* forces) const {
std::vector<RealOpenMM> deltaR[2];
std::vector<double> deltaR[2];
if (usePeriodic)
AmoebaReferenceForce::loadDeltaRPeriodic(positionAtomA, positionAtomB, deltaR[0], boxVectors);
else
AmoebaReferenceForce::loadDeltaR(positionAtomA, positionAtomB, deltaR[0]);
RealOpenMM rAB2 = AmoebaReferenceForce::getNormSquared3(deltaR[0]);
RealOpenMM rAB = SQRT(rAB2);
double rAB2 = AmoebaReferenceForce::getNormSquared3(deltaR[0]);
double rAB = SQRT(rAB2);
if (usePeriodic)
AmoebaReferenceForce::loadDeltaRPeriodic(positionAtomC, positionAtomB, deltaR[1], boxVectors);
else
AmoebaReferenceForce::loadDeltaR(positionAtomC, positionAtomB, deltaR[1]);
RealOpenMM rCB2 = AmoebaReferenceForce::getNormSquared3(deltaR[1]);
RealOpenMM rCB = SQRT(rCB2);
double rCB2 = AmoebaReferenceForce::getNormSquared3(deltaR[1]);
double rCB = SQRT(rCB2);
if (rAB <= zero || rCB <= zero) {
return zero;
if (rAB <= 0.0 || rCB <= 0.0) {
return 0.0;
}
std::vector<RealOpenMM> pVector(3);
std::vector<double> pVector(3);
AmoebaReferenceForce::getCrossProduct(deltaR[0], deltaR[1], pVector);
RealOpenMM rp = AmoebaReferenceForce::getNorm3(pVector);
double rp = AmoebaReferenceForce::getNorm3(pVector);
if (rp < 1.0e-06) {
rp = 1.0e-06;
}
RealOpenMM dot = AmoebaReferenceForce::getDotProduct3(deltaR[0], deltaR[1]);
RealOpenMM cosine = dot/(rAB*rCB);
double dot = AmoebaReferenceForce::getDotProduct3(deltaR[0], deltaR[1]);
double cosine = dot/(rAB*rCB);
RealOpenMM dEdR;
RealOpenMM energy = getPrefactorsGivenAngleCosine(cosine, angle, angleK, angleCubic, angleQuartic,
double dEdR;
double energy = getPrefactorsGivenAngleCosine(cosine, angle, angleK, angleCubic, angleQuartic,
anglePentic, angleSextic, &dEdR);
RealOpenMM termA = dEdR/(rAB2*rp);
RealOpenMM termC = -dEdR/(rCB2*rp);
double termA = dEdR/(rAB2*rp);
double termC = -dEdR/(rCB2*rp);
std::vector<RealOpenMM> deltaCrossP[3];
std::vector<double> deltaCrossP[3];
deltaCrossP[0].resize(3);
deltaCrossP[1].resize(3);
deltaCrossP[2].resize(3);
......@@ -196,27 +172,27 @@ RealOpenMM AmoebaReferenceAngleForce::calculateAngleIxn(const RealVec& positionA
return energy;
}
RealOpenMM AmoebaReferenceAngleForce::calculateForceAndEnergy(int numAngles, vector<RealVec>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<RealOpenMM>& angle,
const std::vector<RealOpenMM>& kQuadratic,
RealOpenMM angleCubic,
RealOpenMM angleQuartic,
RealOpenMM anglePentic,
RealOpenMM angleSextic,
vector<RealVec>& forceData) const {
RealOpenMM energy = 0.0;
double AmoebaReferenceAngleForce::calculateForceAndEnergy(int numAngles, vector<Vec3>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<double>& angle,
const std::vector<double>& kQuadratic,
double angleCubic,
double angleQuartic,
double anglePentic,
double angleSextic,
vector<Vec3>& forceData) const {
double energy = 0.0;
for (unsigned int ii = 0; ii < static_cast<unsigned int>(numAngles); ii++) {
int particle1Index = particle1[ii];
int particle2Index = particle2[ii];
int particle3Index = particle3[ii];
RealOpenMM idealAngle = angle[ii];
RealOpenMM angleK = kQuadratic[ii];
RealVec forces[3];
energy += calculateAngleIxn(posData[particle1Index], posData[particle2Index], posData[particle3Index],
idealAngle, angleK, angleCubic, angleQuartic, anglePentic, angleSextic, forces);
int particle1Index = particle1[ii];
int particle2Index = particle2[ii];
int particle3Index = particle3[ii];
double idealAngle = angle[ii];
double angleK = kQuadratic[ii];
Vec3 forces[3];
energy += calculateAngleIxn(posData[particle1Index], posData[particle2Index], posData[particle3Index],
idealAngle, angleK, angleCubic, angleQuartic, anglePentic, angleSextic, forces);
for (unsigned int jj = 0; jj < 3; jj++) {
forceData[particle1Index][jj] += forces[0][jj];
......
......@@ -25,7 +25,7 @@
#ifndef __AmoebaReferenceAngleForce_H__
#define __AmoebaReferenceAngleForce_H__
#include "RealVec.h"
#include "openmm/Vec3.h"
#include <vector>
namespace OpenMM {
......@@ -58,7 +58,7 @@ public:
--------------------------------------------------------------------------------------- */
void setPeriodic(OpenMM::RealVec* vectors);
void setPeriodic(OpenMM::Vec3* vectors);
/**---------------------------------------------------------------------------------------
......@@ -82,22 +82,22 @@ public:
--------------------------------------------------------------------------------------- */
RealOpenMM calculateForceAndEnergy(int numAngles, std::vector<OpenMM::RealVec>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<RealOpenMM>& angle,
const std::vector<RealOpenMM>& kQuadratic,
RealOpenMM globalAngleCubic,
RealOpenMM globalAngleQuartic,
RealOpenMM globalAnglePentic,
RealOpenMM globalAngleSextic,
std::vector<OpenMM::RealVec>& forceData) const;
double calculateForceAndEnergy(int numAngles, std::vector<OpenMM::Vec3>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<double>& angle,
const std::vector<double>& kQuadratic,
double globalAngleCubic,
double globalAngleQuartic,
double globalAnglePentic,
double globalAngleSextic,
std::vector<OpenMM::Vec3>& forceData) const;
private:
bool usePeriodic;
RealVec boxVectors[3];
Vec3 boxVectors[3];
/**---------------------------------------------------------------------------------------
......@@ -117,10 +117,10 @@ private:
--------------------------------------------------------------------------------------- */
RealOpenMM getPrefactorsGivenAngleCosine(RealOpenMM cosine, RealOpenMM idealAngle, RealOpenMM angleK,
RealOpenMM angleCubic, RealOpenMM angleQuartic,
RealOpenMM anglePentic, RealOpenMM angleSextic,
RealOpenMM* dEdR) const;
double getPrefactorsGivenAngleCosine(double cosine, double idealAngle, double angleK,
double angleCubic, double angleQuartic,
double anglePentic, double angleSextic,
double* dEdR) const;
/**---------------------------------------------------------------------------------------
......@@ -141,12 +141,12 @@ private:
--------------------------------------------------------------------------------------- */
RealOpenMM calculateAngleIxn(const OpenMM::RealVec& positionAtomA, const OpenMM::RealVec& positionAtomB,
const OpenMM::RealVec& positionAtomC,
RealOpenMM angle, RealOpenMM angleK,
RealOpenMM angleCubic, RealOpenMM angleQuartic,
RealOpenMM anglePentic, RealOpenMM angleSextic,
OpenMM::RealVec* forces) const;
double calculateAngleIxn(const OpenMM::Vec3& positionAtomA, const OpenMM::Vec3& positionAtomB,
const OpenMM::Vec3& positionAtomC,
double angle, double angleK,
double angleCubic, double angleQuartic,
double anglePentic, double angleSextic,
OpenMM::Vec3* forces) const;
};
......
......@@ -28,7 +28,7 @@
using std::vector;
using namespace OpenMM;
void AmoebaReferenceBondForce::setPeriodic(OpenMM::RealVec* vectors) {
void AmoebaReferenceBondForce::setPeriodic(OpenMM::Vec3* vectors) {
usePeriodic = true;
boxVectors[0] = vectors[0];
boxVectors[1] = vectors[1];
......@@ -51,73 +51,61 @@ void AmoebaReferenceBondForce::setPeriodic(OpenMM::RealVec* vectors) {
--------------------------------------------------------------------------------------- */
RealOpenMM AmoebaReferenceBondForce::calculateBondIxn(const RealVec& positionAtomA, const RealVec& positionAtomB,
RealOpenMM bondLength, RealOpenMM bondK,
RealOpenMM bondCubic, RealOpenMM bondQuartic,
RealVec* forces) const {
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "AmoebaReferenceBondForce::calculateBondIxn";
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
static const RealOpenMM onePt5 = 1.5;
static const RealOpenMM two = 2.0;
// ---------------------------------------------------------------------------------------
double AmoebaReferenceBondForce::calculateBondIxn(const Vec3& positionAtomA, const Vec3& positionAtomB,
double bondLength, double bondK,
double bondCubic, double bondQuartic,
Vec3* forces) const {
// get deltaR, R2, and R between 2 atoms
std::vector<RealOpenMM> deltaR;
std::vector<double> deltaR;
if (usePeriodic)
AmoebaReferenceForce::loadDeltaRPeriodic(positionAtomA, positionAtomB, deltaR, boxVectors);
else
AmoebaReferenceForce::loadDeltaR(positionAtomA, positionAtomB, deltaR);
RealOpenMM r = AmoebaReferenceForce::getNorm3(deltaR);
double r = AmoebaReferenceForce::getNorm3(deltaR);
// deltaIdeal = r - r_0
RealOpenMM deltaIdeal = r - bondLength;
RealOpenMM deltaIdeal2 = deltaIdeal*deltaIdeal;
double deltaIdeal = r - bondLength;
double deltaIdeal2 = deltaIdeal*deltaIdeal;
RealOpenMM dEdR = (one + onePt5*bondCubic*deltaIdeal + two*bondQuartic*deltaIdeal2);
dEdR *= two*bondK*deltaIdeal;
dEdR = r > zero ? (dEdR/r) : zero;
double dEdR = (1.0 + 1.5*bondCubic*deltaIdeal + 2.0*bondQuartic*deltaIdeal2);
dEdR *= 2.0*bondK*deltaIdeal;
dEdR = r > 0.0 ? (dEdR/r) : 0.0;
forces[0][0] = dEdR*deltaR[0];
forces[0][1] = dEdR*deltaR[1];
forces[0][2] = dEdR*deltaR[2];
forces[0][0] = dEdR*deltaR[0];
forces[0][1] = dEdR*deltaR[1];
forces[0][2] = dEdR*deltaR[2];
dEdR *= -1.0;
forces[1][0] = dEdR*deltaR[0];
forces[1][1] = dEdR*deltaR[1];
forces[1][2] = dEdR*deltaR[2];
dEdR *= -1.0;
forces[1][0] = dEdR*deltaR[0];
forces[1][1] = dEdR*deltaR[1];
forces[1][2] = dEdR*deltaR[2];
RealOpenMM energy = bondK*deltaIdeal2*(one + bondCubic*deltaIdeal + bondQuartic*deltaIdeal2);
double energy = bondK*deltaIdeal2*(1.0 + bondCubic*deltaIdeal + bondQuartic*deltaIdeal2);
return energy;
}
RealOpenMM AmoebaReferenceBondForce::calculateForceAndEnergy(int numBonds,
vector<RealVec>& particlePositions,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<RealOpenMM>& length,
const std::vector<RealOpenMM>& kQuadratic,
RealOpenMM globalBondCubic,
RealOpenMM globalBondQuartic,
vector<RealVec>& forceData) const {
RealOpenMM energy = 0.0;
double AmoebaReferenceBondForce::calculateForceAndEnergy(int numBonds,
vector<Vec3>& particlePositions,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<double>& length,
const std::vector<double>& kQuadratic,
double globalBondCubic,
double globalBondQuartic,
vector<Vec3>& forceData) const {
double energy = 0.0;
for (int ii = 0; ii < numBonds; ii++) {
int particle1Index = particle1[ii];
int particle2Index = particle2[ii];
RealOpenMM bondLength = length[ii];
RealOpenMM bondK = kQuadratic[ii];
RealVec forces[2];
energy += calculateBondIxn(particlePositions[particle1Index], particlePositions[particle2Index],
bondLength, bondK, globalBondCubic, globalBondQuartic,
forces);
int particle1Index = particle1[ii];
int particle2Index = particle2[ii];
double bondLength = length[ii];
double bondK = kQuadratic[ii];
Vec3 forces[2];
energy += calculateBondIxn(particlePositions[particle1Index], particlePositions[particle2Index],
bondLength, bondK, globalBondCubic, globalBondQuartic,
forces);
for (int jj = 0; jj < 3; jj++) {
forceData[particle1Index][jj] += forces[0][jj];
......
......@@ -25,7 +25,7 @@
#ifndef __AmoebaReferenceBondForce_H__
#define __AmoebaReferenceBondForce_H__
#include "RealVec.h"
#include "openmm/Vec3.h"
#include <vector>
namespace OpenMM {
......@@ -58,7 +58,7 @@ public:
--------------------------------------------------------------------------------------- */
void setPeriodic(OpenMM::RealVec* vectors);
void setPeriodic(OpenMM::Vec3* vectors);
/**---------------------------------------------------------------------------------------
......@@ -78,18 +78,18 @@ public:
--------------------------------------------------------------------------------------- */
RealOpenMM calculateForceAndEnergy(int numBonds, std::vector<OpenMM::RealVec>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<RealOpenMM>& bondLength,
const std::vector<RealOpenMM>& bondK,
RealOpenMM bondCubic, RealOpenMM bondQuartic,
std::vector<OpenMM::RealVec>& forceData) const;
double calculateForceAndEnergy(int numBonds, std::vector<OpenMM::Vec3>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<double>& bondLength,
const std::vector<double>& bondK,
double bondCubic, double bondQuartic,
std::vector<OpenMM::Vec3>& forceData) const;
private:
bool usePeriodic;
RealVec boxVectors[3];
Vec3 boxVectors[3];
/**---------------------------------------------------------------------------------------
......@@ -107,10 +107,10 @@ private:
--------------------------------------------------------------------------------------- */
RealOpenMM calculateBondIxn(const OpenMM::RealVec& positionAtomA, const OpenMM::RealVec& positionAtomB,
RealOpenMM bondLength, RealOpenMM bondK,
RealOpenMM bondCubic, RealOpenMM bondQuartic,
OpenMM::RealVec* forces) const;
double calculateBondIxn(const OpenMM::Vec3& positionAtomA, const OpenMM::Vec3& positionAtomB,
double bondLength, double bondK,
double bondCubic, double bondQuartic,
OpenMM::Vec3* forces) const;
};
......
......@@ -23,6 +23,7 @@
*/
#include "AmoebaReferenceForce.h"
#include <cmath>
#include <vector>
using namespace OpenMM;
......@@ -37,8 +38,8 @@ using namespace OpenMM;
--------------------------------------------------------------------------------------- */
void AmoebaReferenceForce::loadDeltaR(const RealVec& xVector, const RealVec& yVector,
std::vector<RealOpenMM>& deltaR) {
void AmoebaReferenceForce::loadDeltaR(const Vec3& xVector, const Vec3& yVector,
std::vector<double>& deltaR) {
deltaR.resize(0);
deltaR.push_back(yVector[0] - xVector[0]);
deltaR.push_back(yVector[1] - xVector[1]);
......@@ -56,9 +57,9 @@ void AmoebaReferenceForce::loadDeltaR(const RealVec& xVector, const RealVec& yVe
--------------------------------------------------------------------------------------- */
void AmoebaReferenceForce::loadDeltaRPeriodic(const RealVec& xVector, const RealVec& yVector,
std::vector<RealOpenMM>& deltaR, const RealVec* boxVectors) {
RealVec diff = yVector-xVector;
void AmoebaReferenceForce::loadDeltaRPeriodic(const Vec3& xVector, const Vec3& yVector,
std::vector<double>& deltaR, const Vec3* boxVectors) {
Vec3 diff = yVector-xVector;
diff -= boxVectors[2]*floor(diff[2]/boxVectors[2][2]+0.5);
diff -= boxVectors[1]*floor(diff[1]/boxVectors[1][1]+0.5);
diff -= boxVectors[0]*floor(diff[0]/boxVectors[0][0]+0.5);
......@@ -78,7 +79,7 @@ void AmoebaReferenceForce::loadDeltaRPeriodic(const RealVec& xVector, const Real
--------------------------------------------------------------------------------------- */
RealOpenMM AmoebaReferenceForce::getNormSquared3(const std::vector<RealOpenMM>& inputVector) {
double AmoebaReferenceForce::getNormSquared3(const std::vector<double>& inputVector) {
// get 3 norm
return (inputVector[0]*inputVector[0] + inputVector[1]*inputVector[1] + inputVector[2]*inputVector[2]);
......@@ -94,7 +95,7 @@ RealOpenMM AmoebaReferenceForce::getNormSquared3(const std::vector<RealOpenMM>&
--------------------------------------------------------------------------------------- */
RealOpenMM AmoebaReferenceForce::getNormSquared3(const RealOpenMM* inputVector) {
double AmoebaReferenceForce::getNormSquared3(const double* inputVector) {
// get 3 norm
return (inputVector[0]*inputVector[0] + inputVector[1]*inputVector[1] + inputVector[2]*inputVector[2]);
......@@ -110,25 +111,25 @@ RealOpenMM AmoebaReferenceForce::getNormSquared3(const RealOpenMM* inputVector)
--------------------------------------------------------------------------------------- */
RealOpenMM AmoebaReferenceForce::getNorm3(const std::vector<RealOpenMM>& inputVector) {
double AmoebaReferenceForce::getNorm3(const std::vector<double>& inputVector) {
// get 3 norm
return SQRT(inputVector[0]*inputVector[0] + inputVector[1]*inputVector[1] + inputVector[2]*inputVector[2]);
return sqrt(inputVector[0]*inputVector[0] + inputVector[1]*inputVector[1] + inputVector[2]*inputVector[2]);
}
RealOpenMM AmoebaReferenceForce::getNorm3(const RealOpenMM* inputVector) {
double AmoebaReferenceForce::getNorm3(const double* inputVector) {
// get 3 norm
return SQRT(inputVector[0]*inputVector[0] + inputVector[1]*inputVector[1] + inputVector[2]*inputVector[2]);
return sqrt(inputVector[0]*inputVector[0] + inputVector[1]*inputVector[1] + inputVector[2]*inputVector[2]);
}
RealOpenMM AmoebaReferenceForce::normalizeVector3(RealOpenMM* inputVector) {
RealOpenMM norm = SQRT(inputVector[0]*inputVector[0] + inputVector[1]*inputVector[1] + inputVector[2]*inputVector[2]);
double AmoebaReferenceForce::normalizeVector3(double* inputVector) {
double norm = sqrt(inputVector[0]*inputVector[0] + inputVector[1]*inputVector[1] + inputVector[2]*inputVector[2]);
if (norm > 0.0) {
RealOpenMM normI = 1.0/norm;
inputVector[0] *= normI;
inputVector[1] *= normI;
inputVector[2] *= normI;
double normI = 1.0/norm;
inputVector[0] *= normI;
inputVector[1] *= normI;
inputVector[2] *= normI;
}
return norm;
......@@ -145,7 +146,7 @@ RealOpenMM AmoebaReferenceForce::normalizeVector3(RealOpenMM* inputVector) {
--------------------------------------------------------------------------------------- */
RealOpenMM AmoebaReferenceForce::getDotProduct3(const std::vector<RealOpenMM>& xVector, const std::vector<RealOpenMM>& yVector) {
double AmoebaReferenceForce::getDotProduct3(const std::vector<double>& xVector, const std::vector<double>& yVector) {
// get dot product
return xVector[0]*yVector[0] + xVector[1]*yVector[1] + xVector[2]*yVector[2];
......@@ -162,13 +163,13 @@ RealOpenMM AmoebaReferenceForce::getDotProduct3(const std::vector<RealOpenMM>& x
--------------------------------------------------------------------------------------- */
RealOpenMM AmoebaReferenceForce::getDotProduct3(const RealOpenMM* xVector, const RealOpenMM* yVector) {
double AmoebaReferenceForce::getDotProduct3(const double* xVector, const double* yVector) {
// get dot product
return xVector[0]*yVector[0] + xVector[1]*yVector[1] + xVector[2]*yVector[2];
}
RealOpenMM AmoebaReferenceForce::getDotProduct3(const RealOpenMM* xVector, const OpenMM::Vec3& yVector) {
double AmoebaReferenceForce::getDotProduct3(const double* xVector, const OpenMM::Vec3& yVector) {
// get dot product
return xVector[0]*yVector[0] + xVector[1]*yVector[1] + xVector[2]*yVector[2];
......@@ -186,7 +187,7 @@ RealOpenMM AmoebaReferenceForce::getDotProduct3(const RealOpenMM* xVector, const
--------------------------------------------------------------------------------------- */
RealOpenMM AmoebaReferenceForce::getDotProduct3(unsigned int vectorOffset, const std::vector<RealOpenMM>& xVector, const RealOpenMM* yVector) {
double AmoebaReferenceForce::getDotProduct3(unsigned int vectorOffset, const std::vector<double>& xVector, const double* yVector) {
// get dot product
return xVector[vectorOffset+0]*yVector[0] + xVector[vectorOffset+1]*yVector[1] + xVector[vectorOffset+2]*yVector[2];
......@@ -202,9 +203,9 @@ RealOpenMM AmoebaReferenceForce::getDotProduct3(unsigned int vectorOffset, const
--------------------------------------------------------------------------------------- */
void AmoebaReferenceForce::getCrossProduct(const std::vector<RealOpenMM>& xVector,
const std::vector<RealOpenMM>& yVector,
std::vector<RealOpenMM>& zVector) {
void AmoebaReferenceForce::getCrossProduct(const std::vector<double>& xVector,
const std::vector<double>& yVector,
std::vector<double>& zVector) {
zVector[0] = xVector[1]*yVector[2] - xVector[2]*yVector[1];
zVector[1] = xVector[2]*yVector[0] - xVector[0]*yVector[2];
zVector[2] = xVector[0]*yVector[1] - xVector[1]*yVector[0];
......@@ -220,9 +221,9 @@ void AmoebaReferenceForce::getCrossProduct(const std::vector<RealOpenMM>& xVecto
--------------------------------------------------------------------------------------- */
void AmoebaReferenceForce::getCrossProduct(const RealOpenMM* xVector,
const RealOpenMM* yVector,
RealOpenMM* zVector) {
void AmoebaReferenceForce::getCrossProduct(const double* xVector,
const double* yVector,
double* zVector) {
zVector[0] = xVector[1]*yVector[2] - xVector[2]*yVector[1];
zVector[1] = xVector[2]*yVector[0] - xVector[0]*yVector[2];
zVector[2] = xVector[0]*yVector[1] - xVector[1]*yVector[0];
......
......@@ -25,7 +25,6 @@
#ifndef __AmoebaReferenceForce_H__
#define __AmoebaReferenceForce_H__
#include "RealVec.h"
#include "openmm/Vec3.h"
#include <vector>
......@@ -62,8 +61,8 @@ public:
--------------------------------------------------------------------------------------- */
static void loadDeltaR(const OpenMM::RealVec& xVector, const OpenMM::RealVec& yVector,
std::vector<RealOpenMM>& deltaR);
static void loadDeltaR(const OpenMM::Vec3& xVector, const OpenMM::Vec3& yVector,
std::vector<double>& deltaR);
/**---------------------------------------------------------------------------------------
Load delta of two vectors, applying periodic boundary conditions
......@@ -75,7 +74,7 @@ public:
--------------------------------------------------------------------------------------- */
static void loadDeltaRPeriodic(const RealVec& xVector, const RealVec& yVector, std::vector<RealOpenMM>& deltaR, const RealVec* boxVectors);
static void loadDeltaRPeriodic(const Vec3& xVector, const Vec3& yVector, std::vector<double>& deltaR, const Vec3* boxVectors);
/**---------------------------------------------------------------------------------------
......@@ -87,8 +86,8 @@ public:
--------------------------------------------------------------------------------------- */
static RealOpenMM getNormSquared3(const std::vector<RealOpenMM>& inputVector);
static RealOpenMM getNormSquared3(const RealOpenMM* inputVector);
static double getNormSquared3(const std::vector<double>& inputVector);
static double getNormSquared3(const double* inputVector);
/**---------------------------------------------------------------------------------------
......@@ -100,8 +99,8 @@ public:
--------------------------------------------------------------------------------------- */
static RealOpenMM getNorm3(const std::vector<RealOpenMM>& inputVector);
static RealOpenMM getNorm3(const RealOpenMM* inputVector);
static double getNorm3(const std::vector<double>& inputVector);
static double getNorm3(const double* inputVector);
/**---------------------------------------------------------------------------------------
......@@ -113,7 +112,7 @@ public:
--------------------------------------------------------------------------------------- */
static RealOpenMM normalizeVector3(RealOpenMM* inputVector);
static double normalizeVector3(double* inputVector);
/**---------------------------------------------------------------------------------------
......@@ -126,10 +125,10 @@ public:
--------------------------------------------------------------------------------------- */
static RealOpenMM getDotProduct3(const std::vector<RealOpenMM>& xVector, const std::vector<RealOpenMM>& yVector);
static RealOpenMM getDotProduct3(const RealOpenMM* xVector, const RealOpenMM* yVector);
static RealOpenMM getDotProduct3(const RealOpenMM* xVector, const OpenMM::Vec3& yVector);
static RealOpenMM getDotProduct3(unsigned int vectorOffset, const std::vector<RealOpenMM>& xVector, const RealOpenMM* yVector);
static double getDotProduct3(const std::vector<double>& xVector, const std::vector<double>& yVector);
static double getDotProduct3(const double* xVector, const double* yVector);
static double getDotProduct3(const double* xVector, const OpenMM::Vec3& yVector);
static double getDotProduct3(unsigned int vectorOffset, const std::vector<double>& xVector, const double* yVector);
/**---------------------------------------------------------------------------------------
......@@ -141,10 +140,10 @@ public:
--------------------------------------------------------------------------------------- */
static void getCrossProduct(const std::vector<RealOpenMM>& xVector, const std::vector<RealOpenMM>& yVector,
std::vector<RealOpenMM>& zVector);
static void getCrossProduct(const std::vector<double>& xVector, const std::vector<double>& yVector,
std::vector<double>& zVector);
static void getCrossProduct(const RealOpenMM* xVector, const RealOpenMM* yVector, RealOpenMM* zVector);
static void getCrossProduct(const double* xVector, const double* yVector, double* zVector);
};
......
......@@ -22,6 +22,7 @@
*/
#include "AmoebaReferenceGeneralizedKirkwoodForce.h"
#include <cmath>
using std::vector;
using namespace OpenMM;
......@@ -61,120 +62,113 @@ int AmoebaReferenceGeneralizedKirkwoodForce::getDirectPolarization() const {
return _directPolarization;
}
void AmoebaReferenceGeneralizedKirkwoodForce::setSoluteDielectric(RealOpenMM soluteDielectric) {
void AmoebaReferenceGeneralizedKirkwoodForce::setSoluteDielectric(double soluteDielectric) {
_soluteDielectric = soluteDielectric;
}
RealOpenMM AmoebaReferenceGeneralizedKirkwoodForce::getSoluteDielectric() const {
double AmoebaReferenceGeneralizedKirkwoodForce::getSoluteDielectric() const {
return _soluteDielectric;
}
void AmoebaReferenceGeneralizedKirkwoodForce::setSolventDielectric(RealOpenMM solventDielectric) {
void AmoebaReferenceGeneralizedKirkwoodForce::setSolventDielectric(double solventDielectric) {
_solventDielectric = solventDielectric;
}
RealOpenMM AmoebaReferenceGeneralizedKirkwoodForce::getSolventDielectric() const {
double AmoebaReferenceGeneralizedKirkwoodForce::getSolventDielectric() const {
return _solventDielectric;
}
void AmoebaReferenceGeneralizedKirkwoodForce::setDielectricOffset(RealOpenMM dielectricOffset) {
void AmoebaReferenceGeneralizedKirkwoodForce::setDielectricOffset(double dielectricOffset) {
_dielectricOffset = dielectricOffset;
}
RealOpenMM AmoebaReferenceGeneralizedKirkwoodForce::getDielectricOffset() const {
double AmoebaReferenceGeneralizedKirkwoodForce::getDielectricOffset() const {
return _dielectricOffset;
}
void AmoebaReferenceGeneralizedKirkwoodForce::setProbeRadius(RealOpenMM probeRadius) {
void AmoebaReferenceGeneralizedKirkwoodForce::setProbeRadius(double probeRadius) {
_probeRadius = probeRadius;
}
RealOpenMM AmoebaReferenceGeneralizedKirkwoodForce::getProbeRadius() const {
double AmoebaReferenceGeneralizedKirkwoodForce::getProbeRadius() const {
return _probeRadius;
}
void AmoebaReferenceGeneralizedKirkwoodForce::setSurfaceAreaFactor(RealOpenMM surfaceAreaFactor) {
void AmoebaReferenceGeneralizedKirkwoodForce::setSurfaceAreaFactor(double surfaceAreaFactor) {
_surfaceAreaFactor = surfaceAreaFactor;
}
RealOpenMM AmoebaReferenceGeneralizedKirkwoodForce::getSurfaceAreaFactor() const {
double AmoebaReferenceGeneralizedKirkwoodForce::getSurfaceAreaFactor() const {
return _surfaceAreaFactor;
}
void AmoebaReferenceGeneralizedKirkwoodForce::setAtomicRadii(const vector<RealOpenMM>& atomicRadii) {
void AmoebaReferenceGeneralizedKirkwoodForce::setAtomicRadii(const vector<double>& atomicRadii) {
_atomicRadii.resize(atomicRadii.size());
copy(atomicRadii.begin(), atomicRadii.end(), _atomicRadii.begin());
}
void AmoebaReferenceGeneralizedKirkwoodForce::getAtomicRadii(vector<RealOpenMM>& atomicRadii) const {
void AmoebaReferenceGeneralizedKirkwoodForce::getAtomicRadii(vector<double>& atomicRadii) const {
atomicRadii.resize(_atomicRadii.size());
copy(_atomicRadii.begin(), _atomicRadii.end(), atomicRadii.begin());
}
void AmoebaReferenceGeneralizedKirkwoodForce::setScaleFactors(const vector<RealOpenMM>& scaleFactors) {
void AmoebaReferenceGeneralizedKirkwoodForce::setScaleFactors(const vector<double>& scaleFactors) {
_scaleFactors.resize(scaleFactors.size());
copy(scaleFactors.begin(), scaleFactors.end(), _scaleFactors.begin());
}
void AmoebaReferenceGeneralizedKirkwoodForce::getScaleFactors(vector<RealOpenMM>& scaleFactors) const {
void AmoebaReferenceGeneralizedKirkwoodForce::getScaleFactors(vector<double>& scaleFactors) const {
scaleFactors.resize(_scaleFactors.size());
copy(_scaleFactors.begin(), _scaleFactors.end(), scaleFactors.begin());
}
void AmoebaReferenceGeneralizedKirkwoodForce::setCharges(const vector<RealOpenMM>& charges) {
void AmoebaReferenceGeneralizedKirkwoodForce::setCharges(const vector<double>& charges) {
_charges.resize(charges.size());
copy(charges.begin(), charges.end(), _charges.begin());
}
void AmoebaReferenceGeneralizedKirkwoodForce::getGrycukBornRadii(vector<RealOpenMM>& bornRadii) const {
void AmoebaReferenceGeneralizedKirkwoodForce::getGrycukBornRadii(vector<double>& bornRadii) const {
bornRadii.resize(_bornRadii.size());
copy(_bornRadii.begin(), _bornRadii.end(), bornRadii.begin());
}
void AmoebaReferenceGeneralizedKirkwoodForce::calculateGrycukBornRadii(const vector<RealVec>& particlePositions) {
void AmoebaReferenceGeneralizedKirkwoodForce::calculateGrycukBornRadii(const vector<Vec3>& particlePositions) {
const RealOpenMM zero = 0.0;
const RealOpenMM one = 1.0;
const RealOpenMM three = 3.0;
const RealOpenMM six = 6.0;
const RealOpenMM eight = 8.0;
const RealOpenMM sixteen = 16.0;
const RealOpenMM oneThird = 1.0/3.0;
const RealOpenMM bigRadius = 1000.0;
const double bigRadius = 1000.0;
_bornRadii.resize(_numParticles);
for (unsigned int ii = 0; ii < _numParticles; ii++) {
if (_atomicRadii[ii] <= zero) {
if (_atomicRadii[ii] <= 0.0) {
_bornRadii[ii] = bigRadius;
continue;
}
RealOpenMM bornSum = zero;
double bornSum = 0.0;
for (unsigned int jj = 0; jj < _numParticles; jj++) {
if (ii == jj || _atomicRadii[jj] < zero)continue;
if (ii == jj || _atomicRadii[jj] < 0.0)continue;
RealOpenMM xr = particlePositions[jj][0] - particlePositions[ii][0];
RealOpenMM yr = particlePositions[jj][1] - particlePositions[ii][1];
RealOpenMM zr = particlePositions[jj][2] - particlePositions[ii][2];
double xr = particlePositions[jj][0] - particlePositions[ii][0];
double yr = particlePositions[jj][1] - particlePositions[ii][1];
double zr = particlePositions[jj][2] - particlePositions[ii][2];
RealOpenMM r2 = xr*xr + yr*yr + zr*zr;
RealOpenMM r = SQRT(r2);
double r2 = xr*xr + yr*yr + zr*zr;
double r = sqrt(r2);
RealOpenMM sk = _atomicRadii[jj]*_scaleFactors[jj];
RealOpenMM sk2 = sk*sk;
double sk = _atomicRadii[jj]*_scaleFactors[jj];
double sk2 = sk*sk;
if ((_atomicRadii[ii] + r) < sk) {
RealOpenMM lik = _atomicRadii[ii];
RealOpenMM uik = sk - r;
RealOpenMM lik3 = lik*lik*lik;
RealOpenMM uik3 = uik*uik*uik;
bornSum -= (one/uik3 - one/lik3);
double lik = _atomicRadii[ii];
double uik = sk - r;
double lik3 = lik*lik*lik;
double uik3 = uik*uik*uik;
bornSum -= (1.0/uik3 - 1.0/lik3);
}
RealOpenMM uik = r + sk;
RealOpenMM lik;
double uik = r + sk;
double lik;
if ((_atomicRadii[ii] + r) < sk) {
lik = sk - r;
} else if (r < (_atomicRadii[ii] + sk)) {
......@@ -183,22 +177,22 @@ void AmoebaReferenceGeneralizedKirkwoodForce::calculateGrycukBornRadii(const vec
lik = r - sk;
}
RealOpenMM l2 = lik*lik;
RealOpenMM l4 = l2*l2;
RealOpenMM lr = lik*r;
RealOpenMM l4r = l4*r;
double l2 = lik*lik;
double l4 = l2*l2;
double lr = lik*r;
double l4r = l4*r;
RealOpenMM u2 = uik*uik;
RealOpenMM u4 = u2*u2;
RealOpenMM ur = uik*r;
RealOpenMM u4r = u4*r;
double u2 = uik*uik;
double u4 = u2*u2;
double ur = uik*r;
double u4r = u4*r;
RealOpenMM term = (three*(r2-sk2) + six*u2 - eight*ur)/u4r - (three*(r2-sk2) + six*l2 - eight*lr)/l4r;
bornSum += term/sixteen;
double term = (3.0*(r2-sk2) + 6.0*u2 - 8.0*ur)/u4r - (3.0*(r2-sk2) + 6.0*l2 - 8.0*lr)/l4r;
bornSum += term/16.0;
}
bornSum = one/(_atomicRadii[ii]*_atomicRadii[ii]*_atomicRadii[ii]) - bornSum;
_bornRadii[ii] = (bornSum <= zero) ? bigRadius : POW(bornSum, -oneThird);
bornSum = 1.0/(_atomicRadii[ii]*_atomicRadii[ii]*_atomicRadii[ii]) - bornSum;
_bornRadii[ii] = (bornSum <= 0.0) ? bigRadius : pow(bornSum, -1.0/3.0);
}
return;
......
......@@ -25,7 +25,7 @@
#ifndef __AmoebaReferenceGeneralizedKirkwoodForce_H__
#define __AmoebaReferenceGeneralizedKirkwoodForce_H__
#include "RealVec.h"
#include "openmm/Vec3.h"
#include <vector>
using namespace OpenMM;
......@@ -101,7 +101,7 @@ public:
*
* @return soluteDielectric
*/
RealOpenMM getSoluteDielectric() const;
double getSoluteDielectric() const;
/**
* Set solute dielectric
......@@ -109,7 +109,7 @@ public:
* @param soluteDielectric solute dielectric
*
*/
void setSoluteDielectric(RealOpenMM soluteDielectric);
void setSoluteDielectric(double soluteDielectric);
/**
* Get solvent dielectric
......@@ -117,7 +117,7 @@ public:
* @return solventDielectric
*
*/
RealOpenMM getSolventDielectric() const;
double getSolventDielectric() const;
/**
* Set solvent dielectric
......@@ -125,7 +125,7 @@ public:
* @param solventDielectric solvent dielectric
*
*/
void setSolventDielectric(RealOpenMM solventDielectric);
void setSolventDielectric(double solventDielectric);
/**
* Get dielectric offset
......@@ -133,7 +133,7 @@ public:
* @return dielectricOffset
*
*/
RealOpenMM getDielectricOffset() const;
double getDielectricOffset() const;
/**
* Set dielectric offset
......@@ -141,7 +141,7 @@ public:
* @param dielectricOffset dielectric offset
*
*/
void setDielectricOffset(RealOpenMM dielectricOffset);
void setDielectricOffset(double dielectricOffset);
/**
* Get probeRadius
......@@ -149,7 +149,7 @@ public:
* @return probeRadius
*
*/
RealOpenMM getProbeRadius() const;
double getProbeRadius() const;
/**
* Set probe radius
......@@ -157,7 +157,7 @@ public:
* @param probeRadius probe radiue
*
*/
void setProbeRadius(RealOpenMM probeRadius);
void setProbeRadius(double probeRadius);
/**
* Get surfaceAreaFactor
......@@ -165,7 +165,7 @@ public:
* @return surfaceAreaFactor
*
*/
RealOpenMM getSurfaceAreaFactor() const;
double getSurfaceAreaFactor() const;
/**
* Set surface area factor
......@@ -173,7 +173,7 @@ public:
* @param surfaceAreaFactor surface area factor
*
*/
void setSurfaceAreaFactor(RealOpenMM surfaceAreaFactor);
void setSurfaceAreaFactor(double surfaceAreaFactor);
/**
* Set atomic radii
......@@ -181,7 +181,7 @@ public:
* @param atomicRadii input vector of atomic radii
*
*/
void setAtomicRadii(const vector<RealOpenMM>& atomicRadii);
void setAtomicRadii(const vector<double>& atomicRadii);
/**
* Get atomic radii
......@@ -189,7 +189,7 @@ public:
* @param atomicRadii output vector of atomic radii
*
*/
void getAtomicRadii(vector<RealOpenMM>& atomicRadii) const;
void getAtomicRadii(vector<double>& atomicRadii) const;
/**
* Set scale factors
......@@ -197,7 +197,7 @@ public:
* @param scaleFactors input vector of scale factors
*
*/
void setScaleFactors(const vector<RealOpenMM>& scaleFactors);
void setScaleFactors(const vector<double>& scaleFactors);
/**
* Get scale factors
......@@ -205,7 +205,7 @@ public:
* @param scaleFactors output vector of scale factors
*
*/
void getScaleFactors(vector<RealOpenMM>& scaleFactors) const;
void getScaleFactors(vector<double>& scaleFactors) const;
/**
* Set charges
......@@ -213,7 +213,7 @@ public:
* @param charges input vector of charges
*
*/
void setCharges(const vector<RealOpenMM>& charges);
void setCharges(const vector<double>& charges);
/**
* Calculate Grycuk Born radii
......@@ -221,7 +221,7 @@ public:
* @param particlePositions particle positions
*
*/
void calculateGrycukBornRadii(const vector<RealVec>& particlePositions);
void calculateGrycukBornRadii(const vector<Vec3>& particlePositions);
/**
* Get Grycik Born radii (must have called calculateGrycukBornRadii())
......@@ -229,7 +229,7 @@ public:
* @param bornRadii vector of Born radii
*
*/
void getGrycukBornRadii(vector<RealOpenMM>& bornRadii) const;
void getGrycukBornRadii(vector<double>& bornRadii) const;
private:
......@@ -237,17 +237,17 @@ private:
int _includeCavityTerm;
int _directPolarization;
RealOpenMM _soluteDielectric;
RealOpenMM _solventDielectric;
RealOpenMM _dielectricOffset;
RealOpenMM _probeRadius;
RealOpenMM _surfaceAreaFactor;
double _soluteDielectric;
double _solventDielectric;
double _dielectricOffset;
double _probeRadius;
double _surfaceAreaFactor;
std::vector<RealOpenMM> _atomicRadii;
std::vector<RealOpenMM> _scaleFactors;
std::vector<RealOpenMM> _charges;
std::vector<double> _atomicRadii;
std::vector<double> _scaleFactors;
std::vector<double> _charges;
std::vector<RealOpenMM> _bornRadii;
std::vector<double> _bornRadii;
};
......
......@@ -25,11 +25,12 @@
#include "AmoebaReferenceForce.h"
#include "AmoebaReferenceInPlaneAngleForce.h"
#include "ReferenceForce.h"
#include "SimTKOpenMMRealType.h"
using std::vector;
using namespace OpenMM;
void AmoebaReferenceInPlaneAngleForce::setPeriodic(OpenMM::RealVec* vectors) {
void AmoebaReferenceInPlaneAngleForce::setPeriodic(OpenMM::Vec3* vectors) {
usePeriodic = true;
boxVectors[0] = vectors[0];
boxVectors[1] = vectors[1];
......@@ -54,49 +55,34 @@ void AmoebaReferenceInPlaneAngleForce::setPeriodic(OpenMM::RealVec* vectors) {
--------------------------------------------------------------------------------------- */
RealOpenMM AmoebaReferenceInPlaneAngleForce::getPrefactorsGivenAngleCosine(RealOpenMM cosine,
RealOpenMM idealAngle, RealOpenMM angleK,
RealOpenMM angleCubic, RealOpenMM angleQuartic,
RealOpenMM anglePentic, RealOpenMM angleSextic,
RealOpenMM* dEdR) const {
// ---------------------------------------------------------------------------------------
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
static const RealOpenMM two = 2.0;
static const RealOpenMM three = 3.0;
static const RealOpenMM four = 4.0;
static const RealOpenMM five = 5.0;
static const RealOpenMM six = 6.0;
// static const std::string methodName = "AmoebaReferenceInPlaneAngleForce::getPrefactorsGivenAngleCosine";
// ---------------------------------------------------------------------------------------
RealOpenMM angle;
if (cosine >= one) {
angle = zero;
} else if (cosine <= -one) {
double AmoebaReferenceInPlaneAngleForce::getPrefactorsGivenAngleCosine(double cosine,
double idealAngle, double angleK,
double angleCubic, double angleQuartic,
double anglePentic, double angleSextic,
double* dEdR) const {
double angle;
if (cosine >= 1.0) {
angle = 0.0;
} else if (cosine <= -1.0) {
angle = RADIAN*PI_M;
} else {
angle = RADIAN*ACOS(cosine);
}
RealOpenMM deltaIdeal = angle - idealAngle;
RealOpenMM deltaIdeal2 = deltaIdeal*deltaIdeal;
RealOpenMM deltaIdeal3 = deltaIdeal*deltaIdeal2;
RealOpenMM deltaIdeal4 = deltaIdeal2*deltaIdeal2;
double deltaIdeal = angle - idealAngle;
double deltaIdeal2 = deltaIdeal*deltaIdeal;
double deltaIdeal3 = deltaIdeal*deltaIdeal2;
double deltaIdeal4 = deltaIdeal2*deltaIdeal2;
*dEdR = (two + three*angleCubic*deltaIdeal +
four*angleQuartic*deltaIdeal2 +
five*anglePentic*deltaIdeal3 +
six*angleSextic*deltaIdeal4);
*dEdR = (2.0 + 3.0*angleCubic*deltaIdeal +
4.0*angleQuartic*deltaIdeal2 +
5.0*anglePentic*deltaIdeal3 +
6.0*angleSextic*deltaIdeal4);
*dEdR *= RADIAN*angleK*deltaIdeal;
*dEdR *= RADIAN*angleK*deltaIdeal;
RealOpenMM energy = 1.0f + angleCubic*deltaIdeal + angleQuartic*deltaIdeal2 +
anglePentic*deltaIdeal3 + angleSextic*deltaIdeal4;
energy *= angleK*deltaIdeal2;
double energy = 1.0f + angleCubic*deltaIdeal + angleQuartic*deltaIdeal2 +
anglePentic*deltaIdeal3 + angleSextic*deltaIdeal4;
energy *= angleK*deltaIdeal2;
return energy;
......@@ -122,12 +108,12 @@ RealOpenMM AmoebaReferenceInPlaneAngleForce::getPrefactorsGivenAngleCosine(RealO
--------------------------------------------------------------------------------------- */
RealOpenMM AmoebaReferenceInPlaneAngleForce::calculateAngleIxn(const RealVec& positionAtomA, const RealVec& positionAtomB,
const RealVec& positionAtomC, const RealVec& positionAtomD,
RealOpenMM angle, RealOpenMM angleK,
RealOpenMM angleCubic, RealOpenMM angleQuartic,
RealOpenMM anglePentic, RealOpenMM angleSextic,
RealVec* forces) const {
double AmoebaReferenceInPlaneAngleForce::calculateAngleIxn(const Vec3& positionAtomA, const Vec3& positionAtomB,
const Vec3& positionAtomC, const Vec3& positionAtomD,
double angle, double angleK,
double angleCubic, double angleQuartic,
double anglePentic, double angleSextic,
Vec3* forces) const {
// T = AD x CD
// P = B + T*delta
// AP = A - P
......@@ -136,7 +122,7 @@ RealOpenMM AmoebaReferenceInPlaneAngleForce::calculateAngleIxn(const RealVec& po
enum { AD, BD, CD, T, AP, P, CP, M, APxM, CPxM, ADxBD, BDxCD, TxCD, ADxT, dBxAD, CDxdB, LastDeltaAtomIndex };
RealVec deltaR[LastDeltaAtomIndex];
Vec3 deltaR[LastDeltaAtomIndex];
if (usePeriodic) {
deltaR[AD] = ReferenceForce::getDeltaRPeriodic(positionAtomD, positionAtomA, boxVectors);
deltaR[BD] = ReferenceForce::getDeltaRPeriodic(positionAtomD, positionAtomB, boxVectors);
......@@ -150,9 +136,8 @@ RealOpenMM AmoebaReferenceInPlaneAngleForce::calculateAngleIxn(const RealVec& po
deltaR[T] = deltaR[AD].cross(deltaR[CD]);
RealOpenMM rT2 = deltaR[T].dot(deltaR[T]);
RealOpenMM delta = deltaR[T].dot(deltaR[BD])/rT2;
delta *= -1;
double rT2 = deltaR[T].dot(deltaR[T]);
double delta = -deltaR[T].dot(deltaR[BD])/rT2;
deltaR[P] = positionAtomB + deltaR[T]*delta;
if (usePeriodic) {
......@@ -164,28 +149,28 @@ RealOpenMM AmoebaReferenceInPlaneAngleForce::calculateAngleIxn(const RealVec& po
deltaR[CP] = ReferenceForce::getDeltaR(deltaR[P], positionAtomC);
}
RealOpenMM rAp2 = deltaR[AP].dot(deltaR[AP]);
RealOpenMM rCp2 = deltaR[CP].dot(deltaR[CP]);
double rAp2 = deltaR[AP].dot(deltaR[AP]);
double rCp2 = deltaR[CP].dot(deltaR[CP]);
if (rAp2 <= 0 && rCp2 <= 0) {
return 0;
}
deltaR[M] = deltaR[CP].cross(deltaR[AP]);
RealOpenMM rm = SQRT(deltaR[M].dot(deltaR[M]));
double rm = sqrt(deltaR[M].dot(deltaR[M]));
if (rm < 1.0e-06) {
rm = 1.0e-06;
}
RealOpenMM dot = deltaR[AP].dot(deltaR[CP]);
RealOpenMM cosine = dot/SQRT(rAp2*rCp2);
double dot = deltaR[AP].dot(deltaR[CP]);
double cosine = dot/SQRT(rAp2*rCp2);
RealOpenMM dEdR;
RealOpenMM energy = getPrefactorsGivenAngleCosine(cosine, angle, angleK, angleCubic, angleQuartic,
double dEdR;
double energy = getPrefactorsGivenAngleCosine(cosine, angle, angleK, angleCubic, angleQuartic,
anglePentic, angleSextic, &dEdR);
RealOpenMM termA = -dEdR/(rAp2*rm);
RealOpenMM termC = dEdR/(rCp2*rm);
double termA = -dEdR/(rAp2*rm);
double termC = dEdR/(rCp2*rm);
deltaR[APxM] = deltaR[AP].cross(deltaR[M]);
deltaR[CPxM] = deltaR[CP].cross(deltaR[M]);
......@@ -193,27 +178,27 @@ RealOpenMM AmoebaReferenceInPlaneAngleForce::calculateAngleIxn(const RealVec& po
// forces will be gathered here
enum { dA, dB, dC, dD, LastDIndex };
RealVec forceTerm[LastDIndex];
Vec3 forceTerm[LastDIndex];
forceTerm[dA] = deltaR[APxM]*termA;
forceTerm[dC] = deltaR[CPxM]*termC;
forceTerm[dB] = -(forceTerm[dA] + forceTerm[dC]);
RealOpenMM pTrT2 = forceTerm[dB].dot(deltaR[T]);
pTrT2 /= rT2;
double pTrT2 = forceTerm[dB].dot(deltaR[T]);
pTrT2 /= rT2;
deltaR[CDxdB] = deltaR[CD].cross(forceTerm[dB]);
deltaR[dBxAD] = forceTerm[dB].cross(deltaR[AD]);
if (FABS(pTrT2) > 1.0e-08) {
RealOpenMM delta2 = delta*2;
double delta2 = delta*2;
deltaR[BDxCD] = forceTerm[dB].cross(deltaR[CD]);
deltaR[TxCD] = forceTerm[T].cross(deltaR[CD]);
deltaR[ADxBD] = forceTerm[AD].cross(deltaR[BD]);
deltaR[ADxT] = forceTerm[AD].cross(deltaR[T]);
RealVec term = deltaR[BDxCD] + deltaR[TxCD]*delta2;
Vec3 term = deltaR[BDxCD] + deltaR[TxCD]*delta2;
forceTerm[dA] += deltaR[CDxdB]*delta + term*pTrT2;
term = deltaR[ADxBD] + deltaR[ADxT]*delta2;
forceTerm[dC] += deltaR[dBxAD]*delta + term*pTrT2;
......@@ -233,29 +218,29 @@ RealOpenMM AmoebaReferenceInPlaneAngleForce::calculateAngleIxn(const RealVec& po
}
RealOpenMM AmoebaReferenceInPlaneAngleForce::calculateForceAndEnergy(int numAngles, vector<RealVec>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<int>& particle4,
const std::vector<RealOpenMM>& angle,
const std::vector<RealOpenMM>& kQuadratic,
RealOpenMM angleCubic,
RealOpenMM angleQuartic,
RealOpenMM anglePentic,
RealOpenMM angleSextic,
vector<RealVec>& forceData) const {
RealOpenMM energy = 0.0;
double AmoebaReferenceInPlaneAngleForce::calculateForceAndEnergy(int numAngles, vector<Vec3>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<int>& particle4,
const std::vector<double>& angle,
const std::vector<double>& kQuadratic,
double angleCubic,
double angleQuartic,
double anglePentic,
double angleSextic,
vector<Vec3>& forceData) const {
double energy = 0.0;
for (unsigned int ii = 0; ii < static_cast<unsigned int>(numAngles); ii++) {
int particle1Index = particle1[ii];
int particle2Index = particle2[ii];
int particle3Index = particle3[ii];
int particle4Index = particle4[ii];
RealOpenMM idealAngle = angle[ii];
RealOpenMM angleK = kQuadratic[ii];
RealVec forces[4];
energy += calculateAngleIxn(posData[particle1Index], posData[particle2Index], posData[particle3Index], posData[particle4Index],
idealAngle, angleK, angleCubic, angleQuartic, anglePentic, angleSextic, forces);
int particle1Index = particle1[ii];
int particle2Index = particle2[ii];
int particle3Index = particle3[ii];
int particle4Index = particle4[ii];
double idealAngle = angle[ii];
double angleK = kQuadratic[ii];
Vec3 forces[4];
energy += calculateAngleIxn(posData[particle1Index], posData[particle2Index], posData[particle3Index], posData[particle4Index],
idealAngle, angleK, angleCubic, angleQuartic, anglePentic, angleSextic, forces);
// accumulate forces
......
......@@ -25,7 +25,7 @@
#ifndef __AmoebaReferenceInPlaneAngleForce_H__
#define __AmoebaReferenceInPlaneAngleForce_H__
#include "RealVec.h"
#include "openmm/Vec3.h"
#include <vector>
namespace OpenMM {
......@@ -58,7 +58,7 @@ public:
--------------------------------------------------------------------------------------- */
void setPeriodic(OpenMM::RealVec* vectors);
void setPeriodic(OpenMM::Vec3* vectors);
/**---------------------------------------------------------------------------------------
......@@ -83,23 +83,23 @@ public:
--------------------------------------------------------------------------------------- */
RealOpenMM calculateForceAndEnergy(int numAngles, std::vector<OpenMM::RealVec>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<int>& particle4,
const std::vector<RealOpenMM>& angle,
const std::vector<RealOpenMM>& kQuadratic,
RealOpenMM globalAngleCubic,
RealOpenMM globalAngleQuartic,
RealOpenMM globalAnglePentic,
RealOpenMM globalAngleSextic,
std::vector<OpenMM::RealVec>& forceData) const;
double calculateForceAndEnergy(int numAngles, std::vector<OpenMM::Vec3>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<int>& particle4,
const std::vector<double>& angle,
const std::vector<double>& kQuadratic,
double globalAngleCubic,
double globalAngleQuartic,
double globalAnglePentic,
double globalAngleSextic,
std::vector<OpenMM::Vec3>& forceData) const;
private:
bool usePeriodic;
RealVec boxVectors[3];
Vec3 boxVectors[3];
/**---------------------------------------------------------------------------------------
......@@ -119,11 +119,11 @@ private:
--------------------------------------------------------------------------------------- */
RealOpenMM getPrefactorsGivenAngleCosine(RealOpenMM cosine, RealOpenMM idealAngle, RealOpenMM angleK,
RealOpenMM angleCubic, RealOpenMM angleQuartic,
RealOpenMM anglePentic, RealOpenMM angleSextic,
RealOpenMM* dEdR) const;
double getPrefactorsGivenAngleCosine(double cosine, double idealAngle, double angleK,
double angleCubic, double angleQuartic,
double anglePentic, double angleSextic,
double* dEdR) const;
/**---------------------------------------------------------------------------------------
Calculate Amoeba angle ixn (force and energy)
......@@ -144,12 +144,12 @@ private:
--------------------------------------------------------------------------------------- */
RealOpenMM calculateAngleIxn(const OpenMM::RealVec& positionAtomA, const OpenMM::RealVec& positionAtomB,
const OpenMM::RealVec& positionAtomC, const OpenMM::RealVec& positionAtomD,
RealOpenMM angle, RealOpenMM angleK,
RealOpenMM angleCubic, RealOpenMM angleQuartic,
RealOpenMM anglePentic, RealOpenMM angleSextic,
OpenMM::RealVec* forces) const;
double calculateAngleIxn(const OpenMM::Vec3& positionAtomA, const OpenMM::Vec3& positionAtomB,
const OpenMM::Vec3& positionAtomC, const OpenMM::Vec3& positionAtomD,
double angle, double angleK,
double angleCubic, double angleQuartic,
double anglePentic, double angleSextic,
OpenMM::Vec3* forces) const;
};
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -24,8 +24,8 @@
#ifndef __AmoebaReferenceMultipoleForce_H__
#define __AmoebaReferenceMultipoleForce_H__
#include "RealVec.h"
#include "openmm/AmoebaMultipoleForce.h"
#include "openmm/Vec3.h"
#include "AmoebaReferenceGeneralizedKirkwoodForce.h"
#include <map>
#include "fftpack.h"
......@@ -33,22 +33,22 @@
namespace OpenMM {
typedef std::map< unsigned int, RealOpenMM> MapIntRealOpenMM;
typedef std::map< unsigned int, double> MapIntRealOpenMM;
typedef MapIntRealOpenMM::iterator MapIntRealOpenMMI;
typedef MapIntRealOpenMM::const_iterator MapIntRealOpenMMCI;
// A few useful constants for the spherical harmonic multipole code.
const RealOpenMM oneThird = 1.0/3.0;
const RealOpenMM twoThirds = 2.0/3.0;
const RealOpenMM fourThirds = 4.0/3.0;
const RealOpenMM fourSqrtOneThird = 4.0/sqrt(3.0);
const RealOpenMM sqrtFourThirds = 2.0/sqrt(3.0);
const RealOpenMM sqrtOneThird = 1.0/sqrt(3.0);
const RealOpenMM sqrtThree = sqrt(3.0);
const RealOpenMM oneNinth = 1.0/9.0;
const RealOpenMM fourOverFortyFive = 4.0/45.0;
const RealOpenMM fourOverFifteen = 4.0/15.0;
const double oneThird = 1.0/3.0;
const double twoThirds = 2.0/3.0;
const double fourThirds = 4.0/3.0;
const double fourSqrtOneThird = 4.0/sqrt(3.0);
const double sqrtFourThirds = 2.0/sqrt(3.0);
const double sqrtOneThird = 1.0/sqrt(3.0);
const double sqrtThree = sqrt(3.0);
const double oneNinth = 1.0/9.0;
const double fourOverFortyFive = 4.0/45.0;
const double fourOverFifteen = 4.0/15.0;
/**
......@@ -167,30 +167,30 @@ private:
};
/**
* 4-dimensional RealOpenMM vector
* 4-dimensional double vector
*/
class RealOpenMM4 {
class double4 {
public:
/**
* Create a RealOpenMM4 whose elements are all 0.
* Create a double4 whose elements are all 0.
*/
RealOpenMM4() {
double4() {
data[0] = data[1] = data[2] = data[3] = 0.0;
}
/**
* Create a RealOpenMM4 with specified x, y, z, w components.
* Create a double4 with specified x, y, z, w components.
*/
RealOpenMM4(RealOpenMM x, RealOpenMM y, RealOpenMM z, RealOpenMM w) {
double4(double x, double y, double z, double w) {
data[0] = x;
data[1] = y;
data[2] = z;
data[3] = w;
}
RealOpenMM operator[](int index) const {
double operator[](int index) const {
assert(index >= 0 && index < 4);
return data[index];
}
RealOpenMM& operator[](int index) {
double& operator[](int index) {
assert(index >= 0 && index < 4);
return data[index];
}
......@@ -198,17 +198,17 @@ public:
// Arithmetic operators
// unary plus
RealOpenMM4 operator+() const {
return RealOpenMM4(*this);
double4 operator+() const {
return double4(*this);
}
// plus
RealOpenMM4 operator+(const RealOpenMM4& rhs) const {
const RealOpenMM4& lhs = *this;
return RealOpenMM4(lhs[0] + rhs[0], lhs[1] + rhs[1], lhs[2] + rhs[2],lhs[3] + rhs[3]);
double4 operator+(const double4& rhs) const {
const double4& lhs = *this;
return double4(lhs[0] + rhs[0], lhs[1] + rhs[1], lhs[2] + rhs[2],lhs[3] + rhs[3]);
}
RealOpenMM4& operator+=(const RealOpenMM4& rhs) {
double4& operator+=(const double4& rhs) {
data[0] += rhs[0];
data[1] += rhs[1];
data[2] += rhs[2];
......@@ -216,7 +216,7 @@ public:
return *this;
}
RealOpenMM4& operator-=(const RealOpenMM4& rhs) {
double4& operator-=(const double4& rhs) {
data[0] -= rhs[0];
data[1] -= rhs[1];
data[2] -= rhs[2];
......@@ -225,7 +225,7 @@ public:
}
private:
RealOpenMM data[4];
double data[4];
};
using namespace OpenMM;
......@@ -425,7 +425,7 @@ public:
* @return epsilon
*
*/
RealOpenMM getMutualInducedDipoleEpsilon() const;
double getMutualInducedDipoleEpsilon() const;
/**
* Set the coefficients for the µ_0, µ_1, µ_2, µ_n terms in the extrapolation
......@@ -434,7 +434,7 @@ public:
* @param optCoefficients a vector whose mth entry specifies the coefficient for µ_m
*
*/
void setExtrapolationCoefficients(const std::vector<RealOpenMM> &coefficients);
void setExtrapolationCoefficients(const std::vector<double> &coefficients);
/**
* Set the target epsilon for converging mutual induced dipoles.
......@@ -442,7 +442,7 @@ public:
* @param targetEpsilon target epsilon for converging mutual induced dipoles
*
*/
void setMutualInducedDipoleTargetEpsilon(RealOpenMM targetEpsilon);
void setMutualInducedDipoleTargetEpsilon(double targetEpsilon);
/**
* Get the target epsilon for converging mutual induced dipoles.
......@@ -450,7 +450,7 @@ public:
* @return target epsilon for converging mutual induced dipoles
*
*/
RealOpenMM getMutualInducedDipoleTargetEpsilon() const;
double getMutualInducedDipoleTargetEpsilon() const;
/**
* Set the maximum number of iterations to be executed in converging mutual induced dipoles.
......@@ -487,19 +487,19 @@ public:
*
* @return energy
*/
RealOpenMM calculateForceAndEnergy(const std::vector<OpenMM::RealVec>& particlePositions,
const std::vector<RealOpenMM>& charges,
const std::vector<RealOpenMM>& dipoles,
const std::vector<RealOpenMM>& quadrupoles,
const std::vector<RealOpenMM>& tholes,
const std::vector<RealOpenMM>& dampingFactors,
const std::vector<RealOpenMM>& polarity,
const std::vector<int>& axisTypes,
const std::vector<int>& multipoleAtomZs,
const std::vector<int>& multipoleAtomXs,
const std::vector<int>& multipoleAtomYs,
const std::vector< std::vector< std::vector<int> > >& multipoleAtomCovalentInfo,
std::vector<OpenMM::RealVec>& forces);
double calculateForceAndEnergy(const std::vector<OpenMM::Vec3>& particlePositions,
const std::vector<double>& charges,
const std::vector<double>& dipoles,
const std::vector<double>& quadrupoles,
const std::vector<double>& tholes,
const std::vector<double>& dampingFactors,
const std::vector<double>& polarity,
const std::vector<int>& axisTypes,
const std::vector<int>& multipoleAtomZs,
const std::vector<int>& multipoleAtomXs,
const std::vector<int>& multipoleAtomYs,
const std::vector< std::vector< std::vector<int> > >& multipoleAtomCovalentInfo,
std::vector<OpenMM::Vec3>& forces);
/**
* Calculate particle induced dipoles.
......@@ -519,19 +519,19 @@ public:
* @param multipoleAtomCovalentInfo covalent info needed to set scaling factors
* @param outputMultipoleMoments output multipole moments
*/
void calculateInducedDipoles(const std::vector<OpenMM::RealVec>& particlePositions,
const std::vector<RealOpenMM>& charges,
const std::vector<RealOpenMM>& dipoles,
const std::vector<RealOpenMM>& quadrupoles,
const std::vector<RealOpenMM>& tholes,
const std::vector<RealOpenMM>& dampingFactors,
const std::vector<RealOpenMM>& polarity,
void calculateInducedDipoles(const std::vector<OpenMM::Vec3>& particlePositions,
const std::vector<double>& charges,
const std::vector<double>& dipoles,
const std::vector<double>& quadrupoles,
const std::vector<double>& tholes,
const std::vector<double>& dampingFactors,
const std::vector<double>& polarity,
const std::vector<int>& axisTypes,
const std::vector<int>& multipoleAtomZs,
const std::vector<int>& multipoleAtomXs,
const std::vector<int>& multipoleAtomYs,
const std::vector< std::vector< std::vector<int> > >& multipoleAtomCovalentInfo,
std::vector<RealVec>& outputInducedDipoles);
std::vector<Vec3>& outputInducedDipoles);
/**
* Calculate particle permanent dipoles rotated in the lab frame.
......@@ -552,19 +552,19 @@ public:
* @param outputMultipoleMoments output multipole moments
*/
void calculateLabFramePermanentDipoles(const std::vector<RealVec>& particlePositions,
const std::vector<RealOpenMM>& charges,
const std::vector<RealOpenMM>& dipoles,
const std::vector<RealOpenMM>& quadrupoles,
const std::vector<RealOpenMM>& tholes,
const std::vector<RealOpenMM>& dampingFactors,
const std::vector<RealOpenMM>& polarity,
void calculateLabFramePermanentDipoles(const std::vector<Vec3>& particlePositions,
const std::vector<double>& charges,
const std::vector<double>& dipoles,
const std::vector<double>& quadrupoles,
const std::vector<double>& tholes,
const std::vector<double>& dampingFactors,
const std::vector<double>& polarity,
const std::vector<int>& axisTypes,
const std::vector<int>& multipoleAtomZs,
const std::vector<int>& multipoleAtomXs,
const std::vector<int>& multipoleAtomYs,
const std::vector< vector< vector<int> > >& multipoleAtomCovalentInfo,
std::vector<RealVec>& outputRotatedPermanentDipoles);
std::vector<Vec3>& outputRotatedPermanentDipoles);
/**
* Calculate particle total dipoles.
......@@ -586,19 +586,19 @@ public:
*/
void calculateTotalDipoles(const std::vector<RealVec>& particlePositions,
const std::vector<RealOpenMM>& charges,
const std::vector<RealOpenMM>& dipoles,
const std::vector<RealOpenMM>& quadrupoles,
const std::vector<RealOpenMM>& tholes,
const std::vector<RealOpenMM>& dampingFactors,
const std::vector<RealOpenMM>& polarity,
const std::vector<int>& axisTypes,
const std::vector<int>& multipoleAtomZs,
const std::vector<int>& multipoleAtomXs,
const std::vector<int>& multipoleAtomYs,
const std::vector< vector< vector<int> > >& multipoleAtomCovalentInfo,
std::vector<RealVec>& outputRotatedPermanentDipoles);
void calculateTotalDipoles(const std::vector<Vec3>& particlePositions,
const std::vector<double>& charges,
const std::vector<double>& dipoles,
const std::vector<double>& quadrupoles,
const std::vector<double>& tholes,
const std::vector<double>& dampingFactors,
const std::vector<double>& polarity,
const std::vector<int>& axisTypes,
const std::vector<int>& multipoleAtomZs,
const std::vector<int>& multipoleAtomXs,
const std::vector<int>& multipoleAtomYs,
const std::vector< vector< vector<int> > >& multipoleAtomCovalentInfo,
std::vector<Vec3>& outputRotatedPermanentDipoles);
......@@ -620,20 +620,20 @@ public:
* @param multipoleAtomCovalentInfo covalent info needed to set scaling factors
* @param outputMultipoleMoments output multipole moments
*/
void calculateAmoebaSystemMultipoleMoments(const std::vector<RealOpenMM>& masses,
const std::vector<OpenMM::RealVec>& particlePositions,
const std::vector<RealOpenMM>& charges,
const std::vector<RealOpenMM>& dipoles,
const std::vector<RealOpenMM>& quadrupoles,
const std::vector<RealOpenMM>& tholes,
const std::vector<RealOpenMM>& dampingFactors,
const std::vector<RealOpenMM>& polarity,
void calculateAmoebaSystemMultipoleMoments(const std::vector<double>& masses,
const std::vector<OpenMM::Vec3>& particlePositions,
const std::vector<double>& charges,
const std::vector<double>& dipoles,
const std::vector<double>& quadrupoles,
const std::vector<double>& tholes,
const std::vector<double>& dampingFactors,
const std::vector<double>& polarity,
const std::vector<int>& axisTypes,
const std::vector<int>& multipoleAtomZs,
const std::vector<int>& multipoleAtomXs,
const std::vector<int>& multipoleAtomYs,
const std::vector< std::vector< std::vector<int> > >& multipoleAtomCovalentInfo,
std::vector<RealOpenMM>& outputMultipoleMoments);
std::vector<double>& outputMultipoleMoments);
/**
* Calculate electrostatic potential at a set of grid points.
......@@ -653,20 +653,20 @@ public:
* @param input grid input grid points to compute potential
* @param outputPotential output electrostatic potential
*/
void calculateElectrostaticPotential(const std::vector<OpenMM::RealVec>& particlePositions,
const std::vector<RealOpenMM>& charges,
const std::vector<RealOpenMM>& dipoles,
const std::vector<RealOpenMM>& quadrupoles,
const std::vector<RealOpenMM>& tholes,
const std::vector<RealOpenMM>& dampingFactors,
const std::vector<RealOpenMM>& polarity,
void calculateElectrostaticPotential(const std::vector<OpenMM::Vec3>& particlePositions,
const std::vector<double>& charges,
const std::vector<double>& dipoles,
const std::vector<double>& quadrupoles,
const std::vector<double>& tholes,
const std::vector<double>& dampingFactors,
const std::vector<double>& polarity,
const std::vector<int>& axisTypes,
const std::vector<int>& multipoleAtomZs,
const std::vector<int>& multipoleAtomXs,
const std::vector<int>& multipoleAtomYs,
const std::vector< std::vector< std::vector<int> > >& multipoleAtomCovalentInfo,
const std::vector<RealVec>& inputGrid,
std::vector<RealOpenMM>& outputPotential);
const std::vector<Vec3>& inputGrid,
std::vector<double>& outputPotential);
protected:
......@@ -682,15 +682,15 @@ protected:
class MultipoleParticleData {
public:
unsigned int particleIndex;
RealVec position;
RealOpenMM charge;
RealVec dipole;
RealOpenMM quadrupole[6];
RealVec sphericalDipole;
RealOpenMM sphericalQuadrupole[5];
RealOpenMM thole;
RealOpenMM dampingFactor;
RealOpenMM polarity;
Vec3 position;
double charge;
Vec3 dipole;
double quadrupole[6];
Vec3 sphericalDipole;
double sphericalQuadrupole[5];
double thole;
double dampingFactor;
double polarity;
};
/**
......@@ -698,22 +698,22 @@ protected:
*/
class TransformedMultipole {
public:
RealOpenMM charge;
RealVec dipole;
RealOpenMM quadrupole[6];
double charge;
Vec3 dipole;
double quadrupole[6];
};
/*
* Helper class used in calculating induced dipoles
*/
struct UpdateInducedDipoleFieldStruct {
UpdateInducedDipoleFieldStruct(std::vector<OpenMM::RealVec>& inputFixed_E_Field, std::vector<OpenMM::RealVec>& inputInducedDipoles, std::vector<std::vector<RealVec> >& extrapolatedDipoles, std::vector<std::vector<RealOpenMM> >& extrapolatedDipoleFieldGradient);
std::vector<OpenMM::RealVec>* fixedMultipoleField;
std::vector<OpenMM::RealVec>* inducedDipoles;
std::vector<std::vector<RealVec> >* extrapolatedDipoles;
std::vector<std::vector<RealOpenMM> >* extrapolatedDipoleFieldGradient;
std::vector<OpenMM::RealVec> inducedDipoleField;
std::vector<std::vector<RealOpenMM> > inducedDipoleFieldGradient;
UpdateInducedDipoleFieldStruct(std::vector<OpenMM::Vec3>& inputFixed_E_Field, std::vector<OpenMM::Vec3>& inputInducedDipoles, std::vector<std::vector<Vec3> >& extrapolatedDipoles, std::vector<std::vector<double> >& extrapolatedDipoleFieldGradient);
std::vector<OpenMM::Vec3>* fixedMultipoleField;
std::vector<OpenMM::Vec3>* inducedDipoles;
std::vector<std::vector<Vec3> >* extrapolatedDipoles;
std::vector<std::vector<double> >* extrapolatedDipoleFieldGradient;
std::vector<OpenMM::Vec3> inducedDipoleField;
std::vector<std::vector<double> > inducedDipoleFieldGradient;
};
unsigned int _numParticles;
......@@ -721,37 +721,37 @@ protected:
NonbondedMethod _nonbondedMethod;
PolarizationType _polarizationType;
RealOpenMM _electric;
RealOpenMM _dielectric;
double _electric;
double _dielectric;
enum ScaleType { D_SCALE, P_SCALE, M_SCALE, U_SCALE, LAST_SCALE_TYPE_INDEX };
std::vector< std::vector< MapIntRealOpenMM > > _scaleMaps;
std::vector<unsigned int> _maxScaleIndex;
RealOpenMM _dScale[5];
RealOpenMM _pScale[5];
RealOpenMM _mScale[5];
RealOpenMM _uScale[5];
double _dScale[5];
double _pScale[5];
double _mScale[5];
double _uScale[5];
std::vector<TransformedMultipole> _transformed;
std::vector<RealVec> _fixedMultipoleField;
std::vector<RealVec> _fixedMultipoleFieldPolar;
std::vector<RealVec> _inducedDipole;
std::vector<RealVec> _inducedDipolePolar;
std::vector<std::vector<RealVec> > _ptDipoleP;
std::vector<std::vector<RealVec> > _ptDipoleD;
std::vector<std::vector<RealOpenMM> > _ptDipoleFieldGradientP;
std::vector<std::vector<RealOpenMM> > _ptDipoleFieldGradientD;
std::vector<Vec3> _fixedMultipoleField;
std::vector<Vec3> _fixedMultipoleFieldPolar;
std::vector<Vec3> _inducedDipole;
std::vector<Vec3> _inducedDipolePolar;
std::vector<std::vector<Vec3> > _ptDipoleP;
std::vector<std::vector<Vec3> > _ptDipoleD;
std::vector<std::vector<double> > _ptDipoleFieldGradientP;
std::vector<std::vector<double> > _ptDipoleFieldGradientD;
int _mutualInducedDipoleConverged;
int _mutualInducedDipoleIterations;
int _maximumMutualInducedDipoleIterations;
int _maxPTOrder;
std::vector<RealOpenMM> _extrapolationCoefficients;
std::vector<RealOpenMM> _extPartCoefficients;
RealOpenMM _mutualInducedDipoleEpsilon;
RealOpenMM _mutualInducedDipoleTargetEpsilon;
RealOpenMM _polarSOR;
RealOpenMM _debye;
std::vector<double> _extrapolationCoefficients;
std::vector<double> _extPartCoefficients;
double _mutualInducedDipoleEpsilon;
double _mutualInducedDipoleTargetEpsilon;
double _polarSOR;
double _debye;
/**
* Helper constructor method to centralize initialization of objects.
......@@ -772,13 +772,13 @@ protected:
* @param particleData output data struct
*
*/
void loadParticleData(const std::vector<OpenMM::RealVec>& particlePositions,
const std::vector<RealOpenMM>& charges,
const std::vector<RealOpenMM>& dipoles,
const std::vector<RealOpenMM>& quadrupoles,
const std::vector<RealOpenMM>& tholes,
const std::vector<RealOpenMM>& dampingFactors,
const std::vector<RealOpenMM>& polarity,
void loadParticleData(const std::vector<OpenMM::Vec3>& particlePositions,
const std::vector<double>& charges,
const std::vector<double>& dipoles,
const std::vector<double>& quadrupoles,
const std::vector<double>& tholes,
const std::vector<double>& dampingFactors,
const std::vector<double>& polarity,
std::vector<MultipoleParticleData>& particleData) const;
/**
......@@ -811,7 +811,7 @@ protected:
* @param epsilon
*
*/
void setMutualInducedDipoleEpsilon(RealOpenMM epsilon);
void setMutualInducedDipoleEpsilon(double epsilon);
/**
* Setup scale factors given covalent info.
......@@ -830,7 +830,7 @@ protected:
*
* @return scaleFactor
*/
RealOpenMM getMultipoleScaleFactor(unsigned int particleI, unsigned int particleJ, ScaleType scaleType) const;
double getMultipoleScaleFactor(unsigned int particleI, unsigned int particleJ, ScaleType scaleType) const;
/**
* Get scale factor for particleI & particleJ
......@@ -841,7 +841,7 @@ protected:
*
* @return array of scaleFactors
*/
void getMultipoleScaleFactors(unsigned int particleI, unsigned int particleJ, std::vector<RealOpenMM>& scaleFactors) const;
void getMultipoleScaleFactors(unsigned int particleI, unsigned int particleJ, std::vector<double>& scaleFactors) const;
/**
* Get p- and d-scale factors for particleI & particleJ ixn
......@@ -851,7 +851,7 @@ protected:
* @param dScale output d-scale factor
* @param pScale output p-scale factor
*/
void getDScaleAndPScale(unsigned int particleI, unsigned int particleJ, RealOpenMM& dScale, RealOpenMM& pScale) const;
void getDScaleAndPScale(unsigned int particleI, unsigned int particleJ, double& dScale, double& pScale) const;
/**
* Calculate damped powers of 1/r.
......@@ -861,8 +861,8 @@ protected:
* @param dScale output d-scale factor
* @param pScale output p-scale factor
*/
void getAndScaleInverseRs(RealOpenMM dampI, RealOpenMM dampJ, RealOpenMM tholeI, RealOpenMM tholeJ,
RealOpenMM r, std::vector<RealOpenMM>& rrI) const;
void getAndScaleInverseRs(double dampI, double dampJ, double tholeI, double tholeJ,
double r, std::vector<double>& rrI) const;
/**
* Check if multipoles at chiral site should be inverted.
......@@ -900,8 +900,8 @@ protected:
* @param axisType axis type
*/
void applyRotationMatrixToParticle( MultipoleParticleData& particleI,
const MultipoleParticleData& particleZ,
const MultipoleParticleData& particleX,
const MultipoleParticleData* particleZ,
const MultipoleParticleData* particleX,
MultipoleParticleData* particleY, int axisType) const;
/**
......@@ -915,11 +915,11 @@ protected:
* @param r the bond length between atoms I and J
* @param rotationmatrix the output rotation matrix for a 3-vector
*/
void formQIRotationMatrix(const RealVec& iPosition,
const RealVec& jPosition,
const RealVec &deltaR,
RealOpenMM r,
RealOpenMM (&rotationMatrix)[3][3]) const;
void formQIRotationMatrix(const Vec3& iPosition,
const Vec3& jPosition,
const Vec3 &deltaR,
double r,
double (&rotationMatrix)[3][3]) const;
/**
......@@ -928,7 +928,7 @@ protected:
* @param D1 The input spherical harmonic dipole rotation matrix
* @param D2 The output spherical harmonic quadrupole rotation matrix
*/
void buildSphericalQuadrupoleRotationMatrix(const RealOpenMM (&D1)[3][3], RealOpenMM (&D2)[5][5]) const;
void buildSphericalQuadrupoleRotationMatrix(const double (&D1)[3][3], double (&D2)[5][5]) const;
/**
* Constructs a rotation matrix for spherical harmonic quadrupoles, using the dipole rotation matrix.
......@@ -937,7 +937,7 @@ protected:
* @param D1 The input spherical harmonic dipole rotation matrix
* @param D2 The output spherical harmonic quadrupole rotation matrix
*/
void buildPartialSphericalQuadrupoleRotationMatrix(const RealOpenMM (&D1)[3][3], RealOpenMM (&D2)[3][5]) const;
void buildPartialSphericalQuadrupoleRotationMatrix(const double (&D1)[3][3], double (&D2)[3][5]) const;
/**
* Apply rotation matrix to molecular dipole/quadrupoles to get corresponding lab frame values.
......@@ -969,7 +969,7 @@ protected:
* @param pScale p-scale value for i-j interaction
*/
virtual void calculateFixedMultipoleFieldPairIxn(const MultipoleParticleData& particleI, const MultipoleParticleData& particleJ,
RealOpenMM dScale, RealOpenMM pScale);
double dScale, double pScale);
/**
* Initialize induced dipoles
......@@ -991,9 +991,9 @@ protected:
* @param field vector of induced dipole fields
*/
void calculateInducedDipolePairIxn(unsigned int particleI, unsigned int particleJ,
RealOpenMM rr3, RealOpenMM rr5, const RealVec& delta,
const std::vector<RealVec>& inducedDipole,
std::vector<RealVec>& field) const;
double rr3, double rr5, const Vec3& delta,
const std::vector<Vec3>& inducedDipole,
std::vector<Vec3>& field) const;
/**
* Calculate fields due induced dipoles at each site.
......@@ -1044,7 +1044,7 @@ protected:
* @param prevErrors the vector of errors from previous iterations
* @param coefficients the coefficients will be stored into this
*/
void computeDIISCoefficients(const std::vector<std::vector<RealVec> >& prevErrors, std::vector<RealOpenMM>& coefficients) const;
void computeDIISCoefficients(const std::vector<std::vector<Vec3> >& prevErrors, std::vector<double>& coefficients) const;
/**
* Update fields due to induced dipoles for each particle.
......@@ -1052,8 +1052,8 @@ protected:
* @param particleData vector of particle positions and parameters (charge, labFrame dipoles, quadrupoles, ...)
* @param updateInducedDipoleFields vector of UpdateInducedDipoleFieldStruct containing input induced dipoles and output fields
*/
RealOpenMM updateInducedDipoleFields(const std::vector<MultipoleParticleData>& particleData,
std::vector<UpdateInducedDipoleFieldStruct>& calculateInducedDipoleField);
double updateInducedDipoleFields(const std::vector<MultipoleParticleData>& particleData,
std::vector<UpdateInducedDipoleFieldStruct>& calculateInducedDipoleField);
/**
* Update induced dipole for a particle given updated induced dipole field at the site.
......@@ -1063,10 +1063,10 @@ protected:
* @param inducedDipoleField fields due induced dipoles at each site
* @param inducedDipoles output vector of updated induced dipoles
*/
RealOpenMM updateInducedDipole(const std::vector<MultipoleParticleData>& particleI,
const std::vector<RealVec>& fixedMultipoleField,
const std::vector<RealVec>& inducedDipoleField,
std::vector<RealVec>& inducedDipoles);
double updateInducedDipole(const std::vector<MultipoleParticleData>& particleI,
const std::vector<Vec3>& fixedMultipoleField,
const std::vector<Vec3>& inducedDipoleField,
std::vector<Vec3>& inducedDipoles);
/**
* Calculate induced dipoles.
......@@ -1097,13 +1097,13 @@ protected:
* @param particleData output vector of parameters (charge, labFrame dipoles, quadrupoles, ...) for particles
*
*/
void setup(const std::vector<OpenMM::RealVec>& particlePositions,
const std::vector<RealOpenMM>& charges,
const std::vector<RealOpenMM>& dipoles,
const std::vector<RealOpenMM>& quadrupoles,
const std::vector<RealOpenMM>& tholes,
const std::vector<RealOpenMM>& dampingFactors,
const std::vector<RealOpenMM>& polarity,
void setup(const std::vector<OpenMM::Vec3>& particlePositions,
const std::vector<double>& charges,
const std::vector<double>& dipoles,
const std::vector<double>& quadrupoles,
const std::vector<double>& tholes,
const std::vector<double>& dampingFactors,
const std::vector<double>& polarity,
const std::vector<int>& axisTypes,
const std::vector<int>& multipoleAtomZs,
const std::vector<int>& multipoleAtomXs,
......@@ -1120,8 +1120,8 @@ protected:
* @param forces vector of particle forces to be updated
* @param torque vector of particle torques to be updated
*/
RealOpenMM calculateElectrostaticPairIxn(const MultipoleParticleData& particleI, const MultipoleParticleData& particleK,
const std::vector<RealOpenMM>& scalingFactors, std::vector<OpenMM::RealVec>& forces, std::vector<RealVec>& torque) const;
double calculateElectrostaticPairIxn(const MultipoleParticleData& particleI, const MultipoleParticleData& particleK,
const std::vector<double>& scalingFactors, std::vector<OpenMM::Vec3>& forces, std::vector<Vec3>& torque) const;
/**
* Map particle torque to force.
......@@ -1138,7 +1138,7 @@ protected:
const MultipoleParticleData& particleU,
const MultipoleParticleData& particleV,
MultipoleParticleData* particleW,
int axisType, const Vec3& torque, std::vector<OpenMM::RealVec>& forces) const;
int axisType, const Vec3& torque, std::vector<OpenMM::Vec3>& forces) const;
/**
* Map torques to forces.
......@@ -1156,8 +1156,8 @@ protected:
const std::vector<int>& multipoleAtomYs,
const std::vector<int>& multipoleAtomZs,
const std::vector<int>& axisTypes,
std::vector<OpenMM::RealVec>& torques,
std::vector<OpenMM::RealVec>& forces) const;
std::vector<OpenMM::Vec3>& torques,
std::vector<OpenMM::Vec3>& forces) const;
/**
* Calculate electrostatic forces
......@@ -1168,44 +1168,44 @@ protected:
*
* @return energy
*/
virtual RealOpenMM calculateElectrostatic(const std::vector<MultipoleParticleData>& particleData,
std::vector<OpenMM::RealVec>& torques,
std::vector<OpenMM::RealVec>& forces);
virtual double calculateElectrostatic(const std::vector<MultipoleParticleData>& particleData,
std::vector<OpenMM::Vec3>& torques,
std::vector<OpenMM::Vec3>& forces);
/**
* Normalize a RealVec
* Normalize a Vec3
*
* @param vectorToNormalize vector to normalize
*
* @return norm of vector on input
*
*/
RealOpenMM normalizeRealVec(RealVec& vectorToNormalize) const;
double normalizeVec3(Vec3& vectorToNormalize) const;
/**
* Initialize vector of RealOpenMM (size=numParticles)
* Initialize vector of double (size=numParticles)
*
* @param vectorToInitialize vector to initialize
*
*/
void initializeRealOpenMMVector(vector<RealOpenMM>& vectorToInitialize) const;
void initializeRealOpenMMVector(vector<double>& vectorToInitialize) const;
/**
* Initialize vector of RealVec (size=numParticles)
* Initialize vector of Vec3 (size=numParticles)
*
* @param vectorToInitialize vector to initialize
*
*/
void initializeRealVecVector(vector<RealVec>& vectorToInitialize) const;
void initializeVec3Vector(vector<Vec3>& vectorToInitialize) const;
/**
* Copy vector of RealVec
* Copy vector of Vec3
*
* @param inputVector vector to copy
* @param outputVector output vector
*
*/
void copyRealVecVector(const std::vector<OpenMM::RealVec>& inputVector, std::vector<OpenMM::RealVec>& outputVector) const;
void copyVec3Vector(const std::vector<OpenMM::Vec3>& inputVector, std::vector<OpenMM::Vec3>& outputVector) const;
/**
* Calculate potential at grid point due to a particle
......@@ -1216,7 +1216,7 @@ protected:
* @return potential at grid point
*
*/
RealOpenMM calculateElectrostaticPotentialForParticleGridPoint(const MultipoleParticleData& particleI, const RealVec& gridPoint) const;
double calculateElectrostaticPotentialForParticleGridPoint(const MultipoleParticleData& particleI, const Vec3& gridPoint) const;
/**
* Apply periodic boundary conditions to difference in positions
......@@ -1224,7 +1224,7 @@ protected:
* @param deltaR difference in particle positions; modified on output after applying PBC
*
*/
virtual void getPeriodicDelta(RealVec& deltaR) const {};
virtual void getPeriodicDelta(Vec3& deltaR) const {};
};
class AmoebaReferenceGeneralizedKirkwoodMultipoleForce : public AmoebaReferenceMultipoleForce {
......@@ -1257,7 +1257,7 @@ public:
* @return probe radius
*
*/
RealOpenMM getProbeRadius() const;
double getProbeRadius() const;
/**
* Get surface area factor.
......@@ -1265,7 +1265,7 @@ public:
* @return surface area factor
*
*/
RealOpenMM getSurfaceAreaFactor() const;
double getSurfaceAreaFactor() const;
/**
* Get dielectric offset.
......@@ -1273,34 +1273,34 @@ public:
* @return dielectric offset
*
*/
RealOpenMM getDielectricOffset() const;
double getDielectricOffset() const;
private:
AmoebaReferenceGeneralizedKirkwoodForce* _amoebaReferenceGeneralizedKirkwoodForce;
RealOpenMM _gkc;
RealOpenMM _fc;
RealOpenMM _fd;
RealOpenMM _fq;
double _gkc;
double _fc;
double _fd;
double _fq;
std::vector<RealOpenMM> _atomicRadii;
std::vector<RealOpenMM> _scaledRadii;
std::vector<RealOpenMM> _bornRadii;
std::vector<RealOpenMM> _bornForce;
std::vector<double> _atomicRadii;
std::vector<double> _scaledRadii;
std::vector<double> _bornRadii;
std::vector<double> _bornForce;
std::vector<RealVec> _gkField;
std::vector<RealVec> _inducedDipoleS;
std::vector<RealVec> _inducedDipolePolarS;
std::vector<std::vector<RealVec> > _ptDipolePS;
std::vector<std::vector<RealVec> > _ptDipoleDS;
std::vector<std::vector<RealOpenMM> > _ptDipoleFieldGradientPS;
std::vector<std::vector<RealOpenMM> > _ptDipoleFieldGradientDS;
std::vector<Vec3> _gkField;
std::vector<Vec3> _inducedDipoleS;
std::vector<Vec3> _inducedDipolePolarS;
std::vector<std::vector<Vec3> > _ptDipolePS;
std::vector<std::vector<Vec3> > _ptDipoleDS;
std::vector<std::vector<double> > _ptDipoleFieldGradientPS;
std::vector<std::vector<double> > _ptDipoleFieldGradientDS;
int _includeCavityTerm;
RealOpenMM _probeRadius;
RealOpenMM _surfaceAreaFactor;
RealOpenMM _dielectricOffset;
double _probeRadius;
double _surfaceAreaFactor;
double _dielectricOffset;
/**
* Zero fixed multipole fields.
......@@ -1318,7 +1318,7 @@ private:
* @param pScale p-scale value for i-j interaction
*/
void calculateFixedMultipoleFieldPairIxn(const MultipoleParticleData& particleI, const MultipoleParticleData& particleJ,
RealOpenMM dScale, RealOpenMM pScale);
double dScale, double pScale);
/**
* Calculate induced dipoles.
......@@ -1346,9 +1346,9 @@ private:
*
* @return energy
*/
RealOpenMM calculateElectrostatic(const std::vector<MultipoleParticleData>& particleData,
std::vector<OpenMM::RealVec>& torques,
std::vector<OpenMM::RealVec>& forces);
double calculateElectrostatic(const std::vector<MultipoleParticleData>& particleData,
std::vector<OpenMM::Vec3>& torques,
std::vector<OpenMM::Vec3>& forces);
/**
* Calculate GK field at particle I due induced dipole at particle J and vice versa
......@@ -1360,7 +1360,7 @@ private:
* @param fieldPolar vector of induced dipole polar fields
*/
void calculateInducedDipolePairGkIxn(const MultipoleParticleData& particleI, const MultipoleParticleData& particleJ,
const std::vector<RealVec>& field, std::vector<RealVec>& fieldPolar) const;
const std::vector<Vec3>& field, std::vector<Vec3>& fieldPolar) const;
/**
* Calculate Kirkwood interaction.
......@@ -1373,10 +1373,10 @@ private:
*
* @return energy
*/
RealOpenMM calculateKirkwoodPairIxn(const MultipoleParticleData& particleI, const MultipoleParticleData& particleJ,
std::vector<RealVec>& forces,
std::vector<RealVec>& torques,
std::vector<RealOpenMM>& dBorn) const;
double calculateKirkwoodPairIxn(const MultipoleParticleData& particleI, const MultipoleParticleData& particleJ,
std::vector<Vec3>& forces,
std::vector<Vec3>& torques,
std::vector<double>& dBorn) const;
/**
* Calculate Grycuk 'chain-rule' force.
......@@ -1388,7 +1388,7 @@ private:
*
*/
void calculateGrycukChainRulePairIxn(const MultipoleParticleData& particleI, const MultipoleParticleData& particleJ,
const std::vector<RealOpenMM>& dBorn, std::vector<RealVec>& forces) const;
const std::vector<double>& dBorn, std::vector<Vec3>& forces) const;
/**
* Calculate TINKER's ACE approximation to non-polar cavity term.
......@@ -1398,7 +1398,7 @@ private:
* @return ACE energy
*
*/
RealOpenMM calculateCavityTermEnergyAndForces(std::vector<RealOpenMM>& dBorn) const;
double calculateCavityTermEnergyAndForces(std::vector<double>& dBorn) const;
/**
* Correct vacuum to SCRF derivatives (TINKER's ediff1()).
......@@ -1412,9 +1412,9 @@ private:
*
* @return energy
*/
RealOpenMM calculateKirkwoodEDiffPairIxn(const MultipoleParticleData& particleI, const MultipoleParticleData& particleJ,
RealOpenMM pscale, RealOpenMM dscale,
std::vector<RealVec>& forces, std::vector<RealVec>& torques) const;
double calculateKirkwoodEDiffPairIxn(const MultipoleParticleData& particleI, const MultipoleParticleData& particleJ,
double pscale, double dscale,
std::vector<Vec3>& forces, std::vector<Vec3>& torques) const;
};
......@@ -1440,7 +1440,7 @@ public:
* @return cutoff distance
*
*/
RealOpenMM getCutoffDistance() const;
double getCutoffDistance() const;
/**
* Set cutoff distance.
......@@ -1448,7 +1448,7 @@ public:
* @return cutoff distance
*
*/
void setCutoffDistance(RealOpenMM cutoffDistance);
void setCutoffDistance(double cutoffDistance);
/**
* Get alpha used in Ewald summation.
......@@ -1456,7 +1456,7 @@ public:
* @return alpha
*
*/
RealOpenMM getAlphaEwald() const;
double getAlphaEwald() const;
/**
* Set alpha used in Ewald summation.
......@@ -1464,7 +1464,7 @@ public:
* @return alpha
*
*/
void setAlphaEwald(RealOpenMM alphaEwald);
void setAlphaEwald(double alphaEwald);
/**
* Get PME grid dimensions.
......@@ -1488,19 +1488,19 @@ public:
*
* @param vectors the vectors defining the periodic box
*/
void setPeriodicBoxSize(OpenMM::RealVec* vectors);
void setPeriodicBoxSize(OpenMM::Vec3* vectors);
private:
static const int AMOEBA_PME_ORDER;
static const RealOpenMM SQRT_PI;
static const double SQRT_PI;
RealOpenMM _alphaEwald;
RealOpenMM _cutoffDistance;
RealOpenMM _cutoffDistanceSquared;
double _alphaEwald;
double _cutoffDistance;
double _cutoffDistanceSquared;
RealVec _recipBoxVectors[3];
RealVec _periodicBoxVectors[3];
Vec3 _recipBoxVectors[3];
Vec3 _periodicBoxVectors[3];
int _totalGridSize;
IntVec _pmeGridDimensions;
......@@ -1510,15 +1510,15 @@ private:
unsigned int _pmeGridSize;
t_complex* _pmeGrid;
std::vector<RealOpenMM> _pmeBsplineModuli[3];
std::vector<RealOpenMM4> _thetai[3];
std::vector<double> _pmeBsplineModuli[3];
std::vector<double4> _thetai[3];
std::vector<IntVec> _iGrid;
std::vector<RealOpenMM> _phi;
std::vector<RealOpenMM> _phid;
std::vector<RealOpenMM> _phip;
std::vector<RealOpenMM> _phidp;
std::vector<RealOpenMM4> _pmeBsplineTheta;
std::vector<RealOpenMM4> _pmeBsplineDtheta;
std::vector<double> _phi;
std::vector<double> _phid;
std::vector<double> _phip;
std::vector<double> _phidp;
std::vector<double4> _pmeBsplineTheta;
std::vector<double4> _pmeBsplineDtheta;
/**
* Resize PME arrays.
......@@ -1537,7 +1537,7 @@ private:
* @param delta input vector of difference in particle positions; on output adjusted for
* periodic boundary conditions
*/
void getPeriodicDelta(RealVec& deltaR) const;
void getPeriodicDelta(Vec3& deltaR) const;
/**
* Calculate damped inverse distances.
......@@ -1550,8 +1550,8 @@ private:
* @param dampedPInverseDistances damped inverse distances (prr3,prr5,prr7 in udirect2a() in TINKER)
*/
void getDampedInverseDistances(const MultipoleParticleData& particleI, const MultipoleParticleData& particleJ,
RealOpenMM dscale, RealOpenMM pscale, RealOpenMM r,
RealVec& dampedDInverseDistances, RealVec& dampedPInverseDistances) const;
double dscale, double pscale, double r,
Vec3& dampedDInverseDistances, Vec3& dampedPInverseDistances) const;
/**
* Initialize B-spline moduli.
......@@ -1568,7 +1568,7 @@ private:
* @param pScale p-scale value for i-j interaction
*/
void calculateFixedMultipoleFieldPairIxn(const MultipoleParticleData& particleI, const MultipoleParticleData& particleJ,
RealOpenMM dscale, RealOpenMM pscale);
double dscale, double pscale);
/**
* Calculate fixed multipole fields.
......@@ -1584,7 +1584,7 @@ private:
* @param thetai output spline coefficients
* @param w offset from grid point
*/
void computeBSplinePoint(std::vector<RealOpenMM4>& thetai, RealOpenMM w);
void computeBSplinePoint(std::vector<double4>& thetai, double w);
/**
* Compute bspline coefficients.
......@@ -1601,7 +1601,7 @@ private:
/**
* Transform potential from fractional coordinates to cartesian coordinates.
*/
void transformPotentialToCartesianCoordinates(const std::vector<RealOpenMM>& fphi, std::vector<RealOpenMM>& cphi) const;
void transformPotentialToCartesianCoordinates(const std::vector<double>& fphi, std::vector<double>& cphi) const;
/**
* Spread fixed multipoles onto PME grid.
......@@ -1637,8 +1637,8 @@ private:
*
* @return energy
*/
RealOpenMM computeReciprocalSpaceFixedMultipoleForceAndEnergy(const std::vector<MultipoleParticleData>& particleData,
std::vector<RealVec>& forces, std::vector<RealVec>& torques) const;
double computeReciprocalSpaceFixedMultipoleForceAndEnergy(const std::vector<MultipoleParticleData>& particleData,
std::vector<Vec3>& forces, std::vector<Vec3>& torques) const;
/**
* Set reciprocal space fixed multipole fields.
......@@ -1665,9 +1665,9 @@ private:
* @param field vector of field at each particle due induced dipole of other particles
*/
void calculateDirectInducedDipolePairIxn(unsigned int iIndex, unsigned int jIndex,
RealOpenMM preFactor1, RealOpenMM preFactor2, const RealVec& delta,
const std::vector<RealVec>& inducedDipole,
std::vector<RealVec>& field) const;
double preFactor1, double preFactor2, const Vec3& delta,
const std::vector<Vec3>& inducedDipole,
std::vector<Vec3>& field) const;
/**
* Calculate direct space field at particleI due to induced dipole at particle J and vice versa for
......@@ -1694,8 +1694,8 @@ private:
* @param inputInducedDipole induced dipole value
* @param inputInducedDipolePolar induced dipole polar value
*/
void spreadInducedDipolesOnGrid(const std::vector<RealVec>& inputInducedDipole,
const std::vector<RealVec>& inputInducedDipolePolar);
void spreadInducedDipolesOnGrid(const std::vector<Vec3>& inputInducedDipole,
const std::vector<Vec3>& inputInducedDipolePolar);
/**
* Calculate induced dipole fields.
......@@ -1713,14 +1713,14 @@ private:
* @param fieldPolar reciprocal space output induced dipole polar field value at each site
*
*/
void recordInducedDipoleField(vector<RealVec>& field, vector<RealVec>& fieldPolar);
void recordInducedDipoleField(vector<Vec3>& field, vector<Vec3>& fieldPolar);
/**
* Compute Pme self energy.
*
* @param particleData vector of parameters (charge, labFrame dipoles, quadrupoles, ...) for particles
*/
RealOpenMM calculatePmeSelfEnergy(const std::vector<MultipoleParticleData>& particleData) const;
double calculatePmeSelfEnergy(const std::vector<MultipoleParticleData>& particleData) const;
/**
* Compute the self torques.
......@@ -1728,7 +1728,7 @@ private:
* @param particleData vector of parameters (charge, labFrame dipoles, quadrupoles, ...) for particles
* @param torques vector of torques
*/
void calculatePmeSelfTorque(const std::vector<MultipoleParticleData>& particleData, std::vector<RealVec>& torques) const;
void calculatePmeSelfTorque(const std::vector<MultipoleParticleData>& particleData, std::vector<Vec3>& torques) const;
/**
* Calculate direct space electrostatic interaction between particles I and J.
......@@ -1739,9 +1739,9 @@ private:
* @param forces vector of particle forces to be updated
* @param torques vector of particle torques to be updated
*/
RealOpenMM calculatePmeDirectElectrostaticPairIxn(const MultipoleParticleData& particleI, const MultipoleParticleData& particleJ,
const std::vector<RealOpenMM>& scalingFactors,
std::vector<RealVec>& forces, std::vector<RealVec>& torques) const;
double calculatePmeDirectElectrostaticPairIxn(const MultipoleParticleData& particleI, const MultipoleParticleData& particleJ,
const std::vector<double>& scalingFactors,
std::vector<Vec3>& forces, std::vector<Vec3>& torques) const;
/**
* Calculate reciprocal space energy/force/torque for dipole interaction.
......@@ -1752,9 +1752,9 @@ private:
* @param forces vector of particle forces to be updated
* @param torques vector of particle torques to be updated
*/
RealOpenMM computeReciprocalSpaceInducedDipoleForceAndEnergy(AmoebaReferenceMultipoleForce::PolarizationType polarizationType,
const std::vector<MultipoleParticleData>& particleData,
std::vector<RealVec>& forces, std::vector<RealVec>& torques) const;
double computeReciprocalSpaceInducedDipoleForceAndEnergy(AmoebaReferenceMultipoleForce::PolarizationType polarizationType,
const std::vector<MultipoleParticleData>& particleData,
std::vector<Vec3>& forces, std::vector<Vec3>& torques) const;
/**
* Calculate electrostatic forces.
......@@ -1765,9 +1765,9 @@ private:
*
* @return energy
*/
RealOpenMM calculateElectrostatic(const std::vector<MultipoleParticleData>& particleData,
std::vector<OpenMM::RealVec>& torques,
std::vector<OpenMM::RealVec>& forces);
double calculateElectrostatic(const std::vector<MultipoleParticleData>& particleData,
std::vector<OpenMM::Vec3>& torques,
std::vector<OpenMM::Vec3>& forces);
};
......
......@@ -24,11 +24,12 @@
#include "AmoebaReferenceForce.h"
#include "AmoebaReferenceOutOfPlaneBendForce.h"
#include "SimTKOpenMMRealType.h"
using std::vector;
using namespace OpenMM;
void AmoebaReferenceOutOfPlaneBendForce::setPeriodic(OpenMM::RealVec* vectors) {
void AmoebaReferenceOutOfPlaneBendForce::setPeriodic(OpenMM::Vec3* vectors) {
usePeriodic = true;
boxVectors[0] = vectors[0];
boxVectors[1] = vectors[1];
......@@ -55,34 +56,20 @@ void AmoebaReferenceOutOfPlaneBendForce::setPeriodic(OpenMM::RealVec* vectors) {
--------------------------------------------------------------------------------------- */
RealOpenMM AmoebaReferenceOutOfPlaneBendForce::calculateOutOfPlaneBendIxn(const RealVec& positionAtomA, const RealVec& positionAtomB,
const RealVec& positionAtomC, const RealVec& positionAtomD,
RealOpenMM angleK,
RealOpenMM angleCubic, RealOpenMM angleQuartic,
RealOpenMM anglePentic, RealOpenMM angleSextic,
RealVec* forces) const {
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "AmoebaReferenceOutOfPlaneBendForce::calculateOutOfPlaneBendIxn";
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
static const RealOpenMM two = 2.0;
static const RealOpenMM three = 3.0;
static const RealOpenMM four = 4.0;
static const RealOpenMM five = 5.0;
static const RealOpenMM six = 6.0;
double AmoebaReferenceOutOfPlaneBendForce::calculateOutOfPlaneBendIxn(const Vec3& positionAtomA, const Vec3& positionAtomB,
const Vec3& positionAtomC, const Vec3& positionAtomD,
double angleK,
double angleCubic, double angleQuartic,
double anglePentic, double angleSextic,
Vec3* forces) const {
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
std::vector<RealOpenMM> deltaR[LastDeltaIndex];
std::vector<double> deltaR[LastDeltaIndex];
for (int ii = 0; ii < LastDeltaIndex; ii++) {
deltaR[ii].resize(3);
}
......@@ -101,52 +88,52 @@ RealOpenMM AmoebaReferenceOutOfPlaneBendForce::calculateOutOfPlaneBendIxn(const
AmoebaReferenceForce::loadDeltaR(positionAtomD, positionAtomC, deltaR[CD]);
}
RealOpenMM rDB2 = AmoebaReferenceForce::getNormSquared3(deltaR[DB]);
RealOpenMM rAD2 = AmoebaReferenceForce::getNormSquared3(deltaR[AD]);
RealOpenMM rCD2 = AmoebaReferenceForce::getNormSquared3(deltaR[CD]);
double rDB2 = AmoebaReferenceForce::getNormSquared3(deltaR[DB]);
double rAD2 = AmoebaReferenceForce::getNormSquared3(deltaR[AD]);
double rCD2 = AmoebaReferenceForce::getNormSquared3(deltaR[CD]);
std::vector<RealOpenMM> tempVector(3);
std::vector<double> tempVector(3);
AmoebaReferenceForce::getCrossProduct(deltaR[CB], deltaR[DB], tempVector);
RealOpenMM eE = AmoebaReferenceForce::getDotProduct3(deltaR[AB], tempVector);
RealOpenMM dot = AmoebaReferenceForce::getDotProduct3(deltaR[AD], deltaR[CD]);
RealOpenMM cc = rAD2*rCD2 - dot*dot;
double eE = AmoebaReferenceForce::getDotProduct3(deltaR[AB], tempVector);
double dot = AmoebaReferenceForce::getDotProduct3(deltaR[AD], deltaR[CD]);
double cc = rAD2*rCD2 - dot*dot;
if (rDB2 <= zero || cc == zero) {
return zero;
if (rDB2 <= 0.0 || cc == 0.0) {
return 0.0;
}
RealOpenMM bkk2 = rDB2 - eE*eE/cc;
RealOpenMM cosine = SQRT(bkk2/rDB2);
RealOpenMM angle;
if (cosine >= one) {
angle = zero;
} else if (cosine <= -one) {
angle = PI_M;
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 = M_PI;
} else {
angle = RADIAN*ACOS(cosine);
angle = RADIAN*acos(cosine);
}
// chain rule
RealOpenMM dt = angle;
RealOpenMM dt2 = dt*dt;
RealOpenMM dt3 = dt2*dt;
RealOpenMM dt4 = dt2*dt2;
double dt = angle;
double dt2 = dt*dt;
double dt3 = dt2*dt;
double dt4 = dt2*dt2;
RealOpenMM dEdDt = two + three*angleCubic*dt + four*angleQuartic*dt2 +
five*anglePentic*dt3 + six*angleSextic*dt4;
double dEdDt = 2.0 + 3.0*angleCubic*dt + 4.0*angleQuartic*dt2 +
5.0*anglePentic*dt3 + 6.0*angleSextic*dt4;
dEdDt *= angleK*dt*RADIAN;
RealOpenMM dEdCos = dEdDt/SQRT(cc*bkk2);
if (eE > zero) {
dEdCos *= -one;
double dEdCos = dEdDt/sqrt(cc*bkk2);
if (eE > 0.0) {
dEdCos *= -1.0;
}
RealOpenMM term = eE/cc;
double term = eE/cc;
std::vector<RealOpenMM> dccd[LastAtomIndex];
std::vector<RealOpenMM> deed[LastAtomIndex];
std::vector<RealOpenMM> subForce[LastAtomIndex];
std::vector<double> dccd[LastAtomIndex];
std::vector<double> deed[LastAtomIndex];
std::vector<double> subForce[LastAtomIndex];
for (int ii = 0; ii < LastAtomIndex; ii++) {
dccd[ii].resize(3);
deed[ii].resize(3);
......@@ -155,7 +142,7 @@ RealOpenMM AmoebaReferenceOutOfPlaneBendForce::calculateOutOfPlaneBendIxn(const
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] = -one*(dccd[A][ii] + dccd[C][ii]);
dccd[D][ii] = -1.0*(dccd[A][ii] + dccd[C][ii]);
}
AmoebaReferenceForce::getCrossProduct(deltaR[DB], deltaR[CB], deed[A]);
......@@ -189,7 +176,7 @@ RealOpenMM AmoebaReferenceOutOfPlaneBendForce::calculateOutOfPlaneBendIxn(const
if (jj == 3) {
for (int ii = 0; ii < 3; ii++) {
subForce[1][ii] = -one*(subForce[0][ii] + subForce[2][ii] + subForce[3][ii]);
subForce[1][ii] = -1.0*(subForce[0][ii] + subForce[2][ii] + subForce[3][ii]);
}
}
}
......@@ -206,31 +193,31 @@ RealOpenMM AmoebaReferenceOutOfPlaneBendForce::calculateOutOfPlaneBendIxn(const
// calculate energy if 'energy' is set
RealOpenMM energy = one + angleCubic*dt + angleQuartic*dt2 + anglePentic*dt3 + angleSextic*dt4;
energy *= angleK*dt2;
double energy = 1.0 + angleCubic*dt + angleQuartic*dt2 + anglePentic*dt3 + angleSextic*dt4;
energy *= angleK*dt2;
return energy;
}
RealOpenMM AmoebaReferenceOutOfPlaneBendForce::calculateForceAndEnergy(int numOutOfPlaneBends, vector<RealVec>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<int>& particle4,
const std::vector<RealOpenMM>& kQuadratic,
RealOpenMM angleCubic,
RealOpenMM angleQuartic,
RealOpenMM anglePentic,
RealOpenMM angleSextic,
vector<RealVec>& forceData) const {
RealOpenMM energy = 0.0;
double AmoebaReferenceOutOfPlaneBendForce::calculateForceAndEnergy(int numOutOfPlaneBends, vector<Vec3>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<int>& particle4,
const std::vector<double>& kQuadratic,
double angleCubic,
double angleQuartic,
double anglePentic,
double angleSextic,
vector<Vec3>& forceData) const {
double energy = 0.0;
for (unsigned int ii = 0; ii < static_cast<unsigned int>(numOutOfPlaneBends); ii++) {
int particle1Index = particle1[ii];
int particle2Index = particle2[ii];
int particle3Index = particle3[ii];
int particle4Index = particle4[ii];
RealOpenMM kAngle = kQuadratic[ii];
RealVec forces[4];
double kAngle = kQuadratic[ii];
Vec3 forces[4];
energy += calculateOutOfPlaneBendIxn(posData[particle1Index], posData[particle2Index], posData[particle3Index], posData[particle4Index],
kAngle, angleCubic, angleQuartic, anglePentic, angleSextic, forces);
for (int jj = 0; jj < 3; jj++) {
......
......@@ -25,7 +25,7 @@
#ifndef __AmoebaReferenceOutOfPlaneBendForce_H__
#define __AmoebaReferenceOutOfPlaneBendForce_H__
#include "RealVec.h"
#include "openmm/Vec3.h"
#include <vector>
namespace OpenMM {
......@@ -58,7 +58,7 @@ public:
--------------------------------------------------------------------------------------- */
void setPeriodic(OpenMM::RealVec* vectors);
void setPeriodic(OpenMM::Vec3* vectors);
/**---------------------------------------------------------------------------------------
......@@ -82,22 +82,22 @@ public:
--------------------------------------------------------------------------------------- */
RealOpenMM calculateForceAndEnergy(int numOutOfPlaneBends, std::vector<OpenMM::RealVec>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<int>& particle4,
const std::vector<RealOpenMM>& kAngle,
RealOpenMM angleCubic,
RealOpenMM angleQuartic,
RealOpenMM anglePentic,
RealOpenMM angleSextic,
std::vector<OpenMM::RealVec>& forceData) const;
double calculateForceAndEnergy(int numOutOfPlaneBends, std::vector<OpenMM::Vec3>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<int>& particle4,
const std::vector<double>& kAngle,
double angleCubic,
double angleQuartic,
double anglePentic,
double angleSextic,
std::vector<OpenMM::Vec3>& forceData) const;
private:
bool usePeriodic;
RealVec boxVectors[3];
Vec3 boxVectors[3];
/**---------------------------------------------------------------------------------------
......@@ -118,13 +118,12 @@ private:
--------------------------------------------------------------------------------------- */
RealOpenMM calculateOutOfPlaneBendIxn(const OpenMM::RealVec& positionAtomA, const OpenMM::RealVec& positionAtomB,
const OpenMM::RealVec& positionAtomC, const OpenMM::RealVec& positionAtomD,
RealOpenMM angleK,
RealOpenMM angleCubic, RealOpenMM angleQuartic,
RealOpenMM anglePentic, RealOpenMM angleSextic,
OpenMM::RealVec* forces) const;
double calculateOutOfPlaneBendIxn(const OpenMM::Vec3& positionAtomA, const OpenMM::Vec3& positionAtomB,
const OpenMM::Vec3& positionAtomC, const OpenMM::Vec3& positionAtomD,
double angleK,
double angleCubic, double angleQuartic,
double anglePentic, double angleSextic,
OpenMM::Vec3* forces) const;
};
} // namespace OpenMM
......
......@@ -23,12 +23,13 @@
#include "AmoebaReferenceForce.h"
#include "AmoebaReferencePiTorsionForce.h"
#include <cmath>
#include <vector>
using std::vector;
using namespace OpenMM;
void AmoebaReferencePiTorsionForce::setPeriodic(OpenMM::RealVec* vectors) {
void AmoebaReferencePiTorsionForce::setPeriodic(OpenMM::Vec3* vectors) {
usePeriodic = true;
boxVectors[0] = vectors[0];
boxVectors[1] = vectors[1];
......@@ -52,24 +53,14 @@ void AmoebaReferencePiTorsionForce::setPeriodic(OpenMM::RealVec* vectors) {
--------------------------------------------------------------------------------------- */
RealOpenMM AmoebaReferencePiTorsionForce::calculatePiTorsionIxn(const RealVec& positionAtomA, const RealVec& positionAtomB,
const RealVec& positionAtomC, const RealVec& positionAtomD,
const RealVec& positionAtomE, const RealVec& positionAtomF,
RealOpenMM piTorsionK, RealVec* forces) const {
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "AmoebaReferencePiTorsionForce::calculatePiTorsionIxn";
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
static const RealOpenMM two = 2.0;
// ---------------------------------------------------------------------------------------
double AmoebaReferencePiTorsionForce::calculatePiTorsionIxn(const Vec3& positionAtomA, const Vec3& positionAtomB,
const Vec3& positionAtomC, const Vec3& positionAtomD,
const Vec3& positionAtomE, const Vec3& positionAtomF,
double piTorsionK, Vec3* forces) const {
enum { AD, BD, EC, FC, P, Q, CP, DC, QD, T, U, TU, DP, QC, dT, dU, dP, dQ, dC1, dC2, dD1, dD2, LastDeltaIndex };
std::vector<RealOpenMM> deltaR[LastDeltaIndex];
std::vector<double> deltaR[LastDeltaIndex];
for (unsigned int ii = 0; ii < LastDeltaIndex; ii++) {
deltaR[ii].resize(3);
}
......@@ -87,7 +78,7 @@ RealOpenMM AmoebaReferencePiTorsionForce::calculatePiTorsionIxn(const RealVec& p
}
enum { A, B, C, D, E, F, LastAtomIndex };
std::vector<RealOpenMM> d[LastAtomIndex];
std::vector<double> d[LastAtomIndex];
for (unsigned int ii = 0; ii < LastAtomIndex; ii++) {
d[ii].resize(3);
}
......@@ -106,36 +97,36 @@ RealOpenMM AmoebaReferencePiTorsionForce::calculatePiTorsionIxn(const RealVec& p
AmoebaReferenceForce::getCrossProduct(deltaR[DC], deltaR[QD], deltaR[U]);
AmoebaReferenceForce::getCrossProduct(deltaR[T], deltaR[U], deltaR[TU]);
RealOpenMM rT2 = AmoebaReferenceForce::getNormSquared3(deltaR[T]);
RealOpenMM rU2 = AmoebaReferenceForce::getNormSquared3(deltaR[U]);
RealOpenMM rTrU = SQRT(rT2*rU2);
if (rTrU <= zero) {
return zero;
double rT2 = AmoebaReferenceForce::getNormSquared3(deltaR[T]);
double rU2 = AmoebaReferenceForce::getNormSquared3(deltaR[U]);
double rTrU = sqrt(rT2*rU2);
if (rTrU <= 0.0) {
return 0.0;
}
RealOpenMM rDC = AmoebaReferenceForce::getNorm3(deltaR[DC]);
double rDC = AmoebaReferenceForce::getNorm3(deltaR[DC]);
RealOpenMM cosine = AmoebaReferenceForce::getDotProduct3(deltaR[T], deltaR[U]);
cosine /= rTrU;
double cosine = AmoebaReferenceForce::getDotProduct3(deltaR[T], deltaR[U]);
cosine /= rTrU;
RealOpenMM sine = AmoebaReferenceForce::getDotProduct3(deltaR[DC], deltaR[TU]);
sine /= (rDC*rTrU);
double sine = AmoebaReferenceForce::getDotProduct3(deltaR[DC], deltaR[TU]);
sine /= (rDC*rTrU);
RealOpenMM cosine2 = cosine*cosine - sine*sine;
RealOpenMM sine2 = two*cosine*sine;
double cosine2 = cosine*cosine - sine*sine;
double sine2 = 2.0*cosine*sine;
RealOpenMM phi2 = one - cosine2;
RealOpenMM dphi2 = two*sine2;
double phi2 = 1.0 - cosine2;
double dphi2 = 2.0*sine2;
RealOpenMM dedphi = piTorsionK*dphi2;
double dedphi = piTorsionK*dphi2;
for (unsigned int ii = 0; ii < 3; ii++) {
deltaR[DP][ii] = positionAtomD[ii] - deltaR[P][ii];
deltaR[QC][ii] = deltaR[Q][ii] - positionAtomC[ii];
}
RealOpenMM factorT = dedphi/(rDC*rT2);
RealOpenMM factorU = -dedphi/(rDC*rU2);
double factorT = dedphi/(rDC*rT2);
double factorU = -dedphi/(rDC*rU2);
AmoebaReferenceForce::getCrossProduct(deltaR[T], deltaR[DC], deltaR[dT]);
AmoebaReferenceForce::getCrossProduct(deltaR[U], deltaR[DC], deltaR[dU]);
......@@ -200,16 +191,16 @@ RealOpenMM AmoebaReferencePiTorsionForce::calculatePiTorsionIxn(const RealVec& p
}
RealOpenMM AmoebaReferencePiTorsionForce::calculateForceAndEnergy(int numPiTorsions, vector<RealVec>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<int>& particle4,
const std::vector<int>& particle5,
const std::vector<int>& particle6,
const std::vector<RealOpenMM>& kTorsion,
vector<RealVec>& forceData) const {
RealOpenMM energy = 0.0;
double AmoebaReferencePiTorsionForce::calculateForceAndEnergy(int numPiTorsions, vector<Vec3>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<int>& particle4,
const std::vector<int>& particle5,
const std::vector<int>& particle6,
const std::vector<double>& kTorsion,
vector<Vec3>& forceData) const {
double energy = 0.0;
for (unsigned int ii = 0; ii < static_cast<unsigned int>(numPiTorsions); ii++) {
int particle1Index = particle1[ii];
......@@ -219,7 +210,7 @@ RealOpenMM AmoebaReferencePiTorsionForce::calculateForceAndEnergy(int numPiTorsi
int particle5Index = particle5[ii];
int particle6Index = particle6[ii];
RealVec forces[6];
Vec3 forces[6];
energy += calculatePiTorsionIxn(posData[particle1Index], posData[particle2Index],
posData[particle3Index], posData[particle4Index],
posData[particle5Index], posData[particle6Index],
......
......@@ -25,7 +25,7 @@
#ifndef __AmoebaReferencePiTorsionForce_H__
#define __AmoebaReferencePiTorsionForce_H__
#include "RealVec.h"
#include "openmm/Vec3.h"
#include <vector>
namespace OpenMM {
......@@ -58,7 +58,7 @@ public:
--------------------------------------------------------------------------------------- */
void setPeriodic(OpenMM::RealVec* vectors);
void setPeriodic(OpenMM::Vec3* vectors);
/**---------------------------------------------------------------------------------------
......@@ -82,21 +82,21 @@ public:
--------------------------------------------------------------------------------------- */
RealOpenMM calculateForceAndEnergy(int numPiTorsions, std::vector<OpenMM::RealVec>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<int>& particle4,
const std::vector<int>& particle5,
const std::vector<int>& particle6,
const std::vector<RealOpenMM>& kTorsion,
std::vector<OpenMM::RealVec>& forceData) const;
double calculateForceAndEnergy(int numPiTorsions, std::vector<OpenMM::Vec3>& posData,
const std::vector<int>& particle1,
const std::vector<int>& particle2,
const std::vector<int>& particle3,
const std::vector<int>& particle4,
const std::vector<int>& particle5,
const std::vector<int>& particle6,
const std::vector<double>& kTorsion,
std::vector<OpenMM::Vec3>& forceData) const;
private:
bool usePeriodic;
RealVec boxVectors[3];
Vec3 boxVectors[3];
/**---------------------------------------------------------------------------------------
......@@ -115,10 +115,10 @@ private:
--------------------------------------------------------------------------------------- */
RealOpenMM calculatePiTorsionIxn(const OpenMM::RealVec& positionAtomA, const OpenMM::RealVec& positionAtomB,
const OpenMM::RealVec& positionAtomC, const OpenMM::RealVec& positionAtomD,
const OpenMM::RealVec& positionAtomE, const OpenMM::RealVec& positionAtomF,
RealOpenMM kTorsion, OpenMM::RealVec* forces) const;
double calculatePiTorsionIxn(const OpenMM::Vec3& positionAtomA, const OpenMM::Vec3& positionAtomB,
const OpenMM::Vec3& positionAtomC, const OpenMM::Vec3& positionAtomD,
const OpenMM::Vec3& positionAtomE, const OpenMM::Vec3& positionAtomF,
double kTorsion, OpenMM::Vec3* forces) const;
};
......
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