Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions dpgen/auto_test/lib/abacus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]):
Expand Down
25 changes: 16 additions & 9 deletions dpgen/generator/lib/abacus_scf.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down
19 changes: 5 additions & 14 deletions dpgen/generator/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down