Commit e45f1f28 authored by peastman's avatar peastman
Browse files

Implemented switching function for GayBerneForce

parent 505824d6
...@@ -229,6 +229,15 @@ RealOpenMM ReferenceGayBerneForce::computeOneInteraction(int particle1, int part ...@@ -229,6 +229,15 @@ RealOpenMM ReferenceGayBerneForce::computeOneInteraction(int particle1, int part
Matrix G12inv = G12.inverse(); Matrix G12inv = G12.inverse();
RealOpenMM detG12 = G12.determinant(); RealOpenMM detG12 = G12.determinant();
// Compute the switching function.
RealOpenMM switchValue = 1, switchDeriv = 0;
if (useSwitchingFunction && r > switchingDistance) {
RealOpenMM t = (r-switchingDistance)/(cutoffDistance-switchingDistance);
switchValue = 1+t*t*t*(-10+t*(15-t*6));
switchDeriv = t*t*(-30+t*(60-t*30))/(cutoffDistance-switchingDistance);
}
// Estimate the distance between the ellipsoids and compute the first terms needed for the energy. // Estimate the distance between the ellipsoids and compute the first terms needed for the energy.
RealOpenMM sigma12 = 1/SQRT(0.5*drUnit.dot(G12inv*drUnit)); RealOpenMM sigma12 = 1/SQRT(0.5*drUnit.dot(G12inv*drUnit));
...@@ -240,6 +249,7 @@ RealOpenMM ReferenceGayBerneForce::computeOneInteraction(int particle1, int part ...@@ -240,6 +249,7 @@ RealOpenMM ReferenceGayBerneForce::computeOneInteraction(int particle1, int part
RealOpenMM eta = SQRT(2*s[particle1]*s[particle2]/detG12); RealOpenMM eta = SQRT(2*s[particle1]*s[particle2]/detG12);
RealOpenMM chi = 2*drUnit.dot(B12inv*drUnit); RealOpenMM chi = 2*drUnit.dot(B12inv*drUnit);
chi *= chi; chi *= chi;
RealOpenMM energy = u*eta*chi;
// Compute the terms needed for the force. // Compute the terms needed for the force.
...@@ -250,7 +260,7 @@ RealOpenMM ReferenceGayBerneForce::computeOneInteraction(int particle1, int part ...@@ -250,7 +260,7 @@ RealOpenMM ReferenceGayBerneForce::computeOneInteraction(int particle1, int part
RealOpenMM temp = 0.5*sigma12*sigma12*sigma12*rInv2; RealOpenMM temp = 0.5*sigma12*sigma12*sigma12*rInv2;
RealVec dudr = (drUnit + (kappa-drUnit*kappa.dot(drUnit))*temp)*dUSLJdr; RealVec dudr = (drUnit + (kappa-drUnit*kappa.dot(drUnit))*temp)*dUSLJdr;
RealVec dchidr = (iota-drUnit*iota.dot(drUnit))*(-8*rInv2*SQRT(chi)); RealVec dchidr = (iota-drUnit*iota.dot(drUnit))*(-8*rInv2*SQRT(chi));
RealVec force = (dchidr*u + dudr*chi)*eta; RealVec force = (dchidr*u + dudr*chi)*(eta*switchValue) - drUnit*(energy*switchDeriv);
forces[particle1] += force; forces[particle1] += force;
forces[particle2] -= force; forces[particle2] -= force;
...@@ -314,8 +324,8 @@ RealOpenMM ReferenceGayBerneForce::computeOneInteraction(int particle1, int part ...@@ -314,8 +324,8 @@ RealOpenMM ReferenceGayBerneForce::computeOneInteraction(int particle1, int part
RealVec detadq; RealVec detadq;
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
detadq += RealVec(a[i][0], a[i][1], a[i][2]).cross(RealVec(d[i][0], d[i][1], d[i][2])); detadq += RealVec(a[i][0], a[i][1], a[i][2]).cross(RealVec(d[i][0], d[i][1], d[i][2]));
RealVec torque = dchidq*(u*eta) + detadq*(u*chi) + dudq*(eta*chi); RealVec torque = (dchidq*(u*eta) + detadq*(u*chi) + dudq*(eta*chi))*switchValue;
torques[particle] -= torque; torques[particle] -= torque;
} }
return u*eta*chi; return switchValue*energy;
} }
...@@ -146,6 +146,8 @@ void testEnergyConservation() { ...@@ -146,6 +146,8 @@ void testEnergyConservation() {
system.addForce(gb); system.addForce(gb);
gb->setNonbondedMethod(GayBerneForce::CutoffPeriodic); gb->setNonbondedMethod(GayBerneForce::CutoffPeriodic);
gb->setCutoffDistance(1.0); gb->setCutoffDistance(1.0);
gb->setUseSwitchingFunction(true);
gb->setSwitchingDistance(0.9);
vector<Vec3> positions; vector<Vec3> positions;
for (int x = 0; x < 3; x++) { for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) { for (int y = 0; y < 3; y++) {
...@@ -178,7 +180,7 @@ void testEnergyConservation() { ...@@ -178,7 +180,7 @@ void testEnergyConservation() {
if (i == 0) if (i == 0)
initialEnergy = energy; initialEnergy = energy;
else else
ASSERT_EQUAL_TOL(initialEnergy, energy, 1e-3); ASSERT_EQUAL_TOL(initialEnergy, energy, 1e-4);
} }
} }
......
...@@ -412,6 +412,8 @@ UNITS = { ...@@ -412,6 +412,8 @@ UNITS = {
("PeriodicTorsionForce", "getTorsionParameters") ("PeriodicTorsionForce", "getTorsionParameters")
: (None, (None, None, None, None, : (None, (None, None, None, None,
None, 'unit.radian', 'unit.kilojoule_per_mole')), None, 'unit.radian', 'unit.kilojoule_per_mole')),
("GayBerneForce", "getParticleParameters")
: (None, ('unit.nanometer', 'unit.kilojoule_per_mole', None, None, 'unit.nanometer', 'unit.nanometer', 'unit.nanometer', None, None, None)),
("Platform", "getDefaultPluginsDirectory") : (None, ()), ("Platform", "getDefaultPluginsDirectory") : (None, ()),
("Platform", "getPropertyDefaultValue") : (None, ()), ("Platform", "getPropertyDefaultValue") : (None, ()),
("Platform", "getPropertyNames") : (None, ()), ("Platform", "getPropertyNames") : (None, ()),
......
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