def write_character_file(name, ks, energies, characters, n_bands, n_k):
    """ Create a file containing columns of kx, ky, kz, E and the character 
    of a specific band (the name of which should be reflected in the 
    filename). """
    fmt = '{: .10f} '
    s = '{:>10} ' + 5 * fmt + '\n'
    header = '#{:>9}' + 5 * '{:>14}' + '\n'
    header = header.format('k index', 'kx (pi/a)', 'ky (pi/b)', 'kz (pi/c)',
        'E (eV)', 'character %')
    with open(name, 'w+') as f:
        f.write(header)
        for band in range(n_bands):
            f.write('# Band {}\n'.format(band))
            for k in range(n_k):
                i = band * n_k + k
                line = s.format(k, ks[k][0], ks[k][1], ks[k][2], energies[i
                    ], characters[i])
                f.write(line)
