Skip to content

Commit 945a2a6

Browse files
abacus: fix bug in make_abacus_scf_stru (#1755)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved the selection of pseudopotential and orbital files to ensure only relevant files for the atoms present in the system are included. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: root <pxlxingliang> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 86bfe1b commit 945a2a6

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

dpgen/generator/lib/abacus_scf.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,38 @@ def make_abacus_scf_stru(
213213
):
214214
sys_data_copy = copy.deepcopy(sys_data)
215215
# re-construct the path of files by pporb + file name
216-
fp_pp_files = [os.path.join(pporb, i) for i in fp_pp_files]
216+
# when element in sys_data is part of type_map/fp_pp_files
217+
# we need to only pass the pp_file in sys_data, but not all pp_files
218+
if type_map is None:
219+
type_map = sys_data_copy["atom_names"]
220+
221+
missing_atoms = set(sys_data_copy["atom_names"]) - set(type_map)
222+
if len(missing_atoms) > 0:
223+
raise ValueError(
224+
f"Some atoms in sys_data are not in type_map: {missing_atoms}. "
225+
"Please provide a valid type_map."
226+
)
227+
228+
if len(fp_pp_files) != len(type_map):
229+
raise ValueError(
230+
"The length of fp_pp_files should be equal to the length of type_map."
231+
)
232+
if fp_orb_files is not None and len(fp_orb_files) != len(type_map):
233+
raise ValueError(
234+
"The length of fp_orb_files should be equal to the length of type_map."
235+
)
236+
237+
fp_pp_files = [
238+
os.path.join(pporb, fp_pp_files[type_map.index(atom_name)])
239+
for atom_name in sys_data_copy["atom_names"]
240+
]
241+
217242
if fp_orb_files is not None:
218-
fp_orb_files = [os.path.join(pporb, i) for i in fp_orb_files]
243+
fp_orb_files = [
244+
os.path.join(pporb, fp_orb_files[type_map.index(atom_name)])
245+
for atom_name in sys_data_copy["atom_names"]
246+
]
247+
219248
if fp_dpks_descriptor is not None:
220249
fp_dpks_descriptor = os.path.join(pporb, fp_dpks_descriptor)
221250

tests/data/test_gen_bulk_abacus.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def test(self):
7676
def testSTRU(self):
7777
jdata = self.jdata
7878
jdata["from_poscar_path"] = "./Cu.STRU"
79-
jdata["potcars"] = ["abacus.in/Cu_ONCV_PBE-1.0.upf"]
8079
make_super_cell_STRU(jdata)
8180
make_abacus_relax(jdata, {"fp_resources": {}})
8281
make_scale_ABACUS(jdata)

0 commit comments

Comments
 (0)