Pymatgen:如何将查询结果转换为结构

2024-05-18 16:17:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我们有现有的代码来获取许多材质(>;60000)的某些材质属性。你知道吗

from pymatgen import MPRester
mpr = MPRester(api_key="")
criteria={"nelements":{'$lt':4}}
properties=["pretty_formula","cif","material_id", "formation_energy_per_atom", "band_gap"]

c = mpr.query(criteria=criteria,properties=properties)

但对于这个项目,我们需要一种特定形式的信息,即结构中的信息。我可以通过为每个材质ID分别调用它们来轻松地获得此结构:

structures = []
for mid in mid_list:
    structures.append(mpr.get_structure_by_material_id(mid))

在中调用这个函数材料项目地址:

    def get_structure_by_material_id(self, material_id, final=True,
                                     conventional_unit_cell=False):
        """
        Get a Structure corresponding to a material_id.

        Args:
            material_id (str): Materials Project material_id (a string,
                e.g., mp-1234).
            final (bool): Whether to get the final structure, or the initial
                (pre-relaxation) structure. Defaults to True.
            conventional_unit_cell (bool): Whether to get the standard
                conventional unit cell

        Returns:
            Structure object.
        """

问题是,这需要很长时间(>;4小时),有时在调用API时会卡住。你知道吗

有没有办法避免调用API 60000次,而是转换初始查询结果?你知道吗


Tags: thetoidgetunitcellpropertiesstructure
1条回答
网友
1楼 · 发布于 2024-05-18 16:17:38

您不需要查询每个mpid。您的第一个代码块已经查询了所有材料的"cif"信息!你知道吗

您只需使用PyMatGen将cif字符串转换为结构:

from pymatgen.io.cif import CifParser
structures = []
for material in c:
    structures.append(CifParser.from_string(material["cif"]).get_structures()[0])

相关问题 更多 >

    热门问题