Skip to content

Commit d8ed585

Browse files
authored
Merge branch 'master' into hotfix/pmg-io-vasp-MPScanRelaxSet
2 parents 21b9e03 + b985b94 commit d8ed585

File tree

4 files changed

+39
-25
lines changed

4 files changed

+39
-25
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
__pycache__/
22
.DS_Store
3-
pymatgen.egg-info
3+
*.egg-info
44
*.o
55
*.so
66
*.pyc
77
*.swp
88
*.swo
99
*.pyd
1010
*.c
11-
pymatgen/pymatgen.cfg
1211
dist
1312
_build
1413
_site
@@ -21,13 +20,12 @@ build
2120
setuptools*
2221
.ipynb_checkpoints
2322
.cache
24-
.tox
2523
.eggs/
2624
.coverage
2725
.*_cache
2826
# VS Code
2927
.vscode/*
30-
28+
*.code-workspace
3129
# Environments
3230
.env
3331
.venv

src/pymatgen/analysis/phase_diagram.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,17 @@ def __init__(
389389

390390
def as_dict(self):
391391
"""Get MSONable dict representation of PhaseDiagram."""
392+
393+
qhull_entry_indices = [self.all_entries.index(e) for e in self.qhull_entries]
394+
392395
return {
393396
"@module": type(self).__module__,
394397
"@class": type(self).__name__,
395-
"all_entries": [e.as_dict() for e in self.all_entries],
396398
"elements": [e.as_dict() for e in self.elements],
397-
"computed_data": self.computed_data,
399+
"computed_data": self.computed_data
400+
| {
401+
"qhull_entries": qhull_entry_indices,
402+
},
398403
}
399404

400405
@classmethod
@@ -406,9 +411,19 @@ def from_dict(cls, dct: dict[str, Any]) -> Self:
406411
Returns:
407412
PhaseDiagram
408413
"""
409-
entries = [MontyDecoder().process_decoded(entry) for entry in dct["all_entries"]]
410-
elements = [Element.from_dict(elem) for elem in dct["elements"]]
411414
computed_data = dct.get("computed_data")
415+
elements = [Element.from_dict(elem) for elem in dct["elements"]]
416+
417+
# for backwards compatibility, check for old format
418+
if "all_entries" in dct:
419+
entries = [MontyDecoder().process_decoded(entry) for entry in dct["all_entries"]]
420+
else:
421+
entries = [MontyDecoder().process_decoded(entry) for entry in computed_data["all_entries"]]
422+
423+
complete_qhull_entries = [computed_data["all_entries"][i] for i in computed_data["qhull_entries"]]
424+
425+
computed_data = computed_data | {"qhull_entries": complete_qhull_entries}
426+
412427
return cls(entries, elements, computed_data=computed_data)
413428

414429
def _compute(self) -> dict[str, Any]:
@@ -1609,7 +1624,7 @@ class PatchedPhaseDiagram(PhaseDiagram):
16091624

16101625
def __init__(
16111626
self,
1612-
entries: Sequence[PDEntry] | set[PDEntry],
1627+
entries: Sequence[Entry] | set[Entry],
16131628
elements: Sequence[Element] | None = None,
16141629
keep_all_spaces: bool = False,
16151630
verbose: bool = False,

src/pymatgen/entries/compatibility.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010
import warnings
1111
from collections import defaultdict
12-
from typing import TYPE_CHECKING, TypeAlias, cast
12+
from typing import TYPE_CHECKING, TypeAlias, TypeVar, cast
1313

1414
import numpy as np
1515
from joblib import Parallel, delayed
@@ -77,6 +77,7 @@
7777
raise RuntimeError("MP2020Compatibility.yaml expected to have the same Hubbard U corrections for O and F")
7878

7979
AnyComputedEntry: TypeAlias = ComputedEntry | ComputedStructureEntry
80+
TypeVarAnyEntry = TypeVar("TypeVarAnyEntry", bound=AnyComputedEntry)
8081

8182

8283
class CompatibilityError(Exception):
@@ -577,10 +578,10 @@ def get_adjustments(self, entry: AnyComputedEntry) -> list[EnergyAdjustment]:
577578

578579
def process_entry(
579580
self,
580-
entry: ComputedEntry,
581+
entry: TypeVarAnyEntry,
581582
inplace: bool = True,
582583
**kwargs,
583-
) -> ComputedEntry | None:
584+
) -> TypeVarAnyEntry | None:
584585
"""Process a single entry with the chosen Corrections.
585586
Note that this method may change the original entry.
586587
@@ -595,29 +596,29 @@ def process_entry(
595596
if not inplace:
596597
entry = copy.deepcopy(entry)
597598

598-
_entry: tuple[ComputedEntry, bool] | None = self._process_entry_inplace(entry, **kwargs)
599+
_entry: tuple[TypeVarAnyEntry, bool] | None = self._process_entry_inplace(entry, **kwargs)
599600

600601
return _entry[0] if _entry is not None else None
601602

602603
def _process_entry_inplace(
603604
self,
604-
entry: AnyComputedEntry,
605+
entry: TypeVarAnyEntry,
605606
clean: bool = True,
606607
on_error: Literal["ignore", "warn", "raise"] = "ignore",
607-
) -> tuple[ComputedEntry, bool] | None:
608+
) -> tuple[TypeVarAnyEntry, bool] | None:
608609
"""Process a single entry with the chosen Corrections.
609610
Note that this method will change the original entry.
610611
611612
Args:
612-
entry (AnyComputedEntry): An AnyComputedEntry object.
613+
entry (TypeVarAnyEntry): A TypeVarAnyEntry object.
613614
clean (bool): Whether to remove any previously-applied energy adjustments.
614615
If True, all EnergyAdjustment are removed prior to processing the Entry.
615616
Defaults to True.
616617
on_error ("ignore" | "warn" | "raise"): What to do when get_adjustments(entry)
617618
raises CompatibilityError. Defaults to "ignore".
618619
619620
Returns:
620-
tuple[AnyComputedEntry, ignore_entry (bool)] if entry is compatible, else None.
621+
tuple[TypeVarAnyEntry, ignore_entry (bool)] if entry is compatible, else None.
621622
"""
622623
ignore_entry: bool = False
623624
# If clean, remove all previous adjustments from the entry
@@ -662,13 +663,13 @@ def _process_entry_inplace(
662663

663664
def process_entries(
664665
self,
665-
entries: AnyComputedEntry | list[AnyComputedEntry],
666+
entries: TypeVarAnyEntry | list[TypeVarAnyEntry],
666667
clean: bool = True,
667668
verbose: bool = False,
668669
inplace: bool = True,
669670
n_workers: int = 1,
670671
on_error: Literal["ignore", "warn", "raise"] = "ignore",
671-
) -> list[AnyComputedEntry]:
672+
) -> list[TypeVarAnyEntry]:
672673
"""Process a sequence of entries with the chosen Compatibility scheme.
673674
674675
Warning: This method changes entries in place! All changes can be undone and original entries
@@ -695,7 +696,7 @@ def process_entries(
695696
if isinstance(entries, ComputedEntry): # True for ComputedStructureEntry too
696697
entries = [entries]
697698

698-
processed_entry_list: list[AnyComputedEntry] = []
699+
processed_entry_list: list[TypeVarAnyEntry] = []
699700

700701
# if inplace = False, process entries on a copy
701702
if not inplace:
@@ -1570,13 +1571,13 @@ def get_adjustments(self, entry: ComputedEntry) -> list[EnergyAdjustment]:
15701571

15711572
def process_entries(
15721573
self,
1573-
entries: list[AnyComputedEntry],
1574+
entries: list[TypeVarAnyEntry],
15741575
clean: bool = False,
15751576
verbose: bool = False,
15761577
inplace: bool = True,
15771578
n_workers: int = 1,
15781579
on_error: Literal["ignore", "warn", "raise"] = "ignore",
1579-
) -> list[AnyComputedEntry]:
1580+
) -> list[TypeVarAnyEntry]:
15801581
"""Process a sequence of entries with the chosen Compatibility scheme.
15811582
15821583
Args:

src/pymatgen/entries/mixing_scheme.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
from pymatgen.analysis.phase_diagram import PhaseDiagram
1717
from pymatgen.analysis.structure_matcher import StructureMatcher
1818
from pymatgen.entries.compatibility import (
19-
AnyComputedEntry,
2019
Compatibility,
2120
CompatibilityError,
2221
MaterialsProject2020Compatibility,
22+
TypeVarAnyEntry,
2323
)
2424
from pymatgen.entries.computed_entries import ComputedStructureEntry, ConstantEnergyAdjustment
2525
from pymatgen.entries.entry_tools import EntrySet
@@ -121,12 +121,12 @@ def __init__(
121121

122122
def process_entries(
123123
self,
124-
entries: AnyComputedEntry | list[AnyComputedEntry],
124+
entries: TypeVarAnyEntry | list[TypeVarAnyEntry],
125125
clean: bool = True,
126126
verbose: bool = False,
127127
inplace: bool = True,
128128
mixing_state_data=None,
129-
) -> list[AnyComputedEntry]:
129+
) -> list[TypeVarAnyEntry]:
130130
"""Process a sequence of entries with the DFT mixing scheme. Note
131131
that this method will change the data of the original entries.
132132

0 commit comments

Comments
 (0)