Skip to content

Commit 38c8928

Browse files
pablogalavizpgalavizjanosh
authored
Fix a bug in pwscf.py. The proc_val function modifies string values. (#3172)
* 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. * Correct typo 'defauss' -> 'degauss' in pwscf.py. Added test_proc_val function in test_pwscf.py. --------- Co-authored-by: Pablo Galaviz <[email protected]> Co-authored-by: Janosh Riebesell <[email protected]>
1 parent 5d6f566 commit 38c8928

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

pymatgen/io/pwscf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def proc_val(key, val):
371371
"conv_thr",
372372
"Hubbard_U",
373373
"Hubbard_J0",
374-
"defauss",
374+
"degauss",
375375
"starting_magnetization",
376376
)
377377

@@ -482,8 +482,7 @@ def smart_int_or_float(numstr):
482482
pass
483483

484484
try:
485-
val = val.replace("d", "e")
486-
return smart_int_or_float(val)
485+
return smart_int_or_float(val.replace("d", "e"))
487486
except ValueError:
488487
pass
489488

pymatgen/io/tests/test_pwscf.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,17 @@ def test_write_str_with_kpoints(self):
208208
"""
209209
assert str(pw).strip() == expected.strip()
210210

211+
def test_proc_val(self):
212+
inputs = {
213+
"degauss": ("7.3498618000d-03", 7.3498618000e-03),
214+
"nat": ("2", 2),
215+
"nosym": (".TRUE.", True),
216+
"smearing": ("'cold'", "cold"),
217+
}
218+
for key, (input_str, expected) in inputs.items():
219+
value = PWInput.proc_val(key, input_str)
220+
assert value == expected
221+
211222
def test_read_str(self):
212223
string = """
213224
&CONTROL
@@ -223,6 +234,7 @@ def test_read_str(self):
223234
ecutwfc = 80
224235
nspin = 1
225236
nbnd = 280
237+
smearing = 'cold'
226238
/
227239
&ELECTRONS
228240
/
@@ -364,6 +376,7 @@ def test_read_str(self):
364376
np.testing.assert_allclose(sites, pw_sites)
365377

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

368381

369382
class PWOuputTest(PymatgenTest):

0 commit comments

Comments
 (0)