Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust pp_file as an unnessary parameter in save to abacus/stru #752

Merged
merged 5 commits into from
Nov 8, 2024
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
25 changes: 17 additions & 8 deletions dpdata/abacus/scf.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ def get_frame_from_stru(fname):
def make_unlabeled_stru(
data,
frame_idx,
pp_file,
pp_file=None,
numerical_orbital=None,
numerical_descriptor=None,
mass=None,
Expand Down Expand Up @@ -759,7 +759,15 @@ def process_file_input(file_input, atom_names, input_name):

# ATOMIC_SPECIES block
out = "ATOMIC_SPECIES\n"
ppfiles = process_file_input(ndarray2list(pp_file), data["atom_names"], "pp_file")
if pp_file is not None:
ppfiles = process_file_input(
ndarray2list(pp_file), data["atom_names"], "pp_file"
)
else:
warnings.warn(
"pp_file is not provided, will use empty string for pseudo potential file."
)
ppfiles = [""] * len(data["atom_names"])
Comment on lines +762 to +770
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance warning implementation and add test coverage.

  1. Add stacklevel to the warning to help trace its origin
  2. Add test coverage for the None case
-        warnings.warn(
-            "pp_file is not provided, will use empty string for pseudo potential file."
-        )
+        warnings.warn(
+            "pp_file is not provided, will use empty string for pseudo potential file.",
+            stacklevel=2
+        )

Would you like me to help create test cases for the scenario where pp_file is None?

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if pp_file is not None:
ppfiles = process_file_input(
ndarray2list(pp_file), data["atom_names"], "pp_file"
)
else:
warnings.warn(
"pp_file is not provided, will use empty string for pseudo potential file."
)
ppfiles = [""] * len(data["atom_names"])
if pp_file is not None:
ppfiles = process_file_input(
ndarray2list(pp_file), data["atom_names"], "pp_file"
)
else:
warnings.warn(
"pp_file is not provided, will use empty string for pseudo potential file.",
stacklevel=2
)
ppfiles = [""] * len(data["atom_names"])
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 767-767: dpdata/abacus/scf.py#L767
Added line #L767 was not covered by tests


[warning] 770-770: dpdata/abacus/scf.py#L770
Added line #L770 was not covered by tests

🪛 Ruff

767-767: No explicit stacklevel keyword argument found

(B028)


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

ipp_file = ppfiles[iele]
if not link_file:
out += ipp_file
else:
out += os.path.basename(ipp_file.rstrip("/"))
if dest_dir is not None:
_link_file(dest_dir, ipp_file)
if ipp_file != "":
if not link_file:
out += ipp_file
else:
out += os.path.basename(ipp_file.rstrip("/"))
if dest_dir is not None:
_link_file(dest_dir, ipp_file)
out += "\n"
out += "\n"

Expand Down
4 changes: 4 additions & 0 deletions tests/test_abacus_stru_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def test_dump_stru(self):
)
myfilecmp(self, "abacus.scf/stru_test", "STRU_tmp")

def test_dump_stru_without_pporb(self):
self.system_ch4.to("stru", "STRU_tmp", mass=[12, 1])
self.assertTrue(os.path.isfile("STRU_tmp"))

def test_dumpStruLinkFile(self):
os.makedirs("abacus.scf/tmp", exist_ok=True)
self.system_ch4.to(
Expand Down