コード例 #1
0
    def test_products_reactants(self):
        reactants = [
            Composition("Li3Fe2(PO4)3"),
            Composition("Fe2O3"),
            Composition("O2"),
        ]
        products = [Composition("LiFePO4")]
        energies = {
            Composition("Li3Fe2(PO4)3"): -0.1,
            Composition("Fe2O3"): -0.2,
            Composition("O2"): -0.2,
            Composition("LiFePO4"): -0.5,
        }
        rxn = Reaction(reactants, products)

        self.assertIn(Composition("O2"), rxn.products, "O not in products!")
        self.assertIn(
            Composition("Li3Fe2(PO4)3"), rxn.reactants, "Li3Fe2(PO4)4 not in reactants!"
        )
        self.assertEqual(
            str(rxn), "0.3333 Li3Fe2(PO4)3 + 0.1667 Fe2O3 -> 0.25 O2 + LiFePO4"
        )
        self.assertEqual(
            rxn.normalized_repr, "4 Li3Fe2(PO4)3 + 2 Fe2O3 -> 3 O2 + 12 LiFePO4"
        )
        self.assertAlmostEqual(rxn.calculate_energy(energies), -0.48333333, 5)
コード例 #2
0
 def test_calculate_energy(self):
     reactants = [Composition("MgO"), Composition("Al2O3")]
     products = [Composition("MgAl2O4")]
     energies = {Composition("MgO"): -0.1, Composition("Al2O3"): -0.2, Composition("MgAl2O4"): -0.5}
     rxn = Reaction(reactants, products)
     self.assertEqual(str(rxn), "1.000 MgO + 1.000 Al2O3 -> 1.000 MgAl2O4")
     self.assertEqual(rxn.normalized_repr, "MgO + Al2O3 -> MgAl2O4")
     self.assertAlmostEquals(rxn.calculate_energy(energies), -0.2, 5)
コード例 #3
0
    def test_products_reactants(self):
        reactants = [Composition.from_formula("Li3Fe2(PO4)3"), Composition.from_formula("Fe2O3"), Composition.from_formula("O2")]
        products = [Composition.from_formula("LiFePO4")]
        energies = {Composition.from_formula("Li3Fe2(PO4)3"):-0.1, Composition.from_formula("Fe2O3"):-0.2, Composition.from_formula("O2"):-0.2, Composition.from_formula("LiFePO4"):-0.5}
        rxn = Reaction(reactants, products)

        self.assertIn(Composition.from_formula("O2"), rxn.products, "O not in products!")
        self.assertIn(Composition.from_formula("Li3Fe2(PO4)3"), rxn.reactants, "Li3Fe2(PO4)4 not in reactants!")
        self.assertEquals(str(rxn), "0.333 Li3Fe2(PO4)3 + 0.167 Fe2O3 -> 0.250 O2 + 1.000 LiFePO4", "Wrong reaction obtained!")
        self.assertEquals(rxn.normalized_repr, "4 Li3Fe2(PO4)3 + 2 Fe2O3 -> 3 O2 + 12 LiFePO4", "Wrong normalized reaction obtained!")
        self.assertAlmostEquals(rxn.calculate_energy(energies), -0.48333333, 5)
コード例 #4
0
 def test_calculate_energy(self):
     reactants = [Composition("MgO"), Composition("Al2O3")]
     products = [Composition("MgAl2O4")]
     energies = {
         Composition("MgO"): -0.1,
         Composition("Al2O3"): -0.2,
         Composition("MgAl2O4"): -0.5
     }
     rxn = Reaction(reactants, products)
     self.assertEqual(str(rxn), "MgO + Al2O3 -> MgAl2O4")
     self.assertEqual(rxn.normalized_repr, "MgO + Al2O3 -> MgAl2O4")
     self.assertAlmostEqual(rxn.calculate_energy(energies), -0.2, 5)