Coverage for tbkit/optics.py: 100%
151 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-21 11:05 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-21 11:05 +0000
1r"""
2Linear and nonlinear optical response of 2D Bloch models (:class:`~tbkit.kspace.KSpace`)
3over a uniform Brillouin-zone mesh.
5* :func:`optical_conductivity` -- the Kubo-Greenwood conductivity
6 :math:`\sigma_{ab}(\omega)`, interband and intraband (Drude), with a
7 broadening :math:`\eta`.
8* :func:`joint_dos` -- the joint density of states of vertical transitions.
9* :func:`berry_curvature_dipole` -- the Berry curvature dipole of the
10 nonlinear Hall effect (Sodemann and Fu 2015).
11* :func:`shift_current` -- the shift-current conductivity
12 :math:`\sigma^{abc}(0;\omega,-\omega)` (Sipe and Shkrebtii 2000).
14Every function works in units :math:`\hbar = e = 1`, energies (and
15:math:`\hbar\omega`) in the units of the hoppings, lengths in those of
16*prim_vec*, and counts each orbital once: a spinless model gives the
17response *per spin*.
19The velocities are the exact :math:`\partial H/\partial k_a` of
20*KSpace._bloch_derivatives* along the Cartesian axes :math:`x, y` (for a 2D
21lattice embedded in 3D space, the axes of *KSpace.k_basis*). With
22``positions=True`` (the default) the bond vectors include the orbital
23positions, :math:`\mathbf{d} = \mathbf{R} + \boldsymbol\tau_j -
24\boldsymbol\tau_i`, so that the velocity is the physical :math:`i[H,
25\mathbf{r}]` (see *KSpace.hall_conductivity*). A model read from a
26Wannier90 ``_tb.dat`` file (*tbkit.io.read_wannier90_tb*) also carries the
27other matrix elements of the position operator: :func:`optical_conductivity`
28includes them in :math:`i[H, \mathbf{r}]`, while
29:func:`berry_curvature_dipole` and :func:`shift_current` refuse them (read
30the model with ``elements=False``, or pass ``positions=False``).
32Examples
33--------
34Example usage::
36 from tbkit.optics import optical_conductivity
37 omega = np.linspace(0.05, 3., 60)
38 sigma = optical_conductivity(graphene, omega, e_fermi=0., nk=300)
39 # Re sigma ~ pi/4 e^2/h per spin for hbar omega << t
40"""
41from __future__ import annotations
43from typing import Any, Iterator
45import numpy as np
46from numpy.typing import ArrayLike, NDArray
48import tbkit.error_handling as error_handling
49import tbkit.occupation as occupation
50from tbkit.kspace import KSpace
53_AXES = {'x': 0, 'y': 1}
54_DEGENERATE = 1e-9
57def _mesh(ks: KSpace, nk: int | tuple[int, int], positions: bool) -> NDArray[np.float64]:
58 '''
59 Private function. Validate the model (a static, Hermitian, 2D KSpace)
60 and return the k-points of a uniform Brillouin-zone mesh.
61 '''
62 error_handling.kspace(ks, KSpace)
63 ks._check_static()
64 error_handling.dim_exact(ks.dim, 2)
65 error_handling.hermitian_model(ks.is_hermitian())
66 error_handling.boolean(positions, 'positions')
67 return ks.mesh_grid(nk)[1]
70def cell_area(ks: KSpace) -> float:
71 r'''
72 Get the area :math:`A_c = |\mathbf{a}_1\times\mathbf{a}_2|` of the unit
73 cell of a 2D model (in the units of *prim_vec*), which turns a
74 Brillouin-zone average into an integral:
75 :math:`\int\frac{d^2k}{(2\pi)^2}g = \frac{1}{N_kA_c}\sum_{\mathbf{k}}g`.
77 Parameters
78 ----------
79 ks : **KSpace** instance, 2D
81 Returns
82 -------
83 area : Positive real
84 '''
85 error_handling.kspace(ks, KSpace)
86 error_handling.dim_exact(ks.dim, 2)
87 a1, a2 = (np.zeros(3) for _ in range(2))
88 a1[:ks.space_dim] = ks.lat.prim_vec[0]
89 a2[:ks.space_dim] = ks.lat.prim_vec[1]
90 return float(np.linalg.norm(np.cross(a1, a2)))
93def _bands(
94 ks: KSpace, kpts: NDArray[np.float64], positions: bool, second: bool = False,
95) -> Iterator[tuple]:
96 r'''
97 Private function. Over chunks of the k-points *kpts*: the band energies
98 (nk, n), the velocity matrices :math:`v^a_{nm} = \langle n|\partial_aH|m\rangle`
99 in the eigenbasis (2, nk, n, n) and, with *second*, the matrices
100 :math:`w^{ab}_{nm} = \langle n|\partial_a\partial_bH|m\rangle` (2, 2, nk, n, n).
101 '''
102 directions = [ks.k_basis[:, 0], ks.k_basis[:, 1]]
103 chunk = max(1, 200000 // ks.norb ** 2)
104 if second:
105 # d^2 H / dk_a dk_b is the first derivative of the Bloch sum of the
106 # hoppings t * i(d.u_a): the same _bloch_sum, with rescaled amplitudes.
107 hops = ks._hop
108 d = np.array([h[2] for h in hops], dtype='f8').reshape(len(hops), ks.space_dim)
109 if positions:
110 tau = ks.orbital_positions()
111 d = d + tau[[h[1] for h in hops]] - tau[[h[0] for h in hops]]
112 scaled = [[(h[0], h[1], h[2], h[3] * 1j * (dd @ u)) for h, dd in zip(hops, d)]
113 for u in directions]
114 for c0 in range(0, len(kpts), chunk):
115 kc = kpts[c0:c0 + chunk]
116 ham, dham = ks._bloch_derivatives(kc, directions, positions)
117 en, vec = np.linalg.eigh(ham)
118 vh = vec.conj().transpose(0, 2, 1)
119 vel = np.array([vh @ dh @ vec for dh in dham])
120 if not second:
121 yield en, vel
122 continue
123 k_cart = kc @ ks.k_basis.T
124 w = np.array([ks._bloch_sum(h, k_cart, directions, positions)[1] for h in scaled])
125 yield en, vel, vh[None, None] @ w @ vec[None, None]
128def _as_output(values: NDArray, like: ArrayLike) -> Any:
129 '''
130 Private function. A scalar for a scalar input, else shaped like it.
131 '''
132 if np.ndim(like) == 0:
133 return values[0]
134 return values.reshape(np.shape(like) + values.shape[1:])
137def optical_conductivity(
138 ks: KSpace, omega: float | ArrayLike, e_fermi: float = 0., temperature: float = 0.,
139 eta: float = 0.05, nk: int | tuple[int, int] = 100, component: str = 'xx',
140 positions: bool = True,
141) -> complex | NDArray[np.complex128]:
142 r'''
143 Get the optical conductivity :math:`\sigma_{ab}(\omega)` of a 2D model
144 from the Kubo-Greenwood formula over a uniform Brillouin-zone mesh,
146 .. math::
148 \sigma_{ab}(\omega) = \frac{i e^2}{\hbar}\int\frac{d^2k}{(2\pi)^2}
149 \sum_{n,m}\frac{f_n - f_m}{E_m - E_n}\,
150 \frac{v^a_{nm}\,v^b_{mn}}{\hbar\omega + E_n - E_m + i\eta}\, ,
152 with :math:`v^a_{nm} = \langle n|\partial H/\partial k_a|m\rangle`,
153 :math:`f_n` the Fermi-Dirac occupations at *e_fermi* and *temperature*,
154 and :math:`\eta` a phenomenological broadening (the inverse lifetime).
155 Pairs of degenerate states, :math:`n = m` included, enter through the
156 limit :math:`(f_n-f_m)/(E_m-E_n)\to-\partial f/\partial E`: the
157 intraband (Drude) term :math:`\frac{i}{\hbar\omega+i\eta}\sum_n
158 (-f'_n)v^a_{nn}v^b_{nn}`. It samples the Fermi surface only through the
159 thermal window, so it needs a *temperature* larger than the level
160 spacing of the mesh; at ``temperature=0`` only the interband part is
161 computed.
163 It is the Ohm's-law tensor, :math:`j_a = \sigma_{ab}E_b`. In a gap its
164 static Hall part is the TKNN conductance:
165 :math:`\sigma_{yx}(0) = -\sigma_{xy}(0)` equals
166 *KSpace.hall_conductivity* (which returns :math:`\sigma^{\mathrm{Ohm}}_{yx}`,
167 see its docstring). The absorptive part obeys the f-sum rule
168 :math:`\int_0^\infty\mathrm{Re}\,\sigma_{aa}\,d\omega =
169 \frac{\pi e^2}{2\hbar^2}\int\frac{d^2k}{(2\pi)^2}\sum_n f_n\langle n|\partial_a^2H|n\rangle`.
170 For graphene at neutrality, :math:`\mathrm{Re}\,\sigma_{xx} \to
171 \frac{e^2}{16\hbar}` per spin and valley for :math:`\eta \ll \hbar\omega
172 \ll t`: the universal :math:`\sigma_0 = e^2/4\hbar` once spin and
173 valleys are counted, :math:`\pi/4` in units of :math:`e^2/h` for a
174 spinless model.
176 Parameters
177 ----------
178 ks : **KSpace** instance, 2D, Hermitian
179 omega : Real number or array of real numbers
180 Photon energies
181 :math:`\hbar\omega`.
182 e_fermi : Real number, default 0
183 Fermi energy.
184 temperature : Positive real or zero
185 Default value 0 (:math:`k_B = 1`).
186 eta : Positive real, default 0.05
187 Broadening, larger than
188 the spacing of the transition energies on the mesh.
189 nk : Positive integer, or tuple of 2, default 100
190 k-mesh.
191 component : 'xx', 'xy', 'yx' or 'yy', default 'xx'
192 positions : Boolean, default True
193 Orbital positions in the
194 bond vectors (see *KSpace.hall_conductivity*).
196 Returns
197 -------
198 sigma
199 Complex number (or ndarray shaped like *omega*), in
200 units of :math:`e^2/h`.
201 '''
202 kpts = _mesh(ks, nk, positions)
203 error_handling.frequencies(omega, 'omega')
204 error_handling.real_number(e_fermi, 'e_fermi')
205 error_handling.positive_real_zero(temperature, 'temperature')
206 error_handling.positive_real(eta, 'eta')
207 a, b = error_handling.tensor_component(component, 2)
208 w_arr = np.atleast_1d(np.asarray(omega, dtype='f8')).ravel()
209 total = np.zeros(len(w_arr), 'c16')
210 for en, vel in _bands(ks, kpts, positions):
211 f = occupation.fermi_dirac(en, e_fermi, temperature)
212 minus_df = f * (1. - f) / temperature if temperature > 0 else np.zeros_like(f)
213 de = en[:, None, :] - en[:, :, None] # E_m - E_n
214 degenerate = np.abs(de) < _DEGENERATE
215 ratio = np.where(degenerate, minus_df[:, :, None],
216 (f[:, :, None] - f[:, None, :]) / np.where(degenerate, 1., de))
217 weight = ratio * vel[a] * vel[b].transpose(0, 2, 1)
218 keep = weight != 0
219 wk, dk = weight[keep], np.where(degenerate, 0., de)[keep]
220 step = max(1, 2000000 // len(w_arr))
221 for c0 in range(0, len(wk), step):
222 total += (wk[None, c0:c0 + step]
223 / (w_arr[:, None] - dk[None, c0:c0 + step] + 1j * eta)).sum(axis=1)
224 sigma = 1j * 2 * np.pi * total / (len(kpts) * cell_area(ks))
225 return _as_output(sigma, omega)
228def joint_dos(
229 ks: KSpace, omega: float | ArrayLike, e_fermi: float = 0., temperature: float = 0.,
230 eta: float = 0.05, nk: int | tuple[int, int] = 100,
231) -> float | NDArray[np.float64]:
232 r'''
233 Get the joint density of states of the vertical (interband) transitions,
234 per unit cell,
236 .. math::
238 J(\omega) = \frac{1}{N_k}\sum_{\mathbf{k}}\sum_{n\neq m}
239 f_n\,(1 - f_m)\,\delta(\hbar\omega - E_m + E_n)\, ,
241 with the delta function a Gaussian of standard deviation :math:`\eta`.
242 Its integral over :math:`\omega` is the number of (occupied, empty)
243 pairs per k-point. For graphene at neutrality,
244 :math:`J = A_c\,\hbar\omega/(4\pi\hbar^2 v_F^2)` near the Dirac points
245 (both valleys, per spin).
247 Parameters
248 ----------
249 ks : **KSpace** instance, 2D, Hermitian
250 omega : Real number or array of real numbers
251 Photon energies.
252 e_fermi : Real number, default 0
253 temperature : Positive real or zero, default 0
254 eta : Positive real, default 0.05
255 Gaussian width.
256 nk : Positive integer, or tuple of 2, default 100
258 Returns
259 -------
260 jdos
261 Real number (or ndarray shaped like *omega*), in states
262 per unit cell and per unit energy.
263 '''
264 kpts = _mesh(ks, nk, True)
265 error_handling.frequencies(omega, 'omega')
266 error_handling.real_number(e_fermi, 'e_fermi')
267 error_handling.positive_real_zero(temperature, 'temperature')
268 error_handling.positive_real(eta, 'eta')
269 w_arr = np.atleast_1d(np.asarray(omega, dtype='f8')).ravel()
270 total = np.zeros(len(w_arr))
271 for en, _ in _bands(ks, kpts, False):
272 f = occupation.fermi_dirac(en, e_fermi, temperature)
273 weight = f[:, :, None] * (1. - f[:, None, :])
274 weight[:, np.arange(ks.norb), np.arange(ks.norb)] = 0.
275 keep = weight > 0
276 wk = weight[keep]
277 dk = (en[:, None, :] - en[:, :, None])[keep]
278 total += _gaussian_sum(w_arr, dk, wk, eta)
279 return _as_output(total / len(kpts), omega)
282def _gaussian_sum(
283 x: NDArray[np.float64], centers: NDArray[np.float64], weights: NDArray[np.float64], eta: float,
284) -> NDArray[np.float64]:
285 r'''
286 Private function. :math:`\sum_i w_i\,g(x - c_i)` with the normalized
287 Gaussian :math:`g` of standard deviation *eta*, in chunks of the centers.
288 '''
289 out = np.zeros(len(x))
290 step = max(1, 2000000 // len(x))
291 for c0 in range(0, len(centers), step):
292 u = (x[:, None] - centers[None, c0:c0 + step]) / eta
293 out += (weights[None, c0:c0 + step] * np.exp(-0.5 * u ** 2)).sum(axis=1)
294 return out / (np.sqrt(2 * np.pi) * eta)
297def berry_curvature_dipole(
298 ks: KSpace, e_fermi: float | ArrayLike, temperature: float,
299 nk: int | tuple[int, int] = 100, positions: bool = True,
300) -> NDArray[np.float64]:
301 r'''
302 Get the Berry curvature dipole of a 2D model (Sodemann and Fu, Phys.
303 Rev. Lett. 115, 216806 (2015)),
305 .. math::
307 D_a = \int\frac{d^2k}{(2\pi)^2}\sum_n f_n\,\partial_a\Omega_n
308 = \int\frac{d^2k}{(2\pi)^2}\sum_n
309 \left(-\frac{\partial f}{\partial E}\right)_{E_n}
310 v^a_{nn}\,\Omega_n\, ,
312 the first moment of the Berry curvature :math:`\Omega_n` (the
313 convention of *KSpace.berry_curvature* and *hall_conductivity*,
314 :math:`\Omega_n = -2\,\mathrm{Im}\sum_{m\neq n}v^x_{nm}v^y_{mn}/(E_n-E_m)^2`)
315 over the occupied states. It is a Fermi-surface property: the second
316 form, used here, samples it through the thermal window
317 :math:`-\partial f/\partial E`, so *temperature* must be positive and
318 larger than the level spacing of the mesh near :math:`E_F`. A finite
319 dipole needs broken inversion symmetry and a single mirror line at
320 most. In a DC field it drives the nonlinear Hall current
321 :math:`j_a = \chi_{abc}E_bE_c`,
322 :math:`\chi_{abc} = -\varepsilon_{adc}\frac{e^3\tau}{2\hbar^2(1+i\omega\tau)}D_{bd}`,
323 with :math:`D_{bd} = D_b` along :math:`d = z` in 2D.
325 For the tilted massive Dirac cone
326 :math:`H = t k_x + v(k_x\sigma_x + k_y\sigma_y) + m\sigma_z` doped into
327 the conduction band (:math:`\mu > |m|`), the first order in the tilt is
328 :math:`D_x = -\frac{3\,t\,m\,(\mu^2 - m^2)}{8\pi\mu^4}`,
329 :math:`D_y = 0`, from :math:`\Omega_c = -mv^2/2\varepsilon^3`
330 (Sodemann and Fu's model, in these conventions).
332 Parameters
333 ----------
334 ks : **KSpace** instance, 2D, Hermitian
335 e_fermi : Real number, or array of real numbers
336 Fermi energies.
337 temperature : Positive real
338 Temperature (:math:`k_B = 1`).
339 nk : Positive integer, or tuple of 2, default 100
340 positions : Boolean, default True
341 See *KSpace.hall_conductivity*.
343 Returns
344 -------
345 dipole
346 Real ndarray of shape (2,): :math:`(D_x, D_y)` (or
347 ``e_fermi.shape + (2,)``), in units of length (of *prim_vec*).
348 '''
349 kpts = _mesh(ks, nk, positions)
350 error_handling.no_position_elements(positions and bool(ks._position_hop), 'berry_curvature_dipole')
351 error_handling.fermi_energies(e_fermi)
352 error_handling.positive_real(temperature, 'temperature')
353 mus = np.atleast_1d(np.asarray(e_fermi, dtype='f8')).ravel()
354 total = np.zeros((len(mus), 2))
355 for en, vel in _bands(ks, kpts, positions):
356 de = en[:, :, None] - en[:, None, :]
357 degenerate = np.abs(de) < _DEGENERATE
358 inv2 = np.where(degenerate, 0., 1. / np.where(degenerate, 1., de) ** 2)
359 omega_n = -2 * np.sum(np.imag(vel[0] * vel[1].transpose(0, 2, 1)) * inv2, axis=2)
360 vdiag = np.real(np.diagonal(vel, axis1=2, axis2=3)) # (2, nk, n)
361 for e, mu in enumerate(mus):
362 f = occupation.fermi_dirac(en, float(mu), temperature)
363 window = f * (1. - f) / temperature
364 total[e] += np.einsum('kn,akn->a', window * omega_n, vdiag)
365 return _as_output(total / (len(kpts) * cell_area(ks)), e_fermi)
368def generalized_derivative(
369 en: NDArray[np.float64], vel: NDArray[np.complex128], w: NDArray[np.complex128],
370) -> tuple[NDArray[np.complex128], NDArray[np.complex128]]:
371 r'''
372 Get the interband position matrix elements and their generalized
373 derivatives from the band energies and the first and second derivatives
374 of :math:`H` in the eigenbasis (a sum over states, Sipe and Shkrebtii
375 2000; Cook et al. 2017; :math:`\hbar = 1`, :math:`\omega_{nm} = E_n - E_m`,
376 :math:`\Delta^a_{nm} = v^a_{nn} - v^a_{mm}`):
378 .. math::
380 r^b_{nm} = \frac{v^b_{nm}}{i\omega_{nm}}\, ,\qquad
381 r^b_{nm;a} = \frac{i}{\omega_{nm}}\left[
382 \frac{v^b_{nm}\Delta^a_{nm} + v^a_{nm}\Delta^b_{nm}}{\omega_{nm}}
383 - w^{ba}_{nm} + \sum_{p\neq n,m}\left(
384 \frac{v^b_{np}v^a_{pm}}{\omega_{pm}} - \frac{v^a_{np}v^b_{pm}}{\omega_{np}}
385 \right)\right]\, ,
387 :math:`r^b_{nm;a} = \partial_ar^b_{nm} - i(A^a_{nn} - A^a_{mm})r^b_{nm}`,
388 gauge covariant. Degenerate pairs (:math:`|\omega_{nm}| < 10^{-9}`) are
389 set to zero, and dropped from the sum over :math:`p`.
391 Parameters
392 ----------
393 en : Real ndarray, shape (nk, n)
394 Band energies.
395 vel : Complex ndarray, shape (2, nk, n, n)
396 :math:`v^a_{nm}`.
397 w : Complex ndarray, shape (2, 2, nk, n, n)
398 :math:`w^{ab}_{nm} =
399 \langle n|\partial_a\partial_bH|m\rangle`.
401 Returns
402 -------
403 r : Complex ndarray, shape (2, nk, n, n): r[b] is :math:`r^b_{nm}`
404 r_der
405 Complex ndarray, shape (2, 2, nk, n, n): r_der[b, a]
406 is :math:`r^b_{nm;a}`.
407 '''
408 en, vel, w = np.asarray(en), np.asarray(vel), np.asarray(w)
409 error_handling.band_derivatives(en, vel, w)
410 om = en[:, :, None] - en[:, None, :]
411 degenerate = np.abs(om) < _DEGENERATE
412 inv = np.where(degenerate, 0., 1. / np.where(degenerate, 1., om))
413 diag = np.diagonal(vel, axis1=2, axis2=3) # (2, nk, n)
414 delta = diag[:, :, :, None] - diag[:, :, None, :]
415 r = -1j * vel * inv[None]
416 r_der = np.zeros((2, 2) + om.shape, 'c16')
417 for b in range(2):
418 for a in range(2):
419 # the full sums over p include p = n, m: those terms add
420 # Delta^b v^a / omega, removed again below
421 full = vel[b] @ (vel[a] * inv) - (vel[a] * inv) @ vel[b]
422 bracket = ((vel[b] * delta[a] + vel[a] * delta[b]) * inv - w[b, a] + full
423 - vel[a] * delta[b] * inv)
424 r_der[b, a] = 1j * inv * bracket
425 return r, r_der
428def shift_current(
429 ks: KSpace, omega: float | ArrayLike, e_fermi: float = 0., temperature: float = 0.,
430 eta: float = 0.05, nk: int | tuple[int, int] = 100, component: str = 'xxx',
431 positions: bool = True,
432) -> float | NDArray[np.float64]:
433 r'''
434 Get the shift-current conductivity of a 2D model under linearly
435 polarized light (Sipe and Shkrebtii, Phys. Rev. B 61, 5337 (2000)),
436 :math:`j^a = 2\sigma^{abc}(0;\omega,-\omega)E^b(\omega)E^c(-\omega)`,
438 .. math::
440 \sigma^{abc}(\omega) = -\frac{\pi e^3}{2\hbar^2}\int\frac{d^2k}{(2\pi)^2}
441 \sum_{n,m}f_{nm}\,\mathrm{Im}\left[r^b_{mn}r^c_{nm;a}
442 + r^c_{mn}r^b_{nm;a}\right]\delta(\omega_{mn} - \omega)\, ,
444 :math:`f_{nm} = f_n - f_m`, with the position matrix elements
445 :math:`r` and their generalized derivatives from
446 :func:`generalized_derivative` (a sum over states, with the exact second
447 derivatives of :math:`H`). The delta function is a Gaussian of standard
448 deviation :math:`\eta`. For :math:`b = c`,
449 :math:`\mathrm{Im}[r^b_{mn}r^b_{nm;a}] = |r^b_{nm}|^2R^{a,b}_{nm}` with
450 :math:`R^{a,b}_{nm}` the shift vector, the real-space displacement of
451 the electron in the transition. It vanishes with inversion symmetry.
452 Unlike the Hall conductance of full bands, it depends on where the
453 orbitals sit in the cell (Ibanez-Azpiroz, Tsirkin and Souza, Phys. Rev.
454 B 97, 245143 (2018)): ``positions=False``, which puts them all at the
455 cell origin, describes a different crystal.
457 Parameters
458 ----------
459 ks : **KSpace** instance, 2D, Hermitian, without overlap
460 omega : Real number or array of real numbers
461 Photon energies :math:`\hbar\omega`.
462 e_fermi : Real number, default 0
463 temperature : Positive real or zero, default 0
464 eta : Positive real, default 0.05
465 Gaussian width.
466 nk : Positive integer, or tuple of 2, default 100
467 component
468 Three letters among 'x', 'y' (current direction, then
469 the two field directions). Default value 'xxx'.
470 positions : Boolean, default True
471 See *KSpace.hall_conductivity*.
473 Returns
474 -------
475 sigma
476 Real number (or ndarray shaped like *omega*), in units
477 of :math:`e^3/\hbar\times` length / energy (:math:`\hbar = e = 1`),
478 counting each orbital once.
479 '''
480 kpts = _mesh(ks, nk, positions)
481 error_handling.no_overlap(bool(ks._overlap_hop))
482 error_handling.no_position_elements(positions and bool(ks._position_hop), 'shift_current')
483 error_handling.frequencies(omega, 'omega')
484 error_handling.real_number(e_fermi, 'e_fermi')
485 error_handling.positive_real_zero(temperature, 'temperature')
486 error_handling.positive_real(eta, 'eta')
487 a, b, c = error_handling.tensor_component(component, 3)
488 w_arr = np.atleast_1d(np.asarray(omega, dtype='f8')).ravel()
489 total = np.zeros(len(w_arr))
490 for en, vel, w in _bands(ks, kpts, positions, second=True):
491 r, r_der = generalized_derivative(en, vel, w)
492 f = occupation.fermi_dirac(en, e_fermi, temperature)
493 fnm = f[:, :, None] - f[:, None, :]
494 integrand = np.imag(r[b].transpose(0, 2, 1) * r_der[c, a]
495 + r[c].transpose(0, 2, 1) * r_der[b, a]) * fnm
496 keep = integrand != 0
497 wmn = (en[:, None, :] - en[:, :, None])[keep]
498 total += _gaussian_sum(w_arr, wmn, integrand[keep], eta)
499 sigma = -np.pi / 2 * total / (len(kpts) * cell_area(ks))
500 return _as_output(sigma, omega)