def is_clashing(atom, others, max_dist):
    """Check if a given atom is closer than max_dist from at least one atom in
    another given set."""
    # Avoid sqrt by comparing squared distances.
    max_dist2 = max_dist**2
    for atom2 in others:
        dx = atom2.x - atom.x
        dy = atom2.y - atom.y
        dz = atom2.z - atom.z
        d2 = dx*dx + dy*dy + dz*dz
        if d2 < max_dist2:
            return True
    return False