Exemplo n.º 1
0
    def test_energy(self):

        reaction = IntermolecularReaction(
            self.LiEC_RO_entry, [self.C1Li1O3_entry, self.C2H4_entry])
        reaction.energy()
        self.assertEqual(reaction.energy_A, 0.035409666514283344)
        self.assertEqual(reaction.energy_B, -0.035409666514283344)
Exemplo n.º 2
0
    def test_free_energy(self):

        reaction = IntermolecularReaction(
            entries["LiEC_RO"], [entries["C1Li1O3"], entries["C2H4"]])
        reaction.set_free_energy()
        self.assertEqual(reaction.free_energy_A, 0.37075842588456)
        self.assertEqual(reaction.free_energy_B, -0.37075842588410524)
Exemplo n.º 3
0
    def test_free_energy(self):

        reaction = IntermolecularReaction(
            self.LiEC_RO_entry, [self.C1Li1O3_entry, self.C2H4_entry])
        reaction.free_energy()
        self.assertEqual(reaction.free_energy_A, 0.37075842588456)
        self.assertEqual(reaction.free_energy_B, -0.37075842588456)
Exemplo n.º 4
0
    def test_graph_representation(self):

        # set up input variables
        C2H4_RN_entry = entries["C2H4"]
        LiEC_RO_RN_entry = entries["LiEC_RO"]
        C1Li1O3_RN_entry = entries["C1Li1O3"]

        C2H4_ind = C2H4_RN_entry.parameters["ind"]
        LiEC_RO_ind = LiEC_RO_RN_entry.parameters["ind"]
        C1Li1O3_ind = C1Li1O3_RN_entry.parameters["ind"]

        # perform calc
        reaction = IntermolecularReaction(LiEC_RO_RN_entry,
                                          [C2H4_RN_entry, C1Li1O3_RN_entry])
        graph = reaction.graph_representation()

        # assert
        self.assertCountEqual(
            list(graph.nodes),
            [
                LiEC_RO_ind,
                C2H4_ind,
                C1Li1O3_ind,
                str(LiEC_RO_ind) + "," + str(C1Li1O3_ind) + "+" +
                str(C2H4_ind),
                str(C2H4_ind) + "+PR_" + str(C1Li1O3_ind) + "," +
                str(LiEC_RO_ind),
                str(C1Li1O3_ind) + "+PR_" + str(C2H4_ind) + "," +
                str(LiEC_RO_ind),
            ],
        )
        self.assertEqual(len(graph.edges), 7)
        self.assertEqual(
            graph.get_edge_data(
                LiEC_RO_ind,
                str(LiEC_RO_ind) + "," + str(C1Li1O3_ind) + "+" +
                str(C2H4_ind),
            )["softplus"],
            0.5828092060367285,
        )
        self.assertEqual(
            graph.get_edge_data(
                LiEC_RO_ind,
                str(C2H4_ind) + "+PR_" + str(C1Li1O3_ind) + "," +
                str(LiEC_RO_ind),
            ),
            None,
        )
Exemplo n.º 5
0
    def test_generate(self):
        reactions = IntermolecularReaction.generate(entries["RN"].entries)

        self.assertEqual(len(reactions), 3029)
        reaction_set = set()
        for reaction in reactions:
            reaction_set.add(
                frozenset([
                    reaction.reactant.entry_id,
                    reaction.product_0.entry_id,
                    reaction.product_1.entry_id,
                ]))
        self.assertEqual(len(reaction_set), 3029)

        for r in reactions:
            if r.reactant.entry_id == entries["LiEC_RO"].entry_id:
                if (r.products[0].entry_id == entries["C2H4"].entry_id
                        or r.products[1].entry_id == entries["C2H4"].entry_id):
                    self.assertTrue(r.products[0].formula == "C1 Li1 O3"
                                    or r.products[1].formula == "C1 Li1 O3")
                    self.assertTrue(r.products[0].get_free_energy()
                                    == entries["C1Li1O3"].get_free_energy()
                                    or r.products[1].get_free_energy()
                                    == entries["C1Li1O3"].get_free_energy())
                    self.assertTrue(r.products[0].get_free_energy()
                                    == entries["C1Li1O3"].get_free_energy()
                                    or r.products[1].get_free_energy()
                                    == entries["C1Li1O3"].get_free_energy())
Exemplo n.º 6
0
    def test_reaction_type(self):

        reaction = IntermolecularReaction(
            self.LiEC_RO_entry, [self.C1Li1O3_entry, self.C2H4_entry])
        self.assertEqual(reaction.rxn_type_A,
                         "Molecular decomposition breaking one bond A -> B+C")
        self.assertEqual(reaction.rxn_type_B,
                         "Molecular formation from one new bond A+B -> C")
Exemplo n.º 7
0
    def test_reaction_type(self):

        reaction = IntermolecularReaction(
            entries["LiEC_RO"], [entries["C1Li1O3"], entries["C2H4"]])
        self.assertEqual(reaction.__class__.__name__, "IntermolecularReaction")
        self.assertEqual(reaction.rxn_type_A,
                         "Molecular decomposition breaking one bond A -> B+C")
        self.assertEqual(reaction.rxn_type_B,
                         "Molecular formation from one new bond A+B -> C")
Exemplo n.º 8
0
    def test_atom_mapping(self):

        entries = bucket_mol_entries(
            [self.LiEC_RO_entry, self.C1Li1O3_entry, self.C2H4_entry])

        reactions, families = IntermolecularReaction.generate(entries)
        self.assertEqual(len(reactions), 1)
        rxn = reactions[0]
        self.assertEqual(rxn.reactant_ids[0], self.LiEC_RO_entry.entry_id)
        self.assertEqual(rxn.product_ids[0], self.C2H4_entry.entry_id)
        self.assertEqual(rxn.product_ids[1], self.C1Li1O3_entry.entry_id)

        self.assertEqual(
            rxn.reactants_atom_mapping,
            [{
                0: 0,
                1: 1,
                2: 2,
                3: 3,
                4: 4,
                5: 5,
                6: 6,
                7: 7,
                8: 8,
                9: 9,
                10: 10
            }],
        )
        self.assertEqual(
            rxn.products_atom_mapping,
            [{
                0: 0,
                1: 1,
                2: 7,
                3: 8,
                4: 9,
                5: 10
            }, {
                0: 2,
                1: 3,
                2: 4,
                3: 5,
                4: 6
            }],
        )
Exemplo n.º 9
0
    def test_atom_mapping(self):

        ents = bucket_mol_entries(
            [entries["LiEC_RO"], entries["C1Li1O3"], entries["C2H4"]])

        reactions = IntermolecularReaction.generate(ents)
        self.assertEqual(len(reactions), 1)
        rxn = reactions[0]
        self.assertEqual(rxn.reactant.entry_id, entries["LiEC_RO"].entry_id)
        self.assertEqual(rxn.product_0.entry_id, entries["C2H4"].entry_id)
        self.assertEqual(rxn.product_1.entry_id, entries["C1Li1O3"].entry_id)

        self.assertEqual(
            rxn.reactant_atom_mapping,
            [{
                0: 0,
                1: 1,
                2: 2,
                3: 3,
                4: 4,
                5: 5,
                6: 6,
                7: 7,
                8: 8,
                9: 9,
                10: 10
            }],
        )
        self.assertEqual(
            rxn.product_atom_mapping,
            [{
                0: 0,
                1: 1,
                2: 7,
                3: 8,
                4: 9,
                5: 10
            }, {
                0: 2,
                1: 3,
                2: 4,
                3: 5,
                4: 6
            }],
        )
Exemplo n.º 10
0
    def test_generate(self):

        RN = ReactionNetwork.from_input_entries(self.LiEC_reextended_entries)
        reactions, families = IntermolecularReaction.generate(RN.entries)

        self.assertEqual(len(reactions), 3673)

        for r in reactions:
            if r.reactant_ids[0] == self.LiEC_RO_entry.entry_id:
                if (r.product_ids[0] == self.C2H4_entry.entry_id
                        or r.product_ids[1] == self.C2H4_entry.entry_id):
                    self.assertTrue(r.pro0_formula == "C1 Li1 O3"
                                    or r.pro1_formula == "C1 Li1 O3")
                    self.assertTrue(r.pro0_charge == 0 or r.pro1_charge == 0)
                    self.assertTrue(r.pro0_free_energy()
                                    == self.C1Li1O3_entry.free_energy()
                                    or r.pro1_free_energy()
                                    == self.C1Li1O3_entry.free_energy())
Exemplo n.º 11
0
    def test_generate(self):
        reactions = IntermolecularReaction.generate(entries["RN"].entries)

        self.assertEqual(len(reactions), 3673)

        for r in reactions:
            if r.reactant.entry_id == entries["LiEC_RO"].entry_id:
                if (r.products[0].entry_id == entries["C2H4"].entry_id
                        or r.products[1].entry_id == entries["C2H4"].entry_id):
                    self.assertTrue(r.products[0].formula == "C1 Li1 O3"
                                    or r.products[1].formula == "C1 Li1 O3")
                    self.assertTrue(r.products[0].get_free_energy()
                                    == entries["C1Li1O3"].get_free_energy()
                                    or r.products[1].get_free_energy()
                                    == entries["C1Li1O3"].get_free_energy())
                    self.assertTrue(r.products[0].get_free_energy()
                                    == entries["C1Li1O3"].get_free_energy()
                                    or r.products[1].get_free_energy()
                                    == entries["C1Li1O3"].get_free_energy())
Exemplo n.º 12
0
    def test_graph_representation(self):

        # set up RN
        RN = ReactionNetwork.from_input_entries(self.LiEC_reextended_entries)

        # set up input variables
        C2H4_ind = None
        LiEC_RO_ind = None
        C1Li1O3_ind = None
        C2H4_RN_entry = None
        LiEC_RO_RN_entry = None
        C1Li1O3_RN_entry = None

        for entry in RN.entries["C2 H4"][5][0]:
            if self.C2H4_mg.isomorphic_to(entry.mol_graph):
                C2H4_ind = entry.parameters["ind"]
                C2H4_RN_entry = entry
                break
        for entry in RN.entries["C3 H4 Li1 O3"][11][0]:
            if self.LiEC_RO_mg.isomorphic_to(entry.mol_graph):
                LiEC_RO_ind = entry.parameters["ind"]
                LiEC_RO_RN_entry = entry
                break
        for entry in RN.entries["C1 Li1 O3"][5][0]:
            if self.C1Li1O3_mg.isomorphic_to(entry.mol_graph):
                C1Li1O3_ind = entry.parameters["ind"]
                C1Li1O3_RN_entry = entry
                break

        # perform calc
        reaction = IntermolecularReaction(LiEC_RO_RN_entry,
                                          [C2H4_RN_entry, C1Li1O3_RN_entry])
        graph = reaction.graph_representation()

        # assert
        self.assertCountEqual(
            list(graph.nodes),
            [
                LiEC_RO_ind,
                C2H4_ind,
                C1Li1O3_ind,
                str(LiEC_RO_ind) + "," + str(C1Li1O3_ind) + "+" +
                str(C2H4_ind),
                str(C2H4_ind) + "+PR_" + str(C1Li1O3_ind) + "," +
                str(LiEC_RO_ind),
                str(C1Li1O3_ind) + "+PR_" + str(C2H4_ind) + "," +
                str(LiEC_RO_ind),
            ],
        )
        self.assertEqual(len(graph.edges), 7)
        self.assertEqual(
            graph.get_edge_data(
                LiEC_RO_ind,
                str(LiEC_RO_ind) + "," + str(C1Li1O3_ind) + "+" +
                str(C2H4_ind),
            )["softplus"],
            0.5828092060367285,
        )
        self.assertEqual(
            graph.get_edge_data(
                LiEC_RO_ind,
                str(C2H4_ind) + "+PR_" + str(C1Li1O3_ind) + "," +
                str(LiEC_RO_ind),
            ),
            None,
        )
Exemplo n.º 13
0
    def test_energy(self):

        reaction = IntermolecularReaction(
            entries["LiEC_RO"], [entries["C1Li1O3"], entries["C2H4"]])
        self.assertEqual(reaction.energy_A, 0.035409666514283344)
        self.assertEqual(reaction.energy_B, -0.035409666514283344)