From 1053cfd62326a0a3336f8eb751f2bf4f5a5c132a Mon Sep 17 00:00:00 2001 From: "njzjz-bot (driven by OpenClaw (model: gpt-5.5))[bot]" <48687836+njzjz-bot@users.noreply.github.com> Date: Fri, 8 May 2026 02:27:38 +0000 Subject: [PATCH] fix(dpdata): use public format APIs Avoid importing dpdata backend parser modules directly. Use dpdata's registered public format interface for ABACUS STRU, VASP POSCAR, and SIESTA output handling so DP-GEN works with both dpdata 0.2.x and 1.x without depending on moved backend module paths. Authored by OpenClaw (model: gpt-5.5) --- dpgen/auto_test/lib/abacus.py | 16 ++++------------ dpgen/generator/lib/abacus_scf.py | 25 ++++++++++++++++--------- dpgen/generator/run.py | 19 +++++-------------- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/dpgen/auto_test/lib/abacus.py b/dpgen/auto_test/lib/abacus.py index 05ebd5cc1..2f0e902fd 100644 --- a/dpgen/auto_test/lib/abacus.py +++ b/dpgen/auto_test/lib/abacus.py @@ -4,9 +4,6 @@ import dpdata import numpy as np -from dpdata.abacus.stru import make_unlabeled_stru -from dpdata.utils import uniq_atom_names -from dpdata.vasp import poscar as dpdata_poscar import dpgen.generator.lib.abacus_scf as abacus_scf @@ -142,11 +139,7 @@ def poscar2stru(poscar, inter_param, stru="STRU"): - deepks_desc: a string of deepks descriptor file - stru: output filename, usally is 'STRU'. """ - # if use dpdata.System, the structure will be rotated to make cell to be lower triangular - with open(poscar) as fp: - lines = [line.rstrip("\n") for line in fp] - stru_data = dpdata_poscar.to_system_data(lines) - stru_data = uniq_atom_names(stru_data) + stru_data = dpdata.System(poscar, fmt="vasp/poscar").data atom_mass = [] pseudo = None @@ -185,16 +178,15 @@ def poscar2stru(poscar, inter_param, stru="STRU"): if "deepks_desc" in inter_param: deepks_desc = "./pp_orb/{}\n".format(inter_param["deepks_desc"]) - stru_string = make_unlabeled_stru( - data=stru_data, + dpdata.System(data=stru_data).to( + "abacus/stru", + stru, frame_idx=0, pp_file=pseudo, numerical_orbital=orb, numerical_descriptor=deepks_desc, mass=atom_mass, ) - with open(stru, "w") as fp: - fp.write(stru_string) def stru_fix_atom(struf, fix_atom=[True, True, True]): diff --git a/dpgen/generator/lib/abacus_scf.py b/dpgen/generator/lib/abacus_scf.py index 21f1e1377..86e3e78b2 100644 --- a/dpgen/generator/lib/abacus_scf.py +++ b/dpgen/generator/lib/abacus_scf.py @@ -1,9 +1,10 @@ import copy import os import re +import tempfile +import dpdata import numpy as np -from dpdata.abacus.stru import get_frame_from_stru, make_unlabeled_stru from dpgen.auto_test.lib import vasp @@ -259,13 +260,19 @@ def make_abacus_scf_stru( if len(cells.shape) == 2: sys_data_copy["cells"] = np.array([cells]) sys_data_copy["coords"] = np.array([coords]) - c = make_unlabeled_stru( - sys_data_copy, - 0, - pp_file=fp_pp_files, - numerical_orbital=fp_orb_files, - numerical_descriptor=fp_dpks_descriptor, - ) + with tempfile.NamedTemporaryFile( + mode="r+", prefix="dpgen-abacus-", suffix=".stru" + ) as fp: + dpdata.System(data=sys_data_copy).to( + "abacus/stru", + fp.name, + frame_idx=0, + pp_file=fp_pp_files, + numerical_orbital=fp_orb_files, + numerical_descriptor=fp_dpks_descriptor, + ) + fp.seek(0) + c = fp.read() return c @@ -302,7 +309,7 @@ def get_abacus_STRU(STRU): "dpks_descriptor": str, } """ - data = get_frame_from_stru(STRU) + data = dpdata.System(STRU, fmt="abacus/stru").data data["atom_masses"] = data.pop("masses") data["cells"] = data.pop("cells")[0] data["coords"] = data.pop("coords")[0] diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index 46ec6e1ce..0ce513a96 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -4585,9 +4585,10 @@ def post_fp_abacus_scf(iter_index, jdata): all_sys = None for ii, oo in zip(sys_input, sys_output): - _sys = dpdata.LabeledSystem( - oo, fmt="abacus/scf", type_map=jdata["type_map"] - ) + _sys = dpdata.LabeledSystem(oo, fmt="abacus/scf") + if len(_sys) > 0: + _sys.data["atom_types"] = np.asarray(_sys.data["atom_types"], dtype=int) + _sys.apply_type_map(jdata["type_map"]) if len(_sys) > 0: if all_sys is None: all_sys = _sys @@ -4626,17 +4627,7 @@ def post_fp_siesta(iter_index, jdata): sys_output.sort() sys_input.sort() for idx, oo in enumerate(sys_output): - _sys = dpdata.LabeledSystem() - ( - _sys.data["atom_names"], - _sys.data["atom_numbs"], - _sys.data["atom_types"], - _sys.data["cells"], - _sys.data["coords"], - _sys.data["energies"], - _sys.data["forces"], - _sys.data["virials"], - ) = dpdata.siesta.output.obtain_frame(oo) + _sys = dpdata.LabeledSystem(oo, fmt="siesta/output") if idx == 0: all_sys = _sys else: