materialsproject / pymatgen

Python Materials Genomics (pymatgen) is a robust materials analysis code that defines classes for structures and molecules with support for many electronic structure codes. It powers the Materials Project.
https://pymatgen.org
Other
1.51k stars 863 forks source link

Improper parsing of `METAGGA` flag in `Vasprun` parser #3667

Closed Andrew-S-Rosen closed 8 months ago

Andrew-S-Rosen commented 8 months ago

Python version

3.9+

Pymatgen version

2024.3.1

Operating system version

No response

Current behavior

The Vasprun parser is not properly parsing the METAGGA flag, which can introduce some painful downstream effects related to MP (see my original report in emmet https://github.com/materialsproject/emmet/issues/960).

from pymatgen.io.vasp import Vasprun

vr = Vasprun("vasprun.xml.gz")
print(vr.parameters["METAGGA"]) # raises a KeyError

vasprun.xml.gz

My guess is because that even though

  <i type="string" name="METAGGA"> R2scan</i>

is in the <incar> section, it's not elsewhere in the file. I can confirm the meta-GGA is applied in the OUTCAR.

If I recall correctly, this omission in the vasprun.xml was present in certain older versions of VASP, but perhaps it was fixed more recently? It'd be good to confirm this with VASP 6.4.

Maybe the solution here is to get a dictionary of parameters form the incar field and then merge the two dictionaries, with that from the incar field having lower priority.

DanielYang59 commented 8 months ago

I just had a quick look (quite busy this week sorry) and found this seems not specific to METAGGA, for example print(vr.parameters["ALGO"]) would also trigger KeyError: 'ALGO'. Not sure about the reason though.

Meanwhile Vasprun indeed got these tags as .incar but not into .parameters (haven't got time to look into):

print(vr.incar)

ALGO = All
EDIFF = 1e-05
EDIFFG = -0.02
ENAUG = 1360.0
ENCUT = 680.0
IBRION = 2
ICHARG = 1
ISIF = 3
ISMEAR = 2
ISPIN = 2
KPAR = 4
KSPACING = 0.22
LAECHG = True
LASPH = True
LCHARG = True
LELF = False
LMAXMIX = 6
LMIXTAU = True
LREAL = Auto
LVTOT = True
LWAVE = False
MAGMOM = 3*0.6
METAGGA = R2scan
NELM = 200
NPAR = 4
NSW = 99
PREC = Accurate
SIGMA = 0.14

A side note, docstring for the internal _parse method is completely missing (I could help add one if no one else volunteer):https://github.com/materialsproject/pymatgen/blob/442d740eb7794d360cb35f187e271b3debb7f047/pymatgen/io/vasp/outputs.py#L326-L337

Andrew-S-Rosen commented 8 months ago

@DanielYang59 it looks like ALGO is also missing from the <parameters> section of the vasprun.xml file, hence why it too was not showing up.

To summarize, it seems the there are several parameters that are strangely omitted from the <parameters> section of the vasprun.xml even though they are valid in the <incar> (and other) sections. This then causes the KeyError.

I'm not exactly sure the best way to handle this one because vr.parameters is indeed reporting accurate information, and populating it with flags from other fields seems perhaps unwise. My concern is mostly with codes that use this information to get the run_type, like to generate the MP compatibility data. But I guess that should be handled in those packages directly.

So, perhaps this should be closed and handled elsewhere where needed? Hopefully this was an issue resolved in newer versions of VASP.

Andrew-S-Rosen commented 8 months ago

Closing this as a VASP bug, not a pymatgen bug.