def _get_contacts(all_atoms, ions, cutoff):
    """Identify the atoms closest to the ions and return them."""
    contacts = {}
    for ion in ions:
        contacts[ion.resid] = []
        for atom in all_atoms:
            dist = (
                (ion.x - atom.x) ** 2
                + (ion.y - atom.y) ** 2
                + (ion.z - atom.z) ** 2
            ) ** 0.5
            if dist <= cutoff and ion.resname != atom.resname:
                contacts[ion.resid].append((atom, dist))

    return contacts