materialsproject / pymatgen

Python Materials Genomics (pymatgen) is a robust materials analysis code that defines classes for structures and molecules with support for many electronic structure codes. It powers the Materials Project.
https://pymatgen.org
Other
1.52k stars 864 forks source link

Not all relevant species in a facet are reported by Pourbaix Plotter #846

Closed ashtonmv closed 1 year ago

ashtonmv commented 7 years ago

Summary

Example code

from pymatgen.analysis.pourbaix.analyzer import PourbaixAnalyzer
from pymatgen.analysis.pourbaix.entry import PourbaixEntry, IonEntry
from pymatgen.analysis.pourbaix.maker import PourbaixDiagram
from pymatgen.analysis.pourbaix.plotter import PourbaixPlotter

from pymatgen.entries.computed_entries import ComputedEntry
from pymatgen.phasediagram.maker import PhaseDiagram

from pymatgen import Composition, Element
from pymatgen.core.ion import Ion

import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
import seaborn as sb

elements = ["Zn", "Cu"]
ion_concentration = 1e-6  # Molar concentration of all ions in solution.

DFT_DATA = {'Cr': {'Cr1': -9.63855526, 'Cr2': -18.46059112, 'Cr8': -76.55796371, 'Cr6 O16': -173.41734137, 'Cr12 O24': -301.39540709, 'Cr4 O8': -101.87982108, 'Cr8 O16': -203.64870131, 'Cr4 O10': -111.70017197, 'Cr6 O18': -164.37043378, 'Cr16 O32': -402.10647713000003, 'Cr3 O8': -85.90411586, 'Cr2 O6': -61.196047279999995, 'Cr2 O4': -50.19744204, 'Cr12 O28': -322.89517198, 'Cr8 O12': -182.54916321, 'Cr10 O14': -213.79653814, 'Cr1 O2': -25.09149781, 'Cr8 O18': -210.1552443, 'Cr9 O13': -195.66151579, 'Cr1 O3': -30.36372084, 'Cr4 O12': -121.53645591, 'Cr19 O48': -532.97091756, 'Cr16 O24': -365.28992538999995, 'Cr8 O8': -145.63123877, 'Cr8 O21': -230.13747106, 'Cr6 O2': -61.35854639, 'Cr20 O48': -553.54453296, 'Cr4 O6': -91.05921984, 'Cr6 O8': -127.23524215, 'Cr1 O1': -17.81872604, 'Cr2 O2': -36.64706484, 'Cr6 O6': -109.10354077, 'Cr1 H1': -12.98096354, 'Cr2 H2': -25.302549, 'Cr1 H2': -16.21170315, 'H1 O2 Cr1': -30.832740790000003, 'H2 O4 Cr2': -61.561420770000005, 'Cr2 O4 H1': -56.300474460000004, 'Cr6 O16 H2': -180.83487127, 'Cr4 O8 H4': -123.31355353000001}, 'Fe': {'Fe2': -16.7278538, 'Fe1': -8.31266428, 'Fe6': -46.05347314, 'Fe4 O8': -89.66020753, 'Fe8 O16': -175.93366871, 'Fe12 O24': -265.23717575, 'Fe2 O4': -45.26742012, 'Fe1 O2': -22.30417569, 'Fe16 O32': -353.710741, 'Fe8 O12': -163.50194596, 'Fe10 O14': -193.70198301, 'Fe43 O64': -871.6942494699999, 'Fe64 O96': -1286.15875187, 'Fe32 O35': -556.6097124199999, 'Fe16 O24': -322.42751699, 'Fe35 O36': -587.79564685, 'Fe9 O13': -177.31327963, 'Fe38 O39': -643.29935963, 'Fe15 O16': -257.18807836, 'Fe2 O2': -33.16405348, 'Fe12 O18': -233.17108267999998, 'Fe24 O32': -456.84616745999995, 'Fe6 O8': -112.48629374999999, 'Fe23 O25': -399.2480867, 'Fe21 O27': -388.42010648999997, 'Fe2 O6': -55.2428685, 'Fe41 O56': -782.1973546199999, 'Fe13 O14': -216.26811935, 'Fe11 O12': -191.26877137000002, 'Fe12 O16': -230.13741406999998, 'Fe17 O18': -291.71916361, 'Fe21 O32': -396.67246079, 'Fe9 O10': -158.08496116999999, 'Fe21 O23': -365.95350949, 'Fe20 O32': -398.5544822, 'Fe12 O13': -207.25752108, 'Fe13 O15': -227.98661347, 'Fe4 O6': -82.31106048000001, 'Fe10 O11': -174.45994504, 'Fe14 O15': -237.19155325000003, 'Fe8 O9': -141.00985131, 'Fe14 O16': -248.88203259, 'Fe4 O4': -66.32824289, 'Fe16 O18': -281.14962684, 'Fe23 O32': -442.50592830999994, 'Fe1 O1': -15.90710818, 'Fe12 O12': -198.97163238, 'Fe20 O22': -349.46194576000005, 'Fe7 O8': -123.85862518, 'H2 Fe6': -52.61762353, 'H3 Fe1': -17.52759945, 'H1 Fe1': -11.8135345, 'H2 Fe42 O64': -866.61665873, 'H16 Fe16 O32': -443.93843547, 'H2 Fe2 O4': -56.41867967, 'H4 Fe4 O8': -112.29883521, 'H2 Fe1 O2': -32.29983393, 'H20 Fe16 O34': -475.36958252, 'H14 Fe4 O13': -188.33015303, 'H1 Fe1 O2': -28.08261191}, 'Ni': {'Ni2': -11.50759993, 'Ni1': -5.77713619, 'Ni4': -20.7238843, 'Ni2 O4': -34.55866155, 'Ni9 O13': -128.96431095, 'Ni12 O24': -205.06196917, 'Ni8 O12': -115.86613666, 'Ni10 O14': -141.27277680999998, 'Ni4 O8': -69.0414111, 'Ni1 O2': -17.29577084, 'Ni16 O32': -265.37076793, 'Ni8 O16': -136.28786271, 'Ni12 O14': -160.04721952, 'Ni3 O4': -42.685898910000006, 'Ni6 O8': -85.01586619000001, 'Ni15 O16': -190.61065495, 'Ni5 O6': -67.43739237999999, 'Ni2 O2': -25.16227672, 'Ni9 O10': -117.30897441, 'Ni1 O1': -12.499247910000001, 'H6 Ni2': -29.60708342, 'H1 Ni1': -9.24218458, 'H1 Ni2': -14.9537264, 'H1 Ni3': -18.62541446, 'H2 Ni6': -37.46048501, 'H1 O2 Ni1': -22.53897943, 'H2 O2 Ni1': -28.00920867}, 'Cu': {'Cu2': -8.18695876, 'Cu1': -4.09881235, 'Cu4': -16.38209642, 'Cu9 O13': -115.95764487, 'Cu8 O12': -110.91936536, 'Cu10 O14': -126.71951978, 'Cu2 O4': -31.17387195, 'Cu8 O7': -79.72144566, 'Cu16 O16': -178.25853609, 'Cu8 O1': -38.06555083, 'Cu2 O2': -21.88310477, 'Cu1 O2': -15.22022848, 'Cu1 O1': -10.6034845, 'Cu16 O24': -217.44930975, 'Cu4 O2': -30.16371667, 'Cu8 O6': -72.41523587, 'Cu4 O8': -62.21381766, 'Cu4 O4': -39.06145244, 'Cu4 O6': -54.35408565, 'Cu3 O2': -25.216271029999998, 'Cu8 O8': -85.01700835, 'H2 Cu2': -14.43186655, 'H2 Cu2 O4': -42.431307329999996, 'H1 Cu1 O2': -21.315096479999998, 'H4 Cu2 O4': -51.87450708}, 'Zn': {'H12 Zn6 O12': -150.9611988, 'H2 Zn1 O2': -24.89819783, 'H2 Zn2': -7.63904814, 'H4 Zn24 O24': -244.29155522, 'H8 Zn4 O8': -101.30155395999999, 'Zn1 O1': -8.37152477, 'Zn12 O12': -113.49470373, 'Zn2': -2.54433504, 'Zn2 O2': -18.39817112, 'Zn4 O8': -57.23496385}, 'Si': {'Si2': -10.85073298, 'Si1': -4.88861001, 'Si8': -39.91456936, 'Si46': -246.67712539, 'Si23': -122.90686896, 'Si4': -21.6584824, 'Si34': -172.91580555, 'Si30 O60': -718.52508282, 'Si16 O32': -397.67820858, 'Si6 O12': -146.25622408, 'Si8 O16': -197.14199162, 'Si4 O8': -96.95159471, 'Si12 O24': -284.33501127, 'Si18 O36': -451.1797014, 'Si2 O4': -47.78844694, 'Si3 O6': -75.35639395, 'Si1 O2': -21.33645897, 'Si36 O72': -904.02894055, 'Si32 O64': -803.47951011, 'Si28 O56': -702.91911153, 'Si24 O48': -602.30151028, 'Si22 O44': -552.46013027, 'Si48 O96': -1081.17829571, 'Si40 O80': -1002.5353485799999, 'Si6 O14': -142.53195331, 'Si56 O112': -1405.6819772400002, 'Si14 O28': -351.41483736000004, 'Si46 O92': -1155.73584262, 'Si5 O10': -125.37082849000001, 'Si34 O68': -854.04674275, 'Si10 O20': -250.74134930000002, 'Si12 O4': -97.5628526, 'Si17 O34': -426.87216217, 'Si64 O128': -1584.6848330799999, 'Si24 O52': -581.08321702, 'Si20 O40': -501.02898387000005, 'Si6 O6': -86.89641169000001, 'Si4 O10': -107.63911160999999, 'Si60 O120': -1504.78068369, 'Si3 O12': -99.43645066, 'Si54 O108': -1356.59379433, 'H1 Si3': -17.19631432, 'H2 Si6': -38.95277657, 'H2 Si2': -17.49653262, 'H16 Si4': -75.66880693, 'H8 Si1': -32.38367938, 'H20 Si20 O30': -430.36439077999995, 'H8 Si8 O12': -188.17013374, 'H24 Si8 O4': -162.28364717, 'H4 Si4 O10': -130.94868235, 'H8 Si16 O36': -461.16932584, 'H2 Si1 O1': -19.41968791}}

OH = {'H1': -3.2397366613799994, 'H11 O8': -96.59891012, 'H14 O8': -97.73905279, 'H16 O8': -101.99091727999999, 'H2': -6.479473322759999, 'H24 O12': -187.01891262, 'H28 O14': -199.20391543000002, 'H4': -27.367, 'H4 O2': -30.77041763, 'H8 O4': -61.103031009999995, 'H8 O8': -80.14937463, 'O2': -10.8}

# Create a phase diagram to determine which solid phases are most stable.
# These will be used in the Pourbaix diagram.
for element in elements:
    entries = [ComputedEntry(composition=k, energy=DFT_DATA[element][k]) for k in DFT_DATA[element]]
    entries += [ComputedEntry(composition=k, energy=OH[k]) for k in OH]

pd = PhaseDiagram(entries)
stable_solids = [entry for entry in pd.stable_entries if 
                 entry.composition.reduced_formula not in ["H2", "O2", "H2O", "H2O2"]]
pbx_solid_entries = list()
for entry in stable_solids:
    pbx_entry = PourbaixEntry(entry)
    pbx_entry.g0_replace(pd.get_form_energy(entry))
    pbx_entry.reduced_entry()
    pbx_solid_entries.append(pbx_entry)

ION_FORMATION_ENERGIES = {'Li': {'Li[+]': -3.04, 'Li2O2': -6.886, 'LiOH': -4.682}, 'Be': {'Be[2+]': -3.936, 'BeO2[2-]': -6.634, 'Be3(OH)3[3+]': -18.672}, 'B': {'BO2[-]': -7.036, 'B4O7[2-]': -26.996, 'BH4[-]': 1.185, 'H3BO3': -10.04, 'B(OH)4[-]': -11.951, 'H2BO3(H2O2)[-]': -10.961, 'H5(BO3)2(H2O2)2[-]': -22.38, 'HB4O7[-]': -27.828, 'H2B4O7': -28.189}, 'C': {'CO2': -4.0, 'CH4': -0.355, 'HCO3[-]': -6.08, 'CO3[2-]': -5.47}, 'N': {'HNO3': -1.153, 'N2': 0.19, 'NO3[-]': -1.15, 'NH3': -0.275, 'NH4[+]': -0.822}, 'F': {'F[-]': -2.8655592000000003, 'HF': -3.0533296500000002}, 'Na': {'Na[+]': -2.714, 'NaOH': -4.344, 'NaHO2': -3.412}, 'Mg': {'Mg[2+]': -4.714, 'MgOH[+]': -6.495, 'Mg(OH)2': -7.974}, 'Al': {'AlO2[-]': -8.70378915, 'Al[3+]': -4.986975}, 'Si': {'H2SiO3': -10.49433, 'SiO3[2-]': -9.193380000000001, 'HSiO3[-]': -9.9028314, 'H4SiO4': -13.814, 'HSi(OH)6[-]': -17.98}, 'P': {'H3PO3': 8.881152, 'H3PO2': -5.4249615, 'H3PO4': 11.890683000000001, 'PO4[3-]': -10.628761500000001, 'HPO3[2-]': 8.41281, 'H2PO4[2-]': 11.764924500000001, 'H4P2O6': 16.99908, 'H3P2O6[-]': 16.868985000000002, 'HPO4[2-]': 11.339947500000001, 'HPO3': -9.358167, 'H2PO2[-]': 5.307876, 'P2O6[4-]': 15.6851205, 'HP2O6[3-]': 16.274884500000002, 'H2PO3[-]': 8.77490775, 'H2P2O6[2-]': 16.704198}, 'S': {'S3O6[2-]': -9.930585, 'SO3[2-]': -5.034676500000001, 'H2S2O3': 5.6331135, 'S5O6[2-]': -9.9089025, 'S2O4[2-]': -5.98437, 'HS[-]': 0.13052865, 'H2SO3': -5.58064185, 'S5[2-]': 0.680353485, 'S2O8[2-]': -11.36163, 'S2O6[2-]': -10.017315, 'S4[2-]': 0.7205094750000001, 'HS2O3[-]': -5.6157675000000005, 'S[2-]': 0.9522086700000001, 'HSO3[-]': -5.46399, 'HSO4[-]': -7.803098100000001, 'S4O6[2-]': -10.5940695, 'SO4[2-]': -7.690349100000001, 'S3[2-]': 0.7791823200000001, 'HS2O4[-]': -6.13215792, 'H2SO4': -7.690349100000001, 'H2S': -0.2836071, 'S2[2-]': 0.856415385, 'S2O3[2-]': -5.516028}, 'Cl': {'Cl[-]': -1.36, 'Cl2': 0.072, 'Cl3[-]': -1.248, 'ClO[-]': -0.381, 'ClO2': 1.245, 'ClO2[-]': 0.178, 'ClO3[-]': -0.096, 'ClO4[-]': -0.088, 'HCl': -1.36, 'HClO': -0.828, 'HClO2': 0.061, 'HClO3': -0.082, 'HClO4': -0.088}, 'K': {'K[+]': -2.936, 'KOH': -4.565}, 'Ca': {'Ca[2+]': -5.737, 'CaOH[+]': -7.445, 'Ca(OH)2': -8.997}, 'Sc': {'ScOH[2+]': -8.3036, 'Sc[3+]': -6.079}, 'Ti': {'Ti[2+]': -3.2567115, 'Ti[3+]': -3.6253140000000004, 'TiO2[2+]': -4.84256955}, 'V': {'VO4[3-]': -9.545720625000001, 'HVO4[2-]': -10.1028272, 'VO[2+]': -4.626785000000001, 'VO3[-]': -8.1212304, 'VO2[+]': -6.08168075, 'HVO2[+]': -6.868148700000001, 'VO4[-]': -8.842123500000001}, 'Cr': {'CrOH[2+]': -4.466595, 'CrO4[2-]': -7.6365765, 'HCrO4[-]': -8.0181885, 'Cr[2+]': -1.8256665, 'Cr[3+]': -2.2332975}, 'Mn': {'Mn[2+]': -2.364, 'MnO4[-]': -4.365, 'MnO4[2-]': -5.189, 'MnOH[+]': -4.197, 'Mn(OH)3[-]': -7.713}, 'Fe': {'Fe[2+]': -0.818, 'Fe[3+]': -0.049, 'FeO2[2-]': -3.06, 'FeOH[+]': -2.875, 'FeOH[2+]': -2.378, 'HFeO2[-]': -3.914, 'Fe(OH)2[+]': -4.539, 'Fe(OH)3': -5.833, 'Fe(OH)3[-]': -6.373, 'Fe(OH)4[2-]': -7.977, 'Fe2(OH)2[4+]': -4.843}, 'Co': {'Co[2+]': -0.564, 'Co[3+]': 1.389, 'HCoO2[-]': -4.223, 'Co(OH)2': 4.37}, 'Ni': {'Ni[2+]': -0.472, 'NiOH[+]': -2.359, 'Ni(OH)2': -3.733}, 'Cu': {'Cu[+]': 0.518, 'Cu[2+]': 0.679, 'CuO2[2-]': -1.903, 'HCuO2[-]': -2.679, 'Cu(OH)2': -2.581}, 'Zn': {'Zn[2+]': -1.524, 'ZnO2[2-]': -3.982, 'ZnOH[+]': -3.421, 'HZnO2[-]': -4.737, 'Zn(OH)2': -5.418, 'Zn(OH)3[-]': -7.195, 'Zn(OH)4[2-]': -8.898}, 'Ga': {'Ga[3+]': -1.587159, 'Ga[2+]': -0.9106650000000001, 'HGaO3[2-]': -7.11186, 'GaO2[-]': -5.260174500000001, 'Ga(OH)3': -9.884184450000001, 'GaO[+]': -3.703371, 'GaOH[2+]': -3.894177, 'GaO3[3-]': -6.41802}, 'Ge': {'HGeO2[-]': -3.998253, 'H2GeO3': -8.100582000000001, 'GeO3[2-]': -6.8473335, 'HGeO3[-]': -7.597548000000001}, 'As': {'AsO[+]': -1.6955715, 'H3AsO4': -7.970487, 'HAsO2': -4.17388125, 'H2AsO3[-]': -6.088446, 'AsO2[-]': -3.6296505000000003, 'AsO4[3-]': -6.591480000000001, 'H3AsO3': -6.6322431, 'H2AsO4[-]': -7.7579985, 'HAsO4[2-]': -7.328685}, 'Se': {'H2Se': 0.2300808, 'H2SeO3': -4.41651496, 'HSeO3[-]': -4.26437144, 'HSeO4[-]': -4.6866008, 'HSe[-]': 0.456016, 'SeO2': -2.2969733199999998, 'SeO3[2-]': -3.8326072, 'SeO4[2-]': -4.5736332, 'Se[2-]': 1.3400652000000002}, 'Br': {'Br[-]': -1.26, 'Br2': -0.027, 'Br3[-]': -1.352, 'Br5[-]': -1.475, 'BrO[-]': -0.975, 'BrO3[-]': -0.695, 'HBrO': -1.171, 'HBrO3': -0.695}, 'Rb': {'Rb': -2.943, 'RbOH': -4.573, 'RbHO2': -3.642}, 'Sr': {'Sr[2+]': -5.798, 'SrOH[+]': -7.476}, 'Y': {'Y[3+]': -7.191, 'Y(OH)[2+]': -9.111, 'Y2(OH)2[4+]': -18.451}, 'Zr': {'Zr[4+]': -5.774, 'ZrOH[3+]': -8.25, 'ZrO[2+]': -8.128, 'ZrO2': -10.113, 'HZrO2[2+]': -10.386, 'HZrO3[3-]': -12.197}, 'Nb': {'NbO3[-]': -9.6602844, 'Nb(OH)5': -15.0101812, 'Nb(OH)4[+]': -12.525930399999998}, 'Mo': {'MoO4[2-]': -8.6641, 'Mo[3+]': -0.5982}, 'Tc': {'HTcO4': -7.504}, 'Ru': {'RuO4': -1.526, 'RuO4[-]': -2.544, 'RuO4[2-]': -3.148, 'Ru(OH)2[2+]': -2.208}, 'Rh': None, 'Pd': {'Pd[2+]': 1.829}, 'Ag': {'Ag[+]': 0.799, 'AgOH': -0.953, 'Ag(OH)2[-]': -2.697}, 'Cd': {'Cd[2+]': -0.8057217000000001, 'HCdO2[-]': -3.7510725000000003, 'Cd(OH)2': -2.4475206000000003}, 'In': {'In[2+]': -0.537726, 'InOH[2+]': -3.2567115, 'In[+]': -0.138768, 'InO2[-]': 4.50996, 'In(OH)3': -8.40977445, 'In[3+]': -1.0277505}, 'Sn': {'Sn[4+]': 0.02818725, 'Sn[2+]': -0.272115375, 'SnO3[2-]': -5.959218300000001, 'Sn(OH)4': -4.9488138, 'Sn2O3[2-]': -6.1179342000000005, 'SnOH[+]': -2.6279190000000003, 'SnO(OH)[+]': -4.913, 'HSnO2[-]': -4.24977, 'Sn(OH)2': -2.64136215}, 'Sb': {'H3SbO4': -9.4011844, 'HSb(OH)6': -15.324210399999998, 'HSbO2': -4.22333, 'Sb(OH)3': -6.6816708, 'Sb2O3': -7.1501236, 'Sb2O5': -9.9173116, 'SbO2[-]': -3.52572916, 'SbO[+]': -1.83556804}, 'Te': {'H2TeO3': -4.934300400000001, 'H4TeO6[2-]': -12.6658444, 'H5TeO6[-]': -13.074186, 'H6TeO6': -13.307376, 'Te(OH)3[+]': -5.1415804000000005, 'TeO3[2-]': -5.6463072}, 'I': {'I[-]': -0.572, 'I3[-]': -0.534, 'IO[-]': -1.114, 'IO3[-]': -2.294, 'IO4[-]': -0.606, 'I2O[2-]': -0.854, 'HIO': -1.431, 'HIO3': -2.19, 'H2OI[+]': -1.106, 'H3IO6[2-]': -7.835, 'H4IO6[-]': -7.87, 'H5IO6': -7.87, 'I2OH[-]': -2.385}, 'Cs': {'Cs[+]': -3.026, 'CsOH': -4.656, 'CsHO2': -3.725}, 'Ba': {'Ba[2+]': -5.812, 'BaOH[+]': -7.571}, 'La': {'La[3+]': -7.328}, 'Hf': {'Hf[4+]': -6.799632000000001, 'HfO[2+]': -9.3538305}, 'Ta': {'TaO2[+]': -8.7327064}, 'W': {'WO4[2-]': -11.149, 'HW6O21[5-]': -60.517}, 'Re': {'Re[+]': -0.342, 'Re[-]': 0.105, 'ReO4[-]': -7.198, 'HReO4': -7.198}, 'Os': {'OsO4': -301.85, 'HOsO5[-]': -470.2, 'H2OsO5': -538.95}, 'Ir': None, 'Pt': {'Pt[2+]': 2.641}, 'Au': {'AuO3[3-]': -0.537, 'HAuO3[2-]': -1.474, 'H2AuO3[-]': -2.262, 'Au(OH)3': -2.937}, 'Hg': {'Hg': 0.407, 'Hg[2+]': 1.704, 'Hg2[2+]': 1.591, 'HgOH[+]': -0.542, 'HHgO2[-]': -1.972, 'Hg(OH)2[-]': -2.848}, 'Tl': {'TlOH': -1.48785315, 'Tl[3+]': 2.16825, 'Tl[+]': -0.336295575, 'Tl(OH)3': -3.29270445}, 'Pb': {'PbO3[2-]': -2.8768341, 'PbO4[4-]': -2.9237116650000003, 'HPbO2[-]': -3.5125650000000004, 'Pb[2+]': -0.25195065, 'Pb[4+]': 3.1352895000000003, 'Pb(OH)2': -1.90415715}, 'Bi': None}

# These corrections are the difference in formation energy
# (in eV/atom) of reference oxides between DFT and experiment.
ION_CORRECTIONS = {'Cr': -0.093, 'Fe': -0.608, 'Ni': 0.630, 'Cu': -0.230, 'Zn': 0.0, 'Si': -0.573}

# Add all relevant ions to a list.
pbx_ion_entries = list()
for element in elements:
    for key in ION_FORMATION_ENERGIES[element]:
        comp = Ion.from_formula(key)
        if comp.composition[element] != 0:
            factor = comp.composition[element]
            energy = ION_FORMATION_ENERGIES[element][key]
            pbx_entry_ion = PourbaixEntry(IonEntry(comp, energy))
            pbx_entry_ion.correction = (
                ION_CORRECTIONS[element] * factor
            )
            pbx_entry_ion.conc = ion_concentration
            pbx_entry_ion.name = key
            pbx_ion_entries.append(pbx_entry_ion)

all_entries = pbx_solid_entries + pbx_ion_entries
pourbaix_diagram = PourbaixDiagram(all_entries)

plotter = PourbaixPlotter(pourbaix_diagram)

# Plotting details...
font = "serif"
fig = plt.figure(figsize=(14, 9))
ax1 = fig.gca()
ax1.set_xlim([0, 14])
ax1.set_xticklabels([int(t) for t in ax1.get_xticks()], fontname=font, fontsize=18)
ax1.set_ylim(-2, 2)
ax1.set_yticklabels(ax1.get_yticks(), fontname=font, fontsize=18)
ax1.set_xlabel("pH", fontname=font, fontsize=18)
ax1.set_ylabel("Potential vs. SHE (V)", fontname=font, fontsize=18)

# Outline water's stability range.
ax1.plot([0, 14], [0, -0.829], color="gray", linestyle="--", alpha=0.7, linewidth=2)
ax1.plot([0, 14], [1.229, 0.401], color="gray", linestyle="--", alpha=0.7, linewidth=2)

stable_entries = plotter.pourbaix_plot_data(
    limits=[[0, 14], [-2, 2]])[0]

# Add coloring.
colors = sb.color_palette("Set2", len(stable_entries))

i = 0
for entry in stable_entries:
    col = colors[i]
    i += 1
    vertices = plotter.domain_vertices(entry)
    center_x = sum([v[0] for v in vertices])/len(vertices)
    center_y = sum([v[1] for v in vertices])/len(vertices)
    patch = Polygon(vertices, closed=True, fill=True, facecolor=col, linewidth=2, edgecolor="w")
    ax1.text(center_x, center_y, plotter.print_name(entry),
             verticalalignment="center", horizontalalignment="center", fontname=font, fontsize=18)
    ax1.add_patch(patch)

# Display plot
plt.show()

Suggested solution (if any)

Files (if any)

shyuep commented 7 years ago

@kristinpersson Maybe get one of your folks working on the Pourbaix stuff to look into this?

as2362 commented 7 years ago

@ashtonmv Hey Michael, using the pymatgen.analysis.pourbaix.plotter functions you can enable the labeling of all the entries in a Pourbaix domain. I think the problem in this specific case is due to the way the Pourbaix entries are generated for doing the Pourbaix analysis. In this example I can only find “Pourbaix Entry”.

However, for more than 1 non H and O elements considered for the Pourbaix analysis, the pymatgen.analysis.pourbaix.maker creates multi-entries, or “Multiple Pourbaix Entry”, which are combination of the “Pourbaix Entry”. These multi-entries can have # of Pourbaix Entry < = # of non H and O elements considered in your Pourbaix analysis. This is based on the Gibbs phase rule. You can see an example of this for the case of a ternary Ag, Te, N system in the pymatgen.analysis.pourbaix.tests.test_analyzer. Please use the latest version since we added the ternary test recently.

ashtonmv commented 7 years ago

Hi Arunima,

Thanks so much! I am surprised the solution was so simple- I just needed to add a comp_dict as an argument when I created the PourbaixGiagram object (I also had a few bugs in the above code).

As far as I can tell, the actual values in comp_dict do not affect the Pourbaix diagram, so maybe comp_dict can just be automatically generated based on the entries used and should not need to be specified as an argument? Have I misunderstood that?

as2362 commented 7 years ago

@ashtonmv, Hi Michael, It is great that you were able to generate the PourbaixDiagram object for multi-element systems. Since only those multi-entries which have the ratio of elements same as in the comp_dict are retained in the Pourbaix diagram, the Pourbaix diagrams should be affected quite a bit by the comp dict. Note that the individual entries in the multi-entries have weights. These weights are not available through the MP website Pourbaix app, but are easy to get from pymatgen.

For example, for the V: Co Pourbaix diagram you will see that the Pourbaix stable domain at potential < -2 V changes when a {‘V’: 0.8,’Co’: 0.2} comp_dict is used instead of the default {‘V’: 0.5, ‘Co’: 0.5}. In both cases though, the Pourbaix stable entries satisfy the comp_dict with certain weights for each entry in the “Multi Entry”. It is possible that for the cases you examined the Pourbaix diagram does not change since the comp_dict is satisfied by the same set of multi-entries in the entire composition range. However, the weights of the entries in each multi-entry should be changing as you change the comp_dict.

ashtonmv commented 7 years ago

Ah okay, that makes a lot of sense. I was not seeing the weights for each entry. Thanks!