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


Python Reaction.normalized_repr_and_factor方法代码示例

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


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

示例1: test_init

# 需要导入模块: from pymatgen.analysis.reaction_calculator import Reaction [as 别名]
# 或者: from pymatgen.analysis.reaction_calculator.Reaction import normalized_repr_and_factor [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.normalized_repr_and_factor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。