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.
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.
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 structure.to(fmt="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.
Hi @Luke and @mkhorton,
I’m also getting stuck with writing cif files using the API materials.search().
mids=mpr.materials.search(material_ids= ["mp-149", "mp-4163"], fields=["structure"])
for i in range(len(mids)):
structure=mids[i].structure
structure.to(filename="cif"%i)