import re


def final_energy_from_outcar( filename='OUTCAR' ):
    """
    Finds and returns the energy from a VASP OUTCAR file, by searching for the last `energy(sigma->0)` entry.

    Args:
        filename (Str, optional): OUTCAR filename. Defaults to 'OUTCAR'.

    Returns:
        (Float): The last energy read from the OUTCAR file.
    """
    with open( filename ) as f:
        outcar = f.read()
    energy_re = re.compile(r"energy\(sigma->0\) =\s+([-\d\.]+)")
    energy = float( energy_re.findall( outcar )[-1] )
    return energy