Pulling structures only relaxed with PBE or only relaxed using r2SCAN

Hi,

I understand that the Materials Project database contains structures relaxed using both PBE and r2SCAN functionals. Is there a way to specifically filter and retrieve only structures relaxed with either PBE or r2SCAN through the API? I’d like to distinguish between the two for my analysis.

Best regards,
Nigel

Hi @nigel_hew, the easiest way right now is using the origins field of the summary documents, which will point you to the “task” (a DFT calculation) which generated a given property:

from mp_api.client import MPRester

mp_id_to_task_id = {}
with MPRester() as mpr:
    summary_docs = mpr.materials.summary.search(fields = ["material_id", "structure", "origins"])

    for doc in summary_docs:
        for prop in doc.origins:
            if prop.name == "structure":
                mp_id_to_task_id[doc.material_id] = {
                    "task_id": prop.task_id,
                    "structure": doc.structure,
                }
                break

    thermo_docs = mpr.materials.thermo.search(fields = ["material_id","entries"])

for doc in thermo_docs:
    mp_id = doc.material_id
    for entry in doc.entries.values():
        if entry.data["task_id"] == mp_id_to_task_id[mp_id]["task_id"]:
            mp_id_to_task_id[mp_id]["run_type"] = entry.parameters["run_type"]
            break

In this case, a run_type of GGA indicates a PBE GGA calculation, GGA_U indicates a PBE+U calculation, and r2SCAN indicates an r2SCAN calculation

An alternative is to use the tasks endpoint to directly locate the task which generated the structure. If you take that approach, it’s worth downloading all the tasks and filtering through the IDs you need:

tasks = mpr.materials.tasks.search(fields=["task_id","run_type","structure","energy"])
3 Likes

Thanks @Aaron_Kaplan!

Nigel