本文整理汇总了Python中pymatgen.core.composition.Composition.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Composition.copy方法的具体用法?Python Composition.copy怎么用?Python Composition.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.core.composition.Composition
的用法示例。
在下文中一共展示了Composition.copy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_negative_compositions
# 需要导入模块: from pymatgen.core.composition import Composition [as 别名]
# 或者: from pymatgen.core.composition.Composition import copy [as 别名]
def test_negative_compositions(self):
self.assertEqual(Composition("Li-1(PO-1)4", allow_negative=True).formula, "Li-1 P4 O-4")
self.assertEqual(Composition("Li-1(PO-1)4", allow_negative=True).reduced_formula, "Li-1(PO-1)4")
self.assertEqual(
Composition("Li-2Mg4", allow_negative=True).reduced_composition, Composition("Li-1Mg2", allow_negative=True)
)
self.assertEqual(
Composition("Li-2.5Mg4", allow_negative=True).reduced_composition,
Composition("Li-2.5Mg4", allow_negative=True),
)
# test math
c1 = Composition("LiCl", allow_negative=True)
c2 = Composition("Li")
self.assertEqual(c1 - 2 * c2, Composition({"Li": -1, "Cl": 1}, allow_negative=True))
self.assertEqual((c1 + c2).allow_negative, True)
self.assertEqual(c1 / -1, Composition("Li-1Cl-1", allow_negative=True))
# test num_atoms
c1 = Composition("Mg-1Li", allow_negative=True)
self.assertEqual(c1.num_atoms, 2)
self.assertEqual(c1.get_atomic_fraction("Mg"), 0.5)
self.assertEqual(c1.get_atomic_fraction("Li"), 0.5)
self.assertEqual(c1.fractional_composition, Composition("Mg-0.5Li0.5", allow_negative=True))
# test copy
self.assertEqual(c1.copy(), c1)
# test species
c1 = Composition({"Mg": 1, "Mg2+": -1}, allow_negative=True)
self.assertEqual(c1.num_atoms, 2)
self.assertEqual(c1.element_composition, Composition())
self.assertEqual(c1.average_electroneg, 1.31)
示例2: test_negative_compositions
# 需要导入模块: from pymatgen.core.composition import Composition [as 别名]
# 或者: from pymatgen.core.composition.Composition import copy [as 别名]
def test_negative_compositions(self):
self.assertEqual(Composition('Li-1(PO-1)4', allow_negative=True).formula,
'Li-1 P4 O-4')
self.assertEqual(Composition('Li-1(PO-1)4', allow_negative=True).reduced_formula,
'Li-1(PO-1)4')
self.assertEqual(Composition('Li-2Mg4', allow_negative=True).reduced_composition,
Composition('Li-1Mg2', allow_negative=True))
self.assertEqual(Composition('Li-2.5Mg4', allow_negative=True).reduced_composition,
Composition('Li-2.5Mg4', allow_negative=True))
#test math
c1 = Composition('LiCl', allow_negative=True)
c2 = Composition('Li')
self.assertEqual(c1 - 2 * c2, Composition({'Li': -1, 'Cl': 1},
allow_negative=True))
self.assertEqual((c1 + c2).allow_negative, True)
self.assertEqual(c1 / -1, Composition('Li-1Cl-1', allow_negative=True))
#test num_atoms
c1 = Composition('Mg-1Li', allow_negative=True)
self.assertEqual(c1.num_atoms, 2)
self.assertEqual(c1.get_atomic_fraction('Mg'), 0.5)
self.assertEqual(c1.get_atomic_fraction('Li'), 0.5)
self.assertEqual(c1.fractional_composition,
Composition('Mg-0.5Li0.5', allow_negative=True))
#test copy
self.assertEqual(c1.copy(), c1)
#test species
c1 = Composition({'Mg':1, 'Mg2+':-1}, allow_negative=True)
self.assertEqual(c1.num_atoms, 2)
self.assertEqual(c1.element_composition, Composition())
self.assertEqual(c1.average_electroneg, 1.31)