コード例 #1
0
ファイル: _func_group.py プロジェクト: kevinmooreiii/autochem
def two_bond_idxs(gra, asymb1='H', cent='C', asymb2='H'):
    """ Determine triplet of idxs for describing bond

        idxs = (asymb1_idx, cent_idx, asymb2_idx)
    """

    grps = tuple()

    neigh_dct = atom_neighbor_keys(gra)
    idx_symb_dct = atom_symbols(gra)
    symb_idx_dct = atom_symbol_idxs(gra)

    cent_idxs = symb_idx_dct.get(cent, tuple())
    for cent_idx in cent_idxs:
        neighs = tuple(neigh_dct[cent_idx])
        neigh_symbs = atom_idx_to_symb(neighs, idx_symb_dct)
        if neigh_symbs == (asymb1, asymb2):
            grp_idxs = (neighs[0], cent_idx, neighs[1])
        elif neigh_symbs == (asymb2, asymb1):
            grp_idxs = (neighs[1], cent_idx, neighs[0])
        else:
            grp_idxs = ()

        if grp_idxs:
            grps += ((grp_idxs),)

    return grps
コード例 #2
0
ファイル: _func_group.py プロジェクト: kevinmooreiii/autochem
def chem_unique_atoms_of_type(gra, asymb):
    """ For the given atom type, determine the idxs of all the
         chemically unique atoms.
    """

    # Get the indices for the atom type
    symb_idx_dct = atom_symbol_idxs(gra)
    atom_idxs = symb_idx_dct[asymb]

    # Loop over each idx
    uni_idxs = tuple()
    uni_del_gras = []
    for idx in atom_idxs:

        # Remove the atom from the graph
        del_gra = remove_atoms(gra, [idx])

        # Test if the del_gra is isomorphic to any of the uni_del_gras
        new_uni = True
        for uni_del_gra in uni_del_gras:
            iso_dct = full_isomorphism(del_gra, uni_del_gra)
            if iso_dct:
                new_uni = False
                break

        # Add graph and idx to lst if del gra is unique
        if new_uni:
            uni_del_gras.append(del_gra)
            uni_idxs += (idx,)

    return uni_idxs
コード例 #3
0
ファイル: _func_group.py プロジェクト: sjklipp/autochem
def _unique_atoms(gra):
    """ Determine the symbols of unique atom types.

        :param gra: molecular graph
        :type gra: molecular graph data structure
        :rtype: tuple(str)
    """

    symb_idx_dct = atom_symbol_idxs(gra)

    return tuple(symb_idx_dct.keys())
コード例 #4
0
def _prod_group_loss(gra, grp='H'):
    """ products of hydrogen loss. Need to generalize to group loss
    """

    prod_gras = tuple()

    symb_idx_dct = atom_symbol_idxs(gra)
    h_idxs = symb_idx_dct[grp]

    for idx in h_idxs:
        prod_gras += ((remove_atoms(gra, [idx]), ), )

    return _unique_gras(prod_gras)
コード例 #5
0
ファイル: _func_group.py プロジェクト: kevinmooreiii/autochem
def halide_groups(gra):
    """ Determine the location of halide groups
    """

    hal_grps = tuple()

    symb_idx_dct = atom_symbol_idxs(gra)

    for symb in ('F', 'Cl', 'Br', 'I'):
        hal_idxs = symb_idx_dct.get(symb, ())
        for hal_idx in hal_idxs:
            hal_neighs = neighbors_of_type(gra, hal_idx, asymb='C')
            hal_grps += ((hal_neighs[0], hal_idx),)

    return hal_grps
コード例 #6
0
ファイル: _func_group.py プロジェクト: sjklipp/autochem
def halide_groups(gra):
    """ Determine the location of halide groups. The locations are
        specified as tuple-of-tuple of idxs indicating the C-X atoms
        of the group: (C-idx, X-idx).

        :param gra: molecular graph
        :type gra: molecular graph data structure
        :rtype: tuple(int)
    """

    hal_grps = tuple()

    symb_idx_dct = atom_symbol_idxs(gra)

    for symb in ('F', 'Cl', 'Br', 'I'):
        hal_idxs = symb_idx_dct.get(symb, ())
        for hal_idx in hal_idxs:
            hal_neighs = neighbors_of_type(gra, hal_idx, symb='C')
            hal_grps += ((hal_neighs[0], hal_idx), )

    return hal_grps
コード例 #7
0
ファイル: _func_group.py プロジェクト: sjklipp/autochem
def two_bond_idxs(gra, symb1, cent, symb2):
    """ Determine the triplet of indices of atoms of specified
        types that are connected in a chain by two bonds:
        (symb1_idx, cent_idx, symb2_idx).

        :param gra: molecular graph
        :type gra: molecular graph data structure
        :param symb1: symbol of atom at one end of chain
        :type symb1: str
        :param cent: symbol of atom in the middle of a chain
        :type cent: str
        :param symb2: symbol of atom at other end of chain
        :type symb2: str
    """

    grps = tuple()

    neigh_dct = atoms_neighbor_atom_keys(gra)
    idx_symb_dct = atom_symbols(gra)
    symb_idx_dct = atom_symbol_idxs(gra)

    cent_idxs = symb_idx_dct.get(cent, tuple())
    for cent_idx in cent_idxs:
        neighs = tuple(neigh_dct[cent_idx])
        neigh_symbs = atom_idx_to_symb(neighs, idx_symb_dct)
        if neigh_symbs == (symb1, symb2):
            grp_idxs = (neighs[0], cent_idx, neighs[1])
        elif neigh_symbs == (symb2, symb1):
            grp_idxs = (neighs[1], cent_idx, neighs[0])
        else:
            grp_idxs = ()

        if grp_idxs:
            grps += ((grp_idxs), )

    return grps
コード例 #8
0
ファイル: _func_group.py プロジェクト: kevinmooreiii/autochem
def _unique_atoms(gra):
    """ Determine the symbols of unique atom types
    """
    symb_idx_dct = atom_symbol_idxs(gra)

    return tuple(symb_idx_dct.keys())