from collections import defaultdict


def _match_terminal_real_and_dummy_atoms(
    mol, real_atoms_cc: list, dummy_atoms_cc: list
):
    """
    Matches the terminal real and dummy atoms and returns a dict with real atom idx as key and a set of dummy atoms that connect
    to this real atom as a set
    Parameters
    ----------
    mol : [Chem.Mol]
        The mol object with the real and dummy atoms
    real_atoms_cc : list
        list of real atom idx
    dummy_atoms_cc : list
        list of dummy atom idx

    Returns
    -------
    [type]
        [description]
    """


    real_atom_match_dummy_atom = defaultdict(set)
    for real_atom_idx in real_atoms_cc:
        real_atom = mol.GetAtomWithIdx(real_atom_idx)
        real_neighbors = [x.GetIdx() for x in real_atom.GetNeighbors()]
        for dummy_atoms_idx in dummy_atoms_cc:
            if dummy_atoms_idx in real_neighbors:
                real_atom_match_dummy_atom[real_atom_idx].add(dummy_atoms_idx)

    return real_atom_match_dummy_atom