gftool.chemical_potential

gftool.chemical_potential(occ_root: Callable[[float], float], mu0=0.0, step0=1.0, **kwds) float[source]

Search chemical potential for a given occupation.

Parameters:
occ_rootcallable

Function occ_root(mu_i) -> occ_i - occ, which returns the difference in occupation to the desired occupation occ for a chemical potential mu_i. Note that the sign is important, occ_i - occ has to be returned.

mu0float, optional

The starting guess for the chemical potential (default: 0).

step0float, optional

Starting step-width for the bracket search. A reasonable guess is of the order of the band-width (default: 1).

**kwds

Additional keyword arguments passed to scipy.optimize.root_scalar. Common arguments might be xtol or rtol for absolute or relative tolerance.

Returns:
float

The chemical potential given the correct charge occ_root(mu)=0.

Raises:
RuntimeError

If either no bracket can be found (this should only happen for the complete empty or completely filled case), or if the scalar root search in the bracket fails.

Notes

The search for a chemical potential is a two-step procedure: First, we search for a bracket [mua, mub] with occ_root(mua) < 0 < occ_root(mub). We use that the occupation is a monotonous increasing function of the chemical potential mu. Second, we perform a standard root-search in [mua, mub] which is done using scipy.optimize.root_scalar, Brent’s method is currently used as default.

Examples

We search for the occupation of a simple 3-level system, where the occupation of each level is simply given by the Fermi function:

>>> occ = 1.67  # desired total occupation
>>> BETA = 100  # inverse temperature
>>> eps = np.random.random(3)
>>> def occ_fct(mu):
...     return gt.fermi_fct(eps - mu, beta=BETA).sum()
>>> mu = gt.chemical_potential(lambda mu: occ_fct(mu) - occ)
>>> occ_fct(mu), occ
(1.67000..., 1.67)