AttributeError: 'MPDataDoc' object has no attribute 'pretty_formula'

Dear all:
I tested the example and found a problem.

from mp_api.client import MPRester

with open(‘key.txt’) as f:
key = f.read()

with MPRester(api_key = key) as mpr:
docs = mpr.summary.search(elements=[“Si”, “O”],
fields=[“material_id”, “band_gap”])
mpid_formula_dict = {doc.material_id: doc.pretty_formula for doc in docs}

Thanks for reporting this! You uncovered an error in our docs :slight_smile: The fields was missing in the fields argument and is actually called formula_pretty. Below the updated example. I also fixed the example in our docs.

from mp_api.client import MPRester

with MPRester("your_api_key_here") as mpr:
    docs = mpr.summary.search(
        elements=["Si", "O"],
        fields=["material_id", "band_gap", "formula_pretty"]
    )
    mpid_formula_dict = {
        doc.material_id: doc.formula_pretty for doc in docs
    }
1 Like

You are doing me a great service, and I’m very grateful to you.

I would like to ask another question。

How do I get access to all the materials except rare earth elements when the data is too large to be accessed directly by the api?

You’re welcome :slight_smile: I saw your other post about this. We’ll reply there when we had a chance to look into it. @munrojm

1 Like