How do you access the CIF data in the new API?


I have figured out how to use the new query API to search for the specific structures that I require, but I can’t figure out how to extract the CIF information.

Previously in the legacy API this worked:

mp_data = mp.query(criteria={"elements": {"$all": ["Fe"]}},

This is what I am trying now:

mp_data =['Fe'])
for f in mp_data:
      cif = f.cif

Could anyone tell me what I’m doing wrong here and how to extract the CIF data correctly?

Unfortunately, you cannot pull the raw CIF data from the API anymore. Instead, I would suggest getting the structure objects and using the built in to method to dump the data to the CIF format.

– Jason

That is a shame. Do you know exactly which structure objects I would need to construct the CIF file?

You can pull all of the structure data with the following query.

docs =['Fe'], fields=["structure"])

Then, the structure object for each material will be accessible as doc.structure. Each of those has the to method to dump the data to a CIF format.

– Jason


To offer more context, pymatgen can export into multiple file formats, including CIF, and it makes sense to do these conversions on the client-side rather than converting to all possible filetypes on the server. To use our API client, you would already have pymatgen installed, therefore it should be straight forward to export as CIF.

This can be done in one of two ways, either retrieving the structure and using"cif") to retrieve a string, to with the filename argument, to write a file, or you can use CifWriter directly for more advanced options. This would be equivalent to the CIFs available via the old API, which were generated in exactly the same way.

Hope this helps,


1 Like

Thanks very much, I have got it working!

1 Like

Hi @Luke and @mkhorton,
I’m also getting stuck with writing cif files using the API ["mp-149", "mp-4163"], fields=["structure"]) 
for i in range(len(mids)):

Many thanks for your help !!!

Thread closed due to inactivity, please open a new thread to address related issues.