示例#1
0
文件: loader.py 项目: alongd/RMG-Py
def loadRMGPyJob(inputFile, chemkinFile=None, speciesDict=None, generateImages=True):
    """
    Load the results of an RMG-Py job generated from the given `inputFile`.
    """
    from rmgpy.rmg.main import RMG
    
    # Load the specified RMG input file
    rmg = RMG()
    rmg.loadInput(inputFile)
    rmg.outputDirectory = os.path.abspath(os.path.dirname(inputFile))
    
    # Load the final Chemkin model generated by RMG
    if not chemkinFile:
        chemkinFile = os.path.join(os.path.dirname(inputFile), 'chemkin', 'chem.inp')
    if not speciesDict:
        speciesDict = os.path.join(os.path.dirname(inputFile), 'chemkin', 'species_dictionary.txt')
    speciesList, reactionList = loadChemkinFile(chemkinFile, speciesDict)
    
    # Map species in input file to corresponding species in Chemkin file
    speciesDict = {}
    for spec0 in rmg.initialSpecies:
        for species in speciesList:
            if species.isIsomorphic(spec0):
                speciesDict[spec0] = species
                break
            
    # Generate flux pairs for each reaction if needed
    for reaction in reactionList:
        if not reaction.pairs: reaction.generatePairs()
    
    # Replace species in input file with those in Chemkin file
    for reactionSystem in rmg.reactionSystems:
        reactionSystem.initialMoleFractions = dict([(speciesDict[spec], frac) for spec, frac in reactionSystem.initialMoleFractions.iteritems()])
        for t in reactionSystem.termination:
            if isinstance(t, TerminationConversion):
                t.species = speciesDict[t.species]
        reactionSystem.sensitiveSpecies = [speciesDict[spec] for spec in reactionSystem.sensitiveSpecies]
    
    # Set reaction model to match model loaded from Chemkin file
    rmg.reactionModel.core.species = speciesList
    rmg.reactionModel.core.reactions = reactionList

    # Generate species images
    if generateImages:
        speciesPath = os.path.join(os.path.dirname(inputFile), 'species')
        try:
            os.mkdir(speciesPath)
        except OSError:
            pass
        for species in speciesList:
            path = os.path.join(speciesPath, '{0!s}.png'.format(species))
            if not os.path.exists(path):
                species.molecule[0].draw(str(path))
    
    return rmg
示例#2
0
def loadRMGPyJob(inputFile, chemkinFile, speciesDict=None):
    """
    Load the results of an RMG-Py job generated from the given `inputFile`.
    """

    # Load the specified RMG input file
    rmg = RMG()
    rmg.loadInput(inputFile)
    rmg.outputDirectory = os.path.abspath(os.path.dirname(inputFile))

    # Load the final Chemkin model generated by RMG
    speciesList, reactionList = loadChemkinFile(chemkinFile,
                                                speciesDict,
                                                readComments=False)
    assert speciesList, reactionList

    # print 'labels from species in the chemkin file:'
    # for spc in speciesList:
    #     print spc.label

    # Map species in input file to corresponding species in Chemkin file
    speciesDict = {}
    assert rmg.initialSpecies
    # print 'initial species: ', rmg.initialSpecies

    #label of initial species must correspond to the label in the chemkin file WITHOUT parentheses.
    #E.g.: "JP10" not "JP10(1)"
    for spec0 in rmg.initialSpecies:
        for species in speciesList:
            if species.label == spec0.label:
                speciesDict[spec0] = species
                break

    assert speciesDict
    # Replace species in input file with those in Chemkin file
    for reactionSystem in rmg.reactionSystems:
        reactionSystem.initialMoleFractions = dict([
            (speciesDict[spec], frac)
            for spec, frac in reactionSystem.initialMoleFractions.iteritems()
        ])
        for t in reactionSystem.termination:
            if isinstance(t, TerminationConversion):
                t.species = speciesDict[t.species]

    # Set reaction model to match model loaded from Chemkin file
    rmg.reactionModel.core.species = speciesList
    rmg.reactionModel.core.reactions = reactionList

    # print 'core: ', speciesList
    return rmg
示例#3
0
def loadRMGPyJob(inputFile, chemkinFile, speciesDict=None):
    """
    Load the results of an RMG-Py job generated from the given `inputFile`.
    """
    
    # Load the specified RMG input file
    rmg = RMG()
    rmg.loadInput(inputFile)
    rmg.outputDirectory = os.path.abspath(os.path.dirname(inputFile))
    
    # Load the final Chemkin model generated by RMG
    speciesList, reactionList = loadChemkinFile(chemkinFile, speciesDict, readComments=False)
    assert speciesList, reactionList

    # print 'labels from species in the chemkin file:'
    # for spc in speciesList:
    #     print spc.label

    # Map species in input file to corresponding species in Chemkin file
    speciesDict = {}
    assert rmg.initialSpecies
    # print 'initial species: ', rmg.initialSpecies


    #label of initial species must correspond to the label in the chemkin file WITHOUT parentheses.
    #E.g.: "JP10" not "JP10(1)"
    for spec0 in rmg.initialSpecies:
        for species in speciesList:
            if species.label == spec0.label:
                speciesDict[spec0] = species
                break
            
    assert speciesDict
    # Replace species in input file with those in Chemkin file
    for reactionSystem in rmg.reactionSystems:
        reactionSystem.initialMoleFractions = dict([(speciesDict[spec], frac) for spec, frac in reactionSystem.initialMoleFractions.iteritems()])
        for t in reactionSystem.termination:
            if isinstance(t, TerminationConversion):
                t.species = speciesDict[t.species]
    
    # Set reaction model to match model loaded from Chemkin file
    rmg.reactionModel.core.species = speciesList
    rmg.reactionModel.core.reactions = reactionList

    # print 'core: ', speciesList   
    return rmg
示例#4
0
def loadRMGPyJob(inputFile, chemkinFile, speciesDict):
    """
    Load the results of an RMG-Py job generated from the given `inputFile`.
    """
    import os.path
    from rmgpy.chemkin import getSpeciesIdentifier, loadChemkinFile
    from rmgpy.rmg.main import RMG
    from rmgpy.solver.base import TerminationTime, TerminationConversion

    # Load the specified RMG input file
    rmg = RMG()
    rmg.loadInput(inputFile)
    rmg.outputDirectory = os.path.abspath(os.path.dirname(inputFile))

    # Load the final Chemkin model generated by RMG
    speciesList, reactionList = loadChemkinFile(chemkinFile,
                                                speciesDict,
                                                readComments=False)

    # Map species in input file to corresponding species in Chemkin file
    speciesDict = {}

    #label of initial species must correspond to the label in the chemkin file WITHOUT parentheses.
    for spec0 in rmg.initialSpecies:
        for species in speciesList:
            if species.label == spec0.label:
                speciesDict[spec0] = species
                break

    # Replace species in input file with those in Chemkin file
    for reactionSystem in rmg.reactionSystems:
        reactionSystem.initialMoleFractions = dict([
            (speciesDict[spec], frac)
            for spec, frac in reactionSystem.initialMoleFractions.iteritems()
        ])
        for t in reactionSystem.termination:
            if isinstance(t, TerminationConversion):
                t.species = speciesDict[t.species]

    # Set reaction model to match model loaded from Chemkin file
    rmg.reactionModel.core.species = speciesList
    rmg.reactionModel.core.reactions = reactionList

    return rmg
示例#5
0
def loadRMGPyJob(inputFile, chemkinFile, speciesDict):
    """
    Load the results of an RMG-Py job generated from the given `inputFile`.
    """
    import os.path
    from rmgpy.chemkin import getSpeciesIdentifier, loadChemkinFile
    from rmgpy.rmg.main import RMG
    from rmgpy.solver.base import TerminationTime, TerminationConversion

    # Load the specified RMG input file
    rmg = RMG()
    rmg.loadInput(inputFile)
    rmg.outputDirectory = os.path.abspath(os.path.dirname(inputFile))
    
    # Load the final Chemkin model generated by RMG
    speciesList, reactionList = loadChemkinFile(chemkinFile, speciesDict, readComments=False)

    # Map species in input file to corresponding species in Chemkin file
    speciesDict = {}


    #label of initial species must correspond to the label in the chemkin file WITHOUT parentheses.
    for spec0 in rmg.initialSpecies:
        for species in speciesList:
            if species.label == spec0.label:
                speciesDict[spec0] = species
                break
            
    # Replace species in input file with those in Chemkin file
    for reactionSystem in rmg.reactionSystems:
        reactionSystem.initialMoleFractions = dict([(speciesDict[spec], frac) for spec, frac in reactionSystem.initialMoleFractions.iteritems()])
        for t in reactionSystem.termination:
            if isinstance(t, TerminationConversion):
                t.species = speciesDict[t.species]
    
    # Set reaction model to match model loaded from Chemkin file
    rmg.reactionModel.core.species = speciesList
    rmg.reactionModel.core.reactions = reactionList

    return rmg
示例#6
0
def loadRMGPyJob(inputFile):
    """
    Load the results of an RMG-Py job generated from the given `inputFile`.
    """
    
    # Load the specified RMG input file
    rmg = RMG()
    rmg.loadInput(inputFile)
    rmg.outputDirectory = os.path.abspath(os.path.dirname(inputFile))
    
    # Load the final Chemkin model generated by RMG
    chemkinFile = os.path.join(os.path.dirname(inputFile), 'chemkin', 'chem.inp')
    speciesDict = os.path.join(os.path.dirname(inputFile), 'chemkin', 'species_dictionary.txt')
    speciesList, reactionList = loadChemkinFile(chemkinFile, speciesDict)
    
    # Map species in input file to corresponding species in Chemkin file
    speciesDict = {}
    for spec0 in rmg.initialSpecies:
        for species in speciesList:
            if species.isIsomorphic(spec0):
                speciesDict[spec0] = species
                break
            
    # Generate flux pairs for each reaction if needed
    for reaction in reactionList:
        if not reaction.pairs: reaction.generatePairs()
    
    # Replace species in input file with those in Chemkin file
    for reactionSystem in rmg.reactionSystems:
        reactionSystem.initialMoleFractions = dict([(speciesDict[spec], frac) for spec, frac in reactionSystem.initialMoleFractions.iteritems()])
        for t in reactionSystem.termination:
            if isinstance(t, TerminationConversion):
                t.species = speciesDict[t.species]
    
    # Set reaction model to match model loaded from Chemkin file
    rmg.reactionModel.core.species = speciesList
    rmg.reactionModel.core.reactions = reactionList
    
    return rmg
示例#7
0
def loadRMGPyJob(inputFile,
                 chemkinFile=None,
                 speciesDict=None,
                 generateImages=True):
    """
    Load the results of an RMG-Py job generated from the given `inputFile`.
    """

    # Load the specified RMG input file
    rmg = RMG()
    rmg.loadInput(inputFile)
    rmg.outputDirectory = os.path.abspath(os.path.dirname(inputFile))

    # Load the final Chemkin model generated by RMG
    if not chemkinFile:
        chemkinFile = os.path.join(os.path.dirname(inputFile), 'chemkin',
                                   'chem.inp')
    if not speciesDict:
        speciesDict = os.path.join(os.path.dirname(inputFile), 'chemkin',
                                   'species_dictionary.txt')
    speciesList, reactionList = loadChemkinFile(chemkinFile, speciesDict)

    # Map species in input file to corresponding species in Chemkin file
    speciesDict = {}
    for spec0 in rmg.initialSpecies:
        for species in speciesList:
            if species.isIsomorphic(spec0):
                speciesDict[spec0] = species
                break

    # Generate flux pairs for each reaction if needed
    for reaction in reactionList:
        if not reaction.pairs: reaction.generatePairs()

    # Replace species in input file with those in Chemkin file
    for reactionSystem in rmg.reactionSystems:
        reactionSystem.initialMoleFractions = dict([
            (speciesDict[spec], frac)
            for spec, frac in reactionSystem.initialMoleFractions.iteritems()
        ])
        for t in reactionSystem.termination:
            if isinstance(t, TerminationConversion):
                t.species = speciesDict[t.species]
        reactionSystem.sensitiveSpecies = [
            speciesDict[spec] for spec in reactionSystem.sensitiveSpecies
        ]

    # Set reaction model to match model loaded from Chemkin file
    rmg.reactionModel.core.species = speciesList
    rmg.reactionModel.core.reactions = reactionList

    # Generate species images
    if generateImages:
        speciesPath = os.path.join(os.path.dirname(inputFile), 'species')
        try:
            os.mkdir(speciesPath)
        except OSError:
            pass
        for species in speciesList:
            path = os.path.join(speciesPath, '{0!s}.png'.format(species))
            if not os.path.exists(path):
                species.molecule[0].draw(str(path))

    return rmg
示例#8
0
def loadRMGPyJob(inputFile,
                 chemkinFile=None,
                 speciesDict=None,
                 generateImages=True,
                 useChemkinNames=False,
                 checkDuplicates=True):
    """
    Load the results of an RMG-Py job generated from the given `inputFile`.
    """
    from rmgpy.rmg.main import RMG

    # Load the specified RMG input file
    rmg = RMG(inputFile=inputFile)
    rmg.loadInput(inputFile)
    rmg.outputDirectory = os.path.abspath(os.path.dirname(inputFile))

    # Load the final Chemkin model generated by RMG
    if not chemkinFile:
        chemkinFile = os.path.join(os.path.dirname(inputFile), 'chemkin',
                                   'chem.inp')
    if not speciesDict:
        speciesDict = os.path.join(os.path.dirname(inputFile), 'chemkin',
                                   'species_dictionary.txt')
    speciesList, reactionList = loadChemkinFile(
        chemkinFile,
        speciesDict,
        useChemkinNames=useChemkinNames,
        checkDuplicates=checkDuplicates)

    # Map species in input file to corresponding species in Chemkin file
    speciesDict = {}
    for spec0 in rmg.initialSpecies:
        for species in speciesList:
            if species.isIsomorphic(spec0):
                speciesDict[spec0] = species
                break

    # Generate flux pairs for each reaction if needed
    for reaction in reactionList:
        if not reaction.pairs: reaction.generatePairs()

    # Replace species in input file with those in Chemkin file
    for reactionSystem in rmg.reactionSystems:
        if isinstance(reactionSystem, LiquidReactor):
            # If there are constant species, map their input file names to
            # corresponding species in Chemkin file
            if reactionSystem.constSPCNames:
                constSpeciesDict = {}
                for spec0 in rmg.initialSpecies:
                    for constSpecLabel in reactionSystem.constSPCNames:
                        if spec0.label == constSpecLabel:
                            constSpeciesDict[constSpecLabel] = speciesDict[
                                spec0].label
                            break
                reactionSystem.constSPCNames = [
                    constSpeciesDict[sname]
                    for sname in reactionSystem.constSPCNames
                ]

            reactionSystem.initialConcentrations = dict([
                (speciesDict[spec], conc) for spec, conc in
                reactionSystem.initialConcentrations.iteritems()
            ])
        else:
            reactionSystem.initialMoleFractions = dict([
                (speciesDict[spec], frac) for spec, frac in
                reactionSystem.initialMoleFractions.iteritems()
            ])
        for t in reactionSystem.termination:
            if isinstance(t, TerminationConversion):
                t.species = speciesDict[t.species]
        if reactionSystem.sensitiveSpecies != ['all']:
            reactionSystem.sensitiveSpecies = [
                speciesDict[spec] for spec in reactionSystem.sensitiveSpecies
            ]

    # Set reaction model to match model loaded from Chemkin file
    rmg.reactionModel.core.species = speciesList
    rmg.reactionModel.core.reactions = reactionList

    # Generate species images
    if generateImages:
        speciesPath = os.path.join(os.path.dirname(inputFile), 'species')
        try:
            os.mkdir(speciesPath)
        except OSError:
            pass
        for species in speciesList:
            path = os.path.join(speciesPath, '{0!s}.png'.format(species))
            if not os.path.exists(path):
                species.molecule[0].draw(str(path))

    return rmg