Skip to content

Commit c9e15e4

Browse files
committed
FIX: PD Plotter only show lowest energy for unstable composition
1 parent de71e2a commit c9e15e4

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
@@ -3214,11 +3214,9 @@ def get_marker_props(coords, entries) -> dict[str, Any]:
32143214
highlight_entries = []
32153215

32163216
stable_coords: list[Sequence[float]] = []
3217-
unstable_coords: list[Sequence[float]] = []
32183217
highlight_coords: list[Sequence[float]] = []
32193218

32203219
stable_entries: list[PDEntry] = []
3221-
unstable_entries: list[PDEntry] = []
32223220
highlight_ents: list[PDEntry] = []
32233221

32243222
# Stable entries
@@ -3230,14 +3228,23 @@ def get_marker_props(coords, entries) -> dict[str, Any]:
32303228
stable_coords.append(coord)
32313229
stable_entries.append(entry)
32323230

3233-
# Unstable entries
3231+
# Unstable entries (lowest energy only per composition)
3232+
min_unstable: dict[str, tuple[Sequence[float], PDEntry]] = {}
3233+
32343234
for coord, entry in zip(self.pd_plot_data[2].values(), self.pd_plot_data[2], strict=True):
32353235
if entry in highlight_entries:
32363236
highlight_coords.append(coord)
32373237
highlight_ents.append(entry)
3238-
else:
3239-
unstable_coords.append(coord)
3240-
unstable_entries.append(entry)
3238+
continue
3239+
3240+
formula = entry.composition.reduced_formula
3241+
e_above_hull = self._pd.get_e_above_hull(entry)
3242+
3243+
if formula not in min_unstable or e_above_hull < self._pd.get_e_above_hull(min_unstable[formula][1]):
3244+
min_unstable[formula] = (coord, entry)
3245+
3246+
unstable_coords = [coord for coord, _ in min_unstable.values()]
3247+
unstable_entries = [entry for _, entry in min_unstable.values()]
32413248

32423249
stable_props = get_marker_props(stable_coords, stable_entries)
32433250
unstable_props = get_marker_props(unstable_coords, unstable_entries)

0 commit comments

Comments
 (0)