Skip to content

Commit d677a0a

Browse files
Fix Vasprun.get_potcars search method; tweak fake POTCARs (#3587)
* Fix Vasprun Potcar search in cases where no leading is specified * change potcar scrambling to not affect titel, update test files * Update and test comments to cite issue * fix tests * fix str | Path | bool type anno, remove debug print * requirements.txt fix bad merge conflict resolution * maybe fix failing TestPhaseDiagram.test_read_json * revert monty==2024.1.23 see materialsvirtuallab/monty#610 * setup.py monty<=2024.1.26 --------- Co-authored-by: Janosh Riebesell <[email protected]>
1 parent 75ca0a7 commit d677a0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+76
-5481
lines changed

dev_scripts/potcar_scrambler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def scramble_single_potcar(self, potcar: PotcarSingle):
114114

115115
aux_str = ""
116116
if "TITEL" in line:
117-
aux_str = " FAKE"
117+
aux_str = " ; FAKE"
118118
scrambled_potcar_str += f"{cline}{aux_str}\n"
119119

120120
if needs_sha256:

pymatgen/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
__maintainer__ = "Shyue Ping Ong, Matthew Horton, Janosh Riebesell"
3636
__maintainer_email__ = "[email protected]"
3737
try:
38-
__version__ = "2024.1.27"
38+
__version__ = version("pymatgen")
3939
except PackageNotFoundError: # pragma: no cover
4040
# package is not installed
4141
pass

pymatgen/core/libxcfunc.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,16 +482,12 @@ def is_hyb_mgga_family(self) -> bool:
482482
return self.family == "HYB_MGGA"
483483

484484
def as_dict(self):
485-
"""Makes LibxcFunc obey the general json interface used in pymatgen for
486-
easier serialization.
487-
"""
485+
"""Serialize to MSONable dict representation e.g. to write to disk as JSON."""
488486
return {"name": self.name, "@module": type(self).__module__, "@class": type(self).__name__}
489487

490488
@classmethod
491-
def from_dict(cls, dct):
492-
"""Makes LibxcFunc obey the general json interface used in pymatgen for
493-
easier serialization.
494-
"""
489+
def from_dict(cls, dct: dict) -> LibxcFunc:
490+
"""Deserialize from MSONable dict representation."""
495491
return cls[dct["name"]]
496492

497493
def to_json(self):

pymatgen/core/periodic_table.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -747,22 +747,14 @@ def iupac_ordering(self):
747747
def __deepcopy__(self, memo):
748748
return Element(self.symbol)
749749

750-
@staticmethod
751-
def from_dict(d) -> Element:
752-
"""Makes Element obey the general json interface used in pymatgen for
753-
easier serialization.
754-
"""
755-
return Element(d["element"])
756-
757750
def as_dict(self) -> dict[Literal["element", "@module", "@class"], str]:
758-
"""Makes Element obey the general json interface used in pymatgen for
759-
easier serialization.
760-
"""
761-
return {
762-
"@module": type(self).__module__,
763-
"@class": type(self).__name__,
764-
"element": self.symbol,
765-
}
751+
"""Serialize to MSONable dict representation e.g. to write to disk as JSON."""
752+
return {"@module": type(self).__module__, "@class": type(self).__name__, "element": self.symbol}
753+
754+
@staticmethod
755+
def from_dict(dct: dict) -> Element:
756+
"""Deserialize from MSONable dict representation."""
757+
return Element(dct["element"])
766758

767759
@staticmethod
768760
def print_periodic_table(filter_function: Callable | None = None) -> None:

pymatgen/core/xcfunc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,8 @@ def from_type_name(cls, typ, name):
173173
xc = LibxcFunc[name]
174174
return cls(xc=xc)
175175

176-
@classmethod
177-
def from_dict(cls, d):
178-
"""Makes XcFunc obey the general json interface used in pymatgen for easier serialization."""
179-
return cls(xc=d.get("xc"), x=d.get("x"), c=d.get("c"))
180-
181176
def as_dict(self):
182-
"""Makes XcFunc obey the general json interface used in pymatgen for easier serialization."""
177+
"""Serialize to MSONable dict representation e.g. to write to disk as JSON."""
183178
dct = {"@module": type(self).__module__, "@class": type(self).__name__}
184179
if self.x is not None:
185180
dct["x"] = self.x.as_dict()
@@ -189,6 +184,11 @@ def as_dict(self):
189184
dct["xc"] = self.xc.as_dict()
190185
return dct
191186

187+
@classmethod
188+
def from_dict(cls, dct):
189+
"""Deserialize from MSONable dict representation."""
190+
return cls(xc=dct.get("xc"), x=dct.get("x"), c=dct.get("c"))
191+
192192
def __init__(self, xc=None, x=None, c=None) -> None:
193193
"""
194194
Args:

pymatgen/io/vasp/outputs.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -988,12 +988,12 @@ def get_vbm_cbm(fermi):
988988
# it is actually a metal
989989
return self.efermi
990990

991-
def get_potcars(self, path: str | Path) -> Potcar | None:
992-
"""
993-
Returns the POTCAR from the specified path.
991+
def get_potcars(self, path: str | Path | bool) -> Potcar | None:
992+
"""Returns the POTCAR from the specified path.
994993
995994
Args:
996-
path (str | Path): The path to search for POTCARs.
995+
path (str | Path | bool): If a str or Path, the path to search for POTCARs.
996+
If a bool, whether to take the search path from the specified vasprun.xml
997997
998998
Returns:
999999
Potcar | None: The POTCAR from the specified path or None if not found/no path specified.
@@ -1005,7 +1005,10 @@ def get_potcars(self, path: str | Path) -> Potcar | None:
10051005
if isinstance(path, (str, Path)) and "POTCAR" in str(path):
10061006
potcar_paths = [str(path)]
10071007
else:
1008-
search_path = os.path.split(self.filename)[0] if path is True else str(path)
1008+
# the abspath is needed here in cases where no leading directory is specified,
1009+
# e.g., Vasprun("vasprun.xml"). see gh-3586:
1010+
search_path = os.path.dirname(os.path.abspath(self.filename)) if path is True else str(path)
1011+
10091012
potcar_paths = [
10101013
f"{search_path}/{fn}" for fn in os.listdir(search_path) if fn.startswith("POTCAR") and ".spec" not in fn
10111014
]

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
numpy==1.25.2
22
sympy==1.11.1
33
requests==2.31.0
4-
monty==2024.1.26
5-
>>>>>>> bee080171 (Fix monty version.)
4+
monty==2024.1.23
65
ruamel.yaml==0.17.32
76
scipy==1.11.2
87
tabulate==0.9.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
python_requires=">=3.9",
3030
install_requires=[
3131
"matplotlib>=1.5",
32-
"monty>=3.0.2",
32+
"monty<=2024.1.26", # https://github.com/materialsvirtuallab/monty/issues/610
3333
"networkx>=2.2",
3434
"numpy>=1.25.0",
3535
"palettable>=3.1.1",

tests/analysis/test_phase_diagram.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ def test_read_json(self):
614614
dumpfn(self.pd, f"{self.tmp_path}/pd.json")
615615
pd = loadfn(f"{self.tmp_path}/pd.json")
616616
assert isinstance(pd, PhaseDiagram)
617+
assert pd.elements == self.pd.elements
617618
assert {*pd.as_dict()} == {*self.pd.as_dict()}
618619

619620
def test_el_refs(self):

0 commit comments

Comments
 (0)