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
c41581a3
Commit
c41581a3
authored
Nov 12, 2019
by
Gao, Xiang
Committed by
Farhad Ramezanghorbani
Nov 12, 2019
Browse files
Use type inference of arange to clean up code (#357)
* Use type inference of arange to clean up code * commit
parent
1a2b4504
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
torchani/aev.py
torchani/aev.py
+5
-5
No files found.
torchani/aev.py
View file @
c41581a3
...
@@ -98,9 +98,9 @@ def compute_shifts(cell: Tensor, pbc: Tensor, cutoff: float) -> Tensor:
...
@@ -98,9 +98,9 @@ def compute_shifts(cell: Tensor, pbc: Tensor, cutoff: float) -> Tensor:
inv_distances
=
reciprocal_cell
.
norm
(
2
,
-
1
)
inv_distances
=
reciprocal_cell
.
norm
(
2
,
-
1
)
num_repeats
=
torch
.
ceil
(
cutoff
*
inv_distances
).
to
(
torch
.
long
)
num_repeats
=
torch
.
ceil
(
cutoff
*
inv_distances
).
to
(
torch
.
long
)
num_repeats
=
torch
.
where
(
pbc
,
num_repeats
,
torch
.
zeros_like
(
num_repeats
))
num_repeats
=
torch
.
where
(
pbc
,
num_repeats
,
torch
.
zeros_like
(
num_repeats
))
r1
=
torch
.
arange
(
1
,
num_repeats
[
0
]
+
1
,
device
=
cell
.
device
,
dtype
=
torch
.
long
)
r1
=
torch
.
arange
(
1
,
num_repeats
[
0
]
+
1
,
device
=
cell
.
device
)
r2
=
torch
.
arange
(
1
,
num_repeats
[
1
]
+
1
,
device
=
cell
.
device
,
dtype
=
torch
.
long
)
r2
=
torch
.
arange
(
1
,
num_repeats
[
1
]
+
1
,
device
=
cell
.
device
)
r3
=
torch
.
arange
(
1
,
num_repeats
[
2
]
+
1
,
device
=
cell
.
device
,
dtype
=
torch
.
long
)
r3
=
torch
.
arange
(
1
,
num_repeats
[
2
]
+
1
,
device
=
cell
.
device
)
o
=
torch
.
zeros
(
1
,
dtype
=
torch
.
long
,
device
=
cell
.
device
)
o
=
torch
.
zeros
(
1
,
dtype
=
torch
.
long
,
device
=
cell
.
device
)
return
torch
.
cat
([
return
torch
.
cat
([
torch
.
cartesian_prod
(
r1
,
r2
,
r3
),
torch
.
cartesian_prod
(
r1
,
r2
,
r3
),
...
@@ -136,7 +136,7 @@ def neighbor_pairs(padding_mask: Tensor, coordinates: Tensor, cell: Tensor,
...
@@ -136,7 +136,7 @@ def neighbor_pairs(padding_mask: Tensor, coordinates: Tensor, cell: Tensor,
coordinates
=
coordinates
.
detach
()
coordinates
=
coordinates
.
detach
()
cell
=
cell
.
detach
()
cell
=
cell
.
detach
()
num_atoms
=
padding_mask
.
shape
[
1
]
num_atoms
=
padding_mask
.
shape
[
1
]
all_atoms
=
torch
.
arange
(
num_atoms
,
device
=
cell
.
device
,
dtype
=
torch
.
long
)
all_atoms
=
torch
.
arange
(
num_atoms
,
device
=
cell
.
device
)
# Step 2: center cell
# Step 2: center cell
p1_center
,
p2_center
=
torch
.
combinations
(
all_atoms
).
unbind
(
-
1
)
p1_center
,
p2_center
=
torch
.
combinations
(
all_atoms
).
unbind
(
-
1
)
...
@@ -145,7 +145,7 @@ def neighbor_pairs(padding_mask: Tensor, coordinates: Tensor, cell: Tensor,
...
@@ -145,7 +145,7 @@ def neighbor_pairs(padding_mask: Tensor, coordinates: Tensor, cell: Tensor,
# Step 3: cells with shifts
# Step 3: cells with shifts
# shape convention (shift index, molecule index, atom index, 3)
# shape convention (shift index, molecule index, atom index, 3)
num_shifts
=
shifts
.
shape
[
0
]
num_shifts
=
shifts
.
shape
[
0
]
all_shifts
=
torch
.
arange
(
num_shifts
,
device
=
cell
.
device
,
dtype
=
torch
.
long
)
all_shifts
=
torch
.
arange
(
num_shifts
,
device
=
cell
.
device
)
shift_index
,
p1
,
p2
=
torch
.
cartesian_prod
(
all_shifts
,
all_atoms
,
all_atoms
).
unbind
(
-
1
)
shift_index
,
p1
,
p2
=
torch
.
cartesian_prod
(
all_shifts
,
all_atoms
,
all_atoms
).
unbind
(
-
1
)
shifts_outide
=
shifts
.
index_select
(
0
,
shift_index
)
shifts_outide
=
shifts
.
index_select
(
0
,
shift_index
)
...
...
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