Пример #1
0
 def setE0WithThermo(self):
     """
     Helper method that sets species' E0 using the species' thermo data
     """
     if self.getThermoData().E0 is not None:
         self.conformer.E0 = self.getThermoData().E0
     else:
         if not self.thermo.Cp0 or not self.thermo.CpInf:
             # set Cp0 and CpInf
             from rmgpy.data.thermo import findCp0andCpInf
             findCp0andCpInf(self, self.thermo)
         self.conformer.E0 = self.getThermoData().toWilhoit().E0
Пример #2
0
 def setE0WithThermo(self):
     """
     Helper method that sets species' E0 using the species' thermo data
     """
     if self.getThermoData().E0 is not None:
         self.conformer.E0 = self.getThermoData().E0
     else:
         if not self.thermo.Cp0 or not self.thermo.CpInf:
             # set Cp0 and CpInf
             from rmgpy.data.thermo import findCp0andCpInf
             findCp0andCpInf(self, self.thermo)
         self.conformer.E0 = self.getThermoData().toWilhoit().E0
Пример #3
0
def run(inputFile, outputDir, original=None, maximumIsotopicAtoms = 1,
                            useOriginalReactions = False,
                            kineticIsotopeEffect = 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.")

        outputdirRMG = os.path.join(outputDir, 'rmg')
        os.mkdir(outputdirRMG)

        rmg = generate_RMG_model(inputFile, outputdirRMG)
    else:
        logging.info("isotope: original model being copied from previous RMG job in folder {}".format(original))
        outputdirRMG = original
        chemkinFile = os.path.join(outputdirRMG, 'chemkin', 'chem_annotated.inp')
        dictFile = os.path.join(outputdirRMG, 'chemkin', 'species_dictionary.txt')
        rmg = loadRMGJob(inputFile, chemkinFile, dictFile, generateImages=False, useChemkinNames=True)

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

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

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

    outputdirIso = os.path.join(outputDir, 'iso')
    os.mkdir(outputdirIso)

    logging.info('isotope: Generating RMG isotope model in {}'.format(outputdirIso))
    generate_isotope_model(outputdirIso, rmg, isotopes, useOriginalReactions = useOriginalReactions, kineticIsotopeEffect = kineticIsotopeEffect)
Пример #4
0
def run(inputFile, outputDir, original=None, maximumIsotopicAtoms = 1,
                            useOriginalReactions = False,
                            kineticIsotopeEffect = 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.")

        outputdirRMG = os.path.join(outputDir, 'rmg')
        os.mkdir(outputdirRMG)

        rmg = generate_RMG_model(inputFile, outputdirRMG)
    else:
        logging.info("isotope: original model being copied from previous RMG job in folder {}".format(original))
        outputdirRMG = original
        chemkinFile = os.path.join(outputdirRMG, 'chemkin', 'chem_annotated.inp')
        dictFile = os.path.join(outputdirRMG, 'chemkin', 'species_dictionary.txt')
        rmg = loadRMGJob(inputFile, chemkinFile, dictFile, generateImages=False, useChemkinNames=True)

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

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

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

    outputdirIso = os.path.join(outputDir, 'iso')
    os.mkdir(outputdirIso)

    logging.info('isotope: Generating RMG isotope model in {}'.format(outputdirIso))
    generate_isotope_model(outputdirIso, rmg, isotopes, useOriginalReactions = useOriginalReactions, kineticIsotopeEffect = kineticIsotopeEffect)
Пример #5
0
    def reconstructKineticsFromSource(self,
                                      reaction,
                                      source,
                                      fixBarrierHeight=False,
                                      forcePositiveBarrier=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.extractSourceFromComments, 
        self-constructed.  
        fixBarrierHeight and forcePositiveBarrier will change the kinetics based on the Reaction.fixBarrierHeight function.
        Return Arrhenius form kinetics if the source is from training reaction or rate rules.
        """
        from rmgpy.data.thermo import findCp0andCpInf
        from rmgpy.thermo import Wilhoit
        if 'Library' in source:
            return reaction.kinetics
        elif 'PDep' in source:
            return reaction.kinetics
        else:
            rxnCopy = deepcopy(reaction)
            if 'Training' in source:
                trainingEntry = source['Training'][1]
                reverse = source['Training'][2]
                if reverse:
                    reverseKinetics = trainingEntry.data
                    rxnCopy.kinetics = reverseKinetics
                    forwardKinetics = rxnCopy.generateReverseRateCoefficient()
                    kinetics = forwardKinetics
                else:
                    kinetics = trainingEntry.data
            elif 'Rate Rules' in source:

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

                logA = 0
                n = 0
                alpha = 0
                E0 = 0
                for ruleEntry, weight in rules:
                    logA += numpy.log10(ruleEntry.data.A.value_si) * weight
                    n += ruleEntry.data.n.value_si * weight
                    alpha += ruleEntry.data.alpha.value_si * weight
                    E0 += ruleEntry.data.E0.value_si * weight
                for ruleEntry, trainingEntry, weight in training:
                    logA += numpy.log10(ruleEntry.data.A.value_si) * weight
                    n += ruleEntry.data.n.value_si * weight
                    alpha += ruleEntry.data.alpha.value_si * weight
                    E0 += ruleEntry.data.E0.value_si * weight

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

            # Convert ArrheniusEP to Arrhenius
            if fixBarrierHeight:
                for spc in rxnCopy.reactants + rxnCopy.products:
                    # Need wilhoit to do this
                    if not isinstance(spc.thermo, Wilhoit):
                        findCp0andCpInf(spc, spc.thermo)
                        wilhoit = spc.thermo.toWilhoit()
                        spc.thermo = wilhoit

                rxnCopy.kinetics = kinetics
                rxnCopy.fixBarrierHeight(forcePositive=forcePositiveBarrier)

                return rxnCopy.kinetics
            else:

                H298 = rxnCopy.getEnthalpyOfReaction(298)
                if isinstance(kinetics, ArrheniusEP):
                    kinetics = kinetics.toArrhenius(H298)
                return kinetics
Пример #6
0
 def reconstructKineticsFromSource(self, reaction, source, fixBarrierHeight=False, forcePositiveBarrier=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.extractSourceFromComments, 
     self-constructed.  
     fixBarrierHeight and forcePositiveBarrier will change the kinetics based on the Reaction.fixBarrierHeight function.
     Return Arrhenius form kinetics if the source is from training reaction or rate rules.
     """
     from rmgpy.data.thermo import findCp0andCpInf
     from rmgpy.thermo import Wilhoit
     if 'Library' in source:
         return reaction.kinetics
     elif 'PDep' in source:
         return reaction.kinetics
     else:
         rxnCopy = deepcopy(reaction)
         if 'Training' in source:
             trainingEntry = source['Training'][1]
             reverse = source['Training'][2]
             if reverse:
                 reverseKinetics = trainingEntry.data
                 rxnCopy.kinetics = reverseKinetics
                 forwardKinetics = rxnCopy.generateReverseRateCoefficient()
                 kinetics = forwardKinetics
             else:
                 kinetics = trainingEntry.data
         elif 'Rate Rules' in source:
 
             sourceDict = source['Rate Rules'][1]
             rules = sourceDict['rules']
             training = sourceDict['training']
             degeneracy = sourceDict['degeneracy']
 
             logA = 0
             n = 0
             alpha = 0
             E0 = 0
             for ruleEntry, weight in rules:
                 logA += numpy.log10(ruleEntry.data.A.value_si)*weight
                 n += ruleEntry.data.n.value_si*weight
                 alpha +=ruleEntry.data.alpha.value_si*weight
                 E0 +=ruleEntry.data.E0.value_si*weight
             for ruleEntry, trainingEntry, weight in training:
                 logA += numpy.log10(ruleEntry.data.A.value_si)*weight
                 n += ruleEntry.data.n.value_si*weight
                 alpha +=ruleEntry.data.alpha.value_si*weight
                 E0 +=ruleEntry.data.E0.value_si*weight
             
             Aunits = ruleEntry.data.A.units 
             if Aunits == 'cm^3/(mol*s)' or Aunits == 'cm^3/(molecule*s)' or Aunits == 'm^3/(molecule*s)':
                 Aunits = 'm^3/(mol*s)'
             elif Aunits == 'cm^6/(mol^2*s)' or Aunits == 'cm^6/(molecule^2*s)' or Aunits == 'm^6/(molecule^2*s)':
                 Aunits = 'm^6/(mol^2*s)'
             elif Aunits == 's^-1' or Aunits == 'm^3/(mol*s)' or Aunits == 'm^6/(mol^2*s)':
                 pass
             else:
                 raise Exception('Invalid units {0} for averaging kinetics.'.format(Aunits))
             kinetics = ArrheniusEP(
                 A = (degeneracy*10**logA, Aunits),
                 n = n,
                 alpha = alpha,
                 E0 = (E0*0.001,"kJ/mol"),
             )
         else:
             raise Exception("Source data must be either 'Library', 'PDep','Training', or 'Rate Rules'.")
             
         
         # Convert ArrheniusEP to Arrhenius
         if fixBarrierHeight:
             for spc in rxnCopy.reactants + rxnCopy.products:
                 # Need wilhoit to do this
                 if not isinstance(spc.thermo, Wilhoit):
                     findCp0andCpInf(spc, spc.thermo)
                     wilhoit = spc.thermo.toWilhoit()
                     spc.thermo = wilhoit
                     
             rxnCopy.kinetics = kinetics
             rxnCopy.fixBarrierHeight(forcePositive=forcePositiveBarrier)
             
             return rxnCopy.kinetics
         else:
             
             H298 = rxnCopy.getEnthalpyOfReaction(298)
             if isinstance(kinetics, ArrheniusEP):
                 kinetics = kinetics.toArrhenius(H298)
             return kinetics