Commit 2cfc6821 authored by Peter Eastman's avatar Peter Eastman
Browse files

Continuing to implement ReferencePlatform (implemented GBSA kernels, added...

Continuing to implement ReferencePlatform (implemented GBSA kernels, added test case for SHAKE and fixed some bugs in it)
parent 5d9ae810
......@@ -106,13 +106,11 @@ public:
/**
* Initialize the kernel, setting up the values of all the force field parameters.
*
* @param bornRadii the initial value of the Born radius for each atom
* @param atomParameters the force parameters (charge, atomic radius, scaling factor) for each atom
* @param solventDielectric the dielectric constant of the solvent
* @param soluteDielectric the dielectric constant of the solute
*/
virtual void initialize(const std::vector<double>& bornRadii, const std::vector<std::vector<double> >& atomParameters,
double solventDielectric, double soluteDielectric) = 0;
virtual void initialize(const std::vector<std::vector<double> >& atomParameters, double solventDielectric, double soluteDielectric) = 0;
/**
* Execute the kernel to calculate the forces.
*
......
......@@ -36,7 +36,7 @@
using namespace OpenMM;
GBSAOBCForceField::GBSAOBCForceField(int numAtoms) : atoms(numAtoms) {
GBSAOBCForceField::GBSAOBCForceField(int numAtoms) : atoms(numAtoms), solventDielectric(78.3), soluteDielectric(1.0) {
}
void GBSAOBCForceField::getAtomParameters(int index, double& charge, double& radius, double& scalingFactor) const {
......
......@@ -43,9 +43,7 @@ GBSAOBCForceFieldImpl::GBSAOBCForceFieldImpl(GBSAOBCForceField& owner, OpenMMCon
void GBSAOBCForceFieldImpl::initialize(OpenMMContextImpl& context) {
hasInitialized = true;
kernel = context.getPlatform().createKernel(CalcGBSAOBCForceFieldKernel::Name());
std::vector<double> bornRadii;
// TODO calculate the initial Born radii.
vector<vector<double> > atomParameters;
vector<vector<double> > atomParameters(owner.getNumAtoms());
for (int i = 0; i < owner.getNumAtoms(); ++i) {
double charge, radius, scalingFactor;
owner.getAtomParameters(i, charge, radius, scalingFactor);
......@@ -53,8 +51,7 @@ void GBSAOBCForceFieldImpl::initialize(OpenMMContextImpl& context) {
atomParameters[i].push_back(radius);
atomParameters[i].push_back(scalingFactor);
}
dynamic_cast<CalcGBSAOBCForceFieldKernel&>(kernel.getImpl()).initialize(bornRadii, atomParameters,
owner.getSolventDielectric(), owner.getSoluteDielectric());
dynamic_cast<CalcGBSAOBCForceFieldKernel&>(kernel.getImpl()).initialize(atomParameters, owner.getSolventDielectric(), owner.getSoluteDielectric());
}
void GBSAOBCForceFieldImpl::calcForces(OpenMMContextImpl& context, Stream& forces) {
......
......@@ -31,6 +31,7 @@
#include "ReferenceKernels.h"
#include "ReferenceFloatStreamImpl.h"
#include "gbsa/CpuObc.h"
#include "SimTKReference/ReferenceAngleBondIxn.h"
#include "SimTKReference/ReferenceBondForce.h"
#include "SimTKReference/ReferenceHarmonicBondIxn.h"
......@@ -209,17 +210,44 @@ double ReferenceCalcStandardMMForceFieldKernel::executeEnergy(const Stream& posi
return energy;
}
void ReferenceCalcGBSAOBCForceFieldKernel::initialize(const vector<double>& bornRadii, const vector<vector<double> >& atomParameters,
double solventDielectric, double soluteDielectric) {
ReferenceCalcGBSAOBCForceFieldKernel::~ReferenceCalcGBSAOBCForceFieldKernel() {
if (obc) {
delete obc->getObcParameters();
delete obc;
}
}
void ReferenceCalcGBSAOBCForceFieldKernel::initialize(const vector<vector<double> >& atomParameters, double solventDielectric, double soluteDielectric) {
int numAtoms = atomParameters.size();
charges.resize(numAtoms);
vector<RealOpenMM> atomicRadii(numAtoms);
vector<RealOpenMM> scaleFactors(numAtoms);
for (int i = 0; i < numAtoms; ++i) {
charges[i] = atomParameters[i][0];
atomicRadii[i] = atomParameters[i][1];
scaleFactors[i] = atomParameters[i][2];
}
ObcParameters* obcParameters = new ObcParameters(numAtoms, ObcParameters::ObcTypeII);
obcParameters->setAtomicRadii(atomicRadii, SimTKOpenMMCommon::KcalAngUnits);
obcParameters->setScaledRadiusFactors(scaleFactors);
obcParameters->setSolventDielectric(solventDielectric);
obcParameters->setSoluteDielectric(soluteDielectric);
obc = new CpuObc(obcParameters);
obc->setIncludeAceApproximation(true);
}
void ReferenceCalcGBSAOBCForceFieldKernel::executeForces(const Stream& positions, Stream& forces) {
RealOpenMM** posData = const_cast<RealOpenMM**>(((ReferenceFloatStreamImpl&) positions.getImpl()).getData()); // Reference code needs to be made const correct
RealOpenMM** forceData = ((ReferenceFloatStreamImpl&) forces.getImpl()).getData();
obc->computeImplicitSolventForces(posData, &charges[0], forceData, 0);
}
double ReferenceCalcGBSAOBCForceFieldKernel::executeEnergy(const Stream& positions) {
return 0.0; // TODO implement correctly
RealOpenMM** posData = const_cast<RealOpenMM**>(((ReferenceFloatStreamImpl&) positions.getImpl()).getData()); // Reference code needs to be made const correct
RealOpenMM** forceData = allocateRealArray(positions.getSize(), 3);
obc->computeImplicitSolventForces(posData, &charges[0], forceData, 1);
disposeRealArray(forceData, positions.getSize());
return obc->getEnergy();
}
void ReferenceIntegrateVerletStepKernel::initialize(const vector<double>& masses, const vector<vector<int> >& constraintIndices,
......
......@@ -35,6 +35,7 @@
#include "kernels.h"
#include "SimTKUtilities/SimTKOpenMMRealType.h"
class CpuObc;
class ReferenceStochasticDynamics;
class ReferenceShakeAlgorithm;
......@@ -102,16 +103,15 @@ class ReferenceCalcGBSAOBCForceFieldKernel : public CalcGBSAOBCForceFieldKernel
public:
ReferenceCalcGBSAOBCForceFieldKernel(std::string name, const Platform& platform) : CalcGBSAOBCForceFieldKernel(name, platform) {
}
~ReferenceCalcGBSAOBCForceFieldKernel();
/**
* Initialize the kernel, setting up the values of all the force field parameters.
*
* @param bornRadii the initial value of the Born radius for each atom
* @param atomParameters the force parameters (charge, atomic radius, scaling factor) for each atom
* @param solventDielectric the dielectric constant of the solvent
* @param soluteDielectric the dielectric constant of the solute
*/
void initialize(const std::vector<double>& bornRadii, const std::vector<std::vector<double> >& atomParameters,
double solventDielectric, double soluteDielectric);
void initialize(const std::vector<std::vector<double> >& atomParameters, double solventDielectric, double soluteDielectric);
/**
* Execute the kernel to calculate the forces.
*
......@@ -127,6 +127,9 @@ public:
* @return the potential energy due to the GBSAOBCForceField
*/
double executeEnergy(const Stream& positions);
private:
CpuObc* obc;
std::vector<RealOpenMM> charges;
};
/**
......
......@@ -65,6 +65,7 @@ ReferenceShakeAlgorithm::ReferenceShakeAlgorithm( int numberOfConstraints,
_maximumNumberOfIterations = 15;
_tolerance = (RealOpenMM) 1.0e-04;
_hasInitializedMasses = false;
// work arrays
......@@ -237,7 +238,6 @@ int ReferenceShakeAlgorithm::applyShake( int numberOfAtoms, RealOpenMM** atomCoo
static const RealOpenMM epsilon6 = (RealOpenMM) 1.0e-06;
static int firstPass = 1;
static int debug = 0;
// ---------------------------------------------------------------------------------------
......@@ -253,8 +253,8 @@ int ReferenceShakeAlgorithm::applyShake( int numberOfAtoms, RealOpenMM** atomCoo
// calculate reduced masses on 1st pass
if( firstPass ){
firstPass = 0;
if( !_hasInitializedMasses ){
_hasInitializedMasses = true;
for( int ii = 0; ii < _numberOfConstraints; ii++ ){
int atomI = _atomIndices[ii][0];
int atomJ = _atomIndices[ii][1];
......@@ -298,7 +298,8 @@ int ReferenceShakeAlgorithm::applyShake( int numberOfAtoms, RealOpenMM** atomCoo
}
RealOpenMM rp2 = DOT3( rp_ij, rp_ij );
RealOpenMM diff = d_ij2[ii] - rp2;
RealOpenMM dist2= _shakeParameters[ii][0]*_shakeParameters[ii][0];
RealOpenMM diff = dist2 - rp2;
int iconv = (int) ( FABS( diff )*distanceTolerance[ii] );
if( iconv ){
RealOpenMM rrpr = DOT3( rp_ij, r_ij[ii] );
......
......@@ -42,6 +42,7 @@ class ReferenceShakeAlgorithm {
RealOpenMM* _d_ij2;
RealOpenMM* _distanceTolerance;
RealOpenMM* _reducedMasses;
bool _hasInitializedMasses;
public:
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* Portions copyright (c) 2006 Stanford University and Simbios.
* Contributors: Pande Group
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __CpuObc_H__
#define __CpuObc_H__
#include "ObcParameters.h"
#include "CpuImplicitSolvent.h"
// ---------------------------------------------------------------------------------------
class CpuObc : public CpuImplicitSolvent {
private:
// GBSA/OBC parameters
ObcParameters* _obcParameters;
// arrays containing OBC chain derivative
RealOpenMM* _obcChain;
RealOpenMM* _obcChainTemp;
// initialize data members (more than
// one constructor, so centralize intialization here)
void _initializeObcDataMembers( void );
public:
/**---------------------------------------------------------------------------------------
Constructor
@param implicitSolventParameters ImplicitSolventParameters reference
@return CpuImplicitSolvent object
--------------------------------------------------------------------------------------- */
CpuObc( ImplicitSolventParameters* obcParameters );
/**---------------------------------------------------------------------------------------
Destructor
--------------------------------------------------------------------------------------- */
~CpuObc( );
/**---------------------------------------------------------------------------------------
Return ObcParameters
@return ObcParameters
--------------------------------------------------------------------------------------- */
ObcParameters* getObcParameters( void ) const;
/**---------------------------------------------------------------------------------------
Set ImplicitSolventParameters
@param ImplicitSolventParameters
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
int setObcParameters( ObcParameters* obcParameters );
/**---------------------------------------------------------------------------------------
Return OBC chain derivative: size = _implicitSolventParameters->getNumberOfAtoms()
On first call, memory for array is allocated if not set
@return array
--------------------------------------------------------------------------------------- */
RealOpenMM* getObcChain( void );
RealOpenMM* getObcChainConst( void ) const;
/**---------------------------------------------------------------------------------------
Return OBC chain temp work array of size=_implicitSolventParameters->getNumberOfAtoms()
On first call, memory for array is allocated if not set
@return array
--------------------------------------------------------------------------------------- */
RealOpenMM* getObcChainTemp( void );
/**---------------------------------------------------------------------------------------
Get Born radii based on OBC
@param atomCoordinates atomic coordinates
@param bornRadii output array of Born radii
@param obcChain output array of OBC chain derivative factors; if NULL,
then ignored
@return array of Born radii
--------------------------------------------------------------------------------------- */
int computeBornRadii( RealOpenMM** atomCoordinates, RealOpenMM* bornRadii,
RealOpenMM* obcChain = NULL );
/**---------------------------------------------------------------------------------------
Get Born energy and forces based on OBC
@param bornRadii Born radii
@param atomCoordinates atomic coordinates
@param partialCharges partial charges
@param forces forces
@return force array
--------------------------------------------------------------------------------------- */
int computeBornEnergyForces( RealOpenMM* bornRadii, RealOpenMM** atomCoordinates,
const RealOpenMM* partialCharges, RealOpenMM** forces );
int computeBornEnergyForcesPrint( RealOpenMM* bornRadii, RealOpenMM** atomCoordinates,
const RealOpenMM* partialCharges, RealOpenMM** forces );
/**---------------------------------------------------------------------------------------
Get state
title title (optional)
@return state string
--------------------------------------------------------------------------------------- */
std::string getStateString( const char* title ) const;
/**---------------------------------------------------------------------------------------
Write Born energy and forces (Simbios)
@param atomCoordinates atomic coordinates
@param partialCharges partial atom charges
@param forces force array
@param resultsFileName output file name
@return SimTKOpenMMCommon::DefaultReturn if file opened; else return SimTKOpenMMCommon::ErrorReturn
--------------------------------------------------------------------------------------- */
int writeBornEnergyForces( RealOpenMM** atomCoordinates,
const RealOpenMM* partialCharges, RealOpenMM** forces,
const std::string& resultsFileName ) const;
/**---------------------------------------------------------------------------------------
Write results from first loop
@param atomCoordinates atomic coordinates
@param RealOpenMM forces forces
@param outputFileName output file name
@return SimTKOpenMMCommon::DefaultReturn unless
file cannot be opened
in which case return SimTKOpenMMCommon::ErrorReturn
--------------------------------------------------------------------------------------- */
static int writeForceLoop1( int numberOfAtoms, RealOpenMM** forces, const RealOpenMM* bornForce,
const std::string& outputFileName );
/**---------------------------------------------------------------------------------------
Write results
@param numberOfAtoms number of atoms
@param chunkSizes vector of chunk sizes for realRealOpenMMVector
@param realRealOpenMMVector vector of RealOpenMM**
@param realVector vector of RealOpenMM*
@param outputFileName output file name
@return SimTKOpenMMCommon::DefaultReturn unless
file cannot be opened
in which case return SimTKOpenMMCommon::ErrorReturn
--------------------------------------------------------------------------------------- */
static int writeForceLoop( int numberOfAtoms, const IntVector& chunkSizes,
const RealOpenMMPtrPtrVector& realRealOpenMMVector,
const RealOpenMMPtrVector& realVector,
const std::string& outputFileName );
};
// ---------------------------------------------------------------------------------------
#endif // __CpuObc_H__
This diff is collapsed.
/* Portions copyright (c) 2006 Stanford University and Simbios.
* Contributors: Pande Group
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __ImplicitSolventParameters_H__
#define __ImplicitSolventParameters_H__
#include "../SimTKUtilities/SimTKOpenMMRealType.h"
#include <string>
// ---------------------------------------------------------------------------------------
class ImplicitSolventParameters {
protected:
// parameters common to implicit solvent models
RealOpenMM _solventDielectric;
RealOpenMM _soluteDielectric;
RealOpenMM _kcalA_To_kJNm;
RealOpenMM _electricConstant;
RealOpenMM _probeRadius;
RealOpenMM _pi4Asolv;
RealOpenMM _preFactor;
// ---------------------------------------------------------------------------------------
// atom count
int _numberOfAtoms;
// flag signalling whether arrays are to be freed
int _freeArrays;
// atomic radii
int _ownAtomicRadii;
RealOpenMM* _atomicRadii;
/**---------------------------------------------------------------------------------------
Initialize ImplicitSolvent Parameters (Simbios)
--------------------------------------------------------------------------------------- */
void _initializeImplicitSolventConstants( void );
/**---------------------------------------------------------------------------------------
Set KcalA_To_kJNm
@param kcalA_To_kJNm probe radius
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
int setKcalA_To_kJNm( RealOpenMM kcalA_To_kJNm );
/**---------------------------------------------------------------------------------------
Set free array flag -- if set then work arrays are freed when destructor is called
@param freeArrays flag
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
int setFreeArrays( int freeArrays );
/**---------------------------------------------------------------------------------------
Reset prefactor (Simbios)
called when _electricConstant, _soluteDielectric, or _solventDielectric are modified
--------------------------------------------------------------------------------------- */
void _resetPreFactor( void );
public:
/**---------------------------------------------------------------------------------------
ImplicitSolventParameters constructor (Simbios)
@param numberOfAtoms number of atoms
--------------------------------------------------------------------------------------- */
ImplicitSolventParameters( int numberOfAtoms );
/**---------------------------------------------------------------------------------------
ImplicitSolventParameters destructor (Simbios)
--------------------------------------------------------------------------------------- */
~ImplicitSolventParameters( );
// override of new/delete
//static void* operator new( size_t size );
//static void operator delete( void *p );
//static void* operator new[]( size_t size );
//static void operator delete[]( void *p );
/**---------------------------------------------------------------------------------------
Get number of atoms
@return number of atoms
--------------------------------------------------------------------------------------- */
int getNumberOfAtoms( void ) const;
/**---------------------------------------------------------------------------------------
Get free array flag -- if set then work arrays are freed when destructor is called
@return freeArrays flag
--------------------------------------------------------------------------------------- */
int getFreeArrays( void ) const;
/**---------------------------------------------------------------------------------------
Get solvent dielectric
@return solvent dielectric
--------------------------------------------------------------------------------------- */
RealOpenMM getSolventDielectric( void ) const;
/**---------------------------------------------------------------------------------------
Set solvent dielectric
@param solventDielectric solvent dielectric
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
int setSolventDielectric( RealOpenMM solventDielectric );
/**---------------------------------------------------------------------------------------
Get solute dielectric
@return soluteDielectric
--------------------------------------------------------------------------------------- */
RealOpenMM getSoluteDielectric( void ) const;
/**---------------------------------------------------------------------------------------
Set solute dielectric
@param soluteDielectric solute dielectric
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
int setSoluteDielectric( RealOpenMM soluteDielectric );
/**---------------------------------------------------------------------------------------
Get conversion factor for kcal/A -> kJ/nm (Simbios)
@return kcalA_To_kJNm factor
--------------------------------------------------------------------------------------- */
RealOpenMM getKcalA_To_kJNm( void ) const;
/**---------------------------------------------------------------------------------------
Get electric constant (Simbios)
@return electricConstant
--------------------------------------------------------------------------------------- */
RealOpenMM getElectricConstant( void ) const;
/**---------------------------------------------------------------------------------------
Set electric constant (Simbios)
@param electricConstant electric constant
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
int setElectricConstant( RealOpenMM electricConstant );
/**---------------------------------------------------------------------------------------
Get probe radius (Simbios)
@return probeRadius
--------------------------------------------------------------------------------------- */
RealOpenMM getProbeRadius( void ) const;
/**---------------------------------------------------------------------------------------
Set probe radius (Simbios)
@param probeRadius probe radius
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
int 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 prefactor
@returnpreFactor
--------------------------------------------------------------------------------------- */
RealOpenMM getPreFactor( void ) const;
/**---------------------------------------------------------------------------------------
Set values used in ACE approximation for nonpolar term
((RealOpenMM) M_PI)*4.0f*0.0049f*1000.0f; (Simbios)
@param pi4Asolv see above
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
int setPi4Asolv( RealOpenMM pi4Asolv );
/**---------------------------------------------------------------------------------------
Get AtomicRadii array
@return array of atom volumes
--------------------------------------------------------------------------------------- */
virtual RealOpenMM* getAtomicRadii( void ) const;
/**---------------------------------------------------------------------------------------
Set AtomicRadii array
@param atomicRadii array of atomic radii
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
virtual int setAtomicRadii( RealOpenMM* atomicRadii );
/**---------------------------------------------------------------------------------------
Set AtomicRadii array
@param atomicRadii vector of atomic radii
@param units units flag SimTKOpenMMCommon::MdUnits or
SimTKOpenMMCommon::KcalAngUnits
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
virtual int setAtomicRadii( const RealOpenMMVector& atomicRadii,
int units = SimTKOpenMMCommon::MdUnits );
/**---------------------------------------------------------------------------------------
Set AtomicRadii array
@param atomicRadii array of atomic radii
@param units units flag: SimTKOpenMMCommon::KcalAngUnits or
SimTKOpenMMCommon::MdUnits
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
virtual int setAtomicRadii( RealOpenMM* atomicRadii, int units );
/**---------------------------------------------------------------------------------------
Set flag indicating whether AtomicRadii array is owned by
object; if flag is set, then when the object is deleted,
the array will be freed
@param ownAtomicRadii flag indicating whether array of atomic radii
should be freed
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
int setOwnAtomicRadii( int ownAtomicRadii );
/**---------------------------------------------------------------------------------------
Print state to log file (Simbios)
@param title title (optional)
@param log print state to log file
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
virtual std::string getStateString( const char* title ) const;
/**---------------------------------------------------------------------------------------
Get string tab -- centralized
@return tab string
--------------------------------------------------------------------------------------- */
std::string getStringTab( void ) const;
/**---------------------------------------------------------------------------------------
Return nonzero value errors
@return ready status
--------------------------------------------------------------------------------------- */
virtual int isNotReady( void ) const;
};
// ---------------------------------------------------------------------------------------
#endif // __ImplicitSolventParameters_H__
This diff is collapsed.
This diff is collapsed.
The OBC Generalized Born model is based on the following papers:
J. Phys. Chem. 1996 100, 19824-19839 (HCT paper)
Proteins: Structure, Function, and Bioinformatics 55:383-394 (2004) (OBC paper)
---------------------------------------------------------------------------------------
The two main interface methods perform the following tasks:
(1) set the GBSA parameters; this method is called once prior to execution of
the main simulation loop
(2) calculate the GBSA forces/energy given the atom coordinates and charges
for each simulation step
The two methods and helper methods are in the file cpuObcInterface.cpp
---------------------------------------------------------------------------------------
The setup call is
cpuSetObcParameters( int numberOfAtoms, RealOpenMM* atomicRadii, RealOpenMM* obcScaleFactors,
int includeAceApproximation,
RealOpenMM soluteDielectric, RealOpenMM solventDielectric, FILE* log );
The parameters include the following:
(1) number of atoms
(2) the OBC atomic radii (akin to VDW radii, but optimized for GBSA calculations)
(3) the OBC scale factors for each atom
(4) a flag indicating whether the nonpolar ACE approximation is to be included
in calculating the forces and energy: I do not have a reference for this term
(5-6) the solute and solvent dielectric (typically 1.0 & 78.3)
(7) a log file reference; the reference may be set to NULL,
if logging is unwanted. Note: if the reference is NULL, warnings, ... will be output to stderr
cpuSetObcParameters() creates a static CpuObc object which is then referenced when the
GBSA forces and energy are to be calculated
The default OBC model is the Type II model: Eq. 8 in the 2004 OBC paper;
for the Type I model, replace the call
ObcParameters* obcParameters = new ObcParameters( numberOfAtoms, ObcParameters::ObcTypeII );
with
ObcParameters* obcParameters = new ObcParameters( numberOfAtoms, ObcParameters::ObcTypeI );
---------------------------------------------------------------------------------------
The OBC scale factors may be obtained via calls to either of the following 'helper' methods
getObcScaleFactors( int numberOfAtoms, const int* atomicNumber, RealOpenMM* scaleFactors )
or
getObcScaleFactorsGivenAtomMasses( int numberOfAtoms, const RealOpenMM* masses, RealOpenMM* scaleFactors )
Documentation for the inputs to these routines is contained in the file, cpuObcInterface.cpp.
The scale factors are those used in Tinker5, and are based on the element type
of each atom (H, C, N, O, ...).
---------------------------------------------------------------------------------------
The OBC radii may be obtained via the helper method:
getGbsaRadii( int numberOfAtoms, const int* atomicNumber,
const int* numberOfCovalentPartners, const int* indexOfCovalentPartner,
RealOpenMM* gbsaRadii );
Documentation for the inputs to this routine is contained in the file, cpuObcInterface.cpp.
The radii are based on the atom type (methyl C, carbonyl C, ...). The value for a hydrogen
depends on its covalent heavy atom partner. As for the OBC scale factors, the values
hardwired into the method are the same as those used in Tinker5.
---------------------------------------------------------------------------------------
The energy/forces are calculated via the call
cpuCalculateImplicitSolventForces( RealOpenMM** atomCoordinates, const RealOpenMM* partialCharges,
RealOpenMM** forces, RealOpenMM* energy, int updateBornRadii );
The coordinate and force arrays should have the layout: atomCoordinates[atomIndex][3] &
forces[atomIndex][3]
If updateBornRadii = 0, then the Born radii from the previous iteration are used; this reduces the
number of O(N**2) loops from 3 to 2.
If updateBornRadii != 0, then the Born radii are calculated for the input configuration.
For MD runs, setting updateBornRadii = 0 is relatively safe since the radii change little
from one iteration to the next. However, for minimization techniques updateBornRadii
should probably be set to a nonzero value since the configuarations can change significantly
between adjacent calls.
---------------------------------------------------------------------------------------
Notes:
(1) The type (float or double) for floating-point numbers is set in the file SimTKOpenMMRealType.h.
If 'RealOpenMMType' is set to 1 in the file, the calculations are performed in
single-precision; otherwise they are performed in double-precision
(2) The units are Angstroms for the spatial dimensions, kcal/mol for energy, and kcal/mol.A for the forces
(3) The code in gromacsCpuObcInterface.cpp provides an example of the parameter setup, ... used for
interfacing w/ Gromacs; the details are somewhat different from the code in cpuObcInterface.cpp
(4) Output from Tinker for a singles ubiquitin configuration are in the directory 'Examples'.
The xyz file gives the coordinates and atom types (Amber99 -- note the charge for atom type 268
(line 2008 in the Tinker amber99.prm file) was changed from -0.2737 to -0.2774 to agree w/
the value used in the version of Gromacs we have access to.)
The key file specifies that OBC should be used for the implicit solvent.
The results are in the files 111UBQ.gbsaAce and 111UBQ.gbsaNoAce. The first file includes the
ACE approximation, while the second does not. On the first line of each file, the number of atoms
and GBSA energy are reported. The remaining lines (one for each atom) give the coordinates (3 entries),
Born radius, partial charge, GBSA radius (rsolv in Tinker), the OBC scaling factor, and the forces (3). The
last three fields give the atomic number, Tinker Amber99 atom name and type.
---------------------------------------------------------------------------------------
/* Portions copyright (c) 2006 Stanford University and Simbios.
* Contributors: Pande Group
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __SimTKOpenMMWindowLinux_H_
#define __SimTKOpenMMWindowLinux_H__
#ifdef WIN32
#define FOPEN fopen_s
#else
#define FOPEN fopen
#endif
#endif // __SimTKOpenMMWindowLinux_H__
This diff is collapsed.
This diff is collapsed.
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
/**
* This tests the reference implementation of GBSAOBCForceField.
*/
#include "../../../tests/AssertionUtilities.h"
#include "OpenMMContext.h"
#include "ReferencePlatform.h"
#include "GBSAOBCForceField.h"
#include "System.h"
#include "LangevinIntegrator.h"
#include "../src/SimTKUtilities/SimTKOpenMMRealType.h"
#include "../src/sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void testSingleAtom() {
ReferencePlatform platform;
System system(1, 0);
system.setAtomMass(0, 2.0);
LangevinIntegrator integrator(0, 0.1, 0.01);
GBSAOBCForceField* forceField = new GBSAOBCForceField(1);
forceField->setAtomParameters(0, 0.5, 1.5, 1);
system.addForce(forceField);
OpenMMContext context(system, integrator, platform);
vector<Vec3> positions(1);
positions[0] = Vec3(0, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Energy);
double bornRadius = 1.5-0.09; // dielectric offset
double eps0 = EPSILON0*A2NM*CAL2JOULE;
double bornEnergy = (-0.5*0.5/(8*PI_M*eps0))*(1.0/forceField->getSoluteDielectric()-1.0/forceField->getSolventDielectric())/bornRadius;
double extendedRadius = bornRadius+1.4; // probe radius
double nonpolarEnergy = PI_M*0.0216*extendedRadius*extendedRadius*std::pow(1.5/bornRadius, 6.0); // Where did this formula come from? Just copied it from CpuImplicitSolvent.cpp
ASSERT_EQUAL_TOL(bornEnergy+nonpolarEnergy, state.getPotentialEnergy(), 0.01);
}
void testForce() {
ReferencePlatform platform;
const int numAtoms = 10;
System system(numAtoms, 0);
LangevinIntegrator integrator(0, 0.1, 0.01);
GBSAOBCForceField* forceField = new GBSAOBCForceField(numAtoms);
for (int i = 0; i < numAtoms; ++i)
forceField->setAtomParameters(i, i%2 == 0 ? -1 : 1, 1.5, 1);
system.addForce(forceField);
OpenMMContext context(system, integrator, platform);
// Set random positions for all the atoms.
vector<Vec3> positions(numAtoms);
init_gen_rand(0);
for (int i = 0; i < numAtoms; ++i)
positions[i] = Vec3(5.0*genrand_real2(), 5.0*genrand_real2(), 5.0*genrand_real2());
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
// Take a small step in the direction of the energy gradient.
double norm = 0.0;
for (int i = 0; i < numAtoms; ++i) {
Vec3 f = state.getForces()[i];
norm += f[0]*f[0] + f[1]*f[1] + f[2]*f[2];
}
norm = std::sqrt(norm);
const double delta = 1e-3;
double step = delta/norm;
for (int i = 0; i < numAtoms; ++i) {
Vec3 p = positions[i];
Vec3 f = state.getForces()[i];
positions[i] = Vec3(p[0]-f[0]*step, p[1]-f[1]*step, p[2]-f[2]*step);
}
context.setPositions(positions);
// See whether the potential energy changed by the expected amount.
State state2 = context.getState(State::Energy);
ASSERT_EQUAL_TOL(norm, (state2.getPotentialEnergy()-state.getPotentialEnergy())/delta, 0.01)
}
int main() {
try {
testSingleAtom();
testForce();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
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