Commit 162d69a2 authored by peastman's avatar peastman
Browse files

Merge pull request #827 from peastman/reference

Lots of cleanup to reference platform
parents 2379b982 c44c956d
...@@ -25,14 +25,12 @@ ...@@ -25,14 +25,12 @@
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
#include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h"
#include "SimTKOpenMMUtilities.h" #include "SimTKOpenMMUtilities.h"
#include "ReferenceLJCoulomb14.h" #include "ReferenceLJCoulomb14.h"
#include "ReferenceForce.h" #include "ReferenceForce.h"
using std::vector; using std::vector;
using OpenMM::RealVec; using namespace OpenMM;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -40,7 +38,7 @@ using OpenMM::RealVec; ...@@ -40,7 +38,7 @@ using OpenMM::RealVec;
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceLJCoulomb14::ReferenceLJCoulomb14( ) { ReferenceLJCoulomb14::ReferenceLJCoulomb14() {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -56,7 +54,7 @@ ReferenceLJCoulomb14::ReferenceLJCoulomb14( ) { ...@@ -56,7 +54,7 @@ ReferenceLJCoulomb14::ReferenceLJCoulomb14( ) {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceLJCoulomb14::~ReferenceLJCoulomb14( ){ ReferenceLJCoulomb14::~ReferenceLJCoulomb14() {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -81,9 +79,9 @@ ReferenceLJCoulomb14::~ReferenceLJCoulomb14( ){ ...@@ -81,9 +79,9 @@ ReferenceLJCoulomb14::~ReferenceLJCoulomb14( ){
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceLJCoulomb14::calculateBondIxn( int* atomIndices, vector<RealVec>& atomCoordinates, void ReferenceLJCoulomb14::calculateBondIxn(int* atomIndices, vector<RealVec>& atomCoordinates,
RealOpenMM* parameters, vector<RealVec>& forces, RealOpenMM* parameters, vector<RealVec>& forces,
RealOpenMM* totalEnergy ) const { RealOpenMM* totalEnergy) const {
static const std::string methodName = "\nReferenceLJCoulomb14::calculateBondIxn"; static const std::string methodName = "\nReferenceLJCoulomb14::calculateBondIxn";
...@@ -113,7 +111,7 @@ void ReferenceLJCoulomb14::calculateBondIxn( int* atomIndices, vector<RealVec>& ...@@ -113,7 +111,7 @@ void ReferenceLJCoulomb14::calculateBondIxn( int* atomIndices, vector<RealVec>&
int atomAIndex = atomIndices[0]; int atomAIndex = atomIndices[0];
int atomBIndex = atomIndices[1]; int atomBIndex = atomIndices[1];
ReferenceForce::getDeltaR( atomCoordinates[atomBIndex], atomCoordinates[atomAIndex], deltaR[0] ); ReferenceForce::getDeltaR(atomCoordinates[atomBIndex], atomCoordinates[atomAIndex], deltaR[0]);
RealOpenMM r2 = deltaR[0][ReferenceForce::R2Index]; RealOpenMM r2 = deltaR[0][ReferenceForce::R2Index];
RealOpenMM inverseR = one/(deltaR[0][ReferenceForce::RIndex]); RealOpenMM inverseR = one/(deltaR[0][ReferenceForce::RIndex]);
...@@ -121,13 +119,13 @@ void ReferenceLJCoulomb14::calculateBondIxn( int* atomIndices, vector<RealVec>& ...@@ -121,13 +119,13 @@ void ReferenceLJCoulomb14::calculateBondIxn( int* atomIndices, vector<RealVec>&
sig2 *= sig2; sig2 *= sig2;
RealOpenMM sig6 = sig2*sig2*sig2; RealOpenMM sig6 = sig2*sig2*sig2;
RealOpenMM dEdR = parameters[1]*( twelve*sig6 - six )*sig6; RealOpenMM dEdR = parameters[1]*(twelve*sig6 - six)*sig6;
dEdR += (RealOpenMM) (ONE_4PI_EPS0*parameters[2]*inverseR); dEdR += (RealOpenMM) (ONE_4PI_EPS0*parameters[2]*inverseR);
dEdR *= inverseR*inverseR; dEdR *= inverseR*inverseR;
// accumulate forces // accumulate forces
for( int ii = 0; ii < 3; ii++ ){ for (int ii = 0; ii < 3; ii++) {
RealOpenMM force = dEdR*deltaR[0][ii]; RealOpenMM force = dEdR*deltaR[0][ii];
forces[atomAIndex][ii] += force; forces[atomAIndex][ii] += force;
forces[atomBIndex][ii] -= force; forces[atomBIndex][ii] -= force;
...@@ -136,5 +134,5 @@ void ReferenceLJCoulomb14::calculateBondIxn( int* atomIndices, vector<RealVec>& ...@@ -136,5 +134,5 @@ void ReferenceLJCoulomb14::calculateBondIxn( int* atomIndices, vector<RealVec>&
// accumulate energies // accumulate energies
if (totalEnergy != NULL) if (totalEnergy != NULL)
*totalEnergy += parameters[1]*( sig6 - one )*sig6 + (ONE_4PI_EPS0*parameters[2]*inverseR); *totalEnergy += parameters[1]*(sig6 - one)*sig6 + (ONE_4PI_EPS0*parameters[2]*inverseR);
} }
...@@ -27,12 +27,11 @@ ...@@ -27,12 +27,11 @@
#include <complex> #include <complex>
#include <algorithm> #include <algorithm>
#include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h"
#include "SimTKOpenMMUtilities.h" #include "SimTKOpenMMUtilities.h"
#include "ReferenceLJCoulombIxn.h" #include "ReferenceLJCoulombIxn.h"
#include "ReferenceForce.h" #include "ReferenceForce.h"
#include "ReferencePME.h" #include "ReferencePME.h"
#include "openmm/OpenMMException.h"
// In case we're using some primitive version of Visual Studio this will // In case we're using some primitive version of Visual Studio this will
// make sure that erf() and erfc() are defined. // make sure that erf() and erfc() are defined.
...@@ -40,7 +39,7 @@ ...@@ -40,7 +39,7 @@
using std::set; using std::set;
using std::vector; using std::vector;
using OpenMM::RealVec; using namespace OpenMM;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -48,7 +47,7 @@ using OpenMM::RealVec; ...@@ -48,7 +47,7 @@ using OpenMM::RealVec;
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceLJCoulombIxn::ReferenceLJCoulombIxn( ) : cutoff(false), useSwitch(false), periodic(false), ewald(false), pme(false) { ReferenceLJCoulombIxn::ReferenceLJCoulombIxn() : cutoff(false), useSwitch(false), periodic(false), ewald(false), pme(false) {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -64,7 +63,7 @@ ReferenceLJCoulombIxn::ReferenceLJCoulombIxn( ) : cutoff(false), useSwitch(false ...@@ -64,7 +63,7 @@ ReferenceLJCoulombIxn::ReferenceLJCoulombIxn( ) : cutoff(false), useSwitch(false
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceLJCoulombIxn::~ReferenceLJCoulombIxn( ){ ReferenceLJCoulombIxn::~ReferenceLJCoulombIxn() {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -84,7 +83,7 @@ ReferenceLJCoulombIxn::~ReferenceLJCoulombIxn( ){ ...@@ -84,7 +83,7 @@ ReferenceLJCoulombIxn::~ReferenceLJCoulombIxn( ){
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceLJCoulombIxn::setUseCutoff( RealOpenMM distance, const OpenMM::NeighborList& neighbors, RealOpenMM solventDielectric ) { void ReferenceLJCoulombIxn::setUseCutoff(RealOpenMM distance, const OpenMM::NeighborList& neighbors, RealOpenMM solventDielectric) {
cutoff = true; cutoff = true;
cutoffDistance = distance; cutoffDistance = distance;
...@@ -101,7 +100,7 @@ ReferenceLJCoulombIxn::~ReferenceLJCoulombIxn( ){ ...@@ -101,7 +100,7 @@ ReferenceLJCoulombIxn::~ReferenceLJCoulombIxn( ){
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceLJCoulombIxn::setUseSwitchingFunction( RealOpenMM distance ) { void ReferenceLJCoulombIxn::setUseSwitchingFunction(RealOpenMM distance) {
useSwitch = true; useSwitch = true;
switchingDistance = distance; switchingDistance = distance;
} }
...@@ -210,16 +209,16 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec> ...@@ -210,16 +209,16 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
// ************************************************************************************** // **************************************************************************************
if (includeReciprocal) { if (includeReciprocal) {
for( int atomID = 0; atomID < numberOfAtoms; atomID++ ){ for (int atomID = 0; atomID < numberOfAtoms; atomID++) {
RealOpenMM selfEwaldEnergy = (RealOpenMM) (ONE_4PI_EPS0*atomParameters[atomID][QIndex]*atomParameters[atomID][QIndex] * alphaEwald/SQRT_PI); RealOpenMM selfEwaldEnergy = (RealOpenMM) (ONE_4PI_EPS0*atomParameters[atomID][QIndex]*atomParameters[atomID][QIndex] * alphaEwald/SQRT_PI);
totalSelfEwaldEnergy -= selfEwaldEnergy; totalSelfEwaldEnergy -= selfEwaldEnergy;
if( energyByAtom ){ if (energyByAtom) {
energyByAtom[atomID] -= selfEwaldEnergy; energyByAtom[atomID] -= selfEwaldEnergy;
} }
} }
} }
if( totalEnergy ){ if (totalEnergy) {
*totalEnergy += totalSelfEwaldEnergy; *totalEnergy += totalSelfEwaldEnergy;
} }
...@@ -238,11 +237,11 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec> ...@@ -238,11 +237,11 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
charges[i] = atomParameters[i][QIndex]; charges[i] = atomParameters[i][QIndex];
pme_exec(pmedata,atomCoordinates,forces,charges,periodicBoxVectors,&recipEnergy); pme_exec(pmedata,atomCoordinates,forces,charges,periodicBoxVectors,&recipEnergy);
if( totalEnergy ) if (totalEnergy)
*totalEnergy += recipEnergy; *totalEnergy += recipEnergy;
if( energyByAtom ) if (energyByAtom)
for(int n = 0; n < numberOfAtoms; n++) for (int n = 0; n < numberOfAtoms; n++)
energyByAtom[n] += recipEnergy; energyByAtom[n] += recipEnergy;
pme_destroy(pmedata); pme_destroy(pmedata);
...@@ -264,22 +263,19 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec> ...@@ -264,22 +263,19 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
vector<d_complex> tab_xy(numberOfAtoms); vector<d_complex> tab_xy(numberOfAtoms);
vector<d_complex> tab_qxyz(numberOfAtoms); vector<d_complex> tab_qxyz(numberOfAtoms);
if (kmax < 1) { if (kmax < 1)
std::stringstream message; throw OpenMMException("kmax for Ewald summation < 1");
message << " kmax < 1 , Aborting" << std::endl;
SimTKOpenMMLog::printError( message );
}
for(int i = 0; (i < numberOfAtoms); i++) { for (int i = 0; (i < numberOfAtoms); i++) {
for(int m = 0; (m < 3); m++) for (int m = 0; (m < 3); m++)
EIR(0, i, m) = d_complex(1,0); EIR(0, i, m) = d_complex(1,0);
for(int m=0; (m<3); m++) for (int m=0; (m<3); m++)
EIR(1, i, m) = d_complex(cos(atomCoordinates[i][m]*recipBoxSize[m]), EIR(1, i, m) = d_complex(cos(atomCoordinates[i][m]*recipBoxSize[m]),
sin(atomCoordinates[i][m]*recipBoxSize[m])); sin(atomCoordinates[i][m]*recipBoxSize[m]));
for(int j=2; (j<kmax); j++) for (int j=2; (j<kmax); j++)
for(int m=0; (m<3); m++) for (int m=0; (m<3); m++)
EIR(j, i, m) = EIR(j-1, i, m) * EIR(1, i, m); EIR(j, i, m) = EIR(j-1, i, m) * EIR(1, i, m);
} }
...@@ -288,40 +284,40 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec> ...@@ -288,40 +284,40 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
int lowry = 0; int lowry = 0;
int lowrz = 1; int lowrz = 1;
for(int rx = 0; rx < numRx; rx++) { for (int rx = 0; rx < numRx; rx++) {
RealOpenMM kx = rx * recipBoxSize[0]; RealOpenMM kx = rx * recipBoxSize[0];
for(int ry = lowry; ry < numRy; ry++) { for (int ry = lowry; ry < numRy; ry++) {
RealOpenMM ky = ry * recipBoxSize[1]; RealOpenMM ky = ry * recipBoxSize[1];
if(ry >= 0) { if (ry >= 0) {
for(int n = 0; n < numberOfAtoms; n++) for (int n = 0; n < numberOfAtoms; n++)
tab_xy[n] = EIR(rx, n, 0) * EIR(ry, n, 1); tab_xy[n] = EIR(rx, n, 0) * EIR(ry, n, 1);
} }
else { else {
for(int n = 0; n < numberOfAtoms; n++) for (int n = 0; n < numberOfAtoms; n++)
tab_xy[n]= EIR(rx, n, 0) * conj (EIR(-ry, n, 1)); tab_xy[n]= EIR(rx, n, 0) * conj (EIR(-ry, n, 1));
} }
for (int rz = lowrz; rz < numRz; rz++) { for (int rz = lowrz; rz < numRz; rz++) {
if( rz >= 0) { if (rz >= 0) {
for( int n = 0; n < numberOfAtoms; n++) for (int n = 0; n < numberOfAtoms; n++)
tab_qxyz[n] = atomParameters[n][QIndex] * (tab_xy[n] * EIR(rz, n, 2)); tab_qxyz[n] = atomParameters[n][QIndex] * (tab_xy[n] * EIR(rz, n, 2));
} }
else { else {
for( int n = 0; n < numberOfAtoms; n++) for (int n = 0; n < numberOfAtoms; n++)
tab_qxyz[n] = atomParameters[n][QIndex] * (tab_xy[n] * conj(EIR(-rz, n, 2))); tab_qxyz[n] = atomParameters[n][QIndex] * (tab_xy[n] * conj(EIR(-rz, n, 2)));
} }
RealOpenMM cs = 0.0f; RealOpenMM cs = 0.0f;
RealOpenMM ss = 0.0f; RealOpenMM ss = 0.0f;
for( int n = 0; n < numberOfAtoms; n++) { for (int n = 0; n < numberOfAtoms; n++) {
cs += tab_qxyz[n].real(); cs += tab_qxyz[n].real();
ss += tab_qxyz[n].imag(); ss += tab_qxyz[n].imag();
} }
...@@ -330,21 +326,21 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec> ...@@ -330,21 +326,21 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
RealOpenMM k2 = kx * kx + ky * ky + kz * kz; RealOpenMM k2 = kx * kx + ky * ky + kz * kz;
RealOpenMM ak = exp(k2*factorEwald) / k2; RealOpenMM ak = exp(k2*factorEwald) / k2;
for(int n = 0; n < numberOfAtoms; n++) { for (int n = 0; n < numberOfAtoms; n++) {
RealOpenMM force = ak * (cs * tab_qxyz[n].imag() - ss * tab_qxyz[n].real()); RealOpenMM force = ak * (cs * tab_qxyz[n].imag() - ss * tab_qxyz[n].real());
forces[n][0] += 2 * recipCoeff * force * kx ; forces[n][0] += 2 * recipCoeff * force * kx ;
forces[n][1] += 2 * recipCoeff * force * ky ; forces[n][1] += 2 * recipCoeff * force * ky ;
forces[n][2] += 2 * recipCoeff * force * kz ; forces[n][2] += 2 * recipCoeff * force * kz ;
} }
recipEnergy = recipCoeff * ak * ( cs * cs + ss * ss); recipEnergy = recipCoeff * ak * (cs * cs + ss * ss);
totalRecipEnergy += recipEnergy; totalRecipEnergy += recipEnergy;
if( totalEnergy ) if (totalEnergy)
*totalEnergy += recipEnergy; *totalEnergy += recipEnergy;
if( energyByAtom ) if (energyByAtom)
for(int n = 0; n < numberOfAtoms; n++) for (int n = 0; n < numberOfAtoms; n++)
energyByAtom[n] += recipEnergy; energyByAtom[n] += recipEnergy;
lowrz = 1 - numRz; lowrz = 1 - numRz;
...@@ -369,7 +365,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec> ...@@ -369,7 +365,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
int jj = pair.second; int jj = pair.second;
RealOpenMM deltaR[2][ReferenceForce::LastDeltaRIndex]; RealOpenMM deltaR[2][ReferenceForce::LastDeltaRIndex];
ReferenceForce::getDeltaRPeriodic( atomCoordinates[jj], atomCoordinates[ii], periodicBoxVectors, deltaR[0] ); ReferenceForce::getDeltaRPeriodic(atomCoordinates[jj], atomCoordinates[ii], periodicBoxVectors, deltaR[0]);
RealOpenMM r = deltaR[0][ReferenceForce::RIndex]; RealOpenMM r = deltaR[0][ReferenceForce::RIndex];
RealOpenMM inverseR = one/(deltaR[0][ReferenceForce::RIndex]); RealOpenMM inverseR = one/(deltaR[0][ReferenceForce::RIndex]);
RealOpenMM switchValue = 1, switchDeriv = 0; RealOpenMM switchValue = 1, switchDeriv = 0;
...@@ -382,14 +378,14 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec> ...@@ -382,14 +378,14 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
RealOpenMM dEdR = (RealOpenMM) (ONE_4PI_EPS0 * atomParameters[ii][QIndex] * atomParameters[jj][QIndex] * inverseR * inverseR * inverseR); RealOpenMM dEdR = (RealOpenMM) (ONE_4PI_EPS0 * atomParameters[ii][QIndex] * atomParameters[jj][QIndex] * inverseR * inverseR * inverseR);
dEdR = (RealOpenMM) (dEdR * (erfc(alphaR) + 2 * alphaR * exp ( - alphaR * alphaR) / SQRT_PI )); dEdR = (RealOpenMM) (dEdR * (erfc(alphaR) + 2 * alphaR * exp (- alphaR * alphaR) / SQRT_PI));
RealOpenMM sig = atomParameters[ii][SigIndex] + atomParameters[jj][SigIndex]; RealOpenMM sig = atomParameters[ii][SigIndex] + atomParameters[jj][SigIndex];
RealOpenMM sig2 = inverseR*sig; RealOpenMM sig2 = inverseR*sig;
sig2 *= sig2; sig2 *= sig2;
RealOpenMM sig6 = sig2*sig2*sig2; RealOpenMM sig6 = sig2*sig2*sig2;
RealOpenMM eps = atomParameters[ii][EpsIndex]*atomParameters[jj][EpsIndex]; RealOpenMM eps = atomParameters[ii][EpsIndex]*atomParameters[jj][EpsIndex];
dEdR += switchValue*eps*( twelve*sig6 - six )*sig6*inverseR*inverseR; dEdR += switchValue*eps*(twelve*sig6 - six)*sig6*inverseR*inverseR;
vdwEnergy = eps*(sig6-one)*sig6; vdwEnergy = eps*(sig6-one)*sig6;
if (useSwitch) { if (useSwitch) {
dEdR -= vdwEnergy*switchDeriv*inverseR; dEdR -= vdwEnergy*switchDeriv*inverseR;
...@@ -398,7 +394,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec> ...@@ -398,7 +394,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
// accumulate forces // accumulate forces
for( int kk = 0; kk < 3; kk++ ){ for (int kk = 0; kk < 3; kk++) {
RealOpenMM force = dEdR*deltaR[0][kk]; RealOpenMM force = dEdR*deltaR[0][kk];
forces[ii][kk] += force; forces[ii][kk] += force;
forces[jj][kk] -= force; forces[jj][kk] -= force;
...@@ -411,14 +407,14 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec> ...@@ -411,14 +407,14 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
totalVdwEnergy += vdwEnergy; totalVdwEnergy += vdwEnergy;
totalRealSpaceEwaldEnergy += realSpaceEwaldEnergy; totalRealSpaceEwaldEnergy += realSpaceEwaldEnergy;
if( energyByAtom ){ if (energyByAtom) {
energyByAtom[ii] += realSpaceEwaldEnergy + vdwEnergy; energyByAtom[ii] += realSpaceEwaldEnergy + vdwEnergy;
energyByAtom[jj] += realSpaceEwaldEnergy + vdwEnergy; energyByAtom[jj] += realSpaceEwaldEnergy + vdwEnergy;
} }
} }
if( totalEnergy ) if (totalEnergy)
*totalEnergy += totalRealSpaceEwaldEnergy + totalVdwEnergy; *totalEnergy += totalRealSpaceEwaldEnergy + totalVdwEnergy;
// Now subtract off the exclusions, since they were implicitly included in the reciprocal space sum. // Now subtract off the exclusions, since they were implicitly included in the reciprocal space sum.
...@@ -431,17 +427,17 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec> ...@@ -431,17 +427,17 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
int jj = *iter; int jj = *iter;
RealOpenMM deltaR[2][ReferenceForce::LastDeltaRIndex]; RealOpenMM deltaR[2][ReferenceForce::LastDeltaRIndex];
ReferenceForce::getDeltaR( atomCoordinates[jj], atomCoordinates[ii], deltaR[0] ); ReferenceForce::getDeltaR(atomCoordinates[jj], atomCoordinates[ii], deltaR[0]);
RealOpenMM r = deltaR[0][ReferenceForce::RIndex]; RealOpenMM r = deltaR[0][ReferenceForce::RIndex];
RealOpenMM inverseR = one/(deltaR[0][ReferenceForce::RIndex]); RealOpenMM inverseR = one/(deltaR[0][ReferenceForce::RIndex]);
RealOpenMM alphaR = alphaEwald * r; RealOpenMM alphaR = alphaEwald * r;
if (erf(alphaR) > 1e-6) { if (erf(alphaR) > 1e-6) {
RealOpenMM dEdR = (RealOpenMM) (ONE_4PI_EPS0 * atomParameters[ii][QIndex] * atomParameters[jj][QIndex] * inverseR * inverseR * inverseR); RealOpenMM dEdR = (RealOpenMM) (ONE_4PI_EPS0 * atomParameters[ii][QIndex] * atomParameters[jj][QIndex] * inverseR * inverseR * inverseR);
dEdR = (RealOpenMM) (dEdR * (erf(alphaR) - 2 * alphaR * exp ( - alphaR * alphaR) / SQRT_PI )); dEdR = (RealOpenMM) (dEdR * (erf(alphaR) - 2 * alphaR * exp (- alphaR * alphaR) / SQRT_PI));
// accumulate forces // accumulate forces
for( int kk = 0; kk < 3; kk++ ){ for (int kk = 0; kk < 3; kk++) {
RealOpenMM force = dEdR*deltaR[0][kk]; RealOpenMM force = dEdR*deltaR[0][kk];
forces[ii][kk] -= force; forces[ii][kk] -= force;
forces[jj][kk] += force; forces[jj][kk] += force;
...@@ -452,7 +448,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec> ...@@ -452,7 +448,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
realSpaceEwaldEnergy = (RealOpenMM) (ONE_4PI_EPS0*atomParameters[ii][QIndex]*atomParameters[jj][QIndex]*inverseR*erf(alphaR)); realSpaceEwaldEnergy = (RealOpenMM) (ONE_4PI_EPS0*atomParameters[ii][QIndex]*atomParameters[jj][QIndex]*inverseR*erf(alphaR));
totalExclusionEnergy += realSpaceEwaldEnergy; totalExclusionEnergy += realSpaceEwaldEnergy;
if( energyByAtom ){ if (energyByAtom) {
energyByAtom[ii] -= realSpaceEwaldEnergy; energyByAtom[ii] -= realSpaceEwaldEnergy;
energyByAtom[jj] -= realSpaceEwaldEnergy; energyByAtom[jj] -= realSpaceEwaldEnergy;
} }
...@@ -460,7 +456,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec> ...@@ -460,7 +456,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
} }
} }
if( totalEnergy ) if (totalEnergy)
*totalEnergy -= totalExclusionEnergy; *totalEnergy -= totalExclusionEnergy;
} }
...@@ -502,10 +498,10 @@ void ReferenceLJCoulombIxn::calculatePairIxn(int numberOfAtoms, vector<RealVec>& ...@@ -502,10 +498,10 @@ void ReferenceLJCoulombIxn::calculatePairIxn(int numberOfAtoms, vector<RealVec>&
} }
} }
else { else {
for( int ii = 0; ii < numberOfAtoms; ii++ ){ for (int ii = 0; ii < numberOfAtoms; ii++) {
// loop over atom pairs // loop over atom pairs
for( int jj = ii+1; jj < numberOfAtoms; jj++ ) for (int jj = ii+1; jj < numberOfAtoms; jj++)
if (exclusions[jj].find(ii) == exclusions[jj].end()) if (exclusions[jj].find(ii) == exclusions[jj].end())
calculateOneIxn(ii, jj, atomCoordinates, atomParameters, forces, energyByAtom, totalEnergy); calculateOneIxn(ii, jj, atomCoordinates, atomParameters, forces, energyByAtom, totalEnergy);
} }
...@@ -526,9 +522,9 @@ void ReferenceLJCoulombIxn::calculatePairIxn(int numberOfAtoms, vector<RealVec>& ...@@ -526,9 +522,9 @@ void ReferenceLJCoulombIxn::calculatePairIxn(int numberOfAtoms, vector<RealVec>&
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, vector<RealVec>& atomCoordinates, void ReferenceLJCoulombIxn::calculateOneIxn(int ii, int jj, vector<RealVec>& atomCoordinates,
RealOpenMM** atomParameters, vector<RealVec>& forces, RealOpenMM** atomParameters, vector<RealVec>& forces,
RealOpenMM* energyByAtom, RealOpenMM* totalEnergy ) const { RealOpenMM* energyByAtom, RealOpenMM* totalEnergy) const {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -555,9 +551,9 @@ void ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, vector<RealVec>& at ...@@ -555,9 +551,9 @@ void ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, vector<RealVec>& at
// get deltaR, R2, and R between 2 atoms // get deltaR, R2, and R between 2 atoms
if (periodic) if (periodic)
ReferenceForce::getDeltaRPeriodic( atomCoordinates[jj], atomCoordinates[ii], periodicBoxVectors, deltaR[0] ); ReferenceForce::getDeltaRPeriodic(atomCoordinates[jj], atomCoordinates[ii], periodicBoxVectors, deltaR[0]);
else else
ReferenceForce::getDeltaR( atomCoordinates[jj], atomCoordinates[ii], deltaR[0] ); ReferenceForce::getDeltaR(atomCoordinates[jj], atomCoordinates[ii], deltaR[0]);
RealOpenMM r2 = deltaR[0][ReferenceForce::R2Index]; RealOpenMM r2 = deltaR[0][ReferenceForce::R2Index];
RealOpenMM inverseR = one/(deltaR[0][ReferenceForce::RIndex]); RealOpenMM inverseR = one/(deltaR[0][ReferenceForce::RIndex]);
...@@ -576,7 +572,7 @@ void ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, vector<RealVec>& at ...@@ -576,7 +572,7 @@ void ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, vector<RealVec>& at
RealOpenMM sig6 = sig2*sig2*sig2; RealOpenMM sig6 = sig2*sig2*sig2;
RealOpenMM eps = atomParameters[ii][EpsIndex]*atomParameters[jj][EpsIndex]; RealOpenMM eps = atomParameters[ii][EpsIndex]*atomParameters[jj][EpsIndex];
RealOpenMM dEdR = switchValue*eps*( twelve*sig6 - six )*sig6; RealOpenMM dEdR = switchValue*eps*(twelve*sig6 - six)*sig6;
if (cutoff) if (cutoff)
dEdR += (RealOpenMM) (ONE_4PI_EPS0*atomParameters[ii][QIndex]*atomParameters[jj][QIndex]*(inverseR-2.0f*krf*r2)); dEdR += (RealOpenMM) (ONE_4PI_EPS0*atomParameters[ii][QIndex]*atomParameters[jj][QIndex]*(inverseR-2.0f*krf*r2));
else else
...@@ -594,7 +590,7 @@ void ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, vector<RealVec>& at ...@@ -594,7 +590,7 @@ void ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, vector<RealVec>& at
// accumulate forces // accumulate forces
for( int kk = 0; kk < 3; kk++ ){ for (int kk = 0; kk < 3; kk++) {
RealOpenMM force = dEdR*deltaR[0][kk]; RealOpenMM force = dEdR*deltaR[0][kk];
forces[ii][kk] += force; forces[ii][kk] += force;
forces[jj][kk] -= force; forces[jj][kk] -= force;
...@@ -602,9 +598,9 @@ void ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, vector<RealVec>& at ...@@ -602,9 +598,9 @@ void ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, vector<RealVec>& at
// accumulate energies // accumulate energies
if( totalEnergy ) if (totalEnergy)
*totalEnergy += energy; *totalEnergy += energy;
if( energyByAtom ){ if (energyByAtom) {
energyByAtom[ii] += energy; energyByAtom[ii] += energy;
energyByAtom[jj] += energy; energyByAtom[jj] += energy;
} }
......
...@@ -24,15 +24,13 @@ ...@@ -24,15 +24,13 @@
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
#include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMUtilities.h" #include "SimTKOpenMMUtilities.h"
#include "SimTKOpenMMLog.h"
#include "ReferenceLincsAlgorithm.h" #include "ReferenceLincsAlgorithm.h"
#include "ReferenceDynamics.h" #include "ReferenceDynamics.h"
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
using std::vector; using std::vector;
using OpenMM::RealVec; using namespace OpenMM;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -44,9 +42,9 @@ using OpenMM::RealVec; ...@@ -44,9 +42,9 @@ using OpenMM::RealVec;
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceLincsAlgorithm::ReferenceLincsAlgorithm( int numberOfConstraints, ReferenceLincsAlgorithm::ReferenceLincsAlgorithm(int numberOfConstraints,
int** atomIndices, int** atomIndices,
RealOpenMM* distance ){ RealOpenMM* distance) {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -70,7 +68,7 @@ ReferenceLincsAlgorithm::ReferenceLincsAlgorithm( int numberOfConstraints, ...@@ -70,7 +68,7 @@ ReferenceLincsAlgorithm::ReferenceLincsAlgorithm( int numberOfConstraints,
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int ReferenceLincsAlgorithm::getNumberOfConstraints( void ) const { int ReferenceLincsAlgorithm::getNumberOfConstraints() const {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -89,7 +87,7 @@ int ReferenceLincsAlgorithm::getNumberOfConstraints( void ) const { ...@@ -89,7 +87,7 @@ int ReferenceLincsAlgorithm::getNumberOfConstraints( void ) const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int ReferenceLincsAlgorithm::getNumTerms( void ) const { int ReferenceLincsAlgorithm::getNumTerms() const {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -106,7 +104,7 @@ int ReferenceLincsAlgorithm::getNumTerms( void ) const { ...@@ -106,7 +104,7 @@ int ReferenceLincsAlgorithm::getNumTerms( void ) const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceLincsAlgorithm::setNumTerms( int terms ){ void ReferenceLincsAlgorithm::setNumTerms(int terms) {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -214,14 +212,11 @@ void ReferenceLincsAlgorithm::updateAtomPositions(int numberOfAtoms, vector<Real ...@@ -214,14 +212,11 @@ void ReferenceLincsAlgorithm::updateAtomPositions(int numberOfAtoms, vector<Real
@param atomCoordinatesP atom coordinates prime @param atomCoordinatesP atom coordinates prime
@param inverseMasses 1/mass @param inverseMasses 1/mass
@return SimTKOpenMMCommon::DefaultReturn if converge; else
return SimTKOpenMMCommon::ErrorReturn
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int ReferenceLincsAlgorithm::apply( int numberOfAtoms, vector<RealVec>& atomCoordinates, void ReferenceLincsAlgorithm::apply(int numberOfAtoms, vector<RealVec>& atomCoordinates,
vector<RealVec>& atomCoordinatesP, vector<RealVec>& atomCoordinatesP,
vector<RealOpenMM>& inverseMasses ){ vector<RealOpenMM>& inverseMasses) {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -234,9 +229,9 @@ int ReferenceLincsAlgorithm::apply( int numberOfAtoms, vector<RealVec>& atomCoor ...@@ -234,9 +229,9 @@ int ReferenceLincsAlgorithm::apply( int numberOfAtoms, vector<RealVec>& atomCoor
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
if (_numberOfConstraints == 0) if (_numberOfConstraints == 0)
return SimTKOpenMMCommon::DefaultReturn; return;
if( !_hasInitialized ) if (!_hasInitialized)
initialize(numberOfAtoms, inverseMasses); initialize(numberOfAtoms, inverseMasses);
// Calculate the direction of each constraint, along with the initial RHS and solution vectors. // Calculate the direction of each constraint, along with the initial RHS and solution vectors.
...@@ -288,9 +283,6 @@ int ReferenceLincsAlgorithm::apply( int numberOfAtoms, vector<RealVec>& atomCoor ...@@ -288,9 +283,6 @@ int ReferenceLincsAlgorithm::apply( int numberOfAtoms, vector<RealVec>& atomCoor
} }
solveMatrix(); solveMatrix();
updateAtomPositions(numberOfAtoms, atomCoordinatesP, inverseMasses); updateAtomPositions(numberOfAtoms, atomCoordinatesP, inverseMasses);
return SimTKOpenMMCommon::DefaultReturn;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -302,12 +294,9 @@ int ReferenceLincsAlgorithm::apply( int numberOfAtoms, vector<RealVec>& atomCoor ...@@ -302,12 +294,9 @@ int ReferenceLincsAlgorithm::apply( int numberOfAtoms, vector<RealVec>& atomCoor
@param velocities atom velocities @param velocities atom velocities
@param inverseMasses 1/mass @param inverseMasses 1/mass
@return SimTKOpenMMCommon::DefaultReturn if converge; else
return SimTKOpenMMCommon::ErrorReturn
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int ReferenceLincsAlgorithm::applyToVelocities(int numberOfAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, void ReferenceLincsAlgorithm::applyToVelocities(int numberOfAtoms, std::vector<OpenMM::RealVec>& atomCoordinates,
std::vector<OpenMM::RealVec>& velocities, std::vector<RealOpenMM>& inverseMasses) { std::vector<OpenMM::RealVec>& velocities, std::vector<RealOpenMM>& inverseMasses) {
throw OpenMM::OpenMMException("applyToVelocities is not implemented"); throw OpenMM::OpenMMException("applyToVelocities is not implemented");
} }
...@@ -49,7 +49,7 @@ ReferenceMonteCarloBarostat::ReferenceMonteCarloBarostat(int numAtoms, const vec ...@@ -49,7 +49,7 @@ ReferenceMonteCarloBarostat::ReferenceMonteCarloBarostat(int numAtoms, const vec
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceMonteCarloBarostat::~ReferenceMonteCarloBarostat( ) { ReferenceMonteCarloBarostat::~ReferenceMonteCarloBarostat() {
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
......
...@@ -45,12 +45,12 @@ void OPENMM_EXPORT computeNeighborListNaive( ...@@ -45,12 +45,12 @@ void OPENMM_EXPORT computeNeighborListNaive(
for (AtomIndex atomJ = atomI + 1; atomJ < (AtomIndex) nAtoms; ++atomJ) for (AtomIndex atomJ = atomI + 1; atomJ < (AtomIndex) nAtoms; ++atomJ)
{ {
double pairDistanceSquared = compPairDistanceSquared(atomLocations[atomI], atomLocations[atomJ], periodicBoxVectors, usePeriodic); double pairDistanceSquared = compPairDistanceSquared(atomLocations[atomI], atomLocations[atomJ], periodicBoxVectors, usePeriodic);
if ( (pairDistanceSquared <= maxDistanceSquared) && (pairDistanceSquared >= minDistanceSquared)) if ((pairDistanceSquared <= maxDistanceSquared) && (pairDistanceSquared >= minDistanceSquared))
if (exclusions[atomI].find(atomJ) == exclusions[atomI].end()) if (exclusions[atomI].find(atomJ) == exclusions[atomI].end())
{ {
neighborList.push_back( AtomPair(atomI, atomJ) ); neighborList.push_back(AtomPair(atomI, atomJ));
if (reportSymmetricPairs) if (reportSymmetricPairs)
neighborList.push_back( AtomPair(atomI, atomJ) ); neighborList.push_back(AtomPair(atomI, atomJ));
} }
} }
} }
...@@ -199,9 +199,9 @@ public: ...@@ -199,9 +199,9 @@ public:
// Ignore exclusions. // Ignore exclusions.
if (exclusions[atomI].find(atomJ) != exclusions[atomI].end()) continue; if (exclusions[atomI].find(atomJ) != exclusions[atomI].end()) continue;
neighbors.push_back( AtomPair(atomI, atomJ) ); neighbors.push_back(AtomPair(atomI, atomJ));
if (reportSymmetricPairs) if (reportSymmetricPairs)
neighbors.push_back( AtomPair(atomJ, atomI) ); neighbors.push_back(AtomPair(atomJ, atomI));
} }
} }
} }
......
...@@ -25,19 +25,19 @@ ...@@ -25,19 +25,19 @@
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
#include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h"
#include "SimTKOpenMMUtilities.h" #include "SimTKOpenMMUtilities.h"
#include "ReferenceForce.h" #include "ReferenceForce.h"
#include "ReferencePairIxn.h" #include "ReferencePairIxn.h"
using namespace OpenMM;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
ReferencePairIxn constructor ReferencePairIxn constructor
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferencePairIxn::ReferencePairIxn( ){ ReferencePairIxn::ReferencePairIxn() {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -53,7 +53,7 @@ ReferencePairIxn::ReferencePairIxn( ){ ...@@ -53,7 +53,7 @@ ReferencePairIxn::ReferencePairIxn( ){
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferencePairIxn::~ReferencePairIxn( ){ ReferencePairIxn::~ReferencePairIxn() {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
......
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