Пример #1
0
def graph(gra, frm_bnd_keys, brk_bnd_keys):
    """ generate a transition-state graph
    """
    frm_bnd_keys = frozenset(map(frozenset, frm_bnd_keys))
    brk_bnd_keys = frozenset(map(frozenset, brk_bnd_keys))

    frm_ord_dct = {k: 0.1 for k in frm_bnd_keys}
    brk_ord_dct = {k: 0.9 for k in brk_bnd_keys}

    tsg = add_bonds(gra, frm_bnd_keys, ord_dct=frm_ord_dct, check=False)
    tsg = add_bonds(tsg, brk_bnd_keys, ord_dct=brk_ord_dct, check=False)
    return tsg
Пример #2
0
def addition(xgr1, xgr2):
    """ find an addition transformation
    """
    assert xgr1 == _explicit(xgr1) and xgr2 == _explicit(xgr2)

    tra = None
    xgrs1 = _connected_components(xgr1)
    xgrs2 = _connected_components(xgr2)

    if len(xgrs1) == 2 and len(xgrs2) == 1:
        x_xgr, y_xgr = xgrs1
        xgr2, = xgrs2
        x_atm_keys = _unsaturated_atom_keys(x_xgr)
        y_atm_keys = _unsaturated_atom_keys(y_xgr)
        # xgeo = geometry(xgr2)
        for x_atm_key, y_atm_key in itertools.product(x_atm_keys, y_atm_keys):
            xy_xgr = add_bonds(_union(x_xgr, y_xgr), [{x_atm_key, y_atm_key}])

            # xgeo = geometry(xy_xgr)
            atm_key_dct = _full_isomorphism(xy_xgr, xgr2)
            if atm_key_dct:
                tra = from_data('addition',
                                frm_bnd_keys=[{x_atm_key, y_atm_key}],
                                brk_bnd_keys=[])

    return tra
Пример #3
0
def apply(tra, xgr):
    """ apply this transformation to a graph
    """
    brk_bnd_keys = broken_bond_keys(tra)
    frm_bnd_keys = formed_bond_keys(tra)
    # in case some bonds are broken *and* formed, we subtract the other set
    xgr = remove_bonds(xgr, brk_bnd_keys - frm_bnd_keys)
    xgr = add_bonds(xgr, frm_bnd_keys - brk_bnd_keys)
    return xgr
Пример #4
0
def _substitution(atmsa, neighsa, bndsa, atmsb, xgr1, xgr2):
    ret_tra = None
    for atmi in atmsa:
        if _is_heavy(atmi, atmsa):
            i_neighs = neighsa[atmi]
            for atmj in i_neighs:
                bnd_break_key_ij = _get_bnd_key(atmi, atmj, bndsa)
                new_xgr = remove_bonds(xgr1, [bnd_break_key_ij])
                for atmk in atmsb:
                    if atmk not in (atmi, atmj):
                        bnd_form_key_ik = frozenset({atmi, atmk})
                        newnew_xgr = add_bonds(new_xgr, [bnd_form_key_ik])
                        atm_key_dct = _full_isomorphism(newnew_xgr, xgr2)
                        if atm_key_dct:
                            tra = [[bnd_form_key_ik], [bnd_break_key_ij]]
                            ret_tra = tra
    return ret_tra
Пример #5
0
def add_bonded_atom(gra,
                    sym,
                    atm_key,
                    bnd_atm_key=None,
                    imp_hyd_vlc=None,
                    atm_ste_par=None,
                    bnd_ord=None,
                    bnd_ste_par=None):
    """ add a single atom with a bond to an atom already in the graph
    """
    atm_keys = atom_keys(gra)

    bnd_atm_key = max(atm_keys) + 1 if bnd_atm_key is None else bnd_atm_key

    symb_dct = {bnd_atm_key: sym}
    imp_hyd_vlc_dct = ({
        bnd_atm_key: imp_hyd_vlc
    } if imp_hyd_vlc is not None else None)
    atm_ste_par_dct = ({
        bnd_atm_key: atm_ste_par
    } if atm_ste_par is not None else None)

    gra = add_atoms(gra,
                    symb_dct,
                    imp_hyd_vlc_dct=imp_hyd_vlc_dct,
                    ste_par_dct=atm_ste_par_dct)

    bnd_key = frozenset({bnd_atm_key, atm_key})
    bnd_ord_dct = {bnd_key: bnd_ord} if bnd_ord is not None else None
    bnd_ste_par_dct = ({
        bnd_key: bnd_ste_par
    } if bnd_ste_par is not None else None)

    gra = add_bonds(gra, [bnd_key],
                    ord_dct=bnd_ord_dct,
                    ste_par_dct=bnd_ste_par_dct)

    return gra
Пример #6
0
def _insertion(atmsa, neighsa, bndsa, atmsb, neighsb, xgr1, xgr2):
    """Do the insertion for an order of reactants
    """
    ret_tra = None
    for i in atmsa:
        if _is_heavy(i, atmsa):
            i_neighs = neighsa[i]
            for j in i_neighs:
                bnd_break_key_ij = _get_bnd_key(i, j, bndsa)
                new_xgr = remove_bonds(xgr1, [bnd_break_key_ij])
                for k in atmsb:
                    if _is_heavy(k, atmsb) and (k != i and k != j
                                                and i not in neighsb[k]
                                                and j not in neighsb[k]):
                        bnd_form_key_ik = {i, k}
                        bnd_form_key_jk = {j, k}
                        newnew_xgr = add_bonds(
                            new_xgr, [bnd_form_key_ik, bnd_form_key_jk])
                        atm_key_dct = _full_isomorphism(newnew_xgr, xgr2)
                        if atm_key_dct:
                            tra = [[bnd_form_key_ik, bnd_form_key_jk],
                                   [bnd_break_key_ij]]
                            ret_tra = tra
    return ret_tra
Пример #7
0
def elimination(xgr1, xgr2):
    """identifies elimination reactions
    """
    assert xgr1 == _explicit(xgr1) and xgr2 == _explicit(xgr2)
    tra = None
    xgrs1 = _connected_components(xgr1)
    xgrs2 = _connected_components(xgr2)
    tras = []
    if len(xgrs1) == 1 and len(xgrs2) == 2:
        atms = atoms(xgr1)
        neighs = atom_neighbor_keys(xgr1)
        bnds = bond_keys(xgr1)
        radicals = _resonance_dominant_radical_atom_keys(xgr1)
        lonepairs = atom_lone_pair_counts(xgr1)
        for atmi in atms:
            i_neighs = neighs[atmi]
            for atmj in i_neighs:
                bnd_break_key_ij = _get_bnd_key(atmi, atmj, bnds)
                new_xgr = remove_bonds(xgr1, [bnd_break_key_ij])
                new_xgrs = _connected_components(new_xgr)
                if len(new_xgrs) == 2:
                    xgra, xgrb = new_xgrs
                    atmsa = atoms(xgra)
                    if atmi not in atmsa.keys():
                        xgrb, xgra = xgra, xgrb
                        atmsa = atoms(xgra)
                    neighsa = atom_neighbor_keys(xgra)
                    atmsb = atoms(xgrb)
                    neighs_i = neighsa[atmi]
                    for atmk in atmsb:
                        if atmk in radicals:
                            for atml in neighs_i:
                                neighs_l = neighsa[atml]
                                if atml != atmj:
                                    bnd_break_key_il = _get_bnd_key(
                                        atmi, atml, bnds)
                                    bnd_form_key_kl = frozenset({atmk, atml})
                                    newnew_xgr = remove_bonds(
                                        new_xgr, [bnd_break_key_il])
                                    newnew_xgr = add_bonds(
                                        newnew_xgr, [bnd_form_key_kl])
                                    atm_key_dct = _full_isomorphism(
                                        newnew_xgr, xgr2)
                                    if atm_key_dct:
                                        tra = [[bnd_form_key_kl],
                                               [
                                                   bnd_break_key_ij,
                                                   bnd_break_key_il
                                               ]]
                                        return tra
                                for atmm in neighs_l:
                                    if atmm != atmi:
                                        bnd_break_key_lm = _get_bnd_key(
                                            atml, atmm, bnds)
                                        bnd_form_key_km = frozenset(
                                            {atmk, atmm})
                                        newnew_xgr = remove_bonds(
                                            new_xgr, [bnd_break_key_lm])
                                        newnew_xgr = add_bonds(
                                            newnew_xgr, [bnd_form_key_km])
                                        atm_key_dct = _full_isomorphism(
                                            newnew_xgr, xgr2)
                                        if atm_key_dct:
                                            tras.append([[bnd_form_key_km],
                                                         [
                                                             bnd_break_key_ij,
                                                             bnd_break_key_lm
                                                         ]])
        for atmi in atms:
            i_neighs = neighs[atmi]
            print('atmi test:', atmi)
            print('i_neighs test:', i_neighs)
            for atmj in i_neighs:
                bnd_break_key_ij = _get_bnd_key(atmi, atmj, bnds)
                new_xgr = remove_bonds(xgr1, [bnd_break_key_ij])
                new_xgrs = _connected_components(new_xgr)
                if len(new_xgrs) == 2:
                    xgra, xgrb = new_xgrs
                    atmsa = atoms(xgra)
                    if atmi not in atmsa.keys():
                        xgrb, xgra = xgra, xgrb
                        atmsa = atoms(xgra)
                    neighsa = atom_neighbor_keys(xgra)
                    atmsb = atoms(xgrb)
                    neighs_i = neighsa[atmi]
                    print('len atmsb test:', len(atmsb))
                    for atmk in atmsb:
                        if lonepairs[atmk] > 0 or len(atmsb) == 1:
                            # if lonepairs[atmk] > 0:
                            for atml in neighs_i:
                                neighs_l = neighsa[atml]
                                if atml != atmj:
                                    bnd_break_key_il = _get_bnd_key(
                                        atmi, atml, bnds)
                                    bnd_form_key_kl = frozenset({atmk, atml})
                                    newnew_xgr = remove_bonds(
                                        new_xgr, [bnd_break_key_il])
                                    newnew_xgr = add_bonds(
                                        newnew_xgr, [bnd_form_key_kl])
                                    atm_key_dct = _full_isomorphism(
                                        newnew_xgr, xgr2)
                                    if atm_key_dct:
                                        tra = [[bnd_form_key_kl],
                                               [
                                                   bnd_break_key_ij,
                                                   bnd_break_key_il
                                               ]]
                                        return tra
                                for atmm in neighs_l:
                                    if atmm != atmi:
                                        bnd_break_key_lm = _get_bnd_key(
                                            atml, atmm, bnds)
                                        bnd_form_key_km = frozenset(
                                            {atmk, atmm})
                                        newnew_xgr = remove_bonds(
                                            new_xgr, [bnd_break_key_lm])
                                        newnew_xgr = add_bonds(
                                            newnew_xgr, [bnd_form_key_km])
                                        atm_key_dct = _full_isomorphism(
                                            newnew_xgr, xgr2)
                                        if atm_key_dct:
                                            tras.append([[bnd_form_key_km],
                                                         [
                                                             bnd_break_key_ij,
                                                             bnd_break_key_lm
                                                         ]])
    if len(tras) < 1:
        tras = None
    return tras