Skip to content

Commit

Permalink
improve: ase try to get virials from different sources
Browse files Browse the repository at this point in the history
  • Loading branch information
link89 committed May 17, 2024
1 parent 626e692 commit aa8d22e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions dpdata/plugins/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,21 @@ def from_labeled_system(self, atoms: ase.Atoms, **kwargs) -> dict:
"energies": np.array([energies]),
"forces": np.array([forces]),
}
try:
stress = atoms.get_stress(False)
except PropertyNotImplementedError:
pass
else:
virials = np.array([-atoms.get_volume() * stress])

# try to get virials from different sources
virials = atoms.info.get("virial")
if virials is None:
virials = atoms.info.get("virials")
if virials is None:
try:
stress = atoms.get_stress(False)
except PropertyNotImplementedError:
pass

Check warning on line 105 in dpdata/plugins/ase.py

View check run for this annotation

Codecov / codecov/patch

dpdata/plugins/ase.py#L104-L105

Added lines #L104 - L105 were not covered by tests
else:
virials = np.array([-atoms.get_volume() * stress])
if virials is not None:
info_dict["virials"] = virials

return info_dict

def from_multi_systems(
Expand Down

0 comments on commit aa8d22e

Please sign in to comment.