def classify_habs(rcts, prds, fml_df, spc_dct): """ Check if an A+B=C+D reaction is an hydrogen abstraction based on the stoichiometries and multiplicities of reactants and products. :rtype: bool """ if not isinstance(rcts, tuple) or not isinstance(prds, tuple): print('error: reactants and products are not tuples') sys.exit() elif len(rcts) != 2 or len(prds) != 2: print('error: not A+B=C+D reaction') sys.exit() mult_rct = numpy.array([get_mult(rcts[0], spc_dct), get_mult(rcts[1], spc_dct)]) mult_prd = numpy.array([get_mult(prds[0], spc_dct), get_mult(prds[1], spc_dct)]) if (any(mult_rct == 1) and any(mult_rct > 1) and any(mult_prd == 1) and any(mult_prd > 1)): species_rct = rcts[numpy.where(mult_rct == 1)[0][0]] species_prd = prds[numpy.where(mult_prd > 1)[0][0]] stoich_add = [0, -1, 0] flag_try_prd2 = False # Habs with O2 and O: multiplicities are 1*3=2*2 elif (any(mult_rct == 1) and any(mult_rct == 3) and all(mult_prd == 2)): species_rct = rcts[numpy.where(mult_rct == 3)[0][0]] species_prd = prds[0] stoich_add = [0, +1, 0] # try the second product in case the first is not right flag_try_prd2 = True try: flag_habs = set_flag_habs(species_rct, species_prd, fml_df, stoich_add) if flag_try_prd2 and not flag_habs: # try the second product species_prd = prds[1] flag_habs = set_flag_habs( species_rct, species_prd, fml_df, stoich_add) except NameError: flag_habs = False return flag_habs
def classify_unimol(rcts, prds, spc_dct): """ Classifies unimolecular reaction from reactants and products names: - A=B: isomerization - A=C+H/O/OH/O2/HO2/CH3: addition - A=C+D: decomposition - A=C+D+E.. : decomposition(lumped) For recombination (depends on multiplicity of the products) it would be nice to distinguish type of bond that being broken :param rcts: reactant names :type rcts: tuple :param prds: product names :type prds: tuple :param spc_dct: :type spc_dct: dict[] """ # extract formula dictionary fml_df = extract_fml_df(spc_dct) mult_rcts = get_mult(rcts, spc_dct) mult_prds = get_mult(prds, spc_dct) if len(prds) == 1: rxn_class_broad = 'Isomerization' elif len(prds) == 2: rxn_class_broad = 'Decomposition' # derive products multiplicity and formulas if mult_rcts == 1 and mult_prds >= 4: rxn_class_broad = 'Bond fission' elif mult_rcts > 1 and mult_prds == 2: rxn_class_broad = 'Beta-scission' prds_fmls = numpy.array( [fml_df['fml'][prds[0]], fml_df['fml'][prds[1]]]) # check product composition # give priority to the second product (should be the lightest) if any(prds_fmls[1] == FMLS_SET): rxn_class_broad += f' +{prds[1]}' elif any(prds_fmls[0] == FMLS_SET): rxn_class_broad += f' +{prds[0]}' elif len(prds) > 2: rxn_class_broad = 'Decomposition(lumped)' return rxn_class_broad
def reac_mult(self, reac_mult_df): """ determines the multiplicity of the reactants of the reactions considered :param self.mech_df: dataframe with mech info (contains all reactions) :param self.spc_dct: species dictionary :param rxncl_mult_df: empty dataframe index=rxns, column: 'mult' :returns: reac_mult_df dataframe with reactants mult dataframe[mult][rxn] :rtype: dataframe[str][tuple] """ # assign multiplicity values to each reactant for rxn in reac_mult_df.index: mult = 1 rcts = self.mech_df['rct_names_lst'][rxn] mult = get_mult(rcts, self.spc_dct) reac_mult_df['mult'][rxn] = str(mult) return reac_mult_df
def classify_bimol(rcts, prds, spc_dct): """ Classifies bimolecular reactions from reactants and products names with 1 product: - A+H/O/OH/O2/HO2/CH3 = B - A+R=B+RH: Habstraction-R (subclass indicates the abstractor) - A+R=A+R: isomerization-bim (isomerization aided by a radical. ex. CH2+H=CH2(S)+H, C6H6+H=FULV+H) - A+B=C+D: addition-decomposition - branch/prop/term - A+B=C+D+E..: addition-decomposition(lumped) - branch/prop/term For recombination (depends on the multiplicity of the reactants) with 2 products. :param rcts: reactant names :type rcts: tuple :param prds: product names :type prds: tuple :param spc_dct: :type spc_dct: dict[] """ # extract formula dictionary fml_df = extract_fml_df(spc_dct) # extracts reactants and products multiplicity mult_rcts = get_mult(rcts, spc_dct) mult_prds = get_mult(prds, spc_dct) if mult_rcts < 4: rxn_class_broad = 'Addition' elif mult_rcts >= 4: rxn_class_broad = 'Recombination' if len(prds) == 1: rcts_fmls = numpy.array( [fml_df['fml'][rcts[0]], fml_df['fml'][rcts[1]]]) # check reactant composition # give priority to the second reactant (should be the lightest) if any(rcts_fmls[1] == FMLS_SET): rxn_class_broad += f' {rcts[1]}' elif any(rcts_fmls[0] == FMLS_SET): rxn_class_broad += f' {rcts[0]}' elif len(prds) == 2: rxn_class_broad += '-decomposition' # H abstraction flag_habs = classify_habs(rcts, prds, fml_df, spc_dct) # Bimolecular isomerization flag_isom_bim = classify_isom_bim(rcts, prds, fml_df) if flag_habs == 1: rxn_class_broad = 'H abstraction' elif flag_isom_bim == 1: rxn_class_broad = 'Bimol Isomerization' elif len(prds) > 2: rxn_class_broad += '-decomposition(lumped)' # add subclass related to branching/propagation/termination # for addition-decomposition rxns if 'decomposition' in rxn_class_broad: # check if branching/propagation/termination rxn_class_broad += bran_prop_term(mult_rcts, mult_prds) return rxn_class_broad