Reaction calculator from versus pymatgen


I have been having a lot of trouble trying to obtain the same answer I get from while using pymatgen. The example is simple: I type H2O + H2O as reactants and H2O + H2O as products on the website and it naturally yields 0 eV as the enthalpy of the reaction. However, if I try to do the same with pymatgen (the api_key is the api key):

from pymatgen.analysis.reaction_calculator import Reaction

def get_most_stable_entry(entries, formula):
    entries = api_key.get_entries_in_chemsys(entries)
    relevant_entries = [entry for entry in entries if entry.composition.reduced_formula == Composition(formula).reduced_formula]
    relevant_entries = sorted(relevant_entries, key=lambda e: e.energy_per_atom)
    return relevant_entries[0]

H2O = get_most_stable_entry(["H", "O"], "H2O")
Reaction.elements([H2O, H2O], [H2O, H2O])

I get:
TypeError: 'property' object is not callable

What am I doing wrong? Is there a function that gives the calculated or the experimental enthalpy values such that it could be used with the material ID like:

In: Reaction([mp-###, mp-###], [mp-###, mp-###])
Out: #.###

Hi @davidmsousa, sorry for the slow response time – hopefully you have got it working. In case you haven’t (and for others possibly reading this), there was a small typo in what you posted. You should be using ComputedReaction and omit the elements property.


Reaction.elements([H2O, H2O], [H2O, H2O])


from pymatgen.analysis.reaction_calculator import ComputedReaction
ComputedReaction[H2O, H2O], [H2O, H2O])

For your other question, there is indeed an API function in MPRester that can be used to get reaction information from the Materials Project:

from pymatgen import MPRester
with MPRester() as mpr:
    rxn = mpr.get_reaction(["H2O","H2O"],["H2O","H2O"])

You can then access the “Reaction”, “Reaction_energy”, and “Experimental_reaction_energy” keys of the dictionary that is returned.