From fa58d0df8cf45cc70ea597ce8013f32db9628a7e Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Sat, 19 Oct 2024 14:23:34 +0800 Subject: [PATCH] fix index error for vasprun --- src/pymatgen/io/vasp/outputs.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pymatgen/io/vasp/outputs.py b/src/pymatgen/io/vasp/outputs.py index 1c0536534a8..0fa06737e10 100644 --- a/src/pymatgen/io/vasp/outputs.py +++ b/src/pymatgen/io/vasp/outputs.py @@ -140,7 +140,7 @@ def _parse_from_incar(filename: PathLike, key: str) -> Any: dirname = os.path.dirname(filename) for fn in os.listdir(dirname): if re.search("INCAR", fn): - warnings.warn(f"INCAR found. Using {key} from INCAR.") + warnings.warn(f"INCAR found. Using {key} from INCAR.", stacklevel=2) incar = Incar.from_file(os.path.join(dirname, fn)) return incar.get(key, None) return None @@ -345,7 +345,7 @@ def __init__( self.update_potcar_spec(parse_potcar_file) self.update_charge_from_potcar(parse_potcar_file) - if self.incar.get("ALGO") not in {"CHI", "BSE"} and not self.converged and self.parameters.get("IBRION") != 0: + if self.incar.get("ALGO") not in {"Chi", "Bse"} and not self.converged and self.parameters.get("IBRION") != 0: msg = f"{filename} is an unconverged VASP run.\n" msg += f"Electronic convergence reached: {self.converged_electronic}.\n" msg += f"Ionic convergence reached: {self.converged_ionic}." @@ -364,10 +364,10 @@ def _parse( self.projected_magnetisation: NDArray | None = None self.dielectric_data: dict[str, tuple] = {} self.other_dielectric: dict[str, tuple] = {} - self.incar: dict[str, Any] = {} + self.incar: Incar = {} self.kpoints_opt_props: KpointOptProps | None = None - ionic_steps: list = [] + ionic_steps: list[dict] = [] md_data: list[dict] = [] parsed_header: bool = False @@ -1355,9 +1355,9 @@ def as_dict(self) -> dict: dct["output"] = vout return jsanitize(dct, strict=True) - def _parse_params(self, elem: XML_Element) -> dict: - """Parse INCAR parameters.""" - params: dict = {} + def _parse_params(self, elem: XML_Element) -> Incar[str, Any]: + """Parse INCAR parameters and more.""" + params: dict[str, Any] = {} for c in elem: # VASP 6.4.3 can add trailing whitespace # for example, PE @@ -1369,6 +1369,7 @@ def _parse_params(self, elem: XML_Element) -> dict: # which overrides the values in the root params. p = {k: v for k, v in p.items() if k not in params} params |= p + else: ptype = c.attrib.get("type", "") val = c.text.strip() if c.text else ""