Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
torchani
Commits
347e845c
Commit
347e845c
authored
Aug 06, 2019
by
Ignacio Pickering
Committed by
Gao, Xiang
Aug 06, 2019
Browse files
Add test for isolated atoms and large distances for 2 and 3 atoms (#274)
parent
6fe30cc9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
0 deletions
+70
-0
tests/test_aev.py
tests/test_aev.py
+70
-0
No files found.
tests/test_aev.py
View file @
347e845c
...
...
@@ -9,12 +9,82 @@ import itertools
import
ase
import
ase.io
import
math
import
traceback
path
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
N
=
97
tolerance
=
1e-5
class
TestIsolated
(
unittest
.
TestCase
):
# Tests that there is no error when atoms are separated
# a distance greater than the cutoff radius from all other atoms
# this can throw an IndexError for large distances or lone atoms
def
setUp
(
self
):
if
torch
.
cuda
.
is_available
():
self
.
device
=
'cuda'
else
:
self
.
device
=
'cpu'
ani1x
=
torchani
.
models
.
ANI1x
().
to
(
self
.
device
)
self
.
aev_computer
=
ani1x
.
aev_computer
self
.
species_to_tensor
=
ani1x
.
species_to_tensor
self
.
rcr
=
ani1x
.
aev_computer
.
Rcr
self
.
rca
=
self
.
aev_computer
.
Rca
def
testCO2
(
self
):
species
=
self
.
species_to_tensor
([
'O'
,
'C'
,
'O'
]).
to
(
self
.
device
).
unsqueeze
(
0
)
distances
=
[
1.0
,
self
.
rca
,
self
.
rca
+
1e-4
,
self
.
rcr
,
self
.
rcr
+
1e-4
,
2
*
self
.
rcr
]
error
=
()
for
dist
in
distances
:
coordinates
=
torch
.
tensor
(
[[[
-
dist
,
0.
,
0.
],
[
0.
,
0.
,
0.
],
[
0.
,
0.
,
dist
]]],
requires_grad
=
True
,
device
=
self
.
device
)
try
:
_
,
_
=
self
.
aev_computer
((
species
,
coordinates
))
except
IndexError
:
error
=
(
traceback
.
format_exc
(),
dist
)
if
error
:
self
.
fail
(
f
'
\n\n
{
error
[
0
]
}
\n
Failure at distance:
{
error
[
1
]
}
\n
'
f
'Radial r_cut of aev_computer:
{
self
.
rcr
}
\n
'
f
'Angular r_cut of aev_computer:
{
self
.
rca
}
'
)
def
testH2
(
self
):
species
=
self
.
species_to_tensor
([
'H'
,
'H'
]).
to
(
self
.
device
).
unsqueeze
(
0
)
distances
=
[
1.0
,
self
.
rca
,
self
.
rca
+
1e-4
,
self
.
rcr
,
self
.
rcr
+
1e-4
,
2
*
self
.
rcr
]
error
=
()
for
dist
in
distances
:
coordinates
=
torch
.
tensor
(
[[[
0.
,
0.
,
0.
],
[
0.
,
0.
,
dist
]]],
requires_grad
=
True
,
device
=
self
.
device
)
try
:
_
,
_
=
self
.
aev_computer
((
species
,
coordinates
))
except
IndexError
:
error
=
(
traceback
.
format_exc
(),
dist
)
if
error
:
self
.
fail
(
f
'
\n\n
{
error
[
0
]
}
\n
Failure at distance:
{
error
[
1
]
}
\n
'
f
'Radial r_cut of aev_computer:
{
self
.
rcr
}
\n
'
f
'Angular r_cut of aev_computer:
{
self
.
rca
}
'
)
def
testH
(
self
):
# Tests for failure on a single atom
species
=
self
.
species_to_tensor
([
'H'
]).
to
(
self
.
device
).
unsqueeze
(
0
)
error
=
()
coordinates
=
torch
.
tensor
(
[[[
0.
,
0.
,
0.
]]],
requires_grad
=
True
,
device
=
self
.
device
)
try
:
_
,
_
=
self
.
aev_computer
((
species
,
coordinates
))
except
IndexError
:
error
=
(
traceback
.
format_exc
())
if
error
:
self
.
fail
(
f
'
\n\n
{
error
}
\n
Failure on lone atom
\n
'
)
class
TestAEV
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
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