Skip to content

Commit

Permalink
Fixed Incar object to allow for ML_MODE vasp tag (#3625)
Browse files Browse the repository at this point in the history
* Fixed Incar object to allow for ML_MODE vasp tag which does not want to
have capitalized values (train, run, ...). By default, pymatgen
capitalizes the values of the INCAR tags (e.g. "ALGO = Fast", even if
you set incar["ALGO"] = "fast"). This is not working for the ML_MODE
tag.
Also fixed (i.e. ignored specific mypy code) random mypy errors in files
that were not touched ...

* rename lowerstr_keys -> lower_str_keys

---------

Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
  • Loading branch information
davidwaroquiers and janosh committed Feb 15, 2024
1 parent 988da0c commit d44363e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pymatgen/core/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
conversion factors. What matters is the relative values, not the absolute.
The SI units must have factor 1.
"""
BASE_UNITS = {
BASE_UNITS: dict[str, dict] = {
"length": {
"m": 1,
"km": 1000,
Expand Down
4 changes: 4 additions & 0 deletions pymatgen/io/vasp/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ def proc_val(key: str, val: Any):
"LDAUTYPE",
"IVDW",
)
lower_str_keys = ("ML_MODE",)

def smart_int_or_float(num_str):
if num_str.find(".") != -1 or num_str.lower().find("e") != -1:
Expand Down Expand Up @@ -904,6 +905,9 @@ def smart_int_or_float(num_str):
if key in int_keys:
return int(re.match(r"^-?[0-9]+", val).group(0)) # type: ignore

if key in lower_str_keys:
return val.strip().lower()

except ValueError:
pass

Expand Down
3 changes: 3 additions & 0 deletions tests/io/vasp/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,9 @@ def test_types(self):

def test_proc_types(self):
assert Incar.proc_val("HELLO", "-0.85 0.85") == "-0.85 0.85"
assert Incar.proc_val("ML_MODE", "train") == "train"
assert Incar.proc_val("ML_MODE", "RUN") == "run"
assert Incar.proc_val("ALGO", "fast") == "Fast"

def test_check_params(self):
# Triggers warnings when running into invalid parameters
Expand Down

0 comments on commit d44363e

Please sign in to comment.