Skip to content

Commit

Permalink
Merge pull request #324 from juliayang/development
Browse files Browse the repository at this point in the history
add checks for ase calculators with no stress tensor property impleme…
  • Loading branch information
YuuuXie authored Oct 21, 2022
2 parents 2ec05b3 + 0c734a8 commit f6e457f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
15 changes: 11 additions & 4 deletions flare/io/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import flare
from ase.data import chemical_symbols
from ase.io import write

from ase.calculators.calculator import PropertyNotImplementedError

# Unit conversions.
eva_to_gpa = 160.21766208
Expand Down Expand Up @@ -277,14 +277,21 @@ def write_md_config(

string += "\n"

# Check if we need to report the stress and pressure tensors
try:
if type(structure.stress) == np.ndarray:
stress_exist = True
except PropertyNotImplementedError:
stress_exist = False

# Report cell if stress attribute is present.
if structure.stress is not None:
if stress_exist and structure.stress is not None:
string += "Periodic cell (A): \n"
string += str(np.array(structure.cell)) + "\n\n"

# Report stress tensor.
pressure = None
if structure.stress is not None:
if stress_exist and structure.stress is not None:
stress_tensor = structure.stress * eva_to_gpa # Convert to GPa
s8 = " " * 8
string += "Stress tensor (GPa):\n"
Expand All @@ -308,7 +315,7 @@ def write_md_config(
pressure = (stress_tensor[0] + stress_tensor[1] + stress_tensor[2]) / 3

# Report stress tensor uncertainties.
if structure.stress_stds is not None:
if stress_exist and structure.stress_stds is not None:
stress_stds = structure.stress_stds * eva_to_gpa # Convert to GPa
string += "Stress tensor uncertainties (GPa):\n"
for p in range(6):
Expand Down
9 changes: 8 additions & 1 deletion flare/learners/otf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from flare.md.fake import FakeMD
from ase import units
from ase.io import read, write
from ase.calculators.calculator import PropertyNotImplementedError

from flare.io.output import Output, compute_mae
from flare.learners.utils import is_std_in_bound, get_env_indices
Expand Down Expand Up @@ -462,7 +463,13 @@ def initialize_train(self):
# call dft and update positions
self.run_dft()
dft_frcs = deepcopy(self.atoms.forces)
dft_stress = deepcopy(self.atoms.stress)

# some ase calculators don't have the stress property implemented
try:
dft_stress = deepcopy(self.atoms.stress)
except PropertyNotImplementedError:
dft_stress = None

dft_energy = self.atoms.potential_energy

self.update_temperature()
Expand Down

0 comments on commit f6e457f

Please sign in to comment.