Skip to content

Commit e4139b1

Browse files
committed
rename similar->same param in diff method
1 parent e28003f commit e4139b1

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

src/pymatgen/io/vasp/inputs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,21 +1117,21 @@ def diff(self, other: Self) -> dict[str, dict[str, Any]]:
11171117
{"Same" : parameters_that_are_the_same, "Different": parameters_that_are_different}
11181118
Note that the parameters are return as full dictionaries of values. E.g. {"ISIF":3}
11191119
"""
1120-
similar_params = {}
1120+
same_params = {}
11211121
different_params = {}
11221122
for k1, v1 in self.items():
11231123
if k1 not in other:
11241124
different_params[k1] = {"INCAR1": v1, "INCAR2": None}
11251125
elif v1 != other[k1]:
11261126
different_params[k1] = {"INCAR1": v1, "INCAR2": other[k1]}
11271127
else:
1128-
similar_params[k1] = v1
1128+
same_params[k1] = v1
11291129

11301130
for k2, v2 in other.items():
1131-
if k2 not in similar_params and k2 not in different_params and k2 not in self:
1131+
if k2 not in same_params and k2 not in different_params and k2 not in self:
11321132
different_params[k2] = {"INCAR1": None, "INCAR2": v2}
11331133

1134-
return {"Same": similar_params, "Different": different_params}
1134+
return {"Same": same_params, "Different": different_params}
11351135

11361136
def check_params(self) -> None:
11371137
"""Check INCAR for invalid tags or values.

tests/io/vasp/test_inputs.py

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -886,22 +886,34 @@ def test_write(self):
886886
incar = Incar.from_file(tmp_file)
887887
assert incar == self.incar
888888

889-
def test_from_str_multiline_str(self):
889+
def test_from_str_complex(self):
890890
r"""Test of handling complex INCAR:
891891
- Multiple statements on a single line separated by semicolon
892892
- Comments marked by hashtag # or exclamation mark !
893893
- Ignore lines does not fit (tag = values) statement format
894894
- Long lines split by backslash \
895895
- Multi-line strings (comment would not be ignored), e.g. WANNIER90_WIN
896+
897+
TODO:
898+
- test line-ending char independence
899+
- test cast casting for multi-line string (auto-capitalization?)
896900
"""
897901
incar_str = r"""
902+
# Test comment handling (especially for string tags)
903+
SIGMA = 0.05 # random comment (known float tag)
904+
EDIFF = 1e-6 ! another comment (known float tag)
905+
ALGO = Normal # comment (unknown tag -> inferred as str)
906+
GGA = PE ! comment (unknown tag -> inferred as str)
907+
898908
# Test interaction between semicolon and comment
899909
ENCUT = 520; ISMEAR = 0 # smearing scheme
900910
PREC = Accurate ; LREAL = Auto ! precision and projection scheme
901-
SIGMA = 0.05 # random comment with hashtag
902-
EDIFF = 1e-6 ! another comment with exclamation mark
911+
NELM = 60; ! ENCUT = 200 # should not parse second assignment
912+
ENMIN = 100; # ENCUT = 200 # should not parse second assignment
903913
904-
# Line continuation with backslash
914+
# Line continuation with backslash (backslash in comment)
915+
ENMAX = 200 ! \
916+
IBRION = 0 # \
905917
MAGMOM = 0 0 1.0 0 0 -1.0 \
906918
0 0 1.0 0 0 -1.0 \
907919
6*0
@@ -912,11 +924,13 @@ def test_from_str_multiline_str(self):
912924
End Projections ! random comment
913925
"
914926
915-
! invalid statement (tag = values)
927+
# Test valid statement (tag = values) in comment
916928
! invalid ENCUT = 100
917929
# still invalid ENCUT = 200
930+
931+
# Test invalid statement (tag = values)
918932
Not a valid statement
919-
ENCUT
933+
ENCUT 300
920934
"""
921935

922936
incar = Incar.from_str(incar_str)
@@ -926,20 +940,32 @@ def test_from_str_multiline_str(self):
926940
"ISMEAR",
927941
"PREC",
928942
"LREAL",
943+
"NELM",
944+
"ENMIN",
945+
"ENMAX",
946+
"IBRION",
947+
"ALGO",
948+
"GGA",
929949
"SIGMA",
930950
"EDIFF",
931951
"MAGMOM",
932952
"WANNIER90_WIN",
933953
}
934954
assert set(incar.keys()) == expected_keys
935955

936-
# Basic parsing
956+
# Comment handling
937957
assert incar["SIGMA"] == approx(0.05)
938958
assert incar["EDIFF"] == approx(1e-6)
959+
assert incar["ALGO"] == "Normal"
960+
assert incar["GGA"] == "Pe"
939961

940962
# Line with both ; and comment
941963
assert incar["ENCUT"] == 520
942964
assert incar["ISMEAR"] == 0
965+
assert incar["NELM"] == 60
966+
assert incar["ENMIN"] == 100
967+
assert incar["ENMAX"] == 200
968+
assert incar["IBRION"] == 0
943969
assert incar["PREC"].lower() == "accurate"
944970
assert incar["LREAL"].lower() == "auto"
945971

@@ -953,6 +979,12 @@ def test_from_str_multiline_str(self):
953979
# Comments and structure inside string should be preserved exactly
954980
assert win.strip() == expected_win.strip()
955981

982+
def test_from_str_not_closed_multi_line_str(self):
983+
"""Test not closed (no ending quote) multi-line string.
984+
985+
TODO:
986+
"""
987+
956988
def test_get_str(self):
957989
incar_str = self.incar.get_str(pretty=True, sort_keys=True)
958990
expected = """ALGO = Damped
@@ -1070,6 +1102,7 @@ def test_types(self):
10701102

10711103
def test_proc_types(self):
10721104
assert Incar.proc_val("HELLO", "-0.85 0.85") == "-0.85 0.85"
1105+
# `ML_MODE` should always be lower case
10731106
assert Incar.proc_val("ML_MODE", "train") == "train"
10741107
assert Incar.proc_val("ML_MODE", "RUN") == "run"
10751108
assert Incar.proc_val("ALGO", "fast") == "Fast"

0 commit comments

Comments
 (0)