Example #1
0
def execute(input_model_files, **kwargs):
    try:
        wd = kwargs['wd']
    except KeyError:
        wd = os.getcwd()

    transport = kwargs['transport']

    output_chemkin_file = os.path.join(wd, 'chem.inp')
    output_species_dictionary = os.path.join(wd, 'species_dictionary.txt')
    output_transport_file = os.path.join(wd, 'tran.dat') if transport else None

    models = get_models_to_merge(input_model_files)

    final_model = combine_models(models)

    # Save the merged model to disk
    save_chemkin_file(output_chemkin_file, final_model.species,
                      final_model.reactions)
    save_species_dictionary(output_species_dictionary, final_model.species)
    if transport:
        save_transport_file(output_transport_file, final_model.species)

    print('Merged Chemkin file saved to {0}'.format(output_chemkin_file))
    print('Merged species dictionary saved to {0}'.format(
        output_species_dictionary))
    if transport:
        print(
            'Merged transport file saved to {0}'.format(output_transport_file))
Example #2
0
    def test_read_and_write_template_reaction_family_for_pdd_example(self):
        """
        This example is mainly to ensure comments like
        '! Kinetics were estimated in this direction instead
        of the reverse because:' or '! This direction matched
        an entry in H_Abstraction, the other was just an estimate.'
        won't interfere reaction family info retrival.
        """
        folder = os.path.join(os.path.dirname(rmgpy.__file__), 'test_data/chemkin/chemkin_py')

        chemkin_path = os.path.join(folder, 'pdd', 'chem.inp')
        dictionary_path = os.path.join(folder, 'pdd', 'species_dictionary.txt')

        # load_chemkin_file
        species, reactions = load_chemkin_file(chemkin_path, dictionary_path)

        reaction1 = reactions[0]
        self.assertEqual(reaction1.family, "H_Abstraction")

        reaction2 = reactions[1]
        self.assertEqual(reaction2.family, "H_Abstraction")

        # save_chemkin_file
        chemkin_save_path = os.path.join(folder, 'minimal', 'chem_new.inp')
        dictionary_save_path = os.path.join(folder, 'minimal', 'species_dictionary_new.txt')

        save_chemkin_file(chemkin_save_path, species, reactions, verbose=False, check_for_duplicates=False)
        save_species_dictionary(dictionary_save_path, species, old_style=False)

        self.assertTrue(os.path.isfile(chemkin_save_path))
        self.assertTrue(os.path.isfile(dictionary_save_path))

        # clean up
        os.remove(chemkin_save_path)
        os.remove(dictionary_save_path)
Example #3
0
    def test_read_and_write_and_read_template_reaction_family_for_minimal_example(
            self):
        """
        This example tests if family and templates info can be correctly
        parsed from comments like '!Template reaction: R_Recombination'.
        """
        folder = os.path.join(os.path.dirname(rmgpy.__file__),
                              'test_data/chemkin/chemkin_py')

        chemkin_path = os.path.join(folder, 'minimal', 'chem.inp')
        dictionary_path = os.path.join(folder, 'minimal',
                                       'species_dictionary.txt')

        # read original chemkin file
        species, reactions = load_chemkin_file(chemkin_path, dictionary_path)

        # ensure correct reading
        reaction1 = reactions[0]
        self.assertEqual(reaction1.family, "R_Recombination")
        self.assertEqual(frozenset('C_methyl;C_methyl'.split(';')),
                         frozenset(reaction1.template))
        reaction2 = reactions[1]
        self.assertEqual(reaction2.family, "H_Abstraction")
        self.assertEqual(frozenset('C/H3/Cs\H3;C_methyl'.split(';')),
                         frozenset(reaction2.template))
        # save_chemkin_file
        chemkin_save_path = os.path.join(folder, 'minimal', 'chem_new.inp')
        dictionary_save_path = os.path.join(folder, 'minimal',
                                            'species_dictionary_new.txt')

        save_chemkin_file(chemkin_save_path,
                          species,
                          reactions,
                          verbose=True,
                          check_for_duplicates=True)
        save_species_dictionary(dictionary_save_path, species, old_style=False)

        self.assertTrue(os.path.isfile(chemkin_save_path))
        self.assertTrue(os.path.isfile(dictionary_save_path))

        # read newly written chemkin file to make sure the entire cycle works
        _, reactions2 = load_chemkin_file(chemkin_save_path,
                                          dictionary_save_path)

        reaction1_new = reactions2[0]
        self.assertEqual(reaction1_new.family, reaction1_new.family)
        self.assertEqual(reaction1_new.template, reaction1_new.template)
        self.assertEqual(reaction1_new.degeneracy, reaction1_new.degeneracy)

        reaction2_new = reactions2[1]
        self.assertEqual(reaction2_new.family, reaction2_new.family)
        self.assertEqual(reaction2_new.template, reaction2_new.template)
        self.assertEqual(reaction2_new.degeneracy, reaction2_new.degeneracy)

        # clean up
        os.remove(chemkin_save_path)
        os.remove(dictionary_save_path)
Example #4
0
def run_thermo_estimator(input_file, library_flag):
    """
    Estimate thermo for a list of species using RMG and the settings chosen inside a thermo input file.
    """

    rmg = RMG()
    rmg.load_thermo_input(input_file)

    rmg.database = RMGDatabase()
    path = os.path.join(settings['database.directory'])

    # forbidden structure loading
    rmg.database.load_thermo(os.path.join(path, 'thermo'),
                             rmg.thermo_libraries,
                             depository=False)

    if rmg.solvent:
        rmg.database.load_solvation(os.path.join(path, 'solvation'))
        Species.solvent_data = rmg.database.solvation.get_solvent_data(
            rmg.solvent)
        Species.solvent_name = rmg.solvent

    for species in rmg.initial_species:
        submit(species)

    if library_flag:
        library = ThermoLibrary(name='Thermo Estimation Library')
        for species in rmg.initial_species:
            library.load_entry(
                index=len(library.entries) + 1,
                label=species.label,
                molecule=species.molecule[0].to_adjacency_list(),
                thermo=species.get_thermo_data().to_thermo_data(),
                shortDesc=species.get_thermo_data().comment,
            )
        library.save(os.path.join(rmg.output_directory, 'ThermoLibrary.py'))

    # Save the thermo data to chemkin format output files and dictionary, with no reactions
    save_chemkin_file(os.path.join(rmg.output_directory, 'chem_annotated.inp'),
                      species=rmg.initial_species,
                      reactions=[])
    save_species_dictionary(os.path.join(rmg.output_directory,
                                         'species_dictionary.txt'),
                            species=rmg.initial_species)
Example #5
0
                                           library=library_name)
        reaction_list.append(library_reaction)

    species_list = []
    index = 0
    species_dict = kinetic_library.get_species(
        os.path.join(settings['database.directory'], 'kinetics', 'libraries',
                     library_name, 'dictionary.txt'))
    for spec in list(species_dict.values()):
        index = index + 1
        species = Species(molecule=spec.molecule)
        species.get_thermo_data()
        species.index = index
        species_list.append(species)

    for reaction in reaction_list:
        for reactant in reaction.reactants:
            for spec in species_list:
                if reactant.is_isomorphic(spec):
                    reactant.index = spec.index
                    spec.label = reactant.label
        for product in reaction.products:
            for spec in species_list:
                if product.is_isomorphic(spec):
                    product.index = spec.index
                    spec.label = product.label

    print('Saving the chem.inp and species_dictionary.txt to local directory')
    save_chemkin_file('chem.inp', species_list, reaction_list)
    save_species_dictionary('species_dictionary.txt', species_list)
Example #6
0
            chemkin, speciesPath, transport_path=transportPath)
        models.append(model)

    all_species = []
    species_indices = [[] for i in range(len(models))]
    for i, model in enumerate(models):
        species_indices[i] = []
        for j, species in enumerate(model.species):
            for index, species0 in enumerate(all_species):
                if species0.is_isomorphic(species):
                    species_indices[i].append(index)
                    break
            else:
                all_species.append(species)
                species_indices[i].append(all_species.index(species))
    # Reassign species names and labels according to the list of all species in all models
    # We must retain the original thermochemistry
    for i, model in enumerate(models):
        for j, species in enumerate(model.species):
            index = species_indices[i][j]
            species.label = all_species[index].label
            species.index = all_species[index].index

        # Resave the models
        save_chemkin_file('chem{0}.inp'.format(i + 1), model.species,
                          model.reactions)
        save_species_dictionary('species_dictionary{0}.txt'.format(i + 1),
                                model.species)

    print('Saving of new models with consistent names is complete!')