Accessing Battery database through PyMatgen

Hello, I wonder whether the Battery Explorer is accessible with pymatgen API. I couldn’t find any keywords suitable to retrieve battery data in the documentation. I have tried to request data with MP IDs of battery cells, but it got failed. It will be of great help if the battery explorer is also included in the pymatgen. Thanks.

1 Like

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

This would suffice. Thank you!!