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

Fix a bug in pwscf.py. The proc_val function modifies string values. #3172

Merged
merged 5 commits into from
Jul 22, 2023
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
5 changes: 2 additions & 3 deletions pymatgen/io/pwscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def proc_val(key, val):
"conv_thr",
"Hubbard_U",
"Hubbard_J0",
"defauss",
"degauss",
"starting_magnetization",
)

Expand Down Expand Up @@ -482,8 +482,7 @@ def smart_int_or_float(numstr):
pass

try:
val = val.replace("d", "e")
return smart_int_or_float(val)
return smart_int_or_float(val.replace("d", "e"))
except ValueError:
pass

Expand Down
13 changes: 13 additions & 0 deletions pymatgen/io/tests/test_pwscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,17 @@ def test_write_str_with_kpoints(self):
"""
assert str(pw).strip() == expected.strip()

def test_proc_val(self):
inputs = {
"degauss": ("7.3498618000d-03", 7.3498618000e-03),
"nat": ("2", 2),
"nosym": (".TRUE.", True),
"smearing": ("'cold'", "cold"),
}
for key, (input_str, expected) in inputs.items():
value = PWInput.proc_val(key, input_str)
assert value == expected

def test_read_str(self):
string = """
&CONTROL
Expand All @@ -223,6 +234,7 @@ def test_read_str(self):
ecutwfc = 80
nspin = 1
nbnd = 280
smearing = 'cold'
/
&ELECTRONS
/
Expand Down Expand Up @@ -364,6 +376,7 @@ def test_read_str(self):
np.testing.assert_allclose(sites, pw_sites)

np.testing.assert_allclose(lattice, pwin.structure.lattice.matrix)
assert pwin.sections["system"]["smearing"] == "cold"


class PWOuputTest(PymatgenTest):
Expand Down