import itertools


def get_emin_emax(self):
    """
    Finds how much the Ek_grid has to be expanded
    above the bandwidth D of the leads.

    Parameters
    ----------
    self : Approach2vN
        Approach2vN object.

    self.funcp.emin : float
        (Modifies) Minimal energy in the updated Ek_grid.
    self.funcp.emax : float
        (Modifies) Maximal energy in the updated Ek_grid.
    """
    # (E, si, dband) = (self.qd.Ea, self.si, self.leads.dlst[0,1])
    (E, si, dmin, dmax) = (self.qd.Ea, self.si, self.funcp.dmin, self.funcp.dmax)
    lst = [dmin, dmax]
    for charge in range(si.ncharge):
        for b, bp in itertools.product(si.statesdm[charge], si.statesdm[charge]):
            lst.append(dmax-E[b]+E[bp])
            lst.append(dmin-E[b]+E[bp])
    for charge in range(si.ncharge-2):
        for d, b in itertools.product(si.statesdm[charge+2], si.statesdm[charge]):
            lst.append(dmin+E[d]-E[b])
            lst.append(dmax+E[d]-E[b])
    self.funcp.emax = max(lst)
    self.funcp.emin = min(lst)
    return 0