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

Make Incar keys case insensitive, fix init Incar from dict val processing for str/float/int #4122

Merged
merged 37 commits into from
Oct 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b9b3804
move ENCUT from int to float list
DanielYang59 Oct 18, 2024
a5ba6ca
remove str case sensitivity in check_params
DanielYang59 Oct 18, 2024
60e1a48
fix return type annotation
DanielYang59 Oct 18, 2024
945368b
fix unit test failure
DanielYang59 Oct 18, 2024
f0ebb34
use original key for warning msg
DanielYang59 Oct 18, 2024
37ac9f5
add duplicate check in check_params
DanielYang59 Oct 18, 2024
13b5a67
add test first, issue not fixed yet
DanielYang59 Oct 18, 2024
adcdba7
init from dict also use setter method and fix val filter logic
DanielYang59 Oct 18, 2024
bae2320
relocate test_from_file_and_from_dict
DanielYang59 Oct 18, 2024
44a06c3
Revert "init from dict also use setter method and fix val filter logic"
DanielYang59 Oct 18, 2024
6799044
remove seemingly unused monkeypatch
DanielYang59 Oct 18, 2024
966bb91
tweak type
DanielYang59 Oct 18, 2024
532cad0
make module level var all cap
DanielYang59 Oct 18, 2024
a24ac8e
casting to list doesn't seem necessary, remain iterator for lazy eval
DanielYang59 Oct 18, 2024
92bfc7e
add docstring to clarify parse list
DanielYang59 Oct 18, 2024
f1fb45b
Merge branch 'master' into fix-4119-incar-tag-check
shyuep Oct 18, 2024
fdc40b8
Merge branch 'master' into fix-4119-incar-tag-check
DanielYang59 Oct 18, 2024
552c006
Merge branch 'fix-4119-incar-tag-check' of https://github.com/DanielY…
DanielYang59 Oct 18, 2024
536eae5
remove duplicate check
DanielYang59 Oct 19, 2024
ba0f349
reduce indentation level
DanielYang59 Oct 19, 2024
198ce83
remove docstring of warn that doesn't exist
DanielYang59 Oct 19, 2024
a2da974
fix typo in incar tag ECUT -> ENCUT
DanielYang59 Oct 19, 2024
435320d
inherit from UserDict, and make more ops case insensitive
DanielYang59 Oct 19, 2024
51f5922
also override del and in methdos
DanielYang59 Oct 19, 2024
3b231be
issue warning for duplicate keys
DanielYang59 Oct 19, 2024
dbaaa98
enhance warning check
DanielYang59 Oct 19, 2024
f8b223c
tweak docstring
DanielYang59 Oct 19, 2024
f30e740
fix type of float/int casting
DanielYang59 Oct 19, 2024
259124d
enhance test for from_dict consistency check
DanielYang59 Oct 19, 2024
96ad945
relocate duplicate check to setter so that both from str and dict wou…
DanielYang59 Oct 19, 2024
fa58d0d
fix index error for vasprun
DanielYang59 Oct 19, 2024
8d5768e
move duplicate warning to init otherwise get false pos when update
DanielYang59 Oct 19, 2024
c350714
enhance unit test from type cast from dict
DanielYang59 Oct 19, 2024
48d2755
remove unnecessary get default
DanielYang59 Oct 19, 2024
b2e9a63
remove unnecessary type cast in check_params
DanielYang59 Oct 19, 2024
9dc98f9
tweak Incar docstring
DanielYang59 Oct 19, 2024
837a011
Merge branch 'master' into fix-4119-incar-tag-check
DanielYang59 Oct 21, 2024
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
15 changes: 8 additions & 7 deletions src/pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Copy link
Contributor Author

@DanielYang59 DanielYang59 Oct 19, 2024

Choose a reason for hiding this comment

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

Before migrating to subclassing UserDict, the setter method is not triggered through update method when init from a dict, therefore these values remain as is (BSE) when it should be capitalized (Bse).

def __init__(self, params: dict[str, Any] | None = None) -> None:
"""
Create an Incar object.
Args:
params (dict): Input parameters as a dictionary.
"""
super().__init__()
if params is not None:
# If INCAR contains vector-like MAGMOMS given as a list
# of floats, convert to a list of lists
if (params.get("MAGMOM") and isinstance(params["MAGMOM"][0], int | float)) and (
params.get("LSORBIT") or params.get("LNONCOLLINEAR")
):
val = []
for idx in range(len(params["MAGMOM"]) // 3):
val.append(params["MAGMOM"][idx * 3 : (idx + 1) * 3])
params["MAGMOM"] = val
self.update(params)

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}."
Expand All @@ -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
Expand Down Expand Up @@ -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, <i type="string" name="GGA ">PE</i>
Expand All @@ -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 ""
Expand Down
Loading