Пример #1
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))
    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))
Пример #3
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]))
    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]))
    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]))
Пример #6
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]))