Skip to content

Commit

Permalink
updateParametersInContext() can change tabulated functions (openmm#3307)
Browse files Browse the repository at this point in the history
* updateParametersInContext() can change tabulated functions

* Fixed error in building C wrappers

* updateParametersInContext() can change tabulated functions for CustomCentroidBondForce

* CustomNonbondedForce can update tabulated functions

* CustomGBForce can update tabulated functions

* CustomManyParticleForce can update tabulated functions

* CustomHbondForce can update tabulated functions
  • Loading branch information
peastman authored Nov 2, 2021
1 parent d83c272 commit 27bcb65
Show file tree
Hide file tree
Showing 21 changed files with 709 additions and 180 deletions.
9 changes: 5 additions & 4 deletions openmmapi/include/openmm/CustomCentroidBondForce.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,16 @@ class OPENMM_EXPORT CustomCentroidBondForce : public Force {
*/
const std::string& getTabulatedFunctionName(int index) const;
/**
* Update the per-bond parameters in a Context to match those stored in this Force object. This method provides
* Update the per-bond parameters and tabulated functions in a Context to match those stored in this Force object. This method provides
* an efficient method to update certain parameters in an existing Context without needing to reinitialize it.
* Simply call setBondParameters() to modify this object's parameters, then call updateParametersInContext()
* to copy them over to the Context.
*
* This method has several limitations. The only information it updates is the values of per-bond parameters.
* All other aspects of the Force (such as the energy function) are unaffected and can only be changed by reinitializing
* This method has several limitations. The only information it updates is the values of per-bond parameters and tabulated
* functions. All other aspects of the Force (such as the energy function) are unaffected and can only be changed by reinitializing
* the Context. Neither the definitions of groups nor the set of groups involved in a bond can be changed, nor can new
* bonds be added.
* bonds be added. Also, while the tabulated values of a function can change, everything else about it (its dimensions,
* the data range) must not be changed.
*/
void updateParametersInContext(Context& context);
/**
Expand Down
9 changes: 5 additions & 4 deletions openmmapi/include/openmm/CustomCompoundBondForce.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,15 @@ class OPENMM_EXPORT CustomCompoundBondForce : public Force {
*/
void setFunctionParameters(int index, const std::string& name, const std::vector<double>& values, double min, double max);
/**
* Update the per-bond parameters in a Context to match those stored in this Force object. This method provides
* Update the per-bond parameters and tabulated functions in a Context to match those stored in this Force object. This method provides
* an efficient method to update certain parameters in an existing Context without needing to reinitialize it.
* Simply call setBondParameters() to modify this object's parameters, then call updateParametersInContext()
* to copy them over to the Context.
*
* This method has several limitations. The only information it updates is the values of per-bond parameters.
* All other aspects of the Force (such as the energy function) are unaffected and can only be changed by reinitializing
* the Context. The set of particles involved in a bond cannot be changed, nor can new bonds be added.
* This method has several limitations. The only information it updates is the values of per-bond parameters and tabulated
* functions. All other aspects of the Force (such as the energy function) are unaffected and can only be changed by reinitializing
* the Context. The set of particles involved in a bond cannot be changed, nor can new bonds be added. Also, while the
* tabulated values of a function can change, everything else about it (its dimensions, the data range) must not be changed.
*/
void updateParametersInContext(Context& context);
/**
Expand Down
11 changes: 6 additions & 5 deletions openmmapi/include/openmm/CustomGBForce.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) 2008-2016 Stanford University and the Authors. *
* Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
Expand Down Expand Up @@ -544,14 +544,15 @@ class OPENMM_EXPORT CustomGBForce : public Force {
*/
void setFunctionParameters(int index, const std::string& name, const std::vector<double>& values, double min, double max);
/**
* Update the per-particle parameters in a Context to match those stored in this Force object. This method provides
* Update the per-particle parameters and tabulated functions in a Context to match those stored in this Force object. This method provides
* an efficient method to update certain parameters in an existing Context without needing to reinitialize it.
* Simply call setParticleParameters() to modify this object's parameters, then call updateParametersInContext()
* to copy them over to the Context.
*
* This method has several limitations. The only information it updates is the values of per-particle parameters.
* All other aspects of the Force (such as the energy function) are unaffected and can only be changed by reinitializing
* the Context. Also, this method cannot be used to add new particles, only to change the parameters of existing ones.
* This method has several limitations. The only information it updates is the values of per-particle parameters and tabulated
* functions. All other aspects of the Force (such as the energy function) are unaffected and can only be changed by reinitializing
* the Context. Also, this method cannot be used to add new particles, only to change the parameters of existing ones. While
* the tabulated values of a function can change, everything else about it (its dimensions, the data range) must not be changed.
*/
void updateParametersInContext(Context& context);
/**
Expand Down
11 changes: 6 additions & 5 deletions openmmapi/include/openmm/CustomHbondForce.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) 2008-2014 Stanford University and the Authors. *
* Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
Expand Down Expand Up @@ -443,15 +443,16 @@ class OPENMM_EXPORT CustomHbondForce : public Force {
*/
void setFunctionParameters(int index, const std::string& name, const std::vector<double>& values, double min, double max);
/**
* Update the per-donor and per-acceptor parameters in a Context to match those stored in this Force object. This method
* Update the per-donor and per-acceptor parameters and tabulated functions in a Context to match those stored in this Force object. This method
* provides an efficient method to update certain parameters in an existing Context without needing to reinitialize it.
* Simply call setDonorParameters() and setAcceptorParameters() to modify this object's parameters, then call
* updateParametersInContext() to copy them over to the Context.
*
* This method has several limitations. The only information it updates is the values of per-donor and per-acceptor parameters.
* All other aspects of the Force (the energy function, nonbonded method, cutoff distance, etc.) are unaffected and can only
* This method has several limitations. The only information it updates is the values of per-donor and per-acceptor parameters and tabulated
* functions. All other aspects of the Force (the energy function, nonbonded method, cutoff distance, etc.) are unaffected and can only
* be changed by reinitializing the Context. The set of particles involved in a donor or acceptor cannot be changed, nor can
* new donors or acceptors be added.
* new donors or acceptors be added. While the tabulated values of a function can change, everything else about it (its dimensions,
* the data range) must not be changed.
*/
void updateParametersInContext(Context& context);
/**
Expand Down
9 changes: 5 additions & 4 deletions openmmapi/include/openmm/CustomManyParticleForce.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,16 @@ class OPENMM_EXPORT CustomManyParticleForce : public Force {
*/
const std::string& getTabulatedFunctionName(int index) const;
/**
* Update the per-particle parameters in a Context to match those stored in this Force object. This method provides
* Update the per-particle parameters and tabulated functions in a Context to match those stored in this Force object. This method provides
* an efficient method to update certain parameters in an existing Context without needing to reinitialize it.
* Simply call setParticleParameters() to modify this object's parameters, then call updateParametersInContext()
* to copy them over to the Context.
*
* This method has several limitations. The only information it updates is the values of per-particle parameters.
* All other aspects of the Force (the energy function, nonbonded method, cutoff distance, etc.) are unaffected and can
* This method has several limitations. The only information it updates is the values of per-particle parameters and tabulated
* functions. All other aspects of the Force (the energy function, nonbonded method, cutoff distance, etc.) are unaffected and can
* only be changed by reinitializing the Context. Also, this method cannot be used to add new particles, only to change
* the parameters of existing ones.
* the parameters of existing ones. While the tabulated values of a function can change, everything else about it (its dimensions,
* the data range) must not be changed.
*/
void updateParametersInContext(Context& context);
/**
Expand Down
11 changes: 6 additions & 5 deletions openmmapi/include/openmm/CustomNonbondedForce.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) 2008-2016 Stanford University and the Authors. *
* Portions copyright (c) 2008-2021 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
Expand Down Expand Up @@ -490,15 +490,16 @@ class OPENMM_EXPORT CustomNonbondedForce : public Force {
*/
void setInteractionGroupParameters(int index, const std::set<int>& set1, const std::set<int>& set2);
/**
* Update the per-particle parameters in a Context to match those stored in this Force object. This method provides
* Update the per-particle parameters and tabulated functions in a Context to match those stored in this Force object. This method provides
* an efficient method to update certain parameters in an existing Context without needing to reinitialize it.
* Simply call setParticleParameters() to modify this object's parameters, then call updateParametersInContext()
* to copy them over to the Context.
*
* This method has several limitations. The only information it updates is the values of per-particle parameters.
* All other aspects of the Force (the energy function, nonbonded method, cutoff distance, etc.) are unaffected and can
* This method has several limitations. The only information it updates is the values of per-particle parameters and tabulated
* functions. All other aspects of the Force (the energy function, nonbonded method, cutoff distance, etc.) are unaffected and can
* only be changed by reinitializing the Context. Also, this method cannot be used to add new particles, only to change
* the parameters of existing ones.
* the parameters of existing ones. While the tabulated values of a function can change, everything else about it (its dimensions,
* the data range) must not be changed.
*/
void updateParametersInContext(Context& context);
/**
Expand Down
11 changes: 10 additions & 1 deletion openmmapi/include/openmm/TabulatedFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ class OPENMM_EXPORT TabulatedFunction {
virtual TabulatedFunction* Copy() const = 0;
/**
* Get the periodicity status of the tabulated function.
*
*/
bool getPeriodic() const;
virtual bool operator==(const TabulatedFunction& other) const = 0;
virtual bool operator!=(const TabulatedFunction& other) const {
return !(*this == other);
}
protected:
bool periodic;
};
Expand Down Expand Up @@ -114,6 +117,7 @@ class OPENMM_EXPORT Continuous1DFunction : public TabulatedFunction {
* @deprecated This will be removed in a future release.
*/
Continuous1DFunction* Copy() const;
bool operator==(const TabulatedFunction& other) const;
private:
std::vector<double> values;
double min, max;
Expand Down Expand Up @@ -176,6 +180,7 @@ class OPENMM_EXPORT Continuous2DFunction : public TabulatedFunction {
* @deprecated This will be removed in a future release.
*/
Continuous2DFunction* Copy() const;
bool operator==(const TabulatedFunction& other) const;
private:
std::vector<double> values;
int xsize, ysize;
Expand Down Expand Up @@ -254,6 +259,7 @@ class OPENMM_EXPORT Continuous3DFunction : public TabulatedFunction {
* @deprecated This will be removed in a future release.
*/
Continuous3DFunction* Copy() const;
bool operator==(const TabulatedFunction& other) const;
private:
std::vector<double> values;
int xsize, ysize, zsize;
Expand Down Expand Up @@ -291,6 +297,7 @@ class OPENMM_EXPORT Discrete1DFunction : public TabulatedFunction {
* @deprecated This will be removed in a future release.
*/
Discrete1DFunction* Copy() const;
bool operator==(const TabulatedFunction& other) const;
private:
std::vector<double> values;
};
Expand Down Expand Up @@ -335,6 +342,7 @@ class OPENMM_EXPORT Discrete2DFunction : public TabulatedFunction {
* @deprecated This will be removed in a future release.
*/
Discrete2DFunction* Copy() const;
bool operator==(const TabulatedFunction& other) const;
private:
int xsize, ysize;
std::vector<double> values;
Expand Down Expand Up @@ -383,6 +391,7 @@ class OPENMM_EXPORT Discrete3DFunction : public TabulatedFunction {
* @deprecated This will be removed in a future release.
*/
Discrete3DFunction* Copy() const;
bool operator==(const TabulatedFunction& other) const;
private:
int xsize, ysize, zsize;
std::vector<double> values;
Expand Down
63 changes: 62 additions & 1 deletion openmmapi/src/TabulatedFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 Stanford University and the Authors. *
* Portions copyright (c) 2014-2021 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
Expand Down Expand Up @@ -75,6 +75,15 @@ Continuous1DFunction* Continuous1DFunction::Copy() const {
return new Continuous1DFunction(new_vec, min, max);
}

bool Continuous1DFunction::operator==(const TabulatedFunction& other) const {
const Continuous1DFunction* fn = dynamic_cast<const Continuous1DFunction*>(&other);
if (fn == NULL)
return false;
if (fn->min != min || fn->max != max)
return false;
return (fn->values == values);
}

Continuous2DFunction::Continuous2DFunction(int xsize, int ysize, const vector<double>& values, double xmin, double xmax, double ymin, double ymax, bool periodic) {
this->periodic = periodic;
setFunctionParameters(xsize, ysize, values, xmin, xmax, ymin, ymax);
Expand Down Expand Up @@ -120,6 +129,19 @@ Continuous2DFunction* Continuous2DFunction::Copy() const {
return new Continuous2DFunction(xsize, ysize, new_vec, xmin, xmax, ymin, ymax);
}

bool Continuous2DFunction::operator==(const TabulatedFunction& other) const {
const Continuous2DFunction* fn = dynamic_cast<const Continuous2DFunction*>(&other);
if (fn == NULL)
return false;
if (fn->xsize != xsize || fn->ysize != ysize)
return false;
if (fn->xmin != xmin || fn->xmax != xmax)
return false;
if (fn->ymin != ymin || fn->ymax != ymax)
return false;
return (fn->values == values);
}

Continuous3DFunction::Continuous3DFunction(int xsize, int ysize, int zsize, const vector<double>& values, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, bool periodic) {
this->periodic = periodic;
setFunctionParameters(xsize, ysize, zsize, values, xmin, xmax, ymin, ymax, zmin, zmax);
Expand Down Expand Up @@ -173,6 +195,20 @@ Continuous3DFunction* Continuous3DFunction::Copy() const {
return new Continuous3DFunction(xsize, ysize, zsize, new_vec, xmin, xmax, ymin, ymax, zmin, zmax);
}

bool Continuous3DFunction::operator==(const TabulatedFunction& other) const {
const Continuous3DFunction* fn = dynamic_cast<const Continuous3DFunction*>(&other);
if (fn == NULL)
return false;
if (fn->xsize != xsize || fn->ysize != ysize || fn->zsize != zsize)
return false;
if (fn->xmin != xmin || fn->xmax != xmax)
return false;
if (fn->ymin != ymin || fn->ymax != ymax)
return false;
if (fn->zmin != zmin || fn->zmax != zmax)
return false;
return (fn->values == values);
}

Discrete1DFunction::Discrete1DFunction(const vector<double>& values) {
this->values = values;
Expand All @@ -193,6 +229,13 @@ Discrete1DFunction* Discrete1DFunction::Copy() const {
return new Discrete1DFunction(new_vec);
}

bool Discrete1DFunction::operator==(const TabulatedFunction& other) const {
const Discrete1DFunction* fn = dynamic_cast<const Discrete1DFunction*>(&other);
if (fn == NULL)
return false;
return (fn->values == values);
}

Discrete2DFunction::Discrete2DFunction(int xsize, int ysize, const vector<double>& values) {
if (values.size() != xsize*ysize)
throw OpenMMException("Discrete2DFunction: incorrect number of values");
Expand Down Expand Up @@ -222,6 +265,15 @@ Discrete2DFunction* Discrete2DFunction::Copy() const {
return new Discrete2DFunction(xsize, ysize, new_vec);
}

bool Discrete2DFunction::operator==(const TabulatedFunction& other) const {
const Discrete2DFunction* fn = dynamic_cast<const Discrete2DFunction*>(&other);
if (fn == NULL)
return false;
if (fn->xsize != xsize || fn->ysize != ysize)
return false;
return (fn->values == values);
}

Discrete3DFunction::Discrete3DFunction(int xsize, int ysize, int zsize, const vector<double>& values) {
if (values.size() != xsize*ysize*zsize)
throw OpenMMException("Discrete3DFunction: incorrect number of values");
Expand Down Expand Up @@ -253,3 +305,12 @@ Discrete3DFunction* Discrete3DFunction::Copy() const {
new_vec[i] = values[i];
return new Discrete3DFunction(xsize, ysize, zsize, new_vec);
}

bool Discrete3DFunction::operator==(const TabulatedFunction& other) const {
const Discrete3DFunction* fn = dynamic_cast<const Discrete3DFunction*>(&other);
if (fn == NULL)
return false;
if (fn->xsize != xsize || fn->ysize != ysize || fn->zsize != zsize)
return false;
return (fn->values == values);
}
Loading

0 comments on commit 27bcb65

Please sign in to comment.