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 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) commonSpecies, uniqueSpecies1, uniqueSpecies2 = compareModelSpecies(model1, model2) outputPath = outputDir + 'diff.html' saveDiffHTML(outputPath, commonSpecies, uniqueSpecies1, uniqueSpecies2, commonReactions, uniqueReactions1, uniqueReactions2)
parser.add_argument('files', metavar='FILE', type=str, nargs='+', help='the Chemkin files and species dictionaries of each model to merge') args = parser.parse_args() outputChemkinFile = 'chem.inp' outputSpeciesDictionary = 'species_dictionary.txt' assert len(args.files) % 2 == 0 # Load the models to merge models = [] for chemkin, speciesDict in zip(args.files[0::2], args.files[1::2]): print 'Loading model #{0:d}...'.format(len(models)+1) model = ReactionModel() model.species, model.reactions = loadChemkinFile(chemkin, speciesDict) models.append(model) finalModel = ReactionModel() for i, model in enumerate(models): print 'Ignoring common species and reactions from model #{0:d}...'.format(i+1) Nspec0 = len(finalModel.species) Nrxn0 = len(finalModel.reactions) finalModel = finalModel.merge(model) Nspec = len(finalModel.species) Nrxn = len(finalModel.reactions) print 'Added {1:d} out of {2:d} ({3:.1f}%) unique species from model #{0:d}.'.format(i+1, Nspec - Nspec0, len(model.species), (Nspec - Nspec0) * 100. / len(model.species)) print 'Added {1:d} out of {2:d} ({3:.1f}%) unique reactions from model #{0:d}.'.format(i+1, Nrxn - Nrxn0, len(model.reactions), (Nrxn - Nrxn0) * 100. / len(model.reactions))
metavar='THERMO2', type=str, nargs=1, help='the thermo file of the second model') args = parser.parse_args() chemkin1 = args.chemkin1[0] speciesDict1 = args.speciesDict1[0] thermo1 = args.thermo1[0] chemkin2 = args.chemkin2[0] speciesDict2 = args.speciesDict2[0] thermo2 = args.thermo2[0] 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) print '{0:d} species were found in both models:'.format(len(commonSpecies)) for spec1, spec2 in commonSpecies: print ' {0!s}'.format(spec1) if spec1.thermo and spec2.thermo:
help='the Chemkin file of the first model') parser.add_argument('speciesDict1', metavar='SPECIESDICT1', type=str, nargs=1, help='the species dictionary file of the first model') parser.add_argument('chemkin2', metavar='CHEMKIN2', type=str, nargs=1, help='the Chemkin file of the second model') parser.add_argument('speciesDict2', metavar='SPECIESDICT2', type=str, nargs=1, help='the species dictionary file of the second model') args = parser.parse_args() chemkin1 = args.chemkin1[0] speciesDict1 = args.speciesDict1[0] chemkin2 = args.chemkin2[0] speciesDict2 = args.speciesDict2[0] model1 = ReactionModel() model1.species, model1.reactions = loadChemkinFile(chemkin1, speciesDict1) model2 = ReactionModel() model2.species, model2.reactions = loadChemkinFile(chemkin2, speciesDict2) commonSpecies, uniqueSpecies1, uniqueSpecies2 = compareModelSpecies(model1, model2) commonReactions, uniqueReactions1, uniqueReactions2 = compareModelReactions(model1, model2) print '{0:d} species were found in both models:'.format(len(commonSpecies)) for spec1, spec2 in commonSpecies: print ' {0!s}'.format(spec1) if spec1.thermo and spec2.thermo: spec1.molecule[0].calculateSymmetryNumber() 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} {8:7.2f}'.format( spec1.thermo.getEnthalpy(298) / 4184., spec1.thermo.getEntropy(298) / 4.184, spec1.thermo.getHeatCapacity(300) / 4.184,
elif len(model) == 3: transport = True inputModelFiles.append((model[0], model[1], model[2])) else: raise Exception outputChemkinFile = 'chem.inp' outputSpeciesDictionary = 'species_dictionary.txt' outputTransportFile = 'tran.dat' if transport else None # Load the models to merge models = [] for chemkin, speciesPath, transportPath in inputModelFiles: print 'Loading model #{0:d}...'.format(len(models) + 1) model = ReactionModel() model.species, model.reactions = loadChemkinFile( chemkin, speciesPath, transportPath=transportPath) models.append(model) finalModel = ReactionModel() for i, model in enumerate(models): print 'Ignoring common species and reactions from model #{0:d}...'.format( i + 1) Nspec0 = len(finalModel.species) Nrxn0 = len(finalModel.reactions) finalModel = finalModel.merge(model) Nspec = len(finalModel.species) Nrxn = len(finalModel.reactions) print 'Added {1:d} out of {2:d} ({3:.1f}%) unique species from model #{0:d}.'.format( i + 1, Nspec - Nspec0, len(model.species), (Nspec - Nspec0) * 100. / len(model.species)) print 'Added {1:d} out of {2:d} ({3:.1f}%) unique reactions from model #{0:d}.'.format(
help='the Chemkin file of the second model') parser.add_argument('speciesDict2', metavar='SPECIESDICT2', type=str, nargs=1, help='the species dictionary file of the second model') parser.add_argument('thermo2', metavar = 'THERMO2', type=str, nargs = 1, help = 'the thermo file of the second model') args = parser.parse_args() chemkin1 = args.chemkin1[0] speciesDict1 = args.speciesDict1[0] thermo1 = args.thermo1[0] chemkin2 = args.chemkin2[0] speciesDict2 = args.speciesDict2[0] thermo2 = args.thermo2[0] 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) print '{0:d} species were found in both models:'.format(len(commonSpecies)) for spec1, spec2 in commonSpecies: print ' {0!s}'.format(spec1) if spec1.thermo and spec2.thermo: spec1.molecule[0].calculateSymmetryNumber() 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} {8:7.2f}'.format( spec1.thermo.getEnthalpy(300) / 4184., spec1.thermo.getEntropy(300) / 4.184, spec1.thermo.getHeatCapacity(300) / 4.184,