Skip to content

Parse bad float values in vasprun.xml for MD runs and OSZICAR #4537

@DaanHolleman

Description

@DaanHolleman

Python version

3.9.18

Pymatgen version

2024.8.9 / 2025.10.7

Operating system version

Red Hat Enterprise Linux 9.4

Current behavior

Vaspruns or Oszicars with unconverged ionic steps have ******** to indicate a wrong value but this throws an exception when trying to convert to float.

The parser should still parse these files as it is still interesting to see how the energies behaved up until this point.

Expected Behavior

Convert the ***** string to nan and raise a warning. There already exists a function for this called _vasprun_float

Minimal example

Use the following for an OSZICAR file:
       N       E                     dE             d eps       ncg     rms          rms(c)
DAV:   1     0.831012218308E+03    0.83101E+03   -0.25939E+05  4672   0.894E+02
DAV:   2    -0.461632861706E+04   -0.54473E+04   -0.53016E+04  5716   0.208E+02
DAV:   3    -0.541060909256E+04   -0.79428E+03   -0.78895E+03  5280   0.860E+01
DAV:   4    -0.544402022598E+04   -0.33411E+02   -0.33288E+02  5632   0.205E+01
          1 T= ****** E= 0.64876404E+06 F= 0.49220367E+06 E0= 0.49220367E+06  EK= 0.15656E+06 SP= 0.00E+00 SK= 0.00E+00

Then try to load the file:

from pymatgen.io.vasp import Oszicar
Oszicar('OSZICAR')

Relevant files to reproduce this bug

The float conversion in these places could maybe be changed to _vasprun_float

This one for vasprun.xml files

elif tag == "energy":
d = {i.attrib["name"]: float(i.text) for i in elem.findall("i")} # type:ignore[arg-type]
if "kinetic" in d:
md_data[-1]["energy"] = {i.attrib["name"]: float(i.text) for i in elem.findall("i")} # type:ignore[arg-type]

This one for Oszicar files

ionic_steps.append({key: float(value) for key, value in matches})

There might be more places where the float needs to be converted

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions