From 66554531c8a4929f9c5e130a83ef9b0d4c271150 Mon Sep 17 00:00:00 2001 From: "weihong.xu" Date: Wed, 16 Jul 2025 22:28:25 +0800 Subject: [PATCH 1/3] read virial from ase --- dpdata/plugins/ase.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/dpdata/plugins/ase.py b/dpdata/plugins/ase.py index 212d4af9b..a682569c0 100644 --- a/dpdata/plugins/ase.py +++ b/dpdata/plugins/ase.py @@ -63,6 +63,8 @@ def from_labeled_system(self, atoms: ase.Atoms, **kwargs) -> dict: """Convert ase.Atoms to a LabeledSystem. Energies and forces are calculated by the calculator. + Note that this method will try to load virials from either virial field or converted from stress tensor. + Parameters ---------- atoms : ase.Atoms @@ -94,13 +96,19 @@ def from_labeled_system(self, atoms: ase.Atoms, **kwargs) -> dict: "energies": np.array([energies]), "forces": np.array([forces]), } - try: - stress = atoms.get_stress(voigt=False) - except PropertyNotImplementedError: - pass - else: - virials = np.array([-atoms.get_volume() * stress]) - info_dict["virials"] = virials + + # try to get virials from different sources + virials = atoms.info.get("virial") + if virials is None: + try: + stress = atoms.get_stress(voigt=False) + except PropertyNotImplementedError: + pass + else: + virials = -atoms.get_volume() * stress + if virials is not None: + info_dict["virials"] = np.array([virials]) + return info_dict def from_multi_systems( @@ -166,7 +174,6 @@ def to_labeled_system(self, data, *args, **kwargs) -> list[ase.Atoms]: structures = [] species = [data["atom_names"][tt] for tt in data["atom_types"]] - for ii in range(data["coords"].shape[0]): structure = Atoms( symbols=species, From d6906f600781b02535dba4c35eb7e409773c525a Mon Sep 17 00:00:00 2001 From: "weihong.xu" Date: Wed, 16 Jul 2025 22:44:46 +0800 Subject: [PATCH 2/3] fix broken doc --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 52c47804e..10e0fa0bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,6 +59,7 @@ docs = [ 'rdkit', 'jupyterlite-sphinx', 'jupyterlite-xeus', + 'm2r>=0.3.1', ] benchmark = [ 'pytest', From 457de069d843af851f74633bc8ced8840042deaa Mon Sep 17 00:00:00 2001 From: "weihong.xu" Date: Thu, 17 Jul 2025 01:39:52 +0800 Subject: [PATCH 3/3] revert m2r fix --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 10e0fa0bd..52c47804e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,6 @@ docs = [ 'rdkit', 'jupyterlite-sphinx', 'jupyterlite-xeus', - 'm2r>=0.3.1', ] benchmark = [ 'pytest',