当前位置: 首页>>代码示例>>Python>>正文


Python Reaction.as_dict方法代码示例

本文整理汇总了Python中pymatgen.analysis.reaction_calculator.Reaction.as_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Reaction.as_dict方法的具体用法?Python Reaction.as_dict怎么用?Python Reaction.as_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymatgen.analysis.reaction_calculator.Reaction的用法示例。


在下文中一共展示了Reaction.as_dict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_to_from_dict

# 需要导入模块: from pymatgen.analysis.reaction_calculator import Reaction [as 别名]
# 或者: from pymatgen.analysis.reaction_calculator.Reaction import as_dict [as 别名]
 def test_to_from_dict(self):
     reactants = [Composition("Fe"), Composition("O2")]
     products = [Composition("Fe2O3")]
     rxn = Reaction(reactants, products)
     d = rxn.as_dict()
     rxn = Reaction.from_dict(d)
     self.assertEqual(rxn.normalized_repr, "4 Fe + 3 O2 -> 2 Fe2O3")
开发者ID:antoinedewandre,项目名称:pymatgen,代码行数:9,代码来源:test_reaction_calculator.py

示例2: test_init

# 需要导入模块: from pymatgen.analysis.reaction_calculator import Reaction [as 别名]
# 或者: from pymatgen.analysis.reaction_calculator.Reaction import as_dict [as 别名]
    def test_init(self):
        reactants = [Composition("Fe"),
                     Composition("O2")]
        products = [Composition("Fe2O3")]
        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn), "2.000 Fe + 1.500 O2 -> 1.000 Fe2O3",
                         "Wrong reaction obtained!")
        self.assertEqual(rxn.normalized_repr, "4 Fe + 3 O2 -> 2 Fe2O3",
                         "Wrong normalized reaction obtained!")

        d = rxn.as_dict()
        rxn = Reaction.from_dict(d)
        self.assertEqual(rxn.normalized_repr, "4 Fe + 3 O2 -> 2 Fe2O3",
                         "Wrong normalized reaction obtained!")

        reactants = [Composition("Fe"), Composition("O"), Composition("Mn"),
                     Composition("P")]
        products = [Composition("FeP"), Composition("MnO")]
        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn),
                         "1.000 Fe + 0.500 O2 + 1.000 Mn + 1.000 P -> 1.000 FeP + 1.000 MnO",
                         "Wrong reaction obtained!")
        self.assertEqual(rxn.normalized_repr,
                         "2 Fe + O2 + 2 Mn + 2 P -> 2 FeP + 2 MnO",
                         "Wrong normalized reaction obtained!")
        reactants = [Composition("FePO4")]
        products = [Composition("FePO4")]

        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn), "1.000 FePO4 -> 1.000 FePO4",
                         "Wrong reaction obtained!")

        products = [Composition("Ti2 O4"), Composition("O1")]
        reactants = [Composition("Ti1 O2")]
        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn), "2.000 TiO2 -> 2.000 TiO2",
                         "Wrong reaction obtained!")

        reactants = [Composition("FePO4"), Composition("Li")]
        products = [Composition("LiFePO4")]
        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn), "1.000 FePO4 + 1.000 Li -> 1.000 LiFePO4",
                         "Wrong reaction obtained!")

        reactants = [Composition("MgO")]
        products = [Composition("MgO")]

        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn), "1.000 MgO -> 1.000 MgO",
                         "Wrong reaction obtained!")

        reactants = [Composition("Mg")]
        products = [Composition("Mg")]

        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn), "1.000 Mg -> 1.000 Mg",
                         "Wrong reaction obtained!")

        reactants = [Composition("FePO4"), Composition("LiPO3")]
        products = [Composition("LiFeP2O7")]

        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn),
                         "1.000 FePO4 + 1.000 LiPO3 -> 1.000 LiFeP2O7",
                         "Wrong reaction obtained!")

        reactants = [Composition("Na"), Composition("K2O")]
        products = [Composition("Na2O"), Composition("K")]
        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn),
                         "1.000 Na + 0.500 K2O -> 0.500 Na2O + 1.000 K",
                         "Wrong reaction obtained!")

        # Test for an old bug which has a problem when excess product is
        # defined.
        products = [Composition("FePO4"), Composition("O")]
        reactants = [Composition("FePO4")]
        rxn = Reaction(reactants, products)

        self.assertEqual(str(rxn), "1.000 FePO4 -> 1.000 FePO4",
                         "Wrong reaction obtained!")

        products = list(map(Composition, ['La8Ti8O12', 'O2', 'LiCrO2']))
        reactants = [Composition('LiLa3Ti3CrO12')]
        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn),
                         "1.000 LiLa3Ti3CrO12 -> 1.500 La2Ti2O3 + 2.750 O2 + 1.000 LiCrO2",
                         "Wrong reaction obtained!")
开发者ID:antoinedewandre,项目名称:pymatgen,代码行数:90,代码来源:test_reaction_calculator.py

示例3: test_init

# 需要导入模块: from pymatgen.analysis.reaction_calculator import Reaction [as 别名]
# 或者: from pymatgen.analysis.reaction_calculator.Reaction import as_dict [as 别名]
    def test_init(self):
        reactants = [Composition("Fe"),
                     Composition("O2")]
        products = [Composition("Fe2O3")]
        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn), "2 Fe + 1.5 O2 -> Fe2O3")
        self.assertEqual(rxn.normalized_repr, "4 Fe + 3 O2 -> 2 Fe2O3")

        d = rxn.as_dict()
        rxn = Reaction.from_dict(d)
        repr, factor = rxn.normalized_repr_and_factor()
        self.assertEqual(repr, "4 Fe + 3 O2 -> 2 Fe2O3")
        self.assertAlmostEqual(factor, 2)

        reactants = [Composition("FePO4"), Composition('Mn')]
        products = [Composition("FePO4"), Composition('Xe')]
        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn), "FePO4 -> FePO4")

        products = [Composition("Ti2 O4"), Composition("O1")]
        reactants = [Composition("Ti1 O2")]
        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn), "2 TiO2 -> 2 TiO2")

        reactants = [Composition("FePO4"), Composition("Li")]
        products = [Composition("LiFePO4")]
        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn), "FePO4 + Li -> LiFePO4")

        reactants = [Composition("MgO")]
        products = [Composition("MgO")]

        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn), "MgO -> MgO")

        reactants = [Composition("Mg")]
        products = [Composition("Mg")]

        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn), "Mg -> Mg")

        reactants = [Composition("FePO4"), Composition("LiPO3")]
        products = [Composition("LiFeP2O7")]

        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn),
                         "FePO4 + LiPO3 -> LiFeP2O7")

        reactants = [Composition("Na"), Composition("K2O")]
        products = [Composition("Na2O"), Composition("K")]
        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn),
                         "2 Na + K2O -> Na2O + 2 K")

        # Test for an old bug which has a problem when excess product is
        # defined.
        products = [Composition("FePO4"), Composition("O")]
        reactants = [Composition("FePO4")]
        rxn = Reaction(reactants, products)

        self.assertEqual(str(rxn), "FePO4 -> FePO4")

        products = list(map(Composition, ['LiCrO2', 'La8Ti8O12', 'O2']))
        reactants = [Composition('LiLa3Ti3CrO12')]
        rxn = Reaction(reactants, products)
        self.assertEqual(str(rxn),
                         "LiLa3Ti3CrO12 -> LiCrO2 + 1.5 La2Ti2O3 + 2.75 O2")
开发者ID:bocklund,项目名称:pymatgen,代码行数:69,代码来源:test_reaction_calculator.py


注:本文中的pymatgen.analysis.reaction_calculator.Reaction.as_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。