示例#1
0
文件: react.py 项目: yplitw/RMG-Py
def correctDegeneracyOfReverseReactions(reactionList, reactants):
    """
    This method corrects the degeneracy of reactions found when the backwards
    template is used. Given the following parameters:

        reactionList - list of reactions with their degeneracies already counted
        reactants - list/tuple of species used in the generateReactions method

    This method modifies reactionList in place and returns nothing
    
    This does not adjust for identical reactants, you need to use `reduceSameReactantDegeneracy`
    to adjust for that.
    """
    from rmgpy.reaction import _isomorphicSpeciesList
    from rmgpy.reaction import ReactionError

    for rxn in reactionList:
        if _isomorphicSpeciesList(rxn.reactants, reactants):
            # was forward reaction so ignore
            continue
        elif _isomorphicSpeciesList(rxn.products, reactants):
            # was reverse reaction so should find degeneracy
            family = getDB('kinetics').families[rxn.family]
            if not family.ownReverse:
                rxn.degeneracy = family.calculateDegeneracy(
                    rxn, ignoreSameReactants=True)
        else:
            # wrong reaction was sent here
            raise ReactionError(
                'Reaction in reactionList did not match reactants. Reaction: {}, Reactants: {}'
                .format(rxn, reactants))
示例#2
0
    def test_degeneracy_same_reactant_different_resonance_structure(self):
        """Test if degeneracy is correct when reacting different resonance structures."""
        from rmgpy.reaction import _isomorphicSpeciesList

        spc = Species().fromSMILES('CC=C[CH2]')
        # reactSpecies will label reactants and generate resonance structures
        reactions = reactSpecies((spc, spc))
        # these products are only possible if the reacting structures are CC=C[CH2] and C[CH2]C=C
        products = [
            Species().fromSMILES('CC=CC'),
            Species().fromSMILES('C=CC=C')
        ]

        # search for the desired products
        desired_rxn = None
        for rxn in reactions:
            if rxn.family == 'Disproportionation' and _isomorphicSpeciesList(
                    rxn.products, products):
                if desired_rxn is None:
                    desired_rxn = rxn
                else:
                    self.fail(
                        'Found two reactions which should be isomorphic.')

        self.assertEqual(desired_rxn.degeneracy, 3)
        self.assertEqual(set(desired_rxn.template),
                         {'C_rad/H2/Cd', 'Cmethyl_Csrad/H/Cd'})