Get Charge Density for Multiple Materials

Hi there,

I’m currently trying to retrieve charge density data for multiple materials. I’ve been using the mp_api.client.MPRester('api_key').get_charge_density_from_material_id('mpid') method, but iterating through material IDs one by one is extremely time-consuming.

I noticed in the Materials Project documentation (Tips for Large Downloads | Materials Project Documentation) that there might be more efficient ways to handle bulk data requests. Could you advise if there’s a way to batch query charge density data for multiple materials simultaneously?

The most efficient/performant way is to directly download the underlying S3 objects from our AWS OpenData repository using the AWS CLI. See AWS OpenData | Materials Project Documentation. Since the ChgCar objects are organized by task ID you could use gnu parallel to parallelize the requests. HTH

1 Like

Hi, I can successfully retrieve charge density data for material ID mp-7 using MPRester with the following code:

with MPRester(API_KEY) as mpr:
    chgcar = mpr.get_charge_density_from_material_id("mp-7") 

However, when I try to access the same data via AWS CLI in the S3 bucket, the file does not seem to exist:

aws s3api head-object --no-sign-request --bucket materialsproject-parsed --key "chgcars/mp-7.json.gz"

The command returns that the object does not exist.

@YirongWho Make sure to translate the material ID to the right task ID for the requests to OpenData. See the implementation of get_charge_density_from_material_id. HTH

1 Like

Thank you !