Materials Project API
注册Materials Project账号
产生私钥
通过API得到材料的结构和性质数据
API 手册:https://materialsproject.org/docs/api#materials_.28calculated_materials_data.29
简单的API功能:https://pymatgen.org/usage.html
from pymatgen.ext.matproj import MPRester with MPRester("USER_API_KEY") as m: # Structure for material id structure = m.get_structure_by_material_id("mp-1234") # Dos for material id dos = m.get_dos_by_material_id("mp-1234") # Bandstructure for material id bandstructure = m.get_bandstructure_by_material_id("mp-1234")
通过上面三个功能就把mp数据库里第1234号结构的,结构数据,dos和band数据得到了,分别保存在structure, dos, bandstructure这三个变量里。
想要得到一些列结构的数据,比如所有晶相的
Fe2O3
, 可以用如下代码实现:# To get a list of data for all entries having formula Fe2O3data = m.get_data("Fe2O3") # To get the energies of all entries having formula Fe2O3energies = m.get_data("Fe2O3", "energy")
API得到数据不但可以单独处理,还可以和我们自己计算出来的数据一起处理。比如我们要计算Li,Fe,O三种元素的组成的相图,我们可以用
mp_entries = m.get_entries_in_chemsys(["Li", "Fe", "O"])
得到数据库里有的数据,还可以通过pymatgen.apps.borg.hive
里的VaspToComputedEntryDrone
功能把自己计算的结果和数据库种的数据一起分析:from pymatgen.ext.matproj import MPRester from pymatgen.apps.borg.hive import VaspToComputedEntryDrone from pymatgen.apps.borg.queen import BorgQueen from pymatgen.entries.compatibility import MaterialsProjectCompatibility from pymatgen.analysis.phase_diagram import PhaseDiagram, PDPlotter # Assimilate VASP calculations into ComputedEntry object. Let's assume that # the calculations are for a series of new LixFeyOz phases that we want to # know the phase stability. drone = VaspToComputedEntryDrone() queen = BorgQueen(drone, rootpath=".") entries = queen.get_data() # Obtain all existing Li-Fe-O phases using the Materials Project REST API with MPRester("USER_API_KEY") as m: mp_entries = m.get_entries_in_chemsys(["Li", "Fe", "O"]) # Combined entry from calculated run with Materials Project entries entries.extend(mp_entries) # Process entries using the MaterialsProjectCompatibility compat = MaterialsProjectCompatibility() entries = compat.process_entries(entries) # Generate and plot Li-Fe-O phase diagram pd = PhaseDiagram(entries) plotter = PDPlotter(pd) plotter.show()