diff --git a/src/pymatgen/io/vasp/outputs.py b/src/pymatgen/io/vasp/outputs.py index 14b116ffcbf..a8205cd7c38 100644 --- a/src/pymatgen/io/vasp/outputs.py +++ b/src/pymatgen/io/vasp/outputs.py @@ -2136,7 +2136,15 @@ def __init__(self, filename: PathLike) -> None: self.final_fr_energy = e_fr_energy self.data: dict = {} - # Read "total number of plane waves", NPLWV: + # Read "number of bands" (NBANDS) + self.read_pattern( + {"nbands": r"number\s+of\s+bands\s+NBANDS=\s+(\d+)"}, + terminate_on_match=True, + postprocess=int, + ) + self.data["nbands"] = self.data["nbands"][0][0] + + # Read "total number of plane waves" (NPLWV) self.read_pattern( {"nplwv": r"total plane-waves NPLWV =\s+(\*{6}|\d+)"}, terminate_on_match=True, @@ -2170,7 +2178,6 @@ def __init__(self, filename: PathLike) -> None: # Read the drift self.read_pattern( {"drift": r"total drift:\s+([\.\-\d]+)\s+([\.\-\d]+)\s+([\.\-\d]+)"}, - terminate_on_match=False, postprocess=float, ) self.drift = self.data.get("drift", []) diff --git a/tests/files/io/vasp/outputs/OUTCAR.nbands_overridden.gz b/tests/files/io/vasp/outputs/OUTCAR.nbands_overridden.gz new file mode 100644 index 00000000000..f69bb7acdad Binary files /dev/null and b/tests/files/io/vasp/outputs/OUTCAR.nbands_overridden.gz differ diff --git a/tests/io/vasp/test_outputs.py b/tests/io/vasp/test_outputs.py index e02b9ac027a..837884c22f0 100644 --- a/tests/io/vasp/test_outputs.py +++ b/tests/io/vasp/test_outputs.py @@ -1327,6 +1327,22 @@ def test_onsite_density_matrix(self): outcar = Outcar(f"{VASP_OUT_DIR}/OUTCAR_merged_numbers2") assert "onsite_density_matrices" in outcar.as_dict() + def test_nbands(self): + # Test VASP 5.2.11 + nbands = Outcar(f"{VASP_OUT_DIR}/OUTCAR.gz").data["nbands"] + assert nbands == 33 + assert isinstance(nbands, int) + + # Test VASP 5.4.4 + assert Outcar(f"{VASP_OUT_DIR}/OUTCAR.LOPTICS.vasp544").data["nbands"] == 128 + + # Test VASP 6.3.0 + assert Outcar(f"{VASP_OUT_DIR}/OUTCAR_vasp_6.3.gz").data["nbands"] == 64 + + # Test NBANDS set by user but overridden by VASP + # VASP 6.3.2 + assert Outcar(f"{VASP_OUT_DIR}/OUTCAR.nbands_overridden.gz").data["nbands"] == 32 + def test_nplwvs(self): outcar = Outcar(f"{VASP_OUT_DIR}/OUTCAR.gz") assert outcar.data["nplwv"] == [[34560]]