예제 #1
0
    def test_calculate_degeneracy_for_non_reactive_molecule(self):
        """
        tests that the calculateDegeneracy method gets the degeneracy correct for unreactive molecules
        and that __generateReactions work correctly with the react_non_reactive flag set to `True`.
        """
        from rmgpy.data.rmg import getDB
        from rmgpy.data.kinetics.family import TemplateReaction

        adjlist = [
            '''
        multiplicity 2
        1 H u1 p0 c0''', '''
        multiplicity 2
        1 O u1 p1 c+1 {2,D}
        2 N u0 p2 c-1 {1,D}''', '''
        1 O u0 p1 c+1 {2,D} {3,S}
        2 N u0 p2 c-1 {1,D}
        3 H u0 p0 c0 {1,S}'''
        ]

        family = getDB('kinetics').families['R_Recombination']
        r1 = Species(molecule=[Molecule().fromAdjacencyList(adjlist[0])])
        r2 = Species(molecule=[Molecule().fromAdjacencyList(adjlist[1])
                               ])  # r2 is not the representative structure of
        # NO, but it is the correct structure participating in this reaction
        p1 = Species(molecule=[Molecule().fromAdjacencyList(adjlist[2])])
        r2.generate_resonance_structures(keep_isomorphic=True)

        rxn = TemplateReaction(reactants=[r1, r2], products=[p1])
        rxn.degeneracy = family.calculateDegeneracy(rxn)
        self.assertEqual(rxn.degeneracy, 1)
예제 #2
0
    def test_compare_isotopomers_fails_on_reactions(self):
        """
        Test that compareIsotomers fails on different reaction objects
        """
        h = Species().from_adjacency_list("""
multiplicity 2
1 H u1 p0 c0
""")
        h2 = Species().from_adjacency_list("""
1 H u0 p0 c0 {2,S}
2 H u0 p0 c0 {1,S}
""")
        propanei = Species().from_adjacency_list("""
1  C u0 p0 c0 {2,S} {4,S} {5,S} {6,S}
2  C u0 p0 c0 {1,S} {3,S} {7,S} {8,S}
3  C u0 p0 c0 i13 {2,S} {9,S} {10,S} {11,S}
4  H u0 p0 c0 {1,S}
5  H u0 p0 c0 {1,S}
6  H u0 p0 c0 {1,S}
7  H u0 p0 c0 {2,S}
8  H u0 p0 c0 {2,S}
9  H u0 p0 c0 {3,S}
10 H u0 p0 c0 {3,S}
11 H u0 p0 c0 {3,S}
""")
        propane = Species().from_adjacency_list("""
1  C u0 p0 c0 {2,S} {4,S} {5,S} {6,S}
2  C u0 p0 c0 {1,S} {3,S} {7,S} {8,S}
3  C u0 p0 c0 {2,S} {9,S} {10,S} {11,S}
4  H u0 p0 c0 {1,S}
5  H u0 p0 c0 {1,S}
6  H u0 p0 c0 {1,S}
7  H u0 p0 c0 {2,S}
8  H u0 p0 c0 {2,S}
9  H u0 p0 c0 {3,S}
10 H u0 p0 c0 {3,S}
11 H u0 p0 c0 {3,S}
""")
        npropyli = Species().from_adjacency_list("""
multiplicity 2
1  C u0 p0 c0 {2,S} {6,S} {7,S} {8,S}
2  C u0 p0 c0 {1,S} {3,S} {9,S} {10,S}
3  C u1 p0 c0 i13 {2,S} {4,S} {5,S}
4  H u0 p0 c0 {3,S}
5  H u0 p0 c0 {3,S}
6  H u0 p0 c0 {1,S}
7  H u0 p0 c0 {1,S}
8  H u0 p0 c0 {1,S}
9  H u0 p0 c0 {2,S}
10 H u0 p0 c0 {2,S}
""")

        reaction2 = TemplateReaction(reactants=[propanei, h],
                                     products=[npropyli, h2],
                                     family='H_Abstraction')

        magic_reaction = TemplateReaction(reactants=[propane, h],
                                         products=[propanei, h],
                                         family='H_Abstraction')
        self.assertFalse(compare_isotopomers(reaction2, magic_reaction))
    def test_calculate_degeneracy_for_non_reactive_molecule(self):
        """
        tests that the calculateDegeneracy method gets the degeneracy correct for unreactive molecules
        and that __generateReactions work correctly with the react_non_reactive flag set to `True`.
        """
        from rmgpy.data.rmg import getDB
        from rmgpy.data.kinetics.family import TemplateReaction

        adjlist = ['''
        multiplicity 2
        1 H u1 p0 c0''',
                   '''
        multiplicity 2
        1 O u1 p1 c+1 {2,D}
        2 N u0 p2 c-1 {1,D}''',
                   '''
        1 O u0 p1 c+1 {2,D} {3,S}
        2 N u0 p2 c-1 {1,D}
        3 H u0 p0 c0 {1,S}''']

        family = getDB('kinetics').families['R_Recombination']
        r1 = Species(molecule=[Molecule().fromAdjacencyList(adjlist[0])])
        r2 = Species(molecule=[Molecule().fromAdjacencyList(adjlist[1])])  # r2 is not the representative structure of
        # NO, but it is the correct structure participating in this reaction
        p1 = Species(molecule=[Molecule().fromAdjacencyList(adjlist[2])])
        r2.generate_resonance_structures(keep_isomorphic=True)

        rxn = TemplateReaction(reactants=[r1, r2], products=[p1])
        rxn.degeneracy = family.calculateDegeneracy(rxn)
        self.assertEqual(rxn.degeneracy, 1)
예제 #4
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)
예제 #5
0
    def test_checkForExistingReaction_removes_duplicates_in_opposite_directions(self):
        """
        Test that checkForExistingReaction will remove duplicates if reaction.reverse
        would be a duplicate
        """
        from rmgpy.data.kinetics.family import TemplateReaction
        cerm = CoreEdgeReactionModel()

        # make species' objects
        s1 = Species().fromSMILES("[H]")
        s2 = Species().fromSMILES("CC")
        s3 = Species().fromSMILES("[H][H]")
        s4 = Species().fromSMILES("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.addReactionToCore(rxn_f)
        cerm.registerReaction(rxn_f)

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

        found, rxn = cerm.checkForExistingReaction(rxn_r)

        self.assertTrue(found, 'checkForExistingReaction failed to identify existing reaction when it is in the reverse direction')
        self.assertEqual(rxn, rxn_f)
예제 #6
0
    def test_ensure_reaction_direction_with_multiple_ts(self):
        """Tests that ensure reaction direction can handle multiple transition states"""
        family = self.database.kinetics.families['intra_H_migration']
        r = Molecule().from_smiles("[CH2]CCC")
        p = Molecule().from_smiles("C[CH]CC")
        rxn = TemplateReaction(reactants=[r], products=[p])
        family.add_atom_labels_for_reaction(reaction=rxn)
        rxn.template = family.get_reaction_template_labels(reaction=rxn)
        rxn.degeneracy = family.calculate_degeneracy(rxn)
        rxn.family = 'intra_H_migration'
        rxn.kinetics = Arrhenius(A=(1, 's^-1'))
        ri = Molecule().from_adjacency_list("""
multiplicity 2
1  C u1 p0 c0 {2,S} {3,S} {4,S}
2  H u0 p0 c0 {1,S}
3  H u0 p0 c0 {1,S}
4  C u0 p0 c0 i13 {1,S} {5,S} {7,S} {8,S}
5  C u0 p0 c0 i13 {4,S} {6,S} {9,S} {10,S}
6  C u0 p0 c0 {5,S} {11,S} {12,S} {13,S}
7  H u0 p0 c0 {4,S}
8  H u0 p0 c0 {4,S}
9  H u0 p0 c0 {5,S}
10 H u0 p0 c0 {5,S}
11 H u0 p0 c0 {6,S}
12 H u0 p0 c0 {6,S}
13 H u0 p0 c0 {6,S}
""")
        pi = Molecule().from_adjacency_list("""
multiplicity 2
1  C u0 p0 c0 {2,S} {6,S} {7,S} {8,S}
2  C u1 p0 c0 i13 {1,S} {3,S} {4,S}
3  H u0 p0 c0 {2,S}
4  C u0 p0 c0 i13 {2,S} {5,S} {9,S} {10,S}
5  C u0 p0 c0 {4,S} {11,S} {12,S} {13,S}
6  H u0 p0 c0 {1,S}
7  H u0 p0 c0 {1,S}
8  H u0 p0 c0 {1,S}
9  H u0 p0 c0 {4,S}
10 H u0 p0 c0 {4,S}
11 H u0 p0 c0 {5,S}
12 H u0 p0 c0 {5,S}
13 H u0 p0 c0 {5,S}
""")
        rxni = TemplateReaction(reactants=[pi],
                                products=[ri],
                                pairs=[[pi, ri]])
        family.add_atom_labels_for_reaction(reaction=rxni)
        rxni.template = family.get_reaction_template_labels(reaction=rxni)
        rxn_cluster = [rxn, rxni]
        ensure_reaction_direction(rxn_cluster)

        self.assertEqual(rxn_cluster[0].degeneracy, 2)
        self.assertEqual(rxn_cluster[1].degeneracy, 2)

        self.assertIn('R2Hall', rxn_cluster[0].template)
        self.assertIn('R2Hall', rxn_cluster[1].template)

        self.assertAlmostEqual(
            rxn_cluster[0].kinetics.get_rate_coefficient(298),
            rxn_cluster[1].kinetics.get_rate_coefficient(298))
예제 #7
0
    def test_get_kinetic_isotope_effect_simple(self):
        reactant_pair = [
            Species().from_smiles("C"),
            Species().from_smiles("[H]")
        ]
        product_pair = [
            Species().from_smiles("[H][H]"),
            Species().from_smiles("[CH3]")
        ]
        rxn_unlabeled = TemplateReaction(reactants=reactant_pair,
                                         products=product_pair,
                                         family='H_Abstraction',
                                         kinetics=Arrhenius(A=(1e5,
                                                               'cm^3/(mol*s)'),
                                                            Ea=(0, 'J/mol')))
        rxn_labeled = TemplateReaction(reactants=[
            Species().from_adjacency_list("""
1 C u0 p0 c0 i13 {2,S} {3,S} {4,S} {5,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
4 H u0 p0 c0 {1,S}
5 H u0 p0 c0 {1,S}
"""),
            Species().from_adjacency_list("""
multiplicity 2
1 H u1 p0 c0
""")
        ],
                                       products=[
                                           Species().from_adjacency_list("""
1 H u0 p0 c0 {2,S}
2 H u0 p0 c0 {1,S}
"""),
                                           Species().from_adjacency_list("""
multiplicity 2
1 C u1 p0 c0 i13 {2,S} {3,S} {4,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
4 H u0 p0 c0 {1,S}
""")
                                       ],
                                       family='H_Abstraction',
                                       kinetics=Arrhenius(A=(1e5,
                                                             'cm^3/(mol*s)'),
                                                          Ea=(0, 'J/mol')))
        rxn_cluster = [[rxn_labeled, rxn_unlabeled]]
        apply_kinetic_isotope_effect_simple(rxn_cluster,
                                            self.database.kinetics)
        expected_kie = ((1 / 1.008 + 1 / (13.01 + 1.008)) /
                        (1 / 1.008 + 1 / (12.01 + 1.008)))**0.5
        self.assertAlmostEqual(rxn_cluster[0][0].kinetics.A.value,
                               1e5 * expected_kie,
                               places=-1)
예제 #8
0
    def test_generate_isotope_reactions_limited_labeling(self):
        """
        shows that all isotope reactions are created with generateIsotopeReactions
        with limits of two isotopes per molecule
        """
        max_number_labels = 1
        methyl = Species().from_smiles('[CH3]')
        methyl_isotopologues = [methyl] + generate_isotopomers(
            methyl, max_number_labels)
        methane = Species().from_smiles('C')
        methane_isotopologues = [methane] + generate_isotopomers(
            methane, max_number_labels)
        ethyl = Species().from_smiles('C[CH2]')
        ethyl_isotopologues = [ethyl] + generate_isotopomers(
            ethyl, max_number_labels)
        ethane = Species().from_smiles('CC')
        ethane_isotopologues = [ethane] + generate_isotopomers(
            ethane, max_number_labels)

        self.assertEqual(len(methyl_isotopologues), 2)
        self.assertEqual(len(methane_isotopologues), 2)
        self.assertEqual(len(ethane_isotopologues), 2)
        self.assertEqual(len(ethyl_isotopologues), 3)

        reaction = TemplateReaction(reactants=[ethyl, methane],
                                    products=[ethane, methyl],
                                    family='H_Abstraction',
                                    template=['C/H4', 'Y_rad'],
                                    degeneracy=4)
        reaction.kinetics = Arrhenius(A=(1e5, 'cm^3/(mol*s)'), Ea=(0, 'J/mol'))
        isotope_list = [
            methyl_isotopologues, methane_isotopologues, ethyl_isotopologues,
            ethane_isotopologues
        ]

        new_reactions = generate_isotope_reactions([reaction], isotope_list)

        self.assertEqual(len(new_reactions), 6)

        degeneracies_found = set()
        for rxn in new_reactions:
            self.assertEqual(rxn.template, reaction.template)
            degeneracies_found.add(rxn.degeneracy)
            self.assertIsNotNone(
                rxn.kinetics,
                'kinetics not obtained for reaction {}.'.format(rxn))
            self.assertAlmostEqual(
                reaction.kinetics.get_rate_coefficient(298),
                rxn.kinetics.get_rate_coefficient(298) * reaction.degeneracy /
                rxn.degeneracy)

        self.assertEqual(degeneracies_found, set([4]))
예제 #9
0
    def test_debug_forbidden_reverse_rxn(self, mock_logging):
        """Test that we can automatically debug when a reverse reaction is forbidden."""
        reactants = [
            Species().from_smiles('CC'),
            Species().from_smiles('[CH2]C=C[CH2]')
        ]
        products = [
            Species().from_smiles('C[CH2]'),
            Species().from_smiles('[CH2]C=CC')
        ]

        reaction = TemplateReaction(reactants=reactants, products=products)

        successful = self.database.kinetics.families[
            'H_Abstraction'].add_reverse_attribute(reaction)

        self.assertFalse(successful)

        mock_logging.error.assert_has_calls([
            mock.call(
                'Expecting one matching reverse reaction, not zero in reaction family H_Abstraction '
                'for forward reaction CC + [CH2]C=C[CH2] <=> C[CH2] + [CH2]C=CC.\n'
            ),
        ])

        mock_logging.error.assert_has_calls([
            mock.call(
                'Error was fixed, the product is a forbidden structure when '
                'used as a reactant in the reverse direction.'),
        ])
예제 #10
0
    def test_checkForExistingReaction_keeps_identical_reactions_with_duplicate_flag(
            self):
        """
        Test that checkForExistingReaction keeps reactions with different templates and duplicate=True.
        """
        cerm = CoreEdgeReactionModel()

        # make species' objects
        spcA = Species().fromSMILES('[H]')
        spcB = Species().fromSMILES('C=C[CH2]C')
        spcC = Species().fromSMILES('C=C=CC')
        spcD = Species().fromSMILES('[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.addSpeciesToCore(spcA)
        cerm.addSpeciesToCore(spcB)
        cerm.addSpeciesToCore(spcC)
        cerm.addSpeciesToCore(spcD)

        reaction_in_model = TemplateReaction(reactants=[spcA, spcB],
                                             products=[spcC, spcD],
                                             family='H_Abstraction',
                                             template=['Csd', 'H'],
                                             duplicate=True)
        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=True)
        cerm.addReactionToCore(reaction_in_model)
        cerm.registerReaction(reaction_in_model)

        found, rxn = cerm.checkForExistingReaction(reaction_to_add)

        self.assertFalse(
            found,
            'checkForExistingReaction failed to identify duplicate template reactions'
        )
예제 #11
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'
        )
    def testGenerateIsotopeReactionsLimitedLabeling(self):
        """
        shows that all isotope reactions are created with generateIsotopeReactions
        with limits of two isotopes per molecule
        """
        max_number_labels = 1
        methyl = Species().fromSMILES('[CH3]')
        methyl_isotopologues = [methyl] + generate_isotopomers(methyl,max_number_labels)
        methane = Species().fromSMILES('C')
        methane_isotopologues = [methane] + generate_isotopomers(methane,max_number_labels)
        ethyl = Species().fromSMILES('C[CH2]')
        ethyl_isotopologues = [ethyl] + generate_isotopomers(ethyl,max_number_labels)
        ethane = Species().fromSMILES('CC')
        ethane_isotopologues = [ethane] + generate_isotopomers(ethane,max_number_labels)

        self.assertEqual(len(methyl_isotopologues),2)
        self.assertEqual(len(methane_isotopologues),2)
        self.assertEqual(len(ethane_isotopologues),2)
        self.assertEqual(len(ethyl_isotopologues),3)

        reaction = TemplateReaction(reactants = [ethyl,methane],
                                    products = [ethane,methyl],
                                    family = 'H_Abstraction',
                                    template = ['C/H4', 'Y_rad'],
                                    degeneracy = 4)
        reaction.kinetics = Arrhenius(A=(1e5,'cm^3/(mol*s)'),Ea=(0,'J/mol'))
        isotope_list = [methyl_isotopologues,
                        methane_isotopologues,
                        ethyl_isotopologues,
                        ethane_isotopologues]

        new_reactions = generate_isotope_reactions([reaction], isotope_list)

        self.assertEqual(len(new_reactions), 6)

        degeneracies_found = set()
        for rxn in new_reactions:
            self.assertEqual(rxn.template, reaction.template)
            degeneracies_found.add(rxn.degeneracy)
            self.assertIsNotNone(rxn.kinetics,'kinetics not obtained for reaction {}.'.format(rxn))
            self.assertAlmostEqual(reaction.kinetics.getRateCoefficient(298),
                                   rxn.kinetics.getRateCoefficient(298) *\
                                    reaction.degeneracy / rxn.degeneracy)

        self.assertEqual(degeneracies_found, set([4]))
예제 #13
0
    def test_addAtomLabelsForReaction(self):
        """Test that we can add atom labels to an existing reaction"""
        reactants = [Species().fromSMILES('C=C'), Species().fromSMILES('[OH]')]
        products = [Species().fromSMILES('[CH2]CO')]

        reaction = TemplateReaction(reactants=reactants, products=products)

        self.database.kinetics.families[
            'R_Addition_MultipleBond'].addAtomLabelsForReaction(reaction)

        expected_reactants = [
            Molecule().fromAdjacencyList("""
1 *1 C u0 p0 c0 {2,D} {3,S} {4,S}
2 *2 C u0 p0 c0 {1,D} {5,S} {6,S}
3    H u0 p0 c0 {1,S}
4    H u0 p0 c0 {1,S}
5    H u0 p0 c0 {2,S}
6    H u0 p0 c0 {2,S}
"""),
            Molecule().fromAdjacencyList("""
multiplicity 2
1 *3 O u1 p2 c0 {2,S}
2    H u0 p0 c0 {1,S}
""")
        ]

        expected_products = [
            Molecule().fromAdjacencyList("""
multiplicity 2
1 *1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2 *2 C u1 p0 c0 {1,S} {6,S} {7,S}
3 *3 O u0 p2 c0 {1,S} {8,S}
4    H u0 p0 c0 {1,S}
5    H u0 p0 c0 {1,S}
6    H u0 p0 c0 {2,S}
7    H u0 p0 c0 {2,S}
8    H u0 p0 c0 {3,S}
""")
        ]

        for i, reactant in enumerate(reaction.reactants):
            mapping = {}
            for label, atom in expected_reactants[i].getLabeledAtoms(
            ).iteritems():
                mapping[atom] = reactant.molecule[0].getLabeledAtom(label)

            self.assertTrue(expected_reactants[i].isIsomorphic(
                reactant.molecule[0], mapping))

        for i, product in enumerate(reaction.products):
            mapping = {}
            for label, atom in expected_products[i].getLabeledAtoms(
            ).iteritems():
                mapping[atom] = product.molecule[0].getLabeledAtom(label)

            self.assertTrue(expected_products[i].isIsomorphic(
                product.molecule[0], mapping))
예제 #14
0
    def test_is_enriched(self):
        """
        ensures the Enriched method functions
        """
        npropyl = Species().from_adjacency_list("""
multiplicity 2
1  C u0 p0 c0 {2,S} {6,S} {7,S} {8,S}
2  C u0 p0 c0 {1,S} {3,S} {9,S} {10,S}
3  C u1 p0 c0 {2,S} {4,S} {5,S}
4  H u0 p0 c0 {3,S}
5  H u0 p0 c0 {3,S}
6  H u0 p0 c0 {1,S}
7  H u0 p0 c0 {1,S}
8  H u0 p0 c0 {1,S}
9  H u0 p0 c0 {2,S}
10 H u0 p0 c0 {2,S}
""")
        npropyli = Species().from_adjacency_list("""
multiplicity 2
1  C u0 p0 c0 {2,S} {6,S} {7,S} {8,S}
2  C u0 p0 c0 i13 {1,S} {3,S} {9,S} {10,S}
3  C u1 p0 c0 {2,S} {4,S} {5,S}
4  H u0 p0 c0 {3,S}
5  H u0 p0 c0 {3,S}
6  H u0 p0 c0 {1,S}
7  H u0 p0 c0 {1,S}
8  H u0 p0 c0 {1,S}
9  H u0 p0 c0 {2,S}
10 H u0 p0 c0 {2,S}
""")

        self.assertTrue(is_enriched(npropyli))
        self.assertFalse(is_enriched(npropyl))

        enriched_reaction = TemplateReaction(reactants=[npropyl],
                                            products=[npropyli],
                                            family='H_Abstraction')
        self.assertTrue(is_enriched(enriched_reaction))

        bare_reaction = TemplateReaction(reactants=[npropyl],
                                        products=[npropyl],
                                        family='H_Abstraction')

        self.assertFalse(is_enriched(bare_reaction))
예제 #15
0
    def test_checkForExistingReaction_removes_duplicates_in_opposite_directions(
            self):
        """
        Test that checkForExistingReaction will remove duplicates if reaction.reverse
        would be a duplicate
        """
        from rmgpy.data.kinetics.family import TemplateReaction
        cerm = CoreEdgeReactionModel()

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

        cerm.addSpeciesToCore(spcA)
        cerm.addSpeciesToCore(spcB)
        cerm.addSpeciesToCore(spcC)
        cerm.addSpeciesToCore(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.addReactionToCore(reaction_in_model)
        cerm.registerReaction(reaction_in_model)

        found, rxn = cerm.checkForExistingReaction(reaction_to_add)

        self.assertTrue(
            found,
            'checkForExistingReaction failed to identify existing reaction')
예제 #16
0
    def test_checkForExistingReaction_keeps_different_template_reactions(self):
        """
        Test that checkForExistingReaction keeps reactions with different templates
        """
        from rmgpy.data.kinetics.family import TemplateReaction
        cerm = CoreEdgeReactionModel()

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

        cerm.addSpeciesToCore(spcA)
        cerm.addSpeciesToCore(spcB)
        cerm.addSpeciesToCore(spcC)
        cerm.addSpeciesToCore(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=['Cs12345', 'H'])
        cerm.addReactionToCore(reaction_in_model)
        cerm.registerReaction(reaction_in_model)

        found, rxn = cerm.checkForExistingReaction(reaction_to_add)

        self.assertFalse(
            found,
            'checkForExistingReaction failed to identify reactions with different templates'
        )
예제 #17
0
    def testThermoFilterDown(self):
        """
        test that thermoFilterDown with maximumEdgeSpecies = 1 reduces
        the edge to one species
        """
        cerm = CoreEdgeReactionModel()

        spcs = [Species().fromSMILES('[OH]'), 
                Species().fromSMILES('C'),
                Species().fromSMILES('[CH3]'),
                Species().fromSMILES('[CH2]'),
                Species().fromSMILES('O')]
        
        for spc in spcs:
            cerm.makeNewSpecies(spc,label=spc.molecule[0].toSMILES())
            spc.label = spc.molecule[0].toSMILES()
        
        thermoDict = {'[OH]':NASA(polynomials=[NASAPolynomial(coeffs=[3.51457,2.92787e-05,-5.32168e-07,1.0195e-09,-3.85947e-13,3414.25,2.10435], Tmin=(100,'K'), Tmax=(1145.75,'K')), NASAPolynomial(coeffs=[3.07194,0.000604014,-1.39775e-08,-2.13448e-11,2.48067e-15,3579.39,4.578], Tmin=(1145.75,'K'), Tmax=(5000,'K'))], Tmin=(100,'K'), Tmax=(5000,'K'), E0=(28.3945,'kJ/mol'), Cp0=(29.1007,'J/(mol*K)'), CpInf=(37.4151,'J/(mol*K)'), label="""OH(D)""", comment="""Thermo library: primaryThermoLibrary"""),
        'C' : NASA(polynomials=[NASAPolynomial(coeffs=[4.20541,-0.00535551,2.51121e-05,-2.1376e-08,5.97513e-12,-10161.9,-0.921259], Tmin=(100,'K'), Tmax=(1084.13,'K')), NASAPolynomial(coeffs=[0.908298,0.011454,-4.57171e-06,8.29185e-10,-5.66309e-14,-9719.99,13.9929], Tmin=(1084.13,'K'), Tmax=(5000,'K'))], Tmin=(100,'K'), Tmax=(5000,'K'), E0=(-84.435,'kJ/mol'), Cp0=(33.2579,'J/(mol*K)'), CpInf=(108.088,'J/(mol*K)'), label="""CH4""", comment="""Thermo library: primaryThermoLibrary"""),
        '[CH3]' : NASA(polynomials=[NASAPolynomial(coeffs=[3.67359,0.00201095,5.73022e-06,-6.87117e-09,2.54386e-12,16445,1.60456], Tmin=(200,'K'), Tmax=(1000,'K')), NASAPolynomial(coeffs=[2.28572,0.0072399,-2.98714e-06,5.95685e-10,-4.67154e-14,16775.6,8.48007], Tmin=(1000,'K'), Tmax=(3500,'K'))], Tmin=(200,'K'), Tmax=(3500,'K'), E0=(136.42,'kJ/mol'), Cp0=(33.2579,'J/(mol*K)'), CpInf=(83.1447,'J/(mol*K)'), label="""CH3""", comment="""Thermo library: GRI-Mech3.0"""),
        '[CH2]': NASA(polynomials=[NASAPolynomial(coeffs=[4.01192,-0.000154978,3.26298e-06,-2.40422e-09,5.69497e-13,45867.7,0.533201], Tmin=(100,'K'), Tmax=(1104.62,'K')), NASAPolynomial(coeffs=[3.14983,0.00296674,-9.76056e-07,1.54115e-10,-9.50338e-15,46058.1,4.77808], Tmin=(1104.62,'K'), Tmax=(5000,'K'))], Tmin=(100,'K'), Tmax=(5000,'K'), E0=(381.37,'kJ/mol'), Cp0=(33.2579,'J/(mol*K)'), CpInf=(58.2013,'J/(mol*K)'), label="""CH2(T)""", comment="""Thermo library: primaryThermoLibrary"""),
        'O' : NASA(polynomials=[NASAPolynomial(coeffs=[4.05764,-0.000787936,2.90877e-06,-1.47519e-09,2.12842e-13,-30281.6,-0.311364], Tmin=(100,'K'), Tmax=(1130.24,'K')), NASAPolynomial(coeffs=[2.84325,0.00275109,-7.81031e-07,1.07244e-10,-5.79392e-15,-29958.6,5.91042], Tmin=(1130.24,'K'), Tmax=(5000,'K'))], Tmin=(100,'K'), Tmax=(5000,'K'), E0=(-251.755,'kJ/mol'), Cp0=(33.2579,'J/(mol*K)'), CpInf=(58.2013,'J/(mol*K)'), label="""H2O""", comment="""Thermo library: primaryThermoLibrary"""),
        }
        
        for spc in spcs[:3]:
            cerm.addSpeciesToCore(spc)
            
        reaction = TemplateReaction(
            reactants = [spcs[0],spcs[2]],
            products = [spcs[-1],spcs[-2]],
            degeneracy = 1,
            reversible = True,
            family = 'H_Abstraction',
        )
        
        cerm.processNewReactions(newReactions=[reaction],newSpecies=[]) #add CH2 and O to edge
        
        for spc in cerm.core.species+cerm.edge.species:
            spc.thermo = thermoDict[spc.molecule[0].toSMILES()] #assign thermo
        
        cerm.setThermodynamicFilteringParameters(Tmax=300.0, 
                                                 toleranceThermoKeepSpeciesInEdge=1000.0,
                                                 minCoreSizeForPrune=0,
                                                 maximumEdgeSpecies=1,
                                                 reactionSystems=[])
           
        difset = set([x.molecule[0].toSMILES() for x in cerm.edge.species])-set([x.molecule[0].toSMILES() for x in cerm.core.species])
        
        self.assertEquals(len(difset),2) #no change because toleranceThermoKeepSpeciesInEdge is high
        
        cerm.thermoFilterDown(maximumEdgeSpecies=1)
        
        difset = set([x.molecule[0].toSMILES() for x in cerm.edge.species])-set([x.molecule[0].toSMILES() for x in cerm.core.species])
        
        self.assertEquals(len(difset),1) #should be one because we thermo filtered down to one edge species
    def test_ensure_reaction_direction_with_multiple_TS(self):
        """Tests that ensure reaction direction can handle multiple transition states"""
        family = self.database.kinetics.families['intra_H_migration']
        r = Molecule().fromSMILES("[CH2]CCC")
        p = Molecule().fromSMILES("C[CH]CC")
        rxn = TemplateReaction(reactants=[r], products=[p])
        family.addAtomLabelsForReaction(reaction=rxn)
        rxn.template = family.getReactionTemplateLabels(reaction=rxn)
        rxn.degeneracy = family.calculateDegeneracy(rxn)
        rxn.family = 'intra_H_migration'
        rxn.kinetics = Arrhenius(A=(1,'s^-1'))
        ri = Molecule().fromAdjacencyList("""
        multiplicity 2
        1  C u1 p0 c0 {2,S} {3,S} {4,S}
        2  H u0 p0 c0 {1,S}
        3  H u0 p0 c0 {1,S}
        4  C u0 p0 c0 i13 {1,S} {5,S} {7,S} {8,S}
        5  C u0 p0 c0 i13 {4,S} {6,S} {9,S} {10,S}
        6  C u0 p0 c0 {5,S} {11,S} {12,S} {13,S}
        7  H u0 p0 c0 {4,S}
        8  H u0 p0 c0 {4,S}
        9  H u0 p0 c0 {5,S}
        10 H u0 p0 c0 {5,S}
        11 H u0 p0 c0 {6,S}
        12 H u0 p0 c0 {6,S}
        13 H u0 p0 c0 {6,S}
        """)
        pi = Molecule().fromAdjacencyList("""
        multiplicity 2
        1  C u0 p0 c0 {2,S} {6,S} {7,S} {8,S}
        2  C u1 p0 c0 i13 {1,S} {3,S} {4,S}
        3  H u0 p0 c0 {2,S}
        4  C u0 p0 c0 i13 {2,S} {5,S} {9,S} {10,S}
        5  C u0 p0 c0 {4,S} {11,S} {12,S} {13,S}
        6  H u0 p0 c0 {1,S}
        7  H u0 p0 c0 {1,S}
        8  H u0 p0 c0 {1,S}
        9  H u0 p0 c0 {4,S}
        10 H u0 p0 c0 {4,S}
        11 H u0 p0 c0 {5,S}
        12 H u0 p0 c0 {5,S}
        13 H u0 p0 c0 {5,S}
        """)
        rxni = TemplateReaction(reactants=[pi], products=[ri],pairs=[[pi,ri]])
        family.addAtomLabelsForReaction(reaction=rxni)
        rxni.template = family.getReactionTemplateLabels(reaction=rxni)
        rxn_cluster = [rxn,rxni]
        ensure_reaction_direction(rxn_cluster)

        self.assertEqual(rxn_cluster[0].degeneracy, 2)
        self.assertEqual(rxn_cluster[1].degeneracy, 2)

        self.assertIn('R2Hall', rxn_cluster[0].template)
        self.assertIn('R2Hall', rxn_cluster[1].template)

        self.assertAlmostEqual(rxn_cluster[0].kinetics.getRateCoefficient(298),
                               rxn_cluster[1].kinetics.getRateCoefficient(298))
예제 #19
0
    def test_add_atom_labels_for_reaction_3(self):
        """Test that addAtomLabelsForReaction can identify reactions with resonance and isotopes"""
        from rmgpy.data.rmg import getDB
        mr0 = Molecule().fromAdjacencyList(
            '1    C u0 p0 c0 i13 {3,D} {4,S} {5,S}\n2 *1 C u0 p0 c0 {3,D} {6,S} {7,S}\n3    C u0 p0 c0 {1,D} {2,D}\n4    H u0 p0 c0 {1,S}\n5    H u0 p0 c0 {1,S}\n6    H u0 p0 c0 {2,S}\n7 *4 H u0 p0 c0 {2,S}\n'
        )
        mr1a = Molecule().fromAdjacencyList(
            'multiplicity 2\n1    C u0 p0 c0 i13 {2,D} {4,S} {5,S}\n2    C u0 p0 c0 {1,D} {3,D}\n3 *1 C u1 p0 c0 {2,D} {6,S}\n4    H u0 p0 c0 {1,S}\n5    H u0 p0 c0 {1,S}\n6    H u0 p0 c0 {3,S}\n'
        )
        mr1b = Molecule().fromAdjacencyList(
            'multiplicity 2\n1    C u1 p0 c0 i13 {2,S} {4,S} {5,S}\n2    C u0 p0 c0 {1,S} {3,T}\n3 *1 C u0 p0 c0 {2,T} {6,S}\n4    H u0 p0 c0 {1,S}\n5    H u0 p0 c0 {1,S}\n6    H u0 p0 c0 {3,S}\n'
        )
        mp1a = Molecule().fromAdjacencyList(
            'multiplicity 2\n1    C u0 p0 c0 {2,D} {4,S} {5,S}\n2    C u0 p0 c0 {1,D} {3,D}\n3 *1 C u1 p0 c0 i13 {2,D} {6,S}\n4    H u0 p0 c0 {1,S}\n5    H u0 p0 c0 {1,S}\n6    H u0 p0 c0 {3,S}\n'
        )
        mp1b = Molecule().fromAdjacencyList(
            'multiplicity 2\n1    C u1 p0 c0 {2,S} {4,S} {5,S}\n2    C u0 p0 c0 {1,S} {3,T}\n3 *1 C u0 p0 c0 i13 {2,T} {6,S}\n4    H u0 p0 c0 {1,S}\n5    H u0 p0 c0 {1,S}\n6    H u0 p0 c0 {3,S}\n'
        )
        s1 = Species(molecule=[mr0])
        s2 = Species(molecule=[mr1a, mr1b])
        s3 = Species(molecule=[mp1a, mp1b])
        reactants = [s1, s2]
        products = [s1, s3]
        reaction = TemplateReaction(reactants=reactants,
                                    products=products,
                                    family='H_Abstraction')
        family = getDB('kinetics').families['H_Abstraction']
        print reaction.reactants
        print reaction.products
        family.addAtomLabelsForReaction(reaction, output_with_resonance=False)

        # test that the reaction has labels
        found_labels = []
        for species in reaction.reactants:
            for atom in species.molecule[0].atoms:
                if atom.label != '':
                    found_labels.append(atom.label)
        self.assertEqual(
            len(found_labels), 3,
            'wrong number of labels found {0}'.format(found_labels))
        self.assertIn('*1', found_labels)
        self.assertIn('*2', found_labels)
        self.assertIn('*3', found_labels)

        # test for the products too
        found_labels = []
        for species in reaction.products:
            for atom in species.molecule[0].atoms:
                if atom.label != '':
                    found_labels.append(atom.label)
        self.assertEqual(len(found_labels), 3)
        self.assertIn('*1', found_labels)
        self.assertIn('*2', found_labels)
        self.assertIn('*3', found_labels)
예제 #20
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')
예제 #21
0
    def test_add_atom_labels_for_reaction(self):
        """Test that addAtomLabelsForReaction can identify reactions with resonance
        The molecule [CH]=C=C has resonance in this reaction"""
        from rmgpy.data.rmg import getDB
        reactants = [
            Molecule().fromSMILES('C=C=C'),
            Molecule().fromSMILES('[CH]=C=C'),
        ]
        products = [
            Molecule().fromSMILES('C#C[CH2]'),
            Molecule().fromSMILES('C#CC'),
        ]
        reaction = TemplateReaction(reactants=reactants,
                                    products=products,
                                    family='H_Abstraction')
        reaction.ensure_species(reactant_resonance=True,
                                product_resonance=True)
        family = getDB('kinetics').families['H_Abstraction']
        family.addAtomLabelsForReaction(reaction, output_with_resonance=False)

        # test that the reaction has labels
        found_labels = []
        for species in reaction.reactants:
            for atom in species.molecule[0].atoms:
                if atom.label != '':
                    found_labels.append(atom.label)
        self.assertEqual(len(found_labels), 3)
        self.assertIn('*1', found_labels)
        self.assertIn('*2', found_labels)
        self.assertIn('*3', found_labels)

        # test for the products too
        found_labels = []
        for species in reaction.products:
            for atom in species.molecule[0].atoms:
                if atom.label != '':
                    found_labels.append(atom.label)
        self.assertEqual(len(found_labels), 3)
        self.assertIn('*1', found_labels)
        self.assertIn('*2', found_labels)
        self.assertIn('*3', found_labels)
예제 #22
0
    def test_checkForExistingReaction_elminates_duplicate(self):
        """
        Test that checkForExistingReaction catches duplicate reactions
        """
        cerm = CoreEdgeReactionModel()

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

        cerm.addSpeciesToCore(spcA)
        cerm.addSpeciesToCore(spcB)
        cerm.addSpeciesToCore(spcC)
        cerm.addSpeciesToCore(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.addReactionToCore(reaction_in_model)
        cerm.registerReaction(reaction_in_model)

        found, rxn = cerm.checkForExistingReaction(reaction_to_add)

        self.assertTrue(
            found,
            'checkForExistingReaction failed to identify existing reaction')
    def test_add_atom_labels_for_reaction(self):
        """Test that addAtomLabelsForReaction can identify reactions with resonance
        The molecule [CH]=C=C has resonance in this reaction"""
        from rmgpy.data.rmg import getDB
        reactants = [
            Molecule().fromSMILES('C=C=C'),
            Molecule().fromSMILES('[CH]=C=C'),
        ]
        products = [
            Molecule().fromSMILES('C#C[CH2]'),
            Molecule().fromSMILES('C#CC'),
        ]
        reaction = TemplateReaction(reactants =reactants,
                                    products = products,
                                    family = 'H_Abstraction')
        reaction.ensure_species(reactant_resonance=True, product_resonance=True)
        family = getDB('kinetics').families['H_Abstraction']
        family.addAtomLabelsForReaction(reaction, output_with_resonance=False)

        # test that the reaction has labels
        found_labels = []
        for species in reaction.reactants:
            for atom in species.molecule[0].atoms:
                if atom.label != '':
                    found_labels.append(atom.label)
        self.assertEqual(len(found_labels), 3)
        self.assertIn('*1',found_labels)
        self.assertIn('*2',found_labels)
        self.assertIn('*3',found_labels)

        # test for the products too
        found_labels = []
        for species in reaction.products:
            for atom in species.molecule[0].atoms:
                if atom.label != '':
                    found_labels.append(atom.label)
        self.assertEqual(len(found_labels), 3)
        self.assertIn('*1',found_labels)
        self.assertIn('*2',found_labels)
        self.assertIn('*3',found_labels)
예제 #24
0
 def test_get_labeled_reactants(self):
     """
     tests to ensure that get_labeled_reactants returns labeled reactants
     """
     reactant_pair = [Species().from_smiles("C"), Species().from_smiles("[H]")]
     product_pair = [Species().from_smiles("[H][H]"), Species().from_smiles("[CH3]")]
     rxn = TemplateReaction(reactants=reactant_pair,
                            products=product_pair,
                            family='H_Abstraction')
     labeled_reactants = get_labeled_reactants(rxn, self.family)
     r1_labels = labeled_reactants[0].get_all_labeled_atoms()
     self.assertIn("*1", list(r1_labels.keys()))
     self.assertIn("*2", list(r1_labels.keys()))
     r2_labels = labeled_reactants[1].get_all_labeled_atoms()
     self.assertIn("*3", list(r2_labels.keys()))
예제 #25
0
    def get_library_reactions(self):
        """
        makes library and template reactions as appropriate from the library comments
        and returns at list of all of these LibraryReaction and TemplateReaction objects
        """
        rxns = []
        for entry in self.entries.values():
            if self.auto_generated and entry.long_desc and 'Originally from reaction library: ' in entry.long_desc:
                lib = [line for line in entry.long_desc.split('\n') if 'Originally from reaction library: ' in line]
                lib = lib[0].replace('Originally from reaction library: ', '')
                lib = lib.replace('\n', '')
                # Clean up any leading indents in kinetics comment
                entry.data.comment = '\n'.join([line.strip() for line in entry.data.comment.split('\n')])
                rxn = LibraryReaction(reactants=entry.item.reactants[:], products=entry.item.products[:],
                                      library=lib, specific_collider=entry.item.specific_collider, kinetics=entry.data,
                                      duplicate=entry.item.duplicate, reversible=entry.item.reversible,
                                      allow_pdep_route=entry.item.allow_pdep_route,
                                      elementary_high_p=entry.item.elementary_high_p)
                rxn.family = self.label  # the library the reaction was loaded from (opposed to originally from)
            elif self.auto_generated and entry.long_desc and 'rate rule' in entry.long_desc:  # template reaction
                family = ''
                template = ''
                for line in entry.long_desc.split('\n'):
                    line = line.strip()
                    if 'rate rule' in line:
                        rule_part = line.split('rate rule')[1].strip()
                        template = re.split(r'\[(.*)\]', rule_part)[1]  # Remove outer brackets and trailing text
                    elif 'family:' in line:
                        family = line.split('family:')[1].strip()
                # Clean up any leading indents in kinetics comment
                entry.data.comment = '\n'.join([line.strip() for line in entry.data.comment.split('\n')])
                rxn = TemplateReaction(reactants=entry.item.reactants[:], products=entry.item.products[:],
                                       specific_collider=entry.item.specific_collider, kinetics=entry.data,
                                       duplicate=entry.item.duplicate, reversible=entry.item.reversible,
                                       family=family, template=template, degeneracy=entry.item.degeneracy)
            else:  # pdep or standard library reaction
                rxn = LibraryReaction(reactants=entry.item.reactants[:], products=entry.item.products[:],
                                      library=self.label, specific_collider=entry.item.specific_collider,
                                      kinetics=entry.data, duplicate=entry.item.duplicate,
                                      reversible=entry.item.reversible, allow_pdep_route=entry.item.allow_pdep_route,
                                      elementary_high_p=entry.item.elementary_high_p)
            rxns.append(rxn)

        return rxns
예제 #26
0
    def test_add_atom_labels_for_reaction_2(self):
        """Test that addAtomLabelsForReaction can identify reactions with identical references
        The molecule [CH]=C=C has resonance in this reaction"""
        from rmgpy.data.rmg import getDB
        s1 = Species().fromSMILES('C=C=C')
        s2 = Species().fromSMILES('C=C=[CH]')
        s3 = Species().fromSMILES('C#CC')
        s2.generate_resonance_structures()
        reactants = [s1, s2]
        products = [s2, s3]
        reaction = TemplateReaction(reactants=reactants,
                                    products=products,
                                    family='H_Abstraction')
        family = getDB('kinetics').families['H_Abstraction']
        print reaction.reactants
        print reaction.products
        family.addAtomLabelsForReaction(reaction, output_with_resonance=False)

        # test that the reaction has labels
        found_labels = []
        for species in reaction.reactants:
            for atom in species.molecule[0].atoms:
                if atom.label != '':
                    found_labels.append(atom.label)
        self.assertEqual(
            len(found_labels), 3,
            'wrong number of labels found {0}'.format(found_labels))
        self.assertIn('*1', found_labels)
        self.assertIn('*2', found_labels)
        self.assertIn('*3', found_labels)

        # test for the products too
        found_labels = []
        for species in reaction.products:
            for atom in species.molecule[0].atoms:
                if atom.label != '':
                    found_labels.append(atom.label)
        self.assertEqual(len(found_labels), 3)
        self.assertIn('*1', found_labels)
        self.assertIn('*2', found_labels)
        self.assertIn('*3', found_labels)
예제 #27
0
    def testCompareIsotopomersWorksOnReactions(self):
        """
        Test that compareIsotomers works on different reaction objects
        """
        h = Species().fromAdjacencyList("""
multiplicity 2
1 H u1 p0 c0
        """)
        h2 = Species().fromAdjacencyList("""
1 H u0 p0 c0 {2,S}
2 H u0 p0 c0 {1,S}
        """)
        propanei = Species().fromAdjacencyList("""
1  C u0 p0 c0 {2,S} {4,S} {5,S} {6,S}
2  C u0 p0 c0 {1,S} {3,S} {7,S} {8,S}
3  C u0 p0 c0 i13 {2,S} {9,S} {10,S} {11,S}
4  H u0 p0 c0 {1,S}
5  H u0 p0 c0 {1,S}
6  H u0 p0 c0 {1,S}
7  H u0 p0 c0 {2,S}
8  H u0 p0 c0 {2,S}
9  H u0 p0 c0 {3,S}
10 H u0 p0 c0 {3,S}
11 H u0 p0 c0 {3,S}
        """)
        propane = Species().fromAdjacencyList("""
1  C u0 p0 c0 {2,S} {4,S} {5,S} {6,S}
2  C u0 p0 c0 {1,S} {3,S} {7,S} {8,S}
3  C u0 p0 c0 {2,S} {9,S} {10,S} {11,S}
4  H u0 p0 c0 {1,S}
5  H u0 p0 c0 {1,S}
6  H u0 p0 c0 {1,S}
7  H u0 p0 c0 {2,S}
8  H u0 p0 c0 {2,S}
9  H u0 p0 c0 {3,S}
10 H u0 p0 c0 {3,S}
11 H u0 p0 c0 {3,S}
        """)
        npropyli = Species().fromAdjacencyList("""
multiplicity 2
1  C u0 p0 c0 {2,S} {6,S} {7,S} {8,S}
2  C u0 p0 c0 {1,S} {3,S} {9,S} {10,S}
3  C u1 p0 c0 i13 {2,S} {4,S} {5,S}
4  H u0 p0 c0 {3,S}
5  H u0 p0 c0 {3,S}
6  H u0 p0 c0 {1,S}
7  H u0 p0 c0 {1,S}
8  H u0 p0 c0 {1,S}
9  H u0 p0 c0 {2,S}
10 H u0 p0 c0 {2,S}
        """)
        npropyl = Species().fromAdjacencyList("""
multiplicity 2
1  C u0 p0 c0 {2,S} {6,S} {7,S} {8,S}
2  C u0 p0 c0 {1,S} {3,S} {9,S} {10,S}
3  C u1 p0 c0 {2,S} {4,S} {5,S}
4  H u0 p0 c0 {3,S}
5  H u0 p0 c0 {3,S}
6  H u0 p0 c0 {1,S}
7  H u0 p0 c0 {1,S}
8  H u0 p0 c0 {1,S}
9  H u0 p0 c0 {2,S}
10 H u0 p0 c0 {2,S}
        """)

        reaction2 = TemplateReaction(reactants=[propanei, h],
                                     products=[npropyli, h2],
                                     family='H_Abstraction')
        reaction3 = TemplateReaction(reactants=[propane, h],
                                     products=[h2, npropyl],
                                     family='H_Abstraction')
        self.assertTrue(compare_isotopomers(reaction2, reaction3))
    def testaddReverseAttribute(self):
        """
        tests that the addReverseAttribute method gets the reverse degeneracy correct
        """
        from rmgpy.data.rmg import getDB
        from rmgpy.data.kinetics.family import TemplateReaction
        adjlist = ['''
        multiplicity 2
        1 H u0 p0 c0 {7,S}
        2 H u0 p0 c0 {4,S}
        3 C u1 p0 c0 {5,S} {7,S} {8,S}
        4 C u0 p0 c0 {2,S} {6,S} {7,D}
        5 H u0 p0 c0 {3,S}
        6 H u0 p0 c0 {4,S}
        7 C u0 p0 c0 {1,S} {3,S} {4,D}
        8 H u0 p0 c0 {3,S}
        ''',
          '''
        1 C u0 p0 c0 {2,S} {4,S} {5,S} {6,S}
        2 C u0 p0 c0 i13 {1,S} {3,D} {7,S}
        3 C u0 p0 c0 {2,D} {8,S} {9,S}
        4 H u0 p0 c0 {1,S}
        5 H u0 p0 c0 {1,S}
        6 H u0 p0 c0 {1,S}
        7 H u0 p0 c0 {2,S}
        8 H u0 p0 c0 {3,S}
        9 H u0 p0 c0 {3,S}
        ''',
                '''
        multiplicity 2
        1 H u0 p0 c0 {7,S}
        2 H u0 p0 c0 {4,S}
        3 C u1 p0 c0 {5,S} {7,S} {8,S}
        4 C u0 p0 c0 {2,S} {6,S} {7,D}
        5 H u0 p0 c0 {3,S}
        6 H u0 p0 c0 {4,S}
        7 C u0 p0 c0 i13 {1,S} {3,S} {4,D}
        8 H u0 p0 c0 {3,S}
        ''',
          '''
        1 C u0 p0 c0 {2,S} {4,S} {5,S} {6,S}
        2 C u0 p0 c0 {1,S} {3,D} {7,S}
        3 C u0 p0 c0 {2,D} {8,S} {9,S}
        4 H u0 p0 c0 {1,S}
        5 H u0 p0 c0 {1,S}
        6 H u0 p0 c0 {1,S}
        7 H u0 p0 c0 {2,S}
        8 H u0 p0 c0 {3,S}
        9 H u0 p0 c0 {3,S}
        '''
          ]
        family = getDB('kinetics').families['H_Abstraction']
        r1 = Species(molecule=[Molecule().fromAdjacencyList(adjlist[0])])
        r2 = Species(molecule=[Molecule().fromAdjacencyList(adjlist[1])])
        p1 = Species(molecule=[Molecule().fromAdjacencyList(adjlist[2])])
        p2 = Species(molecule=[Molecule().fromAdjacencyList(adjlist[3])])
        r1.generate_resonance_structures(keep_isomorphic=True)
        p1.generate_resonance_structures(keep_isomorphic=True)

        rxn = TemplateReaction(reactants=[r1, r2], products=[p1, p2])
        
        rxn.degeneracy = family.calculateDegeneracy(rxn)
        self.assertEqual(rxn.degeneracy, 6)
        
        family.addReverseAttribute(rxn)
        
        self.assertEqual(rxn.reverse.degeneracy, 6)
예제 #29
0
    def test_add_atom_labels_for_reaction_r_recombination(self):
        """Test that we can add atom labels to an existing R_Recombination reaction"""
        reactants = [
            Species().from_smiles('C[CH2]'),
            Species().from_smiles('[CH3]')
        ]
        products = [Species().from_smiles('CCC')]

        reaction = TemplateReaction(reactants=reactants, products=products)

        self.database.kinetics.families[
            'R_Recombination'].add_atom_labels_for_reaction(reaction)

        expected_reactants = [
            Molecule().from_adjacency_list("""
multiplicity 2
1   C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2 * C u1 p0 c0 {1,S} {6,S} {7,S}
3   H u0 p0 c0 {1,S}
4   H u0 p0 c0 {1,S}
5   H u0 p0 c0 {1,S}
6   H u0 p0 c0 {2,S}
7   H u0 p0 c0 {2,S}
"""),
            Molecule().from_adjacency_list("""
multiplicity 2
1 * C u1 p0 c0 {2,S} {3,S} {4,S}
2   H u0 p0 c0 {1,S}
3   H u0 p0 c0 {1,S}
4   H u0 p0 c0 {1,S}
""")
        ]

        expected_products = [
            Molecule().from_adjacency_list("""
1  * C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2  * C u0 p0 c0 {1,S} {6,S} {7,S} {8,S}
3    C u0 p0 c0 {1,S} {9,S} {10,S} {11,S}
4    H u0 p0 c0 {1,S}
5    H u0 p0 c0 {1,S}
6    H u0 p0 c0 {2,S}
7    H u0 p0 c0 {2,S}
8    H u0 p0 c0 {2,S}
9    H u0 p0 c0 {3,S}
10   H u0 p0 c0 {3,S}
11   H u0 p0 c0 {3,S}
""")
        ]

        for i, reactant in enumerate(reaction.reactants):
            mapping = {}
            for label, atom in expected_reactants[i].get_all_labeled_atoms(
            ).items():
                mapping[atom] = reactant.molecule[0].get_labeled_atoms(
                    label)[0]

            self.assertTrue(expected_reactants[i].is_isomorphic(
                reactant.molecule[0], mapping))

        for i, product in enumerate(reaction.products):
            # There are two identical labels in the product, so we need to check both mappings
            # Only one of the mappings will result in isomorphic structures though
            atoms_a = expected_products[i].get_labeled_atoms('*')
            atoms_b = product.molecule[0].get_labeled_atoms('*')
            mapping1 = {atoms_a[0]: atoms_b[0], atoms_a[1]: atoms_b[1]}
            mapping2 = {atoms_a[0]: atoms_b[1], atoms_a[1]: atoms_b[0]}

            results = [
                expected_products[i].is_isomorphic(product.molecule[0],
                                                   mapping1),
                expected_products[i].is_isomorphic(product.molecule[0],
                                                   mapping2)
            ]

            self.assertTrue(any(results))
            self.assertFalse(all(results))
예제 #30
0
    def setUp(self):
        self.A = 1e14
        self.sar = sar
        self.ipropyl_mol = Molecule(SMILES='C[CH]C')
        self.ipropyl_ip = 7.37
        self.methyl_ip = 9.84
        # breakdown forming benzyl radical (though not as primary resonance structure)
        self.resonance_reaction = 0
        #ethyoxy breakdown
        self.reaction = TemplateReaction(reactants=[
            Species(
                label="",
                thermo=ThermoData(
                    Tdata=([300, 400, 500, 600, 800, 1000, 1500], 'K'),
                    Cpdata=([
                        35.4385, 39.2459, 43.7646, 48.1997, 55.9401, 61.965,
                        61.965
                    ], 'J/(mol*K)'),
                    H298=(-108.575, 'kJ/mol'),
                    S298=(218.834, 'J/(mol*K)'),
                    Cp0=(33.2579, 'J/(mol*K)'),
                    CpInf=(83.1447, 'J/(mol*K)'),
                    comment=
                    """Thermo group additivity estimation: group(Cds-OdHH)"""),
                molecule=[
                    Molecule().fromAdjacencyList(
                        """1 *1 C u0 p0 c0 {2,S} {3,S} {4,D}
2    H u0 p0 c0 {1,S}
3    H u0 p0 c0 {1,S}
4 *2 O u0 p2 c0 {1,D}
""")
                ]),
            Species(
                label="",
                thermo=ThermoData(
                    Tdata=([300, 400, 500, 600, 800, 1000, 1500], 'K'),
                    Cpdata=([
                        9.331, 9.988,
                        10.611, 11.274, 12.457, 13.427, 15.105
                    ], 'cal/(mol*K)'),
                    H298=(34.893, 'kcal/mol'),
                    S298=(46.3704, 'cal/(mol*K)'),
                    Cp0=(33.2579, 'J/(mol*K)'),
                    CpInf=(108.088, 'J/(mol*K)'),
                    comment=
                    """Thermo library: primaryThermoLibrary + radical(CH3)"""),
                molecule=[
                    Molecule().fromAdjacencyList("""multiplicity 2
1 *3 C u1 p0 c0 {2,S} {3,S} {4,S}
2    H u0 p0 c0 {1,S}
3    H u0 p0 c0 {1,S}
4    H u0 p0 c0 {1,S}
""")
                ])
        ],
                                         products=[
                                             Species(label="",
                                                     thermo=ThermoData(
                                                         Tdata=([
                                                             300, 400, 500,
                                                             600, 800, 1000,
                                                             1500
                                                         ], 'K'),
                                                         Cpdata=([
                                                             61.879, 72.3026,
                                                             83.2296, 93.9954,
                                                             112.876, 127.558,
                                                             150.145
                                                         ], 'J/(mol*K)'),
                                                         H298=(-17.2758,
                                                               'kJ/mol'),
                                                         S298=(284.871,
                                                               'J/(mol*K)'),
                                                         Cp0=(33.2579,
                                                              'J/(mol*K)'),
                                                         CpInf=(178.761,
                                                                'J/(mol*K)'),
                                                         comment=
                                                         """Thermo group additivity estimation: group(Cs-CsOsHH) + group(Cs-CsHHH) + group(Os-CsH) + radical(CCOJ)"""
                                                     ),
                                                     molecule=[
                                                         Molecule().
                                                         fromAdjacencyList(
                                                             """multiplicity 2
1 *3 C u0 p0 c0 {2,S} {4,S} {5,S} {6,S}
2 *1 C u0 p0 c0 {1,S} {3,S} {7,S} {8,S}
3 *2 O u1 p2 c0 {2,S}
4    H u0 p0 c0 {1,S}
5    H u0 p0 c0 {1,S}
6    H u0 p0 c0 {1,S}
7    H u0 p0 c0 {2,S}
8    H u0 p0 c0 {2,S}
""")
                                                     ])
                                         ],
                                         pairs=[[
                                             Species(label="",
                                                     thermo=ThermoData(
                                                         Tdata=([
                                                             300, 400, 500,
                                                             600, 800, 1000,
                                                             1500
                                                         ], 'K'),
                                                         Cpdata=([
                                                             35.4385, 39.2459,
                                                             43.7646, 48.1997,
                                                             55.9401, 61.965,
                                                             61.965
                                                         ], 'J/(mol*K)'),
                                                         H298=(-108.575,
                                                               'kJ/mol'),
                                                         S298=(218.834,
                                                               'J/(mol*K)'),
                                                         Cp0=(33.2579,
                                                              'J/(mol*K)'),
                                                         CpInf=(83.1447,
                                                                'J/(mol*K)'),
                                                         comment=
                                                         """Thermo group additivity estimation: group(Cds-OdHH)"""
                                                     ),
                                                     molecule=[
                                                         Molecule().
                                                         fromAdjacencyList(
                                                             """1 *1 C u0 p0 c0 {2,S} {3,S} {4,D}
2    H u0 p0 c0 {1,S}
3    H u0 p0 c0 {1,S}
4 *2 O u0 p2 c0 {1,D}
""")
                                                     ]),
                                             Species(label="",
                                                     thermo=ThermoData(
                                                         Tdata=([
                                                             300, 400, 500,
                                                             600, 800, 1000,
                                                             1500
                                                         ], 'K'),
                                                         Cpdata=([
                                                             61.879, 72.3026,
                                                             83.2296, 93.9954,
                                                             112.876, 127.558,
                                                             150.145
                                                         ], 'J/(mol*K)'),
                                                         H298=(-17.2758,
                                                               'kJ/mol'),
                                                         S298=(284.871,
                                                               'J/(mol*K)'),
                                                         Cp0=(33.2579,
                                                              'J/(mol*K)'),
                                                         CpInf=(178.761,
                                                                'J/(mol*K)'),
                                                         comment=
                                                         """Thermo group additivity estimation: group(Cs-CsOsHH) + group(Cs-CsHHH) + group(Os-CsH) + radical(CCOJ)"""
                                                     ),
                                                     molecule=[
                                                         Molecule().
                                                         fromAdjacencyList(
                                                             """multiplicity 2
1 *3 C u0 p0 c0 {2,S} {4,S} {5,S} {6,S}
2 *1 C u0 p0 c0 {1,S} {3,S} {7,S} {8,S}
3 *2 O u1 p2 c0 {2,S}
4    H u0 p0 c0 {1,S}
5    H u0 p0 c0 {1,S}
6    H u0 p0 c0 {1,S}
7    H u0 p0 c0 {2,S}
8    H u0 p0 c0 {2,S}
""")
                                                     ])
                                         ],
                                                [
                                                    Species(
                                                        label="",
                                                        thermo=ThermoData(
                                                            Tdata=([
                                                                300, 400, 500,
                                                                600, 800, 1000,
                                                                1500
                                                            ], 'K'),
                                                            Cpdata=([
                                                                9.331, 9.988,
                                                                10.611, 11.274,
                                                                12.457, 13.427,
                                                                15.105
                                                            ], 'cal/(mol*K)'),
                                                            H298=(34.893,
                                                                  'kcal/mol'),
                                                            S298=(
                                                                46.3704,
                                                                'cal/(mol*K)'),
                                                            Cp0=(33.2579,
                                                                 'J/(mol*K)'),
                                                            CpInf=(
                                                                108.088,
                                                                'J/(mol*K)'),
                                                            comment=
                                                            """Thermo library: primaryThermoLibrary + radical(CH3)"""
                                                        ),
                                                        molecule=[
                                                            Molecule().
                                                            fromAdjacencyList(
                                                                """multiplicity 2
1 *3 C u1 p0 c0 {2,S} {3,S} {4,S}
2    H u0 p0 c0 {1,S}
3    H u0 p0 c0 {1,S}
4    H u0 p0 c0 {1,S}
""")
                                                        ]),
                                                    Species(
                                                        label="",
                                                        thermo=ThermoData(
                                                            Tdata=([
                                                                300, 400, 500,
                                                                600, 800, 1000,
                                                                1500
                                                            ], 'K'),
                                                            Cpdata=([
                                                                61.879,
                                                                72.3026,
                                                                83.2296,
                                                                93.9954,
                                                                112.876,
                                                                127.558,
                                                                150.145
                                                            ], 'J/(mol*K)'),
                                                            H298=(-17.2758,
                                                                  'kJ/mol'),
                                                            S298=(284.871,
                                                                  'J/(mol*K)'),
                                                            Cp0=(33.2579,
                                                                 'J/(mol*K)'),
                                                            CpInf=(
                                                                178.761,
                                                                'J/(mol*K)'),
                                                            comment=
                                                            """Thermo group additivity estimation: group(Cs-CsOsHH) + group(Cs-CsHHH) + group(Os-CsH) + radical(CCOJ)"""
                                                        ),
                                                        molecule=[
                                                            Molecule().
                                                            fromAdjacencyList(
                                                                """multiplicity 2
1 *3 C u0 p0 c0 {2,S} {4,S} {5,S} {6,S}
2 *1 C u0 p0 c0 {1,S} {3,S} {7,S} {8,S}
3 *2 O u1 p2 c0 {2,S}
4    H u0 p0 c0 {1,S}
5    H u0 p0 c0 {1,S}
6    H u0 p0 c0 {1,S}
7    H u0 p0 c0 {2,S}
8    H u0 p0 c0 {2,S}
""")
                                                        ])
                                                ]],
                                         family='R_Addition_MultipleBond',
                                         template=['Cd_R', 'CsJ'])
        self.degenerate_reaction = TemplateReaction(reactants=[
            Species(
                label="",
                thermo=ThermoData(
                    Tdata=([300, 400, 500, 600, 800, 1000, 1500], 'K'),
                    Cpdata=([51.55, 63.29, 74.38, 84.19, 100.1, 112.02,
                             130.2], 'J/(mol*K)'),
                    H298=(-166.3, 'kJ/mol'),
                    S298=(263.446, 'J/(mol*K)'),
                    Cp0=(33.2579, 'J/(mol*K)'),
                    CpInf=(153.818, 'J/(mol*K)'),
                    comment=
                    """Thermo group additivity estimation: group(Cs-(Cds-Od)HHH) + group(Cds-OdCsH)"""
                ),
                molecule=[
                    Molecule().fromAdjacencyList(
                        """1    C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2 *1 C u0 p0 c0 {1,S} {6,D} {7,S}
3    H u0 p0 c0 {1,S}
4    H u0 p0 c0 {1,S}
5    H u0 p0 c0 {1,S}
6 *2 O u0 p2 c0 {2,D}
7    H u0 p0 c0 {2,S}
""")
                ]),
            Species(
                label="",
                thermo=ThermoData(
                    Tdata=([300, 400, 500, 600, 800, 1000, 1500], 'K'),
                    Cpdata=([
                        9.331, 9.988,
                        10.611, 11.274, 12.457, 13.427, 15.105
                    ], 'cal/(mol*K)'),
                    H298=(34.893, 'kcal/mol'),
                    S298=(46.3704, 'cal/(mol*K)'),
                    Cp0=(33.2579, 'J/(mol*K)'),
                    CpInf=(108.088, 'J/(mol*K)'),
                    comment=
                    """Thermo library: primaryThermoLibrary + radical(CH3)"""),
                molecule=[
                    Molecule().fromAdjacencyList("""multiplicity 2
1 *3 C u1 p0 c0 {2,S} {3,S} {4,S}
2    H u0 p0 c0 {1,S}
3    H u0 p0 c0 {1,S}
4    H u0 p0 c0 {1,S}
""")
                ])
        ],
                                                    products=[
                                                        Species(
                                                            label="",
                                                            thermo=ThermoData(
                                                                Tdata=([
                                                                    300, 400,
                                                                    500, 600,
                                                                    800, 1000,
                                                                    1500
                                                                ], 'K'),
                                                                Cpdata=([
                                                                    87.5579,
                                                                    108.135,
                                                                    126.429,
                                                                    141.841,
                                                                    165.681,
                                                                    183.615,
                                                                    211.679
                                                                ], 'J/(mol*K)'
                                                                        ),
                                                                H298=(
                                                                    -46.0526,
                                                                    'kJ/mol'),
                                                                S298=(
                                                                    302.672,
                                                                    'J/(mol*K)'
                                                                ),
                                                                Cp0=(
                                                                    33.2579,
                                                                    'J/(mol*K)'
                                                                ),
                                                                CpInf=(
                                                                    249.434,
                                                                    'J/(mol*K)'
                                                                ),
                                                                comment=
                                                                """Thermo group additivity estimation: group(Cs-CsCsOsH) + group(Cs-CsHHH) + group(Cs-CsHHH) + group(Os-CsH) + radical(CC(C)OJ)"""
                                                            ),
                                                            molecule=[
                                                                Molecule().
                                                                fromAdjacencyList(
                                                                    """multiplicity 2
1  *1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2     C u0 p0 c0 {1,S} {6,S} {7,S} {8,S}
3  *3 C u0 p0 c0 {1,S} {9,S} {10,S} {11,S}
4  *2 O u1 p2 c0 {1,S}
5     H u0 p0 c0 {1,S}
6     H u0 p0 c0 {2,S}
7     H u0 p0 c0 {2,S}
8     H u0 p0 c0 {2,S}
9     H u0 p0 c0 {3,S}
10    H u0 p0 c0 {3,S}
11    H u0 p0 c0 {3,S}
""")
                                                            ])
                                                    ],
                                                    degeneracy=2.0,
                                                    pairs=[[
                                                        Species(
                                                            label="",
                                                            thermo=ThermoData(
                                                                Tdata=([
                                                                    300, 400,
                                                                    500, 600,
                                                                    800, 1000,
                                                                    1500
                                                                ], 'K'),
                                                                Cpdata=([
                                                                    51.55,
                                                                    63.29,
                                                                    74.38,
                                                                    84.19,
                                                                    100.1,
                                                                    112.02,
                                                                    130.2
                                                                ], 'J/(mol*K)'
                                                                        ),
                                                                H298=(
                                                                    -166.3,
                                                                    'kJ/mol'),
                                                                S298=(
                                                                    263.446,
                                                                    'J/(mol*K)'
                                                                ),
                                                                Cp0=(
                                                                    33.2579,
                                                                    'J/(mol*K)'
                                                                ),
                                                                CpInf=(
                                                                    153.818,
                                                                    'J/(mol*K)'
                                                                ),
                                                                comment=
                                                                """Thermo group additivity estimation: group(Cs-(Cds-Od)HHH) + group(Cds-OdCsH)"""
                                                            ),
                                                            molecule=[
                                                                Molecule().
                                                                fromAdjacencyList(
                                                                    """1    C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2 *1 C u0 p0 c0 {1,S} {6,D} {7,S}
3    H u0 p0 c0 {1,S}
4    H u0 p0 c0 {1,S}
5    H u0 p0 c0 {1,S}
6 *2 O u0 p2 c0 {2,D}
7    H u0 p0 c0 {2,S}
""")
                                                            ]),
                                                        Species(
                                                            label="",
                                                            thermo=ThermoData(
                                                                Tdata=([
                                                                    300, 400,
                                                                    500, 600,
                                                                    800, 1000,
                                                                    1500
                                                                ], 'K'),
                                                                Cpdata=([
                                                                    87.5579,
                                                                    108.135,
                                                                    126.429,
                                                                    141.841,
                                                                    165.681,
                                                                    183.615,
                                                                    211.679
                                                                ], 'J/(mol*K)'
                                                                        ),
                                                                H298=(
                                                                    -46.0526,
                                                                    'kJ/mol'),
                                                                S298=(
                                                                    302.672,
                                                                    'J/(mol*K)'
                                                                ),
                                                                Cp0=(
                                                                    33.2579,
                                                                    'J/(mol*K)'
                                                                ),
                                                                CpInf=(
                                                                    249.434,
                                                                    'J/(mol*K)'
                                                                ),
                                                                comment=
                                                                """Thermo group additivity estimation: group(Cs-CsCsOsH) + group(Cs-CsHHH) + group(Cs-CsHHH) + group(Os-CsH) + radical(CC(C)OJ)"""
                                                            ),
                                                            molecule=[
                                                                Molecule().
                                                                fromAdjacencyList(
                                                                    """multiplicity 2
1  *1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2     C u0 p0 c0 {1,S} {6,S} {7,S} {8,S}
3  *3 C u0 p0 c0 {1,S} {9,S} {10,S} {11,S}
4  *2 O u1 p2 c0 {1,S}
5     H u0 p0 c0 {1,S}
6     H u0 p0 c0 {2,S}
7     H u0 p0 c0 {2,S}
8     H u0 p0 c0 {2,S}
9     H u0 p0 c0 {3,S}
10    H u0 p0 c0 {3,S}
11    H u0 p0 c0 {3,S}
""")
                                                            ])
                                                    ],
                                                           [
                                                               Species(
                                                                   label="",
                                                                   thermo=
                                                                   ThermoData(
                                                                       Tdata=([
                                                                           300,
                                                                           400,
                                                                           500,
                                                                           600,
                                                                           800,
                                                                           1000,
                                                                           1500
                                                                       ], 'K'),
                                                                       Cpdata=([
                                                                           9.331,
                                                                           9.988,
                                                                           10.611,
                                                                           11.274,
                                                                           12.457,
                                                                           13.427,
                                                                           15.105
                                                                       ], 'cal/(mol*K)'
                                                                               ),
                                                                       H298=
                                                                       (34.893,
                                                                        'kcal/mol'
                                                                        ),
                                                                       S298=
                                                                       (46.3704,
                                                                        'cal/(mol*K)'
                                                                        ),
                                                                       Cp0=
                                                                       (33.2579,
                                                                        'J/(mol*K)'
                                                                        ),
                                                                       CpInf=
                                                                       (108.088,
                                                                        'J/(mol*K)'
                                                                        ),
                                                                       comment=
                                                                       """Thermo library: primaryThermoLibrary + radical(CH3)"""
                                                                   ),
                                                                   molecule=[
                                                                       Molecule(
                                                                       ).
                                                                       fromAdjacencyList(
                                                                           """multiplicity 2
1 *3 C u1 p0 c0 {2,S} {3,S} {4,S}
2    H u0 p0 c0 {1,S}
3    H u0 p0 c0 {1,S}
4    H u0 p0 c0 {1,S}
""")
                                                                   ]),
                                                               Species(
                                                                   label="",
                                                                   thermo=
                                                                   ThermoData(
                                                                       Tdata=([
                                                                           300,
                                                                           400,
                                                                           500,
                                                                           600,
                                                                           800,
                                                                           1000,
                                                                           1500
                                                                       ], 'K'),
                                                                       Cpdata=([
                                                                           87.5579,
                                                                           108.135,
                                                                           126.429,
                                                                           141.841,
                                                                           165.681,
                                                                           183.615,
                                                                           211.679
                                                                       ], 'J/(mol*K)'
                                                                               ),
                                                                       H298=
                                                                       (-46.0526,
                                                                        'kJ/mol'
                                                                        ),
                                                                       S298=
                                                                       (302.672,
                                                                        'J/(mol*K)'
                                                                        ),
                                                                       Cp0=
                                                                       (33.2579,
                                                                        'J/(mol*K)'
                                                                        ),
                                                                       CpInf=
                                                                       (249.434,
                                                                        'J/(mol*K)'
                                                                        ),
                                                                       comment=
                                                                       """Thermo group additivity estimation: group(Cs-CsCsOsH) + group(Cs-CsHHH) + group(Cs-CsHHH) + group(Os-CsH) + radical(CC(C)OJ)"""
                                                                   ),
                                                                   molecule=[
                                                                       Molecule(
                                                                       ).
                                                                       fromAdjacencyList(
                                                                           """multiplicity 2
1  *1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2     C u0 p0 c0 {1,S} {6,S} {7,S} {8,S}
3  *3 C u0 p0 c0 {1,S} {9,S} {10,S} {11,S}
4  *2 O u1 p2 c0 {1,S}
5     H u0 p0 c0 {1,S}
6     H u0 p0 c0 {2,S}
7     H u0 p0 c0 {2,S}
8     H u0 p0 c0 {2,S}
9     H u0 p0 c0 {3,S}
10    H u0 p0 c0 {3,S}
11    H u0 p0 c0 {3,S}
""")
                                                                   ])
                                                           ]],
                                                    family=
                                                    'R_Addition_MultipleBond',
                                                    template=['Cd_R', 'CsJ'])
    def testGenerateIsotopeReactions(self):
        """
        shows that all isotope reactions are created with generateIsotopeReactions
        """
        methyl = Species().fromSMILES('[CH3]')
        methyli = Species().fromAdjacencyList(
            """
    multiplicity 2
    1 C u1 p0 c0 i13 {2,S} {3,S} {4,S}
    2 H u0 p0 c0 {1,S}
    3 H u0 p0 c0 {1,S}
    4 H u0 p0 c0 {1,S}
            """)
        methane = Species().fromAdjacencyList(
            """
1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
4 H u0 p0 c0 {1,S}
5 H u0 p0 c0 {1,S}
            """)
        methanei = Species().fromAdjacencyList(
            """
1 C u0 p0 c0 i13 {2,S} {3,S} {4,S} {5,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
4 H u0 p0 c0 {1,S}
5 H u0 p0 c0 {1,S}
            """)
        craigie = Species().fromAdjacencyList(
            """
multiplicity 3
1 C u2 p0 c0 {2,S} {3,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
            """)
        craigiei = Species().fromAdjacencyList(
            """
multiplicity 3
1 C u2 p0 c0 i13 {2,S} {3,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
            """)
        reaction = TemplateReaction(reactants = [methyl,methyl],
                                    products = [methane,craigie],
                                    family = 'H_Abstraction',
                                    template = ['Xrad_H', 'Y_rad'],
                                    degeneracy = 3)
        reaction.kinetics = Arrhenius(A=(1e5,'cm^3/(mol*s)'),Ea=(0,'J/mol'))
        isotope_list = [[methyl,methyli],
                        [methane,methanei],
                        [craigie,craigiei]]

        new_reactions = generate_isotope_reactions([reaction], isotope_list)

        self.assertEqual(len(new_reactions), 4)

        degeneracies_found = set()
        for rxn in new_reactions:
            self.assertEqual(rxn.template, reaction.template)
            degeneracies_found.add(rxn.degeneracy)
            self.assertIsNotNone(rxn.kinetics,'kinetics not obtained for reaction {}.'.format(rxn))
            self.assertAlmostEqual(reaction.kinetics.getRateCoefficient(298),
                                   rxn.kinetics.getRateCoefficient(298) *\
                                    reaction.degeneracy / rxn.degeneracy)

        self.assertEqual(degeneracies_found, set([3]))
예제 #32
0
    def test_generate_isotope_reactions(self):
        """
        shows that all isotope reactions are created with generateIsotopeReactions
        """
        methyl = Species().from_smiles('[CH3]')
        methyli = Species().from_adjacency_list("""
multiplicity 2
1 C u1 p0 c0 i13 {2,S} {3,S} {4,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
4 H u0 p0 c0 {1,S}
""")
        methane = Species().from_adjacency_list("""
1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
4 H u0 p0 c0 {1,S}
5 H u0 p0 c0 {1,S}
""")
        methanei = Species().from_adjacency_list("""
1 C u0 p0 c0 i13 {2,S} {3,S} {4,S} {5,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
4 H u0 p0 c0 {1,S}
5 H u0 p0 c0 {1,S}
""")
        craigie = Species().from_adjacency_list("""
multiplicity 3
1 C u2 p0 c0 {2,S} {3,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
""")
        craigiei = Species().from_adjacency_list("""
multiplicity 3
1 C u2 p0 c0 i13 {2,S} {3,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
""")
        reaction = TemplateReaction(reactants=[methyl, methyl],
                                    products=[methane, craigie],
                                    family='H_Abstraction',
                                    template=['Xrad_H', 'Y_rad'],
                                    degeneracy=3)
        reaction.kinetics = Arrhenius(A=(1e5, 'cm^3/(mol*s)'), Ea=(0, 'J/mol'))
        isotope_list = [[methyl, methyli],
                        [methane, methanei],
                        [craigie, craigiei]]

        new_reactions = generate_isotope_reactions([reaction], isotope_list)

        self.assertEqual(len(new_reactions), 4)

        degeneracies_found = set()
        for rxn in new_reactions:
            self.assertEqual(rxn.template, reaction.template)
            degeneracies_found.add(rxn.degeneracy)
            self.assertIsNotNone(rxn.kinetics, 'kinetics not obtained for reaction {}.'.format(rxn))
            self.assertAlmostEqual(reaction.kinetics.get_rate_coefficient(298),
                                   rxn.kinetics.get_rate_coefficient(298) * reaction.degeneracy / rxn.degeneracy)

        self.assertEqual(degeneracies_found, set([3]))
예제 #33
0
    def test_ensure_reaction_direction(self):
        """
        Tests that the direction of the reaction is constant for every isotopomer
        """

        # get reactions

        methyl = Species().from_smiles('[CH3]')
        methyli = Species().from_adjacency_list("""
multiplicity 2
1 C u1 p0 c0 i13 {2,S} {3,S} {4,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
4 H u0 p0 c0 {1,S}
""")
        methane = Species().from_smiles('C')
        methanei = Species().from_adjacency_list("""
1 C u0 p0 c0 i13 {2,S} {3,S} {4,S} {5,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
4 H u0 p0 c0 {1,S}
5 H u0 p0 c0 {1,S}
""")

        dipropyl = Species().from_smiles('[CH2]C[CH2]')
        dipropyli = Species().from_adjacency_list("""
multiplicity 3
1 C u1 p0 c0 {2,S} {3,S} {4,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
4 C u0 p0 c0 {1,S} {5,S} {8,S} {9,S}
5 C u1 p0 c0 i13 {4,S} {6,S} {7,S}
6 H u0 p0 c0 {5,S}
7 H u0 p0 c0 {5,S}
8 H u0 p0 c0 {4,S}
9 H u0 p0 c0 {4,S}
""")

        propyl = Species().from_smiles('CC[CH2]')
        propyli = Species().from_adjacency_list("""
multiplicity 2
1  C u1 p0 c0 i13 {2,S} {3,S} {4,S}
2  H u0 p0 c0 {1,S}
3  H u0 p0 c0 {1,S}
4  C u0 p0 c0 {1,S} {5,S} {6,S} {7,S}
5  C u0 p0 c0 {4,S} {8,S} {9,S} {10,S}
6  H u0 p0 c0 {4,S}
7  H u0 p0 c0 {4,S}
8  H u0 p0 c0 {5,S}
9  H u0 p0 c0 {5,S}
10 H u0 p0 c0 {5,S}
""")
        propyl.label = 'propyl'
        propyli.label = 'propyli'
        dipropyl.label = 'dipropyl'
        dipropyli.label = 'dipropyli'
        methyl.label = 'methyl'
        methyli.label = 'methyli'
        methane.label = 'methane'
        methanei.label = 'methanei'
        # make reactions
        rxn1 = TemplateReaction(reactants=[dipropyl, methane],
                                products=[methyl, propyl],
                                kinetics=Arrhenius(A=(1., 'cm^3/(mol*s)'), Ea=(2., 'kJ/mol'), n=0.),
                                family='H_Abstraction',
                                template=['a', 'c'],
                                degeneracy=8,
                                pairs=[[methane, methyl], [dipropyl, propyl]])
        rxn2 = TemplateReaction(reactants=[methyli, propyl],
                                products=[methanei, dipropyl],
                                kinetics=Arrhenius(A=(1e-20, 'cm^3/(mol*s)'), Ea=(2., 'kJ/mol'), n=0.),
                                family='H_Abstraction',
                                template=['b', 'd'],
                                degeneracy=3,
                                pairs=[[methyli, methanei], [propyl, dipropyl]])
        rxn3 = TemplateReaction(reactants=[methane, dipropyli],
                                products=[methyl, propyli],
                                kinetics=Arrhenius(A=(0.5, 'cm^3/(mol*s)'), Ea=(2., 'kJ/mol'), n=0.),
                                family='H_Abstraction',
                                template=['a', 'c'],
                                degeneracy=4,
                                pairs=[[methane, methyl], [dipropyli, propyli]])
        rxn4 = TemplateReaction(reactants=[methyli, propyli],
                                products=[methanei, dipropyli],
                                kinetics=Arrhenius(A=(1e-20, 'cm^3/(mol*s)'), Ea=(2., 'kJ/mol'), n=0.),
                                family='H_Abstraction',
                                template=['d', 'b'],
                                degeneracy=3,
                                pairs=[[methyli, methanei], [propyli, dipropyli]])

        rxns = [rxn1, rxn2, rxn3, rxn4]

        # call method
        ensure_reaction_direction(rxns)

        for rxn in rxns:
            # ensure there is a methane in reactants for each reaction
            self.assertTrue(any([compare_isotopomers(methane, reactant) for reactant in rxn.reactants]),
                            msg='ensureReactionDirection didnt flip the proper reactants and products')

            # ensure kinetics is correct
            if any([dipropyli.is_isomorphic(reactant) for reactant in rxn.reactants]):
                self.assertAlmostEqual(rxn.kinetics.A.value, 0.5,
                                       msg='The A value returned, {0}, is incorrect. '
                                           'Check the reactions degeneracy and how A.value is obtained. '
                                           'The reaction is:{1}'.format(rxn.kinetics.A.value, rxn))
            else:
                self.assertAlmostEqual(rxn.kinetics.A.value, 1.,
                                       msg='The A value returned, {0}, is incorrect. '
                                           'Check the reactions degeneracy and how A.value is obtained. '
                                           'The reaction is:{1}'.format(rxn.kinetics.A.value, rxn))
예제 #34
0
class SarRateEstimationTest(unittest.TestCase):
    def setUp(self):
        self.A = 1e14
        self.sar = sar
        self.ipropyl_mol = Molecule(SMILES='C[CH]C')
        self.ipropyl_ip = 7.37
        self.methyl_ip = 9.84
        # breakdown forming benzyl radical (though not as primary resonance structure)
        self.resonance_reaction = 0
        #ethyoxy breakdown
        self.reaction = TemplateReaction(reactants=[
            Species(
                label="",
                thermo=ThermoData(
                    Tdata=([300, 400, 500, 600, 800, 1000, 1500], 'K'),
                    Cpdata=([
                        35.4385, 39.2459, 43.7646, 48.1997, 55.9401, 61.965,
                        61.965
                    ], 'J/(mol*K)'),
                    H298=(-108.575, 'kJ/mol'),
                    S298=(218.834, 'J/(mol*K)'),
                    Cp0=(33.2579, 'J/(mol*K)'),
                    CpInf=(83.1447, 'J/(mol*K)'),
                    comment=
                    """Thermo group additivity estimation: group(Cds-OdHH)"""),
                molecule=[
                    Molecule().fromAdjacencyList(
                        """1 *1 C u0 p0 c0 {2,S} {3,S} {4,D}
2    H u0 p0 c0 {1,S}
3    H u0 p0 c0 {1,S}
4 *2 O u0 p2 c0 {1,D}
""")
                ]),
            Species(
                label="",
                thermo=ThermoData(
                    Tdata=([300, 400, 500, 600, 800, 1000, 1500], 'K'),
                    Cpdata=([
                        9.331, 9.988,
                        10.611, 11.274, 12.457, 13.427, 15.105
                    ], 'cal/(mol*K)'),
                    H298=(34.893, 'kcal/mol'),
                    S298=(46.3704, 'cal/(mol*K)'),
                    Cp0=(33.2579, 'J/(mol*K)'),
                    CpInf=(108.088, 'J/(mol*K)'),
                    comment=
                    """Thermo library: primaryThermoLibrary + radical(CH3)"""),
                molecule=[
                    Molecule().fromAdjacencyList("""multiplicity 2
1 *3 C u1 p0 c0 {2,S} {3,S} {4,S}
2    H u0 p0 c0 {1,S}
3    H u0 p0 c0 {1,S}
4    H u0 p0 c0 {1,S}
""")
                ])
        ],
                                         products=[
                                             Species(label="",
                                                     thermo=ThermoData(
                                                         Tdata=([
                                                             300, 400, 500,
                                                             600, 800, 1000,
                                                             1500
                                                         ], 'K'),
                                                         Cpdata=([
                                                             61.879, 72.3026,
                                                             83.2296, 93.9954,
                                                             112.876, 127.558,
                                                             150.145
                                                         ], 'J/(mol*K)'),
                                                         H298=(-17.2758,
                                                               'kJ/mol'),
                                                         S298=(284.871,
                                                               'J/(mol*K)'),
                                                         Cp0=(33.2579,
                                                              'J/(mol*K)'),
                                                         CpInf=(178.761,
                                                                'J/(mol*K)'),
                                                         comment=
                                                         """Thermo group additivity estimation: group(Cs-CsOsHH) + group(Cs-CsHHH) + group(Os-CsH) + radical(CCOJ)"""
                                                     ),
                                                     molecule=[
                                                         Molecule().
                                                         fromAdjacencyList(
                                                             """multiplicity 2
1 *3 C u0 p0 c0 {2,S} {4,S} {5,S} {6,S}
2 *1 C u0 p0 c0 {1,S} {3,S} {7,S} {8,S}
3 *2 O u1 p2 c0 {2,S}
4    H u0 p0 c0 {1,S}
5    H u0 p0 c0 {1,S}
6    H u0 p0 c0 {1,S}
7    H u0 p0 c0 {2,S}
8    H u0 p0 c0 {2,S}
""")
                                                     ])
                                         ],
                                         pairs=[[
                                             Species(label="",
                                                     thermo=ThermoData(
                                                         Tdata=([
                                                             300, 400, 500,
                                                             600, 800, 1000,
                                                             1500
                                                         ], 'K'),
                                                         Cpdata=([
                                                             35.4385, 39.2459,
                                                             43.7646, 48.1997,
                                                             55.9401, 61.965,
                                                             61.965
                                                         ], 'J/(mol*K)'),
                                                         H298=(-108.575,
                                                               'kJ/mol'),
                                                         S298=(218.834,
                                                               'J/(mol*K)'),
                                                         Cp0=(33.2579,
                                                              'J/(mol*K)'),
                                                         CpInf=(83.1447,
                                                                'J/(mol*K)'),
                                                         comment=
                                                         """Thermo group additivity estimation: group(Cds-OdHH)"""
                                                     ),
                                                     molecule=[
                                                         Molecule().
                                                         fromAdjacencyList(
                                                             """1 *1 C u0 p0 c0 {2,S} {3,S} {4,D}
2    H u0 p0 c0 {1,S}
3    H u0 p0 c0 {1,S}
4 *2 O u0 p2 c0 {1,D}
""")
                                                     ]),
                                             Species(label="",
                                                     thermo=ThermoData(
                                                         Tdata=([
                                                             300, 400, 500,
                                                             600, 800, 1000,
                                                             1500
                                                         ], 'K'),
                                                         Cpdata=([
                                                             61.879, 72.3026,
                                                             83.2296, 93.9954,
                                                             112.876, 127.558,
                                                             150.145
                                                         ], 'J/(mol*K)'),
                                                         H298=(-17.2758,
                                                               'kJ/mol'),
                                                         S298=(284.871,
                                                               'J/(mol*K)'),
                                                         Cp0=(33.2579,
                                                              'J/(mol*K)'),
                                                         CpInf=(178.761,
                                                                'J/(mol*K)'),
                                                         comment=
                                                         """Thermo group additivity estimation: group(Cs-CsOsHH) + group(Cs-CsHHH) + group(Os-CsH) + radical(CCOJ)"""
                                                     ),
                                                     molecule=[
                                                         Molecule().
                                                         fromAdjacencyList(
                                                             """multiplicity 2
1 *3 C u0 p0 c0 {2,S} {4,S} {5,S} {6,S}
2 *1 C u0 p0 c0 {1,S} {3,S} {7,S} {8,S}
3 *2 O u1 p2 c0 {2,S}
4    H u0 p0 c0 {1,S}
5    H u0 p0 c0 {1,S}
6    H u0 p0 c0 {1,S}
7    H u0 p0 c0 {2,S}
8    H u0 p0 c0 {2,S}
""")
                                                     ])
                                         ],
                                                [
                                                    Species(
                                                        label="",
                                                        thermo=ThermoData(
                                                            Tdata=([
                                                                300, 400, 500,
                                                                600, 800, 1000,
                                                                1500
                                                            ], 'K'),
                                                            Cpdata=([
                                                                9.331, 9.988,
                                                                10.611, 11.274,
                                                                12.457, 13.427,
                                                                15.105
                                                            ], 'cal/(mol*K)'),
                                                            H298=(34.893,
                                                                  'kcal/mol'),
                                                            S298=(
                                                                46.3704,
                                                                'cal/(mol*K)'),
                                                            Cp0=(33.2579,
                                                                 'J/(mol*K)'),
                                                            CpInf=(
                                                                108.088,
                                                                'J/(mol*K)'),
                                                            comment=
                                                            """Thermo library: primaryThermoLibrary + radical(CH3)"""
                                                        ),
                                                        molecule=[
                                                            Molecule().
                                                            fromAdjacencyList(
                                                                """multiplicity 2
1 *3 C u1 p0 c0 {2,S} {3,S} {4,S}
2    H u0 p0 c0 {1,S}
3    H u0 p0 c0 {1,S}
4    H u0 p0 c0 {1,S}
""")
                                                        ]),
                                                    Species(
                                                        label="",
                                                        thermo=ThermoData(
                                                            Tdata=([
                                                                300, 400, 500,
                                                                600, 800, 1000,
                                                                1500
                                                            ], 'K'),
                                                            Cpdata=([
                                                                61.879,
                                                                72.3026,
                                                                83.2296,
                                                                93.9954,
                                                                112.876,
                                                                127.558,
                                                                150.145
                                                            ], 'J/(mol*K)'),
                                                            H298=(-17.2758,
                                                                  'kJ/mol'),
                                                            S298=(284.871,
                                                                  'J/(mol*K)'),
                                                            Cp0=(33.2579,
                                                                 'J/(mol*K)'),
                                                            CpInf=(
                                                                178.761,
                                                                'J/(mol*K)'),
                                                            comment=
                                                            """Thermo group additivity estimation: group(Cs-CsOsHH) + group(Cs-CsHHH) + group(Os-CsH) + radical(CCOJ)"""
                                                        ),
                                                        molecule=[
                                                            Molecule().
                                                            fromAdjacencyList(
                                                                """multiplicity 2
1 *3 C u0 p0 c0 {2,S} {4,S} {5,S} {6,S}
2 *1 C u0 p0 c0 {1,S} {3,S} {7,S} {8,S}
3 *2 O u1 p2 c0 {2,S}
4    H u0 p0 c0 {1,S}
5    H u0 p0 c0 {1,S}
6    H u0 p0 c0 {1,S}
7    H u0 p0 c0 {2,S}
8    H u0 p0 c0 {2,S}
""")
                                                        ])
                                                ]],
                                         family='R_Addition_MultipleBond',
                                         template=['Cd_R', 'CsJ'])
        self.degenerate_reaction = TemplateReaction(reactants=[
            Species(
                label="",
                thermo=ThermoData(
                    Tdata=([300, 400, 500, 600, 800, 1000, 1500], 'K'),
                    Cpdata=([51.55, 63.29, 74.38, 84.19, 100.1, 112.02,
                             130.2], 'J/(mol*K)'),
                    H298=(-166.3, 'kJ/mol'),
                    S298=(263.446, 'J/(mol*K)'),
                    Cp0=(33.2579, 'J/(mol*K)'),
                    CpInf=(153.818, 'J/(mol*K)'),
                    comment=
                    """Thermo group additivity estimation: group(Cs-(Cds-Od)HHH) + group(Cds-OdCsH)"""
                ),
                molecule=[
                    Molecule().fromAdjacencyList(
                        """1    C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2 *1 C u0 p0 c0 {1,S} {6,D} {7,S}
3    H u0 p0 c0 {1,S}
4    H u0 p0 c0 {1,S}
5    H u0 p0 c0 {1,S}
6 *2 O u0 p2 c0 {2,D}
7    H u0 p0 c0 {2,S}
""")
                ]),
            Species(
                label="",
                thermo=ThermoData(
                    Tdata=([300, 400, 500, 600, 800, 1000, 1500], 'K'),
                    Cpdata=([
                        9.331, 9.988,
                        10.611, 11.274, 12.457, 13.427, 15.105
                    ], 'cal/(mol*K)'),
                    H298=(34.893, 'kcal/mol'),
                    S298=(46.3704, 'cal/(mol*K)'),
                    Cp0=(33.2579, 'J/(mol*K)'),
                    CpInf=(108.088, 'J/(mol*K)'),
                    comment=
                    """Thermo library: primaryThermoLibrary + radical(CH3)"""),
                molecule=[
                    Molecule().fromAdjacencyList("""multiplicity 2
1 *3 C u1 p0 c0 {2,S} {3,S} {4,S}
2    H u0 p0 c0 {1,S}
3    H u0 p0 c0 {1,S}
4    H u0 p0 c0 {1,S}
""")
                ])
        ],
                                                    products=[
                                                        Species(
                                                            label="",
                                                            thermo=ThermoData(
                                                                Tdata=([
                                                                    300, 400,
                                                                    500, 600,
                                                                    800, 1000,
                                                                    1500
                                                                ], 'K'),
                                                                Cpdata=([
                                                                    87.5579,
                                                                    108.135,
                                                                    126.429,
                                                                    141.841,
                                                                    165.681,
                                                                    183.615,
                                                                    211.679
                                                                ], 'J/(mol*K)'
                                                                        ),
                                                                H298=(
                                                                    -46.0526,
                                                                    'kJ/mol'),
                                                                S298=(
                                                                    302.672,
                                                                    'J/(mol*K)'
                                                                ),
                                                                Cp0=(
                                                                    33.2579,
                                                                    'J/(mol*K)'
                                                                ),
                                                                CpInf=(
                                                                    249.434,
                                                                    'J/(mol*K)'
                                                                ),
                                                                comment=
                                                                """Thermo group additivity estimation: group(Cs-CsCsOsH) + group(Cs-CsHHH) + group(Cs-CsHHH) + group(Os-CsH) + radical(CC(C)OJ)"""
                                                            ),
                                                            molecule=[
                                                                Molecule().
                                                                fromAdjacencyList(
                                                                    """multiplicity 2
1  *1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2     C u0 p0 c0 {1,S} {6,S} {7,S} {8,S}
3  *3 C u0 p0 c0 {1,S} {9,S} {10,S} {11,S}
4  *2 O u1 p2 c0 {1,S}
5     H u0 p0 c0 {1,S}
6     H u0 p0 c0 {2,S}
7     H u0 p0 c0 {2,S}
8     H u0 p0 c0 {2,S}
9     H u0 p0 c0 {3,S}
10    H u0 p0 c0 {3,S}
11    H u0 p0 c0 {3,S}
""")
                                                            ])
                                                    ],
                                                    degeneracy=2.0,
                                                    pairs=[[
                                                        Species(
                                                            label="",
                                                            thermo=ThermoData(
                                                                Tdata=([
                                                                    300, 400,
                                                                    500, 600,
                                                                    800, 1000,
                                                                    1500
                                                                ], 'K'),
                                                                Cpdata=([
                                                                    51.55,
                                                                    63.29,
                                                                    74.38,
                                                                    84.19,
                                                                    100.1,
                                                                    112.02,
                                                                    130.2
                                                                ], 'J/(mol*K)'
                                                                        ),
                                                                H298=(
                                                                    -166.3,
                                                                    'kJ/mol'),
                                                                S298=(
                                                                    263.446,
                                                                    'J/(mol*K)'
                                                                ),
                                                                Cp0=(
                                                                    33.2579,
                                                                    'J/(mol*K)'
                                                                ),
                                                                CpInf=(
                                                                    153.818,
                                                                    'J/(mol*K)'
                                                                ),
                                                                comment=
                                                                """Thermo group additivity estimation: group(Cs-(Cds-Od)HHH) + group(Cds-OdCsH)"""
                                                            ),
                                                            molecule=[
                                                                Molecule().
                                                                fromAdjacencyList(
                                                                    """1    C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2 *1 C u0 p0 c0 {1,S} {6,D} {7,S}
3    H u0 p0 c0 {1,S}
4    H u0 p0 c0 {1,S}
5    H u0 p0 c0 {1,S}
6 *2 O u0 p2 c0 {2,D}
7    H u0 p0 c0 {2,S}
""")
                                                            ]),
                                                        Species(
                                                            label="",
                                                            thermo=ThermoData(
                                                                Tdata=([
                                                                    300, 400,
                                                                    500, 600,
                                                                    800, 1000,
                                                                    1500
                                                                ], 'K'),
                                                                Cpdata=([
                                                                    87.5579,
                                                                    108.135,
                                                                    126.429,
                                                                    141.841,
                                                                    165.681,
                                                                    183.615,
                                                                    211.679
                                                                ], 'J/(mol*K)'
                                                                        ),
                                                                H298=(
                                                                    -46.0526,
                                                                    'kJ/mol'),
                                                                S298=(
                                                                    302.672,
                                                                    'J/(mol*K)'
                                                                ),
                                                                Cp0=(
                                                                    33.2579,
                                                                    'J/(mol*K)'
                                                                ),
                                                                CpInf=(
                                                                    249.434,
                                                                    'J/(mol*K)'
                                                                ),
                                                                comment=
                                                                """Thermo group additivity estimation: group(Cs-CsCsOsH) + group(Cs-CsHHH) + group(Cs-CsHHH) + group(Os-CsH) + radical(CC(C)OJ)"""
                                                            ),
                                                            molecule=[
                                                                Molecule().
                                                                fromAdjacencyList(
                                                                    """multiplicity 2
1  *1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2     C u0 p0 c0 {1,S} {6,S} {7,S} {8,S}
3  *3 C u0 p0 c0 {1,S} {9,S} {10,S} {11,S}
4  *2 O u1 p2 c0 {1,S}
5     H u0 p0 c0 {1,S}
6     H u0 p0 c0 {2,S}
7     H u0 p0 c0 {2,S}
8     H u0 p0 c0 {2,S}
9     H u0 p0 c0 {3,S}
10    H u0 p0 c0 {3,S}
11    H u0 p0 c0 {3,S}
""")
                                                            ])
                                                    ],
                                                           [
                                                               Species(
                                                                   label="",
                                                                   thermo=
                                                                   ThermoData(
                                                                       Tdata=([
                                                                           300,
                                                                           400,
                                                                           500,
                                                                           600,
                                                                           800,
                                                                           1000,
                                                                           1500
                                                                       ], 'K'),
                                                                       Cpdata=([
                                                                           9.331,
                                                                           9.988,
                                                                           10.611,
                                                                           11.274,
                                                                           12.457,
                                                                           13.427,
                                                                           15.105
                                                                       ], 'cal/(mol*K)'
                                                                               ),
                                                                       H298=
                                                                       (34.893,
                                                                        'kcal/mol'
                                                                        ),
                                                                       S298=
                                                                       (46.3704,
                                                                        'cal/(mol*K)'
                                                                        ),
                                                                       Cp0=
                                                                       (33.2579,
                                                                        'J/(mol*K)'
                                                                        ),
                                                                       CpInf=
                                                                       (108.088,
                                                                        'J/(mol*K)'
                                                                        ),
                                                                       comment=
                                                                       """Thermo library: primaryThermoLibrary + radical(CH3)"""
                                                                   ),
                                                                   molecule=[
                                                                       Molecule(
                                                                       ).
                                                                       fromAdjacencyList(
                                                                           """multiplicity 2
1 *3 C u1 p0 c0 {2,S} {3,S} {4,S}
2    H u0 p0 c0 {1,S}
3    H u0 p0 c0 {1,S}
4    H u0 p0 c0 {1,S}
""")
                                                                   ]),
                                                               Species(
                                                                   label="",
                                                                   thermo=
                                                                   ThermoData(
                                                                       Tdata=([
                                                                           300,
                                                                           400,
                                                                           500,
                                                                           600,
                                                                           800,
                                                                           1000,
                                                                           1500
                                                                       ], 'K'),
                                                                       Cpdata=([
                                                                           87.5579,
                                                                           108.135,
                                                                           126.429,
                                                                           141.841,
                                                                           165.681,
                                                                           183.615,
                                                                           211.679
                                                                       ], 'J/(mol*K)'
                                                                               ),
                                                                       H298=
                                                                       (-46.0526,
                                                                        'kJ/mol'
                                                                        ),
                                                                       S298=
                                                                       (302.672,
                                                                        'J/(mol*K)'
                                                                        ),
                                                                       Cp0=
                                                                       (33.2579,
                                                                        'J/(mol*K)'
                                                                        ),
                                                                       CpInf=
                                                                       (249.434,
                                                                        'J/(mol*K)'
                                                                        ),
                                                                       comment=
                                                                       """Thermo group additivity estimation: group(Cs-CsCsOsH) + group(Cs-CsHHH) + group(Cs-CsHHH) + group(Os-CsH) + radical(CC(C)OJ)"""
                                                                   ),
                                                                   molecule=[
                                                                       Molecule(
                                                                       ).
                                                                       fromAdjacencyList(
                                                                           """multiplicity 2
1  *1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2     C u0 p0 c0 {1,S} {6,S} {7,S} {8,S}
3  *3 C u0 p0 c0 {1,S} {9,S} {10,S} {11,S}
4  *2 O u1 p2 c0 {1,S}
5     H u0 p0 c0 {1,S}
6     H u0 p0 c0 {2,S}
7     H u0 p0 c0 {2,S}
8     H u0 p0 c0 {2,S}
9     H u0 p0 c0 {3,S}
10    H u0 p0 c0 {3,S}
11    H u0 p0 c0 {3,S}
""")
                                                                   ])
                                                           ]],
                                                    family=
                                                    'R_Addition_MultipleBond',
                                                    template=['Cd_R', 'CsJ'])

    def test_get_IP_ipropyl(self):
        IP = get_ionization_potential(self.ipropyl_mol)
        self.assertEqual(IP, self.ipropyl_ip)

    def test_get_IP_reaction(self):
        IP = get_IP_of_reaction(self.reaction)
        self.assertEqual(IP, self.methyl_ip)

    def test_get_arrhenius(self):
        "For ethoxyl radical decomposition"
        rate = self.sar.get_arrhenius(self.sar, self.reaction)
        self.assertAlmostEqual(rate.Ea.value,
                               2.4 * self.methyl_ip - 11.8 + 0.58 * 13.1,
                               places=1)

        self.assertAlmostEqual(rate.Ea.value, 18.2, places=-1)
        self.assertAlmostEqual(rate.A.value, self.A * self.reaction.degeneracy)

    def test_get_arrhenius_accounts_for_degeneracy(self):
        "test CC([O])C decomposition takes into account degenerarcy"
        rate = self.sar.get_arrhenius(self.sar, self.degenerate_reaction)
        self.assertAlmostEqual(rate.A.value, 2 * self.A)

    def test_get_rate(self):
        rate = self.sar.get_rate(self.reaction, 298)
        print self.reaction.getEnthalpyOfReaction(298) / 4184
        print self.sar.get_arrhenius(self.sar, self.reaction)
예제 #35
0
    def testaddReverseAttribute(self):
        """
        tests that the addReverseAttribute method gets the reverse degeneracy correct
        """
        from rmgpy.data.rmg import getDB
        from rmgpy.data.kinetics.family import TemplateReaction
        adjlist = [
            '''
        multiplicity 2
        1 H u0 p0 c0 {7,S}
        2 H u0 p0 c0 {4,S}
        3 C u1 p0 c0 {5,S} {7,S} {8,S}
        4 C u0 p0 c0 {2,S} {6,S} {7,D}
        5 H u0 p0 c0 {3,S}
        6 H u0 p0 c0 {4,S}
        7 C u0 p0 c0 {1,S} {3,S} {4,D}
        8 H u0 p0 c0 {3,S}
        ''', '''
        1 C u0 p0 c0 {2,S} {4,S} {5,S} {6,S}
        2 C u0 p0 c0 i13 {1,S} {3,D} {7,S}
        3 C u0 p0 c0 {2,D} {8,S} {9,S}
        4 H u0 p0 c0 {1,S}
        5 H u0 p0 c0 {1,S}
        6 H u0 p0 c0 {1,S}
        7 H u0 p0 c0 {2,S}
        8 H u0 p0 c0 {3,S}
        9 H u0 p0 c0 {3,S}
        ''', '''
        multiplicity 2
        1 H u0 p0 c0 {7,S}
        2 H u0 p0 c0 {4,S}
        3 C u1 p0 c0 {5,S} {7,S} {8,S}
        4 C u0 p0 c0 {2,S} {6,S} {7,D}
        5 H u0 p0 c0 {3,S}
        6 H u0 p0 c0 {4,S}
        7 C u0 p0 c0 i13 {1,S} {3,S} {4,D}
        8 H u0 p0 c0 {3,S}
        ''', '''
        1 C u0 p0 c0 {2,S} {4,S} {5,S} {6,S}
        2 C u0 p0 c0 {1,S} {3,D} {7,S}
        3 C u0 p0 c0 {2,D} {8,S} {9,S}
        4 H u0 p0 c0 {1,S}
        5 H u0 p0 c0 {1,S}
        6 H u0 p0 c0 {1,S}
        7 H u0 p0 c0 {2,S}
        8 H u0 p0 c0 {3,S}
        9 H u0 p0 c0 {3,S}
        '''
        ]
        family = getDB('kinetics').families['H_Abstraction']
        r1 = Species(molecule=[Molecule().fromAdjacencyList(adjlist[0])])
        r2 = Species(molecule=[Molecule().fromAdjacencyList(adjlist[1])])
        p1 = Species(molecule=[Molecule().fromAdjacencyList(adjlist[2])])
        p2 = Species(molecule=[Molecule().fromAdjacencyList(adjlist[3])])
        r1.generateResonanceIsomers(keepIsomorphic=True)
        p1.generateResonanceIsomers(keepIsomorphic=True)

        rxn = TemplateReaction(reactants=[r1, r2], products=[p1, p2])

        rxn.degeneracy = family.calculateDegeneracy(rxn)
        self.assertEqual(rxn.degeneracy, 6)

        family.addReverseAttribute(rxn)

        self.assertEqual(rxn.reverse.degeneracy, 6)