Exemplo n.º 1
0
 def saveOutputHTML(self):
     """
     Save the current reaction model to a pretty HTML file.
     """
     logging.info('Saving current model to HTML file...')
     from rmgpy.rmg.output import saveOutputHTML
     saveOutputHTML(os.path.join(self.outputDirectory, 'output.html'), self.reactionModel)
Exemplo n.º 2
0
def main(chemkin, dictionary, output, foreign):
    model = CoreEdgeReactionModel()
    model.core.species, model.core.reactions = loadChemkinFile(chemkin, dictionary, readComments=not foreign)
    outputPath = os.path.join(output, 'output.html')
    speciesPath = os.path.join(output, 'species')
    if not os.path.isdir(speciesPath):
        os.makedirs(speciesPath)
    saveOutputHTML(outputPath, model)
Exemplo n.º 3
0
def main(chemkin, dictionary, output, foreign):
    model = CoreEdgeReactionModel()
    model.core.species, model.core.reactions = loadChemkinFile(
        chemkin, dictionary, readComments=not foreign, checkDuplicates=foreign)
    outputPath = os.path.join(output, 'output.html')
    speciesPath = os.path.join(output, 'species')
    if not os.path.isdir(speciesPath):
        os.makedirs(speciesPath)
    saveOutputHTML(outputPath, model)
Exemplo n.º 4
0
def saveHTMLFile(path):
    """
    Save an output HTML file from the contents of a RMG-Java output folder
    """
    from rmgpy.rmg.model import CoreEdgeReactionModel
    from rmgpy.rmg.output import saveOutputHTML
    chemkinPath= path + '/chemkin/chem.inp'
    dictionaryPath = path + 'RMG_Dictionary.txt'
    model = CoreEdgeReactionModel()
    model.core.species, model.core.reactions = loadChemkinFile(chemkinPath,dictionaryPath)
    outputPath = path + 'output.html'
    speciesPath = path + '/species/'
    if not os.path.isdir(speciesPath):
        os.makedirs(speciesPath)
    saveOutputHTML(outputPath, model)
Exemplo n.º 5
0
    def initialize(self, args):
        """
        Initialize an RMG job using the command-line arguments `args` as returned
        by the :mod:`argparse` package.
        """
    
        # Save initialization time
        self.initializationTime = time.time()
    
        # Log start timestamp
        logging.info('RMG execution initiated at ' + time.asctime() + '\n')
    
        # Print out RMG header
        self.logHeader()
        
        # Set directories
        self.outputDirectory = args.output_directory
        self.scratchDirectory = args.scratch_directory
        
        # Read input file
        self.loadInput(args.file[0])
        
        # Check input file 
        self.checkInput()
    
        # See if memory profiling package is available
        try:
            import os
            import psutil
        except ImportError:
            logging.info('Optional package dependency "psutil" not found; memory profiling information will not be saved.')
    
        # See if spreadsheet writing package is available
        if self.saveConcentrationProfiles:
            try:
                xlwt
            except NameError:
                logging.warning('Package dependency "xlwt" not loaded; reaction system concentration profiles will not be saved, despite saveConcentrationProfiles = True option.')
                self.saveConcentrationProfiles = False
        
        # Make output subdirectories
        self.makeOutputSubdirectory('plot')
        self.makeOutputSubdirectory('species')
        self.makeOutputSubdirectory('pdep')
        self.makeOutputSubdirectory('chemkin')
        self.makeOutputSubdirectory('solver')
        
        # Load databases
        self.loadDatabase()
    
        # Set wall time
        if args.walltime == '0': 
            self.wallTime = 0
        else:
            data = args.walltime[0].split(':')
            if len(data) == 1:
                self.wallTime = int(data[-1])
            elif len(data) == 2:
                self.wallTime = int(data[-1]) + 60 * int(data[-2])
            elif len(data) == 3:
                self.wallTime = int(data[-1]) + 60 * int(data[-2]) + 3600 * int(data[-3])
            elif len(data) == 4:
                self.wallTime = int(data[-1]) + 60 * int(data[-2]) + 3600 * int(data[-3]) + 86400 * int(data[-4])
            else:
                raise ValueError('Invalid format for wall time; should be HH:MM:SS.')
    
        # Delete previous HTML file
        from rmgpy.rmg.output import saveOutputHTML
        saveOutputHTML(os.path.join(self.outputDirectory, 'output.html'), self.reactionModel)
        
        # Initialize reaction model
        if args.restart:
            self.loadRestartFile(os.path.join(self.outputDirectory,'restart.pkl'))
        else:
    
            # Seed mechanisms: add species and reactions from seed mechanism
            # DON'T generate any more reactions for the seed species at this time
            for seedMechanism in self.seedMechanisms:
                self.reactionModel.addSeedMechanismToCore(seedMechanism, react=False)

            # Reaction libraries: add species and reactions from reaction library to the edge so
            # that RMG can find them if their rates are large enough
            for library, option in self.reactionLibraries:
                self.reactionModel.addReactionLibraryToEdge(library)
            
            # Add nonreactive species (e.g. bath gases) to core first
            # This is necessary so that the PDep algorithm can identify the bath gas
            self.reactionModel.enlarge([spec for spec in self.initialSpecies if not spec.reactive])
            # Then add remaining reactive species
            for spec in self.initialSpecies:
                spec.generateThermoData(self.database)
            self.reactionModel.enlarge([spec for spec in self.initialSpecies if spec.reactive])
            
            # Save a restart file if desired
            if self.saveRestartPeriod:
                self.saveRestartFile(os.path.join(self.outputDirectory,'restart.pkl'), self.reactionModel)
Exemplo n.º 6
0
# Create pathway calculation folder
if not os.path.exists(pathwayFolder):
    os.makedirs(pathwayFolder)
    shutil.copy(mechFileCti, os.path.join(pathwayFolder, mechFileCti))
    shutil.move(pathwayFile, os.path.join(pathwayFolder, pathwayFile))

# Generate HTML file
if not os.path.isfile(os.path.join(mechFolder, mechHTML)):
    print 'create reaction model...'
    model = CoreEdgeReactionModel()
    print 'load chemkin file...'
    model.core.species, model.core.reactions = loadChemkinFile(
        os.path.join(mechFolder, mechFileInp),
        os.path.join(mechFolder, spcFile))
    print 'save HTML file...'
    saveOutputHTML(os.path.join(mechFolder, mechHTML), model)
    print 'finished!'

# Copy the 'species' folder generated during the generation of HTML file to the 'pathway' folder. Rename the copy as 'structure'
structureDir = os.path.join(pathwayFolder, structureFolder)
if not os.path.exists(structureDir):
    shutil.copytree(os.path.join(mechFolder, spcFolder), structureDir)
    for filename in os.listdir(structureDir):
        if filename.endswith(').png'):
            filename = os.path.join(structureDir, filename)
            im = Image.open(filename)
            # f = 200.0/max(im.width, im.height)
            f = 3
            im = im.resize((int(im.width * f), int(im.height * f)))
            im.save(filename)