Skip to content

Commit

Permalink
Fix Vasprun not interpreting float overflow as nan (#3452)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Nov 8, 2023
1 parent 9e27ca8 commit 52d6b8c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ def _parse_chemical_shielding_calculation(self, elem):

def _parse_calculation(self, elem):
try:
istep = {i.attrib["name"]: float(i.text) for i in elem.find("energy").findall("i")}
istep = {i.attrib["name"]: _vasprun_float(i.text) for i in elem.find("energy").findall("i")}
except AttributeError: # not all calculations have an energy
istep = {}
esteps = []
Expand Down
2 changes: 1 addition & 1 deletion tests/files/.pytest-split-durations
Original file line number Diff line number Diff line change
Expand Up @@ -2169,7 +2169,7 @@
"tests/io/vasp/test_outputs.py::TestVasprun::test_potcar_not_found": 0.1334625000017695,
"tests/io/vasp/test_outputs.py::TestVasprun::test_projected_magnetisation": 4.4185712080216035,
"tests/io/vasp/test_outputs.py::TestVasprun::test_runtype": 14.43198950093938,
"tests/io/vasp/test_outputs.py::TestVasprun::test_sc_step_overflow": 1.980604083975777,
"tests/io/vasp/test_outputs.py::TestVasprun::test_float_overflow": 1.980604083975777,
"tests/io/vasp/test_outputs.py::TestVasprun::test_search_for_potcar": 0.2289056670269929,
"tests/io/vasp/test_outputs.py::TestVasprun::test_selective_dynamics": 1.798271125066094,
"tests/io/vasp/test_outputs.py::TestVasprun::test_smart_efermi": 2.6953831250430085,
Expand Down
2 changes: 1 addition & 1 deletion tests/files/vasprun.xml.sc_overflow
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@
</varray>
</structure>
<varray name="forces" >
<v> 0.41466569 -0.04234049 0.05092706 </v>
<v> ********** -0.04234049 0.05092706 </v>
<v> 0.23840217 0.09338135 -0.08187019 </v>
<v> -0.45497113 0.03109806 -0.23055151 </v>
<v> -0.41847023 0.03902084 -0.19336882 </v>
Expand Down
12 changes: 8 additions & 4 deletions tests/io/vasp/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,17 @@ def test_smart_efermi(self):
smart_fermi = vrun.calculate_efermi()
assert smart_fermi == approx(6.0165)

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

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

0 comments on commit 52d6b8c

Please sign in to comment.