def select(max_r, atoms, label):
    """
    Select a molecule out of a list of atoms.

    The function puts a labelled atom in a list of selected atoms. It then
    checks for nearby atoms to the selected atoms. If any are found and are not
    already selected, they are added to the list. The loop ends when it is
    executed and not atoms are added.

    Parameters
    ----------
    max_r : float
        Maximum distance which is considered a bond
    atoms : list of Atom objects
        Cluster of atoms which from which a molecule needs to be extracted
    label : int
        The number of the atom from which the molecule is generated. Note that
        it is the Python label, so starting from 0, unlike the label in most
        chemistry software which counts from 1

    Returns
    -------
    selected : list of Atom objects
        The atoms belonging to the molecule which is selected

    """
    new_atoms = [atoms[label]]
    selected = new_atoms
    n = True
    while n == True:
        n = False
        old_atoms = new_atoms
        new_atoms = []
        for i in old_atoms:
            for j in atoms:
                if i.c_dist(j.x, j.y, j.z) <= max_r and j not in selected:
                    new_atoms.append(j)
                    selected.append(j)
                    n = True
    return selected
