SMTG-Bham/sumo

Separating spin-up and spin-down contributions in sumo-bandplot output .dat file

JaafarMehrez opened this issue · 2 comments

Using sumo-bandplot -spin 1 or sumo-bandplot -spin -1, one is able to obtain the bandstructure with either spin-up or spin-down channels, however, the created .dat file will contain both spin-up and spin-down contributions. I would like to ask whether one could have those contributions in two separated .dat files?

I just realized I can get that by adjusting the save_data_files() in bandplot.py:

def save_data_files(bs, prefix=None, directory=None):
    """Write the band structure data files to disk.

    Args:
        bs (`BandStructureSymmLine`): Calculated band structure.
        prefix (`str`, optional): Prefix for data file.
        directory (`str`, optional): Directory in which to save the data.

    Returns:
        A tuple of the filenames of the written data files for spin-up and spin-down values.
    """
    filename_up = f"{prefix}_band_up.dat" if prefix else "band_up.dat"
    filename_down = f"{prefix}_band_down.dat" if prefix else "band_down.dat"

    directory = directory if directory else "."
    filename_up = os.path.join(directory, filename_up)
    filename_down = os.path.join(directory, filename_down)

    if bs.is_metal():
        zero = bs.efermi
    else:
        zero = bs.get_vbm()["energy"]

    with open(filename_up, "w") as f_up:
        header = "#k-distance eigenvalue[eV]\n"
        f_up.write(header)

        for band in bs.bands[Spin.up]:
            for d, e in zip(bs.distance, band):
                f_up.write(f"{d:.8f} {e - zero:.8f}\n")
            f_up.write("\n")

    if bs.is_spin_polarized:
        with open(filename_down, "w") as f_down:
            header = "#k-distance eigenvalue[eV]\n"
            f_down.write(header)

            for band in bs.bands[Spin.down]:
                for d, e in zip(bs.distance, band):
                    f_down.write(f"{d:.8f} {e - zero:.8f}\n")
                f_down.write("\n")

    return filename_up, filename_down```

You could use the unix cut program to remove the unwanted columns from the file. Just watch out for the header; the extra # means the header has one more entry and the indices are offset.

e.g. to get the spin-up component from a file with s,p,d components:

FILENAME=Ni_dos.dat
head -n 1 $FILENAME | cut -d ' ' -f 2,3,5
tail -n +2 $FILENAME | cut -d ' ' -f 1,2,4

It shouldn't take much extra work to turn that into a shell function or script that takes a .dat file as input and writes a couple of new ones, and would be a bit easier to share/maintain than a Summo fork.