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
c8fa8828
Commit
c8fa8828
authored
Mar 04, 2014
by
Mike Garrahan
Browse files
added testMultipleBonds
parent
c52a3d25
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
145 additions
and
0 deletions
+145
-0
platforms/cuda/tests/TestCudaCustomCompoundBondForce.cpp
platforms/cuda/tests/TestCudaCustomCompoundBondForce.cpp
+48
-0
platforms/opencl/tests/TestOpenCLCustomCompoundBondForce.cpp
platforms/opencl/tests/TestOpenCLCustomCompoundBondForce.cpp
+48
-0
platforms/reference/tests/TestReferenceCustomCompoundBondForce.cpp
.../reference/tests/TestReferenceCustomCompoundBondForce.cpp
+49
-0
No files found.
platforms/cuda/tests/TestCudaCustomCompoundBondForce.cpp
View file @
c8fa8828
...
@@ -296,6 +296,53 @@ void testContinuous3DFunction() {
...
@@ -296,6 +296,53 @@ void testContinuous3DFunction() {
}
}
}
}
void
testMultipleBonds
()
{
// Two compound bonds using Urey-Bradley example from API doc
System
customSystem
;
customSystem
.
addParticle
(
1.0
);
customSystem
.
addParticle
(
1.0
);
customSystem
.
addParticle
(
1.0
);
customSystem
.
addParticle
(
1.0
);
CustomCompoundBondForce
*
custom
=
new
CustomCompoundBondForce
(
3
,
"0.5*(kangle*(angle(p1,p2,p3)-theta0)^2+kbond*(distance(p1,p3)-r0)^2)"
);
custom
->
addPerBondParameter
(
"kangle"
);
custom
->
addPerBondParameter
(
"kbond"
);
custom
->
addPerBondParameter
(
"theta0"
);
custom
->
addPerBondParameter
(
"r0"
);
vector
<
double
>
parameters
(
4
);
parameters
[
0
]
=
1.0
;
parameters
[
1
]
=
1.0
;
parameters
[
2
]
=
2
*
M_PI
/
3
;
parameters
[
3
]
=
sqrt
(
3
)
/
2
;
vector
<
int
>
particles0
(
3
);
particles0
[
0
]
=
0
;
particles0
[
1
]
=
1
;
particles0
[
2
]
=
2
;
vector
<
int
>
particles1
(
3
);
particles1
[
0
]
=
1
;
particles1
[
1
]
=
2
;
particles1
[
2
]
=
3
;
custom
->
addBond
(
particles0
,
parameters
);
custom
->
addBond
(
particles1
,
parameters
);
customSystem
.
addForce
(
custom
);
vector
<
Vec3
>
positions
(
4
);
positions
[
0
]
=
Vec3
(
0
,
0.5
,
0
);
positions
[
1
]
=
Vec3
(
0
,
0
,
0
);
positions
[
2
]
=
Vec3
(
0.5
,
0
,
0
);
positions
[
3
]
=
Vec3
(
0.6
,
0
,
0.4
);
VerletIntegrator
integrator
(
0.01
);
Context
context
(
customSystem
,
integrator
,
platform
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
ASSERT_EQUAL_TOL
(
0.199
,
state
.
getPotentialEnergy
(),
1e-3
);
vector
<
Vec3
>
forces
(
state
.
getForces
());
ASSERT_EQUAL_VEC
(
Vec3
(
-
1.160
,
0.112
,
0.0
),
forces
[
0
],
1e-3
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.927
,
1.047
,
-
0.638
),
forces
[
1
],
1e-3
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
0.543
,
-
1.160
,
0.721
),
forces
[
2
],
1e-3
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.776
,
0.0
,
-
0.084
),
forces
[
3
],
1e-3
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
try
{
try
{
if
(
argc
>
1
)
if
(
argc
>
1
)
...
@@ -305,6 +352,7 @@ int main(int argc, char* argv[]) {
...
@@ -305,6 +352,7 @@ int main(int argc, char* argv[]) {
testParallelComputation
();
testParallelComputation
();
testContinuous2DFunction
();
testContinuous2DFunction
();
testContinuous3DFunction
();
testContinuous3DFunction
();
testMultipleBonds
();
}
}
catch
(
const
exception
&
e
)
{
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/opencl/tests/TestOpenCLCustomCompoundBondForce.cpp
View file @
c8fa8828
...
@@ -296,6 +296,53 @@ void testContinuous3DFunction() {
...
@@ -296,6 +296,53 @@ void testContinuous3DFunction() {
}
}
}
}
void
testMultipleBonds
()
{
// Two compound bonds using Urey-Bradley example from API doc
System
customSystem
;
customSystem
.
addParticle
(
1.0
);
customSystem
.
addParticle
(
1.0
);
customSystem
.
addParticle
(
1.0
);
customSystem
.
addParticle
(
1.0
);
CustomCompoundBondForce
*
custom
=
new
CustomCompoundBondForce
(
3
,
"0.5*(kangle*(angle(p1,p2,p3)-theta0)^2+kbond*(distance(p1,p3)-r0)^2)"
);
custom
->
addPerBondParameter
(
"kangle"
);
custom
->
addPerBondParameter
(
"kbond"
);
custom
->
addPerBondParameter
(
"theta0"
);
custom
->
addPerBondParameter
(
"r0"
);
vector
<
double
>
parameters
(
4
);
parameters
[
0
]
=
1.0
;
parameters
[
1
]
=
1.0
;
parameters
[
2
]
=
2
*
M_PI
/
3
;
parameters
[
3
]
=
sqrt
(
3
)
/
2
;
vector
<
int
>
particles0
(
3
);
particles0
[
0
]
=
0
;
particles0
[
1
]
=
1
;
particles0
[
2
]
=
2
;
vector
<
int
>
particles1
(
3
);
particles1
[
0
]
=
1
;
particles1
[
1
]
=
2
;
particles1
[
2
]
=
3
;
custom
->
addBond
(
particles0
,
parameters
);
custom
->
addBond
(
particles1
,
parameters
);
customSystem
.
addForce
(
custom
);
vector
<
Vec3
>
positions
(
4
);
positions
[
0
]
=
Vec3
(
0
,
0.5
,
0
);
positions
[
1
]
=
Vec3
(
0
,
0
,
0
);
positions
[
2
]
=
Vec3
(
0.5
,
0
,
0
);
positions
[
3
]
=
Vec3
(
0.6
,
0
,
0.4
);
VerletIntegrator
integrator
(
0.01
);
Context
context
(
customSystem
,
integrator
,
platform
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
ASSERT_EQUAL_TOL
(
0.199
,
state
.
getPotentialEnergy
(),
1e-3
);
vector
<
Vec3
>
forces
(
state
.
getForces
());
ASSERT_EQUAL_VEC
(
Vec3
(
-
1.160
,
0.112
,
0.0
),
forces
[
0
],
1e-3
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.927
,
1.047
,
-
0.638
),
forces
[
1
],
1e-3
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
0.543
,
-
1.160
,
0.721
),
forces
[
2
],
1e-3
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.776
,
0.0
,
-
0.084
),
forces
[
3
],
1e-3
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
try
{
try
{
if
(
argc
>
1
)
if
(
argc
>
1
)
...
@@ -305,6 +352,7 @@ int main(int argc, char* argv[]) {
...
@@ -305,6 +352,7 @@ int main(int argc, char* argv[]) {
testParallelComputation
();
testParallelComputation
();
testContinuous2DFunction
();
testContinuous2DFunction
();
testContinuous3DFunction
();
testContinuous3DFunction
();
testMultipleBonds
();
}
}
catch
(
const
exception
&
e
)
{
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/reference/tests/TestReferenceCustomCompoundBondForce.cpp
View file @
c8fa8828
...
@@ -266,12 +266,61 @@ void testContinuous3DFunction() {
...
@@ -266,12 +266,61 @@ void testContinuous3DFunction() {
}
}
}
}
void
testMultipleBonds
()
{
// Two compound bonds using Urey-Bradley example from API doc
ReferencePlatform
platform
;
System
customSystem
;
customSystem
.
addParticle
(
1.0
);
customSystem
.
addParticle
(
1.0
);
customSystem
.
addParticle
(
1.0
);
customSystem
.
addParticle
(
1.0
);
CustomCompoundBondForce
*
custom
=
new
CustomCompoundBondForce
(
3
,
"0.5*(kangle*(angle(p1,p2,p3)-theta0)^2+kbond*(distance(p1,p3)-r0)^2)"
);
custom
->
addPerBondParameter
(
"kangle"
);
custom
->
addPerBondParameter
(
"kbond"
);
custom
->
addPerBondParameter
(
"theta0"
);
custom
->
addPerBondParameter
(
"r0"
);
vector
<
double
>
parameters
(
4
);
parameters
[
0
]
=
1.0
;
parameters
[
1
]
=
1.0
;
parameters
[
2
]
=
2
*
M_PI
/
3
;
parameters
[
3
]
=
sqrt
(
3
)
/
2
;
vector
<
int
>
particles0
(
3
);
particles0
[
0
]
=
0
;
particles0
[
1
]
=
1
;
particles0
[
2
]
=
2
;
vector
<
int
>
particles1
(
3
);
particles1
[
0
]
=
1
;
particles1
[
1
]
=
2
;
particles1
[
2
]
=
3
;
custom
->
addBond
(
particles0
,
parameters
);
custom
->
addBond
(
particles1
,
parameters
);
customSystem
.
addForce
(
custom
);
vector
<
Vec3
>
positions
(
4
);
positions
[
0
]
=
Vec3
(
0
,
0.5
,
0
);
positions
[
1
]
=
Vec3
(
0
,
0
,
0
);
positions
[
2
]
=
Vec3
(
0.5
,
0
,
0
);
positions
[
3
]
=
Vec3
(
0.6
,
0
,
0.4
);
VerletIntegrator
integrator
(
0.01
);
Context
context
(
customSystem
,
integrator
,
platform
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
ASSERT_EQUAL_TOL
(
0.199
,
state
.
getPotentialEnergy
(),
1e-3
);
vector
<
Vec3
>
forces
(
state
.
getForces
());
ASSERT_EQUAL_VEC
(
Vec3
(
-
1.160
,
0.112
,
0.0
),
forces
[
0
],
1e-3
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.927
,
1.047
,
-
0.638
),
forces
[
1
],
1e-3
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
0.543
,
-
1.160
,
0.721
),
forces
[
2
],
1e-3
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.776
,
0.0
,
-
0.084
),
forces
[
3
],
1e-3
);
}
int
main
()
{
int
main
()
{
try
{
try
{
testBond
();
testBond
();
testPositionDependence
();
testPositionDependence
();
testContinuous2DFunction
();
testContinuous2DFunction
();
testContinuous3DFunction
();
testContinuous3DFunction
();
testMultipleBonds
();
}
}
catch
(
const
exception
&
e
)
{
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
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