def setUp(self): self.dir_name = 'temp_dir_for_testing' os.chdir(originalPath) os.mkdir(self.dir_name) os.chdir(self.dir_name) self.databaseDirectory = settings['database.directory'] self.thermoDir = os.path.join(self.databaseDirectory,'thermo','libraries','testSeed.py') self.kineticsDir = os.path.join(self.databaseDirectory,'kinetics','libraries','testSeed') inputFile = """ database( thermoLibraries = ['primaryThermoLibrary'], reactionLibraries = [], seedMechanisms = [], kineticsDepositories = ['training'], kineticsFamilies = ['R_Recombination'], kineticsEstimator = 'rate rules', ) species( label='ethane', reactive=True, structure=SMILES("CC"), ) simpleReactor( temperature=(1350,'K'), pressure=(1.0,'bar'), initialMoleFractions={ "ethane": 1.0, }, terminationConversion={ 'ethane': 0.000000000001, }, terminationTime=(1e6,'s'), ) model( toleranceKeepInEdge=0.0, toleranceMoveToCore=0.2, toleranceInterruptSimulation=0.2, ) options( name='testSeed', units='si', generateSeedEachIteration=True, saveSeedToDatabase=True, saveRestartPeriod=None, generateOutputHTML=False, generatePlots=False, saveEdgeSpecies=False, saveSimulationProfiles=False, ) """ f = open('input.py','w') f.write(inputFile) f.close() self.rmg = RMG(inputFile=os.path.join(os.getcwd(), 'input.py'), outputDirectory=os.getcwd())
def setUpClass(cls): """A function that is run ONCE before all unit tests in this class.""" cls.testDir = os.path.join(originalPath, 'rmg', 'test_data', 'mainTest') cls.outputDir = 'output' cls.databaseDirectory = settings['database.directory'] cls.seedKinetics = os.path.join(cls.databaseDirectory, 'kinetics', 'libraries', 'testSeed') cls.seedKineticsEdge = os.path.join(cls.databaseDirectory, 'kinetics', 'libraries', 'testSeed_edge') os.mkdir(os.path.join(cls.testDir, cls.outputDir)) cls.rmg = RMG(inputFile=os.path.join(cls.testDir, 'input.py'), outputDirectory=os.path.join(cls.testDir, cls.outputDir)) cls.rmg.execute()
def setUp(self): self.chemkin_files={"""ELEMENTS H D /2.014/ T /3.016/ C CI /13.003/ O OI /18.000/ N END SPECIES ethane(1) CH3(4) END THERM ALL 300.000 1000.000 5000.000 ethane(1) H 6 C 2 G100.000 5000.000 954.52 1 4.58987205E+00 1.41507042E-02-4.75958084E-06 8.60284590E-10-6.21708569E-14 2 -1.27217823E+04-3.61762003E+00 3.78032308E+00-3.24248354E-03 5.52375224E-05 3 -6.38573917E-08 2.28633835E-11-1.16203404E+04 5.21037799E+00 4 CH3(4) H 3 C 1 G100.000 5000.000 1337.62 1 3.54144859E+00 4.76788187E-03-1.82149144E-06 3.28878182E-10-2.22546856E-14 2 1.62239622E+04 1.66040083E+00 3.91546822E+00 1.84153688E-03 3.48743616E-06 3 -3.32749553E-09 8.49963443E-13 1.62856393E+04 3.51739246E-01 4 END REACTIONS KCAL/MOLE MOLES CH3(4)+CH3(4)=ethane(1) 8.260e+17 -1.400 1.000 END """: True, """ELEMENTS CI /13.003/ O OI /18.000/ N END SPECIES ethane(1) CH3(4) END THERM ALL 300.000 1000.000 5000.000 ethane(1) H 6 C 2 G100.000 5000.000 954.52 1 4.58987205E+00 1.41507042E-02-4.75958084E-06 8.60284590E-10-6.21708569E-14 2 -1.27217823E+04-3.61762003E+00 3.78032308E+00-3.24248354E-03 5.52375224E-05 3 -6.38573917E-08 2.28633835E-11-1.16203404E+04 5.21037799E+00 4 CH3(4) H 3 C 1 G100.000 5000.000 1337.62 1 3.54144859E+00 4.76788187E-03-1.82149144E-06 3.28878182E-10-2.22546856E-14 2 1.62239622E+04 1.66040083E+00 3.91546822E+00 1.84153688E-03 3.48743616E-06 3 -3.32749553E-09 8.49963443E-13 1.62856393E+04 3.51739246E-01 4 END REACTIONS KCAL/MOLE MOLES CH3(4)+CH3(4)=ethane(1) 8.260e+17 -1.400 1.000 END """: False, """ELEMENTS H D /2.014/ T /3.016/ C CI /13.003/ O OI /18.000/ N END SPECIES ethane(1) CH3(4) END THERM ALL 300.000 1000.000 5000.000 ethane(1) H 6 C 2 G100.000 5000.000 954.52 1 4.58987205E+00 1.41507042E-02-4.75958084E-06 8.60284590E-10-6.21708569E-14 2 -1.27217823E+04-3.61762003E+00 3.78032308E+00-3.24248354E-03 5.52375224E-05 3 -6.38573917E-08 2.28633835E-11-1.16203404E+04 5.21037799E+00 4 END REACTIONS KCAL/MOLE MOLES CH3(4)+CH3(4)=ethane(1) 8.260e+17 -1.400 1.000 END """: False, } self.rmg = RMG() self.dir_name = 'temp_dir_for_testing' self.rmg.outputDirectory = os.path.join(originalPath, self.dir_name) self.tran_dat = '''
class TestCanteraOutput(unittest.TestCase): def setUp(self): self.chemkin_files={"""ELEMENTS H D /2.014/ T /3.016/ C CI /13.003/ O OI /18.000/ N END SPECIES ethane(1) CH3(4) END THERM ALL 300.000 1000.000 5000.000 ethane(1) H 6 C 2 G100.000 5000.000 954.52 1 4.58987205E+00 1.41507042E-02-4.75958084E-06 8.60284590E-10-6.21708569E-14 2 -1.27217823E+04-3.61762003E+00 3.78032308E+00-3.24248354E-03 5.52375224E-05 3 -6.38573917E-08 2.28633835E-11-1.16203404E+04 5.21037799E+00 4 CH3(4) H 3 C 1 G100.000 5000.000 1337.62 1 3.54144859E+00 4.76788187E-03-1.82149144E-06 3.28878182E-10-2.22546856E-14 2 1.62239622E+04 1.66040083E+00 3.91546822E+00 1.84153688E-03 3.48743616E-06 3 -3.32749553E-09 8.49963443E-13 1.62856393E+04 3.51739246E-01 4 END REACTIONS KCAL/MOLE MOLES CH3(4)+CH3(4)=ethane(1) 8.260e+17 -1.400 1.000 END """: True, """ELEMENTS CI /13.003/ O OI /18.000/ N END SPECIES ethane(1) CH3(4) END THERM ALL 300.000 1000.000 5000.000 ethane(1) H 6 C 2 G100.000 5000.000 954.52 1 4.58987205E+00 1.41507042E-02-4.75958084E-06 8.60284590E-10-6.21708569E-14 2 -1.27217823E+04-3.61762003E+00 3.78032308E+00-3.24248354E-03 5.52375224E-05 3 -6.38573917E-08 2.28633835E-11-1.16203404E+04 5.21037799E+00 4 CH3(4) H 3 C 1 G100.000 5000.000 1337.62 1 3.54144859E+00 4.76788187E-03-1.82149144E-06 3.28878182E-10-2.22546856E-14 2 1.62239622E+04 1.66040083E+00 3.91546822E+00 1.84153688E-03 3.48743616E-06 3 -3.32749553E-09 8.49963443E-13 1.62856393E+04 3.51739246E-01 4 END REACTIONS KCAL/MOLE MOLES CH3(4)+CH3(4)=ethane(1) 8.260e+17 -1.400 1.000 END """: False, """ELEMENTS H D /2.014/ T /3.016/ C CI /13.003/ O OI /18.000/ N END SPECIES ethane(1) CH3(4) END THERM ALL 300.000 1000.000 5000.000 ethane(1) H 6 C 2 G100.000 5000.000 954.52 1 4.58987205E+00 1.41507042E-02-4.75958084E-06 8.60284590E-10-6.21708569E-14 2 -1.27217823E+04-3.61762003E+00 3.78032308E+00-3.24248354E-03 5.52375224E-05 3 -6.38573917E-08 2.28633835E-11-1.16203404E+04 5.21037799E+00 4 END REACTIONS KCAL/MOLE MOLES CH3(4)+CH3(4)=ethane(1) 8.260e+17 -1.400 1.000 END """: False, } self.rmg = RMG() self.dir_name = 'temp_dir_for_testing' self.rmg.outputDirectory = os.path.join(originalPath, self.dir_name) self.tran_dat = ''' ! Species Shape LJ-depth LJ-diam DiplMom Polzblty RotRelaxNum Data ! Name Index epsilon/k_B sigma mu alpha Zrot Source ethane(1) 2 252.301 4.302 0.000 0.000 1.500 ! GRI-Mech CH3(4) 2 144.001 3.800 0.000 0.000 0.000 ! GRI-Mech ''' def tearDown(self): os.chdir(originalPath) # try to remove the tree. If testChemkinToCanteraConversion properly # ran, the files should already be removed. try: shutil.rmtree(self.dir_name) except OSError: pass # go back to the main RMG-Py directory os.chdir('..') def testChemkinToCanteraConversion(self): """ Tests that good and bad chemkin files raise proper exceptions """ from cantera.ck2cti import InputParseError for ck_input, works in self.chemkin_files.items(): os.chdir(originalPath) os.mkdir(self.dir_name) os.chdir(self.dir_name) f = open('chem001.inp','w') f.write(ck_input) f.close() f = open('tran.dat','w') f.write(self.tran_dat) f.close() if works: self.rmg.generateCanteraFiles(os.path.join(os.getcwd(),'chem001.inp')) else: with self.assertRaises(InputParseError): self.rmg.generateCanteraFiles(os.path.join(os.getcwd(),'chem001.inp')) # clean up os.chdir(originalPath) shutil.rmtree(self.dir_name)
class TestMain(unittest.TestCase): def setUp(self): self.dir_name = 'temp_dir_for_testing' os.chdir(originalPath) os.mkdir(self.dir_name) os.chdir(self.dir_name) inputFile = """ database( thermoLibraries = ['primaryThermoLibrary'], reactionLibraries = [], seedMechanisms = [], kineticsDepositories = ['training'], kineticsFamilies = ['R_Recombination'], kineticsEstimator = 'rate rules', ) species( label='ethane', reactive=True, structure=SMILES("CC"), ) simpleReactor( temperature=(1350,'K'), pressure=(1.0,'bar'), initialMoleFractions={ "ethane": 1.0, }, terminationConversion={ 'ethane': 0.000000000001, }, terminationTime=(1e6,'s'), ) model( toleranceKeepInEdge=0.0, toleranceMoveToCore=0.2, toleranceInterruptSimulation=0.2, ) options( units='si', saveRestartPeriod=None, generateOutputHTML=False, generatePlots=False, saveEdgeSpecies=False, saveSimulationProfiles=False, ) """ f = open('input.py','w') f.write(inputFile) f.close() self.rmg = RMG(inputFile=os.path.join(os.getcwd(), 'input.py'), outputDirectory=os.getcwd()) def tearDown(self): os.chdir(originalPath) shutil.rmtree(self.dir_name) # go back to the main RMG-Py directory os.chdir('..') # remove modular level database import rmgpy.data.rmg rmgpy.data.rmg.database = None def testRMGExecute(self): """ This example is to test if RMG.execute increases the core reactions """ self.rmg.execute() self.assertIsInstance(self.rmg.database, RMGDatabase) self.assertTrue(self.rmg.done) self.assertTrue(len(self.rmg.reactionModel.core.reactions) > 0) self.assertTrue(len(self.rmg.reactionModel.core.species) > 1) self.assertTrue(len(self.rmg.reactionModel.edge.reactions) > 0) self.assertTrue(len(self.rmg.reactionModel.edge.species) > 0) def testMakeCanteraInputFile(self): """ This tests to ensure that a usable cantera input file is created """ self.rmg.execute() import cantera as ct outName = os.path.join(self.rmg.outputDirectory, 'cantera') files = os.listdir(outName) for f in files: if '.cti' in f: try: ct.Solution(os.path.join(outName, f)) except: self.assertTrue(False, 'The output cantera file is not loadable in cantera')
def setUp(self): self.chemkin_files={"""ELEMENTS H D /2.014/ T /3.016/ C CI /13.003/ O OI /18.000/ N END SPECIES ethane(1) CH3(4) END THERM ALL 300.000 1000.000 5000.000 ethane(1) H 6 C 2 G100.000 5000.000 954.52 1 4.58987205E+00 1.41507042E-02-4.75958084E-06 8.60284590E-10-6.21708569E-14 2 -1.27217823E+04-3.61762003E+00 3.78032308E+00-3.24248354E-03 5.52375224E-05 3 -6.38573917E-08 2.28633835E-11-1.16203404E+04 5.21037799E+00 4 CH3(4) H 3 C 1 G100.000 5000.000 1337.62 1 3.54144859E+00 4.76788187E-03-1.82149144E-06 3.28878182E-10-2.22546856E-14 2 1.62239622E+04 1.66040083E+00 3.91546822E+00 1.84153688E-03 3.48743616E-06 3 -3.32749553E-09 8.49963443E-13 1.62856393E+04 3.51739246E-01 4 END REACTIONS KCAL/MOLE MOLES CH3(4)+CH3(4)=ethane(1) 8.260e+17 -1.400 1.000 END """: True, """ELEMENTS CI /13.003/ O OI /18.000/ N END SPECIES ethane(1) CH3(4) END THERM ALL 300.000 1000.000 5000.000 ethane(1) H 6 C 2 G100.000 5000.000 954.52 1 4.58987205E+00 1.41507042E-02-4.75958084E-06 8.60284590E-10-6.21708569E-14 2 -1.27217823E+04-3.61762003E+00 3.78032308E+00-3.24248354E-03 5.52375224E-05 3 -6.38573917E-08 2.28633835E-11-1.16203404E+04 5.21037799E+00 4 CH3(4) H 3 C 1 G100.000 5000.000 1337.62 1 3.54144859E+00 4.76788187E-03-1.82149144E-06 3.28878182E-10-2.22546856E-14 2 1.62239622E+04 1.66040083E+00 3.91546822E+00 1.84153688E-03 3.48743616E-06 3 -3.32749553E-09 8.49963443E-13 1.62856393E+04 3.51739246E-01 4 END REACTIONS KCAL/MOLE MOLES CH3(4)+CH3(4)=ethane(1) 8.260e+17 -1.400 1.000 END """: False, """ELEMENTS H D /2.014/ T /3.016/ C CI /13.003/ O OI /18.000/ N END SPECIES ethane(1) CH3(4) END THERM ALL 300.000 1000.000 5000.000 ethane(1) H 6 C 2 G100.000 5000.000 954.52 1 4.58987205E+00 1.41507042E-02-4.75958084E-06 8.60284590E-10-6.21708569E-14 2 -1.27217823E+04-3.61762003E+00 3.78032308E+00-3.24248354E-03 5.52375224E-05 3 -6.38573917E-08 2.28633835E-11-1.16203404E+04 5.21037799E+00 4 END REACTIONS KCAL/MOLE MOLES CH3(4)+CH3(4)=ethane(1) 8.260e+17 -1.400 1.000 END """: False, } self.rmg = RMG() self.dir_name = 'temp_dir_for_testing' self.rmg.outputDirectory = os.path.join(originalPath, self.dir_name) self.tran_dat = '''
class TestCanteraOutput(unittest.TestCase): def setUp(self): self.chemkin_files={"""ELEMENTS H D /2.014/ T /3.016/ C CI /13.003/ O OI /18.000/ N END SPECIES ethane(1) CH3(4) END THERM ALL 300.000 1000.000 5000.000 ethane(1) H 6 C 2 G100.000 5000.000 954.52 1 4.58987205E+00 1.41507042E-02-4.75958084E-06 8.60284590E-10-6.21708569E-14 2 -1.27217823E+04-3.61762003E+00 3.78032308E+00-3.24248354E-03 5.52375224E-05 3 -6.38573917E-08 2.28633835E-11-1.16203404E+04 5.21037799E+00 4 CH3(4) H 3 C 1 G100.000 5000.000 1337.62 1 3.54144859E+00 4.76788187E-03-1.82149144E-06 3.28878182E-10-2.22546856E-14 2 1.62239622E+04 1.66040083E+00 3.91546822E+00 1.84153688E-03 3.48743616E-06 3 -3.32749553E-09 8.49963443E-13 1.62856393E+04 3.51739246E-01 4 END REACTIONS KCAL/MOLE MOLES CH3(4)+CH3(4)=ethane(1) 8.260e+17 -1.400 1.000 END """: True, """ELEMENTS CI /13.003/ O OI /18.000/ N END SPECIES ethane(1) CH3(4) END THERM ALL 300.000 1000.000 5000.000 ethane(1) H 6 C 2 G100.000 5000.000 954.52 1 4.58987205E+00 1.41507042E-02-4.75958084E-06 8.60284590E-10-6.21708569E-14 2 -1.27217823E+04-3.61762003E+00 3.78032308E+00-3.24248354E-03 5.52375224E-05 3 -6.38573917E-08 2.28633835E-11-1.16203404E+04 5.21037799E+00 4 CH3(4) H 3 C 1 G100.000 5000.000 1337.62 1 3.54144859E+00 4.76788187E-03-1.82149144E-06 3.28878182E-10-2.22546856E-14 2 1.62239622E+04 1.66040083E+00 3.91546822E+00 1.84153688E-03 3.48743616E-06 3 -3.32749553E-09 8.49963443E-13 1.62856393E+04 3.51739246E-01 4 END REACTIONS KCAL/MOLE MOLES CH3(4)+CH3(4)=ethane(1) 8.260e+17 -1.400 1.000 END """: False, """ELEMENTS H D /2.014/ T /3.016/ C CI /13.003/ O OI /18.000/ N END SPECIES ethane(1) CH3(4) END THERM ALL 300.000 1000.000 5000.000 ethane(1) H 6 C 2 G100.000 5000.000 954.52 1 4.58987205E+00 1.41507042E-02-4.75958084E-06 8.60284590E-10-6.21708569E-14 2 -1.27217823E+04-3.61762003E+00 3.78032308E+00-3.24248354E-03 5.52375224E-05 3 -6.38573917E-08 2.28633835E-11-1.16203404E+04 5.21037799E+00 4 END REACTIONS KCAL/MOLE MOLES CH3(4)+CH3(4)=ethane(1) 8.260e+17 -1.400 1.000 END """: False, } self.rmg = RMG() self.dir_name = 'temp_dir_for_testing' self.rmg.outputDirectory = os.path.join(originalPath, self.dir_name) self.tran_dat = ''' ! Species Shape LJ-depth LJ-diam DiplMom Polzblty RotRelaxNum Data ! Name Index epsilon/k_B sigma mu alpha Zrot Source ethane(1) 2 252.301 4.302 0.000 0.000 1.500 ! GRI-Mech CH3(4) 2 144.001 3.800 0.000 0.000 0.000 ! GRI-Mech ''' def tearDown(self): os.chdir(originalPath) # try to remove the tree. If testChemkinToCanteraConversion properly # ran, the files should already be removed. try: shutil.rmtree(self.dir_name) except OSError: pass # go back to the main RMG-Py directory os.chdir('..') def testChemkinToCanteraConversion(self): """ Tests that good and bad chemkin files raise proper exceptions """ from cantera.ck2cti import InputParseError for ck_input, works in self.chemkin_files.items(): os.chdir(originalPath) os.mkdir(self.dir_name) os.chdir(self.dir_name) f = open('chem001.inp','w') f.write(ck_input) f.close() f = open('tran.dat','w') f.write(self.tran_dat) f.close() if works: self.rmg.generateCanteraFiles(os.path.join(os.getcwd(),'chem001.inp')) else: with self.assertRaises(InputParseError): self.rmg.generateCanteraFiles(os.path.join(os.getcwd(),'chem001.inp')) # clean up os.chdir(originalPath) shutil.rmtree(self.dir_name)
class TestMain(unittest.TestCase): def setUp(self): self.dir_name = 'temp_dir_for_testing' os.chdir(originalPath) os.mkdir(self.dir_name) os.chdir(self.dir_name) self.databaseDirectory = settings['database.directory'] self.thermoDir = os.path.join(self.databaseDirectory,'thermo','libraries','testSeed.py') self.kineticsDir = os.path.join(self.databaseDirectory,'kinetics','libraries','testSeed') inputFile = """ database( thermoLibraries = ['primaryThermoLibrary'], reactionLibraries = [], seedMechanisms = [], kineticsDepositories = ['training'], kineticsFamilies = ['R_Recombination'], kineticsEstimator = 'rate rules', ) species( label='ethane', reactive=True, structure=SMILES("CC"), ) simpleReactor( temperature=(1350,'K'), pressure=(1.0,'bar'), initialMoleFractions={ "ethane": 1.0, }, terminationConversion={ 'ethane': 0.000000000001, }, terminationTime=(1e6,'s'), ) model( toleranceKeepInEdge=0.0, toleranceMoveToCore=0.2, toleranceInterruptSimulation=0.2, ) options( name='testSeed', units='si', generateSeedEachIteration=True, saveSeedToDatabase=True, saveRestartPeriod=None, generateOutputHTML=False, generatePlots=False, saveEdgeSpecies=False, saveSimulationProfiles=False, ) """ f = open('input.py','w') f.write(inputFile) f.close() self.rmg = RMG(inputFile=os.path.join(os.getcwd(), 'input.py'), outputDirectory=os.getcwd()) def tearDown(self): os.chdir(originalPath) shutil.rmtree(self.dir_name) # go back to the main RMG-Py directory os.chdir('..') # remove modular level database import rmgpy.data.rmg rmgpy.data.rmg.database = None #delete the seed files created in database if os.path.exists(self.thermoDir): os.system('rm '+self.thermoDir) if os.path.exists(self.kineticsDir): os.system('rm -rf '+self.kineticsDir) def testRMGExecute(self): """ This example is to test if RMG.execute increases the core reactions """ self.rmg.execute() self.assertIsInstance(self.rmg.database, RMGDatabase) self.assertTrue(self.rmg.done) self.assertTrue(len(self.rmg.reactionModel.core.reactions) > 0) self.assertTrue(len(self.rmg.reactionModel.core.species) > 1) self.assertTrue(len(self.rmg.reactionModel.edge.reactions) > 0) self.assertTrue(len(self.rmg.reactionModel.edge.species) > 0) #test seed mech generation #test seed mech made in run directory seedDir = os.path.join(originalPath,self.dir_name,'seed') self.assertTrue(os.path.exists) os.chdir(seedDir) self.assertTrue(os.path.exists(self.rmg.name+'.py')) #thermo library made self.assertTrue(os.path.exists(self.rmg.name)) #kinetics library folder made kDir = os.path.join(seedDir,self.rmg.name) os.chdir(kDir) self.assertTrue(os.path.exists('dictionary.txt')) #dictionary file made self.assertTrue(os.path.exists('reactions.py')) #reactions file made os.chdir(os.path.join(originalPath,self.dir_name)) #return to original directory #check seed mech made in database self.assertTrue(os.path.exists(self.thermoDir)) self.assertTrue(os.path.exists(self.kineticsDir)) #check seed works self.rmg.database.load(path=self.databaseDirectory,thermoLibraries=['testSeed'],reactionLibraries=['testSeed'], seedMechanisms=['testSeed'],kineticsFamilies='default',kineticsDepositories = [], depository=False) #reload the database to get the seed self.rmg.reactionModel = CoreEdgeReactionModel() self.rmg.reactionModel.addReactionLibraryToEdge('testSeed') #try adding seed as library self.assertTrue(len(self.rmg.reactionModel.edge.species)>0) self.assertTrue(len(self.rmg.reactionModel.edge.reactions)>0) self.rmg.reactionModel = CoreEdgeReactionModel() self.rmg.reactionModel.addSeedMechanismToCore('testSeed') #try adding seed as seed mech self.assertTrue(len(self.rmg.reactionModel.core.species)>0) self.assertTrue(len(self.rmg.reactionModel.core.reactions)>0) def testMakeCanteraInputFile(self): """ This tests to ensure that a usable cantera input file is created """ self.rmg.execute() import cantera as ct outName = os.path.join(self.rmg.outputDirectory, 'cantera') files = os.listdir(outName) for f in files: if '.cti' in f: try: ct.Solution(os.path.join(outName, f)) except: self.assertTrue(False, 'The output cantera file is not loadable in cantera')