Accessing Battery database through PyMatgen

There are currently no pymatgen MPRester methods to retrieve battery information, but there is an API endpoint to retrieve such information by chemical formula or battery ID. Here is a way to add such a method in your code:

from pymatgen import MPRester

def get_battery_data(self, formula_or_batt_id):
    """Returns batteries from a batt id or formula.

    Examples:
        get_battery("mp-300585433")
        get_battery("LiFePO4")
    """
    return mpr._make_request('/battery/%s' % formula_or_batt_id)

MPRester.get_battery_data = get_battery_data

After setting this, you may e.g.

mpr = MPRester()
results_battid = mpr.get_battery_data("mp-300585433")
results_formula = mpr.get_battery_data("LiFePO4")

Eventually, we will include such functionality in a pymatgen release but I hope this helps for now.

1 Like