Mismatch between structure in materials document vs. structure in task document in MP API

Hi @Martin_Siron1, there is a many-to-one correspondence from tasks to materials. Thus a task with the same MP ID as a material doesn’t necessarily correspond to all properties in a material.

You can see by looking in the origins field of a SummaryDoc which tasks are used to build some of the properties in a material:

from mp_api.client import MPRester

with MPRester() as mpr:
    summary_doc = mpr.materials.summary.search(material_ids = ["mp-753537"])[0]
    print(summary_doc.origins)
    for property in summary_doc.origins:
        if property.name == "structure":
            break
    task = mpr.materials.tasks.search(task_ids = [property.task_id])[0]
print(task.structure.num_sites)

The first print should show you something like this:

[PropertyOrigin(name='structure', task_id=MPID(mp-1319701), last_updated=datetime.datetime(2020, 4, 29, 23, 3, 15, 704000)), PropertyOrigin(name='energy', task_id=MPID(mp-1319701), last_updated=datetime.datetime(2023, 8, 3, 20, 42, 6, 351000)), PropertyOrigin(name='magnetism', task_id=MPID(mp-1319701), last_updated=datetime.datetime(2020, 4, 29, 23, 3, 15, 704000))]

and the second print should show you that the task corresponding to the structure in material mp-753537 has 14 sites