Skip to content

Instantly share code, notes, and snippets.

@tschaume
Last active August 29, 2015 14:16
Show Gist options
  • Save tschaume/fa8d0fc7ed29fe972d2c to your computer and use it in GitHub Desktop.
Save tschaume/fa8d0fc7ed29fe972d2c to your computer and use it in GitHub Desktop.
Testing new MP REST endpoints via MPRester
import os
from pymatgen.matproj.rest import MPRester
from pymatgen.io.cifio import CifParser
ENDPOINT, API_KEY = "https://www.materialsproject.org/rest", os.environ.get('MAPI_KEY')
with MPRester(API_KEY, endpoint=ENDPOINT) as m:
# retrieve all references for a given mp-id
# curl -H "x-api-key:$MAPI_KEY" https://www.materialsproject.org/rest/materials/mp-568345/refs
print m.get_materials_id_references('mp-568')
# find matching structures in MP
# python -c 'from pymatgen.core.structure import Structure; import json; json.dump(Structure.from_file("<filename>").as_dict(),open("/tmp/payload.json","w"))'
# curl -H "x-api-key:$MAPI_KEY" -d "structure=`cat /tmp/payload.json`" https://www.materialsproject.org/rest/find_structure
ciffile = '/Users/patrick/gitrepos/mp/MPContribs/test_files/Fe3O4.cif'
print m.find_structure(ciffile)
s = CifParser(ciffile).get_structures()[0]
print m.find_structure(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment