當前位置: 首頁>>代碼示例>>Python>>正文


Python Species.molecule方法代碼示例

本文整理匯總了Python中species.Species.molecule方法的典型用法代碼示例。如果您正苦於以下問題:Python Species.molecule方法的具體用法?Python Species.molecule怎麽用?Python Species.molecule使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在species.Species的用法示例。


在下文中一共展示了Species.molecule方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: loadChemkinFile

# 需要導入模塊: from species import Species [as 別名]
# 或者: from species.Species import molecule [as 別名]
def loadChemkinFile(path, dictionaryPath=None):
    """
    Load a Chemkin input file to `path` on disk, returning lists of the species
    and reactions in the Chemkin file.
    """
    
    speciesList = []; speciesDict = {}
    reactionList = []

    # If the dictionary path is given, the read it and generate Molecule objects
    # You need to append an additional adjacency list for nonreactive species, such
    # as N2, or else the species objects will not store any structures for the final
    # HTML output.
    if dictionaryPath:
        with open(dictionaryPath, 'r') as f:
            adjlist = ''
            for line in f:
                if line.strip() == '' and adjlist.strip() != '':
                    # Finish this adjacency list
                    species = Species().fromAdjacencyList(adjlist)
                    species.generateResonanceIsomers()
                    speciesDict[species.label] = species
                    adjlist = ''
                else:
                    if "InChI" in line:
                        line = line.split()[0] + '\n'
                    if '//' in line:
                        index = line.index('//')
                        line = line[0:index]
                    adjlist += line
    
    def removeCommentFromLine(line):
        if '!' in line:
            index = line.index('!')
            comment = line[index+1:-1]
            line = line[0:index] + '\n'
            return line, comment
        else:
            comment = ''
            return line, comment

    def checkDuplicateKinetics(reaction, kinetics,comments,dupReactionList,reactionList):
        if 'DUP' in kinetics:
            kinetics = kinetics.replace('\nDUP','')
            reaction = readKineticsEntry(kinetics,speciesDict,energyUnits,moleculeUnits)
            reaction.kinetics.comment = comments
            if dupReactionList:
                if not reaction.hasTemplate(dupReactionList[-1].reactants,dupReactionList[-1].products):
                    # It's not the same kind of duplicate reaction
                    oldReactionKinetics = MultiKinetics()
                    for item in dupReactionList:
                        oldReactionKinetics.kineticsList.append(item.kinetics)
                    oldReaction = dupReactionList[0]
                    oldReaction.kinetics = oldReactionKinetics
                    reactionList.append(oldReaction)
                    dupReactionList = []
            dupReactionList.append(reaction)
            kinetics = ''
            comments = ''
            return reaction, kinetics, comments, dupReactionList, reactionList

        else:
            # No more duplicate reactions
            if dupReactionList:
                # add previous reaction if they were duplicate reactions
                oldReactionKinetics = MultiKinetics()
                for item in dupReactionList:
                    oldReactionKinetics.kineticsList.append(item.kinetics)
                oldReaction = dupReactionList[0]
                oldReaction.kinetics = oldReactionKinetics
                reactionList.append(oldReaction)
                dupReactionList = []
            # add this new, nonduplicate reaction
            reaction = readKineticsEntry(kinetics,speciesDict,energyUnits,moleculeUnits)
            reaction.kinetics.comment = comments
            reactionList.append(reaction)
            kinetics = ''
            comments = ''
            return reaction, kinetics, comments, dupReactionList, reactionList

    with open(path, 'r') as f:
    
        line = f.readline()
        while line != '':        
            line = removeCommentFromLine(line)[0]
            line = line.strip()
            tokens = line.split()
            
            if 'SPECIES' in line:
                # List of species identifiers
                index = tokens.index('SPECIES')
                tokens = tokens[index+1:]
                while 'END' not in tokens:
                    line = f.readline()
                    line = removeCommentFromLine(line)[0]
                    line = line.strip()
                    tokens.extend(line.split())
                
                for token in tokens:
                    if token == 'END':
#.........這裏部分代碼省略.........
開發者ID:sean-v8,項目名稱:RMG-Py,代碼行數:103,代碼來源:chemkin.py


注:本文中的species.Species.molecule方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。