def test_compare_isotopomers_does_not_alter_species(self): """ Test that compareIsotomers works on species objects """ ethii = Species().from_adjacency_list(""" 1 C u0 p0 c0 i13 {2,S} {3,S} {4,S} {5,S} 2 C u0 p0 c0 i13 {1,S} {6,S} {7,S} {8,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} 8 H u0 p0 c0 {2,S} """) ethi = Species().from_adjacency_list(""" 1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S} 2 C u0 p0 c0 i13 {1,S} {6,S} {7,S} {8,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} 8 H u0 p0 c0 {2,S} """) compare_isotopomers(ethii, ethi) # ensure species still have labels for atom in ethii.molecule[0].atoms: if atom.element.symbol == 'C': self.assertEqual(atom.element.isotope, 13, 'compareIsotopomer removed the isotope of a species.')
def testCompareIsotopomersDoesNotAlterSpecies(self): """ Test that compareIsotomers works on species objects """ ethii = Species().fromAdjacencyList( """ 1 C u0 p0 c0 i13 {2,S} {3,S} {4,S} {5,S} 2 C u0 p0 c0 i13 {1,S} {6,S} {7,S} {8,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} 8 H u0 p0 c0 {2,S} """) ethi = Species().fromAdjacencyList( """ 1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S} 2 C u0 p0 c0 i13 {1,S} {6,S} {7,S} {8,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} 8 H u0 p0 c0 {2,S} """) compare_isotopomers(ethii,ethi) # ensure species still have labels for atom in ethii.molecule[0].atoms: if atom.element.symbol == 'C': self.assertEqual(atom.element.isotope, 13, 'compareIsotopomer removed the isotope of a species.')
def testCompareIsotopomersFailsOnSpecies(self): """ Test that compareIsotomers fails on species objects """ ethane = Species().fromAdjacencyList( """ 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 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} 8 H u0 p0 c0 {2,S} """) ethenei = Species().fromAdjacencyList( """ 1 C u0 p0 c0 {2,D} {3,S} {4,S} 2 C u0 p0 c0 i13 {1,D} {6,S} {5,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} """) self.assertFalse(compare_isotopomers(ethane,ethenei))
def testCompareIsotopomersWorksOnSpecies(self): """ Test that compareIsotomers works on species objects """ ethii = Species().fromAdjacencyList( """ 1 C u0 p0 c0 i13 {2,S} {3,S} {4,S} {5,S} 2 C u0 p0 c0 i13 {1,S} {6,S} {7,S} {8,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} 8 H u0 p0 c0 {2,S} """) ethi = Species().fromAdjacencyList( """ 1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S} 2 C u0 p0 c0 i13 {1,S} {6,S} {7,S} {8,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} 8 H u0 p0 c0 {2,S} """) self.assertTrue(compare_isotopomers(ethii,ethi))
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_compare_isotopomers_works_on_species(self): """ Test that compareIsotomers works on species objects """ ethii = Species().from_adjacency_list(""" 1 C u0 p0 c0 i13 {2,S} {3,S} {4,S} {5,S} 2 C u0 p0 c0 i13 {1,S} {6,S} {7,S} {8,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} 8 H u0 p0 c0 {2,S} """) ethi = Species().from_adjacency_list(""" 1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S} 2 C u0 p0 c0 i13 {1,S} {6,S} {7,S} {8,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} 8 H u0 p0 c0 {2,S} """) self.assertTrue(compare_isotopomers(ethii, ethi))
def test_compare_isotopomers_fails_on_species(self): """ Test that compareIsotomers fails on species objects """ ethane = Species().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 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} 8 H u0 p0 c0 {2,S} """) ethenei = Species().from_adjacency_list(""" 1 C u0 p0 c0 {2,D} {3,S} {4,S} 2 C u0 p0 c0 i13 {1,D} {6,S} {5,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} """) self.assertFalse(compare_isotopomers(ethane, ethenei))
def testCompareIsotopomersFailsOnReactions(self): """ Test that compareIsotomers fails 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} """) reaction2 = TemplateReaction(reactants = [propanei,h], products = [npropyli,h2], family = 'H_Abstraction') magicReaction = TemplateReaction(reactants = [propane,h], products = [propanei,h], family = 'H_Abstraction') self.assertFalse(compare_isotopomers(reaction2,magicReaction))
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))
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))
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))