Commit 9f37b18b authored by peastman's avatar peastman
Browse files

Code cleanup to reference and CPU platforms

parent f9106ddb
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2014-2017 Stanford University and the Authors. *
* Portions copyright (c) 2014-2018 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -50,22 +50,22 @@ public:
/**
* Analyze the set of bonds and decide which to compute with each thread.
*/
void initialize(int numAtoms, int numBonds, int numAtomsPerBond, int** bondAtoms, ThreadPool& threads);
void initialize(int numAtoms, int numBonds, int numAtomsPerBond, std::vector<std::vector<int> >& bondAtoms, ThreadPool& threads);
/**
* Compute the forces from all bonds.
*/
void calculateForce(std::vector<OpenMM::Vec3>& atomCoordinates, double** parameters, std::vector<OpenMM::Vec3>& forces,
void calculateForce(std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<std::vector<double> >& parameters, std::vector<OpenMM::Vec3>& forces,
double* totalEnergy, ReferenceBondIxn& referenceBondIxn);
/**
* This routine contains the code executed by each thread.
*/
void threadComputeForce(ThreadPool& threads, int threadIndex, std::vector<OpenMM::Vec3>& atomCoordinates, double** parameters,
void threadComputeForce(ThreadPool& threads, int threadIndex, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<std::vector<double> >& parameters,
std::vector<OpenMM::Vec3>& forces, double* totalEnergy, ReferenceBondIxn& referenceBondIxn);
private:
bool canAssignBond(int bond, int thread, std::vector<int>& atomThread);
void assignBond(int bond, int thread, std::vector<int>& atomThread, std::vector<int>& bondThread, std::vector<std::set<int> >& atomBonds, std::list<int>& candidateBonds);
int numBonds, numAtomsPerBond;
int** bondAtoms;
std::vector<int>* bondAtoms;
ThreadPool* threads;
std::vector<std::vector<int> > threadBonds;
std::vector<int> extraBonds;
......
/* Portions copyright (c) 2009-2017 Stanford University and Simbios.
/* Portions copyright (c) 2009-2018 Stanford University and Simbios.
* Contributors: Peter Eastman
*
* Permission is hereby granted, free of charge, to any person obtaining
......@@ -59,7 +59,7 @@ private:
// The following variables are used to make information accessible to the individual threads.
int numberOfAtoms;
float* posq;
double** atomParameters;
std::vector<double>* atomParameters;
const std::map<std::string, double>* globalParameters;
std::vector<AlignedArray<float> >* threadForce;
bool includeForce, includeEnergy;
......@@ -81,7 +81,7 @@ private:
* @param useExclusions specifies whether to use exclusions
*/
void calculateParticlePairValue(int index, ThreadData& data, int numAtoms, float* posq, double** atomParameters,
void calculateParticlePairValue(int index, ThreadData& data, int numAtoms, float* posq, std::vector<double>* atomParameters,
bool useExclusions, const fvec4& boxSize, const fvec4& invBoxSize);
/**
......@@ -95,7 +95,7 @@ private:
* @param atomParameters atomParameters[atomIndex][paramterIndex]
*/
void calculateOnePairValue(int index, int atom1, int atom2, ThreadData& data, float* posq, double** atomParameters,
void calculateOnePairValue(int index, int atom1, int atom2, ThreadData& data, float* posq, std::vector<double>* atomParameters,
std::vector<float>& valueArray, const fvec4& boxSize, const fvec4& invBoxSize);
/**
......@@ -110,7 +110,7 @@ private:
* @param totalEnergy the energy contribution is added to this
*/
void calculateSingleParticleEnergyTerm(int index, ThreadData& data, int numAtoms, float* posq, double** atomParameters, float* forces, double& totalEnergy);
void calculateSingleParticleEnergyTerm(int index, ThreadData& data, int numAtoms, float* posq, std::vector<double>* atomParameters, float* forces, double& totalEnergy);
/**
* Calculate an energy term that is based on particle pairs
......@@ -125,7 +125,7 @@ private:
* @param totalEnergy the energy contribution is added to this
*/
void calculateParticlePairEnergyTerm(int index, ThreadData& data, int numAtoms, float* posq, double** atomParameters,
void calculateParticlePairEnergyTerm(int index, ThreadData& data, int numAtoms, float* posq, std::vector<double>* atomParameters,
bool useExclusions, float* forces, double& totalEnergy, const fvec4& boxSize, const fvec4& invBoxSize);
/**
......@@ -141,7 +141,7 @@ private:
* @param totalEnergy the energy contribution is added to this
*/
void calculateOnePairEnergyTerm(int index, int atom1, int atom2, ThreadData& data, float* posq, double** atomParameters,
void calculateOnePairEnergyTerm(int index, int atom1, int atom2, ThreadData& data, float* posq, std::vector<double>* atomParameters,
float* forces, double& totalEnergy, const fvec4& boxSize, const fvec4& invBoxSize);
/**
......@@ -154,7 +154,7 @@ private:
* @param forces forces on atoms are added to this
*/
void calculateChainRuleForces(ThreadData& data, int numAtoms, float* posq, double** atomParameters,
void calculateChainRuleForces(ThreadData& data, int numAtoms, float* posq, std::vector<double>* atomParameters,
float* forces, const fvec4& boxSize, const fvec4& invBoxSize);
/**
......@@ -169,7 +169,7 @@ private:
* @param isExcluded specifies whether this is an excluded pair
*/
void calculateOnePairChainRule(int atom1, int atom2, ThreadData& data, float* posq, double** atomParameters,
void calculateOnePairChainRule(int atom1, int atom2, ThreadData& data, float* posq, std::vector<double>* atomParameters,
float* forces, bool isExcluded, const fvec4& boxSize, const fvec4& invBoxSize);
/**
......@@ -231,7 +231,7 @@ public:
* @param energyParamDerivs derivatives of the energy with respect to global parameters
*/
void calculateIxn(int numberOfAtoms, float* posq, double** atomParameters, std::map<std::string, double>& globalParameters,
void calculateIxn(int numberOfAtoms, float* posq, std::vector<std::vector<double> >& atomParameters, std::map<std::string, double>& globalParameters,
std::vector<AlignedArray<float> >& threadForce, bool includeForce, bool includeEnergy, double& totalEnergy, double* energyParamDerivs);
};
......
/* Portions copyright (c) 2009-2017 Stanford University and Simbios.
/* Portions copyright (c) 2009-2018 Stanford University and Simbios.
* Contributors: Peter Eastman
*
* Permission is hereby granted, free of charge, to any person obtaining
......@@ -65,7 +65,7 @@ private:
std::vector<ThreadData*> threadData;
// The following variables are used to make information accessible to the individual threads.
float* posq;
double** particleParameters;
std::vector<double>* particleParameters;
const std::map<std::string, double>* globalParameters;
std::vector<AlignedArray<float> >* threadForce;
bool includeForces, includeEnergy;
......@@ -81,7 +81,7 @@ private:
* interaction for each one.
*/
void loopOverInteractions(std::vector<int>& availableParticles, std::vector<int>& particleSet, int loopIndex, int startIndex,
double** particleParameters, float* forces, ThreadData& data, const fvec4& boxSize, const fvec4& invBoxSize);
std::vector<double>* particleParameters, float* forces, ThreadData& data, const fvec4& boxSize, const fvec4& invBoxSize);
/**---------------------------------------------------------------------------------------
......@@ -104,7 +104,7 @@ private:
* @param boxSize the size of the periodic box
* @param invBoxSize the inverse size of the periodic box
*/
void calculateOneIxn(std::vector<int>& particleSet, double** particleParameters, float* forces, ThreadData& data, const fvec4& boxSize, const fvec4& invBoxSize);
void calculateOneIxn(std::vector<int>& particleSet, std::vector<double>* particleParameters, float* forces, ThreadData& data, const fvec4& boxSize, const fvec4& invBoxSize);
/**
* Compute the displacement and squared distance between two points, optionally using
......@@ -154,7 +154,7 @@ public:
* @param includeEnergy whether to compute energy
* @param energy the total energy is added to this
*/
void calculateIxn(AlignedArray<float>& posq, double** particleParameters, const std::map<std::string, double>& globalParameters,
void calculateIxn(AlignedArray<float>& posq, std::vector<std::vector<double> >& particleParameters, const std::map<std::string, double>& globalParameters,
std::vector<AlignedArray<float> >& threadForce, bool includeForces, bool includeEnergy, double& energy);
};
......
/* Portions copyright (c) 2009-2017 Stanford University and Simbios.
/* Portions copyright (c) 2009-2018 Stanford University and Simbios.
* Contributors: Peter Eastman
*
* Permission is hereby granted, free of charge, to any person obtaining
......@@ -110,7 +110,6 @@ class CpuCustomNonbondedForce {
@param posq atom coordinates in float format
@param atomCoordinates atom coordinates
@param atomParameters atom parameters (charges, c6, c12, ...) atomParameters[atomIndex][paramterIndex]
@param fixedParameters non atom parameters (not currently used)
@param globalParameters the values of global parameters
@param forces force array (forces added)
@param totalEnergy total energy
......@@ -118,9 +117,9 @@ class CpuCustomNonbondedForce {
--------------------------------------------------------------------------------------- */
void calculatePairIxn(int numberOfAtoms, float* posq, std::vector<OpenMM::Vec3>& atomCoordinates, double** atomParameters,
double* fixedParameters, const std::map<std::string, double>& globalParameters,
std::vector<AlignedArray<float> >& threadForce, bool includeForce, bool includeEnergy, double& totalEnergy, double* energyParamDerivs);
void calculatePairIxn(int numberOfAtoms, float* posq, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<std::vector<double> >& atomParameters,
const std::map<std::string, double>& globalParameters, std::vector<AlignedArray<float> >& threadForce,
bool includeForce, bool includeEnergy, double& totalEnergy, double* energyParamDerivs);
private:
class ThreadData;
......@@ -144,7 +143,7 @@ private:
int numberOfAtoms;
float* posq;
Vec3 const* atomCoordinates;
double** atomParameters;
std::vector<double>* atomParameters;
const std::map<std::string, double>* globalParameters;
std::vector<AlignedArray<float> >* threadForce;
bool includeForce, includeEnergy;
......
......@@ -98,9 +98,8 @@ private:
class CpuCalcHarmonicAngleForceKernel : public CalcHarmonicAngleForceKernel {
public:
CpuCalcHarmonicAngleForceKernel(std::string name, const Platform& platform, CpuPlatform::PlatformData& data) :
CalcHarmonicAngleForceKernel(name, platform), data(data), angleIndexArray(NULL), angleParamArray(NULL), usePeriodic(false) {
CalcHarmonicAngleForceKernel(name, platform), data(data), usePeriodic(false) {
}
~CpuCalcHarmonicAngleForceKernel();
/**
* Initialize the kernel.
*
......@@ -127,8 +126,8 @@ public:
private:
CpuPlatform::PlatformData& data;
int numAngles;
int **angleIndexArray;
double **angleParamArray;
std::vector<std::vector<int> > angleIndexArray;
std::vector<std::vector<double> > angleParamArray;
CpuBondForce bondForce;
bool usePeriodic;
};
......@@ -139,9 +138,8 @@ private:
class CpuCalcPeriodicTorsionForceKernel : public CalcPeriodicTorsionForceKernel {
public:
CpuCalcPeriodicTorsionForceKernel(std::string name, const Platform& platform, CpuPlatform::PlatformData& data) :
CalcPeriodicTorsionForceKernel(name, platform), data(data), torsionIndexArray(NULL), torsionParamArray(NULL), usePeriodic(false) {
CalcPeriodicTorsionForceKernel(name, platform), data(data), usePeriodic(false) {
}
~CpuCalcPeriodicTorsionForceKernel();
/**
* Initialize the kernel.
*
......@@ -168,8 +166,8 @@ public:
private:
CpuPlatform::PlatformData& data;
int numTorsions;
int **torsionIndexArray;
double **torsionParamArray;
std::vector<std::vector<int> > torsionIndexArray;
std::vector<std::vector<double> > torsionParamArray;
CpuBondForce bondForce;
bool usePeriodic;
};
......@@ -180,9 +178,8 @@ private:
class CpuCalcRBTorsionForceKernel : public CalcRBTorsionForceKernel {
public:
CpuCalcRBTorsionForceKernel(std::string name, const Platform& platform, CpuPlatform::PlatformData& data) :
CalcRBTorsionForceKernel(name, platform), data(data), torsionIndexArray(NULL), torsionParamArray(NULL), usePeriodic(false) {
CalcRBTorsionForceKernel(name, platform), data(data), usePeriodic(false) {
}
~CpuCalcRBTorsionForceKernel();
/**
* Initialize the kernel.
*
......@@ -209,8 +206,8 @@ public:
private:
CpuPlatform::PlatformData& data;
int numTorsions;
int **torsionIndexArray;
double **torsionParamArray;
std::vector<std::vector<int> > torsionIndexArray;
std::vector<std::vector<double> > torsionParamArray;
CpuBondForce bondForce;
bool usePeriodic;
};
......@@ -269,8 +266,8 @@ private:
class PmeIO;
CpuPlatform::PlatformData& data;
int numParticles, num14, posqIndex;
int **bonded14IndexArray;
double **bonded14ParamArray;
std::vector<std::vector<int> > bonded14IndexArray;
std::vector<std::vector<double> > bonded14ParamArray;
double nonbondedCutoff, switchingDistance, rfDielectric, ewaldAlpha, ewaldDispersionAlpha, ewaldSelfEnergy, dispersionCoefficient;
int kmax[3], gridSize[3], dispersionGridSize[3];
bool useSwitchingFunction, useOptimizedPme, hasInitializedPme, hasInitializedDispersionPme;
......@@ -317,7 +314,7 @@ public:
private:
CpuPlatform::PlatformData& data;
int numParticles;
double **particleParamArray;
std::vector<std::vector<double> > particleParamArray;
double nonbondedCutoff, switchingDistance, periodicBoxSize[3], longRangeCoefficient;
bool useSwitchingFunction, hasInitializedLongRangeCorrection;
CustomNonbondedForce* forceCopy;
......@@ -406,7 +403,7 @@ private:
CpuPlatform::PlatformData& data;
int numParticles;
bool isPeriodic;
double **particleParamArray;
std::vector<std::vector<double> > particleParamArray;
double nonbondedCutoff;
CpuCustomGBForce* ixn;
CpuNeighborList* neighborList;
......@@ -453,7 +450,7 @@ private:
CpuPlatform::PlatformData& data;
int numParticles;
double cutoffDistance;
double **particleParamArray;
std::vector<std::vector<double> > particleParamArray;
CpuCustomManyParticleForce* ixn;
std::vector<std::string> globalParameterNames;
NonbondedMethod nonbondedMethod;
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2014-2017 Stanford University and the Authors. *
* Portions copyright (c) 2014-2018 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -38,10 +38,10 @@ using namespace std;
CpuBondForce::CpuBondForce() {
}
void CpuBondForce::initialize(int numAtoms, int numBonds, int numAtomsPerBond, int** bondAtoms, ThreadPool& threads) {
void CpuBondForce::initialize(int numAtoms, int numBonds, int numAtomsPerBond, vector<vector<int> >& bondAtoms, ThreadPool& threads) {
this->numBonds = numBonds;
this->numAtomsPerBond = numAtomsPerBond;
this->bondAtoms = bondAtoms;
this->bondAtoms = &bondAtoms[0];
this->threads = &threads;
int numThreads = threads.getNumThreads();
int targetBondsPerThread = numBonds/numThreads;
......@@ -164,7 +164,7 @@ void CpuBondForce::assignBond(int bond, int thread, vector<int>& atomThread, vec
}
}
void CpuBondForce::calculateForce(vector<Vec3>& atomCoordinates, double** parameters, vector<Vec3>& forces,
void CpuBondForce::calculateForce(vector<Vec3>& atomCoordinates, vector<vector<double> >& parameters, vector<Vec3>& forces,
double* totalEnergy, ReferenceBondIxn& referenceBondIxn) {
// Have the worker threads compute their forces.
......@@ -189,7 +189,7 @@ void CpuBondForce::calculateForce(vector<Vec3>& atomCoordinates, double** parame
*totalEnergy += threadEnergy[i];
}
void CpuBondForce::threadComputeForce(ThreadPool& threads, int threadIndex, vector<Vec3>& atomCoordinates, double** parameters, vector<Vec3>& forces,
void CpuBondForce::threadComputeForce(ThreadPool& threads, int threadIndex, vector<Vec3>& atomCoordinates, vector<vector<double> >& parameters, vector<Vec3>& forces,
double* totalEnergy, ReferenceBondIxn& referenceBondIxn) {
vector<int>& bonds = threadBonds[threadIndex];
int numBonds = bonds.size();
......
/* Portions copyright (c) 2009-2017 Stanford University and Simbios.
/* Portions copyright (c) 2009-2018 Stanford University and Simbios.
* Contributors: Peter Eastman
*
* Permission is hereby granted, free of charge, to any person obtaining
......@@ -178,14 +178,14 @@ void CpuCustomGBForce::setPeriodic(Vec3& boxSize) {
periodicBoxSize[2] = boxSize[2];
}
void CpuCustomGBForce::calculateIxn(int numberOfAtoms, float* posq, double** atomParameters,
void CpuCustomGBForce::calculateIxn(int numberOfAtoms, float* posq, vector<vector<double> >& atomParameters,
map<string, double>& globalParameters, vector<AlignedArray<float> >& threadForce,
bool includeForce, bool includeEnergy, double& totalEnergy, double* energyParamDerivs) {
// Record the parameters for the threads.
this->numberOfAtoms = numberOfAtoms;
this->posq = posq;
this->atomParameters = atomParameters;
this->atomParameters = &atomParameters[0];
this->globalParameters = &globalParameters;
this->threadForce = &threadForce;
this->includeForce = includeForce;
......@@ -352,7 +352,7 @@ void CpuCustomGBForce::threadComputeForce(ThreadPool& threads, int threadIndex)
calculateChainRuleForces(data, numberOfAtoms, posq, atomParameters, forces, boxSize, invBoxSize);
}
void CpuCustomGBForce::calculateParticlePairValue(int index, ThreadData& data, int numAtoms, float* posq, double** atomParameters,
void CpuCustomGBForce::calculateParticlePairValue(int index, ThreadData& data, int numAtoms, float* posq, vector<double>* atomParameters,
bool useExclusions, const fvec4& boxSize, const fvec4& invBoxSize) {
for (int i = 0; i < numAtoms; i++)
values[index][i] = 0.0f;
......@@ -399,7 +399,7 @@ void CpuCustomGBForce::calculateParticlePairValue(int index, ThreadData& data, i
}
}
void CpuCustomGBForce::calculateOnePairValue(int index, int atom1, int atom2, ThreadData& data, float* posq, double** atomParameters,
void CpuCustomGBForce::calculateOnePairValue(int index, int atom1, int atom2, ThreadData& data, float* posq, vector<double>* atomParameters,
vector<float>& valueArray, const fvec4& boxSize, const fvec4& invBoxSize) {
fvec4 deltaR;
fvec4 pos1(posq+4*atom1);
......@@ -426,7 +426,7 @@ void CpuCustomGBForce::calculateOnePairValue(int index, int atom1, int atom2, Th
}
void CpuCustomGBForce::calculateSingleParticleEnergyTerm(int index, ThreadData& data, int numAtoms, float* posq,
double** atomParameters, float* forces, double& totalEnergy) {
vector<double>* atomParameters, float* forces, double& totalEnergy) {
for (int i = data.firstAtom; i < data.lastAtom; i++) {
data.x = posq[4*i];
data.y = posq[4*i+1];
......@@ -450,7 +450,7 @@ void CpuCustomGBForce::calculateSingleParticleEnergyTerm(int index, ThreadData&
}
}
void CpuCustomGBForce::calculateParticlePairEnergyTerm(int index, ThreadData& data, int numAtoms, float* posq, double** atomParameters,
void CpuCustomGBForce::calculateParticlePairEnergyTerm(int index, ThreadData& data, int numAtoms, float* posq, vector<double>* atomParameters,
bool useExclusions, float* forces, double& totalEnergy, const fvec4& boxSize, const fvec4& invBoxSize) {
if (cutoff) {
// Loop over all pairs in the neighbor list.
......@@ -492,7 +492,7 @@ void CpuCustomGBForce::calculateParticlePairEnergyTerm(int index, ThreadData& da
}
}
void CpuCustomGBForce::calculateOnePairEnergyTerm(int index, int atom1, int atom2, ThreadData& data, float* posq, double** atomParameters,
void CpuCustomGBForce::calculateOnePairEnergyTerm(int index, int atom1, int atom2, ThreadData& data, float* posq, vector<double>* atomParameters,
float* forces, double& totalEnergy, const fvec4& boxSize, const fvec4& invBoxSize) {
// Compute the displacement.
......@@ -537,7 +537,7 @@ void CpuCustomGBForce::calculateOnePairEnergyTerm(int index, int atom1, int atom
data.energyParamDerivs[i] += data.energyParamDerivExpressions[index][i].evaluate();
}
void CpuCustomGBForce::calculateChainRuleForces(ThreadData& data, int numAtoms, float* posq, double** atomParameters,
void CpuCustomGBForce::calculateChainRuleForces(ThreadData& data, int numAtoms, float* posq, vector<double>* atomParameters,
float* forces, const fvec4& boxSize, const fvec4& invBoxSize) {
if (cutoff) {
// Loop over all pairs in the neighbor list.
......@@ -614,7 +614,7 @@ void CpuCustomGBForce::calculateChainRuleForces(ThreadData& data, int numAtoms,
data.energyParamDerivs[k] += dEdV[j][i]*dValuedParam[j][k][i];
}
void CpuCustomGBForce::calculateOnePairChainRule(int atom1, int atom2, ThreadData& data, float* posq, double** atomParameters,
void CpuCustomGBForce::calculateOnePairChainRule(int atom1, int atom2, ThreadData& data, float* posq, vector<double>* atomParameters,
float* forces, bool isExcluded, const fvec4& boxSize, const fvec4& invBoxSize) {
// Compute the displacement.
......
/* Portions copyright (c) 2009-2017 Stanford University and Simbios.
/* Portions copyright (c) 2009-2018 Stanford University and Simbios.
* Contributors: Peter Eastman
*
* Permission is hereby granted, free of charge, to any person obtaining
......@@ -88,13 +88,13 @@ CpuCustomManyParticleForce::~CpuCustomManyParticleForce() {
delete data;
}
void CpuCustomManyParticleForce::calculateIxn(AlignedArray<float>& posq, double** particleParameters,
void CpuCustomManyParticleForce::calculateIxn(AlignedArray<float>& posq, vector<vector<double> >& particleParameters,
const map<string, double>& globalParameters, vector<AlignedArray<float> >& threadForce,
bool includeForces, bool includeEnergy, double& energy) {
// Record the parameters for the threads.
this->posq = &posq[0];
this->particleParameters = particleParameters;
this->particleParameters = &particleParameters[0];
this->globalParameters = &globalParameters;
this->threadForce = &threadForce;
this->includeForces = includeForces;
......@@ -209,7 +209,7 @@ void CpuCustomManyParticleForce::setPeriodic(Vec3* periodicBoxVectors) {
}
void CpuCustomManyParticleForce::loopOverInteractions(vector<int>& availableParticles, vector<int>& particleSet, int loopIndex, int startIndex,
double** particleParameters, float* forces, ThreadData& data, const fvec4& boxSize, const fvec4& invBoxSize) {
vector<double>* particleParameters, float* forces, ThreadData& data, const fvec4& boxSize, const fvec4& invBoxSize) {
int numParticles = availableParticles.size();
double cutoff2 = cutoffDistance*cutoffDistance;
int checkRange = (centralParticleMode ? 1 : loopIndex);
......@@ -243,7 +243,7 @@ void CpuCustomManyParticleForce::loopOverInteractions(vector<int>& availablePart
}
}
void CpuCustomManyParticleForce::calculateOneIxn(vector<int>& particleSet, double** particleParameters, float* forces, ThreadData& data, const fvec4& boxSize, const fvec4& invBoxSize) {
void CpuCustomManyParticleForce::calculateOneIxn(vector<int>& particleSet, vector<double>* particleParameters, float* forces, ThreadData& data, const fvec4& boxSize, const fvec4& invBoxSize) {
// Select the ordering to use for the particles.
vector<int>& permutedParticles = data.permutedParticles;
......
......@@ -120,15 +120,15 @@ void CpuCustomNonbondedForce::setPeriodic(Vec3* periodicBoxVectors) {
}
void CpuCustomNonbondedForce::calculatePairIxn(int numberOfAtoms, float* posq, vector<Vec3>& atomCoordinates, double** atomParameters,
double* fixedParameters, const map<string, double>& globalParameters,
vector<AlignedArray<float> >& threadForce, bool includeForce, bool includeEnergy, double& totalEnergy, double* energyParamDerivs) {
void CpuCustomNonbondedForce::calculatePairIxn(int numberOfAtoms, float* posq, vector<Vec3>& atomCoordinates, vector<vector<double> >& atomParameters,
const map<string, double>& globalParameters, vector<AlignedArray<float> >& threadForce,
bool includeForce, bool includeEnergy, double& totalEnergy, double* energyParamDerivs) {
// Record the parameters for the threads.
this->numberOfAtoms = numberOfAtoms;
this->posq = posq;
this->atomCoordinates = &atomCoordinates[0];
this->atomParameters = atomParameters;
this->atomParameters = &atomParameters[0];
this->globalParameters = &globalParameters;
this->threadForce = &threadForce;
this->includeForce = includeForce;
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2013-2016 Stanford University and the Authors. *
* Portions copyright (c) 2013-2018 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -302,25 +302,10 @@ double CpuCalcForcesAndEnergyKernel::finishComputation(ContextImpl& context, boo
return referenceKernel.getAs<ReferenceCalcForcesAndEnergyKernel>().finishComputation(context, includeForce, includeEnergy, groups, valid);
}
CpuCalcHarmonicAngleForceKernel::~CpuCalcHarmonicAngleForceKernel() {
if (angleIndexArray != NULL) {
for (int i = 0; i < numAngles; i++) {
delete[] angleIndexArray[i];
delete[] angleParamArray[i];
}
delete[] angleIndexArray;
delete[] angleParamArray;
}
}
void CpuCalcHarmonicAngleForceKernel::initialize(const System& system, const HarmonicAngleForce& force) {
numAngles = force.getNumAngles();
angleIndexArray = new int*[numAngles];
for (int i = 0; i < numAngles; i++)
angleIndexArray[i] = new int[3];
angleParamArray = new double*[numAngles];
for (int i = 0; i < numAngles; i++)
angleParamArray[i] = new double[2];
angleIndexArray.resize(numAngles, vector<int>(3));
angleParamArray.resize(numAngles, vector<double>(2));
for (int i = 0; i < numAngles; ++i) {
int particle1, particle2, particle3;
double angle, k;
......@@ -363,25 +348,10 @@ void CpuCalcHarmonicAngleForceKernel::copyParametersToContext(ContextImpl& conte
}
}
CpuCalcPeriodicTorsionForceKernel::~CpuCalcPeriodicTorsionForceKernel() {
if (torsionIndexArray != NULL) {
for (int i = 0; i < numTorsions; i++) {
delete[] torsionIndexArray[i];
delete[] torsionParamArray[i];
}
delete[] torsionIndexArray;
delete[] torsionParamArray;
}
}
void CpuCalcPeriodicTorsionForceKernel::initialize(const System& system, const PeriodicTorsionForce& force) {
numTorsions = force.getNumTorsions();
torsionIndexArray = new int*[numTorsions];
for (int i = 0; i < numTorsions; i++)
torsionIndexArray[i] = new int[4];
torsionParamArray = new double*[numTorsions];
for (int i = 0; i < numTorsions; i++)
torsionParamArray[i] = new double[3];
torsionIndexArray.resize(numTorsions, vector<int>(4));
torsionParamArray.resize(numTorsions, vector<double>(3));
for (int i = 0; i < numTorsions; ++i) {
int particle1, particle2, particle3, particle4, periodicity;
double phase, k;
......@@ -427,25 +397,10 @@ void CpuCalcPeriodicTorsionForceKernel::copyParametersToContext(ContextImpl& con
}
}
CpuCalcRBTorsionForceKernel::~CpuCalcRBTorsionForceKernel() {
if (torsionIndexArray != NULL) {
for (int i = 0; i < numTorsions; i++) {
delete[] torsionIndexArray[i];
delete[] torsionParamArray[i];
}
delete[] torsionIndexArray;
delete[] torsionParamArray;
}
}
void CpuCalcRBTorsionForceKernel::initialize(const System& system, const RBTorsionForce& force) {
numTorsions = force.getNumTorsions();
torsionIndexArray = new int*[numTorsions];
for (int i = 0; i < numTorsions; i++)
torsionIndexArray[i] = new int[4];
torsionParamArray = new double*[numTorsions];
for (int i = 0; i < numTorsions; i++)
torsionParamArray[i] = new double[6];
torsionIndexArray.resize(numTorsions, vector<int>(4));
torsionParamArray.resize(numTorsions, vector<double>(6));
for (int i = 0; i < numTorsions; ++i) {
int particle1, particle2, particle3, particle4;
double c0, c1, c2, c3, c4, c5;
......@@ -522,7 +477,7 @@ CpuNonbondedForce* createCpuNonbondedForceVec4();
CpuNonbondedForce* createCpuNonbondedForceVec8();
CpuCalcNonbondedForceKernel::CpuCalcNonbondedForceKernel(string name, const Platform& platform, CpuPlatform::PlatformData& data) : CalcNonbondedForceKernel(name, platform),
data(data), bonded14IndexArray(NULL), bonded14ParamArray(NULL), hasInitializedPme(false), hasInitializedDispersionPme(false), nonbonded(NULL) {
data(data), hasInitializedPme(false), hasInitializedDispersionPme(false), nonbonded(NULL) {
if (isVec8Supported())
nonbonded = createCpuNonbondedForceVec8();
else
......@@ -530,14 +485,6 @@ CpuCalcNonbondedForceKernel::CpuCalcNonbondedForceKernel(string name, const Plat
}
CpuCalcNonbondedForceKernel::~CpuCalcNonbondedForceKernel() {
if (bonded14ParamArray != NULL) {
for (int i = 0; i < num14; i++) {
delete[] bonded14IndexArray[i];
delete[] bonded14ParamArray[i];
}
delete[] bonded14IndexArray;
delete[] bonded14ParamArray;
}
if (nonbonded != NULL)
delete nonbonded;
}
......@@ -563,12 +510,8 @@ void CpuCalcNonbondedForceKernel::initialize(const System& system, const Nonbond
// Record the particle parameters.
num14 = nb14s.size();
bonded14IndexArray = new int*[num14];
for (int i = 0; i < num14; i++)
bonded14IndexArray[i] = new int[2];
bonded14ParamArray = new double*[num14];
for (int i = 0; i < num14; i++)
bonded14ParamArray[i] = new double[3];
bonded14IndexArray.resize(num14, vector<int>(2));
bonded14ParamArray.resize(num14, vector<double>(3));
particleParams.resize(numParticles);
charges.resize(numParticles);
C6params.resize(numParticles);
......@@ -804,11 +747,6 @@ CpuCalcCustomNonbondedForceKernel::CpuCalcCustomNonbondedForceKernel(string name
}
CpuCalcCustomNonbondedForceKernel::~CpuCalcCustomNonbondedForceKernel() {
if (particleParamArray != NULL) {
for (int i = 0; i < numParticles; i++)
delete[] particleParamArray[i];
delete[] particleParamArray;
}
if (nonbonded != NULL)
delete nonbonded;
if (forceCopy != NULL)
......@@ -831,15 +769,9 @@ void CpuCalcCustomNonbondedForceKernel::initialize(const System& system, const C
// Build the arrays.
int numParameters = force.getNumPerParticleParameters();
particleParamArray = new double*[numParticles];
for (int i = 0; i < numParticles; i++)
particleParamArray[i] = new double[numParameters];
for (int i = 0; i < numParticles; ++i) {
vector<double> parameters;
force.getParticleParameters(i, parameters);
for (int j = 0; j < numParameters; j++)
particleParamArray[i][j] = parameters[j];
}
particleParamArray.resize(numParticles);
for (int i = 0; i < numParticles; ++i)
force.getParticleParameters(i, particleParamArray[i]);
nonbondedMethod = CalcCustomNonbondedForceKernel::NonbondedMethod(force.getNonbondedMethod());
nonbondedCutoff = force.getCutoffDistance();
if (nonbondedMethod == NoCutoff)
......@@ -935,7 +867,7 @@ double CpuCalcCustomNonbondedForceKernel::execute(ContextImpl& context, bool inc
if (useSwitchingFunction)
nonbonded->setUseSwitchingFunction(switchingDistance);
vector<double> energyParamDerivValues(energyParamDerivNames.size()+1, 0.0);
nonbonded->calculatePairIxn(numParticles, &data.posq[0], posData, particleParamArray, 0, globalParamValues, data.threadForce, includeForces, includeEnergy, energy, &energyParamDerivValues[0]);
nonbonded->calculatePairIxn(numParticles, &data.posq[0], posData, particleParamArray, globalParamValues, data.threadForce, includeForces, includeEnergy, energy, &energyParamDerivValues[0]);
map<string, double>& energyParamDerivs = extractEnergyParameterDerivatives(context);
for (int i = 0; i < energyParamDerivNames.size(); i++)
energyParamDerivs[energyParamDerivNames[i]] += energyParamDerivValues[i];
......@@ -1032,11 +964,6 @@ void CpuCalcGBSAOBCForceKernel::copyParametersToContext(ContextImpl& context, co
}
CpuCalcCustomGBForceKernel::~CpuCalcCustomGBForceKernel() {
if (particleParamArray != NULL) {
for (int i = 0; i < numParticles; i++)
delete[] particleParamArray[i];
delete[] particleParamArray;
}
if (ixn != NULL)
delete ixn;
if (neighborList != NULL)
......@@ -1071,15 +998,9 @@ void CpuCalcCustomGBForceKernel::initialize(const System& system, const CustomGB
// Build the arrays.
int numPerParticleParameters = force.getNumPerParticleParameters();
particleParamArray = new double*[numParticles];
for (int i = 0; i < numParticles; i++)
particleParamArray[i] = new double[numPerParticleParameters];
for (int i = 0; i < numParticles; ++i) {
vector<double> parameters;
force.getParticleParameters(i, parameters);
for (int j = 0; j < numPerParticleParameters; j++)
particleParamArray[i][j] = parameters[j];
}
particleParamArray.resize(numParticles);
for (int i = 0; i < numParticles; ++i)
force.getParticleParameters(i, particleParamArray[i]);
for (int i = 0; i < numPerParticleParameters; i++)
particleParameterNames.push_back(force.getPerParticleParameterName(i));
for (int i = 0; i < force.getNumGlobalParameters(); i++)
......@@ -1225,11 +1146,6 @@ void CpuCalcCustomGBForceKernel::copyParametersToContext(ContextImpl& context, c
}
CpuCalcCustomManyParticleForceKernel::~CpuCalcCustomManyParticleForceKernel() {
if (particleParamArray != NULL) {
for (int i = 0; i < numParticles; i++)
delete[] particleParamArray[i];
delete[] particleParamArray;
}
if (ixn != NULL)
delete ixn;
}
......@@ -1240,15 +1156,10 @@ void CpuCalcCustomManyParticleForceKernel::initialize(const System& system, cons
numParticles = system.getNumParticles();
int numParticleParameters = force.getNumPerParticleParameters();
particleParamArray = new double*[numParticles];
for (int i = 0; i < numParticles; i++)
particleParamArray[i] = new double[numParticleParameters];
particleParamArray.resize(numParticles);
for (int i = 0; i < numParticles; ++i) {
vector<double> parameters;
int type;
force.getParticleParameters(i, parameters, type);
for (int j = 0; j < numParticleParameters; j++)
particleParamArray[i][j] = parameters[j];
force.getParticleParameters(i, particleParamArray[i], type);
}
for (int i = 0; i < force.getNumGlobalParameters(); i++)
globalParameterNames.push_back(force.getGlobalParameterName(i));
......
......@@ -77,7 +77,7 @@ class OPENMM_EXPORT ReferenceAngleBondIxn : public ReferenceBondIxn {
--------------------------------------------------------------------------------------- */
void getPrefactorsGivenAngleCosine(double cosine, double* angleParameters,
void getPrefactorsGivenAngleCosine(double cosine, std::vector<double>& angleParameters,
double* dEdR, double* energyTerm) const;
/**---------------------------------------------------------------------------------------
......@@ -93,8 +93,8 @@ class OPENMM_EXPORT ReferenceAngleBondIxn : public ReferenceBondIxn {
--------------------------------------------------------------------------------------- */
void calculateBondIxn(int* atomIndices, std::vector<OpenMM::Vec3>& atomCoordinates,
double* parameters, std::vector<OpenMM::Vec3>& forces,
void calculateBondIxn(std::vector<int>& atomIndices, std::vector<OpenMM::Vec3>& atomCoordinates,
std::vector<double>& parameters, std::vector<OpenMM::Vec3>& forces,
double* totalEnergy, double* energyParamDerivs);
......
......@@ -67,9 +67,9 @@ class OPENMM_EXPORT ReferenceBondForce : public ReferenceForce {
--------------------------------------------------------------------------------------- */
void calculateForce(int numberOfBonds, int** atomIndices,
void calculateForce(int numberOfBonds, std::vector<std::vector<int> >& atomIndices,
std::vector<OpenMM::Vec3>& atomCoordinates,
double** parameters, std::vector<OpenMM::Vec3>& forces,
std::vector<std::vector<double> >& parameters, std::vector<OpenMM::Vec3>& forces,
double* totalEnergy, ReferenceBondIxn& referenceBondIxn);
};
......
......@@ -65,8 +65,8 @@ class OPENMM_EXPORT ReferenceBondIxn {
--------------------------------------------------------------------------------------- */
virtual void calculateBondIxn(int* atomIndices, std::vector<OpenMM::Vec3>& atomCoordinates,
double* parameters, std::vector<OpenMM::Vec3>& forces,
virtual void calculateBondIxn(std::vector<int>& atomIndices, std::vector<OpenMM::Vec3>& atomCoordinates,
std::vector<double>& parameters, std::vector<OpenMM::Vec3>& forces,
double* totalEnergy, double* energyParamDerivs);
/**---------------------------------------------------------------------------------------
......
......@@ -95,8 +95,8 @@ public:
--------------------------------------------------------------------------------------- */
void calculateBondIxn(int* atomIndices, std::vector<OpenMM::Vec3>& atomCoordinates,
double* parameters, std::vector<OpenMM::Vec3>& forces,
void calculateBondIxn(std::vector<int>& atomIndices, std::vector<OpenMM::Vec3>& atomCoordinates,
std::vector<double>& parameters, std::vector<OpenMM::Vec3>& forces,
double* totalEnergy, double* energyParamDerivs);
// ---------------------------------------------------------------------------------------
......
......@@ -84,8 +84,8 @@ class ReferenceCustomAngleIxn : public ReferenceBondIxn {
--------------------------------------------------------------------------------------- */
void calculateBondIxn(int* atomIndices, std::vector<OpenMM::Vec3>& atomCoordinates,
double* parameters, std::vector<OpenMM::Vec3>& forces,
void calculateBondIxn(std::vector<int>& atomIndices, std::vector<OpenMM::Vec3>& atomCoordinates,
std::vector<double>& parameters, std::vector<OpenMM::Vec3>& forces,
double* totalEnergy, double* energyParamDerivs);
......
......@@ -85,8 +85,8 @@ class ReferenceCustomBondIxn : public ReferenceBondIxn {
--------------------------------------------------------------------------------------- */
void calculateBondIxn(int* atomIndices, std::vector<OpenMM::Vec3>& atomCoordinates,
double* parameters, std::vector<OpenMM::Vec3>& forces,
void calculateBondIxn(std::vector<int>& atomIndices, std::vector<OpenMM::Vec3>& atomCoordinates,
std::vector<double>& parameters, std::vector<OpenMM::Vec3>& forces,
double* totalEnergy, double* energyParamDerivs);
......
/* Portions copyright (c) 2009-2016 Stanford University and Simbios.
/* Portions copyright (c) 2009-2018 Stanford University and Simbios.
* Contributors: Peter Eastman
*
* Permission is hereby granted, free of charge, to any person obtaining
......@@ -130,7 +130,7 @@ class ReferenceCustomCentroidBondIxn : public ReferenceBondIxn {
--------------------------------------------------------------------------------------- */
void calculatePairIxn(std::vector<OpenMM::Vec3>& atomCoordinates, double** bondParameters,
void calculatePairIxn(std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<std::vector<double> >& bondParameters,
const std::map<std::string, double>& globalParameters,
std::vector<OpenMM::Vec3>& forces, double* totalEnergy, double* energyParamDerivs);
......
......@@ -127,7 +127,7 @@ class ReferenceCustomCompoundBondIxn : public ReferenceBondIxn {
--------------------------------------------------------------------------------------- */
void calculatePairIxn(std::vector<OpenMM::Vec3>& atomCoordinates, double** bondParameters,
void calculatePairIxn(std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<std::vector<double> >& bondParameters,
const std::map<std::string, double>& globalParameters,
std::vector<OpenMM::Vec3>& forces, double* totalEnergy, double* energyParamDerivs);
......
/* Portions copyright (c) 2009-2013 Stanford University and Simbios.
/* Portions copyright (c) 2009-2018 Stanford University and Simbios.
* Contributors: Peter Eastman
*
* Permission is hereby granted, free of charge, to any person obtaining
......@@ -81,7 +81,7 @@ class ReferenceCustomExternalIxn {
--------------------------------------------------------------------------------------- */
void calculateForce(int atomIndex, std::vector<OpenMM::Vec3>& atomCoordinates,
double* parameters, std::vector<OpenMM::Vec3>& forces, double* energy) const;
std::vector<double>& parameters, std::vector<OpenMM::Vec3>& forces, double* energy) const;
};
......
/* Portions copyright (c) 2009-2016 Stanford University and Simbios.
/* Portions copyright (c) 2009-2018 Stanford University and Simbios.
* Contributors: Peter Eastman
*
* Permission is hereby granted, free of charge, to any person obtaining
......@@ -73,7 +73,7 @@ class ReferenceCustomGBIxn {
--------------------------------------------------------------------------------------- */
void calculateSingleParticleValue(int index, int numAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, double** atomParameters);
void calculateSingleParticleValue(int index, int numAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<std::vector<double> >& atomParameters);
/**---------------------------------------------------------------------------------------
......@@ -88,7 +88,7 @@ class ReferenceCustomGBIxn {
--------------------------------------------------------------------------------------- */
void calculateParticlePairValue(int index, int numAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, double** atomParameters,
void calculateParticlePairValue(int index, int numAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<std::vector<double> >& atomParameters,
const std::vector<std::set<int> >& exclusions, bool useExclusions);
/**---------------------------------------------------------------------------------------
......@@ -103,7 +103,7 @@ class ReferenceCustomGBIxn {
--------------------------------------------------------------------------------------- */
void calculateOnePairValue(int index, int atom1, int atom2, std::vector<OpenMM::Vec3>& atomCoordinates, double** atomParameters);
void calculateOnePairValue(int index, int atom1, int atom2, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<std::vector<double> >& atomParameters);
/**---------------------------------------------------------------------------------------
......@@ -119,7 +119,7 @@ class ReferenceCustomGBIxn {
--------------------------------------------------------------------------------------- */
void calculateSingleParticleEnergyTerm(int index, int numAtoms, std::vector<OpenMM::Vec3>& atomCoordinates,
double** atomParameters, std::vector<OpenMM::Vec3>& forces, double* totalEnergy, double* energyParamDerivs);
std::vector<std::vector<double> >& atomParameters, std::vector<OpenMM::Vec3>& forces, double* totalEnergy, double* energyParamDerivs);
/**---------------------------------------------------------------------------------------
......@@ -136,7 +136,7 @@ class ReferenceCustomGBIxn {
--------------------------------------------------------------------------------------- */
void calculateParticlePairEnergyTerm(int index, int numAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, double** atomParameters,
void calculateParticlePairEnergyTerm(int index, int numAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<std::vector<double> >& atomParameters,
const std::vector<std::set<int> >& exclusions, bool useExclusions,
std::vector<OpenMM::Vec3>& forces, double* totalEnergy, double* energyParamDerivs);
......@@ -154,7 +154,7 @@ class ReferenceCustomGBIxn {
--------------------------------------------------------------------------------------- */
void calculateOnePairEnergyTerm(int index, int atom1, int atom2, std::vector<OpenMM::Vec3>& atomCoordinates, double** atomParameters,
void calculateOnePairEnergyTerm(int index, int atom1, int atom2, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<std::vector<double> >& atomParameters,
std::vector<OpenMM::Vec3>& forces, double* totalEnergy, double* energyParamDerivs);
/**---------------------------------------------------------------------------------------
......@@ -169,7 +169,7 @@ class ReferenceCustomGBIxn {
--------------------------------------------------------------------------------------- */
void calculateChainRuleForces(int numAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, double** atomParameters,
void calculateChainRuleForces(int numAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<std::vector<double> >& atomParameters,
const std::vector<std::set<int> >& exclusions, std::vector<OpenMM::Vec3>& forces, double* energyParamDerivs);
/**---------------------------------------------------------------------------------------
......@@ -185,7 +185,7 @@ class ReferenceCustomGBIxn {
--------------------------------------------------------------------------------------- */
void calculateOnePairChainRule(int atom1, int atom2, std::vector<OpenMM::Vec3>& atomCoordinates, double** atomParameters,
void calculateOnePairChainRule(int atom1, int atom2, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<std::vector<double> >& atomParameters,
std::vector<OpenMM::Vec3>& forces, bool isExcluded);
public:
......@@ -254,7 +254,7 @@ class ReferenceCustomGBIxn {
--------------------------------------------------------------------------------------- */
void calculateIxn(int numberOfAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, double** atomParameters, const std::vector<std::set<int> >& exclusions,
void calculateIxn(int numberOfAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<std::vector<double> >& atomParameters, const std::vector<std::set<int> >& exclusions,
std::map<std::string, double>& globalParameters, std::vector<OpenMM::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