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
15ffd4af
Commit
15ffd4af
authored
Sep 20, 2011
by
Peter Eastman
Browse files
Fixed RPMD test cases
parent
84f5e008
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
71 deletions
+53
-71
plugins/rpmd/platforms/opencl/tests/TestOpenCLRpmd.cpp
plugins/rpmd/platforms/opencl/tests/TestOpenCLRpmd.cpp
+26
-36
plugins/rpmd/platforms/reference/tests/TestReferenceRpmd.cpp
plugins/rpmd/platforms/reference/tests/TestReferenceRpmd.cpp
+27
-35
No files found.
plugins/rpmd/platforms/opencl/tests/TestOpenCLRpmd.cpp
View file @
15ffd4af
...
@@ -47,20 +47,15 @@
...
@@ -47,20 +47,15 @@
using
namespace
OpenMM
;
using
namespace
OpenMM
;
using
namespace
std
;
using
namespace
std
;
void
test
Integration
()
{
void
test
FreeParticles
()
{
const
int
numParticles
=
1
;
const
int
numParticles
=
1
00
;
const
int
numCopies
=
25
;
const
int
numCopies
=
30
;
const
double
temperature
=
300.0
;
const
double
temperature
=
300.0
;
const
double
mass
=
1.0
;
System
system
;
System
system
;
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
system
.
addParticle
(
i
+
1
);
system
.
addParticle
(
mass
);
if
(
numParticles
>
1
)
{
RPMDIntegrator
integ
(
numCopies
,
temperature
,
10.0
,
0.001
);
HarmonicBondForce
*
bonds
=
new
HarmonicBondForce
();
system
.
addForce
(
bonds
);
for
(
int
i
=
0
;
i
<
numParticles
-
1
;
i
++
)
bonds
->
addBond
(
i
,
i
+
1
,
1.0
,
100.0
);
}
RPMDIntegrator
integ
(
numCopies
,
temperature
,
1.0
,
0.001
);
Platform
&
platform
=
Platform
::
getPlatformByName
(
"OpenCL"
);
Platform
&
platform
=
Platform
::
getPlatformByName
(
"OpenCL"
);
Context
context
(
system
,
integ
,
platform
);
Context
context
(
system
,
integ
,
platform
);
OpenMM_SFMT
::
SFMT
sfmt
;
OpenMM_SFMT
::
SFMT
sfmt
;
...
@@ -69,7 +64,7 @@ void testIntegration() {
...
@@ -69,7 +64,7 @@ void testIntegration() {
for
(
int
i
=
0
;
i
<
numCopies
;
i
++
)
for
(
int
i
=
0
;
i
<
numCopies
;
i
++
)
{
{
for
(
int
j
=
0
;
j
<
numParticles
;
j
++
)
for
(
int
j
=
0
;
j
<
numParticles
;
j
++
)
positions
[
j
]
=
Vec3
(
j
+
0.0
1
*
genrand_real2
(
sfmt
),
0.0
1
*
genrand_real2
(
sfmt
),
0.0
1
*
genrand_real2
(
sfmt
));
positions
[
j
]
=
Vec3
(
0.0
2
*
genrand_real2
(
sfmt
),
0.0
2
*
genrand_real2
(
sfmt
),
0.0
2
*
genrand_real2
(
sfmt
));
integ
.
setPositions
(
i
,
positions
);
integ
.
setPositions
(
i
,
positions
);
}
}
const
int
numSteps
=
1000
;
const
int
numSteps
=
1000
;
...
@@ -82,43 +77,38 @@ void testIntegration() {
...
@@ -82,43 +77,38 @@ void testIntegration() {
integ
.
step
(
1
);
integ
.
step
(
1
);
vector
<
State
>
state
(
numCopies
);
vector
<
State
>
state
(
numCopies
);
for
(
int
j
=
0
;
j
<
numCopies
;
j
++
)
for
(
int
j
=
0
;
j
<
numCopies
;
j
++
)
state
[
j
]
=
integ
.
getState
(
j
,
State
::
Positions
|
State
::
Velocities
|
State
::
Energy
);
state
[
j
]
=
integ
.
getState
(
j
,
State
::
Positions
|
State
::
Velocities
);
for
(
int
j
=
0
;
j
<
numCopies
;
j
++
)
ke
[
j
]
+=
state
[
j
].
getKineticEnergy
();
double
totalEnergy
=
0.0
;
for
(
int
j
=
0
;
j
<
numCopies
;
j
++
)
{
totalEnergy
+=
state
[
j
].
getKineticEnergy
()
+
state
[
j
].
getPotentialEnergy
();
for
(
int
k
=
0
;
k
<
numParticles
;
k
++
)
{
Vec3
delta
=
state
[
j
].
getPositions
()[
k
]
-
state
[
j
==
0
?
numCopies
-
1
:
j
-
1
].
getPositions
()[
k
];
totalEnergy
+=
0.5
*
system
.
getParticleMass
(
k
)
*
wn
*
wn
*
delta
.
dot
(
delta
);
}
}
for
(
int
j
=
0
;
j
<
numParticles
;
j
++
)
{
for
(
int
j
=
0
;
j
<
numParticles
;
j
++
)
{
double
rg2
=
0.0
;
double
rg2
=
0.0
;
for
(
int
k
=
0
;
k
<
numCopies
;
k
++
)
for
(
int
k
=
0
;
k
<
numCopies
;
k
++
)
{
Vec3
v
=
state
[
k
].
getVelocities
()[
j
];
ke
[
k
]
+=
0.5
*
mass
*
v
.
dot
(
v
);
for
(
int
m
=
0
;
m
<
numCopies
;
m
++
)
{
for
(
int
m
=
0
;
m
<
numCopies
;
m
++
)
{
Vec3
delta
=
state
[
k
].
getPositions
()[
j
]
-
state
[
m
].
getPositions
()[
j
];
Vec3
delta
=
state
[
k
].
getPositions
()[
j
]
-
state
[
m
].
getPositions
()[
j
];
rg2
+=
delta
.
dot
(
delta
);
rg2
+=
delta
.
dot
(
delta
);
}
}
rg
[
j
]
+=
sqrt
(
rg2
/
(
2
*
numCopies
*
numCopies
));
}
rg
[
j
]
+=
rg2
/
(
2
*
numCopies
*
numCopies
);
}
}
}
}
for
(
int
i
=
0
;
i
<
numCopies
;
i
++
)
{
double
meanKE
=
0.0
;
double
value
=
ke
[
i
]
/
numSteps
;
for
(
int
i
=
0
;
i
<
numCopies
;
i
++
)
double
expected
=
0.5
*
numCopies
*
numParticles
*
3
*
BOLTZ
*
temperature
;
meanKE
+=
ke
[
i
];
printf
(
"%d: %g %g %g
\n
"
,
i
,
value
,
expected
,
value
/
expected
);
meanKE
/=
numSteps
*
numCopies
;
}
double
expectedKE
=
0.5
*
numCopies
*
numParticles
*
3
*
BOLTZ
*
temperature
;
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
{
ASSERT_USUALLY_EQUAL_TOL
(
expectedKE
,
meanKE
,
1e-2
);
double
value
=
rg
[
i
]
/
numSteps
;
double
meanRg2
=
0.0
;
double
expected
=
hbar
/
(
2
*
sqrt
(
system
.
getParticleMass
(
i
)
*
BOLTZ
*
temperature
));
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
printf
(
"%d: %g %g %g
\n
"
,
i
,
value
,
expected
,
value
/
expected
);
meanRg2
+=
rg
[
i
];
}
meanRg2
/=
numSteps
*
numParticles
;
double
expectedRg
=
hbar
/
(
2
*
sqrt
(
mass
*
BOLTZ
*
temperature
));
ASSERT_USUALLY_EQUAL_TOL
(
expectedRg
,
sqrt
(
meanRg2
),
1e-3
);
}
}
int
main
()
{
int
main
()
{
try
{
try
{
Platform
::
loadPluginsFromDirectory
(
Platform
::
getDefaultPluginsDirectory
());
Platform
::
loadPluginsFromDirectory
(
Platform
::
getDefaultPluginsDirectory
());
test
Integration
();
test
FreeParticles
();
}
}
catch
(
const
std
::
exception
&
e
)
{
catch
(
const
std
::
exception
&
e
)
{
std
::
cout
<<
"exception: "
<<
e
.
what
()
<<
std
::
endl
;
std
::
cout
<<
"exception: "
<<
e
.
what
()
<<
std
::
endl
;
...
...
plugins/rpmd/platforms/reference/tests/TestReferenceRpmd.cpp
View file @
15ffd4af
...
@@ -47,18 +47,15 @@
...
@@ -47,18 +47,15 @@
using
namespace
OpenMM
;
using
namespace
OpenMM
;
using
namespace
std
;
using
namespace
std
;
void
test
Integration
()
{
void
test
FreeParticles
()
{
const
int
numParticles
=
1
;
const
int
numParticles
=
1
00
;
const
int
numCopies
=
30
;
const
int
numCopies
=
30
;
const
double
temperature
=
300.0
;
const
double
temperature
=
300.0
;
const
double
mass
=
1.0
;
System
system
;
System
system
;
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
system
.
addParticle
(
i
+
1
);
system
.
addParticle
(
mass
);
HarmonicBondForce
*
bonds
=
new
HarmonicBondForce
();
RPMDIntegrator
integ
(
numCopies
,
temperature
,
10.0
,
0.001
);
system
.
addForce
(
bonds
);
for
(
int
i
=
0
;
i
<
numParticles
-
1
;
i
++
)
bonds
->
addBond
(
i
,
i
+
1
,
1.0
,
100.0
);
RPMDIntegrator
integ
(
numCopies
,
temperature
,
1.0
,
0.001
);
Platform
&
platform
=
Platform
::
getPlatformByName
(
"Reference"
);
Platform
&
platform
=
Platform
::
getPlatformByName
(
"Reference"
);
Context
context
(
system
,
integ
,
platform
);
Context
context
(
system
,
integ
,
platform
);
OpenMM_SFMT
::
SFMT
sfmt
;
OpenMM_SFMT
::
SFMT
sfmt
;
...
@@ -67,11 +64,11 @@ void testIntegration() {
...
@@ -67,11 +64,11 @@ void testIntegration() {
for
(
int
i
=
0
;
i
<
numCopies
;
i
++
)
for
(
int
i
=
0
;
i
<
numCopies
;
i
++
)
{
{
for
(
int
j
=
0
;
j
<
numParticles
;
j
++
)
for
(
int
j
=
0
;
j
<
numParticles
;
j
++
)
positions
[
j
]
=
Vec3
(
j
+
0.0
1
*
genrand_real2
(
sfmt
),
0.0
1
*
genrand_real2
(
sfmt
),
0.0
1
*
genrand_real2
(
sfmt
));
positions
[
j
]
=
Vec3
(
0.0
2
*
genrand_real2
(
sfmt
),
0.0
2
*
genrand_real2
(
sfmt
),
0.0
2
*
genrand_real2
(
sfmt
));
integ
.
setPositions
(
i
,
positions
);
integ
.
setPositions
(
i
,
positions
);
}
}
const
int
numSteps
=
1000
00
;
const
int
numSteps
=
1000
;
integ
.
step
(
1000
0
);
integ
.
step
(
1000
);
vector
<
double
>
ke
(
numCopies
,
0.0
);
vector
<
double
>
ke
(
numCopies
,
0.0
);
vector
<
double
>
rg
(
numParticles
,
0.0
);
vector
<
double
>
rg
(
numParticles
,
0.0
);
const
RealOpenMM
hbar
=
1.054571628e-34
*
AVOGADRO
/
(
1000
*
1e-12
);
const
RealOpenMM
hbar
=
1.054571628e-34
*
AVOGADRO
/
(
1000
*
1e-12
);
...
@@ -80,43 +77,38 @@ void testIntegration() {
...
@@ -80,43 +77,38 @@ void testIntegration() {
integ
.
step
(
1
);
integ
.
step
(
1
);
vector
<
State
>
state
(
numCopies
);
vector
<
State
>
state
(
numCopies
);
for
(
int
j
=
0
;
j
<
numCopies
;
j
++
)
for
(
int
j
=
0
;
j
<
numCopies
;
j
++
)
state
[
j
]
=
integ
.
getState
(
j
,
State
::
Positions
|
State
::
Velocities
|
State
::
Energy
);
state
[
j
]
=
integ
.
getState
(
j
,
State
::
Positions
|
State
::
Velocities
);
for
(
int
j
=
0
;
j
<
numCopies
;
j
++
)
ke
[
j
]
+=
state
[
j
].
getKineticEnergy
();
double
totalEnergy
=
0.0
;
for
(
int
j
=
0
;
j
<
numCopies
;
j
++
)
{
totalEnergy
+=
state
[
j
].
getKineticEnergy
()
+
state
[
j
].
getPotentialEnergy
();
for
(
int
k
=
0
;
k
<
numParticles
;
k
++
)
{
Vec3
delta
=
state
[
j
].
getPositions
()[
k
]
-
state
[
j
==
0
?
numCopies
-
1
:
j
-
1
].
getPositions
()[
k
];
totalEnergy
+=
0.5
*
system
.
getParticleMass
(
k
)
*
wn
*
wn
*
delta
.
dot
(
delta
);
}
}
for
(
int
j
=
0
;
j
<
numParticles
;
j
++
)
{
for
(
int
j
=
0
;
j
<
numParticles
;
j
++
)
{
double
rg2
=
0.0
;
double
rg2
=
0.0
;
for
(
int
k
=
0
;
k
<
numCopies
;
k
++
)
for
(
int
k
=
0
;
k
<
numCopies
;
k
++
)
{
Vec3
v
=
state
[
k
].
getVelocities
()[
j
];
ke
[
k
]
+=
0.5
*
mass
*
v
.
dot
(
v
);
for
(
int
m
=
0
;
m
<
numCopies
;
m
++
)
{
for
(
int
m
=
0
;
m
<
numCopies
;
m
++
)
{
Vec3
delta
=
state
[
k
].
getPositions
()[
j
]
-
state
[
m
].
getPositions
()[
j
];
Vec3
delta
=
state
[
k
].
getPositions
()[
j
]
-
state
[
m
].
getPositions
()[
j
];
rg2
+=
delta
.
dot
(
delta
);
rg2
+=
delta
.
dot
(
delta
);
}
}
rg
[
j
]
+=
sqrt
(
rg2
/
(
2
*
numCopies
*
numCopies
));
}
rg
[
j
]
+=
rg2
/
(
2
*
numCopies
*
numCopies
);
}
}
}
}
for
(
int
i
=
0
;
i
<
numCopies
;
i
++
)
{
double
meanKE
=
0.0
;
double
value
=
ke
[
i
]
/
numSteps
;
for
(
int
i
=
0
;
i
<
numCopies
;
i
++
)
double
expected
=
0.5
*
numCopies
*
numParticles
*
3
*
BOLTZ
*
temperature
;
meanKE
+=
ke
[
i
];
printf
(
"%d: %g %g %g
\n
"
,
i
,
value
,
expected
,
value
/
expected
);
meanKE
/=
numSteps
*
numCopies
;
}
double
expectedKE
=
0.5
*
numCopies
*
numParticles
*
3
*
BOLTZ
*
temperature
;
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
{
ASSERT_USUALLY_EQUAL_TOL
(
expectedKE
,
meanKE
,
1e-2
);
double
value
=
rg
[
i
]
/
numSteps
;
double
meanRg2
=
0.0
;
double
expected
=
hbar
/
(
2
*
sqrt
(
system
.
getParticleMass
(
i
)
*
BOLTZ
*
temperature
));
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
printf
(
"%d: %g %g %g
\n
"
,
i
,
value
,
expected
,
value
/
expected
);
meanRg2
+=
rg
[
i
];
}
meanRg2
/=
numSteps
*
numParticles
;
double
expectedRg
=
hbar
/
(
2
*
sqrt
(
mass
*
BOLTZ
*
temperature
));
ASSERT_USUALLY_EQUAL_TOL
(
expectedRg
,
sqrt
(
meanRg2
),
1e-3
);
}
}
int
main
()
{
int
main
()
{
try
{
try
{
Platform
::
loadPluginsFromDirectory
(
Platform
::
getDefaultPluginsDirectory
());
Platform
::
loadPluginsFromDirectory
(
Platform
::
getDefaultPluginsDirectory
());
test
Integration
();
test
FreeParticles
();
}
}
catch
(
const
std
::
exception
&
e
)
{
catch
(
const
std
::
exception
&
e
)
{
std
::
cout
<<
"exception: "
<<
e
.
what
()
<<
std
::
endl
;
std
::
cout
<<
"exception: "
<<
e
.
what
()
<<
std
::
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