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 @@
#include <string.h>
#include <sstream>
#include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h"
#include "SimTKOpenMMUtilities.h"
#include "ReferenceLJCoulomb14.h"
#include "ReferenceForce.h"
using std::vector;
using OpenMM::RealVec;
using namespace OpenMM;
/**---------------------------------------------------------------------------------------
......@@ -40,7 +38,7 @@ using OpenMM::RealVec;
--------------------------------------------------------------------------------------- */
ReferenceLJCoulomb14::ReferenceLJCoulomb14( ) {
ReferenceLJCoulomb14::ReferenceLJCoulomb14() {
// ---------------------------------------------------------------------------------------
......@@ -56,7 +54,7 @@ ReferenceLJCoulomb14::ReferenceLJCoulomb14( ) {
--------------------------------------------------------------------------------------- */
ReferenceLJCoulomb14::~ReferenceLJCoulomb14( ){
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* totalEnergy ) const {
RealOpenMM* totalEnergy) const {
static const std::string methodName = "\nReferenceLJCoulomb14::calculateBondIxn";
......@@ -113,7 +111,7 @@ void ReferenceLJCoulomb14::calculateBondIxn( int* atomIndices, vector<RealVec>&
int atomAIndex = atomIndices[0];
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 inverseR = one/(deltaR[0][ReferenceForce::RIndex]);
......@@ -121,13 +119,13 @@ void ReferenceLJCoulomb14::calculateBondIxn( int* atomIndices, vector<RealVec>&
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 *= inverseR*inverseR;
// accumulate forces
for( int ii = 0; ii < 3; ii++ ){
for (int ii = 0; ii < 3; ii++) {
RealOpenMM force = dEdR*deltaR[0][ii];
forces[atomAIndex][ii] += force;
forces[atomBIndex][ii] -= force;
......@@ -136,5 +134,5 @@ void ReferenceLJCoulomb14::calculateBondIxn( int* atomIndices, vector<RealVec>&
// accumulate energies
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 @@
#include <complex>
#include <algorithm>
#include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h"
#include "SimTKOpenMMUtilities.h"
#include "ReferenceLJCoulombIxn.h"
#include "ReferenceForce.h"
#include "ReferencePME.h"
#include "openmm/OpenMMException.h"
// In case we're using some primitive version of Visual Studio this will
// make sure that erf() and erfc() are defined.
......@@ -40,7 +39,7 @@
using std::set;
using std::vector;
using OpenMM::RealVec;
using namespace OpenMM;
/**---------------------------------------------------------------------------------------
......@@ -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
--------------------------------------------------------------------------------------- */
ReferenceLJCoulombIxn::~ReferenceLJCoulombIxn( ){
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;
cutoffDistance = distance;
......@@ -101,7 +100,7 @@ ReferenceLJCoulombIxn::~ReferenceLJCoulombIxn( ){
--------------------------------------------------------------------------------------- */
void ReferenceLJCoulombIxn::setUseSwitchingFunction( RealOpenMM distance ) {
void ReferenceLJCoulombIxn::setUseSwitchingFunction(RealOpenMM distance) {
useSwitch = true;
switchingDistance = distance;
}
......@@ -210,16 +209,16 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
// **************************************************************************************
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);
totalSelfEwaldEnergy -= selfEwaldEnergy;
if( energyByAtom ){
if (energyByAtom) {
energyByAtom[atomID] -= selfEwaldEnergy;
}
}
}
if( totalEnergy ){
if (totalEnergy) {
*totalEnergy += totalSelfEwaldEnergy;
}
......@@ -238,11 +237,11 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
charges[i] = atomParameters[i][QIndex];
pme_exec(pmedata,atomCoordinates,forces,charges,periodicBoxVectors,&recipEnergy);
if( totalEnergy )
if (totalEnergy)
*totalEnergy += recipEnergy;
if( energyByAtom )
for(int n = 0; n < numberOfAtoms; n++)
if (energyByAtom)
for (int n = 0; n < numberOfAtoms; n++)
energyByAtom[n] += recipEnergy;
pme_destroy(pmedata);
......@@ -264,22 +263,19 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
vector<d_complex> tab_xy(numberOfAtoms);
vector<d_complex> tab_qxyz(numberOfAtoms);
if (kmax < 1) {
std::stringstream message;
message << " kmax < 1 , Aborting" << std::endl;
SimTKOpenMMLog::printError( message );
}
if (kmax < 1)
throw OpenMMException("kmax for Ewald summation < 1");
for(int i = 0; (i < numberOfAtoms); i++) {
for(int m = 0; (m < 3); m++)
for (int i = 0; (i < numberOfAtoms); i++) {
for (int m = 0; (m < 3); m++)
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]),
sin(atomCoordinates[i][m]*recipBoxSize[m]));
for(int j=2; (j<kmax); j++)
for(int m=0; (m<3); m++)
for (int j=2; (j<kmax); j++)
for (int m=0; (m<3); 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>
int lowry = 0;
int lowrz = 1;
for(int rx = 0; rx < numRx; rx++) {
for (int rx = 0; rx < numRx; rx++) {
RealOpenMM kx = rx * recipBoxSize[0];
for(int ry = lowry; ry < numRy; ry++) {
for (int ry = lowry; ry < numRy; ry++) {
RealOpenMM ky = ry * recipBoxSize[1];
if(ry >= 0) {
for(int n = 0; n < numberOfAtoms; n++)
if (ry >= 0) {
for (int n = 0; n < numberOfAtoms; n++)
tab_xy[n] = EIR(rx, n, 0) * EIR(ry, n, 1);
}
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));
}
for (int rz = lowrz; rz < numRz; rz++) {
if( rz >= 0) {
for( int n = 0; n < numberOfAtoms; n++)
if (rz >= 0) {
for (int n = 0; n < numberOfAtoms; n++)
tab_qxyz[n] = atomParameters[n][QIndex] * (tab_xy[n] * EIR(rz, n, 2));
}
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)));
}
RealOpenMM cs = 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();
ss += tab_qxyz[n].imag();
}
......@@ -330,21 +326,21 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
RealOpenMM k2 = kx * kx + ky * ky + kz * kz;
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());
forces[n][0] += 2 * recipCoeff * force * kx ;
forces[n][1] += 2 * recipCoeff * force * ky ;
forces[n][2] += 2 * recipCoeff * force * kz ;
}
recipEnergy = recipCoeff * ak * ( cs * cs + ss * ss);
recipEnergy = recipCoeff * ak * (cs * cs + ss * ss);
totalRecipEnergy += recipEnergy;
if( totalEnergy )
if (totalEnergy)
*totalEnergy += recipEnergy;
if( energyByAtom )
for(int n = 0; n < numberOfAtoms; n++)
if (energyByAtom)
for (int n = 0; n < numberOfAtoms; n++)
energyByAtom[n] += recipEnergy;
lowrz = 1 - numRz;
......@@ -369,7 +365,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
int jj = pair.second;
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 inverseR = one/(deltaR[0][ReferenceForce::RIndex]);
RealOpenMM switchValue = 1, switchDeriv = 0;
......@@ -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);
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 sig2 = inverseR*sig;
sig2 *= sig2;
RealOpenMM sig6 = sig2*sig2*sig2;
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;
if (useSwitch) {
dEdR -= vdwEnergy*switchDeriv*inverseR;
......@@ -398,7 +394,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
// accumulate forces
for( int kk = 0; kk < 3; kk++ ){
for (int kk = 0; kk < 3; kk++) {
RealOpenMM force = dEdR*deltaR[0][kk];
forces[ii][kk] += force;
forces[jj][kk] -= force;
......@@ -411,14 +407,14 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
totalVdwEnergy += vdwEnergy;
totalRealSpaceEwaldEnergy += realSpaceEwaldEnergy;
if( energyByAtom ){
if (energyByAtom) {
energyByAtom[ii] += realSpaceEwaldEnergy + vdwEnergy;
energyByAtom[jj] += realSpaceEwaldEnergy + vdwEnergy;
}
}
if( totalEnergy )
if (totalEnergy)
*totalEnergy += totalRealSpaceEwaldEnergy + totalVdwEnergy;
// 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>
int jj = *iter;
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 inverseR = one/(deltaR[0][ReferenceForce::RIndex]);
RealOpenMM alphaR = alphaEwald * r;
if (erf(alphaR) > 1e-6) {
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
for( int kk = 0; kk < 3; kk++ ){
for (int kk = 0; kk < 3; kk++) {
RealOpenMM force = dEdR*deltaR[0][kk];
forces[ii][kk] -= force;
forces[jj][kk] += force;
......@@ -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));
totalExclusionEnergy += realSpaceEwaldEnergy;
if( energyByAtom ){
if (energyByAtom) {
energyByAtom[ii] -= realSpaceEwaldEnergy;
energyByAtom[jj] -= realSpaceEwaldEnergy;
}
......@@ -460,7 +456,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
}
}
if( totalEnergy )
if (totalEnergy)
*totalEnergy -= totalExclusionEnergy;
}
......@@ -502,10 +498,10 @@ void ReferenceLJCoulombIxn::calculatePairIxn(int numberOfAtoms, vector<RealVec>&
}
}
else {
for( int ii = 0; ii < numberOfAtoms; ii++ ){
for (int ii = 0; ii < numberOfAtoms; ii++) {
// 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())
calculateOneIxn(ii, jj, atomCoordinates, atomParameters, forces, energyByAtom, totalEnergy);
}
......@@ -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* energyByAtom, RealOpenMM* totalEnergy ) const {
RealOpenMM* energyByAtom, RealOpenMM* totalEnergy) const {
// ---------------------------------------------------------------------------------------
......@@ -555,9 +551,9 @@ void ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, vector<RealVec>& at
// get deltaR, R2, and R between 2 atoms
if (periodic)
ReferenceForce::getDeltaRPeriodic( atomCoordinates[jj], atomCoordinates[ii], periodicBoxVectors, deltaR[0] );
ReferenceForce::getDeltaRPeriodic(atomCoordinates[jj], atomCoordinates[ii], periodicBoxVectors, deltaR[0]);
else
ReferenceForce::getDeltaR( atomCoordinates[jj], atomCoordinates[ii], deltaR[0] );
ReferenceForce::getDeltaR(atomCoordinates[jj], atomCoordinates[ii], deltaR[0]);
RealOpenMM r2 = deltaR[0][ReferenceForce::R2Index];
RealOpenMM inverseR = one/(deltaR[0][ReferenceForce::RIndex]);
......@@ -576,7 +572,7 @@ void ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, vector<RealVec>& at
RealOpenMM sig6 = sig2*sig2*sig2;
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)
dEdR += (RealOpenMM) (ONE_4PI_EPS0*atomParameters[ii][QIndex]*atomParameters[jj][QIndex]*(inverseR-2.0f*krf*r2));
else
......@@ -594,7 +590,7 @@ void ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, vector<RealVec>& at
// accumulate forces
for( int kk = 0; kk < 3; kk++ ){
for (int kk = 0; kk < 3; kk++) {
RealOpenMM force = dEdR*deltaR[0][kk];
forces[ii][kk] += force;
forces[jj][kk] -= force;
......@@ -602,9 +598,9 @@ void ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, vector<RealVec>& at
// accumulate energies
if( totalEnergy )
if (totalEnergy)
*totalEnergy += energy;
if( energyByAtom ){
if (energyByAtom) {
energyByAtom[ii] += energy;
energyByAtom[jj] += energy;
}
......
......@@ -24,15 +24,13 @@
#include <string.h>
#include <sstream>
#include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMUtilities.h"
#include "SimTKOpenMMLog.h"
#include "ReferenceLincsAlgorithm.h"
#include "ReferenceDynamics.h"
#include "openmm/OpenMMException.h"
using std::vector;
using OpenMM::RealVec;
using namespace OpenMM;
/**---------------------------------------------------------------------------------------
......@@ -44,9 +42,9 @@ using OpenMM::RealVec;
--------------------------------------------------------------------------------------- */
ReferenceLincsAlgorithm::ReferenceLincsAlgorithm( int numberOfConstraints,
int** atomIndices,
RealOpenMM* distance ){
ReferenceLincsAlgorithm::ReferenceLincsAlgorithm(int numberOfConstraints,
int** atomIndices,
RealOpenMM* distance) {
// ---------------------------------------------------------------------------------------
......@@ -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 {
--------------------------------------------------------------------------------------- */
int ReferenceLincsAlgorithm::getNumTerms( void ) const {
int ReferenceLincsAlgorithm::getNumTerms() 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
@param atomCoordinatesP atom coordinates prime
@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<RealOpenMM>& inverseMasses ){
vector<RealOpenMM>& inverseMasses) {
// ---------------------------------------------------------------------------------------
......@@ -234,9 +229,9 @@ int ReferenceLincsAlgorithm::apply( int numberOfAtoms, vector<RealVec>& atomCoor
// ---------------------------------------------------------------------------------------
if (_numberOfConstraints == 0)
return SimTKOpenMMCommon::DefaultReturn;
return;
if( !_hasInitialized )
if (!_hasInitialized)
initialize(numberOfAtoms, inverseMasses);
// 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
}
solveMatrix();
updateAtomPositions(numberOfAtoms, atomCoordinatesP, inverseMasses);
return SimTKOpenMMCommon::DefaultReturn;
}
/**---------------------------------------------------------------------------------------
......@@ -302,12 +294,9 @@ int ReferenceLincsAlgorithm::apply( int numberOfAtoms, vector<RealVec>& atomCoor
@param velocities atom velocities
@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) {
throw OpenMM::OpenMMException("applyToVelocities is not implemented");
}
......@@ -49,7 +49,7 @@ ReferenceMonteCarloBarostat::ReferenceMonteCarloBarostat(int numAtoms, const vec
--------------------------------------------------------------------------------------- */
ReferenceMonteCarloBarostat::~ReferenceMonteCarloBarostat( ) {
ReferenceMonteCarloBarostat::~ReferenceMonteCarloBarostat() {
}
/**---------------------------------------------------------------------------------------
......
......@@ -45,12 +45,12 @@ void OPENMM_EXPORT computeNeighborListNaive(
for (AtomIndex atomJ = atomI + 1; atomJ < (AtomIndex) nAtoms; ++atomJ)
{
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())
{
neighborList.push_back( AtomPair(atomI, atomJ) );
neighborList.push_back(AtomPair(atomI, atomJ));
if (reportSymmetricPairs)
neighborList.push_back( AtomPair(atomI, atomJ) );
neighborList.push_back(AtomPair(atomI, atomJ));
}
}
}
......@@ -199,9 +199,9 @@ public:
// Ignore exclusions.
if (exclusions[atomI].find(atomJ) != exclusions[atomI].end()) continue;
neighbors.push_back( AtomPair(atomI, atomJ) );
neighbors.push_back(AtomPair(atomI, atomJ));
if (reportSymmetricPairs)
neighbors.push_back( AtomPair(atomJ, atomI) );
neighbors.push_back(AtomPair(atomJ, atomI));
}
}
}
......@@ -228,7 +228,7 @@ void OPENMM_EXPORT computeNeighborListVoxelHash(
double maxDistance,
double minDistance,
bool reportSymmetricPairs
)
)
{
neighborList.clear();
......@@ -245,7 +245,7 @@ void OPENMM_EXPORT computeNeighborListVoxelHash(
{
// 1) Find other atoms that are close to this one
const RealVec& location = atomLocations[atomJ];
voxelHash.getNeighbors(
voxelHash.getNeighbors(
neighborList,
VoxelItem(&location, atomJ),
exclusions,
......
......@@ -28,32 +28,31 @@
#include <cmath>
#include <cstdio>
#include "SimTKOpenMMCommon.h"
#include "ReferenceForce.h"
#include "CpuObc.h"
#include "ReferenceObc.h"
using namespace OpenMM;
using namespace std;
/**---------------------------------------------------------------------------------------
CpuObc constructor
ReferenceObc constructor
obcParameters obcParameters object
--------------------------------------------------------------------------------------- */
CpuObc::CpuObc( ObcParameters* obcParameters ) : _obcParameters(obcParameters), _includeAceApproximation(1) {
ReferenceObc::ReferenceObc(ObcParameters* obcParameters) : _obcParameters(obcParameters), _includeAceApproximation(1) {
_obcChain.resize(_obcParameters->getNumberOfAtoms());
}
/**---------------------------------------------------------------------------------------
CpuObc destructor
ReferenceObc destructor
--------------------------------------------------------------------------------------- */
CpuObc::~CpuObc( ){
ReferenceObc::~ReferenceObc() {
}
/**---------------------------------------------------------------------------------------
......@@ -64,7 +63,7 @@ CpuObc::~CpuObc( ){
--------------------------------------------------------------------------------------- */
ObcParameters* CpuObc::getObcParameters( void ) const {
ObcParameters* ReferenceObc::getObcParameters() const {
return _obcParameters;
}
......@@ -76,7 +75,7 @@ ObcParameters* CpuObc::getObcParameters( void ) const {
--------------------------------------------------------------------------------------- */
void CpuObc::setObcParameters( ObcParameters* obcParameters ){
void ReferenceObc::setObcParameters( ObcParameters* obcParameters) {
_obcParameters = obcParameters;
}
......@@ -88,7 +87,7 @@ void CpuObc::setObcParameters( ObcParameters* obcParameters ){
--------------------------------------------------------------------------------------- */
int CpuObc::includeAceApproximation( void ) const {
int ReferenceObc::includeAceApproximation() const {
return _includeAceApproximation;
}
......@@ -100,7 +99,7 @@ int CpuObc::includeAceApproximation( void ) const {
--------------------------------------------------------------------------------------- */
void CpuObc::setIncludeAceApproximation( int includeAceApproximation ){
void ReferenceObc::setIncludeAceApproximation(int includeAceApproximation) {
_includeAceApproximation = includeAceApproximation;
}
......@@ -112,7 +111,7 @@ void CpuObc::setIncludeAceApproximation( int includeAceApproximation ){
--------------------------------------------------------------------------------------- */
vector<RealOpenMM>& CpuObc::getObcChain( void ){
vector<RealOpenMM>& ReferenceObc::getObcChain() {
return _obcChain;
}
......@@ -128,25 +127,25 @@ vector<RealOpenMM>& CpuObc::getObcChain( void ){
--------------------------------------------------------------------------------------- */
void CpuObc::computeBornRadii( const vector<RealVec>& atomCoordinates, vector<RealOpenMM>& bornRadii ){
void ReferenceObc::computeBornRadii(const vector<RealVec>& atomCoordinates, vector<RealOpenMM>& bornRadii) {
// ---------------------------------------------------------------------------------------
static const RealOpenMM zero = static_cast<RealOpenMM>( 0.0 );
static const RealOpenMM one = static_cast<RealOpenMM>( 1.0 );
static const RealOpenMM two = static_cast<RealOpenMM>( 2.0 );
static const RealOpenMM three = static_cast<RealOpenMM>( 3.0 );
static const RealOpenMM half = static_cast<RealOpenMM>( 0.5 );
static const RealOpenMM fourth = static_cast<RealOpenMM>( 0.25 );
static const RealOpenMM zero = static_cast<RealOpenMM>(0.0);
static const RealOpenMM one = static_cast<RealOpenMM>(1.0);
static const RealOpenMM two = static_cast<RealOpenMM>(2.0);
static const RealOpenMM three = static_cast<RealOpenMM>(3.0);
static const RealOpenMM half = static_cast<RealOpenMM>(0.5);
static const RealOpenMM fourth = static_cast<RealOpenMM>(0.25);
// ---------------------------------------------------------------------------------------
ObcParameters* obcParameters = getObcParameters();
int numberOfAtoms = obcParameters->getNumberOfAtoms();
const RealOpenMMVector& atomicRadii = obcParameters->getAtomicRadii();
const RealOpenMMVector& scaledRadiusFactor = obcParameters->getScaledRadiusFactors();
RealOpenMMVector& obcChain = getObcChain();
const vector<RealOpenMM>& atomicRadii = obcParameters->getAtomicRadii();
const vector<RealOpenMM>& scaledRadiusFactor = obcParameters->getScaledRadiusFactors();
vector<RealOpenMM>& obcChain = getObcChain();
RealOpenMM dielectricOffset = obcParameters->getDielectricOffset();
RealOpenMM alphaObc = obcParameters->getAlphaObc();
......@@ -157,7 +156,7 @@ void CpuObc::computeBornRadii( const vector<RealVec>& atomCoordinates, vector<Re
// calculate Born radii
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
for (int atomI = 0; atomI < numberOfAtoms; atomI++) {
RealOpenMM radiusI = atomicRadii[atomI];
RealOpenMM offsetRadiusI = radiusI - dielectricOffset;
......@@ -167,15 +166,15 @@ void CpuObc::computeBornRadii( const vector<RealVec>& atomCoordinates, vector<Re
// HCT code
for( int atomJ = 0; atomJ < numberOfAtoms; atomJ++ ){
for (int atomJ = 0; atomJ < numberOfAtoms; atomJ++) {
if( atomJ != atomI ){
if (atomJ != atomI) {
RealOpenMM deltaR[ReferenceForce::LastDeltaRIndex];
if (_obcParameters->getPeriodic())
ReferenceForce::getDeltaRPeriodic( atomCoordinates[atomI], atomCoordinates[atomJ], _obcParameters->getPeriodicBox(), deltaR );
ReferenceForce::getDeltaRPeriodic(atomCoordinates[atomI], atomCoordinates[atomJ], _obcParameters->getPeriodicBox(), deltaR);
else
ReferenceForce::getDeltaR( atomCoordinates[atomI], atomCoordinates[atomJ], deltaR );
ReferenceForce::getDeltaR(atomCoordinates[atomI], atomCoordinates[atomJ], deltaR);
RealOpenMM r = deltaR[ReferenceForce::RIndex];
if (_obcParameters->getUseCutoff() && r > _obcParameters->getCutoffDistance())
continue;
......@@ -184,9 +183,9 @@ void CpuObc::computeBornRadii( const vector<RealVec>& atomCoordinates, vector<Re
RealOpenMM scaledRadiusJ = offsetRadiusJ*scaledRadiusFactor[atomJ];
RealOpenMM rScaledRadiusJ = r + scaledRadiusJ;
if( offsetRadiusI < rScaledRadiusJ ){
if (offsetRadiusI < rScaledRadiusJ) {
RealOpenMM rInverse = one/r;
RealOpenMM l_ij = offsetRadiusI > FABS( r - scaledRadiusJ ) ? offsetRadiusI : FABS( r - scaledRadiusJ );
RealOpenMM l_ij = offsetRadiusI > FABS(r - scaledRadiusJ) ? offsetRadiusI : FABS(r - scaledRadiusJ);
l_ij = one/l_ij;
RealOpenMM u_ij = one/rScaledRadiusJ;
......@@ -194,15 +193,15 @@ void CpuObc::computeBornRadii( const vector<RealVec>& atomCoordinates, vector<Re
RealOpenMM l_ij2 = l_ij*l_ij;
RealOpenMM u_ij2 = u_ij*u_ij;
RealOpenMM ratio = LN( (u_ij/l_ij) );
RealOpenMM term = l_ij - u_ij + fourth*r*(u_ij2 - l_ij2) + ( half*rInverse*ratio) + (fourth*scaledRadiusJ*scaledRadiusJ*rInverse)*(l_ij2 - u_ij2);
RealOpenMM ratio = LN((u_ij/l_ij));
RealOpenMM term = l_ij - u_ij + fourth*r*(u_ij2 - l_ij2) + (half*rInverse*ratio) + (fourth*scaledRadiusJ*scaledRadiusJ*rInverse)*(l_ij2 - u_ij2);
// this case (atom i completely inside atom j) is not considered in the original paper
// Jay Ponder and the authors of Tinker recognized this and
// worked out the details
if( offsetRadiusI < (scaledRadiusJ - r) ){
term += two*( radiusIInverse - l_ij);
if (offsetRadiusI < (scaledRadiusJ - r)) {
term += two*(radiusIInverse - l_ij);
}
sum += term;
......@@ -215,11 +214,11 @@ void CpuObc::computeBornRadii( const vector<RealVec>& atomCoordinates, vector<Re
sum *= half*offsetRadiusI;
RealOpenMM sum2 = sum*sum;
RealOpenMM sum3 = sum*sum2;
RealOpenMM tanhSum = TANH( alphaObc*sum - betaObc*sum2 + gammaObc*sum3 );
RealOpenMM tanhSum = TANH(alphaObc*sum - betaObc*sum2 + gammaObc*sum3);
bornRadii[atomI] = one/( one/offsetRadiusI - tanhSum/radiusI );
bornRadii[atomI] = one/(one/offsetRadiusI - tanhSum/radiusI);
obcChain[atomI] = offsetRadiusI*( alphaObc - two*betaObc*sum + three*gammaObc*sum2 );
obcChain[atomI] = offsetRadiusI*(alphaObc - two*betaObc*sum + three*gammaObc*sum2);
obcChain[atomI] = (one - tanhSum*tanhSum)*obcChain[atomI]/radiusI;
}
......@@ -236,16 +235,16 @@ void CpuObc::computeBornRadii( const vector<RealVec>& atomCoordinates, vector<Re
--------------------------------------------------------------------------------------- */
void CpuObc::computeAceNonPolarForce( const ObcParameters* obcParameters,
const RealOpenMMVector& bornRadii,
void ReferenceObc::computeAceNonPolarForce(const ObcParameters* obcParameters,
const vector<RealOpenMM>& bornRadii,
RealOpenMM* energy,
RealOpenMMVector& forces ) const {
vector<RealOpenMM>& forces) const {
// ---------------------------------------------------------------------------------------
static const RealOpenMM zero = static_cast<RealOpenMM>( 0.0 );
static const RealOpenMM zero = static_cast<RealOpenMM>(0.0);
static const RealOpenMM minusSix = -6.0;
static const RealOpenMM six = static_cast<RealOpenMM>( 6.0 );
static const RealOpenMM six = static_cast<RealOpenMM>(6.0);
// ---------------------------------------------------------------------------------------
......@@ -254,7 +253,7 @@ void CpuObc::computeAceNonPolarForce( const ObcParameters* obcParameters,
const RealOpenMM probeRadius = obcParameters->getProbeRadius();
const RealOpenMM surfaceAreaFactor = obcParameters->getPi4Asolv();
const RealOpenMMVector& atomicRadii = obcParameters->getAtomicRadii();
const vector<RealOpenMM>& atomicRadii = obcParameters->getAtomicRadii();
int numberOfAtoms = obcParameters->getNumberOfAtoms();
// the original ACE equation is based on Eq.2 of
......@@ -271,10 +270,10 @@ void CpuObc::computeAceNonPolarForce( const ObcParameters* obcParameters,
// observed values. He did not think it was important enough to write up, so there is
// no paper to cite.
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
if( bornRadii[atomI] > zero ){
for (int atomI = 0; atomI < numberOfAtoms; atomI++) {
if (bornRadii[atomI] > zero) {
RealOpenMM r = atomicRadii[atomI] + probeRadius;
RealOpenMM ratio6 = POW( atomicRadii[atomI]/bornRadii[atomI], six );
RealOpenMM ratio6 = POW(atomicRadii[atomI]/bornRadii[atomI], six);
RealOpenMM saTerm = surfaceAreaFactor*r*r*ratio6;
*energy += saTerm;
forces[atomI] += minusSix*saTerm/bornRadii[atomI];
......@@ -294,19 +293,19 @@ void CpuObc::computeAceNonPolarForce( const ObcParameters* obcParameters,
--------------------------------------------------------------------------------------- */
RealOpenMM CpuObc::computeBornEnergyForces( const vector<RealVec>& atomCoordinates,
const RealOpenMMVector& partialCharges, vector<RealVec>& inputForces ){
RealOpenMM ReferenceObc::computeBornEnergyForces(const vector<RealVec>& atomCoordinates,
const vector<RealOpenMM>& partialCharges, vector<RealVec>& inputForces) {
// ---------------------------------------------------------------------------------------
static const RealOpenMM zero = static_cast<RealOpenMM>( 0.0 );
static const RealOpenMM one = static_cast<RealOpenMM>( 1.0 );
static const RealOpenMM two = static_cast<RealOpenMM>( 2.0 );
static const RealOpenMM three = static_cast<RealOpenMM>( 3.0 );
static const RealOpenMM four = static_cast<RealOpenMM>( 4.0 );
static const RealOpenMM half = static_cast<RealOpenMM>( 0.5 );
static const RealOpenMM fourth = static_cast<RealOpenMM>( 0.25 );
static const RealOpenMM eighth = static_cast<RealOpenMM>( 0.125 );
static const RealOpenMM zero = static_cast<RealOpenMM>(0.0);
static const RealOpenMM one = static_cast<RealOpenMM>(1.0);
static const RealOpenMM two = static_cast<RealOpenMM>(2.0);
static const RealOpenMM three = static_cast<RealOpenMM>(3.0);
static const RealOpenMM four = static_cast<RealOpenMM>(4.0);
static const RealOpenMM half = static_cast<RealOpenMM>(0.5);
static const RealOpenMM fourth = static_cast<RealOpenMM>(0.25);
static const RealOpenMM eighth = static_cast<RealOpenMM>(0.125);
// constants
......@@ -325,36 +324,36 @@ RealOpenMM CpuObc::computeBornEnergyForces( const vector<RealVec>& atomCoordinat
// compute Born radii
RealOpenMMVector bornRadii( numberOfAtoms );
computeBornRadii( atomCoordinates, bornRadii );
vector<RealOpenMM> bornRadii(numberOfAtoms);
computeBornRadii(atomCoordinates, bornRadii);
// set energy/forces to zero
RealOpenMM obcEnergy = zero;
RealOpenMMVector bornForces( numberOfAtoms, 0.0 );
vector<RealOpenMM> bornForces(numberOfAtoms, 0.0);
// ---------------------------------------------------------------------------------------
// compute the nonpolar solvation via ACE approximation
if( includeAceApproximation() ){
computeAceNonPolarForce( _obcParameters, bornRadii, &obcEnergy, bornForces );
if (includeAceApproximation()) {
computeAceNonPolarForce(_obcParameters, bornRadii, &obcEnergy, bornForces);
}
// ---------------------------------------------------------------------------------------
// first main loop
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
for (int atomI = 0; atomI < numberOfAtoms; atomI++) {
RealOpenMM partialChargeI = preFactor*partialCharges[atomI];
for( int atomJ = atomI; atomJ < numberOfAtoms; atomJ++ ){
for (int atomJ = atomI; atomJ < numberOfAtoms; atomJ++) {
RealOpenMM deltaR[ReferenceForce::LastDeltaRIndex];
if (_obcParameters->getPeriodic())
ReferenceForce::getDeltaRPeriodic( atomCoordinates[atomI], atomCoordinates[atomJ], _obcParameters->getPeriodicBox(), deltaR );
ReferenceForce::getDeltaRPeriodic(atomCoordinates[atomI], atomCoordinates[atomJ], _obcParameters->getPeriodicBox(), deltaR);
else
ReferenceForce::getDeltaR( atomCoordinates[atomI], atomCoordinates[atomJ], deltaR );
ReferenceForce::getDeltaR(atomCoordinates[atomI], atomCoordinates[atomJ], deltaR);
if (_obcParameters->getUseCutoff() && deltaR[ReferenceForce::RIndex] > cutoffDistance)
continue;
......@@ -366,18 +365,18 @@ RealOpenMM CpuObc::computeBornEnergyForces( const vector<RealVec>& atomCoordinat
RealOpenMM alpha2_ij = bornRadii[atomI]*bornRadii[atomJ];
RealOpenMM D_ij = r2/(four*alpha2_ij);
RealOpenMM expTerm = EXP( -D_ij );
RealOpenMM expTerm = EXP(-D_ij);
RealOpenMM denominator2 = r2 + alpha2_ij*expTerm;
RealOpenMM denominator = SQRT( denominator2 );
RealOpenMM denominator = SQRT(denominator2);
RealOpenMM Gpol = (partialChargeI*partialCharges[atomJ])/denominator;
RealOpenMM dGpol_dr = -Gpol*( one - fourth*expTerm )/denominator2;
RealOpenMM dGpol_dr = -Gpol*(one - fourth*expTerm)/denominator2;
RealOpenMM dGpol_dalpha2_ij = -half*Gpol*expTerm*( one + D_ij )/denominator2;
RealOpenMM dGpol_dalpha2_ij = -half*Gpol*expTerm*(one + D_ij)/denominator2;
RealOpenMM energy = Gpol;
if( atomI != atomJ ){
if (atomI != atomJ) {
if (_obcParameters->getUseCutoff())
energy -= partialChargeI*partialCharges[atomJ]/cutoffDistance;
......@@ -410,36 +409,36 @@ RealOpenMM CpuObc::computeBornEnergyForces( const vector<RealVec>& atomCoordinat
// second main loop
const RealOpenMMVector& obcChain = getObcChain();
const RealOpenMMVector& atomicRadii = _obcParameters->getAtomicRadii();
const vector<RealOpenMM>& obcChain = getObcChain();
const vector<RealOpenMM>& atomicRadii = _obcParameters->getAtomicRadii();
const RealOpenMM alphaObc = _obcParameters->getAlphaObc();
const RealOpenMM betaObc = _obcParameters->getBetaObc();
const RealOpenMM gammaObc = _obcParameters->getGammaObc();
const RealOpenMMVector& scaledRadiusFactor = _obcParameters->getScaledRadiusFactors();
const vector<RealOpenMM>& scaledRadiusFactor = _obcParameters->getScaledRadiusFactors();
// compute factor that depends only on the outer loop index
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
for (int atomI = 0; atomI < numberOfAtoms; atomI++) {
bornForces[atomI] *= bornRadii[atomI]*bornRadii[atomI]*obcChain[atomI];
}
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
for (int atomI = 0; atomI < numberOfAtoms; atomI++) {
// radius w/ dielectric offset applied
RealOpenMM radiusI = atomicRadii[atomI];
RealOpenMM offsetRadiusI = radiusI - dielectricOffset;
for( int atomJ = 0; atomJ < numberOfAtoms; atomJ++ ){
for (int atomJ = 0; atomJ < numberOfAtoms; atomJ++) {
if( atomJ != atomI ){
if (atomJ != atomI) {
RealOpenMM deltaR[ReferenceForce::LastDeltaRIndex];
if (_obcParameters->getPeriodic())
ReferenceForce::getDeltaRPeriodic( atomCoordinates[atomI], atomCoordinates[atomJ], _obcParameters->getPeriodicBox(), deltaR );
ReferenceForce::getDeltaRPeriodic(atomCoordinates[atomI], atomCoordinates[atomJ], _obcParameters->getPeriodicBox(), deltaR);
else
ReferenceForce::getDeltaR( atomCoordinates[atomI], atomCoordinates[atomJ], deltaR );
ReferenceForce::getDeltaR(atomCoordinates[atomI], atomCoordinates[atomJ], deltaR);
if (_obcParameters->getUseCutoff() && deltaR[ReferenceForce::RIndex] > cutoffDistance)
continue;
......@@ -459,9 +458,9 @@ RealOpenMM CpuObc::computeBornEnergyForces( const vector<RealVec>& atomCoordinat
// dL/dr & dU/dr are zero (this can be shown analytically)
// removed from calculation
if( offsetRadiusI < rScaledRadiusJ ){
if (offsetRadiusI < rScaledRadiusJ) {
RealOpenMM l_ij = offsetRadiusI > FABS( r - scaledRadiusJ ) ? offsetRadiusI : FABS( r - scaledRadiusJ );
RealOpenMM l_ij = offsetRadiusI > FABS(r - scaledRadiusJ) ? offsetRadiusI : FABS(r - scaledRadiusJ);
l_ij = one/l_ij;
RealOpenMM u_ij = one/rScaledRadiusJ;
......@@ -473,7 +472,7 @@ RealOpenMM CpuObc::computeBornEnergyForces( const vector<RealVec>& atomCoordinat
RealOpenMM rInverse = one/r;
RealOpenMM r2Inverse = rInverse*rInverse;
RealOpenMM t3 = eighth*(one + scaledRadiusJ2*r2Inverse)*(l_ij2 - u_ij2) + fourth*LN( u_ij/l_ij )*r2Inverse;
RealOpenMM t3 = eighth*(one + scaledRadiusJ2*r2Inverse)*(l_ij2 - u_ij2) + fourth*LN(u_ij/l_ij)*r2Inverse;
RealOpenMM de = bornForces[atomI]*t3*rInverse;
......@@ -495,90 +494,5 @@ RealOpenMM CpuObc::computeBornEnergyForces( const vector<RealVec>& atomCoordinat
}
//printObc( atomCoordinates, partialCharges, bornRadii, bornForces, inputForces, "Obc Post loop2", stderr );
return obcEnergy;
}
/**---------------------------------------------------------------------------------------
Print Obc parameters, radii, forces, ...
@param atomCoordinates atomic coordinates
@param partialCharges partial charges
@param bornRadii Born radii (may be empty)
@param bornForces Born forces (may be empty)
@param forces forces (may be empty)
@param idString id string (who is calling)
@param log log file
--------------------------------------------------------------------------------------- */
void CpuObc::printObc( const std::vector<OpenMM::RealVec>& atomCoordinates,
const RealOpenMMVector& partialCharges,
const RealOpenMMVector& bornRadii,
const RealOpenMMVector& bornForces,
const std::vector<OpenMM::RealVec>& forces,
const std::string& idString, FILE* log ){
// ---------------------------------------------------------------------------------------
const ObcParameters* obcParameters = getObcParameters();
const int numberOfAtoms = obcParameters->getNumberOfAtoms();
const RealOpenMMVector& atomicRadii = obcParameters->getAtomicRadii();
const RealOpenMM preFactor = 2.0*obcParameters->getElectricConstant();
const RealOpenMMVector& obcChain = getObcChain();
const RealOpenMMVector& scaledRadiusFactor = obcParameters->getScaledRadiusFactors();
const RealOpenMM alphaObc = obcParameters->getAlphaObc();
const RealOpenMM betaObc = obcParameters->getBetaObc();
const RealOpenMM gammaObc = obcParameters->getGammaObc();
const int comparisonFormat = 1;
// ---------------------------------------------------------------------------------------
(void) fprintf( log, "Reference Obc %s atoms=%d\n", idString.c_str(), numberOfAtoms );
if( comparisonFormat ){
(void) fprintf( log, "Reference Obc %s atoms=%d Chain/Radii/Force\n", idString.c_str(), numberOfAtoms );
for( unsigned int atomI = 0; atomI < static_cast<unsigned int>(numberOfAtoms); atomI++ ){
(void) fprintf( log, "%6d ", atomI );
if( obcChain.size() > atomI ){
(void) fprintf( log, " %15.7e", obcChain[atomI] );
}
if( bornRadii.size() > atomI ){
(void) fprintf( log, " %15.7e", bornRadii[atomI] );
}
if( bornForces.size() > atomI ){
(void) fprintf( log, " %15.7e", bornForces[atomI] );
}
(void) fprintf( log, " %15.7e %6.3f", atomicRadii[atomI], partialCharges[atomI] );
(void) fprintf( log, "\n" );
}
} else {
(void) fprintf( log, "Reference Obc %s atoms=%d\n", idString.c_str(), numberOfAtoms );
(void) fprintf( log, " preFactor %15.7e\n", preFactor );
(void) fprintf( log, " alpha %15.7e\n", alphaObc);
(void) fprintf( log, " beta %15.7e\n", betaObc);
(void) fprintf( log, " gamma %15.7e\n", gammaObc );
for( unsigned int atomI = 0; atomI < static_cast<unsigned int>(numberOfAtoms); atomI++ ){
(void) fprintf( log, "%6d r=%15.7e q=%6.3f", atomI,
atomicRadii[atomI], partialCharges[atomI] );
if( obcChain.size() > atomI ){
(void) fprintf( log, " bChn=%15.7e", obcChain[atomI] );
}
if( bornRadii.size() > atomI ){
(void) fprintf( log, " bR=%15.7e", bornRadii[atomI] );
}
if( bornForces.size() > atomI ){
(void) fprintf( log, " bF=%15.7e", bornForces[atomI] );
}
(void) fprintf( log, "\n" );
}
}
return;
}
......@@ -37,10 +37,10 @@
#include "fftpack.h"
using std::vector;
using OpenMM::RealVec;
typedef int ivec[3];
namespace OpenMM {
struct pme
{
......@@ -77,7 +77,7 @@ struct pme
* If particle i has coordinates { 0.543 , 6.235 , -0.73 }, we will get:
*
* particleindex[i] = { 5 , 62 , 92 } (-0.73 + 10 = 9.27, we always apply PBC for grid calculations!)
* particlefraction[i] = { 0.43 , 0.35 , 0.7 } ( this is the fraction of the cell length where the atom is)
* particlefraction[i] = { 0.43 , 0.35 , 0.7 } (this is the fraction of the cell length where the atom is)
*
* (The reason for precaculating / storing these is that it gets a bit more complex for triclinic cells :-)
*
......@@ -108,7 +108,7 @@ pme_calculate_bsplines_moduli(pme_t pme)
RealOpenMM sc,ss,arg;
nmax = 0;
for(d=0;d<3;d++)
for (d=0;d<3;d++)
{
nmax = (pme->ngrid[d] > nmax) ? pme->ngrid[d] : nmax;
pme->bsplines_moduli[d] = (RealOpenMM *) malloc(sizeof(RealOpenMM)*pme->ngrid[d]);
......@@ -125,11 +125,11 @@ pme_calculate_bsplines_moduli(pme_t pme)
data[1]=0;
data[0]=1;
for(k=3;k<order;k++)
for (k=3;k<order;k++)
{
div=(RealOpenMM) (1.0/(k-1.0));
data[k-1]=0;
for(l=1;l<(k-1);l++)
for (l=1;l<(k-1);l++)
{
data[k-l-1]=div*(l*data[k-l-2]+(k-l)*data[k-l-1]);
}
......@@ -138,7 +138,7 @@ pme_calculate_bsplines_moduli(pme_t pme)
/* differentiate */
ddata[0]=-data[0];
for(k=1;k<order;k++)
for (k=1;k<order;k++)
{
ddata[k]=data[k-1]-data[k];
}
......@@ -146,29 +146,29 @@ pme_calculate_bsplines_moduli(pme_t pme)
div=(RealOpenMM) (1.0/(order-1));
data[order-1]=0;
for(l=1;l<(order-1);l++)
for (l=1;l<(order-1);l++)
{
data[order-l-1]=div*(l*data[order-l-2]+(order-l)*data[order-l-1]);
}
data[0]=div*data[0];
for(i=0;i<nmax;i++)
for (i=0;i<nmax;i++)
{
bsplines_data[i]=0;
}
for(i=1;i<=order;i++)
for (i=1;i<=order;i++)
{
bsplines_data[i]=data[i-1];
}
/* Evaluate the actual bspline moduli for X/Y/Z */
for(d=0;d<3;d++)
for (d=0;d<3;d++)
{
ndata = pme->ngrid[d];
for(i=0;i<ndata;i++)
for (i=0;i<ndata;i++)
{
sc=ss=0;
for(j=0;j<ndata;j++)
for (j=0;j<ndata;j++)
{
arg=(RealOpenMM) ((2.0*M_PI*i*j)/ndata);
sc+=bsplines_data[j]*cos(arg);
......@@ -176,9 +176,9 @@ pme_calculate_bsplines_moduli(pme_t pme)
}
pme->bsplines_moduli[d][i]=sc*sc+ss*ss;
}
for(i=0;i<ndata;i++)
for (i=0;i<ndata;i++)
{
if(pme->bsplines_moduli[d][i]<1.0e-7)
if (pme->bsplines_moduli[d][i]<1.0e-7)
{
pme->bsplines_moduli[d][i]=(pme->bsplines_moduli[d][i-1]+pme->bsplines_moduli[d][i+1])/2;
}
......@@ -213,7 +213,7 @@ pme_update_grid_index_and_fraction(pme_t pme,
RealOpenMM t;
int ti;
for(i=0;i<pme->natoms;i++)
for (i=0;i<pme->natoms;i++)
{
/* Index calculation (Look mom, no conditionals!):
*
......@@ -252,7 +252,7 @@ pme_update_grid_index_and_fraction(pme_t pme,
* (And, by adding 100.0 box lengths, we would lose a bit of numerical accuracy here!)
*/
RealVec coord = atomCoordinates[i];
for(d=0;d<3;d++)
for (d=0;d<3;d++)
{
t = coord[0]*recipBoxVectors[0][d]+coord[1]*recipBoxVectors[1][d]+coord[2]*recipBoxVectors[2][d];
t = (t-floor(t))*pme->ngrid[d];
......@@ -281,9 +281,9 @@ pme_update_bsplines(pme_t pme)
order = pme->order;
for(i=0; (i<pme->natoms); i++)
for (i=0; (i<pme->natoms); i++)
{
for(j=0; j<3; j++)
for (j=0; j<3; j++)
{
/* dr is relative offset from lower cell limit */
dr = pme->particlefraction[i][j];
......@@ -294,11 +294,11 @@ pme_update_bsplines(pme_t pme)
data[1] = dr;
data[0] = 1-dr;
for(k=3; k<order; k++)
for (k=3; k<order; k++)
{
div = (RealOpenMM) (1.0/(k-1.0));
data[k-1] = div*dr*data[k-2];
for(l=1; l<(k-1); l++)
for (l=1; l<(k-1); l++)
{
data[k-l-1] = div*((dr+l)*data[k-l-2]+(k-l-dr)*data[k-l-1]);
}
......@@ -308,7 +308,7 @@ pme_update_bsplines(pme_t pme)
/* differentiate */
ddata[0] = -data[0];
for(k=1; k<order; k++)
for (k=1; k<order; k++)
{
ddata[k] = data[k-1]-data[k];
}
......@@ -316,7 +316,7 @@ pme_update_bsplines(pme_t pme)
div = (RealOpenMM) (1.0/(order-1));
data[order-1] = div*dr*data[order-2];
for(l=1; l<(order-1); l++)
for (l=1; l<(order-1); l++)
{
data[order-l-1] = div*((dr+l)*data[order-l-2]+(order-l-dr)*data[order-l-1]);
}
......@@ -343,12 +343,12 @@ pme_grid_spread_charge(pme_t pme, const vector<RealOpenMM>& charges)
order = pme->order;
/* Reset the grid */
for(i=0;i<pme->ngrid[0]*pme->ngrid[1]*pme->ngrid[2];i++)
for (i=0;i<pme->ngrid[0]*pme->ngrid[1]*pme->ngrid[2];i++)
{
pme->grid[i].re = pme->grid[i].im = 0;
}
for(i=0;i<pme->natoms;i++)
for (i=0;i<pme->natoms;i++)
{
q = charges[i];
......@@ -380,16 +380,16 @@ pme_grid_spread_charge(pme_t pme, const vector<RealOpenMM>& charges)
* 3) When we parallelize things, we only need to communicate in one direction instead of two!
*/
for(ix=0;ix<order;ix++)
for (ix=0;ix<order;ix++)
{
/* Calculate index, apply PBC so we spread to index 0/1/2 when a particle is close to the upper limit of the grid */
xindex = (x0index + ix) % pme->ngrid[0];
for(iy=0;iy<order;iy++)
for (iy=0;iy<order;iy++)
{
yindex = (y0index + iy) % pme->ngrid[1];
for(iz=0;iz<order;iz++)
for (iz=0;iz<order;iz++)
{
/* Can be optimized, but we keep it simple here */
zindex = (z0index + iz) % pme->ngrid[2];
......@@ -448,21 +448,21 @@ pme_reciprocal_convolution(pme_t pme,
maxky = (RealOpenMM) ((ny+1)/2);
maxkz = (RealOpenMM) ((nz+1)/2);
for(kx=0;kx<nx;kx++)
for (kx=0;kx<nx;kx++)
{
/* Calculate frequency. Grid indices in the upper half correspond to negative frequencies! */
mx = (RealOpenMM) ((kx<maxkx) ? kx : (kx-nx));
mhx = mx*recipBoxVectors[0][0];
bx = boxfactor*pme->bsplines_moduli[0][kx];
for(ky=0;ky<ny;ky++)
for (ky=0;ky<ny;ky++)
{
/* Calculate frequency. Grid indices in the upper half correspond to negative frequencies! */
my = (RealOpenMM) ((ky<maxky) ? ky : (ky-ny));
mhy = mx*recipBoxVectors[1][0]+my*recipBoxVectors[1][1];
by = pme->bsplines_moduli[1][ky];
for(kz=0;kz<nz;kz++)
for (kz=0;kz<nz;kz++)
{
/* If the net charge of the system is 0.0, there will not be any DC (direct current, zero frequency) component. However,
* we can still handle charged systems through a charge correction, in which case the DC
......@@ -546,7 +546,7 @@ pme_grid_interpolate_force(pme_t pme,
/* This is almost identical to the charge spreading routine! */
for(i=0;i<pme->natoms;i++)
for (i=0;i<pme->natoms;i++)
{
fx = fy = fz = 0;
......@@ -570,21 +570,21 @@ pme_grid_interpolate_force(pme_t pme,
/* Since we will add order^3 (typically 4*4*4=64) terms to the force on each particle, we use temporary fx/fy/fz
* variables, and only add it to memory forces[] at the end.
*/
for(ix=0;ix<order;ix++)
for (ix=0;ix<order;ix++)
{
xindex = (x0index + ix) % pme->ngrid[0];
/* Get both the bspline factor and its derivative with respect to the x coordinate! */
tx = thetax[ix];
dtx = dthetax[ix];
for(iy=0;iy<order;iy++)
for (iy=0;iy<order;iy++)
{
yindex = (y0index + iy) % pme->ngrid[1];
/* bspline + derivative wrt y */
ty = thetay[iy];
dty = dthetay[iy];
for(iz=0;iz<order;iz++)
for (iz=0;iz<order;iz++)
{
/* Can be optimized, but we keep it simple here */
zindex = (z0index + iz) % pme->ngrid[2];
......@@ -633,7 +633,7 @@ pme_init(pme_t * ppme,
pme->ewaldcoeff = ewaldcoeff;
pme->natoms = natoms;
for(d=0;d<3;d++)
for (d=0;d<3;d++)
{
pme->ngrid[d] = ngrid[d];
pme->bsplines_theta[d] = (RealOpenMM *)malloc(sizeof(RealOpenMM)*pme_order*natoms);
......@@ -712,7 +712,7 @@ pme_destroy(pme_t pme)
free(pme->grid);
for(d=0;d<3;d++)
for (d=0;d<3;d++)
{
free(pme->bsplines_moduli[d]);
free(pme->bsplines_theta[d]);
......@@ -729,3 +729,5 @@ pme_destroy(pme_t pme)
return 0;
}
} // namespace OpenMM
......@@ -25,19 +25,19 @@
#include <string.h>
#include <sstream>
#include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h"
#include "SimTKOpenMMUtilities.h"
#include "ReferenceForce.h"
#include "ReferencePairIxn.h"
using namespace OpenMM;
/**---------------------------------------------------------------------------------------
ReferencePairIxn constructor
--------------------------------------------------------------------------------------- */
ReferencePairIxn::ReferencePairIxn( ){
ReferencePairIxn::ReferencePairIxn() {
// ---------------------------------------------------------------------------------------
......@@ -53,7 +53,7 @@ ReferencePairIxn::ReferencePairIxn( ){
--------------------------------------------------------------------------------------- */
ReferencePairIxn::~ReferencePairIxn( ){
ReferencePairIxn::~ReferencePairIxn() {
// ---------------------------------------------------------------------------------------
......
......@@ -25,14 +25,12 @@
#include <string.h>
#include <sstream>
#include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h"
#include "SimTKOpenMMUtilities.h"
#include "ReferenceProperDihedralBond.h"
#include "ReferenceForce.h"
using std::vector;
using OpenMM::RealVec;
using namespace OpenMM;
/**---------------------------------------------------------------------------------------
......@@ -40,7 +38,7 @@ using OpenMM::RealVec;
--------------------------------------------------------------------------------------- */
ReferenceProperDihedralBond::ReferenceProperDihedralBond( ){
ReferenceProperDihedralBond::ReferenceProperDihedralBond() {
// ---------------------------------------------------------------------------------------
......@@ -56,7 +54,7 @@ ReferenceProperDihedralBond::ReferenceProperDihedralBond( ){
--------------------------------------------------------------------------------------- */
ReferenceProperDihedralBond::~ReferenceProperDihedralBond( ){
ReferenceProperDihedralBond::~ReferenceProperDihedralBond() {
// ---------------------------------------------------------------------------------------
......@@ -80,11 +78,11 @@ ReferenceProperDihedralBond::~ReferenceProperDihedralBond( ){
--------------------------------------------------------------------------------------- */
void ReferenceProperDihedralBond::calculateBondIxn( int* atomIndices,
void ReferenceProperDihedralBond::calculateBondIxn(int* atomIndices,
vector<RealVec>& atomCoordinates,
RealOpenMM* parameters,
vector<RealVec>& forces,
RealOpenMM* totalEnergy ) const {
RealOpenMM* totalEnergy) const {
static const std::string methodName = "\nReferenceProperDihedralBond::calculateBondIxn";
......@@ -112,9 +110,9 @@ void ReferenceProperDihedralBond::calculateBondIxn( int* atomIndices,
int atomBIndex = atomIndices[1];
int atomCIndex = atomIndices[2];
int atomDIndex = atomIndices[3];
ReferenceForce::getDeltaR( atomCoordinates[atomBIndex], atomCoordinates[atomAIndex], deltaR[0] );
ReferenceForce::getDeltaR( atomCoordinates[atomBIndex], atomCoordinates[atomCIndex], deltaR[1] );
ReferenceForce::getDeltaR( atomCoordinates[atomDIndex], atomCoordinates[atomCIndex], deltaR[2] );
ReferenceForce::getDeltaR(atomCoordinates[atomBIndex], atomCoordinates[atomAIndex], deltaR[0]);
ReferenceForce::getDeltaR(atomCoordinates[atomBIndex], atomCoordinates[atomCIndex], deltaR[1]);
ReferenceForce::getDeltaR(atomCoordinates[atomDIndex], atomCoordinates[atomCIndex], deltaR[2]);
RealOpenMM dotDihedral;
RealOpenMM signOfAngle;
......@@ -128,35 +126,35 @@ void ReferenceProperDihedralBond::calculateBondIxn( int* atomIndices,
// get dihedral angle
RealOpenMM dihedralAngle = getDihedralAngleBetweenThreeVectors( deltaR[0], deltaR[1], deltaR[2],
crossProduct, &dotDihedral, deltaR[0],
&signOfAngle, hasREntry );
RealOpenMM dihedralAngle = getDihedralAngleBetweenThreeVectors(deltaR[0], deltaR[1], deltaR[2],
crossProduct, &dotDihedral, deltaR[0],
&signOfAngle, hasREntry);
// evaluate delta angle, dE/d(angle)
RealOpenMM deltaAngle = parameters[2]*dihedralAngle - parameters[1];
RealOpenMM sinDeltaAngle = SIN( deltaAngle );
RealOpenMM sinDeltaAngle = SIN(deltaAngle);
RealOpenMM dEdAngle = -parameters[0]*parameters[2]*sinDeltaAngle;
RealOpenMM energy = parameters[0]*(one + COS( deltaAngle ) );
RealOpenMM energy = parameters[0]*(one + COS(deltaAngle));
// compute force
RealOpenMM internalF[4][3];
RealOpenMM forceFactors[4];
RealOpenMM normCross1 = DOT3( crossProduct[0], crossProduct[0] );
RealOpenMM normCross1 = DOT3(crossProduct[0], crossProduct[0]);
RealOpenMM normBC = deltaR[1][ReferenceForce::RIndex];
forceFactors[0] = (-dEdAngle*normBC)/normCross1;
RealOpenMM normCross2 = DOT3( crossProduct[1], crossProduct[1] );
RealOpenMM normCross2 = DOT3(crossProduct[1], crossProduct[1]);
forceFactors[3] = (dEdAngle*normBC)/normCross2;
forceFactors[1] = DOT3( deltaR[0], deltaR[1] );
forceFactors[1] = DOT3(deltaR[0], deltaR[1]);
forceFactors[1] /= deltaR[1][ReferenceForce::R2Index];
forceFactors[2] = DOT3( deltaR[2], deltaR[1] );
forceFactors[2] = DOT3(deltaR[2], deltaR[1]);
forceFactors[2] /= deltaR[1][ReferenceForce::R2Index];
for( int ii = 0; ii < 3; ii++ ){
for (int ii = 0; ii < 3; ii++) {
internalF[0][ii] = forceFactors[0]*crossProduct[0][ii];
internalF[3][ii] = forceFactors[3]*crossProduct[1][ii];
......@@ -169,7 +167,7 @@ void ReferenceProperDihedralBond::calculateBondIxn( int* atomIndices,
// accumulate forces
for( int ii = 0; ii < 3; ii++ ){
for (int ii = 0; ii < 3; ii++) {
forces[atomAIndex][ii] += internalF[0][ii];
forces[atomBIndex][ii] -= internalF[1][ii];
forces[atomCIndex][ii] -= internalF[2][ii];
......
......@@ -25,14 +25,12 @@
#include <string.h>
#include <sstream>
#include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h"
#include "SimTKOpenMMUtilities.h"
#include "ReferenceRbDihedralBond.h"
#include "ReferenceForce.h"
using std::vector;
using OpenMM::RealVec;
using namespace OpenMM;
/**---------------------------------------------------------------------------------------
......@@ -40,7 +38,7 @@ using OpenMM::RealVec;
--------------------------------------------------------------------------------------- */
ReferenceRbDihedralBond::ReferenceRbDihedralBond( ){
ReferenceRbDihedralBond::ReferenceRbDihedralBond() {
// ---------------------------------------------------------------------------------------
......@@ -56,7 +54,7 @@ ReferenceRbDihedralBond::ReferenceRbDihedralBond( ){
--------------------------------------------------------------------------------------- */
ReferenceRbDihedralBond::~ReferenceRbDihedralBond( ){
ReferenceRbDihedralBond::~ReferenceRbDihedralBond() {
// ---------------------------------------------------------------------------------------
......@@ -78,11 +76,11 @@ ReferenceRbDihedralBond::~ReferenceRbDihedralBond( ){
--------------------------------------------------------------------------------------- */
void ReferenceRbDihedralBond::calculateBondIxn( int* atomIndices,
void ReferenceRbDihedralBond::calculateBondIxn(int* atomIndices,
vector<RealVec>& atomCoordinates,
RealOpenMM* parameters,
vector<RealVec>& forces,
RealOpenMM* totalEnergy ) const {
RealOpenMM* totalEnergy) const {
static const std::string methodName = "\nReferenceRbDihedralBond::calculateBondIxn";
......@@ -114,9 +112,9 @@ void ReferenceRbDihedralBond::calculateBondIxn( int* atomIndices,
int atomBIndex = atomIndices[1];
int atomCIndex = atomIndices[2];
int atomDIndex = atomIndices[3];
ReferenceForce::getDeltaR( atomCoordinates[atomBIndex], atomCoordinates[atomAIndex], deltaR[0] );
ReferenceForce::getDeltaR( atomCoordinates[atomBIndex], atomCoordinates[atomCIndex], deltaR[1] );
ReferenceForce::getDeltaR( atomCoordinates[atomDIndex], atomCoordinates[atomCIndex], deltaR[2] );
ReferenceForce::getDeltaR(atomCoordinates[atomBIndex], atomCoordinates[atomAIndex], deltaR[0]);
ReferenceForce::getDeltaR(atomCoordinates[atomBIndex], atomCoordinates[atomCIndex], deltaR[1]);
ReferenceForce::getDeltaR(atomCoordinates[atomDIndex], atomCoordinates[atomCIndex], deltaR[2]);
RealOpenMM cosPhi;
RealOpenMM signOfAngle;
......@@ -127,13 +125,13 @@ void ReferenceRbDihedralBond::calculateBondIxn( int* atomIndices,
RealOpenMM* crossProduct[2];
crossProduct[0] = crossProductMemory;
crossProduct[1] = crossProductMemory + 3;
RealOpenMM dihederalAngle = getDihedralAngleBetweenThreeVectors( deltaR[0], deltaR[1], deltaR[2],
crossProduct, &cosPhi, deltaR[0],
&signOfAngle, hasREntry );
RealOpenMM dihederalAngle = getDihedralAngleBetweenThreeVectors(deltaR[0], deltaR[1], deltaR[2],
crossProduct, &cosPhi, deltaR[0],
&signOfAngle, hasREntry);
// Gromacs: use polymer convention
if( dihederalAngle < zero ){
if (dihederalAngle < zero) {
dihederalAngle += PI_M;
} else {
dihederalAngle -= PI_M;
......@@ -142,36 +140,36 @@ void ReferenceRbDihedralBond::calculateBondIxn( int* atomIndices,
// Ryckaert-Bellemans:
// V = sum over i: { C_i*cos( psi )**i }, where psi = phi - PI,
// V = sum over i: { C_i*cos(psi)**i }, where psi = phi - PI,
// C_i is ith RB coefficient
RealOpenMM dEdAngle = zero;
RealOpenMM energy = parameters[0];
RealOpenMM cosFactor = one;
for( int ii = 1; ii < numberOfParameters; ii++ ){
for (int ii = 1; ii < numberOfParameters; ii++) {
dEdAngle -= ((RealOpenMM) ii)*parameters[ii]*cosFactor;
cosFactor *= cosPhi;
energy += cosFactor*parameters[ii];
}
dEdAngle *= SIN( dihederalAngle );
dEdAngle *= SIN(dihederalAngle);
RealOpenMM internalF[4][3];
RealOpenMM forceFactors[4];
RealOpenMM normCross1 = DOT3( crossProduct[0], crossProduct[0] );
RealOpenMM normCross1 = DOT3(crossProduct[0], crossProduct[0]);
RealOpenMM normBC = deltaR[1][ReferenceForce::RIndex];
forceFactors[0] = (-dEdAngle*normBC)/normCross1;
RealOpenMM normCross2 = DOT3( crossProduct[1], crossProduct[1] );
RealOpenMM normCross2 = DOT3(crossProduct[1], crossProduct[1]);
forceFactors[3] = (dEdAngle*normBC)/normCross2;
forceFactors[1] = DOT3( deltaR[0], deltaR[1] );
forceFactors[1] = DOT3(deltaR[0], deltaR[1]);
forceFactors[1] /= deltaR[1][ReferenceForce::R2Index];
forceFactors[2] = DOT3( deltaR[2], deltaR[1] );
forceFactors[2] = DOT3(deltaR[2], deltaR[1]);
forceFactors[2] /= deltaR[1][ReferenceForce::R2Index];
for( int ii = 0; ii < 3; ii++ ){
for (int ii = 0; ii < 3; ii++) {
internalF[0][ii] = forceFactors[0]*crossProduct[0][ii];
internalF[3][ii] = forceFactors[3]*crossProduct[1][ii];
......@@ -184,7 +182,7 @@ void ReferenceRbDihedralBond::calculateBondIxn( int* atomIndices,
// accumulate forces
for( int ii = 0; ii < 3; ii++ ){
for (int ii = 0; ii < 3; ii++) {
forces[atomAIndex][ii] += internalF[0][ii];
forces[atomBIndex][ii] -= internalF[1][ii];
forces[atomCIndex][ii] -= internalF[2][ii];
......
......@@ -25,16 +25,15 @@
#include <cstring>
#include <sstream>
#include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h"
#include "SimTKOpenMMUtilities.h"
#include "ReferenceStochasticDynamics.h"
#include "ReferenceVirtualSites.h"
#include "openmm/OpenMMException.h"
#include <cstdio>
using std::vector;
using OpenMM::RealVec;
using namespace OpenMM;
/**---------------------------------------------------------------------------------------
......@@ -47,31 +46,14 @@ using OpenMM::RealVec;
--------------------------------------------------------------------------------------- */
ReferenceStochasticDynamics::ReferenceStochasticDynamics( int numberOfAtoms,
RealOpenMM deltaT, RealOpenMM tau,
RealOpenMM temperature ) :
ReferenceDynamics( numberOfAtoms, deltaT, temperature ), _tau( tau ) {
// ---------------------------------------------------------------------------------------
static const char* methodName = "\nReferenceStochasticDynamics::ReferenceStochasticDynamics";
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
// ---------------------------------------------------------------------------------------
// ensure tau is not zero -- if it is print warning message
if( _tau == zero ){
ReferenceStochasticDynamics::ReferenceStochasticDynamics(int numberOfAtoms,
RealOpenMM deltaT, RealOpenMM tau,
RealOpenMM temperature) :
ReferenceDynamics(numberOfAtoms, deltaT, temperature), _tau(tau) {
if (tau <= 0) {
std::stringstream message;
message << methodName;
message << " input tau value=" << tau << " is invalid -- setting to 1.";
SimTKOpenMMLog::printError( message );
_tau = one;
message << "illegal tau value: " << tau;
throw OpenMMException(message.str());
}
xPrime.resize(numberOfAtoms);
inverseMasses.resize(numberOfAtoms);
......@@ -83,7 +65,7 @@ ReferenceStochasticDynamics::ReferenceStochasticDynamics( int numberOfAtoms,
--------------------------------------------------------------------------------------- */
ReferenceStochasticDynamics::~ReferenceStochasticDynamics( ){
ReferenceStochasticDynamics::~ReferenceStochasticDynamics() {
// ---------------------------------------------------------------------------------------
......@@ -101,7 +83,7 @@ ReferenceStochasticDynamics::~ReferenceStochasticDynamics( ){
--------------------------------------------------------------------------------------- */
RealOpenMM ReferenceStochasticDynamics::getTau( void ) const {
RealOpenMM ReferenceStochasticDynamics::getTau() const {
// ---------------------------------------------------------------------------------------
......@@ -125,10 +107,10 @@ RealOpenMM ReferenceStochasticDynamics::getTau( void ) const {
--------------------------------------------------------------------------------------- */
void ReferenceStochasticDynamics::updatePart1( int numberOfAtoms, vector<RealVec>& atomCoordinates,
void ReferenceStochasticDynamics::updatePart1(int numberOfAtoms, vector<RealVec>& atomCoordinates,
vector<RealVec>& velocities,
vector<RealVec>& forces, vector<RealOpenMM>& inverseMasses,
vector<RealVec>& xPrime ){
vector<RealVec>& xPrime) {
// ---------------------------------------------------------------------------------------
......@@ -166,10 +148,10 @@ void ReferenceStochasticDynamics::updatePart1( int numberOfAtoms, vector<RealVec
--------------------------------------------------------------------------------------- */
void ReferenceStochasticDynamics::updatePart2( int numberOfAtoms, vector<RealVec>& atomCoordinates,
void ReferenceStochasticDynamics::updatePart2(int numberOfAtoms, vector<RealVec>& atomCoordinates,
vector<RealVec>& velocities,
vector<RealVec>& forces, vector<RealOpenMM>& inverseMasses,
vector<RealVec>& xPrime ){
vector<RealVec>& xPrime) {
// ---------------------------------------------------------------------------------------
......@@ -214,10 +196,10 @@ void ReferenceStochasticDynamics::update(const OpenMM::System& system, vector<Re
// first-time-through initialization
int numberOfAtoms = system.getNumParticles();
if( getTimeStep() == 0 ){
if (getTimeStep() == 0) {
// invert masses
for( int ii = 0; ii < numberOfAtoms; ii++ ){
for (int ii = 0; ii < numberOfAtoms; ii++) {
if (masses[ii] == zero)
inverseMasses[ii] = zero;
else
......@@ -227,11 +209,11 @@ void ReferenceStochasticDynamics::update(const OpenMM::System& system, vector<Re
// 1st update
updatePart1( numberOfAtoms, atomCoordinates, velocities, forces, inverseMasses, xPrime );
updatePart1(numberOfAtoms, atomCoordinates, velocities, forces, inverseMasses, xPrime);
// 2nd update
updatePart2( numberOfAtoms, atomCoordinates, velocities, forces, inverseMasses, xPrime );
updatePart2(numberOfAtoms, atomCoordinates, velocities, forces, inverseMasses, xPrime);
ReferenceConstraintAlgorithm* referenceConstraintAlgorithm = getReferenceConstraintAlgorithm();
if (referenceConstraintAlgorithm)
......
......@@ -26,16 +26,15 @@
#include <sstream>
#include <algorithm>
#include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h"
#include "SimTKOpenMMUtilities.h"
#include "ReferenceVariableStochasticDynamics.h"
#include "ReferenceVirtualSites.h"
#include "openmm/OpenMMException.h"
#include <cstdio>
using std::vector;
using OpenMM::RealVec;
using namespace OpenMM;
/**---------------------------------------------------------------------------------------
......@@ -49,31 +48,14 @@ using OpenMM::RealVec;
--------------------------------------------------------------------------------------- */
ReferenceVariableStochasticDynamics::ReferenceVariableStochasticDynamics( int numberOfAtoms,
ReferenceVariableStochasticDynamics::ReferenceVariableStochasticDynamics(int numberOfAtoms,
RealOpenMM tau, RealOpenMM temperature,
RealOpenMM accuracy ) :
RealOpenMM accuracy) :
ReferenceDynamics(numberOfAtoms, 0.0f, temperature), _tau(tau), _accuracy(accuracy) {
// ---------------------------------------------------------------------------------------
static const char* methodName = "\nReferenceVariableStochasticDynamics::ReferenceVariableStochasticDynamics";
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
// ---------------------------------------------------------------------------------------
// ensure tau is not zero -- if it is print warning message
if( _tau == zero ){
if (tau <= 0) {
std::stringstream message;
message << methodName;
message << " input tau value=" << tau << " is invalid -- setting to 1.";
SimTKOpenMMLog::printError( message );
_tau = one;
message << "illegal tau value: " << tau;
throw OpenMMException(message.str());
}
xPrime.resize(numberOfAtoms);
inverseMasses.resize(numberOfAtoms);
......@@ -85,7 +67,7 @@ ReferenceVariableStochasticDynamics::ReferenceVariableStochasticDynamics( int nu
--------------------------------------------------------------------------------------- */
ReferenceVariableStochasticDynamics::~ReferenceVariableStochasticDynamics( ){
ReferenceVariableStochasticDynamics::~ReferenceVariableStochasticDynamics() {
// ---------------------------------------------------------------------------------------
......@@ -103,7 +85,7 @@ ReferenceVariableStochasticDynamics::~ReferenceVariableStochasticDynamics( ){
--------------------------------------------------------------------------------------- */
RealOpenMM ReferenceVariableStochasticDynamics::getAccuracy( void ) const {
RealOpenMM ReferenceVariableStochasticDynamics::getAccuracy() const {
return _accuracy;
}
......@@ -113,7 +95,7 @@ RealOpenMM ReferenceVariableStochasticDynamics::getAccuracy( void ) const {
--------------------------------------------------------------------------------------- */
void ReferenceVariableStochasticDynamics::setAccuracy( RealOpenMM accuracy ) {
void ReferenceVariableStochasticDynamics::setAccuracy(RealOpenMM accuracy) {
_accuracy = accuracy;
}
......@@ -125,7 +107,7 @@ void ReferenceVariableStochasticDynamics::setAccuracy( RealOpenMM accuracy ) {
--------------------------------------------------------------------------------------- */
RealOpenMM ReferenceVariableStochasticDynamics::getTau( void ) const {
RealOpenMM ReferenceVariableStochasticDynamics::getTau() const {
// ---------------------------------------------------------------------------------------
......@@ -151,10 +133,10 @@ RealOpenMM ReferenceVariableStochasticDynamics::getTau( void ) const {
--------------------------------------------------------------------------------------- */
void ReferenceVariableStochasticDynamics::updatePart1( int numberOfAtoms, vector<RealVec>& atomCoordinates,
void ReferenceVariableStochasticDynamics::updatePart1(int numberOfAtoms, vector<RealVec>& atomCoordinates,
vector<RealVec>& velocities,
vector<RealVec>& forces, vector<RealOpenMM>& masses, vector<RealOpenMM>& inverseMasses,
vector<RealVec>& xPrime, RealOpenMM maxStepSize ){
vector<RealVec>& xPrime, RealOpenMM maxStepSize) {
// ---------------------------------------------------------------------------------------
......@@ -165,10 +147,10 @@ void ReferenceVariableStochasticDynamics::updatePart1( int numberOfAtoms, vector
// first-time-through initialization
if( getTimeStep() == 0 ){
if (getTimeStep() == 0) {
// invert masses
for( int ii = 0; ii < numberOfAtoms; ii++ ){
for (int ii = 0; ii < numberOfAtoms; ii++) {
if (masses[ii] == 0)
inverseMasses[ii] = 0;
else
......@@ -225,10 +207,10 @@ void ReferenceVariableStochasticDynamics::updatePart1( int numberOfAtoms, vector
--------------------------------------------------------------------------------------- */
void ReferenceVariableStochasticDynamics::updatePart2( int numberOfAtoms, vector<RealVec>& atomCoordinates,
void ReferenceVariableStochasticDynamics::updatePart2(int numberOfAtoms, vector<RealVec>& atomCoordinates,
vector<RealVec>& velocities,
vector<RealVec>& forces, vector<RealOpenMM>& inverseMasses,
vector<RealVec>& xPrime ){
vector<RealVec>& xPrime) {
// ---------------------------------------------------------------------------------------
......@@ -272,11 +254,11 @@ void ReferenceVariableStochasticDynamics::update(const OpenMM::System& system, v
// 1st update
int numberOfAtoms = system.getNumParticles();
updatePart1( numberOfAtoms, atomCoordinates, velocities, forces, masses, inverseMasses, xPrime, maxStepSize );
updatePart1(numberOfAtoms, atomCoordinates, velocities, forces, masses, inverseMasses, xPrime, maxStepSize);
// 2nd update
updatePart2( numberOfAtoms, atomCoordinates, velocities, forces, inverseMasses, xPrime );
updatePart2(numberOfAtoms, atomCoordinates, velocities, forces, inverseMasses, xPrime);
ReferenceConstraintAlgorithm* referenceConstraintAlgorithm = getReferenceConstraintAlgorithm();
if (referenceConstraintAlgorithm)
......@@ -284,7 +266,7 @@ void ReferenceVariableStochasticDynamics::update(const OpenMM::System& system, v
// copy xPrime -> atomCoordinates
for( int ii = 0; ii < numberOfAtoms; ii++ ) {
for (int ii = 0; ii < numberOfAtoms; ii++) {
if (masses[ii] != 0.0) {
atomCoordinates[ii][0] = xPrime[ii][0];
atomCoordinates[ii][1] = xPrime[ii][1];
......
......@@ -26,14 +26,12 @@
#include <sstream>
#include <algorithm>
#include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h"
#include "SimTKOpenMMUtilities.h"
#include "ReferenceVariableVerletDynamics.h"
#include "ReferenceVirtualSites.h"
using std::vector;
using OpenMM::RealVec;
using namespace OpenMM;
/**---------------------------------------------------------------------------------------
......@@ -45,8 +43,8 @@ using OpenMM::RealVec;
--------------------------------------------------------------------------------------- */
ReferenceVariableVerletDynamics::ReferenceVariableVerletDynamics( int numberOfAtoms, RealOpenMM accuracy ) :
ReferenceDynamics( numberOfAtoms, 0.0f, 0.0f ), _accuracy(accuracy) {
ReferenceVariableVerletDynamics::ReferenceVariableVerletDynamics(int numberOfAtoms, RealOpenMM accuracy) :
ReferenceDynamics(numberOfAtoms, 0.0f, 0.0f), _accuracy(accuracy) {
xPrime.resize(numberOfAtoms);
inverseMasses.resize(numberOfAtoms);
}
......@@ -57,7 +55,7 @@ ReferenceVariableVerletDynamics::ReferenceVariableVerletDynamics( int numberOfAt
--------------------------------------------------------------------------------------- */
ReferenceVariableVerletDynamics::~ReferenceVariableVerletDynamics( ){
ReferenceVariableVerletDynamics::~ReferenceVariableVerletDynamics() {
// ---------------------------------------------------------------------------------------
......@@ -75,7 +73,7 @@ ReferenceVariableVerletDynamics::~ReferenceVariableVerletDynamics( ){
--------------------------------------------------------------------------------------- */
RealOpenMM ReferenceVariableVerletDynamics::getAccuracy( void ) const {
RealOpenMM ReferenceVariableVerletDynamics::getAccuracy() const {
return _accuracy;
}
......@@ -85,7 +83,7 @@ RealOpenMM ReferenceVariableVerletDynamics::getAccuracy( void ) const {
--------------------------------------------------------------------------------------- */
void ReferenceVariableVerletDynamics::setAccuracy( RealOpenMM accuracy ) {
void ReferenceVariableVerletDynamics::setAccuracy(RealOpenMM accuracy) {
_accuracy = accuracy;
}
......@@ -119,10 +117,10 @@ void ReferenceVariableVerletDynamics::update(const OpenMM::System& system, vecto
// first-time-through initialization
int numberOfAtoms = system.getNumParticles();
if( getTimeStep() == 0 ){
if (getTimeStep() == 0) {
// invert masses
for( int ii = 0; ii < numberOfAtoms; ii++ ){
for (int ii = 0; ii < numberOfAtoms; ii++) {
if (masses[ii] == zero)
inverseMasses[ii] = zero;
else
......
......@@ -25,8 +25,6 @@
#include <cstring>
#include <sstream>
#include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h"
#include "SimTKOpenMMUtilities.h"
#include "ReferenceVerletDynamics.h"
#include "ReferenceVirtualSites.h"
......@@ -34,7 +32,7 @@
#include <cstdio>
using std::vector;
using OpenMM::RealVec;
using namespace OpenMM;
/**---------------------------------------------------------------------------------------
......@@ -47,9 +45,8 @@ using OpenMM::RealVec;
--------------------------------------------------------------------------------------- */
ReferenceVerletDynamics::ReferenceVerletDynamics( int numberOfAtoms,
RealOpenMM deltaT ) :
ReferenceDynamics( numberOfAtoms, deltaT, 0.0 ) {
ReferenceVerletDynamics::ReferenceVerletDynamics(int numberOfAtoms, RealOpenMM deltaT) :
ReferenceDynamics(numberOfAtoms, deltaT, 0.0) {
// ---------------------------------------------------------------------------------------
......@@ -70,7 +67,7 @@ ReferenceVerletDynamics::ReferenceVerletDynamics( int numberOfAtoms,
--------------------------------------------------------------------------------------- */
ReferenceVerletDynamics::~ReferenceVerletDynamics( ){
ReferenceVerletDynamics::~ReferenceVerletDynamics() {
// ---------------------------------------------------------------------------------------
......@@ -109,10 +106,10 @@ void ReferenceVerletDynamics::update(const OpenMM::System& system, vector<RealVe
// first-time-through initialization
int numberOfAtoms = system.getNumParticles();
if( getTimeStep() == 0 ){
if (getTimeStep() == 0) {
// invert masses
for( int ii = 0; ii < numberOfAtoms; ii++ ){
for (int ii = 0; ii < numberOfAtoms; ii++) {
if (masses[ii] == zero)
inverseMasses[ii] = zero;
else
......@@ -135,7 +132,7 @@ void ReferenceVerletDynamics::update(const OpenMM::System& system, vector<RealVe
// Update the positions and velocities.
RealOpenMM velocityScale = static_cast<RealOpenMM>( 1.0/getDeltaT() );
RealOpenMM velocityScale = static_cast<RealOpenMM>(1.0/getDeltaT());
for (int i = 0; i < numberOfAtoms; ++i) {
if (masses[i] != zero)
for (int j = 0; j < 3; ++j) {
......
......@@ -26,7 +26,6 @@
#include "openmm/internal/OSRngSeed.h"
#include "SimTKOpenMMUtilities.h"
#include "SimTKOpenMMLog.h"
#include "sfmt/SFMT.h"
// fabs(), ...
......@@ -36,6 +35,8 @@
#include <string.h>
#include <iostream>
using namespace OpenMM;
uint32_t SimTKOpenMMUtilities::_randomNumberSeed = 0;
bool SimTKOpenMMUtilities::_randomInitialized = false;
bool SimTKOpenMMUtilities::nextGaussianIsValid = false;
......@@ -58,9 +59,9 @@ OpenMM_SFMT::SFMT SimTKOpenMMUtilities::sfmt;
--------------------------------------------------------------------------------------- */
RealOpenMM* SimTKOpenMMUtilities::allocateOneDRealOpenMMArray( int iSize, RealOpenMM* array1D,
int initialize, RealOpenMM initialValue,
const std::string& idString ){
RealOpenMM* SimTKOpenMMUtilities::allocateOneDRealOpenMMArray(int iSize, RealOpenMM* array1D,
int initialize, RealOpenMM initialValue,
const std::string& idString) {
// ---------------------------------------------------------------------------------------
......@@ -70,17 +71,17 @@ RealOpenMM* SimTKOpenMMUtilities::allocateOneDRealOpenMMArray( int iSize, RealOp
// ---------------------------------------------------------------------------------------
if( array1D == NULL ){
if (array1D == NULL) {
array1D = new RealOpenMM[iSize];
}
if( initialize ){
if( initialValue == zero ){
memset( array1D, 0, iSize*sizeof( RealOpenMM ) );
if (initialize) {
if (initialValue == zero) {
memset(array1D, 0, iSize*sizeof(RealOpenMM));
} else {
for( int ii = 0; ii < iSize; ii++ ){
for (int ii = 0; ii < iSize; ii++) {
array1D[ii] = initialValue;
}
}
......@@ -106,9 +107,9 @@ RealOpenMM* SimTKOpenMMUtilities::allocateOneDRealOpenMMArray( int iSize, RealOp
--------------------------------------------------------------------------------------- */
RealOpenMM** SimTKOpenMMUtilities::allocateTwoDRealOpenMMArray( int iSize, int jSize, RealOpenMM** array2D,
int initialize, RealOpenMM initialValue,
const std::string& idString ){
RealOpenMM** SimTKOpenMMUtilities::allocateTwoDRealOpenMMArray(int iSize, int jSize, RealOpenMM** array2D,
int initialize, RealOpenMM initialValue,
const std::string& idString) {
// ---------------------------------------------------------------------------------------
......@@ -116,22 +117,22 @@ RealOpenMM** SimTKOpenMMUtilities::allocateTwoDRealOpenMMArray( int iSize, int j
// ---------------------------------------------------------------------------------------
if( array2D == NULL ){
if (array2D == NULL) {
array2D = new RealOpenMM*[iSize];
std::string blockString = idString;
blockString.append( "Block" );
blockString.append("Block");
RealOpenMM* block = new RealOpenMM[jSize*iSize];
for( int ii = 0; ii < iSize; ii++ ){
for (int ii = 0; ii < iSize; ii++) {
array2D[ii] = block;
block += jSize;
}
}
if( initialize ){
initialize2DRealOpenMMArray( iSize, jSize, array2D, initialValue );
if (initialize) {
initialize2DRealOpenMMArray(iSize, jSize, array2D, initialValue);
}
return array2D;
......@@ -148,7 +149,7 @@ RealOpenMM** SimTKOpenMMUtilities::allocateTwoDRealOpenMMArray( int iSize, int j
--------------------------------------------------------------------------------------- */
void SimTKOpenMMUtilities::freeTwoDRealOpenMMArray( RealOpenMM** array2D, const std::string& idString ){
void SimTKOpenMMUtilities::freeTwoDRealOpenMMArray(RealOpenMM** array2D, const std::string& idString) {
// ---------------------------------------------------------------------------------------
......@@ -156,10 +157,10 @@ void SimTKOpenMMUtilities::freeTwoDRealOpenMMArray( RealOpenMM** array2D, const
// ---------------------------------------------------------------------------------------
if( array2D != NULL ){
if (array2D != NULL) {
std::string blockString = idString;
blockString.append( "Block" );
blockString.append("Block");
delete[] array2D[0];
delete[] array2D;
......@@ -177,7 +178,7 @@ void SimTKOpenMMUtilities::freeTwoDRealOpenMMArray( RealOpenMM** array2D, const
--------------------------------------------------------------------------------------- */
void SimTKOpenMMUtilities::freeOneDRealOpenMMArray( RealOpenMM* array1D, const std::string& idString ){
void SimTKOpenMMUtilities::freeOneDRealOpenMMArray(RealOpenMM* array1D, const std::string& idString) {
// ---------------------------------------------------------------------------------------
......@@ -185,7 +186,7 @@ void SimTKOpenMMUtilities::freeOneDRealOpenMMArray( RealOpenMM* array1D, const s
// ---------------------------------------------------------------------------------------
if( array1D != NULL ){
if (array1D != NULL) {
delete[] array1D;
}
}
......@@ -203,9 +204,9 @@ void SimTKOpenMMUtilities::freeOneDRealOpenMMArray( RealOpenMM* array1D, const s
--------------------------------------------------------------------------------------- */
void SimTKOpenMMUtilities::initialize2DRealOpenMMArray( int iSize, int jSize,
void SimTKOpenMMUtilities::initialize2DRealOpenMMArray(int iSize, int jSize,
RealOpenMM** array2D,
RealOpenMM initialValue ){
RealOpenMM initialValue) {
// ---------------------------------------------------------------------------------------
......@@ -216,9 +217,9 @@ void SimTKOpenMMUtilities::initialize2DRealOpenMMArray( int iSize, int jSize,
bool useMemset;
bool useMemsetSingleBlock;
if( initialValue == 0.0f ){
if (initialValue == 0.0f) {
useMemset = true;
if( jSize > 1 && (array2D[0] + jSize) == array2D[1] ){
if (jSize > 1 && (array2D[0] + jSize) == array2D[1]) {
useMemsetSingleBlock = true;
} else {
useMemsetSingleBlock = false;
......@@ -228,17 +229,17 @@ void SimTKOpenMMUtilities::initialize2DRealOpenMMArray( int iSize, int jSize,
useMemset = false;
}
if( useMemset ){
if( useMemsetSingleBlock ){
memset( array2D[0], 0, iSize*jSize*sizeof( RealOpenMM ) );
if (useMemset) {
if (useMemsetSingleBlock) {
memset(array2D[0], 0, iSize*jSize*sizeof(RealOpenMM));
} else {
for( int ii = 0; ii < iSize; ii++ ){
memset( array2D[ii], 0, jSize*sizeof( RealOpenMM ) );
for (int ii = 0; ii < iSize; ii++) {
memset(array2D[ii], 0, jSize*sizeof(RealOpenMM));
}
}
} else {
for( int ii = 0; ii < iSize; ii++ ){
for( int jj = 0; jj < jSize; jj++ ){
for (int ii = 0; ii < iSize; ii++) {
for (int jj = 0; jj < jSize; jj++) {
array2D[ii][jj] = initialValue;
}
}
......@@ -259,9 +260,9 @@ void SimTKOpenMMUtilities::initialize2DRealOpenMMArray( int iSize, int jSize,
--------------------------------------------------------------------------------------- */
void SimTKOpenMMUtilities::crossProductVector3( RealOpenMM* vectorX,
RealOpenMM* vectorY,
RealOpenMM* vectorZ ){
void SimTKOpenMMUtilities::crossProductVector3(RealOpenMM* vectorX,
RealOpenMM* vectorY,
RealOpenMM* vectorZ) {
// ---------------------------------------------------------------------------------------
......@@ -284,7 +285,7 @@ void SimTKOpenMMUtilities::crossProductVector3( RealOpenMM* vectorX,
--------------------------------------------------------------------------------------- */
RealOpenMM SimTKOpenMMUtilities::getNormallyDistributedRandomNumber( void ) {
RealOpenMM SimTKOpenMMUtilities::getNormallyDistributedRandomNumber() {
if (nextGaussianIsValid) {
nextGaussianIsValid = false;
return nextGaussian;
......@@ -303,7 +304,7 @@ RealOpenMM SimTKOpenMMUtilities::getNormallyDistributedRandomNumber( void ) {
y = static_cast<RealOpenMM>(2.0 * genrand_real2(sfmt) - 1.0);
r2 = x*x + y*y;
} while (r2 >= 1.0 || r2 == 0.0);
RealOpenMM multiplier = static_cast<RealOpenMM>( sqrt((-2.0*log(r2))/r2) );
RealOpenMM multiplier = static_cast<RealOpenMM>(sqrt((-2.0*log(r2))/r2));
nextGaussian = y*multiplier;
nextGaussianIsValid = true;
return x*multiplier;
......@@ -317,13 +318,13 @@ RealOpenMM SimTKOpenMMUtilities::getNormallyDistributedRandomNumber( void ) {
--------------------------------------------------------------------------------------- */
RealOpenMM SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber( void ) {
RealOpenMM SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber() {
if (!_randomInitialized) {
init_gen_rand(_randomNumberSeed, sfmt);
_randomInitialized = true;
nextGaussianIsValid = false;
}
RealOpenMM value = static_cast<RealOpenMM>( genrand_real2(sfmt) );
RealOpenMM value = static_cast<RealOpenMM>(genrand_real2(sfmt));
return value;
}
......@@ -335,7 +336,7 @@ RealOpenMM SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber( void ) {
--------------------------------------------------------------------------------------- */
uint32_t SimTKOpenMMUtilities::getRandomNumberSeed( void ) {
uint32_t SimTKOpenMMUtilities::getRandomNumberSeed() {
// ---------------------------------------------------------------------------------------
......@@ -354,7 +355,7 @@ uint32_t SimTKOpenMMUtilities::getRandomNumberSeed( void ) {
--------------------------------------------------------------------------------------- */
void SimTKOpenMMUtilities::setRandomNumberSeed( uint32_t seed ) {
void SimTKOpenMMUtilities::setRandomNumberSeed(uint32_t seed) {
// ---------------------------------------------------------------------------------------
......
......@@ -672,16 +672,16 @@ fftpack_transpose_2d(t_complex * in_data,
t_complex * src;
int i,j;
if(nx<2 || ny<2)
if (nx<2 || ny<2)
{
if(in_data != out_data)
if (in_data != out_data)
{
memcpy(out_data,in_data,sizeof(t_complex)*nx*ny);
}
return 0;
}
if(in_data == out_data)
if (in_data == out_data)
{
src = (t_complex *)malloc(sizeof(t_complex)*nx*ny);
memcpy(src,in_data,sizeof(t_complex)*nx*ny);
......@@ -691,16 +691,16 @@ fftpack_transpose_2d(t_complex * in_data,
src = in_data;
}
for(i=0;i<nx;i++)
for (i=0;i<nx;i++)
{
for(j=0;j<ny;j++)
for (j=0;j<ny;j++)
{
out_data[j*nx+i].re = src[i*ny+j].re;
out_data[j*nx+i].im = src[i*ny+j].im;
}
}
if(src != in_data)
if (src != in_data)
{
free(src);
}
......@@ -722,16 +722,16 @@ fftpack_transpose_2d_nelem(t_complex * in_data,
ncopy = nelem*sizeof(t_complex);
if(nx<2 || ny<2)
if (nx<2 || ny<2)
{
if(in_data != out_data)
if (in_data != out_data)
{
memcpy(out_data,in_data,nx*ny*ncopy);
}
return 0;
}
if(in_data == out_data)
if (in_data == out_data)
{
src = (t_complex *)malloc(nx*ny*ncopy);
memcpy(src,in_data,nx*ny*ncopy);
......@@ -741,15 +741,15 @@ fftpack_transpose_2d_nelem(t_complex * in_data,
src = in_data;
}
for(i=0;i<nx;i++)
for (i=0;i<nx;i++)
{
for(j=0;j<ny;j++)
for (j=0;j<ny;j++)
{
memcpy(out_data + (j*nx+i)*nelem , src + (i*ny+j)*nelem , ncopy);
}
}
if(src != in_data)
if (src != in_data)
{
free(src);
}
......@@ -767,14 +767,14 @@ fftpack_init_1d(fftpack_t * pfft,
{
fftpack_t fft;
if(pfft==NULL)
if (pfft==NULL)
{
fprintf(stderr,"Fatal error - Invalid FFT opaque type pointer.");
return EINVAL;
}
*pfft = NULL;
if( (fft = (struct fftpack *)malloc(sizeof(struct fftpack))) == NULL)
if ((fft = (struct fftpack *)malloc(sizeof(struct fftpack))) == NULL)
{
return ENOMEM;
}
......@@ -783,13 +783,13 @@ fftpack_init_1d(fftpack_t * pfft,
fft->n = nx;
/* Need 4*n storage for 1D complex FFT */
if( (fft->work = (RealOpenMM *)malloc(sizeof(RealOpenMM)*(4*nx))) == NULL)
if ((fft->work = (RealOpenMM *)malloc(sizeof(RealOpenMM)*(4*nx))) == NULL)
{
free(fft);
return ENOMEM;
}
if(fft->n>1)
if (fft->n>1)
fftpack_cffti1(nx,fft->work,fft->ifac);
*pfft = fft;
......@@ -807,7 +807,7 @@ fftpack_init_2d(fftpack_t * pfft,
fftpack_t fft;
int rc;
if(pfft==NULL)
if (pfft==NULL)
{
fprintf(stderr,"Fatal error - Invalid FFT opaque type pointer.");
return EINVAL;
......@@ -815,13 +815,13 @@ fftpack_init_2d(fftpack_t * pfft,
*pfft = NULL;
/* Create the X transform */
if( (rc = fftpack_init_1d(&fft,nx)) != 0)
if ((rc = fftpack_init_1d(&fft,nx)) != 0)
{
return rc;
}
/* Create Y transform as a link from X */
if( (rc=fftpack_init_1d(&(fft->next),ny)) != 0)
if ((rc=fftpack_init_1d(&(fft->next),ny)) != 0)
{
free(fft);
return rc;
......@@ -842,7 +842,7 @@ fftpack_init_3d(fftpack_t * pfft,
fftpack_t fft;
int rc;
if(pfft==NULL)
if (pfft==NULL)
{
fprintf(stderr,"Fatal error - Invalid FFT opaque type pointer.");
return EINVAL;
......@@ -851,7 +851,7 @@ fftpack_init_3d(fftpack_t * pfft,
/* Create the X transform */
if( (fft = (struct fftpack *)malloc(sizeof(struct fftpack))) == NULL)
if ((fft = (struct fftpack *)malloc(sizeof(struct fftpack))) == NULL)
{
return ENOMEM;
}
......@@ -860,7 +860,7 @@ fftpack_init_3d(fftpack_t * pfft,
/* Need 4*nx storage for 1D complex FFT.
*/
if( (fft->work = (RealOpenMM *)malloc(sizeof(RealOpenMM)*(4*nx))) == NULL)
if ((fft->work = (RealOpenMM *)malloc(sizeof(RealOpenMM)*(4*nx))) == NULL)
{
free(fft);
return ENOMEM;
......@@ -869,7 +869,7 @@ fftpack_init_3d(fftpack_t * pfft,
fftpack_cffti1(nx,fft->work,fft->ifac);
/* Create 2D Y/Z transforms as a link from X */
if( (rc=fftpack_init_2d(&(fft->next),ny,nz)) != 0)
if ((rc=fftpack_init_2d(&(fft->next),ny,nz)) != 0)
{
free(fft);
return rc;
......@@ -893,7 +893,7 @@ fftpack_exec_1d (fftpack_t fft,
n=fft->n;
if(n==1)
if (n==1)
{
p1 = (RealOpenMM *)in_data;
p2 = (RealOpenMM *)out_data;
......@@ -904,13 +904,13 @@ fftpack_exec_1d (fftpack_t fft,
/* FFTPACK only does in-place transforms, so emulate out-of-place
* by copying data to the output array first.
*/
if( in_data != out_data )
if (in_data != out_data)
{
p1 = (RealOpenMM *)in_data;
p2 = (RealOpenMM *)out_data;
/* n complex = 2*n RealOpenMM elements */
for(i=0;i<2*n;i++)
for (i=0;i<2*n;i++)
{
p2[i] = p1[i];
}
......@@ -920,11 +920,11 @@ fftpack_exec_1d (fftpack_t fft,
* Elements 2*n .. 4*n-1 are internal FFTPACK work space.
*/
if(dir == FFTPACK_FORWARD)
if (dir == FFTPACK_FORWARD)
{
fftpack_cfftf1(n,(RealOpenMM *)out_data,fft->work+2*n,fft->work,fft->ifac, -1);
}
else if(dir == FFTPACK_BACKWARD)
else if (dir == FFTPACK_BACKWARD)
{
fftpack_cfftf1(n,(RealOpenMM *)out_data,fft->work+2*n,fft->work,fft->ifac, 1);
}
......@@ -957,7 +957,7 @@ fftpack_exec_2d (fftpack_t fft,
* by copying data to the output array first.
* For 2D there is likely enough data to benefit from memcpy().
*/
if( in_data != out_data )
if (in_data != out_data)
{
memcpy(out_data,in_data,sizeof(t_complex)*nx*ny);
}
......@@ -966,7 +966,7 @@ fftpack_exec_2d (fftpack_t fft,
data = (t_complex *)out_data;
/* y transforms */
for(i=0;i<nx;i++)
for (i=0;i<nx;i++)
{
fftpack_exec_1d(fft->next,dir,data+i*ny,data+i*ny);
}
......@@ -975,7 +975,7 @@ fftpack_exec_2d (fftpack_t fft,
fftpack_transpose_2d(data,data,nx,ny);
/* x transforms */
for(i=0;i<ny;i++)
for (i=0;i<ny;i++)
{
fftpack_exec_1d(fft,dir,data+i*nx,data+i*nx);
}
......@@ -1007,7 +1007,7 @@ fftpack_exec_3d (fftpack_t fft,
* by copying data to the output array first.
* For 3D there is likely enough data to benefit from memcpy().
*/
if( in_data != out_data )
if (in_data != out_data)
{
memcpy(out_data,in_data,sizeof(t_complex)*nx*ny*nz);
}
......@@ -1016,23 +1016,23 @@ fftpack_exec_3d (fftpack_t fft,
data = (t_complex *)out_data;
/* Perform z transforms */
for(i=0;i<nx*ny;i++)
for (i=0;i<nx*ny;i++)
fftpack_exec_1d(fft->next->next,dir,data+i*nz,data+i*nz);
/* For each X slice, transpose the y & z dimensions inside the slice */
for(i=0;i<nx;i++)
for (i=0;i<nx;i++)
{
fftpack_transpose_2d(data+i*ny*nz,data+i*ny*nz,ny,nz);
}
/* Array is now (nx,nz,ny) - perform y transforms */
for(i=0;i<nx*nz;i++)
for (i=0;i<nx*nz;i++)
{
fftpack_exec_1d(fft->next,dir,data+i*ny,data+i*ny);
}
/* Transpose back to (nx,ny,nz) */
for(i=0;i<nx;i++)
for (i=0;i<nx;i++)
{
fftpack_transpose_2d(data+i*ny*nz,data+i*ny*nz,nz,ny);
}
......@@ -1041,26 +1041,26 @@ fftpack_exec_3d (fftpack_t fft,
* (nx,ny,nz) to (ny,nx,nz).
*/
rc=fftpack_transpose_2d_nelem(data,data,nx,ny,nz);
if( rc != 0)
if (rc != 0)
{
fprintf(stderr,"Fatal error - cannot transpose X & Y/Z in fftpack_exec_3d().");
return rc;
}
/* Then go from (ny,nx,nz) to (ny,nz,nx) */
for(i=0;i<ny;i++)
for (i=0;i<ny;i++)
{
fftpack_transpose_2d(data+i*nx*nz,data+i*nx*nz,nx,nz);
}
/* Perform x transforms */
for(i=0;i<ny*nz;i++)
for (i=0;i<ny*nz;i++)
{
fftpack_exec_1d(fft,dir,data+i*nx,data+i*nx);
}
/* Transpose back from (ny,nz,nx) to (ny,nx,nz) */
for(i=0;i<ny;i++)
for (i=0;i<ny;i++)
{
fftpack_transpose_2d(data+i*nz*nx,data+i*nz*nx,nz,nx);
}
......@@ -1068,7 +1068,7 @@ fftpack_exec_3d (fftpack_t fft,
/* Transpose from (ny,nx,nz) to (nx,ny,nz).
*/
rc = fftpack_transpose_2d_nelem(data,data,ny,nx,nz);
if( rc != 0)
if (rc != 0)
{
fprintf(stderr,"Fatal error - cannot transpose Y/Z & X in fftpack_exec_3d().");
return rc;
......@@ -1082,10 +1082,10 @@ fftpack_exec_3d (fftpack_t fft,
void
fftpack_destroy(fftpack_t fft)
{
if(fft != NULL)
if (fft != NULL)
{
free(fft->work);
if(fft->next != NULL)
if (fft->next != NULL)
fftpack_destroy(fft->next);
free(fft);
}
......
/* Portions copyright (c) 2006 Stanford University and Simbios.
* Contributors: Pande Group
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "SimTKOpenMMCommon.h"
// static settings
// initialization of static data members
const std::string SimTKOpenMMCommon::NotSet = std::string( "NotSet" );
const std::string SimTKOpenMMCommon::Comment = std::string( "#" );
const std::string SimTKOpenMMCommon::Tab = std::string( "\t" );
const int SimTKOpenMMCommon::DefaultReturn = 0;
const int SimTKOpenMMCommon::ErrorReturn = -1;
const RealOpenMM SimTKOpenMMCommon::BigCutoffValue = 1.0e+05;
/* Portions copyright (c) 2006 Stanford University and Simbios.
* Contributors: Pande Group
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "SimTKOpenMMLog.h"
#include <stdlib.h>
#include "openmm/OpenMMException.h"
// static settings
SimTKOpenMMLog* SimTKOpenMMLog::_simTKOpenMMLog = NULL;
/**---------------------------------------------------------------------------------------
SimTKOpenMMLog constructor (Simbios)
@param logFile file reference for logging
--------------------------------------------------------------------------------------- */
SimTKOpenMMLog::SimTKOpenMMLog( FILE* logFile ) : _logFile( logFile ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nSimTKOpenMMLog::SimTKOpenMMLog";
// ---------------------------------------------------------------------------------------
_logLevel = LogLowLevel;
}
/**---------------------------------------------------------------------------------------
SimTKOpenMMLog destructor (Simbios)
--------------------------------------------------------------------------------------- */
SimTKOpenMMLog::~SimTKOpenMMLog( ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nSimTKOpenMMLog::~SimTKOpenMMLog";
// ---------------------------------------------------------------------------------------
}
/**---------------------------------------------------------------------------------------
Get LogFile
@return logFile
--------------------------------------------------------------------------------------- */
FILE* SimTKOpenMMLog::getLogFile( void ) const {
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nSimTKOpenMMLog::getLogFile";
// ---------------------------------------------------------------------------------------
return _logFile;
}
/**---------------------------------------------------------------------------------------
Set LogFile
@param input logFile
--------------------------------------------------------------------------------------- */
void SimTKOpenMMLog::setLogFile( FILE* logFile ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nSimTKOpenMMLog::setLogFile";
// ---------------------------------------------------------------------------------------
_logFile = logFile;
}
/**---------------------------------------------------------------------------------------
Set LogLevel
@param input logLevel
--------------------------------------------------------------------------------------- */
void SimTKOpenMMLog::setLogLevel( SimTKOpenMMLog::LogLevels logLevel ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nSimTKOpenMMLog::setLogLevel";
// ---------------------------------------------------------------------------------------
_logLevel = logLevel;
}
/**---------------------------------------------------------------------------------------
SimTKOpenMMLog log message to log (Simbios)
@param message message to log
--------------------------------------------------------------------------------------- */
void SimTKOpenMMLog::logMessage( const std::stringstream& message ) const {
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nSimTKOpenMMLog::logMessage";
// ---------------------------------------------------------------------------------------
if( _logFile ){
// (void) fprintf( stderr, "%s", message.str().c_str() );
// (void) fflush( stderr );
(void) fprintf( _logFile, "%s", message.str().c_str() );
(void) fflush( _logFile );
}
}
/**---------------------------------------------------------------------------------------
Set global simTKOpenMMLog (Simbios)
@param logFile file to log to
@return new SimTKOpenMMLog
--------------------------------------------------------------------------------------- */
SimTKOpenMMLog* SimTKOpenMMLog::setSimTKOpenMMLog( FILE* logFile ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nSimTKOpenMMLog::setSimTKOpenMMLog";
// ---------------------------------------------------------------------------------------
// allow for multiple logs
/*
if( _simTKOpenMMLog ){
delete _simTKOpenMMLog;
}
*/
_simTKOpenMMLog = new SimTKOpenMMLog( logFile );
return _simTKOpenMMLog;
}
/**---------------------------------------------------------------------------------------
Get global simTKOpenMMLog -- static method (Simbios)
@return static member
--------------------------------------------------------------------------------------- */
SimTKOpenMMLog* SimTKOpenMMLog::getSimTKOpenMMLog( void ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nSimTKOpenMMLog::getSimTKOpenMMLog";
// ---------------------------------------------------------------------------------------
if( !_simTKOpenMMLog ){
_simTKOpenMMLog = new SimTKOpenMMLog( );
}
return _simTKOpenMMLog;
}
/**---------------------------------------------------------------------------------------
Get global simTKOpenMMLog (Simbios)
@return FILE reference
--------------------------------------------------------------------------------------- */
FILE* SimTKOpenMMLog::getSimTKOpenMMLogFile( void ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nSimTKOpenMMLog::getSimTKOpenMMLogFile";
// ---------------------------------------------------------------------------------------
SimTKOpenMMLog* simTKOpenMMLog = getSimTKOpenMMLog( );
return simTKOpenMMLog->getLogFile();
}
/**---------------------------------------------------------------------------------------
Static method to print message (Simbios)
@param message message to log
--------------------------------------------------------------------------------------- */
void SimTKOpenMMLog::printMessage( const std::stringstream& message ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nSimTKOpenMMLog::printMessage";
// ---------------------------------------------------------------------------------------
if( _simTKOpenMMLog ){
_simTKOpenMMLog->logMessage( message );
} else {
(void) fprintf( stderr, "%s", message.str().c_str() );
(void) fflush( stderr );
}
}
/**---------------------------------------------------------------------------------------
Static method to print warning message (Simbios)
If global _simTKOpenMMLog is not set, then print to stderr
@param message message to log
--------------------------------------------------------------------------------------- */
void SimTKOpenMMLog::printWarning( const std::stringstream& message ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nSimTKOpenMMLog::printWarning";
// ---------------------------------------------------------------------------------------
if( _simTKOpenMMLog ){
std::stringstream messageWithHeader;
messageWithHeader << "Warning: " << message.str();
_simTKOpenMMLog->logMessage( messageWithHeader );
} else {
(void) fprintf( stderr, "Warning: %s", message.str().c_str() );
}
}
/**---------------------------------------------------------------------------------------
Static method to print error message and exit program (Simbios)
If global _simTKOpenMMLog is not set, then print to stderr
@param message message to log
--------------------------------------------------------------------------------------- */
void SimTKOpenMMLog::printError( const std::stringstream& message ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nSimTKOpenMMLog::printError";
// ---------------------------------------------------------------------------------------
std::stringstream messageWithHeader;
messageWithHeader << "Error: " << message.str();
if( _simTKOpenMMLog ){
_simTKOpenMMLog->logMessage( messageWithHeader );
} else {
(void) fprintf( stderr, "%s", messageWithHeader.str().c_str() );
(void) fflush( stderr );
}
throw OpenMM::OpenMMException(messageWithHeader.str());
}
......@@ -473,7 +473,7 @@ void testExclusions() {
// create custom GB/VI force
static CustomGBForce* createCustomGBVI( double solventDielectric, double soluteDielectric ) {
static CustomGBForce* createCustomGBVI(double solventDielectric, double soluteDielectric) {
CustomGBForce* customGbviForce = new CustomGBForce();
......@@ -524,7 +524,7 @@ static CustomGBForce* createCustomGBVI( double solventDielectric, double soluteD
// ethance GB/VI test case
static void buildEthane( GBVIForce* gbviForce, std::vector<Vec3>& positions ) {
static void buildEthane(GBVIForce* gbviForce, std::vector<Vec3>& positions) {
const int numParticles = 8;
......@@ -535,7 +535,7 @@ static void buildEthane( GBVIForce* gbviForce, std::vector<Vec3>& positions ) {
int AM1_BCC = 1;
H_charge = -0.053;
C_charge = -3.0*H_charge;
if( AM1_BCC ){
if (AM1_BCC) {
C_radius = 0.180;
C_gamma = -0.2863;
H_radius = 0.125;
......@@ -548,43 +548,43 @@ static void buildEthane( GBVIForce* gbviForce, std::vector<Vec3>& positions ) {
H_gamma = 0.1237;
}
for( int i = 0; i < numParticles; i++ ){
gbviForce->addParticle( H_charge, H_radius, H_gamma);
for (int i = 0; i < numParticles; i++) {
gbviForce->addParticle(H_charge, H_radius, H_gamma);
}
gbviForce->setParticleParameters( 1, C_charge, C_radius, C_gamma);
gbviForce->setParticleParameters( 4, C_charge, C_radius, C_gamma);
gbviForce->setParticleParameters(1, C_charge, C_radius, C_gamma);
gbviForce->setParticleParameters(4, C_charge, C_radius, C_gamma);
gbviForce->addBond( 0, 1, C_HBondDistance );
gbviForce->addBond( 2, 1, C_HBondDistance );
gbviForce->addBond( 3, 1, C_HBondDistance );
gbviForce->addBond( 1, 4, C_CBondDistance );
gbviForce->addBond( 5, 4, C_HBondDistance );
gbviForce->addBond( 6, 4, C_HBondDistance );
gbviForce->addBond( 7, 4, C_HBondDistance );
gbviForce->addBond(0, 1, C_HBondDistance);
gbviForce->addBond(2, 1, C_HBondDistance);
gbviForce->addBond(3, 1, C_HBondDistance);
gbviForce->addBond(1, 4, C_CBondDistance);
gbviForce->addBond(5, 4, C_HBondDistance);
gbviForce->addBond(6, 4, C_HBondDistance);
gbviForce->addBond(7, 4, C_HBondDistance);
std::vector<pair<int, int> > bondExceptions;
std::vector<double> bondDistances;
bondExceptions.push_back(pair<int, int>(0, 1));
bondDistances.push_back( C_HBondDistance );
bondDistances.push_back(C_HBondDistance);
bondExceptions.push_back(pair<int, int>(2, 1));
bondDistances.push_back( C_HBondDistance );
bondDistances.push_back(C_HBondDistance);
bondExceptions.push_back(pair<int, int>(3, 1));
bondDistances.push_back( C_HBondDistance );
bondDistances.push_back(C_HBondDistance);
bondExceptions.push_back(pair<int, int>(1, 4));
bondDistances.push_back( C_CBondDistance );
bondDistances.push_back(C_CBondDistance);
bondExceptions.push_back(pair<int, int>(5, 4));
bondDistances.push_back( C_HBondDistance );
bondDistances.push_back(C_HBondDistance);
bondExceptions.push_back(pair<int, int>(6, 4));
bondDistances.push_back( C_HBondDistance );
bondDistances.push_back(C_HBondDistance);
bondExceptions.push_back(pair<int, int>(7, 4));
bondDistances.push_back( C_HBondDistance );
bondDistances.push_back(C_HBondDistance);
positions.resize(numParticles);
positions[0] = Vec3(0.5480, 1.7661, 0.0000);
......@@ -600,7 +600,7 @@ static void buildEthane( GBVIForce* gbviForce, std::vector<Vec3>& positions ) {
// dimer GB/VI test case
static void buildDimer( GBVIForce* gbviForce, std::vector<Vec3>& positions ) {
static void buildDimer(GBVIForce* gbviForce, std::vector<Vec3>& positions) {
const int numParticles = 2;
......@@ -614,7 +614,7 @@ static void buildDimer( GBVIForce* gbviForce, std::vector<Vec3>& positions ) {
H_charge = 0.0;
C_charge = 0.0;
if( AM1_BCC ){
if (AM1_BCC) {
C_radius = 0.180;
C_gamma = -0.2863;
H_radius = 0.125;
......@@ -627,17 +627,17 @@ static void buildDimer( GBVIForce* gbviForce, std::vector<Vec3>& positions ) {
H_gamma = 0.1237;
}
for( int i = 0; i < numParticles; i++ ){
gbviForce->addParticle( H_charge, H_radius, H_gamma);
for (int i = 0; i < numParticles; i++) {
gbviForce->addParticle(H_charge, H_radius, H_gamma);
}
gbviForce->setParticleParameters( 1, C_charge, C_radius, C_gamma);
gbviForce->setParticleParameters(1, C_charge, C_radius, C_gamma);
gbviForce->addBond( 0, 1, C_HBondDistance );
gbviForce->addBond(0, 1, C_HBondDistance);
std::vector<pair<int, int> > bondExceptions;
std::vector<double> bondDistances;
bondExceptions.push_back(pair<int, int>(0, 1));
bondDistances.push_back( C_HBondDistance );
bondDistances.push_back(C_HBondDistance);
positions.resize(numParticles);
positions[0] = Vec3(0.0, 0.0, 0.0);
......@@ -646,7 +646,7 @@ static void buildDimer( GBVIForce* gbviForce, std::vector<Vec3>& positions ) {
// monomer GB/VI test case
static void buildMonomer( GBVIForce* gbviForce, std::vector<Vec3>& positions ) {
static void buildMonomer(GBVIForce* gbviForce, std::vector<Vec3>& positions) {
const int numParticles = 1;
......@@ -656,8 +656,8 @@ static void buildMonomer( GBVIForce* gbviForce, std::vector<Vec3>& positions ) {
H_radius = 0.125;
H_gamma = 0.2437;
for( int i = 0; i < numParticles; i++ ){
gbviForce->addParticle( H_charge, H_radius, H_gamma);
for (int i = 0; i < numParticles; i++) {
gbviForce->addParticle(H_charge, H_radius, H_gamma);
}
positions.resize(numParticles);
positions[0] = Vec3(0.0, 0.0, 0.0);
......@@ -666,7 +666,7 @@ static void buildMonomer( GBVIForce* gbviForce, std::vector<Vec3>& positions ) {
// taken from gbviForceImpl class
// computes the scaled radii based on covalent info and atomic radii
static void findScaledRadii( GBVIForce& gbviForce, std::vector<double> & scaledRadii) {
static void findScaledRadii(GBVIForce& gbviForce, std::vector<double> & scaledRadii) {
int numberOfParticles = gbviForce.getNumParticles();
int numberOfBonds = gbviForce.getNumBonds();
......@@ -674,15 +674,11 @@ static void findScaledRadii( GBVIForce& gbviForce, std::vector<double> & scaledR
// load 1-2 atom pairs along w/ bond distance using HarmonicBondForce & constraints
// numberOfBonds < 1, indicating they were not set by the user
if( numberOfBonds < 1 && numberOfParticles > 1 ){
(void) fprintf( stderr, "Warning: no covalent bonds set for GB/VI force!\n" );
}
std::vector< std::vector<int> > bondIndices;
bondIndices.resize( numberOfBonds );
bondIndices.resize(numberOfBonds);
std::vector<double> bondLengths;
bondLengths.resize( numberOfBonds );
bondLengths.resize(numberOfBonds);
scaledRadii.resize(numberOfParticles);
for (int i = 0; i < numberOfParticles; i++) {
......@@ -707,14 +703,14 @@ static void findScaledRadii( GBVIForce& gbviForce, std::vector<double> & scaledR
msg << particle2;
throw OpenMMException(msg.str());
}
if (bondLength < 0 ) {
if (bondLength < 0) {
std::stringstream msg;
msg << "GBVISoftcoreForce: negative bondlength: ";
msg << bondLength;
throw OpenMMException(msg.str());
}
bondIndices[i].push_back( particle1 );
bondIndices[i].push_back( particle2 );
bondIndices[i].push_back(particle1);
bondIndices[i].push_back(particle2);
bondLengths[i] = bondLength;
}
......@@ -732,7 +728,7 @@ static void findScaledRadii( GBVIForce& gbviForce, std::vector<double> & scaledR
// compute scaled radii (Eq. 5 of Labute paper [JCC 29 p. 1693-1698 2008])
for (int j = 0; j < (int) bonded12.size(); ++j){
for (int j = 0; j < (int) bonded12.size(); ++j) {
double charge;
double gamma;
......@@ -741,10 +737,7 @@ static void findScaledRadii( GBVIForce& gbviForce, std::vector<double> & scaledR
gbviForce.getParticleParameters(j, charge, radiusJ, gamma);
if( bonded12[j].size() == 0 ){
if( numberOfParticles > 1 ){
(void) fprintf( stderr, "Warning GBVIForceImpl::findScaledRadii atom %d has no covalent bonds; using atomic radius=%.3f.\n", j, radiusJ );
}
if ( bonded12[j].size() == 0) {
scaledRadiusJ = radiusJ;
// errors++;
}
......@@ -755,7 +748,7 @@ static void findScaledRadii( GBVIForce& gbviForce, std::vector<double> & scaledR
// loop over bonded neighbors of atom j, applying Eq. 5 in Labute
scaledRadiusJ = 0.0;
for (int i = 0; i < (int) bonded12[j].size(); ++i){
for (int i = 0; i < (int) bonded12[j].size(); ++i) {
int index = bonded12[j][i];
int bondedAtomIndex = (j == bondIndices[index][0]) ? bondIndices[index][1] : bondIndices[index][0];
......@@ -772,54 +765,33 @@ static void findScaledRadii( GBVIForce& gbviForce, std::vector<double> & scaledR
a_ji *= a_ji;
a_ji = (rI2 - a_ji)/(2.0*bondLengths[index]);
scaledRadiusJ += a_ij*a_ij*(3.0*radiusI - a_ij) + a_ji*a_ji*( 3.0*radiusJ - a_ji );
scaledRadiusJ += a_ij*a_ij*(3.0*radiusI - a_ij) + a_ji*a_ji*(3.0*radiusJ - a_ji);
}
scaledRadiusJ = (radiusJ*radiusJ*radiusJ) - 0.125*scaledRadiusJ;
if( scaledRadiusJ > 0.0 ){
scaledRadiusJ = 0.95*pow( scaledRadiusJ, (1.0/3.0) );
if (scaledRadiusJ > 0.0) {
scaledRadiusJ = 0.95*pow(scaledRadiusJ, (1.0/3.0));
}
else {
scaledRadiusJ = 0.0;
}
}
//(void) fprintf( stderr, "scaledRadii %d %12.4f\n", j, scaledRadiusJ );
scaledRadii[j] = scaledRadiusJ;
}
// abort if errors
if( errors ){
if (errors) {
throw OpenMMException("GBVIForceImpl::findScaledRadii errors -- aborting");
}
#if GBVIDebug
(void) fprintf( stderr, " R q gamma scaled radii no. bnds\n" );
double totalQ = 0.0;
for( int i = 0; i < (int) scaledRadii.size(); i++ ){
double charge;
double gamma;
double radiusI;
gbviForce.getParticleParameters(i, charge, radiusI, gamma);
totalQ += charge;
(void) fprintf( stderr, "%4d %14.5e %14.5e %14.5e %14.5e %d\n", i, radiusI, charge, gamma, scaledRadii[i], (int) bonded12[i].size() );
}
(void) fprintf( stderr, "Total charge=%e\n", totalQ );
(void) fflush( stderr );
#endif
#undef GBVIDebug
}
// load parameters from gbviForce to customGbviForce
// findScaledRadii() is called to calculate the scaled radii (S)
// S is derived quantity in GBVIForce, not a parameter is the case here
static void loadGbviParameters( GBVIForce* gbviForce, CustomGBForce* customGbviForce ) {
static void loadGbviParameters(GBVIForce* gbviForce, CustomGBForce* customGbviForce) {
int numParticles = gbviForce->getNumParticles();
......@@ -827,11 +799,11 @@ static void loadGbviParameters( GBVIForce* gbviForce, CustomGBForce* customGbviF
vector<double> params(4);
std::vector<double> scaledRadii;
findScaledRadii( *gbviForce, scaledRadii);
findScaledRadii(*gbviForce, scaledRadii);
for( int ii = 0; ii < numParticles; ii++) {
for (int ii = 0; ii < numParticles; ii++) {
double charge, radius, gamma;
gbviForce->getParticleParameters( ii, charge, radius, gamma );
gbviForce->getParticleParameters(ii, charge, radius, gamma);
params[0] = charge;
params[1] = radius;
params[2] = scaledRadii[ii];
......@@ -852,14 +824,14 @@ void testGBVI(GBVIForce::NonbondedMethod gbviMethod, CustomGBForce::NonbondedMet
// select molecule
if( molecule == "Monomer" ){
buildMonomer( gbvi, positions );
if (molecule == "Monomer") {
buildMonomer(gbvi, positions);
}
else if( molecule == "Dimer" ){
buildDimer( gbvi, positions );
else if (molecule == "Dimer") {
buildDimer(gbvi, positions);
}
else {
buildEthane( gbvi, positions );
buildEthane(gbvi, positions);
}
int numParticles = gbvi->getNumParticles();
......@@ -875,12 +847,12 @@ void testGBVI(GBVIForce::NonbondedMethod gbviMethod, CustomGBForce::NonbondedMet
// create customGbviForce GBVI force
CustomGBForce* customGbviForce = createCustomGBVI( gbvi->getSolventDielectric(), gbvi->getSoluteDielectric() );
CustomGBForce* customGbviForce = createCustomGBVI(gbvi->getSolventDielectric(), gbvi->getSoluteDielectric());
customGbviForce->setCutoffDistance(2.0);
// load parameters from gbvi to customGbviForce
loadGbviParameters( gbvi, customGbviForce );
loadGbviParameters(gbvi, customGbviForce);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
......
......@@ -53,7 +53,6 @@ using namespace std;
const double TOL = 1e-5;
void testSingleParticle() {
const int log = 0;
ReferencePlatform platform;
System system;
system.addParticle(2.0);
......@@ -80,24 +79,19 @@ void testSingleParticle() {
double tau = (1.0/forceField->getSoluteDielectric()-1.0/forceField->getSolventDielectric());
double bornEnergy = (-charge*charge/(8*PI_M*eps0))*tau/bornRadius;
double nonpolarEnergy = -gamma*tau*std::pow( radius/bornRadius, 3.0);
double nonpolarEnergy = -gamma*tau*std::pow(radius/bornRadius, 3.0);
double expectedE = (bornEnergy+nonpolarEnergy);
double obtainedE = state.getPotentialEnergy();
double diff = fabs( (obtainedE - expectedE)/expectedE );
if( log ){
(void) fprintf( stderr, "testSingleParticle expected=%14.6e obtained=%14.6e diff=%14.6e breakdown:[%14.6e %14.6e]\n",
expectedE, obtainedE, diff, bornEnergy, nonpolarEnergy );
}
double diff = fabs((obtainedE - expectedE)/expectedE);
ASSERT_EQUAL_TOL((bornEnergy+nonpolarEnergy), state.getPotentialEnergy(), 0.01);
}
void testEnergyEthane( int applyBornRadiiScaling ) {
void testEnergyEthane(int applyBornRadiiScaling) {
ReferencePlatform platform;
const int numParticles = 8;
const int log = 0;
System system;
LangevinIntegrator integrator(0, 0.1, 0.01);
......@@ -123,7 +117,7 @@ void testEnergyEthane( int applyBornRadiiScaling ) {
int AM1_BCC = 1;
H_charge = -0.053;
C_charge = -3.0*H_charge;
if( AM1_BCC ){
if (AM1_BCC) {
C_radius = 0.180;
C_gamma = -0.2863;
H_radius = 0.125;
......@@ -139,59 +133,56 @@ void testEnergyEthane( int applyBornRadiiScaling ) {
NonbondedForce* nonbonded = new NonbondedForce();
nonbonded->setNonbondedMethod(NonbondedForce::NoCutoff);
if( log ){
(void) fprintf( stderr, "Applying GB/VI\n" );
}
GBVIForce* forceField = new GBVIForce();
if( applyBornRadiiScaling ){
forceField->setBornRadiusScalingMethod( GBVIForce::QuinticSpline );
if (applyBornRadiiScaling) {
forceField->setBornRadiusScalingMethod(GBVIForce::QuinticSpline);
}
else {
forceField->setBornRadiusScalingMethod( GBVIForce::NoScaling );
forceField->setBornRadiusScalingMethod(GBVIForce::NoScaling);
}
for( int i = 0; i < numParticles; i++ ){
for (int i = 0; i < numParticles; i++) {
system.addParticle(1.0);
forceField->addParticle( H_charge, H_radius, H_gamma);
nonbonded->addParticle( H_charge, H_radius, 0.0);
forceField->addParticle(H_charge, H_radius, H_gamma);
nonbonded->addParticle( H_charge, H_radius, 0.0);
}
forceField->setParticleParameters( 1, C_charge, C_radius, C_gamma);
forceField->setParticleParameters( 4, C_charge, C_radius, C_gamma);
forceField->setParticleParameters(1, C_charge, C_radius, C_gamma);
forceField->setParticleParameters(4, C_charge, C_radius, C_gamma);
nonbonded->setParticleParameters( 1, C_charge, C_radius, 0.0);
nonbonded->setParticleParameters( 4, C_charge, C_radius, 0.0);
nonbonded->setParticleParameters( 1, C_charge, C_radius, 0.0);
nonbonded->setParticleParameters( 4, C_charge, C_radius, 0.0);
forceField->addBond( 0, 1, C_HBondDistance );
forceField->addBond( 2, 1, C_HBondDistance );
forceField->addBond( 3, 1, C_HBondDistance );
forceField->addBond( 1, 4, C_CBondDistance );
forceField->addBond( 5, 4, C_HBondDistance );
forceField->addBond( 6, 4, C_HBondDistance );
forceField->addBond( 7, 4, C_HBondDistance );
forceField->addBond(0, 1, C_HBondDistance);
forceField->addBond(2, 1, C_HBondDistance);
forceField->addBond(3, 1, C_HBondDistance);
forceField->addBond(1, 4, C_CBondDistance);
forceField->addBond(5, 4, C_HBondDistance);
forceField->addBond(6, 4, C_HBondDistance);
forceField->addBond(7, 4, C_HBondDistance);
std::vector<pair<int, int> > bondExceptions;
std::vector<double> bondDistances;
bondExceptions.push_back(pair<int, int>(0, 1));
bondDistances.push_back( C_HBondDistance );
bondDistances.push_back(C_HBondDistance);
bondExceptions.push_back(pair<int, int>(2, 1));
bondDistances.push_back( C_HBondDistance );
bondDistances.push_back(C_HBondDistance);
bondExceptions.push_back(pair<int, int>(3, 1));
bondDistances.push_back( C_HBondDistance );
bondDistances.push_back(C_HBondDistance);
bondExceptions.push_back(pair<int, int>(1, 4));
bondDistances.push_back( C_CBondDistance );
bondDistances.push_back(C_CBondDistance);
bondExceptions.push_back(pair<int, int>(5, 4));
bondDistances.push_back( C_HBondDistance );
bondDistances.push_back(C_HBondDistance);
bondExceptions.push_back(pair<int, int>(6, 4));
bondDistances.push_back( C_HBondDistance );
bondDistances.push_back(C_HBondDistance);
bondExceptions.push_back(pair<int, int>(7, 4));
bondDistances.push_back( C_HBondDistance );
bondDistances.push_back(C_HBondDistance);
nonbonded->createExceptionsFromBonds(bondExceptions, 0.0, 0.0);
......@@ -212,9 +203,6 @@ void testEnergyEthane( int applyBornRadiiScaling ) {
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
if( log ){
(void) fprintf( stderr, "Energy %.4e\n", state.getPotentialEnergy() );
}
// Take a small step in the direction of the energy gradient.
......@@ -222,18 +210,12 @@ void testEnergyEthane( int applyBornRadiiScaling ) {
double forceSum[3] = { 0.0, 0.0, 0.0 };
for (int i = 0; i < numParticles; ++i) {
Vec3 f = state.getForces()[i];
if( log ){
(void) fprintf( stderr, "F %d [%14.6e %14.6e %14.6e]\n", i, f[0], f[1], f[2] );
}
norm += f[0]*f[0] + f[1]*f[1] + f[2]*f[2];
forceSum[0] += f[0];
forceSum[1] += f[1];
forceSum[2] += f[2];
}
norm = std::sqrt(norm);
if( log ){
(void) fprintf( stderr, "Fsum [%14.6e %14.6e %14.6e] norm=%14.6e\n", forceSum[0], forceSum[1], forceSum[2], norm );
}
const double delta = 1e-4;
double step = delta/norm;
......@@ -246,12 +228,6 @@ void testEnergyEthane( int applyBornRadiiScaling ) {
State state2 = context.getState(State::Energy);
if( log ){
double deltaE = fabs( state.getPotentialEnergy() - state2.getPotentialEnergy() )/delta;
double diff = (deltaE - norm)/norm;
(void) fprintf( stderr, "Energies %.8e %.8e deltaE=%14.7e %14.7e diff=%14.7e\n", state.getPotentialEnergy(), state2.getPotentialEnergy(), deltaE, norm, diff );
}
// See whether the potential energy changed by the expected amount.
ASSERT_EQUAL_TOL(norm, (state2.getPotentialEnergy()-state.getPotentialEnergy())/delta, 0.01)
......@@ -260,8 +236,8 @@ void testEnergyEthane( int applyBornRadiiScaling ) {
int main() {
try {
testSingleParticle();
testEnergyEthane( 0 );
testEnergyEthane( 1 );
testEnergyEthane(0);
testEnergyEthane(1);
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
......
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