def cbhzed_radradabs(gra, site1, site2, atms, bnd_ords, atm_vals, adj_atms, bal=True): """ Fragments molecule so that each heavy-atom is a seperate fragment INPUT: ich -- STR inchi name for molecule OUTPUT frags -- DIC dictionary with keys as STR inchi name for fragments and value as INT their coefficient """ frags = {} for atm in atm_vals: grai = (atms.copy(), bnd_ords.copy()) if (atms[atm][0] != 'H' or atm in site1 + site2): if atm in site1 + site2 and atm != site1[0]: continue coeff = 1.0 if not bal: if atm in site1 + site2: coeff = _coeff_for_extended_site(atms, adj_atms, site1 + site2) else: nonhyd_adj_atms = tsutil.remove_hyd_from_adj_atms( atms, adj_atms[atm]) coeff = (util.branch_point(nonhyd_adj_atms) * util.terminal_moiety(nonhyd_adj_atms)) if atm == site1[0]: key = 'ts_gra' extended_site = [*site1, *site2] else: key = 'exp_gra' extended_site = [atm] for site_atm in extended_site: for atm_x in adj_atms[site_atm]: if atm_x not in extended_site and atms[atm_x][0] != 'H': grai = cleave_group_and_saturate( grai, bnd_ords, site_atm, atm_x) grai = automol.graph.explicit(grai) frags = _add_frag_to_frags(key, coeff, grai, frags) frags = tsutil.simplify_gra_frags(frags) if bal: balance_ = util.balance_ts(gra, frags) balance_ = {k: v for k, v in balance_.items() if v} if balance_: frags = util.balance_frags_ts(gra, frags) frags = tsutil.simplify_gra_frags(frags) return frags
def _coeff_for_elim_sites(atm, atms, adj_atms, site1, site2): if atm in site1: nonhyd_adj_atms1 = tsutil.remove_hyd_from_adj_atms(atms, adj_atms[site1[1]], othersite=site2) nonhyd_adj_atms2 = tsutil.remove_hyd_from_adj_atms(atms, adj_atms[site2[2]], othersite=site1) nonhyd_adj_atms1 = tuple(adj for adj in nonhyd_adj_atms1 if adj not in site1) nonhyd_adj_atms2 = tuple(adj for adj in nonhyd_adj_atms2 if adj not in site2) coeff = (util.branch_point(nonhyd_adj_atms1, nonhyd_adj_atms2) * util.terminal_moiety(nonhyd_adj_atms1, nonhyd_adj_atms2)) else: nonhyd_adj_atms = tsutil.remove_hyd_from_adj_atms(atms, adj_atms[atm]) coeff = (util.branch_point(nonhyd_adj_atms) * util.terminal_moiety(nonhyd_adj_atms)) return coeff
def _coeff_for_rad_rad(atms, adj_atms, site1, site2): nonhyd_adj_atms1 = tsutil.remove_hyd_from_adj_atms( atms, adj_atms[site1[0]], site2, other_adj=adj_atms[site2[0]]) nonhyd_adj_atms2 = tsutil.remove_hyd_from_adj_atms( atms, adj_atms[site2[0]], site1, other_adj=adj_atms[site1[0]]) nonhyd_adj_atms1 = tuple(adj for adj in nonhyd_adj_atms1 if adj not in site1) nonhyd_adj_atms2 = tuple(adj for adj in nonhyd_adj_atms2 if adj not in site2) coeff = (util.branch_point(nonhyd_adj_atms1, nonhyd_adj_atms2) * util.terminal_moiety(nonhyd_adj_atms1, nonhyd_adj_atms2)) return coeff
def _coeff_for_ts_sites(atm, atms, adj_atms, site): if atm in site: nonhyd_adj_atms1 = tsutil.remove_hyd_from_adj_atms( atms, adj_atms[site[0]], site, other_adj=adj_atms[site[2]]) nonhyd_adj_atms2 = tsutil.remove_hyd_from_adj_atms( atms, adj_atms[site[2]], site, other_adj=adj_atms[site[0]]) nonhyd_adj_atms3 = [] for adj in adj_atms[site[0]]: if adj in adj_atms[site[2]]: nonhyd_adj_atms3 = tsutil.remove_hyd_from_adj_atms( atms, adj_atms[adj], othersite=site) coeff = (util.branch_point(nonhyd_adj_atms1, nonhyd_adj_atms2, nonhyd_adj_atms3) * util.terminal_moiety(nonhyd_adj_atms1, nonhyd_adj_atms2, nonhyd_adj_atms3, endisterm=False)) else: nonhyd_adj_atms = tsutil.remove_hyd_from_adj_atms(atms, adj_atms[atm]) coeff = (util.branch_point(nonhyd_adj_atms) * util.terminal_moiety(nonhyd_adj_atms)) return coeff
def cbhzed(ich, balance=True): """ Fragments molecule so that each heavy-atom is a seperate fragment INPUT: ich -- STR inchi name for molecule OUTPUT frags -- DIC dictionary with keys as STR inchi name for fragments and value as INT their coefficient """ # Graphical info about molecule gra = automol.inchi.graph(ich) rad_atms = list(automol.graph.sing_res_dom_radical_atom_keys(gra)) atm_vals = automol.graph.atom_element_valences(gra) atms = automol.graph.atoms(gra) adj_atms = automol.graph.atoms_neighbor_atom_keys(gra) # Determine CBHzed fragments frags = {} for atm in atm_vals: coeff = 1 if not balance: coeff = (util.branch_point(adj_atms[atm]) * util.terminal_moiety(adj_atms[atm])) if atm in rad_atms: atm_vals[atm] -= 1 atm_dic = {0: (atms[atm][0], int(atm_vals[atm]), None)} gra = (atm_dic, {}) frag = automol.graph.inchi(gra) util.add2dic(frags, frag, coeff) if balance: balance_ = util.balance(ich, frags) balance_ = {k: v for k, v in balance_.items() if v} if balance_: frags = util.balance_frags(ich, frags) return frags
def cbhtwo(ich, balance=True): """ Fragments molecule for each heavy-atom to stay bonded to its adjacent atoms INPUT: ich -- STR inchi name for molecule OUTPUT frags -- DIC dictionary with keys as STR inchi name for fragments and value as INT their coefficient """ # Graphical info about molecule gra = automol.inchi.graph(ich) atms = automol.graph.atoms(gra) bnd_ords = automol.graph.one_resonance_dominant_bond_orders(gra) rad_atms = list(automol.graph.sing_res_dom_radical_atom_keys(gra)) atm_vals = automol.graph.atom_element_valences(gra) adj_atms = automol.graph.atoms_neighbor_atom_keys(gra) # Determine CBHtwo fragments frags = {} for atm in atms: vali = atm_vals[atm] if atm in rad_atms: vali -= 1 # First loop over all atoms of this frag to get saturation of atomi for adj in list(adj_atms[atm]): key = frozenset({atm, adj}) bnd_ord = list(bnd_ords[key])[0] vali -= bnd_ord atm_dic = {0: (atms[atm][0], int(vali), None)} bnd_dic = {} # Then start adding bonds to the bnddic and atomdic j = 0 coeff = 1 if not balance: coeff = (util.branch_point(adj_atms[atm]) * util.terminal_moiety(adj_atms[atm])) for adj in list(adj_atms[atm]): j += 1 valj = atm_vals[adj] if adj in rad_atms: valj -= 1 key = frozenset({atm, adj}) bnd_ord = list(bnd_ords[key])[0] valj -= bnd_ord atm_dic[j] = (atms[adj][0], int(valj), None) bnd_dic[frozenset({0, j})] = (1, None) gra = (atm_dic, bnd_dic) frag = automol.graph.inchi(gra) util.add2dic(frags, frag, coeff) frags = {k: v for k, v in frags.items() if v} if not frags: frags = cbhone(frags) # Balance if balance: balance_ = util.balance(ich, frags) balance_ = {k: v for k, v in balance_.items() if v} if balance_: newfrags = frags.copy() onefrags = cbhone(ich, balance=False) for frag in onefrags: util.add2dic(newfrags, frag, -onefrags[frag]) frags = {k: v for k, v in newfrags.items() if v} balance_ = util.balance(ich, frags) balance_ = {k: v for k, v in balance_.items() if v} if balance_: newfrags = frags.copy() zedfrags = cbhzed(ich, balance=False) for frag in zedfrags: util.add2dic(newfrags, frag, zedfrags[frag]) frags = {k: v for k, v in newfrags.items() if v} balance_ = util.balance(ich, frags) balance_ = {k: v for k, v in balance_.items() if v} if balance_: frags = util.balance_frags(ich, frags) return frags
def cbhzed_habs(gra, site, bal=True): """ Fragments molecule so that each heavy-atom is a seperate fragment INPUT: ich -- STR inchi name for molecule OUTPUT frags -- DIC dictionary with keys as STR inchi name for fragments and value as INT their coefficient """ # Graphical info about molecule _, atms, bnd_ords, atm_vals, adj_atms = tsutil.ts_graph(gra, site) # Determine CBHzed fragments frags = {} for atm in atm_vals: if (atms[atm][0] != 'H' or atm in site): if atm in (site[1], site[2]): continue coeff = 1.0 if not bal: if atm in site: nonhyd_adj_atms1 = tsutil.remove_hyd_from_adj_atms( atms, adj_atms[site[0]], site, other_adj=adj_atms[site[2]]) nonhyd_adj_atms2 = tsutil.remove_hyd_from_adj_atms( atms, adj_atms[site[2]], site, other_adj=adj_atms[site[0]]) nonhyd_adj_atms3 = [] for adj in adj_atms[site[0]]: if adj in adj_atms[site[2]]: nonhyd_adj_atms3 = tsutil.remove_hyd_from_adj_atms( atms, adj_atms[adj], othersite=site) coeff = ( util.branch_point( nonhyd_adj_atms1, nonhyd_adj_atms2, nonhyd_adj_atms3) * util.terminal_moiety( nonhyd_adj_atms1, nonhyd_adj_atms2, nonhyd_adj_atms3, endisterm=False) ) else: nonhyd_adj_atms = tsutil.remove_hyd_from_adj_atms( atms, adj_atms[atm]) coeff = ( util.branch_point(nonhyd_adj_atms) * util.terminal_moiety(nonhyd_adj_atms) ) if atm == site[0]: key1 = [site[0], site[1]] key1.sort() key = frozenset({*key1}) bnd_ord1 = list(bnd_ords[key])[0] atm_dic = {0: (atms[atm][0], atm_vals[atm]-bnd_ord1, None)} bnd_dct = {frozenset({0, 1}): (bnd_ord1, None)} key1 = [site[2], site[1]] key1.sort() key = frozenset({*key1}) bnd_ord2 = list(bnd_ords[key])[0] atm_dic[2] = ( atms[site[2]][0], atm_vals[site[2]]-bnd_ord2, None) atm_dic[1] = ( atms[site[1]][0], atm_vals[site[1]]-bnd_ord1-bnd_ord2, None) bnd_dct[frozenset({1, 2})] = (bnd_ord2, None) else: bnd_dct = {} atm_dic = {0: (atms[atm][0], int(atm_vals[atm]), None)} grai = (atm_dic, bnd_dct) try: grai = automol.graph.explicit(grai) key = 'exp_gra' except: key = 'ts_gra' newname = None repeat = False for name in frags: if key in frags[name]: if automol.graph.full_isomorphism(frags[name][key], grai): newname = name repeat = True if not repeat: newname = len(frags.keys()) frags[newname] = {} frags[newname][key] = grai util.add2dic(frags[newname], 'coeff', coeff) frags = tsutil.simplify_gra_frags(frags) if bal: balance_ = util.balance_ts(gra, frags) balance_ = {k: v for k, v in balance_.items() if v} if balance_: frags = util.balance_frags_ts(gra, frags) frags = tsutil.simplify_gra_frags(frags) return frags