Skip to content

Commit

Permalink
Merge pull request #1747 from peastman/realtype
Browse files Browse the repository at this point in the history
Eliminated RealOpenMM
  • Loading branch information
peastman committed Feb 23, 2017
2 parents b84e22b + 6813ca5 commit 8469621
Show file tree
Hide file tree
Showing 151 changed files with 5,893 additions and 6,881 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ IF (NOT (ANDROID OR PNACL OR (WIN32 AND OPENMM_BUILD_STATIC_LIB)))
SET(SOURCE_INCLUDE_FILES ${SOURCE_INCLUDE_FILES} ${incl_files})
INCLUDE_DIRECTORIES(BEFORE "${CMAKE_CURRENT_SOURCE_DIR}/libraries/asmjit")
SET(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DLEPTON_USE_JIT")
ENDIF (NOT (ANDROID OR PNACL))
ENDIF (NOT (ANDROID OR PNACL OR (WIN32 AND OPENMM_BUILD_STATIC_LIB)))

# If API wrappers are being generated, and add them to the build.
SET(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS ON CACHE BOOL "Build wrappers for C and Fortran")
Expand Down
10 changes: 0 additions & 10 deletions docs-source/developerguide/developer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,6 @@ that is the goal.) When implementing a new feature, it is recommended to create
the reference implementation first, then use that as a model for the versions in
other Platforms.

The reference Platform represents all floating point numbers with the type
RealOpenMM, which is defined in SimTKOpenMMRealType.h. This allows the entire
platform to be compiled in either single or double precision. By default it is
double precision, but it can be changed by modifying one flag at the top of that
file. The same file also defines lots of numerical constants and mathematical
functions, so the correct precision version will always be used. Vector
quantities (positions, velocities, etc.) are represented by RealVec objects.
This class is identical to Vec3, except that its components are of type
RealOpenMM instead of double.

When using the reference Platform, the “platform-specific data” stored in
ContextImpl is of type ReferencePlatform::PlatformData, which is declared in
ReferencePlatform.h. Several of the fields in this class are declared as void*
Expand Down
8 changes: 4 additions & 4 deletions platforms/cpu/include/CpuBondForce.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ class OPENMM_EXPORT_CPU CpuBondForce {
/**
* Compute the forces from all bonds.
*/
void calculateForce(std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM** parameters, std::vector<OpenMM::RealVec>& forces,
RealOpenMM* totalEnergy, ReferenceBondIxn& referenceBondIxn);
void calculateForce(std::vector<OpenMM::Vec3>& atomCoordinates, double** parameters, std::vector<OpenMM::Vec3>& forces,
double* totalEnergy, ReferenceBondIxn& referenceBondIxn);
/**
* This routine contains the code executed by each thread.
*/
void threadComputeForce(ThreadPool& threads, int threadIndex, std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM** parameters,
std::vector<OpenMM::RealVec>& forces, RealOpenMM* totalEnergy, ReferenceBondIxn& referenceBondIxn);
void threadComputeForce(ThreadPool& threads, int threadIndex, std::vector<OpenMM::Vec3>& atomCoordinates, double** parameters,
std::vector<OpenMM::Vec3>& forces, double* totalEnergy, ReferenceBondIxn& referenceBondIxn);
private:
bool canAssignBond(int bond, int thread, std::vector<int>& atomThread);
void assignBond(int bond, int thread, std::vector<int>& atomThread, std::vector<int>& bondThread, std::vector<std::set<int> >& atomBonds, std::list<int>& candidateBonds);
Expand Down
20 changes: 10 additions & 10 deletions platforms/cpu/include/CpuCustomGBForce.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CpuCustomGBForce {
// The following variables are used to make information accessible to the individual threads.
int numberOfAtoms;
float* posq;
RealOpenMM** atomParameters;
double** atomParameters;
const std::map<std::string, double>* globalParameters;
std::vector<AlignedArray<float> >* threadForce;
bool includeForce, includeEnergy;
Expand All @@ -81,7 +81,7 @@ class CpuCustomGBForce {
* @param useExclusions specifies whether to use exclusions
*/

void calculateParticlePairValue(int index, ThreadData& data, int numAtoms, float* posq, RealOpenMM** atomParameters,
void calculateParticlePairValue(int index, ThreadData& data, int numAtoms, float* posq, double** atomParameters,
bool useExclusions, const fvec4& boxSize, const fvec4& invBoxSize);

/**
Expand All @@ -95,7 +95,7 @@ class CpuCustomGBForce {
* @param atomParameters atomParameters[atomIndex][paramterIndex]
*/

void calculateOnePairValue(int index, int atom1, int atom2, ThreadData& data, float* posq, RealOpenMM** atomParameters,
void calculateOnePairValue(int index, int atom1, int atom2, ThreadData& data, float* posq, double** atomParameters,
std::vector<float>& valueArray, const fvec4& boxSize, const fvec4& invBoxSize);

/**
Expand All @@ -110,7 +110,7 @@ class CpuCustomGBForce {
* @param totalEnergy the energy contribution is added to this
*/

void calculateSingleParticleEnergyTerm(int index, ThreadData& data, int numAtoms, float* posq, RealOpenMM** atomParameters, float* forces, double& totalEnergy);
void calculateSingleParticleEnergyTerm(int index, ThreadData& data, int numAtoms, float* posq, double** atomParameters, float* forces, double& totalEnergy);

/**
* Calculate an energy term that is based on particle pairs
Expand All @@ -125,7 +125,7 @@ class CpuCustomGBForce {
* @param totalEnergy the energy contribution is added to this
*/

void calculateParticlePairEnergyTerm(int index, ThreadData& data, int numAtoms, float* posq, RealOpenMM** atomParameters,
void calculateParticlePairEnergyTerm(int index, ThreadData& data, int numAtoms, float* posq, double** atomParameters,
bool useExclusions, float* forces, double& totalEnergy, const fvec4& boxSize, const fvec4& invBoxSize);

/**
Expand All @@ -141,7 +141,7 @@ class CpuCustomGBForce {
* @param totalEnergy the energy contribution is added to this
*/

void calculateOnePairEnergyTerm(int index, int atom1, int atom2, ThreadData& data, float* posq, RealOpenMM** atomParameters,
void calculateOnePairEnergyTerm(int index, int atom1, int atom2, ThreadData& data, float* posq, double** atomParameters,
float* forces, double& totalEnergy, const fvec4& boxSize, const fvec4& invBoxSize);

/**
Expand All @@ -154,7 +154,7 @@ class CpuCustomGBForce {
* @param forces forces on atoms are added to this
*/

void calculateChainRuleForces(ThreadData& data, int numAtoms, float* posq, RealOpenMM** atomParameters,
void calculateChainRuleForces(ThreadData& data, int numAtoms, float* posq, double** atomParameters,
float* forces, const fvec4& boxSize, const fvec4& invBoxSize);

/**
Expand All @@ -169,7 +169,7 @@ class CpuCustomGBForce {
* @param isExcluded specifies whether this is an excluded pair
*/

void calculateOnePairChainRule(int atom1, int atom2, ThreadData& data, float* posq, RealOpenMM** atomParameters,
void calculateOnePairChainRule(int atom1, int atom2, ThreadData& data, float* posq, double** atomParameters,
float* forces, bool isExcluded, const fvec4& boxSize, const fvec4& invBoxSize);

/**
Expand Down Expand Up @@ -217,7 +217,7 @@ class CpuCustomGBForce {
* @param boxSize the X, Y, and Z widths of the periodic box
*/

void setPeriodic(RealVec& boxSize);
void setPeriodic(Vec3& boxSize);

/**
* Calculate custom GB ixn
Expand All @@ -231,7 +231,7 @@ class CpuCustomGBForce {
* @param energyParamDerivs derivatives of the energy with respect to global parameters
*/

void calculateIxn(int numberOfAtoms, float* posq, RealOpenMM** atomParameters, std::map<std::string, double>& globalParameters,
void calculateIxn(int numberOfAtoms, float* posq, double** atomParameters, std::map<std::string, double>& globalParameters,
std::vector<AlignedArray<float> >& threadForce, bool includeForce, bool includeEnergy, double& totalEnergy, double* energyParamDerivs);
};

Expand Down
16 changes: 8 additions & 8 deletions platforms/cpu/include/CpuCustomManyParticleForce.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class CpuCustomManyParticleForce {
class ThreadData;
int numParticles, numParticlesPerSet, numPerParticleParameters, numTypes;
bool useCutoff, usePeriodic, triclinic, centralParticleMode;
RealOpenMM cutoffDistance;
double cutoffDistance;
float recipBoxSize[3];
RealVec periodicBoxVectors[3];
Vec3 periodicBoxVectors[3];
AlignedArray<fvec4> periodicBoxVec4;
CpuNeighborList* neighborList;
ThreadPool& threads;
Expand All @@ -65,7 +65,7 @@ class CpuCustomManyParticleForce {
std::vector<ThreadData*> threadData;
// The following variables are used to make information accessible to the individual threads.
float* posq;
RealOpenMM** particleParameters;
double** particleParameters;
const std::map<std::string, double>* globalParameters;
std::vector<AlignedArray<float> >* threadForce;
bool includeForces, includeEnergy;
Expand All @@ -81,7 +81,7 @@ class CpuCustomManyParticleForce {
* interaction for each one.
*/
void loopOverInteractions(std::vector<int>& availableParticles, std::vector<int>& particleSet, int loopIndex, int startIndex,
RealOpenMM** particleParameters, float* forces, ThreadData& data, const fvec4& boxSize, const fvec4& invBoxSize);
double** particleParameters, float* forces, ThreadData& data, const fvec4& boxSize, const fvec4& invBoxSize);

/**---------------------------------------------------------------------------------------
Expand All @@ -104,7 +104,7 @@ class CpuCustomManyParticleForce {
* @param boxSize the size of the periodic box
* @param invBoxSize the inverse size of the periodic box
*/
void calculateOneIxn(std::vector<int>& particleSet, RealOpenMM** particleParameters, float* forces, ThreadData& data, const fvec4& boxSize, const fvec4& invBoxSize);
void calculateOneIxn(std::vector<int>& particleSet, double** particleParameters, float* forces, ThreadData& data, const fvec4& boxSize, const fvec4& invBoxSize);

/**
* Compute the displacement and squared distance between two points, optionally using
Expand Down Expand Up @@ -132,7 +132,7 @@ class CpuCustomManyParticleForce {
*
* @param distance the cutoff distance
*/
void setUseCutoff(RealOpenMM distance);
void setUseCutoff(double distance);

/**
* Set the force to use periodic boundary conditions. This requires that a cutoff has
Expand All @@ -141,7 +141,7 @@ class CpuCustomManyParticleForce {
*
* @param periodicBoxVectors the vectors defining the periodic box
*/
void setPeriodic(RealVec* periodicBoxVectors);
void setPeriodic(Vec3* periodicBoxVectors);

/**
* Calculate the interaction.
Expand All @@ -154,7 +154,7 @@ class CpuCustomManyParticleForce {
* @param includeEnergy whether to compute energy
* @param energy the total energy is added to this
*/
void calculateIxn(AlignedArray<float>& posq, RealOpenMM** particleParameters, const std::map<std::string, double>& globalParameters,
void calculateIxn(AlignedArray<float>& posq, double** particleParameters, const std::map<std::string, double>& globalParameters,
std::vector<AlignedArray<float> >& threadForce, bool includeForces, bool includeEnergy, double& energy);
};

Expand Down
20 changes: 10 additions & 10 deletions platforms/cpu/include/CpuCustomNonbondedForce.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CpuCustomNonbondedForce {
--------------------------------------------------------------------------------------- */

void setUseCutoff(RealOpenMM distance, const CpuNeighborList& neighbors);
void setUseCutoff(double distance, const CpuNeighborList& neighbors);

/**---------------------------------------------------------------------------------------
Expand All @@ -88,7 +88,7 @@ class CpuCustomNonbondedForce {
--------------------------------------------------------------------------------------- */

void setUseSwitchingFunction(RealOpenMM distance);
void setUseSwitchingFunction(double distance);

/**---------------------------------------------------------------------------------------
Expand All @@ -100,7 +100,7 @@ class CpuCustomNonbondedForce {
--------------------------------------------------------------------------------------- */

void setPeriodic(RealVec* periodicBoxVectors);
void setPeriodic(Vec3* periodicBoxVectors);

/**---------------------------------------------------------------------------------------
Expand All @@ -118,8 +118,8 @@ class CpuCustomNonbondedForce {
--------------------------------------------------------------------------------------- */

void calculatePairIxn(int numberOfAtoms, float* posq, std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM** atomParameters,
RealOpenMM* fixedParameters, const std::map<std::string, double>& globalParameters,
void calculatePairIxn(int numberOfAtoms, float* posq, std::vector<OpenMM::Vec3>& atomCoordinates, double** atomParameters,
double* fixedParameters, const std::map<std::string, double>& globalParameters,
std::vector<AlignedArray<float> >& threadForce, bool includeForce, bool includeEnergy, double& totalEnergy, double* energyParamDerivs);
private:
class ThreadData;
Expand All @@ -131,9 +131,9 @@ class CpuCustomNonbondedForce {
bool useInteractionGroups;
const CpuNeighborList* neighborList;
float recipBoxSize[3];
RealVec periodicBoxVectors[3];
Vec3 periodicBoxVectors[3];
AlignedArray<fvec4> periodicBoxVec4;
RealOpenMM cutoffDistance, switchingDistance;
double cutoffDistance, switchingDistance;
ThreadPool& threads;
const std::vector<std::set<int> > exclusions;
std::vector<ThreadData*> threadData;
Expand All @@ -143,8 +143,8 @@ class CpuCustomNonbondedForce {
// The following variables are used to make information accessible to the individual threads.
int numberOfAtoms;
float* posq;
RealVec const* atomCoordinates;
RealOpenMM** atomParameters;
Vec3 const* atomCoordinates;
double** atomParameters;
const std::map<std::string, double>* globalParameters;
std::vector<AlignedArray<float> >* threadForce;
bool includeForce, includeEnergy;
Expand Down Expand Up @@ -185,7 +185,7 @@ class CpuCustomNonbondedForce::ThreadData {
CompiledExpressionSet expressionSet;
std::vector<double> particleParam;
double r;
std::vector<RealOpenMM> energyParamDerivs;
std::vector<double> energyParamDerivs;
};

} // namespace OpenMM
Expand Down
48 changes: 24 additions & 24 deletions platforms/cpu/include/CpuGayBerneForce.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "openmm/internal/ThreadPool.h"
#include "CpuNeighborList.h"
#include "CpuPlatform.h"
#include "RealVec.h"
#include "openmm/Vec3.h"
#include <set>
#include <utility>

Expand All @@ -61,7 +61,7 @@ class CpuGayBerneForce {
* @param data the platform data for the current context
* @return the energy of the interaction
*/
RealOpenMM calculateForce(const std::vector<RealVec>& positions, std::vector<RealVec>& forces, std::vector<AlignedArray<float> >& threadForce, RealVec* boxVectors, CpuPlatform::PlatformData& data);
double calculateForce(const std::vector<Vec3>& positions, std::vector<Vec3>& forces, std::vector<AlignedArray<float> >& threadForce, Vec3* boxVectors, CpuPlatform::PlatformData& data);

/**
* This routine contains the code executed by each thread.
Expand All @@ -81,43 +81,43 @@ class CpuGayBerneForce {
std::set<std::pair<int, int> > exclusions;
std::vector<std::set<int> > particleExclusions;
GayBerneForce::NonbondedMethod nonbondedMethod;
RealOpenMM cutoffDistance, switchingDistance;
double cutoffDistance, switchingDistance;
bool useSwitchingFunction;
std::vector<RealOpenMM> s;
std::vector<double> s;
std::vector<Matrix> A, B, G;
std::vector<double> threadEnergy;
std::vector<std::vector<RealVec> > threadTorque;
std::vector<std::vector<Vec3> > threadTorque;
// The following variables are used to make information accessible to the individual threads.
RealVec const* positions;
Vec3 const* positions;
std::vector<AlignedArray<float> >* threadForce;
RealVec* boxVectors;
Vec3* boxVectors;
void* atomicCounter;

void computeEllipsoidFrames(const std::vector<RealVec>& positions);
void computeEllipsoidFrames(const std::vector<Vec3>& positions);

void applyTorques(const std::vector<RealVec>& positions, std::vector<RealVec>& forces);
void applyTorques(const std::vector<Vec3>& positions, std::vector<Vec3>& forces);

RealOpenMM computeOneInteraction(int particle1, int particle2, RealOpenMM sigma, RealOpenMM epsilon, const RealVec* positions,
float* forces, std::vector<RealVec>& torques, const RealVec* boxVectors);
double computeOneInteraction(int particle1, int particle2, double sigma, double epsilon, const Vec3* positions,
float* forces, std::vector<Vec3>& torques, const Vec3* boxVectors);
};

struct CpuGayBerneForce::ParticleInfo {
int xparticle, yparticle;
RealOpenMM sigmaOver2, sqrtEpsilon, rx, ry, rz, ex, ey, ez;
double sigmaOver2, sqrtEpsilon, rx, ry, rz, ex, ey, ez;
bool isPointParticle;
};

struct CpuGayBerneForce::ExceptionInfo {
int particle1, particle2;
RealOpenMM sigma, epsilon;
double sigma, epsilon;
};

struct CpuGayBerneForce::Matrix {
RealOpenMM v[3][3];
RealVec operator*(const RealVec& r) {
return RealVec(v[0][0]*r[0] + v[0][1]*r[1] + v[0][2]*r[2],
v[1][0]*r[0] + v[1][1]*r[1] + v[1][2]*r[2],
v[2][0]*r[0] + v[2][1]*r[1] + v[2][2]*r[2]);
double v[3][3];
Vec3 operator*(const Vec3& r) {
return Vec3(v[0][0]*r[0] + v[0][1]*r[1] + v[0][2]*r[2],
v[1][0]*r[0] + v[1][1]*r[1] + v[1][2]*r[2],
v[2][0]*r[0] + v[2][1]*r[1] + v[2][2]*r[2]);
}

Matrix operator+(const Matrix& m) {
Expand All @@ -128,13 +128,13 @@ struct CpuGayBerneForce::Matrix {
return result;
}

RealOpenMM determinant() {
double determinant() {
return (v[0][0]*v[1][1]*v[2][2] + v[0][1]*v[1][2]*v[2][0] + v[0][2]*v[1][0]*v[2][1] -
v[0][0]*v[1][2]*v[2][1] - v[0][1]*v[1][0]*v[2][2] - v[0][2]*v[1][1]*v[2][0]);
}

Matrix inverse() {
RealOpenMM invDet = 1/determinant();
double invDet = 1/determinant();
Matrix result;
result.v[0][0] = invDet*(v[1][1]*v[2][2] - v[1][2]*v[2][1]);
result.v[1][0] = -invDet*(v[1][0]*v[2][2] - v[1][2]*v[2][0]);
Expand All @@ -149,10 +149,10 @@ struct CpuGayBerneForce::Matrix {
}
};

static RealVec operator*(const RealVec& r, CpuGayBerneForce::Matrix& m) {
return RealVec(m.v[0][0]*r[0] + m.v[1][0]*r[1] + m.v[2][0]*r[2],
m.v[0][1]*r[0] + m.v[1][1]*r[1] + m.v[2][1]*r[2],
m.v[0][2]*r[0] + m.v[1][2]*r[1] + m.v[2][2]*r[2]);
static Vec3 operator*(const Vec3& r, CpuGayBerneForce::Matrix& m) {
return Vec3(m.v[0][0]*r[0] + m.v[1][0]*r[1] + m.v[2][0]*r[2],
m.v[0][1]*r[0] + m.v[1][1]*r[1] + m.v[2][1]*r[2],
m.v[0][2]*r[0] + m.v[1][2]*r[1] + m.v[2][2]*r[2]);
}

} // namespace OpenMM
Expand Down
Loading

0 comments on commit 8469621

Please sign in to comment.