def break_kpt_spin_blocks(S):
    """Break a block into smaller kpt and spin blocks."""

    if not 'Symmetrized values from band-averaging' in S:
        raise Exception('Could not find symmetrized values in block:\n' + S)

    S = S.split('Symmetrized values from band-averaging')[-1]
    S = S.split('======================')[0]

    blocks = list()
    iterlines = iter(S.splitlines())
    while True:

        try:
            line = iterlines.next()
        except StopIteration:
            break

        if line.startswith('       k ='):

            lines = list()
            lines.append(line)       # kpoint line
            line = iterlines.next()  # empty line
            lines.append(line)
            line = iterlines.next()  # labels line
            while line.strip():
                lines.append(line)
                line = iterlines.next()
            blocks.append('\n'.join(lines))

    return blocks