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')
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')