CITE THIS NOTEBOOK: MaterialsProjectLink: Wolfram functions for calling Materials Project Rest API by Kirill Belov. Wolfram Community DEC 5 2022.
ORIGINAL PACLET: Kirill Belov (2022). MaterialsProjectLink: Wolfram functions for calling Materials Project Rest API. Wolfram Function Repository. https://resources.wolframcloud.com/PacletRepository/resources/KirillBelov/MaterialsProjectLink/

About

My friend who studies chemistry and uses the Wolfram Language in his work asked me “How can I use data from Materials Project in Wolfram Mathematica?”. To be honest, I didn’t even know what he was asking. I clarified it what kind of data store it is. I studied its documentation and realized that access to the open data of this project can be done very quickly. First I made a small prototype and then created a standard paclet. I am not a chemist, I do not know what illustrative examples can be demonstrated. I just took some examples from here. If you have more useful examples - be sure to show the imitation!

Install package

Standard installation from the Wolfram Language Paclet Repository:
PacletInstall["KirillBelov/MaterialsProjectLink"]

Basic Examples

Import the package:
In[]:=
<<KirillBelov`MaterialsProjectLink`
Save your API key:
In[]:=
Export[​​FileNameJoin[{$HomeDirectory,".MaterialsProjectLinkAPIKey.wl"}],​​<|"APIKey"->"g7EYgVnYFjXbbq7Fh6dsKwDdZElmAmyF"|>​​]
Out[]=
C:\Users\Kirill\.MaterialsProjectLinkAPIKey.wl
Check that API is available:
In[]:=
getMaterials[allFields->True]
Out[]=
data{
⋯1⋯
},metaapi_version0.49.9,time_stamp2022-12-05T14:29:35.927611,total_doc146323,max_limit1000,default_fields{material_id,formula_pretty,last_updated}
Full expression not available
(
original memory size:
18.6 MB)

Materials explorer

Find chemical system H-O:
In[]:=
CH=getSummary[chemsys->"C-H"][["data",All,"material_id"]]
Out[]=
{mp-1096986,mp-995217,mp-985782,mp-866659,mp-30168,mp-1195106,mp-1021328,mp-995184,mp-995202,mp-1079612,mp-995197,mp-1097016,mp-603334,mp-995195,mp-995200}
All formulas:
In[]:=
getMaterialsByMaterialId[#,fields->{"formula_pretty","material_id"}][["data",1]]&/@CH
Out[]=
{_id619ed1bb2c86325a028acc38,formula_prettyHC,material_idmp-1096986,_id619edc9c2c86325a028cc954,formula_prettyH2C3,material_idmp-995217,_id619ee4d82c86325a028e26b0,formula_prettyH2C,material_idmp-985782,_id619ee4d82c86325a028e2746,formula_prettyH34C19,material_idmp-866659,_id619ee4d82c86325a028e2745,formula_prettyH34C19,material_idmp-30168,_id619ed3e52c86325a028b36d8,formula_prettyH8C5,material_idmp-1195106,_id619ed89d2c86325a028c1743,formula_prettyH4C,material_idmp-1021328,_id619ee0112c86325a028d5fbd,formula_prettyHC2,material_idmp-995184,_id619ee4432c86325a028e0ac8,formula_prettyHC6,material_idmp-995202,_id619ed1bb2c86325a028acc39,formula_prettyHC,material_idmp-1079612,_id619ed1bb2c86325a028acc36,formula_prettyHC,material_idmp-995197,_id619ede962c86325a028d2124,formula_prettyH4C7,material_idmp-1097016,_id619ee0112c86325a028d5fbe,formula_prettyHC2,material_idmp-603334,_id619ed1bb2c86325a028acc37,formula_prettyHC,material_idmp-995195,_id619edf2b2c86325a028d3668,formula_prettyHC3,material_idmp-995200}

Summary Queries

Structure data for silicon (mp-149):
In[]:=
docs=getSummaryByMaterialId["mp-149",fields->"structure"]
Out[]=
data{_id633dfed93e1d94017bd5a70c,structure@modulepymatgen.core.structure,@classStructure,charge0,latticematrix{{0.,2.73436,2.73436},{2.73436,0.,2.73436},{2.73436,2.73436,0.}},a3.86697,b3.86697,c3.86697,alpha60.,beta60.,gamma60.,volume40.8883,sites{species{elementSi,occu1},abc{0.25,0.25,0.25},xyz{1.36718,1.36718,1.36718},labelSi,propertiesmagmom0.,species{elementSi,occu1},abc{0.,0.,0.},xyz{0.,0.,0.},labelSi,propertiesmagmom0.}}
And structure:
In[]:=
structure=docs[["data",1,"structure"]]
Out[]=
@modulepymatgen.core.structure,@classStructure,charge0,latticematrix{{0.,2.73436,2.73436},{2.73436,0.,2.73436},{2.73436,2.73436,0.}},a3.86697,b3.86697,c3.86697,alpha60.,beta60.,gamma60.,volume40.8883,sites{species{elementSi,occu1},abc{0.25,0.25,0.25},xyz{1.36718,1.36718,1.36718},labelSi,propertiesmagmom0.,species{elementSi,occu1},abc{0.,0.,0.},xyz{0.,0.,0.},labelSi,propertiesmagmom0.}
Find all Materials Project IDs for entries with dielectric data:
In[]:=
docs=getSummary["hasProps"->"dielectric",fields->"material_id"];
And all materials:
In[]:=
docs[["data",All,"material_id"]]
Out[]=
{mp-754802,mp-549737,mp-766811,mp-8076,mp-7090,mp-28630,mp-19262,mp-556582,mp-553303,mp-22934,mp-1397370,mp-510456,mp-24007,mp-555836,mp-504506,mp-675525,mp-756951,mp-556553,mp-6987,mp-1019576,mp-1211746,mp-38487,mp-554799,mp-3785,mp-763609,mp-656887,mp-1224,mp-2667,mp-23418,mp-4103,mp-1078443,mp-25542,mp-2632,mp-20727,mp-31116,mp-29287,mp-1522,mp-5614,mp-8426,mp-768305,mp-1208162,mp-27834,mp-570238,mp-8714,mp-7456,mp-22875,mp-998428,mp-696944,mp-17792,mp-27192,mp-567949,mp-27833,mp-1222618,mp-677335,mp-625576,mp-7774,mp-754000,mp-961684,mp-675821,mp-758574,mp-753476,mp-5679,mp-27648,mp-1189906,mp-9062,mp-764355,mp-1057286,mp-568032,mp-1029965,mp-1205739,mp-6081,mp-722865,mp-11641,mp-2741,mp-558828,mp-27839,mp-989524,mp-1105143,mp-1214796,mp-2852,mp-35264,mp-6972,mp-3870,mp-553243,mp-1210184,mp-571544,mp-7623,mp-1019323,mp-33024,mp-32539,mp-9338,mp-550998,mp-11018,mp-8890,mp-752395,mp-18000,mp-409,mp-20569,mp-27243,mp-774933}
Calculation (task) IDs and types for silicon (mp-149):
In[]:=
docs=getMaterialsByMaterialId["mp-149",fields->"calc_types"]
Out[]=
data{_id619ee3ad2c86325a028df525,calc_typesmp-655585GGA Static,mp-656511GGA NSCF Line,mp-655936GGA NSCF Uniform,mp-11721GGA Structure Optimization,mp-149GGA Structure Optimization,mp-1057373GGA Static,mp-1057366GGA Structure Optimization,mp-1057380GGA NSCF Uniform,mp-1059585GGA Structure Optimization,mp-1059589GGA Static,mp-1059603GGA NSCF Uniform,mp-1120258GGA Structure Optimization,mp-1120259GGA Structure Optimization,mp-1141021GGA DFPT Dielectric,mp-1248038GGA Structure Optimization,mp-1249516GGA NMR Electric Field Gradient,mp-1267607GGA NMR Nuclear Shielding,mp-1440634GGA Static,mp-1686587GGA NSCF Uniform,mp-1791788GGA Static,mp-1594776GGA NSCF Line,mp-1592727GGA NSCF Line,mp-1059604GGA NSCF Line,mp-1057384GGA NSCF Line}
Task ids:
In[]:=
taskIds=Keys[docs[["data",1,"calc_types"]]]
Out[]=
{mp-655585,mp-656511,mp-655936,mp-11721,mp-149,mp-1057373,mp-1057366,mp-1057380,mp-1059585,mp-1059589,mp-1059603,mp-1120258,mp-1120259,mp-1141021,mp-1248038,mp-1249516,mp-1267607,mp-1440634,mp-1686587,mp-1791788,mp-1594776,mp-1592727,mp-1059604,mp-1057384}
Task types:
In[]:=
taskTypes=Values[docs[["data",1,"calc_types"]]]
Out[]=
{GGA Static,GGA NSCF Line,GGA NSCF Uniform,GGA Structure Optimization,GGA Structure Optimization,GGA Static,GGA Structure Optimization,GGA NSCF Uniform,GGA Structure Optimization,GGA Static,GGA NSCF Uniform,GGA Structure Optimization,GGA Structure Optimization,GGA DFPT Dielectric,GGA Structure Optimization,GGA NMR Electric Field Gradient,GGA NMR Nuclear Shielding,GGA Static,GGA NSCF Uniform,GGA Static,GGA NSCF Line,GGA NSCF Line,GGA NSCF Line,GGA NSCF Line}
Band gaps for all materials containing only Si and O:
In[]:=
docs=getSummary[chemsys->"Si-O",fields->{"material_id","band_gap"}];
As assoc:
In[]:=
mpid=<|Query["data",All,{"material_id","band_gap"}/*Apply[Rule]]@docs|>
Out[]=
mp-8629982.6763,mp-5580255.6213,mp-5565534.9023,mp-5570245.6822,mp-5564545.5651,mp-6673835.5162,mp-5614882.7816,mp-5611815.6107,mp-11948280.0905,mp-10215034.5285,mp-5321055.559,mp-6000025.4577,mp-5570764.0358,mp-6673735.5745,mp-127875.6273,mp-182805.6999,mp-92584.0091,mp-5601555.7966,mp-5608265.4292,mp-6000045.4296,mp-6000295.4247,mp-6000145.7274,mp-12036555.4771,mp-5593894.7204,mp-5598725.6106,mp-6000015.491,mp-5588915.6471,mp-5558915.4968,mp-6159935.5574,mp-5539455.6059,mp-5549465.863,mp-5589475.6495,mp-13911760.1484,mp-9361870.,mp-12581965.6518,mp-5602035.7301,mp-76485.7192,mp-12040575.5444,mp-6468955.7207,mp-5569635.9648,mp-10631180.,mp-6000805.4798,mp-100641.7396,mp-6537635.3421,mp-6001115.5173,mp-6000495.6468,mp-12502615.6701,mp-5603365.5874,mp-116845.5458,mp-5467945.8552,mp-5609735.4387,mp-6000635.6966,mp-6000605.6832,mp-69475.1682,mp-12564995.931,mp-5566625.5653,mp-5569615.736,mp-5569945.3836,mp-6409170.6554,mp-83525.3649,mp-5568805.0612,mp-6000715.4719,mp-5593605.6782,mp-5587335.2427,mp-6395065.6572,mp-69455.5037,mp-5577712.3054,mp-6000785.6143,mp-13532595.5609,mp-70005.7194,mp-70295.7944,mp-5599285.4895,mp-6000515.5706,mp-5574655.5449,mp-6000525.4991,mp-6000185.4453,mp-5542675.6122,mp-5575915.6246,mp-5583746.2197,mp-11796513.4528,mp-6000765.958,mp-12052135.3649,mp-6394805.6231,mp-6395125.6163,mp-5551475.3545,mp-6397486.1775,mp-5541755.7494,mp-12490905.7758,mp-6396825.6453,mp-172795.7092,mp-12088670.,mp-9728085.5882,mp-5564695.7427,mp-6380380.,mp-12040264.1957,mp-5589314.5368,mp-11795295.4553,mp-5608364.9428,mp-6517075.7241,mp-5595505.6097
Stable materials (on the hull) with large band gaps (>3eV):
Stable mpids:

Conclusion

I hope this short note will be useful to someone. In the future I plan to improve this package. Moreover, if suddenly you are engaged in chemistry and see some potential useful application for yourself personally, be sure to write to me here or in the comments. State your wishes and I will implement it in my package. Thank you all for your attention!