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)
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:
inputModelFiles.append((model[0], model[1], None)) 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),