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
d400d8f0
"git@developer.sourcefind.cn:OpenDAS/torchaudio.git" did not exist on "b9247022c153c6109ca3e2900869f83144be5740"
Commit
d400d8f0
authored
Nov 12, 2019
by
Gao, Xiang
Committed by
Farhad Ramezanghorbani
Nov 12, 2019
Browse files
improve analytical stress calculation (#387)
parent
e784666f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
20 deletions
+6
-20
torchani/ase.py
torchani/ase.py
+6
-20
No files found.
torchani/ase.py
View file @
d400d8f0
...
@@ -52,13 +52,6 @@ class Calculator(ase.calculators.calculator.Calculator):
...
@@ -52,13 +52,6 @@ class Calculator(ase.calculators.calculator.Calculator):
self
.
energy_shifter
self
.
energy_shifter
).
to
(
dtype
)
).
to
(
dtype
)
@
staticmethod
def
strain
(
tensor
,
displacement
,
surface_normal_axis
):
displacement_of_tensor
=
torch
.
zeros_like
(
tensor
)
for
axis
in
range
(
3
):
displacement_of_tensor
[...,
axis
]
=
tensor
[...,
surface_normal_axis
]
*
displacement
[
axis
]
return
displacement_of_tensor
def
calculate
(
self
,
atoms
=
None
,
properties
=
[
'energy'
],
def
calculate
(
self
,
atoms
=
None
,
properties
=
[
'energy'
],
system_changes
=
ase
.
calculators
.
calculator
.
all_changes
):
system_changes
=
ase
.
calculators
.
calculator
.
all_changes
):
super
(
Calculator
,
self
).
calculate
(
atoms
,
properties
,
system_changes
)
super
(
Calculator
,
self
).
calculate
(
atoms
,
properties
,
system_changes
)
...
@@ -70,7 +63,7 @@ class Calculator(ase.calculators.calculator.Calculator):
...
@@ -70,7 +63,7 @@ class Calculator(ase.calculators.calculator.Calculator):
species
=
self
.
species_to_tensor
(
self
.
atoms
.
get_chemical_symbols
()).
to
(
self
.
device
)
species
=
self
.
species_to_tensor
(
self
.
atoms
.
get_chemical_symbols
()).
to
(
self
.
device
)
species
=
species
.
unsqueeze
(
0
)
species
=
species
.
unsqueeze
(
0
)
coordinates
=
torch
.
tensor
(
self
.
atoms
.
get_positions
())
coordinates
=
torch
.
tensor
(
self
.
atoms
.
get_positions
())
coordinates
=
coordinates
.
unsqueeze
(
0
).
to
(
self
.
device
).
to
(
self
.
dtype
)
\
coordinates
=
coordinates
.
to
(
self
.
device
).
to
(
self
.
dtype
)
\
.
requires_grad_
(
'forces'
in
properties
)
.
requires_grad_
(
'forces'
in
properties
)
if
pbc_enabled
:
if
pbc_enabled
:
...
@@ -79,20 +72,13 @@ class Calculator(ase.calculators.calculator.Calculator):
...
@@ -79,20 +72,13 @@ class Calculator(ase.calculators.calculator.Calculator):
atoms
.
set_positions
(
coordinates
.
detach
().
cpu
().
reshape
(
-
1
,
3
).
numpy
())
atoms
.
set_positions
(
coordinates
.
detach
().
cpu
().
reshape
(
-
1
,
3
).
numpy
())
if
'stress'
in
properties
:
if
'stress'
in
properties
:
displacements
=
torch
.
zeros
(
3
,
3
,
requires_grad
=
True
,
scaling
=
torch
.
eye
(
3
,
requires_grad
=
True
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
dtype
=
self
.
dtype
,
device
=
self
.
device
)
coordinates
=
coordinates
@
scaling
displacement_x
,
displacement_y
,
displacement_z
=
displacements
coordinates
=
coordinates
.
unsqueeze
(
0
)
strain_x
=
self
.
strain
(
coordinates
,
displacement_x
,
0
)
strain_y
=
self
.
strain
(
coordinates
,
displacement_y
,
1
)
strain_z
=
self
.
strain
(
coordinates
,
displacement_z
,
2
)
coordinates
=
coordinates
+
strain_x
+
strain_y
+
strain_z
if
pbc_enabled
:
if
pbc_enabled
:
if
'stress'
in
properties
:
if
'stress'
in
properties
:
strain_x
=
self
.
strain
(
cell
,
displacement_x
,
0
)
cell
=
cell
@
scaling
strain_y
=
self
.
strain
(
cell
,
displacement_y
,
1
)
strain_z
=
self
.
strain
(
cell
,
displacement_z
,
2
)
cell
=
cell
+
strain_x
+
strain_y
+
strain_z
aev
=
self
.
aev_computer
((
species
,
coordinates
),
cell
=
cell
,
pbc
=
pbc
).
aevs
aev
=
self
.
aev_computer
((
species
,
coordinates
),
cell
=
cell
,
pbc
=
pbc
).
aevs
else
:
else
:
aev
=
self
.
aev_computer
((
species
,
coordinates
)).
aevs
aev
=
self
.
aev_computer
((
species
,
coordinates
)).
aevs
...
@@ -108,5 +94,5 @@ class Calculator(ase.calculators.calculator.Calculator):
...
@@ -108,5 +94,5 @@ class Calculator(ase.calculators.calculator.Calculator):
if
'stress'
in
properties
:
if
'stress'
in
properties
:
volume
=
self
.
atoms
.
get_volume
()
volume
=
self
.
atoms
.
get_volume
()
stress
=
torch
.
autograd
.
grad
(
energy
.
squeeze
(),
displacements
)[
0
]
/
volume
stress
=
torch
.
autograd
.
grad
(
energy
.
squeeze
(),
scaling
)[
0
]
/
volume
self
.
results
[
'stress'
]
=
stress
.
cpu
().
numpy
()
self
.
results
[
'stress'
]
=
stress
.
cpu
().
numpy
()
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