Commit c27f5d1f authored by Peter Eastman's avatar Peter Eastman
Browse files

Continuing refactoring of the reference platform

parent 0843c5f3
...@@ -30,13 +30,8 @@ ...@@ -30,13 +30,8 @@
#include "../SimTKUtilities/SimTKOpenMMLog.h" #include "../SimTKUtilities/SimTKOpenMMLog.h"
#include "../SimTKUtilities/SimTKOpenMMUtilities.h" #include "../SimTKUtilities/SimTKOpenMMUtilities.h"
// #define UseGromacsMalloc 1 using std::vector;
using OpenMM::RealVec;
#ifdef UseGromacsMalloc
extern "C" {
#include "smalloc.h"
}
#endif
const std::string GBVIParameters::ParameterFileName = std::string( "params.agb" ); const std::string GBVIParameters::ParameterFileName = std::string( "params.agb" );
...@@ -516,7 +511,7 @@ RealOpenMM GBVIParameters::getCutoffDistance() { ...@@ -516,7 +511,7 @@ RealOpenMM GBVIParameters::getCutoffDistance() {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int GBVIParameters::setPeriodic( RealOpenMM* boxSize ) { int GBVIParameters::setPeriodic( RealVec& boxSize ) {
assert(cutoff); assert(cutoff);
assert(boxSize[0] >= 2.0*cutoffDistance); assert(boxSize[0] >= 2.0*cutoffDistance);
......
...@@ -241,7 +241,7 @@ class GBVIParameters : public ImplicitSolventParameters { ...@@ -241,7 +241,7 @@ class GBVIParameters : public ImplicitSolventParameters {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int setPeriodic( RealOpenMM* boxSize ); int setPeriodic( OpenMM::RealVec& boxSize );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
......
...@@ -30,13 +30,8 @@ ...@@ -30,13 +30,8 @@
#include "../SimTKUtilities/SimTKOpenMMLog.h" #include "../SimTKUtilities/SimTKOpenMMLog.h"
#include "../SimTKUtilities/SimTKOpenMMUtilities.h" #include "../SimTKUtilities/SimTKOpenMMUtilities.h"
// #define UseGromacsMalloc 1 using std::vector;
using OpenMM::RealVec;
#ifdef UseGromacsMalloc
extern "C" {
#include "smalloc.h"
}
#endif
const std::string ObcParameters::ParameterFileName = std::string( "params.agb" ); const std::string ObcParameters::ParameterFileName = std::string( "params.agb" );
...@@ -619,7 +614,7 @@ RealOpenMM ObcParameters::getCutoffDistance() { ...@@ -619,7 +614,7 @@ RealOpenMM ObcParameters::getCutoffDistance() {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int ObcParameters::setPeriodic( RealOpenMM* boxSize ) { int ObcParameters::setPeriodic( RealVec& boxSize ) {
assert(cutoff); assert(cutoff);
assert(boxSize[0] >= 2.0*cutoffDistance); assert(boxSize[0] >= 2.0*cutoffDistance);
......
...@@ -321,7 +321,7 @@ class ObcParameters : public ImplicitSolventParameters { ...@@ -321,7 +321,7 @@ class ObcParameters : public ImplicitSolventParameters {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int setPeriodic( RealOpenMM* boxSize ); int setPeriodic( OpenMM::RealVec& boxSize );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
......
...@@ -48,16 +48,17 @@ void testNeighborList() ...@@ -48,16 +48,17 @@ void testNeighborList()
NeighborList neighborList; NeighborList neighborList;
computeNeighborListNaive(neighborList, 2, particleList, exclusions, NULL, 13.7, 0.01); RealVec boxSize;
computeNeighborListNaive(neighborList, 2, particleList, exclusions, boxSize, false, 13.7, 0.01);
assert(neighborList.size() == 1); assert(neighborList.size() == 1);
computeNeighborListNaive(neighborList, 2, particleList, exclusions, NULL, 13.5, 0.01); computeNeighborListNaive(neighborList, 2, particleList, exclusions, boxSize, false, 13.5, 0.01);
assert(neighborList.size() == 0); assert(neighborList.size() == 0);
computeNeighborListVoxelHash(neighborList, 2, particleList, exclusions, NULL, 13.7, 0.01); computeNeighborListVoxelHash(neighborList, 2, particleList, exclusions, boxSize, false, 13.7, 0.01);
assert(neighborList.size() == 1); assert(neighborList.size() == 1);
computeNeighborListVoxelHash(neighborList, 2, particleList, exclusions, NULL, 13.5, 0.01); computeNeighborListVoxelHash(neighborList, 2, particleList, exclusions, boxSize, false, 13.5, 0.01);
assert(neighborList.size() == 0); assert(neighborList.size() == 0);
} }
...@@ -67,14 +68,14 @@ double periodicDifference(double val1, double val2, double period) { ...@@ -67,14 +68,14 @@ double periodicDifference(double val1, double val2, double period) {
return diff-base; return diff-base;
} }
double distance2(RealVec& pos1, RealVec& pos2, const RealOpenMM* periodicBoxSize) { double distance2(RealVec& pos1, RealVec& pos2, const RealVec& periodicBoxSize) {
double dx = periodicDifference(pos1[0], pos2[0], periodicBoxSize[0]); double dx = periodicDifference(pos1[0], pos2[0], periodicBoxSize[0]);
double dy = periodicDifference(pos1[1], pos2[1], periodicBoxSize[1]); double dy = periodicDifference(pos1[1], pos2[1], periodicBoxSize[1]);
double dz = periodicDifference(pos1[2], pos2[2], periodicBoxSize[2]); double dz = periodicDifference(pos1[2], pos2[2], periodicBoxSize[2]);
return dx*dx+dy*dy+dz*dz; return dx*dx+dy*dy+dz*dz;
} }
void verifyNeighborList(NeighborList& list, int numParticles, vector<RealVec>& positions, const RealOpenMM* periodicBoxSize, double cutoff) { void verifyNeighborList(NeighborList& list, int numParticles, vector<RealVec>& positions, const RealVec& periodicBoxSize, double cutoff) {
for (int i = 0; i < (int) list.size(); i++) { for (int i = 0; i < (int) list.size(); i++) {
int particle1 = list[i].first; int particle1 = list[i].first;
int particle2 = list[i].second; int particle2 = list[i].second;
...@@ -91,7 +92,7 @@ void verifyNeighborList(NeighborList& list, int numParticles, vector<RealVec>& p ...@@ -91,7 +92,7 @@ void verifyNeighborList(NeighborList& list, int numParticles, vector<RealVec>& p
void testPeriodic() { void testPeriodic() {
const int numParticles = 100; const int numParticles = 100;
const double cutoff = 3.0; const double cutoff = 3.0;
const RealOpenMM periodicBoxSize[3] = {20.0, 15.0, 22.0}; const RealVec periodicBoxSize(20.0, 15.0, 22.0);
vector<RealVec> particleList(numParticles); vector<RealVec> particleList(numParticles);
OpenMM_SFMT::SFMT sfmt; OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt); init_gen_rand(0, sfmt);
...@@ -103,9 +104,9 @@ void testPeriodic() { ...@@ -103,9 +104,9 @@ void testPeriodic() {
} }
vector<set<int> > exclusions(numParticles); vector<set<int> > exclusions(numParticles);
NeighborList neighborList; NeighborList neighborList;
computeNeighborListNaive(neighborList, numParticles, particleList, exclusions, periodicBoxSize, cutoff); computeNeighborListNaive(neighborList, numParticles, particleList, exclusions, periodicBoxSize, true, cutoff);
verifyNeighborList(neighborList, numParticles, particleList, periodicBoxSize, cutoff); verifyNeighborList(neighborList, numParticles, particleList, periodicBoxSize, cutoff);
computeNeighborListVoxelHash(neighborList, numParticles, particleList, exclusions, periodicBoxSize, cutoff); computeNeighborListVoxelHash(neighborList, numParticles, particleList, exclusions, periodicBoxSize, true, cutoff);
verifyNeighborList(neighborList, numParticles, particleList, periodicBoxSize, cutoff); verifyNeighborList(neighborList, numParticles, particleList, periodicBoxSize, cutoff);
} }
......
...@@ -219,7 +219,7 @@ double ReferenceFreeEnergyCalcNonbondedSoftcoreForceKernel::execute(ContextImpl& ...@@ -219,7 +219,7 @@ double ReferenceFreeEnergyCalcNonbondedSoftcoreForceKernel::execute(ContextImpl&
bool ewald = (nonbondedMethod == Ewald); bool ewald = (nonbondedMethod == Ewald);
bool pme = (nonbondedMethod == PME); bool pme = (nonbondedMethod == PME);
if (nonbondedMethod != NoCutoff) { if (nonbondedMethod != NoCutoff) {
computeNeighborListVoxelHash(*neighborList, numParticles, posData, exclusions, (periodic || ewald || pme) ? periodicBoxSize : NULL, nonbondedCutoff, 0.0); computeNeighborListVoxelHash(*neighborList, numParticles, posData, exclusions, periodicBoxSize, periodic || ewald || pme, nonbondedCutoff, 0.0);
clj.setUseCutoff(nonbondedCutoff, *neighborList, rfDielectric); clj.setUseCutoff(nonbondedCutoff, *neighborList, rfDielectric);
} }
if (periodic || ewald || pme) if (periodic || ewald || pme)
...@@ -374,7 +374,7 @@ void ReferenceFreeEnergyCalcGBVISoftcoreForceKernel::initialize(const System& sy ...@@ -374,7 +374,7 @@ void ReferenceFreeEnergyCalcGBVISoftcoreForceKernel::initialize(const System& sy
double ReferenceFreeEnergyCalcGBVISoftcoreForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceFreeEnergyCalcGBVISoftcoreForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<RealVec>& posData = extractPositions(context);
RealOpenMM* bornRadii = new RealOpenMM[context.getSystem().getNumParticles()]; vector<RealOpenMM> bornRadii(context.getSystem().getNumParticles());
gbviSoftcore->computeBornRadii(posData, bornRadii, NULL ); gbviSoftcore->computeBornRadii(posData, bornRadii, NULL );
if (includeForces) { if (includeForces) {
vector<RealVec>& forceData = extractForces(context); vector<RealVec>& forceData = extractForces(context);
...@@ -382,7 +382,6 @@ double ReferenceFreeEnergyCalcGBVISoftcoreForceKernel::execute(ContextImpl& cont ...@@ -382,7 +382,6 @@ double ReferenceFreeEnergyCalcGBVISoftcoreForceKernel::execute(ContextImpl& cont
} }
RealOpenMM energy = 0.0; RealOpenMM energy = 0.0;
if (includeEnergy) if (includeEnergy)
energy = gbviSoftcore->computeBornEnergy(bornRadii ,posData, &charges[0]); energy = gbviSoftcore->computeBornEnergy(bornRadii, posData, &charges[0]);
delete[] bornRadii;
return static_cast<double>(energy); return static_cast<double>(energy);
} }
...@@ -69,7 +69,8 @@ private: ...@@ -69,7 +69,8 @@ private:
int numParticles, num14; int numParticles, num14;
int **exclusionArray, **bonded14IndexArray; int **exclusionArray, **bonded14IndexArray;
RealOpenMM **particleParamArray, **bonded14ParamArray; RealOpenMM **particleParamArray, **bonded14ParamArray;
RealOpenMM nonbondedCutoff, periodicBoxSize[3], rfDielectric, ewaldAlpha; RealOpenMM nonbondedCutoff, rfDielectric, ewaldAlpha;
RealVec periodicBoxSize;
int kmax[3]; int kmax[3];
std::vector<std::set<int> > exclusions; std::vector<std::set<int> > exclusions;
NonbondedSoftcoreMethod nonbondedMethod; NonbondedSoftcoreMethod nonbondedMethod;
......
...@@ -108,7 +108,7 @@ ReferenceFreeEnergyLJCoulombSoftcoreIxn::~ReferenceFreeEnergyLJCoulombSoftcoreIx ...@@ -108,7 +108,7 @@ ReferenceFreeEnergyLJCoulombSoftcoreIxn::~ReferenceFreeEnergyLJCoulombSoftcoreIx
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int ReferenceFreeEnergyLJCoulombSoftcoreIxn::setPeriodic( RealOpenMM* boxSize ) { int ReferenceFreeEnergyLJCoulombSoftcoreIxn::setPeriodic( RealVec& boxSize ) {
assert(cutoff); assert(cutoff);
assert(boxSize[0] >= 2.0*cutoffDistance); assert(boxSize[0] >= 2.0*cutoffDistance);
......
...@@ -118,7 +118,7 @@ class ReferenceFreeEnergyLJCoulombSoftcoreIxn : public ReferencePairIxn { ...@@ -118,7 +118,7 @@ class ReferenceFreeEnergyLJCoulombSoftcoreIxn : public ReferencePairIxn {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int setPeriodic( RealOpenMM* boxSize ); int setPeriodic( OpenMM::RealVec& boxSize );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
#include <vector>
#include "../SimTKUtilities/SimTKOpenMMCommon.h" #include "../SimTKUtilities/SimTKOpenMMCommon.h"
#include "../SimTKUtilities/SimTKOpenMMLog.h" #include "../SimTKUtilities/SimTKOpenMMLog.h"
...@@ -243,7 +244,7 @@ int CpuGBVISoftcore::quinticSpline( RealOpenMM x, RealOpenMM rl, RealOpenMM ru, ...@@ -243,7 +244,7 @@ int CpuGBVISoftcore::quinticSpline( RealOpenMM x, RealOpenMM rl, RealOpenMM ru,
int CpuGBVISoftcore::computeBornRadiiUsingQuinticSpline( RealOpenMM atomicRadius3, RealOpenMM bornSum, int CpuGBVISoftcore::computeBornRadiiUsingQuinticSpline( RealOpenMM atomicRadius3, RealOpenMM bornSum,
GBVISoftcoreParameters* gbviParameters, GBVISoftcoreParameters* gbviParameters,
RealOpenMM* bornRadius, RealOpenMM* switchDeriviative ){ RealOpenMM& bornRadius, RealOpenMM* switchDeriviative ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -301,7 +302,7 @@ int CpuGBVISoftcore::computeBornRadiiUsingQuinticSpline( RealOpenMM atomicRadius ...@@ -301,7 +302,7 @@ int CpuGBVISoftcore::computeBornRadiiUsingQuinticSpline( RealOpenMM atomicRadius
sum = atomicRadius3 - bornSum; sum = atomicRadius3 - bornSum;
*switchDeriviative = one; *switchDeriviative = one;
} }
*bornRadius = POW( sum, minusOneThird ); bornRadius = POW( sum, minusOneThird );
return 0; return 0;
} }
...@@ -322,7 +323,7 @@ int CpuGBVISoftcore::computeBornRadiiUsingQuinticSpline( RealOpenMM atomicRadius ...@@ -322,7 +323,7 @@ int CpuGBVISoftcore::computeBornRadiiUsingQuinticSpline( RealOpenMM atomicRadius
#define GBVISoftcoreDebug 0 #define GBVISoftcoreDebug 0
int CpuGBVISoftcore::computeBornRadii( vector<RealVec>& atomCoordinates, RealOpenMM* bornRadii, RealOpenMM* switchDeriviative ){ int CpuGBVISoftcore::computeBornRadii( vector<RealVec>& atomCoordinates, vector<RealOpenMM>& bornRadii, RealOpenMM* switchDeriviative ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -402,7 +403,7 @@ if( atomI == 0 || atomI == 1 ){ ...@@ -402,7 +403,7 @@ if( atomI == 0 || atomI == 1 ){
switchDeriviative[atomI] = one; switchDeriviative[atomI] = one;
} else if( _gbviParameters->getBornRadiusScalingSoftcoreMethod() == GBVISoftcoreParameters::QuinticSpline ){ } else if( _gbviParameters->getBornRadiusScalingSoftcoreMethod() == GBVISoftcoreParameters::QuinticSpline ){
computeBornRadiiUsingQuinticSpline( atomicRadius3, sum, gbviParameters, computeBornRadiiUsingQuinticSpline( atomicRadius3, sum, gbviParameters,
bornRadii + atomI, switchDeriviative + atomI ); bornRadii[atomI], switchDeriviative + atomI );
} }
#if( GBVISoftcoreDebug == 1 ) #if( GBVISoftcoreDebug == 1 )
...@@ -607,7 +608,7 @@ RealOpenMM CpuGBVISoftcore::Sgb( RealOpenMM t ){ ...@@ -607,7 +608,7 @@ RealOpenMM CpuGBVISoftcore::Sgb( RealOpenMM t ){
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM CpuGBVISoftcore::computeBornEnergy( const RealOpenMM* bornRadii, vector<RealVec>& atomCoordinates, RealOpenMM CpuGBVISoftcore::computeBornEnergy( const vector<RealOpenMM>& bornRadii, vector<RealVec>& atomCoordinates,
const RealOpenMM* partialCharges ){ const RealOpenMM* partialCharges ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -631,10 +632,6 @@ RealOpenMM CpuGBVISoftcore::computeBornEnergy( const RealOpenMM* bornRadii, vect ...@@ -631,10 +632,6 @@ RealOpenMM CpuGBVISoftcore::computeBornEnergy( const RealOpenMM* bornRadii, vect
const RealOpenMM* atomicRadii = gbviParameters->getAtomicRadii(); const RealOpenMM* atomicRadii = gbviParameters->getAtomicRadii();
const RealOpenMM* gammaParameters = gbviParameters->getGammaParameters(); const RealOpenMM* gammaParameters = gbviParameters->getGammaParameters();
if( bornRadii == NULL ){
bornRadii = getBornRadii();
}
#if( GBVISoftcoreDebug == 1 ) #if( GBVISoftcoreDebug == 1 )
FILE* logFile = stderr; FILE* logFile = stderr;
(void) fprintf( logFile, "\n%s\n", methodName ); (void) fprintf( logFile, "\n%s\n", methodName );
...@@ -723,7 +720,7 @@ RealOpenMM e3 = -partialChargeI2*partialCharges[atomJ]*Sgb( t )/deltaR[Reference ...@@ -723,7 +720,7 @@ RealOpenMM e3 = -partialChargeI2*partialCharges[atomJ]*Sgb( t )/deltaR[Reference
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int CpuGBVISoftcore::computeBornForces( const RealOpenMM* bornRadii, vector<RealVec>& atomCoordinates, int CpuGBVISoftcore::computeBornForces( const vector<RealOpenMM>& bornRadii, vector<RealVec>& atomCoordinates,
const RealOpenMM* partialCharges, vector<RealVec>& inputForces ){ const RealOpenMM* partialCharges, vector<RealVec>& inputForces ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -753,10 +750,6 @@ int CpuGBVISoftcore::computeBornForces( const RealOpenMM* bornRadii, vector<Real ...@@ -753,10 +750,6 @@ int CpuGBVISoftcore::computeBornForces( const RealOpenMM* bornRadii, vector<Real
const RealOpenMM* atomicRadii = gbviParameters->getAtomicRadii(); const RealOpenMM* atomicRadii = gbviParameters->getAtomicRadii();
const RealOpenMM* gammaParameters = gbviParameters->getGammaParameters(); const RealOpenMM* gammaParameters = gbviParameters->getGammaParameters();
if( bornRadii == NULL ){
bornRadii = getBornRadii();
}
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// constants // constants
...@@ -767,8 +760,6 @@ int CpuGBVISoftcore::computeBornForces( const RealOpenMM* bornRadii, vector<Real ...@@ -767,8 +760,6 @@ int CpuGBVISoftcore::computeBornForces( const RealOpenMM* bornRadii, vector<Real
// set energy/forces to zero // set energy/forces to zero
const unsigned int arraySzInBytes = sizeof( RealOpenMM )*numberOfAtoms;
RealOpenMM** forces = new RealOpenMM*[numberOfAtoms]; RealOpenMM** forces = new RealOpenMM*[numberOfAtoms];
RealOpenMM* block = new RealOpenMM[numberOfAtoms*3]; RealOpenMM* block = new RealOpenMM[numberOfAtoms*3];
memset( block, 0, sizeof( RealOpenMM )*numberOfAtoms*3 ); memset( block, 0, sizeof( RealOpenMM )*numberOfAtoms*3 );
...@@ -778,8 +769,8 @@ int CpuGBVISoftcore::computeBornForces( const RealOpenMM* bornRadii, vector<Real ...@@ -778,8 +769,8 @@ int CpuGBVISoftcore::computeBornForces( const RealOpenMM* bornRadii, vector<Real
blockPtr += 3; blockPtr += 3;
} }
RealOpenMM* bornForces = getBornForce(); vector<RealOpenMM>& bornForces = getBornForce();
memset( bornForces, 0, arraySzInBytes ); bornForces.assign(numberOfAtoms, 0.0);
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
......
...@@ -115,7 +115,7 @@ class CpuGBVISoftcore : public CpuImplicitSolvent { ...@@ -115,7 +115,7 @@ class CpuGBVISoftcore : public CpuImplicitSolvent {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int computeBornRadii( std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM* bornRadii, int computeBornRadii( std::vector<OpenMM::RealVec>& atomCoordinates, std::vector<RealOpenMM>& bornRadii,
RealOpenMM* switchDeriviative = NULL ); RealOpenMM* switchDeriviative = NULL );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -210,7 +210,7 @@ class CpuGBVISoftcore : public CpuImplicitSolvent { ...@@ -210,7 +210,7 @@ class CpuGBVISoftcore : public CpuImplicitSolvent {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM computeBornEnergy( const RealOpenMM* bornRadii, std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM computeBornEnergy( const std::vector<RealOpenMM>& bornRadii, std::vector<OpenMM::RealVec>& atomCoordinates,
const RealOpenMM* partialCharges ); const RealOpenMM* partialCharges );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -226,7 +226,7 @@ class CpuGBVISoftcore : public CpuImplicitSolvent { ...@@ -226,7 +226,7 @@ class CpuGBVISoftcore : public CpuImplicitSolvent {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int computeBornForces( const RealOpenMM* bornRadii, std::vector<OpenMM::RealVec>& atomCoordinates, int computeBornForces( const std::vector<RealOpenMM>& bornRadii, std::vector<OpenMM::RealVec>& atomCoordinates,
const RealOpenMM* partialCharges, std::vector<OpenMM::RealVec>& inputForces ); const RealOpenMM* partialCharges, std::vector<OpenMM::RealVec>& inputForces );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -319,7 +319,7 @@ class CpuGBVISoftcore : public CpuImplicitSolvent { ...@@ -319,7 +319,7 @@ class CpuGBVISoftcore : public CpuImplicitSolvent {
int computeBornRadiiUsingQuinticSpline( RealOpenMM atomicRadius3, RealOpenMM bornSum, int computeBornRadiiUsingQuinticSpline( RealOpenMM atomicRadius3, RealOpenMM bornSum,
GBVISoftcoreParameters* gbviParameters, GBVISoftcoreParameters* gbviParameters,
RealOpenMM* bornRadius, RealOpenMM* switchDeriviative ); RealOpenMM& bornRadius, RealOpenMM* switchDeriviative );
}; };
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "../SimTKReference/ReferenceForce.h" #include "../SimTKReference/ReferenceForce.h"
#include <cmath> #include <cmath>
#include <cstdio> #include <cstdio>
#include <vector>
using std::vector; using std::vector;
using OpenMM::RealVec; using OpenMM::RealVec;
...@@ -71,13 +72,6 @@ CpuObcSoftcore::~CpuObcSoftcore( ){ ...@@ -71,13 +72,6 @@ CpuObcSoftcore::~CpuObcSoftcore( ){
// static const char* methodName = "\nCpuObcSoftcore::~CpuObcSoftcore"; // static const char* methodName = "\nCpuObcSoftcore::~CpuObcSoftcore";
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
//if( _obcSoftcoreParameters != NULL ){
// delete _obcSoftcoreParameters;
//}
delete[] _obcChain;
delete[] _obcChainTemp;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -95,8 +89,6 @@ void CpuObcSoftcore::_initializeObcDataMembers( void ){ ...@@ -95,8 +89,6 @@ void CpuObcSoftcore::_initializeObcDataMembers( void ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
_obcSoftcoreParameters = NULL; _obcSoftcoreParameters = NULL;
_obcChain = NULL;
_obcChainTemp = NULL;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -149,7 +141,7 @@ int CpuObcSoftcore::setObcSoftcoreParameters( ObcSoftcoreParameters* obcSoftcor ...@@ -149,7 +141,7 @@ int CpuObcSoftcore::setObcSoftcoreParameters( ObcSoftcoreParameters* obcSoftcor
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM* CpuObcSoftcore::getObcChain( void ){ vector<RealOpenMM>& CpuObcSoftcore::getObcChain( void ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -157,8 +149,8 @@ RealOpenMM* CpuObcSoftcore::getObcChain( void ){ ...@@ -157,8 +149,8 @@ RealOpenMM* CpuObcSoftcore::getObcChain( void ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
if( _obcChain == NULL ){ if( _obcChain.size() == 0 ){
_obcChain = new RealOpenMM[_obcSoftcoreParameters->getNumberOfAtoms()]; _obcChain.resize(_obcSoftcoreParameters->getNumberOfAtoms());
} }
return _obcChain; return _obcChain;
} }
...@@ -171,7 +163,7 @@ RealOpenMM* CpuObcSoftcore::getObcChain( void ){ ...@@ -171,7 +163,7 @@ RealOpenMM* CpuObcSoftcore::getObcChain( void ){
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM* CpuObcSoftcore::getObcChainConst( void ) const { const vector<RealOpenMM>& CpuObcSoftcore::getObcChainConst( void ) const {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -191,7 +183,7 @@ RealOpenMM* CpuObcSoftcore::getObcChainConst( void ) const { ...@@ -191,7 +183,7 @@ RealOpenMM* CpuObcSoftcore::getObcChainConst( void ) const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM* CpuObcSoftcore::getObcChainTemp( void ){ vector<RealOpenMM>& CpuObcSoftcore::getObcChainTemp( void ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -199,8 +191,8 @@ RealOpenMM* CpuObcSoftcore::getObcChainTemp( void ){ ...@@ -199,8 +191,8 @@ RealOpenMM* CpuObcSoftcore::getObcChainTemp( void ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
if( _obcChainTemp == NULL ){ if( _obcChainTemp.size() == 0 ){
_obcChainTemp = new RealOpenMM[_obcSoftcoreParameters->getNumberOfAtoms()]; _obcChainTemp.resize(_obcSoftcoreParameters->getNumberOfAtoms());
} }
return _obcChainTemp; return _obcChainTemp;
} }
...@@ -219,7 +211,7 @@ RealOpenMM* CpuObcSoftcore::getObcChainTemp( void ){ ...@@ -219,7 +211,7 @@ RealOpenMM* CpuObcSoftcore::getObcChainTemp( void ){
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int CpuObcSoftcore::computeBornRadii( vector<RealVec>& atomCoordinates, RealOpenMM* bornRadii, RealOpenMM* obcChain ){ int CpuObcSoftcore::computeBornRadii( vector<RealVec>& atomCoordinates, RealOpenMM* bornRadii ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -239,9 +231,7 @@ int CpuObcSoftcore::computeBornRadii( vector<RealVec>& atomCoordinates, RealOpen ...@@ -239,9 +231,7 @@ int CpuObcSoftcore::computeBornRadii( vector<RealVec>& atomCoordinates, RealOpen
int numberOfAtoms = obcSoftcoreParameters->getNumberOfAtoms(); int numberOfAtoms = obcSoftcoreParameters->getNumberOfAtoms();
RealOpenMM* atomicRadii = obcSoftcoreParameters->getAtomicRadii(); RealOpenMM* atomicRadii = obcSoftcoreParameters->getAtomicRadii();
const RealOpenMM* scaledRadiusFactor = obcSoftcoreParameters->getScaledRadiusFactors(); const RealOpenMM* scaledRadiusFactor = obcSoftcoreParameters->getScaledRadiusFactors();
if( !obcChain ){ vector<RealOpenMM>& obcChain = getObcChain();
obcChain = getObcChain();
}
const RealOpenMM* nonPolarScaleFactors = obcSoftcoreParameters->getNonPolarScaleFactors(); const RealOpenMM* nonPolarScaleFactors = obcSoftcoreParameters->getNonPolarScaleFactors();
RealOpenMM dielectricOffset = obcSoftcoreParameters->getDielectricOffset(); RealOpenMM dielectricOffset = obcSoftcoreParameters->getDielectricOffset();
...@@ -363,8 +353,8 @@ if( logFile ){ ...@@ -363,8 +353,8 @@ if( logFile ){
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int CpuObcSoftcore::computeAceNonPolarForce( const ObcSoftcoreParameters* obcSoftcoreParameters, int CpuObcSoftcore::computeAceNonPolarForce( const ObcSoftcoreParameters* obcSoftcoreParameters,
const RealOpenMM* bornRadii, RealOpenMM* energy, const vector<RealOpenMM>& bornRadii, RealOpenMM* energy,
RealOpenMM* forces ) const { vector<RealOpenMM>& forces ) const {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -429,7 +419,7 @@ int CpuObcSoftcore::computeAceNonPolarForce( const ObcSoftcoreParameters* obcSof ...@@ -429,7 +419,7 @@ int CpuObcSoftcore::computeAceNonPolarForce( const ObcSoftcoreParameters* obcSof
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int CpuObcSoftcore::computeBornEnergyForces( RealOpenMM* bornRadii, vector<RealVec>& atomCoordinates, int CpuObcSoftcore::computeBornEnergyForces( vector<RealOpenMM>& bornRadii, vector<RealVec>& atomCoordinates,
const RealOpenMM* partialCharges, vector<RealVec>& inputForces ){ const RealOpenMM* partialCharges, vector<RealVec>& inputForces ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -450,10 +440,6 @@ int CpuObcSoftcore::computeBornEnergyForces( RealOpenMM* bornRadii, vector<RealV ...@@ -450,10 +440,6 @@ int CpuObcSoftcore::computeBornEnergyForces( RealOpenMM* bornRadii, vector<RealV
const ObcSoftcoreParameters* obcSoftcoreParameters = getObcSoftcoreParameters(); const ObcSoftcoreParameters* obcSoftcoreParameters = getObcSoftcoreParameters();
const int numberOfAtoms = obcSoftcoreParameters->getNumberOfAtoms(); const int numberOfAtoms = obcSoftcoreParameters->getNumberOfAtoms();
if( bornRadii == NULL ){
bornRadii = getBornRadii();
}
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// constants // constants
...@@ -482,7 +468,6 @@ int CpuObcSoftcore::computeBornEnergyForces( RealOpenMM* bornRadii, vector<RealV ...@@ -482,7 +468,6 @@ int CpuObcSoftcore::computeBornEnergyForces( RealOpenMM* bornRadii, vector<RealV
// set energy/forces to zero // set energy/forces to zero
RealOpenMM obcEnergy = zero; RealOpenMM obcEnergy = zero;
const unsigned int arraySzInBytes = sizeof( RealOpenMM )*numberOfAtoms;
RealOpenMM** forces = (RealOpenMM**) malloc( sizeof( RealOpenMM* )*numberOfAtoms ); RealOpenMM** forces = (RealOpenMM**) malloc( sizeof( RealOpenMM* )*numberOfAtoms );
RealOpenMM* block = (RealOpenMM*) malloc( sizeof( RealOpenMM )*numberOfAtoms*3 ); RealOpenMM* block = (RealOpenMM*) malloc( sizeof( RealOpenMM )*numberOfAtoms*3 );
...@@ -493,8 +478,8 @@ int CpuObcSoftcore::computeBornEnergyForces( RealOpenMM* bornRadii, vector<RealV ...@@ -493,8 +478,8 @@ int CpuObcSoftcore::computeBornEnergyForces( RealOpenMM* bornRadii, vector<RealV
blockPtr += 3; blockPtr += 3;
} }
RealOpenMM* bornForces = getBornForce(); vector<RealOpenMM>& bornForces = getBornForce();
memset( bornForces, 0, arraySzInBytes ); bornForces.assign(numberOfAtoms, 0.0);
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -585,13 +570,13 @@ int CpuObcSoftcore::computeBornEnergyForces( RealOpenMM* bornRadii, vector<RealV ...@@ -585,13 +570,13 @@ int CpuObcSoftcore::computeBornEnergyForces( RealOpenMM* bornRadii, vector<RealV
// initialize Born radii & ObcChain temp arrays -- contain values // initialize Born radii & ObcChain temp arrays -- contain values
// used in next iteration // used in next iteration
RealOpenMM* bornRadiiTemp = getBornRadiiTemp(); vector<RealOpenMM>& bornRadiiTemp = getBornRadiiTemp();
memset( bornRadiiTemp, 0, arraySzInBytes ); bornRadiiTemp.assign(numberOfAtoms, 0.0);
RealOpenMM* obcChainTemp = getObcChainTemp(); vector<RealOpenMM>& obcChainTemp = getObcChainTemp();
memset( obcChainTemp, 0, arraySzInBytes ); obcChainTemp.assign(numberOfAtoms, 0.0);
RealOpenMM* obcChain = getObcChain(); vector<RealOpenMM>& obcChain = getObcChain();
const RealOpenMM* atomicRadii = obcSoftcoreParameters->getAtomicRadii(); const RealOpenMM* atomicRadii = obcSoftcoreParameters->getAtomicRadii();
const RealOpenMM alphaObc = obcSoftcoreParameters->getAlphaObc(); const RealOpenMM alphaObc = obcSoftcoreParameters->getAlphaObc();
...@@ -732,8 +717,8 @@ int CpuObcSoftcore::computeBornEnergyForces( RealOpenMM* bornRadii, vector<RealV ...@@ -732,8 +717,8 @@ int CpuObcSoftcore::computeBornEnergyForces( RealOpenMM* bornRadii, vector<RealV
// copy new Born radii and obcChain values into permanent array // copy new Born radii and obcChain values into permanent array
memcpy( bornRadii, bornRadiiTemp, arraySzInBytes ); bornRadii = bornRadiiTemp;
memcpy( obcChain, obcChainTemp, arraySzInBytes ); obcChain = obcChainTemp;
free( (char*) block ); free( (char*) block );
free( (char*) forces ); free( (char*) forces );
......
...@@ -40,8 +40,8 @@ class CpuObcSoftcore : public CpuImplicitSolvent { ...@@ -40,8 +40,8 @@ class CpuObcSoftcore : public CpuImplicitSolvent {
// arrays containing OBC chain derivative // arrays containing OBC chain derivative
RealOpenMM* _obcChain; std::vector<RealOpenMM> _obcChain;
RealOpenMM* _obcChainTemp; std::vector<RealOpenMM> _obcChainTemp;
// initialize data members (more than // initialize data members (more than
// one constructor, so centralize intialization here) // one constructor, so centralize intialization here)
...@@ -101,8 +101,8 @@ class CpuObcSoftcore : public CpuImplicitSolvent { ...@@ -101,8 +101,8 @@ class CpuObcSoftcore : public CpuImplicitSolvent {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM* getObcChain( void ); std::vector<RealOpenMM>& getObcChain( void );
RealOpenMM* getObcChainConst( void ) const; const std::vector<RealOpenMM>& getObcChainConst( void ) const;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -113,7 +113,7 @@ class CpuObcSoftcore : public CpuImplicitSolvent { ...@@ -113,7 +113,7 @@ class CpuObcSoftcore : public CpuImplicitSolvent {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM* getObcChainTemp( void ); std::vector<RealOpenMM>& getObcChainTemp( void );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -128,8 +128,7 @@ class CpuObcSoftcore : public CpuImplicitSolvent { ...@@ -128,8 +128,7 @@ class CpuObcSoftcore : public CpuImplicitSolvent {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int computeBornRadii( std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM* bornRadii, int computeBornRadii( std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM* bornRadii );
RealOpenMM* obcChain = NULL );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -146,8 +145,8 @@ class CpuObcSoftcore : public CpuImplicitSolvent { ...@@ -146,8 +145,8 @@ class CpuObcSoftcore : public CpuImplicitSolvent {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int computeAceNonPolarForce( const ObcSoftcoreParameters* obcSoftcoreParameters, int computeAceNonPolarForce( const ObcSoftcoreParameters* obcSoftcoreParameters,
const RealOpenMM* bornRadii, RealOpenMM* energy, const std::vector<RealOpenMM>& bornRadii, RealOpenMM* energy,
RealOpenMM* forces ) const; std::vector<RealOpenMM>& forces ) const;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -162,7 +161,7 @@ class CpuObcSoftcore : public CpuImplicitSolvent { ...@@ -162,7 +161,7 @@ class CpuObcSoftcore : public CpuImplicitSolvent {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int computeBornEnergyForces( RealOpenMM* bornRadii, std::vector<OpenMM::RealVec>& atomCoordinates, int computeBornEnergyForces( std::vector<RealOpenMM>& bornRadii, std::vector<OpenMM::RealVec>& atomCoordinates,
const RealOpenMM* partialCharges, std::vector<OpenMM::RealVec>& forces ); const RealOpenMM* partialCharges, std::vector<OpenMM::RealVec>& forces );
}; };
......
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