示例#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))
    def testEnsureReactionDirection(self):
        """
        Tests that the direction of the reaction is constant for every isotopomer
        """

        # get reactions

        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().fromSMILES('C')
        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}
        """)

        dipropyl = Species().fromSMILES('[CH2]C[CH2]')
        dipropyli = Species().fromAdjacencyList("""
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().fromSMILES('CC[CH2]')
        propyli = 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  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.isIsomorphic(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))
示例#4
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))