Commit b53cd947 authored by Mark Friedrichs's avatar Mark Friedrichs
Browse files

Latest mods

parent ff88ddad
...@@ -100,7 +100,7 @@ BrookBonded::BrookBonded( ){ ...@@ -100,7 +100,7 @@ BrookBonded::BrookBonded( ){
throw OpenMMException( message.str() ); throw OpenMMException( message.str() );
} }
_invMapStreamWidth = -1; _inverseMapStreamWidth = -1;
} }
/** /**
...@@ -164,6 +164,19 @@ int BrookBonded::getMaxInverseMapStreamCount( void ) const { ...@@ -164,6 +164,19 @@ int BrookBonded::getMaxInverseMapStreamCount( void ) const {
return _maxNumberOfInverseMaps; return _maxNumberOfInverseMaps;
} }
/**
* Get max number of inverse maps for specified force stream index
*
* @param index index of force stream
*
* @return max number of inverse maps or -1 if index is out of range
*
*/
int BrookBonded::getMaxInverseMapStreamCount( int index ) const {
return (index >= 0 && index < getNumberOfForceStreams()) ? _maxInverseMapStreamCount[index] : -1;
}
/** /**
* Get width of inverse map streams * Get width of inverse map streams
* *
...@@ -171,8 +184,8 @@ int BrookBonded::getMaxInverseMapStreamCount( void ) const { ...@@ -171,8 +184,8 @@ int BrookBonded::getMaxInverseMapStreamCount( void ) const {
* *
*/ */
int BrookBonded::getInvMapStreamWidth( void ) const { int BrookBonded::getInverseMapStreamWidth( void ) const {
return _invMapStreamWidth; return _inverseMapStreamWidth;
} }
/** /**
...@@ -329,7 +342,7 @@ int BrookBonded::getInverseMapStreamCount( int index ) const { ...@@ -329,7 +342,7 @@ int BrookBonded::getInverseMapStreamCount( int index ) const {
* *
*/ */
BrookFloatStreamImpl* BrookBonded::getAtomIndicesStream( void ) const { BrookFloatStreamInternal* BrookBonded::getAtomIndicesStream( void ) const {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -347,7 +360,7 @@ BrookFloatStreamImpl* BrookBonded::getAtomIndicesStream( void ) const { ...@@ -347,7 +360,7 @@ BrookFloatStreamImpl* BrookBonded::getAtomIndicesStream( void ) const {
* *
*/ */
BrookFloatStreamImpl** BrookBonded::getBondedParameterStreams( void ){ BrookFloatStreamInternal** BrookBonded::getBondedParameterStreams( void ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -365,7 +378,7 @@ BrookFloatStreamImpl** BrookBonded::getBondedParameterStreams( void ){ ...@@ -365,7 +378,7 @@ BrookFloatStreamImpl** BrookBonded::getBondedParameterStreams( void ){
* *
*/ */
BrookFloatStreamImpl** BrookBonded::getBondedForceStreams( void ){ BrookFloatStreamInternal** BrookBonded::getBondedForceStreams( void ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -385,7 +398,7 @@ BrookFloatStreamImpl** BrookBonded::getBondedForceStreams( void ){ ...@@ -385,7 +398,7 @@ BrookFloatStreamImpl** BrookBonded::getBondedForceStreams( void ){
* *
*/ */
BrookFloatStreamImpl** BrookBonded::getInverseStreamMapsStreams( int index ){ BrookFloatStreamInternal** BrookBonded::getInverseStreamMapsStreams( int index ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -1012,16 +1025,16 @@ int BrookBonded::loadInvMaps( int nbondeds, int natoms, int *atoms, const BrookP ...@@ -1012,16 +1025,16 @@ int BrookBonded::loadInvMaps( int nbondeds, int natoms, int *atoms, const BrookP
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookBonded::loadInvMaps"; static const std::string methodName = "BrookBonded::loadInvMaps";
double dangleValue = 0.0;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// get atom stream size // get atom stream size
const BrookStreamFactory& brookStreamFactory = dynamic_cast<const BrookStreamFactory&> (brookPlatform.getDefaultStreamFactory() ); const BrookStreamFactory& brookStreamFactory = dynamic_cast<const BrookStreamFactory&> (brookPlatform.getDefaultStreamFactory() );
BrookStreamInfo* brookStreamInfo = brookStreamFactory.getBrookStreamInfo( BrookStreamFactory::AtomPositions ); int atomStreamWidth = brookStreamFactory.getDefaultAtomStreamWidth();
int atomStreamWidth = brookStreamInfo->getStreamWidth();
int atomStreamSize = brookPlatform.getStreamSize( getNumberOfAtoms(), atomStreamWidth, NULL ); int atomStreamSize = brookPlatform.getStreamSize( getNumberOfAtoms(), atomStreamWidth, NULL );
_invMapStreamWidth = atomStreamWidth; _inverseMapStreamWidth = atomStreamWidth;
// allocate temp memory // allocate temp memory
...@@ -1035,14 +1048,26 @@ int BrookBonded::loadInvMaps( int nbondeds, int natoms, int *atoms, const BrookP ...@@ -1035,14 +1048,26 @@ int BrookBonded::loadInvMaps( int nbondeds, int natoms, int *atoms, const BrookP
// get inverse maps and load into streams // get inverse maps and load into streams
// create streams
// done independently from loading since for test cases some stream counts == 0, but kernels expect stream to
// have been created even though unused
for( int ii = 0; ii < getNumberOfForceStreams(); ii++ ){
for( int jj = 0; jj < getMaxInverseMapStreamCount(ii); jj++ ){
_inverseStreamMaps[ii][jj] = new BrookFloatStreamInternal( BrookStreamFactory::BondedInverseMapStreams, atomStreamSize,
atomStreamWidth, BrookStreamInternal::Float4, dangleValue );
}
}
// load data
for( int ii = 0; ii < getNumberOfForceStreams(); ii++ ){ for( int ii = 0; ii < getNumberOfForceStreams(); ii++ ){
gpuCalcInvMap( ii, 4, nbondeds, natoms, atoms, getInverseMapStreamCount( ii ), counts, invmaps, &(_inverseMapStreamCount[ii]) ); gpuCalcInvMap( ii, 4, nbondeds, natoms, atoms, getInverseMapStreamCount( ii ), counts, invmaps, &(_inverseMapStreamCount[ii]) );
validateInverseMapStreamCount( ii, _inverseMapStreamCount[ii] ); validateInverseMapStreamCount( ii, _inverseMapStreamCount[ii] );
for( int jj = 0; jj < _inverseMapStreamCount[ii]; jj++ ){ for( int jj = 0; jj < _inverseMapStreamCount[ii]; jj++ ){
StreamImpl* inverseStreamMaps = brookStreamFactory.createStreamImpl( BrookStreamFactory::BondedInverseMapStreams, atomStreamSize, Stream::Float4, brookPlatform );
_inverseStreamMaps[ii][jj] = dynamic_cast<BrookFloatStreamImpl*> ( inverseStreamMaps );
_inverseStreamMaps[ii][jj]->loadFromArray( invmaps[jj] ); _inverseStreamMaps[ii][jj]->loadFromArray( invmaps[jj] );
} }
} }
if( getLog() ){ if( getLog() ){
...@@ -1096,16 +1121,19 @@ int BrookBonded::setup( int numberOfAtoms, ...@@ -1096,16 +1121,19 @@ int BrookBonded::setup( int numberOfAtoms,
const vector<vector<int> >& periodicTorsionIndices, const vector<vector<double> >& periodicTorsionParameters, const vector<vector<int> >& periodicTorsionIndices, const vector<vector<double> >& periodicTorsionParameters,
const vector<vector<int> >& rbTorsionIndices, const vector<vector<double> >& rbTorsionParameters, const vector<vector<int> >& rbTorsionIndices, const vector<vector<double> >& rbTorsionParameters,
const vector<vector<int> >& bonded14Indices, const vector<vector<double> >& nonbondedParameters, const vector<vector<int> >& bonded14Indices, const vector<vector<double> >& nonbondedParameters,
double lj14Scale, double coulombScale, const BrookPlatform& platform ){ double lj14Scale, double coulombScale, const Platform& platform ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookBonded::setup"; static const std::string methodName = "BrookBonded::setup";
double dangleValue = 0.0;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
_numberOfAtoms = numberOfAtoms; _numberOfAtoms = numberOfAtoms;
const BrookPlatform& brookPlatform = dynamic_cast<const BrookPlatform&> (platform);
// check that atom indices & parameters agree // check that atom indices & parameters agree
if( bondIndices.size() != bondParameters.size() ){ if( bondIndices.size() != bondParameters.size() ){
...@@ -1206,23 +1234,22 @@ int BrookBonded::setup( int numberOfAtoms, ...@@ -1206,23 +1234,22 @@ int BrookBonded::setup( int numberOfAtoms,
(void) fflush( getLog() ); (void) fflush( getLog() );
} }
// get factory const BrookStreamFactory& brookStreamFactory = dynamic_cast<const BrookStreamFactory&> (brookPlatform.getDefaultStreamFactory() );
int atomStreamWidth = brookStreamFactory.getDefaultAtomStreamWidth();
const BrookStreamFactory& brookStreamFactory = dynamic_cast<const BrookStreamFactory&> (platform.getDefaultStreamFactory());
// build streams // build streams
StreamImpl* atomIndicesStream = brookStreamFactory.createStreamImpl( BrookStreamFactory::BondedAtomIndicesStream, nbondeds, Stream::Float4, platform ); _atomIndicesStream = new BrookFloatStreamInternal( BrookStreamFactory::BondedAtomIndicesStream, nbondeds, atomStreamWidth,
_atomIndicesStream = dynamic_cast<BrookFloatStreamImpl*> (atomIndicesStream); BrookStreamInternal::Float4, dangleValue );
_atomIndicesStream->loadFromArray( atoms, Stream::Integer ); _atomIndicesStream->loadFromArray( atoms, BrookStreamInternal::Integer );
StreamImpl* chargeStream = brookStreamFactory.createStreamImpl( BrookStreamFactory::BondedChargeStream, numberOfAtoms, Stream::Float, platform ); _chargeStream = new BrookFloatStreamInternal( BrookStreamFactory::BondedChargeStream, numberOfAtoms, atomStreamWidth,
_chargeStream = dynamic_cast<BrookFloatStreamImpl*> (chargeStream); BrookStreamInternal::Float, dangleValue );
_chargeStream->loadFromArray( charges ); _chargeStream->loadFromArray( charges );
for( int ii = 0; ii < getNumberOfParameterStreams(); ii++ ){ for( int ii = 0; ii < getNumberOfParameterStreams(); ii++ ){
StreamImpl* bondedParameters = brookStreamFactory.createStreamImpl( BrookStreamFactory::BondedParametersStream, nbondeds, Stream::Float4, platform ); _bondedParameters[ii] = new BrookFloatStreamInternal( BrookStreamFactory::BondedParametersStream, nbondeds, atomStreamWidth,
_bondedParameters[ii] = dynamic_cast<BrookFloatStreamImpl*> (bondedParameters); BrookStreamInternal::Float4, dangleValue );
_bondedParameters[ii]->loadFromArray( params[ii] ); _bondedParameters[ii]->loadFromArray( params[ii] );
} }
...@@ -1230,11 +1257,10 @@ int BrookBonded::setup( int numberOfAtoms, ...@@ -1230,11 +1257,10 @@ int BrookBonded::setup( int numberOfAtoms,
if( 1 && getLog() ){ if( 1 && getLog() ){
BrookFloatStreamImpl* atomIndicesStream = dynamic_cast<BrookFloatStreamImpl*> (_atomIndicesStream);
(void) fprintf( getLog(), "%s nbondeds=%d strDim [%d %d ] sz=%d\n", methodName.c_str(), nbondeds, (void) fprintf( getLog(), "%s nbondeds=%d strDim [%d %d ] sz=%d\n", methodName.c_str(), nbondeds,
atomIndicesStream->getStreamWidth(), _atomIndicesStream->getStreamWidth(),
atomIndicesStream->getStreamHeight(), _atomIndicesStream->getStreamHeight(),
atomIndicesStream->getStreamSize() ); _atomIndicesStream->getStreamSize() );
int kIndex = 0; int kIndex = 0;
int jIndex = 1; int jIndex = 1;
...@@ -1271,7 +1297,7 @@ int BrookBonded::setup( int numberOfAtoms, ...@@ -1271,7 +1297,7 @@ int BrookBonded::setup( int numberOfAtoms,
// load inverse maps to streams // load inverse maps to streams
loadInvMaps( nbondeds, getNumberOfAtoms(), atoms, platform ); loadInvMaps( nbondeds, getNumberOfAtoms(), atoms, brookPlatform );
// free memory // free memory
...@@ -1290,8 +1316,8 @@ int BrookBonded::setup( int numberOfAtoms, ...@@ -1290,8 +1316,8 @@ int BrookBonded::setup( int numberOfAtoms,
// initialize output streams // initialize output streams
for( int ii = 0; ii < getNumberOfForceStreams(); ii++ ){ for( int ii = 0; ii < getNumberOfForceStreams(); ii++ ){
StreamImpl* bondedForceStreams = brookStreamFactory.createStreamImpl( BrookStreamFactory::UnrolledForceStream, nbondeds, Stream::Float3, platform ); _bondedForceStreams[ii] = new BrookFloatStreamInternal( BrookStreamFactory::UnrolledForceStream, nbondeds, atomStreamWidth,
_bondedForceStreams[ii] = dynamic_cast<BrookFloatStreamImpl*> (bondedForceStreams); BrookStreamInternal::Float3, dangleValue );
} }
return DefaultReturnValue; return DefaultReturnValue;
...@@ -1307,11 +1333,11 @@ int BrookBonded::setup( int numberOfAtoms, ...@@ -1307,11 +1333,11 @@ int BrookBonded::setup( int numberOfAtoms,
* *
* */ * */
std::string BrookBonded::getContents( int level ) const { std::string BrookBonded::getContentsString( int level ) const {
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookBonded::getContents"; static const std::string methodName = "BrookBonded::getContentsString";
static const unsigned int MAX_LINE_CHARS = 256; static const unsigned int MAX_LINE_CHARS = 256;
char value[MAX_LINE_CHARS]; char value[MAX_LINE_CHARS];
...@@ -1340,6 +1366,9 @@ std::string BrookBonded::getContents( int level ) const { ...@@ -1340,6 +1366,9 @@ std::string BrookBonded::getContents( int level ) const {
(void) LOCAL_SPRINTF( value, "%.5f", getCoulombFactor() ); (void) LOCAL_SPRINTF( value, "%.5f", getCoulombFactor() );
message << _getLine( tab, "Coulomb factor:", value ); message << _getLine( tab, "Coulomb factor:", value );
(void) LOCAL_SPRINTF( value, "%d", getInverseMapStreamWidth() );
message << _getLine( tab, "Inverse map stream width:", value );
/* /*
(void) LOCAL_SPRINTF( value, "%d", getAtomStreamWidth() ); (void) LOCAL_SPRINTF( value, "%d", getAtomStreamWidth() );
message << _getLine( tab, "Atom stream width:", value ); message << _getLine( tab, "Atom stream width:", value );
......
#ifndef BrookBonded_H_ #ifndef OPENMM_BROOK_BONDED_H_
#define BrookBonded_H_ #define OPENMM_BROOK_BONDED_H_
/* -------------------------------------------------------------------------- * /* -------------------------------------------------------------------------- *
* OpenMM * * OpenMM *
...@@ -34,8 +34,8 @@ ...@@ -34,8 +34,8 @@
#include <vector> #include <vector>
#include "BrookFloatStreamImpl.h" #include "BrookFloatStreamInternal.h"
#include "BrookIntStreamImpl.h" #include "BrookIntStreamInternal.h"
#include "BrookPlatform.h" #include "BrookPlatform.h"
#include "BrookCommon.h" #include "BrookCommon.h"
#include "OpenMMContext.h" #include "OpenMMContext.h"
...@@ -84,7 +84,16 @@ class BrookBonded : public BrookCommon { ...@@ -84,7 +84,16 @@ class BrookBonded : public BrookCommon {
const std::vector<std::vector<int> >& periodicTorsionIndices, const std::vector<std::vector<double> >& periodicTorsionParameters, const std::vector<std::vector<int> >& periodicTorsionIndices, const std::vector<std::vector<double> >& periodicTorsionParameters,
const std::vector<std::vector<int> >& rbTorsionIndices, const std::vector<std::vector<double> >& rbTorsionParameters, const std::vector<std::vector<int> >& rbTorsionIndices, const std::vector<std::vector<double> >& rbTorsionParameters,
const std::vector<std::vector<int> >& bonded14Indices, const std::vector<std::vector<double> >& nonbondedParameters, const std::vector<std::vector<int> >& bonded14Indices, const std::vector<std::vector<double> >& nonbondedParameters,
double lj14Scale, double coulomb14Scale, const BrookPlatform& platform ); double lj14Scale, double coulomb14Scale, const Platform& platform );
/**
* Get inverse map stream width
*
* @return stream width
*
*/
int getInverseMapStreamWidth( void ) const;
/** /**
* Return number of parameter streams * Return number of parameter streams
...@@ -122,13 +131,24 @@ class BrookBonded : public BrookCommon { ...@@ -122,13 +131,24 @@ class BrookBonded : public BrookCommon {
int getMaxInverseMapStreamCount( void ) const; int getMaxInverseMapStreamCount( void ) const;
/**
* Return max stream count for specified index
*
* @param index index of force stream
*
* @return max stream count
*
*/
int getMaxInverseMapStreamCount( int index ) const;
/** /**
* Return Brook stream handle * Return Brook stream handle
* *
* @return * @return
*/ */
BrookFloatStreamImpl* getBrookAtomIndices( void ) const; BrookFloatStreamInternal* getBrookAtomIndices( void ) const;
/** /**
* Get LJ 14 scale factor * Get LJ 14 scale factor
...@@ -155,7 +175,7 @@ class BrookBonded : public BrookCommon { ...@@ -155,7 +175,7 @@ class BrookBonded : public BrookCommon {
* *
*/ */
BrookFloatStreamImpl* getAtomIndicesStream( void ) const; BrookFloatStreamInternal* getAtomIndicesStream( void ) const;
/** /**
* Get array of bonded parameter streams * Get array of bonded parameter streams
...@@ -164,7 +184,7 @@ class BrookBonded : public BrookCommon { ...@@ -164,7 +184,7 @@ class BrookBonded : public BrookCommon {
* *
*/ */
BrookFloatStreamImpl** getBondedParameterStreams( void ); BrookFloatStreamInternal** getBondedParameterStreams( void );
/** /**
* Get array of force streams * Get array of force streams
...@@ -173,7 +193,7 @@ class BrookBonded : public BrookCommon { ...@@ -173,7 +193,7 @@ class BrookBonded : public BrookCommon {
* *
*/ */
BrookFloatStreamImpl** getBondedForceStreams( void ); BrookFloatStreamInternal** getBondedForceStreams( void );
/** /**
* Get array of inverse map streams * Get array of inverse map streams
...@@ -184,7 +204,7 @@ class BrookBonded : public BrookCommon { ...@@ -184,7 +204,7 @@ class BrookBonded : public BrookCommon {
* *
*/ */
BrookFloatStreamImpl** getInverseStreamMapsStreams( int index ); BrookFloatStreamInternal** getInverseStreamMapsStreams( int index );
/** /**
* Return true if force[index] stream is set * Return true if force[index] stream is set
...@@ -228,7 +248,7 @@ class BrookBonded : public BrookCommon { ...@@ -228,7 +248,7 @@ class BrookBonded : public BrookCommon {
* *
* */ * */
std::string getContents( int level ) const; std::string getContentsString( int level = 0 ) const;
private: private:
...@@ -240,7 +260,7 @@ class BrookBonded : public BrookCommon { ...@@ -240,7 +260,7 @@ class BrookBonded : public BrookCommon {
// inverse map stream width // inverse map stream width
int _invMapStreamWidth; int _inverseMapStreamWidth;
// actual max number of inverse maps // actual max number of inverse maps
...@@ -253,11 +273,11 @@ class BrookBonded : public BrookCommon { ...@@ -253,11 +273,11 @@ class BrookBonded : public BrookCommon {
// streams // streams
BrookFloatStreamImpl* _atomIndicesStream; BrookFloatStreamInternal* _atomIndicesStream;
BrookFloatStreamImpl* _bondedParameters[NumberOfParameterStreams]; BrookFloatStreamInternal* _bondedParameters[NumberOfParameterStreams];
BrookFloatStreamImpl* _bondedForceStreams[NumberOfForceStreams]; BrookFloatStreamInternal* _bondedForceStreams[NumberOfForceStreams];
BrookFloatStreamImpl* _chargeStream; BrookFloatStreamInternal* _chargeStream;
BrookFloatStreamImpl* _inverseStreamMaps[NumberOfForceStreams][MaxNumberOfInverseMaps]; BrookFloatStreamInternal* _inverseStreamMaps[NumberOfForceStreams][MaxNumberOfInverseMaps];
int _maxInverseMapStreamCount[NumberOfForceStreams]; int _maxInverseMapStreamCount[NumberOfForceStreams];
int _inverseMapStreamCount[NumberOfForceStreams]; int _inverseMapStreamCount[NumberOfForceStreams];
...@@ -369,15 +389,6 @@ class BrookBonded : public BrookCommon { ...@@ -369,15 +389,6 @@ class BrookBonded : public BrookCommon {
int loadInvMaps( int nbondeds, int natoms, int *atoms, const BrookPlatform& platform ); int loadInvMaps( int nbondeds, int natoms, int *atoms, const BrookPlatform& platform );
/**
* Get inverse amp stream width
*
* @return stream width
*
*/
int getInvMapStreamWidth( void ) const;
/** /**
* Validate inverse map count * Validate inverse map count
* *
...@@ -396,4 +407,4 @@ class BrookBonded : public BrookCommon { ...@@ -396,4 +407,4 @@ class BrookBonded : public BrookCommon {
} // namespace OpenMM } // namespace OpenMM
#endif /*OPENMM_BROOKKERNELS_H_*/ #endif /* OPENMM_BROOK_BONDED_H_ */
/* -------------------------------------------------------------------------- *
* 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, Mark Friedrichs *
* 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. *
* -------------------------------------------------------------------------- */
#include <cmath>
#include <limits>
#include "OpenMMException.h"
#include <sstream>
#include "BrookStreamImpl.h"
#include "BrookCalcGBSAOBCForceFieldKernel.h"
#include "force.h"
#include "kgbsa.h"
#include "kforce.h"
#include "math.h"
using namespace OpenMM;
using namespace std;
/**
* BrookCalcGBSAOBCForceFieldKernel constructor
*
* @param name kernel name
* @param platform platform
*
*/
BrookCalcGBSAOBCForceFieldKernel::BrookCalcGBSAOBCForceFieldKernel( std::string name, const Platform& platform ) :
CalcGBSAOBCForceFieldKernel( name, platform ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookCalcGBSAOBCForceFieldKernel::BrookCalcGBSAOBCForceFieldKernel";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
_numberOfAtoms = 0;
_brookGbsa = NULL;
const BrookPlatform brookPlatform = dynamic_cast<const BrookPlatform&> (platform);
if( brookPlatform.getLog() != NULL ){
setLog( brookPlatform.getLog() );
}
}
/**
* BrookCalcGBSAOBCForceFieldKernel destructor
*
*/
BrookCalcGBSAOBCForceFieldKernel::~BrookCalcGBSAOBCForceFieldKernel( ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookCalcGBSAOBCForceFieldKernel::BrookCalcGBSAOBCForceFieldKernel";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
delete _brookGbsa;
}
/**
* Get log file reference
*
* @return log file reference
*
*/
FILE* BrookCalcGBSAOBCForceFieldKernel::getLog( void ) const {
return _log;
}
/**
* Set log file reference
*
* @param log file reference
*
* @return DefaultReturnValue
*
*/
int BrookCalcGBSAOBCForceFieldKernel::setLog( FILE* log ){
_log = log;
return BrookCommon::DefaultReturnValue;
}
/**
* Initialize the kernel, setting up the values of all the force field parameters.
*
* @param atomParameters vector containing atom index, charge, radius, scalingFactor
* @param solventDielectric solvent dielectric
* @param soluteDielectric solute dielectric
*
*/
void BrookCalcGBSAOBCForceFieldKernel::initialize( const std::vector<std::vector<double> >& atomParameters,
double solventDielectric, double soluteDielectric ){
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookCalcGBSAOBCForceFieldKernel::initialize";
// ---------------------------------------------------------------------------------------
FILE* log = getLog();
_numberOfAtoms = (int) atomParameters.size();
// ---------------------------------------------------------------------------------------
// bonded
if( _brookGbsa ){
delete _brookGbsa;
}
_brookGbsa = new BrookGbsa();
_brookGbsa->setLog( log );
_brookGbsa->setup( atomParameters, solventDielectric, soluteDielectric );
if( log ){
std::string contents = _brookGbsa->getContentsString( );
(void) fprintf( log, "%s brookGbsa::contents\n%s", methodName.c_str(), contents.c_str() );
(void) fflush( log );
}
// ---------------------------------------------------------------------------------------
}
/**
* Compute forces given atom coordinates
*
* @param positions atom coordinates
* @param forces output forces
*
*/
void BrookCalcGBSAOBCForceFieldKernel::executeForces( const Stream& positions, Stream& forces ){
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookCalcGBSAOBCForceFieldKernel::executeForces";
// ---------------------------------------------------------------------------------------
// OBC
const BrookStreamImpl& positionStreamC = dynamic_cast<const BrookStreamImpl&> (positions.getImpl());
BrookStreamImpl& positionStream = const_cast<BrookStreamImpl&> (positionStreamC);
BrookStreamImpl& forceStream = dynamic_cast<BrookStreamImpl&> (forces.getImpl());
float includeAce = (float) (_brookGbsa->includeAce());
BrookFloatStreamInternal** gbsaForceStreams = _brookGbsa->getForceStreams();
// first major loop
kObcLoop1( (float) _brookGbsa->getNumberOfAtoms(),
(float) _brookGbsa->getAtomSizeCeiling(),
(float) _brookGbsa->getDuplicationFactor(),
(float) _brookGbsa->getAtomStreamWidth( ),
(float) _brookGbsa->getPartialForceStreamWidth( ),
_brookGbsa->getSoluteDielectric(),
_brookGbsa->getSolventDielectric(),
includeAce,
positionStream.getBrookStream(),
_brookGbsa->getObcBornRadii()->getBrookStream(),
_brookGbsa->getObcAtomicRadii()->getBrookStream(),
gbsaForceStreams[0]->getBrookStream(),
gbsaForceStreams[1]->getBrookStream(),
gbsaForceStreams[2]->getBrookStream(),
gbsaForceStreams[3]->getBrookStream()
);
// gather for first loop
kPostObcLoop1_nobranch(
(float) _brookGbsa->getDuplicationFactor(),
(float) _brookGbsa->getAtomStreamWidth( ),
(float) _brookGbsa->getPartialForceStreamWidth( ),
(float) _brookGbsa->getNumberOfAtoms(),
(float) _brookGbsa->getAtomSizeCeiling(),
(float) _brookGbsa->getInnerLoopUnroll(),
gbsaForceStreams[0]->getBrookStream(),
gbsaForceStreams[1]->getBrookStream(),
gbsaForceStreams[2]->getBrookStream(),
gbsaForceStreams[3]->getBrookStream(),
_brookGbsa->getObcChain()->getBrookStream(),
_brookGbsa->getObcBornRadii()->getBrookStream(),
_brookGbsa->getObcIntermediateForce()->getBrookStream(),
_brookGbsa->getObcBornRadii2()->getBrookStream() );
// second major loop
kObcLoop2( (float) _brookGbsa->getNumberOfAtoms(),
(float) _brookGbsa->getAtomSizeCeiling(),
(float) _brookGbsa->getDuplicationFactor(),
(float) _brookGbsa->getAtomStreamWidth( ),
(float) _brookGbsa->getPartialForceStreamWidth( ),
positionStream.getBrookStream(),
_brookGbsa->getObcAtomicRadiiWithDielectricOffset()->getBrookStream(),
_brookGbsa->getObcScaledAtomicRadii()->getBrookStream(),
_brookGbsa->getObcBornRadii2()->getBrookStream(),
gbsaForceStreams[0]->getBrookStream(),
gbsaForceStreams[1]->getBrookStream(),
gbsaForceStreams[2]->getBrookStream(),
gbsaForceStreams[3]->getBrookStream()
);
// gather for second loop
float mergeNonObcForces = 1.0f;
float kcalMolTokJNM = -0.4184f;
kPostObcLoop2_nobranch(
(float) _brookGbsa->getDuplicationFactor(),
(float) _brookGbsa->getAtomStreamWidth( ),
(float) _brookGbsa->getPartialForceStreamWidth( ),
(float) _brookGbsa->getNumberOfAtoms(),
(float) _brookGbsa->getAtomSizeCeiling(),
(float) _brookGbsa->getInnerLoopUnroll(),
kcalMolTokJNM,
mergeNonObcForces,
_brookGbsa->getObcIntermediateForce()->getBrookStream(),
forceStream.getBrookStream(),
gbsaForceStreams[0]->getBrookStream(),
gbsaForceStreams[1]->getBrookStream(),
gbsaForceStreams[2]->getBrookStream(),
gbsaForceStreams[3]->getBrookStream(),
_brookGbsa->getObcAtomicRadii()->getBrookStream(),
_brookGbsa->getObcBornRadii()->getBrookStream(),
_brookGbsa->getObcChain()->getBrookStream(),
forceStream.getBrookStream()
);
// ---------------------------------------------------------------------------------------
}
/**
* Execute the kernel to calculate the energy.
*
* @param positions atom positions
*
* @return potential energy due to the StandardMMForceField
* Currently always return 0.0 since energies not calculated on gpu
*
*/
double BrookCalcGBSAOBCForceFieldKernel::executeEnergy( const Stream& positions ){
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "BrookCalcGBSAOBCForceFieldKernel::executeEnergy";
// ---------------------------------------------------------------------------------------
return 0.0;
}
#ifndef OPENMM_BROOK__CALCL_GBSAOBC_FORCEFIELD_KERNEL_H_
#define OPENMM_BROOK__CALCL_GBSAOBC_FORCEFIELD_KERNEL_H_
/* -------------------------------------------------------------------------- *
* 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, Mark Friedrichs *
* 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. *
* -------------------------------------------------------------------------- */
#include "kernels.h"
#include "SimTKUtilities/SimTKOpenMMRealType.h"
#include "BrookGbsa.h"
namespace OpenMM {
/**
* This kernel is invoked by StandardMMForceField to calculate the forces acting on the system.
*/
class BrookCalcGBSAOBCForceFieldKernel : public CalcGBSAOBCForceFieldKernel {
public:
/**
* BrookCalcGBSAOBCForceFieldKernel constructor
*/
BrookCalcGBSAOBCForceFieldKernel( std::string name, const Platform& platform );
/**
* BrookCalcGBSAOBCForceFieldKernel destructor
*/
~BrookCalcGBSAOBCForceFieldKernel();
/**
* Initialize the kernel, setting up the values of all the force field parameters.
*
* @param atomParameters vector containing atom index, charge, radius, scalingFactor
* @param solventDielectric solvent dielectric
* @param soluteDielectric solute dielectric
*
*/
void initialize( const std::vector<std::vector<double> >& atomParameters, double solventDielectric, double soluteDielectric );
/**
* Execute the kernel to calculate the forces.
*
* @param positions atom coordiantes
* @param forces output forces
*
*/
void executeForces( const Stream& positions, Stream& forces );
/**
* Execute the kernel to calculate the energy.
*
* @param positions atom positions
*
* @return potential energy due to the StandardMMForceField
* Currently always return 0.0 since energies not calculated on gpu
*
*/
double executeEnergy( const Stream& positions );
/**
* Set log file reference
*
* @param log file reference
*
* @return DefaultReturnValue
*
*/
int setLog( FILE* log );
/*
* Get contents of object
*
* @param level of dump
*
* @return string containing contents
*
* */
std::string getContents( int level ) const;
/**
* Get log file reference
*
* @return log file reference
*
*/
FILE* getLog( void ) const;
private:
// log file reference
FILE* _log;
// number of atoms
int _numberOfAtoms;
// Brook Gbsa
BrookGbsa* _brookGbsa;
};
} // namespace OpenMM
#endif /* OPENMM_BROOK__CALCL_GBSAOBC_FORCEFIELD_KERNEL_H_ */
/* -------------------------------------------------------------------------- *
* 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. *
* -------------------------------------------------------------------------- */
#include "BrookCalcKineticEnergyKernel.h"
#include "BrookStreamInternal.h"
using namespace OpenMM;
using namespace std;
/**
* BrookCalcKineticEnergyKernel constructor
*
* @param name name of the stream to create
* @param platform platform
*
*/
BrookCalcKineticEnergyKernel::BrookCalcKineticEnergyKernel( std::string name, const Platform& platform ) :
CalcKineticEnergyKernel( name, platform ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookCalcKineticEnergyKernel::BrookCalcKineticEnergyKernel";
// ---------------------------------------------------------------------------------------
}
/**
* BrookCalcKineticEnergyKernel destructor
*
*/
BrookCalcKineticEnergyKernel::~BrookCalcKineticEnergyKernel( ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookCalcKineticEnergyKernel::~BrookCalcKineticEnergyKernel";
// ---------------------------------------------------------------------------------------
/*
if (dynamics)
delete dynamics;
if (shake)
delete shake;
if (masses)
delete[] masses;
if (constraintIndices)
disposeIntArray(constraintIndices, numConstraints);
if (shakeParameters)
disposeRealArray(shakeParameters, numConstraints);
*/
}
/**
* Initialize the kernel
*
* @param masses mass of each atom
*
*/
void BrookCalcKineticEnergyKernel::initialize( const vector<double>& masses ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookCalcKineticEnergyKernel::initialize";
// ---------------------------------------------------------------------------------------
// this->masses = masses;
return;
}
/**
* Execute kernel
*
* @param velocities stream of atom velocities
*
* @return kinetic energy of the system
*
*/
double BrookCalcKineticEnergyKernel::execute( const Stream& velocities ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookCalcKineticEnergyKernel::execute";
// ---------------------------------------------------------------------------------------
/*
RealOpenMM** velData = const_cast<RealOpenMM**>(((BrookFloatStreamImpl&) velocities.getImpl()).getData()); // Brook code needs to be made const correct
double energy = 0.0;
for (size_t i = 0; i < masses.size(); ++i)
energy += masses[i]*(velData[i][0]*velData[i][0]+velData[i][1]*velData[i][1]+velData[i][2]*velData[i][2]);
return 0.5*energy;
*/
return 0.0;
}
#ifndef OPENMM_BROOKFLOATSTREAMIMPL_H_ #ifndef OPENMM_BROOK_CALC_KINETIC_ENERGY_KERNEL_H_
#define OPENMM_BROOKFLOATSTREAMIMPL_H_ #define OPENMM_BROOK_CALC_KINETIC_ENERGY_KERNEL_H_
/* -------------------------------------------------------------------------- * /* -------------------------------------------------------------------------- *
* OpenMM * * OpenMM *
...@@ -32,61 +32,56 @@ ...@@ -32,61 +32,56 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * * USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "StreamImpl.h" #include "kernels.h"
#include "BrookPlatform.h"
#include <brook/brook.hpp>
#include "SimTKUtilities/SimTKOpenMMRealType.h"
namespace OpenMM { namespace OpenMM {
/** /**
* This is the implementation of Float and Double streams in the Brook Platform. * Brook class for calculating kinetic energy
*/ */
class BrookFloatStreamImpl : public StreamImpl { class BrookCalcKineticEnergyKernel : public CalcKineticEnergyKernel {
public: public:
BrookFloatStreamImpl( std::string name, int size, Stream::DataType type, const Platform& platform, int inputStreamWidth, double defaultDangleValue ); /**
* BrookCalcKineticEnergyKernel constructor
*
* @param name name of the stream to create
* @param platform platform
*
*/
~BrookFloatStreamImpl( ); BrookCalcKineticEnergyKernel( std::string name, const Platform& platform );
void loadFromArray( const void* array );
void loadFromArray( const void* array, Stream::DataType type );
void saveToArray( void* array );
void fillWithValue( void* value );
const RealOpenMM* const * getData( ) const;
RealOpenMM** getData( void );
/** /**
* Get width * BrookCalcKineticEnergyKernel destructor
* *
* @return width
*/ */
int BrookFloatStreamImpl::getWidth( void ) const; ~BrookCalcKineticEnergyKernel();
int getStreamWidth( void ) const; /**
int getStreamHeight( void ) const; * Initialize the kernel
int getStreamSize( void ) const; *
* @param masses mass of each atom
brook::stream& getBrookStream( void ); *
*/
void initialize( const std::vector<double>& masses );
private: /**
* Execute the kernel.
*
* @param velocities stream of atom velocities
*
*/
int _width; double execute( const Stream& velocities );
int _streamWidth;
int _streamHeight;
float _defaultDangleValue; private:
Stream::DataType _baseType;
brook::stream _aStream;
float** _data;
RealOpenMM** _realOpenMMData;
void _loadDanglingValues( void );
void _loadDanglingValues( float );
}; };
} // namespace OpenMM } // namespace OpenMM
#endif /*OPENMM_BROOKFLOATSTREAMIMPL_H_*/ #endif /* OPENMM_BROOK_CALC_KINETIC_ENERGY_KERNEL_H_ */
/* -------------------------------------------------------------------------- *
* 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, Mark Friedrichs *
* 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. *
* -------------------------------------------------------------------------- */
#include <cmath>
#include <limits>
#include "OpenMMException.h"
#include <sstream>
#include "BrookStreamImpl.h"
#include "BrookCalcStandardMMForceFieldKernel.h"
#include "kforce.h"
#include "kinvmap_gather.h"
using namespace OpenMM;
using namespace std;
/**
* BrookCalcStandardMMForceFieldKernel constructor
*
* @param name kernel name
* @param platform platform
*
*/
BrookCalcStandardMMForceFieldKernel::BrookCalcStandardMMForceFieldKernel( std::string name, const Platform& platform ) :
CalcStandardMMForceFieldKernel( name, platform ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookCalcStandardMMForceFieldKernel::BrookCalcStandardMMForceFieldKernel";
// ---------------------------------------------------------------------------------------
_numberOfAtoms = 0;
_brookBonded = NULL;
_brookNonBonded = NULL;
const BrookPlatform brookPlatform = dynamic_cast<const BrookPlatform&> (platform);
if( brookPlatform.getLog() != NULL ){
setLog( brookPlatform.getLog() );
}
}
/**
* BrookCalcStandardMMForceFieldKernel destructor
*
*/
BrookCalcStandardMMForceFieldKernel::~BrookCalcStandardMMForceFieldKernel( ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookCalcStandardMMForceFieldKernel::BrookCalcStandardMMForceFieldKernel";
// ---------------------------------------------------------------------------------------
delete _brookBonded;
delete _brookNonBonded;
}
/**
* Get log file reference
*
* @return log file reference
*
*/
FILE* BrookCalcStandardMMForceFieldKernel::getLog( void ) const {
return _log;
}
/**
* Set log file reference
*
* @param log file reference
*
* @return DefaultReturnValue
*
*/
int BrookCalcStandardMMForceFieldKernel::setLog( FILE* log ){
_log = log;
return BrookCommon::DefaultReturnValue;
}
/**
* Initialize the kernel, setting up the values of all the force field parameters.
*
* @param bondIndices the two atoms connected by each bond term
* @param bondParameters the force parameters (length, k) for each bond term
* @param angleIndices the three atoms connected by each angle term
* @param angleParameters the force parameters (angle, k) for each angle term
* @param periodicTorsionIndices the four atoms connected by each periodic torsion term
* @param periodicTorsionParameters the force parameters (k, phase, periodicity) for each periodic torsion term
* @param rbTorsionIndices the four atoms connected by each Ryckaert-Bellemans torsion term
* @param rbTorsionParameters the coefficients (in order of increasing powers) for each Ryckaert-Bellemans torsion term
* @param bonded14Indices each element contains the indices of two atoms whose nonbonded interactions should be reduced since
* they form a bonded 1-4 pair
* @param lj14Scale the factor by which van der Waals interactions should be reduced for bonded 1-4 pairs
* @param coulomb14Scale the factor by which Coulomb interactions should be reduced for bonded 1-4 pairs
* @param exclusions the i'th element lists the indices of all atoms with which the i'th atom should not interact through
* nonbonded forces. Bonded 1-4 pairs are also included in this list, since they should be omitted from
* the standard nonbonded calculation.
* @param nonbondedParameters the nonbonded force parameters (charge, sigma, epsilon) for each atom
* @param nonbondedMethod the method to use for handling long range nonbonded interactions
* @param nonbondedCutoff the cutoff distance for nonbonded interactions (if nonbondedMethod involves a cutoff)
* @param periodicBoxSize the size of the periodic box (if nonbondedMethod involves a periodic boundary conditions)
*/
void BrookCalcStandardMMForceFieldKernel::initialize(
const vector<vector<int> >& bondIndices, const vector<vector<double> >& bondParameters,
const vector<vector<int> >& angleIndices, const vector<vector<double> >& angleParameters,
const vector<vector<int> >& periodicTorsionIndices, const vector<vector<double> >& periodicTorsionParameters,
const vector<vector<int> >& rbTorsionIndices, const vector<vector<double> >& rbTorsionParameters,
const vector<vector<int> >& bonded14Indices, double lj14Scale, double coulomb14Scale,
const vector<set<int> >& exclusions, const vector<vector<double> >& nonbondedParameters,
NonbondedMethod nonbondedMethod, double nonbondedCutoff, double periodicBoxSize[3] ){
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookCalcStandardMMForceFieldKernel::initialize";
// ---------------------------------------------------------------------------------------
FILE* log = getLog();
_numberOfAtoms = nonbondedParameters.size();
// ---------------------------------------------------------------------------------------
// bonded
if( _brookBonded ){
delete _brookBonded;
}
_brookBonded = new BrookBonded();
_brookBonded->setLog( log );
_brookBonded->setup( _numberOfAtoms,
bondIndices, bondParameters,
angleIndices, angleParameters,
periodicTorsionIndices, periodicTorsionParameters,
rbTorsionIndices, rbTorsionParameters,
bonded14Indices, nonbondedParameters,
lj14Scale, coulomb14Scale, getPlatform() );
// echo contents
if( log ){
std::string contents = _brookBonded->getContentsString( );
(void) fprintf( log, "%s brookBonded::contents\n%s", methodName.c_str(), contents.c_str() );
(void) fflush( log );
}
// ---------------------------------------------------------------------------------------
// nonbonded
if( _brookNonBonded ){
delete _brookNonBonded;
}
_brookNonBonded = new BrookNonBonded();
_brookNonBonded->setLog( log );
_brookNonBonded->setup( _numberOfAtoms, nonbondedParameters, exclusions, getPlatform() );
// echo contents
if( log ){
std::string contents = _brookNonBonded->getContentsString( );
(void) fprintf( log, "%s brookNonBonded::contents\n%s", methodName.c_str(), contents.c_str() );
(void) fflush( log );
}
// ---------------------------------------------------------------------------------------
}
/**
* Execute the kernel to calculate the bonded & nonbonded forces
*
* @param positions stream of type Double3 containing the position (x, y, z) of each atom
* @param forces stream of type Double3 containing the force (x, y, z) on each atom. On entry, this contains the forces that
* have been calculated so far. The kernel should add its own forces to the values already in the stream.
*/
void BrookCalcStandardMMForceFieldKernel::executeForces( const Stream& positions, Stream& forces ){
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookCalcStandardMMForceFieldKernel::executeForces";
static const int I_Stream = 0;
static const int J_Stream = 1;
static const int K_Stream = 2;
static const int L_Stream = 3;
static const float4 dummyParameters( 0.0, 0.0, 0.0, 0.0 );
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
// bonded
const BrookStreamImpl& positionStreamC = dynamic_cast<const BrookStreamImpl&> (positions.getImpl());
BrookStreamImpl& positionStream = const_cast<BrookStreamImpl&> (positionStreamC);
BrookStreamImpl& forceStream = dynamic_cast<BrookStreamImpl&> (forces.getImpl());
float epsfac = (float) (_brookBonded->getLJ_14Scale()*_brookBonded->getCoulombFactor());
float width = (float) (_brookBonded->getInverseMapStreamWidth());
// bonded forces
BrookFloatStreamInternal** bondedParameters = _brookBonded->getBondedParameterStreams();
BrookFloatStreamInternal** bondedForceStreams = _brookBonded->getBondedForceStreams();
BrookFloatStreamInternal** inverseStreamMaps[4];
inverseStreamMaps[0] = _brookBonded->getInverseStreamMapsStreams( 0 );
inverseStreamMaps[1] = _brookBonded->getInverseStreamMapsStreams( 1 );
inverseStreamMaps[2] = _brookBonded->getInverseStreamMapsStreams( 2 );
inverseStreamMaps[3] = _brookBonded->getInverseStreamMapsStreams( 3 );
kbonded_CDLJ( epsfac,
(float) bondedForceStreams[0]->getStreamWidth(),
dummyParameters,
positionStream.getBrookStream(),
_brookBonded->getAtomIndicesStream()->getBrookStream(),
bondedParameters[0]->getBrookStream(),
bondedParameters[1]->getBrookStream(),
bondedParameters[2]->getBrookStream(),
bondedParameters[3]->getBrookStream(),
bondedParameters[4]->getBrookStream(),
bondedForceStreams[0]->getBrookStream(),
bondedForceStreams[1]->getBrookStream(),
bondedForceStreams[2]->getBrookStream(),
bondedForceStreams[3]->getBrookStream() );
// gather forces
if( _brookBonded->getInverseMapStreamCount( K_Stream ) <= 4 ){
// kinvmap_gather3_4( (float) bp->width, bp->strInvMapi[0], bp->strInvMapi[1], bp->strInvMapi[2], bp->fi, bp->strInvMapk[0], bp->strInvMapk[1], bp->strInvMapk[2], bp->strInvMapk[3], bp->fk, gpu->strF, gpu->strF );
kinvmap_gather3_4( width,
inverseStreamMaps[I_Stream][0]->getBrookStream(),
inverseStreamMaps[I_Stream][1]->getBrookStream(),
inverseStreamMaps[I_Stream][2]->getBrookStream(),
bondedForceStreams[I_Stream]->getBrookStream(),
inverseStreamMaps[K_Stream][0]->getBrookStream(),
inverseStreamMaps[K_Stream][1]->getBrookStream(),
inverseStreamMaps[K_Stream][2]->getBrookStream(),
inverseStreamMaps[K_Stream][3]->getBrookStream(),
bondedForceStreams[K_Stream]->getBrookStream(),
forceStream.getBrookStream(), forceStream.getBrookStream() );
} else if( _brookBonded->getInverseMapStreamCount( K_Stream ) == 5 ){
// kinvmap_gather3_5( (float) bp->width, bp->strInvMapi[0], bp->strInvMapi[1], bp->strInvMapi[2], bp->fi, bp->strInvMapk[0], bp->strInvMapk[1], bp->strInvMapk[2], bp->strInvMapk[3], bp->strInvMapk[4], bp->fk, gpu->strF, gpu->strF );
kinvmap_gather3_5( width,
inverseStreamMaps[I_Stream][0]->getBrookStream(),
inverseStreamMaps[I_Stream][1]->getBrookStream(),
inverseStreamMaps[I_Stream][2]->getBrookStream(),
bondedForceStreams[I_Stream]->getBrookStream(),
inverseStreamMaps[K_Stream][0]->getBrookStream(),
inverseStreamMaps[K_Stream][1]->getBrookStream(),
inverseStreamMaps[K_Stream][2]->getBrookStream(),
inverseStreamMaps[K_Stream][3]->getBrookStream(),
inverseStreamMaps[K_Stream][4]->getBrookStream(),
bondedForceStreams[K_Stream]->getBrookStream(),
forceStream.getBrookStream(), forceStream.getBrookStream() );
} else {
// case not handled -- throw an exception
if( _brookBonded->getLog() ){
(void) fprintf( _brookBonded->getLog(), "%s nkmaps=%d -- not handled.", methodName.c_str(), _brookBonded->getInverseMapStreamCount( K_Stream ) );
(void) fflush( _brookBonded->getLog() );
}
std::stringstream message;
message << methodName << "K-maps=" << _brookBonded->getInverseMapStreamCount( K_Stream ) << " not handled.";
throw OpenMMException( message.str() );
}
//kinvmap_gather5_2( (float) bp->width, bp->strInvMapj[0], bp->strInvMapj[1], bp->strInvMapj[2], bp->strInvMapj[3], bp->strInvMapj[4], bp->fj,
// bp->strInvMapl[0], bp->strInvMapl[1], bp->fl, gpu->strF, gpu->strF );
kinvmap_gather5_2( width,
inverseStreamMaps[J_Stream][0]->getBrookStream(),
inverseStreamMaps[J_Stream][1]->getBrookStream(),
inverseStreamMaps[J_Stream][2]->getBrookStream(),
inverseStreamMaps[J_Stream][3]->getBrookStream(),
inverseStreamMaps[J_Stream][4]->getBrookStream(),
bondedForceStreams[J_Stream]->getBrookStream(),
inverseStreamMaps[L_Stream][0]->getBrookStream(),
inverseStreamMaps[L_Stream][1]->getBrookStream(),
bondedForceStreams[L_Stream]->getBrookStream(),
forceStream.getBrookStream(), forceStream.getBrookStream() );
// ---------------------------------------------------------------------------------------
// nonbonded forces
BrookFloatStreamInternal** nonbondedForceStreams = _brookNonBonded->getForceStreams();
knbforce_CDLJ4(
(float) _brookNonBonded->getNumberOfAtoms(),
(float) _brookNonBonded->getAtomSizeCeiling(),
(float) _brookNonBonded->getDuplicationFactor(),
(float) _brookNonBonded->getAtomStreamHeight( ),
(float) _brookNonBonded->getAtomStreamWidth( ),
(float) _brookNonBonded->getJStreamWidth( ),
(float) _brookNonBonded->getPartialForceStreamWidth( ),
epsfac,
dummyParameters,
positionStream.getBrookStream(),
_brookNonBonded->getOuterVdwStream()->getBrookStream(),
_brookNonBonded->getInnerSigmaStream()->getBrookStream(),
_brookNonBonded->getInnerEpsilonStream()->getBrookStream(),
_brookNonBonded->getExclusionStream()->getBrookStream(),
nonbondedForceStreams[0]->getBrookStream(),
nonbondedForceStreams[1]->getBrookStream(),
nonbondedForceStreams[2]->getBrookStream(),
nonbondedForceStreams[3]->getBrookStream()
);
// strF is assummed to be zero here
// gather forces
kMergeFloat3_4_nobranch( (float) _brookNonBonded->getDuplicationFactor(),
(float) _brookNonBonded->getAtomStreamWidth(),
(float) _brookNonBonded->getPartialForceStreamWidth(),
(float) _brookNonBonded->getNumberOfAtoms(),
(float) _brookNonBonded->getAtomSizeCeiling(),
(float) _brookNonBonded->getOuterLoopUnroll(),
nonbondedForceStreams[0]->getBrookStream(),
nonbondedForceStreams[1]->getBrookStream(),
nonbondedForceStreams[2]->getBrookStream(),
nonbondedForceStreams[3]->getBrookStream(),
forceStream.getBrookStream() );
// ---------------------------------------------------------------------------------------
}
/**
* Execute the kernel to calculate the energy.
*
* @param positions atom positions
*
* @return potential energy due to the StandardMMForceField
* Currently always return 0.0 since energies not calculated on gpu
*
*/
double BrookCalcStandardMMForceFieldKernel::executeEnergy( const Stream& positions ){
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "BrookCalcStandardMMForceFieldKernel::executeEnergy";
// ---------------------------------------------------------------------------------------
return 0.0;
}
#ifndef OPENMM_BROOK_CALC_STANDARD_MM_FORCEFIELD_KERNEL_H_
#define OPENMM_BROOK_CALC_STANDARD_MM_FORCEFIELD_KERNEL_H_
/* -------------------------------------------------------------------------- *
* 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, Mark Friedrichs *
* 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. *
* -------------------------------------------------------------------------- */
#include "kernels.h"
#include "SimTKUtilities/SimTKOpenMMRealType.h"
#include "BrookBonded.h"
#include "BrookNonBonded.h"
namespace OpenMM {
/**
* This kernel is invoked by StandardMMForceField to calculate the forces acting on the system.
*/
class BrookCalcStandardMMForceFieldKernel : public CalcStandardMMForceFieldKernel {
public:
BrookCalcStandardMMForceFieldKernel( std::string name, const Platform& platform );
~BrookCalcStandardMMForceFieldKernel();
/**
* Initialize the kernel, setting up the values of all the force field parameters.
*
* @param bondIndices the two atoms connected by each bond term
* @param bondParameters the force parameters (length, k) for each bond term
* @param angleIndices the three atoms connected by each angle term
* @param angleParameters the force parameters (angle, k) for each angle term
* @param periodicTorsionIndices the four atoms connected by each periodic torsion term
* @param periodicTorsionParameters the force parameters (k, phase, periodicity) for each periodic torsion term
* @param rbTorsionIndices the four atoms connected by each Ryckaert-Bellemans torsion term
* @param rbTorsionParameters the coefficients (in order of increasing powers) for each Ryckaert-Bellemans torsion term
* @param bonded14Indices each element contains the indices of two atoms whose nonbonded interactions should be reduced since
* they form a bonded 1-4 pair
* @param lj14Scale the factor by which van der Waals interactions should be reduced for bonded 1-4 pairs
* @param coulomb14Scale the factor by which Coulomb interactions should be reduced for bonded 1-4 pairs
* @param exclusions the i'th element lists the indices of all atoms with which the i'th atom should not interact through
* nonbonded forces. Bonded 1-4 pairs are also included in this list, since they should be omitted from
* the standard nonbonded calculation.
* @param nonbondedParameters the nonbonded force parameters (charge, sigma, epsilon) for each atom
* @param nonbondedMethod the method to use for handling long range nonbonded interactions
* @param nonbondedCutoff the cutoff distance for nonbonded interactions (if nonbondedMethod involves a cutoff)
* @param periodicBoxSize the size of the periodic box (if nonbondedMethod involves a periodic boundary conditions)
*
*/
void initialize( const std::vector<std::vector<int> >& bondIndices, const std::vector<std::vector<double> >& bondParameters,
const std::vector<std::vector<int> >& angleIndices, const std::vector<std::vector<double> >& angleParameters,
const std::vector<std::vector<int> >& periodicTorsionIndices, const std::vector<std::vector<double> >& periodicTorsionParameters,
const std::vector<std::vector<int> >& rbTorsionIndices, const std::vector<std::vector<double> >& rbTorsionParameters,
const std::vector<std::vector<int> >& bonded14Indices, double lj14Scale, double coulomb14Scale,
const std::vector<std::set <int> >& exclusions, const std::vector<std::vector<double> >& nonbondedParameters,
NonbondedMethod nonbondedMethod, double nonbondedCutoff, double periodicBoxSize[3] );
/**
* Execute the kernel to calculate the forces.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom. On entry, this contains the forces that
* have been calculated so far. The kernel should add its own forces to the values already in the stream.
*/
void executeForces( const Stream& positions, Stream& forces );
/**
* Execute the kernel to calculate the energy.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
*
* @return the potential energy due to the StandardMMForceField
*
* Currently always return 0.0 since energies not calculated on gpu
*/
double executeEnergy( const Stream& positions );
/**
* Set log file reference
*
* @param log file reference
*
* @return DefaultReturnValue
*
*/
int setLog( FILE* log );
/*
* Get contents of object
*
* @param level of dump
*
* @return string containing contents
*
* */
std::string getContents( int level ) const;
/**
* Get log file reference
*
* @return log file reference
*
*/
FILE* getLog( void ) const;
private:
// log file reference
FILE* _log;
// number of atoms
int _numberOfAtoms;
// Brook bonded & nonbonded
BrookBonded* _brookBonded;
BrookNonBonded* _brookNonBonded;
};
} // namespace OpenMM
#endif /* OPENMM_BROOK_CALC_STANDARD_MM_FORCEFIELD_KERNEL_H_ */
...@@ -254,8 +254,7 @@ void BrookCommon::_getAtomStreamDimensions( const Platform& platform ){ ...@@ -254,8 +254,7 @@ void BrookCommon::_getAtomStreamDimensions( const Platform& platform ){
const BrookPlatform brookPlatform = dynamic_cast<const BrookPlatform&> (platform); const BrookPlatform brookPlatform = dynamic_cast<const BrookPlatform&> (platform);
const BrookStreamFactory& brookStreamFactory = dynamic_cast<const BrookStreamFactory&> (platform.getDefaultStreamFactory() ); const BrookStreamFactory& brookStreamFactory = dynamic_cast<const BrookStreamFactory&> (platform.getDefaultStreamFactory() );
BrookStreamInfo* brookStreamInfo = brookStreamFactory.getBrookStreamInfo( BrookStreamFactory::AtomPositions ); _atomStreamWidth = brookStreamFactory.getDefaultAtomStreamWidth();
_atomStreamWidth = brookStreamInfo->getStreamWidth();
_atomStreamSize = brookPlatform.getStreamSize( getNumberOfAtoms(), _atomStreamWidth, NULL ); _atomStreamSize = brookPlatform.getStreamSize( getNumberOfAtoms(), _atomStreamWidth, NULL );
_atomStreamHeight = (int) ( ((float) _atomStreamSize)/( (float) _atomStreamWidth) + 0.001); _atomStreamHeight = (int) ( ((float) _atomStreamSize)/( (float) _atomStreamWidth) + 0.001);
......
#ifndef BrookCommon_H_ #ifndef OPENMM_BROOK_COMMON_H_
#define BrookCommon_H_ #define OPENMM_BROOK_COMMON_H_
/* -------------------------------------------------------------------------- * /* -------------------------------------------------------------------------- *
* OpenMM * * OpenMM *
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
#include <vector> #include <vector>
#include <set> #include <set>
#include "BrookFloatStreamImpl.h" #include "BrookFloatStreamInternal.h"
#include "BrookIntStreamImpl.h" #include "BrookIntStreamInternal.h"
#include "BrookPlatform.h" #include "BrookPlatform.h"
namespace OpenMM { namespace OpenMM {
...@@ -151,6 +151,15 @@ class BrookCommon { ...@@ -151,6 +151,15 @@ class BrookCommon {
std::string getContents( int level ) const; std::string getContents( int level ) const;
/**
* Get log file reference
*
* @return log file reference
*
*/
FILE* getLog( void ) const;
protected: protected:
// number of atoms // number of atoms
...@@ -189,15 +198,6 @@ class BrookCommon { ...@@ -189,15 +198,6 @@ class BrookCommon {
void _getAtomStreamDimensions( const Platform& platform ); void _getAtomStreamDimensions( const Platform& platform );
/**
* Get log file reference
*
* @return log file reference
*
*/
FILE* getLog( void ) const;
/* /*
* Get line * Get line
* *
...@@ -215,4 +215,4 @@ class BrookCommon { ...@@ -215,4 +215,4 @@ class BrookCommon {
} // namespace OpenMM } // namespace OpenMM
#endif /*OPENMM_BROOKKERNELS_H_*/ #endif /* OPENMM_BROOK_COMMON_H_ */
...@@ -30,13 +30,14 @@ ...@@ -30,13 +30,14 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include <sstream> #include <sstream>
#include "BrookFloatStreamImpl.h" #include "BrookFloatStreamInternal.h"
#include "BrookPlatform.h"
#include "OpenMMException.h" #include "OpenMMException.h"
using namespace OpenMM; using namespace OpenMM;
/** /**
* BrookFloatStreamImpl constructor * BrookFloatStreamInternal constructor
* *
* @param name stream name * @param name stream name
* @param size stream size * @param size stream size
...@@ -47,13 +48,12 @@ using namespace OpenMM; ...@@ -47,13 +48,12 @@ using namespace OpenMM;
* *
*/ */
BrookFloatStreamImpl::BrookFloatStreamImpl( std::string name, int size, Stream::DataType type, BrookFloatStreamInternal::BrookFloatStreamInternal( const std::string& name, int size, int streamWidth, BrookStreamInternal::DataType type,
const Platform& platform, int inputStreamWidth, double inputDefaultDangleValue ) : BrookStreamInternal( name, size, streamWidth, type ){
double inputDefaultDangleValue = 0.0 ) : StreamImpl( name, size, type, platform ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookFloatStreamImpl::BrookFloatStreamImpl"; static const std::string methodName = "BrookFloatStreamInternal::BrookFloatStreamInternal";
// static const int debug = 1; // static const int debug = 1;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -62,20 +62,20 @@ BrookFloatStreamImpl::BrookFloatStreamImpl( std::string name, int size, Stream:: ...@@ -62,20 +62,20 @@ BrookFloatStreamImpl::BrookFloatStreamImpl( std::string name, int size, Stream::
switch( type ){ switch( type ){
case Stream::Float: case BrookStreamInternal::Float:
case Stream::Float2: case BrookStreamInternal::Float2:
case Stream::Float3: case BrookStreamInternal::Float3:
case Stream::Float4: case BrookStreamInternal::Float4:
_baseType = Stream::Float; _baseType = BrookStreamInternal::Float;
break; break;
case Stream::Double: case BrookStreamInternal::Double:
case Stream::Double2: case BrookStreamInternal::Double2:
case Stream::Double3: case BrookStreamInternal::Double3:
case Stream::Double4: case BrookStreamInternal::Double4:
_baseType = Stream::Float; _baseType = BrookStreamInternal::Double;
break; break;
default: default:
...@@ -89,250 +89,178 @@ BrookFloatStreamImpl::BrookFloatStreamImpl( std::string name, int size, Stream:: ...@@ -89,250 +89,178 @@ BrookFloatStreamImpl::BrookFloatStreamImpl( std::string name, int size, Stream::
switch( type ){ switch( type ){
case Stream::Float: case BrookStreamInternal::Float:
case Stream::Double: case BrookStreamInternal::Double:
_width = 1; _width = 1;
break; break;
case Stream::Float2: case BrookStreamInternal::Float2:
case Stream::Double2: case BrookStreamInternal::Double2:
_width = 2; _width = 2;
break; break;
case Stream::Float3: case BrookStreamInternal::Float3:
case Stream::Double3: case BrookStreamInternal::Double3:
_width = 3; _width = 3;
break; break;
case Stream::Float4: case BrookStreamInternal::Float4:
case Stream::Double4: case BrookStreamInternal::Double4:
_width = 4; _width = 4;
break; break;
} }
_defaultDangleValue = (BrookOpenMMFloat) inputDefaultDangleValue; _defaultDangleValue = (float) inputDefaultDangleValue;
// set stream height based on specified stream _width // set stream height based on specified stream _width
if( inputStreamWidth < 1 ){ if( streamWidth < 1 ){
std::stringstream message; std::stringstream message;
message << methodName << " stream=" << name << " input stream width=" << type << " is less than 1."; message << methodName << " stream=" << name << " input stream width=" << streamWidth << " is less than 1.";
throw OpenMMException( message.str() ); throw OpenMMException( message.str() );
} }
_streamWidth = inputStreamWidth;
_streamHeight = size/_streamWidth + ((size % _streamWidth) ? 1 : 0);
int streamSize = getStreamSize();
// create Brook stream handle // create Brook stream handle
switch( _width ){ switch( _width ){
case 1: case 1:
_aStream = brook::stream::create<float>( _streamHeight, _streamWidth ); _aStream = brook::stream::create<float>( _streamHeight, _streamWidth );
break; break;
case 2: case 2:
_aStream = brook::stream::create<float2>( _streamHeight, _streamWidth ); _aStream = brook::stream::create<float2>( _streamHeight, _streamWidth );
break; break;
case 3: case 3:
_aStream = brook::stream::create<float3>( _streamHeight, _streamWidth ); _aStream = brook::stream::create<float3>( _streamHeight, _streamWidth );
break; break;
case 4: case 4:
_aStream = brook::stream::create<float4>( _streamHeight, _streamWidth ); _aStream = brook::stream::create<float4>( _streamHeight, _streamWidth );
break; break;
} }
// allocate memory for data buffer int streamSize = getStreamSize();
_data = new float*[streamSize];
for( int ii = 0; ii < streamSize; ii++ ){
_data[ii] = new float[_width];
}
// check if we are using float or double // allocate memory for data buffer
if( sizeof( float ) != sizeof( RealOpenMM ) ){ _data = new float[streamSize*_width];
_realOpenMMData = new RealOpenMM*[streamSize];
for( int ii = 0; ii < streamSize; ii++ ){
_realOpenMMData[ii] = new RealOpenMM[_width];
}
} else {
_realOpenMMData = NULL;
}
} }
/** /**
* BrookFloatStreamImpl destructor * BrookFloatStreamInternal destructor
* *
*/ */
BrookFloatStreamImpl::~BrookFloatStreamImpl( ){ BrookFloatStreamInternal::~BrookFloatStreamInternal( ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
//static const std::string methodName = "BrookFloatStreamImpl::~BrookFloatStreamImpl"; //static const std::string methodName = "BrookFloatStreamInternal::~BrookFloatStreamInternal";
// static const int debug = 1; // static const int debug = 1;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
//delete _aStream; //delete _aStream;
int streamSize = getStreamSize();
for( int ii = 0; ii < streamSize; ii++ ){
delete[] _data[ii];
}
delete[] _data; delete[] _data;
if( _realOpenMMData ){ }
for( int ii = 0; ii < streamSize; ii++ ){
delete[] _realOpenMMData[ii];
}
delete[] _realOpenMMData;
}
/**
* Get dangle value
*
* @return dangle value
*/
double BrookFloatStreamInternal::getDangleValue( void ) const {
return _defaultDangleValue;
} }
/** /**
* Load _data from input array * Load data from input array
* *
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream, * @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct _data type for this stream. If the stream has a compound _data type, all * and to contain elements of the correct _data type for this stream. If the stream has a compound _data type, all
* the values should be packed into a single array: all the values for the first element, followed by all the values * the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc. * for the next element, etc.
* *
* @throw exception if baseType not recognized
*
*/ */
void BrookFloatStreamImpl::loadFromArray( const void* array ){ void BrookFloatStreamInternal::loadFromArray( const void* array ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookFloatStreamImpl::loadFromArray"; //static const std::string methodName = "BrookFloatStreamInternal::loadFromArray";
// static const int debug = 1;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
if( _baseType == Stream::Float ){ return loadFromArray( array, getBaseDataType() );
loadFromArray( array, Stream::Float );
} else {
loadFromArray( array, Stream::Double );
}
}
/**
* Get width
*
* @return width
*/
int BrookFloatStreamImpl::getWidth( void ) const {
return _width;
}
/**
* Get stream width
*
* @return stream width
*/
int BrookFloatStreamImpl::getStreamWidth( void ) const {
return _streamWidth;
}
/**
* Get stream height
*
* @return stream height
*/
int BrookFloatStreamImpl::getStreamHeight( void ) const {
return _streamHeight;
}
/**
* Get Brook stream
*
* @return Brook stream
*/
brook::stream& BrookFloatStreamImpl::getBrookStream( void ){
return _aStream;
}
/**
* Get stream size
*
* @return stream size
*/
int BrookFloatStreamImpl::getStreamSize( void ) const {
return _streamWidth*_streamHeight;
} }
/** /**
* Load _data from input array * Load data from input array
* *
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream, * @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct _data type for this stream. If the stream has a compound _data type, all * and to contain elements of the correct _data type for this stream. If the stream has a compound _data type, all
* the values should be packed into a single array: all the values for the first element, followed by all the values * the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc. * for the next element, etc.
* *
* @param inputType type of input array (Stream::Float, Stream::Double, Stream::Integer) * @throw exception if baseType not float or double
* *
* @throw if input type not recognized, an exception is thrown
*/ */
void BrookFloatStreamImpl::loadFromArray( const void* array, Stream::DataType inputType ){ void BrookFloatStreamInternal::loadFromArray( const void* array, BrookStreamInternal::DataType baseType ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookFloatStreamImpl::loadFromArray"; static const std::string methodName = "BrookFloatStreamInternal::loadFromArray";
// static const int debug = 1; // static const int debug = 1;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
int index = 0; int totalSize = getSize()*getWidth();
if( inputType == Stream::Float ){
if( baseType == BrookStreamInternal::Float ){
memcpy( _data, array, sizeof( float )*totalSize );
/*
float* arrayData = (float*) array; float* arrayData = (float*) array;
for( int ii = 0; ii < getSize(); ii++ ){ for( int ii = 0; ii < totalSize; ii++ ){
for( int jj = 0; jj < getWidth(); jj++ ){ _data[ii] = (BrookOpenMMFloat) arrayData[ii];
_data[ii][jj] = (BrookOpenMMFloat) arrayData[index++];
}
} }
*/
} else if( inputType == Stream::Double ){ } else if( baseType == BrookStreamInternal::Double ){
double* arrayData = (double*) array; double* arrayData = (double*) array;
for( int ii = 0; ii < getSize(); ii++ ){ for( int ii = 0; ii < totalSize; ii++ ){
for( int jj = 0; jj < getWidth(); jj++ ){ _data[ii] = (BrookOpenMMFloat) arrayData[ii];
_data[ii][jj] = (BrookOpenMMFloat) arrayData[index++];
}
} }
} else if( inputType == Stream::Integer ){ } else if( baseType == BrookStreamInternal::Integer ){
int* arrayData = (int*) array; int* arrayData = (int*) array;
for( int ii = 0; ii < totalSize; ii++ ){
for( int ii = 0; ii < getSize(); ii++ ){ _data[ii] = (BrookOpenMMFloat) arrayData[ii];
for( int jj = 0; jj < getWidth(); jj++ ){
_data[ii][jj] = (BrookOpenMMFloat) arrayData[index++];
}
} }
} else { } else {
std::stringstream message; std::stringstream message;
message << methodName << " stream=" << getName() << " input type=" << inputType << " not recognized."; message << methodName << " stream=" << getName() << " base type=" << getTypeString( baseType ) << " not recognized.";
throw OpenMMException( message.str() ); throw OpenMMException( message.str() );
} }
...@@ -346,12 +274,11 @@ void BrookFloatStreamImpl::loadFromArray( const void* array, Stream::DataType in ...@@ -346,12 +274,11 @@ void BrookFloatStreamImpl::loadFromArray( const void* array, Stream::DataType in
_aStream.read( _data ); _aStream.read( _data );
} }
void BrookFloatStreamImpl::saveToArray( void* array ){ void BrookFloatStreamInternal::saveToArray( void* array ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
//static const std::string methodName = "BrookFloatStreamImpl::saveToArray"; static const std::string methodName = "BrookFloatStreamInternal::saveToArray";
// static const int debug = 1;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -361,24 +288,37 @@ void BrookFloatStreamImpl::saveToArray( void* array ){ ...@@ -361,24 +288,37 @@ void BrookFloatStreamImpl::saveToArray( void* array ){
// load into array // load into array
int index = 0; int totalSize = getSize()*getWidth();
if( _baseType == Stream::Float ){ BrookStreamInternal::DataType baseType = getBaseDataType();
if( baseType == BrookStreamInternal::Float ){
memcpy( array, _data, sizeof( float )*totalSize );
/*
float* arrayData = (float*) array; float* arrayData = (float*) array;
for( int ii = 0; ii < getSize(); ii++ ){ for( int ii = 0; ii < totalSize; ii++ ){
for( int jj = 0; jj < getWidth(); jj++ ){ arrayData[ii] = (float) _data[ii];
arrayData[index++] = (float) _data[ii][jj];
}
} }
*/
} else { } else if( baseType == BrookStreamInternal::Double ){
double* arrayData = (double*) array; double* arrayData = (double*) array;
for( int ii = 0; ii < getSize(); ii++ ){ for( int ii = 0; ii < totalSize; ii++ ){
for( int jj = 0; jj < getWidth(); jj++ ){ arrayData[ii] = (double) _data[ii];
arrayData[index++] = _data[ii][jj];
} }
} else if( baseType == BrookStreamInternal::Integer ){
int* arrayData = (int*) array;
for( int ii = 0; ii < totalSize; ii++ ){
arrayData[ii] = (int) _data[ii];
} }
} else {
std::stringstream message;
message << methodName << " stream=" << getName() << " base type=" << getTypeString( baseType ) << " not recognized.";
throw OpenMMException( message.str() );
} }
} }
...@@ -390,39 +330,41 @@ void BrookFloatStreamImpl::saveToArray( void* array ){ ...@@ -390,39 +330,41 @@ void BrookFloatStreamImpl::saveToArray( void* array ){
* *
*/ */
void BrookFloatStreamImpl::fillWithValue( void* value ){ void BrookFloatStreamInternal::fillWithValue( void* value ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookFloatStreamImpl::fillWithValue"; // static const std::string methodName = "BrookFloatStreamInternal::fillWithValue";
// static const int debug = 1; // static const int debug = 1;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
BrookOpenMMFloat valueData; BrookOpenMMFloat valueData;
if( _baseType == Stream::Float) { if( _baseType == BrookStreamInternal::Float) {
valueData = (BrookOpenMMFloat) *((float*) value); valueData = (BrookOpenMMFloat) *((float*) value);
} else { } else {
valueData = (BrookOpenMMFloat) *((double*) value); valueData = (BrookOpenMMFloat) *((double*) value);
} }
for( int ii = 0; ii < getSize(); ii++ ){ //memset( _data, valueData, sizeof( float )*getSize()*getWidth() );
for (int jj = 0; jj < getWidth(); jj++ ){
_data[ii][jj] = valueData; int totalSize = getSize()*getWidth();
} for( int ii = 0; ii < totalSize; ii++ ){
_data[ii] = valueData;
} }
_loadDanglingValues(); _loadDanglingValues();
_aStream.read( _data ); _aStream.read( _data );
} }
const RealOpenMM* const * BrookFloatStreamImpl::getData() const { const RealOpenMM* const * BrookFloatStreamInternal::getData() const {
return NULL; return NULL;
} }
// problem w/ const here -- _data is modified (cast away?) // problem w/ const here -- _data is modified (cast away?)
/* /*
const RealOpenMM* const * BrookFloatStreamImpl::getData() const { const RealOpenMM* const * BrookFloatStreamInternal::getData() const {
// retrieve _data from GPU // retrieve _data from GPU
...@@ -433,7 +375,7 @@ const RealOpenMM* const * BrookFloatStreamImpl::getData() const { ...@@ -433,7 +375,7 @@ const RealOpenMM* const * BrookFloatStreamImpl::getData() const {
if( realOpenMMData ){ if( realOpenMMData ){
for( int i = 0; i < getSize(); i++ ){ for( int i = 0; i < getSize(); i++ ){
for( int j = 0; j < _width; j++ ){ for( int j = 0; j < getWidth(); j++ ){
realOpenMMData[i][j] = (RealOpenMM) _data[i][j]; realOpenMMData[i][j] = (RealOpenMM) _data[i][j];
} }
} }
...@@ -451,29 +393,30 @@ const RealOpenMM* const * BrookFloatStreamImpl::getData() const { ...@@ -451,29 +393,30 @@ const RealOpenMM* const * BrookFloatStreamImpl::getData() const {
* *
*/ */
RealOpenMM** BrookFloatStreamImpl::getData( void ){ RealOpenMM** BrookFloatStreamInternal::getData( void ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookFloatStreamImpl::getData"; // static const std::string methodName = "BrookFloatStreamInternal::getData";
// static const int debug = 1; // static const int debug = 1;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
/*
_aStream.write( _data ); _aStream.write( _data );
if( _realOpenMMData ){ if( _realOpenMMData ){
for( int ii = 0; ii < getSize(); ii++ ){ int totalSize = getSize()*getWidth();
for (int jj = 0; jj < getWidth(); jj++ ){ for( int ii = 0; ii < totalSize; ii++ ){
_realOpenMMData[ii][jj] = (RealOpenMM) _data[ii][jj]; _realOpenMMData[ii] = (RealOpenMM) _data[ii];
}
} }
return _realOpenMMData; return _realOpenMMData;
} else { } else {
return _data; return _data;
} }
*/
return NULL;
} }
/** /**
* Load dangling value into stream * Load dangling value into stream
* *
...@@ -481,19 +424,23 @@ RealOpenMM** BrookFloatStreamImpl::getData( void ){ ...@@ -481,19 +424,23 @@ RealOpenMM** BrookFloatStreamImpl::getData( void ){
* *
*/ */
void BrookFloatStreamImpl::_loadDanglingValues( float danglingValue ){ void BrookFloatStreamInternal::_loadDanglingValues( float danglingValue ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookFloatStreamImpl::_loadDanglingValues"; // static const std::string methodName = "BrookFloatStreamInternal::_loadDanglingValues";
// static const int debug = 1; // static const int debug = 1;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
int streamSize = getStreamSize(); int width = getWidth();
for( int ii = getSize(); ii < streamSize; ii++ ){
for (int jj = 0; jj < getWidth(); jj++ ){ int arraySize = getSize()*width;
_data[ii][jj] = danglingValue; int streamSize = getStreamSize()*width;
if( arraySize < streamSize ){
for( int ii = arraySize; ii < streamSize; ii++ ){
_data[ii] = danglingValue;
} }
} }
} }
...@@ -503,6 +450,60 @@ void BrookFloatStreamImpl::_loadDanglingValues( float danglingValue ){ ...@@ -503,6 +450,60 @@ void BrookFloatStreamImpl::_loadDanglingValues( float danglingValue ){
* *
*/ */
void BrookFloatStreamImpl::_loadDanglingValues( void ){ void BrookFloatStreamInternal::_loadDanglingValues( void ){
_loadDanglingValues( _defaultDangleValue ); _loadDanglingValues( _defaultDangleValue );
} }
/*
* Get contents of object
*
* @param level level of dump
*
* @return string containing contents
*
* */
const std::string BrookFloatStreamInternal::getContentsString( int level ) const {
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookFloatStreamInternal::getContentsString";
static const unsigned int MAX_LINE_CHARS = 256;
char value[MAX_LINE_CHARS];
//static const char* Set = "Set";
//static const char* NotSet = "Not set";
// ---------------------------------------------------------------------------------------
std::stringstream message;
std::string tab = " ";
#ifdef WIN32
#define LOCAL_SPRINTF(a,b,c) sprintf_s( (a), MAX_LINE_CHARS, (b), (c) );
#else
#define LOCAL_SPRINTF(a,b,c) sprintf( (a), (b), (c) );
#endif
(void) LOCAL_SPRINTF( value, "%s", getName().c_str() );
message << _getLine( tab, "Name:", value );
(void) LOCAL_SPRINTF( value, "%d", getWidth() );
message << _getLine( tab, "Width:", value );
(void) LOCAL_SPRINTF( value, "%d", getStreamSize() );
message << _getLine( tab, "Stream size:", value );
(void) LOCAL_SPRINTF( value, "%d", getStreamWidth() );
message << _getLine( tab, "Stream width:", value );
(void) LOCAL_SPRINTF( value, "%d", getStreamHeight() );
message << _getLine( tab, "Stream height:", value );
(void) LOCAL_SPRINTF( value, "%3e", getDangleValue() );
message << _getLine( tab, "Dangle value:", value );
return message.str();
}
#ifndef OPENMM_BROOK_FLOAT_STREAM_INTERNAL_H_
#define OPENMM_BROOK_FLOAT_STREAM_INTERNAL_H_
/* -------------------------------------------------------------------------- *
* 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, Mark Friedrichs *
* 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. *
* -------------------------------------------------------------------------- */
#include "BrookPlatform.h"
#include "BrookStreamInternal.h"
#include "SimTKUtilities/SimTKOpenMMRealType.h"
namespace OpenMM {
/**
* This is the implementation of Float and Double streams in the Brook Platform.
*/
class BrookFloatStreamInternal : public BrookStreamInternal {
public:
/**
* BrookFloatStreamInternal constructor
*
* @param name stream name
* @param size size of array
* @param streamWidth stream width
* @param type stream type (float, float2, ...)
* @param inputDefaultDangleValue default dangle value
*
*/
BrookFloatStreamInternal( const std::string& name, int size, int inputStreamWidth, BrookStreamInternal::DataType type, double defaultDangleValue = 0.0 );
/**
* BrookFloatStreamInternal destructor
*
*/
~BrookFloatStreamInternal( );
/**
* Load data from input array
*
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct _data type for this stream. If the stream has a compound _data type, all
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*
* @throw exception if baseType not float or double
*
*/
void loadFromArray( const void* array );
/**
* Copy the contents of an array into this stream.
*
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct data type for this stream. If the stream has a compound data type, all
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*/
void loadFromArray( const void* array, BrookStreamInternal::DataType baseType );
/**
* Save data to input array
*
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct _data type for this stream. If the stream has a compound _data type, all
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*
* @throw exception if baseType not float or double
*
*/
void saveToArray( void* array );
void fillWithValue( void* value );
const RealOpenMM* const * getData( ) const;
RealOpenMM** getData( void );
/**
* Get dangle value
*
* @return dangle value
*/
double getDangleValue( void ) const;
/*
* Get contents of object
*
*
* @param level level of dump
*
* @return string containing contents
*
* */
const std::string getContentsString( int level = 0 ) const;
private:
BrookOpenMMFloat _defaultDangleValue;
float* _data;
RealOpenMM* _realOpenMMData;
void _loadDanglingValues( void );
void _loadDanglingValues( float );
};
} // namespace OpenMM
#endif /* OPENMM_BROOK_FLOAT_STREAM_INTERNAL_H_ */
/* -------------------------------------------------------------------------- *
* 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: Mark Friedrichs *
* 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. *
* -------------------------------------------------------------------------- */
#include <sstream>
#include "BrookGbsa.h"
#include "BrookPlatform.h"
using namespace OpenMM;
using namespace std;
/**
* Constructor
*
*/
BrookGbsa::BrookGbsa( ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookGbsa::BrookGbsa";
// ---------------------------------------------------------------------------------------
_atomSizeCeiling = -1;
_outerUnroll = 4;
_innerUnroll = 4;
_partialForceStreamWidth = 64;
_partialForceStreamHeight = -1;
_partialForceStreamSize = -1;
_gbsaStreamWidth = -1;
_gbsaStreamHeight = -1;
_gbsaStreamSize = -1;
_duplicationFactor = 4;
_solventDielectric = 78.3;
_soluteDielectric = 1.0;
for( int ii = 0; ii < LastStreamIndex; ii++ ){
_gbsaStreams[ii] = NULL;
}
for( int ii = 0; ii < getNumberOfForceStreams(); ii++ ){
_gbsaForceStreams[ii] = NULL;
}
}
/**
* Destructor
*
*/
BrookGbsa::~BrookGbsa( ){
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "BrookGbsa::~BrookGbsa";
// ---------------------------------------------------------------------------------------
for( int ii = 0; ii < LastStreamIndex; ii++ ){
delete _gbsaStreams[ii];
}
for( int ii = 0; ii < getNumberOfForceStreams(); ii++ ){
delete _gbsaForceStreams[ii];
}
}
/**
* Get number of force streams
*
* @return number of force streams (fixed value)
*
*/
int BrookGbsa::getNumberOfForceStreams( void ) const {
return NumberOfForceStreams;
}
/**
* Get inner loop unroll
*
* @return inner loop unroll (fixed value)
*
*/
int BrookGbsa::getInnerLoopUnroll( void ) const {
return _innerUnroll;
}
/**
* Get outer loop unroll
*
* @return outer loop unroll (fixed value)
*
*/
int BrookGbsa::getOuterLoopUnroll( void ) const {
return _outerUnroll;
}
/**
* Get solute dielectric
*
* @return solute dielectric
*
*/
double BrookGbsa::getSoluteDielectric( void ) const {
return _soluteDielectric;
}
/**
* Get solvent dielectric
*
* @return solvent dielectric
*
*/
double BrookGbsa::getSolventDielectric( void ) const {
return _solventDielectric;
}
/**
* Set outer loop unroll
*
* @param outer loop unroll (fixed value)
*
* @return updated outer loop unroll (fixed value)
*
*/
int BrookGbsa::setOuterLoopUnroll( int outerUnroll ){
if( outerUnroll != _outerUnroll ){
_atomSizeCeiling = -1;
}
_outerUnroll = _outerUnroll;
return _outerUnroll;
}
/**
* Get atom ceiling parameter
*
* @return atom ceiling parameter
*
*/
int BrookGbsa::getAtomSizeCeiling( void ) const {
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "BrookGbsa::getAtomSizeCeiling";
// ---------------------------------------------------------------------------------------
if( _atomSizeCeiling < 0 ){
BrookGbsa* localThis = const_cast<BrookGbsa* const>(this);
localThis->_atomSizeCeiling = localThis->getNumberOfAtoms() % localThis->getOuterLoopUnroll();
if( localThis->_atomSizeCeiling ){
localThis->_atomSizeCeiling = localThis->getOuterLoopUnroll() - localThis->_atomSizeCeiling;
}
}
return _atomSizeCeiling;
}
/**
* Get duplication factor
*
* @return duplication factor
*
*/
int BrookGbsa::getDuplicationFactor( void ) const {
return _duplicationFactor;
}
/**
* Get partial force stream width
*
* @param platform platform
*
* @return partial force stream width
*
*/
int BrookGbsa::getPartialForceStreamWidth( const Platform& platform ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookGbsa::getPartialForceStreamWidth";
// ---------------------------------------------------------------------------------------
// get partial force stream width
if( _partialForceStreamWidth < 0 ){
//_getPartialForceStreamDimensions( platform );
}
return _partialForceStreamWidth;
}
/**
* Get partial force stream width
*
* @return partial force stream width
*
*/
int BrookGbsa::getPartialForceStreamWidth( void ) const {
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookGbsa::getPartialForceStreamWidth";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
return _partialForceStreamWidth;
}
/**
* Get partial force stream height
*
* @param platform platform
*
* @return partial force stream height
*
*/
int BrookGbsa::getPartialForceStreamHeight( const Platform& platform ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookGbsa::getPartialForceStreamHeight";
// ---------------------------------------------------------------------------------------
// get partial force stream height
if( _partialForceStreamHeight < 0 ){
//_getPartialForceStreamDimensions( platform );
}
return _partialForceStreamHeight;
}
/**
* Get partial force stream height
*
* @return partial force stream height
*
*/
int BrookGbsa::getPartialForceStreamHeight( void ) const {
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookGbsa::getPartialForceStreamHeight";
// ---------------------------------------------------------------------------------------
return _partialForceStreamHeight;
}
/**
* Get partial force stream size
*
* @param platform platform
*
* @return partial force stream size
*
*/
int BrookGbsa::getPartialForceStreamSize( const Platform& platform ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookGbsa::getPartialForceStreamSize";
// ---------------------------------------------------------------------------------------
// get partial force stream size
if( _partialForceStreamSize < 0 ){
//_getPartialForceStreamDimensions( platform );
}
return _partialForceStreamSize;
}
/**
* Get partial force stream size
*
* @return partial force stream size
*
*/
int BrookGbsa::getPartialForceStreamSize( void ) const {
return _partialForceStreamSize;
}
/**
* Get Gbsa stream size
*
* @return Gbsa stream size
*
*/
int BrookGbsa::getGbsaStreamSize( void ) const {
return _gbsaStreamSize;
}
/**
* Get gbsa stream width
*
* @return gbsa stream width
*
*/
int BrookGbsa::getGbsaStreamWidth( void ) const {
return _gbsaStreamWidth;
}
/**
* Get Obc atomic radii stream
*
* @return Obc atomic radii stream
*
*/
BrookFloatStreamInternal* BrookGbsa::getObcAtomicRadii( void ) const {
return _gbsaStreams[ObcAtomicRadiiStream];
}
/**
* Get Obc scaled atomic radii stream
*
* @return Obc scaled atomic radii stream
*
*/
BrookFloatStreamInternal* BrookGbsa::getObcScaledAtomicRadii( void ) const {
return _gbsaStreams[ObcScaledAtomicRadiiStream];
}
/**
* Get Obc atomic radii w/ dielectric offset
*
* @return Obc atomic radii w/ dielectric offset
*
*/
BrookFloatStreamInternal* BrookGbsa::getObcAtomicRadiiWithDielectricOffset( void ) const {
return _gbsaStreams[ObcAtomicRadiiWithDielectricOffsetStream];
}
/**
* Get Obc Born radii
*
* @return Obc Born radii
*
*/
BrookFloatStreamInternal* BrookGbsa::getObcBornRadii( void ) const {
return _gbsaStreams[ObcBornRadiiStream];
}
/**
* Get Obc Born radii2
*
* @return Obc Born radii2
*
*/
BrookFloatStreamInternal* BrookGbsa::getObcBornRadii2( void ) const {
return _gbsaStreams[ObcBornRadii2Stream];
}
/**
* Get Obc intermediate force stream
*
* @return Obcintermediate force stream
*
*/
BrookFloatStreamInternal* BrookGbsa::getObcIntermediateForce( void ) const {
return _gbsaStreams[ObcIntermediateForceStream];
}
/**
* Get Obc chain stream
*
* @return Obc chain stream
*
*/
BrookFloatStreamInternal* BrookGbsa::getObcChain( void ) const {
return _gbsaStreams[ObcChainStream];
}
/**
* Get force streams
*
* @return force streams
*
*/
BrookFloatStreamInternal** BrookGbsa::getForceStreams( void ){
return _gbsaForceStreams;
}
/**
* Return true if force[index] stream is set
*
* @param index into force stream
* @return true if index is valid && force[index] stream is set; else false
*
*/
int BrookGbsa::isForceStreamSet( int index ) const {
return (index >= 0 && index < getNumberOfForceStreams() && _gbsaForceStreams[index]) ? 1 : 0;
}
/**
* Initialize stream dimensions
*
* @param numberOfAtoms number of atoms
* @param platform platform
*
* @return ErrorReturnValue if error, else DefaultReturnValue
*
*/
int BrookGbsa::initializeStreamSizes( int numberOfAtoms, const Platform& platform ){
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookGbsa::initializeStreamSizes";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
int atomStreamSize = getAtomStreamSize( platform );
int atomStreamWidth = getAtomStreamWidth( platform );
initializeExclusionStreamSize( atomStreamSize, atomStreamWidth );
initializeJStreamSize( atomStreamSize, atomStreamWidth );
initializeOuterVdwStreamSize( atomStreamSize, atomStreamWidth );
initializePartialForceStreamSize( atomStreamSize, atomStreamWidth );
return DefaultReturnValue;
}
/**
* Initialize streams
*
* @param platform platform
*
* @return ErrorReturnValue if error, else DefaultReturnValue
*
*/
int BrookGbsa::initializeStreams( const Platform& platform ){
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookGbsa::initializeStreams";
static const double dangleValue = 0.0;
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
const BrookStreamFactory& brookStreamFactory = dynamic_cast<const BrookStreamFactory&> (platform.getDefaultStreamFactory());
// exclusion
_gbsaStreams[ExclusionStream] = new BrookFloatStreamInternal( BrookStreamFactory::NonBondedExclusionStream,
getExclusionStreamSize(), getExclusionStreamWidth(),
BrookStreamInternal::Float, dangleValue );
// outer vdw
_gbsaStreams[OuterVdwStream] = new BrookFloatStreamInternal( BrookStreamFactory::OuterVdwStream, getAtomStreamSize(),
getAtomStreamWidth(), BrookStreamInternal::Float2, dangleValue );
// inner sigma & epsilon
_gbsaStreams[InnerSigmaStream] = new BrookFloatStreamInternal( BrookStreamFactory::InnerSigmaStream, getJStreamSize(),
getJStreamWidth(), BrookStreamInternal::Float4, dangleValue );
_gbsaStreams[InnerEpsilonStream] = new BrookFloatStreamInternal( BrookStreamFactory::InnerEpsilonStream, getJStreamSize(),
getJStreamWidth(), BrookStreamInternal::Float4, dangleValue );
// charge stream
_gbsaStreams[ChargeStream] = new BrookFloatStreamInternal( BrookStreamFactory::NonBondedChargeStream, getAtomStreamSize(),
getAtomStreamWidth(), BrookStreamInternal::Float, dangleValue );
// partial force stream
std::string partialForceStream = BrookStreamFactory::PartialForceStream;
for( int ii = 0; ii < getNumberOfForceStreams(); ii++ ){
std::stringstream name;
name << partialForceStream << ii;
_gbsaForceStreams[ii] = new BrookFloatStreamInternal( name.str(), getPartialForceStreamSize(),
getPartialForceStreamWidth(), BrookStreamInternal::Float4, dangleValue );
}
return DefaultReturnValue;
}
/*
* Setup of Gbsa parameters
*
* @param atomParameters vector of OBC parameters [atomI][0=index]
* [atomI][1=charge]
* [atomI][2=radius]
* [atomI][2=scaling factor]
* @param solventDielectric solvent dielectric
* @param soluteDielectric solute dielectric
*
* @return nonzero value if error
*
* */
int BrookGbsa::setup( const std::vector<std::vector<double> >& atomParameters,
double solventDielectric, double soluteDielectric );
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookGbsa::setup";
// ---------------------------------------------------------------------------------------
setNumberOfAtoms( (int) atomParameters.size() );
solventDielectric = _solventDielectric;
soluteDielectric = _soluteDielectric;
initializeStreamSizes( getNumberOfAtoms(), platform );
initializeStreams( platform );
return DefaultReturnValue;
}
/*
* Setup of stream dimensions for partial force streams
*
* @param atomStreamSize atom stream size
* @param atomStreamWidth atom stream width
*
* @return ErrorReturnValue if error, else DefaultReturnValue
*
* */
int BrookGbsa::initializePartialForceStreamSize( int atomStreamSize, int atomStreamWidth ){
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookGbsa::initializePartialForceStreamSize";
//static const int debug = 1;
// ---------------------------------------------------------------------------------------
int innerUnroll = getInnerLoopUnroll();
if( innerUnroll < 1 ){
std::stringstream message;
message << methodName << " innerUnrolls=" << innerUnroll << " is less than 1.";
throw OpenMMException( message.str() );
return ErrorReturnValue;
}
if( _partialForceStreamWidth < 1 ){
std::stringstream message;
message << methodName << " partial force stream width=" << _partialForceStreamWidth << " is less than 1.";
throw OpenMMException( message.str() );
return ErrorReturnValue;
}
_partialForceStreamSize = atomStreamSize*getDuplicationFactor()/innerUnroll;
_partialForceStreamHeight = _partialForceStreamSize/_partialForceStreamWidth;
_partialForceStreamHeight += ( (_partialForceStreamSize % _partialForceStreamWidth) ? 1 : 0);
return DefaultReturnValue;
}
/*
* Setup of j-stream dimensions
*
* Get contents of object
*
*
* @param level level of dump
*
* @return string containing contents
*
* */
std::string BrookGbsa::getContentsString( int level ) const {
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookGbsa::getContentsString";
static const unsigned int MAX_LINE_CHARS = 256;
char value[MAX_LINE_CHARS];
static const char* Set = "Set";
static const char* NotSet = "Not set";
// ---------------------------------------------------------------------------------------
std::stringstream message;
std::string tab = " ";
#ifdef WIN32
#define LOCAL_SPRINTF(a,b,c) sprintf_s( (a), MAX_LINE_CHARS, (b), (c) );
#else
#define LOCAL_SPRINTF(a,b,c) sprintf( (a), (b), (c) );
#endif
(void) LOCAL_SPRINTF( value, "%d", getNumberOfAtoms() );
message << _getLine( tab, "Number of atoms:", value );
(void) LOCAL_SPRINTF( value, "%d", getNumberOfForceStreams() );
message << _getLine( tab, "Number of force streams:", value );
(void) LOCAL_SPRINTF( value, "%d", getDuplicationFactor() );
message << _getLine( tab, "Duplication factor:", value );
(void) LOCAL_SPRINTF( value, "%d", getInnerLoopUnroll () )
message << _getLine( tab, "Inner loop unroll:", value );
(void) LOCAL_SPRINTF( value, "%d", getOuterLoopUnroll() )
message << _getLine( tab, "Outer loop unroll:", value );
(void) LOCAL_SPRINTF( value, "%d", getAtomSizeCeiling() );
message << _getLine( tab, "Atom ceiling:", value );
(void) LOCAL_SPRINTF( value, "%d", getAtomStreamWidth() );
message << _getLine( tab, "Atom stream width:", value );
(void) LOCAL_SPRINTF( value, "%d", getAtomStreamHeight() );
message << _getLine( tab, "Atom stream height:", value );
(void) LOCAL_SPRINTF( value, "%d", getAtomStreamSize() );
message << _getLine( tab, "Atom stream size:", value );
(void) LOCAL_SPRINTF( value, "%d", getPartialForceStreamWidth() );
message << _getLine( tab, "Partial force stream width:", value );
(void) LOCAL_SPRINTF( value, "%d", getPartialForceStreamHeight() );
message << _getLine( tab, "Partial force stream height:", value );
(void) LOCAL_SPRINTF( value, "%d", getPartialForceStreamSize() );
message << _getLine( tab, "Partial force stream size:", value );
(void) LOCAL_SPRINTF( value, "%d", getExclusionStreamWidth() );
message << _getLine( tab, "Exclusion stream width:", value );
message << _getLine( tab, "Log:", (getLog() ? Set : NotSet) );
/*
message << _getLine( tab, "ExclusionStream:", (getExclusionStream() ? Set : NotSet) );
message << _getLine( tab, "VdwStream:", (getOuterVdwStream() ? Set : NotSet) );
message << _getLine( tab, "ChargeStream:", (getChargeStream() ? Set : NotSet) );
message << _getLine( tab, "SigmaStream:", (getInnerSigmaStream() ? Set : NotSet) );
message << _getLine( tab, "EpsilonStream:", (getInnerEpsilonStream() ? Set : NotSet) );
*/
for( int ii = 0; ii < LastStreamIndex; ii++ ){
message << std::endl;
if( _gbsaStreams[ii] ){
message << _gbsaStreams[ii]->getContentsString( );
}
}
// force streams
for( int ii = 0; ii < getNumberOfForceStreams(); ii++ ){
char description[256];
(void) LOCAL_SPRINTF( description, "PartialForceStream %d", ii );
message << _getLine( tab, description, (isForceStreamSet(ii) ? Set : NotSet) );
}
for( int ii = 0; ii < getNumberOfForceStreams(); ii++ ){
message << std::endl;
if( _gbsaForceStreams[ii] ){
message << _gbsaForceStreams[ii]->getContentsString( );
}
}
#undef LOCAL_SPRINTF
return message.str();
}
#ifndef OPENMM_BROOK_GBSA_H_
#define OPENMM_BROOK_GBSA_H_
/* -------------------------------------------------------------------------- *
* 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, Mark Friedrichs *
* 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. *
* -------------------------------------------------------------------------- */
#include <vector>
#include <set>
#include "BrookFloatStreamInternal.h"
#include "BrookPlatform.h"
#include "BrookCommon.h"
namespace OpenMM {
/**
* This kernel is invoked by StandardMMForceField to calculate the forces acting on the system.
*/
class BrookGbsa : public BrookCommon {
public:
// return values
static const int DefaultReturnValue = 0;
static const int ErrorReturnValue = -1;
BrookGbsa( );
~BrookGbsa();
/**
* Return number of force streams
*
* @return number of force streams
*
*/
int getNumberOfForceStreams( void ) const;
/**
* Get duplication factor
*
* @return duplication factor
*
*/
int getDuplicationFactor( void ) const;
/**
* Get atom ceiling parameter
*
* @return atom ceiling parameter
*
*/
int getAtomSizeCeiling( void ) const;
/**
* Get outer loop unroll
*
* @return outer loop unroll (fixed value)
*
*/
int getOuterLoopUnroll( void ) const;
/**
* Set outer loop unroll
*
* @param outer loop unroll (fixed value)
*
* @return updated outer loop unroll (fixed value)
*
*/
int setOuterLoopUnroll( int outerUnroll );
/**
* Return unrolling for inner loops
*
* @return outer loop unrolling
*/
int getInnerLoopUnroll( void ) const;
/**
* Return true if ACE approximation is to be included
*
* @return true if ACE approximation is to be included
*/
int includeAce( void ) const;
/**
* Get partial force stream width
*
* @return partial force stream width
*/
int getPartialForceStreamWidth( void ) const;
/**
* Get partial force stream height
*
* @return partial force stream height
*/
int getPartialForceStreamHeight( void ) const;
/**
* Get partial force stream size
*
* @return partial force stream size
*/
int getPartialForceStreamSize( void ) const;
/**
* Get solute dielectric
*
* @return solute dielectric
*/
float getSoluteDielectric( void ) const;
/**
* Get solvent dielectric
*
* @return solvent dielectric
*/
float getSolventDielectric( void ) const;
/**
* Get atomic radii
*
* @return atomic radii stream
*
*/
BrookFloatStreamInternal* getObcAtomicRadii( void ) const;
/**
* Get scaled atomic radii
*
* @return scaled atomic radii stream
*
*/
BrookFloatStreamInternal* getObcScaledAtomicRadii( void ) const;
/**
* Get atomic radii w/ dielectric offset
*
* @return atomic radii w/ dielectric offset stream
*
*/
BrookFloatStreamInternal* getObcAtomicRadiiWithDielectricOffset( void ) const;
/**
* Get Born radii stream
*
* @return Born radii stream
*
*/
BrookFloatStreamInternal* getObcBornRadii( void ) const;
/**
* Get Born radii2 stream
*
* @return Born radii2 stream
*
*/
BrookFloatStreamInternal* getObcBornRadii2( void ) const;
/**
* Get Obc intermediate force stream
*
* @return Obc intermediate force stream
*
*/
BrookFloatStreamInternal* getObcIntermediateForce( void ) const;
/**
* Get Obc chain stream
*
* @return Obc chain stream
*
*/
BrookFloatStreamInternal* getObcChain( void ) const;
/**
* Get force streams
*
* @return force streams
*
*/
BrookFloatStreamInternal** getForceStreams( void );
/**
* Return true if force[index] stream is set
*
* @return true if index is valid && force[index] stream is set; else false
*
*/
int isForceStreamSet( int index ) const;
/*
* Setup of Gbsa parameters
*
* @param atomParameters vector of OBC parameters [atomI][0=index]
* [atomI][1=charge]
* [atomI][2=radius]
* [atomI][2=scaling factor]
* @param solventDielectric solvent dielectric
* @param soluteDielectric solute dielectric
*
* @return nonzero value if error
*
* */
int setup( const std::vector<std::vector<double> >& atomParameters,
double solventDielectric, double soluteDielectric );
/*
* Get contents of object
*
* @param level of dump
*
* @return string containing contents
*
* */
std::string getContentsString( int level = 0 ) const;
private:
// fixed number of force streams
static const int NumberOfForceStreams = 4;
// streams indices
enum {
ObcAtomicRadiiStream,
ObcRadiiStreamStream,
ObcScaledAtomicRadiiStream,
ObcAtomicRadiiWithDielectricOffsetStream,
ObcBornRadiiStream,
ObcBornRadii2Stream,
ObcIntermediateForceStream,
ObcChainStream,
LastStreamIndex
};
// atom ceiling
int _atomSizeCeiling;
// unroll in i/j dimensions
int _outerUnroll;
int _innerUnroll;
// duplication factor
int _duplicationFactor;
// force stream width
int _partialForceStreamWidth;
int _partialForceStreamHeight;
int _partialForceStreamSize;
// Gbsa stream dimensions
int _gbsaStreamWidth;
int _gbsaStreamHeight;
int _gbsaStreamSize;
// dielectrics
double _solventDielectric
double _soluteDielectric
// internal streams
BrookFloatStreamInternal* _gbsaStreams[LastStreamIndex];
BrookFloatStreamInternal* _gbsaForceStreams[NumberOfForceStreams];
/*
* Setup of stream dimensions
*
* @param atomStreamSize atom stream size
* @param atomStreamWidth atom stream width
*
* @return ErrorReturnValue if error, else DefaultReturnValue
*
* */
int initializeStreamSizes( int atomStreamSize, int atomStreamWidth );
/**
* Initialize stream dimensions
*
* @param numberOfAtoms number of atoms
* @param platform platform
*
* @return ErrorReturnValue if error, else DefaultReturnValue
*
*/
int initializeStreamSizes( int numberOfAtoms, const Platform& platform );
/**
* Initialize stream dimensions and streams
*
* @param platform platform
*
* @return nonzero value if error
*
*/
int initializeStreams( const Platform& platform );
/*
* Setup of stream dimensions for partial force streams
*
* @param atomStreamSize atom stream size
* @param atomStreamWidth atom stream width
*
* @return ErrorReturnValue if error, else DefaultReturnValue
*
* */
int initializePartialForceStreamSize( int atomStreamSize, int atomStreamWidth );
};
} // namespace OpenMM
#endif /* OPENMM_BROOK_GBSA_H_ */
...@@ -29,14 +29,14 @@ ...@@ -29,14 +29,14 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * * USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "BrookIntStreamImpl.h" #include "BrookIntStreamInternal.h"
#include "OpenMMException.h" #include "OpenMMException.h"
#include <sstream> #include <sstream>
using namespace OpenMM; using namespace OpenMM;
/** /**
* BrookIntStreamImpl constructor * BrookIntStreamInternal constructor
* *
* @param name stream name * @param name stream name
* @param size stream size * @param size stream size
...@@ -44,30 +44,33 @@ using namespace OpenMM; ...@@ -44,30 +44,33 @@ using namespace OpenMM;
* *
*/ */
BrookIntStreamImpl::BrookIntStreamImpl( std::string name, int size, Stream::DataType type, const Platform& platform ) : StreamImpl( name, size, type, platform ){ BrookIntStreamInternal::BrookIntStreamInternal( std::string name, int size, int width, BrookStreamInternal::DataType type,
int dangleValue ) : BrookStreamInternal( name, size, width, type ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookIntStreamImpl::BrookIntStreamImpl"; static const std::string methodName = "BrookIntStreamInternal::BrookIntStreamInternal";
// static const int debug = 1; // static const int debug = 1;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
_dangleValue = dangleValue;
switch( type ){ switch( type ){
case Stream::Integer: case BrookStreamInternal::Integer:
width = 1; width = 1;
break; break;
case Stream::Integer2: case BrookStreamInternal::Integer2:
width = 2; width = 2;
break; break;
case Stream::Integer3: case BrookStreamInternal::Integer3:
width = 3; width = 3;
break; break;
case Stream::Integer4: case BrookStreamInternal::Integer4:
width = 4; width = 4;
break; break;
...@@ -85,11 +88,11 @@ BrookIntStreamImpl::BrookIntStreamImpl( std::string name, int size, Stream::Data ...@@ -85,11 +88,11 @@ BrookIntStreamImpl::BrookIntStreamImpl( std::string name, int size, Stream::Data
} }
/** /**
* BrookIntStreamImpl destructor * BrookIntStreamInternal destructor
* *
*/ */
BrookIntStreamImpl::~BrookIntStreamImpl() { BrookIntStreamInternal::~BrookIntStreamInternal() {
delete[] data; delete[] data;
} }
...@@ -100,19 +103,44 @@ BrookIntStreamImpl::~BrookIntStreamImpl() { ...@@ -100,19 +103,44 @@ BrookIntStreamImpl::~BrookIntStreamImpl() {
* *
*/ */
void BrookIntStreamImpl::loadFromArray( const void* array ){ void BrookIntStreamInternal::loadFromArray( const void* array ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookIntStreamImpl::loadFromArray"; // static const std::string methodName = "BrookIntStreamInternal::loadFromArray";
// static const int debug = 1; // static const int debug = 1;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
return loadFromArray( array, getBaseDataType() );
}
/**
* Load data from array into stream
*
* @param array array to load (length=size*width)
*
*/
void BrookIntStreamInternal::loadFromArray( const void* array, BrookStreamInternal::DataType baseType ){
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookIntStreamInternal::loadFromArray(1)";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
if( baseType != BrookStreamInternal::Integer ){
std::stringstream message;
message << methodName << " stream=" << getName() << " base type=" << getTypeString( baseType ) << " not handled -- add code.";
throw OpenMMException( message.str() );
}
int* arrayData = (int*) array; int* arrayData = (int*) array;
int index = 0; int index = 0;
for( int ii = 0; ii < getSize(); ii++ ){ for( int ii = 0; ii < getSize(); ii++ ){
for( int jj = 0; jj < width; jj++ ){ for( int jj = 0; jj < getWidth(); jj++ ){
data[ii][jj] = arrayData[index++]; data[ii][jj] = arrayData[index++];
} }
} }
...@@ -125,11 +153,11 @@ void BrookIntStreamImpl::loadFromArray( const void* array ){ ...@@ -125,11 +153,11 @@ void BrookIntStreamImpl::loadFromArray( const void* array ){
* *
*/ */
void BrookIntStreamImpl::saveToArray( void* array ){ void BrookIntStreamInternal::saveToArray( void* array ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookIntStreamImpl::saveToArray"; // static const std::string methodName = "BrookIntStreamInternal::saveToArray";
// static const int debug = 1; // static const int debug = 1;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -137,7 +165,7 @@ void BrookIntStreamImpl::saveToArray( void* array ){ ...@@ -137,7 +165,7 @@ void BrookIntStreamImpl::saveToArray( void* array ){
int* arrayData = (int*) array; int* arrayData = (int*) array;
int index = 0; int index = 0;
for( int ii = 0; ii < getSize(); ii++ ){ for( int ii = 0; ii < getSize(); ii++ ){
for( int jj = 0; jj < width; jj++ ){ for( int jj = 0; jj < getWidth(); jj++ ){
arrayData[index++] = data[ii][jj]; arrayData[index++] = data[ii][jj];
} }
} }
...@@ -150,18 +178,18 @@ void BrookIntStreamImpl::saveToArray( void* array ){ ...@@ -150,18 +178,18 @@ void BrookIntStreamImpl::saveToArray( void* array ){
* *
*/ */
void BrookIntStreamImpl::fillWithValue( void* value ){ void BrookIntStreamInternal::fillWithValue( void* value ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookIntStreamImpl::fillWithValue"; // static const std::string methodName = "BrookIntStreamInternal::fillWithValue";
// static const int debug = 1; // static const int debug = 1;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
int valueData = *((int*) value); int valueData = *((int*) value);
for( int ii = 0; ii < getSize(); ii++ ){ for( int ii = 0; ii < getSize(); ii++ ){
for (int jj = 0; jj < width; jj++ ){ for (int jj = 0; jj < getWidth(); jj++ ){
data[ii][jj] = valueData; data[ii][jj] = valueData;
} }
} }
...@@ -174,7 +202,7 @@ void BrookIntStreamImpl::fillWithValue( void* value ){ ...@@ -174,7 +202,7 @@ void BrookIntStreamImpl::fillWithValue( void* value ){
* *
*/ */
const int* const * BrookIntStreamImpl::getData( void ) const { const int* const * BrookIntStreamInternal::getData( void ) const {
return data; return data;
} }
...@@ -185,7 +213,7 @@ const int* const * BrookIntStreamImpl::getData( void ) const { ...@@ -185,7 +213,7 @@ const int* const * BrookIntStreamImpl::getData( void ) const {
* *
*/ */
int** BrookIntStreamImpl::getData( void ){ int** BrookIntStreamInternal::getData( void ){
return data; return data;
} }
#ifndef OPENMM_BROOKINTSTREAMIMPL_H_ #ifndef OPENMM_BROOK_INT_STREAM_INTERNAL_H_
#define OPENMM_BROOKINTSTREAMIMPL_H_ #define OPENMM_BROOK_INT_STREAM_INTERNAL_H_
/* -------------------------------------------------------------------------- * /* -------------------------------------------------------------------------- *
* OpenMM * * OpenMM *
...@@ -32,24 +32,35 @@ ...@@ -32,24 +32,35 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * * USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "StreamImpl.h" #include "BrookStreamInternal.h"
#include "brook/brook.hpp" #include "brook/brook.hpp"
namespace OpenMM { namespace OpenMM {
/** /**
* Implementation of int streams for the Brook platform * Internalementation of int streams for the Brook platform
*/ */
class BrookIntStreamImpl : public StreamImpl { class BrookIntStreamInternal : public BrookStreamInternal {
public: public:
BrookIntStreamImpl( std::string name, int size, Stream::DataType type, const Platform& platform ); BrookIntStreamInternal( std::string name, int size, int streamWidth, BrookStreamInternal::DataType type, int dangleValue );
~BrookIntStreamImpl( ); ~BrookIntStreamInternal( );
void loadFromArray( const void* array ); void loadFromArray( const void* array );
/**
* Copy the contents of an array into this stream.
*
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct data type for this stream. If the stream has a compound data type, all
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*/
void loadFromArray( const void* array, BrookStreamInternal::DataType baseType );
void saveToArray( void* array ); void saveToArray( void* array );
void fillWithValue( void* value ); void fillWithValue( void* value );
const int* const * getData( void ) const; const int* const * getData( void ) const;
...@@ -57,11 +68,11 @@ public: ...@@ -57,11 +68,11 @@ public:
private: private:
int width; int _dangleValue;
Stream::DataType baseType;
int** data; int** data;
}; };
} // namespace OpenMM } // namespace OpenMM
#endif /*OPENMM_BROOKINTSTREAMIMPL_H_*/ #endif /* OPENMM_BROOK_INT_STREAM_INTERNAL_H_ */
/* -------------------------------------------------------------------------- *
* 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. *
* -------------------------------------------------------------------------- */
#include "BrookIntegrateKernals.h"
#include "BrookStreamInternal.h"
using namespace OpenMM;
using namespace std;
BrookIntegrateVerletStepKernel::BrookIntegrateVerletStepKernel( std::string name, const Platform& platform ) :
IntegrateVerletStepKernel( name, platform ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookIntegrateVerletStepKernel::BrookIntegrateVerletStepKernel";
// ---------------------------------------------------------------------------------------
}
BrookIntegrateVerletStepKernel::~BrookIntegrateVerletStepKernel( ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookIntegrateVerletStepKernel::~BrookIntegrateVerletStepKernel";
// ---------------------------------------------------------------------------------------
/*
if (dynamics)
delete dynamics;
if (shake)
delete shake;
if (masses)
delete[] masses;
if (constraintIndices)
disposeIntArray(constraintIndices, numConstraints);
if (shakeParameters)
disposeRealArray(shakeParameters, numConstraints);
*/
}
void BrookIntegrateVerletStepKernel::initialize( const vector<double>& masses,
const vector<vector<int> >& constraintIndices,
const vector<double>& constraintLengths ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookIntegrateVerletStepKernel::initialize";
// ---------------------------------------------------------------------------------------
/*
this->masses = new RealOpenMM[masses.size()];
for (size_t i = 0; i < masses.size(); ++i)
this->masses[i] = static_cast<RealOpenMM>( masses[i] );
numConstraints = constraintIndices.size();
this->constraintIndices = allocateIntArray(numConstraints, 2);
for (int i = 0; i < numConstraints; ++i) {
this->constraintIndices[i][0] = constraintIndices[i][0];
this->constraintIndices[i][1] = constraintIndices[i][1];
}
shakeParameters = allocateRealArray(constraintLengths.size(), 1);
for (size_t i = 0; i < constraintLengths.size(); ++i)
shakeParameters[i][0] = static_cast<RealOpenMM>( constraintLengths[i] );
*/
}
void BrookIntegrateVerletStepKernel::execute( Stream& positions, Stream& velocities,
const Stream& forces, double stepSize ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookIntegrateVerletStepKernel::execute";
// ---------------------------------------------------------------------------------------
/*
RealOpenMM** posData = ((BrookFloatStreamImpl&) positions.getImpl()).getData();
RealOpenMM** velData = ((BrookFloatStreamImpl&) velocities.getImpl()).getData();
RealOpenMM** forceData = const_cast<RealOpenMM**>(((BrookFloatStreamImpl&) forces.getImpl()).getData()); // Brook code needs to be made const correct
if (dynamics == 0 || stepSize != prevStepSize) {
// Recreate the computation objects with the new parameters.
if (dynamics) {
delete dynamics;
delete shake;
}
dynamics = new BrookVerletDynamics(positions.getSize(), static_cast<RealOpenMM>(stepSize) );
shake = new BrookShakeAlgorithm(numConstraints, constraintIndices, shakeParameters);
dynamics->setBrookShakeAlgorithm(shake);
prevStepSize = stepSize;
}
dynamics->update(positions.getSize(), posData, velData, forceData, masses);
*/
}
#ifndef OPENMM_BROOK_INTEGRATE_KERNELS_H_
#define OPENMM_BROOK_INTEGRATE_KERNELS_H_
/* -------------------------------------------------------------------------- *
* 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, Mark Friedrichs *
* 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. *
* -------------------------------------------------------------------------- */
#include "kernels.h"
namespace OpenMM {
/**
* This is the base class of Float and Double streams in the Brook Platform.
*/
class BrookIntegrateVerletStepKernel : public IntegrateVerletStepKernel {
public:
/**
* BrookIntegrateVerletStepKernel constructor
*
* @param name name of the stream to create
* @param platform platform
*
*/
BrookIntegrateVerletStepKernel( std::string name, const Platform& platform );
/**
* BrookIntegrateVerletStepKernel destructor
*
*/
~BrookIntegrateVerletStepKernel();
/**
* Initialize the kernel, setting up all parameters related to integrator.
*
* @param masses the mass of each atom
* @param constraintIndices each element contains the indices of two atoms whose distance should be constrained
* @param constraintLengths the required distance between each pair of constrained atoms
*
*/
void initialize( const std::vector<double>& masses, const std::vector<std::vector<int> >& constraintIndices,
const std::vector<double>& constraintLengths );
/**
* Execute the kernel.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom
* @param stepSize the integration step size
*
*/
void execute( Stream& positions, Stream& velocities, const Stream& forces, double stepSize );
protected:
int _width;
int _streamWidth;
int _streamHeight;
int _streamSize;
};
} // namespace OpenMM
#endif /* OPENMM_BROOK_INTEGRATE_KERNELS_H_ */
...@@ -30,27 +30,58 @@ ...@@ -30,27 +30,58 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "BrookKernelFactory.h" #include "BrookKernelFactory.h"
#include "BrookKernels.h" #include "BrookCalcStandardMMForceFieldKernel.h"
#include "BrookIntegrateKernals.h"
#include "BrookCalcKineticEnergyKernel.h"
using namespace OpenMM; using namespace OpenMM;
KernelImpl* BrookKernelFactory::createKernelImpl(std::string name, const Platform& platform, OpenMMContextImpl& context) const { KernelImpl* BrookKernelFactory::createKernelImpl( std::string name, const Platform& platform, OpenMMContextImpl& context ) const {
if (name == CalcStandardMMForceFieldKernel::Name())
(void) fprintf( stderr, "CalcStandardMMForceFieldKernel not set BrookKernelFactory::createKernelImpl\n" ); // ---------------------------------------------------------------------------------------
(void) fflush( stderr );
//return new BrookCalcStandardMMForceFieldKernel(name, platform); static const std::string methodName = "BrookKernelFactory::createKernelImpl";
if (name == CalcGBSAOBCForceFieldKernel::Name())
// ---------------------------------------------------------------------------------------
// StandardMM
if( name == CalcStandardMMForceFieldKernel::Name() ){
return new BrookCalcStandardMMForceFieldKernel( name, platform );
// GBSA OBC
} else if( name == CalcGBSAOBCForceFieldKernel::Name() ){
(void) fprintf( stderr, "CalcGBSAOBCForceFieldKernel not set BrookKernelFactory::createKernelImpl\n" ); (void) fprintf( stderr, "CalcGBSAOBCForceFieldKernel not set BrookKernelFactory::createKernelImpl\n" );
(void) fflush( stderr ); (void) fflush( stderr );
//return new BrookCalcGBSAOBCForceFieldKernel(name, platform); //return new BrookCalcGBSAOBCForceFieldKernel(name, platform);
if (name == IntegrateVerletStepKernel::Name())
return new BrookIntegrateVerletStepKernel(name, platform); // Verlet integrator
} else if( name == IntegrateVerletStepKernel::Name() ){
(void) fprintf( stderr, "IntegrateVerletStepKernel created BrookKernelFactory::createKernelImpl\n" );
(void) fflush( stderr );
return new BrookIntegrateVerletStepKernel( name, platform );
// KE calculator
} else if( name == CalcKineticEnergyKernel::Name() ){
return new BrookCalcKineticEnergyKernel( name, platform );
}
(void) fprintf( stderr, "createKernelImpl: name=<%s> not found.", methodName.c_str(), name.c_str() );
(void) fflush( stderr );
/*
if (name == IntegrateLangevinStepKernel::Name()) if (name == IntegrateLangevinStepKernel::Name())
return new BrookIntegrateLangevinStepKernel(name, platform); //return new BrookIntegrateLangevinStepKernel(name, platform);
if (name == IntegrateBrownianStepKernel::Name()) //if (name == IntegrateBrownianStepKernel::Name())
return new BrookIntegrateBrownianStepKernel(name, platform); //return new BrookIntegrateBrownianStepKernel(name, platform);
if (name == ApplyAndersenThermostatKernel::Name()) if (name == ApplyAndersenThermostatKernel::Name())
return new BrookApplyAndersenThermostatKernel(name, platform); //return new BrookApplyAndersenThermostatKernel(name, platform);
if (name == CalcKineticEnergyKernel::Name()) */
return new BrookCalcKineticEnergyKernel(name, platform); return NULL;
} }
/* -------------------------------------------------------------------------- *
* 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, Mark Friedrichs *
* 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. *
* -------------------------------------------------------------------------- */
#include "BrookKernels.h"
#include "BrookFloatStreamImpl.h"
/*
#include "SimTKBrook/BrookAngleBondIxn.h"
#include "SimTKBrook/BrookBondForce.h"
#include "SimTKBrook/BrookHarmonicBondIxn.h"
#include "SimTKBrook/BrookLJCoulomb14.h"
#include "SimTKBrook/BrookLJCoulombIxn.h"
#include "SimTKBrook/BrookProperDihedralBond.h"
#include "SimTKBrook/BrookRbDihedralBond.h"
#include "SimTKBrook/BrookStochasticDynamics.h"
#include "SimTKBrook/BrookShakeAlgorithm.h"
*/
#include <cmath>
#include <limits>
using namespace OpenMM;
using namespace std;
/*
int** allocateIntArray(int length, int width) {
int** array = new int*[length];
for (int i = 0; i < length; ++i)
array[i] = new int[width];
return array;
}
RealOpenMM** allocateRealArray(int length, int width) {
RealOpenMM** array = new RealOpenMM*[length];
for (int i = 0; i < length; ++i)
array[i] = new RealOpenMM[width];
return array;
}
int** copyToArray(const vector<vector<int> > vec) {
if (vec.size() == 0)
return new int*[0];
int** array = allocateIntArray(vec.size(), vec[0].size());
for (int i = 0; i < vec.size(); ++i)
for (int j = 0; j < vec[i].size(); ++j)
array[i][j] = vec[i][j];
return array;
}
RealOpenMM** copyToArray(const vector<vector<double> > vec) {
if (vec.size() == 0)
return new RealOpenMM*[0];
RealOpenMM** array = allocateRealArray(vec.size(), vec[0].size());
for (int i = 0; i < vec.size(); ++i)
for (int j = 0; j < vec[i].size(); ++j)
array[i][j] = vec[i][j];
return array;
}
void disposeIntArray(int** array, int size) {
if (array) {
for (int i = 0; i < size; ++i)
delete[] array[i];
delete[] array;
}
}
void disposeRealArray(RealOpenMM** array, int size) {
if (array) {
for (int i = 0; i < size; ++i)
delete[] array[i];
delete[] array;
}
}
*/
BrookCalcStandardMMForceFieldKernel::~BrookCalcStandardMMForceFieldKernel() {
/*
disposeIntArray(bondIndexArray, numBonds);
disposeRealArray(bondParamArray, numBonds);
disposeIntArray(angleIndexArray, numAngles);
disposeRealArray(angleParamArray, numAngles);
disposeIntArray(periodicTorsionIndexArray, numPeriodicTorsions);
disposeRealArray(periodicTorsionParamArray, numPeriodicTorsions);
disposeIntArray(rbTorsionIndexArray, numRBTorsions);
disposeRealArray(rbTorsionParamArray, numRBTorsions);
disposeRealArray(atomParamArray, numAtoms);
disposeIntArray(exclusionArray, numAtoms);
disposeIntArray(bonded14IndexArray, num14);
disposeRealArray(bonded14ParamArray, num14);
*/
}
void BrookCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >& bondIndices, const vector<vector<double> >& bondParameters,
const vector<vector<int> >& angleIndices, const vector<vector<double> >& angleParameters,
const vector<vector<int> >& periodicTorsionIndices, const vector<vector<double> >& periodicTorsionParameters,
const vector<vector<int> >& rbTorsionIndices, const vector<vector<double> >& rbTorsionParameters,
const vector<vector<int> >& bonded14Indices, double lj14Scale, double coulomb14Scale,
const vector<set<int> >& exclusions, const vector<vector<double> >& nonbondedParameters) {
/*
numAtoms = nonbondedParameters.size();
numBonds = bondIndices.size();
numAngles = angleIndices.size();
numPeriodicTorsions = periodicTorsionIndices.size();
numRBTorsions = rbTorsionIndices.size();
num14 = bonded14Indices.size();
bondIndexArray = copyToArray(bondIndices);
bondParamArray = copyToArray(bondParameters);
angleIndexArray = copyToArray(angleIndices);
angleParamArray = copyToArray(angleParameters);
periodicTorsionIndexArray = copyToArray(periodicTorsionIndices);
periodicTorsionParamArray = copyToArray(periodicTorsionParameters);
rbTorsionIndexArray = copyToArray(rbTorsionIndices);
rbTorsionParamArray = copyToArray(rbTorsionParameters);
atomParamArray = allocateRealArray(numAtoms, 3);
RealOpenMM sqrtEps = std::sqrt(138.935485);
for (int i = 0; i < numAtoms; ++i) {
atomParamArray[i][0] = 0.5*nonbondedParameters[i][1];
atomParamArray[i][1] = 2.0*sqrt(nonbondedParameters[i][2]);
atomParamArray[i][2] = nonbondedParameters[i][0]*sqrtEps;
}
exclusionArray = new int*[numAtoms];
for (int i = 0; i < numAtoms; ++i) {
exclusionArray[i] = new int[exclusions[i].size()+1];
exclusionArray[i][0] = exclusions[i].size();
int index = 0;
for (set<int>::const_iterator iter = exclusions[i].begin(); iter != exclusions[i].end(); ++iter)
exclusionArray[i][++index] = *iter;
}
bonded14IndexArray = copyToArray(bonded14Indices);
bonded14ParamArray = allocateRealArray(num14, 3);
for (int i = 0; i < num14; ++i) {
int atom1 = bonded14Indices[i][0];
int atom2 = bonded14Indices[i][1];
bonded14ParamArray[i][0] = atomParamArray[atom1][0]+atomParamArray[atom2][0];
bonded14ParamArray[i][1] = lj14Scale*(atomParamArray[atom1][1]*atomParamArray[atom2][1]);
bonded14ParamArray[i][2] = coulomb14Scale*(atomParamArray[atom1][2]*atomParamArray[atom2][2]);
}
*/
}
void BrookCalcStandardMMForceFieldKernel::executeForces(const Stream& positions, Stream& forces) {
/*
RealOpenMM** posData = const_cast<RealOpenMM**>(((BrookFloatStreamImpl&) positions.getImpl()).getData()); // Brook code needs to be made const correct
RealOpenMM** forceData = ((BrookFloatStreamImpl&) forces.getImpl()).getData();
BrookBondForce refBondForce;
BrookHarmonicBondIxn harmonicBond;
refBondForce.calculateForce(numBonds, bondIndexArray, posData, bondParamArray, forceData, 0, 0, 0, harmonicBond);
BrookAngleBondIxn angleBond;
refBondForce.calculateForce(numAngles, angleIndexArray, posData, angleParamArray, forceData, 0, 0, 0, angleBond);
BrookProperDihedralBond periodicTorsionBond;
refBondForce.calculateForce(numPeriodicTorsions, periodicTorsionIndexArray, posData, periodicTorsionParamArray, forceData, 0, 0, 0, periodicTorsionBond);
BrookRbDihedralBond rbTorsionBond;
refBondForce.calculateForce(numRBTorsions, rbTorsionIndexArray, posData, rbTorsionParamArray, forceData, 0, 0, 0, rbTorsionBond);
BrookLJCoulombIxn clj;
clj.calculatePairIxn(numAtoms, posData, atomParamArray, exclusionArray, 0, forceData, 0, 0);
BrookLJCoulomb14 nonbonded14;
refBondForce.calculateForce(num14, bonded14IndexArray, posData, bonded14ParamArray, forceData, 0, 0, 0, nonbonded14);
*/
}
double BrookCalcStandardMMForceFieldKernel::executeEnergy(const Stream& positions) {
RealOpenMM energy = 0;
/*
RealOpenMM** posData = const_cast<RealOpenMM**>(((BrookFloatStreamImpl&) positions.getImpl()).getData()); // Brook code needs to be made const correct
RealOpenMM** forceData = allocateRealArray(numAtoms, 3);
int arraySize = max(max(max(max(numAtoms, numBonds), numAngles), numPeriodicTorsions), numRBTorsions);
RealOpenMM* energyArray = new RealOpenMM[arraySize];
BrookBondForce refBondForce;
BrookHarmonicBondIxn harmonicBond;
for (int i = 0; i < arraySize; ++i)
energyArray[i] = 0;
refBondForce.calculateForce(numBonds, bondIndexArray, posData, bondParamArray, forceData, energyArray, 0, &energy, harmonicBond);
BrookAngleBondIxn angleBond;
for (int i = 0; i < arraySize; ++i)
energyArray[i] = 0;
refBondForce.calculateForce(numAngles, angleIndexArray, posData, angleParamArray, forceData, energyArray, 0, &energy, angleBond);
BrookProperDihedralBond periodicTorsionBond;
for (int i = 0; i < arraySize; ++i)
energyArray[i] = 0;
refBondForce.calculateForce(numPeriodicTorsions, periodicTorsionIndexArray, posData, periodicTorsionParamArray, forceData, energyArray, 0, &energy, periodicTorsionBond);
BrookRbDihedralBond rbTorsionBond;
for (int i = 0; i < arraySize; ++i)
energyArray[i] = 0;
refBondForce.calculateForce(numRBTorsions, rbTorsionIndexArray, posData, rbTorsionParamArray, forceData, energyArray, 0, &energy, rbTorsionBond);
BrookLJCoulombIxn clj;
clj.calculatePairIxn(numAtoms, posData, atomParamArray, exclusionArray, 0, forceData, 0, &energy);
BrookLJCoulomb14 nonbonded14;
for (int i = 0; i < arraySize; ++i)
energyArray[i] = 0;
refBondForce.calculateForce(num14, bonded14IndexArray, posData, bonded14ParamArray, forceData, energyArray, 0, &energy, nonbonded14);
disposeRealArray(forceData, numAtoms);
delete[] energyArray;
*/
return energy;
}
void BrookCalcGBSAOBCForceFieldKernel::initialize(const vector<double>& bornRadii, const vector<vector<double> >& atomParameters,
double solventDielectric, double soluteDielectric) {
}
void BrookCalcGBSAOBCForceFieldKernel::executeForces(const Stream& positions, Stream& forces) {
}
double BrookCalcGBSAOBCForceFieldKernel::executeEnergy(const Stream& positions) {
return 0.0; // TODO implement correctly
}
void BrookIntegrateVerletStepKernel::initialize(const vector<double>& masses, const vector<vector<int> >& constraintIndices,
const vector<double>& constraintLengths) {
}
void BrookIntegrateVerletStepKernel::execute(Stream& positions, Stream& velocities, const Stream& forces, double stepSize) {
}
#include <iostream>
BrookIntegrateLangevinStepKernel::~BrookIntegrateLangevinStepKernel() {
/*
if (dynamics)
delete dynamics;
if (shake)
delete shake;
if (masses)
delete[] masses;
if (constraintIndices)
disposeIntArray(constraintIndices, numConstraints);
if (shakeParameters)
disposeRealArray(shakeParameters, numConstraints);
*/
}
void BrookIntegrateLangevinStepKernel::initialize(const vector<double>& masses, const vector<vector<int> >& constraintIndices,
const vector<double>& constraintLengths) {
/*
this->masses = new RealOpenMM[masses.size()];
for (int i = 0; i < masses.size(); ++i)
this->masses[i] = masses[i];
numConstraints = constraintIndices.size();
this->constraintIndices = allocateIntArray(numConstraints, 2);
for (int i = 0; i < numConstraints; ++i) {
this->constraintIndices[i][0] = constraintIndices[i][0];
this->constraintIndices[i][1] = constraintIndices[i][1];
}
shakeParameters = allocateRealArray(constraintLengths.size(), 1);
for (int i = 0; i < constraintLengths.size(); ++i)
shakeParameters[i][0] = constraintLengths[i];
*/
}
void BrookIntegrateLangevinStepKernel::execute(Stream& positions, Stream& velocities, const Stream& forces, double temperature, double friction, double stepSize) {
/*
RealOpenMM** posData = ((BrookFloatStreamImpl&) positions.getImpl()).getData();
RealOpenMM** velData = ((BrookFloatStreamImpl&) velocities.getImpl()).getData();
RealOpenMM** forceData = const_cast<RealOpenMM**>(((BrookFloatStreamImpl&) forces.getImpl()).getData()); // Brook code needs to be made const correct
if (dynamics == 0 || temperature != prevTemp || friction != prevFriction || stepSize != prevStepSize) {
// Recreate the computation objects with the new parameters.
if (dynamics) {
delete dynamics;
delete shake;
}
RealOpenMM tau = (friction == 0.0 ? 0.0 : 1.0/friction);
dynamics = new BrookStochasticDynamics(positions.getSize(), stepSize, tau, temperature);
shake = new BrookShakeAlgorithm(numConstraints, constraintIndices, shakeParameters);
dynamics->setBrookShakeAlgorithm(shake);
prevTemp = temperature;
prevFriction = friction;
prevStepSize = stepSize;
}
dynamics->update(positions.getSize(), posData, velData, forceData, masses);
*/
}
void BrookIntegrateBrownianStepKernel::initialize(const vector<double>& masses, const vector<vector<int> >& constraintIndices,
const vector<double>& constraintLengths) {
}
void BrookIntegrateBrownianStepKernel::execute(Stream& positions, Stream& velocities, const Stream& forces, double temperature, double friction, double stepSize) {
}
void BrookApplyAndersenThermostatKernel::initialize(const vector<double>& masses) {
}
void BrookApplyAndersenThermostatKernel::execute(Stream& velocities, double temperature, double collisionFrequency, double stepSize) {
}
void BrookCalcKineticEnergyKernel::initialize(const vector<double>& masses) {
this->masses = masses;
}
double BrookCalcKineticEnergyKernel::execute(const Stream& velocities) {
double energy = 0.0;
/*
RealOpenMM** velData = const_cast<RealOpenMM**>(((BrookFloatStreamImpl&) velocities.getImpl()).getData()); // Brook code needs to be made const correct
for (int i = 0; i < masses.size(); ++i)
energy += masses[i]*(velData[i][0]*velData[i][0]+velData[i][1]*velData[i][1]+velData[i][2]*velData[i][2]);
*/
return 0.5*energy;
}
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