Skip to content

Commit 52d6b8c

Browse files
tawe141Eric Tawjanosh
authored
Fix Vasprun not interpreting float overflow as nan (#3452)
* fix vasprun not interpreting float overflow as nan * add test * pre-commit auto-fixes * rename and cleanup test_float_overflow introduce artificial overflow in <varray name="forces"> in vasprun.xml.sc_overflow rm tests/files/vasprun.xml.force_overflow --------- Co-authored-by: Eric Taw <[email protected]> Co-authored-by: Janosh Riebesell <[email protected]>
1 parent 9e27ca8 commit 52d6b8c

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

pymatgen/io/vasp/outputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ def _parse_chemical_shielding_calculation(self, elem):
13011301

13021302
def _parse_calculation(self, elem):
13031303
try:
1304-
istep = {i.attrib["name"]: float(i.text) for i in elem.find("energy").findall("i")}
1304+
istep = {i.attrib["name"]: _vasprun_float(i.text) for i in elem.find("energy").findall("i")}
13051305
except AttributeError: # not all calculations have an energy
13061306
istep = {}
13071307
esteps = []

tests/files/.pytest-split-durations

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@
21692169
"tests/io/vasp/test_outputs.py::TestVasprun::test_potcar_not_found": 0.1334625000017695,
21702170
"tests/io/vasp/test_outputs.py::TestVasprun::test_projected_magnetisation": 4.4185712080216035,
21712171
"tests/io/vasp/test_outputs.py::TestVasprun::test_runtype": 14.43198950093938,
2172-
"tests/io/vasp/test_outputs.py::TestVasprun::test_sc_step_overflow": 1.980604083975777,
2172+
"tests/io/vasp/test_outputs.py::TestVasprun::test_float_overflow": 1.980604083975777,
21732173
"tests/io/vasp/test_outputs.py::TestVasprun::test_search_for_potcar": 0.2289056670269929,
21742174
"tests/io/vasp/test_outputs.py::TestVasprun::test_selective_dynamics": 1.798271125066094,
21752175
"tests/io/vasp/test_outputs.py::TestVasprun::test_smart_efermi": 2.6953831250430085,

tests/files/vasprun.xml.sc_overflow

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@
891891
</varray>
892892
</structure>
893893
<varray name="forces" >
894-
<v> 0.41466569 -0.04234049 0.05092706 </v>
894+
<v> ********** -0.04234049 0.05092706 </v>
895895
<v> 0.23840217 0.09338135 -0.08187019 </v>
896896
<v> -0.45497113 0.03109806 -0.23055151 </v>
897897
<v> -0.41847023 0.03902084 -0.19336882 </v>

tests/io/vasp/test_outputs.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,13 +578,17 @@ def test_smart_efermi(self):
578578
smart_fermi = vrun.calculate_efermi()
579579
assert smart_fermi == approx(6.0165)
580580

581-
def test_sc_step_overflow(self):
581+
def test_float_overflow(self):
582+
# test we interpret VASP's *********** for overflowed values as NaNs
583+
# https://github.com/materialsproject/pymatgen/pull/3452
582584
filepath = f"{TEST_FILES_DIR}/vasprun.xml.sc_overflow"
583585
with pytest.warns(UserWarning, match="Float overflow .* encountered in vasprun"):
584586
vasp_run = Vasprun(filepath)
585-
vasp_run = Vasprun(filepath)
586-
estep = vasp_run.ionic_steps[0]["electronic_steps"][29]
587-
assert np.isnan(estep["e_wo_entrp"])
587+
first_ionic_step = vasp_run.ionic_steps[0]
588+
elec_step = first_ionic_step["electronic_steps"][29]
589+
assert np.isnan(elec_step["e_wo_entrp"])
590+
assert np.isnan(elec_step["e_fr_energy"])
591+
assert np.isnan(first_ionic_step["forces"]).any()
588592

589593
def test_update_potcar(self):
590594
filepath = f"{TEST_FILES_DIR}/vasprun.xml"

0 commit comments

Comments
 (0)