Using advanced search syntax in URL


#1

Dear users and developers,

I’d like to gather data of ternary alloys such as transition metal ternary alloy

From the URL like https://www.materialsproject.org/rest/v1/materials/Co-O/vasp/total_magnetization?API_KEY=0sNptBT7IkVyz3iX,

I already can get total magnetization of any composition of CoxOy

And in Web of Explore Materials, there are advanced Search syntax like *-Fe-O.

(We can find any material including Fe-O)

Can I use this function (*-Fe-O) in URL like https://www.materialsproject.org/rest/v1/materials/Co-O/vasp/total_magnetization?API_KEY=0sNptBT7IkVyz3iX?

or should I use pymatgen interface?

Thanks alot


#2

Here’s the python code to do what you ask:

from pymatgen import MPRester                                                  
                                                                               
if __name__ == "__main__":                                                     
    MAPI_KEY = "XXXXXX"  # You must change this to your Materials API key! (or set MAPI_KEY env variable)
                                                                               
    with MPRester(MAPI_KEY) as m: # object for connecting to MP Rest interface 
        criteria  ={'elements': {'$all':['Fe', 'O']}}                          
        properties=['pretty_formula', 'full_formula', 'total_magnetization']   
        data = m.query(criteria, properties)                                   
        print(data)                                                            
        print(len(data))                                                       

It prints 4568 elements with their corresponding total magnetization


#3

And just to answer your initial question if you can accomplish this with an URL link and the REST library, the answer is currently no. This is from the API help page

Advanced query using Mongo-like language for flexible queries on the Materials Project database. This provides the possibility of queries which would otherwise not be possible using the other simpler REST forms.