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
cd566c63
Commit
cd566c63
authored
Jul 06, 2016
by
peastman
Browse files
Beginnings of support for derivatives with respect to parameters
parent
77b9b7ba
Changes
39
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
137 additions
and
27 deletions
+137
-27
olla/include/openmm/kernels.h
olla/include/openmm/kernels.h
+7
-1
openmmapi/include/openmm/CustomBondForce.h
openmmapi/include/openmm/CustomBondForce.h
+27
-0
openmmapi/include/openmm/State.h
openmmapi/include/openmm/State.h
+16
-3
openmmapi/include/openmm/internal/ContextImpl.h
openmmapi/include/openmm/internal/ContextImpl.h
+5
-1
openmmapi/src/Context.cpp
openmmapi/src/Context.cpp
+9
-3
openmmapi/src/ContextImpl.cpp
openmmapi/src/ContextImpl.cpp
+4
-0
openmmapi/src/CustomBondForce.cpp
openmmapi/src/CustomBondForce.cpp
+14
-0
openmmapi/src/State.cpp
openmmapi/src/State.cpp
+15
-1
platforms/cpu/src/CpuBondForce.cpp
platforms/cpu/src/CpuBondForce.cpp
+3
-3
platforms/cuda/include/CudaKernels.h
platforms/cuda/include/CudaKernels.h
+6
-0
platforms/cuda/src/CudaKernels.cpp
platforms/cuda/src/CudaKernels.cpp
+4
-0
platforms/opencl/include/OpenCLKernels.h
platforms/opencl/include/OpenCLKernels.h
+6
-0
platforms/opencl/src/OpenCLKernels.cpp
platforms/opencl/src/OpenCLKernels.cpp
+4
-0
platforms/reference/include/ReferenceAngleBondIxn.h
platforms/reference/include/ReferenceAngleBondIxn.h
+2
-2
platforms/reference/include/ReferenceBondIxn.h
platforms/reference/include/ReferenceBondIxn.h
+2
-2
platforms/reference/include/ReferenceCMAPTorsionIxn.h
platforms/reference/include/ReferenceCMAPTorsionIxn.h
+2
-2
platforms/reference/include/ReferenceCustomAngleIxn.h
platforms/reference/include/ReferenceCustomAngleIxn.h
+1
-1
platforms/reference/include/ReferenceCustomBondIxn.h
platforms/reference/include/ReferenceCustomBondIxn.h
+8
-6
platforms/reference/include/ReferenceCustomTorsionIxn.h
platforms/reference/include/ReferenceCustomTorsionIxn.h
+1
-1
platforms/reference/include/ReferenceHarmonicBondIxn.h
platforms/reference/include/ReferenceHarmonicBondIxn.h
+1
-1
No files found.
olla/include/openmm/kernels.h
View file @
cd566c63
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2008-201
5
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
6
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -172,6 +172,12 @@ public:
...
@@ -172,6 +172,12 @@ public:
* @param forces on exit, this contains the forces
* @param forces on exit, this contains the forces
*/
*/
virtual
void
getForces
(
ContextImpl
&
context
,
std
::
vector
<
Vec3
>&
forces
)
=
0
;
virtual
void
getForces
(
ContextImpl
&
context
,
std
::
vector
<
Vec3
>&
forces
)
=
0
;
/**
* Get the current derivatives of the energy with respect to context parameters.
*
* @param derivs on exit, this contains the derivatives
*/
virtual
void
getEnergyParameterDerivatives
(
ContextImpl
&
context
,
std
::
map
<
std
::
string
,
double
>&
derivs
)
=
0
;
/**
/**
* Get the current periodic box vectors.
* Get the current periodic box vectors.
*
*
...
...
openmmapi/include/openmm/CustomBondForce.h
View file @
cd566c63
...
@@ -63,6 +63,10 @@ namespace OpenMM {
...
@@ -63,6 +63,10 @@ namespace OpenMM {
* force->addPerBondParameter("k");
* force->addPerBondParameter("k");
* force->addPerBondParameter("r0");
* force->addPerBondParameter("r0");
* </pre></tt>
* </pre></tt>
*
* This class also has the ability to compute derivatives of the potential energy with respect to global parameters.
* Call addEnergyParameterDerivative() to request that the derivative with respect to a particular parameter be
* computed. You can then query its value in a Context by calling getState() on it.
*
*
* Expressions may involve the operators + (add), - (subtract), * (multiply), / (divide), and ^ (power), and the following
* Expressions may involve the operators + (add), - (subtract), * (multiply), / (divide), and ^ (power), and the following
* functions: sqrt, exp, log, sin, cos, sec, csc, tan, cot, asin, acos, atan, sinh, cosh, tanh, erf, erfc, min, max, abs, floor, ceil, step, delta, select. All trigonometric functions
* functions: sqrt, exp, log, sin, cos, sec, csc, tan, cot, asin, acos, atan, sinh, cosh, tanh, erf, erfc, min, max, abs, floor, ceil, step, delta, select. All trigonometric functions
...
@@ -97,6 +101,13 @@ public:
...
@@ -97,6 +101,13 @@ public:
int
getNumGlobalParameters
()
const
{
int
getNumGlobalParameters
()
const
{
return
globalParameters
.
size
();
return
globalParameters
.
size
();
}
}
/**
* Get the number of global parameters with respect to which the derivative of the energy
* should be computed.
*/
int
getNumEnergyParameterDerivatives
()
const
{
return
energyParameterDerivatives
.
size
();
}
/**
/**
* Get the algebraic expression that gives the interaction energy for each bond
* Get the algebraic expression that gives the interaction energy for each bond
*/
*/
...
@@ -162,6 +173,21 @@ public:
...
@@ -162,6 +173,21 @@ public:
* @param defaultValue the default value of the parameter
* @param defaultValue the default value of the parameter
*/
*/
void
setGlobalParameterDefaultValue
(
int
index
,
double
defaultValue
);
void
setGlobalParameterDefaultValue
(
int
index
,
double
defaultValue
);
/**
* Request that this Force compute the derivative of its energy with respect to a global parameter.
* The parameter must have already been added with addGlobalParameter().
*
* @param name the name of the parameter
*/
void
addEnergyParameterDerivative
(
const
std
::
string
&
name
);
/**
* Get the name of a global parameter with respect to which this Force should compute the
* derivative of the energy.
*
* @param index the index of the parameter derivative, between 0 and getNumEnergyParameterDerivatives()
* @return the parameter name
*/
const
std
::
string
&
getEnergyParameterDerivativeName
(
int
index
)
const
;
/**
/**
* Add a bond term to the force field.
* Add a bond term to the force field.
*
*
...
@@ -222,6 +248,7 @@ private:
...
@@ -222,6 +248,7 @@ private:
std
::
vector
<
BondParameterInfo
>
parameters
;
std
::
vector
<
BondParameterInfo
>
parameters
;
std
::
vector
<
GlobalParameterInfo
>
globalParameters
;
std
::
vector
<
GlobalParameterInfo
>
globalParameters
;
std
::
vector
<
BondInfo
>
bonds
;
std
::
vector
<
BondInfo
>
bonds
;
std
::
vector
<
int
>
energyParameterDerivatives
;
bool
usePeriodic
;
bool
usePeriodic
;
};
};
...
...
openmmapi/include/openmm/State.h
View file @
cd566c63
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2008 Stanford University and the Authors.
*
* Portions copyright (c) 2008
-2016
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -58,7 +58,7 @@ public:
...
@@ -58,7 +58,7 @@ public:
* This is an enumeration of the types of data which may be stored in a State. When you create
* This is an enumeration of the types of data which may be stored in a State. When you create
* a State, use these values to specify which data types it should contain.
* a State, use these values to specify which data types it should contain.
*/
*/
enum
DataType
{
Positions
=
1
,
Velocities
=
2
,
Forces
=
4
,
Energy
=
8
,
Parameters
=
16
};
enum
DataType
{
Positions
=
1
,
Velocities
=
2
,
Forces
=
4
,
Energy
=
8
,
Parameters
=
16
,
ParameterDerivatives
=
32
};
/**
/**
* Construct an empty State containing no data. This exists so State objects can be used in STL containers.
* Construct an empty State containing no data. This exists so State objects can be used in STL containers.
*/
*/
...
@@ -108,6 +108,17 @@ public:
...
@@ -108,6 +108,17 @@ public:
* Get a map containing the values of all parameters. If this State does not contain parameters, this will throw an exception.
* Get a map containing the values of all parameters. If this State does not contain parameters, this will throw an exception.
*/
*/
const
std
::
map
<
std
::
string
,
double
>&
getParameters
()
const
;
const
std
::
map
<
std
::
string
,
double
>&
getParameters
()
const
;
/**
* Get a map containing derivatives of the potential energy with respect to context parameters.
* In most cases derivatives are only calculated if the corresponding Force objects have been
* specifically told to compute them. Otherwise, the values in the map will be zero. Likewise,
* if multiple Forces depend on the same parameter but only some have been told to compute
* derivatives with respect to it, the returned value will include only the contributions from
* the Forces that were told to compute it.
*
* If this State does not contain parameter derivatives, this will throw an exception.
*/
const
std
::
map
<
std
::
string
,
double
>&
getEnergyParameterDerivatives
()
const
;
/**
/**
* Get which data types are stored in this State. The return value is a sum of DataType flags.
* Get which data types are stored in this State. The return value is a sum of DataType flags.
*/
*/
...
@@ -118,6 +129,7 @@ private:
...
@@ -118,6 +129,7 @@ private:
void
setVelocities
(
const
std
::
vector
<
Vec3
>&
vel
);
void
setVelocities
(
const
std
::
vector
<
Vec3
>&
vel
);
void
setForces
(
const
std
::
vector
<
Vec3
>&
force
);
void
setForces
(
const
std
::
vector
<
Vec3
>&
force
);
void
setParameters
(
const
std
::
map
<
std
::
string
,
double
>&
params
);
void
setParameters
(
const
std
::
map
<
std
::
string
,
double
>&
params
);
void
setEnergyParameterDerivatives
(
const
std
::
map
<
std
::
string
,
double
>&
derivs
);
void
setEnergy
(
double
ke
,
double
pe
);
void
setEnergy
(
double
ke
,
double
pe
);
void
setPeriodicBoxVectors
(
const
Vec3
&
a
,
const
Vec3
&
b
,
const
Vec3
&
c
);
void
setPeriodicBoxVectors
(
const
Vec3
&
a
,
const
Vec3
&
b
,
const
Vec3
&
c
);
int
types
;
int
types
;
...
@@ -126,7 +138,7 @@ private:
...
@@ -126,7 +138,7 @@ private:
std
::
vector
<
Vec3
>
velocities
;
std
::
vector
<
Vec3
>
velocities
;
std
::
vector
<
Vec3
>
forces
;
std
::
vector
<
Vec3
>
forces
;
Vec3
periodicBoxVectors
[
3
];
Vec3
periodicBoxVectors
[
3
];
std
::
map
<
std
::
string
,
double
>
parameters
;
std
::
map
<
std
::
string
,
double
>
parameters
,
energyParameterDerivatives
;
};
};
/**
/**
...
@@ -142,6 +154,7 @@ public:
...
@@ -142,6 +154,7 @@ public:
void
setVelocities
(
const
std
::
vector
<
Vec3
>&
vel
);
void
setVelocities
(
const
std
::
vector
<
Vec3
>&
vel
);
void
setForces
(
const
std
::
vector
<
Vec3
>&
force
);
void
setForces
(
const
std
::
vector
<
Vec3
>&
force
);
void
setParameters
(
const
std
::
map
<
std
::
string
,
double
>&
params
);
void
setParameters
(
const
std
::
map
<
std
::
string
,
double
>&
params
);
void
setEnergyParameterDerivatives
(
const
std
::
map
<
std
::
string
,
double
>&
params
);
void
setEnergy
(
double
ke
,
double
pe
);
void
setEnergy
(
double
ke
,
double
pe
);
void
setPeriodicBoxVectors
(
const
Vec3
&
a
,
const
Vec3
&
b
,
const
Vec3
&
c
);
void
setPeriodicBoxVectors
(
const
Vec3
&
a
,
const
Vec3
&
b
,
const
Vec3
&
c
);
private:
private:
...
...
openmmapi/include/openmm/internal/ContextImpl.h
View file @
cd566c63
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2008-201
3
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
6
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -138,6 +138,10 @@ public:
...
@@ -138,6 +138,10 @@ public:
* @param value the value of the parameter
* @param value the value of the parameter
*/
*/
void
setParameter
(
std
::
string
name
,
double
value
);
void
setParameter
(
std
::
string
name
,
double
value
);
/**
* Get the derivatives of the energy with respect to parameters.
*/
void
getEnergyParameterDerivatives
(
std
::
map
<
std
::
string
,
double
>&
derivs
);
/**
/**
* Get the vectors defining the axes of the periodic box (measured in nm). They will affect
* Get the vectors defining the axes of the periodic box (measured in nm). They will affect
* any Force that uses periodic boundary conditions.
* any Force that uses periodic boundary conditions.
...
...
openmmapi/src/Context.cpp
View file @
cd566c63
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2008-201
5
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
6
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -84,8 +84,9 @@ State Context::getState(int types, bool enforcePeriodicBox, int groups) const {
...
@@ -84,8 +84,9 @@ State Context::getState(int types, bool enforcePeriodicBox, int groups) const {
builder
.
setPeriodicBoxVectors
(
periodicBoxSize
[
0
],
periodicBoxSize
[
1
],
periodicBoxSize
[
2
]);
builder
.
setPeriodicBoxVectors
(
periodicBoxSize
[
0
],
periodicBoxSize
[
1
],
periodicBoxSize
[
2
]);
bool
includeForces
=
types
&
State
::
Forces
;
bool
includeForces
=
types
&
State
::
Forces
;
bool
includeEnergy
=
types
&
State
::
Energy
;
bool
includeEnergy
=
types
&
State
::
Energy
;
if
(
includeForces
||
includeEnergy
)
{
bool
includeParameterDerivs
=
types
&
State
::
ParameterDerivatives
;
double
energy
=
impl
->
calcForcesAndEnergy
(
includeForces
||
includeEnergy
,
includeEnergy
,
groups
);
if
(
includeForces
||
includeEnergy
||
includeParameterDerivs
)
{
double
energy
=
impl
->
calcForcesAndEnergy
(
includeForces
||
includeEnergy
||
includeParameterDerivs
,
includeEnergy
,
groups
);
if
(
includeEnergy
)
if
(
includeEnergy
)
builder
.
setEnergy
(
impl
->
calcKineticEnergy
(),
energy
);
builder
.
setEnergy
(
impl
->
calcKineticEnergy
(),
energy
);
if
(
includeForces
)
{
if
(
includeForces
)
{
...
@@ -100,6 +101,11 @@ State Context::getState(int types, bool enforcePeriodicBox, int groups) const {
...
@@ -100,6 +101,11 @@ State Context::getState(int types, bool enforcePeriodicBox, int groups) const {
params
[
iter
->
first
]
=
iter
->
second
;
params
[
iter
->
first
]
=
iter
->
second
;
builder
.
setParameters
(
params
);
builder
.
setParameters
(
params
);
}
}
if
(
types
&
State
::
ParameterDerivatives
)
{
map
<
string
,
double
>
derivs
;
impl
->
getEnergyParameterDerivatives
(
derivs
);
builder
.
setEnergyParameterDerivatives
(
derivs
);
}
if
(
types
&
State
::
Positions
)
{
if
(
types
&
State
::
Positions
)
{
vector
<
Vec3
>
positions
;
vector
<
Vec3
>
positions
;
impl
->
getPositions
(
positions
);
impl
->
getPositions
(
positions
);
...
...
openmmapi/src/ContextImpl.cpp
View file @
cd566c63
...
@@ -240,6 +240,10 @@ void ContextImpl::setParameter(std::string name, double value) {
...
@@ -240,6 +240,10 @@ void ContextImpl::setParameter(std::string name, double value) {
integrator
.
stateChanged
(
State
::
Parameters
);
integrator
.
stateChanged
(
State
::
Parameters
);
}
}
void
ContextImpl
::
getEnergyParameterDerivatives
(
std
::
map
<
std
::
string
,
double
>&
derivs
)
{
updateStateDataKernel
.
getAs
<
UpdateStateDataKernel
>
().
getEnergyParameterDerivatives
(
*
this
,
derivs
);
}
void
ContextImpl
::
getPeriodicBoxVectors
(
Vec3
&
a
,
Vec3
&
b
,
Vec3
&
c
)
{
void
ContextImpl
::
getPeriodicBoxVectors
(
Vec3
&
a
,
Vec3
&
b
,
Vec3
&
c
)
{
updateStateDataKernel
.
getAs
<
UpdateStateDataKernel
>
().
getPeriodicBoxVectors
(
*
this
,
a
,
b
,
c
);
updateStateDataKernel
.
getAs
<
UpdateStateDataKernel
>
().
getPeriodicBoxVectors
(
*
this
,
a
,
b
,
c
);
}
}
...
...
openmmapi/src/CustomBondForce.cpp
View file @
cd566c63
...
@@ -95,6 +95,20 @@ void CustomBondForce::setGlobalParameterDefaultValue(int index, double defaultVa
...
@@ -95,6 +95,20 @@ void CustomBondForce::setGlobalParameterDefaultValue(int index, double defaultVa
globalParameters
[
index
].
defaultValue
=
defaultValue
;
globalParameters
[
index
].
defaultValue
=
defaultValue
;
}
}
void
CustomBondForce
::
addEnergyParameterDerivative
(
const
string
&
name
)
{
for
(
int
i
=
0
;
i
<
globalParameters
.
size
();
i
++
)
if
(
name
==
globalParameters
[
i
].
name
)
{
energyParameterDerivatives
.
push_back
(
i
);
return
;
}
throw
OpenMMException
(
string
(
"addEnergyParameterDerivative: Unknown global parameter '"
+
name
+
"'"
));
}
const
string
&
CustomBondForce
::
getEnergyParameterDerivativeName
(
int
index
)
const
{
ASSERT_VALID_INDEX
(
index
,
energyParameterDerivatives
);
return
globalParameters
[
energyParameterDerivatives
[
index
]].
name
;
}
int
CustomBondForce
::
addBond
(
int
particle1
,
int
particle2
,
const
vector
<
double
>&
parameters
)
{
int
CustomBondForce
::
addBond
(
int
particle1
,
int
particle2
,
const
vector
<
double
>&
parameters
)
{
bonds
.
push_back
(
BondInfo
(
particle1
,
particle2
,
parameters
));
bonds
.
push_back
(
BondInfo
(
particle1
,
particle2
,
parameters
));
return
bonds
.
size
()
-
1
;
return
bonds
.
size
()
-
1
;
...
...
openmmapi/src/State.cpp
View file @
cd566c63
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2008 Stanford University and the Authors.
*
* Portions copyright (c) 2008
-2016
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -76,6 +76,11 @@ const map<string, double>& State::getParameters() const {
...
@@ -76,6 +76,11 @@ const map<string, double>& State::getParameters() const {
throw
OpenMMException
(
"Invoked getParameters() on a State which does not contain parameters."
);
throw
OpenMMException
(
"Invoked getParameters() on a State which does not contain parameters."
);
return
parameters
;
return
parameters
;
}
}
const
map
<
string
,
double
>&
State
::
getEnergyParameterDerivatives
()
const
{
if
((
types
&
ParameterDerivatives
)
==
0
)
throw
OpenMMException
(
"Invoked getEnergyParameterDerivatives() on a State which does not contain parameter derivatives."
);
return
energyParameterDerivatives
;
}
int
State
::
getDataTypes
()
const
{
int
State
::
getDataTypes
()
const
{
return
types
;
return
types
;
}
}
...
@@ -103,6 +108,11 @@ void State::setParameters(const std::map<std::string, double>& params) {
...
@@ -103,6 +108,11 @@ void State::setParameters(const std::map<std::string, double>& params) {
types
|=
Parameters
;
types
|=
Parameters
;
}
}
void
State
::
setEnergyParameterDerivatives
(
const
std
::
map
<
std
::
string
,
double
>&
derivs
)
{
energyParameterDerivatives
=
derivs
;
types
|=
ParameterDerivatives
;
}
void
State
::
setEnergy
(
double
kinetic
,
double
potential
)
{
void
State
::
setEnergy
(
double
kinetic
,
double
potential
)
{
ke
=
kinetic
;
ke
=
kinetic
;
pe
=
potential
;
pe
=
potential
;
...
@@ -138,6 +148,10 @@ void State::StateBuilder::setParameters(const std::map<std::string, double>& par
...
@@ -138,6 +148,10 @@ void State::StateBuilder::setParameters(const std::map<std::string, double>& par
state
.
setParameters
(
params
);
state
.
setParameters
(
params
);
}
}
void
State
::
StateBuilder
::
setEnergyParameterDerivatives
(
const
std
::
map
<
std
::
string
,
double
>&
derivs
)
{
state
.
setEnergyParameterDerivatives
(
derivs
);
}
void
State
::
StateBuilder
::
setEnergy
(
double
ke
,
double
pe
)
{
void
State
::
StateBuilder
::
setEnergy
(
double
ke
,
double
pe
)
{
state
.
setEnergy
(
ke
,
pe
);
state
.
setEnergy
(
ke
,
pe
);
}
}
...
...
platforms/cpu/src/CpuBondForce.cpp
View file @
cd566c63
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2014 Stanford University and the Authors.
*
* Portions copyright (c) 2014
-2016
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -196,7 +196,7 @@ void CpuBondForce::calculateForce(vector<RealVec>& atomCoordinates, RealOpenMM**
...
@@ -196,7 +196,7 @@ void CpuBondForce::calculateForce(vector<RealVec>& atomCoordinates, RealOpenMM**
for
(
int
i
=
0
;
i
<
extraBonds
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
extraBonds
.
size
();
i
++
)
{
int
bond
=
extraBonds
[
i
];
int
bond
=
extraBonds
[
i
];
referenceBondIxn
.
calculateBondIxn
(
bondAtoms
[
bond
],
atomCoordinates
,
parameters
[
bond
],
forces
,
totalEnergy
);
referenceBondIxn
.
calculateBondIxn
(
bondAtoms
[
bond
],
atomCoordinates
,
parameters
[
bond
],
forces
,
totalEnergy
,
NULL
);
}
}
// Compute the total energy.
// Compute the total energy.
...
@@ -212,6 +212,6 @@ void CpuBondForce::threadComputeForce(ThreadPool& threads, int threadIndex, vect
...
@@ -212,6 +212,6 @@ void CpuBondForce::threadComputeForce(ThreadPool& threads, int threadIndex, vect
int
numBonds
=
bonds
.
size
();
int
numBonds
=
bonds
.
size
();
for
(
int
i
=
0
;
i
<
numBonds
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numBonds
;
i
++
)
{
int
bond
=
bonds
[
i
];
int
bond
=
bonds
[
i
];
referenceBondIxn
.
calculateBondIxn
(
bondAtoms
[
bond
],
atomCoordinates
,
parameters
[
bond
],
forces
,
totalEnergy
);
referenceBondIxn
.
calculateBondIxn
(
bondAtoms
[
bond
],
atomCoordinates
,
parameters
[
bond
],
forces
,
totalEnergy
,
NULL
);
}
}
}
}
\ No newline at end of file
platforms/cuda/include/CudaKernels.h
View file @
cd566c63
...
@@ -163,6 +163,12 @@ public:
...
@@ -163,6 +163,12 @@ public:
* @param forces on exit, this contains the forces
* @param forces on exit, this contains the forces
*/
*/
void
getForces
(
ContextImpl
&
context
,
std
::
vector
<
Vec3
>&
forces
);
void
getForces
(
ContextImpl
&
context
,
std
::
vector
<
Vec3
>&
forces
);
/**
* Get the current derivatives of the energy with respect to context parameters.
*
* @param derivs on exit, this contains the derivatives
*/
void
getEnergyParameterDerivatives
(
ContextImpl
&
context
,
std
::
map
<
std
::
string
,
double
>&
derivs
);
/**
/**
* Get the current periodic box vectors.
* Get the current periodic box vectors.
*
*
...
...
platforms/cuda/src/CudaKernels.cpp
View file @
cd566c63
...
@@ -339,6 +339,10 @@ void CudaUpdateStateDataKernel::getForces(ContextImpl& context, vector<Vec3>& fo
...
@@ -339,6 +339,10 @@ void CudaUpdateStateDataKernel::getForces(ContextImpl& context, vector<Vec3>& fo
forces[order[i]] = Vec3(scale*force[i], scale*force[i+paddedNumParticles], scale*force[i+paddedNumParticles*2]);
forces[order[i]] = Vec3(scale*force[i], scale*force[i+paddedNumParticles], scale*force[i+paddedNumParticles*2]);
}
}
void CudaUpdateStateDataKernel::getEnergyParameterDerivatives(ContextImpl& context, map<string, double>& derivs) {
}
void CudaUpdateStateDataKernel::getPeriodicBoxVectors(ContextImpl& context, Vec3& a, Vec3& b, Vec3& c) const {
void CudaUpdateStateDataKernel::getPeriodicBoxVectors(ContextImpl& context, Vec3& a, Vec3& b, Vec3& c) const {
cu.getPeriodicBoxVectors(a, b, c);
cu.getPeriodicBoxVectors(a, b, c);
}
}
...
...
platforms/opencl/include/OpenCLKernels.h
View file @
cd566c63
...
@@ -141,6 +141,12 @@ public:
...
@@ -141,6 +141,12 @@ public:
* @param forces on exit, this contains the forces
* @param forces on exit, this contains the forces
*/
*/
void
getForces
(
ContextImpl
&
context
,
std
::
vector
<
Vec3
>&
forces
);
void
getForces
(
ContextImpl
&
context
,
std
::
vector
<
Vec3
>&
forces
);
/**
* Get the current derivatives of the energy with respect to context parameters.
*
* @param derivs on exit, this contains the derivatives
*/
void
getEnergyParameterDerivatives
(
ContextImpl
&
context
,
std
::
map
<
std
::
string
,
double
>&
derivs
);
/**
/**
* Get the current periodic box vectors.
* Get the current periodic box vectors.
*
*
...
...
platforms/opencl/src/OpenCLKernels.cpp
View file @
cd566c63
...
@@ -368,6 +368,10 @@ void OpenCLUpdateStateDataKernel::getForces(ContextImpl& context, vector<Vec3>&
...
@@ -368,6 +368,10 @@ void OpenCLUpdateStateDataKernel::getForces(ContextImpl& context, vector<Vec3>&
}
}
}
}
void
OpenCLUpdateStateDataKernel
::
getEnergyParameterDerivatives
(
ContextImpl
&
context
,
map
<
string
,
double
>&
derivs
)
{
}
void
OpenCLUpdateStateDataKernel
::
getPeriodicBoxVectors
(
ContextImpl
&
context
,
Vec3
&
a
,
Vec3
&
b
,
Vec3
&
c
)
const
{
void
OpenCLUpdateStateDataKernel
::
getPeriodicBoxVectors
(
ContextImpl
&
context
,
Vec3
&
a
,
Vec3
&
b
,
Vec3
&
c
)
const
{
cl
.
getPeriodicBoxVectors
(
a
,
b
,
c
);
cl
.
getPeriodicBoxVectors
(
a
,
b
,
c
);
}
}
...
...
platforms/reference/include/ReferenceAngleBondIxn.h
View file @
cd566c63
/* Portions copyright (c) 2006 Stanford University and Simbios.
/* Portions copyright (c) 2006
-2016
Stanford University and Simbios.
* Contributors: Pande Group
* Contributors: Pande Group
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* Permission is hereby granted, free of charge, to any person obtaining
...
@@ -94,7 +94,7 @@ class OPENMM_EXPORT ReferenceAngleBondIxn : public ReferenceBondIxn {
...
@@ -94,7 +94,7 @@ class OPENMM_EXPORT ReferenceAngleBondIxn : public ReferenceBondIxn {
void
calculateBondIxn
(
int
*
atomIndices
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
void
calculateBondIxn
(
int
*
atomIndices
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
RealOpenMM
*
parameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
parameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
totalEnergy
)
const
;
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
;
};
};
...
...
platforms/reference/include/ReferenceBondIxn.h
View file @
cd566c63
/* Portions copyright (c) 2006 Stanford University and Simbios.
/* Portions copyright (c) 2006
-2016
Stanford University and Simbios.
* Contributors: Pande Group
* Contributors: Pande Group
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* Permission is hereby granted, free of charge, to any person obtaining
...
@@ -67,7 +67,7 @@ class OPENMM_EXPORT ReferenceBondIxn {
...
@@ -67,7 +67,7 @@ class OPENMM_EXPORT ReferenceBondIxn {
virtual
void
calculateBondIxn
(
int
*
atomIndices
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
virtual
void
calculateBondIxn
(
int
*
atomIndices
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
RealOpenMM
*
parameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
parameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
totalEnergy
)
const
;
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
;
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
...
platforms/reference/include/ReferenceCMAPTorsionIxn.h
View file @
cd566c63
/* Portions copyright (c) 2010 Stanford University and Simbios.
/* Portions copyright (c) 2010
-2016
Stanford University and Simbios.
* Contributors: Peter Eastman
* Contributors: Peter Eastman
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* Permission is hereby granted, free of charge, to any person obtaining
...
@@ -97,7 +97,7 @@ public:
...
@@ -97,7 +97,7 @@ public:
void
calculateBondIxn
(
int
*
atomIndices
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
void
calculateBondIxn
(
int
*
atomIndices
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
RealOpenMM
*
parameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
parameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
totalEnergy
)
const
;
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
;
// ---------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------
...
...
platforms/reference/include/ReferenceCustomAngleIxn.h
View file @
cd566c63
...
@@ -85,7 +85,7 @@ class ReferenceCustomAngleIxn : public ReferenceBondIxn {
...
@@ -85,7 +85,7 @@ class ReferenceCustomAngleIxn : public ReferenceBondIxn {
void
calculateBondIxn
(
int
*
atomIndices
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
void
calculateBondIxn
(
int
*
atomIndices
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
RealOpenMM
*
parameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
parameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
totalEnergy
)
const
;
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
;
};
};
...
...
platforms/reference/include/ReferenceCustomBondIxn.h
View file @
cd566c63
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#define __ReferenceCustomBondIxn_H__
#define __ReferenceCustomBondIxn_H__
#include "ReferenceBondIxn.h"
#include "ReferenceBondIxn.h"
#include "openmm/internal/CompiledExpressionSet.h"
#include "lepton/CompiledExpression.h"
#include "lepton/CompiledExpression.h"
namespace
OpenMM
{
namespace
OpenMM
{
...
@@ -35,10 +36,10 @@ class ReferenceCustomBondIxn : public ReferenceBondIxn {
...
@@ -35,10 +36,10 @@ class ReferenceCustomBondIxn : public ReferenceBondIxn {
private:
private:
Lepton
::
CompiledExpression
energyExpression
;
Lepton
::
CompiledExpression
energyExpression
;
Lepton
::
CompiledExpression
forceExpression
;
Lepton
::
CompiledExpression
forceExpression
;
std
::
vector
<
double
*>
energyParam
s
;
std
::
vector
<
Lepton
::
CompiledExpression
>
energyParamDerivExpression
s
;
std
::
vector
<
double
*>
forceParams
;
CompiledExpressionSet
expressionSet
;
double
*
energyR
;
std
::
vector
<
int
>
bondParamIndex
;
double
*
forceR
;
int
rIndex
;
int
numParameters
;
int
numParameters
;
bool
usePeriodic
;
bool
usePeriodic
;
RealVec
boxVectors
[
3
];
RealVec
boxVectors
[
3
];
...
@@ -52,7 +53,8 @@ class ReferenceCustomBondIxn : public ReferenceBondIxn {
...
@@ -52,7 +53,8 @@ class ReferenceCustomBondIxn : public ReferenceBondIxn {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceCustomBondIxn
(
const
Lepton
::
CompiledExpression
&
energyExpression
,
const
Lepton
::
CompiledExpression
&
forceExpression
,
ReferenceCustomBondIxn
(
const
Lepton
::
CompiledExpression
&
energyExpression
,
const
Lepton
::
CompiledExpression
&
forceExpression
,
const
std
::
vector
<
std
::
string
>&
parameterNames
,
std
::
map
<
std
::
string
,
double
>
globalParameters
);
const
std
::
vector
<
std
::
string
>&
parameterNames
,
std
::
map
<
std
::
string
,
double
>
globalParameters
,
const
std
::
vector
<
Lepton
::
CompiledExpression
>
energyParamDerivExpressions
);
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
@@ -86,7 +88,7 @@ class ReferenceCustomBondIxn : public ReferenceBondIxn {
...
@@ -86,7 +88,7 @@ class ReferenceCustomBondIxn : public ReferenceBondIxn {
void
calculateBondIxn
(
int
*
atomIndices
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
void
calculateBondIxn
(
int
*
atomIndices
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
RealOpenMM
*
parameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
parameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
totalEnergy
)
const
;
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
;
};
};
...
...
platforms/reference/include/ReferenceCustomTorsionIxn.h
View file @
cd566c63
...
@@ -85,7 +85,7 @@ class ReferenceCustomTorsionIxn : public ReferenceBondIxn {
...
@@ -85,7 +85,7 @@ class ReferenceCustomTorsionIxn : public ReferenceBondIxn {
void
calculateBondIxn
(
int
*
atomIndices
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
void
calculateBondIxn
(
int
*
atomIndices
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
RealOpenMM
*
parameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
parameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
totalEnergy
)
const
;
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
;
};
};
...
...
platforms/reference/include/ReferenceHarmonicBondIxn.h
View file @
cd566c63
...
@@ -79,7 +79,7 @@ class ReferenceHarmonicBondIxn : public ReferenceBondIxn {
...
@@ -79,7 +79,7 @@ class ReferenceHarmonicBondIxn : public ReferenceBondIxn {
void
calculateBondIxn
(
int
*
atomIndices
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
void
calculateBondIxn
(
int
*
atomIndices
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
RealOpenMM
*
parameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
parameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
totalEnergy
)
const
;
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
;
};
};
...
...
Prev
1
2
Next
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