Use of get_element_profile with CompoundPhaseDiagram

Hi,

In a previous version of the code (3+ years ago), I was able to construct a CompoundPhaseDiagram between 2 elements, O2 and CO2. I would then go through each of the stable entries of this CPD, and use get_element_profile.

Toy code:

cpd = CompoundPhaseDiagram(all_entries, [Composition(c) for c in [el1, el2, "O2", "CO2"]], normalize_terminal_compositions=False)

stable = cpd.stable_entries

for entry in stable:
    if entry.name == "CO2":
        sp = entry.composition.elements[0]
    if entry.name == "O2":
        sp_O = entry.composition.elements[0]

for entry in stable:            
    if entry.name == "CO2":
        pass
    else:
        comp = entry.composition

        b = PDAnalyzer(cpd)
        Atom_key = {'Xf':el1, 'Xg':el2, 'Xh':'(O2)', 'Xi':'(CO2)'}

        q = 0       
    
        for reaction in b.get_element_profile(sp, comp):
              etc.

Now, I know that PDAnalyzer has been subsumed into the main pymatgen.analysis.phase_diagram, so I can replace that, but my issue is now get_element_profile throws an error because the dummy elements produced by the CompoundPhaseDiagram construction are not real elements (this didn’t happen before).

Does anyone know the best way around this? I’ve been trying to look for a way to directly edit the entry.composition with an Atom_key, but I only can find ways to transform Structures, not Compositions.

Thank you for your help!

Can you provide the error message?

Thanks Shyue!


ValueError Traceback (most recent call last)
in ()
35 q = 0
36
—> 37 for reaction in com_pd.get_element_profile(sp, comp):
38 print(‘blah’)

~/miniconda3/envs/matador/lib/python3.6/site-packages/pymatgen/analysis/phase_diagram.py in get_element_profile(self, element, comp, comp_tol)
773 “”"
774 element = get_el_sp(element)
–> 775 element = Element(element.symbol)
776
777 if element not in self.elements:

~/miniconda3/envs/matador/lib/python3.6/enum.py in call(cls, value, names, module, qualname, type, start)
289 “”"
290 if names is None: # simple value lookup
–> 291 return cls.new(cls, value)
292 # otherwise, functional API: we’re creating a new Enum type
293 return cls.create(value, names, module=module, qualname=qualname, type=type, start=start)

~/miniconda3/envs/matador/lib/python3.6/enum.py in new(cls, value)
531 return member
532 # still not found – try missing hook
–> 533 return cls.missing(value)
534
535 def generate_next_value(name, start, count, last_values):

~/miniconda3/envs/matador/lib/python3.6/enum.py in missing(cls, value)
544 @classmethod
545 def missing(cls, value):
–> 546 raise ValueError("%r is not a valid %s" % (value, cls.name))
547
548 def repr(self):

ValueError: ‘Xj’ is not a valid Element

This seems like you have a very old version of pymatgen installed. Since 2019, pymatgen does not use enum.py anymore. Can you try to install new pymatgen?

Also, pls send me a code snippet to test the code.

Test code here:

from pymatgen.analysis.phase_diagram import CompoundPhaseDiagram
from pymatgen import Composition

com_pd = CompoundPhaseDiagram(all_entries, [Composition© for c in [el1, el2, el3, “O2”, “CO2”]], normalize_terminal_compositions=False)

stable = com_pd.stable_entries

for entry in stable:
if entry.name == “CO2”:
sp = entry.composition.elements[0]

for entry in stable:
if entry.name == “CO2”:
pass
else:
comp = entry.composition
for reaction in com_pd.get_element_profile(sp, comp):
print(reaction)