GrandPotentialPhaseDiagram.get_equilibrium_reaction_energy raises for stable entries with open element
`get_equilibrium_reaction_energy` raises `ValueError("Missing terminal entries for elements ['Li']")` for entries that are stable on the grand potential hull, when their original composition contains the open element.
the root cause is in `PhaseDiagram.get_equilibrium_reaction_energy`: it uses `entry.elements` which for `GrandPotPDEntry` returns elements from the *original* composition (including the open element), not the projected GP composition. the modified sub-hull then fails because there's no endpoint for the open element.
### minimal repro
```python
from pymatgen.analysis.phase_diagram import GrandPotentialPhaseDiagram, PDEntry
from pymatgen.core import Composition
entries = [
PDEntry(Composition("Li"), -2.0),
PDEntry(Composition("Fe"), -8.0),
PDEntry(Composition("O2"), -10.0),
PDEntry(Composition("LiFe3O"), -40.0),
]
gpd = GrandPotentialPhaseDiagram(entries, {"Li": -2.0})
# LiFe3O is stable on the GP hull (projected to Fe3O)
gp_entry = next(e for e in gpd.stable_entries if "Fe" in str(e.composition) and "O" in str(e.composition))
assert gp_entry in gpd.stable_entries
# raises: ValueError("Missing terminal entries for elements ['Li']")
gpd.get_equilibrium_reaction_energy(gp_entry)
```
### expected behavior
should return the ERE using the projected composition (Fe-O), not the original (Li-Fe-O).
### suggested fix
use `entry.composition.elements` instead of `entry.elements` in `get_equilibrium_reaction_energy`, or override the method in `GrandPotentialPhaseDiagram`.
关闭于 2026-04-07 0 条评论