Skip to content

Commit 6fa5b87

Browse files
authored
Read NBANDS in io.vasp.outputs.Outcar init (#4195)
* add NBANDS parser * add unit test * test more vasp versions * remove repeat default arg * add overridden test
1 parent 8726f8c commit 6fa5b87

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/pymatgen/io/vasp/outputs.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,7 +2149,15 @@ def __init__(self, filename: PathLike) -> None:
21492149
self.final_fr_energy = e_fr_energy
21502150
self.data: dict = {}
21512151

2152-
# Read "total number of plane waves", NPLWV:
2152+
# Read "number of bands" (NBANDS)
2153+
self.read_pattern(
2154+
{"nbands": r"number\s+of\s+bands\s+NBANDS=\s+(\d+)"},
2155+
terminate_on_match=True,
2156+
postprocess=int,
2157+
)
2158+
self.data["nbands"] = self.data["nbands"][0][0]
2159+
2160+
# Read "total number of plane waves" (NPLWV)
21532161
self.read_pattern(
21542162
{"nplwv": r"total plane-waves NPLWV =\s+(\*{6}|\d+)"},
21552163
terminate_on_match=True,
@@ -2183,7 +2191,6 @@ def __init__(self, filename: PathLike) -> None:
21832191
# Read the drift
21842192
self.read_pattern(
21852193
{"drift": r"total drift:\s+([\.\-\d]+)\s+([\.\-\d]+)\s+([\.\-\d]+)"},
2186-
terminate_on_match=False,
21872194
postprocess=float,
21882195
)
21892196
self.drift = self.data.get("drift", [])
355 KB
Binary file not shown.

tests/io/vasp/test_outputs.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,22 @@ def test_onsite_density_matrix(self):
13271327
outcar = Outcar(f"{VASP_OUT_DIR}/OUTCAR_merged_numbers2")
13281328
assert "onsite_density_matrices" in outcar.as_dict()
13291329

1330+
def test_nbands(self):
1331+
# Test VASP 5.2.11
1332+
nbands = Outcar(f"{VASP_OUT_DIR}/OUTCAR.gz").data["nbands"]
1333+
assert nbands == 33
1334+
assert isinstance(nbands, int)
1335+
1336+
# Test VASP 5.4.4
1337+
assert Outcar(f"{VASP_OUT_DIR}/OUTCAR.LOPTICS.vasp544").data["nbands"] == 128
1338+
1339+
# Test VASP 6.3.0
1340+
assert Outcar(f"{VASP_OUT_DIR}/OUTCAR_vasp_6.3.gz").data["nbands"] == 64
1341+
1342+
# Test NBANDS set by user but overridden by VASP
1343+
# VASP 6.3.2
1344+
assert Outcar(f"{VASP_OUT_DIR}/OUTCAR.nbands_overridden.gz").data["nbands"] == 32
1345+
13301346
def test_nplwvs(self):
13311347
outcar = Outcar(f"{VASP_OUT_DIR}/OUTCAR.gz")
13321348
assert outcar.data["nplwv"] == [[34560]]

0 commit comments

Comments
 (0)