Skip to content

Commit 2416303

Browse files
committed
FIX: PD Plotter only show lowest energy for unstable composition
1 parent 206152f commit 2416303

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/pymatgen/analysis/phase_diagram.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3229,11 +3229,9 @@ def get_marker_props(coords, entries) -> dict[str, Any]:
32293229
highlight_entries = []
32303230

32313231
stable_coords: list[Sequence[float]] = []
3232-
unstable_coords: list[Sequence[float]] = []
32333232
highlight_coords: list[Sequence[float]] = []
32343233

32353234
stable_entries: list[PDEntry] = []
3236-
unstable_entries: list[PDEntry] = []
32373235
highlight_ents: list[PDEntry] = []
32383236

32393237
# Stable entries
@@ -3245,14 +3243,23 @@ def get_marker_props(coords, entries) -> dict[str, Any]:
32453243
stable_coords.append(coord)
32463244
stable_entries.append(entry)
32473245

3248-
# Unstable entries
3246+
# Unstable entries (lowest energy only per composition)
3247+
min_unstable: dict[str, tuple[Sequence[float], PDEntry]] = {}
3248+
32493249
for coord, entry in zip(self.pd_plot_data[2].values(), self.pd_plot_data[2], strict=True):
32503250
if entry in highlight_entries:
32513251
highlight_coords.append(coord)
32523252
highlight_ents.append(entry)
3253-
else:
3254-
unstable_coords.append(coord)
3255-
unstable_entries.append(entry)
3253+
continue
3254+
3255+
formula = entry.composition.reduced_formula
3256+
e_above_hull = self._pd.get_e_above_hull(entry)
3257+
3258+
if formula not in min_unstable or e_above_hull < self._pd.get_e_above_hull(min_unstable[formula][1]):
3259+
min_unstable[formula] = (coord, entry)
3260+
3261+
unstable_coords = [coord for coord, _ in min_unstable.values()]
3262+
unstable_entries = [entry for _, entry in min_unstable.values()]
32563263

32573264
stable_props = get_marker_props(stable_coords, stable_entries)
32583265
unstable_props = get_marker_props(unstable_coords, unstable_entries)

0 commit comments

Comments
 (0)