Skip to content

Commit

Permalink
Fix LNONCOLLINEAR match in Outcar parser (#4034)
Browse files Browse the repository at this point in the history
* revert LNONCOLLINEAR match condition

* avoid hard coding number of spaces

* NEED CONFIRM: turn on terminate_on_match for boolean tags

* put True/False in different branches

* add unit test for ncl True

* reuse existing test file

* revert using `terminate_on_match` as True
  • Loading branch information
DanielYang59 authored Sep 4, 2024
1 parent ed52258 commit 1404220
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2106,19 +2106,14 @@ def __init__(self, filename: PathLike) -> None:
self.drift = self.data.get("drift", [])

# Check if calculation is spin polarized
self.spin = False
self.read_pattern({"spin": "ISPIN = 2"})
if self.data.get("spin", []):
self.spin = True
self.read_pattern({"spin": r"ISPIN\s*=\s*2"})
self.spin = bool(self.data.get("spin", []))

# Check if calculation is non-collinear
self.noncollinear = False
self.read_pattern({"noncollinear": "LNONCOLLINEAR = T"})
if self.data.get("noncollinear", []):
self.noncollinear = False
self.read_pattern({"noncollinear": r"LNONCOLLINEAR\s*=\s*T"})
self.noncollinear = bool(self.data.get("noncollinear", []))

# Check if the calculation type is DFPT
self.dfpt = False
self.read_pattern(
{"ibrion": r"IBRION =\s+([\-\d]+)"},
terminate_on_match=True,
Expand All @@ -2127,24 +2122,28 @@ def __init__(self, filename: PathLike) -> None:
if self.data.get("ibrion", [[0]])[0][0] > 6:
self.dfpt = True
self.read_internal_strain_tensor()
else:
self.dfpt = False

# Check if LEPSILON is True and read piezo data if so
self.lepsilon = False
self.read_pattern({"epsilon": "LEPSILON= T"})
self.read_pattern({"epsilon": r"LEPSILON\s*=\s*T"})
if self.data.get("epsilon", []):
self.lepsilon = True
self.read_lepsilon()
# Only read ionic contribution if DFPT is turned on
if self.dfpt:
self.read_lepsilon_ionic()
else:
self.lepsilon = False

# Check if LCALCPOL is True and read polarization data if so
self.lcalcpol = False
self.read_pattern({"calcpol": "LCALCPOL = T"})
self.read_pattern({"calcpol": r"LCALCPOL\s*=\s*T"})
if self.data.get("calcpol", []):
self.lcalcpol = True
self.read_lcalcpol()
self.read_pseudo_zval()
else:
self.lcalcpol = False

# Read electrostatic potential
self.electrostatic_potential: list[float] | None = None
Expand All @@ -2154,30 +2153,33 @@ def __init__(self, filename: PathLike) -> None:
if self.data.get("electrostatic", []):
self.read_electrostatic_potential()

self.nmr_cs = False
self.read_pattern({"nmr_cs": r"LCHIMAG = (T)"})
self.read_pattern({"nmr_cs": r"LCHIMAG\s*=\s*(T)"})
if self.data.get("nmr_cs"):
self.nmr_cs = True
self.read_chemical_shielding()
self.read_cs_g0_contribution()
self.read_cs_core_contribution()
self.read_cs_raw_symmetrized_tensors()
else:
self.nmr_cs = False

self.nmr_efg = False
self.read_pattern({"nmr_efg": r"NMR quadrupolar parameters"})
if self.data.get("nmr_efg"):
self.nmr_efg = True
self.read_nmr_efg()
self.read_nmr_efg_tensor()
else:
self.nmr_efg = False

self.has_onsite_density_matrices = False
self.read_pattern(
{"has_onsite_density_matrices": r"onsite density matrix"},
terminate_on_match=True,
)
if "has_onsite_density_matrices" in self.data:
self.has_onsite_density_matrices = True
self.read_onsite_density_matrices()
else:
self.has_onsite_density_matrices = False

# Store the individual contributions to the final total energy
final_energy_contribs = {}
Expand Down
2 changes: 2 additions & 0 deletions tests/io/vasp/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,8 @@ def test_soc(self):
# so fine to use == operator here
assert outcar.magnetization == expected_mag, "Wrong vector magnetization read from Outcar for SOC calculation"

assert outcar.noncollinear is True

def test_polarization(self):
filepath = f"{VASP_OUT_DIR}/OUTCAR.BaTiO3.polar"
outcar = Outcar(filepath)
Expand Down

0 comments on commit 1404220

Please sign in to comment.