pymatgen icon indicating copy to clipboard operation
pymatgen copied to clipboard

Support parsing of NBANDS from a VASP OUTCAR file

Open Andrew-S-Rosen opened this issue 1 year ago • 0 comments

Feature Requested

In VASP, the NBANDS parameter describes the number of bands. It can be modified on-the-fly by VASP, potentially even overriding the setting chosen by the user. This is done based on the number of cores requested for the calculation. Therefore, knowing the NBANDS VASP actually uses is quite useful. This information is available in the OUTCAR but is not currently parsed. We should add support for this as an attribute of pymatgen.io.vasp.outputs.Outcar (see below).

Proposed Solution

In Custodian, we have a block of code that looks like:

nbands = None
with open(os.path.join(directory, "OUTCAR")) as file:
    for line in file:
        # Have to take the last NBANDS line since sometimes VASP
        # updates it automatically even if the user specifies it.
        # The last one is marked by NBANDS= (no space).
        if "NBANDS=" in line:
            try:
                d = line.split("=")
                nbands = int(d[-1].strip())
                break
            except (IndexError, ValueError):
                pass

We can basically port this over to Pymatgen's pymatgen.io.vasp.outputs.Outcar class as a .nbands attribute (and then remove the code block from Custodian).

Relevant Information

No response

Andrew-S-Rosen avatar May 21 '24 15:05 Andrew-S-Rosen