materialsproject / api

New API client for the Materials Project
https://materialsproject.github.io/api/
Other
104 stars 38 forks source link

`get_task_ids_associated_with_material_id` gives wrong `task_ids` when `calc_types` are `R2SCAN` calculations #806

Closed chiang-yuan closed 1 year ago

chiang-yuan commented 1 year ago

Hi MP team!

I try to use the following code to pull out CHGCARs and their associated TaskDoc, ChgcarDoc. It works perfectly for calc_types=[CalcType.GGA_Static, CalcType.GGA_U_Static] calculations. However, when I try to use calc_types=[CalcType.R2SCAN_Static, CalcType.R2SCAN_U_Static]. The task_ids is empty. Do we have CHGCARs of R2SCAN calculations available yet?

Also if I feed empty task_ids into mpr.charge_density.search, the function will not yield any error message, and this snippet will all print out mp-1920798 at the second print, which is not associated with any entry in the materials_ids. (I was looping over "Cl" compounds but it gives me 'Ba6B12O24')


for material_id in material_ids:
    task_ids = mpr.get_task_ids_associated_with_material_id(
        material_id, calc_types=[CalcType.R2SCAN_Static, CalcType.R2SCAN_U_Static]
        # material_id, calc_types=[CalcType.GGA_Static, CalcType.GGA_U_Static]
    )

    print('task_ids', task_ids)

    chgcar_docs = mpr.charge_density.search(task_ids=task_ids)

    chgcar_doc = max(chgcar_docs, key=lambda x: x.last_updated) 
    task_doc = mpr.tasks.get_data_by_id(chgcar_doc.task_id)

    print(chgcar_doc.task_id)
chiang-yuan commented 1 year ago

Let me add one thing. Even if CHGCARs of R2SCAN calculations are not ready yet, the task_ids are still supposed be available right? Looks like the pipe between this function and the database is broken 😢 (I have ensured mp_api is up-to-date)

munrojm commented 1 year ago

Hi @chiang-yuan, sorry for such a delayed response. Have been traveling.

This is indeed a bug. task_ids should definitely be populated. I will take care of fixing this.

munrojm commented 1 year ago

@chiang-yuan, looks like things are okay under the hood. This is actually just due to the fact that the R2SCAN calculations that data is pulled from are optimizations and not statics. If you instead search with CalcType.R2SCAN_Structure_Optimization you will get the correct task_id values.

chiang-yuan commented 1 year ago

Thanks @munrojm ! I did pull out some data from the optimization calculation type. As for mpr.charge_density.search outputting Ba6B12O24 if the task_ids is empty, I added a line to check the length of task_ids list before feeding them into mpr.charge_density.search. Is the default output Ba6B12O24 of mpr.charge_density.search desirable or intentional? Perhaps we need a foolproof (although nobody will intend to send an empty request to api...)