Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read NBANDS in io.vasp.outputs.Outcar init #4195

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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", [])
Expand Down
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/io/vasp/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Copy link
Contributor Author

@DanielYang59 DanielYang59 Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question

Why would the "total number of plane waves (NPLWV)" value take a nested list format (added in #1757)?

# Read "total number of plane waves", NPLWV:
self.read_pattern(
{"nplwv": r"total plane-waves NPLWV =\s+(\*{6}|\d+)"},
terminate_on_match=True,
)
try:
self.data["nplwv"] = [[int(self.data["nplwv"][0][0])]]
except ValueError:
self.data["nplwv"] = [[None]]

def test_nplwvs(self):
outcar = Outcar(f"{VASP_OUT_DIR}/OUTCAR.gz")
assert outcar.data["nplwv"] == [[34560]]

Expand Down
Loading