Beispiel #1
0
def readThermoInputFile(path, rmg0):
    """
    Read an thermo estimation input file at `path` on disk into the :class:`RMG` object 
    `rmg`.
    """

    global rmg, speciesDict
    
    full_path = os.path.abspath(os.path.expandvars(path))
    try:
        f = open(full_path)
    except IOError:
        logging.error('The input file "{0}" could not be opened.'.format(full_path))
        logging.info('Check that the file exists and that you have read access.')
        raise

    logging.info('Reading input file "{0}"...'.format(full_path))

    rmg = rmg0
    rmg.reactionModel = CoreEdgeReactionModel()
    rmg.initialSpecies = []
    rmg.reactionSystems = []
    speciesDict = {}
    
    global_context = { '__builtins__': None }
    local_context = {
        '__builtins__': None,
        'True': True,
        'False': False,
        'database': database,
        'catalystProperties': catalystProperties,
        'species': species,
        'SMARTS': SMARTS,
        'SMILES': SMILES,
        'InChI': InChI,
        'solvation': solvation,
        'adjacencyList': adjacencyList,
        'quantumMechanics': quantumMechanics,
        'mlEstimator': mlEstimator,
    }

    try:
        exec f in global_context, local_context
    except (NameError, TypeError, SyntaxError) as e:
        logging.error('The input file "{0}" was invalid:'.format(full_path))
        logging.exception(e)
        raise
    finally:
        f.close()

    if rmg.quantumMechanics:
        rmg.quantumMechanics.setDefaultOutputDirectory(rmg.outputDirectory)
        rmg.quantumMechanics.initialize()
    broadcast(rmg.quantumMechanics, 'quantumMechanics')
    
    logging.info('')    
Beispiel #2
0
	def testSaveOutputHTML(self):
		"""
		This example is to test if an HTML file can be generated
		for the provided chemkin model.
		"""
		folder = os.path.join(os.getcwd(),'rmgpy/rmg/test_data/saveOutputHTML/')
		
		chemkinPath = os.path.join(folder, 'eg6', 'chem_annotated.inp')
		dictionaryPath = os.path.join(folder,'eg6', 'species_dictionary.txt')

		# loadChemkinFile
		species, reactions = loadChemkinFile(chemkinPath, dictionaryPath) 

		# convert it into a reaction model:
		core = ReactionModel(species, reactions)
		cerm = CoreEdgeReactionModel(core)

		out = os.path.join(folder, 'output.html')
		saveOutputHTML(out, cerm)

		self.assertTrue(os.path.isfile(out))
		os.remove(out)
		shutil.rmtree(os.path.join(folder,'species'))
Beispiel #3
0
    global rmg, speciesDict
    
    full_path = os.path.abspath(os.path.expandvars(path))
    try:
        f = open(full_path)
    except IOError, e:
        logging.error('The input file "{0}" could not be opened.'.format(full_path))
        logging.info('Check that the file exists and that you have read access.')
        raise e

    logging.info('Reading input file "{0}"...'.format(full_path))
    logging.info(f.read())
    f.seek(0)# return to beginning of file

    rmg = rmg0
    rmg.reactionModel = CoreEdgeReactionModel()
    rmg.initialSpecies = []
    rmg.reactionSystems = []
    speciesDict = {}
    
    global_context = { '__builtins__': None }
    local_context = {
        '__builtins__': None,
        'True': True,
        'False': False,
        'database': database,
        'species': species,
        'SMARTS': SMARTS,
        'SMILES': SMILES,
        'InChI': InChI,
        'adjacencyList': adjacencyList,
Beispiel #4
0
def readInputFile(path, rmg0):
    """
    Read an RMG input file at `path` on disk into the :class:`RMG` object 
    `rmg`.
    """
    global rmg, speciesDict
    
    full_path = os.path.abspath(os.path.expandvars(path))
    try:
        f = open(full_path)
    except IOError:
        logging.error('The input file "{0}" could not be opened.'.format(full_path))
        logging.info('Check that the file exists and that you have read access.')
        raise

    logging.info('Reading input file "{0}"...'.format(full_path))
    logging.info(f.read())
    f.seek(0)# return to beginning of file

    setGlobalRMG(rmg0)
    rmg.reactionModel = CoreEdgeReactionModel()
    rmg.initialSpecies = []
    rmg.reactionSystems = []
    speciesDict = {}
    
    global_context = { '__builtins__': None }
    local_context = {
        '__builtins__': None,
        'True': True,
        'False': False,
        'database': database,
        'catalystProperties': catalystProperties,
        'species': species,
        'SMARTS': SMARTS,
        'SMILES': SMILES,
        'InChI': InChI,
        'adjacencyList': adjacencyList,
        'simpleReactor': simpleReactor,
        'liquidReactor': liquidReactor,
        'surfaceReactor': surfaceReactor,
        'simulator': simulator,
        'solvation': solvation,
        'model': model,
        'quantumMechanics': quantumMechanics,
        'mlEstimator': mlEstimator,
        'pressureDependence': pressureDependence,
        'options': options,
        'generatedSpeciesConstraints': generatedSpeciesConstraints,
        'thermoCentralDatabase': thermoCentralDatabase
    }

    try:
        exec f in global_context, local_context
    except (NameError, TypeError, SyntaxError) as e:
        logging.error('The input file "{0}" was invalid:'.format(full_path))
        logging.exception(e)
        raise
    finally:
        f.close()
    
    rmg.speciesConstraints['explicitlyAllowedMolecules'] = []         
    broadcast(rmg.speciesConstraints, 'speciesConstraints')

    # convert keys from species names into species objects.
    for reactionSystem in rmg.reactionSystems:
        reactionSystem.convertInitialKeysToSpeciesObjects(speciesDict)

    if rmg.quantumMechanics:
        rmg.quantumMechanics.setDefaultOutputDirectory(rmg.outputDirectory)
        rmg.quantumMechanics.initialize()
    broadcast(rmg.quantumMechanics, 'quantumMechanics')

    logging.info('')