py4mulas package

py4mulas.utils

class py4mulas.utils.KspaceOptions(precomp: bool = True, chunk_size: int = None, memmap: bool = False)[source]

Bases: object

chunk_size: int = None
memmap: bool = False
precomp: bool = True

py4mulas.models

class py4mulas.models.Kmodel(hamiltonian: Any, k_1: list | numpy.ndarray | None = None, k_2: list | numpy.ndarray | None = None, k_3: list | numpy.ndarray | None = None, zone: callable | None = None, params: dict = {}, real_space: bool = False)[source]

Bases: object

Base class for calculating k-space proprties of a momentum dependent Hamiltonian.

hamiltonian

The k-space hamiltonian matrix.

params

the parameters used in the definition of hamiltonian

k_1

The momentum values in the first dimension.

k_2

The momentum values in the second dimension.

k_3

The momentum values in the third dimension.

zone

The zone of the momentum space or the Brillouin zone

real_space

False corresponds to reduced Bloch phase representation. True corresponds to cartesian momenta representation. For py4mulas integration the reduced momenta representation is recomaended. If hamiltonian is given as a string or a sympy expression, the user should be carefull to appropriately handle the underlying representation.

Exemple:
>>> System = Kmodel(model, k_1=[0], k_2=[0], k_3=[0], params={}, zone=shape)
property H
property bounds
property dk
property k_vectors
property params
property symbolic_H
property symbolic_ham
property velocities

py4mulas.operators

class py4mulas.operators.HamDiff(model: Kmodel, orders: dict[str, int])[source]

Bases: KspaceOpera

Computes higher order momentum derrivatives

Parameters:
  • model – An instance of Kmodel

  • orders – A dictionary in the form {“k_x”: nx, “k_y”: ny} with ni the derrivative order allong the corresponding momentum variable.

Example

To compute : \(\frac{\partial^5 H}{\partial_{k_x}^2 \partial_{k_y}^3}\)

>>> HamDiff(some_model, orders={'k_x':2, 'k_y':3})
__call__(k_args: list[numpy.ndarray], energy: numpy.ndarray, psi: numpy.ndarray)[source]

Call self as a function.

class py4mulas.operators.Identity(model: Kmodel)[source]

Bases: KspaceOpera

Computes the identity operator \(\langle \psi_m | \psi_n \rangle\)

Parameters:

model – An instance of Kmodel

__call__(k_args: list[numpy.ndarray], energy: numpy.ndarray, psi: numpy.ndarray)[source]

Call self as a function.

class py4mulas.operators.MagneticOctupoleCurrent(model: Kmodel, a: numpy.ndarray | sympy.MatrixBase | str, b: numpy.ndarray | sympy.MatrixBase | str, c: numpy.ndarray | sympy.MatrixBase, direction: str)[source]

Bases: MagneticOctupole

Cumputes octupole current operator \(\frac{1}{2}\{v, O_{ab}^c\}\) with \(v\) being the velocity operator along the flow direction and

\(O_{ab}^c=\{L_a, L_b\} S_c\).

\(L_a\) is the orbital operator polarized along \(a\) and \(S_c\) is the spin matrix written in the same basis as \(L\).

See. Han et al [Phys. Rev. Lett. 135, 076705 (2025)]

model

An instance of Kmodel

direction

The current flow direction

a

An orbital matrix or a polarization direction. In the atomic center approximation, we have the orbital matrix. This works perfectly. If a string is given then \(L_a\) will be constructed from itenerent orbital moment expression of modern theory of orbital magnetism. The last approach is not fully tested. This should be only used when really intended.

b

An orbital matrix or a polarization direction. In the atomic center approximation, we have the orbital matrix. This works perfectly. If a string is given then \(L_a\) will be constructed from itenerent orbital moment expression of modern theory of orbital magnetism. The last approach is not fully tested. This should be only used when really intended.

c

A spin angular momentum matrix.

class py4mulas.operators.MagneticOctupoleDensity(model: Kmodel, a: numpy.ndarray | str, b: numpy.ndarray | str, c: numpy.ndarray | sympy.MatrixBase)[source]

Bases: MagneticOctupole

Cumputes otupole density operator \(O_{ab}^c=\{L_a, L_b\} S_c\).

\(L_a\) being the orbital operator polarized along \(a\)

model

An instance of Kmodel

a

An orbital matrix or a polarization direction. In the atomic center approximation, we have the orbital matrix. This works perfectly. If a string is given then \(L_a\) will be constructed from itenerent orbital moment expression of modern theory of orbital magnetism. The last approach is not fully tested. This should be only used when really intended.

b

An orbital matrix or a polarization direction. In the atomic center approximation, we have the orbital matrix. This works perfectly. If a string is given then \(L_b\) will be constructed from itenerent orbital moment expression of modern theory of orbital magnetism. The last approach is not fully tested. This should be only used when really intended.

c

A spin angular momentum matrix.

class py4mulas.operators.OrbitalCurrent(model: Kmodel, direction: str, gamma: numpy.ndarray | str)[source]

Bases: OrbitalOperator

Cumputes orbital current operator polarized along gamma flowing in direction

model

An instance of Kmodel

direction

The current flow direction

gamma

The polarization direction of the orbital current

class py4mulas.operators.OrbitalDensity(model: Kmodel, gamma=typing.Union[numpy.ndarray, str])[source]

Bases: OrbitalOperator

Cumputes orbital density operator

model

An instance of Kmodel

gamma

The polarization direction of the orbital angular momentum

class py4mulas.operators.QuadripoleCurrent(model: Kmodel, a: numpy.ndarray | sympy.MatrixBase | str, b: numpy.ndarray | sympy.MatrixBase | str, direction: str)[source]

Bases: MagneticOctupole

Cumputes the quadripole current operator \(\frac{1}{2}\{v, Q_{ab}\}\) with \(v\) the velocity operator along the flow direction and \(Q_{ab}=\{L_a,L_b\}\), and

\(L_a\) being the orbital operator polarized along \(a\)

model

An instance of Kmodel

direction

The current flow direction

a

An orbital matrix or a polarization direction. In the atomic center approximation, we have the orbital matrix. This works perfectly. If a string is given then \(L_a\) will be constructed from itenerent orbital moment expression of modern theory of orbital magnetism. The last approach is not fully tested. This should be only used when really intended.

b

An orbital matrix or a polarization direction. In the atomic center approximation, we have the orbital matrix. This works perfectly. If a string is given then \(L_b\) will be constructed from itenerent orbital moment expression of modern theory of orbital magnetism. The last approach is not fully tested. This should be only used when really intended.

class py4mulas.operators.QuadripoleDensity(model: Kmodel, a: numpy.ndarray | str, b: numpy.ndarray | str)[source]

Bases: MagneticOctupole

Cumputes quadripole density operator \(Q_{ab}=\{L_a,L_b\}\) with \(L_a\) being the orbital operator polarized along \(a\)

model

An instance of Kmodel

a

An orbital matrix or a polarization direction. In the atomic center approximation, we have the orbital matrix. This works perfectly. If a string is given then \(L_a\) will be constructed from itenerent orbital moment expression of modern theory of orbital magnetism. The last approach is not fully tested. This should be only used when really intended.

b

An orbital matrix or a polarization direction. In the atomic center approximation, we have the orbital matrix. This works perfectly. If a string is given then \(L_a\) will be constructed from itenerent orbital moment expression of modern theory of orbital magnetism. The last approach is not fully tested. This should be only used when really intended.

class py4mulas.operators.SpinCurrent(model: Kmodel, pauli: numpy.ndarray | None = None, direction: str | None = None)[source]

Bases: SpinOperator

Cumputes spin current operator

model

An instance of Kmodel

direction

The current direction

pauli

The polarization direction of the spin current

class py4mulas.operators.SpinDensity(model: Kmodel, pauli: numpy.ndarray | None = None)[source]

Bases: SpinOperator

Cumputes spin density operator

model

An instance of Kmodel

pauli

The spin matrix along the polarization direction

class py4mulas.operators.SpinOperator(model: Kmodel, direction: str | None = None, pauli: numpy.ndarray | sympy.MatrixBase | None = None)[source]

Bases: KspaceOpera

Base class for SpinDensity and SpinCurrent operators.

model

An instance of Kmodel

direction

The direction of flow for the current. It should be specified for SpinCurrent.

pauli

Angular momentum polarization. A pauli or an orbital matrix.

__call__(k_args: list[numpy.ndarray], energy: numpy.ndarray, psi: numpy.ndarray)[source]
Calculates the current polarized along pauli and flowing

along direction.

Parameters:
  • pauli – Spin matrix of the same shape as the hamiltonian.

  • direction – Current flow direction.

band_resolved(n: int | list | tuple = 0, m: int | None = None) numpy.ndarray[source]

For computing a SpinOperator expectation value for a specific band or a list of bands. If m is given the expectation value between n and m is computed.

Parameters:
  • n – A band index or a list of bands.

  • m – A band index for the ket Bloch vector.

Returns:

the expectation values over py4mulas

class py4mulas.operators.Velocity(model: Kmodel, direction: str)[source]

Bases: KspaceOpera

Computes velocity operator along a given direction

Parameters:
  • model – An instance of Kmodel

  • direction – The direction along which velocity is

  • computed.

__call__(k_args: list[numpy.ndarray], energy: numpy.ndarray, psi: numpy.ndarray)[source]

Computes the velocity matrix along direction. If a list or a tuple of floats is given a linear combination of velocities is considered. Then the elements of direction give the respective coefficients along \(x\), \(y\), \(z\).

py4mulas.formulas

class py4mulas.formulas.KuboFormula(kmodel: Kmodel, kspace_options: dict | None = None, contractions: list[str] | str | None = None, opera_kernel: Callable | None = None, mu_kernel: list[Callable] | Callable | list[list[Callable]] | None = None)[source]

Bases: _Prebuilder

Computes an arbitrary response formula

\[\sigma = \sum_k\sum_{mn} K_{mn}(k) O_{mn}(k)\]

with \(K_{mn}\) being the matrix elements of the energy kernel K which may depend on transport properties such as \(\mu\), \(T\), \(\eta\) and \(E\) but should not nvolve \(\psi\). The memeber \(O_{mn}\) is the operator kernel which may depend on \(\psi\). It is assumed to depend on py4mulas operators. This can be used to implement an arbitrary formula with tenorial contractions. The contractions einsum (subscripts) should be provided as an argument. This separation enables to store the operator kernel for the whole kspace. So varying transport properties becomes quite cheap. In cases, where these kernels have further symmetries or simplifications we should provide the shape of the matrix \(O\) through kernel_norbs. This is exploited in py4mulas.responses.Kubo.

model

An instance of Kmodel

kspace_options

A dictionary specifying chunk_size and precomp. If chunk_size is not given, a default is used. Note that if precomp is True, the energy and temperature scans are momentum space free. If eta is to be changed, then set precomp = False, as the kernels are eta-dependent.

contractions

Explicit np.einsum subscripts to be used for the computation.

mu_kernel

Energy kernel. If this is not given _mu_kernel method should be implemented.

opera_kernel

Operator kernel to be optionally stored. If this is not given the _opera_kernel method should be implemented. If opera_kernel returns a list of kernel arrays, their length should be equal to mu_kernel length. Possibly, each of these opera_kernels can take a list of mu_kernels. In this case mu_kernel can be provided as a list of lists. Besides len(mu_kernell) should always equal the length of returned opera_kernels.

Note

Enabling the opera_kernel to be a list is mainly for making the computation of these kernels more performent. For instance one can avoid rediagonalization of the hamiltonian.

Example

>>> class OperaKernel:
>>>    def __init__(self, alpha, beta, **kwargs):
>>>        self.alpha = alpha
>>>        self.beta = beta
>>>    def __call__(self, k_args, energy, psi, eta):
>>>        alpha = self.alpha(k_args, energy, psi)
>>>        beta = self.beta(k_args, energy, psi)
>>>        kernel = beta * np.swapaxes(alpha, 1, 2)
>>>        return kernel
>>> opera_kernel = OperaKernel(alpha, beta)
>>> mu_kernel = [KuboKernel('inter_band'), KuboKernel('intra_band')]
>>> kspace_options = dict(chunk_size=1000, precomp=True)
>>> formula = KuboFormula(kmodel, kspace_options=kspace_options, mu_kernel=mu_kernel, opera_kernel=opera_kernel)
>>> response = formula(mu=0, temperature=0, eta=0, k_resolved=False)
property H
__call__(mu: float = 0.0, temperature: float = 0.0, eta: float = 0.0, k_resolved: bool = False) complex[source]

Computes the response fomula at \(\mu\), \(T\) and \(\eta\).

Parameters:
  • mu – Chemical potential.

  • temperature – Temperature.

  • eta – Broadening (the infinitesimal parameter).

  • k_resolved – Specifies whether we want a summed transport response

  • resolved. (or momentum)

Returns:

A numpy arry, if k_resolved is True or a complex number if it is False.

property chunk_size
property e_shape
integrand(*k: list | tuple | numpy.ndarray, mu: float, temperature: float, eta: float) complex[source]

unvectorized integrand, for single k evaluation

property k_vectors
property kernel_shape
property num_k
property prefactor
py4mulas.formulas.batcher(formula: KuboFormula, data: list[tuple], n: int = 10) numpy.ndarray[source]

Computes formula, partitioning the kspace into n batches, for a full set of data. This can be used when the kspace is too large, to reduce memory load and still use precomp.

Parameters:
  • formula – An instance of KuboFormula or Kubo

  • data – List of tuples in the form of (\(\mu\), \(T\), \(\eta\)) to be passed as arguments to formula.

  • n – Number of wanted kspace batches

Raises:

ValueError – When precomp is set to False

Returns:

An array in the same order of the data

py4mulas.responses

class py4mulas.responses.Kubo(model: Kmodel, kspace_options: dict | None = None, alpha: str | KspaceOpera = 'x', beta: str | KspaceOpera = 'y', mu_kernel: MuKernel | list[MuKernel] | None = None)[source]

Bases: KuboFormula

Computes the kubo conductivity

\[\sigma_{\alpha,\beta} = i\sum_k \sum_{mn} \frac{f_m - f_n}{(E_n - E_m) (E_n - E_m + i \eta)} \langle m|\beta|n \rangle \langle n|\alpha|m \rangle.\]

\(R_{nm} = \langle n|\alpha|m \rangle\).

We note \(L_{mn}=\langle m|\beta|n \rangle\), \(R_{nm} = \langle n|\alpha|m \rangle\)

We then write it as a product of an energy kernel \(K\)

and operator matrix \(O\)

\[\sigma_{\alpha,\beta}=\sum_k \sum_{mn}K_{mn} O_{mn}\]

with \(O = L R^T\)

and \(K_{mn} = (f_m - f_n) I_{mn}.\)

Where \(I^{mn} = \frac{1}{(E_n - E_m) (E_n - E_m + i \eta)}.\)

We enable the construction of any kubo like formula by providing a tailored \(K\) kernel can depend on \((E, \mu, T, \eta).\)

In the case of the habitual kubo formula, the computation can be further simplified as

\[\sigma_{\alpha,\beta} = \sum_k\sum_{m} f_m V_m\]

with \(V_m = \sum_n (\Gamma_{mn} - \Gamma_{nm})\)

and \(\Gamma_{ij} = I_{ij} O_{ij}\).

Note

this symmetrized decomposition is more memory efficient than the kernel based approach, as it holds a reduced array.

model

An instance of Kmodel

alpha

An instance of KspaceOpera

beta

An instance of KspaceOpera

kspace_options

a dictionary specifying chunk_size and precomp. If chunk_size is not given, a default is used. Note: if precomp is True, the energy and temperature scans are momentum space free. If eta is to be changed, then set precomp = False, as the kernels are eta-dependent.

kernel

An instance or list of instances of MuKernel, the energy kernel of the Kubo formula. If a list of kernels is given they should assume the same shape as _opera_kernel(), when precomp is True. If precomp is False then the shape uniformity is not important.

Exemple:
>>> G = Kubo(some_model, alpha='x', beta=Velocity('y'),
    kspace_options=dict(chunk_size=1000, precomp=True), kernel=MuKernel('inter_band'))
>>> conductivities = []
>>> for mu_i in np.arange(-1, 1):
>>>     conductivity = G(mu=mu_i, temperature=0, eta=0)
>>>     conductivities.append(conductivity)
class py4mulas.responses.SecondOrderKubo(model: Kmodel, kspace_options: dict | None = None, alpha: str | KspaceOpera = 'x', beta: str | KspaceOpera = 'y', gamma: str | KspaceOpera = 'x', mu_kernel: SecondOrderKuboKernel | list[SecondOrderKuboKernel] | None = None, contribution: str | None = None)[source]

Bases: Kubo

Computes the kubo conductivity

\[\sigma_{\alpha,\beta \gamma} = \frac{1}{2}\sum_k \sum_{mnl} O^{nml}(k) K_{nml}(k).\]

with :

\[O^{nml} = \langle n|\alpha|m \rangle (\langle m|\beta|l \rangle \langle l|\gamma|n \rangle + \beta \leftrightarrow \alpha)\]
\[K_{nml} = \frac{1}{E_n - E_m + 2 i \eta} (\frac{f_n - f_l}{E_n - E_l + i \eta} - \frac{f_l - f_m}{E_l - E_m + i \eta})\]

Terms corresponding to the decomposition of this formula into odd and even under time-reversal symmetry are implemented. See _opera_kernel().

See. Yatsushiro et al [PRB 104, 054412 (2021)].

Note

This class can in principle implement any energy kernel \(K\) provided that it assumes an operator kernel which is exactly equal to \(O\) described above. For formulas containing combinations of operator kernels, each product of the type \(K O\) can be implemented independently from formulas. In this class we also enable even and odd energy kernels which involve different operator kernels. These can be accessed through the parameter contribution.

model

Kmodel

alpha

KspaceOpera

beta

KspaceOpera

gamma

KspaceOpera

kspace_options

A dictionary specifying chunk_size and precomp. If chunk_size is not given, a default is used. Note: if precomp is True, the energy and temperature scans are momentum space free. If eta is to be changed, then set precomp = False, as the kernels are eta-dependent.

kernel

SecondOrderKuboKernel, the second order energy kernel of the Kubo formula. If a list of kernels is given they should assume the same shape as _opera_kernel(), when precomp is True. If precomp is False then the shape uniformity is not important.

contribution

Specifies a particular kernel from [‘even’, ‘odd’]. When this is set to None the full undecomposed kernel is assumed. contribution=None is equivalent to kernel=SecondOrderKuboKernel().

Exemple:
>>> G = Kubo(some_model, alpha='x', beta=Velocity('y'), gamma='z',
    kspace_options=dict(chunk_size=10000, precomp=True), kernel=SecondOrderKuboKernel())
>>> conductivities = []
>>> for mu_i in np.arange(-1, 1):
>>>     conductivity = G(mu=mu_i, temperature=0, eta=0)
>>>     conductivities.append(conductivity)

py4mulas.integrator

class py4mulas.integrator.Nquad(formula: KuboFormula, bounds: list[tuple] | None = None, opts: dict | None = None)[source]

Bases: object

Integrates a formula with integration variables, which can be either \(k\), \(E\) or both.

Parameters:
  • formula – An instance of KuboFormula

  • bounds – Integration bounds, if not provided default model bounds are used

  • opts – Options to be passed to nquad.

Example

>>> F = py4mulas.responses.Kubo(some_model, alpha='x', beta='y', kspace_options)
>>> I = py4mulas.integrator.Nquad(F, opts=None)
>>> response = I(mu=0, temperature=0.1, eta=0.01)
__call__(mu: float = 0, temperature: float = 0, eta: float = 0)[source]

Call self as a function.

py4mulas.mu_kernels

class py4mulas.mu_kernels.BerryKernel[source]

Bases: MuKernel

__call__(energy, mu=0, temperature=0, eta=0)[source]

Call self as a function.

class py4mulas.mu_kernels.FermiDirac[source]

Bases: MuKernel

__call__(energy: numpy.ndarray, mu: float = 0.0, temperature: float = 0.0, eta: float | None = None) numpy.ndarray[source]

Call self as a function.

class py4mulas.mu_kernels.KuboBastinKernel(name: str | None = None)[source]

Bases: MuKernel

A class for Kubo-Bastin formula kernels.

name

Specifies the response to be computed.

__call__(energy: numpy.ndarray, mu: float = 0.0, temperature: float = 0.0, eta: float = 0.0) numpy.ndarray[source]

Call self as a function.

bmII_kernel(energy: numpy.ndarray, mu: float = 0.0, temperature: float = 0.0, eta: float = 0.0) numpy.ndarray[source]

Sea contribution of Bonbian-Manchon decomposition

[1] Bonbian and Manchon [PRB 102, 085113 (2020)]

Parameters:
  • energy – Energy eigenvalues

  • mu – Chemical potential

  • temperature – Temperature

  • eta – Broadening

full_kernel(energy: numpy.ndarray, mu: float = 0.0, temperature: float = 0.0, eta: float = 0.0) numpy.ndarray[source]

Computes the Kubo Bastin kernel in Eq(A9) of [1]

[1] Crepieux et Bruno, PRB 64, 014416 (2001)

Parameters:
  • energy – Energy eigenvalues

  • mu – Chemical potential

  • temperature – Temperature

  • eta – Broadening

overlap_kernel(energy: numpy.ndarray, mu: float = 0.0, temperature: float = 0.0, eta: float = 0.0) numpy.ndarray[source]

Overlap between surface and sea contributions

Parameters:
  • energy – Energy eigenvalues

  • mu – Chemical potential

  • temperature – Temperature

  • eta – Broadening

stredaI_kernel(energy: numpy.ndarray, mu: float = 0.0, temperature: float = 0.0, eta: float = 0.0) numpy.ndarray[source]

First term of Strada-Smrka decomposition

Parameters:
  • energy – Energy eigenvalues

  • mu – Chemical potential

  • temperature – Temperature

  • eta – Broadening

class py4mulas.mu_kernels.KuboKernel(name: str = 'intra_band')[source]

Bases: MuKernel

Interband, intraband, anomalous, even or odd kernels.

name

Specifies the response to be computed.

__call__(energy: numpy.ndarray, mu: float = 0.0, temperature: float = 0.0, eta: float = 0.0) numpy.ndarray[source]

Call self as a function.

anomalous_kernel(energy: numpy.ndarray, mu: float = 0.0, temperature: float = 0.0, eta: float = 0.0) numpy.ndarray[source]

Computes the anomalous kernel.

\[-2i\frac{f_n}{(E_n - E_m)(E_n - E_m + i\eta)}\]
Parameters:
  • energy – Energy eigenvalues

  • mu – Chemical potential

  • temperature – Temperature

  • eta – Broadening

evenKernel(energy: numpy.ndarray, mu: float = 0.0, temperature: float = 0.0, eta: float = 0.0) numpy.ndarray[source]

Eq (4) of [1]. The effect of temperature is included in the constant broadening \(\eta\).

Parameters:
  • energy – Energy eigenvalues

  • mu – Chemical potential

  • temperature – Temperature

  • eta – Broadening

[1] Freimuth et al, [PRB 90, 174423 (2014)]

interband_kubo_kernel(energy: numpy.ndarray, mu: float = 0.0, temperature: float = 0.0, eta: float = 0.0) numpy.ndarray[source]

Computes the kubo kernel in Eq(A5) of [1]

\[i\frac{f_m - f_n}{(E_n - E_m)(E_n - E_m + i\eta)}\]

[1] Crepieux et Bruno, [PRB 64, 014416 (2001)]

Parameters:
  • energy – Energy eigenvalues

  • mu – Chemical potential

  • temperature – Temperature

  • eta – Broadening

intraband_kubo_kernel(energy: numpy.ndarray, mu: float = 0.0, temperature: float = 0.0, eta: float = 0.0) numpy.ndarray[source]

Computes the intra-band kubo kernel

\[\frac{i}{\eta}\partial_E f|_{E=e_n}\]

See for instance Eq(5), Huhtinen et al, [PRB 108, 155108 (2023)]

Parameters:
  • energy – Energy eigenvalues

  • mu – Chemical potential

  • temperature – Temperature

  • eta – Broadening

oddKernel(energy: numpy.ndarray, mu: float = 0.0, temperature: float = 0.0, eta: float = 0.0) numpy.ndarray[source]

Eq (5) of [1]. The effect of temperature is included in the constant broadening \(\eta\).

Parameters:
  • energy – Energy eigenvalues

  • mu – Chemical potential

  • temperature – Temperature

  • eta – Broadening

[1] Freimuth et al, [PRB 90, 174423 (2014)]

class py4mulas.mu_kernels.MuKernel[source]

Bases: ABC

abstract __call__(*args)[source]

Call self as a function.

property contractions
class py4mulas.mu_kernels.PrimitiveFermiDirac[source]

Bases: MuKernel

__call__(energy: numpy.ndarray, mu: float = 0.0, temperature: float = 0.0, eta: float | None = None) numpy.ndarray[source]

Call self as a function.

class py4mulas.mu_kernels.SecondOrderKuboKernel[source]

Bases: MuKernel

__call__(energy: numpy.ndarray, mu: float = 0.0, temperature: float = 0.0, eta: float = 0.0) numpy.ndarray[source]

Call self as a function.

py4mulas.opera_kernels

class py4mulas.opera_kernels.Kubo(alpha: KspaceOpera, beta: KspaceOpera, reduce: bool = False)[source]

Bases: object

__call__(k_args: list[numpy.ndarray], en: numpy.ndarray, psi: numpy.ndarray, eta: float) numpy.ndarray[source]

Call self as a function.

py4mulas.topology

class py4mulas.topology.BerryCurvature(model: Kmodel, alpha: str | KspaceOpera = 'x', beta: str | KspaceOpera = 'y')[source]

Bases: Kubo

Computes the k-space Berry curvature (oriented along a direction perpendicular to alpha and beta) for a single band.

model

An instance of Kmodel

alpha

An instance of KspaceOpera, a longitudinal in-plane direction

beta

An instance of KspaceOpera, a transversal in-plane direction

Note

For spin or orbital berry curvature alpha or beta should be either a spin or orbital operator.

__call__(band: int | None = None) numpy.ndarray[source]

Computes the response fomula at \(\mu\), \(T\) and \(\eta\).

Parameters:
  • mu – Chemical potential.

  • temperature – Temperature.

  • eta – Broadening (the infinitesimal parameter).

  • k_resolved – Specifies whether we want a summed transport response

  • resolved. (or momentum)

Returns:

A numpy arry, if k_resolved is True or a complex number if it is False.

class py4mulas.topology.QuantumGeometricTensor(model: Kmodel, alpha: str | KspaceOpera = 'x', beta: str | KspaceOpera = 'y')[source]

Bases: BerryCurvature

__call__(band: int = 0) numpy.ndarray[source]

Computes the response fomula at \(\mu\), \(T\) and \(\eta\).

Parameters:
  • mu – Chemical potential.

  • temperature – Temperature.

  • eta – Broadening (the infinitesimal parameter).

  • k_resolved – Specifies whether we want a summed transport response

  • resolved. (or momentum)

Returns:

A numpy arry, if k_resolved is True or a complex number if it is False.

class py4mulas.topology.QuantumMetric(model: Kmodel, alpha: str | KspaceOpera = 'x', beta: str | KspaceOpera = 'y')[source]

Bases: BerryCurvature

__call__(band: int = 0) numpy.ndarray[source]

Computes the response fomula at \(\mu\), \(T\) and \(\eta\).

Parameters:
  • mu – Chemical potential.

  • temperature – Temperature.

  • eta – Broadening (the infinitesimal parameter).

  • k_resolved – Specifies whether we want a summed transport response

  • resolved. (or momentum)

Returns:

A numpy arry, if k_resolved is True or a complex number if it is False.

py4mulas.plotters

py4mulas.plotters.kplot(model: Kmodel, quantity: numpy.ndarray, cmap: str = 'seismic', label: str | None = None, title: str | None = None, show: bool = True, file: str | None = None, ax: matplotlib.pyplot.Axes | None = None, s: int = 10, vmin: float | None = None, vmax: float | None = None, fontsize: float = 12, figsize: tuple | None = None, alpha: float = 0.8, k_vectors: numpy.ndarray | None = None)[source]

Plots quantity over the kspace of model. A scatter plot.

Parameters:
  • model – An instance of Kmodel

  • quantity – The quantity to plot

  • cmap – Colormap

  • label – Colorbar label

  • title – Title of the plot

  • show – Whether to show the fig or not

  • file – Name of file to whish the figure can be saved

  • ax – Axes to be used for the plot

  • s – Marker size

  • vmin – Minimum value of quantity

  • vmax – Maximum value of quantity

  • fontsize – The fontsize to be used

  • figsize – The size of the figure

  • alpha – Alpha blending value

  • k_vectors – Momentum vectors over which quantity is plotted

py4mulas.plotters.plot_bands(model: Kmodel, path: list[tuple] | None = None, operator: KspaceOpera | None = None, path_labels: list[str] | None = None, n_per_segment: int = 70, ax: matplotlib.pyplot.Axes | None = None, cmap: str = 'viridis', file: str = False, show: bool = True, figsize: tuple = (8, 6), fontsize: float = 14, vmin: float | None = None, vmax: float | None = None, emin: float | None = None, emax: float | None = None, cbar: bool = True, bands: list | int | tuple | None = None)[source]

Plots the energy bands of a model along a given path, optionally with the expectation value of a py4mulas operator

Parameters:
  • model – An instance of Kmodel

  • path – a path in kspace

  • operator – An instance of KspaceOpera, an operator whose expectation value is to be plotted

  • path_labels – Labels corresponding to the momentum points in path.

  • n_per_segment – Number of points for each segment of path.

  • ax – Axes to be used for the plot.

  • cmap – A custum colormap

  • file – Name of file to which plot can be saved.

  • show – Whether display the plot or not.

  • figsize – Size of figure.

  • fontsize – Font size for ticks and labeling.

  • vmin – Minimum value of the operator expectation value.

  • vmax – Maxmum value of the operator expectation value.

  • emin – Minimum energy to be considered.

  • emax – Maximum energy to be considered.

  • cbar – Whether to show the colorbar or not.

  • bands – A sellection of bands to be shown.

py4mulas.plotters.projected_spectrum(model: Kmodel, path: list[numpy.ndarray] | None = None, operator: KspaceOpera | None = None) tuple[numpy.ndarray][source]

Compute eigenvalues and optionally operator weight along a path.

Parameters:
  • model – An instnce of Kmodel

  • path – A list of kpoits

  • operator – An instance of ~py4mulas.operators.KspaceOpera

Raises:

TypeError – When operator is not An instance of ~py4mulas.operators.KspaceOpera

Returns:

Array of eigenvaluses, and corresponding operator projection

Submodules