Example #1
0
def save_compare_html(outputDir,
                      chemkin_path1,
                      species_dict_path1,
                      chemkin_path2,
                      species_dict_path2,
                      read_comments1=True,
                      read_comments2=True):
    """
    Saves a model comparison HTML file based on two sets of chemkin and species dictionary
    files.
    """
    model1 = ReactionModel()
    model1.species, model1.reactions = load_chemkin_file(
        chemkin_path1, species_dict_path1, read_comments=read_comments1)
    model2 = ReactionModel()
    model2.species, model2.reactions = load_chemkin_file(
        chemkin_path2, species_dict_path2, read_comments=read_comments2)
    common_reactions, unique_reactions1, unique_reactions2 = compare_model_reactions(
        model1, model2)
    common_species, unique_species1, unique_species2 = compare_model_species(
        model1, model2)

    output_path = outputDir + 'diff.html'
    save_diff_html(output_path, common_species, unique_species1,
                   unique_species2, common_reactions, unique_reactions1,
                   unique_reactions2)
Example #2
0
def execute(chemkin1, species_dict1, thermo1, chemkin2, species_dict2, thermo2,
            **kwargs):
    model1 = ReactionModel()
    model1.species, model1.reactions = load_chemkin_file(chemkin1,
                                                         species_dict1,
                                                         thermo_path=thermo1)
    model2 = ReactionModel()
    model2.species, model2.reactions = load_chemkin_file(chemkin2,
                                                         species_dict2,
                                                         thermo_path=thermo2)

    common_species, unique_species1, unique_species2 = compare_model_species(
        model1, model2)
    common_reactions, unique_reactions1, unique_reactions2 = compare_model_reactions(
        model1, model2)

    try:
        diff_only = kwargs['diffOnly']
    except KeyError:
        diff_only = False

    try:
        common_diff_only = kwargs['commonDiffOnly']
    except KeyError:
        common_diff_only = False

    if diff_only or common_diff_only:
        common_species = [x for x in common_species if not identical_thermo(x)]
        common_reactions = [
            x for x in common_reactions if not identical_kinetics(x)
        ]

    if common_diff_only:
        unique_species1 = []
        unique_species2 = []
        unique_reactions1 = []
        unique_reactions2 = []

    try:
        web = kwargs['web']
    except KeyError:
        web = False

    if not web:
        logging.info('{0:d} species were found in both models:'.format(
            len(common_species)))
        for spec1, spec2 in common_species:
            logging.info('    {0!s}'.format(spec1))
            if spec1.thermo and spec2.thermo:
                spec1.molecule[0].get_symmetry_number()
                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.get_enthalpy(300) / 4184.,
                        spec1.thermo.get_entropy(300) / 4.184,
                        spec1.thermo.get_heat_capacity(300) / 4.184,
                        spec1.thermo.get_heat_capacity(400) / 4.184,
                        spec1.thermo.get_heat_capacity(500) / 4.184,
                        spec1.thermo.get_heat_capacity(600) / 4.184,
                        spec1.thermo.get_heat_capacity(800) / 4.184,
                        spec1.thermo.get_heat_capacity(1000) / 4.184,
                        spec1.thermo.get_heat_capacity(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.get_enthalpy(300) / 4184.,
                        spec2.thermo.get_entropy(300) / 4.184,
                        spec2.thermo.get_heat_capacity(300) / 4.184,
                        spec2.thermo.get_heat_capacity(400) / 4.184,
                        spec2.thermo.get_heat_capacity(500) / 4.184,
                        spec2.thermo.get_heat_capacity(600) / 4.184,
                        spec2.thermo.get_heat_capacity(800) / 4.184,
                        spec2.thermo.get_heat_capacity(1000) / 4.184,
                        spec2.thermo.get_heat_capacity(1500) / 4.184,
                    ))
        logging.info(
            '{0:d} species were only found in the first model:'.format(
                len(unique_species1)))
        for spec in unique_species1:
            logging.info('    {0!s}'.format(spec))
        logging.info(
            '{0:d} species were only found in the second model:'.format(
                len(unique_species2)))
        for spec in unique_species2:
            logging.info('    {0!s}'.format(spec))

        logging.info('{0:d} reactions were found in both models:'.format(
            len(common_reactions)))
        for rxn1, rxn2 in common_reactions:
            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.get_rate_coefficient(
                            300, 1e5)),
                        math.log10(rxn1.kinetics.get_rate_coefficient(
                            400, 1e5)),
                        math.log10(rxn1.kinetics.get_rate_coefficient(
                            500, 1e5)),
                        math.log10(rxn1.kinetics.get_rate_coefficient(
                            600, 1e5)),
                        math.log10(rxn1.kinetics.get_rate_coefficient(
                            800, 1e5)),
                        math.log10(
                            rxn1.kinetics.get_rate_coefficient(1000, 1e5)),
                        math.log10(
                            rxn1.kinetics.get_rate_coefficient(1500, 1e5)),
                        math.log10(
                            rxn1.kinetics.get_rate_coefficient(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.get_rate_coefficient(
                            300, 1e5)),
                        math.log10(rxn2.kinetics.get_rate_coefficient(
                            400, 1e5)),
                        math.log10(rxn2.kinetics.get_rate_coefficient(
                            500, 1e5)),
                        math.log10(rxn2.kinetics.get_rate_coefficient(
                            600, 1e5)),
                        math.log10(rxn2.kinetics.get_rate_coefficient(
                            800, 1e5)),
                        math.log10(
                            rxn2.kinetics.get_rate_coefficient(1000, 1e5)),
                        math.log10(
                            rxn2.kinetics.get_rate_coefficient(1500, 1e5)),
                        math.log10(
                            rxn2.kinetics.get_rate_coefficient(2000, 1e5)),
                    ))
        logging.info(
            '{0:d} reactions were only found in the first model:'.format(
                len(unique_reactions1)))
        for rxn in unique_reactions1:
            logging.info('    {0!s}'.format(rxn))
        logging.info(
            '{0:d} reactions were only found in the second model:'.format(
                len(unique_reactions2)))
        for rxn in unique_reactions2:
            logging.info('    {0!s}'.format(rxn))

    logging.info("Saving output in diff.html")

    try:
        wd = kwargs['wd']
    except KeyError:
        wd = os.getcwd()

    output_path = os.path.join(wd, 'diff.html')
    save_diff_html(output_path, common_species, unique_species1,
                   unique_species2, common_reactions, unique_reactions1,
                   unique_reactions2)
    logging.info("Finished!")

    return common_species, unique_species1, unique_species2, common_reactions, unique_reactions1, unique_reactions2