def test_reaction_degeneracy_independent_of_generatereactions_direction( self): """ test_reaction_degeneracy_independent_of_generatereactions_direction Ensure the returned kinetics have the same degeneracy irrespective of whether __generateReactions has forward = True or False """ family = database.kinetics.families['Disproportionation'] molA = Molecule().fromSMILES('C[CH2]') molB = Molecule().fromSMILES('C[CH2]') molC = Molecule().fromSMILES('C=C') molD = Molecule().fromSMILES('CC') molA.assignAtomIDs() molB.assignAtomIDs() molC.assignAtomIDs() molD.assignAtomIDs() # generate reactions in both directions forward_reactions = family._KineticsFamily__generateReactions( [molA, molB], products=[molC, molD], forward=True) reverse_reactions = family._KineticsFamily__generateReactions( [molC, molD], products=[molA, molB], forward=False) forward_reactions = findDegeneracies(forward_reactions) reverse_reactions = findDegeneracies(reverse_reactions) self.assertEqual( forward_reactions[0].degeneracy, reverse_reactions[0].degeneracy, 'the kinetics from forward and reverse directions had different degeneracies, {} and {} respectively' .format(forward_reactions[0].degeneracy, reverse_reactions[0].degeneracy))
def find_reaction_degeneracy(self, reactants_adj_list, rxn_family_str, num_independent_reactions=1): """ given: reactants_adj_list: a list of adjacency lists of the reactants `reaction_family_str`: the string representation of the reaction family `num_independent_rxns`: the number of reaction objects expected from generateReactions returns: a tuple with the total degeneracy and a list of reaction objects """ family = self.database.kinetics.families[rxn_family_str] reactants = [ Molecule().fromAdjacencyList(reactants_adj_list[0]), Molecule().fromAdjacencyList(reactants_adj_list[1]) ] for reactant in reactants: reactant.assignAtomIDs() reactions = family.generateReactions(reactants) reactions = findDegeneracies(reactions) reduceSameReactantDegeneracy(reactions) self.assertEqual( len(reactions), num_independent_reactions, 'only {1} reaction(s) should be produced. Produced reactions {0}'. format(reactions, num_independent_reactions)) return sum([reaction.degeneracy for reaction in reactions]), reactions
def testR_RecombinationPhenyl(self): """Test that the proper degeneracy is calculated for phenyl + H recombination""" family = 'R_Recombination' reactants = [ Molecule().fromSMILES('[c]1ccccc1'), Molecule().fromSMILES('[H]'), ] # assign atom IDs for reactant in reactants: reactant.assignAtomIDs() reactants = [mol.generateResonanceIsomers() for mol in reactants] combinations = itertools.product(reactants[0], reactants[1]) reactionList = [] for combi in combinations: reactionList.extend( self.database.kinetics.families[family].generateReactions( combi)) reactionList = findDegeneracies(reactionList) self.assertEqual(len(reactionList), 1) for rxn in reactionList: self.assertEqual(rxn.degeneracy, 1)
def testR_Addition_MultipleBondMethylNaphthalene(self): """Test that the proper degeneracy is calculated for H addition to methylnaphthalene""" family = 'R_Addition_MultipleBond' reactants = [ Molecule().fromSMILES('C1=CC=C2C=CC=CC2=C1C'), Molecule().fromSMILES('[H]'), ] # assign atom IDs for reactant in reactants: reactant.assignAtomIDs() reactants = [mol.generateResonanceIsomers() for mol in reactants] combinations = itertools.product(reactants[0], reactants[1]) reactionList = [] for combi in combinations: reactionList.extend( self.database.kinetics.families[family].generateReactions( combi)) product = Species().fromSMILES('C[C]1CC=CC2=CC=CC=C12') product.generateResonanceIsomers() targetReactions = [] for rxn in reactionList: for spc in rxn.products: if product.isIsomorphic(spc): targetReactions.append(rxn) targetReactions = findDegeneracies(targetReactions) self.assertEqual(len(targetReactions), 1) for rxn in targetReactions: self.assertEqual(rxn.degeneracy, 1)
def testR_RecombinationH(self): """Test that the proper degeneracy is calculated for H + H recombination""" family = 'R_Recombination' reactants = [ Molecule().fromSMILES('[H]'), Molecule().fromSMILES('[H]'), ] for reactant in reactants: reactant.assignAtomIDs() reactionList = self.database.kinetics.families[ family].generateReactions(reactants) reactionList = findDegeneracies(reactionList) self.assertEqual(len(reactionList), 1) self.assertEqual(reactionList[0].degeneracy, 1)