def fermi_energy_parser(vasp_dir):
    """
    Parses fermi energy from DOSCAR file.
    :param vasp_dir: string containing path to VASP-file.
    :return: float containing fermi energy.
    """
    # Open DOSCAR file.
    outcar_file = vasp_dir + '/DOSCAR'
    try:
        with open(outcar_file, "r") as f:
            (next(f))
            next(f)
            next(f)
            next(f)
            next(f)
            line = next(f)
            fermi_energy = float(line.split()[3])
    except OSError:
        print('DOSCAR file not in directory. Skipping.')
        return 0
    except StopIteration:
        print('Data not found in DOSCAR. Skipping.')
        return 0
    return fermi_energy