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
cc6a0ac8
Commit
cc6a0ac8
authored
Jan 22, 2020
by
Andy Simmonett
Browse files
Fix precision issues in Drude tests
parent
012f6eb4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
7 deletions
+21
-7
plugins/drude/tests/TestDrudeForce.h
plugins/drude/tests/TestDrudeForce.h
+11
-6
plugins/drude/tests/TestDrudeSCFIntegrator.h
plugins/drude/tests/TestDrudeSCFIntegrator.h
+10
-1
No files found.
plugins/drude/tests/TestDrudeForce.h
View file @
cc6a0ac8
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/Context.h"
#include "openmm/NonbondedForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/OpenMMException.h"
#include "openmm/Platform.h"
#include "openmm/Platform.h"
#include "openmm/System.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "openmm/VerletIntegrator.h"
...
@@ -43,8 +44,6 @@
...
@@ -43,8 +44,6 @@
using
namespace
OpenMM
;
using
namespace
OpenMM
;
using
namespace
std
;
using
namespace
std
;
bool
doublePrecision
=
false
;
void
validateForce
(
System
&
system
,
vector
<
Vec3
>&
positions
,
double
expectedEnergy
)
{
void
validateForce
(
System
&
system
,
vector
<
Vec3
>&
positions
,
double
expectedEnergy
)
{
// Given a System containing a Drude force, check that its energy has the expected value.
// Given a System containing a Drude force, check that its energy has the expected value.
...
@@ -55,9 +54,16 @@ void validateForce(System& system, vector<Vec3>& positions, double expectedEnerg
...
@@ -55,9 +54,16 @@ void validateForce(System& system, vector<Vec3>& positions, double expectedEnerg
ASSERT_EQUAL_TOL
(
expectedEnergy
,
state
.
getPotentialEnergy
(),
1e-5
);
ASSERT_EQUAL_TOL
(
expectedEnergy
,
state
.
getPotentialEnergy
(),
1e-5
);
// Try moving each particle along each axis, and see if the energy changes by the correct amount.
// Try moving each particle along each axis, and see if the energy changes by the correct amount.
double
offset
=
1e-3
;
double
offset
=
doublePrecision
?
1e-3
:
1e-2
;
double
TOL
=
1e-5
;
const
double
TOL
=
doublePrecision
?
1e-5
:
5e-4
;
try
{
if
(
platform
.
getPropertyValue
(
context
,
"Precision"
)
!=
"double"
)
{
offset
=
1e-2
;
TOL
=
5e-4
;
}
}
catch
(
OpenMMException
)
{
// The defaults above are for double precision, which is assumed in this case
}
for
(
int
i
=
0
;
i
<
system
.
getNumParticles
();
i
++
)
for
(
int
i
=
0
;
i
<
system
.
getNumParticles
();
i
++
)
for
(
int
j
=
0
;
j
<
3
;
j
++
)
{
for
(
int
j
=
0
;
j
<
3
;
j
++
)
{
vector
<
Vec3
>
offsetPos
=
positions
;
vector
<
Vec3
>
offsetPos
=
positions
;
...
@@ -196,7 +202,6 @@ void runPlatformTests();
...
@@ -196,7 +202,6 @@ void runPlatformTests();
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
try
{
try
{
setupKernels
(
argc
,
argv
);
setupKernels
(
argc
,
argv
);
if
(
argc
>
0
&&
std
::
string
(
argv
[
1
])
==
"double"
)
doublePrecision
=
true
;
testSingleParticle
();
testSingleParticle
();
testAnisotropicParticle
();
testAnisotropicParticle
();
testThole
();
testThole
();
...
...
plugins/drude/tests/TestDrudeSCFIntegrator.h
View file @
cc6a0ac8
...
@@ -36,6 +36,7 @@
...
@@ -36,6 +36,7 @@
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/Context.h"
#include "openmm/NonbondedForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/OpenMMException.h"
#include "openmm/Platform.h"
#include "openmm/Platform.h"
#include "openmm/System.h"
#include "openmm/System.h"
#include "openmm/VirtualSite.h"
#include "openmm/VirtualSite.h"
...
@@ -106,6 +107,14 @@ void testWater() {
...
@@ -106,6 +107,14 @@ void testWater() {
State
state
=
context
.
getState
(
State
::
Energy
);
State
state
=
context
.
getState
(
State
::
Energy
);
double
initialEnergy
;
double
initialEnergy
;
int
numSteps
=
1000
;
int
numSteps
=
1000
;
double
maxNorm
=
1.0
;
try
{
if
(
platform
.
getPropertyValue
(
context
,
"Precision"
)
!=
"double"
)
{
maxNorm
=
5.0
;
}
}
catch
(
OpenMMException
)
{
// The defaults above are for double precision, which is assumed in this case
}
for
(
int
i
=
0
;
i
<
numSteps
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numSteps
;
i
++
)
{
integ
.
step
(
1
);
integ
.
step
(
1
);
state
=
context
.
getState
(
State
::
Energy
|
State
::
Forces
);
state
=
context
.
getState
(
State
::
Energy
|
State
::
Forces
);
...
@@ -118,7 +127,7 @@ void testWater() {
...
@@ -118,7 +127,7 @@ void testWater() {
for
(
int
j
=
1
;
j
<
(
int
)
force
.
size
();
j
+=
5
)
for
(
int
j
=
1
;
j
<
(
int
)
force
.
size
();
j
+=
5
)
norm
+=
sqrt
(
force
[
j
].
dot
(
force
[
j
]));
norm
+=
sqrt
(
force
[
j
].
dot
(
force
[
j
]));
norm
=
(
norm
/
numMolecules
);
norm
=
(
norm
/
numMolecules
);
ASSERT
(
norm
<
1.0
);
ASSERT
(
norm
<
maxNorm
);
}
}
}
}
...
...
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