示例#1
0
def cbhone(ich, balance=True):
    """
    Fragments molecule in a way that conserves each heavy-atom/heavy-atom bond
    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 CBHone fragments
    frags = {}
    for atm in atm_vals:
        for adj in list(adj_atms[atm]):
            if atm > adj:
                vali = atm_vals[atm]
                valj = atm_vals[adj]
                if atm in rad_atms:
                    vali -= 1
                if adj in rad_atms:
                    valj -= 1
                key = frozenset({atm, adj})
                bnd_ord = list(bnd_ords[key])[0]
                vali -= bnd_ord
                valj -= bnd_ord
                atm_dic = {
                    0: (atms[atm][0], int(vali), None),
                    1: (atms[adj][0], int(valj), None)
                }
                bnd_dic = {frozenset({0, 1}): (1, None)}
                gra = (atm_dic, bnd_dic)
                frag = automol.graph.inchi(gra)
                util.add2dic(frags, frag)
    frags = {k: v for k, v in frags.items() if v}
    if not frags:
        frags = cbhzed(ich)
    # Balance
    if balance:
        balance_ = util.balance(ich, frags)
        balance_ = {k: v for k, v in balance_.items() if v}
        if balance_:
            zedfrags = cbhzed(ich, balance=False)
            newfrags = frags.copy()
            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
示例#2
0
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
示例#3
0
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