"csrc/vscode:/vscode.git/clone" did not exist on "c6faca45c171f099d759e8392772a43da6008bbc"
Commit 6718e0cc authored by Mark Friedrichs's avatar Mark Friedrichs
Browse files

Code cleanup

parent 1079a319
...@@ -23,15 +23,13 @@ ...@@ -23,15 +23,13 @@
*/ */
#include <string.h> #include <string.h>
#include <math.h>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include "../SimTKUtilities/SimTKOpenMMCommon.h" #include "../SimTKUtilities/SimTKOpenMMCommon.h"
#include "../SimTKUtilities/SimTKOpenMMLog.h"
#include "../SimTKUtilities/SimTKOpenMMUtilities.h"
#include "CpuGBVISoftcore.h"
#include "../SimTKReference/ReferenceForce.h" #include "../SimTKReference/ReferenceForce.h"
#include <math.h> #include "CpuGBVISoftcore.h"
using std::vector; using std::vector;
using OpenMM::RealVec; using OpenMM::RealVec;
......
/* Portions copyright (c) 2006-2009 Stanford University and Simbios. /* Portions copyright (c) 2006-2009 Stanford University and Simbios.
* Contributors: Pande Group * Contributors: Pande Group
* *
...@@ -26,15 +25,14 @@ ...@@ -26,15 +25,14 @@
#include <sstream> #include <sstream>
#include <stdlib.h> #include <stdlib.h>
//#include "../SimTKUtilities/SimTKOpenMMCommon.h"
#include "../SimTKUtilities/SimTKOpenMMLog.h"
#include "../SimTKUtilities/SimTKOpenMMUtilities.h"
#include "CpuObcSoftcore.h"
#include "../SimTKReference/ReferenceForce.h"
#include <cmath> #include <cmath>
#include <cstdio> #include <cstdio>
#include <vector> #include <vector>
#include "../SimTKUtilities/SimTKOpenMMCommon.h"
#include "../SimTKReference/ReferenceForce.h"
#include "CpuObcSoftcore.h"
using std::vector; using std::vector;
using OpenMM::RealVec; using OpenMM::RealVec;
...@@ -46,661 +44,466 @@ using OpenMM::RealVec; ...@@ -46,661 +44,466 @@ using OpenMM::RealVec;
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
CpuObcSoftcore::CpuObcSoftcore( ImplicitSolventParameters* obcSoftcoreParameters ) : CpuImplicitSolvent( obcSoftcoreParameters ){ CpuObcSoftcore::CpuObcSoftcore( ObcSoftcoreParameters* obcSoftcoreParameters ){
_obcSoftcoreParameters = obcSoftcoreParameters;
// --------------------------------------------------------------------------------------- _includeAceApproximation = 1;
_obcChain.resize(_obcSoftcoreParameters->getNumberOfAtoms());
// static const char* methodName = "\nCpuObcSoftcore::CpuObcSoftcore";
// ---------------------------------------------------------------------------------------
_initializeObcDataMembers( );
_obcSoftcoreParameters = static_cast<ObcSoftcoreParameters*> (obcSoftcoreParameters);
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
CpuObcSoftcore destructor CpuObcSoftcore destructor
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
CpuObcSoftcore::~CpuObcSoftcore( ){ CpuObcSoftcore::~CpuObcSoftcore( ){
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObcSoftcore::~CpuObcSoftcore";
// ---------------------------------------------------------------------------------------
}
/**---------------------------------------------------------------------------------------
Initialize data members
--------------------------------------------------------------------------------------- */
void CpuObcSoftcore::_initializeObcDataMembers( void ){
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObcSoftcore::initializeDataMembers";
// ---------------------------------------------------------------------------------------
_obcSoftcoreParameters = NULL;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get ObcSoftcoreParameters reference Get ObcSoftcoreParameters reference
@return ObcSoftcoreParameters reference @return ObcSoftcoreParameters reference
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ObcSoftcoreParameters* CpuObcSoftcore::getObcSoftcoreParameters( void ) const { ObcSoftcoreParameters* CpuObcSoftcore::getObcSoftcoreParameters( void ) const {
return _obcSoftcoreParameters;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObcSoftcore::getObcSoftcoreParameters";
// ---------------------------------------------------------------------------------------
return _obcSoftcoreParameters;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Set ObcSoftcoreParameters reference Set ObcSoftcoreParameters reference
@param ObcSoftcoreParameters reference
--------------------------------------------------------------------------------------- */
void CpuObcSoftcore::setObcSoftcoreParameters( ObcSoftcoreParameters* obcSoftcoreParameters ){
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObcSoftcore::setObcSoftcoreParameters"; @param ObcSoftcoreParameters reference
// --------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------- */
_obcSoftcoreParameters = obcSoftcoreParameters; void CpuObcSoftcore::setObcSoftcoreParameters( ObcSoftcoreParameters* obcSoftcoreParameters ){
_obcSoftcoreParameters = obcSoftcoreParameters;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Return OBC chain derivative: size = _obcSoftcoreParameters->getNumberOfAtoms() Return OBC chain derivative: size = _obcSoftcoreParameters->getNumberOfAtoms()
On first call, memory for array is allocated if not set On first call, memory for array is allocated if not set
@return array
--------------------------------------------------------------------------------------- */
vector<RealOpenMM>& CpuObcSoftcore::getObcChain( void ){
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObcSoftcore::getObcChain"; @return array
// --------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------- */
if( _obcChain.size() == 0 ){ RealOpenMMVector& CpuObcSoftcore::getObcChain( void ){
_obcChain.resize(_obcSoftcoreParameters->getNumberOfAtoms()); return _obcChain;
}
return _obcChain;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Return OBC chain derivative: size = _obcSoftcoreParameters->getNumberOfAtoms() Return flag signalling whether AceApproximation for nonpolar term is to be included
@return array @return flag
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
const vector<RealOpenMM>& CpuObcSoftcore::getObcChainConst( void ) const { int CpuObcSoftcore::includeAceApproximation( void ) const {
return _includeAceApproximation;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObcSoftcore::getObcChain";
// ---------------------------------------------------------------------------------------
return _obcChain;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Return OBC chain temp work array of size=_obcSoftcoreParameters->getNumberOfAtoms() Set flag indicating whether AceApproximation is to be included
On first call, memory for array is allocated if not set
@return array @param includeAceApproximation new includeAceApproximation value
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
vector<RealOpenMM>& CpuObcSoftcore::getObcChainTemp( void ){ void CpuObcSoftcore::setIncludeAceApproximation( int includeAceApproximation ){
_includeAceApproximation = includeAceApproximation;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObcSoftcore::getImplicitSolventObcChainTemp";
// ---------------------------------------------------------------------------------------
if( _obcChainTemp.size() == 0 ){
_obcChainTemp.resize(_obcSoftcoreParameters->getNumberOfAtoms());
}
return _obcChainTemp;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get Born radii based on papers: Calculation of Born radii based on papers:
J. Phys. Chem. 1996 100, 19824-19839 (HCT paper)
Proteins: Structure, Function, and Bioinformatcis 55:383-394 (2004) (OBC paper)
@param atomCoordinates atomic coordinates
@param bornRadii output array of Born radii
--------------------------------------------------------------------------------------- */
void CpuObcSoftcore::computeBornRadii( vector<RealVec>& atomCoordinates, std::vector<RealOpenMM>& bornRadii ){
// --------------------------------------------------------------------------------------- J. Phys. Chem. 1996 100, 19824-19839 (HCT paper)
Proteins: Structure, Function, and Bioinformatcis 55:383-394 (2004) (OBC paper)
static const RealOpenMM zero = (RealOpenMM) 0.0; @param atomCoordinates atomic coordinates
static const RealOpenMM one = (RealOpenMM) 1.0; @param bornRadii output array of Born radii
static const RealOpenMM two = (RealOpenMM) 2.0;
static const RealOpenMM three = (RealOpenMM) 3.0;
static const RealOpenMM half = (RealOpenMM) 0.5;
static const RealOpenMM fourth = (RealOpenMM) 0.25;
static const char* methodName = "\nCpuObcSoftcore::computeBornRadii"; --------------------------------------------------------------------------------------- */
// --------------------------------------------------------------------------------------- void CpuObcSoftcore::computeBornRadii( vector<RealVec>& atomCoordinates, RealOpenMMVector& bornRadii ){
ObcSoftcoreParameters* obcSoftcoreParameters = getObcSoftcoreParameters(); // ---------------------------------------------------------------------------------------
int numberOfAtoms = obcSoftcoreParameters->getNumberOfAtoms(); static const RealOpenMM zero = static_cast<RealOpenMM>( 0.0 );
RealOpenMM* atomicRadii = obcSoftcoreParameters->getAtomicRadii(); static const RealOpenMM one = static_cast<RealOpenMM>( 1.0 );
const RealOpenMM* scaledRadiusFactor = obcSoftcoreParameters->getScaledRadiusFactors(); static const RealOpenMM two = static_cast<RealOpenMM>( 2.0 );
vector<RealOpenMM>& obcChain = getObcChain(); 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 );
const RealOpenMM* nonPolarScaleFactors = obcSoftcoreParameters->getNonPolarScaleFactors(); // ---------------------------------------------------------------------------------------
RealOpenMM dielectricOffset = obcSoftcoreParameters->getDielectricOffset();
RealOpenMM alphaObc = obcSoftcoreParameters->getAlphaObc();
RealOpenMM betaObc = obcSoftcoreParameters->getBetaObc();
RealOpenMM gammaObc = obcSoftcoreParameters->getGammaObc();
// --------------------------------------------------------------------------------------- ObcSoftcoreParameters* obcSoftcoreParameters = getObcSoftcoreParameters();
// calculate Born radii int numberOfAtoms = obcSoftcoreParameters->getNumberOfAtoms();
//FILE* logFile = SimTKOpenMMLog::getSimTKOpenMMLogFile( ); const RealOpenMMVector& atomicRadii = obcSoftcoreParameters->getAtomicRadii();
//FILE* logFile = NULL; const RealOpenMMVector& scaledRadiusFactor = obcSoftcoreParameters->getScaledRadiusFactors();
//FILE* logFile = fopen( "bRSoft", "w" ); RealOpenMMVector& obcChain = getObcChain();
const RealOpenMMVector& nonPolarScaleFactors = obcSoftcoreParameters->getNonPolarScaleFactors();
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){ RealOpenMM dielectricOffset = obcSoftcoreParameters->getDielectricOffset();
RealOpenMM alphaObc = obcSoftcoreParameters->getAlphaObc();
RealOpenMM radiusI = atomicRadii[atomI]; RealOpenMM betaObc = obcSoftcoreParameters->getBetaObc();
RealOpenMM offsetRadiusI = radiusI - dielectricOffset; RealOpenMM gammaObc = obcSoftcoreParameters->getGammaObc();
RealOpenMM radiusIInverse = one/offsetRadiusI;
RealOpenMM sum = zero;
// HCT code // ---------------------------------------------------------------------------------------
for( int atomJ = 0; atomJ < numberOfAtoms; atomJ++ ){ // calculate Born radii
if( atomJ != atomI ){ for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
RealOpenMM deltaR[ReferenceForce::LastDeltaRIndex]; RealOpenMM radiusI = atomicRadii[atomI];
if (_obcSoftcoreParameters->getPeriodic()) RealOpenMM offsetRadiusI = radiusI - dielectricOffset;
ReferenceForce::getDeltaRPeriodic( atomCoordinates[atomI], atomCoordinates[atomJ], _obcSoftcoreParameters->getPeriodicBox(), deltaR );
else
ReferenceForce::getDeltaR( atomCoordinates[atomI], atomCoordinates[atomJ], deltaR );
RealOpenMM r = deltaR[ReferenceForce::RIndex];
if (_obcSoftcoreParameters->getUseCutoff() && r > _obcSoftcoreParameters->getCutoffDistance())
continue;
RealOpenMM offsetRadiusJ = atomicRadii[atomJ] - dielectricOffset;
RealOpenMM scaledRadiusJ = offsetRadiusJ*scaledRadiusFactor[atomJ];
RealOpenMM rScaledRadiusJ = r + scaledRadiusJ;
if( offsetRadiusI < rScaledRadiusJ ){
RealOpenMM rInverse = one/r;
RealOpenMM l_ij = offsetRadiusI > FABS( r - scaledRadiusJ ) ? offsetRadiusI : FABS( r - scaledRadiusJ );
l_ij = one/l_ij;
RealOpenMM u_ij = one/rScaledRadiusJ;
RealOpenMM l_ij2 = l_ij*l_ij;
RealOpenMM u_ij2 = u_ij*u_ij;
RealOpenMM ratio = LN( (u_ij/l_ij) ); RealOpenMM radiusIInverse = one/offsetRadiusI;
RealOpenMM term = l_ij - u_ij + fourth*r*(u_ij2 - l_ij2) + ( half*rInverse*ratio) + (fourth*scaledRadiusJ*scaledRadiusJ*rInverse)*(l_ij2 - u_ij2); RealOpenMM sum = zero;
// 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);
}
sum += nonPolarScaleFactors[atomJ]*term;
}
}
}
// OBC-specific code (Eqs. 6-8 in paper) // HCT code
sum *= nonPolarScaleFactors[atomI]*half*offsetRadiusI; for( int atomJ = 0; atomJ < numberOfAtoms; atomJ++ ){
RealOpenMM sum2 = sum*sum;
RealOpenMM sum3 = sum*sum2; if( atomJ != atomI ){
RealOpenMM tanhSum = TANH( alphaObc*sum - betaObc*sum2 + gammaObc*sum3 );
RealOpenMM deltaR[ReferenceForce::LastDeltaRIndex];
if (_obcSoftcoreParameters->getPeriodic())
ReferenceForce::getDeltaRPeriodic( atomCoordinates[atomI], atomCoordinates[atomJ], _obcSoftcoreParameters->getPeriodicBox(), deltaR );
else
ReferenceForce::getDeltaR( atomCoordinates[atomI], atomCoordinates[atomJ], deltaR );
RealOpenMM r = deltaR[ReferenceForce::RIndex];
if (_obcSoftcoreParameters->getUseCutoff() && r > _obcSoftcoreParameters->getCutoffDistance())
continue;
RealOpenMM offsetRadiusJ = atomicRadii[atomJ] - dielectricOffset;
RealOpenMM scaledRadiusJ = offsetRadiusJ*scaledRadiusFactor[atomJ];
RealOpenMM rScaledRadiusJ = r + scaledRadiusJ;
if( offsetRadiusI < rScaledRadiusJ ){
RealOpenMM rInverse = one/r;
RealOpenMM l_ij = offsetRadiusI > FABS( r - scaledRadiusJ ) ? offsetRadiusI : FABS( r - scaledRadiusJ );
l_ij = one/l_ij;
RealOpenMM u_ij = one/rScaledRadiusJ;
RealOpenMM l_ij2 = l_ij*l_ij;
RealOpenMM u_ij2 = u_ij*u_ij;
bornRadii[atomI] = one/( one/offsetRadiusI - tanhSum/radiusI ); 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);
}
sum += nonPolarScaleFactors[atomJ]*term;
}
}
}
// OBC-specific code (Eqs. 6-8 in paper)
obcChain[atomI] = offsetRadiusI*( alphaObc - two*betaObc*sum + three*gammaObc*sum2 ); sum *= nonPolarScaleFactors[atomI]*half*offsetRadiusI;
obcChain[atomI] = (one - tanhSum*tanhSum)*obcChain[atomI]/radiusI; RealOpenMM sum2 = sum*sum;
RealOpenMM sum3 = sum*sum2;
RealOpenMM tanhSum = TANH( alphaObc*sum - betaObc*sum2 + gammaObc*sum3 );
bornRadii[atomI] = one/( one/offsetRadiusI - tanhSum/radiusI );
obcChain[atomI] = offsetRadiusI*( alphaObc - two*betaObc*sum + three*gammaObc*sum2 );
obcChain[atomI] = (one - tanhSum*tanhSum)*obcChain[atomI]/radiusI;
#if 0 }
if( logFile && atomI >= 0 ){
(void) fprintf( logFile, "RRQ %d sum %12.6e tanhS %12.6e radI %.5f %.5f born %18.10e obc %12.6e\n",
atomI, sum, tanhSum, radiusI, offsetRadiusI, bornRadii[atomI], obcChain[atomI] );
}
#endif
}
#if 0
if( logFile ){
(void) fclose( logFile );
logFile = fopen( "bRSoftJ", "w" );
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
(void) fprintf( logFile, "%6d %18.10e %18.10e\n",
atomI, bornRadii[atomI], obcChain[atomI] );
}
(void) fclose( logFile );
}
#endif
return;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get nonpolar solvation force constribution via ACE approximation Get nonpolar solvation force constribution via ACE approximation
@param obcSoftcoreParameters parameters @param obcSoftcoreParameters parameters
@param vdwRadii Vdw radii @param vdwRadii Vdw radii
@param bornRadii Born radii @param bornRadii Born radii
@param energy energy (output): value is incremented from input value @param energy energy (output): value is incremented from input value
@param forces forces: values are incremented from input values @param forces forces: values are incremented from input values
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void CpuObcSoftcore::computeAceNonPolarForce( const ObcSoftcoreParameters* obcSoftcoreParameters, void CpuObcSoftcore::computeAceNonPolarForce( const ObcSoftcoreParameters* obcSoftcoreParameters,
const vector<RealOpenMM>& bornRadii, RealOpenMM* energy, const vector<RealOpenMM>& bornRadii, RealOpenMM* energy,
vector<RealOpenMM>& forces ) const { vector<RealOpenMM>& forces ) const {
// --------------------------------------------------------------------------------------- static const RealOpenMM minusSix = -6.0;
// static const char* methodName = "\nCpuImplicitSolvent::computeAceNonPolarForce"; // ---------------------------------------------------------------------------------------
static const RealOpenMM minusSix = -6.0; // compute the nonpolar solvation via ACE approximation
// --------------------------------------------------------------------------------------- const RealOpenMM probeRadius = obcSoftcoreParameters->getProbeRadius();
const RealOpenMM surfaceAreaFactor = obcSoftcoreParameters->getPi4Asolv();
// compute the nonpolar solvation via ACE approximation const RealOpenMMVector& atomicRadii = obcSoftcoreParameters->getAtomicRadii();
const RealOpenMMVector& nonPolarScaleFactors = obcSoftcoreParameters->getNonPolarScaleFactors();
const RealOpenMM probeRadius = obcSoftcoreParameters->getProbeRadius(); int numberOfAtoms = obcSoftcoreParameters->getNumberOfAtoms();
const RealOpenMM surfaceAreaFactor = obcSoftcoreParameters->getPi4Asolv();
const RealOpenMM* atomicRadii = obcSoftcoreParameters->getAtomicRadii(); // the original ACE equation is based on Eq.2 of
const RealOpenMM* nonPolarScaleFactors = obcSoftcoreParameters->getNonPolarScaleFactors();
int numberOfAtoms = obcSoftcoreParameters->getNumberOfAtoms();
// 1 + 1 + pow + 3 + 1 + 2 FLOP // M. Schaefer, C. Bartels and M. Karplus, "Solution Conformations
// and Thermodynamics of Structured Peptides: Molecular Dynamics
// Simulation with an Implicit Solvation Model", J. Mol. Biol.,
// 284, 835-848 (1998) (ACE Method)
// the original ACE equation is based on Eq.2 of // The original equation includes the factor (atomicRadii[atomI]/bornRadii[atomI]) to the first power,
// whereas here the ratio is raised to the sixth power: (atomicRadii[atomI]/bornRadii[atomI])**6
// M. Schaefer, C. Bartels and M. Karplus, "Solution Conformations // This modification was made by Jay Ponder and is based on observations that the change yields better correlations w/
// and Thermodynamics of Structured Peptides: Molecular Dynamics // expected values. Jay did not think it was important enough to write up, so there is
// Simulation with an Implicit Solvation Model", J. Mol. Biol., // no paper to cite.
// 284, 835-848 (1998) (ACE Method)
// The original equation includes the factor (atomicRadii[atomI]/bornRadii[atomI]) to the first power, for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
// whereas here the ratio is raised to the sixth power: (atomicRadii[atomI]/bornRadii[atomI])**6 if( bornRadii[atomI] > 0.0 ){
RealOpenMM r = atomicRadii[atomI] + probeRadius;
// This modification was made by Jay Ponder who observed it gave better correlations w/ RealOpenMM ratio6 = POW( atomicRadii[atomI]/bornRadii[atomI], static_cast<RealOpenMM>( 6.0 ) );
// observed values. He did not think it was important enough to write up, so there is RealOpenMM saTerm = nonPolarScaleFactors[atomI]*surfaceAreaFactor*r*r*ratio6;
// no paper to cite. *energy += saTerm;
forces[atomI] += minusSix*saTerm/bornRadii[atomI];
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){ }
if( bornRadii[atomI] > 0.0 ){ }
RealOpenMM r = atomicRadii[atomI] + probeRadius;
RealOpenMM ratio6 = POW( atomicRadii[atomI]/bornRadii[atomI], (RealOpenMM) 6.0 );
RealOpenMM saTerm = nonPolarScaleFactors[atomI]*surfaceAreaFactor*r*r*ratio6;
*energy += saTerm;
forces[atomI] += minusSix*saTerm/bornRadii[atomI];
}
}
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get Obc Born energy and forces Get Obc Born energy and forces
@param bornRadii Born radii -- optional; if NULL, then ObcSoftcoreParameters @param atomCoordinates atomic coordinates
entry is used @param partialCharges partial charges
@param atomCoordinates atomic coordinates @param forces forces
@param partialCharges partial charges
@param forces forces
The array bornRadii is also updated and the obcEnergy The array bornRadii is also updated and the obcEnergy
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void CpuObcSoftcore::computeBornEnergyForces( vector<RealOpenMM>& bornRadii, vector<RealVec>& atomCoordinates, RealOpenMM CpuObcSoftcore::computeBornEnergyForces( vector<RealVec>& atomCoordinates,
const RealOpenMM* partialCharges, vector<RealVec>& inputForces ){ const RealOpenMMVector& partialCharges,
vector<RealVec>& inputForces ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObcSoftcore::computeBornEnergyForces"; 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 = (RealOpenMM) 0.0; // ---------------------------------------------------------------------------------------
static const RealOpenMM one = (RealOpenMM) 1.0;
static const RealOpenMM two = (RealOpenMM) 2.0;
static const RealOpenMM three = (RealOpenMM) 3.0;
static const RealOpenMM four = (RealOpenMM) 4.0;
static const RealOpenMM half = (RealOpenMM) 0.5;
static const RealOpenMM fourth = (RealOpenMM) 0.25;
static const RealOpenMM eighth = (RealOpenMM) 0.125;
// --------------------------------------------------------------------------------------- const ObcSoftcoreParameters* obcSoftcoreParameters = getObcSoftcoreParameters();
const int numberOfAtoms = obcSoftcoreParameters->getNumberOfAtoms();
const ObcSoftcoreParameters* obcSoftcoreParameters = getObcSoftcoreParameters(); // ---------------------------------------------------------------------------------------
const int numberOfAtoms = obcSoftcoreParameters->getNumberOfAtoms();
// --------------------------------------------------------------------------------------- // constants
// constants const RealOpenMM preFactor = two*obcSoftcoreParameters->getElectricConstant()*(
(one/obcSoftcoreParameters->getSoluteDielectric()) -
(one/obcSoftcoreParameters->getSolventDielectric()) );
const RealOpenMM preFactor = obcSoftcoreParameters->getPreFactor(); const RealOpenMM dielectricOffset = obcSoftcoreParameters->getDielectricOffset();
const RealOpenMM dielectricOffset = obcSoftcoreParameters->getDielectricOffset();
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
#if 0 // compute Born radii
{
RealOpenMM* atomicRadii = obcSoftcoreParameters->getAtomicRadii();
const RealOpenMM* scaledRadiusFactor = obcSoftcoreParameters->getScaledRadiusFactors();
RealOpenMM* obcChain = getObcChain();
FILE* logFile = fopen( "bornParameters", "w" );
(void) fprintf( logFile, "%5d dielOff=%.4e rad::hct::q::bR::Chain::coords\n", numberOfAtoms, dielectricOffset );
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
(void) fprintf( logFile, "%5d %10.5f %10.5f %10.5f %14.7e %14.7e %14.7e %14.7e %14.7e\n", atomI,
atomicRadii[atomI], scaledRadiusFactor[atomI], partialCharges[atomI], bornRadii[atomI], obcChain[atomI],
atomCoordinates[atomI][0], atomCoordinates[atomI][1], atomCoordinates[atomI][2] );
}
(void) fclose( logFile );
}
#endif
// set energy/forces to zero
RealOpenMM obcEnergy = zero; RealOpenMMVector bornRadii( numberOfAtoms );
computeBornRadii( atomCoordinates, bornRadii );
RealOpenMM** forces = (RealOpenMM**) malloc( sizeof( RealOpenMM* )*numberOfAtoms ); RealOpenMM obcEnergy = zero;
RealOpenMM* block = (RealOpenMM*) malloc( sizeof( RealOpenMM )*numberOfAtoms*3 ); RealOpenMMVector bornForces( numberOfAtoms );
memset( block, 0, sizeof( RealOpenMM )*numberOfAtoms*3 ); for( int ii = 0; ii < numberOfAtoms; ii++ ){
RealOpenMM* blockPtr = block; bornForces[ii] = zero;
for( int ii = 0; ii < numberOfAtoms; ii++ ){ }
forces[ii] = blockPtr;
blockPtr += 3;
}
vector<RealOpenMM>& bornForces = getBornForce(); // ---------------------------------------------------------------------------------------
bornForces.assign(numberOfAtoms, 0.0);
// --------------------------------------------------------------------------------------- // N*( 8 + pow) ACE
// compute the nonpolar solvation via ACE approximation
// N*( 8 + pow) ACE
// compute the nonpolar solvation via ACE approximation if( includeAceApproximation() ){
computeAceNonPolarForce( obcSoftcoreParameters, bornRadii, &obcEnergy, bornForces );
if( includeAceApproximation() ){ }
computeAceNonPolarForce( obcSoftcoreParameters, bornRadii, &obcEnergy, bornForces );
}
const RealOpenMM* nonPolarScaleFactors = obcSoftcoreParameters->getNonPolarScaleFactors(); const RealOpenMMVector& nonPolarScaleFactors = obcSoftcoreParameters->getNonPolarScaleFactors();
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// first main loop // first main loop
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){ for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
RealOpenMM partialChargeI = preFactor*partialCharges[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 (_obcSoftcoreParameters->getPeriodic())
ReferenceForce::getDeltaRPeriodic( atomCoordinates[atomI], atomCoordinates[atomJ], _obcSoftcoreParameters->getPeriodicBox(), deltaR );
else
ReferenceForce::getDeltaR( atomCoordinates[atomI], atomCoordinates[atomJ], deltaR );
if (_obcSoftcoreParameters->getUseCutoff() && deltaR[ReferenceForce::RIndex] > _obcSoftcoreParameters->getCutoffDistance())
continue;
RealOpenMM r2 = deltaR[ReferenceForce::R2Index];
RealOpenMM deltaX = deltaR[ReferenceForce::XIndex];
RealOpenMM deltaY = deltaR[ReferenceForce::YIndex];
RealOpenMM deltaZ = deltaR[ReferenceForce::ZIndex];
RealOpenMM alpha2_ij = bornRadii[atomI]*bornRadii[atomJ];
RealOpenMM D_ij = r2/(four*alpha2_ij);
RealOpenMM expTerm = EXP( -D_ij ); RealOpenMM deltaR[ReferenceForce::LastDeltaRIndex];
RealOpenMM denominator2 = r2 + alpha2_ij*expTerm; if (_obcSoftcoreParameters->getPeriodic())
RealOpenMM denominator = SQRT( denominator2 ); ReferenceForce::getDeltaRPeriodic( atomCoordinates[atomI], atomCoordinates[atomJ], _obcSoftcoreParameters->getPeriodicBox(), deltaR );
else
ReferenceForce::getDeltaR( atomCoordinates[atomI], atomCoordinates[atomJ], deltaR );
if (_obcSoftcoreParameters->getUseCutoff() && deltaR[ReferenceForce::RIndex] > _obcSoftcoreParameters->getCutoffDistance())
continue;
RealOpenMM r2 = deltaR[ReferenceForce::R2Index];
RealOpenMM deltaX = deltaR[ReferenceForce::XIndex];
RealOpenMM deltaY = deltaR[ReferenceForce::YIndex];
RealOpenMM deltaZ = deltaR[ReferenceForce::ZIndex];
// charges are assumed to be scaled on input so nonPolarScaleFactor is not needed RealOpenMM alpha2_ij = bornRadii[atomI]*bornRadii[atomJ];
RealOpenMM D_ij = r2/(four*alpha2_ij);
//RealOpenMM nonPolarScaleFactor = atomI != atomJ ? nonPolarScaleFactors[atomI]*nonPolarScaleFactors[atomJ] : nonPolarScaleFactors[atomI]; RealOpenMM expTerm = EXP( -D_ij );
RealOpenMM denominator2 = r2 + alpha2_ij*expTerm;
RealOpenMM denominator = SQRT( denominator2 );
RealOpenMM Gpol = (partialChargeI*partialCharges[atomJ])/denominator; // charges are assumed to be scaled on input so nonPolarScaleFactor is not needed
// Gpol *= nonPolarScaleFactor;
RealOpenMM dGpol_dalpha2_ij = -half*Gpol*expTerm*( one + D_ij )/denominator2; RealOpenMM Gpol = (partialChargeI*partialCharges[atomJ])/denominator;
RealOpenMM dGpol_dr = -Gpol*( one - fourth*expTerm )/denominator2; RealOpenMM dGpol_dalpha2_ij = -half*Gpol*expTerm*( one + D_ij )/denominator2;
if( atomI != atomJ ){ RealOpenMM dGpol_dr = -Gpol*( one - fourth*expTerm )/denominator2;
bornForces[atomJ] += dGpol_dalpha2_ij*bornRadii[atomI]; if( atomI != atomJ ){
deltaX *= dGpol_dr; bornForces[atomJ] += dGpol_dalpha2_ij*bornRadii[atomI];
deltaY *= dGpol_dr;
deltaZ *= dGpol_dr;
forces[atomI][0] += deltaX; deltaX *= dGpol_dr;
forces[atomI][1] += deltaY; deltaY *= dGpol_dr;
forces[atomI][2] += deltaZ; deltaZ *= dGpol_dr;
forces[atomJ][0] -= deltaX; inputForces[atomI][0] += deltaX;
forces[atomJ][1] -= deltaY; inputForces[atomI][1] += deltaY;
forces[atomJ][2] -= deltaZ; inputForces[atomI][2] += deltaZ;
} else { inputForces[atomJ][0] -= deltaX;
Gpol *= half; inputForces[atomJ][1] -= deltaY;
} inputForces[atomJ][2] -= deltaZ;
// 3 FLOP } else {
Gpol *= half;
}
obcEnergy += Gpol; obcEnergy += Gpol;
bornForces[atomI] += dGpol_dalpha2_ij*bornRadii[atomJ]; bornForces[atomI] += dGpol_dalpha2_ij*bornRadii[atomJ];
} }
} }
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// second main loop // second main loop
// initialize Born radii & ObcChain temp arrays -- contain values RealOpenMMVector& obcChain = getObcChain();
// used in next iteration const RealOpenMMVector& atomicRadii = obcSoftcoreParameters->getAtomicRadii();
vector<RealOpenMM>& bornRadiiTemp = getBornRadiiTemp(); const RealOpenMM alphaObc = obcSoftcoreParameters->getAlphaObc();
bornRadiiTemp.assign(numberOfAtoms, 0.0); const RealOpenMM betaObc = obcSoftcoreParameters->getBetaObc();
const RealOpenMM gammaObc = obcSoftcoreParameters->getGammaObc();
const RealOpenMMVector& scaledRadiusFactor = obcSoftcoreParameters->getScaledRadiusFactors();
vector<RealOpenMM>& obcChainTemp = getObcChainTemp(); // compute factor that depends only on the outer loop index
obcChainTemp.assign(numberOfAtoms, 0.0);
vector<RealOpenMM>& obcChain = getObcChain(); for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
const RealOpenMM* atomicRadii = obcSoftcoreParameters->getAtomicRadii(); bornForces[atomI] *= bornRadii[atomI]*bornRadii[atomI]*obcChain[atomI];
}
const RealOpenMM alphaObc = obcSoftcoreParameters->getAlphaObc(); for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
const RealOpenMM betaObc = obcSoftcoreParameters->getBetaObc();
const RealOpenMM gammaObc = obcSoftcoreParameters->getGammaObc();
const RealOpenMM* scaledRadiusFactor = obcSoftcoreParameters->getScaledRadiusFactors();
// compute factor that depends only on the outer loop index
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
bornForces[atomI] *= bornRadii[atomI]*bornRadii[atomI]*obcChain[atomI];
}
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
// radius w/ dielectric offset applied // radius w/ dielectric offset applied
RealOpenMM radiusI = atomicRadii[atomI];
RealOpenMM offsetRadiusI = radiusI - dielectricOffset;
// used to compute Born radius for next iteration RealOpenMM radiusI = atomicRadii[atomI];
RealOpenMM offsetRadiusI = radiusI - dielectricOffset;
RealOpenMM bornSum = zero; 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 (_obcSoftcoreParameters->getPeriodic())
RealOpenMM deltaR[ReferenceForce::LastDeltaRIndex]; ReferenceForce::getDeltaRPeriodic( atomCoordinates[atomI], atomCoordinates[atomJ], _obcSoftcoreParameters->getPeriodicBox(), deltaR );
if (_obcSoftcoreParameters->getPeriodic()) else
ReferenceForce::getDeltaRPeriodic( atomCoordinates[atomI], atomCoordinates[atomJ], _obcSoftcoreParameters->getPeriodicBox(), deltaR ); ReferenceForce::getDeltaR( atomCoordinates[atomI], atomCoordinates[atomJ], deltaR );
else if (_obcSoftcoreParameters->getUseCutoff() && deltaR[ReferenceForce::RIndex] > _obcSoftcoreParameters->getCutoffDistance())
ReferenceForce::getDeltaR( atomCoordinates[atomI], atomCoordinates[atomJ], deltaR ); continue;
if (_obcSoftcoreParameters->getUseCutoff() && deltaR[ReferenceForce::RIndex] > _obcSoftcoreParameters->getCutoffDistance())
continue; RealOpenMM deltaX = deltaR[ReferenceForce::XIndex];
RealOpenMM deltaY = deltaR[ReferenceForce::YIndex];
RealOpenMM deltaX = deltaR[ReferenceForce::XIndex]; RealOpenMM deltaZ = deltaR[ReferenceForce::ZIndex];
RealOpenMM deltaY = deltaR[ReferenceForce::YIndex]; RealOpenMM r = deltaR[ReferenceForce::RIndex];
RealOpenMM deltaZ = deltaR[ReferenceForce::ZIndex];
RealOpenMM r = deltaR[ReferenceForce::RIndex];
// radius w/ dielectric offset applied // radius w/ dielectric offset applied
RealOpenMM offsetRadiusJ = atomicRadii[atomJ] - dielectricOffset; RealOpenMM offsetRadiusJ = atomicRadii[atomJ] - dielectricOffset;
RealOpenMM scaledRadiusJ = offsetRadiusJ*scaledRadiusFactor[atomJ]; RealOpenMM scaledRadiusJ = offsetRadiusJ*scaledRadiusFactor[atomJ];
RealOpenMM scaledRadiusJ2 = scaledRadiusJ*scaledRadiusJ; RealOpenMM scaledRadiusJ2 = scaledRadiusJ*scaledRadiusJ;
RealOpenMM rScaledRadiusJ = r + scaledRadiusJ; RealOpenMM rScaledRadiusJ = r + scaledRadiusJ;
// dL/dr & dU/dr are zero (this can be shown analytically) // dL/dr & dU/dr are zero (this can be shown analytically)
// removed from calculation // 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; l_ij = one/l_ij;
RealOpenMM u_ij = one/rScaledRadiusJ; RealOpenMM u_ij = one/rScaledRadiusJ;
RealOpenMM l_ij2 = l_ij*l_ij; RealOpenMM l_ij2 = l_ij*l_ij;
RealOpenMM u_ij2 = u_ij*u_ij; RealOpenMM u_ij2 = u_ij*u_ij;
RealOpenMM rInverse = one/r; RealOpenMM rInverse = one/r;
RealOpenMM r2Inverse = rInverse*rInverse; 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;
t3 *= nonPolarScaleFactors[atomI]*nonPolarScaleFactors[atomJ]; t3 *= nonPolarScaleFactors[atomI]*nonPolarScaleFactors[atomJ];
RealOpenMM de = bornForces[atomI]*t3*rInverse; RealOpenMM de = bornForces[atomI]*t3*rInverse;
deltaX *= de; deltaX *= de;
deltaY *= de; deltaY *= de;
deltaZ *= de; deltaZ *= de;
forces[atomI][0] -= deltaX; inputForces[atomI][0] -= deltaX;
forces[atomI][1] -= deltaY; inputForces[atomI][1] -= deltaY;
forces[atomI][2] -= deltaZ; inputForces[atomI][2] -= deltaZ;
forces[atomJ][0] += deltaX; inputForces[atomJ][0] += deltaX;
forces[atomJ][1] += deltaY; inputForces[atomJ][1] += deltaY;
forces[atomJ][2] += deltaZ; inputForces[atomJ][2] += deltaZ;
// Born radius term }
}
RealOpenMM term = l_ij - u_ij + fourth*r*(u_ij2 - l_ij2) + (half*rInverse)*LN(u_ij/l_ij) + }
(fourth*scaledRadiusJ*scaledRadiusJ*rInverse)*(l_ij2-u_ij2); }
if( offsetRadiusI < (scaledRadiusJ - r) ){
term += two*( (one/offsetRadiusI) - l_ij);
}
bornSum += term;
}
}
}
// OBC-specific code (Eqs. 6-8 in paper)
bornSum *= half*offsetRadiusI;
RealOpenMM sum2 = bornSum*bornSum;
RealOpenMM sum3 = bornSum*sum2;
RealOpenMM tanhSum = TANH( alphaObc*bornSum - betaObc*sum2 + gammaObc*sum3 );
bornRadiiTemp[atomI] = one/( one/offsetRadiusI - tanhSum/radiusI );
obcChainTemp[atomI] = offsetRadiusI*( alphaObc - two*betaObc*bornSum + three*gammaObc*sum2 );
obcChainTemp[atomI] = (one - tanhSum*tanhSum)*obcChainTemp[atomI]/radiusI;
}
// cal to Joule conversion
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
inputForces[atomI][0] += forces[atomI][0];
inputForces[atomI][1] += forces[atomI][1];
inputForces[atomI][2] += forces[atomI][2];
}
setEnergy( obcEnergy );
#if 0
{
RealOpenMM* atomicRadii = obcSoftcoreParameters->getAtomicRadii();
const RealOpenMM* scaledRadiusFactor = obcSoftcoreParameters->getScaledRadiusFactors();
RealOpenMM* obcChain = getObcChain();
//FILE* logFile = fopen( "bornParameters", "w" );
FILE* logFile = stderr;
(void) fprintf( logFile, "%5d dielOff=%.4e rad::hct::q::bR::Chain::bF::f::coords\n", numberOfAtoms, dielectricOffset );
for( int atomI = 0; atomI < numberOfAtoms; atomI++ ){
(void) fprintf( logFile, "%5d %10.5f %10.5f q=%10.5f b[%14.7e %14.7e %14.7e] f[%14.7e %14.7e %14.7e] x[%14.7e %14.7e %14.7e]\n", atomI,
atomicRadii[atomI], scaledRadiusFactor[atomI], partialCharges[atomI], bornRadii[atomI], obcChain[atomI],
conversion*bornForces[atomI],
conversion*forces[atomI][0], conversion*forces[atomI][1], conversion*forces[atomI][2],
atomCoordinates[atomI][0], atomCoordinates[atomI][1], atomCoordinates[atomI][2] );
}
if( logFile != stderr || logFile != stdout ){
(void) fclose( logFile );
}
}
#endif
// copy new Born radii and obcChain values into permanent array
bornRadii = bornRadiiTemp; return obcEnergy;;
obcChain = obcChainTemp;
free( (char*) block );
free( (char*) forces );
} }
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
class CpuObcSoftcore : public CpuImplicitSolvent { class CpuObcSoftcore {
private: private:
...@@ -40,13 +40,12 @@ class CpuObcSoftcore : public CpuImplicitSolvent { ...@@ -40,13 +40,12 @@ class CpuObcSoftcore : public CpuImplicitSolvent {
// arrays containing OBC chain derivative // arrays containing OBC chain derivative
std::vector<RealOpenMM> _obcChain; RealOpenMMVector _obcChain;
std::vector<RealOpenMM> _obcChainTemp;
// initialize data members (more than // flag to signal whether ACE approximation
// one constructor, so centralize intialization here) // is to be included
void _initializeObcDataMembers( void ); int _includeAceApproximation;
public: public:
...@@ -60,7 +59,7 @@ class CpuObcSoftcore : public CpuImplicitSolvent { ...@@ -60,7 +59,7 @@ class CpuObcSoftcore : public CpuImplicitSolvent {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
CpuObcSoftcore( ImplicitSolventParameters* obcSoftcoreParameters ); CpuObcSoftcore( ObcSoftcoreParameters* obcSoftcoreParameters );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -92,26 +91,45 @@ class CpuObcSoftcore : public CpuImplicitSolvent { ...@@ -92,26 +91,45 @@ class CpuObcSoftcore : public CpuImplicitSolvent {
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Return OBC chain derivative: size = _implicitSolventParameters->getNumberOfAtoms() Return flag signalling whether AceApproximation for nonpolar term is to be included
On first call, memory for array is allocated if not set
@return array @return flag
--------------------------------------------------------------------------------------- */
int includeAceApproximation( void ) const;
/**---------------------------------------------------------------------------------------
Set flag indicating whether AceApproximation is to be included
@param includeAceApproximation new includeAceApproximation value
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void setIncludeAceApproximation( int includeAceApproximation );
/**---------------------------------------------------------------------------------------
Get energy
std::vector<RealOpenMM>& getObcChain( void ); @return energy
const std::vector<RealOpenMM>& getObcChainConst( void ) const;
--------------------------------------------------------------------------------------- */
RealOpenMM getEnergy( void ) const;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Return OBC chain temp work array of size=_implicitSolventParameters->getNumberOfAtoms() Return OBC chain derivative: size = _implicitSolventParameters->getNumberOfAtoms()
On first call, memory for array is allocated if not set On first call, memory for array is allocated if not set
@return array @return array
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
std::vector<RealOpenMM>& getObcChainTemp( void ); RealOpenMMVector& getObcChain( void );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -124,7 +142,7 @@ class CpuObcSoftcore : public CpuImplicitSolvent { ...@@ -124,7 +142,7 @@ class CpuObcSoftcore : public CpuImplicitSolvent {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void computeBornRadii( std::vector<OpenMM::RealVec>& atomCoordinates, std::vector<RealOpenMM>& bornRadii ); void computeBornRadii( std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMMVector& bornRadii );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -139,22 +157,23 @@ class CpuObcSoftcore : public CpuImplicitSolvent { ...@@ -139,22 +157,23 @@ class CpuObcSoftcore : public CpuImplicitSolvent {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void computeAceNonPolarForce( const ObcSoftcoreParameters* obcSoftcoreParameters, void computeAceNonPolarForce( const ObcSoftcoreParameters* obcSoftcoreParameters,
const std::vector<RealOpenMM>& bornRadii, RealOpenMM* energy, const RealOpenMMVector& bornRadii, RealOpenMM* energy,
std::vector<RealOpenMM>& forces ) const; RealOpenMMVector& forces ) const;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get Born energy and forces based on OBC Get Born energy and forces based on OBC
@param bornRadii Born radii
@param atomCoordinates atomic coordinates @param atomCoordinates atomic coordinates
@param partialCharges partial charges @param partialCharges partial charges
@param forces forces @param forces forces
@return energy
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void computeBornEnergyForces( std::vector<RealOpenMM>& bornRadii, std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM computeBornEnergyForces( std::vector<OpenMM::RealVec>& atomCoordinates,
const RealOpenMM* partialCharges, std::vector<OpenMM::RealVec>& forces ); const RealOpenMMVector& partialCharges, std::vector<OpenMM::RealVec>& forces );
}; };
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
......
...@@ -26,764 +26,425 @@ ...@@ -26,764 +26,425 @@
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
#include "openmm/OpenMMException.h"
#include "ObcSoftcoreParameters.h" #include "ObcSoftcoreParameters.h"
#include "../SimTKUtilities/SimTKOpenMMCommon.h" #include "../SimTKUtilities/SimTKOpenMMCommon.h"
#include "../SimTKUtilities/SimTKOpenMMLog.h"
#include "../SimTKUtilities/SimTKOpenMMUtilities.h"
// #define UseGromacsMalloc 1
#ifdef UseGromacsMalloc
extern "C" {
#include "smalloc.h"
}
#endif
const std::string ObcSoftcoreParameters::ParameterFileName = std::string( "params.agb" );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
ObcSoftcoreParameters: ObcSoftcoreParameters constructor
Calculates for each atom
(1) the van der Waal radii
(2) volume
(3) fixed terms in Obc equation gPol
(4) list of atoms that should be excluded in calculating
force -- nonbonded atoms (1-2, and 1-3 atoms)
Implementation:
Slightly different sequence of calls when running on CPU vs GPU.
Difference arise because the CPU-side data arrays for the Brook
streams are allocated by the BrookStreamWrapper objects. These
arrays are then used by ObcSoftcoreParameters when initializing the
the values (vdwRadii, volume, ...) to be used in the calculation.
Cpu:
ObcSoftcoreParameters* obcParameters = new ObcSoftcoreParameters( numberOfAtoms, log );
obcParameters->initializeParameters( top );
Gpu:
obcParameters = new ObcSoftcoreParameters( gpu->natoms, log );
// set arrays for cpu using stream data field;
// initializeParameters() only allocates space for arrays if they are not set (==NULL)
// also set flag so that ObcSoftcoreParameters destructor does not free arrays
obcParameters->setVdwRadii( getBrookStreamWrapperAtIndex( GpuObc::obcVdwRadii )->getData() );
obcParameters->setVolume( getBrookStreamWrapperAtIndex( GpuObc::obcVolume )->getData() );
obcParameters->setGPolFixed( getBrookStreamWrapperAtIndex( GpuObc::obcGpolFixed )->getData() );
obcParameters->setBornRadii( getBrookStreamWrapperAtIndex( GpuObc::obcBornRadii )->getData() );
obcParameters->setFreeArrays( false );
obcParameters->initializeParameters( top );
Issues:
Tinker's atom radii are used.
The logic for mapping the Gromacs atom names to Tinker type may be incomplete;
only tested for generic proteins
see mapGmxAtomNameToTinkerAtomNumber()
--------------------------------------------------------------------------------------- */
@param numberOfAtoms number of atoms
@param obcType OBC type (Eq. 7 or 8 in paper)
/**--------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------- */
ObcSoftcoreParameters constructor (Simbios)
@param numberOfAtoms number of atoms
@param obcType OBC type (Eq. 7 or 8 in paper)
--------------------------------------------------------------------------------------- */
ObcSoftcoreParameters::ObcSoftcoreParameters( int numberOfAtoms, ObcSoftcoreParameters::ObcType obcType ) : ImplicitSolventParameters( numberOfAtoms ), cutoff(false), periodic(false) { ObcSoftcoreParameters::ObcSoftcoreParameters( int numberOfAtoms, ObcSoftcoreParameters::ObcType obcType ) :
_numberOfAtoms(numberOfAtoms),
_obcType(obcType), _dielectricOffset(0.009), _nonPolarPreFactor(2.25936),
_soluteDielectric(1.0), _solventDielectric(78.3), _probeRadius(0.14),
_electricConstant(-0.5*ONE_4PI_EPS0), _pi4Asolv( 28.3919551),
_cutoff(false), _periodic(false) {
// --------------------------------------------------------------------------------------- _atomicRadii.resize( numberOfAtoms );
_scaledRadiusFactors.resize( numberOfAtoms );
_nonPolarScaleFactors.resize( numberOfAtoms );
// static const char* methodName = "\nObcSoftcoreParameters::ObcSoftcoreParameters"; setObcTypeParameters( obcType );
// ---------------------------------------------------------------------------------------
_obcType = obcType;
_dielectricOffset = 0.009f;
_ownScaledRadiusFactors = 0;
_scaledRadiusFactors = NULL;
_ownNonPolarScaleFactors = 0;
_nonPolarScaleFactors = NULL;
_nonPolarPreFactor = (RealOpenMM) 2.25936;
setObcTypeParameters( obcType );
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
ObcSoftcoreParameters destructor (Simbios) ObcSoftcoreParameters destructor
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ObcSoftcoreParameters::~ObcSoftcoreParameters( ){ ObcSoftcoreParameters::~ObcSoftcoreParameters( ){
}
// --------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
// static const char* methodName = "\nObcSoftcoreParameters::~ObcSoftcoreParameters";
// ---------------------------------------------------------------------------------------
// in GPU runs, arrays may be 'owned' by BrookStreamWrapper -- hence they should not
// be freed here, i.e., _freeArrays should be 'false'
#ifdef UseGromacsMalloc
/*
if( _freeArrays ){
if( _vdwRadii != NULL ){
save_free( "_vdwRadii", __FILE__, __LINE__, _vdwRadii );
}
} */
#else
if( _ownScaledRadiusFactors ){
delete[] _scaledRadiusFactors;
}
if( _ownNonPolarScaleFactors ){
delete[] _nonPolarScaleFactors;
}
/* Get number of atoms
if( getFreeArrays() ){
} */ @return number of atoms
#endif --------------------------------------------------------------------------------------- */
int ObcSoftcoreParameters::getNumberOfAtoms( void ) const {
return _numberOfAtoms;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get OBC type Get OBC type
@return OBC type @return OBC type
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ObcSoftcoreParameters::ObcType ObcSoftcoreParameters::getObcType( void ) const { ObcSoftcoreParameters::ObcType ObcSoftcoreParameters::getObcType( void ) const {
return _obcType;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nObcSoftcoreParameters::getObcType:";
// ---------------------------------------------------------------------------------------
return _obcType;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Set OBC type specific parameters Set OBC type specific parameters
@param obcType OBC type (ObcTypeI or ObcTypeII -- Eq. 7 or 8) @param obcType OBC type (ObcTypeI or ObcTypeII -- Eq. 7 or 8)
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcSoftcoreParameters::setObcTypeParameters( ObcSoftcoreParameters::ObcType obcType ){ void ObcSoftcoreParameters::setObcTypeParameters( ObcSoftcoreParameters::ObcType obcType ){
// --------------------------------------------------------------------------------------- if( obcType == ObcTypeI ){
_alphaObc = 0.8f;
// static const char* methodName = "\nObcSoftcoreParameters::setObcTypeParameters:"; _betaObc = 0.0f;
_gammaObc = 2.91f;
// --------------------------------------------------------------------------------------- } else {
_alphaObc = 1.0f;
if( obcType == ObcTypeI ){ _betaObc = 0.8f;
_alphaObc = 0.8f; _gammaObc = 4.85f;
_betaObc = 0.0f; }
_gammaObc = 2.91f; _obcType = obcType;
} else {
_alphaObc = 1.0f;
_betaObc = 0.8f;
_gammaObc = 4.85f;
}
_obcType = obcType;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get dielectricOffset Get dielectricOffset
@return _dielectricOffset @return _dielectricOffset
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcSoftcoreParameters::getDielectricOffset( void ) const { RealOpenMM ObcSoftcoreParameters::getDielectricOffset( void ) const {
return _dielectricOffset;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nObcSoftcoreParameters::getDielectricOffset:";
// ---------------------------------------------------------------------------------------
return _dielectricOffset;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get alpha OBC (Eqs. 6 & 7) in Proteins paper Get alpha OBC (Eqs. 6 & 7) in Proteins paper
@return alphaObc @return alphaObc
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcSoftcoreParameters::getAlphaObc( void ) const { RealOpenMM ObcSoftcoreParameters::getAlphaObc( void ) const {
return _alphaObc;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nObcSoftcoreParameters::getAlphaObc:";
// ---------------------------------------------------------------------------------------
return _alphaObc;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get beta OBC (Eqs. 6 & 7) in Proteins paper Get beta OBC (Eqs. 6 & 7) in Proteins paper
@return betaObc @return betaObc
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcSoftcoreParameters::getBetaObc( void ) const { RealOpenMM ObcSoftcoreParameters::getBetaObc( void ) const {
return _betaObc;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nObcSoftcoreParameters::getBetaObc:";
// ---------------------------------------------------------------------------------------
return _betaObc;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get gamma OBC (Eqs. 6 & 7) in Proteins paper Get gamma OBC (Eqs. 6 & 7) in Proteins paper
@return gammaObc @return gammaObc
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcSoftcoreParameters::getGammaObc( void ) const { RealOpenMM ObcSoftcoreParameters::getGammaObc( void ) const {
return _gammaObc;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nObcSoftcoreParameters::getGammaObc:";
// ---------------------------------------------------------------------------------------
return _gammaObc;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get AtomicRadii array Get solvent dielectric
@return array of atomic radii @return solvent dielectric
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM* ObcSoftcoreParameters::getAtomicRadii( void ) const { RealOpenMM ObcSoftcoreParameters::getSolventDielectric( void ) const {
return _solventDielectric;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nImplicitSolventParameters::getAtomicRadii:";
// ---------------------------------------------------------------------------------------
RealOpenMM* atomicRadii = ImplicitSolventParameters::getAtomicRadii();
// if dielectric offset applied, then unapply
return atomicRadii;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Set AtomicRadii array Set solvent dielectric
@param atomicRadii array of atomic radii @param solventDielectric solvent dielectric
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcSoftcoreParameters::setAtomicRadii( RealOpenMM* atomicRadii ){ void ObcSoftcoreParameters::setSolventDielectric( RealOpenMM solventDielectric ){
_solventDielectric = solventDielectric;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nObcSoftcoreParameters::setAtomicRadii:";
// ---------------------------------------------------------------------------------------
ImplicitSolventParameters::setAtomicRadii( atomicRadii );
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Set AtomicRadii array Get solute dielectric
@param atomicRadii vector of atomic radii @return soluteDielectric
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcSoftcoreParameters::setAtomicRadii( const RealOpenMMVector& atomicRadii ){ RealOpenMM ObcSoftcoreParameters::getSoluteDielectric( void ) const {
return _soluteDielectric;
// ---------------------------------------------------------------------------------------
static const char* methodName = "\nObcSoftcoreParameters::setAtomicRadii:";
// ---------------------------------------------------------------------------------------
ImplicitSolventParameters::setAtomicRadii( atomicRadii );
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Return OBC scale factors Set solute dielectric
If not previously set, allocate space
@return array @param soluteDielectric solute dielectric
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
const RealOpenMM* ObcSoftcoreParameters::getScaledRadiusFactors( void ) const { void ObcSoftcoreParameters::setSoluteDielectric( RealOpenMM soluteDielectric ){
_soluteDielectric = soluteDielectric;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObc::getScaledRadiusFactors";
// ---------------------------------------------------------------------------------------
if( _scaledRadiusFactors == NULL ){
ObcSoftcoreParameters* localThis = const_cast<ObcSoftcoreParameters* const>(this);
localThis->_scaledRadiusFactors = new RealOpenMM[getNumberOfAtoms()];
localThis->_ownScaledRadiusFactors = true;
memset( _scaledRadiusFactors, 0, sizeof( RealOpenMM )*getNumberOfAtoms() );
}
return _scaledRadiusFactors;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Set flag indicating whether scale factors array should be deleted Get electric constant
@param ownScaledRadiusFactors flag indicating whether scale factors @return electricConstant
array should be deleted
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcSoftcoreParameters::setOwnScaleFactors( int ownScaledRadiusFactors ){ RealOpenMM ObcSoftcoreParameters::getElectricConstant( void ) const {
return _electricConstant;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObc::setOwnScaleFactors";
// ---------------------------------------------------------------------------------------
_ownScaledRadiusFactors = ownScaledRadiusFactors;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Set OBC scale factors Get probe radius
@param scaledRadiusFactors scaledRadiusFactors @return probeRadius
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcSoftcoreParameters::setScaledRadiusFactors( RealOpenMM* scaledRadiusFactors ){ RealOpenMM ObcSoftcoreParameters::getProbeRadius( void ) const {
return _probeRadius;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObc::setScaledRadiusFactors";
// ---------------------------------------------------------------------------------------
if( _ownScaledRadiusFactors && _scaledRadiusFactors != scaledRadiusFactors ){
delete[] _scaledRadiusFactors;
_ownScaledRadiusFactors = false;
}
_scaledRadiusFactors = scaledRadiusFactors;
} }
#if RealOpenMMType == 0
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Set OBC scale factors Set probe radius
@param scaledRadiusFactors scaledRadiusFactors @param probeRadius probe radius
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcSoftcoreParameters::setScaledRadiusFactors( float* scaledRadiusFactors ){ void ObcSoftcoreParameters::setProbeRadius( RealOpenMM probeRadius ){
_probeRadius = probeRadius;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObc::setScaledRadiusFactors";
// ---------------------------------------------------------------------------------------
if( _scaledRadiusFactors == NULL ){
_scaledRadiusFactors = new RealOpenMM[getNumberOfAtoms()];
_ownScaledRadiusFactors = true;
}
for( int ii = 0; ii < getNumberOfAtoms(); ii++ ){
_scaledRadiusFactors[ii] = (RealOpenMM) scaledRadiusFactors[ii];
}
} }
#endif
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Set OBC scale factors Get pi*4*Asolv: used in ACE approximation for nonpolar term
((RealOpenMM) M_PI)*4.0f*0.0049*1000.0; (Still)
((RealOpenMM) M_PI)*4.0f*0.0054*1000.0; (OBC)
@param scaledRadiusFactors scaledRadiusFactors @return pi4Asolv
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcSoftcoreParameters::setScaledRadiusFactors( const RealOpenMMVector& scaledRadiusFactors ){ RealOpenMM ObcSoftcoreParameters::getPi4Asolv( void ) const {
return _pi4Asolv;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObc::setScaledRadiusFactors";
// ---------------------------------------------------------------------------------------
if( _ownScaledRadiusFactors && _scaledRadiusFactors != NULL ){
delete[] _scaledRadiusFactors;
}
_ownScaledRadiusFactors = true;
_scaledRadiusFactors = new RealOpenMM[getNumberOfAtoms()];
for( int ii = 0; ii < (int) scaledRadiusFactors.size(); ii++ ){
_scaledRadiusFactors[ii] = scaledRadiusFactors[ii];
}
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Map Gmx atom name to Tinker atom number (Simbios) Get AtomicRadii array
@param atomName atom name (CA, HA, ...); upper and lower case should both work
@param log if set, then print error messages to log file
@return Tinker atom number if atom name is valid; else return -1
--------------------------------------------------------------------------------------- */
int ObcSoftcoreParameters::mapGmxAtomNameToTinkerAtomNumber( const char* atomName, FILE* log ) const {
// --------------------------------------------------------------------------------------- @return array of atomic radii
static int mapCreated = 0; --------------------------------------------------------------------------------------- */
static int atomNameMap[26];
// ---------------------------------------------------------------------------------------
// set up atomNameMap array on first call to this method const RealOpenMMVector& ObcSoftcoreParameters::getAtomicRadii( void ) const {
return _atomicRadii;
// atomNameMap[ii] = Tinker atom number }
// where ii = (the ASCII index - 65) of the first character in the
// input atom name; name may be lower case
if( !mapCreated ){
mapCreated = 1;
for( int ii = 0; ii < 26; ii++ ){
atomNameMap[ii] = -1;
}
// H
atomNameMap[7] = 1;
// C
atomNameMap[2] = 6;
// N
atomNameMap[13] = 7;
// O
atomNameMap[14] = 8;
// S
atomNameMap[18] = 16;
}
// map first letter in atom name to Tinker atom number /**---------------------------------------------------------------------------------------
int firstAsciiValue = ((int) atomName[0]) - 65; Set AtomicRadii array
// check for lower case @param atomicRadii vector of atomic radii
if( firstAsciiValue > 25 ){ --------------------------------------------------------------------------------------- */
firstAsciiValue -= 32;
}
// validate void ObcSoftcoreParameters::setAtomicRadii( const RealOpenMMVector& atomicRadii ){
if( firstAsciiValue < 0 || firstAsciiValue > 25 ){ if( atomicRadii.size() == _atomicRadii.size() ){
if( log != NULL ){ for( unsigned int ii = 0; ii < atomicRadii.size(); ii++ ){
(void) fprintf( log, "Atom name=<%s> unrecognized.", atomName ); _atomicRadii[ii] = atomicRadii[ii];
} }
(void) fprintf( stderr, "Atom name=<%s> unrecognized.", atomName ); } else {
return -1; std::stringstream msg;
} msg << "ObcSoftcoreParameters: input size for atomic radii does not agree w/ current size: input=";
return atomNameMap[firstAsciiValue]; msg << atomicRadii.size();
msg << " current size=" << _atomicRadii.size();
throw OpenMM::OpenMMException(msg.str());
}
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get string w/ state
@param title title (optional)
@return string
--------------------------------------------------------------------------------------- */
std::string ObcSoftcoreParameters::getStateString( const char* title ) const { Return OBC scale factors
// --------------------------------------------------------------------------------------- @return array
// static const char* methodName = "\nObcSoftcoreParameters::getStateString"; --------------------------------------------------------------------------------------- */
// --------------------------------------------------------------------------------------- const RealOpenMMVector& ObcSoftcoreParameters::getScaledRadiusFactors( void ) const {
return _scaledRadiusFactors;
}
std::stringstream message; /**---------------------------------------------------------------------------------------
message << ImplicitSolventParameters::getStateString( title );
std::string tab = getStringTab(); Set OBC scale factors
if( getObcType() == ObcTypeI ){ @param scaledRadiusFactors scaledRadiusFactors
message << tab << "OBC type: Type I";
} else {
message << tab << "OBC type: Type II";
}
message << tab << "Alpha: " << getAlphaObc();
message << tab << "Beta: " << getBetaObc();
message << tab << "Gamma: " << getGammaObc();
return message.str(); --------------------------------------------------------------------------------------- */
void ObcSoftcoreParameters::setScaledRadiusFactors( const RealOpenMMVector& scaledRadiusFactors ){
if( scaledRadiusFactors.size() == _scaledRadiusFactors.size() ){
for( unsigned int ii = 0; ii < scaledRadiusFactors.size(); ii++ ){
_scaledRadiusFactors[ii] = scaledRadiusFactors[ii];
}
} else {
std::stringstream msg;
msg << "ObcSoftcoreParameters: input size for scaled radius factors does not agree w/ current size: input=";
msg << scaledRadiusFactors.size();
msg << " current size=" << _scaledRadiusFactors.size();
throw OpenMM::OpenMMException(msg.str());
}
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Set the force to use a cutoff. Set the force to use a cutoff.
@param distance the cutoff distance @param distance the cutoff distance
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcSoftcoreParameters::setUseCutoff( RealOpenMM distance ) { void ObcSoftcoreParameters::setUseCutoff( RealOpenMM distance ) {
_cutoff = true;
cutoff = true; _cutoffDistance = distance;
cutoffDistance = distance;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get whether to use a cutoff. Get whether to use a cutoff.
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
bool ObcSoftcoreParameters::getUseCutoff() { bool ObcSoftcoreParameters::getUseCutoff() {
return cutoff; return _cutoff;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get the cutoff distance. Get the cutoff distance.
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcSoftcoreParameters::getCutoffDistance() { RealOpenMM ObcSoftcoreParameters::getCutoffDistance() {
return cutoffDistance; return _cutoffDistance;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Set the force to use periodic boundary conditions. This requires that a cutoff has Set the force to use periodic boundary conditions. This requires that a cutoff has
also been set, and the smallest side of the periodic box is at least twice the cutoff also been set, and the smallest side of the periodic box is at least twice the cutoff
distance. distance.
@param boxSize the X, Y, and Z widths of the periodic box @param boxSize the X, Y, and Z widths of the periodic box
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcSoftcoreParameters::setPeriodic( RealOpenMM* boxSize ) { void ObcSoftcoreParameters::setPeriodic( RealOpenMM* boxSize ) {
assert(cutoff); assert(_cutoff);
assert(boxSize[0] >= 2.0*cutoffDistance);
assert(boxSize[1] >= 2.0*cutoffDistance);
assert(boxSize[2] >= 2.0*cutoffDistance);
periodic = true;
periodicBoxSize[0] = boxSize[0];
periodicBoxSize[1] = boxSize[1];
periodicBoxSize[2] = boxSize[2];
}
/**---------------------------------------------------------------------------------------
Get whether to use periodic boundary conditions. assert(boxSize[0] >= 2.0*_cutoffDistance);
assert(boxSize[1] >= 2.0*_cutoffDistance);
assert(boxSize[2] >= 2.0*_cutoffDistance);
--------------------------------------------------------------------------------------- */ _periodic = true;
_periodicBoxSize[0] = boxSize[0];
bool ObcSoftcoreParameters::getPeriodic() { _periodicBoxSize[1] = boxSize[1];
return periodic; _periodicBoxSize[2] = boxSize[2];
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get the periodic box dimension Get whether to use periodic boundary conditions.
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
const RealOpenMM* ObcSoftcoreParameters::getPeriodicBox() { bool ObcSoftcoreParameters::getPeriodic() {
return periodicBoxSize; return _periodic;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Return non-polar scale factors Get the periodic box dimension
If not previously set, allocate space
@return array
--------------------------------------------------------------------------------------- */
const RealOpenMM* ObcSoftcoreParameters::getNonPolarScaleFactors( void ) const {
// ---------------------------------------------------------------------------------------
// static const char* methodName = "ObcSoftcoreParameters::getNonPolarScaleFactors";
// --------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------- */
if( _nonPolarScaleFactors == NULL ){ const RealOpenMM* ObcSoftcoreParameters::getPeriodicBox() {
ObcSoftcoreParameters* localThis = const_cast<ObcSoftcoreParameters* const>(this); return _periodicBoxSize;
localThis->_nonPolarScaleFactors = new RealOpenMM[getNumberOfAtoms()];
localThis->_ownNonPolarScaleFactors = true;
memset( _nonPolarScaleFactors, 0, sizeof( RealOpenMM )*getNumberOfAtoms() );
}
return _nonPolarScaleFactors;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Set flag indicating whether scale factors array should be deleted Return non-polar scale factors
@param ownNonPolarScaleFactors flag indicating whether scale factors
array should be deleted
--------------------------------------------------------------------------------------- */
void ObcSoftcoreParameters::setOwnNonPolarScaleFactors( int ownNonPolarScaleFactors ){
// --------------------------------------------------------------------------------------- @return array
// static const char* methodName = "\nCpuObc::setOwnScaleFactors"; --------------------------------------------------------------------------------------- */
// --------------------------------------------------------------------------------------- const RealOpenMMVector& ObcSoftcoreParameters::getNonPolarScaleFactors( void ) const {
return _nonPolarScaleFactors;
_ownNonPolarScaleFactors = ownNonPolarScaleFactors;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Set non-polar scale factors Set non-polar scale factors
@param nonPolarScaleFactors nonPolarScaleFactors @param nonPolarScaleFactors nonPolarScaleFactors
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcSoftcoreParameters::setNonPolarScaleFactors( const RealOpenMMVector& nonPolarScaleFactors ){ void ObcSoftcoreParameters::setNonPolarScaleFactors( const RealOpenMMVector& nonPolarScaleFactors ){
// --------------------------------------------------------------------------------------- if( nonPolarScaleFactors.size() == _nonPolarScaleFactors.size() ){
for( unsigned int ii = 0; ii < nonPolarScaleFactors.size(); ii++ ){
// static const char* methodName = "\nCpuObc::setNonPolarScaleFactors"; _nonPolarScaleFactors[ii] = nonPolarScaleFactors[ii];
}
// --------------------------------------------------------------------------------------- } else {
std::stringstream msg;
if( _ownNonPolarScaleFactors ){ msg << "ObcSoftcoreParameters: input size for non-polar scale factors does not agree w/ current size: input=";
delete[] _nonPolarScaleFactors; msg << nonPolarScaleFactors.size();
} msg << " current size=" << _nonPolarScaleFactors.size();
_ownNonPolarScaleFactors = true; throw OpenMM::OpenMMException(msg.str());
_nonPolarScaleFactors = new RealOpenMM[nonPolarScaleFactors.size()]; }
for( int ii = 0; ii < getNumberOfAtoms(); ii++ ){
_nonPolarScaleFactors[ii] = nonPolarScaleFactors[ii];
}
}
#if RealOpenMMType == 0
/**---------------------------------------------------------------------------------------
Set non-polar scale factors
@param nonPolarScaleFactors nonPolarScaleFactors
--------------------------------------------------------------------------------------- */
void ObcSoftcoreParameters::setNonPolarScaleFactors( float* nonPolarScaleFactors ){
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObc::setNonPolarScaleFactors";
// ---------------------------------------------------------------------------------------
if( _nonPolarScaleFactors == NULL ){
_nonPolarScaleFactors = new RealOpenMM[getNumberOfAtoms()];
_ownNonPolarScaleFactors = true;
}
for( int ii = 0; ii < getNumberOfAtoms(); ii++ ){
_nonPolarScaleFactors[ii] = (RealOpenMM) nonPolarScaleFactors[ii];
}
} }
#endif
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Set OBC scale factors Set OBC scale factors
@param nonPolarScaleFactors nonPolarScaleFactors @param nonPolarScaleFactors nonPolarScaleFactors
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcSoftcoreParameters::setNonPolarPrefactor( RealOpenMM nonPolarPreFactor ){ void ObcSoftcoreParameters::setNonPolarPrefactor( RealOpenMM nonPolarPreFactor ){
_nonPolarPreFactor = nonPolarPreFactor;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nCpuObc::setNonPolarScaleFactors";
// ---------------------------------------------------------------------------------------
_nonPolarPreFactor = nonPolarPreFactor;
} }
/* Portions copyright (c) 2006-2009 Stanford University and Simbios. /* Portions copyright (c) 2006-2009 Stanford University and Simbios.
* Contributors: Pande Group * Contributors: Pande Group
* *
...@@ -26,11 +25,10 @@ ...@@ -26,11 +25,10 @@
#define __ObcSoftcoreParameters_H__ #define __ObcSoftcoreParameters_H__
#include "../SimTKUtilities/SimTKOpenMMCommon.h" #include "../SimTKUtilities/SimTKOpenMMCommon.h"
#include "gbsa/ImplicitSolventParameters.h"
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
class ObcSoftcoreParameters : public ImplicitSolventParameters { class ObcSoftcoreParameters {
public: public:
...@@ -38,37 +36,42 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters { ...@@ -38,37 +36,42 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters {
enum ObcType { ObcTypeI, ObcTypeII }; enum ObcType { ObcTypeI, ObcTypeII };
static const std::string ParameterFileName;
private: private:
int _numberOfAtoms;
// OBC constants & parameters // OBC constants & parameters
RealOpenMM _dielectricOffset; RealOpenMM _dielectricOffset;
RealOpenMM _alphaObc; RealOpenMM _alphaObc;
RealOpenMM _betaObc; RealOpenMM _betaObc;
RealOpenMM _gammaObc; RealOpenMM _gammaObc;
RealOpenMM _probeRadius;
RealOpenMM _pi4Asolv;
ObcType _obcType; ObcType _obcType;
RealOpenMM _nonPolarPreFactor; RealOpenMM _nonPolarPreFactor;
RealOpenMM _solventDielectric;
RealOpenMM _soluteDielectric;
RealOpenMM _electricConstant;
// scaling factors for nonpolar term // scaling factors for nonpolar term
int _ownNonPolarScaleFactors; RealOpenMMVector _atomicRadii;
RealOpenMM* _nonPolarScaleFactors; RealOpenMMVector _nonPolarScaleFactors;
// scaled radius factors (S_kk in HCT paper) // scaled radius factors (S_kk in HCT paper)
int _ownScaledRadiusFactors; RealOpenMMVector _scaledRadiusFactors;
RealOpenMM* _scaledRadiusFactors;
// cutoff and periodic boundary conditions // cutoff and periodic boundary conditions
bool cutoff; bool _cutoff;
bool periodic; bool _periodic;
RealOpenMM periodicBoxSize[3]; RealOpenMM _periodicBoxSize[3];
RealOpenMM cutoffDistance; RealOpenMM _cutoffDistance;
public: public:
...@@ -90,6 +93,97 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters { ...@@ -90,6 +93,97 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters {
~ObcSoftcoreParameters( ); ~ObcSoftcoreParameters( );
/**---------------------------------------------------------------------------------------
Get number of atoms
@return number of atoms
--------------------------------------------------------------------------------------- */
int getNumberOfAtoms( void ) const;
/**---------------------------------------------------------------------------------------
Get electric constant
@return electric constant
--------------------------------------------------------------------------------------- */
RealOpenMM getElectricConstant( void ) const;
/**---------------------------------------------------------------------------------------
Get probe radius (Simbios)
@return probeRadius
--------------------------------------------------------------------------------------- */
RealOpenMM getProbeRadius( void ) const;
/**---------------------------------------------------------------------------------------
Set probe radius (Simbios)
@param probeRadius probe radius
--------------------------------------------------------------------------------------- */
void setProbeRadius( RealOpenMM probeRadius );
/**---------------------------------------------------------------------------------------
Get pi4Asolv: used in ACE approximation for nonpolar term
((RealOpenMM) M_PI)*4.0f*0.0049f*1000.0f; (Simbios)
@return pi4Asolv
--------------------------------------------------------------------------------------- */
RealOpenMM getPi4Asolv( void ) const;
/**---------------------------------------------------------------------------------------
Get solvent dielectric
@return solvent dielectric
--------------------------------------------------------------------------------------- */
RealOpenMM getSolventDielectric( void ) const;
/**---------------------------------------------------------------------------------------
Set solvent dielectric
@param solventDielectric solvent dielectric
--------------------------------------------------------------------------------------- */
void setSolventDielectric( RealOpenMM solventDielectric );
/**---------------------------------------------------------------------------------------
Get solute dielectric
@return soluteDielectric
--------------------------------------------------------------------------------------- */
RealOpenMM getSoluteDielectric( void ) const;
/**---------------------------------------------------------------------------------------
Set solute dielectric
@param soluteDielectric solute dielectric
--------------------------------------------------------------------------------------- */
void setSoluteDielectric( RealOpenMM soluteDielectric );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get OBC type Get OBC type
...@@ -158,33 +252,18 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters { ...@@ -158,33 +252,18 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
const RealOpenMM* getScaledRadiusFactors( void ) const; const RealOpenMMVector& getScaledRadiusFactors( void ) const;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Return OBC scale factors Set OBC scale factors
@return array @param input vector of radius factors
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void setScaledRadiusFactors( RealOpenMM* scaledRadiusFactors );
#if RealOpenMMType == 0
void setScaledRadiusFactors( float* scaledRadiusFactors );
#endif
void setScaledRadiusFactors( const RealOpenMMVector& scaledRadiusFactors ); void setScaledRadiusFactors( const RealOpenMMVector& scaledRadiusFactors );
/**---------------------------------------------------------------------------------------
Set flag indicating whether scale factors arra should be deleted
@param ownScaledRadiusFactors flag indicating whether scale factors
array should be deleted
--------------------------------------------------------------------------------------- */
void setOwnScaleFactors( int ownScaledRadiusFactors );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get AtomicRadii array w/ dielectric offset applied Get AtomicRadii array w/ dielectric offset applied
...@@ -193,17 +272,7 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters { ...@@ -193,17 +272,7 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM* getAtomicRadii( void ) const; const RealOpenMMVector& getAtomicRadii( void ) const;
/**---------------------------------------------------------------------------------------
Set AtomicRadii array
@param atomicRadii array of atomic radii
--------------------------------------------------------------------------------------- */
void setAtomicRadii( RealOpenMM* atomicRadii );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -215,31 +284,6 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters { ...@@ -215,31 +284,6 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters {
void setAtomicRadii( const RealOpenMMVector& atomicRadii ); void setAtomicRadii( const RealOpenMMVector& atomicRadii );
/**---------------------------------------------------------------------------------------
Map Gmx atom name to Tinker atom number (Simbios)
@param atomName atom name (CA, HA, ...); upper and lower case should both work
@param log if set, then print error messages to log file
return Tinker atom number if atom name is valid; else return -1
--------------------------------------------------------------------------------------- */
int mapGmxAtomNameToTinkerAtomNumber( const char* atomName, FILE* log ) const;
/**---------------------------------------------------------------------------------------
Get string w/ state
@param title title (optional)
@return string
--------------------------------------------------------------------------------------- */
std::string getStateString( const char* title ) const;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Set the force to use a cutoff. Set the force to use a cutoff.
...@@ -256,7 +300,7 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters { ...@@ -256,7 +300,7 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
bool getUseCutoff(); bool getUseCutoff( void );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -264,7 +308,7 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters { ...@@ -264,7 +308,7 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM getCutoffDistance(); RealOpenMM getCutoffDistance( void );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -284,7 +328,7 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters { ...@@ -284,7 +328,7 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
bool getPeriodic(); bool getPeriodic( void );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -292,29 +336,17 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters { ...@@ -292,29 +336,17 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
const RealOpenMM* getPeriodicBox(); const RealOpenMM* getPeriodicBox( void );
/**---------------------------------------------------------------------------------------
Set flag indicating whether scale factors array should be deleted
@param ownNonPolarScaleFactors flag indicating whether scale factors
array should be deleted
--------------------------------------------------------------------------------------- */
void setOwnNonPolarScaleFactors( int ownNonPolarScaleFactors );
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Return non-polar scale factors Return non-polar scale factors
If not previously set, allocate space
@return array @return array
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
const RealOpenMM* getNonPolarScaleFactors( void ) const; const RealOpenMMVector& getNonPolarScaleFactors( void ) const;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -338,19 +370,6 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters { ...@@ -338,19 +370,6 @@ class ObcSoftcoreParameters : public ImplicitSolventParameters {
}; };
/**---------------------------------------------------------------------------------------
Qsort/heapsort integer comparison (Simbios)
@parma a first value to compare
@param b second value to compare
@return -1, 0, 1
--------------------------------------------------------------------------------------- */
int integerComparison( const void *a, const void *b);
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
#endif // __ObcSoftcoreParameters_H__ #endif // __ObcSoftcoreParameters_H__
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