Ejemplo n.º 1
0
 def set_e0_with_thermo(self):
     """
     Helper method that sets species' E0 using the species' thermo data
     """
     if self.get_thermo_data().E0 is not None:
         self.conformer.E0 = self.get_thermo_data().E0
     else:
         if not self.thermo.Cp0 or not self.thermo.CpInf:
             # set Cp0 and CpInf
             from rmgpy.data.thermo import find_cp0_and_cpinf
             find_cp0_and_cpinf(self, self.thermo)
         self.conformer.E0 = self.get_thermo_data().to_wilhoit().E0
Ejemplo n.º 2
0
def run(input_file,
        output_directory,
        original=None,
        maximum_isotopic_atoms=1,
        use_original_reactions=False,
        kinetic_isotope_effect=None):
    """
    Accepts one input file with the RMG-Py model to generate.

    Firstly, generates the RMG model for the first input file. Takes the core species of that mechanism
    and generates all isotopomers of those core species. Next, generates all reactions between the
    generated pool of isotopomers, and writes it to file.
    """
    logging.info("isotope: Starting the RMG isotope generation method 'run'")
    if not original:
        logging.info(
            "isotope: original model not found, generating new one in directory `rmg`"
        )
        logging.info(
            "isotope: check `rmg/RMG.log` for the rest of the logging info.")

        outputdir_rmg = os.path.join(output_directory, 'rmg')
        os.mkdir(outputdir_rmg)

        rmg = generate_rmg_model(input_file, outputdir_rmg)
    else:
        logging.info(
            "isotope: original model being copied from previous RMG job in folder {}"
            .format(original))
        outputdir_rmg = original
        chemkin_file = os.path.join(outputdir_rmg, 'chemkin',
                                    'chem_annotated.inp')
        dict_file = os.path.join(outputdir_rmg, 'chemkin',
                                 'species_dictionary.txt')
        rmg = load_rmg_job(input_file,
                           chemkin_file,
                           dict_file,
                           generate_images=False,
                           use_chemkin_names=True)

    logging.info("isotope: generating isotope model")
    logging.info('Generating isotopomers for the core species in {}'.format(
        outputdir_rmg))
    isotopes = []

    logging.info("isotope: adding all the new and old isotopomers")
    for spc in rmg.reaction_model.core.species:
        find_cp0_and_cpinf(spc, spc.thermo)
        isotopes.append([spc] +
                        generate_isotopomers(spc, maximum_isotopic_atoms))

    logging.info('isotope: number of isotopomers: {}'.format(
        sum([len(isotopomer) for isotopomer in isotopes if isotopomer])))

    outputdir_iso = os.path.join(output_directory, 'iso')
    os.mkdir(outputdir_iso)

    logging.info(
        'isotope: Generating RMG isotope model in {}'.format(outputdir_iso))
    generate_isotope_model(outputdir_iso,
                           rmg,
                           isotopes,
                           use_original_reactions=use_original_reactions,
                           kinetic_isotope_effect=kinetic_isotope_effect)
Ejemplo n.º 3
0
    def reconstruct_kinetics_from_source(self,
                                         reaction,
                                         source,
                                         fix_barrier_height=False,
                                         force_positive_barrier=False):
        """
        Reaction is the original reaction with original kinetics.
        Note that for Library and PDep reactions this function does not do anything other than return the original kinetics...
        
        You must enter source data in the appropriate format such as returned from returned from self.extract_source_from_comments,
        self-constructed.  
        fix_barrier_height and force_positive_barrier will change the kinetics based on the Reaction.fix_barrier_height function.
        Return Arrhenius form kinetics if the source is from training reaction or rate rules.
        """
        from rmgpy.data.thermo import find_cp0_and_cpinf
        from rmgpy.thermo import Wilhoit
        if 'Library' in source:
            return reaction.kinetics
        elif 'PDep' in source:
            return reaction.kinetics
        else:
            rxn_copy = deepcopy(reaction)
            if 'Training' in source:
                training_entry = source['Training'][1]
                reverse = source['Training'][2]
                if reverse:
                    reverse_kinetics = training_entry.data
                    rxn_copy.kinetics = reverse_kinetics
                    forward_kinetics = rxn_copy.generate_reverse_rate_coefficient(
                    )
                    kinetics = forward_kinetics
                else:
                    kinetics = training_entry.data
            elif 'Rate Rules' in source:

                source_dict = source['Rate Rules'][1]
                rules = source_dict['rules']
                training = source_dict['training']
                degeneracy = source_dict['degeneracy']

                log_a = 0
                n = 0
                alpha = 0
                E0 = 0
                for rule_entry, weight in rules:
                    log_a += np.log10(rule_entry.data.A.value_si) * weight
                    n += rule_entry.data.n.value_si * weight
                    alpha += rule_entry.data.alpha.value_si * weight
                    E0 += rule_entry.data.E0.value_si * weight
                for rule_entry, training_entry, weight in training:
                    log_a += np.log10(rule_entry.data.A.value_si) * weight
                    n += rule_entry.data.n.value_si * weight
                    alpha += rule_entry.data.alpha.value_si * weight
                    E0 += rule_entry.data.E0.value_si * weight

                a_units = rule_entry.data.A.units
                if a_units == 'cm^3/(mol*s)' or a_units == 'cm^3/(molecule*s)' or a_units == 'm^3/(molecule*s)':
                    a_units = 'm^3/(mol*s)'
                elif a_units == 'cm^6/(mol^2*s)' or a_units == 'cm^6/(molecule^2*s)' or a_units == 'm^6/(molecule^2*s)':
                    a_units = 'm^6/(mol^2*s)'
                elif a_units == 's^-1' or a_units == 'm^3/(mol*s)' or a_units == 'm^6/(mol^2*s)':
                    pass
                else:
                    raise ValueError(
                        'Invalid units {0} for averaging kinetics.'.format(
                            a_units))
                kinetics = ArrheniusEP(
                    A=(degeneracy * 10**log_a, a_units),
                    n=n,
                    alpha=alpha,
                    E0=(E0 * 0.001, "kJ/mol"),
                )
            else:
                raise ValueError(
                    "Source data must be either 'Library', 'PDep','Training', or 'Rate Rules'."
                )

            # Convert ArrheniusEP to Arrhenius
            if fix_barrier_height:
                for spc in rxn_copy.reactants + rxn_copy.products:
                    # Need wilhoit to do this
                    if not isinstance(spc.thermo, Wilhoit):
                        find_cp0_and_cpinf(spc, spc.thermo)
                        wilhoit = spc.thermo.to_wilhoit()
                        spc.thermo = wilhoit

                rxn_copy.kinetics = kinetics
                rxn_copy.fix_barrier_height(
                    force_positive=force_positive_barrier)

                return rxn_copy.kinetics
            else:

                h298 = rxn_copy.get_enthalpy_of_reaction(298)
                if isinstance(kinetics, (ArrheniusEP, ArrheniusBM)):
                    kinetics = kinetics.to_arrhenius(h298)
                return kinetics