Exemplo n.º 1
0
    def test_check_for_existing_reaction_removes_duplicates_in_opposite_directions(
            self):
        """
        Test that check_for_existing_reaction removes duplicate reverse reactions
        """
        cerm = CoreEdgeReactionModel()

        # make species' objects
        s1 = Species().from_smiles("[H]")
        s2 = Species().from_smiles("CC")
        s3 = Species().from_smiles("[H][H]")
        s4 = Species().from_smiles("C[CH2]")
        s1.label = 'H'
        s2.label = 'CC'
        s3.label = 'HH'
        s4.label = 'C[CH2]'

        rxn_f = TemplateReaction(reactants=[s1, s2],
                                 products=[s3, s4],
                                 template=['C/H3/Cs/H3', 'H_rad'],
                                 degeneracy=6,
                                 family='H_Abstraction',
                                 reverse=TemplateReaction(
                                     reactants=[s3, s4],
                                     products=[s1, s2],
                                     template=['H2', 'C_rad/H2/Cs/H3'],
                                     degeneracy=2,
                                     family='H_Abstraction'))

        rxn_r = TemplateReaction(reactants=[s3, s4],
                                 products=[s1, s2],
                                 template=['H2', 'C_rad/H2/Cs/H3'],
                                 degeneracy=2,
                                 family='H_Abstraction',
                                 reverse=TemplateReaction(
                                     reactants=[s1, s2],
                                     products=[s3, s4],
                                     template=['C/H3/Cs/H3', 'H_rad'],
                                     degeneracy=6,
                                     family='H_Abstraction'))

        rxn_f.reactants.sort()
        rxn_f.products.sort()

        cerm.add_reaction_to_core(rxn_f)
        cerm.register_reaction(rxn_f)

        reactions = cerm.search_retrieve_reactions(rxn_r)
        self.assertEqual(
            1, len(reactions),
            'cerm.search_retrieve_reactions could not identify reverse reaction'
        )

        found, rxn = cerm.check_for_existing_reaction(rxn_r)

        self.assertTrue(
            found,
            'check_for_existing_reaction failed to identify existing reaction in the reverse direction'
        )
        self.assertEqual(rxn, rxn_f)
Exemplo n.º 2
0
    def test_check_for_existing_reaction_eliminates_identical_reactions_without_duplicate_flag(
            self):
        """
        Test that check_for_existing_reaction eliminates reactions with different templates and duplicate=false
        """
        cerm = CoreEdgeReactionModel()

        # make species' objects
        spcA = Species().from_smiles('[H]')
        spcB = Species().from_smiles('C=C[CH2]C')
        spcC = Species().from_smiles('C=C=CC')
        spcD = Species().from_smiles('[H][H]')
        spcA.label = '[H]'
        spcB.label = 'C=C[CH2]C'
        spcC.label = 'C=C=CC'
        spcD.label = '[H][H]'
        spcB.generate_resonance_structures()

        cerm.add_species_to_core(spcA)
        cerm.add_species_to_core(spcB)
        cerm.add_species_to_core(spcC)
        cerm.add_species_to_core(spcD)

        reaction_in_model = TemplateReaction(reactants=[spcA, spcB],
                                             products=[spcC, spcD],
                                             family='H_Abstraction',
                                             template=['Csd', 'H'],
                                             duplicate=False)
        reaction_in_model.reactants.sort()
        reaction_in_model.products.sort()

        reaction_to_add = TemplateReaction(reactants=[spcA, spcB],
                                           products=[spcC, spcD],
                                           family='H_Abstraction',
                                           template=['Cs12345', 'H'],
                                           duplicate=False)
        cerm.add_reaction_to_core(reaction_in_model)
        cerm.register_reaction(reaction_in_model)

        found, rxn = cerm.check_for_existing_reaction(reaction_to_add)

        self.assertTrue(
            found,
            'check_for_existing_reaction failed to eliminate reactions without duplicate tag'
        )
Exemplo n.º 3
0
    def test_check_for_existing_reaction_eliminates_identical_reactions(self):
        """
        Test that check_for_existing_reaction catches identical reactions.
        """
        cerm = CoreEdgeReactionModel()

        # make species' objects
        spcA = Species().from_smiles('[H]')
        spcB = Species().from_smiles('C=C[CH2]C')
        spcC = Species().from_smiles('C=C=CC')
        spcD = Species().from_smiles('[H][H]')
        spcA.label = '[H]'
        spcB.label = 'C=C[CH2]C'
        spcC.label = 'C=C=CC'
        spcD.label = '[H][H]'
        spcB.generate_resonance_structures()

        cerm.add_species_to_core(spcA)
        cerm.add_species_to_core(spcB)
        cerm.add_species_to_core(spcC)
        cerm.add_species_to_core(spcD)

        reaction_in_model = TemplateReaction(reactants=[spcA, spcB],
                                             products=[spcC, spcD],
                                             family='H_Abstraction',
                                             template=['Csd', 'H'])
        reaction_in_model.reactants.sort()
        reaction_in_model.products.sort()

        reaction_to_add = TemplateReaction(reactants=[spcA, spcB],
                                           products=[spcC, spcD],
                                           family='H_Abstraction',
                                           template=['Csd', 'H'])
        cerm.add_reaction_to_core(reaction_in_model)
        cerm.register_reaction(reaction_in_model)

        found, rxn = cerm.check_for_existing_reaction(reaction_to_add)

        self.assertTrue(
            found,
            'check_for_existing_reaction failed to identify existing reaction')