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

Continuing to implement ReferencePlatform (kernels for StandardMMForceField are done).

parent 012b28e6
......@@ -40,11 +40,11 @@ namespace OpenMM {
/**
* This kernel is invoked by StandardMMForceField to calculate the forces acting on the system.
*/
class ReferenceCalcStandardMMForcesKernel : public CalcStandardMMForcesKernel {
class ReferenceCalcStandardMMForceFieldKernel : public CalcStandardMMForceFieldKernel {
public:
ReferenceCalcStandardMMForcesKernel(std::string name, const Platform& platform) : CalcStandardMMForcesKernel(name, platform) {
ReferenceCalcStandardMMForceFieldKernel(std::string name, const Platform& platform) : CalcStandardMMForceFieldKernel(name, platform) {
}
~ReferenceCalcStandardMMForcesKernel();
~ReferenceCalcStandardMMForceFieldKernel();
/**
* Initialize the kernel, setting up the values of all the force field parameters.
*
......@@ -53,82 +53,51 @@ public:
* @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 (periodicity, phase, k) for 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, van der Waals radius, van der Waals depth) for each atom
* @param nonbondedParameters the nonbonded force parameters (charge, sigma, epsilon) for each atom
*/
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, const std::vector<std::set<int> >& exclusions,
const std::vector<std::vector<double> >& nonbondedParameters);
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);
/**
* Execute the kernel.
* 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 execute(const Stream& positions, Stream& forces);
private:
int numAtoms, numBonds, numAngles, numPeriodicTorsions, numRBTorsions;
int **bondIndexArray, **angleIndexArray, **periodicTorsionIndexArray, **rbTorsionIndexArray;
RealOpenMM **bondParamArray, **angleParamArray, **periodicTorsionParamArray, **rbTorsionParamArray;
};
/**
* This kernel is invoked by StandardMMForceField to calculate the energy of the system.
*/
class ReferenceCalcStandardMMEnergyKernel : public CalcStandardMMEnergyKernel {
public:
ReferenceCalcStandardMMEnergyKernel(std::string name, const Platform& platform) : CalcStandardMMEnergyKernel(name, platform) {
}
/**
* 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 (periodicity, phase, k) 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 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, van der Waals radius, van der Waals depth) for each atom
*/
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, const std::vector<std::set<int> >& exclusions,
const std::vector<std::vector<double> >& nonbondedParameters);
void executeForces(const Stream& positions, Stream& forces);
/**
* Execute the kernel.
* 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
*/
double execute(const Stream& positions);
double executeEnergy(const Stream& positions);
private:
int numAtoms, numBonds, numAngles, numPeriodicTorsions, numRBTorsions, num14;
int **bondIndexArray, **angleIndexArray, **periodicTorsionIndexArray, **rbTorsionIndexArray, **exclusionArray, **bonded14IndexArray;
RealOpenMM **bondParamArray, **angleParamArray, **periodicTorsionParamArray, **rbTorsionParamArray, **atomParamArray, **bonded14ParamArray;
};
/**
* This kernel is invoked by GBSAOBCForceField to calculate the forces acting on the system.
*/
class ReferenceCalcGBSAOBCForcesKernel : public CalcGBSAOBCForcesKernel {
class ReferenceCalcGBSAOBCForceFieldKernel : public CalcGBSAOBCForceFieldKernel {
public:
ReferenceCalcGBSAOBCForcesKernel(std::string name, const Platform& platform) : CalcGBSAOBCForcesKernel(name, platform) {
ReferenceCalcGBSAOBCForceFieldKernel(std::string name, const Platform& platform) : CalcGBSAOBCForceFieldKernel(name, platform) {
}
/**
* Initialize the kernel, setting up the values of all the force field parameters.
......@@ -141,39 +110,20 @@ public:
void initialize(const std::vector<double>& bornRadii, const std::vector<std::vector<double> >& atomParameters,
double solventDielectric, double soluteDielectric);
/**
* Execute the kernel.
* 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 execute(const Stream& positions, Stream& forces);
};
/**
* This kernel is invoked by GBSAOBCForceField to calculate the energy of the system.
*/
class ReferenceCalcGBSAOBCEnergyKernel : public CalcGBSAOBCEnergyKernel {
public:
ReferenceCalcGBSAOBCEnergyKernel(std::string name, const Platform& platform) : CalcGBSAOBCEnergyKernel(name, platform) {
}
void executeForces(const Stream& positions, Stream& forces);
/**
* Initialize the kernel, setting up the values of all the force field parameters.
*
* @param bornRadii the initial value of the Born radius for each atom
* @param atomParameters the force parameters (charge, atomic radius, scaling factor) for each atom
* @param solventDielectric the dielectric constant of the solvent
* @param soluteDielectric the dielectric constant of the solute
*/
void initialize(const std::vector<double>& bornRadii, const std::vector<std::vector<double> >& atomParameters,
double solventDielectric, double soluteDielectric);
/**
* Execute the kernel.
* 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 GBSAOBCForceField
*/
double execute(const Stream& positions);
double executeEnergy(const Stream& positions);
};
/**
......
......@@ -45,10 +45,8 @@ ReferencePlatform* staticPlatform = registerReferencePlatform();
ReferencePlatform::ReferencePlatform() {
ReferenceKernelFactory* factory = new ReferenceKernelFactory();
registerKernelFactory(CalcStandardMMForcesKernel::Name(), factory);
registerKernelFactory(CalcStandardMMEnergyKernel::Name(), factory);
registerKernelFactory(CalcGBSAOBCForcesKernel::Name(), factory);
registerKernelFactory(CalcGBSAOBCEnergyKernel::Name(), factory);
registerKernelFactory(CalcStandardMMForceFieldKernel::Name(), factory);
registerKernelFactory(CalcGBSAOBCForceFieldKernel::Name(), factory);
registerKernelFactory(IntegrateVerletStepKernel::Name(), factory);
registerKernelFactory(IntegrateLangevinStepKernel::Name(), factory);
registerKernelFactory(IntegrateBrownianStepKernel::Name(), factory);
......
......@@ -68,7 +68,7 @@ ReferenceAngleBondIxn::~ReferenceAngleBondIxn( ){
Get dEdR and energy term for angle bond
@param cosine cosine of angle
@param angleParameters angleParameters: angleParameters[0] = angle in degrees
@param angleParameters angleParameters: angleParameters[0] = angle in radians
angleParameters[1] = k (force constant)
@param dEdR output dEdR
@param energyTerm output energyTerm
......@@ -98,7 +98,7 @@ int ReferenceAngleBondIxn::getPrefactorsGivenAngleCosine( RealOpenMM cosine, Rea
} else {
angle = ACOS(cosine);
}
RealOpenMM deltaIdeal = angle - (angleParameters[0]*DEGREE_TO_RADIAN);
RealOpenMM deltaIdeal = angle - angleParameters[0];
RealOpenMM deltaIdeal2 = deltaIdeal*deltaIdeal;
*dEdR = angleParameters[1]*deltaIdeal;
......
......@@ -56,7 +56,7 @@ class ReferenceAngleBondIxn : public ReferenceBondIxn {
Get dEdR and energy term for angle bond
@param cosine cosine of angle
@param angleParameters angleParameters: angleParameters[0] = angle in degrees
@param angleParameters angleParameters: angleParameters[0] = angle in radians
angleParameters[1] = k (force constant)
@param dEdR output dEdR
@param energyTerm output energyTerm
......
......@@ -28,20 +28,20 @@
#include "../SimTKUtilities/SimTKOpenMMCommon.h"
#include "../SimTKUtilities/SimTKOpenMMLog.h"
#include "../SimTKUtilities/SimTKOpenMMUtilities.h"
#include "ReferenceLJ14.h"
#include "ReferenceLJCoulomb14.h"
#include "ReferenceForce.h"
/**---------------------------------------------------------------------------------------
ReferenceLJ14 constructor
ReferenceLJCoulomb14 constructor
--------------------------------------------------------------------------------------- */
ReferenceLJ14::ReferenceLJ14( ){
ReferenceLJCoulomb14::ReferenceLJCoulomb14( ){
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceLJ14::ReferenceLJ14";
// static const char* methodName = "\nReferenceLJCoulomb14::ReferenceLJCoulomb14";
// ---------------------------------------------------------------------------------------
......@@ -49,15 +49,15 @@ ReferenceLJ14::ReferenceLJ14( ){
/**---------------------------------------------------------------------------------------
ReferenceLJ14 destructor
ReferenceLJCoulomb14 destructor
--------------------------------------------------------------------------------------- */
ReferenceLJ14::~ReferenceLJ14( ){
ReferenceLJCoulomb14::~ReferenceLJCoulomb14( ){
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceLJ14::~ReferenceLJ14";
// static const char* methodName = "\nReferenceLJCoulomb14::~ReferenceLJCoulomb14";
// ---------------------------------------------------------------------------------------
......@@ -71,7 +71,7 @@ ReferenceLJ14::~ReferenceLJ14( ){
@param c12 c12
@param q1 q1 charge atom 1
@param q2 q2 charge atom 2
@param epsfac epsfac ????????????/
@param epsfac epsfac ????????????
@param parameters output parameters:
parameter[0]= c6*c6/c12
parameter[1]= (c12/c6)**1/6
......@@ -81,13 +81,13 @@ ReferenceLJ14::~ReferenceLJ14( ){
--------------------------------------------------------------------------------------- */
int ReferenceLJ14::getDerivedParameters( RealOpenMM c6, RealOpenMM c12, RealOpenMM q1,
int ReferenceLJCoulomb14::getDerivedParameters( RealOpenMM c6, RealOpenMM c12, RealOpenMM q1,
RealOpenMM q2, RealOpenMM epsfac,
RealOpenMM* parameters ) const {
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceLJ14::getDerivedParameters";
// static const char* methodName = "\nReferenceLJCoulomb14::getDerivedParameters";
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
......@@ -114,10 +114,10 @@ int ReferenceLJ14::getDerivedParameters( RealOpenMM c6, RealOpenMM c12, RealOpen
@param atomIndices atom indices of 4 atoms in bond
@param atomCoordinates atom coordinates
@param parameters two parameters:
parameter[0]= c6*c6/c12
parameter[1]= (c12/c6)**1/6
parameter[2]= epsfac*q1*q2
@param parameters three parameters:
parameters[0]= (c12/c6)**1/6 (sigma)
parameters[1]= c6*c6/c12 (4*epsilon)
parameters[2]= epsfac*q1*q2
@param forces force array (forces added to current values)
@param energiesByBond energies by bond: energiesByBond[bondIndex]
@param energiesByAtom energies by atom: energiesByAtom[atomIndex]
......@@ -126,18 +126,18 @@ int ReferenceLJ14::getDerivedParameters( RealOpenMM c6, RealOpenMM c12, RealOpen
--------------------------------------------------------------------------------------- */
int ReferenceLJ14::calculateBondIxn( int* atomIndices, RealOpenMM** atomCoordinates,
int ReferenceLJCoulomb14::calculateBondIxn( int* atomIndices, RealOpenMM** atomCoordinates,
RealOpenMM* parameters, RealOpenMM** forces,
RealOpenMM* energiesByBond,
RealOpenMM* energiesByAtom ) const {
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceLJ14::calculateBondIxn";
// static const char* methodName = "\nReferenceLJCoulomb14::calculateBondIxn";
// ---------------------------------------------------------------------------------------
static const std::string methodName = "\nReferenceLJ14::calculateBondIxn";
static const std::string methodName = "\nReferenceLJCoulomb14::calculateBondIxn";
// constants -- reduce Visual Studio warnings regarding conversions between float & double
......@@ -172,11 +172,11 @@ int ReferenceLJ14::calculateBondIxn( int* atomIndices, RealOpenMM** atomCoordina
ReferenceForce::getDeltaR( atomCoordinates[atomBIndex], atomCoordinates[atomAIndex], deltaR[0] );
RealOpenMM inverseR = one/(deltaR[0][ReferenceForce::RIndex]);
RealOpenMM sig2 = inverseR*parameters[1];
RealOpenMM sig2 = inverseR*parameters[0];
sig2 *= sig2;
RealOpenMM sig6 = sig2*sig2*sig2;
RealOpenMM dEdR = parameters[0]*( twelve*sig6 - six )*sig6;
RealOpenMM dEdR = parameters[1]*( twelve*sig6 - six )*sig6;
dEdR += parameters[2]*inverseR;
dEdR *= inverseR*inverseR;
......@@ -188,11 +188,11 @@ int ReferenceLJ14::calculateBondIxn( int* atomIndices, RealOpenMM** atomCoordina
forces[atomBIndex][ii] -= force;
}
RealOpenMM energy = 0.0;
RealOpenMM energy = parameters[1]*( sig6 - one )*sig6 + parameters[2]*inverseR;
// accumulate energies
//updateEnergy( energy, energiesByBond, LastAtomIndex, atomIndices, energiesByAtom );
updateEnergy( energy, energiesByBond, LastAtomIndex, atomIndices, energiesByAtom );
// debug
......
......@@ -22,14 +22,14 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __ReferenceLJ14_H__
#define __ReferenceLJ14_H__
#ifndef __ReferenceLJCoulomb14_H__
#define __ReferenceLJCoulomb14_H__
#include "ReferenceBondIxn.h"
// ---------------------------------------------------------------------------------------
class ReferenceLJ14 : public ReferenceBondIxn {
class ReferenceLJCoulomb14 : public ReferenceBondIxn {
private:
......@@ -41,7 +41,7 @@ class ReferenceLJ14 : public ReferenceBondIxn {
--------------------------------------------------------------------------------------- */
ReferenceLJ14( );
ReferenceLJCoulomb14( );
/**---------------------------------------------------------------------------------------
......@@ -49,7 +49,7 @@ class ReferenceLJ14 : public ReferenceBondIxn {
--------------------------------------------------------------------------------------- */
~ReferenceLJ14( );
~ReferenceLJCoulomb14( );
/**---------------------------------------------------------------------------------------
......@@ -59,7 +59,7 @@ class ReferenceLJ14 : public ReferenceBondIxn {
@param c12 c12
@param q1 q1 charge atom 1
@param q2 q2 charge atom 2
@param epsfac epsfac ????????????/
@param epsfac epsfac ????????????
@param parameters output parameters:
parameter[0]= c6*c6/c12
parameter[1]= (c12/c6)**1/6
......@@ -69,7 +69,7 @@ class ReferenceLJ14 : public ReferenceBondIxn {
--------------------------------------------------------------------------------------- */
int ReferenceLJ14::getDerivedParameters( RealOpenMM c6, RealOpenMM c12, RealOpenMM q1,
int ReferenceLJCoulomb14::getDerivedParameters( RealOpenMM c6, RealOpenMM c12, RealOpenMM q1,
RealOpenMM q2, RealOpenMM epsfac,
RealOpenMM* parameters ) const;
......@@ -97,4 +97,4 @@ class ReferenceLJ14 : public ReferenceBondIxn {
// ---------------------------------------------------------------------------------------
#endif // __ReferenceLJ14_H__
#endif // __ReferenceLJCoulomb14_H__
......@@ -70,10 +70,10 @@ ReferenceLJCoulombIxn::~ReferenceLJCoulombIxn( ){
@param c6 c6
@param c12 c12
@param q1 q1 charge atom 1
@param epsfac epsfacSqrt ????????????/
@param epsfac epsfacSqrt ????????????
@param parameters output parameters:
parameter[SigIndex] = sqrt(c6*c6/c12)
parameter[EpsIndex] = 0.5*( (c12/c6)**1/6 )
parameter[SigIndex] = 0.5*( (c12/c6)**1/6 ) (sigma/2)
parameter[EpsIndex] = sqrt(c6*c6/c12) (2*sqrt(epsilon))
parameter[QIndex] = epsfactorSqrt*q1
@return ReferenceForce::DefaultReturn
......@@ -218,11 +218,16 @@ int ReferenceLJCoulombIxn::calculatePairIxn( int numberOfAtoms, RealOpenMM** ato
// accumulate energies
if( totalEnergy || energyByAtom ) {
energy = atomParameters[ii][QIndex]*atomParameters[jj][QIndex]*inverseR;
energy += eps*(sig6-one)*sig6;
if( totalEnergy )
*totalEnergy += energy;
if( energyByAtom ){
energyByAtom[ii] += energy;
energyByAtom[jj] += energy;
}
}
// debug
......
......@@ -70,7 +70,7 @@ ReferenceProperDihedralBond::~ReferenceProperDihedralBond( ){
@param atomIndices atom indices of 4 atoms in bond
@param atomCoordinates atom coordinates
@param parameters 3 parameters: parameters[0] = k
parameters[1] = ideal bond angle in degrees
parameters[1] = ideal bond angle in radians
parameters[2] = multiplicity
@param forces force array (forces added to current values)
@param energiesByBond energies by bond: energiesByBond[bondIndex]
......@@ -145,7 +145,7 @@ int ReferenceProperDihedralBond::calculateBondIxn( int* atomIndices,
// evaluate delta angle, dE/d(angle)
RealOpenMM deltaAngle = parameters[2]*dihedralAngle - (parameters[1]*DEGREE_TO_RADIAN);
RealOpenMM deltaAngle = parameters[2]*dihedralAngle - parameters[1];
RealOpenMM sinDeltaAngle = SIN( deltaAngle );
RealOpenMM dEdAngle = -parameters[0]*parameters[2]*sinDeltaAngle;
RealOpenMM energy = parameters[0]*(one + COS( deltaAngle ) );
......
......@@ -58,7 +58,7 @@ class ReferenceProperDihedralBond : public ReferenceBondIxn {
@param atomIndices atom indices of 4 atoms in bond
@param atomCoordinates atom coordinates
@param parameters 3 parameters: parameters[0] = k
parameters[1] = ideal bond angle in degrees
parameters[1] = ideal bond angle in radians
parameters[2] = multiplicity
@param forces force array (forces added to current values)
@param energiesByBond energies by bond: energiesByBond[bondIndex]
......
/* Portions copyright (c) 2006 Stanford University and Simbios.
* Contributors: Pande Group
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <new>
#include <stdio.h>
// Replacement new/delete w/ Gromac's smalloc() and sfree()
extern "C" {
#include "smalloc.h"
}
/* ---------------------------------------------------------------------------------------
Override C++ new w/ Gromac's smalloc/sfree (Simbios)
@param size bytes to allocate
@return ptr to allocated memory
--------------------------------------------------------------------------------------- */
void* operator new( size_t size ){
void *ptr;
smalloc(ptr, (int) size);
// (void) fprintf( stdout, "\nGlobal override new called -- size=%u", size );
// (void) fflush( stdout );
return ptr;
}
/* ---------------------------------------------------------------------------------------
Override C++ delete w/ Gromac's sfree (Simbios)
@param ptr ptr to block to free
--------------------------------------------------------------------------------------- */
void operator delete( void *ptr ){
// (void) fprintf( stdout, "\nGlobal override delete called." );
// (void) fflush( stdout );
sfree( ptr );
}
/* Portions copyright (c) 2006 Stanford University and Simbios.
* Contributors: Pande Group
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <new>
#include <stdio.h>
// Replacement new/delete w/ Gromac's smalloc() and sfree()
extern "C" {
#include "smalloc.h"
}
/* ---------------------------------------------------------------------------------------
Override C++ new w/ Gromac's smalloc/sfree (Simbios)
@param size bytes to allocate
@return ptr to allocated memory
--------------------------------------------------------------------------------------- */
void* operator new( size_t size ){
void *ptr;
smalloc(ptr, (int) size);
// (void) fprintf( stdout, "\nGlobal override new called -- size=%u", size );
// (void) fflush( stdout );
return ptr;
}
/* ---------------------------------------------------------------------------------------
Override C++ delete w/ Gromac's sfree (Simbios)
@param ptr ptr to block to free
--------------------------------------------------------------------------------------- */
void operator delete( void *ptr ){
// (void) fprintf( stdout, "\nGlobal override delete called." );
// (void) fflush( stdout );
sfree( ptr );
}
#
# Testing
#
ENABLE_TESTING()
# Automatically create tests using files named "Test*.cpp"
FILE(GLOB TEST_PROGS "*Test*.cpp")
FOREACH(TEST_PROG ${TEST_PROGS})
GET_FILENAME_COMPONENT(TEST_ROOT ${TEST_PROG} NAME_WE)
# Link with shared library
ADD_EXECUTABLE(${TEST_ROOT} ${TEST_PROG})
TARGET_LINK_LIBRARIES(${TEST_ROOT} ${SHARED_TARGET})
ADD_TEST(${TEST_ROOT} ${EXECUTABLE_OUTPUT_PATH}/${TEST_ROOT})
# Link with static library
# SET(TEST_STATIC ${TEST_ROOT}Static)
# ADD_EXECUTABLE(${TEST_STATIC} ${TEST_PROG})
# SET_TARGET_PROPERTIES(${TEST_STATIC}
# PROPERTIES
# COMPILE_FLAGS "-DOPENMM_USE_STATIC_LIBRARIES"
# )
# TARGET_LINK_LIBRARIES(${TEST_STATIC} ${STATIC_TARGET})
# ADD_TEST(${TEST_STATIC} ${EXECUTABLE_OUTPUT_PATH}/${TEST_STATIC})
ENDFOREACH(TEST_PROG ${TEST_PROGS})
......@@ -37,6 +37,7 @@
*/
#include "OpenMMException.h"
#include <cmath>
#include <string>
#include <sstream>
......@@ -57,4 +58,8 @@ void throwException(const char* file, int line, const std::string& details) {
#define ASSERT_EQUAL(expected, found) {if ((expected) != (found)) {std::stringstream details; details << "Expected "<<(expected)<<", found "<<(found); throwException(__FILE__, __LINE__, details.str());}};
#define ASSERT_EQUAL_TOL(expected, found, tol) {double scale = std::max(1.0, std::fabs(expected)); if (std::fabs(expected-found)/scale > tol) {std::stringstream details; details << "Expected "<<(expected)<<", found "<<(found); throwException(__FILE__, __LINE__, details.str());}};
#define ASSERT_EQUAL_VEC(expected, found, tol) {ASSERT_EQUAL_TOL(expected[0], found[0], tol); ASSERT_EQUAL_TOL(expected[1], found[1], tol); ASSERT_EQUAL_TOL(expected[2], found[2], tol);};
#endif /*OPENMM_ASSERTIONUTILITIES_H_*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment