From 67e891c03ef8b8764bfab00bbed7eead69b0cddf Mon Sep 17 00:00:00 2001 From: Pablo Galaviz Date: Fri, 21 Jul 2023 13:25:47 +1000 Subject: [PATCH 1/4] Fix a bug in pwscf.py. The proc_val function modifies the value of string variables (changes 'd' for 'e'). For example, smearing = 'cold' becomes smearing = 'cole'. Solved by using a local variable. --- pymatgen/io/pwscf.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pymatgen/io/pwscf.py b/pymatgen/io/pwscf.py index 88c06fda48e..ba3162c91a5 100644 --- a/pymatgen/io/pwscf.py +++ b/pymatgen/io/pwscf.py @@ -482,8 +482,9 @@ def smart_int_or_float(numstr): pass try: - val = val.replace("d", "e") - return smart_int_or_float(val) + # use local variable to avoid modifications to a string value + val_replace = val.replace("d", "e") + return smart_int_or_float(val_replace) except ValueError: pass From eab913f1c24d326f3e69455641544e54af2c8f8d Mon Sep 17 00:00:00 2001 From: Pablo Galaviz Date: Sat, 22 Jul 2023 21:00:14 +1000 Subject: [PATCH 2/4] Correct typo 'defauss' -> 'degauss' in pwscf.py. Added test_proc_val function in test_pwscf.py. --- pymatgen/io/pwscf.py | 2 +- pymatgen/io/tests/test_pwscf.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pymatgen/io/pwscf.py b/pymatgen/io/pwscf.py index ba3162c91a5..9884e37177f 100644 --- a/pymatgen/io/pwscf.py +++ b/pymatgen/io/pwscf.py @@ -371,7 +371,7 @@ def proc_val(key, val): "conv_thr", "Hubbard_U", "Hubbard_J0", - "defauss", + "degauss", "starting_magnetization", ) diff --git a/pymatgen/io/tests/test_pwscf.py b/pymatgen/io/tests/test_pwscf.py index 0406076f8fc..a50a25cd249 100644 --- a/pymatgen/io/tests/test_pwscf.py +++ b/pymatgen/io/tests/test_pwscf.py @@ -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 @@ -223,6 +234,7 @@ def test_read_str(self): ecutwfc = 80 nspin = 1 nbnd = 280 + smearing = 'cold' / &ELECTRONS / @@ -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): From a52daeb9ca5c30ec1b54b83d5865970c7c17d005 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 22 Jul 2023 11:07:20 +0000 Subject: [PATCH 3/4] pre-commit auto-fixes --- pymatgen/io/tests/test_pwscf.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pymatgen/io/tests/test_pwscf.py b/pymatgen/io/tests/test_pwscf.py index a50a25cd249..ed07e2ccd84 100644 --- a/pymatgen/io/tests/test_pwscf.py +++ b/pymatgen/io/tests/test_pwscf.py @@ -209,14 +209,14 @@ 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") + 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) + for key, (input_str, expected) in inputs.items(): + value = PWInput.proc_val(key, input_str) assert value == expected def test_read_str(self): From 4ea9769029f8af3741d0412aea9195bf9d47183a Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Sat, 22 Jul 2023 07:01:12 -0700 Subject: [PATCH 4/4] one line --- pymatgen/io/pwscf.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pymatgen/io/pwscf.py b/pymatgen/io/pwscf.py index 9884e37177f..d2f2d627aa3 100644 --- a/pymatgen/io/pwscf.py +++ b/pymatgen/io/pwscf.py @@ -482,9 +482,7 @@ def smart_int_or_float(numstr): pass try: - # use local variable to avoid modifications to a string value - val_replace = val.replace("d", "e") - return smart_int_or_float(val_replace) + return smart_int_or_float(val.replace("d", "e")) except ValueError: pass