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

Fix Vasprun.get_potcars search method; tweak fake POTCARs #3587

Merged
merged 10 commits into from
Jan 28, 2024
2 changes: 1 addition & 1 deletion dev_scripts/potcar_scrambler.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def scramble_single_potcar(self, potcar: PotcarSingle):

aux_str = ""
if "TITEL" in line:
aux_str = " FAKE"
aux_str = " ; FAKE"
scrambled_potcar_str += f"{cline}{aux_str}\n"

if needs_sha256:
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
__maintainer__ = "Shyue Ping Ong, Matthew Horton, Janosh Riebesell"
__maintainer_email__ = "shyuep@gmail.com"
try:
__version__ = "2024.1.27"
__version__ = version("pymatgen")
except PackageNotFoundError: # pragma: no cover
# package is not installed
pass
Expand Down
10 changes: 3 additions & 7 deletions pymatgen/core/libxcfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,16 +482,12 @@ def is_hyb_mgga_family(self) -> bool:
return self.family == "HYB_MGGA"

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

@classmethod
def from_dict(cls, dct):
"""Makes LibxcFunc obey the general json interface used in pymatgen for
easier serialization.
"""
def from_dict(cls, dct: dict) -> LibxcFunc:
"""Deserialize from MSONable dict representation."""
return cls[dct["name"]]

def to_json(self):
Expand Down
22 changes: 7 additions & 15 deletions pymatgen/core/periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,22 +747,14 @@ def iupac_ordering(self):
def __deepcopy__(self, memo):
return Element(self.symbol)

@staticmethod
def from_dict(d) -> Element:
"""Makes Element obey the general json interface used in pymatgen for
easier serialization.
"""
return Element(d["element"])

def as_dict(self) -> dict[Literal["element", "@module", "@class"], str]:
"""Makes Element obey the general json interface used in pymatgen for
easier serialization.
"""
return {
"@module": type(self).__module__,
"@class": type(self).__name__,
"element": self.symbol,
}
"""Serialize to MSONable dict representation e.g. to write to disk as JSON."""
return {"@module": type(self).__module__, "@class": type(self).__name__, "element": self.symbol}

@staticmethod
def from_dict(dct: dict) -> Element:
"""Deserialize from MSONable dict representation."""
return Element(dct["element"])

@staticmethod
def print_periodic_table(filter_function: Callable | None = None) -> None:
Expand Down
12 changes: 6 additions & 6 deletions pymatgen/core/xcfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,8 @@ def from_type_name(cls, typ, name):
xc = LibxcFunc[name]
return cls(xc=xc)

@classmethod
def from_dict(cls, d):
"""Makes XcFunc obey the general json interface used in pymatgen for easier serialization."""
return cls(xc=d.get("xc"), x=d.get("x"), c=d.get("c"))

def as_dict(self):
"""Makes XcFunc obey the general json interface used in pymatgen for easier serialization."""
"""Serialize to MSONable dict representation e.g. to write to disk as JSON."""
dct = {"@module": type(self).__module__, "@class": type(self).__name__}
if self.x is not None:
dct["x"] = self.x.as_dict()
Expand All @@ -189,6 +184,11 @@ def as_dict(self):
dct["xc"] = self.xc.as_dict()
return dct

@classmethod
def from_dict(cls, dct):
"""Deserialize from MSONable dict representation."""
return cls(xc=dct.get("xc"), x=dct.get("x"), c=dct.get("c"))

def __init__(self, xc=None, x=None, c=None) -> None:
"""
Args:
Expand Down
13 changes: 8 additions & 5 deletions pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,12 +988,12 @@ def get_vbm_cbm(fermi):
# it is actually a metal
return self.efermi

def get_potcars(self, path: str | Path) -> Potcar | None:
"""
Returns the POTCAR from the specified path.
def get_potcars(self, path: str | Path | bool) -> Potcar | None:
"""Returns the POTCAR from the specified path.
Args:
path (str | Path): The path to search for POTCARs.
path (str | Path | bool): If a str or Path, the path to search for POTCARs.
If a bool, whether to take the search path from the specified vasprun.xml
Returns:
Potcar | None: The POTCAR from the specified path or None if not found/no path specified.
Expand All @@ -1005,7 +1005,10 @@ def get_potcars(self, path: str | Path) -> Potcar | None:
if isinstance(path, (str, Path)) and "POTCAR" in str(path):
potcar_paths = [str(path)]
else:
search_path = os.path.split(self.filename)[0] if path is True else str(path)
# the abspath is needed here in cases where no leading directory is specified,
# e.g., Vasprun("vasprun.xml"). see gh-3586:
search_path = os.path.dirname(os.path.abspath(self.filename)) if path is True else str(path)

potcar_paths = [
f"{search_path}/{fn}" for fn in os.listdir(search_path) if fn.startswith("POTCAR") and ".spec" not in fn
]
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
numpy==1.25.2
sympy==1.11.1
requests==2.31.0
monty==2024.1.26
>>>>>>> bee080171 (Fix monty version.)
monty==2024.1.23
ruamel.yaml==0.17.32
scipy==1.11.2
tabulate==0.9.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
python_requires=">=3.9",
install_requires=[
"matplotlib>=1.5",
"monty>=3.0.2",
"monty<=2024.1.26", # https://github.com/materialsvirtuallab/monty/issues/610
"networkx>=2.2",
"numpy>=1.25.0",
"palettable>=3.1.1",
Expand Down
1 change: 1 addition & 0 deletions tests/analysis/test_phase_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ def test_read_json(self):
dumpfn(self.pd, f"{self.tmp_path}/pd.json")
pd = loadfn(f"{self.tmp_path}/pd.json")
assert isinstance(pd, PhaseDiagram)
assert pd.elements == self.pd.elements
assert {*pd.as_dict()} == {*self.pd.as_dict()}

def test_el_refs(self):
Expand Down
Loading
Loading