Dear Community,
I am new to using the Materials Project API and have encountered an issue. When I use MPRester.materials.summary.search()
and include spacegroup_number
or crystal_system
as one of the required fields, these parameters are not returned in the query results.
Is querying the symmetry
or structure
fields and then unpacking the relevant information (e.g., spacegroup_number
and crystal_system
) from these dictionaries the only way to access this data?
If there is a more direct way to query these properties, I would greatly appreciate your guidance.
Thank you in advance for your help!
Does this issue in the mp-api repo help? If you provide an example code snippet, I can provide further guidance.
I did try out as suggested, unfortunately it doesnt seem to work out. Please find my code snippet below:
from mp_api.client import MPRester
REQUIRED_PROPERTIES = ['material_id','formula_pretty','composition', 'composition_reduced',
'nelements','chemsys','volume','symmetry','density','is_stable', 'energy_above_hull',
'formation_energy_per_atom', 'database_IDs', 'structure','theoretical', 'spacegroup_symbol', 'spacegroup.number']
def download_all_materials_data(api_key,n_elements, min_nsites, max_nsites, properties = None):
rester = MPRester(api_key)
list_dic = []
print('Materials Project API Successfully established ..')
results = rester.materials.summary.search(num_elements = n_elements, num_sites= (min_nsites,max_nsites),
fields= properties)
list_dic.extend(result.dict() for result in results)
return list_dic
def main():
mp = download_all_materials_data(api_key, n_elements= 3, min_nsites= 1, max_nsites= 150,
properties= REQUIRED_PROPERTIES)
data = pd.DataFrame(mp)
data.to_csv('Materials_Project_ternary.csv')
print('Data successfully queried from Materials Project Database')
if __name__ == '__main__':
main()
spacegroup symbol and number are under the symmetry
field. You can find details about the structure of SummaryDoc
in the API docs (Scroll down to the Schemas
section and look for SummaryDoc
). Or you can retrieve a single document with all fields included and explore, e.g.:
doc = mpr.materials.summary.search(num_chunks=1, chunk_size=1)[0]
doc["symmetry"]
Also see #4 on this doc page. It might be more efficient for you to download the entire summary collection and post-filter what you need.
HTH