Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
98640b63
Commit
98640b63
authored
Jan 23, 2014
by
peastman
Browse files
Converted reference platform to process tabulated functions with the TabulatedFunction API
parent
dabc225e
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
160 additions
and
72 deletions
+160
-72
openmmapi/include/openmm/CustomCompoundBondForce.h
openmmapi/include/openmm/CustomCompoundBondForce.h
+1
-1
openmmapi/include/openmm/CustomGBForce.h
openmmapi/include/openmm/CustomGBForce.h
+1
-1
openmmapi/include/openmm/CustomHbondForce.h
openmmapi/include/openmm/CustomHbondForce.h
+1
-1
openmmapi/include/openmm/CustomNonbondedForce.h
openmmapi/include/openmm/CustomNonbondedForce.h
+1
-1
openmmapi/include/openmm/TabulatedFunction.h
openmmapi/include/openmm/TabulatedFunction.h
+3
-3
openmmapi/src/CustomCompoundBondForce.cpp
openmmapi/src/CustomCompoundBondForce.cpp
+1
-1
openmmapi/src/CustomGBForce.cpp
openmmapi/src/CustomGBForce.cpp
+1
-1
openmmapi/src/CustomHbondForce.cpp
openmmapi/src/CustomHbondForce.cpp
+1
-1
openmmapi/src/CustomNonbondedForce.cpp
openmmapi/src/CustomNonbondedForce.cpp
+1
-1
platforms/reference/include/ReferenceTabulatedFunction.h
platforms/reference/include/ReferenceTabulatedFunction.h
+65
-0
platforms/reference/src/ReferenceKernels.cpp
platforms/reference/src/ReferenceKernels.cpp
+9
-61
platforms/reference/src/ReferenceTabulatedFunction.cpp
platforms/reference/src/ReferenceTabulatedFunction.cpp
+75
-0
No files found.
openmmapi/include/openmm/CustomCompoundBondForce.h
View file @
98640b63
...
...
@@ -256,7 +256,7 @@ public:
* @param index the index of the function to get
* @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.
*
...
...
openmmapi/include/openmm/CustomGBForce.h
View file @
98640b63
...
...
@@ -482,7 +482,7 @@ public:
* @param index the index of the function to get
* @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.
*
...
...
openmmapi/include/openmm/CustomHbondForce.h
View file @
98640b63
...
...
@@ -401,7 +401,7 @@ public:
* @param index the index of the function to get
* @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.
*
...
...
openmmapi/include/openmm/CustomNonbondedForce.h
View file @
98640b63
...
...
@@ -386,7 +386,7 @@ public:
* @param index the index of the function to get
* @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.
*
...
...
openmmapi/include/openmm/TabulatedFunction.h
View file @
98640b63
#ifndef OPENMM_T
abulatedFunction
_H_
#define OPENMM_T
abulatedFunction
_H_
#ifndef OPENMM_T
ABULATEDFUNCTION
_H_
#define OPENMM_T
ABULATEDFUNCTION
_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
...
...
@@ -103,4 +103,4 @@ private:
}
// namespace OpenMM
#endif
/*OPENMM_T
abulatedFunction
_H_*/
#endif
/*OPENMM_T
ABULATEDFUNCTION
_H_*/
openmmapi/src/CustomCompoundBondForce.cpp
View file @
98640b63
...
...
@@ -135,7 +135,7 @@ TabulatedFunction& CustomCompoundBondForce::getFunction(int index) {
return
*
functions
[
index
].
function
;
}
const
string
&
CustomCompoundBondForce
::
getFunctionName
(
int
index
)
{
const
string
&
CustomCompoundBondForce
::
getFunctionName
(
int
index
)
const
{
ASSERT_VALID_INDEX
(
index
,
functions
);
return
functions
[
index
].
name
;
}
...
...
openmmapi/src/CustomGBForce.cpp
View file @
98640b63
...
...
@@ -188,7 +188,7 @@ TabulatedFunction& CustomGBForce::getFunction(int index) {
return
*
functions
[
index
].
function
;
}
const
string
&
CustomGBForce
::
getFunctionName
(
int
index
)
{
const
string
&
CustomGBForce
::
getFunctionName
(
int
index
)
const
{
ASSERT_VALID_INDEX
(
index
,
functions
);
return
functions
[
index
].
name
;
}
...
...
openmmapi/src/CustomHbondForce.cpp
View file @
98640b63
...
...
@@ -202,7 +202,7 @@ TabulatedFunction& CustomHbondForce::getFunction(int index) {
return
*
functions
[
index
].
function
;
}
const
string
&
CustomHbondForce
::
getFunctionName
(
int
index
)
{
const
string
&
CustomHbondForce
::
getFunctionName
(
int
index
)
const
{
ASSERT_VALID_INDEX
(
index
,
functions
);
return
functions
[
index
].
name
;
}
...
...
openmmapi/src/CustomNonbondedForce.cpp
View file @
98640b63
...
...
@@ -184,7 +184,7 @@ TabulatedFunction& CustomNonbondedForce::getFunction(int index) {
return
*
functions
[
index
].
function
;
}
const
string
&
CustomNonbondedForce
::
getFunctionName
(
int
index
)
{
const
string
&
CustomNonbondedForce
::
getFunctionName
(
int
index
)
const
{
ASSERT_VALID_INDEX
(
index
,
functions
);
return
functions
[
index
].
name
;
}
...
...
platforms/reference/include/ReferenceTabulatedFunction.h
0 → 100644
View file @
98640b63
#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_*/
platforms/reference/src/ReferenceKernels.cpp
View file @
98640b63
...
...
@@ -55,6 +55,7 @@
#include "ReferenceProperDihedralBond.h"
#include "ReferenceRbDihedralBond.h"
#include "ReferenceStochasticDynamics.h"
#include "ReferenceTabulatedFunction.h"
#include "ReferenceVariableStochasticDynamics.h"
#include "ReferenceVariableVerletDynamics.h"
#include "ReferenceVerletDynamics.h"
...
...
@@ -69,7 +70,6 @@
#include "openmm/internal/CustomNonbondedForceImpl.h"
#include "openmm/internal/CMAPTorsionForceImpl.h"
#include "openmm/internal/NonbondedForceImpl.h"
#include "openmm/internal/SplineFitter.h"
#include "openmm/Integrator.h"
#include "openmm/OpenMMException.h"
#include "SimTKOpenMMUtilities.h"
...
...
@@ -923,38 +923,6 @@ void ReferenceCalcNonbondedForceKernel::copyParametersToContext(ContextImpl& con
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
()
{
disposeRealArray
(
particleParamArray
,
numParticles
);
if
(
neighborList
!=
NULL
)
...
...
@@ -1001,13 +969,8 @@ void ReferenceCalcCustomNonbondedForceKernel::initialize(const System& system, c
// Create custom functions for the tabulated functions.
map
<
string
,
Lepton
::
CustomFunction
*>
functions
;
for
(
int
i
=
0
;
i
<
force
.
getNumFunctions
();
i
++
)
{
string
name
;
vector
<
double
>
values
;
double
min
,
max
;
force
.
getFunctionParameters
(
i
,
name
,
values
,
min
,
max
);
functions
[
name
]
=
new
ReferenceTabulatedFunction
(
min
,
max
,
values
);
}
for
(
int
i
=
0
;
i
<
force
.
getNumFunctions
();
i
++
)
functions
[
force
.
getFunctionName
(
i
)]
=
createReferenceTabulatedFunction
(
force
.
getFunction
(
i
));
// Parse the various expressions used to calculate the force.
...
...
@@ -1288,13 +1251,8 @@ void ReferenceCalcCustomGBForceKernel::initialize(const System& system, const Cu
// Create custom functions for the tabulated functions.
map
<
string
,
Lepton
::
CustomFunction
*>
functions
;
for
(
int
i
=
0
;
i
<
force
.
getNumFunctions
();
i
++
)
{
string
name
;
vector
<
double
>
values
;
double
min
,
max
;
force
.
getFunctionParameters
(
i
,
name
,
values
,
min
,
max
);
functions
[
name
]
=
new
ReferenceTabulatedFunction
(
min
,
max
,
values
);
}
for
(
int
i
=
0
;
i
<
force
.
getNumFunctions
();
i
++
)
functions
[
force
.
getFunctionName
(
i
)]
=
createReferenceTabulatedFunction
(
force
.
getFunction
(
i
));
// Parse the expressions for computed values.
...
...
@@ -1507,13 +1465,8 @@ void ReferenceCalcCustomHbondForceKernel::initialize(const System& system, const
// Create custom functions for the tabulated functions.
map
<
string
,
Lepton
::
CustomFunction
*>
functions
;
for
(
int
i
=
0
;
i
<
force
.
getNumFunctions
();
i
++
)
{
string
name
;
vector
<
double
>
values
;
double
min
,
max
;
force
.
getFunctionParameters
(
i
,
name
,
values
,
min
,
max
);
functions
[
name
]
=
new
ReferenceTabulatedFunction
(
min
,
max
,
values
);
}
for
(
int
i
=
0
;
i
<
force
.
getNumFunctions
();
i
++
)
functions
[
force
.
getFunctionName
(
i
)]
=
createReferenceTabulatedFunction
(
force
.
getFunction
(
i
));
// Parse the expression and create the object used to calculate the interaction.
...
...
@@ -1609,13 +1562,8 @@ void ReferenceCalcCustomCompoundBondForceKernel::initialize(const System& system
// Create custom functions for the tabulated functions.
map
<
string
,
Lepton
::
CustomFunction
*>
functions
;
for
(
int
i
=
0
;
i
<
force
.
getNumFunctions
();
i
++
)
{
string
name
;
vector
<
double
>
values
;
double
min
,
max
;
force
.
getFunctionParameters
(
i
,
name
,
values
,
min
,
max
);
functions
[
name
]
=
new
ReferenceTabulatedFunction
(
min
,
max
,
values
);
}
for
(
int
i
=
0
;
i
<
force
.
getNumFunctions
();
i
++
)
functions
[
force
.
getFunctionName
(
i
)]
=
createReferenceTabulatedFunction
(
force
.
getFunction
(
i
));
// Parse the expression and create the object used to calculate the interaction.
...
...
platforms/reference/src/ReferenceTabulatedFunction.cpp
0 → 100644
View file @
98640b63
/* -------------------------------------------------------------------------- *
* 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
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment