Exemplo n.º 1
0
                        nargs=1,
                        help='The path of the RMG dictionary file')
    parser.add_argument('outputPath',
                        metavar='OUTPUT',
                        type=str,
                        nargs=1,
                        help='The path where the output will be saved')

    args = parser.parse_args()
    inputPath = args.inputPath[0]
    dictionaryPath = args.dictionaryPath[0]
    outputPath = args.outputPath[0]

    # Read RMG input file
    rmg = RMG()
    readInputFile(inputPath, rmg)
    # Read species dictionary
    speciesDict = loadSpeciesDictionary(dictionaryPath)

    addedMoleFractions = {}
    for key, spec in speciesDict.items():
        for existing in rmg.initialSpecies:
            if spec.isIsomorphic(existing):
                break
        else:
            rmg.initialSpecies.append(spec)
            addedMoleFractions[spec] = 0

    for system in rmg.reactionSystems:
        system.initialMoleFractions.update(addedMoleFractions)
Exemplo n.º 2
0
    def loadForm(self, path):
        """
        Load input.py file onto form initial data.
        """
        readInputFile(path, self.rmg)

        # Databases
        initial_thermo_libraries = []
        if self.rmg.thermoLibraries:
            for item in self.rmg.thermoLibraries:
                initial_thermo_libraries.append({'thermolib': item})

        initial_reaction_libraries = []
        if self.rmg.seedMechanisms:
            for item in self.rmg.seedMechanisms:
                initial_reaction_libraries.append({
                    'reactionlib': item,
                    'seedmech': True,
                    'edge': False
                })
        if self.rmg.reactionLibraries:
            for item, edge in self.rmg.reactionLibraries:
                initial_reaction_libraries.append({
                    'reactionlib': item,
                    'seedmech': False,
                    'edge': edge
                })

        # Reactor systems
        initial_reactor_systems = []
        for system in self.rmg.reactionSystems:
            temperature = system.T.getValue()
            temperature_units = system.T.units
            pressure = system.P.getValue()
            pressure_units = system.P.units
            initialMoleFractions = system.initialMoleFractions
            for item in system.termination:
                if isinstance(item, TerminationTime):
                    terminationtime = item.time.getValue()
                    time_units = item.time.units
                else:
                    species = item.species.label
                    conversion = item.conversion
            # Sensitivity
            if system.sensitiveSpecies:
                sensitivity = []
                for item in system.sensitiveSpecies:
                    sensitivity.append(item.label)
                sensitivity = ','.join(sensitivity)
                sensitivityThreshold = system.sensitivityThreshold
            else:
                sensitivity = ''
                sensitivityThreshold = 0.001
            initial_reactor_systems.append({
                'temperature':
                temperature,
                'temperature_units':
                temperature_units,
                'pressure':
                pressure,
                'pressure_units':
                pressure_units,
                'terminationtime':
                terminationtime,
                'time_units':
                time_units,
                'species':
                species,
                'conversion':
                conversion,
                'sensitivity':
                sensitivity,
                'sensitivityThreshold':
                sensitivityThreshold
            })

        # Species
        initial_species = []
        for item in self.rmg.initialSpecies:
            name = item.label
            adjlist = item.molecule[0].toAdjacencyList()
            inert = False if item.reactive else True
            spec, isNew = self.rmg.reactionModel.makeNewSpecies(
                item.molecule[0], label=item.label, reactive=item.reactive)
            molefrac = initialMoleFractions[spec]
            initial_species.append({
                'name': name,
                'adjlist': adjlist,
                'inert': inert,
                'molefrac': molefrac
            })

        # Tolerances
        initial = {}
        initial['simulator_atol'] = self.rmg.absoluteTolerance
        initial['simulator_rtol'] = self.rmg.relativeTolerance
        initial['simulator_sens_atol'] = self.rmg.sensitivityAbsoluteTolerance
        initial['simulator_sens_rtol'] = self.rmg.sensitivityRelativeTolerance
        initial['toleranceKeepInEdge'] = self.rmg.fluxToleranceKeepInEdge
        initial['toleranceMoveToCore'] = self.rmg.fluxToleranceMoveToCore
        initial[
            'toleranceInterruptSimulation'] = self.rmg.fluxToleranceInterrupt
        initial['maximumEdgeSpecies'] = self.rmg.maximumEdgeSpecies
        initial['minCoreSizeForPrune'] = self.rmg.minCoreSizeForPrune
        initial[
            'minSpeciesExistIterationsForPrune'] = self.rmg.minSpeciesExistIterationsForPrune
        initial['filterReactions'] = self.rmg.filterReactions

        # Pressure Dependence
        if self.rmg.pressureDependence:
            # Pressure dependence method
            initial['pdep'] = self.rmg.pressureDependence.method.lower()
            # Process interpolation model
            initial[
                'interpolation'] = self.rmg.pressureDependence.interpolationModel[
                    0].lower()
            if initial['interpolation'] == 'chebyshev':
                initial[
                    'temp_basis'] = self.rmg.pressureDependence.interpolationModel[
                        1]
                initial[
                    'p_basis'] = self.rmg.pressureDependence.interpolationModel[
                        2]
            # Temperature and pressure ranges
            initial['temp_low'] = self.rmg.pressureDependence.Tmin.getValue()
            initial['temp_high'] = self.rmg.pressureDependence.Tmax.getValue()
            initial['temprange_units'] = self.rmg.pressureDependence.Tmax.units
            initial['temp_interp'] = self.rmg.pressureDependence.Tcount
            initial['p_low'] = self.rmg.pressureDependence.Pmin.getValue()
            initial['p_high'] = self.rmg.pressureDependence.Pmax.getValue()
            initial['prange_units'] = self.rmg.pressureDependence.Pmax.units
            initial['p_interp'] = self.rmg.pressureDependence.Pcount
            # Process grain size and count
            initial[
                'maximumGrainSize'] = self.rmg.pressureDependence.maximumGrainSize.getValue(
                )
            initial[
                'grainsize_units'] = self.rmg.pressureDependence.maximumGrainSize.units
            initial[
                'minimumNumberOfGrains'] = self.rmg.pressureDependence.minimumGrainCount

            initial['maximumAtoms'] = self.rmg.pressureDependence.maximumAtoms
        else:
            initial['pdep'] = 'off'

        # Species Constraints
        if self.rmg.speciesConstraints:
            initial['speciesConstraints'] = 'on'
            for key, value in self.rmg.speciesConstraints.items():
                if key == 'allowed':
                    allowed_dict = {
                        'input species': 'allowed_inputSpecies',
                        'reaction libraries': 'allowed_reactionLibraries',
                        'seed mechanisms': 'allowed_seedMechanisms'
                    }
                    if isinstance(value, list):
                        for allowed_name in value:
                            field = allowed_dict[allowed_name.lower()]
                            initial[field] = True
                    else:
                        raise Exception(
                            "Input File generatedSpeciesConstraints(allowed='[..]'), allowed block must be a list containing either 'reaction libraries', 'seed mechanisms', or 'input species'."
                        )
                else:
                    initial[key] = value
        else:
            initial['speciesConstraints'] = 'off'

        # Quantum Calculations
        if self.rmg.quantumMechanics:
            initial['quantumCalc'] = 'on'
            initial['software'] = self.rmg.quantumMechanics.settings.software
            initial['method'] = self.rmg.quantumMechanics.settings.method
            if self.rmg.quantumMechanics.settings.fileStore:
                initial['fileStore'] = os.path.split(
                    self.rmg.quantumMechanics.settings.fileStore)[0]
            else:
                initial['fileStore'] = ''
            if self.rmg.quantumMechanics.settings.scratchDirectory:
                initial['scratchDirectory'] = os.path.split(
                    self.rmg.quantumMechanics.settings.scratchDirectory)[0]
            else:
                initial['scratchDirectory'] = ''
            initial[
                'onlyCyclics'] = self.rmg.quantumMechanics.settings.onlyCyclics
            initial[
                'maxRadicalNumber'] = self.rmg.quantumMechanics.settings.maxRadicalNumber
        else:
            initial['quantumCalc'] = 'off'

        # Additional Options
        if self.rmg.saveRestartPeriod:
            initial['saveRestartPeriod'] = self.rmg.saveRestartPeriod.getValue(
            )
            initial[
                'saveRestartPeriodUnits'] = self.rmg.saveRestartPeriod.units
        if self.rmg.generateOutputHTML:
            initial['generateOutputHTML'] = True
        if self.rmg.generatePlots:
            initial['generatePlots'] = True
        if self.rmg.saveSimulationProfiles:
            initial['saveSimulationProfiles'] = True
        if self.rmg.saveEdgeSpecies:
            initial['saveEdgeSpecies'] = True
        if self.rmg.verboseComments:
            initial['verboseComments'] = True

        return initial_thermo_libraries, initial_reaction_libraries, initial_reactor_systems, initial_species, initial
Exemplo n.º 3
0
    def loadForm(self, path):
        """
        Load input.py file onto form initial data.
        """        
        readInputFile(path, self.rmg)
        
        # Databases
        initial_thermo_libraries = []
        if self.rmg.thermoLibraries:
            for item in self.rmg.thermoLibraries:
                initial_thermo_libraries.append({'thermolib': item})
        
        initial_reaction_libraries = []
        if self.rmg.seedMechanisms:
            for item in self.rmg.seedMechanism:
                initial_reaction_libraries.append({'reactionlib': item, 'seedmech': True, 'edge': False})
        if self.rmg.reactionLibraries:
            for item, edge in self.rmg.reactionLibraries:
                initial_reaction_libraries.append({'reactionlib': item, 'seedmech': False, 'edge': edge})
        
        # Reactor systems
        initial_reactor_systems = []
        for system in self.rmg.reactionSystems:
            temperature = system.T.getValue()
            temperature_units = system.T.units
            pressure = system.P.getValue()
            pressure_units = system.P.units
            initialMoleFractions = system.initialMoleFractions
            for item in system.termination:
                if isinstance(item, TerminationTime):
                    terminationtime = item.time.getValue()
                    time_units = item.time.units
                else:
                    species = item.species.label
                    conversion = item.conversion
            initial_reactor_systems.append({'temperature': temperature, 'temperature_units': temperature_units,
                                            'pressure': pressure, 'pressure_units': pressure_units,
                                            'terminationtime': terminationtime, 'time_units': time_units,
                                            'species': species, 'conversion': conversion})       
        
        # Species
        initial_species = []
        for item in self.rmg.initialSpecies:
            name = item.label
            adjlist = item.molecule[0].toAdjacencyList()
            inert = False if item.reactive else True
            spec, isNew = self.rmg.reactionModel.makeNewSpecies(item.molecule[0], label = item.label, reactive = item.reactive)
            molefrac = initialMoleFractions[spec]
            initial_species.append({'name': name, 'adjlist': adjlist, 
                                    'inert': inert, 'molefrac': molefrac})
            
        # Tolerances
        initial = {}
        initial['simulator_atol'] = self.rmg.absoluteTolerance 
        initial['simulator_rtol'] = self.rmg.relativeTolerance 
        initial['toleranceKeepInEdge'] = self.rmg.fluxToleranceKeepInEdge 
        initial['toleranceMoveToCore']= self.rmg.fluxToleranceMoveToCore
        initial['toleranceInterruptSimulation'] = self.rmg.fluxToleranceInterrupt
        initial['maximumEdgeSpecies'] = self.rmg.maximumEdgeSpecies 
                
        # Pressure Dependence
        if self.rmg.pressureDependence:
            initial['interpolation'] = self.rmg.pressureDependence.model[0]
            initial['temp_basis'] = self.rmg.pressureDependence.model[1]
            initial['p_basis'] = self.rmg.pressureDependence.model[2]
            initial['temp_low'] = self.rmg.pressureDependence.Tmin.getValue()
            initial['temp_high'] = self.rmg.pressureDependence.Tmax.getValue()
            initial['temprange_units'] = self.rmg.pressureDependence.Tmax.units
            initial['temp_interp'] = self.rmg.pressureDependence.Tcount
            initial['p_low'] = self.rmg.pressureDependence.Pmin.getValue()
            initial['p_high'] = self.rmg.pressureDependence.Pmax.getValue()
            initial['prange_units'] = self.rmg.pressureDependence.Pmax.units
            initial['p_interp'] = self.rmg.pressureDepence.Pcount
            
            initial['maximumGrainSize'] = self.rmg.pressureDependence.grainSize.getValue()
            initial['grainsize_units'] = self.rmg.pressureDependence.grainSize.units
            initial['minimumNumberOfGrains'] = self.rmg.pressureDependence.grainCount

        else:
            initial['pdep'] = 'off'    
            
        # Additional Options
        if self.rmg.saveRestartPeriod:
            initial['saveRestartPeriod'] = self.rmg.saveRestartPeriod.getValue()
            initial['saveRestartPeriodUnits'] = self.rmg.saveRestartPeriod.units
        if self.rmg.drawMolecules:
            initial['drawMolecules'] = True
        if self.rmg.generatePlots:
            initial['generatePlots'] = True
        if self.rmg.saveSimulationProfiles:
            initial['saveSimulationProfiles'] = True       
            
        return initial_thermo_libraries, initial_reaction_libraries, initial_reactor_systems, initial_species, initial
Exemplo n.º 4
0
    def loadForm(self, path):
        """
        Load input.py file onto form initial data.
        """
        readInputFile(path, self.rmg)

        # Databases
        initial_thermo_libraries = []
        if self.rmg.thermoLibraries:
            for item in self.rmg.thermoLibraries:
                initial_thermo_libraries.append({'thermolib': item})

        initial_reaction_libraries = []
        if self.rmg.seedMechanisms:
            for item in self.rmg.seedMechanism:
                initial_reaction_libraries.append({
                    'reactionlib': item,
                    'seedmech': True,
                    'edge': False
                })
        if self.rmg.reactionLibraries:
            for item, edge in self.rmg.reactionLibraries:
                initial_reaction_libraries.append({
                    'reactionlib': item,
                    'seedmech': False,
                    'edge': edge
                })

        # Reactor systems
        initial_reactor_systems = []
        for system in self.rmg.reactionSystems:
            temperature = system.T.getValueInGivenUnits()
            temperature_units = system.T.units
            pressure = system.P.getValueInGivenUnits()
            pressure_units = system.P.units
            initialMoleFractions = system.initialMoleFractions
            for item in system.termination:
                if isinstance(item, TerminationTime):
                    terminationtime = item.time.getValueInGivenUnits()
                    time_units = item.time.units
                else:
                    species = item.species.label
                    conversion = item.conversion
            initial_reactor_systems.append({
                'temperature': temperature,
                'temperature_units': temperature_units,
                'pressure': pressure,
                'pressure_units': pressure_units,
                'terminationtime': terminationtime,
                'time_units': time_units,
                'species': species,
                'conversion': conversion
            })

        # Species
        initial_species = []
        for item in self.rmg.initialSpecies:
            name = item.label
            adjlist = item.molecule[0].toAdjacencyList()
            inert = False if item.reactive else True
            spec, isNew = self.rmg.reactionModel.makeNewSpecies(
                item.molecule[0], label=item.label, reactive=item.reactive)
            molefrac = initialMoleFractions[spec]
            initial_species.append({
                'name': name,
                'adjlist': adjlist,
                'inert': inert,
                'molefrac': molefrac
            })

        # Tolerances
        initial = {}
        initial['simulator_atol'] = self.rmg.absoluteTolerance
        initial['simulator_rtol'] = self.rmg.relativeTolerance
        initial['toleranceKeepInEdge'] = self.rmg.fluxToleranceKeepInEdge
        initial['toleranceMoveToCore'] = self.rmg.fluxToleranceMoveToCore
        initial[
            'toleranceInterruptSimulation'] = self.rmg.fluxToleranceInterrupt
        initial['maximumEdgeSpecies'] = self.rmg.maximumEdgeSpecies

        # Pressure Dependence
        if self.rmg.pressureDependence:
            initial['interpolation'] = self.rmg.pressureDependence.model[0]
            initial['temp_basis'] = self.rmg.pressureDependence.model[1]
            initial['p_basis'] = self.rmg.pressureDependence.model[2]
            initial[
                'temp_low'] = self.rmg.pressureDependence.Tmin.getValueInGivenUnits(
                )
            initial[
                'temp_high'] = self.rmg.pressureDependence.Tmax.getValueInGivenUnits(
                )
            initial['temprange_units'] = self.rmg.pressureDependence.Tmax.units
            initial['temp_interp'] = self.rmg.pressureDependence.Tcount
            initial[
                'p_low'] = self.rmg.pressureDependence.Pmin.getValueInGivenUnits(
                )
            initial[
                'p_high'] = self.rmg.pressureDependence.Pmax.getValueInGivenUnits(
                )
            initial['prange_units'] = self.rmg.pressureDependence.Pmax.units
            initial['p_interp'] = self.rmg.pressureDepence.Pcount

            initial[
                'maximumGrainSize'] = self.rmg.pressureDependence.grainSize.getValueInGivenUnits(
                )
            initial[
                'grainsize_units'] = self.rmg.pressureDependence.grainSize.units
            initial[
                'minimumNumberOfGrains'] = self.rmg.pressureDependence.grainCount

        else:
            initial['pdep'] = 'off'

        # Additional Options
        if self.rmg.saveRestartPeriod:
            initial[
                'saveRestartPeriod'] = self.rmg.saveRestartPeriod.getValueInGivenUnits(
                )
            initial[
                'saveRestartPeriodUnits'] = self.rmg.saveConcentrationProfiles.units
        if self.rmg.drawMolecules:
            initial['drawMolecules'] = True
        if self.rmg.generatePlots:
            initial['generatePlots'] = True
        if self.rmg.saveConcentrationProfiles:
            initial['saveConcentrationProfiles'] = True

        return initial_thermo_libraries, initial_reaction_libraries, initial_reactor_systems, initial_species, initial
Exemplo n.º 5
0
    def loadForm(self, path):
        """
        Load input.py file onto form initial data.
        """
        readInputFile(path, self.rmg)

        # Databases
        initial_thermo_libraries = []
        if self.rmg.thermoLibraries:
            for item in self.rmg.thermoLibraries:
                initial_thermo_libraries.append({"thermolib": item})

        initial_reaction_libraries = []
        if self.rmg.seedMechanisms:
            for item in self.rmg.seedMechanisms:
                initial_reaction_libraries.append({"reactionlib": item, "seedmech": True, "edge": False})
        if self.rmg.reactionLibraries:
            for item, edge in self.rmg.reactionLibraries:
                initial_reaction_libraries.append({"reactionlib": item, "seedmech": False, "edge": edge})

        # Reactor systems
        initial_reactor_systems = []
        for system in self.rmg.reactionSystems:
            temperature = system.T.getValue()
            temperature_units = system.T.units
            pressure = system.P.getValue()
            pressure_units = system.P.units
            initialMoleFractions = system.initialMoleFractions
            for item in system.termination:
                if isinstance(item, TerminationTime):
                    terminationtime = item.time.getValue()
                    time_units = item.time.units
                else:
                    species = item.species.label
                    conversion = item.conversion
            # Sensitivity
            if system.sensitiveSpecies:
                sensitivity = []
                for item in system.sensitiveSpecies:
                    sensitivity.append(item.label)
                sensitivity = ",".join(sensitivity)
                sensitivityThreshold = system.sensitivityThreshold
            else:
                sensitivity = ""
                sensitivityThreshold = 0.001
            initial_reactor_systems.append(
                {
                    "temperature": temperature,
                    "temperature_units": temperature_units,
                    "pressure": pressure,
                    "pressure_units": pressure_units,
                    "terminationtime": terminationtime,
                    "time_units": time_units,
                    "species": species,
                    "conversion": conversion,
                    "sensitivity": sensitivity,
                    "sensitivityThreshold": sensitivityThreshold,
                }
            )

        # Species
        initial_species = []
        for item in self.rmg.initialSpecies:
            name = item.label
            adjlist = item.molecule[0].toAdjacencyList()
            inert = False if item.reactive else True
            spec, isNew = self.rmg.reactionModel.makeNewSpecies(
                item.molecule[0], label=item.label, reactive=item.reactive
            )
            molefrac = initialMoleFractions[spec]
            initial_species.append({"name": name, "adjlist": adjlist, "inert": inert, "molefrac": molefrac})

        # Tolerances
        initial = {}
        initial["simulator_atol"] = self.rmg.absoluteTolerance
        initial["simulator_rtol"] = self.rmg.relativeTolerance
        initial["simulator_sens_atol"] = self.rmg.sensitivityAbsoluteTolerance
        initial["simulator_sens_rtol"] = self.rmg.sensitivityRelativeTolerance
        initial["toleranceKeepInEdge"] = self.rmg.fluxToleranceKeepInEdge
        initial["toleranceMoveToCore"] = self.rmg.fluxToleranceMoveToCore
        initial["toleranceInterruptSimulation"] = self.rmg.fluxToleranceInterrupt
        initial["maximumEdgeSpecies"] = self.rmg.maximumEdgeSpecies

        # Pressure Dependence
        if self.rmg.pressureDependence:
            # Pressure dependence method
            initial["pdep"] = self.rmg.pressureDependence.method.lower()
            # Process interpolation model
            initial["interpolation"] = self.rmg.pressureDependence.interpolationModel[0].lower()
            if initial["interpolation"] == "chebyshev":
                initial["temp_basis"] = self.rmg.pressureDependence.interpolationModel[1]
                initial["p_basis"] = self.rmg.pressureDependence.interpolationModel[2]
            # Temperature and pressure ranges
            initial["temp_low"] = self.rmg.pressureDependence.Tmin.getValue()
            initial["temp_high"] = self.rmg.pressureDependence.Tmax.getValue()
            initial["temprange_units"] = self.rmg.pressureDependence.Tmax.units
            initial["temp_interp"] = self.rmg.pressureDependence.Tcount
            initial["p_low"] = self.rmg.pressureDependence.Pmin.getValue()
            initial["p_high"] = self.rmg.pressureDependence.Pmax.getValue()
            initial["prange_units"] = self.rmg.pressureDependence.Pmax.units
            initial["p_interp"] = self.rmg.pressureDependence.Pcount
            # Process grain size and count
            initial["maximumGrainSize"] = self.rmg.pressureDependence.maximumGrainSize.getValue()
            initial["grainsize_units"] = self.rmg.pressureDependence.maximumGrainSize.units
            initial["minimumNumberOfGrains"] = self.rmg.pressureDependence.minimumGrainCount

            initial["maximumAtoms"] = self.rmg.pressureDependence.maximumAtoms
        else:
            initial["pdep"] = "off"

        # Species Constraints
        if self.rmg.speciesConstraints:
            initial["speciesConstraints"] = "on"
            for key, value in self.rmg.speciesConstraints.items():
                if key == "allowed":
                    allowed_dict = {
                        "input species": "allowed_inputSpecies",
                        "reaction libraries": "allowed_reactionLibraries",
                        "seed mechanisms": "allowed_seedMechanisms",
                    }
                    if isinstance(value, list):
                        for allowed_name in value:
                            field = allowed_dict[allowed_name.lower()]
                            initial[field] = True
                    else:
                        raise Exception(
                            "Input File generatedSpeciesConstraints(allowed='[..]'), allowed block must be a list containing either 'reaction libraries', 'seed mechanisms', or 'input species'."
                        )
                else:
                    initial[key] = value
        else:
            initial["speciesConstraints"] = "off"

        # Quantum Calculations
        if self.rmg.quantumMechanics:
            initial["quantumCalc"] = "on"
            initial["software"] = self.rmg.quantumMechanics.settings.software
            initial["method"] = self.rmg.quantumMechanics.settings.method
            if self.rmg.quantumMechanics.settings.fileStore:
                initial["fileStore"] = os.path.split(self.rmg.quantumMechanics.settings.fileStore)[0]
            else:
                initial["fileStore"] = ""
            if self.rmg.quantumMechanics.settings.scratchDirectory:
                initial["scratchDirectory"] = os.path.split(self.rmg.quantumMechanics.settings.scratchDirectory)[0]
            else:
                initial["scratchDirectory"] = ""
            initial["onlyCyclics"] = self.rmg.quantumMechanics.settings.onlyCyclics
            initial["maxRadicalNumber"] = self.rmg.quantumMechanics.settings.maxRadicalNumber
        else:
            initial["quantumCalc"] = "off"

        # Additional Options
        if self.rmg.saveRestartPeriod:
            initial["saveRestartPeriod"] = self.rmg.saveRestartPeriod.getValue()
            initial["saveRestartPeriodUnits"] = self.rmg.saveRestartPeriod.units
        if self.rmg.generateOutputHTML:
            initial["generateOutputHTML"] = True
        if self.rmg.generatePlots:
            initial["generatePlots"] = True
        if self.rmg.saveSimulationProfiles:
            initial["saveSimulationProfiles"] = True
        if self.rmg.saveEdgeSpecies:
            initial["saveEdgeSpecies"] = True
        if self.rmg.verboseComments:
            initial["verboseComments"] = True

        return initial_thermo_libraries, initial_reaction_libraries, initial_reactor_systems, initial_species, initial
Exemplo n.º 6
0
 def loadForm(self, path):
     """
     Load input.py file onto form initial data.
     """        
     readInputFile(path, self.rmg)
     
     # Databases
     initial_thermo_libraries = []
     if self.rmg.thermoLibraries:
         for item in self.rmg.thermoLibraries:
             initial_thermo_libraries.append({'thermolib': item})
     
     initial_reaction_libraries = []
     if self.rmg.seedMechanisms:
         for item in self.rmg.seedMechanisms:
             initial_reaction_libraries.append({'reactionlib': item, 'seedmech': True, 'edge': False})
     if self.rmg.reactionLibraries:
         for item, edge in self.rmg.reactionLibraries:
             initial_reaction_libraries.append({'reactionlib': item, 'seedmech': False, 'edge': edge})
     
     # Reactor systems
     initial_reactor_systems = []
     for system in self.rmg.reactionSystems:
         temperature = system.T.getValue()
         temperature_units = system.T.units
         pressure = system.P.getValue()
         pressure_units = system.P.units
         initialMoleFractions = system.initialMoleFractions
         for item in system.termination:
             if isinstance(item, TerminationTime):
                 terminationtime = item.time.getValue()
                 time_units = item.time.units
             else:
                 species = item.species.label
                 conversion = item.conversion
         # Sensitivity
         if system.sensitiveSpecies:
             sensitivity = []
             for item in system.sensitiveSpecies:
                 sensitivity.append(item.label)
             sensitivity = ','.join(sensitivity)
             sensitivityThreshold = system.sensitivityThreshold
         else:
             sensitivity = ''
             sensitivityThreshold = 0.001
         initial_reactor_systems.append({'temperature': temperature, 'temperature_units': temperature_units,
                                         'pressure': pressure, 'pressure_units': pressure_units,
                                         'terminationtime': terminationtime, 'time_units': time_units,
                                         'species': species, 'conversion': conversion,
                                         'sensitivity': sensitivity, 'sensitivityThreshold': sensitivityThreshold})
     
     # Species
     initial_species = []
     for item in self.rmg.initialSpecies:
         name = item.label
         adjlist = item.molecule[0].toAdjacencyList()
         inert = False if item.reactive else True
         spec, isNew = self.rmg.reactionModel.makeNewSpecies(item.molecule[0], label = item.label, reactive = item.reactive)
         molefrac = initialMoleFractions[spec]
         initial_species.append({'name': name, 'adjlist': adjlist, 
                                 'inert': inert, 'molefrac': molefrac})
         
     # Tolerances
     initial = {}
     initial['simulator_atol'] = self.rmg.absoluteTolerance 
     initial['simulator_rtol'] = self.rmg.relativeTolerance 
     initial['simulator_sens_atol'] = self.rmg.sensitivityAbsoluteTolerance 
     initial['simulator_sens_rtol'] = self.rmg.sensitivityRelativeTolerance 
     initial['toleranceKeepInEdge'] = self.rmg.fluxToleranceKeepInEdge 
     initial['toleranceMoveToCore']= self.rmg.fluxToleranceMoveToCore
     initial['toleranceInterruptSimulation'] = self.rmg.fluxToleranceInterrupt
     initial['maximumEdgeSpecies'] = self.rmg.maximumEdgeSpecies 
     initial['minCoreSizeForPrune'] = self.rmg.minCoreSizeForPrune
     initial['minSpeciesExistIterationsForPrune'] = self.rmg.minSpeciesExistIterationsForPrune
             
     # Pressure Dependence
     if self.rmg.pressureDependence:
         # Pressure dependence method
         initial['pdep'] = self.rmg.pressureDependence.method.lower()
         # Process interpolation model
         initial['interpolation'] = self.rmg.pressureDependence.interpolationModel[0].lower()
         if initial['interpolation'] == 'chebyshev':
             initial['temp_basis'] = self.rmg.pressureDependence.interpolationModel[1]
             initial['p_basis'] = self.rmg.pressureDependence.interpolationModel[2]
         # Temperature and pressure ranges
         initial['temp_low'] = self.rmg.pressureDependence.Tmin.getValue()
         initial['temp_high'] = self.rmg.pressureDependence.Tmax.getValue()
         initial['temprange_units'] = self.rmg.pressureDependence.Tmax.units
         initial['temp_interp'] = self.rmg.pressureDependence.Tcount
         initial['p_low'] = self.rmg.pressureDependence.Pmin.getValue()
         initial['p_high'] = self.rmg.pressureDependence.Pmax.getValue()
         initial['prange_units'] = self.rmg.pressureDependence.Pmax.units
         initial['p_interp'] = self.rmg.pressureDependence.Pcount
         # Process grain size and count
         initial['maximumGrainSize'] = self.rmg.pressureDependence.maximumGrainSize.getValue()
         initial['grainsize_units'] = self.rmg.pressureDependence.maximumGrainSize.units
         initial['minimumNumberOfGrains'] = self.rmg.pressureDependence.minimumGrainCount
         
         initial['maximumAtoms'] = self.rmg.pressureDependence.maximumAtoms
     else:
         initial['pdep'] = 'off'    
         
     # Species Constraints
     if self.rmg.speciesConstraints:
         initial['speciesConstraints'] = 'on'
         for key, value in self.rmg.speciesConstraints.items():
             if key == 'allowed':
                 allowed_dict = {'input species':'allowed_inputSpecies', 'reaction libraries':'allowed_reactionLibraries', 'seed mechanisms':'allowed_seedMechanisms'}
                 if isinstance(value,list):
                     for allowed_name in value:
                         field = allowed_dict[allowed_name.lower()]
                         initial[field] = True
                 else:
                     raise Exception("Input File generatedSpeciesConstraints(allowed='[..]'), allowed block must be a list containing either 'reaction libraries', 'seed mechanisms', or 'input species'." )
             else:
                 initial[key] = value
     else:
         initial['speciesConstraints'] = 'off'
     
     # Quantum Calculations
     if self.rmg.quantumMechanics:
         initial['quantumCalc'] = 'on'
         initial['software'] = self.rmg.quantumMechanics.settings.software
         initial['method'] = self.rmg.quantumMechanics.settings.method
         if self.rmg.quantumMechanics.settings.fileStore:
             initial['fileStore'] = os.path.split(self.rmg.quantumMechanics.settings.fileStore)[0]
         else:
             initial['fileStore'] = ''
         if self.rmg.quantumMechanics.settings.scratchDirectory:
             initial['scratchDirectory'] = os.path.split(self.rmg.quantumMechanics.settings.scratchDirectory)[0]
         else:
             initial['scratchDirectory'] = ''
         initial['onlyCyclics'] = self.rmg.quantumMechanics.settings.onlyCyclics
         initial['maxRadicalNumber'] = self.rmg.quantumMechanics.settings.maxRadicalNumber
     else:
         initial['quantumCalc'] = 'off'
     
     # Additional Options
     if self.rmg.saveRestartPeriod:
         initial['saveRestartPeriod'] = self.rmg.saveRestartPeriod.getValue()
         initial['saveRestartPeriodUnits'] = self.rmg.saveRestartPeriod.units
     if self.rmg.generateOutputHTML:
         initial['generateOutputHTML'] = True
     if self.rmg.generatePlots:
         initial['generatePlots'] = True
     if self.rmg.saveSimulationProfiles:
         initial['saveSimulationProfiles'] = True
     if self.rmg.saveEdgeSpecies:
         initial['saveEdgeSpecies'] = True
     if self.rmg.verboseComments:
         initial['verboseComments'] = True
         
     return initial_thermo_libraries, initial_reaction_libraries, initial_reactor_systems, initial_species, initial
Exemplo n.º 7
0
    def loadForm(self, path):
        """
        Load input.py file onto form initial data.
        """
        readInputFile(path, self.rmg)

        # Databases
        initial_thermo_libraries = []
        if self.rmg.thermoLibraries:
            for item in self.rmg.thermoLibraries:
                initial_thermo_libraries.append({"thermolib": item})

        initial_reaction_libraries = []
        if self.rmg.seedMechanisms:
            for item in self.rmg.seedMechanism:
                initial_reaction_libraries.append({"reactionlib": item, "seedmech": True, "edge": False})
        if self.rmg.reactionLibraries:
            for item, edge in self.rmg.reactionLibraries:
                initial_reaction_libraries.append({"reactionlib": item, "seedmech": False, "edge": edge})

        # Reactor systems
        initial_reactor_systems = []
        for system in self.rmg.reactionSystems:
            temperature = system.T.getValueInGivenUnits()
            temperature_units = system.T.units
            pressure = system.P.getValueInGivenUnits()
            pressure_units = system.P.units
            initialMoleFractions = system.initialMoleFractions
            for item in system.termination:
                if isinstance(item, TerminationTime):
                    terminationtime = item.time.getValueInGivenUnits()
                    time_units = item.time.units
                else:
                    species = item.species.label
                    conversion = item.conversion
            initial_reactor_systems.append(
                {
                    "temperature": temperature,
                    "temperature_units": temperature_units,
                    "pressure": pressure,
                    "pressure_units": pressure_units,
                    "terminationtime": terminationtime,
                    "time_units": time_units,
                    "species": species,
                    "conversion": conversion,
                }
            )

        # Species
        initial_species = []
        for item in self.rmg.initialSpecies:
            name = item.label
            adjlist = item.molecule[0].toAdjacencyList()
            inert = False if item.reactive else True
            spec, isNew = self.rmg.reactionModel.makeNewSpecies(
                item.molecule[0], label=item.label, reactive=item.reactive
            )
            molefrac = initialMoleFractions[spec]
            initial_species.append({"name": name, "adjlist": adjlist, "inert": inert, "molefrac": molefrac})

        # Tolerances
        initial = {}
        initial["simulator_atol"] = self.rmg.absoluteTolerance
        initial["simulator_rtol"] = self.rmg.relativeTolerance
        initial["toleranceKeepInEdge"] = self.rmg.fluxToleranceKeepInEdge
        initial["toleranceMoveToCore"] = self.rmg.fluxToleranceMoveToCore
        initial["toleranceInterruptSimulation"] = self.rmg.fluxToleranceInterrupt
        initial["maximumEdgeSpecies"] = self.rmg.maximumEdgeSpecies

        # Pressure Dependence
        if self.rmg.pressureDependence:
            initial["interpolation"] = self.rmg.pressureDependence.model[0]
            initial["temp_basis"] = self.rmg.pressureDependence.model[1]
            initial["p_basis"] = self.rmg.pressureDependence.model[2]
            initial["temp_low"] = self.rmg.pressureDependence.Tmin.getValueInGivenUnits()
            initial["temp_high"] = self.rmg.pressureDependence.Tmax.getValueInGivenUnits()
            initial["temprange_units"] = self.rmg.pressureDependence.Tmax.units
            initial["temp_interp"] = self.rmg.pressureDependence.Tcount
            initial["p_low"] = self.rmg.pressureDependence.Pmin.getValueInGivenUnits()
            initial["p_high"] = self.rmg.pressureDependence.Pmax.getValueInGivenUnits()
            initial["prange_units"] = self.rmg.pressureDependence.Pmax.units
            initial["p_interp"] = self.rmg.pressureDepence.Pcount

            initial["maximumGrainSize"] = self.rmg.pressureDependence.grainSize.getValueInGivenUnits()
            initial["grainsize_units"] = self.rmg.pressureDependence.grainSize.units
            initial["minimumNumberOfGrains"] = self.rmg.pressureDependence.grainCount

        else:
            initial["pdep"] = "off"

        # Additional Options
        if self.rmg.saveRestartPeriod:
            initial["saveRestartPeriod"] = self.rmg.saveRestartPeriod.getValueInGivenUnits()
            initial["saveRestartPeriodUnits"] = self.rmg.saveConcentrationProfiles.units
        if self.rmg.drawMolecules:
            initial["drawMolecules"] = True
        if self.rmg.generatePlots:
            initial["generatePlots"] = True
        if self.rmg.saveConcentrationProfiles:
            initial["saveConcentrationProfiles"] = True

        return initial_thermo_libraries, initial_reaction_libraries, initial_reactor_systems, initial_species, initial