Пример #1
0
    def test_free_energy(self):

        reaction = IntramolSingleBondChangeReaction(self.LiEC_entry,
                                                    self.LiEC_RO_entry)
        reaction.free_energy()
        self.assertEqual(reaction.free_energy_A, -1.1988634269218892)
        self.assertEqual(reaction.free_energy_B, 1.1988634269218892)
Пример #2
0
    def test_energy(self):

        reaction = IntramolSingleBondChangeReaction(self.LiEC_entry,
                                                    self.LiEC_RO_entry)
        reaction.energy()
        self.assertEqual(reaction.energy_A, -0.03746218086303088)
        self.assertEqual(reaction.energy_B, 0.03746218086303088)
Пример #3
0
    def test_graph_representation(self):

        LiEC_RN_entry = entries["LiEC"]
        LiEC_RO_RN_entry = entries["LiEC_RO"]
        LiEC_ind = LiEC_RN_entry.parameters["ind"]
        LiEC_RO_ind = LiEC_RO_RN_entry.parameters["ind"]

        reaction = IntramolSingleBondChangeReaction(LiEC_RN_entry,
                                                    LiEC_RO_RN_entry)
        reaction.electron_free_energy = -2.15
        graph = reaction.graph_representation()
        # print(graph.nodes, graph.edges)
        # print(graph.get_edge_data(LiEC_ind, str(LiEC_ind) + "," + str(LiEC_RO_ind)))
        self.assertCountEqual(
            list(graph.nodes),
            [
                LiEC_ind,
                LiEC_RO_ind,
                str(LiEC_ind) + "," + str(LiEC_RO_ind),
                str(LiEC_RO_ind) + "," + str(LiEC_ind),
            ],
        )
        self.assertEqual(len(graph.edges), 4)
        self.assertEqual(
            graph.get_edge_data(LiEC_ind,
                                str(LiEC_ind) + "," +
                                str(LiEC_RO_ind))["softplus"],
            0.15092362164364986,
        )
Пример #4
0
    def test_generate(self):

        RN = ReactionNetwork.from_input_entries(self.LiEC_reextended_entries)
        reactions, families = IntramolSingleBondChangeReaction.generate(
            RN.entries)
        self.assertEqual(len(reactions), 93)

        for r in reactions:
            # TODO (mjwen) this is never run for two reasons:
            #  1. It should be:
            #  if r.reactant == self.LiEC_RO_entry:
            #     self.assertEqual(r.product.entry_id, self.LiEC_entry.entry_id)
            #  since this class generates bond formation reactions
            #  Even, after fixing 1, there is still another problem.
            #  2. There are multiple MoleculeEntry with the same `formula`,`Nbonds`,
            #  and `charge` as self.LiEC_entry. In `setUpClass`, one of such
            #  MoleculeEntry is set to self.LiEC_entry,
            #  but in IntramolSingleBondChangeReaction, another MoleculeEntry will be
            #  used as the reactant. This happens because in both `setUpClass` and
            #  `IntramolSingleBondChangeReaction`, the code `break` when one entry is
            #  found.
            #  To fix this, we can either clean the input data to make sure there is
            #  only one LiEC, or we do some bookkeeping in `setUpClass` and then make
            #  the correct check.

            # if r.reactant == self.LiEC_entry:
            #    self.assertEqual(r.product.entry_id, self.LiEC_RO_entry.entry_id)
            pass
Пример #5
0
    def test_generate(self):

        reactions = IntramolSingleBondChangeReaction.generate(
            entries["entries_box"].entries_dict)
        self.assertEqual(len(reactions), 73)

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

        for r in reactions:
            # TODO (mjwen) this is never run for two reasons:
            #  1. It should be:
            #  if r.reactant == self.LiEC_RO_entry:
            #     self.assertEqual(r.product.entry_id, self.LiEC_entry.entry_id)
            #  since this class generates bond formation reactions
            #  Even, after fixing 1, there is still another problem.
            #  2. There are multiple MoleculeEntry with the same `formula`,`Nbonds`,
            #  and `charge` as self.LiEC_entry. In `setUpClass`, one of such
            #  MoleculeEntry is set to self.LiEC_entry,
            #  but in IntramolSingleBondChangeReaction, another MoleculeEntry will be
            #  used as the reactant. This happens because in both `setUpClass` and
            #  `IntramolSingleBondChangeReaction`, the code `break` when one entry is
            #  found.
            #  To fix this, we can either clean the input data to make sure there is
            #  only one LiEC, or we do some bookkeeping in `setUpClass` and then make
            #  the correct check.
            if r.reactant == entries["LiEC_RO"]:
                self.assertEqual(r.product.entry_id, entries["LiEC"].entry_id)
Пример #6
0
    def test_reaction_type(self):

        reaction = IntramolSingleBondChangeReaction(self.LiEC_entry,
                                                    self.LiEC_RO_entry)
        self.assertEqual(reaction.rxn_type_A,
                         "Intramolecular single bond formation")
        self.assertEqual(reaction.rxn_type_B,
                         "Intramolecular single bond breakage")
Пример #7
0
    def test_graph_representation(self):

        RN = ReactionNetwork.from_input_entries(self.LiEC_reextended_entries)
        # print(RN.entries["C3 H4 Li1 O3"][11][0][0].molecule)

        LiEC_ind = None
        LiEC_RO_ind = None
        LiEC_RN_entry = None
        LiEC_RO_RN_entry = None
        for entry in RN.entries["C3 H4 Li1 O3"][12][0]:
            if self.LiEC_mg.isomorphic_to(entry.mol_graph):
                LiEC_ind = entry.parameters["ind"]
                LiEC_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
        reaction = IntramolSingleBondChangeReaction(LiEC_RN_entry,
                                                    LiEC_RO_RN_entry)
        reaction.electron_free_energy = -2.15
        graph = reaction.graph_representation()
        print(graph.nodes, graph.edges)
        print(
            graph.get_edge_data(LiEC_ind,
                                str(LiEC_ind) + "," + str(LiEC_RO_ind)))
        self.assertCountEqual(
            list(graph.nodes),
            [
                LiEC_ind,
                LiEC_RO_ind,
                str(LiEC_ind) + "," + str(LiEC_RO_ind),
                str(LiEC_RO_ind) + "," + str(LiEC_ind),
            ],
        )
        self.assertEqual(len(graph.edges), 4)
        self.assertEqual(
            graph.get_edge_data(LiEC_ind,
                                str(LiEC_ind) + "," +
                                str(LiEC_RO_ind))["softplus"],
            0.15092362164364986,
        )
Пример #8
0
    def test_reaction_type(self):

        reaction = IntramolSingleBondChangeReaction(entries["LiEC"],
                                                    entries["LiEC_RO"])
        self.assertEqual(reaction.__class__.__name__,
                         "IntramolSingleBondChangeReaction")
        self.assertEqual(reaction.rxn_type_A,
                         "Intramolecular single bond formation")
        self.assertEqual(reaction.rxn_type_B,
                         "Intramolecular single bond breakage")
Пример #9
0
    def test_atom_mapping(self):

        entries = bucket_mol_entries([self.LiEC_RO_entry, self.LiEC_entry])

        reactions, families = IntramolSingleBondChangeReaction.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.LiEC_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: 2,
                3: 3,
                4: 4,
                5: 5,
                6: 6,
                7: 7,
                8: 8,
                9: 9,
                10: 10
            }],
        )
Пример #10
0
    def test_atom_mapping(self):

        ents = bucket_mol_entries([entries["LiEC_RO"], entries["LiEC"]])

        reactions = IntramolSingleBondChangeReaction.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.entry_id, entries["LiEC"].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: 2,
                1: 3,
                2: 1,
                3: 4,
                4: 5,
                5: 0,
                6: 6,
                7: 9,
                8: 10,
                9: 7,
                10: 8
            }],
        )
Пример #11
0
 def test_energy(self):
     reaction = IntramolSingleBondChangeReaction(entries["LiEC"],
                                                 entries["LiEC_RO"])
     self.assertEqual(reaction.energy_A, -0.0377282729020294)
     self.assertEqual(reaction.energy_B, 0.0377282729020294)
Пример #12
0
 def test_free_energy(self):
     reaction = IntramolSingleBondChangeReaction(entries["LiEC"],
                                                 entries["LiEC_RO"])
     reaction.set_free_energy()
     self.assertEqual(reaction.free_energy_A, -1.2094343722765188)
     self.assertEqual(reaction.free_energy_B, 1.2094343722765188)