"wrappers/vscode:/vscode.git/clone" did not exist on "a468fa3a31c83b6262e8be29b842662734fee98c"
Commit 40610876 authored by Mark Friedrichs's avatar Mark Friedrichs
Browse files

Mods

parent 309008f7
...@@ -59,19 +59,8 @@ BrookBondParameters::BrookBondParameters( std::string bondName, int numberOfPart ...@@ -59,19 +59,8 @@ BrookBondParameters::BrookBondParameters( std::string bondName, int numberOfPart
// allocate memory for particle indices/parameters // allocate memory for particle indices/parameters
int* particleIndicesBlock = new int[numberOfParticlesInBond*numberOfBonds]; _bondParameters.resize( numberOfBonds );
double* parametersBlock = new double[numberOfParametersInBond*numberOfBonds]; _particleIndices.resize( numberOfBonds );
_particleIndices = new int*[numberOfBonds];
_bondParameters = new double*[numberOfBonds];
for( int ii = 0; ii < numberOfBonds; ii++ ){
_particleIndices[ii] = particleIndicesBlock;
particleIndicesBlock += numberOfParticlesInBond;
_bondParameters[ii] = parametersBlock;
parametersBlock += numberOfParametersInBond;
}
} }
...@@ -88,12 +77,28 @@ BrookBondParameters::~BrookBondParameters( ){ ...@@ -88,12 +77,28 @@ BrookBondParameters::~BrookBondParameters( ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
delete[] _particleIndices[0]; }
delete[] _particleIndices;
delete[] _bondParameters[0]; /**
delete[] _bondParameters; * Get particle indices
*
* @return particle indices
*
*/
const std::vector<std::vector<int>>& BrookBondParameters::getParticleIndices( void ) const {
return _particleIndices;
}
/**
* Get bond parameters
*
* @return parameters
*
*/
const std::vector<std::vector<double>>& BrookBondParameters::getBondParameters( void ) const {
return _bondParameters;
} }
/** /**
...@@ -107,6 +112,17 @@ FILE* BrookBondParameters::getLog( void ) const { ...@@ -107,6 +112,17 @@ FILE* BrookBondParameters::getLog( void ) const {
return _log; return _log;
} }
/**
* Get bond name
*
* @return bond name
*
*/
std::string BrookBondParameters::getBondName( void ) const {
return _bondName;
}
/** /**
* Set log file reference * Set log file reference
* *
...@@ -196,13 +212,21 @@ int BrookBondParameters::setBond( int bondIndex, int* particleIndices, double* b ...@@ -196,13 +212,21 @@ int BrookBondParameters::setBond( int bondIndex, int* particleIndices, double* b
// load'em up // load'em up
int numberOfParticlesInBond = getNumberOfParticlesInBond(); int numberOfParticlesInBond = getNumberOfParticlesInBond();
std::vector<int> indices;
_particleIndices[bondIndex] = indices;
indices.resize( numberOfParticlesInBond );
for( int ii = 0; ii < numberOfParticlesInBond; ii++ ){ for( int ii = 0; ii < numberOfParticlesInBond; ii++ ){
_particleIndices[bondIndex][ii] = particleIndices[ii]; indices[ii] = particleIndices[ii];
} }
int numberOfParametersInBond = getNumberOfParametersInBond(); int numberOfParametersInBond = getNumberOfParametersInBond();
std::vector<double> parameters;
_bondParameters[bondIndex] = parameters;
parameters.resize( numberOfParametersInBond );
for( int ii = 0; ii < numberOfParametersInBond; ii++ ){ for( int ii = 0; ii < numberOfParametersInBond; ii++ ){
_bondParameters[bondIndex][ii] = bondParameters[ii]; parameters[ii] = bondParameters[ii];
} }
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -281,7 +305,7 @@ std::string BrookBondParameters::getContentsString( int level ) const { ...@@ -281,7 +305,7 @@ std::string BrookBondParameters::getContentsString( int level ) const {
#define LOCAL_2_SPRINTF(a,b,c,d) sprintf( (a), (b), (c), (d) ); #define LOCAL_2_SPRINTF(a,b,c,d) sprintf( (a), (b), (c), (d) );
#endif #endif
(void) LOCAL_SPRINTF( value, "%s", getBondName() ); (void) LOCAL_SPRINTF( value, "%s", getBondName().c_str() );
message << _getLine( tab, "Bond name:", value ); message << _getLine( tab, "Bond name:", value );
(void) LOCAL_SPRINTF( value, "%d", getNumberOfBonds() ); (void) LOCAL_SPRINTF( value, "%d", getNumberOfBonds() );
...@@ -295,12 +319,28 @@ std::string BrookBondParameters::getContentsString( int level ) const { ...@@ -295,12 +319,28 @@ std::string BrookBondParameters::getContentsString( int level ) const {
message << "Bonds:" << std::endl; message << "Bonds:" << std::endl;
for( int ii = 0; ii < getNumberOfBonds(); ii++ ){ for( int ii = 0; ii < getNumberOfBonds(); ii++ ){
const static size_t descriptionSz = 256;
char description[256]; char description[256];
char buffer[256]; char buffer[256];
(void) LOCAL_SPRINTF( description, "%6d [", ii ); (void) LOCAL_SPRINTF( description, "%6d [", ii );
// particle indices // particle indices
#ifdef WIN32
for( int jj = 0; jj < getNumberOfParticlesInBond(); jj++ ){
(void) LOCAL_SPRINTF( buffer, "%6d ", _particleIndices[ii][jj] );
(void) strcat_s( description, descriptionSz, buffer );
}
(void) strcat_s( description, descriptionSz, "] [" );
// parameters
for( int jj = 0; jj < getNumberOfParametersInBond(); jj++ ){
(void) LOCAL_SPRINTF( buffer, "%18.10e ", _bondParameters[ii][jj] );
(void) strcat_s( description, descriptionSz, buffer );
}
(void) strcat_s( description, descriptionSz, "]" );
#else
for( int jj = 0; jj < getNumberOfParticlesInBond(); jj++ ){ for( int jj = 0; jj < getNumberOfParticlesInBond(); jj++ ){
(void) LOCAL_SPRINTF( buffer, "%6d ", _particleIndices[ii][jj] ); (void) LOCAL_SPRINTF( buffer, "%6d ", _particleIndices[ii][jj] );
(void) strcat( description, buffer ); (void) strcat( description, buffer );
...@@ -314,6 +354,7 @@ std::string BrookBondParameters::getContentsString( int level ) const { ...@@ -314,6 +354,7 @@ std::string BrookBondParameters::getContentsString( int level ) const {
(void) strcat( description, buffer ); (void) strcat( description, buffer );
} }
(void) strcat( description, "]" ); (void) strcat( description, "]" );
#endif
message << _getLine( tab, "", description ); message << _getLine( tab, "", description );
} }
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * * USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include <vector>
namespace OpenMM { namespace OpenMM {
/** /**
...@@ -143,6 +145,24 @@ class BrookBondParameters { ...@@ -143,6 +145,24 @@ class BrookBondParameters {
int getNumberOfBonds( void ) const; int getNumberOfBonds( void ) const;
/**
* Get particle indices
*
* @return particle indices
*
*/
const std::vector<std::vector<int>>& getParticleIndices( void ) const;
/**
* Get parameters
*
* @return parameters
*
*/
const std::vector<std::vector<double>>& getBondParameters( void ) const;
/* /*
* Get contents of object * Get contents of object
* *
...@@ -173,8 +193,8 @@ class BrookBondParameters { ...@@ -173,8 +193,8 @@ class BrookBondParameters {
// particle indices and parameters // particle indices and parameters
int** _particleIndices; std::vector<std::vector<int>> _particleIndices;
double** _bondParameters; std::vector<std::vector<double>> _bondParameters;
/* /*
* Get contents of object * Get contents of object
......
...@@ -59,6 +59,7 @@ BrookBonded::BrookBonded( ){ ...@@ -59,6 +59,7 @@ BrookBonded::BrookBonded( ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
_setupCompleted = 0;
_numberOfParticles = 0; _numberOfParticles = 0;
_ljScale = (BrookOpenMMFloat) 0.83333333; _ljScale = (BrookOpenMMFloat) 0.83333333;
//_coulombFactor = 332.0; //_coulombFactor = 332.0;
...@@ -225,6 +226,16 @@ int BrookBonded::isForceStreamSet( int index ) const { ...@@ -225,6 +226,16 @@ int BrookBonded::isForceStreamSet( int index ) const {
return (index >= 0 && index < getNumberOfForceStreams() && _bondedForceStreams[index]) ? 1 : 0; return (index >= 0 && index < getNumberOfForceStreams() && _bondedForceStreams[index]) ? 1 : 0;
} }
/**
* Return SetupCompleted flag
*
* @return SetupCompleted flag
*/
int BrookBonded::isSetupCompleted( void ) const {
return _setupCompleted;
}
/** /**
* Return string showing if all inverse map streams are set * Return string showing if all inverse map streams are set
* *
...@@ -1052,7 +1063,7 @@ int BrookBonded::addPairs( int *nbondeds, int *particles, BrookOpenMMFloat* para ...@@ -1052,7 +1063,7 @@ int BrookBonded::addPairs( int *nbondeds, int *particles, BrookOpenMMFloat* para
* *
*/ */
int BrookBonded::loadInvMaps( int nbondeds, int nparticles, int *particles, const BrookPlatform& brookPlatform ){ int BrookBonded::loadInvMaps( int nbondeds, int nparticles, int *particles, int particleStreamWidth, int particleStreamSize ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -1064,9 +1075,11 @@ int BrookBonded::loadInvMaps( int nbondeds, int nparticles, int *particles, cons ...@@ -1064,9 +1075,11 @@ int BrookBonded::loadInvMaps( int nbondeds, int nparticles, int *particles, cons
// get particle stream size // get particle stream size
/*
const BrookStreamFactory& brookStreamFactory = dynamic_cast<const BrookStreamFactory&> (brookPlatform.getDefaultStreamFactory() ); const BrookStreamFactory& brookStreamFactory = dynamic_cast<const BrookStreamFactory&> (brookPlatform.getDefaultStreamFactory() );
int particleStreamWidth = brookStreamFactory.getDefaultParticleStreamWidth(); int particleStreamWidth = brookStreamFactory.getDefaultParticleStreamWidth();
int particleStreamSize = brookPlatform.getStreamSize( getNumberOfParticles(), particleStreamWidth, NULL ); int particleStreamSize = brookPlatform.getStreamSize( getNumberOfParticles(), particleStreamWidth, NULL );
*/
_inverseMapStreamWidth = particleStreamWidth; _inverseMapStreamWidth = particleStreamWidth;
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -1194,12 +1207,12 @@ int BrookBonded::loadInvMaps( int nbondeds, int nparticles, int *particles, cons ...@@ -1194,12 +1207,12 @@ int BrookBonded::loadInvMaps( int nbondeds, int nparticles, int *particles, cons
* */ * */
int BrookBonded::setup( int numberOfParticles, int BrookBonded::setup( int numberOfParticles,
const vector<vector<int> >& bondIndices, const vector<vector<double> >& bondParameters, BrookBondParameters* harmonicBondBrookBondParameters,
const vector<vector<int> >& angleIndices, const vector<vector<double> >& angleParameters, BrookBondParameters* harmonicAngleBrookBondParameters,
const vector<vector<int> >& periodicTorsionIndices, const vector<vector<double> >& periodicTorsionParameters, BrookBondParameters* periodicTorsionBrookBondParameters,
const vector<vector<int> >& rbTorsionIndices, const vector<vector<double> >& rbTorsionParameters, BrookBondParameters* rbTorsionBrookBondParameters,
const vector<vector<int> >& bonded14Indices, const vector<vector<double> >& nonbondedParameters, BrookBondParameters* nonBonded14ForceParameters,
double lj14Scale, double coulombScale, const Platform& platform ){ double lj14Scale, double coulombScale, int particleStreamWidth, int particleStreamSize ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -1211,55 +1224,8 @@ int BrookBonded::setup( int numberOfParticles, ...@@ -1211,55 +1224,8 @@ int BrookBonded::setup( int numberOfParticles,
_numberOfParticles = numberOfParticles; _numberOfParticles = numberOfParticles;
const BrookPlatform& brookPlatform = dynamic_cast<const BrookPlatform&> (platform);
// check that particle indices & parameters agree // check that particle indices & parameters agree
if( bondIndices.size() != bondParameters.size() ){
std::stringstream message;
message << methodName << " number of harmonic bond particle indices=" << bondIndices.size() << " does not equal number of harmonic bond parameter entries=" << bondParameters.size();
throw OpenMMException( message.str() );
} else if( PrintOn && getLog() ){
(void) fprintf( getLog(), "%s harmonic bonds=%d\n", methodName.c_str(), bondIndices.size() );
(void) fflush( getLog() );
}
if( angleIndices.size() != angleParameters.size() ){
std::stringstream message;
message << methodName << " number of angle particle indices=" << angleIndices.size() << " does not equal number of angle parameter entries=" << angleParameters.size();
throw OpenMMException( message.str() );
} else if( PrintOn && getLog() ){
(void) fprintf( getLog(), "%s angle bonds=%d\n", methodName.c_str(), angleIndices.size() );
(void) fflush( getLog() );
}
if( periodicTorsionIndices.size() != periodicTorsionParameters.size() ){
std::stringstream message;
message << methodName << " number of periodicTorsion particle indices=" << periodicTorsionIndices.size() << " does not equal number of periodicTorsion parameter entries=" << periodicTorsionParameters.size();
throw OpenMMException( message.str() );
} else if( PrintOn && getLog() ){
(void) fprintf( getLog(), "%s periodicTorsion bonds=%d\n", methodName.c_str(), periodicTorsionIndices.size() );
(void) fflush( getLog() );
}
if( rbTorsionIndices.size() != rbTorsionParameters.size() ){
std::stringstream message;
message << methodName << " number of rbTorsion particle indices=" << rbTorsionIndices.size() << " does not equal number of rbTorsion parameter entries=" << rbTorsionParameters.size();
throw OpenMMException( message.str() );
} else if( PrintOn && getLog() ){
(void) fprintf( getLog(), "%s rbTorsion bonds=%d\n", methodName.c_str(), rbTorsionIndices.size() );
(void) fflush( getLog() );
}
if( (numberOfParticles != (int) nonbondedParameters.size()) && bonded14Indices.size() > 0 ){
std::stringstream message;
message << methodName << " number particles=" << numberOfParticles << " does not equal number of nb parameter entries=" << nonbondedParameters.size();
throw OpenMMException( message.str() );
} else if( PrintOn && getLog() ){
(void) fprintf( getLog(), "%s LJ 14 ixns=%d\n", methodName.c_str(), bonded14Indices.size() );
(void) fflush( getLog() );
}
// allocate temp memory // allocate temp memory
int maxBonds = 10*numberOfParticles; int maxBonds = 10*numberOfParticles;
...@@ -1274,8 +1240,8 @@ int BrookBonded::setup( int numberOfParticles, ...@@ -1274,8 +1240,8 @@ int BrookBonded::setup( int numberOfParticles,
// build streams // build streams
const BrookStreamFactory& brookStreamFactory = dynamic_cast<const BrookStreamFactory&> (brookPlatform.getDefaultStreamFactory() ); // const BrookStreamFactory& brookStreamFactory = dynamic_cast<const BrookStreamFactory&> (brookPlatform.getDefaultStreamFactory() );
int particleStreamWidth = brookStreamFactory.getDefaultParticleStreamWidth(); // int particleStreamWidth = brookStreamFactory.getDefaultParticleStreamWidth();
// Initialize all particle indices to -1 to indicate empty slots // Initialize all particle indices to -1 to indicate empty slots
// All parameters must be initialized to values that will // All parameters must be initialized to values that will
...@@ -1300,11 +1266,13 @@ int BrookBonded::setup( int numberOfParticles, ...@@ -1300,11 +1266,13 @@ int BrookBonded::setup( int numberOfParticles,
} }
// nbondeds tracks number of ixn // nbondeds tracks number of ixn
int nbondeds = 0; int nbondeds = 0;
addRBDihedrals( &nbondeds, particles, params, rbTorsionIndices, rbTorsionParameters );
addPDihedrals ( &nbondeds, particles, params, periodicTorsionIndices, periodicTorsionParameters ); addRBDihedrals( &nbondeds, particles, params, rbTorsionBrookBondParameters->getParticleIndices(), rbTorsionBrookBondParameters->getBondParameters() );
addAngles( &nbondeds, particles, params, angleIndices, angleParameters ); addPDihedrals ( &nbondeds, particles, params, periodicTorsionBrookBondParameters->getParticleIndices(), periodicTorsionBrookBondParameters->getBondParameters() );
addBonds( &nbondeds, particles, params, bondIndices, bondParameters ); addAngles( &nbondeds, particles, params, harmonicAngleBrookBondParameters->getParticleIndices(), harmonicAngleBrookBondParameters->getBondParameters() );
addBonds( &nbondeds, particles, params, harmonicBondBrookBondParameters->getParticleIndices(), harmonicBondBrookBondParameters->getBondParameters() );
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -1319,7 +1287,7 @@ int BrookBonded::setup( int numberOfParticles, ...@@ -1319,7 +1287,7 @@ int BrookBonded::setup( int numberOfParticles,
//(void) fprintf( getLog(), "%s Post addBonds particles=%d number of bonds=%d maxBonds=%d\n", methodName.c_str(), numberOfParticles, nbondeds, maxBonds ); //(void) fprintf( getLog(), "%s Post addBonds particles=%d number of bonds=%d maxBonds=%d\n", methodName.c_str(), numberOfParticles, nbondeds, maxBonds );
addPairs( &nbondeds, particles, params, charges, bonded14Indices, nonbondedParameters, lj14Scale, coulombScale ); addPairs( &nbondeds, particles, params, charges, nonBonded14ForceParameters->getParticleIndices(), nonBonded14ForceParameters->getBondParameters(), lj14Scale, coulombScale );
// check that number of bonds not too large for memory allocated // check that number of bonds not too large for memory allocated
...@@ -1412,7 +1380,7 @@ int BrookBonded::setup( int numberOfParticles, ...@@ -1412,7 +1380,7 @@ int BrookBonded::setup( int numberOfParticles,
// load inverse maps to streams // load inverse maps to streams
loadInvMaps( nbondeds, getNumberOfParticles(), particles, brookPlatform ); loadInvMaps( nbondeds, getNumberOfParticles(), particles, particleStreamWidth, particleStreamSize );
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -1438,6 +1406,8 @@ int BrookBonded::setup( int numberOfParticles, ...@@ -1438,6 +1406,8 @@ int BrookBonded::setup( int numberOfParticles,
BrookStreamInternal::Float3, dangleValue ); BrookStreamInternal::Float3, dangleValue );
} }
_setupCompleted = 1;
return DefaultReturnValue; return DefaultReturnValue;
} }
......
...@@ -35,9 +35,10 @@ ...@@ -35,9 +35,10 @@
#include <vector> #include <vector>
#include "BrookStreamImpl.h" #include "BrookStreamImpl.h"
#include "BrookPlatform.h" //#include "BrookPlatform.h"
#include "BrookCommon.h" #include "BrookCommon.h"
#include "OpenMMContext.h" #include "OpenMMContext.h"
#include "BrookBondParameters.h"
namespace OpenMM { namespace OpenMM {
...@@ -86,6 +87,7 @@ class BrookBonded : public BrookCommon { ...@@ -86,6 +87,7 @@ class BrookBonded : public BrookCommon {
* *
*/ */
/*
int setup( int numberOfParticles, int setup( int numberOfParticles,
const std::vector<std::vector<int> >& bondIndices, const std::vector<std::vector<double> >& bondParameters, 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> >& angleIndices, const std::vector<std::vector<double> >& angleParameters,
...@@ -93,6 +95,14 @@ class BrookBonded : public BrookCommon { ...@@ -93,6 +95,14 @@ class BrookBonded : public BrookCommon {
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 Platform& platform ); double lj14Scale, double coulomb14Scale, const Platform& platform );
*/
int setup( int numberOfParticles,
BrookBondParameters* harmonicBondBrookBondParameters,
BrookBondParameters* harmonicAngleBrookBondParameters,
BrookBondParameters* periodicTorsionBrookBondParameters,
BrookBondParameters* rbTorsionBrookBondParameters,
BrookBondParameters* nonBonded14ForceParameters, double lj14Scale, double coulombScale, int particleStreamWidth, int particleStreamSize );
/** /**
* Get inverse map stream width * Get inverse map stream width
...@@ -274,6 +284,13 @@ class BrookBonded : public BrookCommon { ...@@ -274,6 +284,13 @@ class BrookBonded : public BrookCommon {
void computeForces( BrookStreamImpl& positionStream, BrookStreamImpl& forceStream ); void computeForces( BrookStreamImpl& positionStream, BrookStreamImpl& forceStream );
/**
* Return SetupCompleted flag
*
* @return SetupCompleted flag
*/
int isSetupCompleted( void ) const;
private: private:
...@@ -283,6 +300,8 @@ class BrookBonded : public BrookCommon { ...@@ -283,6 +300,8 @@ class BrookBonded : public BrookCommon {
enum { StreamI, StreamJ, StreamK, StreamL, StreamMax }; enum { StreamI, StreamJ, StreamK, StreamL, StreamMax };
int _setupCompleted;
// inverse map stream width // inverse map stream width
int _inverseMapStreamWidth; int _inverseMapStreamWidth;
...@@ -412,7 +431,8 @@ class BrookBonded : public BrookCommon { ...@@ -412,7 +431,8 @@ class BrookBonded : public BrookCommon {
* *
*/ */
int loadInvMaps( int nbondeds, int nparticles, int *particles, const BrookPlatform& platform ); //int loadInvMaps( int nbondeds, int nparticles, int *particles, const BrookPlatform& platform );
int loadInvMaps( int nbondeds, int nparticles, int *particles, int particleStreamWidth, int particleStreamSize );
/** /**
* Validate inverse map count * Validate inverse map count
...@@ -479,7 +499,6 @@ class BrookBonded : public BrookCommon { ...@@ -479,7 +499,6 @@ class BrookBonded : public BrookCommon {
* */ * */
int gpuRepackInvMap_merged( int nparticles, int nmaps, int *counts, float4 *invmaps[], float4 *buf ); int gpuRepackInvMap_merged( int nparticles, int nmaps, int *counts, float4 *invmaps[], float4 *buf );
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -138,7 +138,7 @@ void BrookCalcHarmonicAngleForceKernel::initialize( const System& system, const ...@@ -138,7 +138,7 @@ void BrookCalcHarmonicAngleForceKernel::initialize( const System& system, const
if( _brookBondParameters ){ if( _brookBondParameters ){
delete _brookBondParameters; delete _brookBondParameters;
} }
_brookBondParameters = new BrookBondParameters( BondName, NumberOfParticlesInBond, NumberOfParametersInBond, numberOfBonds, getLog() ); _brookBondParameters = new BrookBondParameters( BrookCalcHarmonicAngleForceKernel::BondName, NumberOfParticlesInBond, NumberOfParametersInBond, numberOfBonds, getLog() );
for( int ii = 0; ii < numberOfBonds; ii++ ){ for( int ii = 0; ii < numberOfBonds; ii++ ){
......
...@@ -138,7 +138,7 @@ void BrookCalcHarmonicBondForceKernel::initialize( const System& system, const H ...@@ -138,7 +138,7 @@ void BrookCalcHarmonicBondForceKernel::initialize( const System& system, const H
if( _brookBondParameters ){ if( _brookBondParameters ){
delete _brookBondParameters; delete _brookBondParameters;
} }
_brookBondParameters = new BrookBondParameters( BondName, NumberOfParticlesInBond, NumberOfParametersInBond, numberOfBonds, getLog() ); _brookBondParameters = new BrookBondParameters( BrookCalcHarmonicBondForceKernel::BondName, NumberOfParticlesInBond, NumberOfParametersInBond, numberOfBonds, getLog() );
for( int ii = 0; ii < numberOfBonds; ii++ ){ for( int ii = 0; ii < numberOfBonds; ii++ ){
......
...@@ -42,11 +42,13 @@ using namespace std; ...@@ -42,11 +42,13 @@ using namespace std;
* *
* @param name name of the stream to create * @param name name of the stream to create
* @param platform platform * @param platform platform
* @param OpenMMBrookInterface OpenMM-Brook interface
* @param System System reference
* *
*/ */
BrookCalcKineticEnergyKernel::BrookCalcKineticEnergyKernel( std::string name, const Platform& platform ) : BrookCalcKineticEnergyKernel::BrookCalcKineticEnergyKernel( std::string name, const Platform& platform, OpenMMBrookInterface& openMMBrookInterface, System& system ) :
CalcKineticEnergyKernel( name, platform ){ CalcKineticEnergyKernel( name, platform ), _openMMBrookInterface( openMMBrookInterface ), _system( system ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -54,6 +56,7 @@ BrookCalcKineticEnergyKernel::BrookCalcKineticEnergyKernel( std::string name, co ...@@ -54,6 +56,7 @@ BrookCalcKineticEnergyKernel::BrookCalcKineticEnergyKernel( std::string name, co
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
_numberOfParticles = 0;
_masses = NULL; _masses = NULL;
} }
...@@ -77,11 +80,11 @@ BrookCalcKineticEnergyKernel::~BrookCalcKineticEnergyKernel( ){ ...@@ -77,11 +80,11 @@ BrookCalcKineticEnergyKernel::~BrookCalcKineticEnergyKernel( ){
/** /**
* Initialize the kernel * Initialize the kernel
* *
* @param masses mass of each particle * @param system System reference
* *
*/ */
void BrookCalcKineticEnergyKernel::initialize( const vector<double>& masses ){ void BrookCalcKineticEnergyKernel::initialize( const System& system ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -89,31 +92,33 @@ void BrookCalcKineticEnergyKernel::initialize( const vector<double>& masses ){ ...@@ -89,31 +92,33 @@ void BrookCalcKineticEnergyKernel::initialize( const vector<double>& masses ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// masses _numberOfParticles = system.getNumParticles();
// load masses
if( _masses ){ if( _masses ){
delete[] _masses; delete[] _masses;
} }
_masses = new BrookOpenMMFloat[masses.size()]; _masses = new BrookOpenMMFloat[_numberOfParticles];
for( unsigned int ii = 0; ii < masses.size(); ii++ ){ for( unsigned int ii = 0; ii < (unsigned int) _numberOfParticles; ii++ ){
_masses[ii] = static_cast<BrookOpenMMFloat> (masses[ii]); _masses[ii] = static_cast<BrookOpenMMFloat>(system.getParticleMass(ii));
} }
return; return;
} }
/** /**
* Execute kernel * Calculate kinetic energy
* *
* @param velocities stream of particle velocities * @param context OpenMMContextImpl reference
* *
* @return kinetic energy of the system * @return kinetic energy of the system
* *
*/ */
double BrookCalcKineticEnergyKernel::execute( const Stream& velocities ){ double BrookCalcKineticEnergyKernel::execute( OpenMMContextImpl& context ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -121,9 +126,7 @@ double BrookCalcKineticEnergyKernel::execute( const Stream& velocities ){ ...@@ -121,9 +126,7 @@ double BrookCalcKineticEnergyKernel::execute( const Stream& velocities ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
const BrookStreamImpl& velocityStreamC = dynamic_cast<const BrookStreamImpl&> (velocities.getImpl()); void* dataV = _openMMBrookInterface.getParticleVelocities()->getData( );
BrookStreamImpl& velocityStream = const_cast<BrookStreamImpl&> (velocityStreamC);
void* dataV = velocityStream.getData( );
float* velocity = (float*) dataV; float* velocity = (float*) dataV;
double energy = 0.0; double energy = 0.0;
...@@ -143,7 +146,7 @@ printf( " [%12.5e %12.5e %12.5e]\n", velocity[index], velocity[index+1], velocit ...@@ -143,7 +146,7 @@ printf( " [%12.5e %12.5e %12.5e]\n", velocity[index], velocity[index+1], velocit
index = 0; index = 0;
*/ */
for ( int ii = 0; ii < velocityStream.getSize(); ii++, index += 3 ){ for ( int ii = 0; ii < _numberOfParticles; ii++, index += 3 ){
energy += _masses[ii]*(velocity[index]*velocity[index] + velocity[index + 1]*velocity[index + 1] + velocity[index + 2]*velocity[index + 2]); energy += _masses[ii]*(velocity[index]*velocity[index] + velocity[index + 1]*velocity[index + 1] + velocity[index + 2]*velocity[index + 2]);
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "kernels.h" #include "kernels.h"
#include "BrookFloatStreamInternal.h" #include "BrookFloatStreamInternal.h"
#include "OpenMMBrookInterface.h"
namespace OpenMM { namespace OpenMM {
...@@ -50,10 +51,11 @@ class BrookCalcKineticEnergyKernel : public CalcKineticEnergyKernel { ...@@ -50,10 +51,11 @@ class BrookCalcKineticEnergyKernel : public CalcKineticEnergyKernel {
* *
* @param name name of the stream to create * @param name name of the stream to create
* @param platform platform * @param platform platform
* * @param OpenMMBrookInterface OpenMM-Brook interface
* @param System System reference
*/ */
BrookCalcKineticEnergyKernel( std::string name, const Platform& platform ); BrookCalcKineticEnergyKernel( std::string name, const Platform& platform, OpenMMBrookInterface& openMMBrookInterface, System& system );
/** /**
* BrookCalcKineticEnergyKernel destructor * BrookCalcKineticEnergyKernel destructor
...@@ -65,26 +67,38 @@ class BrookCalcKineticEnergyKernel : public CalcKineticEnergyKernel { ...@@ -65,26 +67,38 @@ class BrookCalcKineticEnergyKernel : public CalcKineticEnergyKernel {
/** /**
* Initialize the kernel * Initialize the kernel
* *
* @param masses mass of each particle * @param system System reference
* *
*/ */
void initialize( const std::vector<double>& masses ); void initialize( const System& system );
/** /**
* Execute the kernel. * Execute the kernel.
* *
* @param velocities stream of particle velocities * @param context OpenMMContextImpl reference
* *
*/ */
double execute( const Stream& velocities ); double execute( OpenMMContextImpl& context );
private: private:
int _numberOfParticles;
// masses // masses
BrookOpenMMFloat* _masses; BrookOpenMMFloat* _masses;
// interface
OpenMMBrookInterface& _openMMBrookInterface;
// System reference
System& _system;
}; };
} // namespace OpenMM } // namespace OpenMM
......
/* -------------------------------------------------------------------------- *
* 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 "BrookInitializeForcesKernel.h"
using namespace OpenMM;
using namespace std;
/**
* BrookInitializeForcesKernel constructor
*
* @param name kernel name
* @param platform platform
* @param openMMBrookInterface OpenMMBrookInterface reference
* @param system System reference
*
*/
BrookInitializeForcesKernel::BrookInitializeForcesKernel( std::string name, const Platform& platform,
OpenMMBrookInterface& openMMBrookInterface, System& system ) :
InitializeForcesKernel( name, platform ), _openMMBrookInterface( openMMBrookInterface ), _system( system ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookInitializeForcesKernel::BrookInitializeForcesKernel";
// ---------------------------------------------------------------------------------------
_numberOfParticles = 0;
_log = NULL;
const BrookPlatform brookPlatform = dynamic_cast<const BrookPlatform&> (platform);
if( brookPlatform.getLog() != NULL ){
setLog( brookPlatform.getLog() );
}
}
/**
* BrookInitializeForcesKernel destructor
*
*/
BrookInitializeForcesKernel::~BrookInitializeForcesKernel( ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookInitializeForcesKernel::BrookInitializeForcesKernel";
// ---------------------------------------------------------------------------------------
}
/**
* Get log file reference
*
* @return log file reference
*
*/
FILE* BrookInitializeForcesKernel::getLog( void ) const {
return _log;
}
/**
* Set log file reference
*
* @param log file reference
*
* @return DefaultReturnValue
*
*/
int BrookInitializeForcesKernel::setLog( FILE* log ){
_log = log;
return BrookCommon::DefaultReturnValue;
}
/**
* Initialize
*
* @param system System reference
*
* @return DefaultReturnValue
*
*/
void BrookInitializeForcesKernel::initialize( const System& system ){
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "BrookInitializeForcesKernel::initialize";
// ---------------------------------------------------------------------------------------
//FILE* log = getLog();
}
/**
* Zero forces
*
* @param context OpenMMContextImpl context
*
*/
void BrookInitializeForcesKernel::execute( OpenMMContextImpl& context ){
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "BrookInitializeForcesKernel::execute";
// ---------------------------------------------------------------------------------------
_openMMBrookInterface.zeroForces( context );
// ---------------------------------------------------------------------------------------
}
#ifndef OPENMM_BROOK_INITIALIZE_FORCES_KERNEL_H_
#define OPENMM_BROOK_INITIALIZE_FORCES_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 "OpenMMBrookInterface.h"
namespace OpenMM {
/**
* This kernel initializes the forces
*/
class BrookInitializeForcesKernel : public InitializeForcesKernel {
public:
BrookInitializeForcesKernel( std::string name, const Platform& platform, OpenMMBrookInterface& openMMBrookInterface, System& system );
~BrookInitializeForcesKernel();
/**
* Initialize the kernel
*
* @param system the System this kernel will be applied to
*/
void initialize( const System& system );
/**
* Execute the kernel to calculate the forces.
*
* @param context the context in which to execute this kernel
*/
void execute( OpenMMContextImpl& context );
/**
* 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 particles
int _numberOfParticles;
OpenMMBrookInterface& _openMMBrookInterface;
System& _system;
};
} // namespace OpenMM
#endif /* OPENMM_BROOK_INITIALIZE_FORCES_KERNEL_H_ */
...@@ -35,16 +35,19 @@ ...@@ -35,16 +35,19 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
/** /**
* BrookIntegrateLangevinStepKernel constructor * BrookIntegrateLangevinStepKernel constructor
* *
* @param name name of the stream to create * @param name name of the stream to create
* @param platform platform * @param platform platform
* @param openMMBrookInterface OpenMMBrookInterface reference
* @param system System reference
* *
*/ */
BrookIntegrateLangevinStepKernel::BrookIntegrateLangevinStepKernel( std::string name, const Platform& platform ) : BrookIntegrateLangevinStepKernel::BrookIntegrateLangevinStepKernel( std::string name, const Platform& platform,
IntegrateLangevinStepKernel( name, platform ){ OpenMMBrookInterface& openMMBrookInterface, System& system ) :
IntegrateLangevinStepKernel( name, platform ), _openMMBrookInterface( openMMBrookInterface ), _system( system ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -80,15 +83,12 @@ BrookIntegrateLangevinStepKernel::~BrookIntegrateLangevinStepKernel( ){ ...@@ -80,15 +83,12 @@ BrookIntegrateLangevinStepKernel::~BrookIntegrateLangevinStepKernel( ){
/** /**
* Initialize the kernel, setting up all parameters related to integrator. * Initialize the kernel, setting up all parameters related to integrator.
* *
* @param masses the mass of each particle * @param system System reference
* @param constraintIndices each element contains the indices of two particles whose distance should be constrained * @param integrator LangevinIntegrator reference
* @param constraintLengths the required distance between each pair of constrained particles
* *
*/ */
void BrookIntegrateLangevinStepKernel::initialize( const vector<double>& masses, void BrookIntegrateLangevinStepKernel::initialize( const System& system, const LangevinIntegrator& integrator ){
const vector<vector<int> >& constraintIndices,
const vector<double>& constraintLengths ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -96,34 +96,64 @@ void BrookIntegrateLangevinStepKernel::initialize( const vector<double>& masses, ...@@ -96,34 +96,64 @@ void BrookIntegrateLangevinStepKernel::initialize( const vector<double>& masses,
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
int numberOfParticles = system.getNumParticles();
// masses
std::vector<double> masses;
masses.resize( numberOfParticles );
for( int ii = 0; ii < numberOfParticles; ii++ ){
masses[ii] = static_cast<RealOpenMM>(system.getParticleMass(ii));
}
// constraints
int numberOfConstraints = system.getNumConstraints();
std::vector<std::vector<int> > constraintIndicesVector;
constraintIndicesVector.resize( numberOfConstraints );
std::vector<double> constraintLengths;
constraintLengths.resize( numberOfConstraints );
for( int ii = 0; ii < numberOfConstraints; ii++ ){
int particle1, particle2;
double distance;
system.getConstraintParameters( ii, particle1, particle2, distance );
std::vector<int> constraintIndices;
constraintIndicesVector[ii] = constraintIndices;
constraintIndices[0] = particle1;
constraintIndices[1] = particle2;
constraintLengths[ii] = static_cast<RealOpenMM>(distance);
}
_brookLangevinDynamics = new BrookLangevinDynamics( ); _brookLangevinDynamics = new BrookLangevinDynamics( );
_brookLangevinDynamics->setup( masses, getPlatform() ); _brookLangevinDynamics->setup( masses, getPlatform() );
_brookShakeAlgorithm = new BrookShakeAlgorithm( ); _brookShakeAlgorithm = new BrookShakeAlgorithm( );
_brookShakeAlgorithm->setup( masses, constraintIndices, constraintLengths, getPlatform() ); _brookShakeAlgorithm->setup( masses, constraintIndicesVector, constraintLengths, getPlatform() );
// assert( (_brookShakeAlgorithm->getNumberOfConstraints() > 0) ); // assert( (_brookShakeAlgorithm->getNumberOfConstraints() > 0) );
_brookRandomNumberGenerator = new BrookRandomNumberGenerator( ); _brookRandomNumberGenerator = new BrookRandomNumberGenerator( );
_brookRandomNumberGenerator->setup( (int) masses.size(), getPlatform() ); _brookRandomNumberGenerator->setup( (int) masses.size(), getPlatform() );
_brookRandomNumberGenerator->setVerbosity( 1 ); _brookRandomNumberGenerator->setVerbosity( 1 );
} }
/** /**
* Execute kernel * Execute kernel
* *
* @param positions particle coordinates * @param context OpenMMContextImpl reference
* @param velocities particle velocities * @param integrator LangevinIntegrator reference
* @param forces particle forces
* @param temperature heat bath temperature
* @param friction friction coefficient coupling the system to the heat bath
* @param stepSize integration step size
* *
*/ */
void BrookIntegrateLangevinStepKernel::execute( Stream& positions, Stream& velocities, void BrookIntegrateLangevinStepKernel::execute( OpenMMContextImpl& context, const LangevinIntegrator& integrator ){
const Stream& forces, double temperature,
double friction, double stepSize ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -140,16 +170,17 @@ void BrookIntegrateLangevinStepKernel::execute( Stream& positions, Stream& veloc ...@@ -140,16 +170,17 @@ void BrookIntegrateLangevinStepKernel::execute( Stream& positions, Stream& veloc
// take step // take step
double differences[3]; double differences[3];
differences[0] = temperature - (double) _brookLangevinDynamics->getTemperature(); differences[0] = integrator.getTemperature() - (double) _brookLangevinDynamics->getTemperature();
differences[1] = friction - (double) _brookLangevinDynamics->getFriction(); differences[1] = integrator.getFriction() - (double) _brookLangevinDynamics->getFriction();
differences[2] = stepSize - (double) _brookLangevinDynamics->getStepSize(); differences[2] = integrator.getStepSize() - (double) _brookLangevinDynamics->getStepSize();
if( fabs( differences[0] ) > epsilon || fabs( differences[1] ) > epsilon || fabs( differences[2] ) > epsilon ){ if( fabs( differences[0] ) > epsilon || fabs( differences[1] ) > epsilon || fabs( differences[2] ) > epsilon ){
//printf( "%s calling updateParameters\n", methodName.c_str() ); //printf( "%s calling updateParameters\n", methodName.c_str() );
_brookLangevinDynamics->updateParameters( temperature, friction, stepSize ); _brookLangevinDynamics->updateParameters( integrator.getTemperature(), integrator.getFriction(), integrator.getStepSize() );
} else { } else {
//printf( "%s NOT calling updateParameters\n", methodName.c_str() ); //printf( "%s NOT calling updateParameters\n", methodName.c_str() );
} }
_brookLangevinDynamics->update( positions, velocities, forces, *_brookShakeAlgorithm, *_brookRandomNumberGenerator ); _brookLangevinDynamics->update( *(_openMMBrookInterface.getParticlePositions()), *(_openMMBrookInterface.getParticleVelocities()),
*(_openMMBrookInterface.getParticleForces()), *_brookShakeAlgorithm, *_brookRandomNumberGenerator );
} }
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "kernels.h" #include "kernels.h"
#include "OpenMMBrookInterface.h"
#include "BrookLangevinDynamics.h" #include "BrookLangevinDynamics.h"
#include "BrookShakeAlgorithm.h" #include "BrookShakeAlgorithm.h"
#include "BrookRandomNumberGenerator.h" #include "BrookRandomNumberGenerator.h"
...@@ -40,7 +41,7 @@ ...@@ -40,7 +41,7 @@
namespace OpenMM { namespace OpenMM {
/** /**
* This is the base class of Float and Double streams in the Brook Platform. * Performs Langevin integration step
*/ */
class BrookIntegrateLangevinStepKernel : public IntegrateLangevinStepKernel { class BrookIntegrateLangevinStepKernel : public IntegrateLangevinStepKernel {
...@@ -60,7 +61,7 @@ class BrookIntegrateLangevinStepKernel : public IntegrateLangevinStepKernel { ...@@ -60,7 +61,7 @@ class BrookIntegrateLangevinStepKernel : public IntegrateLangevinStepKernel {
* *
*/ */
BrookIntegrateLangevinStepKernel( std::string name, const Platform& platform ); BrookIntegrateLangevinStepKernel( std::string name, const Platform& platform, OpenMMBrookInterface& openMMBrookInterface, System& system );
/** /**
* BrookIntegrateLangevinStepKernel destructor * BrookIntegrateLangevinStepKernel destructor
...@@ -72,26 +73,21 @@ class BrookIntegrateLangevinStepKernel : public IntegrateLangevinStepKernel { ...@@ -72,26 +73,21 @@ class BrookIntegrateLangevinStepKernel : public IntegrateLangevinStepKernel {
/** /**
* Initialize the kernel, setting up all parameters related to integrator. * Initialize the kernel, setting up all parameters related to integrator.
* *
* @param masses particle masses * @param system System reference
* @param constraintIndices each element contains the indices of two particles whose distance should be constrained * @param integrator LangevinIntegrator reference
* @param constraintLengths required distance between each pair of constrained particles
*/ */
void initialize( const std::vector<double>& masses, const std::vector<std::vector<int> >& constraintIndices, void initialize( const System& system, const LangevinIntegrator& integrator );
const std::vector<double>& constraintLengths );
/** /**
* Execute kernel * Execute kernel
* *
* @param positions coordinates * @param context OpenMMContextImpl reference
* @param velocities velocities * @param integrator LangevinIntegrator reference
* @param forces forces
* @param temperature heat bath temperature
* @param friction friction coefficient coupling the system to the heat bath
* @param stepSize step size
* *
*/ */
void execute( Stream& positions, Stream& velocities, const Stream& forces, double temperature, double friction, double stepSize ); void execute( OpenMMContextImpl& context, const LangevinIntegrator& integrator );
protected: protected:
...@@ -99,6 +95,14 @@ class BrookIntegrateLangevinStepKernel : public IntegrateLangevinStepKernel { ...@@ -99,6 +95,14 @@ class BrookIntegrateLangevinStepKernel : public IntegrateLangevinStepKernel {
BrookShakeAlgorithm* _brookShakeAlgorithm; BrookShakeAlgorithm* _brookShakeAlgorithm;
BrookRandomNumberGenerator* _brookRandomNumberGenerator; BrookRandomNumberGenerator* _brookRandomNumberGenerator;
// interface
OpenMMBrookInterface& _openMMBrookInterface;
// System reference
System& _system;
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -30,13 +30,17 @@ ...@@ -30,13 +30,17 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "BrookKernelFactory.h" #include "BrookKernelFactory.h"
#include "BrookInitializeForcesKernel.h"
#include "BrookCalcHarmonicBondForceKernel.h"
#include "BrookCalcHarmonicAngleForceKernel.h" #include "BrookCalcHarmonicAngleForceKernel.h"
#include "BrookCalcPeriodicTorsionForceKernel.h"
#include "BrookCalcRBTorsionForceKernel.h"
#include "BrookCalcNonbondedForceKernel.h" #include "BrookCalcNonbondedForceKernel.h"
#include "BrookIntegrateLangevinStepKernel.h" #include "BrookIntegrateLangevinStepKernel.h"
#include "BrookIntegrateVerletStepKernel.h" #include "BrookIntegrateVerletStepKernel.h"
#include "BrookIntegrateBrownianStepKernel.h" #include "BrookIntegrateBrownianStepKernel.h"
#include "BrookCalcKineticEnergyKernel.h" #include "BrookCalcKineticEnergyKernel.h"
//#include "BrookCalcGBSAOBCForceKernel.h" #include "BrookCalcGBSAOBCForceKernel.h"
#include "BrookRemoveCMMotionKernel.h" #include "BrookRemoveCMMotionKernel.h"
#include "internal/OpenMMContextImpl.h" #include "internal/OpenMMContextImpl.h"
...@@ -52,11 +56,17 @@ KernelImpl* BrookKernelFactory::createKernelImpl( std::string name, const Platfo ...@@ -52,11 +56,17 @@ KernelImpl* BrookKernelFactory::createKernelImpl( std::string name, const Platfo
OpenMMBrookInterface& openMMBrookInterface = *static_cast<OpenMMBrookInterface*>(context.getPlatformData()); OpenMMBrookInterface& openMMBrookInterface = *static_cast<OpenMMBrookInterface*>(context.getPlatformData());
// initialize forces
if( name == InitializeForcesKernel::Name() ){
return new BrookInitializeForcesKernel( name, platform, openMMBrookInterface, context.getSystem() );
// harmonic bonds // harmonic bonds
if( name == CalcHarmonicBondForceKernel::Name() ){ } else if( name == CalcHarmonicBondForceKernel::Name() ){
// return new BrookCalcHarmonicBondForceKernel( name, platform, openMMBrookInterface, context.getSystem() ); return new BrookCalcHarmonicBondForceKernel( name, platform, openMMBrookInterface, context.getSystem() );
// angle bonds // angle bonds
...@@ -68,25 +78,25 @@ KernelImpl* BrookKernelFactory::createKernelImpl( std::string name, const Platfo ...@@ -68,25 +78,25 @@ KernelImpl* BrookKernelFactory::createKernelImpl( std::string name, const Platfo
} else if( name == CalcPeriodicTorsionForceKernel::Name() ){ } else if( name == CalcPeriodicTorsionForceKernel::Name() ){
// return new BrookCalcPeriodicTorsionForceKernel( name, platform, openMMBrookInterface, context.getSystem() ); return new BrookCalcPeriodicTorsionForceKernel( name, platform, openMMBrookInterface, context.getSystem() );
// RB torsion bonds // RB torsion bonds
} else if( name == CalcRBTorsionForceKernel::Name() ){ } else if( name == CalcRBTorsionForceKernel::Name() ){
// return new BrookCalcRBTorsionForceKernel( name, platform, openMMBrookInterface, context.getSystem() ); return new BrookCalcRBTorsionForceKernel( name, platform, openMMBrookInterface, context.getSystem() );
// nonbonded // nonbonded
} else if( name == CalcNonbondedForceKernel::Name() ){ } else if( name == CalcNonbondedForceKernel::Name() ){
// return new BrookCalcNonbondedForceKernel( name, platform, openMMBrookInterface, context.getSystem() ); return new BrookCalcNonbondedForceKernel( name, platform, openMMBrookInterface, context.getSystem() );
// GBSA OBC // GBSA OBC
} else if( name == CalcGBSAOBCForceKernel::Name() ){ } else if( name == CalcGBSAOBCForceKernel::Name() ){
// return new BrookCalcGBSAOBCForceFieldKernel( name, platform, openMMBrookInterface, context.getSystem() ); return new BrookCalcGBSAOBCForceKernel( name, platform, openMMBrookInterface, context.getSystem() );
// Verlet integrator // Verlet integrator
...@@ -110,7 +120,7 @@ KernelImpl* BrookKernelFactory::createKernelImpl( std::string name, const Platfo ...@@ -110,7 +120,7 @@ KernelImpl* BrookKernelFactory::createKernelImpl( std::string name, const Platfo
} else if( name == IntegrateLangevinStepKernel::Name() ){ } else if( name == IntegrateLangevinStepKernel::Name() ){
// return new BrookIntegrateLangevinStepKernel( name, platform, openMMBrookInterface ); return new BrookIntegrateLangevinStepKernel( name, platform, openMMBrookInterface, context.getSystem() );
// Remove com // Remove com
...@@ -121,10 +131,10 @@ KernelImpl* BrookKernelFactory::createKernelImpl( std::string name, const Platfo ...@@ -121,10 +131,10 @@ KernelImpl* BrookKernelFactory::createKernelImpl( std::string name, const Platfo
// KE calculator // KE calculator
} else if( name == CalcKineticEnergyKernel::Name() ){ } else if( name == CalcKineticEnergyKernel::Name() ){
// return new BrookCalcKineticEnergyKernel( name, platform, openMMBrookInterface ); return new BrookCalcKineticEnergyKernel( name, platform, openMMBrookInterface, context.getSystem() );
} }
(void) fprintf( stderr, "createKernelImpl: name=<%s> not found.", methodName.c_str(), name.c_str() ); (void) fprintf( stderr, "%s: name=<%s> not found.", methodName.c_str(), name.c_str() );
(void) fflush( stderr ); (void) fflush( stderr );
return NULL; return NULL;
......
...@@ -362,8 +362,8 @@ int BrookLangevinDynamics::updateParameters( double temperature, double friction ...@@ -362,8 +362,8 @@ int BrookLangevinDynamics::updateParameters( double temperature, double friction
* *
*/ */
int BrookLangevinDynamics::update( Stream& positions, Stream& velocities, int BrookLangevinDynamics::update( BrookStreamImpl& positionStream, BrookStreamImpl& velocityStream,
const Stream& forces, BrookStreamImpl& forceStream,
BrookShakeAlgorithm& brookShakeAlgorithm, BrookShakeAlgorithm& brookShakeAlgorithm,
BrookRandomNumberGenerator& brookRandomNumberGenerator ){ BrookRandomNumberGenerator& brookRandomNumberGenerator ){
...@@ -381,11 +381,6 @@ int BrookLangevinDynamics::update( Stream& positions, Stream& velocities, ...@@ -381,11 +381,6 @@ int BrookLangevinDynamics::update( Stream& positions, Stream& velocities,
const BrookOpenMMFloat* derivedParameters = getDerivedParameters(); const BrookOpenMMFloat* derivedParameters = getDerivedParameters();
BrookStreamImpl& positionStream = dynamic_cast<BrookStreamImpl&> (positions.getImpl());
BrookStreamImpl& velocityStream = dynamic_cast<BrookStreamImpl&> (velocities.getImpl());
const BrookStreamImpl& forceStreamC = dynamic_cast<const BrookStreamImpl&> (forces.getImpl());
BrookStreamImpl& forceStream = const_cast<BrookStreamImpl&> (forceStreamC);
if( (1 || PrintOn) && getLog() ){ if( (1 || PrintOn) && getLog() ){
static int showAux = 1; static int showAux = 1;
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include <vector> #include <vector>
#include <set> #include <set>
#include "BrookFloatStreamInternal.h" #include "BrookStreamImpl.h"
#include "BrookShakeAlgorithm.h" #include "BrookShakeAlgorithm.h"
#include "BrookRandomNumberGenerator.h" #include "BrookRandomNumberGenerator.h"
#include "BrookPlatform.h" #include "BrookPlatform.h"
...@@ -159,8 +159,9 @@ class BrookLangevinDynamics : public BrookCommon { ...@@ -159,8 +159,9 @@ class BrookLangevinDynamics : public BrookCommon {
* *
*/ */
int update( Stream& positions, Stream& velocities, int update( BrookStreamImpl& positionStream, BrookStreamImpl& velocityStream,
const Stream& forces, BrookShakeAlgorithm& brookShakeAlgorithm, BrookStreamImpl& forceStream,
BrookShakeAlgorithm& brookShakeAlgorithm,
BrookRandomNumberGenerator& brookRandomNumberGenerator ); BrookRandomNumberGenerator& brookRandomNumberGenerator );
/** /**
* Get array of LangevinDynamics streams * Get array of LangevinDynamics streams
......
...@@ -271,14 +271,19 @@ void BrookPlatform::_initializeKernelFactory( void ){ ...@@ -271,14 +271,19 @@ void BrookPlatform::_initializeKernelFactory( void ){
BrookKernelFactory* factory = new BrookKernelFactory(); BrookKernelFactory* factory = new BrookKernelFactory();
registerKernelFactory( CalcNonbondedForceKernel::Name(), factory); registerKernelFactory( InitializeForcesKernel::Name(), factory );
registerKernelFactory( CalcGBSAOBCForceKernel::Name(), factory); registerKernelFactory( CalcHarmonicBondForceKernel::Name(), factory );
registerKernelFactory( IntegrateVerletStepKernel::Name(), factory); registerKernelFactory( CalcHarmonicAngleForceKernel::Name(), factory );
registerKernelFactory( IntegrateLangevinStepKernel::Name(), factory); registerKernelFactory( CalcPeriodicTorsionForceKernel::Name(), factory );
registerKernelFactory( IntegrateBrownianStepKernel::Name(), factory); registerKernelFactory( CalcRBTorsionForceKernel::Name(), factory );
//registerKernelFactory( ApplyAndersenThermostatKernel::Name(), factory); registerKernelFactory( CalcNonbondedForceKernel::Name(), factory );
registerKernelFactory( CalcKineticEnergyKernel::Name(), factory); registerKernelFactory( CalcGBSAOBCForceKernel::Name(), factory );
registerKernelFactory( RemoveCMMotionKernel::Name(), factory); registerKernelFactory( IntegrateVerletStepKernel::Name(), factory );
registerKernelFactory( IntegrateLangevinStepKernel::Name(), factory );
registerKernelFactory( IntegrateBrownianStepKernel::Name(), factory );
//registerKernelFactory( ApplyAndersenThermostatKernel::Name(), factory );
registerKernelFactory( CalcKineticEnergyKernel::Name(), factory );
registerKernelFactory( RemoveCMMotionKernel::Name(), factory );
} }
......
...@@ -36,9 +36,7 @@ ...@@ -36,9 +36,7 @@
#include "BrookStreamImpl.h" #include "BrookStreamImpl.h"
#include "OpenMMBrookInterface.h" #include "OpenMMBrookInterface.h"
#include "gpu/kforce.h" #include "gpu/kcommon.h"
#include "gpu/kinvmap_gather.h"
#include "NonbondedForce.h"
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
...@@ -62,6 +60,9 @@ OpenMMBrookInterface::OpenMMBrookInterface( void ){ ...@@ -62,6 +60,9 @@ OpenMMBrookInterface::OpenMMBrookInterface( void ){
_brookNonBonded = NULL; _brookNonBonded = NULL;
_brookGbsa = NULL; _brookGbsa = NULL;
_triggerForceKernel = NULL;
_triggerEnergyKernel = NULL;
_positions = NULL; _positions = NULL;
_velocities = NULL; _velocities = NULL;
_forces = NULL; _forces = NULL;
...@@ -284,6 +285,73 @@ int OpenMMBrookInterface::setParticleForces( BrookStreamImpl* forces ){ ...@@ -284,6 +285,73 @@ int OpenMMBrookInterface::setParticleForces( BrookStreamImpl* forces ){
return DefaultReturnValue; return DefaultReturnValue;
} }
/**
* Set trigger Force Kernel
*
* @param triggerForceKernel kernel to calculate force
*
*/
void OpenMMBrookInterface::setTriggerForceKernel( void* triggerForceKernel ){
_triggerForceKernel = triggerForceKernel;
}
/**
* Get trigger Force Kernel
*
* @return triggerForceKernel kernel to calculate force
*
*/
void* OpenMMBrookInterface::getTriggerForceKernel( void ) const {
return _triggerForceKernel;
}
/**
* Set trigger Energy Kernel
*
* @param triggerEnergyKernel kernel to calculate force
*
*/
void OpenMMBrookInterface::setTriggerEnergyKernel( void* triggerEnergyKernel ){
_triggerEnergyKernel = triggerEnergyKernel;
}
/**
* Get trigger Energy Kernel
*
* @return triggerEnergyKernel kernel to calculate force
*
*/
void* OpenMMBrookInterface::getTriggerEnergyKernel( void ) const {
return _triggerEnergyKernel;
}
/**
* Zero forces
*
* @param context context
*
*/
void OpenMMBrookInterface::zeroForces( OpenMMContextImpl& context ){
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "OpenMMBrookInterface::zeroForces";
// ---------------------------------------------------------------------------------------
// zero forces
BrookStreamImpl* forces = getParticleForces();
kzerof3( forces->getBrookStream() );
// ---------------------------------------------------------------------------------------
}
/** /**
* Compute forces * Compute forces
* *
...@@ -351,3 +419,30 @@ void OpenMMBrookInterface::computeForces( OpenMMContextImpl& context ){ ...@@ -351,3 +419,30 @@ void OpenMMBrookInterface::computeForces( OpenMMContextImpl& context ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
} }
/**
* Compute energy
*
* @param context context
*
*/
double OpenMMBrookInterface::computeEnergy( OpenMMContextImpl& context ){
// ---------------------------------------------------------------------------------------
/*
static const std::string methodName = "OpenMMBrookInterface::computeEnergy";
static const int PrintOn = 0;
static const int MaxErrorMessages = 2;
static int ErrorMessages = 0;
*/
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
return 0.0;
// ---------------------------------------------------------------------------------------
}
...@@ -99,6 +99,15 @@ class OpenMMBrookInterface { ...@@ -99,6 +99,15 @@ class OpenMMBrookInterface {
FILE* getLog( void ) const; FILE* getLog( void ) const;
/**
* Zero forces
*
* @param context OpenMMContextImpl context
*
*/
void zeroForces( OpenMMContextImpl& context );
/** /**
* Compute forces * Compute forces
* *
...@@ -115,7 +124,7 @@ class OpenMMBrookInterface { ...@@ -115,7 +124,7 @@ class OpenMMBrookInterface {
* *
*/ */
float computeEnergy( OpenMMContextImpl& context ); double computeEnergy( OpenMMContextImpl& context );
/** /**
* Set trigger Force Kernel * Set trigger Force Kernel
...@@ -124,39 +133,48 @@ class OpenMMBrookInterface { ...@@ -124,39 +133,48 @@ class OpenMMBrookInterface {
* *
*/ */
void setTriggerForceKernel( KernelImpl* triggerForceKernel ); void setTriggerForceKernel( void* triggerForceKernel );
/** /**
* Set trigger Energy Kernel * Get trigger Force Kernel
* *
* @param triggerEnergyKernel kernel to calculate energy * @return triggerForceKernel kernel to calculate force
* *
*/ */
void setTriggerEnergyKernel( KernelImpl* triggerForceKernel ); void* getTriggerForceKernel( void ) const;
/** /**
* Get trigger Force Kernel * Set trigger Energy Kernel
* *
* @return triggerForceKernel kernel to calculate force * @param triggerEnergyKernel kernel to calculate force
* *
*/ */
KernelImpl* getTriggerForceKernel( void ) const; void setTriggerEnergyKernel( void* triggerEnergyKernel );
/** /**
* Get trigger Energy Kernel * Get trigger Energy Kernel
* *
* @return triggerEnergyKernel kernel to calculate energy * @return triggerEnergyKernel kernel to calculate force
* *
*/ */
KernelImpl* getTriggerEnergyKernel( void ) const; void* getTriggerEnergyKernel( void ) const;
/** /**
* Set BrookBondParameters for harmonic angle force * Get BrookBondParameters for harmonic bond force
* *
* @param brookBondParameters brookBondParameters for BrookBondParameters for harmonic angle force * @return brookBondParameters for BrookBondParameters for harmonic bond force
*
*/
BrookBondParameters* getHarmonicBondForceParameters( void );
/**
* Set BrookBondParameters for harmonic bond force
*
* @param brookBondParameters BrookBondParameters for harmonic bond force
* *
* @return DefaultReturnValue * @return DefaultReturnValue
* *
...@@ -164,6 +182,15 @@ class OpenMMBrookInterface { ...@@ -164,6 +182,15 @@ class OpenMMBrookInterface {
int setHarmonicBondForceParameters( BrookBondParameters* brookBondParameters ); int setHarmonicBondForceParameters( BrookBondParameters* brookBondParameters );
/**
* Get BrookBondParameters for harmonic angle force
*
* @return brookBondParameters for BrookBondParameters for harmonic angle force
*
*/
BrookBondParameters* getHarmonicAngleForceParameters( void );
/** /**
* Set BrookBondParameters for harmonic angle force * Set BrookBondParameters for harmonic angle force
* *
...@@ -176,9 +203,18 @@ class OpenMMBrookInterface { ...@@ -176,9 +203,18 @@ class OpenMMBrookInterface {
int setHarmonicAngleForceParameters( BrookBondParameters* brookBondParameters ); int setHarmonicAngleForceParameters( BrookBondParameters* brookBondParameters );
/** /**
* Set BrookBondParameters for proper dihedral force * Get BrookBondParameters for periodic torsion force
*
* @return brookBondParameters for BrookBondParameters for periodic torsion force
*
*/
BrookBondParameters* getPeriodicTorsionForceParameters( void );
/**
* Set BrookBondParameters for periodic torsion force
* *
* @param brookBondParameters brookBondParameters for proper dihedral force * @param brookBondParameters for periodic torsion force
* *
* @return DefaultReturnValue * @return DefaultReturnValue
* *
...@@ -187,9 +223,18 @@ class OpenMMBrookInterface { ...@@ -187,9 +223,18 @@ class OpenMMBrookInterface {
int setPeriodicTorsionForceParameters( BrookBondParameters* brookBondParameters ); int setPeriodicTorsionForceParameters( BrookBondParameters* brookBondParameters );
/** /**
* Set BrookBondParameters for RB dihedral force * Get BrookBondParameters for RB torsion force
* *
* @param brookBondParameters brookBondParameters for RB force * @return brookBondParameters for BrookBondParameters for RB torsion force
*
*/
BrookBondParameters* getRBTorsionForceParameters( void );
/**
* Set BrookBondParameters for RB torsion force
*
* @param brookBondParameters brookBondParameters for RB torsion force
* *
* @return DefaultReturnValue * @return DefaultReturnValue
* *
...@@ -197,6 +242,15 @@ class OpenMMBrookInterface { ...@@ -197,6 +242,15 @@ class OpenMMBrookInterface {
int setRBTorsionForceParameters( BrookBondParameters* brookBondParameters ); int setRBTorsionForceParameters( BrookBondParameters* brookBondParameters );
/**
* Get BrookBondParameters for LJ 14 forces
*
* @return brookBondParameters for BrookBondParameters for LJ 14 forces
*
*/
BrookBondParameters* getNonBonded14ForceParameters( void );
/** /**
* Set BrookBondParameters for LJ 14 force * Set BrookBondParameters for LJ 14 force
* *
...@@ -289,6 +343,9 @@ class OpenMMBrookInterface { ...@@ -289,6 +343,9 @@ class OpenMMBrookInterface {
BrookNonBonded* _brookNonBonded; BrookNonBonded* _brookNonBonded;
BrookGbsa* _brookGbsa; BrookGbsa* _brookGbsa;
void* _triggerForceKernel;
void* _triggerEnergyKernel;
BrookBondParameters* _bondParameters[LastBondForce]; BrookBondParameters* _bondParameters[LastBondForce];
// context-related fields // context-related fields
......
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