Commit a783b996 authored by peastman's avatar peastman
Browse files

Eliminated RealOpenMM type

parent 9500f3af
...@@ -34,7 +34,7 @@ class OPENMM_EXPORT ReferenceRbDihedralBond : public ReferenceBondIxn { ...@@ -34,7 +34,7 @@ class OPENMM_EXPORT ReferenceRbDihedralBond : public ReferenceBondIxn {
private: private:
bool usePeriodic; bool usePeriodic;
RealVec boxVectors[3]; Vec3 boxVectors[3];
public: public:
...@@ -62,7 +62,7 @@ class OPENMM_EXPORT ReferenceRbDihedralBond : public ReferenceBondIxn { ...@@ -62,7 +62,7 @@ class OPENMM_EXPORT ReferenceRbDihedralBond : public ReferenceBondIxn {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void setPeriodic(OpenMM::RealVec* vectors); void setPeriodic(OpenMM::Vec3* vectors);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -76,9 +76,9 @@ class OPENMM_EXPORT ReferenceRbDihedralBond : public ReferenceBondIxn { ...@@ -76,9 +76,9 @@ class OPENMM_EXPORT ReferenceRbDihedralBond : public ReferenceBondIxn {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void calculateBondIxn(int* atomIndices, std::vector<OpenMM::RealVec>& atomCoordinates, void calculateBondIxn(int* atomIndices, std::vector<OpenMM::Vec3>& atomCoordinates,
RealOpenMM* parameters, std::vector<OpenMM::RealVec>& forces, double* parameters, std::vector<OpenMM::Vec3>& forces,
RealOpenMM* totalEnergy, double* energyParamDerivs); double* totalEnergy, double* energyParamDerivs);
}; };
......
...@@ -44,7 +44,7 @@ namespace OpenMM { ...@@ -44,7 +44,7 @@ namespace OpenMM {
class OPENMM_EXPORT ReferenceSETTLEAlgorithm : public ReferenceConstraintAlgorithm { class OPENMM_EXPORT ReferenceSETTLEAlgorithm : public ReferenceConstraintAlgorithm {
public: public:
ReferenceSETTLEAlgorithm(const std::vector<int>& atom1, const std::vector<int>& atom2, const std::vector<int>& atom3, ReferenceSETTLEAlgorithm(const std::vector<int>& atom1, const std::vector<int>& atom2, const std::vector<int>& atom3,
const std::vector<RealOpenMM>& distance1, const std::vector<RealOpenMM>& distance2, std::vector<RealOpenMM>& masses); const std::vector<double>& distance1, const std::vector<double>& distance2, std::vector<double>& masses);
/** /**
* Get the number of clusters. * Get the number of clusters.
...@@ -60,7 +60,7 @@ public: ...@@ -60,7 +60,7 @@ public:
* @param distance1 the distance between atoms 1 and 2 * @param distance1 the distance between atoms 1 and 2
* @param distance2 the distance between atoms 2 and 3 * @param distance2 the distance between atoms 2 and 3
*/ */
void getClusterParameters(int index, int& atom1, int& atom2, int& atom3, RealOpenMM& distance1, RealOpenMM& distance2) const; void getClusterParameters(int index, int& atom1, int& atom2, int& atom3, double& distance1, double& distance2) const;
/** /**
* Apply the constraint algorithm. * Apply the constraint algorithm.
* *
...@@ -69,7 +69,7 @@ public: ...@@ -69,7 +69,7 @@ public:
* @param inverseMasses 1/mass * @param inverseMasses 1/mass
* @param tolerance the constraint tolerance * @param tolerance the constraint tolerance
*/ */
void apply(std::vector<OpenMM::RealVec>& atomCoordinates, std::vector<OpenMM::RealVec>& atomCoordinatesP, std::vector<RealOpenMM>& inverseMasses, RealOpenMM tolerance); void apply(std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<OpenMM::Vec3>& atomCoordinatesP, std::vector<double>& inverseMasses, double tolerance);
/** /**
* Apply the constraint algorithm to velocities. * Apply the constraint algorithm to velocities.
...@@ -79,14 +79,14 @@ public: ...@@ -79,14 +79,14 @@ public:
* @param inverseMasses 1/mass * @param inverseMasses 1/mass
* @param tolerance the constraint tolerance * @param tolerance the constraint tolerance
*/ */
void applyToVelocities(std::vector<OpenMM::RealVec>& atomCoordinates, std::vector<OpenMM::RealVec>& velocities, std::vector<RealOpenMM>& inverseMasses, RealOpenMM tolerance); void applyToVelocities(std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<OpenMM::Vec3>& velocities, std::vector<double>& inverseMasses, double tolerance);
private: private:
std::vector<int> atom1; std::vector<int> atom1;
std::vector<int> atom2; std::vector<int> atom2;
std::vector<int> atom3; std::vector<int> atom3;
std::vector<RealOpenMM> distance1; std::vector<double> distance1;
std::vector<RealOpenMM> distance2; std::vector<double> distance2;
std::vector<RealOpenMM> masses; std::vector<double> masses;
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -34,9 +34,9 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics { ...@@ -34,9 +34,9 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics {
protected: protected:
std::vector<OpenMM::RealVec> xPrime; std::vector<OpenMM::Vec3> xPrime;
std::vector<RealOpenMM> inverseMasses; std::vector<double> inverseMasses;
RealOpenMM friction; double friction;
public: public:
...@@ -51,7 +51,7 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics { ...@@ -51,7 +51,7 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceStochasticDynamics(int numberOfAtoms, RealOpenMM deltaT, RealOpenMM friction, RealOpenMM temperature); ReferenceStochasticDynamics(int numberOfAtoms, double deltaT, double friction, double temperature);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -67,7 +67,7 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics { ...@@ -67,7 +67,7 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM getFriction() const; double getFriction() const;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -82,8 +82,8 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics { ...@@ -82,8 +82,8 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void update(const OpenMM::System& system, std::vector<OpenMM::RealVec>& atomCoordinates, void update(const OpenMM::System& system, std::vector<OpenMM::Vec3>& atomCoordinates,
std::vector<OpenMM::RealVec>& velocities, std::vector<OpenMM::RealVec>& forces, std::vector<RealOpenMM>& masses, RealOpenMM tolerance); std::vector<OpenMM::Vec3>& velocities, std::vector<OpenMM::Vec3>& forces, std::vector<double>& masses, double tolerance);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -98,8 +98,8 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics { ...@@ -98,8 +98,8 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
virtual void updatePart1(int numberOfAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, std::vector<OpenMM::RealVec>& velocities, virtual void updatePart1(int numberOfAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<OpenMM::Vec3>& velocities,
std::vector<OpenMM::RealVec>& forces, std::vector<RealOpenMM>& inverseMasses, std::vector<OpenMM::RealVec>& xPrime); std::vector<OpenMM::Vec3>& forces, std::vector<double>& inverseMasses, std::vector<OpenMM::Vec3>& xPrime);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -113,8 +113,8 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics { ...@@ -113,8 +113,8 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
virtual void updatePart2(int numberOfAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, std::vector<OpenMM::RealVec>& velocities, virtual void updatePart2(int numberOfAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<OpenMM::Vec3>& velocities,
std::vector<OpenMM::RealVec>& forces, std::vector<RealOpenMM>& inverseMasses, std::vector<OpenMM::RealVec>& xPrime); std::vector<OpenMM::Vec3>& forces, std::vector<double>& inverseMasses, std::vector<OpenMM::Vec3>& xPrime);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -127,8 +127,8 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics { ...@@ -127,8 +127,8 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
virtual void updatePart3(int numberOfAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, std::vector<OpenMM::RealVec>& velocities, virtual void updatePart3(int numberOfAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<OpenMM::Vec3>& velocities,
std::vector<RealOpenMM>& inverseMasses, std::vector<OpenMM::RealVec>& xPrime); std::vector<double>& inverseMasses, std::vector<OpenMM::Vec3>& xPrime);
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -33,9 +33,9 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics { ...@@ -33,9 +33,9 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
private: private:
std::vector<OpenMM::RealVec> xPrime; std::vector<OpenMM::Vec3> xPrime;
std::vector<RealOpenMM> inverseMasses; std::vector<double> inverseMasses;
RealOpenMM friction, _accuracy; double friction, _accuracy;
public: public:
...@@ -50,7 +50,7 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics { ...@@ -50,7 +50,7 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceVariableStochasticDynamics(int numberOfAtoms, RealOpenMM friction, RealOpenMM temperature, RealOpenMM accuracy); ReferenceVariableStochasticDynamics(int numberOfAtoms, double friction, double temperature, double accuracy);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -66,7 +66,7 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics { ...@@ -66,7 +66,7 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM getFriction() const; double getFriction() const;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -76,7 +76,7 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics { ...@@ -76,7 +76,7 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM getAccuracy() const; double getAccuracy() const;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -84,7 +84,7 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics { ...@@ -84,7 +84,7 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void setAccuracy(RealOpenMM accuracy); void setAccuracy(double accuracy);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -100,8 +100,8 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics { ...@@ -100,8 +100,8 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void update(const OpenMM::System& system, std::vector<OpenMM::RealVec>& atomCoordinates, void update(const OpenMM::System& system, std::vector<OpenMM::Vec3>& atomCoordinates,
std::vector<OpenMM::RealVec>& velocities, std::vector<OpenMM::RealVec>& forces, std::vector<RealOpenMM>& masses, RealOpenMM maxStepSize, RealOpenMM tolerance); std::vector<OpenMM::Vec3>& velocities, std::vector<OpenMM::Vec3>& forces, std::vector<double>& masses, double maxStepSize, double tolerance);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -118,9 +118,9 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics { ...@@ -118,9 +118,9 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void updatePart1(int numberOfAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, std::vector<OpenMM::RealVec>& velocities, void updatePart1(int numberOfAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<OpenMM::Vec3>& velocities,
std::vector<OpenMM::RealVec>& forces, std::vector<RealOpenMM>& masses, std::vector<RealOpenMM>& inverseMasses, std::vector<OpenMM::Vec3>& forces, std::vector<double>& masses, std::vector<double>& inverseMasses,
std::vector<OpenMM::RealVec>& xPrime, RealOpenMM maxStepSize); std::vector<OpenMM::Vec3>& xPrime, double maxStepSize);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -134,9 +134,9 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics { ...@@ -134,9 +134,9 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void updatePart2(int numberOfAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, std::vector<OpenMM::RealVec>& velocities, void updatePart2(int numberOfAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<OpenMM::Vec3>& velocities,
std::vector<OpenMM::RealVec>& forces, std::vector<RealOpenMM>& inverseMasses, std::vector<OpenMM::Vec3>& forces, std::vector<double>& inverseMasses,
std::vector<OpenMM::RealVec>& xPrime); std::vector<OpenMM::Vec3>& xPrime);
}; };
......
...@@ -33,9 +33,9 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics { ...@@ -33,9 +33,9 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics {
private: private:
std::vector<OpenMM::RealVec> xPrime; std::vector<OpenMM::Vec3> xPrime;
std::vector<RealOpenMM> inverseMasses; std::vector<double> inverseMasses;
RealOpenMM _accuracy; double _accuracy;
public: public:
...@@ -48,7 +48,7 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics { ...@@ -48,7 +48,7 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceVariableVerletDynamics(int numberOfAtoms, RealOpenMM accuracy); ReferenceVariableVerletDynamics(int numberOfAtoms, double accuracy);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -66,7 +66,7 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics { ...@@ -66,7 +66,7 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM getAccuracy() const; double getAccuracy() const;
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -74,7 +74,7 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics { ...@@ -74,7 +74,7 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void setAccuracy(RealOpenMM accuracy); void setAccuracy(double accuracy);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -90,8 +90,8 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics { ...@@ -90,8 +90,8 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void update(const OpenMM::System& system, std::vector<OpenMM::RealVec>& atomCoordinates, void update(const OpenMM::System& system, std::vector<OpenMM::Vec3>& atomCoordinates,
std::vector<OpenMM::RealVec>& velocities, std::vector<OpenMM::RealVec>& forces, std::vector<RealOpenMM>& masses, RealOpenMM maxStepSize, RealOpenMM tolerance); std::vector<OpenMM::Vec3>& velocities, std::vector<OpenMM::Vec3>& forces, std::vector<double>& masses, double maxStepSize, double tolerance);
}; };
......
...@@ -33,8 +33,8 @@ class ReferenceVerletDynamics : public ReferenceDynamics { ...@@ -33,8 +33,8 @@ class ReferenceVerletDynamics : public ReferenceDynamics {
private: private:
std::vector<OpenMM::RealVec> xPrime; std::vector<OpenMM::Vec3> xPrime;
std::vector<RealOpenMM> inverseMasses; std::vector<double> inverseMasses;
public: public:
...@@ -49,7 +49,7 @@ class ReferenceVerletDynamics : public ReferenceDynamics { ...@@ -49,7 +49,7 @@ class ReferenceVerletDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceVerletDynamics(int numberOfAtoms, RealOpenMM deltaT); ReferenceVerletDynamics(int numberOfAtoms, double deltaT);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -72,8 +72,8 @@ class ReferenceVerletDynamics : public ReferenceDynamics { ...@@ -72,8 +72,8 @@ class ReferenceVerletDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void update(const OpenMM::System& system, std::vector<OpenMM::RealVec>& atomCoordinates, void update(const OpenMM::System& system, std::vector<OpenMM::Vec3>& atomCoordinates,
std::vector<OpenMM::RealVec>& velocities, std::vector<OpenMM::RealVec>& forces, std::vector<RealOpenMM>& masses, RealOpenMM tolerance); std::vector<OpenMM::Vec3>& velocities, std::vector<OpenMM::Vec3>& forces, std::vector<double>& masses, double tolerance);
}; };
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#define __ReferenceVirtualSites_H__ #define __ReferenceVirtualSites_H__
#include "openmm/System.h" #include "openmm/System.h"
#include "RealVec.h" #include "openmm/Vec3.h"
#include <vector> #include <vector>
namespace OpenMM { namespace OpenMM {
...@@ -43,11 +43,11 @@ public: ...@@ -43,11 +43,11 @@ public:
/** /**
* Compute the positions of all virtual sites. * Compute the positions of all virtual sites.
*/ */
static void computePositions(const OpenMM::System& system, std::vector<OpenMM::RealVec>& atomCoordinates); static void computePositions(const OpenMM::System& system, std::vector<OpenMM::Vec3>& atomCoordinates);
/** /**
* Distribute forces from virtual sites to the atoms they are based on. * Distribute forces from virtual sites to the atoms they are based on.
*/ */
static void distributeForces(const OpenMM::System& system, const std::vector<OpenMM::RealVec>& atomCoordinates, std::vector<OpenMM::RealVec>& forces); static void distributeForces(const OpenMM::System& system, const std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<OpenMM::Vec3>& forces);
}; };
} // namespace OpenMM } // namespace OpenMM
......
/* Portions copyright (c) 2006 Stanford University and Simbios. /* Portions copyright (c) 2006-2017 Stanford University and Simbios.
* Contributors: Pande Group * Contributors: Pande Group
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
...@@ -28,46 +28,6 @@ ...@@ -28,46 +28,6 @@
#include <cmath> #include <cmath>
// Set RealOpenMMType to 2 for double precision, 1 for float
#ifndef RealOpenMMType
#define RealOpenMMType 2
#endif
#if RealOpenMMType == 1
#define RealOpenMM float
#define SQRT sqrtf
#define POW powf
#define SIN sinf
#define COS cosf
#define TAN tanf
// LOG is used in Vishal's gpu code; modifying LOG -> LN
#define LN logf
#define EXP expf
#define FABS fabsf
#define ACOS acosf
#define ASIN asinf
#define ATAN atanf
#define TANH tanhf
#define FLOOR floorf
#define ATOF atoff
#define PI_M 3.141592653589f
#define TWO_SIX 1.122462048309372981f
#define RADIAN 57.29577951308f
#define RADIAN_TO_DEGREE 57.29577951308f
#define LOG_TEN 2.302585092994045684f
#define SQRT_TWO 1.41421356237309504f
#define DEGREE_TO_RADIAN 0.01745329252f
#define RADIAN_INVERSE 0.01745329252f
#else
#define RealOpenMM double #define RealOpenMM double
#define SQRT sqrt #define SQRT sqrt
#define POW pow #define POW pow
...@@ -98,8 +58,6 @@ ...@@ -98,8 +58,6 @@
#define DEGREE_TO_RADIAN 0.01745329252 #define DEGREE_TO_RADIAN 0.01745329252
#define RADIAN_INVERSE 0.01745329252 #define RADIAN_INVERSE 0.01745329252
#endif
#define DOT3(u,v) ((u[0])*(v[0]) + (u[1])*(v[1]) + (u[2])*(v[2])) #define DOT3(u,v) ((u[0])*(v[0]) + (u[1])*(v[1]) + (u[2])*(v[2]))
#define MATRIXDOT3(u,v) u[0]*v[0] + u[1]*v[1] + u[2]*v[2] + \ #define MATRIXDOT3(u,v) u[0]*v[0] + u[1]*v[1] + u[2]*v[2] + \
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
// class of shared, static utility methods // class of shared, static utility methods
#include "RealVec.h" #include "SimTKOpenMMRealType.h"
#include "sfmt/SFMT.h" #include "sfmt/SFMT.h"
#include "openmm/internal/windowsExport.h" #include "openmm/internal/windowsExport.h"
...@@ -49,7 +49,7 @@ class OPENMM_EXPORT SimTKOpenMMUtilities { ...@@ -49,7 +49,7 @@ class OPENMM_EXPORT SimTKOpenMMUtilities {
static uint32_t _randomNumberSeed; static uint32_t _randomNumberSeed;
static bool _randomInitialized; static bool _randomInitialized;
static bool nextGaussianIsValid; static bool nextGaussianIsValid;
static RealOpenMM nextGaussian; static double nextGaussian;
static OpenMM_SFMT::SFMT sfmt; static OpenMM_SFMT::SFMT sfmt;
public: public:
...@@ -61,7 +61,7 @@ class OPENMM_EXPORT SimTKOpenMMUtilities { ...@@ -61,7 +61,7 @@ class OPENMM_EXPORT SimTKOpenMMUtilities {
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Allocate 1D RealOpenMM array (Simbios) Allocate 1D double array (Simbios)
array[i] array[i]
...@@ -75,13 +75,13 @@ class OPENMM_EXPORT SimTKOpenMMUtilities { ...@@ -75,13 +75,13 @@ class OPENMM_EXPORT SimTKOpenMMUtilities {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
static RealOpenMM* allocateOneDRealOpenMMArray(int iSize, RealOpenMM* array1D, int initialize, static double* allocateOneDRealOpenMMArray(int iSize, double* array1D, int initialize,
RealOpenMM initialValue, double initialValue,
const std::string& idString = std::string("1DArray")); const std::string& idString = std::string("1DArray"));
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Allocate 2D RealOpenMM array (Simbios) Allocate 2D double array (Simbios)
array[i][j] array[i][j]
...@@ -96,14 +96,14 @@ class OPENMM_EXPORT SimTKOpenMMUtilities { ...@@ -96,14 +96,14 @@ class OPENMM_EXPORT SimTKOpenMMUtilities {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
static RealOpenMM** allocateTwoDRealOpenMMArray(int iSize, int jSize, static double** allocateTwoDRealOpenMMArray(int iSize, int jSize,
RealOpenMM** array2D, int initialize, double** array2D, int initialize,
RealOpenMM initialValue, double initialValue,
const std::string& idString = std::string("2DArray")); const std::string& idString = std::string("2DArray"));
/* --------------------------------------------------------------------------------------- /* ---------------------------------------------------------------------------------------
Free 2D RealOpenMM array (Simbios) Free 2D double array (Simbios)
array[i][j] array[i][j]
...@@ -112,12 +112,12 @@ class OPENMM_EXPORT SimTKOpenMMUtilities { ...@@ -112,12 +112,12 @@ class OPENMM_EXPORT SimTKOpenMMUtilities {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
static void freeOneDRealOpenMMArray(RealOpenMM* array1D, static void freeOneDRealOpenMMArray(double* array1D,
const std::string& idString = std::string("1DArray")); const std::string& idString = std::string("1DArray"));
/* --------------------------------------------------------------------------------------- /* ---------------------------------------------------------------------------------------
Free 2D RealOpenMM array (Simbios) Free 2D double array (Simbios)
array[i][j] array[i][j]
...@@ -126,12 +126,12 @@ class OPENMM_EXPORT SimTKOpenMMUtilities { ...@@ -126,12 +126,12 @@ class OPENMM_EXPORT SimTKOpenMMUtilities {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
static void freeTwoDRealOpenMMArray(RealOpenMM** array2D, static void freeTwoDRealOpenMMArray(double** array2D,
const std::string& idString = std::string("2DArray")); const std::string& idString = std::string("2DArray"));
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Initialize 2D RealOpenMM array (Simbios) Initialize 2D double array (Simbios)
array[i][j] array[i][j]
...@@ -143,7 +143,7 @@ class OPENMM_EXPORT SimTKOpenMMUtilities { ...@@ -143,7 +143,7 @@ class OPENMM_EXPORT SimTKOpenMMUtilities {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
static void initialize2DRealOpenMMArray(int iSize, int jSize, static void initialize2DRealOpenMMArray(int iSize, int jSize,
RealOpenMM** array2D, RealOpenMM initialValue); double** array2D, double initialValue);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -159,7 +159,7 @@ class OPENMM_EXPORT SimTKOpenMMUtilities { ...@@ -159,7 +159,7 @@ class OPENMM_EXPORT SimTKOpenMMUtilities {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
static void crossProductVector3(RealOpenMM* vectorX, RealOpenMM* vectorY, RealOpenMM* vectorZ); static void crossProductVector3(double* vectorX, double* vectorY, double* vectorZ);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -169,7 +169,7 @@ class OPENMM_EXPORT SimTKOpenMMUtilities { ...@@ -169,7 +169,7 @@ class OPENMM_EXPORT SimTKOpenMMUtilities {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
static RealOpenMM getNormallyDistributedRandomNumber(); static double getNormallyDistributedRandomNumber();
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -179,7 +179,7 @@ class OPENMM_EXPORT SimTKOpenMMUtilities { ...@@ -179,7 +179,7 @@ class OPENMM_EXPORT SimTKOpenMMUtilities {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
static RealOpenMM getUniformlyDistributedRandomNumber(); static double getUniformlyDistributedRandomNumber();
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include <stdio.h> #include <stdio.h>
#include "RealVec.h"
#include "openmm/internal/windowsExport.h" #include "openmm/internal/windowsExport.h"
#ifdef __cplusplus #ifdef __cplusplus
...@@ -33,15 +32,15 @@ extern "C" { ...@@ -33,15 +32,15 @@ extern "C" {
class t_complex { class t_complex {
public: public:
RealOpenMM re; double re;
RealOpenMM im; double im;
t_complex() : re(0.0), im(0.0) { t_complex() : re(0.0), im(0.0) {
} }
t_complex(RealOpenMM re, RealOpenMM im) : re(re), im(im) { t_complex(double re, double im) : re(re), im(im) {
} }
t_complex(const t_complex& c) : re(c.re), im(c.im) { t_complex(const t_complex& c) : re(c.re), im(c.im) {
} }
t_complex operator*(RealOpenMM r) { t_complex operator*(double r) {
return t_complex(re*r, im*r); return t_complex(re*r, im*r);
} }
t_complex operator+(const t_complex& c) const { t_complex operator+(const t_complex& c) const {
......
...@@ -94,10 +94,10 @@ static int** allocateIntArray(int length, int width) { ...@@ -94,10 +94,10 @@ static int** allocateIntArray(int length, int width) {
return array; return array;
} }
static RealOpenMM** allocateRealArray(int length, int width) { static double** allocateRealArray(int length, int width) {
RealOpenMM** array = new RealOpenMM*[length]; double** array = new double*[length];
for (int i = 0; i < length; ++i) for (int i = 0; i < length; ++i)
array[i] = new RealOpenMM[width]; array[i] = new double[width];
return array; return array;
} }
...@@ -109,7 +109,7 @@ static void disposeIntArray(int** array, int size) { ...@@ -109,7 +109,7 @@ static void disposeIntArray(int** array, int size) {
} }
} }
static void disposeRealArray(RealOpenMM** array, int size) { static void disposeRealArray(double** array, int size) {
if (array) { if (array) {
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
delete[] array[i]; delete[] array[i];
...@@ -117,29 +117,29 @@ static void disposeRealArray(RealOpenMM** array, int size) { ...@@ -117,29 +117,29 @@ static void disposeRealArray(RealOpenMM** array, int size) {
} }
} }
static vector<RealVec>& extractPositions(ContextImpl& context) { static vector<Vec3>& extractPositions(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData()); ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<RealVec>*) data->positions); return *((vector<Vec3>*) data->positions);
} }
static vector<RealVec>& extractVelocities(ContextImpl& context) { static vector<Vec3>& extractVelocities(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData()); ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<RealVec>*) data->velocities); return *((vector<Vec3>*) data->velocities);
} }
static vector<RealVec>& extractForces(ContextImpl& context) { static vector<Vec3>& extractForces(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData()); ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<RealVec>*) data->forces); return *((vector<Vec3>*) data->forces);
} }
static RealVec& extractBoxSize(ContextImpl& context) { static Vec3& extractBoxSize(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData()); ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *(RealVec*) data->periodicBoxSize; return *(Vec3*) data->periodicBoxSize;
} }
static RealVec* extractBoxVectors(ContextImpl& context) { static Vec3* extractBoxVectors(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData()); ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return (RealVec*) data->periodicBoxVectors; return (Vec3*) data->periodicBoxVectors;
} }
static ReferenceConstraints& extractConstraints(ContextImpl& context) { static ReferenceConstraints& extractConstraints(ContextImpl& context) {
...@@ -168,14 +168,14 @@ static void validateVariables(const Lepton::ExpressionTreeNode& node, const set< ...@@ -168,14 +168,14 @@ static void validateVariables(const Lepton::ExpressionTreeNode& node, const set<
* for a leapfrog integrator. * for a leapfrog integrator.
*/ */
static double computeShiftedKineticEnergy(ContextImpl& context, vector<double>& masses, double timeShift) { static double computeShiftedKineticEnergy(ContextImpl& context, vector<double>& masses, double timeShift) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& velData = extractVelocities(context); vector<Vec3>& velData = extractVelocities(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
int numParticles = context.getSystem().getNumParticles(); int numParticles = context.getSystem().getNumParticles();
// Compute the shifted velocities. // Compute the shifted velocities.
vector<RealVec> shiftedVel(numParticles); vector<Vec3> shiftedVel(numParticles);
for (int i = 0; i < numParticles; ++i) { for (int i = 0; i < numParticles; ++i) {
if (masses[i] > 0) if (masses[i] > 0)
shiftedVel[i] = velData[i]+forceData[i]*(timeShift/masses[i]); shiftedVel[i] = velData[i]+forceData[i]*(timeShift/masses[i]);
...@@ -203,13 +203,13 @@ void ReferenceCalcForcesAndEnergyKernel::initialize(const System& system) { ...@@ -203,13 +203,13 @@ void ReferenceCalcForcesAndEnergyKernel::initialize(const System& system) {
} }
void ReferenceCalcForcesAndEnergyKernel::beginComputation(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) { void ReferenceCalcForcesAndEnergyKernel::beginComputation(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) {
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
if (includeForces) { if (includeForces) {
int numParticles = context.getSystem().getNumParticles(); int numParticles = context.getSystem().getNumParticles();
for (int i = 0; i < numParticles; ++i) { for (int i = 0; i < numParticles; ++i) {
forceData[i][0] = (RealOpenMM) 0.0; forceData[i][0] = 0.0;
forceData[i][1] = (RealOpenMM) 0.0; forceData[i][1] = 0.0;
forceData[i][2] = (RealOpenMM) 0.0; forceData[i][2] = 0.0;
} }
} }
else else
...@@ -239,7 +239,7 @@ void ReferenceUpdateStateDataKernel::setTime(ContextImpl& context, double time) ...@@ -239,7 +239,7 @@ void ReferenceUpdateStateDataKernel::setTime(ContextImpl& context, double time)
void ReferenceUpdateStateDataKernel::getPositions(ContextImpl& context, std::vector<Vec3>& positions) { void ReferenceUpdateStateDataKernel::getPositions(ContextImpl& context, std::vector<Vec3>& positions) {
int numParticles = context.getSystem().getNumParticles(); int numParticles = context.getSystem().getNumParticles();
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
positions.resize(numParticles); positions.resize(numParticles);
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < numParticles; ++i)
positions[i] = Vec3(posData[i][0], posData[i][1], posData[i][2]); positions[i] = Vec3(posData[i][0], posData[i][1], posData[i][2]);
...@@ -247,17 +247,17 @@ void ReferenceUpdateStateDataKernel::getPositions(ContextImpl& context, std::vec ...@@ -247,17 +247,17 @@ void ReferenceUpdateStateDataKernel::getPositions(ContextImpl& context, std::vec
void ReferenceUpdateStateDataKernel::setPositions(ContextImpl& context, const std::vector<Vec3>& positions) { void ReferenceUpdateStateDataKernel::setPositions(ContextImpl& context, const std::vector<Vec3>& positions) {
int numParticles = context.getSystem().getNumParticles(); int numParticles = context.getSystem().getNumParticles();
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
for (int i = 0; i < numParticles; ++i) { for (int i = 0; i < numParticles; ++i) {
posData[i][0] = (RealOpenMM) positions[i][0]; posData[i][0] = positions[i][0];
posData[i][1] = (RealOpenMM) positions[i][1]; posData[i][1] = positions[i][1];
posData[i][2] = (RealOpenMM) positions[i][2]; posData[i][2] = positions[i][2];
} }
} }
void ReferenceUpdateStateDataKernel::getVelocities(ContextImpl& context, std::vector<Vec3>& velocities) { void ReferenceUpdateStateDataKernel::getVelocities(ContextImpl& context, std::vector<Vec3>& velocities) {
int numParticles = context.getSystem().getNumParticles(); int numParticles = context.getSystem().getNumParticles();
vector<RealVec>& velData = extractVelocities(context); vector<Vec3>& velData = extractVelocities(context);
velocities.resize(numParticles); velocities.resize(numParticles);
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < numParticles; ++i)
velocities[i] = Vec3(velData[i][0], velData[i][1], velData[i][2]); velocities[i] = Vec3(velData[i][0], velData[i][1], velData[i][2]);
...@@ -265,17 +265,17 @@ void ReferenceUpdateStateDataKernel::getVelocities(ContextImpl& context, std::ve ...@@ -265,17 +265,17 @@ void ReferenceUpdateStateDataKernel::getVelocities(ContextImpl& context, std::ve
void ReferenceUpdateStateDataKernel::setVelocities(ContextImpl& context, const std::vector<Vec3>& velocities) { void ReferenceUpdateStateDataKernel::setVelocities(ContextImpl& context, const std::vector<Vec3>& velocities) {
int numParticles = context.getSystem().getNumParticles(); int numParticles = context.getSystem().getNumParticles();
vector<RealVec>& velData = extractVelocities(context); vector<Vec3>& velData = extractVelocities(context);
for (int i = 0; i < numParticles; ++i) { for (int i = 0; i < numParticles; ++i) {
velData[i][0] = (RealOpenMM) velocities[i][0]; velData[i][0] = velocities[i][0];
velData[i][1] = (RealOpenMM) velocities[i][1]; velData[i][1] = velocities[i][1];
velData[i][2] = (RealOpenMM) velocities[i][2]; velData[i][2] = velocities[i][2];
} }
} }
void ReferenceUpdateStateDataKernel::getForces(ContextImpl& context, std::vector<Vec3>& forces) { void ReferenceUpdateStateDataKernel::getForces(ContextImpl& context, std::vector<Vec3>& forces) {
int numParticles = context.getSystem().getNumParticles(); int numParticles = context.getSystem().getNumParticles();
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
forces.resize(numParticles); forces.resize(numParticles);
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < numParticles; ++i)
forces[i] = Vec3(forceData[i][0], forceData[i][1], forceData[i][2]); forces[i] = Vec3(forceData[i][0], forceData[i][1], forceData[i][2]);
...@@ -286,18 +286,18 @@ void ReferenceUpdateStateDataKernel::getEnergyParameterDerivatives(ContextImpl& ...@@ -286,18 +286,18 @@ void ReferenceUpdateStateDataKernel::getEnergyParameterDerivatives(ContextImpl&
} }
void ReferenceUpdateStateDataKernel::getPeriodicBoxVectors(ContextImpl& context, Vec3& a, Vec3& b, Vec3& c) const { void ReferenceUpdateStateDataKernel::getPeriodicBoxVectors(ContextImpl& context, Vec3& a, Vec3& b, Vec3& c) const {
RealVec* vectors = extractBoxVectors(context); Vec3* vectors = extractBoxVectors(context);
a = vectors[0]; a = vectors[0];
b = vectors[1]; b = vectors[1];
c = vectors[2]; c = vectors[2];
} }
void ReferenceUpdateStateDataKernel::setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) { void ReferenceUpdateStateDataKernel::setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) {
RealVec& box = extractBoxSize(context); Vec3& box = extractBoxSize(context);
box[0] = (RealOpenMM) a[0]; box[0] = a[0];
box[1] = (RealOpenMM) b[1]; box[1] = b[1];
box[2] = (RealOpenMM) c[2]; box[2] = c[2];
RealVec* vectors = extractBoxVectors(context); Vec3* vectors = extractBoxVectors(context);
vectors[0] = a; vectors[0] = a;
vectors[1] = b; vectors[1] = b;
vectors[2] = c; vectors[2] = c;
...@@ -307,12 +307,12 @@ void ReferenceUpdateStateDataKernel::createCheckpoint(ContextImpl& context, ostr ...@@ -307,12 +307,12 @@ void ReferenceUpdateStateDataKernel::createCheckpoint(ContextImpl& context, ostr
int version = 2; int version = 2;
stream.write((char*) &version, sizeof(int)); stream.write((char*) &version, sizeof(int));
stream.write((char*) &data.time, sizeof(data.time)); stream.write((char*) &data.time, sizeof(data.time));
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
stream.write((char*) &posData[0], sizeof(RealVec)*posData.size()); stream.write((char*) &posData[0], sizeof(Vec3)*posData.size());
vector<RealVec>& velData = extractVelocities(context); vector<Vec3>& velData = extractVelocities(context);
stream.write((char*) &velData[0], sizeof(RealVec)*velData.size()); stream.write((char*) &velData[0], sizeof(Vec3)*velData.size());
RealVec* vectors = extractBoxVectors(context); Vec3* vectors = extractBoxVectors(context);
stream.write((char*) vectors, 3*sizeof(RealVec)); stream.write((char*) vectors, 3*sizeof(Vec3));
SimTKOpenMMUtilities::createCheckpoint(stream); SimTKOpenMMUtilities::createCheckpoint(stream);
} }
...@@ -322,12 +322,12 @@ void ReferenceUpdateStateDataKernel::loadCheckpoint(ContextImpl& context, istrea ...@@ -322,12 +322,12 @@ void ReferenceUpdateStateDataKernel::loadCheckpoint(ContextImpl& context, istrea
if (version != 2) if (version != 2)
throw OpenMMException("Checkpoint was created with a different version of OpenMM"); throw OpenMMException("Checkpoint was created with a different version of OpenMM");
stream.read((char*) &data.time, sizeof(data.time)); stream.read((char*) &data.time, sizeof(data.time));
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
stream.read((char*) &posData[0], sizeof(RealVec)*posData.size()); stream.read((char*) &posData[0], sizeof(Vec3)*posData.size());
vector<RealVec>& velData = extractVelocities(context); vector<Vec3>& velData = extractVelocities(context);
stream.read((char*) &velData[0], sizeof(RealVec)*velData.size()); stream.read((char*) &velData[0], sizeof(Vec3)*velData.size());
RealVec* vectors = extractBoxVectors(context); Vec3* vectors = extractBoxVectors(context);
stream.read((char*) vectors, 3*sizeof(RealVec)); stream.read((char*) vectors, 3*sizeof(Vec3));
SimTKOpenMMUtilities::loadCheckpoint(stream); SimTKOpenMMUtilities::loadCheckpoint(stream);
} }
...@@ -336,7 +336,7 @@ void ReferenceApplyConstraintsKernel::initialize(const System& system) { ...@@ -336,7 +336,7 @@ void ReferenceApplyConstraintsKernel::initialize(const System& system) {
masses.resize(numParticles); masses.resize(numParticles);
inverseMasses.resize(numParticles); inverseMasses.resize(numParticles);
for (int i = 0; i < numParticles; ++i) { for (int i = 0; i < numParticles; ++i) {
masses[i] = static_cast<RealOpenMM>(system.getParticleMass(i)); masses[i] = system.getParticleMass(i);
inverseMasses[i] = 1.0/masses[i]; inverseMasses[i] = 1.0/masses[i];
} }
} }
...@@ -345,14 +345,14 @@ ReferenceApplyConstraintsKernel::~ReferenceApplyConstraintsKernel() { ...@@ -345,14 +345,14 @@ ReferenceApplyConstraintsKernel::~ReferenceApplyConstraintsKernel() {
} }
void ReferenceApplyConstraintsKernel::apply(ContextImpl& context, double tol) { void ReferenceApplyConstraintsKernel::apply(ContextImpl& context, double tol) {
vector<RealVec>& positions = extractPositions(context); vector<Vec3>& positions = extractPositions(context);
extractConstraints(context).apply(positions, positions, inverseMasses, tol); extractConstraints(context).apply(positions, positions, inverseMasses, tol);
ReferenceVirtualSites::computePositions(context.getSystem(), positions); ReferenceVirtualSites::computePositions(context.getSystem(), positions);
} }
void ReferenceApplyConstraintsKernel::applyToVelocities(ContextImpl& context, double tol) { void ReferenceApplyConstraintsKernel::applyToVelocities(ContextImpl& context, double tol) {
vector<RealVec>& positions = extractPositions(context); vector<Vec3>& positions = extractPositions(context);
vector<RealVec>& velocities = extractVelocities(context); vector<Vec3>& velocities = extractVelocities(context);
extractConstraints(context).applyToVelocities(positions, velocities, inverseMasses, tol); extractConstraints(context).applyToVelocities(positions, velocities, inverseMasses, tol);
} }
...@@ -360,7 +360,7 @@ void ReferenceVirtualSitesKernel::initialize(const System& system) { ...@@ -360,7 +360,7 @@ void ReferenceVirtualSitesKernel::initialize(const System& system) {
} }
void ReferenceVirtualSitesKernel::computePositions(ContextImpl& context) { void ReferenceVirtualSitesKernel::computePositions(ContextImpl& context) {
vector<RealVec>& positions = extractPositions(context); vector<Vec3>& positions = extractPositions(context);
ReferenceVirtualSites::computePositions(context.getSystem(), positions); ReferenceVirtualSites::computePositions(context.getSystem(), positions);
} }
...@@ -379,16 +379,16 @@ void ReferenceCalcHarmonicBondForceKernel::initialize(const System& system, cons ...@@ -379,16 +379,16 @@ void ReferenceCalcHarmonicBondForceKernel::initialize(const System& system, cons
force.getBondParameters(i, particle1, particle2, length, k); force.getBondParameters(i, particle1, particle2, length, k);
bondIndexArray[i][0] = particle1; bondIndexArray[i][0] = particle1;
bondIndexArray[i][1] = particle2; bondIndexArray[i][1] = particle2;
bondParamArray[i][0] = (RealOpenMM) length; bondParamArray[i][0] = length;
bondParamArray[i][1] = (RealOpenMM) k; bondParamArray[i][1] = k;
} }
usePeriodic = force.usesPeriodicBoundaryConditions(); usePeriodic = force.usesPeriodicBoundaryConditions();
} }
double ReferenceCalcHarmonicBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcHarmonicBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
RealOpenMM energy = 0; double energy = 0;
ReferenceBondForce refBondForce; ReferenceBondForce refBondForce;
ReferenceHarmonicBondIxn harmonicBond; ReferenceHarmonicBondIxn harmonicBond;
if (usePeriodic) if (usePeriodic)
...@@ -411,8 +411,8 @@ void ReferenceCalcHarmonicBondForceKernel::copyParametersToContext(ContextImpl& ...@@ -411,8 +411,8 @@ void ReferenceCalcHarmonicBondForceKernel::copyParametersToContext(ContextImpl&
throw OpenMMException("updateParametersInContext: The set of particles in a bond has changed"); throw OpenMMException("updateParametersInContext: The set of particles in a bond has changed");
bondIndexArray[i][0] = particle1; bondIndexArray[i][0] = particle1;
bondIndexArray[i][1] = particle2; bondIndexArray[i][1] = particle2;
bondParamArray[i][0] = (RealOpenMM) length; bondParamArray[i][0] = length;
bondParamArray[i][1] = (RealOpenMM) k; bondParamArray[i][1] = k;
} }
} }
...@@ -437,7 +437,7 @@ void ReferenceCalcCustomBondForceKernel::initialize(const System& system, const ...@@ -437,7 +437,7 @@ void ReferenceCalcCustomBondForceKernel::initialize(const System& system, const
bondIndexArray[i][0] = particle1; bondIndexArray[i][0] = particle1;
bondIndexArray[i][1] = particle2; bondIndexArray[i][1] = particle2;
for (int j = 0; j < numParameters; j++) for (int j = 0; j < numParameters; j++)
bondParamArray[i][j] = (RealOpenMM) params[j]; bondParamArray[i][j] = params[j];
} }
// Parse the expression used to calculate the force. // Parse the expression used to calculate the force.
...@@ -462,9 +462,9 @@ void ReferenceCalcCustomBondForceKernel::initialize(const System& system, const ...@@ -462,9 +462,9 @@ void ReferenceCalcCustomBondForceKernel::initialize(const System& system, const
} }
double ReferenceCalcCustomBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCustomBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
RealOpenMM energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (int i = 0; i < (int) globalParameterNames.size(); i++)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]);
...@@ -494,7 +494,7 @@ void ReferenceCalcCustomBondForceKernel::copyParametersToContext(ContextImpl& co ...@@ -494,7 +494,7 @@ void ReferenceCalcCustomBondForceKernel::copyParametersToContext(ContextImpl& co
if (particle1 != bondIndexArray[i][0] || particle2 != bondIndexArray[i][1]) if (particle1 != bondIndexArray[i][0] || particle2 != bondIndexArray[i][1])
throw OpenMMException("updateParametersInContext: The set of particles in a bond has changed"); throw OpenMMException("updateParametersInContext: The set of particles in a bond has changed");
for (int j = 0; j < numParameters; j++) for (int j = 0; j < numParameters; j++)
bondParamArray[i][j] = (RealOpenMM) params[j]; bondParamArray[i][j] = params[j];
} }
} }
...@@ -514,16 +514,16 @@ void ReferenceCalcHarmonicAngleForceKernel::initialize(const System& system, con ...@@ -514,16 +514,16 @@ void ReferenceCalcHarmonicAngleForceKernel::initialize(const System& system, con
angleIndexArray[i][0] = particle1; angleIndexArray[i][0] = particle1;
angleIndexArray[i][1] = particle2; angleIndexArray[i][1] = particle2;
angleIndexArray[i][2] = particle3; angleIndexArray[i][2] = particle3;
angleParamArray[i][0] = (RealOpenMM) angle; angleParamArray[i][0] = angle;
angleParamArray[i][1] = (RealOpenMM) k; angleParamArray[i][1] = k;
} }
usePeriodic = force.usesPeriodicBoundaryConditions(); usePeriodic = force.usesPeriodicBoundaryConditions();
} }
double ReferenceCalcHarmonicAngleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcHarmonicAngleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
RealOpenMM energy = 0; double energy = 0;
ReferenceBondForce refBondForce; ReferenceBondForce refBondForce;
ReferenceAngleBondIxn angleBond; ReferenceAngleBondIxn angleBond;
if (usePeriodic) if (usePeriodic)
...@@ -544,8 +544,8 @@ void ReferenceCalcHarmonicAngleForceKernel::copyParametersToContext(ContextImpl& ...@@ -544,8 +544,8 @@ void ReferenceCalcHarmonicAngleForceKernel::copyParametersToContext(ContextImpl&
force.getAngleParameters(i, particle1, particle2, particle3, angle, k); force.getAngleParameters(i, particle1, particle2, particle3, angle, k);
if (particle1 != angleIndexArray[i][0] || particle2 != angleIndexArray[i][1] || particle3 != angleIndexArray[i][2]) if (particle1 != angleIndexArray[i][0] || particle2 != angleIndexArray[i][1] || particle3 != angleIndexArray[i][2])
throw OpenMMException("updateParametersInContext: The set of particles in an angle has changed"); throw OpenMMException("updateParametersInContext: The set of particles in an angle has changed");
angleParamArray[i][0] = (RealOpenMM) angle; angleParamArray[i][0] = angle;
angleParamArray[i][1] = (RealOpenMM) k; angleParamArray[i][1] = k;
} }
} }
...@@ -571,7 +571,7 @@ void ReferenceCalcCustomAngleForceKernel::initialize(const System& system, const ...@@ -571,7 +571,7 @@ void ReferenceCalcCustomAngleForceKernel::initialize(const System& system, const
angleIndexArray[i][1] = particle2; angleIndexArray[i][1] = particle2;
angleIndexArray[i][2] = particle3; angleIndexArray[i][2] = particle3;
for (int j = 0; j < numParameters; j++) for (int j = 0; j < numParameters; j++)
angleParamArray[i][j] = (RealOpenMM) params[j]; angleParamArray[i][j] = params[j];
} }
// Parse the expression used to calculate the force. // Parse the expression used to calculate the force.
...@@ -596,9 +596,9 @@ void ReferenceCalcCustomAngleForceKernel::initialize(const System& system, const ...@@ -596,9 +596,9 @@ void ReferenceCalcCustomAngleForceKernel::initialize(const System& system, const
} }
double ReferenceCalcCustomAngleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCustomAngleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
RealOpenMM energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (int i = 0; i < (int) globalParameterNames.size(); i++)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]);
...@@ -628,7 +628,7 @@ void ReferenceCalcCustomAngleForceKernel::copyParametersToContext(ContextImpl& c ...@@ -628,7 +628,7 @@ void ReferenceCalcCustomAngleForceKernel::copyParametersToContext(ContextImpl& c
if (particle1 != angleIndexArray[i][0] || particle2 != angleIndexArray[i][1] || particle3 != angleIndexArray[i][2]) if (particle1 != angleIndexArray[i][0] || particle2 != angleIndexArray[i][1] || particle3 != angleIndexArray[i][2])
throw OpenMMException("updateParametersInContext: The set of particles in an angle has changed"); throw OpenMMException("updateParametersInContext: The set of particles in an angle has changed");
for (int j = 0; j < numParameters; j++) for (int j = 0; j < numParameters; j++)
angleParamArray[i][j] = (RealOpenMM) params[j]; angleParamArray[i][j] = params[j];
} }
} }
...@@ -649,17 +649,17 @@ void ReferenceCalcPeriodicTorsionForceKernel::initialize(const System& system, c ...@@ -649,17 +649,17 @@ void ReferenceCalcPeriodicTorsionForceKernel::initialize(const System& system, c
torsionIndexArray[i][1] = particle2; torsionIndexArray[i][1] = particle2;
torsionIndexArray[i][2] = particle3; torsionIndexArray[i][2] = particle3;
torsionIndexArray[i][3] = particle4; torsionIndexArray[i][3] = particle4;
torsionParamArray[i][0] = (RealOpenMM) k; torsionParamArray[i][0] = k;
torsionParamArray[i][1] = (RealOpenMM) phase; torsionParamArray[i][1] = phase;
torsionParamArray[i][2] = (RealOpenMM) periodicity; torsionParamArray[i][2] = periodicity;
} }
usePeriodic = force.usesPeriodicBoundaryConditions(); usePeriodic = force.usesPeriodicBoundaryConditions();
} }
double ReferenceCalcPeriodicTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcPeriodicTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
RealOpenMM energy = 0; double energy = 0;
ReferenceBondForce refBondForce; ReferenceBondForce refBondForce;
ReferenceProperDihedralBond periodicTorsionBond; ReferenceProperDihedralBond periodicTorsionBond;
if (usePeriodic) if (usePeriodic)
...@@ -680,9 +680,9 @@ void ReferenceCalcPeriodicTorsionForceKernel::copyParametersToContext(ContextImp ...@@ -680,9 +680,9 @@ void ReferenceCalcPeriodicTorsionForceKernel::copyParametersToContext(ContextImp
force.getTorsionParameters(i, particle1, particle2, particle3, particle4, periodicity, phase, k); force.getTorsionParameters(i, particle1, particle2, particle3, particle4, periodicity, phase, k);
if (particle1 != torsionIndexArray[i][0] || particle2 != torsionIndexArray[i][1] || particle3 != torsionIndexArray[i][2] || particle4 != torsionIndexArray[i][3]) if (particle1 != torsionIndexArray[i][0] || particle2 != torsionIndexArray[i][1] || particle3 != torsionIndexArray[i][2] || particle4 != torsionIndexArray[i][3])
throw OpenMMException("updateParametersInContext: The set of particles in a torsion has changed"); throw OpenMMException("updateParametersInContext: The set of particles in a torsion has changed");
torsionParamArray[i][0] = (RealOpenMM) k; torsionParamArray[i][0] = k;
torsionParamArray[i][1] = (RealOpenMM) phase; torsionParamArray[i][1] = phase;
torsionParamArray[i][2] = (RealOpenMM) periodicity; torsionParamArray[i][2] = periodicity;
} }
} }
...@@ -703,20 +703,20 @@ void ReferenceCalcRBTorsionForceKernel::initialize(const System& system, const R ...@@ -703,20 +703,20 @@ void ReferenceCalcRBTorsionForceKernel::initialize(const System& system, const R
torsionIndexArray[i][1] = particle2; torsionIndexArray[i][1] = particle2;
torsionIndexArray[i][2] = particle3; torsionIndexArray[i][2] = particle3;
torsionIndexArray[i][3] = particle4; torsionIndexArray[i][3] = particle4;
torsionParamArray[i][0] = (RealOpenMM) c0; torsionParamArray[i][0] = c0;
torsionParamArray[i][1] = (RealOpenMM) c1; torsionParamArray[i][1] = c1;
torsionParamArray[i][2] = (RealOpenMM) c2; torsionParamArray[i][2] = c2;
torsionParamArray[i][3] = (RealOpenMM) c3; torsionParamArray[i][3] = c3;
torsionParamArray[i][4] = (RealOpenMM) c4; torsionParamArray[i][4] = c4;
torsionParamArray[i][5] = (RealOpenMM) c5; torsionParamArray[i][5] = c5;
} }
usePeriodic = force.usesPeriodicBoundaryConditions(); usePeriodic = force.usesPeriodicBoundaryConditions();
} }
double ReferenceCalcRBTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcRBTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
RealOpenMM energy = 0; double energy = 0;
ReferenceBondForce refBondForce; ReferenceBondForce refBondForce;
ReferenceRbDihedralBond rbTorsionBond; ReferenceRbDihedralBond rbTorsionBond;
if (usePeriodic) if (usePeriodic)
...@@ -737,12 +737,12 @@ void ReferenceCalcRBTorsionForceKernel::copyParametersToContext(ContextImpl& con ...@@ -737,12 +737,12 @@ void ReferenceCalcRBTorsionForceKernel::copyParametersToContext(ContextImpl& con
force.getTorsionParameters(i, particle1, particle2, particle3, particle4, c0, c1, c2, c3, c4, c5); force.getTorsionParameters(i, particle1, particle2, particle3, particle4, c0, c1, c2, c3, c4, c5);
if (particle1 != torsionIndexArray[i][0] || particle2 != torsionIndexArray[i][1] || particle3 != torsionIndexArray[i][2] || particle4 != torsionIndexArray[i][3]) if (particle1 != torsionIndexArray[i][0] || particle2 != torsionIndexArray[i][1] || particle3 != torsionIndexArray[i][2] || particle4 != torsionIndexArray[i][3])
throw OpenMMException("updateParametersInContext: The set of particles in a torsion has changed"); throw OpenMMException("updateParametersInContext: The set of particles in a torsion has changed");
torsionParamArray[i][0] = (RealOpenMM) c0; torsionParamArray[i][0] = c0;
torsionParamArray[i][1] = (RealOpenMM) c1; torsionParamArray[i][1] = c1;
torsionParamArray[i][2] = (RealOpenMM) c2; torsionParamArray[i][2] = c2;
torsionParamArray[i][3] = (RealOpenMM) c3; torsionParamArray[i][3] = c3;
torsionParamArray[i][4] = (RealOpenMM) c4; torsionParamArray[i][4] = c4;
torsionParamArray[i][5] = (RealOpenMM) c5; torsionParamArray[i][5] = c5;
} }
} }
...@@ -774,9 +774,9 @@ void ReferenceCalcCMAPTorsionForceKernel::initialize(const System& system, const ...@@ -774,9 +774,9 @@ void ReferenceCalcCMAPTorsionForceKernel::initialize(const System& system, const
} }
double ReferenceCalcCMAPTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCMAPTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
RealOpenMM totalEnergy = 0; double totalEnergy = 0;
ReferenceCMAPTorsionIxn torsion(coeff, torsionMaps, torsionIndices); ReferenceCMAPTorsionIxn torsion(coeff, torsionMaps, torsionIndices);
if (usePeriodic) if (usePeriodic)
torsion.setPeriodic(extractBoxVectors(context)); torsion.setPeriodic(extractBoxVectors(context));
...@@ -841,7 +841,7 @@ void ReferenceCalcCustomTorsionForceKernel::initialize(const System& system, con ...@@ -841,7 +841,7 @@ void ReferenceCalcCustomTorsionForceKernel::initialize(const System& system, con
torsionIndexArray[i][2] = particle3; torsionIndexArray[i][2] = particle3;
torsionIndexArray[i][3] = particle4; torsionIndexArray[i][3] = particle4;
for (int j = 0; j < numParameters; j++) for (int j = 0; j < numParameters; j++)
torsionParamArray[i][j] = (RealOpenMM) params[j]; torsionParamArray[i][j] = params[j];
} }
// Parse the expression used to calculate the force. // Parse the expression used to calculate the force.
...@@ -866,9 +866,9 @@ void ReferenceCalcCustomTorsionForceKernel::initialize(const System& system, con ...@@ -866,9 +866,9 @@ void ReferenceCalcCustomTorsionForceKernel::initialize(const System& system, con
} }
double ReferenceCalcCustomTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCustomTorsionForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
RealOpenMM energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (int i = 0; i < (int) globalParameterNames.size(); i++)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]);
...@@ -898,7 +898,7 @@ void ReferenceCalcCustomTorsionForceKernel::copyParametersToContext(ContextImpl& ...@@ -898,7 +898,7 @@ void ReferenceCalcCustomTorsionForceKernel::copyParametersToContext(ContextImpl&
if (particle1 != torsionIndexArray[i][0] || particle2 != torsionIndexArray[i][1] || particle3 != torsionIndexArray[i][2] || particle4 != torsionIndexArray[i][3]) if (particle1 != torsionIndexArray[i][0] || particle2 != torsionIndexArray[i][1] || particle3 != torsionIndexArray[i][2] || particle4 != torsionIndexArray[i][3])
throw OpenMMException("updateParametersInContext: The set of particles in a torsion has changed"); throw OpenMMException("updateParametersInContext: The set of particles in a torsion has changed");
for (int j = 0; j < numParameters; j++) for (int j = 0; j < numParameters; j++)
torsionParamArray[i][j] = (RealOpenMM) params[j]; torsionParamArray[i][j] = params[j];
} }
} }
...@@ -936,9 +936,9 @@ void ReferenceCalcNonbondedForceKernel::initialize(const System& system, const N ...@@ -936,9 +936,9 @@ void ReferenceCalcNonbondedForceKernel::initialize(const System& system, const N
for (int i = 0; i < numParticles; ++i) { for (int i = 0; i < numParticles; ++i) {
double charge, radius, depth; double charge, radius, depth;
force.getParticleParameters(i, charge, radius, depth); force.getParticleParameters(i, charge, radius, depth);
particleParamArray[i][0] = static_cast<RealOpenMM>(0.5*radius); particleParamArray[i][0] = 0.5*radius;
particleParamArray[i][1] = static_cast<RealOpenMM>(2.0*sqrt(depth)); particleParamArray[i][1] = 2.0*sqrt(depth);
particleParamArray[i][2] = static_cast<RealOpenMM>(charge); particleParamArray[i][2] = charge;
} }
this->exclusions = exclusions; this->exclusions = exclusions;
for (int i = 0; i < num14; ++i) { for (int i = 0; i < num14; ++i) {
...@@ -947,12 +947,12 @@ void ReferenceCalcNonbondedForceKernel::initialize(const System& system, const N ...@@ -947,12 +947,12 @@ void ReferenceCalcNonbondedForceKernel::initialize(const System& system, const N
force.getExceptionParameters(nb14s[i], particle1, particle2, charge, radius, depth); force.getExceptionParameters(nb14s[i], particle1, particle2, charge, radius, depth);
bonded14IndexArray[i][0] = particle1; bonded14IndexArray[i][0] = particle1;
bonded14IndexArray[i][1] = particle2; bonded14IndexArray[i][1] = particle2;
bonded14ParamArray[i][0] = static_cast<RealOpenMM>(radius); bonded14ParamArray[i][0] = radius;
bonded14ParamArray[i][1] = static_cast<RealOpenMM>(4.0*depth); bonded14ParamArray[i][1] = 4.0*depth;
bonded14ParamArray[i][2] = static_cast<RealOpenMM>(charge); bonded14ParamArray[i][2] = charge;
} }
nonbondedMethod = CalcNonbondedForceKernel::NonbondedMethod(force.getNonbondedMethod()); nonbondedMethod = CalcNonbondedForceKernel::NonbondedMethod(force.getNonbondedMethod());
nonbondedCutoff = (RealOpenMM) force.getCutoffDistance(); nonbondedCutoff = force.getCutoffDistance();
if (nonbondedMethod == NoCutoff) { if (nonbondedMethod == NoCutoff) {
neighborList = NULL; neighborList = NULL;
useSwitchingFunction = false; useSwitchingFunction = false;
...@@ -965,14 +965,14 @@ void ReferenceCalcNonbondedForceKernel::initialize(const System& system, const N ...@@ -965,14 +965,14 @@ void ReferenceCalcNonbondedForceKernel::initialize(const System& system, const N
if (nonbondedMethod == Ewald) { if (nonbondedMethod == Ewald) {
double alpha; double alpha;
NonbondedForceImpl::calcEwaldParameters(system, force, alpha, kmax[0], kmax[1], kmax[2]); NonbondedForceImpl::calcEwaldParameters(system, force, alpha, kmax[0], kmax[1], kmax[2]);
ewaldAlpha = (RealOpenMM) alpha; ewaldAlpha = alpha;
} }
else if (nonbondedMethod == PME) { else if (nonbondedMethod == PME) {
double alpha; double alpha;
NonbondedForceImpl::calcPMEParameters(system, force, alpha, gridSize[0], gridSize[1], gridSize[2]); NonbondedForceImpl::calcPMEParameters(system, force, alpha, gridSize[0], gridSize[1], gridSize[2]);
ewaldAlpha = (RealOpenMM) alpha; ewaldAlpha = alpha;
} }
rfDielectric = (RealOpenMM)force.getReactionFieldDielectric(); rfDielectric = force.getReactionFieldDielectric();
if (force.getUseDispersionCorrection()) if (force.getUseDispersionCorrection())
dispersionCoefficient = NonbondedForceImpl::calcDispersionCorrection(system, force); dispersionCoefficient = NonbondedForceImpl::calcDispersionCorrection(system, force);
else else
...@@ -980,9 +980,9 @@ void ReferenceCalcNonbondedForceKernel::initialize(const System& system, const N ...@@ -980,9 +980,9 @@ void ReferenceCalcNonbondedForceKernel::initialize(const System& system, const N
} }
double ReferenceCalcNonbondedForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy, bool includeDirect, bool includeReciprocal) { double ReferenceCalcNonbondedForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy, bool includeDirect, bool includeReciprocal) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
RealOpenMM energy = 0; double energy = 0;
ReferenceLJCoulombIxn clj; ReferenceLJCoulombIxn clj;
bool periodic = (nonbondedMethod == CutoffPeriodic); bool periodic = (nonbondedMethod == CutoffPeriodic);
bool ewald = (nonbondedMethod == Ewald); bool ewald = (nonbondedMethod == Ewald);
...@@ -992,7 +992,7 @@ double ReferenceCalcNonbondedForceKernel::execute(ContextImpl& context, bool inc ...@@ -992,7 +992,7 @@ double ReferenceCalcNonbondedForceKernel::execute(ContextImpl& context, bool inc
clj.setUseCutoff(nonbondedCutoff, *neighborList, rfDielectric); clj.setUseCutoff(nonbondedCutoff, *neighborList, rfDielectric);
} }
if (periodic || ewald || pme) { if (periodic || ewald || pme) {
RealVec* boxVectors = extractBoxVectors(context); Vec3* boxVectors = extractBoxVectors(context);
double minAllowedSize = 1.999999*nonbondedCutoff; double minAllowedSize = 1.999999*nonbondedCutoff;
if (boxVectors[0][0] < minAllowedSize || boxVectors[1][1] < minAllowedSize || boxVectors[2][2] < minAllowedSize) if (boxVectors[0][0] < minAllowedSize || boxVectors[1][1] < minAllowedSize || boxVectors[2][2] < minAllowedSize)
throw OpenMMException("The periodic box size has decreased to less than twice the nonbonded cutoff."); throw OpenMMException("The periodic box size has decreased to less than twice the nonbonded cutoff.");
...@@ -1010,7 +1010,7 @@ double ReferenceCalcNonbondedForceKernel::execute(ContextImpl& context, bool inc ...@@ -1010,7 +1010,7 @@ double ReferenceCalcNonbondedForceKernel::execute(ContextImpl& context, bool inc
ReferenceLJCoulomb14 nonbonded14; ReferenceLJCoulomb14 nonbonded14;
refBondForce.calculateForce(num14, bonded14IndexArray, posData, bonded14ParamArray, forceData, includeEnergy ? &energy : NULL, nonbonded14); refBondForce.calculateForce(num14, bonded14IndexArray, posData, bonded14ParamArray, forceData, includeEnergy ? &energy : NULL, nonbonded14);
if (periodic || ewald || pme) { if (periodic || ewald || pme) {
RealVec* boxVectors = extractBoxVectors(context); Vec3* boxVectors = extractBoxVectors(context);
energy += dispersionCoefficient/(boxVectors[0][0]*boxVectors[1][1]*boxVectors[2][2]); energy += dispersionCoefficient/(boxVectors[0][0]*boxVectors[1][1]*boxVectors[2][2]);
} }
} }
...@@ -1036,9 +1036,9 @@ void ReferenceCalcNonbondedForceKernel::copyParametersToContext(ContextImpl& con ...@@ -1036,9 +1036,9 @@ void ReferenceCalcNonbondedForceKernel::copyParametersToContext(ContextImpl& con
for (int i = 0; i < numParticles; ++i) { for (int i = 0; i < numParticles; ++i) {
double charge, radius, depth; double charge, radius, depth;
force.getParticleParameters(i, charge, radius, depth); force.getParticleParameters(i, charge, radius, depth);
particleParamArray[i][0] = static_cast<RealOpenMM>(0.5*radius); particleParamArray[i][0] = 0.5*radius;
particleParamArray[i][1] = static_cast<RealOpenMM>(2.0*sqrt(depth)); particleParamArray[i][1] = 2.0*sqrt(depth);
particleParamArray[i][2] = static_cast<RealOpenMM>(charge); particleParamArray[i][2] = charge;
} }
for (int i = 0; i < num14; ++i) { for (int i = 0; i < num14; ++i) {
int particle1, particle2; int particle1, particle2;
...@@ -1046,9 +1046,9 @@ void ReferenceCalcNonbondedForceKernel::copyParametersToContext(ContextImpl& con ...@@ -1046,9 +1046,9 @@ void ReferenceCalcNonbondedForceKernel::copyParametersToContext(ContextImpl& con
force.getExceptionParameters(nb14s[i], particle1, particle2, charge, radius, depth); force.getExceptionParameters(nb14s[i], particle1, particle2, charge, radius, depth);
bonded14IndexArray[i][0] = particle1; bonded14IndexArray[i][0] = particle1;
bonded14IndexArray[i][1] = particle2; bonded14IndexArray[i][1] = particle2;
bonded14ParamArray[i][0] = static_cast<RealOpenMM>(radius); bonded14ParamArray[i][0] = radius;
bonded14ParamArray[i][1] = static_cast<RealOpenMM>(4.0*depth); bonded14ParamArray[i][1] = 4.0*depth;
bonded14ParamArray[i][2] = static_cast<RealOpenMM>(charge); bonded14ParamArray[i][2] = charge;
} }
// Recompute the coefficient for the dispersion correction. // Recompute the coefficient for the dispersion correction.
...@@ -1096,10 +1096,10 @@ void ReferenceCalcCustomNonbondedForceKernel::initialize(const System& system, c ...@@ -1096,10 +1096,10 @@ void ReferenceCalcCustomNonbondedForceKernel::initialize(const System& system, c
vector<double> parameters; vector<double> parameters;
force.getParticleParameters(i, parameters); force.getParticleParameters(i, parameters);
for (int j = 0; j < numParameters; j++) for (int j = 0; j < numParameters; j++)
particleParamArray[i][j] = static_cast<RealOpenMM>(parameters[j]); particleParamArray[i][j] = parameters[j];
} }
nonbondedMethod = CalcCustomNonbondedForceKernel::NonbondedMethod(force.getNonbondedMethod()); nonbondedMethod = CalcCustomNonbondedForceKernel::NonbondedMethod(force.getNonbondedMethod());
nonbondedCutoff = (RealOpenMM) force.getCutoffDistance(); nonbondedCutoff = force.getCutoffDistance();
if (nonbondedMethod == NoCutoff) { if (nonbondedMethod == NoCutoff) {
neighborList = NULL; neighborList = NULL;
useSwitchingFunction = false; useSwitchingFunction = false;
...@@ -1167,10 +1167,10 @@ void ReferenceCalcCustomNonbondedForceKernel::initialize(const System& system, c ...@@ -1167,10 +1167,10 @@ void ReferenceCalcCustomNonbondedForceKernel::initialize(const System& system, c
} }
double ReferenceCalcCustomNonbondedForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCustomNonbondedForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
RealVec* boxVectors = extractBoxVectors(context); Vec3* boxVectors = extractBoxVectors(context);
RealOpenMM energy = 0; double energy = 0;
ReferenceCustomNonbondedIxn ixn(energyExpression, forceExpression, parameterNames, energyParamDerivExpressions); ReferenceCustomNonbondedIxn ixn(energyExpression, forceExpression, parameterNames, energyParamDerivExpressions);
bool periodic = (nonbondedMethod == CutoffPeriodic); bool periodic = (nonbondedMethod == CutoffPeriodic);
if (nonbondedMethod != NoCutoff) { if (nonbondedMethod != NoCutoff) {
...@@ -1225,7 +1225,7 @@ void ReferenceCalcCustomNonbondedForceKernel::copyParametersToContext(ContextImp ...@@ -1225,7 +1225,7 @@ void ReferenceCalcCustomNonbondedForceKernel::copyParametersToContext(ContextImp
vector<double> parameters; vector<double> parameters;
force.getParticleParameters(i, parameters); force.getParticleParameters(i, parameters);
for (int j = 0; j < numParameters; j++) for (int j = 0; j < numParameters; j++)
particleParamArray[i][j] = static_cast<RealOpenMM>(parameters[j]); particleParamArray[i][j] = parameters[j];
} }
// If necessary, recompute the long range correction. // If necessary, recompute the long range correction.
...@@ -1247,31 +1247,31 @@ ReferenceCalcGBSAOBCForceKernel::~ReferenceCalcGBSAOBCForceKernel() { ...@@ -1247,31 +1247,31 @@ ReferenceCalcGBSAOBCForceKernel::~ReferenceCalcGBSAOBCForceKernel() {
void ReferenceCalcGBSAOBCForceKernel::initialize(const System& system, const GBSAOBCForce& force) { void ReferenceCalcGBSAOBCForceKernel::initialize(const System& system, const GBSAOBCForce& force) {
int numParticles = system.getNumParticles(); int numParticles = system.getNumParticles();
charges.resize(numParticles); charges.resize(numParticles);
vector<RealOpenMM> atomicRadii(numParticles); vector<double> atomicRadii(numParticles);
vector<RealOpenMM> scaleFactors(numParticles); vector<double> scaleFactors(numParticles);
for (int i = 0; i < numParticles; ++i) { for (int i = 0; i < numParticles; ++i) {
double charge, radius, scalingFactor; double charge, radius, scalingFactor;
force.getParticleParameters(i, charge, radius, scalingFactor); force.getParticleParameters(i, charge, radius, scalingFactor);
charges[i] = static_cast<RealOpenMM>(charge); charges[i] = charge;
atomicRadii[i] = static_cast<RealOpenMM>(radius); atomicRadii[i] = radius;
scaleFactors[i] = static_cast<RealOpenMM>(scalingFactor); scaleFactors[i] = scalingFactor;
} }
ObcParameters* obcParameters = new ObcParameters(numParticles, ObcParameters::ObcTypeII); ObcParameters* obcParameters = new ObcParameters(numParticles, ObcParameters::ObcTypeII);
obcParameters->setAtomicRadii(atomicRadii); obcParameters->setAtomicRadii(atomicRadii);
obcParameters->setScaledRadiusFactors(scaleFactors); obcParameters->setScaledRadiusFactors(scaleFactors);
obcParameters->setSolventDielectric(static_cast<RealOpenMM>(force.getSolventDielectric())); obcParameters->setSolventDielectric(force.getSolventDielectric());
obcParameters->setSoluteDielectric(static_cast<RealOpenMM>(force.getSoluteDielectric())); obcParameters->setSoluteDielectric(force.getSoluteDielectric());
obcParameters->setPi4Asolv(4*M_PI*force.getSurfaceAreaEnergy()); obcParameters->setPi4Asolv(4*M_PI*force.getSurfaceAreaEnergy());
if (force.getNonbondedMethod() != GBSAOBCForce::NoCutoff) if (force.getNonbondedMethod() != GBSAOBCForce::NoCutoff)
obcParameters->setUseCutoff(static_cast<RealOpenMM>(force.getCutoffDistance())); obcParameters->setUseCutoff(force.getCutoffDistance());
isPeriodic = (force.getNonbondedMethod() == GBSAOBCForce::CutoffPeriodic); isPeriodic = (force.getNonbondedMethod() == GBSAOBCForce::CutoffPeriodic);
obc = new ReferenceObc(obcParameters); obc = new ReferenceObc(obcParameters);
obc->setIncludeAceApproximation(true); obc->setIncludeAceApproximation(true);
} }
double ReferenceCalcGBSAOBCForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcGBSAOBCForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
if (isPeriodic) if (isPeriodic)
obc->getObcParameters()->setPeriodic(extractBoxVectors(context)); obc->getObcParameters()->setPeriodic(extractBoxVectors(context));
return obc->computeBornEnergyForces(posData, charges, forceData); return obc->computeBornEnergyForces(posData, charges, forceData);
...@@ -1285,14 +1285,14 @@ void ReferenceCalcGBSAOBCForceKernel::copyParametersToContext(ContextImpl& conte ...@@ -1285,14 +1285,14 @@ void ReferenceCalcGBSAOBCForceKernel::copyParametersToContext(ContextImpl& conte
// Record the values. // Record the values.
vector<RealOpenMM> atomicRadii(numParticles); vector<double> atomicRadii(numParticles);
vector<RealOpenMM> scaleFactors(numParticles); vector<double> scaleFactors(numParticles);
for (int i = 0; i < numParticles; ++i) { for (int i = 0; i < numParticles; ++i) {
double charge, radius, scalingFactor; double charge, radius, scalingFactor;
force.getParticleParameters(i, charge, radius, scalingFactor); force.getParticleParameters(i, charge, radius, scalingFactor);
charges[i] = (RealOpenMM) charge; charges[i] = charge;
atomicRadii[i] = (RealOpenMM) radius; atomicRadii[i] = radius;
scaleFactors[i] = (RealOpenMM) scalingFactor; scaleFactors[i] = scalingFactor;
} }
obcParameters->setAtomicRadii(atomicRadii); obcParameters->setAtomicRadii(atomicRadii);
obcParameters->setScaledRadiusFactors(scaleFactors); obcParameters->setScaledRadiusFactors(scaleFactors);
...@@ -1337,14 +1337,14 @@ void ReferenceCalcCustomGBForceKernel::initialize(const System& system, const Cu ...@@ -1337,14 +1337,14 @@ void ReferenceCalcCustomGBForceKernel::initialize(const System& system, const Cu
vector<double> parameters; vector<double> parameters;
force.getParticleParameters(i, parameters); force.getParticleParameters(i, parameters);
for (int j = 0; j < numPerParticleParameters; j++) for (int j = 0; j < numPerParticleParameters; j++)
particleParamArray[i][j] = static_cast<RealOpenMM>(parameters[j]); particleParamArray[i][j] = parameters[j];
} }
for (int i = 0; i < numPerParticleParameters; i++) for (int i = 0; i < numPerParticleParameters; i++)
particleParameterNames.push_back(force.getPerParticleParameterName(i)); particleParameterNames.push_back(force.getPerParticleParameterName(i));
for (int i = 0; i < force.getNumGlobalParameters(); i++) for (int i = 0; i < force.getNumGlobalParameters(); i++)
globalParameterNames.push_back(force.getGlobalParameterName(i)); globalParameterNames.push_back(force.getGlobalParameterName(i));
nonbondedMethod = CalcCustomGBForceKernel::NonbondedMethod(force.getNonbondedMethod()); nonbondedMethod = CalcCustomGBForceKernel::NonbondedMethod(force.getNonbondedMethod());
nonbondedCutoff = (RealOpenMM) force.getCutoffDistance(); nonbondedCutoff = force.getCutoffDistance();
if (nonbondedMethod == NoCutoff) if (nonbondedMethod == NoCutoff)
neighborList = NULL; neighborList = NULL;
else else
...@@ -1442,9 +1442,9 @@ void ReferenceCalcCustomGBForceKernel::initialize(const System& system, const Cu ...@@ -1442,9 +1442,9 @@ void ReferenceCalcCustomGBForceKernel::initialize(const System& system, const Cu
} }
double ReferenceCalcCustomGBForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCustomGBForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
RealOpenMM energy = 0; double energy = 0;
ReferenceCustomGBIxn ixn(valueExpressions, valueDerivExpressions, valueGradientExpressions, valueParamDerivExpressions, valueNames, valueTypes, ReferenceCustomGBIxn ixn(valueExpressions, valueDerivExpressions, valueGradientExpressions, valueParamDerivExpressions, valueNames, valueTypes,
energyExpressions, energyDerivExpressions, energyGradientExpressions, energyParamDerivExpressions, energyTypes, particleParameterNames); energyExpressions, energyDerivExpressions, energyGradientExpressions, energyParamDerivExpressions, energyTypes, particleParameterNames);
bool periodic = (nonbondedMethod == CutoffPeriodic); bool periodic = (nonbondedMethod == CutoffPeriodic);
...@@ -1477,11 +1477,11 @@ void ReferenceCalcCustomGBForceKernel::copyParametersToContext(ContextImpl& cont ...@@ -1477,11 +1477,11 @@ void ReferenceCalcCustomGBForceKernel::copyParametersToContext(ContextImpl& cont
vector<double> parameters; vector<double> parameters;
force.getParticleParameters(i, parameters); force.getParticleParameters(i, parameters);
for (int j = 0; j < numParameters; j++) for (int j = 0; j < numParameters; j++)
particleParamArray[i][j] = static_cast<RealOpenMM>(parameters[j]); particleParamArray[i][j] = parameters[j];
} }
} }
ReferenceCalcCustomExternalForceKernel::PeriodicDistanceFunction::PeriodicDistanceFunction(RealVec** boxVectorHandle) : boxVectorHandle(boxVectorHandle) { ReferenceCalcCustomExternalForceKernel::PeriodicDistanceFunction::PeriodicDistanceFunction(Vec3** boxVectorHandle) : boxVectorHandle(boxVectorHandle) {
} }
int ReferenceCalcCustomExternalForceKernel::PeriodicDistanceFunction::getNumArguments() const { int ReferenceCalcCustomExternalForceKernel::PeriodicDistanceFunction::getNumArguments() const {
...@@ -1489,8 +1489,8 @@ int ReferenceCalcCustomExternalForceKernel::PeriodicDistanceFunction::getNumArgu ...@@ -1489,8 +1489,8 @@ int ReferenceCalcCustomExternalForceKernel::PeriodicDistanceFunction::getNumArgu
} }
double ReferenceCalcCustomExternalForceKernel::PeriodicDistanceFunction::evaluate(const double* arguments) const { double ReferenceCalcCustomExternalForceKernel::PeriodicDistanceFunction::evaluate(const double* arguments) const {
RealVec* boxVectors = *boxVectorHandle; Vec3* boxVectors = *boxVectorHandle;
RealVec delta = RealVec(arguments[0], arguments[1], arguments[2])-RealVec(arguments[3], arguments[4], arguments[5]); Vec3 delta = Vec3(arguments[0], arguments[1], arguments[2])-Vec3(arguments[3], arguments[4], arguments[5]);
delta -= boxVectors[2]*floor(delta[2]/boxVectors[2][2]+0.5); delta -= boxVectors[2]*floor(delta[2]/boxVectors[2][2]+0.5);
delta -= boxVectors[1]*floor(delta[1]/boxVectors[1][1]+0.5); delta -= boxVectors[1]*floor(delta[1]/boxVectors[1][1]+0.5);
delta -= boxVectors[0]*floor(delta[0]/boxVectors[0][0]+0.5); delta -= boxVectors[0]*floor(delta[0]/boxVectors[0][0]+0.5);
...@@ -1506,8 +1506,8 @@ double ReferenceCalcCustomExternalForceKernel::PeriodicDistanceFunction::evaluat ...@@ -1506,8 +1506,8 @@ double ReferenceCalcCustomExternalForceKernel::PeriodicDistanceFunction::evaluat
argIndex = i; argIndex = i;
} }
} }
RealVec* boxVectors = *boxVectorHandle; Vec3* boxVectors = *boxVectorHandle;
RealVec delta = RealVec(arguments[0], arguments[1], arguments[2])-RealVec(arguments[3], arguments[4], arguments[5]); Vec3 delta = Vec3(arguments[0], arguments[1], arguments[2])-Vec3(arguments[3], arguments[4], arguments[5]);
delta -= boxVectors[2]*floor(delta[2]/boxVectors[2][2]+0.5); delta -= boxVectors[2]*floor(delta[2]/boxVectors[2][2]+0.5);
delta -= boxVectors[1]*floor(delta[1]/boxVectors[1][1]+0.5); delta -= boxVectors[1]*floor(delta[1]/boxVectors[1][1]+0.5);
delta -= boxVectors[0]*floor(delta[0]/boxVectors[0][0]+0.5); delta -= boxVectors[0]*floor(delta[0]/boxVectors[0][0]+0.5);
...@@ -1539,7 +1539,7 @@ void ReferenceCalcCustomExternalForceKernel::initialize(const System& system, co ...@@ -1539,7 +1539,7 @@ void ReferenceCalcCustomExternalForceKernel::initialize(const System& system, co
for (int i = 0; i < numParticles; ++i) { for (int i = 0; i < numParticles; ++i) {
force.getParticleParameters(i, particles[i], params); force.getParticleParameters(i, particles[i], params);
for (int j = 0; j < numParameters; j++) for (int j = 0; j < numParameters; j++)
particleParamArray[i][j] = (RealOpenMM) params[j]; particleParamArray[i][j] = params[j];
} }
// Parse the expression used to calculate the force. // Parse the expression used to calculate the force.
...@@ -1566,10 +1566,10 @@ void ReferenceCalcCustomExternalForceKernel::initialize(const System& system, co ...@@ -1566,10 +1566,10 @@ void ReferenceCalcCustomExternalForceKernel::initialize(const System& system, co
} }
double ReferenceCalcCustomExternalForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCustomExternalForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
boxVectors = extractBoxVectors(context); boxVectors = extractBoxVectors(context);
RealOpenMM energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (int i = 0; i < (int) globalParameterNames.size(); i++)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]);
...@@ -1594,7 +1594,7 @@ void ReferenceCalcCustomExternalForceKernel::copyParametersToContext(ContextImpl ...@@ -1594,7 +1594,7 @@ void ReferenceCalcCustomExternalForceKernel::copyParametersToContext(ContextImpl
if (particle != particles[i]) if (particle != particles[i])
throw OpenMMException("updateParametersInContext: A particle index has changed"); throw OpenMMException("updateParametersInContext: A particle index has changed");
for (int j = 0; j < numParameters; j++) for (int j = 0; j < numParameters; j++)
particleParamArray[i][j] = static_cast<RealOpenMM>(parameters[j]); particleParamArray[i][j] = parameters[j];
} }
} }
...@@ -1632,7 +1632,7 @@ void ReferenceCalcCustomHbondForceKernel::initialize(const System& system, const ...@@ -1632,7 +1632,7 @@ void ReferenceCalcCustomHbondForceKernel::initialize(const System& system, const
donorParticles[i].push_back(d2); donorParticles[i].push_back(d2);
donorParticles[i].push_back(d3); donorParticles[i].push_back(d3);
for (int j = 0; j < numDonorParameters; j++) for (int j = 0; j < numDonorParameters; j++)
donorParamArray[i][j] = static_cast<RealOpenMM>(parameters[j]); donorParamArray[i][j] = parameters[j];
} }
vector<vector<int> > acceptorParticles(numAcceptors); vector<vector<int> > acceptorParticles(numAcceptors);
int numAcceptorParameters = force.getNumPerAcceptorParameters(); int numAcceptorParameters = force.getNumPerAcceptorParameters();
...@@ -1645,10 +1645,10 @@ void ReferenceCalcCustomHbondForceKernel::initialize(const System& system, const ...@@ -1645,10 +1645,10 @@ void ReferenceCalcCustomHbondForceKernel::initialize(const System& system, const
acceptorParticles[i].push_back(a2); acceptorParticles[i].push_back(a2);
acceptorParticles[i].push_back(a3); acceptorParticles[i].push_back(a3);
for (int j = 0; j < numAcceptorParameters; j++) for (int j = 0; j < numAcceptorParameters; j++)
acceptorParamArray[i][j] = static_cast<RealOpenMM>(parameters[j]); acceptorParamArray[i][j] = parameters[j];
} }
NonbondedMethod nonbondedMethod = CalcCustomHbondForceKernel::NonbondedMethod(force.getNonbondedMethod()); NonbondedMethod nonbondedMethod = CalcCustomHbondForceKernel::NonbondedMethod(force.getNonbondedMethod());
nonbondedCutoff = (RealOpenMM) force.getCutoffDistance(); nonbondedCutoff = force.getCutoffDistance();
// Create custom functions for the tabulated functions. // Create custom functions for the tabulated functions.
...@@ -1682,11 +1682,11 @@ void ReferenceCalcCustomHbondForceKernel::initialize(const System& system, const ...@@ -1682,11 +1682,11 @@ void ReferenceCalcCustomHbondForceKernel::initialize(const System& system, const
} }
double ReferenceCalcCustomHbondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCustomHbondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
if (isPeriodic) if (isPeriodic)
ixn->setPeriodic(extractBoxVectors(context)); ixn->setPeriodic(extractBoxVectors(context));
RealOpenMM energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (int i = 0; i < (int) globalParameterNames.size(); i++)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]);
...@@ -1711,7 +1711,7 @@ void ReferenceCalcCustomHbondForceKernel::copyParametersToContext(ContextImpl& c ...@@ -1711,7 +1711,7 @@ void ReferenceCalcCustomHbondForceKernel::copyParametersToContext(ContextImpl& c
if (d1 != donorAtoms[i][0] || d2 != donorAtoms[i][1] || d3 != donorAtoms[i][2]) if (d1 != donorAtoms[i][0] || d2 != donorAtoms[i][1] || d3 != donorAtoms[i][2])
throw OpenMMException("updateParametersInContext: The set of particles in a donor group has changed"); throw OpenMMException("updateParametersInContext: The set of particles in a donor group has changed");
for (int j = 0; j < numDonorParameters; j++) for (int j = 0; j < numDonorParameters; j++)
donorParamArray[i][j] = static_cast<RealOpenMM>(parameters[j]); donorParamArray[i][j] = parameters[j];
} }
int numAcceptorParameters = force.getNumPerAcceptorParameters(); int numAcceptorParameters = force.getNumPerAcceptorParameters();
const vector<vector<int> >& acceptorAtoms = ixn->getAcceptorAtoms(); const vector<vector<int> >& acceptorAtoms = ixn->getAcceptorAtoms();
...@@ -1721,7 +1721,7 @@ void ReferenceCalcCustomHbondForceKernel::copyParametersToContext(ContextImpl& c ...@@ -1721,7 +1721,7 @@ void ReferenceCalcCustomHbondForceKernel::copyParametersToContext(ContextImpl& c
if (a1 != acceptorAtoms[i][0] || a2 != acceptorAtoms[i][1] || a3 != acceptorAtoms[i][2]) if (a1 != acceptorAtoms[i][0] || a2 != acceptorAtoms[i][1] || a3 != acceptorAtoms[i][2])
throw OpenMMException("updateParametersInContext: The set of particles in an acceptor group has changed"); throw OpenMMException("updateParametersInContext: The set of particles in an acceptor group has changed");
for (int j = 0; j < numAcceptorParameters; j++) for (int j = 0; j < numAcceptorParameters; j++)
acceptorParamArray[i][j] = static_cast<RealOpenMM>(parameters[j]); acceptorParamArray[i][j] = parameters[j];
} }
} }
...@@ -1751,7 +1751,7 @@ void ReferenceCalcCustomCentroidBondForceKernel::initialize(const System& system ...@@ -1751,7 +1751,7 @@ void ReferenceCalcCustomCentroidBondForceKernel::initialize(const System& system
vector<double> parameters; vector<double> parameters;
force.getBondParameters(i, bondGroups[i], parameters); force.getBondParameters(i, bondGroups[i], parameters);
for (int j = 0; j < numBondParameters; j++) for (int j = 0; j < numBondParameters; j++)
bondParamArray[i][j] = static_cast<RealOpenMM>(parameters[j]); bondParamArray[i][j] = parameters[j];
} }
// Create custom functions for the tabulated functions. // Create custom functions for the tabulated functions.
...@@ -1786,9 +1786,9 @@ void ReferenceCalcCustomCentroidBondForceKernel::initialize(const System& system ...@@ -1786,9 +1786,9 @@ void ReferenceCalcCustomCentroidBondForceKernel::initialize(const System& system
} }
double ReferenceCalcCustomCentroidBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCustomCentroidBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
RealOpenMM energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (int i = 0; i < (int) globalParameterNames.size(); i++)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]);
...@@ -1818,7 +1818,7 @@ void ReferenceCalcCustomCentroidBondForceKernel::copyParametersToContext(Context ...@@ -1818,7 +1818,7 @@ void ReferenceCalcCustomCentroidBondForceKernel::copyParametersToContext(Context
if (groups[j] != bondGroups[i][j]) if (groups[j] != bondGroups[i][j])
throw OpenMMException("updateParametersInContext: The set of groups in a bond has changed"); throw OpenMMException("updateParametersInContext: The set of groups in a bond has changed");
for (int j = 0; j < numParameters; j++) for (int j = 0; j < numParameters; j++)
bondParamArray[i][j] = (RealOpenMM) params[j]; bondParamArray[i][j] = params[j];
} }
} }
...@@ -1841,7 +1841,7 @@ void ReferenceCalcCustomCompoundBondForceKernel::initialize(const System& system ...@@ -1841,7 +1841,7 @@ void ReferenceCalcCustomCompoundBondForceKernel::initialize(const System& system
vector<double> parameters; vector<double> parameters;
force.getBondParameters(i, bondParticles[i], parameters); force.getBondParameters(i, bondParticles[i], parameters);
for (int j = 0; j < numBondParameters; j++) for (int j = 0; j < numBondParameters; j++)
bondParamArray[i][j] = static_cast<RealOpenMM>(parameters[j]); bondParamArray[i][j] = parameters[j];
} }
// Create custom functions for the tabulated functions. // Create custom functions for the tabulated functions.
...@@ -1876,9 +1876,9 @@ void ReferenceCalcCustomCompoundBondForceKernel::initialize(const System& system ...@@ -1876,9 +1876,9 @@ void ReferenceCalcCustomCompoundBondForceKernel::initialize(const System& system
} }
double ReferenceCalcCustomCompoundBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCustomCompoundBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
RealOpenMM energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (int i = 0; i < (int) globalParameterNames.size(); i++)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]);
...@@ -1908,7 +1908,7 @@ void ReferenceCalcCustomCompoundBondForceKernel::copyParametersToContext(Context ...@@ -1908,7 +1908,7 @@ void ReferenceCalcCustomCompoundBondForceKernel::copyParametersToContext(Context
if (particles[j] != bondAtoms[i][j]) if (particles[j] != bondAtoms[i][j])
throw OpenMMException("updateParametersInContext: The set of particles in a bond has changed"); throw OpenMMException("updateParametersInContext: The set of particles in a bond has changed");
for (int j = 0; j < numParameters; j++) for (int j = 0; j < numParameters; j++)
bondParamArray[i][j] = (RealOpenMM) params[j]; bondParamArray[i][j] = params[j];
} }
} }
...@@ -1940,14 +1940,14 @@ void ReferenceCalcCustomManyParticleForceKernel::initialize(const System& system ...@@ -1940,14 +1940,14 @@ void ReferenceCalcCustomManyParticleForceKernel::initialize(const System& system
} }
double ReferenceCalcCustomManyParticleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCustomManyParticleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
RealOpenMM energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (int i = 0; i < (int) globalParameterNames.size(); i++)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]);
if (nonbondedMethod == CutoffPeriodic) { if (nonbondedMethod == CutoffPeriodic) {
RealVec* boxVectors = extractBoxVectors(context); Vec3* boxVectors = extractBoxVectors(context);
double minAllowedSize = 2*cutoffDistance; double minAllowedSize = 2*cutoffDistance;
if (boxVectors[0][0] < minAllowedSize || boxVectors[1][1] < minAllowedSize || boxVectors[2][2] < minAllowedSize) if (boxVectors[0][0] < minAllowedSize || boxVectors[1][1] < minAllowedSize || boxVectors[2][2] < minAllowedSize)
throw OpenMMException("The periodic box size has decreased to less than twice the nonbonded cutoff."); throw OpenMMException("The periodic box size has decreased to less than twice the nonbonded cutoff.");
...@@ -1970,7 +1970,7 @@ void ReferenceCalcCustomManyParticleForceKernel::copyParametersToContext(Context ...@@ -1970,7 +1970,7 @@ void ReferenceCalcCustomManyParticleForceKernel::copyParametersToContext(Context
int type; int type;
force.getParticleParameters(i, parameters, type); force.getParticleParameters(i, parameters, type);
for (int j = 0; j < numParameters; j++) for (int j = 0; j < numParameters; j++)
particleParamArray[i][j] = static_cast<RealOpenMM>(parameters[j]); particleParamArray[i][j] = parameters[j];
} }
} }
...@@ -2002,20 +2002,20 @@ void ReferenceIntegrateVerletStepKernel::initialize(const System& system, const ...@@ -2002,20 +2002,20 @@ void ReferenceIntegrateVerletStepKernel::initialize(const System& system, const
int numParticles = system.getNumParticles(); int numParticles = system.getNumParticles();
masses.resize(numParticles); masses.resize(numParticles);
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < numParticles; ++i)
masses[i] = static_cast<RealOpenMM>(system.getParticleMass(i)); masses[i] = system.getParticleMass(i);
} }
void ReferenceIntegrateVerletStepKernel::execute(ContextImpl& context, const VerletIntegrator& integrator) { void ReferenceIntegrateVerletStepKernel::execute(ContextImpl& context, const VerletIntegrator& integrator) {
double stepSize = integrator.getStepSize(); double stepSize = integrator.getStepSize();
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& velData = extractVelocities(context); vector<Vec3>& velData = extractVelocities(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
if (dynamics == 0 || stepSize != prevStepSize) { if (dynamics == 0 || stepSize != prevStepSize) {
// Recreate the computation objects with the new parameters. // Recreate the computation objects with the new parameters.
if (dynamics) if (dynamics)
delete dynamics; delete dynamics;
dynamics = new ReferenceVerletDynamics(context.getSystem().getNumParticles(), static_cast<RealOpenMM>(stepSize)); dynamics = new ReferenceVerletDynamics(context.getSystem().getNumParticles(), stepSize);
dynamics->setReferenceConstraintAlgorithm(&extractConstraints(context)); dynamics->setReferenceConstraintAlgorithm(&extractConstraints(context));
prevStepSize = stepSize; prevStepSize = stepSize;
} }
...@@ -2037,7 +2037,7 @@ void ReferenceIntegrateLangevinStepKernel::initialize(const System& system, cons ...@@ -2037,7 +2037,7 @@ void ReferenceIntegrateLangevinStepKernel::initialize(const System& system, cons
int numParticles = system.getNumParticles(); int numParticles = system.getNumParticles();
masses.resize(numParticles); masses.resize(numParticles);
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < numParticles; ++i)
masses[i] = static_cast<RealOpenMM>(system.getParticleMass(i)); masses[i] = system.getParticleMass(i);
SimTKOpenMMUtilities::setRandomNumberSeed((unsigned int) integrator.getRandomNumberSeed()); SimTKOpenMMUtilities::setRandomNumberSeed((unsigned int) integrator.getRandomNumberSeed());
} }
...@@ -2045,9 +2045,9 @@ void ReferenceIntegrateLangevinStepKernel::execute(ContextImpl& context, const L ...@@ -2045,9 +2045,9 @@ void ReferenceIntegrateLangevinStepKernel::execute(ContextImpl& context, const L
double temperature = integrator.getTemperature(); double temperature = integrator.getTemperature();
double friction = integrator.getFriction(); double friction = integrator.getFriction();
double stepSize = integrator.getStepSize(); double stepSize = integrator.getStepSize();
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& velData = extractVelocities(context); vector<Vec3>& velData = extractVelocities(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
if (dynamics == 0 || temperature != prevTemp || friction != prevFriction || stepSize != prevStepSize) { if (dynamics == 0 || temperature != prevTemp || friction != prevFriction || stepSize != prevStepSize) {
// Recreate the computation objects with the new parameters. // Recreate the computation objects with the new parameters.
...@@ -2055,9 +2055,9 @@ void ReferenceIntegrateLangevinStepKernel::execute(ContextImpl& context, const L ...@@ -2055,9 +2055,9 @@ void ReferenceIntegrateLangevinStepKernel::execute(ContextImpl& context, const L
delete dynamics; delete dynamics;
dynamics = new ReferenceStochasticDynamics( dynamics = new ReferenceStochasticDynamics(
context.getSystem().getNumParticles(), context.getSystem().getNumParticles(),
static_cast<RealOpenMM>(stepSize), stepSize,
static_cast<RealOpenMM>(friction), friction,
static_cast<RealOpenMM>(temperature)); temperature);
dynamics->setReferenceConstraintAlgorithm(&extractConstraints(context)); dynamics->setReferenceConstraintAlgorithm(&extractConstraints(context));
prevTemp = temperature; prevTemp = temperature;
prevFriction = friction; prevFriction = friction;
...@@ -2081,7 +2081,7 @@ void ReferenceIntegrateBrownianStepKernel::initialize(const System& system, cons ...@@ -2081,7 +2081,7 @@ void ReferenceIntegrateBrownianStepKernel::initialize(const System& system, cons
int numParticles = system.getNumParticles(); int numParticles = system.getNumParticles();
masses.resize(numParticles); masses.resize(numParticles);
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < numParticles; ++i)
masses[i] = static_cast<RealOpenMM>(system.getParticleMass(i)); masses[i] = system.getParticleMass(i);
SimTKOpenMMUtilities::setRandomNumberSeed((unsigned int) integrator.getRandomNumberSeed()); SimTKOpenMMUtilities::setRandomNumberSeed((unsigned int) integrator.getRandomNumberSeed());
} }
...@@ -2089,9 +2089,9 @@ void ReferenceIntegrateBrownianStepKernel::execute(ContextImpl& context, const B ...@@ -2089,9 +2089,9 @@ void ReferenceIntegrateBrownianStepKernel::execute(ContextImpl& context, const B
double temperature = integrator.getTemperature(); double temperature = integrator.getTemperature();
double friction = integrator.getFriction(); double friction = integrator.getFriction();
double stepSize = integrator.getStepSize(); double stepSize = integrator.getStepSize();
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& velData = extractVelocities(context); vector<Vec3>& velData = extractVelocities(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
if (dynamics == 0 || temperature != prevTemp || friction != prevFriction || stepSize != prevStepSize) { if (dynamics == 0 || temperature != prevTemp || friction != prevFriction || stepSize != prevStepSize) {
// Recreate the computation objects with the new parameters. // Recreate the computation objects with the new parameters.
...@@ -2099,9 +2099,9 @@ void ReferenceIntegrateBrownianStepKernel::execute(ContextImpl& context, const B ...@@ -2099,9 +2099,9 @@ void ReferenceIntegrateBrownianStepKernel::execute(ContextImpl& context, const B
delete dynamics; delete dynamics;
dynamics = new ReferenceBrownianDynamics( dynamics = new ReferenceBrownianDynamics(
context.getSystem().getNumParticles(), context.getSystem().getNumParticles(),
static_cast<RealOpenMM>(stepSize), stepSize,
static_cast<RealOpenMM>(friction), friction,
static_cast<RealOpenMM>(temperature)); temperature);
dynamics->setReferenceConstraintAlgorithm(&extractConstraints(context)); dynamics->setReferenceConstraintAlgorithm(&extractConstraints(context));
prevTemp = temperature; prevTemp = temperature;
prevFriction = friction; prevFriction = friction;
...@@ -2125,7 +2125,7 @@ void ReferenceIntegrateVariableLangevinStepKernel::initialize(const System& syst ...@@ -2125,7 +2125,7 @@ void ReferenceIntegrateVariableLangevinStepKernel::initialize(const System& syst
int numParticles = system.getNumParticles(); int numParticles = system.getNumParticles();
masses.resize(numParticles); masses.resize(numParticles);
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < numParticles; ++i)
masses[i] = static_cast<RealOpenMM>(system.getParticleMass(i)); masses[i] = system.getParticleMass(i);
SimTKOpenMMUtilities::setRandomNumberSeed((unsigned int) integrator.getRandomNumberSeed()); SimTKOpenMMUtilities::setRandomNumberSeed((unsigned int) integrator.getRandomNumberSeed());
} }
...@@ -2133,21 +2133,21 @@ double ReferenceIntegrateVariableLangevinStepKernel::execute(ContextImpl& contex ...@@ -2133,21 +2133,21 @@ double ReferenceIntegrateVariableLangevinStepKernel::execute(ContextImpl& contex
double temperature = integrator.getTemperature(); double temperature = integrator.getTemperature();
double friction = integrator.getFriction(); double friction = integrator.getFriction();
double errorTol = integrator.getErrorTolerance(); double errorTol = integrator.getErrorTolerance();
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& velData = extractVelocities(context); vector<Vec3>& velData = extractVelocities(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
if (dynamics == 0 || temperature != prevTemp || friction != prevFriction || errorTol != prevErrorTol) { if (dynamics == 0 || temperature != prevTemp || friction != prevFriction || errorTol != prevErrorTol) {
// Recreate the computation objects with the new parameters. // Recreate the computation objects with the new parameters.
if (dynamics) if (dynamics)
delete dynamics; delete dynamics;
dynamics = new ReferenceVariableStochasticDynamics(context.getSystem().getNumParticles(), (RealOpenMM) friction, (RealOpenMM) temperature, (RealOpenMM) errorTol); dynamics = new ReferenceVariableStochasticDynamics(context.getSystem().getNumParticles(), friction, temperature, errorTol);
dynamics->setReferenceConstraintAlgorithm(&extractConstraints(context)); dynamics->setReferenceConstraintAlgorithm(&extractConstraints(context));
prevTemp = temperature; prevTemp = temperature;
prevFriction = friction; prevFriction = friction;
prevErrorTol = errorTol; prevErrorTol = errorTol;
} }
RealOpenMM maxStepSize = (RealOpenMM) (maxTime-data.time); double maxStepSize = maxTime-data.time;
dynamics->update(context.getSystem(), posData, velData, forceData, masses, maxStepSize, integrator.getConstraintTolerance()); dynamics->update(context.getSystem(), posData, velData, forceData, masses, maxStepSize, integrator.getConstraintTolerance());
data.time += dynamics->getDeltaT(); data.time += dynamics->getDeltaT();
if (dynamics->getDeltaT() == maxStepSize) if (dynamics->getDeltaT() == maxStepSize)
...@@ -2169,24 +2169,24 @@ void ReferenceIntegrateVariableVerletStepKernel::initialize(const System& system ...@@ -2169,24 +2169,24 @@ void ReferenceIntegrateVariableVerletStepKernel::initialize(const System& system
int numParticles = system.getNumParticles(); int numParticles = system.getNumParticles();
masses.resize(numParticles); masses.resize(numParticles);
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < numParticles; ++i)
masses[i] = static_cast<RealOpenMM>(system.getParticleMass(i)); masses[i] = system.getParticleMass(i);
} }
double ReferenceIntegrateVariableVerletStepKernel::execute(ContextImpl& context, const VariableVerletIntegrator& integrator, double maxTime) { double ReferenceIntegrateVariableVerletStepKernel::execute(ContextImpl& context, const VariableVerletIntegrator& integrator, double maxTime) {
double errorTol = integrator.getErrorTolerance(); double errorTol = integrator.getErrorTolerance();
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& velData = extractVelocities(context); vector<Vec3>& velData = extractVelocities(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
if (dynamics == 0 || errorTol != prevErrorTol) { if (dynamics == 0 || errorTol != prevErrorTol) {
// Recreate the computation objects with the new parameters. // Recreate the computation objects with the new parameters.
if (dynamics) if (dynamics)
delete dynamics; delete dynamics;
dynamics = new ReferenceVariableVerletDynamics(context.getSystem().getNumParticles(), (RealOpenMM) errorTol); dynamics = new ReferenceVariableVerletDynamics(context.getSystem().getNumParticles(), errorTol);
dynamics->setReferenceConstraintAlgorithm(&extractConstraints(context)); dynamics->setReferenceConstraintAlgorithm(&extractConstraints(context));
prevErrorTol = errorTol; prevErrorTol = errorTol;
} }
RealOpenMM maxStepSize = (RealOpenMM) (maxTime-data.time); double maxStepSize = maxTime-data.time;
dynamics->update(context.getSystem(), posData, velData, forceData, masses, maxStepSize, integrator.getConstraintTolerance()); dynamics->update(context.getSystem(), posData, velData, forceData, masses, maxStepSize, integrator.getConstraintTolerance());
data.time += dynamics->getDeltaT(); data.time += dynamics->getDeltaT();
if (dynamics->getDeltaT() == maxStepSize) if (dynamics->getDeltaT() == maxStepSize)
...@@ -2208,7 +2208,7 @@ void ReferenceIntegrateCustomStepKernel::initialize(const System& system, const ...@@ -2208,7 +2208,7 @@ void ReferenceIntegrateCustomStepKernel::initialize(const System& system, const
int numParticles = system.getNumParticles(); int numParticles = system.getNumParticles();
masses.resize(numParticles); masses.resize(numParticles);
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < numParticles; ++i)
masses[i] = static_cast<RealOpenMM>(system.getParticleMass(i)); masses[i] = system.getParticleMass(i);
perDofValues.resize(integrator.getNumPerDofVariables()); perDofValues.resize(integrator.getNumPerDofVariables());
for (int i = 0; i < (int) perDofValues.size(); i++) for (int i = 0; i < (int) perDofValues.size(); i++)
perDofValues[i].resize(numParticles); perDofValues[i].resize(numParticles);
...@@ -2220,9 +2220,9 @@ void ReferenceIntegrateCustomStepKernel::initialize(const System& system, const ...@@ -2220,9 +2220,9 @@ void ReferenceIntegrateCustomStepKernel::initialize(const System& system, const
} }
void ReferenceIntegrateCustomStepKernel::execute(ContextImpl& context, CustomIntegrator& integrator, bool& forcesAreValid) { void ReferenceIntegrateCustomStepKernel::execute(ContextImpl& context, CustomIntegrator& integrator, bool& forcesAreValid) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& velData = extractVelocities(context); vector<Vec3>& velData = extractVelocities(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
// Record global variables. // Record global variables.
...@@ -2246,9 +2246,9 @@ void ReferenceIntegrateCustomStepKernel::execute(ContextImpl& context, CustomInt ...@@ -2246,9 +2246,9 @@ void ReferenceIntegrateCustomStepKernel::execute(ContextImpl& context, CustomInt
} }
double ReferenceIntegrateCustomStepKernel::computeKineticEnergy(ContextImpl& context, CustomIntegrator& integrator, bool& forcesAreValid) { double ReferenceIntegrateCustomStepKernel::computeKineticEnergy(ContextImpl& context, CustomIntegrator& integrator, bool& forcesAreValid) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
vector<RealVec>& velData = extractVelocities(context); vector<Vec3>& velData = extractVelocities(context);
vector<RealVec>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
// Record global variables. // Record global variables.
...@@ -2291,18 +2291,18 @@ void ReferenceApplyAndersenThermostatKernel::initialize(const System& system, co ...@@ -2291,18 +2291,18 @@ void ReferenceApplyAndersenThermostatKernel::initialize(const System& system, co
int numParticles = system.getNumParticles(); int numParticles = system.getNumParticles();
masses.resize(numParticles); masses.resize(numParticles);
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < numParticles; ++i)
masses[i] = static_cast<RealOpenMM>(system.getParticleMass(i)); masses[i] = system.getParticleMass(i);
this->thermostat = new ReferenceAndersenThermostat(); this->thermostat = new ReferenceAndersenThermostat();
SimTKOpenMMUtilities::setRandomNumberSeed((unsigned int) thermostat.getRandomNumberSeed()); SimTKOpenMMUtilities::setRandomNumberSeed((unsigned int) thermostat.getRandomNumberSeed());
particleGroups = AndersenThermostatImpl::calcParticleGroups(system); particleGroups = AndersenThermostatImpl::calcParticleGroups(system);
} }
void ReferenceApplyAndersenThermostatKernel::execute(ContextImpl& context) { void ReferenceApplyAndersenThermostatKernel::execute(ContextImpl& context) {
vector<RealVec>& velData = extractVelocities(context); vector<Vec3>& velData = extractVelocities(context);
thermostat->applyThermostat(particleGroups, velData, masses, thermostat->applyThermostat(particleGroups, velData, masses,
static_cast<RealOpenMM>(context.getParameter(AndersenThermostat::Temperature())), context.getParameter(AndersenThermostat::Temperature()),
static_cast<RealOpenMM>(context.getParameter(AndersenThermostat::CollisionFrequency())), context.getParameter(AndersenThermostat::CollisionFrequency()),
static_cast<RealOpenMM>(context.getIntegrator().getStepSize())); context.getIntegrator().getStepSize());
} }
ReferenceApplyMonteCarloBarostatKernel::~ReferenceApplyMonteCarloBarostatKernel() { ReferenceApplyMonteCarloBarostatKernel::~ReferenceApplyMonteCarloBarostatKernel() {
...@@ -2316,13 +2316,13 @@ void ReferenceApplyMonteCarloBarostatKernel::initialize(const System& system, co ...@@ -2316,13 +2316,13 @@ void ReferenceApplyMonteCarloBarostatKernel::initialize(const System& system, co
void ReferenceApplyMonteCarloBarostatKernel::scaleCoordinates(ContextImpl& context, double scaleX, double scaleY, double scaleZ) { void ReferenceApplyMonteCarloBarostatKernel::scaleCoordinates(ContextImpl& context, double scaleX, double scaleY, double scaleZ) {
if (barostat == NULL) if (barostat == NULL)
barostat = new ReferenceMonteCarloBarostat(context.getSystem().getNumParticles(), context.getMolecules()); barostat = new ReferenceMonteCarloBarostat(context.getSystem().getNumParticles(), context.getMolecules());
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
RealVec* boxVectors = extractBoxVectors(context); Vec3* boxVectors = extractBoxVectors(context);
barostat->applyBarostat(posData, boxVectors, scaleX, scaleY, scaleZ); barostat->applyBarostat(posData, boxVectors, scaleX, scaleY, scaleZ);
} }
void ReferenceApplyMonteCarloBarostatKernel::restoreCoordinates(ContextImpl& context) { void ReferenceApplyMonteCarloBarostatKernel::restoreCoordinates(ContextImpl& context) {
vector<RealVec>& posData = extractPositions(context); vector<Vec3>& posData = extractPositions(context);
barostat->restorePositions(posData); barostat->restorePositions(posData);
} }
...@@ -2336,17 +2336,17 @@ void ReferenceRemoveCMMotionKernel::initialize(const System& system, const CMMot ...@@ -2336,17 +2336,17 @@ void ReferenceRemoveCMMotionKernel::initialize(const System& system, const CMMot
void ReferenceRemoveCMMotionKernel::execute(ContextImpl& context) { void ReferenceRemoveCMMotionKernel::execute(ContextImpl& context) {
if (data.stepCount%frequency != 0) if (data.stepCount%frequency != 0)
return; return;
vector<RealVec>& velData = extractVelocities(context); vector<Vec3>& velData = extractVelocities(context);
// Calculate the center of mass momentum. // Calculate the center of mass momentum.
RealOpenMM momentum[] = {0.0, 0.0, 0.0}; double momentum[] = {0.0, 0.0, 0.0};
RealOpenMM mass = 0.0; double mass = 0.0;
for (size_t i = 0; i < masses.size(); ++i) { for (size_t i = 0; i < masses.size(); ++i) {
momentum[0] += static_cast<RealOpenMM>(masses[i]*velData[i][0]); momentum[0] += masses[i]*velData[i][0];
momentum[1] += static_cast<RealOpenMM>(masses[i]*velData[i][1]); momentum[1] += masses[i]*velData[i][1];
momentum[2] += static_cast<RealOpenMM>(masses[i]*velData[i][2]); momentum[2] += masses[i]*velData[i][2];
mass += static_cast<RealOpenMM>(masses[i]); mass += masses[i];
} }
// Adjust the particle velocities. // Adjust the particle velocities.
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include "ReferenceKernels.h" #include "ReferenceKernels.h"
#include "openmm/internal/ContextImpl.h" #include "openmm/internal/ContextImpl.h"
#include "SimTKOpenMMRealType.h" #include "SimTKOpenMMRealType.h"
#include "RealVec.h" #include "openmm/Vec3.h"
#include <map> #include <map>
#include <vector> #include <vector>
...@@ -82,7 +82,7 @@ double ReferencePlatform::getSpeed() const { ...@@ -82,7 +82,7 @@ double ReferencePlatform::getSpeed() const {
} }
bool ReferencePlatform::supportsDoublePrecision() const { bool ReferencePlatform::supportsDoublePrecision() const {
return (sizeof(RealOpenMM) >= sizeof(double)); return true;
} }
void ReferencePlatform::contextCreated(ContextImpl& context, const map<string, string>& properties) const { void ReferencePlatform::contextCreated(ContextImpl& context, const map<string, string>& properties) const {
...@@ -95,21 +95,21 @@ void ReferencePlatform::contextDestroyed(ContextImpl& context) const { ...@@ -95,21 +95,21 @@ void ReferencePlatform::contextDestroyed(ContextImpl& context) const {
} }
ReferencePlatform::PlatformData::PlatformData(const System& system) : time(0.0), stepCount(0), numParticles(system.getNumParticles()) { ReferencePlatform::PlatformData::PlatformData(const System& system) : time(0.0), stepCount(0), numParticles(system.getNumParticles()) {
positions = new vector<RealVec>(numParticles); positions = new vector<Vec3>(numParticles);
velocities = new vector<RealVec>(numParticles); velocities = new vector<Vec3>(numParticles);
forces = new vector<RealVec>(numParticles); forces = new vector<Vec3>(numParticles);
periodicBoxSize = new RealVec(); periodicBoxSize = new Vec3();
periodicBoxVectors = new RealVec[3]; periodicBoxVectors = new Vec3[3];
constraints = new ReferenceConstraints(system); constraints = new ReferenceConstraints(system);
energyParameterDerivatives = new map<string, double>(); energyParameterDerivatives = new map<string, double>();
} }
ReferencePlatform::PlatformData::~PlatformData() { ReferencePlatform::PlatformData::~PlatformData() {
delete (vector<RealVec>*) positions; delete (vector<Vec3>*) positions;
delete (vector<RealVec>*) velocities; delete (vector<Vec3>*) velocities;
delete (vector<RealVec>*) forces; delete (vector<Vec3>*) forces;
delete (RealVec*) periodicBoxSize; delete (Vec3*) periodicBoxSize;
delete[] (RealVec*) periodicBoxVectors; delete[] (Vec3*) periodicBoxVectors;
delete (ReferenceConstraints*) constraints; delete (ReferenceConstraints*) constraints;
delete (map<string, double>*) energyParameterDerivatives; delete (map<string, double>*) energyParameterDerivatives;
} }
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
#include "ObcParameters.h" #include "ObcParameters.h"
#include "SimTKOpenMMRealType.h"
using std::vector; using std::vector;
using namespace OpenMM; using namespace OpenMM;
...@@ -121,7 +122,7 @@ void ObcParameters::setObcTypeParameters(ObcParameters::ObcType obcType) { ...@@ -121,7 +122,7 @@ void ObcParameters::setObcTypeParameters(ObcParameters::ObcType obcType) {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcParameters::getDielectricOffset() const { double ObcParameters::getDielectricOffset() const {
return _dielectricOffset; return _dielectricOffset;
} }
...@@ -133,7 +134,7 @@ RealOpenMM ObcParameters::getDielectricOffset() const { ...@@ -133,7 +134,7 @@ RealOpenMM ObcParameters::getDielectricOffset() const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcParameters::getAlphaObc() const { double ObcParameters::getAlphaObc() const {
return _alphaObc; return _alphaObc;
} }
...@@ -145,7 +146,7 @@ RealOpenMM ObcParameters::getAlphaObc() const { ...@@ -145,7 +146,7 @@ RealOpenMM ObcParameters::getAlphaObc() const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcParameters::getBetaObc() const { double ObcParameters::getBetaObc() const {
return _betaObc; return _betaObc;
} }
...@@ -157,7 +158,7 @@ RealOpenMM ObcParameters::getBetaObc() const { ...@@ -157,7 +158,7 @@ RealOpenMM ObcParameters::getBetaObc() const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcParameters::getGammaObc() const { double ObcParameters::getGammaObc() const {
return _gammaObc; return _gammaObc;
} }
...@@ -169,7 +170,7 @@ RealOpenMM ObcParameters::getGammaObc() const { ...@@ -169,7 +170,7 @@ RealOpenMM ObcParameters::getGammaObc() const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcParameters::getSolventDielectric() const { double ObcParameters::getSolventDielectric() const {
return _solventDielectric; return _solventDielectric;
} }
...@@ -181,7 +182,7 @@ RealOpenMM ObcParameters::getSolventDielectric() const { ...@@ -181,7 +182,7 @@ RealOpenMM ObcParameters::getSolventDielectric() const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcParameters::setSolventDielectric(RealOpenMM solventDielectric) { void ObcParameters::setSolventDielectric(double solventDielectric) {
_solventDielectric = solventDielectric; _solventDielectric = solventDielectric;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -192,7 +193,7 @@ void ObcParameters::setSolventDielectric(RealOpenMM solventDielectric) { ...@@ -192,7 +193,7 @@ void ObcParameters::setSolventDielectric(RealOpenMM solventDielectric) {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcParameters::getSoluteDielectric() const { double ObcParameters::getSoluteDielectric() const {
return _soluteDielectric; return _soluteDielectric;
} }
...@@ -204,7 +205,7 @@ RealOpenMM ObcParameters::getSoluteDielectric() const { ...@@ -204,7 +205,7 @@ RealOpenMM ObcParameters::getSoluteDielectric() const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcParameters::setSoluteDielectric(RealOpenMM soluteDielectric) { void ObcParameters::setSoluteDielectric(double soluteDielectric) {
_soluteDielectric = soluteDielectric; _soluteDielectric = soluteDielectric;
} }
...@@ -216,7 +217,7 @@ void ObcParameters::setSoluteDielectric(RealOpenMM soluteDielectric) { ...@@ -216,7 +217,7 @@ void ObcParameters::setSoluteDielectric(RealOpenMM soluteDielectric) {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcParameters::getElectricConstant() const { double ObcParameters::getElectricConstant() const {
return _electricConstant; return _electricConstant;
} }
...@@ -228,7 +229,7 @@ RealOpenMM ObcParameters::getElectricConstant() const { ...@@ -228,7 +229,7 @@ RealOpenMM ObcParameters::getElectricConstant() const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcParameters::getProbeRadius() const { double ObcParameters::getProbeRadius() const {
return _probeRadius; return _probeRadius;
} }
...@@ -240,25 +241,25 @@ RealOpenMM ObcParameters::getProbeRadius() const { ...@@ -240,25 +241,25 @@ RealOpenMM ObcParameters::getProbeRadius() const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcParameters::setProbeRadius(RealOpenMM probeRadius) { void ObcParameters::setProbeRadius(double probeRadius) {
_probeRadius = probeRadius; _probeRadius = probeRadius;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
Get pi*4*Asolv: used in ACE approximation for nonpolar term Get pi*4*Asolv: used in ACE approximation for nonpolar term
((RealOpenMM) M_PI)*4.0f*0.0049*1000.0; (Still) M_PI*4.0f*0.0049*1000.0; (Still)
((RealOpenMM) M_PI)*4.0f*0.0054*1000.0; (OBC) M_PI*4.0f*0.0054*1000.0; (OBC)
@return pi4Asolv @return pi4Asolv
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcParameters::getPi4Asolv() const { double ObcParameters::getPi4Asolv() const {
return _pi4Asolv; return _pi4Asolv;
} }
void ObcParameters::setPi4Asolv(RealOpenMM pi4Asolv) { void ObcParameters::setPi4Asolv(double pi4Asolv) {
_pi4Asolv = pi4Asolv; _pi4Asolv = pi4Asolv;
} }
...@@ -270,7 +271,7 @@ void ObcParameters::setPi4Asolv(RealOpenMM pi4Asolv) { ...@@ -270,7 +271,7 @@ void ObcParameters::setPi4Asolv(RealOpenMM pi4Asolv) {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
const vector<RealOpenMM>& ObcParameters::getAtomicRadii() const { const vector<double>& ObcParameters::getAtomicRadii() const {
return _atomicRadii; return _atomicRadii;
} }
...@@ -282,7 +283,7 @@ const vector<RealOpenMM>& ObcParameters::getAtomicRadii() const { ...@@ -282,7 +283,7 @@ const vector<RealOpenMM>& ObcParameters::getAtomicRadii() const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcParameters::setAtomicRadii(const vector<RealOpenMM>& atomicRadii) { void ObcParameters::setAtomicRadii(const vector<double>& atomicRadii) {
if (atomicRadii.size() == _atomicRadii.size()) { if (atomicRadii.size() == _atomicRadii.size()) {
for (unsigned int ii = 0; ii < atomicRadii.size(); ii++) { for (unsigned int ii = 0; ii < atomicRadii.size(); ii++) {
...@@ -306,7 +307,7 @@ void ObcParameters::setAtomicRadii(const vector<RealOpenMM>& atomicRadii) { ...@@ -306,7 +307,7 @@ void ObcParameters::setAtomicRadii(const vector<RealOpenMM>& atomicRadii) {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
const vector<RealOpenMM>& ObcParameters::getScaledRadiusFactors() const { const vector<double>& ObcParameters::getScaledRadiusFactors() const {
return _scaledRadiusFactors; return _scaledRadiusFactors;
} }
...@@ -318,7 +319,7 @@ const vector<RealOpenMM>& ObcParameters::getScaledRadiusFactors() const { ...@@ -318,7 +319,7 @@ const vector<RealOpenMM>& ObcParameters::getScaledRadiusFactors() const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcParameters::setScaledRadiusFactors(const vector<RealOpenMM>& scaledRadiusFactors) { void ObcParameters::setScaledRadiusFactors(const vector<double>& scaledRadiusFactors) {
if (scaledRadiusFactors.size() == _scaledRadiusFactors.size()) { if (scaledRadiusFactors.size() == _scaledRadiusFactors.size()) {
for (unsigned int ii = 0; ii < scaledRadiusFactors.size(); ii++) { for (unsigned int ii = 0; ii < scaledRadiusFactors.size(); ii++) {
...@@ -342,7 +343,7 @@ void ObcParameters::setScaledRadiusFactors(const vector<RealOpenMM>& scaledRadiu ...@@ -342,7 +343,7 @@ void ObcParameters::setScaledRadiusFactors(const vector<RealOpenMM>& scaledRadiu
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcParameters::setUseCutoff(RealOpenMM distance) { void ObcParameters::setUseCutoff(double distance) {
_cutoff = true; _cutoff = true;
_cutoffDistance = distance; _cutoffDistance = distance;
...@@ -364,7 +365,7 @@ bool ObcParameters::getUseCutoff() const { ...@@ -364,7 +365,7 @@ bool ObcParameters::getUseCutoff() const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ObcParameters::getCutoffDistance() const { double ObcParameters::getCutoffDistance() const {
return _cutoffDistance; return _cutoffDistance;
} }
...@@ -378,7 +379,7 @@ RealOpenMM ObcParameters::getCutoffDistance() const { ...@@ -378,7 +379,7 @@ RealOpenMM ObcParameters::getCutoffDistance() const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ObcParameters::setPeriodic(OpenMM::RealVec* vectors) { void ObcParameters::setPeriodic(OpenMM::Vec3* vectors) {
assert(_cutoff); assert(_cutoff);
...@@ -408,6 +409,6 @@ bool ObcParameters::getPeriodic() { ...@@ -408,6 +409,6 @@ bool ObcParameters::getPeriodic() {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
const OpenMM::RealVec* ObcParameters::getPeriodicBox() { const OpenMM::Vec3* ObcParameters::getPeriodicBox() {
return _periodicBoxVectors; return _periodicBoxVectors;
} }
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <cmath>
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
...@@ -61,10 +62,10 @@ using namespace OpenMM; ...@@ -61,10 +62,10 @@ using namespace OpenMM;
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceAndersenThermostat::applyThermostat(const vector<vector<int> >& atomGroups, vector<RealVec>& atomVelocities, vector<RealOpenMM>& atomMasses, void ReferenceAndersenThermostat::applyThermostat(const vector<vector<int> >& atomGroups, vector<Vec3>& atomVelocities, vector<double>& atomMasses,
RealOpenMM temperature, RealOpenMM collisionFrequency, RealOpenMM stepSize) const { double temperature, double collisionFrequency, double stepSize) const {
const RealOpenMM collisionProbability = 1.0f - EXP(-collisionFrequency*stepSize); const double collisionProbability = 1.0f - exp(-collisionFrequency*stepSize);
for (int i = 0; i < (int) atomGroups.size(); ++i) { for (int i = 0; i < (int) atomGroups.size(); ++i) {
if (SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber() < collisionProbability) { if (SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber() < collisionProbability) {
...@@ -73,7 +74,7 @@ using namespace OpenMM; ...@@ -73,7 +74,7 @@ using namespace OpenMM;
for (int j = 0; j < (int) atomGroups[i].size(); j++) { for (int j = 0; j < (int) atomGroups[i].size(); j++) {
int atom = atomGroups[i][j]; int atom = atomGroups[i][j];
if (atomMasses[atom] != 0) { if (atomMasses[atom] != 0) {
const RealOpenMM velocityScale = static_cast<RealOpenMM>(sqrt(BOLTZ*temperature/atomMasses[atom])); const double velocityScale = static_cast<double>(sqrt(BOLTZ*temperature/atomMasses[atom]));
atomVelocities[atom][0] = velocityScale*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber(); atomVelocities[atom][0] = velocityScale*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber();
atomVelocities[atom][1] = velocityScale*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber(); atomVelocities[atom][1] = velocityScale*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber();
atomVelocities[atom][2] = velocityScale*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber(); atomVelocities[atom][2] = velocityScale*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber();
......
...@@ -39,13 +39,6 @@ using namespace OpenMM; ...@@ -39,13 +39,6 @@ using namespace OpenMM;
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceAngleBondIxn::ReferenceAngleBondIxn() : usePeriodic(false) { ReferenceAngleBondIxn::ReferenceAngleBondIxn() : usePeriodic(false) {
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceAngleBondIxn::ReferenceAngleBondIxn";
// ---------------------------------------------------------------------------------------
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -55,16 +48,9 @@ ReferenceAngleBondIxn::ReferenceAngleBondIxn() : usePeriodic(false) { ...@@ -55,16 +48,9 @@ ReferenceAngleBondIxn::ReferenceAngleBondIxn() : usePeriodic(false) {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceAngleBondIxn::~ReferenceAngleBondIxn() { ReferenceAngleBondIxn::~ReferenceAngleBondIxn() {
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceAngleBondIxn::~ReferenceAngleBondIxn";
// ---------------------------------------------------------------------------------------
} }
void ReferenceAngleBondIxn::setPeriodic(OpenMM::RealVec* vectors) { void ReferenceAngleBondIxn::setPeriodic(OpenMM::Vec3* vectors) {
usePeriodic = true; usePeriodic = true;
boxVectors[0] = vectors[0]; boxVectors[0] = vectors[0];
boxVectors[1] = vectors[1]; boxVectors[1] = vectors[1];
...@@ -83,32 +69,22 @@ void ReferenceAngleBondIxn::setPeriodic(OpenMM::RealVec* vectors) { ...@@ -83,32 +69,22 @@ void ReferenceAngleBondIxn::setPeriodic(OpenMM::RealVec* vectors) {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceAngleBondIxn::getPrefactorsGivenAngleCosine(RealOpenMM cosine, RealOpenMM* angleParameters, void ReferenceAngleBondIxn::getPrefactorsGivenAngleCosine(double cosine, double* angleParameters,
RealOpenMM* dEdR, RealOpenMM* energyTerm) const { double* dEdR, double* energyTerm) const {
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nReferenceAngleBondIxn::getPrefactorsGivenAngleCosine";
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
static const RealOpenMM half = 0.5;
// --------------------------------------------------------------------------------------- double angle;
if (cosine >= 1.0) {
RealOpenMM angle; angle = 0.0;
if (cosine >= one) { } else if (cosine <= -1.0) {
angle = zero;
} else if (cosine <= -one) {
angle = PI_M; angle = PI_M;
} else { } else {
angle = ACOS(cosine); angle = acos(cosine);
} }
RealOpenMM deltaIdeal = angle - angleParameters[0]; double deltaIdeal = angle - angleParameters[0];
RealOpenMM deltaIdeal2 = deltaIdeal*deltaIdeal; double deltaIdeal2 = deltaIdeal*deltaIdeal;
*dEdR = angleParameters[1]*deltaIdeal; *dEdR = angleParameters[1]*deltaIdeal;
*energyTerm = half*angleParameters[1]*deltaIdeal2; *energyTerm = 0.5*angleParameters[1]*deltaIdeal2;
} }
...@@ -126,24 +102,14 @@ void ReferenceAngleBondIxn::getPrefactorsGivenAngleCosine(RealOpenMM cosine, Rea ...@@ -126,24 +102,14 @@ void ReferenceAngleBondIxn::getPrefactorsGivenAngleCosine(RealOpenMM cosine, Rea
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceAngleBondIxn::calculateBondIxn(int* atomIndices, void ReferenceAngleBondIxn::calculateBondIxn(int* atomIndices,
vector<RealVec>& atomCoordinates, vector<Vec3>& atomCoordinates,
RealOpenMM* parameters, double* parameters,
vector<RealVec>& forces, vector<Vec3>& forces,
RealOpenMM* totalEnergy, double* energyParamDerivs) { double* totalEnergy, double* energyParamDerivs) {
// constants -- reduce Visual Studio warnings regarding conversions between float & double
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
static const RealOpenMM two = 2.0;
static const RealOpenMM three = 3.0;
static const RealOpenMM oneM = -1.0;
static const int threeI = 3;
static const int LastAtomIndex = 3; static const int LastAtomIndex = 3;
RealOpenMM deltaR[2][ReferenceForce::LastDeltaRIndex]; double deltaR[2][ReferenceForce::LastDeltaRIndex];
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
...@@ -161,37 +127,36 @@ void ReferenceAngleBondIxn::calculateBondIxn(int* atomIndices, ...@@ -161,37 +127,36 @@ void ReferenceAngleBondIxn::calculateBondIxn(int* atomIndices,
ReferenceForce::getDeltaR(atomCoordinates[atomCIndex], atomCoordinates[atomBIndex], deltaR[1]); ReferenceForce::getDeltaR(atomCoordinates[atomCIndex], atomCoordinates[atomBIndex], deltaR[1]);
} }
RealOpenMM pVector[threeI]; double pVector[3];
SimTKOpenMMUtilities::crossProductVector3(deltaR[0], deltaR[1], pVector); SimTKOpenMMUtilities::crossProductVector3(deltaR[0], deltaR[1], pVector);
RealOpenMM rp = DOT3(pVector, pVector); double rp = sqrt(DOT3(pVector, pVector));
rp = SQRT(rp);
if (rp < 1.0e-06) { if (rp < 1.0e-06) {
rp = (RealOpenMM) 1.0e-06; rp = 1.0e-06;
} }
RealOpenMM dot = DOT3(deltaR[0], deltaR[1]); double dot = DOT3(deltaR[0], deltaR[1]);
RealOpenMM cosine = dot/SQRT((deltaR[0][ReferenceForce::R2Index]*deltaR[1][ReferenceForce::R2Index])); double cosine = dot/sqrt((deltaR[0][ReferenceForce::R2Index]*deltaR[1][ReferenceForce::R2Index]));
RealOpenMM dEdR; double dEdR;
RealOpenMM energy; double energy;
getPrefactorsGivenAngleCosine(cosine, parameters, &dEdR, &energy); getPrefactorsGivenAngleCosine(cosine, parameters, &dEdR, &energy);
RealOpenMM termA = dEdR/(deltaR[0][ReferenceForce::R2Index]*rp); double termA = dEdR/(deltaR[0][ReferenceForce::R2Index]*rp);
RealOpenMM termC = -dEdR/(deltaR[1][ReferenceForce::R2Index]*rp); double termC = -dEdR/(deltaR[1][ReferenceForce::R2Index]*rp);
RealOpenMM deltaCrossP[LastAtomIndex][threeI]; double deltaCrossP[LastAtomIndex][3];
SimTKOpenMMUtilities::crossProductVector3(deltaR[0], pVector, deltaCrossP[0]); SimTKOpenMMUtilities::crossProductVector3(deltaR[0], pVector, deltaCrossP[0]);
SimTKOpenMMUtilities::crossProductVector3(deltaR[1], pVector, deltaCrossP[2]); SimTKOpenMMUtilities::crossProductVector3(deltaR[1], pVector, deltaCrossP[2]);
for (int ii = 0; ii < threeI; ii++) { for (int ii = 0; ii < 3; ii++) {
deltaCrossP[0][ii] *= termA; deltaCrossP[0][ii] *= termA;
deltaCrossP[2][ii] *= termC; deltaCrossP[2][ii] *= termC;
deltaCrossP[1][ii] = oneM*(deltaCrossP[0][ii] + deltaCrossP[2][ii]); deltaCrossP[1][ii] = -(deltaCrossP[0][ii] + deltaCrossP[2][ii]);
} }
// accumulate forces // accumulate forces
for (int jj = 0; jj < LastAtomIndex; jj++) { for (int jj = 0; jj < LastAtomIndex; jj++) {
for (int ii = 0; ii < threeI; ii++) { for (int ii = 0; ii < 3; ii++) {
forces[atomIndices[jj]][ii] += deltaCrossP[jj][ii]; forces[atomIndices[jj]][ii] += deltaCrossP[jj][ii];
} }
} }
......
...@@ -38,13 +38,6 @@ using namespace OpenMM; ...@@ -38,13 +38,6 @@ using namespace OpenMM;
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceBondForce::ReferenceBondForce() { ReferenceBondForce::ReferenceBondForce() {
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceBondForce::ReferenceBondForce";
// ---------------------------------------------------------------------------------------
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -54,13 +47,6 @@ ReferenceBondForce::ReferenceBondForce() { ...@@ -54,13 +47,6 @@ ReferenceBondForce::ReferenceBondForce() {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceBondForce::~ReferenceBondForce() { ReferenceBondForce::~ReferenceBondForce() {
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceBondForce::~ReferenceBondForce";
// ---------------------------------------------------------------------------------------
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -79,19 +65,12 @@ ReferenceBondForce::~ReferenceBondForce() { ...@@ -79,19 +65,12 @@ ReferenceBondForce::~ReferenceBondForce() {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceBondForce::calculateForce(int numberOfBonds, int** atomIndices, void ReferenceBondForce::calculateForce(int numberOfBonds, int** atomIndices,
vector<RealVec>& atomCoordinates, vector<Vec3>& atomCoordinates,
RealOpenMM** parameters, double** parameters,
vector<RealVec>& forces, vector<Vec3>& forces,
RealOpenMM *totalEnergy, double *totalEnergy,
ReferenceBondIxn& referenceBondIxn) { ReferenceBondIxn& referenceBondIxn) {
// ---------------------------------------------------------------------------------------
static const char* methodName = "\nReferenceBondForce::calculateForce";
// ---------------------------------------------------------------------------------------
for (int ii = 0; ii < numberOfBonds; ii++) { for (int ii = 0; ii < numberOfBonds; ii++) {
// calculate bond ixn // calculate bond ixn
......
...@@ -39,13 +39,6 @@ using namespace OpenMM; ...@@ -39,13 +39,6 @@ using namespace OpenMM;
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceBondIxn::ReferenceBondIxn() { ReferenceBondIxn::ReferenceBondIxn() {
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceBondIxn::ReferenceBondIxn";
// ---------------------------------------------------------------------------------------
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -55,13 +48,6 @@ ReferenceBondIxn::ReferenceBondIxn() { ...@@ -55,13 +48,6 @@ ReferenceBondIxn::ReferenceBondIxn() {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceBondIxn::~ReferenceBondIxn() { ReferenceBondIxn::~ReferenceBondIxn() {
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceBondIxn::~ReferenceBondIxn";
// ---------------------------------------------------------------------------------------
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -76,15 +62,9 @@ ReferenceBondIxn::~ReferenceBondIxn() { ...@@ -76,15 +62,9 @@ ReferenceBondIxn::~ReferenceBondIxn() {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceBondIxn::calculateBondIxn(int* atomIndices, vector<RealVec>& atomCoordinates, void ReferenceBondIxn::calculateBondIxn(int* atomIndices, vector<Vec3>& atomCoordinates,
RealOpenMM* parameters, vector<RealVec>& forces, double* parameters, vector<Vec3>& forces,
RealOpenMM* totalEnergy, double* energyParamDerivs) { double* totalEnergy, double* energyParamDerivs) {
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nReferenceBondIxn::calculateBondIxn";
// ---------------------------------------------------------------------------------------
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -102,67 +82,26 @@ ReferenceBondIxn::~ReferenceBondIxn() { ...@@ -102,67 +82,26 @@ ReferenceBondIxn::~ReferenceBondIxn() {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ReferenceBondIxn::getNormedDotProduct(RealOpenMM* vector1, RealOpenMM* vector2, double ReferenceBondIxn::getNormedDotProduct(double* vector1, double* vector2,
int hasREntry = 0) { int hasREntry = 0) {
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nReferenceBondIxn::getNormedDotProduct";
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
// ---------------------------------------------------------------------------------------
// for angles near pi, double is required due to the 'steepness' of acos()
// in this regime.
//#define USE_DOUBLE_FOR_NORMED_DOT_PRODUCT
#if defined USE_DOUBLE_FOR_NORMED_DOT_PRODUCT double dotProduct = DOT3(vector1, vector2);
double v1D[3]; if (dotProduct != 0.0) {
double v2D[3];
v1D[0] = static_cast<double>(vector1[0]);
v1D[1] = static_cast<double>(vector1[1]);
v1D[2] = static_cast<double>(vector1[2]);
v2D[0] = static_cast<double>(vector2[0]);
v2D[1] = static_cast<double>(vector2[1]);
v2D[2] = static_cast<double>(vector2[2]);
double dotProductD = DOT3(v1D, v2D);
if (dotProductD != 0.0) {
if (hasREntry) {
dotProductD /= (static_cast<double>(vector1[ReferenceForce::RIndex])*static_cast<double>(vector2[ReferenceForce::RIndex]));
} else {
double norm1 = DOT3(v1D, v1D);
double norm2 = DOT3(v2D, v2D);
dotProductD /= sqrt(norm1*norm2);
}
}
RealOpenMM dotProduct = static_cast<RealOpenMM>(dotProductD);
#else
RealOpenMM dotProduct = DOT3(vector1, vector2);
if (dotProduct != zero) {
if (hasREntry) { if (hasREntry) {
dotProduct /= (vector1[ReferenceForce::RIndex]*vector2[ReferenceForce::RIndex]); dotProduct /= (vector1[ReferenceForce::RIndex]*vector2[ReferenceForce::RIndex]);
} else { } else {
RealOpenMM norm1 = DOT3(vector1, vector1); double norm1 = DOT3(vector1, vector1);
RealOpenMM norm2 = DOT3(vector2, vector2); double norm2 = DOT3(vector2, vector2);
dotProduct /= SQRT(norm1*norm2); dotProduct /= sqrt(norm1*norm2);
} }
} }
#endif
#undef USE_DOUBLE_FOR_NORMED_DOT_PRODUCT
// clamp dot product to [-1,1] // clamp dot product to [-1,1]
if (dotProduct > one) { if (dotProduct > 1.0) {
dotProduct = one; dotProduct = 1.0;
} else if (dotProduct < -one) { } else if (dotProduct < -1.0) {
dotProduct = -one; dotProduct = -1.0;
} }
return dotProduct; return dotProduct;
...@@ -183,35 +122,26 @@ RealOpenMM ReferenceBondIxn::getNormedDotProduct(RealOpenMM* vector1, RealOpenMM ...@@ -183,35 +122,26 @@ RealOpenMM ReferenceBondIxn::getNormedDotProduct(RealOpenMM* vector1, RealOpenMM
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ReferenceBondIxn::getAngleBetweenTwoVectors(RealOpenMM* vector1, RealOpenMM* vector2, double ReferenceBondIxn::getAngleBetweenTwoVectors(double* vector1, double* vector2,
RealOpenMM* outputDotProduct = NULL, double* outputDotProduct = NULL,
int hasREntry = 0) { int hasREntry = 0) {
// --------------------------------------------------------------------------------------- // get dot product betweenn vectors and then angle
// static const std::string methodName = "\nReferenceBondIxn::getAngle"; double dotProduct = getNormedDotProduct(vector1, vector2, hasREntry);
static const RealOpenMM zero = 0.0; double angle;
static const RealOpenMM one = 1.0; if (dotProduct > 0.99 || dotProduct < -0.99) {
// ---------------------------------------------------------------------------------------
// get dot product betweenn vectors and then angle
RealOpenMM dotProduct = getNormedDotProduct(vector1, vector2, hasREntry);
RealOpenMM angle;
if (dotProduct > (RealOpenMM) 0.99 || dotProduct < (RealOpenMM) -0.99) {
// We're close to the singularity in acos(), so take the cross product and use asin() instead. // We're close to the singularity in acos(), so take the cross product and use asin() instead.
RealOpenMM cross[3]; double cross[3];
SimTKOpenMMUtilities::crossProductVector3(vector1, vector2, cross); SimTKOpenMMUtilities::crossProductVector3(vector1, vector2, cross);
RealOpenMM scale = DOT3(vector1, vector1)*DOT3(vector2, vector2); double scale = DOT3(vector1, vector1)*DOT3(vector2, vector2);
angle = ASIN(SQRT(DOT3(cross, cross)/scale)); angle = asin(sqrt(DOT3(cross, cross)/scale));
if (dotProduct < zero) if (dotProduct < 0.0)
angle = (RealOpenMM) (M_PI-angle); angle = M_PI-angle;
} else { } else {
angle = ACOS(dotProduct); angle = acos(dotProduct);
} }
if (outputDotProduct) { if (outputDotProduct) {
...@@ -240,29 +170,20 @@ RealOpenMM ReferenceBondIxn::getAngleBetweenTwoVectors(RealOpenMM* vector1, Real ...@@ -240,29 +170,20 @@ RealOpenMM ReferenceBondIxn::getAngleBetweenTwoVectors(RealOpenMM* vector1, Real
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ReferenceBondIxn::getDihedralAngleBetweenThreeVectors(RealOpenMM* vector1, double ReferenceBondIxn::getDihedralAngleBetweenThreeVectors(double* vector1,
RealOpenMM* vector2, double* vector2,
RealOpenMM* vector3, double* vector3,
RealOpenMM** outputCrossProduct = NULL, double** outputCrossProduct = NULL,
RealOpenMM* cosineOfAngle = NULL, double* cosineOfAngle = NULL,
RealOpenMM* signVector = NULL, double* signVector = NULL,
RealOpenMM* signOfAngle = NULL, double* signOfAngle = NULL,
int hasREntry = 0) { int hasREntry = 0) {
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "\nReferenceBondIxn::getDihedralAngleBetweenThreeVectors";
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
RealOpenMM tempVectors[6] = { zero, zero, zero, zero, zero, zero };
// --------------------------------------------------------------------------------------- double tempVectors[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
// get cross products between vectors and then angle between cross product vectors // get cross products between vectors and then angle between cross product vectors
RealOpenMM* crossProduct[2]; double* crossProduct[2];
if (outputCrossProduct) { if (outputCrossProduct) {
crossProduct[0] = outputCrossProduct[0]; crossProduct[0] = outputCrossProduct[0];
crossProduct[1] = outputCrossProduct[1]; crossProduct[1] = outputCrossProduct[1];
...@@ -274,13 +195,13 @@ RealOpenMM ReferenceBondIxn::getDihedralAngleBetweenThreeVectors(RealOpenMM* ve ...@@ -274,13 +195,13 @@ RealOpenMM ReferenceBondIxn::getDihedralAngleBetweenThreeVectors(RealOpenMM* ve
SimTKOpenMMUtilities::crossProductVector3(vector1, vector2, crossProduct[0]); SimTKOpenMMUtilities::crossProductVector3(vector1, vector2, crossProduct[0]);
SimTKOpenMMUtilities::crossProductVector3(vector2, vector3, crossProduct[1]); SimTKOpenMMUtilities::crossProductVector3(vector2, vector3, crossProduct[1]);
RealOpenMM angle = getAngleBetweenTwoVectors(crossProduct[0], crossProduct[1], cosineOfAngle, 0); double angle = getAngleBetweenTwoVectors(crossProduct[0], crossProduct[1], cosineOfAngle, 0);
// take care of sign of angle // take care of sign of angle
if (signVector) { if (signVector) {
RealOpenMM dotProduct = DOT3(signVector, crossProduct[1]); double dotProduct = DOT3(signVector, crossProduct[1]);
RealOpenMM sign = dotProduct < zero ? -one : one; double sign = dotProduct < 0.0 ? -1.0 : 1.0;
if (signOfAngle) { if (signOfAngle) {
*signOfAngle = sign; *signOfAngle = sign;
} }
......
...@@ -47,8 +47,8 @@ using namespace OpenMM; ...@@ -47,8 +47,8 @@ using namespace OpenMM;
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceBrownianDynamics::ReferenceBrownianDynamics(int numberOfAtoms, ReferenceBrownianDynamics::ReferenceBrownianDynamics(int numberOfAtoms,
RealOpenMM deltaT, RealOpenMM friction, double deltaT, double friction,
RealOpenMM temperature) : double temperature) :
ReferenceDynamics(numberOfAtoms, deltaT, temperature), friction(friction) { ReferenceDynamics(numberOfAtoms, deltaT, temperature), friction(friction) {
if (friction <= 0) { if (friction <= 0) {
...@@ -67,13 +67,6 @@ ReferenceBrownianDynamics::ReferenceBrownianDynamics(int numberOfAtoms, ...@@ -67,13 +67,6 @@ ReferenceBrownianDynamics::ReferenceBrownianDynamics(int numberOfAtoms,
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceBrownianDynamics::~ReferenceBrownianDynamics() { ReferenceBrownianDynamics::~ReferenceBrownianDynamics() {
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceBrownianDynamics::~ReferenceBrownianDynamics";
// ---------------------------------------------------------------------------------------
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -84,14 +77,7 @@ ReferenceBrownianDynamics::~ReferenceBrownianDynamics() { ...@@ -84,14 +77,7 @@ ReferenceBrownianDynamics::~ReferenceBrownianDynamics() {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
RealOpenMM ReferenceBrownianDynamics::getFriction() const { double ReferenceBrownianDynamics::getFriction() const {
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceBrownianDynamics::getFriction";
// ---------------------------------------------------------------------------------------
return friction; return friction;
} }
...@@ -108,18 +94,9 @@ RealOpenMM ReferenceBrownianDynamics::getFriction() const { ...@@ -108,18 +94,9 @@ RealOpenMM ReferenceBrownianDynamics::getFriction() const {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceBrownianDynamics::update(const OpenMM::System& system, vector<RealVec>& atomCoordinates, void ReferenceBrownianDynamics::update(const OpenMM::System& system, vector<Vec3>& atomCoordinates,
vector<RealVec>& velocities, vector<Vec3>& velocities,
vector<RealVec>& forces, vector<RealOpenMM>& masses, RealOpenMM tolerance) { vector<Vec3>& forces, vector<double>& masses, double tolerance) {
// ---------------------------------------------------------------------------------------
static const char* methodName = "\nReferenceBrownianDynamics::update";
static const RealOpenMM zero = 0.0;
static const RealOpenMM one = 1.0;
// ---------------------------------------------------------------------------------------
// first-time-through initialization // first-time-through initialization
...@@ -128,21 +105,21 @@ void ReferenceBrownianDynamics::update(const OpenMM::System& system, vector<Real ...@@ -128,21 +105,21 @@ void ReferenceBrownianDynamics::update(const OpenMM::System& system, vector<Real
// invert masses // invert masses
for (int ii = 0; ii < numberOfAtoms; ii++) { for (int ii = 0; ii < numberOfAtoms; ii++) {
if (masses[ii] == zero) if (masses[ii] == 0.0)
inverseMasses[ii] = zero; inverseMasses[ii] = 0.0;
else else
inverseMasses[ii] = one/masses[ii]; inverseMasses[ii] = 1.0/masses[ii];
} }
} }
// Perform the integration. // Perform the integration.
const RealOpenMM noiseAmplitude = static_cast<RealOpenMM>(sqrt(2.0*BOLTZ*getTemperature()*getDeltaT()/getFriction())); const double noiseAmplitude = sqrt(2.0*BOLTZ*getTemperature()*getDeltaT()/getFriction());
const RealOpenMM forceScale = getDeltaT()/getFriction(); const double forceScale = getDeltaT()/getFriction();
for (int i = 0; i < numberOfAtoms; ++i) { for (int i = 0; i < numberOfAtoms; ++i) {
if (masses[i] != zero) if (masses[i] != 0.0)
for (int j = 0; j < 3; ++j) { for (int j = 0; j < 3; ++j) {
xPrime[i][j] = atomCoordinates[i][j] + forceScale*inverseMasses[i]*forces[i][j] + noiseAmplitude*SQRT(inverseMasses[i])*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber(); xPrime[i][j] = atomCoordinates[i][j] + forceScale*inverseMasses[i]*forces[i][j] + noiseAmplitude*sqrt(inverseMasses[i])*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber();
} }
} }
ReferenceConstraintAlgorithm* referenceConstraintAlgorithm = getReferenceConstraintAlgorithm(); ReferenceConstraintAlgorithm* referenceConstraintAlgorithm = getReferenceConstraintAlgorithm();
...@@ -151,9 +128,9 @@ void ReferenceBrownianDynamics::update(const OpenMM::System& system, vector<Real ...@@ -151,9 +128,9 @@ void ReferenceBrownianDynamics::update(const OpenMM::System& system, vector<Real
// Update the positions and velocities. // Update the positions and velocities.
RealOpenMM velocityScale = static_cast<RealOpenMM>(1.0/getDeltaT()); double velocityScale = 1.0/getDeltaT();
for (int i = 0; i < numberOfAtoms; ++i) { for (int i = 0; i < numberOfAtoms; ++i) {
if (masses[i] != zero) if (masses[i] != 0.0)
for (int j = 0; j < 3; ++j) { for (int j = 0; j < 3; ++j) {
velocities[i][j] = velocityScale*(xPrime[i][j] - atomCoordinates[i][j]); velocities[i][j] = velocityScale*(xPrime[i][j] - atomCoordinates[i][j]);
atomCoordinates[i][j] = xPrime[i][j]; atomCoordinates[i][j] = xPrime[i][j];
......
...@@ -43,7 +43,7 @@ using namespace std; ...@@ -43,7 +43,7 @@ using namespace std;
class ExtractMatrixTask : public ThreadPool::Task { class ExtractMatrixTask : public ThreadPool::Task {
public: public:
ExtractMatrixTask(int numConstraints, vector<vector<pair<int, RealOpenMM> > >& transposedMatrix, const vector<RealOpenMM>& distance, RealOpenMM elementCutoff, ExtractMatrixTask(int numConstraints, vector<vector<pair<int, double> > >& transposedMatrix, const vector<double>& distance, double elementCutoff,
const int* qRowStart, const int* qColIndex, const int* rRowStart, const int* rColIndex, const double* qValue, const double* rValue) : const int* qRowStart, const int* qColIndex, const int* rRowStart, const int* rColIndex, const double* qValue, const double* rValue) :
numConstraints(numConstraints), transposedMatrix(transposedMatrix), distance(distance), elementCutoff(elementCutoff), qRowStart(qRowStart), qColIndex(qColIndex), numConstraints(numConstraints), transposedMatrix(transposedMatrix), distance(distance), elementCutoff(elementCutoff), qRowStart(qRowStart), qColIndex(qColIndex),
rRowStart(rRowStart), rColIndex(rColIndex), qValue(qValue), rValue(rValue) { rRowStart(rRowStart), rColIndex(rColIndex), qValue(qValue), rValue(rValue) {
...@@ -60,16 +60,16 @@ public: ...@@ -60,16 +60,16 @@ public:
QUERN_solve_with_r(numConstraints, rRowStart, rColIndex, rValue, &rhs[0], &rhs[0]); QUERN_solve_with_r(numConstraints, rRowStart, rColIndex, rValue, &rhs[0], &rhs[0]);
for (int j = 0; j < numConstraints; j++) { for (int j = 0; j < numConstraints; j++) {
double value = rhs[j]*distance[i]/distance[j]; double value = rhs[j]*distance[i]/distance[j];
if (FABS((RealOpenMM) value) > elementCutoff) if (fabs(value) > elementCutoff)
transposedMatrix[i].push_back(pair<int, RealOpenMM>(j, (RealOpenMM) value)); transposedMatrix[i].push_back(pair<int, double>(j, value));
} }
} }
} }
private: private:
int numConstraints; int numConstraints;
vector<vector<pair<int, RealOpenMM> > >& transposedMatrix; vector<vector<pair<int, double> > >& transposedMatrix;
const vector<RealOpenMM>& distance; const vector<double>& distance;
RealOpenMM elementCutoff; double elementCutoff;
const int *qRowStart, *qColIndex, *rRowStart, *rColIndex; const int *qRowStart, *qColIndex, *rRowStart, *rColIndex;
const double *qValue, *rValue; const double *qValue, *rValue;
}; };
...@@ -77,10 +77,10 @@ private: ...@@ -77,10 +77,10 @@ private:
ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms, ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms,
int numberOfConstraints, int numberOfConstraints,
const vector<pair<int, int> >& atomIndices, const vector<pair<int, int> >& atomIndices,
const vector<RealOpenMM>& distance, const vector<double>& distance,
vector<RealOpenMM>& masses, vector<double>& masses,
vector<AngleInfo>& angles, vector<AngleInfo>& angles,
RealOpenMM elementCutoff) { double elementCutoff) {
_numberOfConstraints = numberOfConstraints; _numberOfConstraints = numberOfConstraints;
_elementCutoff = elementCutoff; _elementCutoff = elementCutoff;
_atomIndices = atomIndices; _atomIndices = atomIndices;
...@@ -116,8 +116,8 @@ ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms, ...@@ -116,8 +116,8 @@ ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms,
int atomj1 = _atomIndices[j].second; int atomj1 = _atomIndices[j].second;
int atomk0 = _atomIndices[k].first; int atomk0 = _atomIndices[k].first;
int atomk1 = _atomIndices[k].second; int atomk1 = _atomIndices[k].second;
RealOpenMM invMass0 = 1/masses[atomj0]; double invMass0 = 1/masses[atomj0];
RealOpenMM invMass1 = 1/masses[atomj1]; double invMass1 = 1/masses[atomj1];
int atoma, atomb, atomc; int atoma, atomb, atomc;
if (atomj0 == atomk0) { if (atomj0 == atomk0) {
atoma = atomj1; atoma = atomj1;
...@@ -192,7 +192,7 @@ ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms, ...@@ -192,7 +192,7 @@ ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms,
double *qValue, *rValue; double *qValue, *rValue;
QUERN_compute_qr(numberOfConstraints, numberOfConstraints, &matrixRowStart[0], &matrixColIndex[0], &matrixValue[0], NULL, QUERN_compute_qr(numberOfConstraints, numberOfConstraints, &matrixRowStart[0], &matrixColIndex[0], &matrixValue[0], NULL,
&qRowStart, &qColIndex, &qValue, &rRowStart, &rColIndex, &rValue); &qRowStart, &qColIndex, &qValue, &rRowStart, &rColIndex, &rValue);
vector<vector<pair<int, RealOpenMM> > > transposedMatrix(numberOfConstraints); vector<vector<pair<int, double> > > transposedMatrix(numberOfConstraints);
_matrix.resize(numberOfConstraints); _matrix.resize(numberOfConstraints);
ThreadPool threads; ThreadPool threads;
ExtractMatrixTask task(numberOfConstraints, transposedMatrix, _distance, _elementCutoff, qRowStart, qColIndex, rRowStart, rColIndex, qValue, rValue); ExtractMatrixTask task(numberOfConstraints, transposedMatrix, _distance, _elementCutoff, qRowStart, qColIndex, rRowStart, rColIndex, qValue, rValue);
...@@ -203,7 +203,7 @@ ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms, ...@@ -203,7 +203,7 @@ ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms,
for (int i = 0; i < numberOfConstraints; i++) { for (int i = 0; i < numberOfConstraints; i++) {
for (int j = 0; j < transposedMatrix[i].size(); j++) { for (int j = 0; j < transposedMatrix[i].size(); j++) {
pair<int, RealOpenMM> value = transposedMatrix[i][j]; pair<int, double> value = transposedMatrix[i][j];
_matrix[value.first].push_back(make_pair(i, value.second)); _matrix[value.first].push_back(make_pair(i, value.second));
} }
} }
...@@ -232,25 +232,25 @@ void ReferenceCCMAAlgorithm::setMaximumNumberOfIterations(int maximumNumberOfIte ...@@ -232,25 +232,25 @@ void ReferenceCCMAAlgorithm::setMaximumNumberOfIterations(int maximumNumberOfIte
_maximumNumberOfIterations = maximumNumberOfIterations; _maximumNumberOfIterations = maximumNumberOfIterations;
} }
void ReferenceCCMAAlgorithm::apply(vector<RealVec>& atomCoordinates, void ReferenceCCMAAlgorithm::apply(vector<Vec3>& atomCoordinates,
vector<RealVec>& atomCoordinatesP, vector<Vec3>& atomCoordinatesP,
vector<RealOpenMM>& inverseMasses, RealOpenMM tolerance) { vector<double>& inverseMasses, double tolerance) {
applyConstraints(atomCoordinates, atomCoordinatesP, inverseMasses, false, tolerance); applyConstraints(atomCoordinates, atomCoordinatesP, inverseMasses, false, tolerance);
} }
void ReferenceCCMAAlgorithm::applyToVelocities(std::vector<OpenMM::RealVec>& atomCoordinates, void ReferenceCCMAAlgorithm::applyToVelocities(std::vector<OpenMM::Vec3>& atomCoordinates,
std::vector<OpenMM::RealVec>& velocities, std::vector<RealOpenMM>& inverseMasses, RealOpenMM tolerance) { std::vector<OpenMM::Vec3>& velocities, std::vector<double>& inverseMasses, double tolerance) {
applyConstraints(atomCoordinates, velocities, inverseMasses, true, tolerance); applyConstraints(atomCoordinates, velocities, inverseMasses, true, tolerance);
} }
void ReferenceCCMAAlgorithm::applyConstraints(vector<RealVec>& atomCoordinates, void ReferenceCCMAAlgorithm::applyConstraints(vector<Vec3>& atomCoordinates,
vector<RealVec>& atomCoordinatesP, vector<Vec3>& atomCoordinatesP,
vector<RealOpenMM>& inverseMasses, bool constrainingVelocities, RealOpenMM tolerance) { vector<double>& inverseMasses, bool constrainingVelocities, double tolerance) {
// temp arrays // temp arrays
vector<RealVec>& r_ij = _r_ij; vector<Vec3>& r_ij = _r_ij;
RealOpenMM* d_ij2 = _d_ij2; double* d_ij2 = _d_ij2;
RealOpenMM* reducedMasses = _reducedMasses; double* reducedMasses = _reducedMasses;
// calculate reduced masses on 1st pass // calculate reduced masses on 1st pass
...@@ -271,33 +271,33 @@ void ReferenceCCMAAlgorithm::applyConstraints(vector<RealVec>& atomCoordinates, ...@@ -271,33 +271,33 @@ void ReferenceCCMAAlgorithm::applyConstraints(vector<RealVec>& atomCoordinates,
r_ij[ii] = atomCoordinates[atomI] - atomCoordinates[atomJ]; r_ij[ii] = atomCoordinates[atomI] - atomCoordinates[atomJ];
d_ij2[ii] = r_ij[ii].dot(r_ij[ii]); d_ij2[ii] = r_ij[ii].dot(r_ij[ii]);
} }
RealOpenMM lowerTol = 1-2*tolerance+tolerance*tolerance; double lowerTol = 1-2*tolerance+tolerance*tolerance;
RealOpenMM upperTol = 1+2*tolerance+tolerance*tolerance; double upperTol = 1+2*tolerance+tolerance*tolerance;
// main loop // main loop
int iterations = 0; int iterations = 0;
int numberConverged = 0; int numberConverged = 0;
vector<RealOpenMM> constraintDelta(_numberOfConstraints); vector<double> constraintDelta(_numberOfConstraints);
vector<RealOpenMM> tempDelta(_numberOfConstraints); vector<double> tempDelta(_numberOfConstraints);
while (iterations < getMaximumNumberOfIterations()) { while (iterations < getMaximumNumberOfIterations()) {
numberConverged = 0; numberConverged = 0;
for (int ii = 0; ii < _numberOfConstraints; ii++) { for (int ii = 0; ii < _numberOfConstraints; ii++) {
int atomI = _atomIndices[ii].first; int atomI = _atomIndices[ii].first;
int atomJ = _atomIndices[ii].second; int atomJ = _atomIndices[ii].second;
RealVec rp_ij = atomCoordinatesP[atomI] - atomCoordinatesP[atomJ]; Vec3 rp_ij = atomCoordinatesP[atomI] - atomCoordinatesP[atomJ];
if (constrainingVelocities) { if (constrainingVelocities) {
RealOpenMM rrpr = rp_ij.dot(r_ij[ii]); double rrpr = rp_ij.dot(r_ij[ii]);
constraintDelta[ii] = -2*reducedMasses[ii]*rrpr/d_ij2[ii]; constraintDelta[ii] = -2*reducedMasses[ii]*rrpr/d_ij2[ii];
if (fabs(constraintDelta[ii]) <= tolerance) if (fabs(constraintDelta[ii]) <= tolerance)
numberConverged++; numberConverged++;
} }
else { else {
RealOpenMM rp2 = rp_ij.dot(rp_ij); double rp2 = rp_ij.dot(rp_ij);
RealOpenMM dist2 = _distance[ii]*_distance[ii]; double dist2 = _distance[ii]*_distance[ii];
RealOpenMM diff = dist2 - rp2; double diff = dist2 - rp2;
constraintDelta[ii] = 0; constraintDelta[ii] = 0;
RealOpenMM rrpr = DOT3(rp_ij, r_ij[ii]); double rrpr = DOT3(rp_ij, r_ij[ii]);
constraintDelta[ii] = reducedMasses[ii]*diff/rrpr; constraintDelta[ii] = reducedMasses[ii]*diff/rrpr;
if (rp2 >= lowerTol*dist2 && rp2 <= upperTol*dist2) if (rp2 >= lowerTol*dist2 && rp2 <= upperTol*dist2)
numberConverged++; numberConverged++;
...@@ -309,9 +309,9 @@ void ReferenceCCMAAlgorithm::applyConstraints(vector<RealVec>& atomCoordinates, ...@@ -309,9 +309,9 @@ void ReferenceCCMAAlgorithm::applyConstraints(vector<RealVec>& atomCoordinates,
if (_matrix.size() > 0) { if (_matrix.size() > 0) {
for (int i = 0; i < _numberOfConstraints; i++) { for (int i = 0; i < _numberOfConstraints; i++) {
RealOpenMM sum = 0.0; double sum = 0.0;
for (int j = 0; j < (int) _matrix[i].size(); j++) { for (int j = 0; j < (int) _matrix[i].size(); j++) {
pair<int, RealOpenMM> element = _matrix[i][j]; pair<int, double> element = _matrix[i][j];
sum += element.second*constraintDelta[element.first]; sum += element.second*constraintDelta[element.first];
} }
tempDelta[i] = sum; tempDelta[i] = sum;
...@@ -321,13 +321,13 @@ void ReferenceCCMAAlgorithm::applyConstraints(vector<RealVec>& atomCoordinates, ...@@ -321,13 +321,13 @@ void ReferenceCCMAAlgorithm::applyConstraints(vector<RealVec>& atomCoordinates,
for (int ii = 0; ii < _numberOfConstraints; ii++) { for (int ii = 0; ii < _numberOfConstraints; ii++) {
int atomI = _atomIndices[ii].first; int atomI = _atomIndices[ii].first;
int atomJ = _atomIndices[ii].second; int atomJ = _atomIndices[ii].second;
RealVec dr = r_ij[ii]*constraintDelta[ii]; Vec3 dr = r_ij[ii]*constraintDelta[ii];
atomCoordinatesP[atomI] += dr*inverseMasses[atomI]; atomCoordinatesP[atomI] += dr*inverseMasses[atomI];
atomCoordinatesP[atomJ] -= dr*inverseMasses[atomJ]; atomCoordinatesP[atomJ] -= dr*inverseMasses[atomJ];
} }
} }
} }
const vector<vector<pair<int, RealOpenMM> > >& ReferenceCCMAAlgorithm::getMatrix() const { const vector<vector<pair<int, double> > >& ReferenceCCMAAlgorithm::getMatrix() const {
return _matrix; return _matrix;
} }
...@@ -34,12 +34,12 @@ using namespace OpenMM; ...@@ -34,12 +34,12 @@ using namespace OpenMM;
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceCMAPTorsionIxn::ReferenceCMAPTorsionIxn(const vector<vector<vector<RealOpenMM> > >& coeff, ReferenceCMAPTorsionIxn::ReferenceCMAPTorsionIxn(const vector<vector<vector<double> > >& coeff,
const vector<int>& torsionMaps, const vector<vector<int> >& torsionIndices) : const vector<int>& torsionMaps, const vector<vector<int> >& torsionIndices) :
coeff(coeff), torsionMaps(torsionMaps), torsionIndices(torsionIndices), usePeriodic(false) { coeff(coeff), torsionMaps(torsionMaps), torsionIndices(torsionIndices), usePeriodic(false) {
} }
void ReferenceCMAPTorsionIxn::setPeriodic(OpenMM::RealVec* vectors) { void ReferenceCMAPTorsionIxn::setPeriodic(OpenMM::Vec3* vectors) {
usePeriodic = true; usePeriodic = true;
boxVectors[0] = vectors[0]; boxVectors[0] = vectors[0];
boxVectors[1] = vectors[1]; boxVectors[1] = vectors[1];
...@@ -59,7 +59,7 @@ void ReferenceCMAPTorsionIxn::setPeriodic(OpenMM::RealVec* vectors) { ...@@ -59,7 +59,7 @@ void ReferenceCMAPTorsionIxn::setPeriodic(OpenMM::RealVec* vectors) {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceCMAPTorsionIxn::calculateIxn(vector<RealVec>& atomCoordinates, vector<RealVec>& forces, RealOpenMM* totalEnergy) const { void ReferenceCMAPTorsionIxn::calculateIxn(vector<Vec3>& atomCoordinates, vector<Vec3>& forces, double* totalEnergy) const {
for (unsigned int i = 0; i < torsionMaps.size(); i++) for (unsigned int i = 0; i < torsionMaps.size(); i++)
calculateOneIxn(i, atomCoordinates, forces, totalEnergy); calculateOneIxn(i, atomCoordinates, forces, totalEnergy);
} }
...@@ -75,8 +75,8 @@ void ReferenceCMAPTorsionIxn::calculateIxn(vector<RealVec>& atomCoordinates, vec ...@@ -75,8 +75,8 @@ void ReferenceCMAPTorsionIxn::calculateIxn(vector<RealVec>& atomCoordinates, vec
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceCMAPTorsionIxn::calculateOneIxn(int index, vector<RealVec>& atomCoordinates, vector<RealVec>& forces, void ReferenceCMAPTorsionIxn::calculateOneIxn(int index, vector<Vec3>& atomCoordinates, vector<Vec3>& forces,
RealOpenMM* totalEnergy) const { double* totalEnergy) const {
int map = torsionMaps[index]; int map = torsionMaps[index];
int a1 = torsionIndices[index][0]; int a1 = torsionIndices[index][0];
int a2 = torsionIndices[index][1]; int a2 = torsionIndices[index][1];
...@@ -89,8 +89,8 @@ void ReferenceCMAPTorsionIxn::calculateOneIxn(int index, vector<RealVec>& atomCo ...@@ -89,8 +89,8 @@ void ReferenceCMAPTorsionIxn::calculateOneIxn(int index, vector<RealVec>& atomCo
// Compute deltas between the various atoms involved. // Compute deltas between the various atoms involved.
RealOpenMM deltaA[3][ReferenceForce::LastDeltaRIndex]; double deltaA[3][ReferenceForce::LastDeltaRIndex];
RealOpenMM deltaB[3][ReferenceForce::LastDeltaRIndex]; double deltaB[3][ReferenceForce::LastDeltaRIndex];
if (usePeriodic) { if (usePeriodic) {
ReferenceForce::getDeltaRPeriodic(atomCoordinates[a2], atomCoordinates[a1], boxVectors, deltaA[0]); ReferenceForce::getDeltaRPeriodic(atomCoordinates[a2], atomCoordinates[a1], boxVectors, deltaA[0]);
ReferenceForce::getDeltaRPeriodic(atomCoordinates[a2], atomCoordinates[a3], boxVectors, deltaA[1]); ReferenceForce::getDeltaRPeriodic(atomCoordinates[a2], atomCoordinates[a3], boxVectors, deltaA[1]);
...@@ -110,40 +110,40 @@ void ReferenceCMAPTorsionIxn::calculateOneIxn(int index, vector<RealVec>& atomCo ...@@ -110,40 +110,40 @@ void ReferenceCMAPTorsionIxn::calculateOneIxn(int index, vector<RealVec>& atomCo
// Visual Studio complains if crossProduct declared as 'crossProduct[2][3]' // Visual Studio complains if crossProduct declared as 'crossProduct[2][3]'
RealOpenMM crossProductMemory[12]; double crossProductMemory[12];
RealOpenMM* cpA[2]; double* cpA[2];
cpA[0] = crossProductMemory; cpA[0] = crossProductMemory;
cpA[1] = crossProductMemory + 3; cpA[1] = crossProductMemory + 3;
RealOpenMM* cpB[2]; double* cpB[2];
cpB[0] = crossProductMemory + 6; cpB[0] = crossProductMemory + 6;
cpB[1] = crossProductMemory + 9; cpB[1] = crossProductMemory + 9;
// Compute the dihedral angles. // Compute the dihedral angles.
RealOpenMM dotDihedral; double dotDihedral;
RealOpenMM signOfAngle; double signOfAngle;
RealOpenMM angleA = getDihedralAngleBetweenThreeVectors(deltaA[0], deltaA[1], deltaA[2], double angleA = getDihedralAngleBetweenThreeVectors(deltaA[0], deltaA[1], deltaA[2],
cpA, &dotDihedral, deltaA[0], &signOfAngle, 1); cpA, &dotDihedral, deltaA[0], &signOfAngle, 1);
RealOpenMM angleB = getDihedralAngleBetweenThreeVectors(deltaB[0], deltaB[1], deltaB[2], double angleB = getDihedralAngleBetweenThreeVectors(deltaB[0], deltaB[1], deltaB[2],
cpB, &dotDihedral, deltaB[0], &signOfAngle, 1); cpB, &dotDihedral, deltaB[0], &signOfAngle, 1);
angleA = fmod(angleA+2.0*M_PI, 2.0*M_PI); angleA = fmod(angleA+2.0*M_PI, 2.0*M_PI);
angleB = fmod(angleB+2.0*M_PI, 2.0*M_PI); angleB = fmod(angleB+2.0*M_PI, 2.0*M_PI);
// Identify which patch this is in. // Identify which patch this is in.
int size = (int) SQRT((RealOpenMM) coeff[map].size()); int size = (int) sqrt(coeff[map].size());
RealOpenMM delta = 2*M_PI/size; double delta = 2*M_PI/size;
int s = (int) (angleA/delta); int s = (int) (angleA/delta);
int t = (int) (angleB/delta); int t = (int) (angleB/delta);
const vector<RealOpenMM>& c = coeff[map][s+size*t]; const vector<double>& c = coeff[map][s+size*t];
RealOpenMM da = angleA/delta-s; double da = angleA/delta-s;
RealOpenMM db = angleB/delta-t; double db = angleB/delta-t;
// Evaluate the spline to determine the energy and gradients. // Evaluate the spline to determine the energy and gradients.
RealOpenMM energy = 0; double energy = 0;
RealOpenMM dEdA = 0; double dEdA = 0;
RealOpenMM dEdB = 0; double dEdB = 0;
for (int i = 3; i >= 0; i--) { for (int i = 3; i >= 0; i--) {
energy = da*energy + ((c[i*4+3]*db + c[i*4+2])*db + c[i*4+1])*db + c[i*4+0]; energy = da*energy + ((c[i*4+3]*db + c[i*4+2])*db + c[i*4+1])*db + c[i*4+0];
dEdA = db*dEdA + (3.0*c[i+3*4]*da + 2.0*c[i+2*4])*da + c[i+1*4]; dEdA = db*dEdA + (3.0*c[i+3*4]*da + 2.0*c[i+2*4])*da + c[i+1*4];
...@@ -156,20 +156,20 @@ void ReferenceCMAPTorsionIxn::calculateOneIxn(int index, vector<RealVec>& atomCo ...@@ -156,20 +156,20 @@ void ReferenceCMAPTorsionIxn::calculateOneIxn(int index, vector<RealVec>& atomCo
// Apply the force to the first torsion. // Apply the force to the first torsion.
RealOpenMM forceFactors[4]; double forceFactors[4];
RealOpenMM normCross1 = DOT3(cpA[0], cpA[0]); double normCross1 = DOT3(cpA[0], cpA[0]);
RealOpenMM normBC = deltaA[1][ReferenceForce::RIndex]; double normBC = deltaA[1][ReferenceForce::RIndex];
forceFactors[0] = (-dEdA*normBC)/normCross1; forceFactors[0] = (-dEdA*normBC)/normCross1;
RealOpenMM normCross2 = DOT3(cpA[1], cpA[1]); double normCross2 = DOT3(cpA[1], cpA[1]);
forceFactors[3] = (dEdA*normBC)/normCross2; forceFactors[3] = (dEdA*normBC)/normCross2;
forceFactors[1] = DOT3(deltaA[0], deltaA[1]); forceFactors[1] = DOT3(deltaA[0], deltaA[1]);
forceFactors[1] /= deltaA[1][ReferenceForce::R2Index]; forceFactors[1] /= deltaA[1][ReferenceForce::R2Index];
forceFactors[2] = DOT3(deltaA[2], deltaA[1]); forceFactors[2] = DOT3(deltaA[2], deltaA[1]);
forceFactors[2] /= deltaA[1][ReferenceForce::R2Index]; forceFactors[2] /= deltaA[1][ReferenceForce::R2Index];
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
RealOpenMM f0 = forceFactors[0]*cpA[0][i]; double f0 = forceFactors[0]*cpA[0][i];
RealOpenMM f3 = forceFactors[3]*cpA[1][i]; double f3 = forceFactors[3]*cpA[1][i];
RealOpenMM s = forceFactors[1]*f0 - forceFactors[2]*f3; double s = forceFactors[1]*f0 - forceFactors[2]*f3;
forces[a1][i] += f0; forces[a1][i] += f0;
forces[a2][i] -= f0-s; forces[a2][i] -= f0-s;
forces[a3][i] -= f3+s; forces[a3][i] -= f3+s;
...@@ -188,9 +188,9 @@ void ReferenceCMAPTorsionIxn::calculateOneIxn(int index, vector<RealVec>& atomCo ...@@ -188,9 +188,9 @@ void ReferenceCMAPTorsionIxn::calculateOneIxn(int index, vector<RealVec>& atomCo
forceFactors[2] = DOT3(deltaB[2], deltaB[1]); forceFactors[2] = DOT3(deltaB[2], deltaB[1]);
forceFactors[2] /= deltaB[1][ReferenceForce::R2Index]; forceFactors[2] /= deltaB[1][ReferenceForce::R2Index];
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
RealOpenMM f0 = forceFactors[0]*cpB[0][i]; double f0 = forceFactors[0]*cpB[0][i];
RealOpenMM f3 = forceFactors[3]*cpB[1][i]; double f3 = forceFactors[3]*cpB[1][i];
RealOpenMM s = forceFactors[1]*f0 - forceFactors[2]*f3; double s = forceFactors[1]*f0 - forceFactors[2]*f3;
forces[b1][i] += f0; forces[b1][i] += f0;
forces[b2][i] -= f0-s; forces[b2][i] -= f0-s;
forces[b3][i] -= f3+s; forces[b3][i] -= f3+s;
...@@ -206,6 +206,6 @@ void ReferenceCMAPTorsionIxn::calculateOneIxn(int index, vector<RealVec>& atomCo ...@@ -206,6 +206,6 @@ void ReferenceCMAPTorsionIxn::calculateOneIxn(int index, vector<RealVec>& atomCo
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void ReferenceCMAPTorsionIxn::calculateBondIxn(int* atomIndices, vector<RealVec>& atomCoordinates, void ReferenceCMAPTorsionIxn::calculateBondIxn(int* atomIndices, vector<Vec3>& atomCoordinates,
RealOpenMM* parameters, vector<RealVec>& forces, RealOpenMM* totalEnergy, double* energyParamDerivs) { double* parameters, vector<Vec3>& forces, double* totalEnergy, double* energyParamDerivs) {
} }
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