Skip to content
Snippets Groups Projects
Forked from kwant / kwant
281 commits behind, 106 commits ahead of the upstream repository.
operators.rst 19.70 KiB

Computing local quantities: densities and currents

In the previous tutorials we have mainly concentrated on calculating global properties such as conductance and band structures. Often, however, insight can be gained from calculating locally-defined quantities, that is, quantities defined over individual sites or hoppings in your system. In the :ref:`closed-systems` tutorial we saw how we could visualize the density associated with the eigenstates of a system using kwant.plotter.map.

In this tutorial we will see how we can calculate more general quantities than simple densities by studying spin transport in a system with a magnetic texture.

Introduction

Our starting point will be the following spinful tight-binding model on a square lattice:

H = - \sum_{\langle ij\rangle }\sum_{\alpha } |i\alpha \rangle \langle j\alpha |
    + J \sum_{i}\sum_{\alpha \beta } \mathbf{m}_i\cdot  \mathbf{\sigma }_{\alpha \beta } |i\alpha \rangle \langle i\beta |,

where latin indices run over sites, and greek indices run over spin. We can identify the first term as a nearest-neighbor hopping between like-spins, and the second as a term that couples spins on the same site. The second term acts like a magnetic field of strength J that varies from site to site and that, on site i, points in the direction of the unit vector \mathbf{m}_i. \mathbf{\sigma }_{\alpha \beta } is a vector of Pauli matrices. We shall take the following form for \mathbf{m}_i:

\mathbf{m}_i &=\ \left(
    \frac{x_i}{x_i^2 + y_i^2} \sin \theta _i,\
    \frac{y_i}{x_i^2 + y_i^2} \sin \theta _i,\
    \cos \theta _i \right)^T,
\\
\theta _i &=\ \frac{\pi }{2} (\tanh \frac{r_i - r_0}{\delta } - 1),

where x_i and y_i are the x and y coordinates of site i, and r_i = \sqrt{x_i^2 + y_i^2}.

To define this model in Kwant we start as usual by defining functions that depend on the model parameters:

and define our system as a square shape on a square lattice with two orbitals per site, with leads attached on the left and right:

Below is a plot of a projection of \mathbf{m}_i onto the x-y plane inside the scattering region. The z component is shown by the color scale:

We will now be interested in analyzing the form of the scattering states that originate from the left lead:

Local densities

If we were simulating a spinless system with only a single degree of freedom, then calculating the density on each site would be as simple as calculating the absolute square of the wavefunction like:

density = np.abs(psi)**2

When there are multiple degrees of freedom per site, however, one has to be more careful. In the present case with two (spin) degrees of freedom per site one could calculate the per-site density like:

With more than one degree of freedom per site we have more freedom as to what local quantities we can meaningfully compute. For example, we may wish to calculate the local z-projected spin density. We could calculate this in the following way:

If we wanted instead to calculate the local y-projected spin density, we would need to use an even more complicated expression:

The kwant.operator module aims to alleviate somewhat this tedious book-keeping by providing a simple interface for defining operators that act on wavefunctions. To calculate the above quantities we would use the ~kwant.operator.Density operator like so:

~kwant.operator.Density takes a ~kwant.system.System as its first parameter as well as (optionally) a square matrix that defines the quantity that you wish to calculate per site. When an instance of a ~kwant.operator.Density is then evaluated with a wavefunction, the quantity

\rho _i = \mathbf{\psi }^\dagger _i \mathbf{M} \mathbf{\psi }_i

is calculated for each site i, where \mathbf{\psi }_{i} is a vector consisting of the wavefunction components on that site and \mathbf{M} is the square matrix referred to previously.

Below we can see colorplots of the above-calculated quantities. The array that is returned by evaluating a ~kwant.operator.Density can be used directly with kwant.plotter.density:

Local currents

kwant.operator also has a class ~kwant.operator.Current for calculating local currents, analogously to the local "densities" described above. If one has defined a density via a matrix \mathbf{M} and the above equation, then one can define a local current flowing from site b to site a:

J_{ab} = i \left(
\mathbf{\psi }^\dagger _b (\mathbf{H}_{ab})^\dagger  \mathbf{M} \mathbf{\psi }_a
- \mathbf{\psi }^\dagger _a \mathbf{M} \mathbf{H}_{ab} \mathbf{\psi }_b
\right),

where \mathbf{H}_{ab} is the hopping matrix from site b to site a. For example, to calculate the local current and spin current:

Evaluating a ~kwant.operator.Current operator on a wavefunction returns a 1D array of values that can be directly used with kwant.plotter.current:

Note

Evaluating a ~kwant.operator.Current operator on a wavefunction returns a 1D array of the same length as the number of hoppings in the system, ordered in the same way as the edges in the system's graph.

Spatially varying operators

The above examples are reasonably simple in the sense that the book-keeping required to manually calculate the various densities and currents is still manageable. Now we shall look at the case where we wish to calculate some projected spin currents, but where the spin projection axis varies from place to place. More specifically, we want to visualize the spin current along the direction of \mathbf{m}_i, which changes continuously over the whole scattering region.

Doing this is as simple as passing a function when instantiating the ~kwant.operator.Current, instead of a constant matrix:

The function must take a ~kwant.system.Site as its first parameter, and may optionally take other parameters (i.e. it must have the same signature as a Hamiltonian onsite function), and must return the square matrix that defines the operator we wish to calculate.

Note

In the above example we had to pass the extra parameters needed by the following_operator function via the params keyword argument. In general you must pass all the parameters needed by the Hamiltonian via params (as you would when calling ~kwant.solvers.default.smatrix or ~kwant.solvers.default.wave_function). In the previous examples, however, we used the fact that the system hoppings do not depend on any parameters (these are the only Hamiltonian elements required to calculate currents) to avoid passing the system parameters for the sake of brevity.

Using this we can see that the spin current is essentially oriented along the direction of m_i in the present regime where the onsite term in the Hamiltonian is dominant:

Note

Although this example used exclusively ~kwant.operator.Current, you can do the same with ~kwant.operator.Density.

Defining operators over parts of a system

Another useful feature of kwant.operator is the ability to calculate operators over selected parts of a system. For example, we may wish to calculate the total density of states in a certain part of the system, or the current flowing through a cut in the system. We can do this selection when creating the operator by using the keyword parameter where.

Density of states in a circle

To calculate the density of states inside a circle of radius 20 we can simply do:

note that we also provide sum=True, which means that evaluating the operator on a wavefunction will produce a single scalar. This is semantically equivalent to providing sum=False (the default) and running numpy.sum on the output.

Current flowing through a cut

Below we calculate the probability current and z-projected spin current near the interfaces with the left and right leads.

We see that the probability current is conserved across the scattering region, but the z-projected spin current is not due to the fact that the Hamiltonian does not commute with \sigma _z everywhere in the scattering region.

Note

where can also be provided as a sequence of ~kwant.system.Site or a sequence of hoppings (i.e. pairs of ~kwant.system.Site), rather than a function.

Advanced Topics

Using bind for speed

In most of the above examples we only used each operator once after creating it. Often one will want to evaluate an operator with many different wavefunctions, for example with all scattering wavefunctions at a certain energy, but with the same set of parameters. In such cases it is best to tell the operator to pre-compute the onsite matrices and any necessary Hamiltonian elements using the given set of parameters, so that this work is not duplicated every time the operator is evaluated.

This can be achieved with ~kwant.operator.Current.bind:

Warning

Take care that you do not use an operator that was bound to a particular set of parameters with wavefunctions calculated with a different set of parameters. This will almost certainly give incorrect results.