MP API summary endpoint, separating the symmetry dictionary field into separate columns in dataset

In the MP API summary endpoint there is a field called symmetry which gives a dictionary with the materials’ crystal system, symbol, space group number, point group, symprec, and version which all occupy 1 column in the dataset. I was wondering if there is a way to easily separate out the contents of the dictionary so that I am able to get separate columns for each property either using the API or with python.

Hi @J0chin, the data in the symmetry should itself be another document model with the fields accessible via its attributes (i.e. doc.symmetry.crystal_system).

– Jason

Hey @munrojm , I am still a little confused, so am I able to get access these fields from the summary endpoint? Also do you have an example you could provide me?

thanks,
Johan

Yes, you just have to ask for the symmetry field, and then access that data as attributes of what it gives you. An example for silicon (mp-149):

from mp_api.client import MPRester

with MPRester("your_api_key") as mpr:
    docs = mpr.summary.search(material_ids=["mp-149"], fields=["symmetry"])
    silicon_crystal_system = docs[0].symmetry.crystal_system

– Jason

I see, do you know then if there are more than one entries in doc how to quickly iterate through all the entries and pull all the crystal systems attributes of all of them into another list?

Actually a found a way to do it using a for loop from one of the api exercises workshop, I’ll post the example it below.

from mp_api.client import MPRester
with MPRester(JOHAN_API_KEY) as mpr:
    SiO2_entries = mpr.summary.search(formula="SiO2", fields=['symmetry'])
    
crystal_systems = []
for entry in SiO2_entries:
    crystal_systems.append(entry.symmetry.crystal_system)