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
4bc723ab
Commit
4bc723ab
authored
Jun 06, 2012
by
Peter Eastman
Browse files
Implemented updateParametersInContext() for seven more Force classes
parent
b5e2a951
Changes
51
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
547 additions
and
30 deletions
+547
-30
openmmapi/src/CustomTorsionForceImpl.cpp
openmmapi/src/CustomTorsionForceImpl.cpp
+4
-1
openmmapi/src/HarmonicAngleForce.cpp
openmmapi/src/HarmonicAngleForce.cpp
+4
-0
openmmapi/src/HarmonicAngleForceImpl.cpp
openmmapi/src/HarmonicAngleForceImpl.cpp
+5
-1
openmmapi/src/HarmonicBondForce.cpp
openmmapi/src/HarmonicBondForce.cpp
+5
-1
openmmapi/src/HarmonicBondForceImpl.cpp
openmmapi/src/HarmonicBondForceImpl.cpp
+5
-1
openmmapi/src/PeriodicTorsionForce.cpp
openmmapi/src/PeriodicTorsionForce.cpp
+5
-1
openmmapi/src/PeriodicTorsionForceImpl.cpp
openmmapi/src/PeriodicTorsionForceImpl.cpp
+5
-1
openmmapi/src/RBTorsionForce.cpp
openmmapi/src/RBTorsionForce.cpp
+5
-1
openmmapi/src/RBTorsionForceImpl.cpp
openmmapi/src/RBTorsionForceImpl.cpp
+5
-1
platforms/cuda/src/CudaKernels.cpp
platforms/cuda/src/CudaKernels.cpp
+28
-0
platforms/cuda/src/CudaKernels.h
platforms/cuda/src/CudaKernels.h
+49
-0
platforms/opencl/src/OpenCLKernels.cpp
platforms/opencl/src/OpenCLKernels.cpp
+167
-1
platforms/opencl/src/OpenCLKernels.h
platforms/opencl/src/OpenCLKernels.h
+49
-0
platforms/opencl/src/OpenCLParallelKernels.cpp
platforms/opencl/src/OpenCLParallelKernels.cpp
+35
-0
platforms/opencl/src/OpenCLParallelKernels.h
platforms/opencl/src/OpenCLParallelKernels.h
+49
-0
platforms/opencl/tests/TestOpenCLCustomAngleForce.cpp
platforms/opencl/tests/TestOpenCLCustomAngleForce.cpp
+29
-4
platforms/opencl/tests/TestOpenCLCustomBondForce.cpp
platforms/opencl/tests/TestOpenCLCustomBondForce.cpp
+25
-5
platforms/opencl/tests/TestOpenCLCustomTorsionForce.cpp
platforms/opencl/tests/TestOpenCLCustomTorsionForce.cpp
+25
-0
platforms/opencl/tests/TestOpenCLHarmonicAngleForce.cpp
platforms/opencl/tests/TestOpenCLHarmonicAngleForce.cpp
+27
-7
platforms/opencl/tests/TestOpenCLHarmonicBondForce.cpp
platforms/opencl/tests/TestOpenCLHarmonicBondForce.cpp
+21
-5
No files found.
openmmapi/src/CustomTorsionForceImpl.cpp
View file @
4bc723ab
...
...
@@ -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) 2010 Stanford University and the Authors.
*
* Portions copyright (c) 2010
-2012
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -113,3 +113,6 @@ map<string, double> CustomTorsionForceImpl::getDefaultParameters() {
return
parameters
;
}
void
CustomTorsionForceImpl
::
updateParametersInContext
(
ContextImpl
&
context
)
{
kernel
.
getAs
<
CalcCustomTorsionForceKernel
>
().
copyParametersToContext
(
context
,
owner
);
}
openmmapi/src/HarmonicAngleForce.cpp
View file @
4bc723ab
...
...
@@ -66,3 +66,7 @@ void HarmonicAngleForce::setAngleParameters(int index, int particle1, int partic
ForceImpl
*
HarmonicAngleForce
::
createImpl
()
{
return
new
HarmonicAngleForceImpl
(
*
this
);
}
void
HarmonicAngleForce
::
updateParametersInContext
(
Context
&
context
)
{
dynamic_cast
<
HarmonicAngleForceImpl
&>
(
getImplInContext
(
context
)).
updateParametersInContext
(
getContextImpl
(
context
));
}
openmmapi/src/HarmonicAngleForceImpl.cpp
View file @
4bc723ab
...
...
@@ -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) 2008 Stanford University and the Authors.
*
* Portions copyright (c) 2008
-2012
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -60,3 +60,7 @@ std::vector<std::string> HarmonicAngleForceImpl::getKernelNames() {
names
.
push_back
(
CalcHarmonicAngleForceKernel
::
Name
());
return
names
;
}
void
HarmonicAngleForceImpl
::
updateParametersInContext
(
ContextImpl
&
context
)
{
kernel
.
getAs
<
CalcHarmonicAngleForceKernel
>
().
copyParametersToContext
(
context
,
owner
);
}
openmmapi/src/HarmonicBondForce.cpp
View file @
4bc723ab
...
...
@@ -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) 2008-20
09
Stanford University and the Authors. *
* Portions copyright (c) 2008-20
12
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -64,3 +64,7 @@ void HarmonicBondForce::setBondParameters(int index, int particle1, int particle
ForceImpl
*
HarmonicBondForce
::
createImpl
()
{
return
new
HarmonicBondForceImpl
(
*
this
);
}
void
HarmonicBondForce
::
updateParametersInContext
(
Context
&
context
)
{
dynamic_cast
<
HarmonicBondForceImpl
&>
(
getImplInContext
(
context
)).
updateParametersInContext
(
getContextImpl
(
context
));
}
openmmapi/src/HarmonicBondForceImpl.cpp
View file @
4bc723ab
...
...
@@ -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) 2008 Stanford University and the Authors.
*
* Portions copyright (c) 2008
-2012
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -70,3 +70,7 @@ vector<pair<int, int> > HarmonicBondForceImpl::getBondedParticles() const {
}
return
bonds
;
}
void
HarmonicBondForceImpl
::
updateParametersInContext
(
ContextImpl
&
context
)
{
kernel
.
getAs
<
CalcHarmonicBondForceKernel
>
().
copyParametersToContext
(
context
,
owner
);
}
openmmapi/src/PeriodicTorsionForce.cpp
View file @
4bc723ab
...
...
@@ -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) 2008-20
09
Stanford University and the Authors. *
* Portions copyright (c) 2008-20
12
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -70,3 +70,7 @@ void PeriodicTorsionForce::setTorsionParameters(int index, int particle1, int pa
ForceImpl
*
PeriodicTorsionForce
::
createImpl
()
{
return
new
PeriodicTorsionForceImpl
(
*
this
);
}
void
PeriodicTorsionForce
::
updateParametersInContext
(
Context
&
context
)
{
dynamic_cast
<
PeriodicTorsionForceImpl
&>
(
getImplInContext
(
context
)).
updateParametersInContext
(
getContextImpl
(
context
));
}
openmmapi/src/PeriodicTorsionForceImpl.cpp
View file @
4bc723ab
...
...
@@ -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) 2008 Stanford University and the Authors.
*
* Portions copyright (c) 2008
-2012
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -60,3 +60,7 @@ std::vector<std::string> PeriodicTorsionForceImpl::getKernelNames() {
names
.
push_back
(
CalcPeriodicTorsionForceKernel
::
Name
());
return
names
;
}
void
PeriodicTorsionForceImpl
::
updateParametersInContext
(
ContextImpl
&
context
)
{
kernel
.
getAs
<
CalcPeriodicTorsionForceKernel
>
().
copyParametersToContext
(
context
,
owner
);
}
openmmapi/src/RBTorsionForce.cpp
View file @
4bc723ab
...
...
@@ -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) 2008-20
09
Stanford University and the Authors. *
* Portions copyright (c) 2008-20
12
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -76,3 +76,7 @@ void RBTorsionForce::setTorsionParameters(int index, int particle1, int particle
ForceImpl
*
RBTorsionForce
::
createImpl
()
{
return
new
RBTorsionForceImpl
(
*
this
);
}
void
RBTorsionForce
::
updateParametersInContext
(
Context
&
context
)
{
dynamic_cast
<
RBTorsionForceImpl
&>
(
getImplInContext
(
context
)).
updateParametersInContext
(
getContextImpl
(
context
));
}
openmmapi/src/RBTorsionForceImpl.cpp
View file @
4bc723ab
...
...
@@ -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) 2008 Stanford University and the Authors.
*
* Portions copyright (c) 2008
-2012
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -60,3 +60,7 @@ std::vector<std::string> RBTorsionForceImpl::getKernelNames() {
names
.
push_back
(
CalcRBTorsionForceKernel
::
Name
());
return
names
;
}
void
RBTorsionForceImpl
::
updateParametersInContext
(
ContextImpl
&
context
)
{
kernel
.
getAs
<
CalcRBTorsionForceKernel
>
().
copyParametersToContext
(
context
,
owner
);
}
platforms/cuda/src/CudaKernels.cpp
View file @
4bc723ab
...
...
@@ -255,6 +255,10 @@ double CudaCalcHarmonicBondForceKernel::execute(ContextImpl& context, bool inclu
return
0.0
;
}
void
CudaCalcHarmonicBondForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicBondForce
&
force
)
{
throw
OpenMMException
(
"CudaPlatform does not support copyParametersToContext"
);
}
class
CudaCalcCustomBondForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
public:
ForceInfo
(
const
CustomBondForce
&
force
)
:
force
(
force
)
{
...
...
@@ -327,6 +331,10 @@ void CudaCalcCustomBondForceKernel::updateGlobalParams(ContextImpl& context) {
SetCustomBondGlobalParams
(
globalParamValues
);
}
void
CudaCalcCustomBondForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomBondForce
&
force
)
{
throw
OpenMMException
(
"CudaPlatform does not support copyParametersToContext"
);
}
class
CudaCalcHarmonicAngleForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
public:
ForceInfo
(
const
HarmonicAngleForce
&
force
)
:
force
(
force
)
{
...
...
@@ -380,6 +388,10 @@ double CudaCalcHarmonicAngleForceKernel::execute(ContextImpl& context, bool incl
return
0.0
;
}
void
CudaCalcHarmonicAngleForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicAngleForce
&
force
)
{
throw
OpenMMException
(
"CudaPlatform does not support copyParametersToContext"
);
}
class
CudaCalcCustomAngleForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
public:
ForceInfo
(
const
CustomAngleForce
&
force
)
:
force
(
force
)
{
...
...
@@ -454,6 +466,10 @@ void CudaCalcCustomAngleForceKernel::updateGlobalParams(ContextImpl& context) {
SetCustomAngleGlobalParams
(
globalParamValues
);
}
void
CudaCalcCustomAngleForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomAngleForce
&
force
)
{
throw
OpenMMException
(
"CudaPlatform does not support copyParametersToContext"
);
}
class
CudaCalcPeriodicTorsionForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
public:
ForceInfo
(
const
PeriodicTorsionForce
&
force
)
:
force
(
force
)
{
...
...
@@ -510,6 +526,10 @@ double CudaCalcPeriodicTorsionForceKernel::execute(ContextImpl& context, bool in
return
0.0
;
}
void
CudaCalcPeriodicTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
PeriodicTorsionForce
&
force
)
{
throw
OpenMMException
(
"CudaPlatform does not support copyParametersToContext"
);
}
class
CudaCalcRBTorsionForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
public:
ForceInfo
(
const
RBTorsionForce
&
force
)
:
force
(
force
)
{
...
...
@@ -572,6 +592,10 @@ double CudaCalcRBTorsionForceKernel::execute(ContextImpl& context, bool includeF
return
0.0
;
}
void
CudaCalcRBTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
RBTorsionForce
&
force
)
{
throw
OpenMMException
(
"CudaPlatform does not support copyParametersToContext"
);
}
class
CudaCalcCMAPTorsionForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
public:
ForceInfo
(
const
CMAPTorsionForce
&
force
)
:
force
(
force
)
{
...
...
@@ -746,6 +770,10 @@ void CudaCalcCustomTorsionForceKernel::updateGlobalParams(ContextImpl& context)
SetCustomTorsionGlobalParams
(
globalParamValues
);
}
void
CudaCalcCustomTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomTorsionForce
&
force
)
{
throw
OpenMMException
(
"CudaPlatform does not support copyParametersToContext"
);
}
class
CudaCalcNonbondedForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
public:
ForceInfo
(
const
NonbondedForce
&
force
)
:
force
(
force
)
{
...
...
platforms/cuda/src/CudaKernels.h
View file @
4bc723ab
...
...
@@ -242,6 +242,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the HarmonicBondForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicBondForce
&
force
);
private:
class
ForceInfo
;
int
numBonds
;
...
...
@@ -274,6 +281,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomBondForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomBondForce
&
force
);
private:
class
ForceInfo
;
void
updateGlobalParams
(
ContextImpl
&
context
);
...
...
@@ -308,6 +322,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the HarmonicAngleForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicAngleForce
&
force
);
private:
class
ForceInfo
;
int
numAngles
;
...
...
@@ -340,6 +361,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomAngleForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomAngleForce
&
force
);
private:
class
ForceInfo
;
void
updateGlobalParams
(
ContextImpl
&
context
);
...
...
@@ -374,6 +402,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the PeriodicTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
PeriodicTorsionForce
&
force
);
private:
class
ForceInfo
;
int
numTorsions
;
...
...
@@ -405,6 +440,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the RBTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
RBTorsionForce
&
force
);
private:
class
ForceInfo
;
int
numTorsions
;
...
...
@@ -474,6 +516,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomTorsionForce
&
force
);
private:
class
ForceInfo
;
void
updateGlobalParams
(
ContextImpl
&
context
);
...
...
platforms/opencl/src/OpenCLKernels.cpp
View file @
4bc723ab
...
...
@@ -351,6 +351,29 @@ double OpenCLCalcHarmonicBondForceKernel::execute(ContextImpl& context, bool inc
return
0.0
;
}
void
OpenCLCalcHarmonicBondForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicBondForce
&
force
)
{
int
numContexts
=
cl
.
getPlatformData
().
contexts
.
size
();
int
startIndex
=
cl
.
getContextIndex
()
*
force
.
getNumBonds
()
/
numContexts
;
int
endIndex
=
(
cl
.
getContextIndex
()
+
1
)
*
force
.
getNumBonds
()
/
numContexts
;
if
(
numBonds
!=
endIndex
-
startIndex
)
throw
OpenMMException
(
"updateParametersInContext: The number of bonds has changed"
);
// Record the per-bond parameters.
vector
<
mm_float2
>
paramVector
(
numBonds
);
for
(
int
i
=
0
;
i
<
numBonds
;
i
++
)
{
int
atom1
,
atom2
;
double
length
,
k
;
force
.
getBondParameters
(
startIndex
+
i
,
atom1
,
atom2
,
length
,
k
);
paramVector
[
i
]
=
mm_float2
((
cl_float
)
length
,
(
cl_float
)
k
);
}
params
->
upload
(
paramVector
);
// Mark that the current reordering may be invalid.
cl
.
invalidateMolecules
();
}
class
OpenCLCustomBondForceInfo
:
public
OpenCLForceInfo
{
public:
OpenCLCustomBondForceInfo
(
const
CustomBondForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
...
...
@@ -467,6 +490,31 @@ double OpenCLCalcCustomBondForceKernel::execute(ContextImpl& context, bool inclu
return
0.0
;
}
void
OpenCLCalcCustomBondForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomBondForce
&
force
)
{
int
numContexts
=
cl
.
getPlatformData
().
contexts
.
size
();
int
startIndex
=
cl
.
getContextIndex
()
*
force
.
getNumBonds
()
/
numContexts
;
int
endIndex
=
(
cl
.
getContextIndex
()
+
1
)
*
force
.
getNumBonds
()
/
numContexts
;
if
(
numBonds
!=
endIndex
-
startIndex
)
throw
OpenMMException
(
"updateParametersInContext: The number of bonds has changed"
);
// Record the per-bond parameters.
vector
<
vector
<
cl_float
>
>
paramVector
(
numBonds
);
vector
<
double
>
parameters
;
for
(
int
i
=
0
;
i
<
numBonds
;
i
++
)
{
int
atom1
,
atom2
;
force
.
getBondParameters
(
startIndex
+
i
,
atom1
,
atom2
,
parameters
);
paramVector
[
i
].
resize
(
parameters
.
size
());
for
(
int
j
=
0
;
j
<
(
int
)
parameters
.
size
();
j
++
)
paramVector
[
i
][
j
]
=
(
cl_float
)
parameters
[
j
];
}
params
->
setParameterValues
(
paramVector
);
// Mark that the current reordering may be invalid.
cl
.
invalidateMolecules
();
}
class
OpenCLHarmonicAngleForceInfo
:
public
OpenCLForceInfo
{
public:
OpenCLHarmonicAngleForceInfo
(
const
HarmonicAngleForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
...
...
@@ -527,6 +575,29 @@ double OpenCLCalcHarmonicAngleForceKernel::execute(ContextImpl& context, bool in
return
0.0
;
}
void
OpenCLCalcHarmonicAngleForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicAngleForce
&
force
)
{
int
numContexts
=
cl
.
getPlatformData
().
contexts
.
size
();
int
startIndex
=
cl
.
getContextIndex
()
*
force
.
getNumAngles
()
/
numContexts
;
int
endIndex
=
(
cl
.
getContextIndex
()
+
1
)
*
force
.
getNumAngles
()
/
numContexts
;
if
(
numAngles
!=
endIndex
-
startIndex
)
throw
OpenMMException
(
"updateParametersInContext: The number of angles has changed"
);
// Record the per-angle parameters.
vector
<
mm_float2
>
paramVector
(
numAngles
);
for
(
int
i
=
0
;
i
<
numAngles
;
i
++
)
{
int
atom1
,
atom2
,
atom3
;
double
angle
,
k
;
force
.
getAngleParameters
(
startIndex
+
i
,
atom1
,
atom2
,
atom3
,
angle
,
k
);
paramVector
[
i
]
=
mm_float2
((
cl_float
)
angle
,
(
cl_float
)
k
);
}
params
->
upload
(
paramVector
);
// Mark that the current reordering may be invalid.
cl
.
invalidateMolecules
();
}
class
OpenCLCustomAngleForceInfo
:
public
OpenCLForceInfo
{
public:
OpenCLCustomAngleForceInfo
(
const
CustomAngleForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
...
...
@@ -644,6 +715,31 @@ double OpenCLCalcCustomAngleForceKernel::execute(ContextImpl& context, bool incl
return
0.0
;
}
void
OpenCLCalcCustomAngleForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomAngleForce
&
force
)
{
int
numContexts
=
cl
.
getPlatformData
().
contexts
.
size
();
int
startIndex
=
cl
.
getContextIndex
()
*
force
.
getNumAngles
()
/
numContexts
;
int
endIndex
=
(
cl
.
getContextIndex
()
+
1
)
*
force
.
getNumAngles
()
/
numContexts
;
if
(
numAngles
!=
endIndex
-
startIndex
)
throw
OpenMMException
(
"updateParametersInContext: The number of angles has changed"
);
// Record the per-angle parameters.
vector
<
vector
<
cl_float
>
>
paramVector
(
numAngles
);
vector
<
double
>
parameters
;
for
(
int
i
=
0
;
i
<
numAngles
;
i
++
)
{
int
atom1
,
atom2
,
atom3
;
force
.
getAngleParameters
(
startIndex
+
i
,
atom1
,
atom2
,
atom3
,
parameters
);
paramVector
[
i
].
resize
(
parameters
.
size
());
for
(
int
j
=
0
;
j
<
(
int
)
parameters
.
size
();
j
++
)
paramVector
[
i
][
j
]
=
(
cl_float
)
parameters
[
j
];
}
params
->
setParameterValues
(
paramVector
);
// Mark that the current reordering may be invalid.
cl
.
invalidateMolecules
();
}
class
OpenCLPeriodicTorsionForceInfo
:
public
OpenCLForceInfo
{
public:
OpenCLPeriodicTorsionForceInfo
(
const
PeriodicTorsionForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
...
...
@@ -692,7 +788,6 @@ void OpenCLCalcPeriodicTorsionForceKernel::initialize(const System& system, cons
double
phase
,
k
;
force
.
getTorsionParameters
(
startIndex
+
i
,
atoms
[
i
][
0
],
atoms
[
i
][
1
],
atoms
[
i
][
2
],
atoms
[
i
][
3
],
periodicity
,
phase
,
k
);
paramVector
[
i
]
=
mm_float4
((
cl_float
)
k
,
(
cl_float
)
phase
,
(
cl_float
)
periodicity
,
0.0
f
);
}
params
->
upload
(
paramVector
);
map
<
string
,
string
>
replacements
;
...
...
@@ -706,6 +801,29 @@ double OpenCLCalcPeriodicTorsionForceKernel::execute(ContextImpl& context, bool
return
0.0
;
}
void
OpenCLCalcPeriodicTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
PeriodicTorsionForce
&
force
)
{
int
numContexts
=
cl
.
getPlatformData
().
contexts
.
size
();
int
startIndex
=
cl
.
getContextIndex
()
*
force
.
getNumTorsions
()
/
numContexts
;
int
endIndex
=
(
cl
.
getContextIndex
()
+
1
)
*
force
.
getNumTorsions
()
/
numContexts
;
if
(
numTorsions
!=
endIndex
-
startIndex
)
throw
OpenMMException
(
"updateParametersInContext: The number of torsions has changed"
);
// Record the per-torsion parameters.
vector
<
mm_float4
>
paramVector
(
numTorsions
);
for
(
int
i
=
0
;
i
<
numTorsions
;
i
++
)
{
int
atom1
,
atom2
,
atom3
,
atom4
,
periodicity
;
double
phase
,
k
;
force
.
getTorsionParameters
(
startIndex
+
i
,
atom1
,
atom2
,
atom3
,
atom4
,
periodicity
,
phase
,
k
);
paramVector
[
i
]
=
mm_float4
((
cl_float
)
k
,
(
cl_float
)
phase
,
(
cl_float
)
periodicity
,
0.0
f
);
}
params
->
upload
(
paramVector
);
// Mark that the current reordering may be invalid.
cl
.
invalidateMolecules
();
}
class
OpenCLRBTorsionForceInfo
:
public
OpenCLForceInfo
{
public:
OpenCLRBTorsionForceInfo
(
const
RBTorsionForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
...
...
@@ -767,6 +885,29 @@ double OpenCLCalcRBTorsionForceKernel::execute(ContextImpl& context, bool includ
return
0.0
;
}
void
OpenCLCalcRBTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
RBTorsionForce
&
force
)
{
int
numContexts
=
cl
.
getPlatformData
().
contexts
.
size
();
int
startIndex
=
cl
.
getContextIndex
()
*
force
.
getNumTorsions
()
/
numContexts
;
int
endIndex
=
(
cl
.
getContextIndex
()
+
1
)
*
force
.
getNumTorsions
()
/
numContexts
;
if
(
numTorsions
!=
endIndex
-
startIndex
)
throw
OpenMMException
(
"updateParametersInContext: The number of torsions has changed"
);
// Record the per-torsion parameters.
vector
<
mm_float8
>
paramVector
(
numTorsions
);
for
(
int
i
=
0
;
i
<
numTorsions
;
i
++
)
{
int
atom1
,
atom2
,
atom3
,
atom4
;
double
c0
,
c1
,
c2
,
c3
,
c4
,
c5
;
force
.
getTorsionParameters
(
startIndex
+
i
,
atom1
,
atom2
,
atom3
,
atom4
,
c0
,
c1
,
c2
,
c3
,
c4
,
c5
);
paramVector
[
i
]
=
mm_float8
((
cl_float
)
c0
,
(
cl_float
)
c1
,
(
cl_float
)
c2
,
(
cl_float
)
c3
,
(
cl_float
)
c4
,
(
cl_float
)
c5
,
0.0
f
,
0.0
f
);
}
params
->
upload
(
paramVector
);
// Mark that the current reordering may be invalid.
cl
.
invalidateMolecules
();
}
class
OpenCLCMAPTorsionForceInfo
:
public
OpenCLForceInfo
{
public:
OpenCLCMAPTorsionForceInfo
(
const
CMAPTorsionForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
...
...
@@ -972,6 +1113,31 @@ double OpenCLCalcCustomTorsionForceKernel::execute(ContextImpl& context, bool in
return
0.0
;
}
void
OpenCLCalcCustomTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomTorsionForce
&
force
)
{
int
numContexts
=
cl
.
getPlatformData
().
contexts
.
size
();
int
startIndex
=
cl
.
getContextIndex
()
*
force
.
getNumTorsions
()
/
numContexts
;
int
endIndex
=
(
cl
.
getContextIndex
()
+
1
)
*
force
.
getNumTorsions
()
/
numContexts
;
if
(
numTorsions
!=
endIndex
-
startIndex
)
throw
OpenMMException
(
"updateParametersInContext: The number of torsions has changed"
);
// Record the per-torsion parameters.
vector
<
vector
<
cl_float
>
>
paramVector
(
numTorsions
);
vector
<
double
>
parameters
;
for
(
int
i
=
0
;
i
<
numTorsions
;
i
++
)
{
int
atom1
,
atom2
,
atom3
,
atom4
;
force
.
getTorsionParameters
(
startIndex
+
i
,
atom1
,
atom2
,
atom3
,
atom4
,
parameters
);
paramVector
[
i
].
resize
(
parameters
.
size
());
for
(
int
j
=
0
;
j
<
(
int
)
parameters
.
size
();
j
++
)
paramVector
[
i
][
j
]
=
(
cl_float
)
parameters
[
j
];
}
params
->
setParameterValues
(
paramVector
);
// Mark that the current reordering may be invalid.
cl
.
invalidateMolecules
();
}
class
OpenCLNonbondedForceInfo
:
public
OpenCLForceInfo
{
public:
OpenCLNonbondedForceInfo
(
int
requiredBuffers
,
const
NonbondedForce
&
force
)
:
OpenCLForceInfo
(
requiredBuffers
),
force
(
force
)
{
...
...
platforms/opencl/src/OpenCLKernels.h
View file @
4bc723ab
...
...
@@ -243,6 +243,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the HarmonicBondForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicBondForce
&
force
);
private:
int
numBonds
;
bool
hasInitializedKernel
;
...
...
@@ -276,6 +283,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomBondForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomBondForce
&
force
);
private:
int
numBonds
;
bool
hasInitializedKernel
;
...
...
@@ -312,6 +326,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the HarmonicAngleForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicAngleForce
&
force
);
private:
int
numAngles
;
bool
hasInitializedKernel
;
...
...
@@ -345,6 +366,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomAngleForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomAngleForce
&
force
);
private:
int
numAngles
;
bool
hasInitializedKernel
;
...
...
@@ -381,6 +409,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the PeriodicTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
PeriodicTorsionForce
&
force
);
private:
int
numTorsions
;
bool
hasInitializedKernel
;
...
...
@@ -414,6 +449,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the RBTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
RBTorsionForce
&
force
);
private:
int
numTorsions
;
bool
hasInitializedKernel
;
...
...
@@ -482,6 +524,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomTorsionForce
&
force
);
private:
int
numTorsions
;
bool
hasInitializedKernel
;
...
...
platforms/opencl/src/OpenCLParallelKernels.cpp
View file @
4bc723ab
...
...
@@ -234,6 +234,11 @@ double OpenCLParallelCalcHarmonicBondForceKernel::execute(ContextImpl& context,
return
0.0
;
}
void
OpenCLParallelCalcHarmonicBondForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicBondForce
&
force
)
{
for
(
int
i
=
0
;
i
<
(
int
)
kernels
.
size
();
i
++
)
getKernel
(
i
).
copyParametersToContext
(
context
,
force
);
}
class
OpenCLParallelCalcCustomBondForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
public:
Task
(
ContextImpl
&
context
,
OpenCLCalcCustomBondForceKernel
&
kernel
,
bool
includeForce
,
...
...
@@ -270,6 +275,11 @@ double OpenCLParallelCalcCustomBondForceKernel::execute(ContextImpl& context, bo
return
0.0
;
}
void
OpenCLParallelCalcCustomBondForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomBondForce
&
force
)
{
for
(
int
i
=
0
;
i
<
(
int
)
kernels
.
size
();
i
++
)
getKernel
(
i
).
copyParametersToContext
(
context
,
force
);
}
class
OpenCLParallelCalcHarmonicAngleForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
public:
Task
(
ContextImpl
&
context
,
OpenCLCalcHarmonicAngleForceKernel
&
kernel
,
bool
includeForce
,
...
...
@@ -306,6 +316,11 @@ double OpenCLParallelCalcHarmonicAngleForceKernel::execute(ContextImpl& context,
return
0.0
;
}
void
OpenCLParallelCalcHarmonicAngleForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicAngleForce
&
force
)
{
for
(
int
i
=
0
;
i
<
(
int
)
kernels
.
size
();
i
++
)
getKernel
(
i
).
copyParametersToContext
(
context
,
force
);
}
class
OpenCLParallelCalcCustomAngleForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
public:
Task
(
ContextImpl
&
context
,
OpenCLCalcCustomAngleForceKernel
&
kernel
,
bool
includeForce
,
...
...
@@ -342,6 +357,11 @@ double OpenCLParallelCalcCustomAngleForceKernel::execute(ContextImpl& context, b
return
0.0
;
}
void
OpenCLParallelCalcCustomAngleForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomAngleForce
&
force
)
{
for
(
int
i
=
0
;
i
<
(
int
)
kernels
.
size
();
i
++
)
getKernel
(
i
).
copyParametersToContext
(
context
,
force
);
}
class
OpenCLParallelCalcPeriodicTorsionForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
public:
Task
(
ContextImpl
&
context
,
OpenCLCalcPeriodicTorsionForceKernel
&
kernel
,
bool
includeForce
,
...
...
@@ -378,6 +398,11 @@ double OpenCLParallelCalcPeriodicTorsionForceKernel::execute(ContextImpl& contex
return
0.0
;
}
void
OpenCLParallelCalcPeriodicTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
PeriodicTorsionForce
&
force
)
{
for
(
int
i
=
0
;
i
<
(
int
)
kernels
.
size
();
i
++
)
getKernel
(
i
).
copyParametersToContext
(
context
,
force
);
}
class
OpenCLParallelCalcRBTorsionForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
public:
Task
(
ContextImpl
&
context
,
OpenCLCalcRBTorsionForceKernel
&
kernel
,
bool
includeForce
,
...
...
@@ -414,6 +439,11 @@ double OpenCLParallelCalcRBTorsionForceKernel::execute(ContextImpl& context, boo
return
0.0
;
}
void
OpenCLParallelCalcRBTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
RBTorsionForce
&
force
)
{
for
(
int
i
=
0
;
i
<
(
int
)
kernels
.
size
();
i
++
)
getKernel
(
i
).
copyParametersToContext
(
context
,
force
);
}
class
OpenCLParallelCalcCMAPTorsionForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
public:
Task
(
ContextImpl
&
context
,
OpenCLCalcCMAPTorsionForceKernel
&
kernel
,
bool
includeForce
,
...
...
@@ -486,6 +516,11 @@ double OpenCLParallelCalcCustomTorsionForceKernel::execute(ContextImpl& context,
return
0.0
;
}
void
OpenCLParallelCalcCustomTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomTorsionForce
&
force
)
{
for
(
int
i
=
0
;
i
<
(
int
)
kernels
.
size
();
i
++
)
getKernel
(
i
).
copyParametersToContext
(
context
,
force
);
}
class
OpenCLParallelCalcNonbondedForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
public:
Task
(
ContextImpl
&
context
,
OpenCLCalcNonbondedForceKernel
&
kernel
,
bool
includeForce
,
...
...
platforms/opencl/src/OpenCLParallelKernels.h
View file @
4bc723ab
...
...
@@ -113,6 +113,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the HarmonicBondForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicBondForce
&
force
);
private:
class
Task
;
OpenCLPlatform
::
PlatformData
&
data
;
...
...
@@ -144,6 +151,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomBondForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomBondForce
&
force
);
private:
class
Task
;
OpenCLPlatform
::
PlatformData
&
data
;
...
...
@@ -175,6 +189,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the HarmonicAngleForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicAngleForce
&
force
);
private:
class
Task
;
OpenCLPlatform
::
PlatformData
&
data
;
...
...
@@ -206,6 +227,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomAngleForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomAngleForce
&
force
);
private:
class
Task
;
OpenCLPlatform
::
PlatformData
&
data
;
...
...
@@ -238,6 +266,13 @@ public:
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
class
Task
;
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the PeriodicTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
PeriodicTorsionForce
&
force
);
private:
OpenCLPlatform
::
PlatformData
&
data
;
std
::
vector
<
Kernel
>
kernels
;
...
...
@@ -268,6 +303,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the RBTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
RBTorsionForce
&
force
);
private:
class
Task
;
OpenCLPlatform
::
PlatformData
&
data
;
...
...
@@ -330,6 +372,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomTorsionForce
&
force
);
private:
class
Task
;
OpenCLPlatform
::
PlatformData
&
data
;
...
...
platforms/opencl/tests/TestOpenCLCustomAngleForce.cpp
View file @
4bc723ab
...
...
@@ -90,11 +90,36 @@ void testAngles() {
init_gen_rand
(
0
,
sfmt
);
vector
<
Vec3
>
positions
(
4
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
VerletIntegrator
integrator1
(
0.01
);
VerletIntegrator
integrator2
(
0.01
);
Context
c1
(
customSystem
,
integrator1
,
platform
);
Context
c2
(
harmonicSystem
,
integrator2
,
platform
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
for
(
int
j
=
0
;
j
<
(
int
)
positions
.
size
();
j
++
)
positions
[
j
]
=
Vec3
(
5.0
*
genrand_real2
(
sfmt
),
5.0
*
genrand_real2
(
sfmt
),
5.0
*
genrand_real2
(
sfmt
));
c1
.
setPositions
(
positions
);
c2
.
setPositions
(
positions
);
State
s1
=
c1
.
getState
(
State
::
Forces
|
State
::
Energy
);
State
s2
=
c2
.
getState
(
State
::
Forces
|
State
::
Energy
);
const
vector
<
Vec3
>&
forces
=
s1
.
getForces
();
for
(
int
i
=
0
;
i
<
customSystem
.
getNumParticles
();
i
++
)
ASSERT_EQUAL_VEC
(
s1
.
getForces
()[
i
],
s2
.
getForces
()[
i
],
TOL
);
ASSERT_EQUAL_TOL
(
s1
.
getPotentialEnergy
(),
s2
.
getPotentialEnergy
(),
TOL
);
}
// Try changing the angle parameters and make sure it's still correct.
parameters
[
0
]
=
1.6
;
parameters
[
1
]
=
0.9
;
custom
->
setAngleParameters
(
0
,
0
,
1
,
2
,
parameters
);
parameters
[
0
]
=
2.1
;
parameters
[
1
]
=
0.6
;
custom
->
setAngleParameters
(
1
,
1
,
2
,
3
,
parameters
);
custom
->
updateParametersInContext
(
c1
);
harmonic
->
setAngleParameters
(
0
,
0
,
1
,
2
,
1.6
,
0.9
);
harmonic
->
setAngleParameters
(
1
,
1
,
2
,
3
,
2.1
,
0.6
);
harmonic
->
updateParametersInContext
(
c2
);
{
for
(
int
j
=
0
;
j
<
(
int
)
positions
.
size
();
j
++
)
positions
[
j
]
=
Vec3
(
5.0
*
genrand_real2
(
sfmt
),
5.0
*
genrand_real2
(
sfmt
),
5.0
*
genrand_real2
(
sfmt
));
c1
.
setPositions
(
positions
);
...
...
platforms/opencl/tests/TestOpenCLCustomBondForce.cpp
View file @
4bc723ab
...
...
@@ -74,11 +74,31 @@ void testBonds() {
positions
[
2
]
=
Vec3
(
1
,
0
,
0
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
{
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
-
0.8
*
0.5
,
0
),
forces
[
0
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.7
*
0.2
,
0
,
0
),
forces
[
2
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
forces
[
0
][
0
]
-
forces
[
2
][
0
],
-
forces
[
0
][
1
]
-
forces
[
2
][
1
],
-
forces
[
0
][
2
]
-
forces
[
2
][
2
]),
forces
[
1
],
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
0.8
*
0.5
*
0.5
+
0.5
*
0.7
*
0.2
*
0.2
,
state
.
getPotentialEnergy
(),
TOL
);
}
// Try changing the bond parameters and make sure it's still correct.
parameters
[
0
]
=
1.6
;
parameters
[
1
]
=
0.9
;
forceField
->
setBondParameters
(
0
,
0
,
1
,
parameters
);
parameters
[
0
]
=
1.3
;
parameters
[
1
]
=
0.8
;
forceField
->
setBondParameters
(
1
,
1
,
2
,
parameters
);
forceField
->
updateParametersInContext
(
context
);
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
{
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
-
0.9
*
0.4
,
0
),
forces
[
0
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.8
*
0.3
,
0
,
0
),
forces
[
2
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
forces
[
0
][
0
]
-
forces
[
2
][
0
],
-
forces
[
0
][
1
]
-
forces
[
2
][
1
],
-
forces
[
0
][
2
]
-
forces
[
2
][
2
]),
forces
[
1
],
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
0.9
*
0.4
*
0.4
+
0.5
*
0.8
*
0.3
*
0.3
,
state
.
getPotentialEnergy
(),
TOL
);
}
}
void
testManyParameters
()
{
...
...
platforms/opencl/tests/TestOpenCLCustomTorsionForce.cpp
View file @
4bc723ab
...
...
@@ -111,6 +111,31 @@ void testTorsions() {
ASSERT_EQUAL_VEC
(
s1
.
getForces
()[
i
],
s2
.
getForces
()[
i
],
TOL
);
ASSERT_EQUAL_TOL
(
s1
.
getPotentialEnergy
(),
s2
.
getPotentialEnergy
(),
TOL
);
}
// Try changing the torsion parameters and make sure it's still correct.
parameters
[
0
]
=
1.6
;
parameters
[
1
]
=
2
;
custom
->
setTorsionParameters
(
0
,
0
,
1
,
2
,
3
,
parameters
);
parameters
[
0
]
=
2.1
;
parameters
[
1
]
=
3
;
custom
->
setTorsionParameters
(
1
,
1
,
2
,
3
,
4
,
parameters
);
custom
->
updateParametersInContext
(
c1
);
periodic
->
setTorsionParameters
(
0
,
0
,
1
,
2
,
3
,
2
,
1.6
,
0.5
);
periodic
->
setTorsionParameters
(
1
,
1
,
2
,
3
,
4
,
3
,
2.1
,
0.5
);
periodic
->
updateParametersInContext
(
c2
);
{
for
(
int
j
=
0
;
j
<
(
int
)
positions
.
size
();
j
++
)
positions
[
j
]
=
Vec3
(
5.0
*
genrand_real2
(
sfmt
),
5.0
*
genrand_real2
(
sfmt
),
5.0
*
genrand_real2
(
sfmt
));
c1
.
setPositions
(
positions
);
c2
.
setPositions
(
positions
);
State
s1
=
c1
.
getState
(
State
::
Forces
|
State
::
Energy
);
State
s2
=
c2
.
getState
(
State
::
Forces
|
State
::
Energy
);
const
vector
<
Vec3
>&
forces
=
s1
.
getForces
();
for
(
int
i
=
0
;
i
<
customSystem
.
getNumParticles
();
i
++
)
ASSERT_EQUAL_VEC
(
s1
.
getForces
()[
i
],
s2
.
getForces
()[
i
],
TOL
);
ASSERT_EQUAL_TOL
(
s1
.
getPotentialEnergy
(),
s2
.
getPotentialEnergy
(),
TOL
);
}
}
void
testRange
()
{
...
...
platforms/opencl/tests/TestOpenCLHarmonicAngleForce.cpp
View file @
4bc723ab
...
...
@@ -69,6 +69,7 @@ void testAngles() {
positions
[
3
]
=
Vec3
(
2
,
1
,
0
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
{
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
double
torque1
=
1.1
*
PI_M
/
6
;
double
torque2
=
1.2
*
PI_M
/
4
;
...
...
@@ -76,6 +77,25 @@ void testAngles() {
ASSERT_EQUAL_VEC
(
Vec3
(
-
0.5
*
torque2
,
0.5
*
torque2
,
0
),
forces
[
3
],
TOL
);
// reduced by sqrt(2) due to the bond length, another sqrt(2) due to the angle
ASSERT_EQUAL_VEC
(
Vec3
(
forces
[
0
][
0
]
+
forces
[
1
][
0
]
+
forces
[
2
][
0
]
+
forces
[
3
][
0
],
forces
[
0
][
1
]
+
forces
[
1
][
1
]
+
forces
[
2
][
1
]
+
forces
[
3
][
1
],
forces
[
0
][
2
]
+
forces
[
1
][
2
]
+
forces
[
2
][
2
]
+
forces
[
3
][
2
]),
Vec3
(
0
,
0
,
0
),
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
1.1
*
(
PI_M
/
6
)
*
(
PI_M
/
6
)
+
0.5
*
1.2
*
(
PI_M
/
4
)
*
(
PI_M
/
4
),
state
.
getPotentialEnergy
(),
TOL
);
}
// Try changing the angle parameters and make sure it's still correct.
forceField
->
setAngleParameters
(
0
,
0
,
1
,
2
,
PI_M
/
3.1
,
1.3
);
forceField
->
setAngleParameters
(
1
,
1
,
2
,
3
,
PI_M
/
2.1
,
1.4
);
forceField
->
updateParametersInContext
(
context
);
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
{
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
double
dtheta1
=
(
PI_M
/
2
)
-
(
PI_M
/
3.1
);
double
dtheta2
=
(
3
*
PI_M
/
4
)
-
(
PI_M
/
2.1
);
double
torque1
=
1.3
*
dtheta1
;
double
torque2
=
1.4
*
dtheta2
;
ASSERT_EQUAL_VEC
(
Vec3
(
torque1
,
0
,
0
),
forces
[
0
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
0.5
*
torque2
,
0.5
*
torque2
,
0
),
forces
[
3
],
TOL
);
// reduced by sqrt(2) due to the bond length, another sqrt(2) due to the angle
ASSERT_EQUAL_VEC
(
Vec3
(
forces
[
0
][
0
]
+
forces
[
1
][
0
]
+
forces
[
2
][
0
]
+
forces
[
3
][
0
],
forces
[
0
][
1
]
+
forces
[
1
][
1
]
+
forces
[
2
][
1
]
+
forces
[
3
][
1
],
forces
[
0
][
2
]
+
forces
[
1
][
2
]
+
forces
[
2
][
2
]
+
forces
[
3
][
2
]),
Vec3
(
0
,
0
,
0
),
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
1.3
*
dtheta1
*
dtheta1
+
0.5
*
1.4
*
dtheta2
*
dtheta2
,
state
.
getPotentialEnergy
(),
TOL
);
}
}
void
testParallelComputation
()
{
...
...
platforms/opencl/tests/TestOpenCLHarmonicBondForce.cpp
View file @
4bc723ab
...
...
@@ -66,11 +66,27 @@ void testBonds() {
positions
[
2
]
=
Vec3
(
1
,
0
,
0
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
{
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
-
0.8
*
0.5
,
0
),
forces
[
0
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.7
*
0.2
,
0
,
0
),
forces
[
2
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
forces
[
0
][
0
]
-
forces
[
2
][
0
],
-
forces
[
0
][
1
]
-
forces
[
2
][
1
],
-
forces
[
0
][
2
]
-
forces
[
2
][
2
]),
forces
[
1
],
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
0.8
*
0.5
*
0.5
+
0.5
*
0.7
*
0.2
*
0.2
,
state
.
getPotentialEnergy
(),
TOL
);
}
// Try changing the bond parameters and make sure it's still correct.
forceField
->
setBondParameters
(
0
,
0
,
1
,
1.6
,
0.9
);
forceField
->
setBondParameters
(
1
,
1
,
2
,
1.3
,
0.8
);
forceField
->
updateParametersInContext
(
context
);
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
{
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
-
0.9
*
0.4
,
0
),
forces
[
0
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.8
*
0.3
,
0
,
0
),
forces
[
2
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
forces
[
0
][
0
]
-
forces
[
2
][
0
],
-
forces
[
0
][
1
]
-
forces
[
2
][
1
],
-
forces
[
0
][
2
]
-
forces
[
2
][
2
]),
forces
[
1
],
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
0.9
*
0.4
*
0.4
+
0.5
*
0.8
*
0.3
*
0.3
,
state
.
getPotentialEnergy
(),
TOL
);
}
}
void
testParallelComputation
()
{
...
...
Prev
1
2
3
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