def saveCompareHTML(outputDir, chemkinPath1, speciesDictPath1, chemkinPath2, speciesDictPath2, readComments1=True, readComments2=True): """ Saves a model comparison HTML file based on two sets of chemkin and species dictionary files. """ model1 = ReactionModel() model1.species, model1.reactions = loadChemkinFile( chemkinPath1, speciesDictPath1, readComments=readComments1) model2 = ReactionModel() model2.species, model2.reactions = loadChemkinFile( chemkinPath2, speciesDictPath2, readComments=readComments2) commonReactions, uniqueReactions1, uniqueReactions2 = compareModelReactions( model1, model2) commonSpecies, uniqueSpecies1, uniqueSpecies2 = compareModelSpecies( model1, model2) outputPath = outputDir + 'diff.html' saveDiffHTML(outputPath, commonSpecies, uniqueSpecies1, uniqueSpecies2, commonReactions, uniqueReactions1, uniqueReactions2)
def saveCompareHTML(outputDir,chemkinPath1,speciesDictPath1,chemkinPath2,speciesDictPath2): """ Saves a model comparison HTML file based on two sets of chemkin and species dictionary files. """ model1 = ReactionModel() model1.species, model1.reactions = loadChemkinFile(chemkinPath1, speciesDictPath1) model2 = ReactionModel() model2.species, model2.reactions = loadChemkinFile(chemkinPath2, speciesDictPath2) commonReactions, uniqueReactions1, uniqueReactions2 = compareModelReactions(model1, model2) outputPath = outputDir + 'diff.html' speciesList1 = [] speciesList1 = model1.species commonSpeciesList = [] speciesList2 = [] for spec2 in model2.species: for spec1 in speciesList1: if spec2.isIsomorphic(spec1): spec2.label = spec1.label speciesList1.remove(spec1) commonSpeciesList.append(spec2) break else: speciesList2.append(spec2) saveDiffHTML(outputPath, commonSpeciesList,speciesList1,speciesList2,commonReactions,uniqueReactions1,uniqueReactions2)
def saveCompareHTML(outputDir,chemkinPath1,speciesDictPath1,chemkinPath2,speciesDictPath2,readComments1=True,readComments2=True): """ Saves a model comparison HTML file based on two sets of chemkin and species dictionary files. """ model1 = ReactionModel() model1.species, model1.reactions = loadChemkinFile(chemkinPath1, speciesDictPath1, readComments = readComments1) model2 = ReactionModel() model2.species, model2.reactions = loadChemkinFile(chemkinPath2, speciesDictPath2, readComments = readComments2) commonReactions, uniqueReactions1, uniqueReactions2 = compareModelReactions(model1, model2) commonSpecies, uniqueSpecies1, uniqueSpecies2 = compareModelSpecies(model1, model2) outputPath = outputDir + 'diff.html' saveDiffHTML(outputPath, commonSpecies, uniqueSpecies1, uniqueSpecies2, commonReactions, uniqueReactions1, uniqueReactions2)
def execute(chemkin1, speciesDict1, thermo1, chemkin2, speciesDict2, thermo2, **kwargs): model1 = ReactionModel() model1.species, model1.reactions = loadChemkinFile(chemkin1, speciesDict1, thermoPath = thermo1) model2 = ReactionModel() model2.species, model2.reactions = loadChemkinFile(chemkin2, speciesDict2, thermoPath = thermo2) commonSpecies, uniqueSpecies1, uniqueSpecies2 = compareModelSpecies(model1, model2) commonReactions, uniqueReactions1, uniqueReactions2 = compareModelReactions(model1, model2) try: diffOnly = kwargs['diffOnly'] except KeyError: diffOnly = False try: commonDiffOnly = kwargs['commonDiffOnly'] except KeyError: commonDiffOnly = False if diffOnly or commonDiffOnly: commonSpecies = filter(lambda x: not identicalThermo(x), commonSpecies) commonReactions = filter(lambda x: not identicalKinetics(x), commonReactions) if commonDiffOnly: uniqueSpecies1 = [] uniqueSpecies2 = [] uniqueReactions1 = [] uniqueReactions2 = [] try: web = kwargs['web'] except KeyError: web = False if not web: logging.info('{0:d} species were found in both models:'.format(len(commonSpecies))) for spec1, spec2 in commonSpecies: logging.info(' {0!s}'.format(spec1)) if spec1.thermo and spec2.thermo: spec1.molecule[0].getSymmetryNumber() logging.info(' {0:7.2f} {1:7.2f} {2:7.2f} {3:7.2f} {4:7.2f} {5:7.2f} {6:7.2f} {7:7.2f} {8:7.2f}'.format( spec1.thermo.getEnthalpy(300) / 4184., spec1.thermo.getEntropy(300) / 4.184, spec1.thermo.getHeatCapacity(300) / 4.184, spec1.thermo.getHeatCapacity(400) / 4.184, spec1.thermo.getHeatCapacity(500) / 4.184, spec1.thermo.getHeatCapacity(600) / 4.184, spec1.thermo.getHeatCapacity(800) / 4.184, spec1.thermo.getHeatCapacity(1000) / 4.184, spec1.thermo.getHeatCapacity(1500) / 4.184, )) logging.info(' {0:7.2f} {1:7.2f} {2:7.2f} {3:7.2f} {4:7.2f} {5:7.2f} {6:7.2f} {7:7.2f} {8:7.2f}'.format( spec2.thermo.getEnthalpy(300) / 4184., spec2.thermo.getEntropy(300) / 4.184, spec2.thermo.getHeatCapacity(300) / 4.184, spec2.thermo.getHeatCapacity(400) / 4.184, spec2.thermo.getHeatCapacity(500) / 4.184, spec2.thermo.getHeatCapacity(600) / 4.184, spec2.thermo.getHeatCapacity(800) / 4.184, spec2.thermo.getHeatCapacity(1000) / 4.184, spec2.thermo.getHeatCapacity(1500) / 4.184, )) logging.info('{0:d} species were only found in the first model:'.format(len(uniqueSpecies1))) for spec in uniqueSpecies1: logging.info(' {0!s}'.format(spec)) logging.info('{0:d} species were only found in the second model:'.format(len(uniqueSpecies2))) for spec in uniqueSpecies2: logging.info(' {0!s}'.format(spec)) logging.info('{0:d} reactions were found in both models:'.format(len(commonReactions))) for rxn1, rxn2 in commonReactions: logging.info(' {0!s}'.format(rxn1)) if rxn1.kinetics and rxn2.kinetics: logging.info(' {0:7.2f} {1:7.2f} {2:7.2f} {3:7.2f} {4:7.2f} {5:7.2f} {6:7.2f} {7:7.2f}'.format( math.log10(rxn1.kinetics.getRateCoefficient(300, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(400, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(500, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(600, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(800, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(1000, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(1500, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(2000, 1e5)), )) logging.info(' {0:7.2f} {1:7.2f} {2:7.2f} {3:7.2f} {4:7.2f} {5:7.2f} {6:7.2f} {7:7.2f}'.format( math.log10(rxn2.kinetics.getRateCoefficient(300, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(400, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(500, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(600, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(800, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(1000, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(1500, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(2000, 1e5)), )) logging.info('{0:d} reactions were only found in the first model:'.format(len(uniqueReactions1))) for rxn in uniqueReactions1: logging.info(' {0!s}'.format(rxn)) logging.info('{0:d} reactions were only found in the second model:'.format(len(uniqueReactions2))) for rxn in uniqueReactions2: logging.info(' {0!s}'.format(rxn)) logging.info("Saving output in diff.html") try: wd = kwargs['wd'] except KeyError: wd = os.getcwd() outputPath = os.path.join(wd, 'diff.html') saveDiffHTML(outputPath, commonSpecies, uniqueSpecies1, uniqueSpecies2, commonReactions, uniqueReactions1, uniqueReactions2) logging.info("Finished!") return commonSpecies, uniqueSpecies1, uniqueSpecies2, commonReactions, uniqueReactions1, uniqueReactions2
math.log10(rxn1.kinetics.getRateCoefficient(1500, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(2000, 1e5)), ) print ' {0:7.2f} {1:7.2f} {2:7.2f} {3:7.2f} {4:7.2f} {5:7.2f} {6:7.2f} {7:7.2f}'.format( math.log10(rxn2.kinetics.getRateCoefficient(300, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(400, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(500, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(600, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(800, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(1000, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(1500, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(2000, 1e5)), ) print '{0:d} reactions were only found in the first model:'.format( len(uniqueReactions1)) for rxn in uniqueReactions1: print ' {0!s}'.format(rxn) print '{0:d} reactions were only found in the second model:'.format( len(uniqueReactions2)) for rxn in uniqueReactions2: print ' {0!s}'.format(rxn) #commonSpecies.sort(key = enthalpyDiff) #commonReactions.sort(key = kineticsDiff) print "Saving output in diff.html" outputPath = 'diff.html' saveDiffHTML(outputPath, commonSpecies, uniqueSpecies1, uniqueSpecies2, commonReactions, uniqueReactions1, uniqueReactions2) print "Finished!"
def execute(chemkin1, speciesDict1, thermo1, chemkin2, speciesDict2, thermo2, **kwargs): model1 = ReactionModel() model1.species, model1.reactions = loadChemkinFile(chemkin1, speciesDict1, thermoPath=thermo1) model2 = ReactionModel() model2.species, model2.reactions = loadChemkinFile(chemkin2, speciesDict2, thermoPath=thermo2) commonSpecies, uniqueSpecies1, uniqueSpecies2 = compareModelSpecies( model1, model2) commonReactions, uniqueReactions1, uniqueReactions2 = compareModelReactions( model1, model2) try: diffOnly = kwargs['diffOnly'] except KeyError: diffOnly = False try: commonDiffOnly = kwargs['commonDiffOnly'] except KeyError: commonDiffOnly = False if diffOnly or commonDiffOnly: commonSpecies = filter(lambda x: not identicalThermo(x), commonSpecies) commonReactions = filter(lambda x: not identicalKinetics(x), commonReactions) if commonDiffOnly: uniqueSpecies1 = [] uniqueSpecies2 = [] uniqueReactions1 = [] uniqueReactions2 = [] try: web = kwargs['web'] except KeyError: web = False if not web: logging.info('{0:d} species were found in both models:'.format( len(commonSpecies))) for spec1, spec2 in commonSpecies: logging.info(' {0!s}'.format(spec1)) if spec1.thermo and spec2.thermo: spec1.molecule[0].getSymmetryNumber() logging.info( ' {0:7.2f} {1:7.2f} {2:7.2f} {3:7.2f} {4:7.2f} {5:7.2f} {6:7.2f} {7:7.2f} {8:7.2f}' .format( spec1.thermo.getEnthalpy(300) / 4184., spec1.thermo.getEntropy(300) / 4.184, spec1.thermo.getHeatCapacity(300) / 4.184, spec1.thermo.getHeatCapacity(400) / 4.184, spec1.thermo.getHeatCapacity(500) / 4.184, spec1.thermo.getHeatCapacity(600) / 4.184, spec1.thermo.getHeatCapacity(800) / 4.184, spec1.thermo.getHeatCapacity(1000) / 4.184, spec1.thermo.getHeatCapacity(1500) / 4.184, )) logging.info( ' {0:7.2f} {1:7.2f} {2:7.2f} {3:7.2f} {4:7.2f} {5:7.2f} {6:7.2f} {7:7.2f} {8:7.2f}' .format( spec2.thermo.getEnthalpy(300) / 4184., spec2.thermo.getEntropy(300) / 4.184, spec2.thermo.getHeatCapacity(300) / 4.184, spec2.thermo.getHeatCapacity(400) / 4.184, spec2.thermo.getHeatCapacity(500) / 4.184, spec2.thermo.getHeatCapacity(600) / 4.184, spec2.thermo.getHeatCapacity(800) / 4.184, spec2.thermo.getHeatCapacity(1000) / 4.184, spec2.thermo.getHeatCapacity(1500) / 4.184, )) logging.info( '{0:d} species were only found in the first model:'.format( len(uniqueSpecies1))) for spec in uniqueSpecies1: logging.info(' {0!s}'.format(spec)) logging.info( '{0:d} species were only found in the second model:'.format( len(uniqueSpecies2))) for spec in uniqueSpecies2: logging.info(' {0!s}'.format(spec)) logging.info('{0:d} reactions were found in both models:'.format( len(commonReactions))) for rxn1, rxn2 in commonReactions: logging.info(' {0!s}'.format(rxn1)) if rxn1.kinetics and rxn2.kinetics: logging.info( ' {0:7.2f} {1:7.2f} {2:7.2f} {3:7.2f} {4:7.2f} {5:7.2f} {6:7.2f} {7:7.2f}' .format( math.log10(rxn1.kinetics.getRateCoefficient(300, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(400, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(500, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(600, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(800, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(1000, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(1500, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(2000, 1e5)), )) logging.info( ' {0:7.2f} {1:7.2f} {2:7.2f} {3:7.2f} {4:7.2f} {5:7.2f} {6:7.2f} {7:7.2f}' .format( math.log10(rxn2.kinetics.getRateCoefficient(300, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(400, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(500, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(600, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(800, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(1000, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(1500, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(2000, 1e5)), )) logging.info( '{0:d} reactions were only found in the first model:'.format( len(uniqueReactions1))) for rxn in uniqueReactions1: logging.info(' {0!s}'.format(rxn)) logging.info( '{0:d} reactions were only found in the second model:'.format( len(uniqueReactions2))) for rxn in uniqueReactions2: logging.info(' {0!s}'.format(rxn)) logging.info("Saving output in diff.html") try: wd = kwargs['wd'] except KeyError: wd = os.getcwd() outputPath = os.path.join(wd, 'diff.html') saveDiffHTML(outputPath, commonSpecies, uniqueSpecies1, uniqueSpecies2, commonReactions, uniqueReactions1, uniqueReactions2) logging.info("Finished!") return commonSpecies, uniqueSpecies1, uniqueSpecies2, commonReactions, uniqueReactions1, uniqueReactions2
math.log10(rxn1.kinetics.getRateCoefficient(600, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(800, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(1000, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(1500, 1e5)), math.log10(rxn1.kinetics.getRateCoefficient(2000, 1e5)), ) print ' {0:7.2f} {1:7.2f} {2:7.2f} {3:7.2f} {4:7.2f} {5:7.2f} {6:7.2f} {7:7.2f}'.format( math.log10(rxn2.kinetics.getRateCoefficient(300, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(400, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(500, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(600, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(800, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(1000, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(1500, 1e5)), math.log10(rxn2.kinetics.getRateCoefficient(2000, 1e5)), ) print '{0:d} reactions were only found in the first model:'.format(len(uniqueReactions1)) for rxn in uniqueReactions1: print ' {0!s}'.format(rxn) print '{0:d} reactions were only found in the second model:'.format(len(uniqueReactions2)) for rxn in uniqueReactions2: print ' {0!s}'.format(rxn) #commonSpecies.sort(key = enthalpyDiff) #commonReactions.sort(key = kineticsDiff) print "Saving output in diff.html" outputPath = 'diff.html' saveDiffHTML(outputPath, commonSpecies, uniqueSpecies1, uniqueSpecies2, commonReactions, uniqueReactions1, uniqueReactions2) print "Finished!"