0

我们有现有的代码来获取许多材料(> 60,000)的一些材料属性。

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))

在 matproj.py 中调用此函数:

    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 60,000 次并转换初始查询结果?

4

1 回答 1

0

您不需要查询每个单独的 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])
于 2019-10-15T08:34:55.830 回答