Building a Pourbaix Diagram manually: (Error) Reference solid not contained in entry list

Referring to the last section of this notebook titled “Building a Pourbaix Diagram manually,” I tested the code and found it to work fine with the Bi-V-O-H system, as shown in the example. However, when I changed the system to “Ti-C-O-H,” I encountered the following error. “ValueError: Reference solid not contained in entry list”

Code Link: https://github.com/materialsvirtuallab/matgenb/blob/dfaf5401c5f2f44cf0f2076509079228e236805d/notebooks/2023-03-10-Plotting%20a%20Pourbaix%20Diagram-new.ipynb

Error:

@Joseph_Montoya @mattmcdermott @tschaume

I don’t think I wrote this version of this notebook, so I can’t comment specifically on the intent of the code, but this notebook will fail any time a ionic species contains an element that’s not in the pourbaix diagram chemical system. Many ionic species are referenced to solids that contain Na, e.g. Na2(CO3) for many of these carbon species. To correct it, you will have to query the chemical system including all elements from the reference solids (in this case add “Na”):

with MPRester(MP_API_KEY) as m:
    solid_entries = m.get_entries_in_chemsys("Ti-C-O-H-Na")

Then you can remove “Na” containing compounds in the construction of your solid entries:

from pymatgen.analysis.phase_diagram import PhaseDiagram
from pymatgen.analysis.pourbaix_diagram import PourbaixEntry
from pymatgen.entries.computed_entries import ComputedEntry

free_energy_entries = []

pd = PhaseDiagram(solid_entries)
for v in pd.stable_entries:
    if v.composition.chemical_system in ["O", "H", "H-O"] or 'Na' in v.composition:
        continue
    # create a new ComputedEntry with the formation energy. Copy all other parameters
    # from the original ComputedEntry.
    free_energy_entries.append(ComputedEntry(v.composition, pd.get_form_energy(v),
                                      parameters=v.parameters))

Sorry for the late reply.