def pdb2selection(pdbfile):
    """
    Create selection strings from pdbfile data.

    A little utility function to convert 'mask' pdb files into
    MDTraj-style selection strings. Basically it reads the second column
    (atom number) and uses it to construct 'index' selections. Runs
    of consecutive numbers are expressed in 'start to stop' form.

    Args:
        pdbfile (str): Name of a PDB file

    Returns:
        selection (str): MDtraj format selection string
    """
    sel = ''
    i = 0
    j = 0
    with open(pdbfile, 'r') as f:
        for line in f:
            if line.find('ATOM') == 0 or line.find('HETATM') == 0:
                k = int(line.split()[1])
                if i == 0:
                    i = k
                    j = k - 1
                if k == j + 1:
                    j = k
                else:
                    sel = sel + ' index {0} to {1} or'.format(i, j)
                    i = k
                    j = k
    if i > 0 and j > 0:
        sel = sel + ' index {0} to {1} or'.format(i, j)
    if len(sel) > 3:
        sel = sel[:-3]
    return sel
