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 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
}