How to Scrape all perovskite (ABO3) type information from materials project api?

I need to scrape all ABO3 using materials project api. I have used following code-

from pymatgen.ext.matproj import MPRester
api_key= “*********”
mpr= MPRester(api_key)
entries= mpr.query(‘**O3’, [“structure”, “material_id”, “pretty_formula”])

But in this process, an error occurred (type error). Now, how do I get all perovskite information using pymatgen?

Hi @Md_Abdullah_al-Rifat,

It looks like you’re using the legacy MP API. Please take a look at our new API and documentation, and let me know if you’re still running into issues.

1 Like

brother… I have tried a lot… But couldn’t solve the code… Actually all the code showing in youtube or website get backdated I think… Can you please provide me a sample code where I can get materials properties for ABO3 (perovskite type) structured materials.

Hi @Md_Abdullah_al-Rifat, the documentation actually includes this particular example, but I’ll put it here along with some necessary filtering code to get only the ABO3 structures:

from math import gcd
from mp_api.client import MPRester

with MPRester() as mpr:
    all_docs = mpr.materials.summary.search(formula="ABC3",chemsys="O-*-*",fields=["structure","material_id","formula_pretty"])

perovskite_docs = []
for doc in all_docs:
    composition = doc.structure.composition.remove_charges().as_dict()
    multiplicity_gcd = gcd(*[int(v) for v in composition.values()])
    composition_reduced = {k: v/multiplicity_gcd for k, v in composition.items()}
    other_elements = [k for k in composition if k != "O"]
    if (
        composition_reduced.get("O") == 3 
        and all(composition_reduced[x] == 1 for x in other_elements)
        and len(composition_reduced) == 3
    ):
        perovskite_docs.append(doc)

thanks a lot vai… actually I havent so much idea about MPRester(). Now I get this