diff --git a/flare/io/output.py b/flare/io/output.py index 2c23a9019..db0382146 100644 --- a/flare/io/output.py +++ b/flare/io/output.py @@ -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 @@ -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" @@ -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): diff --git a/flare/learners/otf.py b/flare/learners/otf.py index 22afacc2c..43d6e75ba 100644 --- a/flare/learners/otf.py +++ b/flare/learners/otf.py @@ -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 @@ -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()