Exemplo n.º 1
0
def _radical_graph_isomorphisms(gra):
    """ Generate a set of graphs where the radical has been migrated to a
        new atom and then calculate the isomorphism between the input
        graph and all of the new graphs generated by moving the radical
    """

    # Determine useful keys
    symbols = atom_symbols(gra)
    unsat_keys = unsaturated_atom_keys(gra)
    unsat_key = next(iter(unsat_keys))
    h_atm_key = max(symbols.keys()) + 1

    new_gras, isomorphisms = [], []
    for aidx, symbol in enumerate(symbols.values()):

        # Loop over saturated (non-radical) heavy atoms
        if symbol != 'H' and aidx != unsat_key:

            # Add hydrogen atom to radical atom
            new_graph = add_atom_explicit_hydrogen_keys(
                gra, {unsat_key: [h_atm_key]})

            # Remove hydrogen from saturated atom
            neighbors = atoms_neighbor_atom_keys(new_graph)
            for neigh in neighbors[aidx]:
                if symbols[neigh] == 'H':
                    aneighbor = neigh
                    break
            new_graph = remove_atoms(new_graph, [aneighbor])

            # Build lists to return
            new_gras.append(new_graph)
            isomorphisms.append(full_isomorphism(gra, new_graph))

    return tuple(zip(new_gras, isomorphisms))
Exemplo n.º 2
0
def _shift_remove_dummy_atom(gra, dummy_key):
    keys = sorted(automol.graph.atom_keys(gra))
    idx = keys.index(dummy_key)
    key_dct = {}
    key_dct.update({k: k for k in keys[:idx]})
    key_dct.update({k: k - 1 for k in keys[(idx + 1):]})
    gra = remove_atoms(gra, [dummy_key])
    gra = relabel(gra, key_dct)
    return gra
Exemplo n.º 3
0
def radical_dissociation_prods(gra, pgra1):
    """ given a dissociation product, determine the other product
    """
    gra = without_fractional_bonds(gra)

    pgra2 = None
    rads = sing_res_dom_radical_atom_keys(gra)
    adj_atms = atoms_neighbor_atom_keys(gra)
    # adj_idxs = tuple(adj_atms[rad] for rad in rads)
    for rad in rads:
        for adj in adj_atms[rad]:
            for group in atom_groups(gra, adj):
                if full_isomorphism(explicit(group), explicit(pgra1)):
                    pgra2 = remove_atoms(gra, atom_keys(group))
                    # pgra2 = remove_bonds(pgra2, bond_keys(group))
                    if bond_keys(group) in pgra2:
                        pgra2 = remove_bonds(pgra2, bond_keys(group))
    return (pgra1, pgra2)
Exemplo n.º 4
0
def standard_keys_without_dummy_atoms(gra):
    """ remove dummy atoms and standardize keys, returning the dummy key
    dictionary for converting back

    Requires that graph follows z-matrix ordering (this is checked)
    """
    dummy_ngb_key_dct = dummy_atoms_neighbor_atom_key(gra)

    dummy_keys_dct = {}
    last_dummy_key = -1
    decr = 0
    for dummy_key, key in sorted(dummy_ngb_key_dct.items()):
        assert last_dummy_key <= key, (
            "{:d} must follow previous dummy {:d}".format(key, last_dummy_key))

        dummy_keys_dct[key - decr] = dummy_key - decr
        gra = remove_atoms(gra, [dummy_key])

        decr += 1
        last_dummy_key = dummy_key - decr

    gra = standard_keys(gra)
    return gra, dummy_keys_dct
Exemplo n.º 5
0
def chem_unique_atoms_of_type(gra, symb):
    """ For the given atom type, determine the idxs of all the
         chemically unique atoms.

        :param gra: molecular graph
        :type gra: molecular graph data structure
        :param symb: atomic symbol to determine symbols for
        :type symb: str
        :rtype: tuple(int)
    """

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

    # 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