Skip to content

Commit 6a05f3b

Browse files
Adjust pp_file as an unnessary parameter in save to abacus/stru (#752)
In case, some one may just save only as a stru file and has no pseudopotential information. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved error handling and messaging for cases where the pseudo potential file is not provided. - Added checks to ensure parameter lengths match the total number of atoms, enhancing robustness. - **New Features** - Introduced a default value for the pseudo potential file parameter, allowing for more flexible function usage. - **Tests** - Added a new test to verify functionality when the pseudo potential file is not specified, ensuring reliable output with minimal parameters. <!-- 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 7c9be86 commit 6a05f3b

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

dpdata/abacus/scf.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ def get_frame_from_stru(fname):
635635
def make_unlabeled_stru(
636636
data,
637637
frame_idx,
638-
pp_file,
638+
pp_file=None,
639639
numerical_orbital=None,
640640
numerical_descriptor=None,
641641
mass=None,
@@ -759,7 +759,15 @@ def process_file_input(file_input, atom_names, input_name):
759759

760760
# ATOMIC_SPECIES block
761761
out = "ATOMIC_SPECIES\n"
762-
ppfiles = process_file_input(ndarray2list(pp_file), data["atom_names"], "pp_file")
762+
if pp_file is not None:
763+
ppfiles = process_file_input(
764+
ndarray2list(pp_file), data["atom_names"], "pp_file"
765+
)
766+
else:
767+
warnings.warn(
768+
"pp_file is not provided, will use empty string for pseudo potential file."
769+
)
770+
ppfiles = [""] * len(data["atom_names"])
763771

764772
for iele in range(len(data["atom_names"])):
765773
if data["atom_numbs"][iele] == 0:
@@ -771,12 +779,13 @@ def process_file_input(file_input, atom_names, input_name):
771779
out += "1 "
772780

773781
ipp_file = ppfiles[iele]
774-
if not link_file:
775-
out += ipp_file
776-
else:
777-
out += os.path.basename(ipp_file.rstrip("/"))
778-
if dest_dir is not None:
779-
_link_file(dest_dir, ipp_file)
782+
if ipp_file != "":
783+
if not link_file:
784+
out += ipp_file
785+
else:
786+
out += os.path.basename(ipp_file.rstrip("/"))
787+
if dest_dir is not None:
788+
_link_file(dest_dir, ipp_file)
780789
out += "\n"
781790
out += "\n"
782791

tests/test_abacus_stru_dump.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def test_dump_stru(self):
2929
)
3030
myfilecmp(self, "abacus.scf/stru_test", "STRU_tmp")
3131

32+
def test_dump_stru_without_pporb(self):
33+
self.system_ch4.to("stru", "STRU_tmp", mass=[12, 1])
34+
self.assertTrue(os.path.isfile("STRU_tmp"))
35+
3236
def test_dumpStruLinkFile(self):
3337
os.makedirs("abacus.scf/tmp", exist_ok=True)
3438
self.system_ch4.to(

0 commit comments

Comments
 (0)