"platforms/opencl/include/OpenCLArray.h" did not exist on "dca7d3399d4f1c8bab6289e142341fa02da4ef3c"
Commit 98640b63 authored by peastman's avatar peastman
Browse files

Converted reference platform to process tabulated functions with the TabulatedFunction API

parent dabc225e
...@@ -256,7 +256,7 @@ public: ...@@ -256,7 +256,7 @@ public:
* @param index the index of the function to get * @param index the index of the function to get
* @return the name of the function as it appears in expressions * @return the name of the function as it appears in expressions
*/ */
const std::string& getFunctionName(int index); const std::string& getFunctionName(int index) const;
/** /**
* Add a tabulated function that may appear in the energy expression. * Add a tabulated function that may appear in the energy expression.
* *
......
...@@ -482,7 +482,7 @@ public: ...@@ -482,7 +482,7 @@ public:
* @param index the index of the function to get * @param index the index of the function to get
* @return the name of the function as it appears in expressions * @return the name of the function as it appears in expressions
*/ */
const std::string& getFunctionName(int index); const std::string& getFunctionName(int index) const;
/** /**
* Add a tabulated function that may appear in expressions. * Add a tabulated function that may appear in expressions.
* *
......
...@@ -401,7 +401,7 @@ public: ...@@ -401,7 +401,7 @@ public:
* @param index the index of the function to get * @param index the index of the function to get
* @return the name of the function as it appears in expressions * @return the name of the function as it appears in expressions
*/ */
const std::string& getFunctionName(int index); const std::string& getFunctionName(int index) const;
/** /**
* Add a tabulated function that may appear in the energy expression. * Add a tabulated function that may appear in the energy expression.
* *
......
...@@ -386,7 +386,7 @@ public: ...@@ -386,7 +386,7 @@ public:
* @param index the index of the function to get * @param index the index of the function to get
* @return the name of the function as it appears in expressions * @return the name of the function as it appears in expressions
*/ */
const std::string& getFunctionName(int index); const std::string& getFunctionName(int index) const;
/** /**
* Add a tabulated function that may appear in the energy expression. * Add a tabulated function that may appear in the energy expression.
* *
......
#ifndef OPENMM_TabulatedFunction_H_ #ifndef OPENMM_TABULATEDFUNCTION_H_
#define OPENMM_TabulatedFunction_H_ #define OPENMM_TABULATEDFUNCTION_H_
/* -------------------------------------------------------------------------- * /* -------------------------------------------------------------------------- *
* OpenMM * * OpenMM *
...@@ -103,4 +103,4 @@ private: ...@@ -103,4 +103,4 @@ private:
} // namespace OpenMM } // namespace OpenMM
#endif /*OPENMM_TabulatedFunction_H_*/ #endif /*OPENMM_TABULATEDFUNCTION_H_*/
...@@ -135,7 +135,7 @@ TabulatedFunction& CustomCompoundBondForce::getFunction(int index) { ...@@ -135,7 +135,7 @@ TabulatedFunction& CustomCompoundBondForce::getFunction(int index) {
return *functions[index].function; return *functions[index].function;
} }
const string& CustomCompoundBondForce::getFunctionName(int index) { const string& CustomCompoundBondForce::getFunctionName(int index) const {
ASSERT_VALID_INDEX(index, functions); ASSERT_VALID_INDEX(index, functions);
return functions[index].name; return functions[index].name;
} }
......
...@@ -188,7 +188,7 @@ TabulatedFunction& CustomGBForce::getFunction(int index) { ...@@ -188,7 +188,7 @@ TabulatedFunction& CustomGBForce::getFunction(int index) {
return *functions[index].function; return *functions[index].function;
} }
const string& CustomGBForce::getFunctionName(int index) { const string& CustomGBForce::getFunctionName(int index) const {
ASSERT_VALID_INDEX(index, functions); ASSERT_VALID_INDEX(index, functions);
return functions[index].name; return functions[index].name;
} }
......
...@@ -202,7 +202,7 @@ TabulatedFunction& CustomHbondForce::getFunction(int index) { ...@@ -202,7 +202,7 @@ TabulatedFunction& CustomHbondForce::getFunction(int index) {
return *functions[index].function; return *functions[index].function;
} }
const string& CustomHbondForce::getFunctionName(int index) { const string& CustomHbondForce::getFunctionName(int index) const {
ASSERT_VALID_INDEX(index, functions); ASSERT_VALID_INDEX(index, functions);
return functions[index].name; return functions[index].name;
} }
......
...@@ -184,7 +184,7 @@ TabulatedFunction& CustomNonbondedForce::getFunction(int index) { ...@@ -184,7 +184,7 @@ TabulatedFunction& CustomNonbondedForce::getFunction(int index) {
return *functions[index].function; return *functions[index].function;
} }
const string& CustomNonbondedForce::getFunctionName(int index) { const string& CustomNonbondedForce::getFunctionName(int index) const {
ASSERT_VALID_INDEX(index, functions); ASSERT_VALID_INDEX(index, functions);
return functions[index].name; return functions[index].name;
} }
......
#ifndef OPENMM_REFERENCETABULATEDFUNCTION_H_
#define OPENMM_REFERENCETABULATEDFUNCTION_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2014 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/TabulatedFunction.h"
#include "openmm/internal/windowsExport.h"
#include "lepton/CustomFunction.h"
#include <vector>
namespace OpenMM {
/**
* Given a TabulatedFunction, wrap it in an appropriate subclass of Lepton::CustomFunction.
*/
extern "C" Lepton::CustomFunction* createReferenceTabulatedFunction(const TabulatedFunction& function);
/**
* This class adapts a Continuous1DFunction into a Lepton::CustomFunction.
*/
class OPENMM_EXPORT ReferenceContinuous1DFunction : public Lepton::CustomFunction {
public:
ReferenceContinuous1DFunction(const Continuous1DFunction& function);
int getNumArguments() const;
double evaluate(const double* arguments) const;
double evaluateDerivative(const double* arguments, const int* derivOrder) const;
CustomFunction* clone() const;
private:
const Continuous1DFunction& function;
double min, max;
std::vector<double> x, values, derivs;
};
} // namespace OpenMM
#endif /*OPENMM_REFERENCETABULATEDFUNCTION_H_*/
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include "ReferenceProperDihedralBond.h" #include "ReferenceProperDihedralBond.h"
#include "ReferenceRbDihedralBond.h" #include "ReferenceRbDihedralBond.h"
#include "ReferenceStochasticDynamics.h" #include "ReferenceStochasticDynamics.h"
#include "ReferenceTabulatedFunction.h"
#include "ReferenceVariableStochasticDynamics.h" #include "ReferenceVariableStochasticDynamics.h"
#include "ReferenceVariableVerletDynamics.h" #include "ReferenceVariableVerletDynamics.h"
#include "ReferenceVerletDynamics.h" #include "ReferenceVerletDynamics.h"
...@@ -69,7 +70,6 @@ ...@@ -69,7 +70,6 @@
#include "openmm/internal/CustomNonbondedForceImpl.h" #include "openmm/internal/CustomNonbondedForceImpl.h"
#include "openmm/internal/CMAPTorsionForceImpl.h" #include "openmm/internal/CMAPTorsionForceImpl.h"
#include "openmm/internal/NonbondedForceImpl.h" #include "openmm/internal/NonbondedForceImpl.h"
#include "openmm/internal/SplineFitter.h"
#include "openmm/Integrator.h" #include "openmm/Integrator.h"
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
#include "SimTKOpenMMUtilities.h" #include "SimTKOpenMMUtilities.h"
...@@ -923,38 +923,6 @@ void ReferenceCalcNonbondedForceKernel::copyParametersToContext(ContextImpl& con ...@@ -923,38 +923,6 @@ void ReferenceCalcNonbondedForceKernel::copyParametersToContext(ContextImpl& con
dispersionCoefficient = NonbondedForceImpl::calcDispersionCorrection(context.getSystem(), force); dispersionCoefficient = NonbondedForceImpl::calcDispersionCorrection(context.getSystem(), force);
} }
class ReferenceTabulatedFunction : public Lepton::CustomFunction {
public:
ReferenceTabulatedFunction(double min, double max, const vector<double>& values) :
min(min), max(max), values(values) {
int numValues = values.size();
x.resize(numValues);
for (int i = 0; i < numValues; i++)
x[i] = min+i*(max-min)/(numValues-1);
SplineFitter::createNaturalSpline(x, values, derivs);
}
int getNumArguments() const {
return 1;
}
double evaluate(const double* arguments) const {
double t = arguments[0];
if (t < min || t > max)
return 0.0;
return SplineFitter::evaluateSpline(x, values, derivs, t);
}
double evaluateDerivative(const double* arguments, const int* derivOrder) const {
double t = arguments[0];
if (t < min || t > max)
return 0.0;
return SplineFitter::evaluateSplineDerivative(x, values, derivs, t);
}
CustomFunction* clone() const {
return new ReferenceTabulatedFunction(min, max, values);
}
double min, max;
vector<double> x, values, derivs;
};
ReferenceCalcCustomNonbondedForceKernel::~ReferenceCalcCustomNonbondedForceKernel() { ReferenceCalcCustomNonbondedForceKernel::~ReferenceCalcCustomNonbondedForceKernel() {
disposeRealArray(particleParamArray, numParticles); disposeRealArray(particleParamArray, numParticles);
if (neighborList != NULL) if (neighborList != NULL)
...@@ -1001,13 +969,8 @@ void ReferenceCalcCustomNonbondedForceKernel::initialize(const System& system, c ...@@ -1001,13 +969,8 @@ void ReferenceCalcCustomNonbondedForceKernel::initialize(const System& system, c
// Create custom functions for the tabulated functions. // Create custom functions for the tabulated functions.
map<string, Lepton::CustomFunction*> functions; map<string, Lepton::CustomFunction*> functions;
for (int i = 0; i < force.getNumFunctions(); i++) { for (int i = 0; i < force.getNumFunctions(); i++)
string name; functions[force.getFunctionName(i)] = createReferenceTabulatedFunction(force.getFunction(i));
vector<double> values;
double min, max;
force.getFunctionParameters(i, name, values, min, max);
functions[name] = new ReferenceTabulatedFunction(min, max, values);
}
// Parse the various expressions used to calculate the force. // Parse the various expressions used to calculate the force.
...@@ -1288,13 +1251,8 @@ void ReferenceCalcCustomGBForceKernel::initialize(const System& system, const Cu ...@@ -1288,13 +1251,8 @@ void ReferenceCalcCustomGBForceKernel::initialize(const System& system, const Cu
// Create custom functions for the tabulated functions. // Create custom functions for the tabulated functions.
map<string, Lepton::CustomFunction*> functions; map<string, Lepton::CustomFunction*> functions;
for (int i = 0; i < force.getNumFunctions(); i++) { for (int i = 0; i < force.getNumFunctions(); i++)
string name; functions[force.getFunctionName(i)] = createReferenceTabulatedFunction(force.getFunction(i));
vector<double> values;
double min, max;
force.getFunctionParameters(i, name, values, min, max);
functions[name] = new ReferenceTabulatedFunction(min, max, values);
}
// Parse the expressions for computed values. // Parse the expressions for computed values.
...@@ -1507,13 +1465,8 @@ void ReferenceCalcCustomHbondForceKernel::initialize(const System& system, const ...@@ -1507,13 +1465,8 @@ void ReferenceCalcCustomHbondForceKernel::initialize(const System& system, const
// Create custom functions for the tabulated functions. // Create custom functions for the tabulated functions.
map<string, Lepton::CustomFunction*> functions; map<string, Lepton::CustomFunction*> functions;
for (int i = 0; i < force.getNumFunctions(); i++) { for (int i = 0; i < force.getNumFunctions(); i++)
string name; functions[force.getFunctionName(i)] = createReferenceTabulatedFunction(force.getFunction(i));
vector<double> values;
double min, max;
force.getFunctionParameters(i, name, values, min, max);
functions[name] = new ReferenceTabulatedFunction(min, max, values);
}
// Parse the expression and create the object used to calculate the interaction. // Parse the expression and create the object used to calculate the interaction.
...@@ -1609,13 +1562,8 @@ void ReferenceCalcCustomCompoundBondForceKernel::initialize(const System& system ...@@ -1609,13 +1562,8 @@ void ReferenceCalcCustomCompoundBondForceKernel::initialize(const System& system
// Create custom functions for the tabulated functions. // Create custom functions for the tabulated functions.
map<string, Lepton::CustomFunction*> functions; map<string, Lepton::CustomFunction*> functions;
for (int i = 0; i < force.getNumFunctions(); i++) { for (int i = 0; i < force.getNumFunctions(); i++)
string name; functions[force.getFunctionName(i)] = createReferenceTabulatedFunction(force.getFunction(i));
vector<double> values;
double min, max;
force.getFunctionParameters(i, name, values, min, max);
functions[name] = new ReferenceTabulatedFunction(min, max, values);
}
// Parse the expression and create the object used to calculate the interaction. // Parse the expression and create the object used to calculate the interaction.
......
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2014 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "ReferenceTabulatedFunction.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/SplineFitter.h"
using namespace OpenMM;
using namespace std;
using Lepton::CustomFunction;
extern "C" CustomFunction* createReferenceTabulatedFunction(const TabulatedFunction& function) {
if (dynamic_cast<const Continuous1DFunction*>(&function) != NULL)
return new ReferenceContinuous1DFunction(dynamic_cast<const Continuous1DFunction&>(function));
throw OpenMMException("createReferenceTabulatedFunction: Unknown function type");
}
ReferenceContinuous1DFunction::ReferenceContinuous1DFunction(const Continuous1DFunction& function) : function(function) {
function.getFunctionParameters(values, min, max);
int numValues = values.size();
x.resize(numValues);
for (int i = 0; i < numValues; i++)
x[i] = min+i*(max-min)/(numValues-1);
SplineFitter::createNaturalSpline(x, values, derivs);
}
int ReferenceContinuous1DFunction::getNumArguments() const {
return 1;
}
double ReferenceContinuous1DFunction::evaluate(const double* arguments) const {
double t = arguments[0];
if (t < min || t > max)
return 0.0;
return SplineFitter::evaluateSpline(x, values, derivs, t);
}
double ReferenceContinuous1DFunction::evaluateDerivative(const double* arguments, const int* derivOrder) const {
double t = arguments[0];
if (t < min || t > max)
return 0.0;
return SplineFitter::evaluateSplineDerivative(x, values, derivs, t);
}
CustomFunction* ReferenceContinuous1DFunction::clone() const {
return new ReferenceContinuous1DFunction(function);
}
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