Example #1
0
def run(inputFile, speciesPath=None, useJava=False):
    
    rmg = loadRMGJob(inputFile, useJava)
        
    # Generate a flux diagram video for each reaction system
    util.makeOutputSubdirectory('flux')
    for index, reactionSystem in enumerate(rmg.reactionSystems):
        
        util.makeOutputSubdirectory('flux/{0:d}'.format(index+1))
        
        # If there is no termination time, then add one to prevent jobs from
        # running forever
        if not any([isinstance(term, TerminationTime) for term in reactionSystem.termination]):
            reactionSystem.termination.append(TerminationTime((1e10,'s')))
        
        
        print 'Conducting simulation of reaction system {0:d}...'.format(index+1)
        time, coreSpeciesConcentrations, coreReactionRates, edgeReactionRates =\
        simulate(rmg.reactionModel, reactionSystem)
        
        centralSpecies = None
        print 'Generating flux diagram for reaction system {0:d}...'.format(index+1)
        generateFluxDiagram(
            rmg.reactionModel, time, coreSpeciesConcentrations, coreReactionRates,\
            os.path.join(rmg.outputDirectory, 'flux', '{0:d}'.format(index+1)), centralSpecies, speciesPath
            )    
Example #2
0
def run(inputFile, speciesPath=None, useJava=False):

    rmg = loadRMGJob(inputFile, useJava=useJava)

    if speciesPath is None:
        speciesPath = os.path.join(os.path.dirname(inputFile), 'species')

    # Generate a flux diagram video for each reaction system
    util.makeOutputSubdirectory(rmg.outputDirectory, 'flux')
    for index, reactionSystem in enumerate(rmg.reactionSystems):

        util.makeOutputSubdirectory(rmg.outputDirectory,
                                    'flux/{0:d}'.format(index + 1))

        # If there is no termination time, then add one to prevent jobs from
        # running forever
        if not any([
                isinstance(term, TerminationTime)
                for term in reactionSystem.termination
        ]):
            reactionSystem.termination.append(TerminationTime((1e10, 's')))

        print 'Conducting simulation of reaction system {0:d}...'.format(
            index + 1)
        time, coreSpeciesConcentrations, coreReactionRates, edgeReactionRates =\
        simulate(rmg.reactionModel, reactionSystem)

        centralSpecies = None
        print 'Generating flux diagram for reaction system {0:d}...'.format(
            index + 1)
        generateFluxDiagram(
            rmg.reactionModel, time, coreSpeciesConcentrations, coreReactionRates,\
            os.path.join(rmg.outputDirectory, 'flux', '{0:d}'.format(index+1)), centralSpecies, speciesPath
            )
Example #3
0
def simulate(rmg):
    """
    Simulate the RMG job and run the sensitivity analysis if it is on, generating
    output csv files
    """
    util.makeOutputSubdirectory(rmg.outputDirectory, 'solver')

    for index, reactionSystem in enumerate(rmg.reactionSystems):

        if reactionSystem.sensitiveSpecies:
            logging.info(
                'Conducting simulation and sensitivity analysis of reaction system %s...'
                % (index + 1))

        else:
            logging.info('Conducting simulation of reaction system %s...' %
                         (index + 1))

        if rmg.saveSimulationProfiles:
            reactionSystem.attach(
                SimulationProfileWriter(rmg.outputDirectory, index,
                                        rmg.reactionModel.core.species))
            reactionSystem.attach(
                SimulationProfilePlotter(rmg.outputDirectory, index,
                                         rmg.reactionModel.core.species))
        else:
            worksheet = None

        sensWorksheet = []
        for spec in reactionSystem.sensitiveSpecies:
            csvfilePath = os.path.join(
                rmg.outputDirectory, 'solver',
                'sensitivity_{0}_SPC_{1}.csv'.format(index + 1, spec.index))
            sensWorksheet.append(csvfilePath)

        pdepNetworks = []
        for source, networks in rmg.reactionModel.networkDict.items():
            pdepNetworks.extend(networks)
        terminated, obj = reactionSystem.simulate(
            coreSpecies=rmg.reactionModel.core.species,
            coreReactions=rmg.reactionModel.core.reactions,
            edgeSpecies=rmg.reactionModel.edge.species,
            edgeReactions=rmg.reactionModel.edge.reactions,
            toleranceKeepInEdge=0,
            toleranceMoveToCore=1,
            toleranceInterruptSimulation=1,
            pdepNetworks=pdepNetworks,
            absoluteTolerance=rmg.absoluteTolerance,
            relativeTolerance=rmg.relativeTolerance,
            sensitivity=True if reactionSystem.sensitiveSpecies else False,
            sensitivityAbsoluteTolerance=rmg.sensitivityAbsoluteTolerance,
            sensitivityRelativeTolerance=rmg.sensitivityRelativeTolerance,
            sensWorksheet=sensWorksheet,
        )

        if reactionSystem.sensitiveSpecies:
            plotSensitivity(rmg.outputDirectory, index,
                            reactionSystem.sensitiveSpecies)
Example #4
0
    def sensitivityAnalysis(self, initialMoleFractions, sensitiveSpecies, T, P, terminationTime, sensitivityThreshold=1e-3, number=10, fileformat='.png'):
        """
        Run sensitivity analysis using the RMG solver in a single ReactionSystem object
        
        initialMoleFractions is a dictionary with Species objects as keys and mole fraction initial conditions
        sensitiveSpecies is a list of sensitive Species objects
        number is the number of top species thermo or reaction kinetics desired to be plotted
        """
        
        
        from rmgpy.solver import SimpleReactor, TerminationTime
        from rmgpy.quantity import Quantity
        from rmgpy.tools.sensitivity import plotSensitivity
        from rmgpy.rmg.listener import SimulationProfileWriter, SimulationProfilePlotter
        from rmgpy.rmg.settings import ModelSettings, SimulatorSettings
        T = Quantity(T)
        P = Quantity(P)
        termination=[TerminationTime(Quantity(terminationTime))]
                                     
        reactionSystem = SimpleReactor(T, P, initialMoleFractions, termination, sensitiveSpecies, sensitivityThreshold)
        
        # Create the csv worksheets for logging sensitivity
        util.makeOutputSubdirectory(self.outputDirectory, 'solver')
        sensWorksheet = []
        reactionSystemIndex = 0
        for spec in reactionSystem.sensitiveSpecies:
            csvfilePath = os.path.join(self.outputDirectory, 'solver', 'sensitivity_{0}_SPC_{1}.csv'.format(reactionSystemIndex+1, spec.index))
            sensWorksheet.append(csvfilePath)

        reactionSystem.attach(SimulationProfileWriter(
            self.outputDirectory, reactionSystemIndex, self.speciesList))  
        reactionSystem.attach(SimulationProfilePlotter(
            self.outputDirectory, reactionSystemIndex, self.speciesList))
        
        simulatorSettings = SimulatorSettings() #defaults
        
        modelSettings = ModelSettings() #defaults
        modelSettings.fluxToleranceMoveToCore = 0.1
        modelSettings.fluxToleranceInterrupt = 1.0
        modelSettings.fluxToleranceKeepInEdge = 0.0
        
        reactionSystem.simulate(
            coreSpecies = self.speciesList,
            coreReactions = self.reactionList,
            edgeSpecies = [],
            edgeReactions = [],
            surfaceSpecies = [],
            surfaceReactions = [],
            modelSettings = modelSettings,
            simulatorSettings = simulatorSettings,
            sensitivity = True,
            sensWorksheet = sensWorksheet,
        )
        
        
        plotSensitivity(self.outputDirectory, reactionSystemIndex, reactionSystem.sensitiveSpecies, number=number, fileformat=fileformat)
Example #5
0
    def __init__(self, outputDirectory):
        super(ExecutionStatsWriter, self).__init__()
        makeOutputSubdirectory(outputDirectory, 'plot')

        # RMG execution statistics
        self.coreSpeciesCount = []
        self.coreReactionCount = []
        self.edgeSpeciesCount = []
        self.edgeReactionCount = []
        self.memoryUse = []
Example #6
0
    def __init__(self, outputDirectory):
        super(ExecutionStatsWriter, self).__init__()
        makeOutputSubdirectory(outputDirectory, 'plot')

        # RMG execution statistics
        self.coreSpeciesCount = []
        self.coreReactionCount = []
        self.edgeSpeciesCount = []
        self.edgeReactionCount = []
        self.restartSize = []
        self.memoryUse = []
Example #7
0
def simulate(rmg):
    """
    Simulate the RMG job and run the sensitivity analysis if it is on, generating
    output csv files
    """
    util.makeOutputSubdirectory(rmg.outputDirectory, 'solver')

    for index, reactionSystem in enumerate(rmg.reactionSystems):
            
        if reactionSystem.sensitiveSpecies:
            logging.info('Conducting simulation and sensitivity analysis of reaction system %s...' % (index+1))
        
        else:
            logging.info('Conducting simulation of reaction system %s...' % (index+1))
            
        if rmg.saveSimulationProfiles:
            reactionSystem.attach(SimulationProfileWriter(
                rmg.outputDirectory, index, rmg.reactionModel.core.species))   
            reactionSystem.attach(SimulationProfilePlotter(
                    rmg.outputDirectory, index, rmg.reactionModel.core.species))  
        else:
            worksheet = None
            
        sensWorksheet = []
        for spec in reactionSystem.sensitiveSpecies:
            csvfilePath = os.path.join(rmg.outputDirectory, 'solver', 'sensitivity_{0}_SPC_{1}.csv'.format(index+1, spec.index))
            sensWorksheet.append(csvfilePath)

        pdepNetworks = []
        for source, networks in rmg.reactionModel.networkDict.items():
            pdepNetworks.extend(networks)
        terminated, obj = reactionSystem.simulate(
            coreSpecies = rmg.reactionModel.core.species,
            coreReactions = rmg.reactionModel.core.reactions,
            edgeSpecies = rmg.reactionModel.edge.species,
            edgeReactions = rmg.reactionModel.edge.reactions,
            toleranceKeepInEdge = 0,
            toleranceMoveToCore = 1,
            toleranceInterruptSimulation = 1,
            pdepNetworks = pdepNetworks,
            absoluteTolerance = rmg.absoluteTolerance,
            relativeTolerance = rmg.relativeTolerance,
            sensitivity = True if reactionSystem.sensitiveSpecies else False,
            sensitivityAbsoluteTolerance = rmg.sensitivityAbsoluteTolerance,
            sensitivityRelativeTolerance = rmg.sensitivityRelativeTolerance,
            sensWorksheet = sensWorksheet,
        )
        
        if reactionSystem.sensitiveSpecies:
            plotSensitivity(rmg.outputDirectory, index, reactionSystem.sensitiveSpecies)
Example #8
0
    def sensitivityAnalysis(self, initialMoleFractions, sensitiveSpecies, T, P, terminationTime, sensitivityThreshold=1e-3, number=10, fileformat='.png'):
        """
        Run sensitivity analysis using the RMG solver in a single ReactionSystem object
        
        initialMoleFractions is a dictionary with Species objects as keys and mole fraction initial conditions
        sensitiveSpecies is a list of sensitive Species objects
        number is the number of top species thermo or reaction kinetics desired to be plotted
        """
        
        
        from rmgpy.solver import SimpleReactor, TerminationTime
        from rmgpy.quantity import Quantity
        from rmgpy.tools.sensitivity import plotSensitivity
        from rmgpy.rmg.listener import SimulationProfileWriter, SimulationProfilePlotter

        T = Quantity(T)
        P = Quantity(P)
        termination=[TerminationTime(Quantity(terminationTime))]
                                     
        reactionSystem = SimpleReactor(T, P, initialMoleFractions, termination, sensitiveSpecies, sensitivityThreshold)
        
        # Create the csv worksheets for logging sensitivity
        util.makeOutputSubdirectory(self.outputDirectory, 'solver')
        sensWorksheet = []
        reactionSystemIndex = 0
        for spec in reactionSystem.sensitiveSpecies:
            csvfilePath = os.path.join(self.outputDirectory, 'solver', 'sensitivity_{0}_SPC_{1}.csv'.format(reactionSystemIndex+1, spec.index))
            sensWorksheet.append(csvfilePath)

        reactionSystem.attach(SimulationProfileWriter(
            self.outputDirectory, reactionSystemIndex, self.speciesList))  
        reactionSystem.attach(SimulationProfilePlotter(
            self.outputDirectory, reactionSystemIndex, self.speciesList))
        
        reactionSystem.simulate(
            coreSpecies = self.speciesList,
            coreReactions = self.reactionList,
            edgeSpecies = [],
            edgeReactions = [],
            toleranceKeepInEdge = 0,
            toleranceMoveToCore = 1,
            toleranceInterruptSimulation = 1,
            sensitivity = True,
            sensWorksheet = sensWorksheet,
        )
        
        
        plotSensitivity(self.outputDirectory, reactionSystemIndex, reactionSystem.sensitiveSpecies, number=number, fileformat=fileformat)
 def __init__(self, outputDirectory=''):
     super(OutputHTMLWriter, self).__init__()
     makeOutputSubdirectory(outputDirectory, 'species')
def simulate(rmg, diffusionLimited=True):
    """
    Simulate the RMG job and run the sensitivity analysis if it is on, generating
    output csv files
    diffusionLimited=True implies that if it is a liquid reactor diffusion limitations will be enforced
    otherwise they will not be in a liquid reactor
    """
    util.makeOutputSubdirectory(rmg.outputDirectory, 'solver')

    for index, reactionSystem in enumerate(rmg.reactionSystems):

        if reactionSystem.sensitiveSpecies:
            logging.info(
                'Conducting simulation and sensitivity analysis of reaction system %s...'
                % (index + 1))

        else:
            logging.info('Conducting simulation of reaction system %s...' %
                         (index + 1))

        if rmg.saveSimulationProfiles:
            reactionSystem.attach(
                SimulationProfileWriter(rmg.outputDirectory, index,
                                        rmg.reactionModel.core.species))
            reactionSystem.attach(
                SimulationProfilePlotter(rmg.outputDirectory, index,
                                         rmg.reactionModel.core.species))

        sensWorksheet = []
        for spec in reactionSystem.sensitiveSpecies:
            csvfilePath = os.path.join(
                rmg.outputDirectory, 'solver',
                'sensitivity_{0}_SPC_{1}.csv'.format(index + 1, spec.index))
            sensWorksheet.append(csvfilePath)

        pdepNetworks = []
        for source, networks in rmg.reactionModel.networkDict.items():
            pdepNetworks.extend(networks)

        modelSettings = ModelSettings(toleranceKeepInEdge=0,
                                      toleranceMoveToCore=1,
                                      toleranceInterruptSimulation=1)
        simulatorSettings = rmg.simulatorSettingsList[-1]

        if isinstance(reactionSystem, LiquidReactor):
            if diffusionLimited:
                rmg.loadDatabase()
                solventData = rmg.database.solvation.getSolventData(
                    rmg.solvent)
                diffusionLimiter.enable(solventData, rmg.database.solvation)

            # Store constant species indices
            if reactionSystem.constSPCNames is not None:
                reactionSystem.get_constSPCIndices(
                    rmg.reactionModel.core.species)

        reactionSystem.simulate(
            coreSpecies=rmg.reactionModel.core.species,
            coreReactions=rmg.reactionModel.core.reactions,
            edgeSpecies=rmg.reactionModel.edge.species,
            edgeReactions=rmg.reactionModel.edge.reactions,
            surfaceSpecies=[],
            surfaceReactions=[],
            pdepNetworks=pdepNetworks,
            sensitivity=True if reactionSystem.sensitiveSpecies else False,
            sensWorksheet=sensWorksheet,
            modelSettings=modelSettings,
            simulatorSettings=simulatorSettings,
        )

        if reactionSystem.sensitiveSpecies:
            plotSensitivity(rmg.outputDirectory, index,
                            reactionSystem.sensitiveSpecies)
Example #11
0
def simulate(rmg, diffusionLimited=True):
    """
    Simulate the RMG job and run the sensitivity analysis if it is on, generating
    output csv files
    diffusionLimited=True implies that if it is a liquid reactor diffusion limitations will be enforced
    otherwise they will not be in a liquid reactor
    """
    util.makeOutputSubdirectory(rmg.outputDirectory, 'solver')

    for index, reactionSystem in enumerate(rmg.reactionSystems):
            
        if reactionSystem.sensitiveSpecies:
            logging.info('Conducting simulation and sensitivity analysis of reaction system %s...' % (index+1))
        
        else:
            logging.info('Conducting simulation of reaction system %s...' % (index+1))
            
        if rmg.saveSimulationProfiles:
            reactionSystem.attach(SimulationProfileWriter(
                rmg.outputDirectory, index, rmg.reactionModel.core.species))   
            reactionSystem.attach(SimulationProfilePlotter(
                    rmg.outputDirectory, index, rmg.reactionModel.core.species))
            
        sensWorksheet = []
        for spec in reactionSystem.sensitiveSpecies:
            csvfilePath = os.path.join(rmg.outputDirectory, 'solver', 'sensitivity_{0}_SPC_{1}.csv'.format(index+1, spec.index))
            sensWorksheet.append(csvfilePath)

        pdepNetworks = []
        for source, networks in rmg.reactionModel.networkDict.items():
            pdepNetworks.extend(networks)
        
        modelSettings = ModelSettings(toleranceKeepInEdge=0, toleranceMoveToCore=1, toleranceInterruptSimulation=1)
        simulatorSettings = rmg.simulatorSettingsList[-1]

        if isinstance(reactionSystem, LiquidReactor):
            if diffusionLimited:
                rmg.loadDatabase()
                solventData = rmg.database.solvation.getSolventData(rmg.solvent)
                diffusionLimiter.enable(solventData, rmg.database.solvation)

            # Store constant species indices
            if reactionSystem.constSPCNames is not None:
                reactionSystem.get_constSPCIndices(rmg.reactionModel.core.species)
        
        reactionSystem.simulate(
            coreSpecies=rmg.reactionModel.core.species,
            coreReactions=rmg.reactionModel.core.reactions,
            edgeSpecies=rmg.reactionModel.edge.species,
            edgeReactions=rmg.reactionModel.edge.reactions,
            surfaceSpecies=[],
            surfaceReactions=[],
            pdepNetworks=pdepNetworks,
            sensitivity=True if reactionSystem.sensitiveSpecies else False,
            sensWorksheet=sensWorksheet,
            modelSettings=modelSettings,
            simulatorSettings=simulatorSettings,
        )
        
        if reactionSystem.sensitiveSpecies:
            plotSensitivity(rmg.outputDirectory, index, reactionSystem.sensitiveSpecies)
Example #12
0
 def __init__(self, outputDirectory=''):
     super(RMSWriter, self).__init__()
     self.outputDirectory = outputDirectory
     makeOutputSubdirectory(outputDirectory, 'rms')