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
e3c73684
Commit
e3c73684
authored
Feb 04, 2020
by
Gao, Xiang
Browse files
Merge branch 'master' of github.com:aiqm/torchani
parents
9589dc35
bf8c39e3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 addition
and
51 deletions
+1
-51
tests/test_padding.py
tests/test_padding.py
+0
-23
torchani/utils.py
torchani/utils.py
+1
-28
No files found.
tests/test_padding.py
View file @
e3c73684
...
@@ -80,29 +80,6 @@ class TestPaddings(unittest.TestCase):
...
@@ -80,29 +80,6 @@ class TestPaddings(unittest.TestCase):
self
.
assertEqual
((
atomic_properties
[
'species'
]
-
expected_species
).
abs
().
max
().
item
(),
0
)
self
.
assertEqual
((
atomic_properties
[
'species'
]
-
expected_species
).
abs
().
max
().
item
(),
0
)
self
.
assertEqual
(
atomic_properties
[
'coordinates'
].
abs
().
max
().
item
(),
0
)
self
.
assertEqual
(
atomic_properties
[
'coordinates'
].
abs
().
max
().
item
(),
0
)
def
testPadSpecies
(
self
):
species1
=
torch
.
tensor
([
[
0
,
2
,
3
,
1
],
[
0
,
2
,
3
,
1
],
[
0
,
2
,
3
,
1
],
[
0
,
2
,
3
,
1
],
[
0
,
2
,
3
,
1
],
])
species2
=
torch
.
tensor
([[
3
,
2
,
0
,
1
,
0
]]).
expand
(
2
,
5
)
species
=
torchani
.
utils
.
pad
([
species1
,
species2
])
self
.
assertEqual
(
species
.
shape
[
0
],
7
)
self
.
assertEqual
(
species
.
shape
[
1
],
5
)
expected_species
=
torch
.
tensor
([
[
0
,
2
,
3
,
1
,
-
1
],
[
0
,
2
,
3
,
1
,
-
1
],
[
0
,
2
,
3
,
1
,
-
1
],
[
0
,
2
,
3
,
1
,
-
1
],
[
0
,
2
,
3
,
1
,
-
1
],
[
3
,
2
,
0
,
1
,
0
],
[
3
,
2
,
0
,
1
,
0
],
])
self
.
assertEqual
((
species
-
expected_species
).
abs
().
max
().
item
(),
0
)
def
testPresentSpecies
(
self
):
def
testPresentSpecies
(
self
):
species
=
torch
.
tensor
([
0
,
1
,
1
,
0
,
3
,
7
,
-
1
,
-
1
])
species
=
torch
.
tensor
([
0
,
1
,
1
,
0
,
3
,
7
,
-
1
,
-
1
])
present_species
=
torchani
.
utils
.
present_species
(
species
)
present_species
=
torchani
.
utils
.
present_species
(
species
)
...
...
torchani/utils.py
View file @
e3c73684
...
@@ -8,33 +8,6 @@ from typing import Tuple, NamedTuple, Optional
...
@@ -8,33 +8,6 @@ from typing import Tuple, NamedTuple, Optional
from
.nn
import
SpeciesEnergies
from
.nn
import
SpeciesEnergies
def
pad
(
species
):
"""Put different species together into single tensor.
If the species are from molecules of different number of total atoms, then
ghost atoms with atom type -1 will be added to make it fit into the same
shape.
Arguments:
species (:class:`collections.abc.Sequence`): sequence of species.
Species must be of shape ``(N, A)``, where ``N`` is the number of
3D structures, ``A`` is the number of atoms.
Returns:
:class:`torch.Tensor`: species batched together.
"""
max_atoms
=
max
([
s
.
shape
[
1
]
for
s
in
species
])
padded_species
=
[]
for
s
in
species
:
natoms
=
s
.
shape
[
1
]
if
natoms
<
max_atoms
:
padding
=
torch
.
full
((
s
.
shape
[
0
],
max_atoms
-
natoms
),
-
1
,
dtype
=
torch
.
long
,
device
=
s
.
device
)
s
=
torch
.
cat
([
s
,
padding
],
dim
=
1
)
padded_species
.
append
(
s
)
return
torch
.
cat
(
padded_species
)
def
pad_atomic_properties
(
atomic_properties
,
padding_values
=
defaultdict
(
lambda
:
0.0
,
species
=-
1
)):
def
pad_atomic_properties
(
atomic_properties
,
padding_values
=
defaultdict
(
lambda
:
0.0
,
species
=-
1
)):
"""Put a sequence of atomic properties together into single tensor.
"""Put a sequence of atomic properties together into single tensor.
...
@@ -350,6 +323,6 @@ def vibrational_analysis(masses, hessian, mode_type='MDU', unit='cm^-1'):
...
@@ -350,6 +323,6 @@ def vibrational_analysis(masses, hessian, mode_type='MDU', unit='cm^-1'):
return
VibAnalysis
(
wavenumbers
,
modes
,
fconstants
,
rmasses
)
return
VibAnalysis
(
wavenumbers
,
modes
,
fconstants
,
rmasses
)
__all__
=
[
'pad'
,
'pad_atomic_properties'
,
'present_species'
,
'hessian'
,
__all__
=
[
'pad_atomic_properties'
,
'present_species'
,
'hessian'
,
'vibrational_analysis'
,
'strip_redundant_padding'
,
'vibrational_analysis'
,
'strip_redundant_padding'
,
'ChemicalSymbolsToInts'
]
'ChemicalSymbolsToInts'
]
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