示例#1
0
def hydrogen_abstraction(xgr1, xgr2):
    """ find an addition transformation
    """
    assert xgr1 == _explicit(xgr1) and xgr2 == _explicit(xgr2)

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

    ret = formula.reac.argsort_hydrogen_abstraction(
        list(map(convert.graph.formula, xgrs1)),
        list(map(convert.graph.formula, xgrs2)))
    if ret is not None:
        idxs1, idxs2 = ret
        q1h_xgr, q2_xgr = list(map(xgrs1.__getitem__, idxs1))
        q1_xgr, q2h_xgr = list(map(xgrs2.__getitem__, idxs2))
        q1_tra = _partial_hydrogen_abstraction(q1h_xgr, q1_xgr)
        q2_rev_tra = _partial_hydrogen_abstraction(q2h_xgr, q2_xgr)
        if q1_tra and q2_rev_tra:
            xgr1_ = _union(apply(q1_tra, q1h_xgr), q2_xgr)
            xgr2_ = _union(q1_xgr, q2h_xgr)

            q2_tra = _reverse(q2_rev_tra, xgr2_, xgr1_)
            tra = from_data('hydrogen abstraction',
                            frm_bnd_keys=formed_bond_keys(q2_tra),
                            brk_bnd_keys=broken_bond_keys(q1_tra))

    return tra
示例#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 insertion(xgr1, xgr2):
    """ find an insertion transformation
    """
    assert xgr1 == _explicit(xgr1) and xgr2 == _explicit(xgr2)

    tra = None
    idxs = None
    xgrs1 = _connected_components(xgr1)
    xgrs2 = _connected_components(xgr2)
    if len(xgrs1) == 2 and len(xgrs2) == 1:
        xgra, xgrb = xgrs1
        atmsa = atoms(xgra)
        atmsb = atoms(xgrb)
        neighsa = atom_neighbor_keys(xgra)
        neighsb = atom_neighbor_keys(xgrb)
        bndsa = bond_keys(xgra)
        bndsb = bond_keys(xgrb)
        tra = _insertion(atmsa, neighsa, bndsa, atmsb, neighsb, xgr1, xgr2)
        idxs = [0, 1]
        if not tra:
            tra = _insertion(atmsb, neighsb, bndsb, atmsa, neighsa, xgr1, xgr2)
            if tra:
                idxs = [1, 0]
            else:
                idxs = None
    elif len(xgrs1) == 1 and len(xgrs2) == 1:
        xgra = xgr1
        idxs = [0]
        atmsa = atoms(xgra)
        neighsa = atom_neighbor_keys(xgra)
        bndsa = bond_keys(xgra)
        tra = _insertion(atmsa, neighsa, bndsa, atmsa, neighsa, xgr1, xgr2)
    return tra, idxs
示例#4
0
def insertion(xgr1, xgr2):
    """ find an insertion transformation
    """
    assert xgr1 == _explicit(xgr1) and xgr2 == _explicit(xgr2)

    tra = None
    idxs = None
    xgrs1 = _connected_components(xgr1)
    xgrs2 = _connected_components(xgr2)
    if len(xgrs1) == 2 and len(xgrs2) == 1:
        xgrA, xgrB = xgrs1
        atmsA = automol.graph.atoms(xgrA)
        atmsB = automol.graph.atoms(xgrB)
        neighsA = automol.graph.atom_neighbor_keys(xgrA)
        neighsB = automol.graph.atom_neighbor_keys(xgrB)
        bndsA = automol.graph.bond_keys(xgrA)
        bndsB = automol.graph.bond_keys(xgrB)
        tra = _insertion(atmsA, neighsA, bndsA, atmsB, neighsB, xgr1, xgr2)
        idxs = [0, 1]
        if not tra:
            tra = _insertion(atmsB, neighsB, bndsB, atmsA, neighsA, xgr1, xgr2)
            if tra:
                idxs = [1, 0]
            else:
                idxs = None
    elif len(xgrs1) == 1 and len(xgrs2) == 1:
        xgrA = xgr1
        idxs = [0]
        atmsA = automol.graph.atoms(xgrA)
        neighsA = automol.graph.atom_neighbor_keys(xgrA)
        bndsA = automol.graph.bond_keys(xgrA)
        tra = _insertion(atmsA, neighsA, bndsA, atmsA, neighsA, xgr1, xgr2)
    return tra, idxs
示例#5
0
def proton_migration(xgr1, xgr2):
    """ find a proton migration transformation
    """
    assert xgr1 == _explicit(xgr1) and xgr2 == _explicit(xgr2)

    tras = []
    xgrs1 = _connected_components(xgr1)
    xgrs2 = _connected_components(xgr2)

    h_atm_key1 = max(_atom_keys(xgr1)) + 1
    h_atm_key2 = max(_atom_keys(xgr2)) + 1

    if len(xgrs1) == 1 and len(xgrs2) == 1:
        xgr1, = xgrs1
        xgr2, = xgrs2
        atm_keys1 = _unsaturated_atom_keys(xgr1)
        atm_keys2 = _unsaturated_atom_keys(xgr2)
        for atm_key1, atm_key2 in itertools.product(atm_keys1, atm_keys2):
            xgr1_h = _add_atom_explicit_hydrogen_keys(xgr1,
                                                      {atm_key1: [h_atm_key1]})
            xgr2_h = _add_atom_explicit_hydrogen_keys(xgr2,
                                                      {atm_key2: [h_atm_key2]})

            inv_atm_key_dct = _full_isomorphism(xgr2_h, xgr1_h)
            if inv_atm_key_dct:
                tras.append(
                    from_data(
                        frm_bnd_keys=[{atm_key1, inv_atm_key_dct[h_atm_key2]}],
                        brk_bnd_keys=[{
                            inv_atm_key_dct[atm_key2],
                            inv_atm_key_dct[h_atm_key2]
                        }]))
    if len(tras) < 1:
        tras = None
    return tras
示例#6
0
def substitution(xgr1, xgr2):
    """identifies substitution reactions
    """
    assert xgr1 == _explicit(xgr1) and xgr2 == _explicit(xgr2)

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

    print('len xgrs test:', len(xgrs1), len(xgrs2))
    print('xgrs test:', xgrs1, xgrs2)

    if len(xgrs1) == 2 and len(xgrs2) == 2:
        xgra, xgrb = xgrs1
        xgrc, xgrd = xgrs2
        atmsa = atoms(xgra)
        neighsa = atom_neighbor_keys(xgra)
        bndsa = bond_keys(xgra)
        atmsb = atoms(xgrb)
        neighsb = atom_neighbor_keys(xgrb)
        bndsb = bond_keys(xgrb)
        atmsc = atoms(xgrc)
        neighsc = atom_neighbor_keys(xgrc)
        bndsc = bond_keys(xgrc)
        atmsd = atoms(xgrd)
        neighsd = atom_neighbor_keys(xgrd)
        bndsd = bond_keys(xgrd)
        tra = _substitution(atmsa, neighsa, bndsa, atmsb, xgr1, xgr2)
        # tra = _substitution(
        # atmsa, neighsa, bndsa, atmsb, neighsb, xgr1, xgr2)
        idxs = [[0, 1], [0, 1]]
        if not tra:
            tra = _substitution(atmsb, neighsb, bndsb, atmsa, xgr1, xgr2)
            # atmsb, neighsb, bndsb, atmsa, neighsa, xgr1, xgr2)
            idxs = [[0, 1], [1, 0]]
            if not tra:
                tra = _substitution(atmsc, neighsc, bndsc, atmsd, xgr2, xgr1)
                # atmsc, neighsc, bndsc, atmsd, neighsd, xgr2, xgr1)
                idxs = [[1, 0], [0, 1]]
                if not tra:
                    tra = _substitution(atmsd, neighsd, bndsd, atmsc, xgr2,
                                        xgr1)
                    # atmsd, neighsd, bndsd, atmsc, neighsc, xgr2, xgr1)
                    idxs = [[1, 0], [1, 0]]
                    if not tra:
                        idxs = None

        # return not substitution for radical + unsaturated reactions
        unsat_atm_keys = _unsaturated_atom_keys(xgra)
        # print('unsat test:', tra[0][0], unsat_atm_keys)
        tra_list = list(tra[0])
        for key in unsat_atm_keys:
            if key in tra_list[0]:
                pass
                # tra = None
                # commented out the tra = None and added pass to run CO + HO2

    return tra, idxs
示例#7
0
def substitution(xgr1, xgr2):
    """identifies substitution reactions
    """
    assert xgr1 == _explicit(xgr1) and xgr2 == _explicit(xgr2)

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

    if len(xgrs1) == 2 and len(xgrs2) == 2:
        xgrA, xgrB = xgrs1
        xgrC, xgrD = xgrs2
        atmsA = automol.graph.atoms(xgrA)
        neighsA = automol.graph.atom_neighbor_keys(xgrA)
        bndsA = automol.graph.bond_keys(xgrA)
        atmsB = automol.graph.atoms(xgrB)
        neighsB = automol.graph.atom_neighbor_keys(xgrB)
        bndsB = automol.graph.bond_keys(xgrB)
        atmsC = automol.graph.atoms(xgrC)
        neighsC = automol.graph.atom_neighbor_keys(xgrC)
        bndsC = automol.graph.bond_keys(xgrC)
        atmsD = automol.graph.atoms(xgrD)
        neighsD = automol.graph.atom_neighbor_keys(xgrD)
        bndsD = automol.graph.bond_keys(xgrD)
        tra = _substitution(atmsA, neighsA, bndsA, atmsB, neighsB, xgr1, xgr2)
        idxs = [[0, 1], [0, 1]]
        if not tra:
            tra = _substitution(atmsB, neighsB, bndsB, atmsA, neighsA, xgr1,
                                xgr2)
            idxs = [[0, 1], [1, 0]]
            if not tra:
                tra = _substitution(atmsC, neighsC, bndsC, atmsD, neighsD,
                                    xgr2, xgr1)
                idxs = [[1, 0], [0, 1]]
                if not tra:
                    tra = _substitution(atmsD, neighsD, bndsD, atmsC, neighsC,
                                        xgr2, xgr1)
                    idxs = [[1, 0], [1, 0]]
                    if not tra:
                        idxs = None

        # return not substitution for radical + unsaturated reactions
        unsat_atm_keys = automol.graph.unsaturated_atom_keys(xgrB)
        for key in unsat_atm_keys:
            if key in tra[0]:
                tra = None

    return tra, idxs
示例#8
0
def _atom_coordinates(sgr):
    """ non-stereo-specific coordinates for a molecular graph
    """
    atm_xyz_dct = {}
    for idx, cnn_sgr in enumerate(_connected_components(sgr)):
        shift = 20. * idx
        cnn_atm_xyz_dct = _connected_graph_atom_coordinates(cnn_sgr)
        atm_keys = list(cnn_atm_xyz_dct.keys())
        atm_xyzs = numpy.array(list(cnn_atm_xyz_dct.values()))
        atm_xyzs += numpy.array([0., 0., shift])
        atm_xyz_dct.update(dict(zip(atm_keys, map(tuple, atm_xyzs))))
    return atm_xyz_dct
示例#9
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
示例#10
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 = automol.graph.atoms(xgr1)
        neighs = automol.graph.atom_neighbor_keys(xgr1)
        bnds = automol.graph.bond_keys(xgr1)
        lonepairs = automol.graph.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 = automol.graph.remove_bonds(xgr1, [bnd_break_key_ij])
                new_xgrs = _connected_components(new_xgr)
                if len(new_xgrs) == 2:
                    xgrA, xgrB = new_xgrs
                    atmsA = automol.graph.atoms(xgrA)
                    if atmi not in atmsA.keys():
                        xgrB, xgrA = xgrA, xgrB
                        atmsA = automol.graph.atoms(xgrA)
                    neighsA = automol.graph.atom_neighbor_keys(xgrA)
                    atmsB = automol.graph.atoms(xgrB)
                    neighs_i = neighsA[atmi]
                    for atmk in atmsB:
                        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 = automol.graph.remove_bonds(
                                        new_xgr, [bnd_break_key_il])
                                    newnew_xgr = automol.graph.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 = automol.graph.remove_bonds(
                                            new_xgr, [bnd_break_key_lm])
                                        newnew_xgr = automol.graph.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