def testIntraHmigration(self): """An intra-H migration reaction""" self.loadDatabase(only_families=['intra_H_migration']) structure1 = Structure() structure1.fromSMILES("[CH](CCCc1ccccc1)CCCCCC") species1 = makeNewSpecies(structure1) structure2 = Structure() structure2.fromSMILES("C(CCCC[CH]c1ccccc1)CCCC") species2 = makeNewSpecies(structure2) # wipe the reaction list reaction.reactionList=[] rxns = reaction.kineticsDatabase.getReactions([species1]) #for rxn in rxns: # print 'Reaction family:',rxn.family # print 'Reaction:',rxn # print 'Kinetics:',rxn.kinetics # print 'bestKinetics:',rxn.bestKinetics # print all_products = [] for rxn in rxns: self.assertEqual(rxn.family.label,'Intra H migration',"Was trying to test 'Intra H migration' but made a reaction from family %s"%rxn.family) self.assertEqual(len(rxn.reactants),1,"Reaction %s wasn't unimolecular"%rxn) all_products.extend(rxn.products) self.assertTrue(species2 in all_products, "None of the reactions made %s"%(species2))
def testSpeciesRestart(self): """ Restart tests for the :class:`rmg.species.Species` class. """ import rmg.structure as structure import rmg.species as species # Create smiles = 'C=CC=C[CH]C' struct0 = structure.Structure(SMILES=smiles) spec0, isNew = species.makeNewSpecies(struct0, label=smiles, reactive=True) # Pickle f = open('test.pkl', 'wb'); cPickle.dump(spec0, f); f.close() # Unpickle f = open('test.pkl', 'rb'); spec = cPickle.load(f); f.close() # Compare self.assertTrue(spec0.id == spec.id) self.assertTrue(spec0.label == spec.label == smiles) self.assertTrue(spec0.reactive == spec.reactive == True) self.assertTrue(len(spec0.structure) == len(spec.structure) == 3) for struct1 in spec0.structure: match = False for struct2 in spec.structure: if struct1.isIsomorphic(struct2): match = True self.assertTrue(match) self.assertTrue(spec0.thermoData.equals(spec.thermoData)) #self.assertTrue(spec0.thermoSnapshot == spec.thermoSnapshot) self.assertTrue(spec0.spectralData == spec.spectralData) self.assertTrue(spec0.lennardJones == spec.lennardJones)
def testCyclicColligation(self): """A test of a Birad_recombination (Cyclic colligation) reactions""" self.loadDatabase(only_families=['Birad_recombination']) for smile in ['C1CCCCC1', 'CCCCCCCCC1C(c2ccccc2)C(CCCCCC)C=CC1c1ccccc1', 'C(=CC(c1ccccc1)C([CH]CCCCCC)C=Cc1ccccc1)[CH]CCCCCC', 'C1(C(CCCCCCCC)C(C(CCCCCC)C=C1)c1ccccc1)c1ccccc1' ]: structure1 = Structure(SMILES=smile) species1 = makeNewSpecies(structure1) print 'Reacting species',species1 # wipe the reaction list reaction.reactionList=[] rxns = reaction.kineticsDatabase.getReactions([species1]) for rxn in rxns: print 'Reaction family:',rxn.family print 'Reaction:',rxn print 'Kinetics:',rxn.kinetics print all_products = [] for rxn in rxns: self.assertEqual(rxn.family.label,'Cyclic colligation',"Was trying to test 'Cyclic colligation' but made a reaction from family %s"%rxn.family) self.assertEqual(len(rxn.reactants),1,"Reaction %s wasn't unimolecular"%rxn) self.assertEqual(len(rxn.products),1,"Reaction %s wasn't unimolecular"%rxn) all_products.extend(rxn.products) print "All products for reacting %s:"%species1, [p.structure[0] for p in all_products]
def test22CycloadditionCd(self): """Test 2+2_cycloaddition_Cd reactions""" self.loadDatabase(only_families=['2+2_cycloaddition_Cd']) for smile in [ 'C1(CC(C)(C)O1)(C)C' ]: structure1 = Structure(SMILES=smile) species1 = makeNewSpecies(structure1) print 'Reacting species',species1 # wipe the reaction list reaction.reactionList=[] rxns = reaction.kineticsDatabase.getReactions([species1]) for rxn in rxns: print 'Reaction family:',rxn.family print 'Reaction:',rxn print 'Kinetics:',rxn.kinetics print all_products = [] for rxn in rxns: #self.assertEqual(rxn.family.label,'Cyclic colligation',"Was trying to test 'Cyclic colligation' but made a reaction from family %s"%rxn.family) #self.assertEqual(len(rxn.reactants),1,"Reaction %s wasn't unimolecular"%rxn) #self.assertEqual(len(rxn.products),1,"Reaction %s wasn't unimolecular"%rxn) all_products.extend(rxn.products) print "All products for reacting %s:"%species1, [p.structure[0] for p in all_products]
def testDisproportionation(self): """A test of a Disproportionation (Radical alpha H abstraction) reactions""" self.loadDatabase(only_families=['Disproportionation']) for smile in ['C(=[CH])[CH2]', ]: structure1 = Structure(SMILES=smile) species1 = makeNewSpecies(structure1) print 'Reacting species',species1, 'with itself' # wipe the reaction list reaction.reactionDict = {} rxns = reaction.kineticsDatabase.getReactions([species1,species1]) for rxn in rxns: print 'Reaction family:',rxn.family print 'Reaction:',rxn print 'Kinetics:',rxn.kinetics print self.assertTrue(len(rxns)>0,"Didn't make any reactions!") all_products = [] for rxn in rxns: #self.assertEqual(rxn.family.label,'Cyclic colligation',"Was trying to test 'Cyclic colligation' but made a reaction from family %s"%rxn.family) self.assertEqual(len(rxn.reactants),2,"Reaction %s wasn't bimolecular"%rxn) self.assertEqual(len(rxn.products),2,"Reaction %s wasn't bimolecular"%rxn) all_products.extend(rxn.products) print "All products for reacting %s:"%species1, [p.structure[0] for p in all_products]
def test12Cycloaddition(self): """Test 1+2_Cycloaddition reactions""" self.loadDatabase(only_families=['1+2_Cycloaddition']) for smile in ['O1OO1' ]: structure1 = Structure(SMILES=smile) species1, isNew = makeNewSpecies(structure1) print 'Reacting species',species1 # wipe the reaction list reaction.reactionDict = {} rxns = reaction.kineticsDatabase.getReactions([species1]) for rxn in rxns: print 'Reaction family:',rxn.family print 'Reaction:',rxn print 'Kinetics:',rxn.kinetics print all_products = [] for rxn in rxns: #self.assertEqual(rxn.family.label,'Cyclic colligation',"Was trying to test 'Cyclic colligation' but made a reaction from family %s"%rxn.family) #self.assertEqual(len(rxn.reactants),1,"Reaction %s wasn't unimolecular"%rxn) #self.assertEqual(len(rxn.products),1,"Reaction %s wasn't unimolecular"%rxn) all_products.extend(rxn.products) print "All products for reacting %s:"%species1, [p.structure[0] for p in all_products] structure2 = Structure() structure2.fromAdjacencyList("O2\n1 O 0 {2,D}\n2 O 0 {1,D}\n") species2 = makeNewSpecies(structure2) structure3 = Structure() structure3.fromAdjacencyList("O\n1 O 2\n") species3 = makeNewSpecies(structure3) reaction.reactionDict = {} print "Now reacting %s with %s:"%(species2, species3) for sp in (species2, species3): print sp.toAdjacencyList() rxns = reaction.kineticsDatabase.getReactions([species2,species3]) for rxn in rxns: print 'Reaction family:',rxn.family print 'Reaction:',rxn print 'Kinetics:',rxn.kinetics self.assertEqual(len(rxns),1, "Made %d 1+2_Cycloaddition reactions instead of 1"%(len(rxns)))
def testEthaneExtrusionFromEther(self): """A reaction that was giving trouble in a diesel simulation""" self.loadDatabase(only_families=['1,3_Insertion_ROR']) structure1 = Structure() structure1.fromSMILES("c1c([CH]C(C=CCCCCCC)OOCc2c3ccccc3ccc2)cccc1") species1 = makeNewSpecies(structure1) structure2 = Structure() structure2.fromSMILES("c1ccc(c2ccccc12)COO") species2 = makeNewSpecies(structure2) structure3 = Structure() structure3.fromSMILES("c1cc(C=C[C]=CCCCCCC)ccc1") species3 = makeNewSpecies(structure3) # wipe the reaction list reaction.reactionList=[] #print "FORWARD" rxns = reaction.kineticsDatabase.getReactions([species2,species3]) #for rxn in rxns: # print 'Reaction family:',rxn.family # print 'Reaction:',rxn # print 'Kinetics:',rxn.kinetics # print 'bestKinetics:',rxn.bestKinetics # print self.assertEqual(len(rxns),18, "Was expecting to make 18 reactions for %s + %s"%(species2,species3)) # wipe the reaction list reaction.reactionList=[] #print "REVERSE" rxns = reaction.kineticsDatabase.getReactions([species1]) #for rxn in rxns: # print 'Reaction family:',rxn.family # print 'Reaction:',rxn # print 'Kinetics:',rxn.kinetics # print 'bestKinetics:',rxn.bestKinetics # print self.assertEqual(len(rxns),1, "Was expecting to make 1 reaction for %s"%(species1)) rxn = rxns[0] self.assertEqual(len(rxn.reactants),2,"Reaction wasn't bimolecular") self.assertTrue(species2 in rxn.reactants, "Didn't make %s"%species2) self.assertTrue(species3 in rxn.reactants, "Didn't make %s"%species3)
def testReactionRestart(self): """ Restart tests for the :class:`rmg.reaction.Reaction` class. """ import rmg.reaction as reaction import rmg.structure as structure import rmg.species as species # Create smiles = 'C' struct0 = structure.Structure(SMILES=smiles) methane, isNew = species.makeNewSpecies(struct0, label=smiles, reactive=True) reactions = reaction.kineticsDatabase.getReactions([methane]) reaction0 = reactions[0] # Pickle f = open('test.pkl', 'wb'); cPickle.dump(reaction0, f); f.close() # Unpickle f = open('test.pkl', 'rb'); reaction = cPickle.load(f); f.close() # Compare for reactant0 in reaction0.reactants: match = False for reactant in reaction.reactants: if reactant0.isIsomorphic(reactant): match = True self.assertTrue(match) for product0 in reaction0.products: match = False for product in reaction.products: if product0.isIsomorphic(product): match = True self.assertTrue(match) for kin0 in reaction0.kinetics: match = False for kin in reaction.kinetics: if kin0.equals(kin): match = True self.assertTrue(match) self.assertTrue(reaction0.family.label == reaction.family.label) self.assertTrue(reaction0.atomLabels.keys() == reaction.atomLabels.keys()) self.assertTrue(reaction0.multiplier == reaction.multiplier) self.assertTrue(reaction0.bestKinetics == reaction.bestKinetics)
def testAllFamilies(self): """A test of all reaction families Doesn't do (m)any actual tests, but hopefully won't cause any errors""" self.loadDatabase() for smile in ['O1OO1', 'C1(CC(C)(C)O1)(C)C', 'C1(C(CCCCCCCC)C(C(CCCCCC)C=C1)c1ccccc1)c1ccccc1', 'C(C)(C)(C)C(=O)OCC(C)C']: structure1 = Structure(SMILES=smile) species1 = makeNewSpecies(structure1) print 'Reacting species',species1 # wipe the reaction list reaction.reactionList=[] rxns = reaction.kineticsDatabase.getReactions([species1]) all_products = [] for rxn in rxns: all_products.extend(rxn.products) print "All products for reacting %s:"%species1, [p.structure[0] for p in all_products]
def testMakeNewReaction(self): """Create a new reaction and check you can identify the reverse""" structure1 = Structure() structure1.fromAdjacencyList(""" 1 C 0 {2,D} {7,S} {8,S} 2 C 0 {1,D} {3,S} {9,S} 3 C 0 {2,S} {4,D} {10,S} 4 C 0 {3,D} {5,S} {11,S} 5 *1 C 0 {4,S} {6,S} {12,S} {13,S} 6 C 0 {5,S} {14,S} {15,S} {16,S} 7 H 0 {1,S} 8 H 0 {1,S} 9 H 0 {2,S} 10 H 0 {3,S} 11 H 0 {4,S} 12 *2 H 0 {5,S} 13 H 0 {5,S} 14 H 0 {6,S} 15 H 0 {6,S} 16 H 0 {6,S} """) structure2 = Structure() structure2.fromAdjacencyList(""" 1 *3 H 1 """) structure3 = Structure() structure3.fromAdjacencyList(""" 1 C 0 {2,D} {7,S} {8,S} 2 C 0 {1,D} {3,S} {9,S} 3 C 0 {2,S} {4,D} {10,S} 4 C 0 {3,D} {5,S} {11,S} 5 *3 C 1 {4,S} {6,S} {12,S} 6 C 0 {5,S} {13,S} {14,S} {15,S} 7 H 0 {1,S} 8 H 0 {1,S} 9 H 0 {2,S} 10 H 0 {3,S} 11 H 0 {4,S} 12 H 0 {5,S} 13 H 0 {6,S} 14 H 0 {6,S} 15 H 0 {6,S} """) structure4 = Structure() structure4.fromAdjacencyList(""" 1 *1 H 0 {2,S} 2 *2 H 0 {1,S} """) C6H10 = makeNewSpecies(structure1) H = makeNewSpecies(structure2) C6H9 = makeNewSpecies(structure3) H2 = makeNewSpecies(structure4) # wipe the reaction list reaction.reactionList=[] reaction1, isNew = makeNewReaction([C6H9, H2], [C6H10, H], \ [C6H9.structure[0], H2.structure[0]], \ [C6H10.structure[0], H.structure[0]], \ None) self.assertFalse(reaction1 is None) self.assertTrue(isNew) reaction2, isNew = makeNewReaction([C6H10, H], [C6H9, H2], \ [C6H10.structure[0], H.structure[0]], \ [C6H9.structure[0], H2.structure[0]], \ None) self.assertTrue(reaction1 is reaction2) self.assertFalse(isNew)