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
a3720bc2
Unverified
Commit
a3720bc2
authored
Dec 18, 2020
by
Ignacio Pickering
Committed by
GitHub
Dec 18, 2020
Browse files
Fix handwritten cosine similarity and add test for NaNs in AEVComputer (#561)
parent
d7302cc3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
2 deletions
+8
-2
tests/test_aev.py
tests/test_aev.py
+7
-0
torchani/aev.py
torchani/aev.py
+1
-2
No files found.
tests/test_aev.py
View file @
a3720bc2
...
...
@@ -118,6 +118,13 @@ class TestAEV(_TestAEVBase):
_
,
aev
=
self
.
aev_computer
((
species
,
coordinates
))
self
.
assertAEVEqual
(
expected_radial
,
expected_angular
,
aev
)
def
testNoNan
(
self
):
# AEV should not output NaN even when coordinates are superimposed
coordinates
=
torch
.
ones
(
1
,
3
,
3
,
dtype
=
torch
.
float
)
species
=
torch
.
zeros
(
1
,
3
,
dtype
=
torch
.
long
)
_
,
aev
=
self
.
aev_computer
((
species
,
coordinates
))
self
.
assertFalse
(
torch
.
isnan
(
aev
).
any
())
def
testPadding
(
self
):
species_coordinates
=
[]
radial_angular
=
[]
...
...
torchani/aev.py
View file @
a3720bc2
...
...
@@ -76,8 +76,7 @@ def angular_terms(Rca: float, ShfZ: Tensor, EtaA: Tensor, Zeta: Tensor,
"""
vectors12
=
vectors12
.
view
(
2
,
-
1
,
3
,
1
,
1
,
1
,
1
)
distances12
=
vectors12
.
norm
(
2
,
dim
=-
5
)
cos_angles
=
vectors12
.
prod
(
0
).
sum
(
1
)
/
distances12
.
prod
(
0
)
cos_angles
=
vectors12
.
prod
(
0
).
sum
(
1
)
/
torch
.
clamp
(
distances12
.
prod
(
0
),
min
=
1e-10
)
# 0.95 is multiplied to the cos values to prevent acos from returning NaN.
angles
=
torch
.
acos
(
0.95
*
cos_angles
)
...
...
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