Skip to content
Snippets Groups Projects
Commit 63bcf5a7 authored by Christoph Groth's avatar Christoph Groth Committed by Joseph Weston
Browse files

fix many small things in FAQ

parent 7e121da3
Branches
No related tags found
No related merge requests found
--- original
+++ modified
@@ -1,6 +1,7 @@
# Frequently Asked Questions
# ==========================
@@ -3,6 +3,7 @@
# This script is a disorganized collection of code snippets. As a whole, it is
# not meant as an example of good programming practice.
+import _defs
import kwant
import numpy as np
import tinyarray
@@ -9,6 +10,12 @@
@@ -11,6 +12,12 @@
matplotlib.rcParams['figure.figsize'] = (3.5, 3.5)
......@@ -18,34 +18,34 @@
+ dpi=_defs.dpi, bbox_inches='tight')
+
+
######## What is a Site? ##############
#### What is a Site?
a = 1
@@ -19,6 +26,7 @@
@@ -21,6 +28,7 @@
syst[lat(1, 1)] = 4
kwant.plot(syst)
+save_figure("faq_site")
@@ -40,6 +48,7 @@
syst[lat2(0, 0)] = 4 # syst[subB(0, 0)] = 4
#### What is a hopping?
@@ -34,6 +42,7 @@
syst[(lat(1, 0), lat(1, 1))] = 1j
kwant.plot(syst)
+save_figure("faq_lattice")
+save_figure("faq_hopping")
########## What is a hopping? #######################
@@ -53,6 +62,7 @@
syst[(lat(1, 0), lat(1, 1))] = -1
#### What is a lattice?
@@ -50,6 +59,7 @@
syst[lat_b(0, 0)] = 4
kwant.plot(syst)
+save_figure("faq_hopping")
########### How to make a hole in a system? ###################"
+save_figure("faq_lattice")
@@ -69,6 +79,7 @@
# One polyatomic lattice containing two sublattices
lat = kwant.lattice.Polyatomic([(1, 0), (0, 1)], [(0, 0), (0.5, 0.5)])
@@ -70,6 +80,7 @@
syst[(lat(i, j, k) for i in range(L) for j in range(W) for k in range(H))] = 4
kwant.plot(syst)
......@@ -53,24 +53,24 @@
# Delete sites to create a hole
@@ -80,6 +91,7 @@
@@ -81,6 +92,7 @@
del syst[site]
kwant.plot(syst)
+save_figure("faq_hole2")
################ How can we get access to the sites of our system? ####################
@@ -133,7 +145,7 @@
#### How can we get access to the sites of our system?
@@ -127,7 +139,7 @@
## Plotting the system
## Plot the system.
plot_system(syst)
-
+save_figure("faq_colors")
#### How to create all hoppings in a given direction using Hoppingkind?
############### How to create all hoppings in a given direction using Hoppingkind? ################
@@ -149,6 +161,7 @@
@@ -141,6 +153,7 @@
syst[kwant.builder.HoppingKind((1, 0), lat)] = -1
kwant.plot(syst)
......@@ -78,7 +78,7 @@
# Polyatomic lattice
@@ -181,12 +194,14 @@
@@ -171,12 +184,14 @@
# equivalent to syst[kwant.builder.HoppingKind((0, 1), b)] = -1
syst[kwant.builder.HoppingKind((0, 1), b, b)] = -1
plot_system(syst)
......@@ -92,8 +92,8 @@
+save_figure("faq_direction3")
########## How to create the hoppings between adjacent sites? ################
@@ -201,11 +216,13 @@
#### How to create the hoppings between adjacent sites?
@@ -190,11 +205,13 @@
syst[lat.neighbors()] = -1 # Equivalent to lat.neighbors(1)
kwant.plot(syst)
......@@ -107,7 +107,7 @@
# Polyatomic lattice
@@ -224,9 +241,11 @@
@@ -213,9 +230,11 @@
syst[lat.neighbors()] = -1
plot_system(syst)
......@@ -119,35 +119,35 @@
del syst[a.neighbors()] # Delete the hoppings previously created
@@ -264,6 +283,7 @@
@@ -253,6 +272,7 @@
syst[(subB(i, j) for i in range(L) for j in range(W))] = 4
syst[lat.neighbors()] = -1
plot_system(syst)
+save_figure("faq_different_latticea1")
+save_figure("faq_different_lattice1")
# Create a lead
lat_lead = kwant.lattice.square()
@@ -273,6 +293,7 @@
@@ -262,6 +282,7 @@
lead1[(lat_lead(i, 0) for i in range(2, 7))] = 4
lead1[lat_lead.neighbors()] = -1
plot_system(lead1)
+save_figure("faq_different_latticea2")
+save_figure("faq_different_lattice2")
syst[(lat_lead(i, 5) for i in range(2, 7))] = 4
syst[lat_lead.neighbors()] = -1
@@ -280,9 +301,11 @@
@@ -269,9 +290,11 @@
# Manually attach sites from graphene to square lattice
syst[((lat_lead(i+2, 5), subB(i, 4)) for i in range(5))] = -1
plot_system(syst)
+save_figure("faq_different_latticea3")
+save_figure("faq_different_lattice3")
syst.attach_lead(lead1)
plot_system(syst)
+save_figure("faq_different_latticea4")
+save_figure("faq_different_lattice4")
############# How to cut a finite system out of a system with translationnal symmetries? ###########
@@ -302,6 +325,7 @@
#### How to cut a finite system out of a system with translationnal symmetries?
@@ -291,6 +314,7 @@
cuboid = kwant.Builder()
cuboid.fill(model, cuboid_shape, (0, 0, 0));
kwant.plot(cuboid);
......@@ -155,31 +155,31 @@
# Build electrode (black).
def electrode_shape(site):
@@ -316,6 +340,7 @@
@@ -305,6 +329,7 @@
cuboid.attach_lead(electrode)
kwant.plot(cuboid);
+save_figure("faq_fill3")
###### How does Kwant order the propagating modes of a lead? ######
@@ -348,6 +373,7 @@
#### How does Kwant order the propagating modes of a lead?
@@ -337,6 +362,7 @@
plt.show()
plot_and_label_modes(flead, E)
+save_figure('faq_pm1')
plt.clf()
# More involved example
@@ -363,6 +389,7 @@
@@ -351,6 +377,7 @@
flead2 = lead2.finalized()
plot_and_label_modes(flead2, 1)
+save_figure('faq_pm2')
plt.clf()
@@ -395,7 +422,8 @@
#### How does Kwant order components of an individual wavefunction?
@@ -381,7 +408,8 @@
idx = syst.id_by_site[lat(0, 0)] # look up index of site
......@@ -189,7 +189,7 @@
lat = kwant.lattice.square(norbs=2)
syst = make_system(lat)
@@ -408,4 +436,5 @@
@@ -394,4 +422,5 @@
# to degrees of freedom on the same site.
wf = wf.reshape(-1, 2)
......
# Frequently Asked Questions
# ==========================
# Frequently asked questions
#
# This script is a disorganized collection of code snippets. As a whole, it is
# not meant as an example of good programming practice.
import kwant
import numpy as np
......@@ -9,7 +11,7 @@ from matplotlib import pyplot as plt
matplotlib.rcParams['figure.figsize'] = (3.5, 3.5)
######## What is a Site? ##############
#### What is a Site?
#HIDDEN_BEGIN_site
a = 1
......@@ -23,44 +25,45 @@ kwant.plot(syst)
#HIDDEN_END_site
#### What is a hopping?
################# What is a family? a tag? a lattice? ##################
#HIDDEN_BEGIN_lattice
# 2 Monatomic lattices
primitive_vectors = [(1, 0), (0, 1)]
lat1 = kwant.lattice.Monatomic(primitive_vectors, offset=(0, 0)) # equivalent to kwant.lattice.square()
lat2 = kwant.lattice.Monatomic(primitive_vectors, offset=(0.5, 0.5))
# 1 Polyatomic lattice containing two sublattices
lat3 = kwant.lattice.Polyatomic([(1, 0) , (0, 1)], [(0, 0) , (0.5, 0.5)])
subA, subB = lat3.sublattices
a = 1
lat = kwant.lattice.square(a)
syst = kwant.Builder()
syst[lat1(0, 0)] = 4 # syst[subA(0, 0)] = 4
syst[lat2(0, 0)] = 4 # syst[subB(0, 0)] = 4
syst[lat(1, 0)] = 4
syst[lat(1, 1)] = 4
#HIDDEN_BEGIN_hopping
syst[(lat(1, 0), lat(1, 1))] = 1j
#HIDDEN_END_hopping
kwant.plot(syst)
#HIDDEN_END_lattice
########## What is a hopping? #######################
#### What is a lattice?
#HIDDEN_BEGIN_lattice_monatomic
# Two monatomic lattices
primitive_vectors = [(1, 0), (0, 1)]
lat_a = kwant.lattice.Monatomic(primitive_vectors, offset=(0, 0))
lat_b = kwant.lattice.Monatomic(primitive_vectors, offset=(0.5, 0.5))
# lat1 is equivalent to kwant.lattice.square()
a = 1
lat = kwant.lattice.square(a)
syst = kwant.Builder()
syst[lat(1, 0)] = 4
syst[lat(1, 1)] = 4
#HIDDEN_BEGIN_hopping
syst[(lat(1, 0), lat(1, 1))] = -1
#HIDDEN_END_hopping
syst[lat_a(0, 0)] = 4
syst[lat_b(0, 0)] = 4
kwant.plot(syst)
#HIDDEN_END_lattice_monatomic
#HIDDEN_BEGIN_lattice_polyatomic
# One polyatomic lattice containing two sublattices
lat = kwant.lattice.Polyatomic([(1, 0), (0, 1)], [(0, 0), (0.5, 0.5)])
sub_a, sub_b = lat.sublattices
#HIDDEN_END_lattice_polyatomic
########### How to make a hole in a system? ###################"
#### How to make a hole in a system?
#HIDDEN_BEGIN_hole
# Define the lattice and the (empty) system
......@@ -90,7 +93,7 @@ kwant.plot(syst)
#HIDDEN_END_hole
################ How can we get access to the sites of our system? ####################
#### How can we get access to the sites of our system?
builder = kwant.Builder()
lat = kwant.lattice.square()
......@@ -99,7 +102,6 @@ builder[(lat(i, j) for i in range(3) for j in range(3))] = 4
# Before finalizing the system
sites = list(builder.sites()) # sites() doe *not* return a list
#HIDDEN_END_sites1
#HIDDEN_BEGIN_sites2
# After finalizing the system
......@@ -111,7 +113,7 @@ i = syst.id_by_site[lat(0, 2)] # we want the id of the site lat(0, 2)
#HIDDEN_END_sites3
################ How to plot a polyatomic lattice with different colors? ##############"
#### How to plot a polyatomic lattice with different colors?
#HIDDEN_BEGIN_colors1
lat = kwant.lattice.kagome()
......@@ -122,44 +124,36 @@ a, b, c = lat.sublattices # The kagome lattice has 3 sublattices
#HIDDEN_BEGIN_colors2
# Plot sites from different families in different colors
def family_color(site):
if site.family == a:
return 'red'
if site.family == b:
return 'green'
else:
return 'blue'
def plot_system(syst):
kwant.plot(syst, site_lw=0.1, site_color=family_color)
def family_color(site):
if site.family == a:
return 'red'
if site.family == b:
return 'green'
else:
return 'blue'
def hopping_lw(site1, site2):
return 0.1 if site1.family == site2.family else 0.1
kwant.plot(syst, site_lw=0.1, site_color=family_color, hop_lw=hopping_lw)
## Adding sites and hoppings
## Add sites and hoppings.
for i in range(4):
for j in range (4):
syst[a(i, j)] = 4 # red
syst[b(i, j)] = 4 # green
syst[c(i, j)] = 4 # blue
syst[a(i, j)] = 4
syst[b(i, j)] = 4
syst[c(i, j)] = 4
syst[lat.neighbors()] = -1
## Plotting the system
## Plot the system.
plot_system(syst)
#HIDDEN_END_colors2
############### How to create all hoppings in a given direction using Hoppingkind? ################
#### How to create all hoppings in a given direction using Hoppingkind?
# Monatomic lattice
#HIDDEN_BEGIN_direction1
# Create hopping between neighbors with HoppingKind
a = 1
syst = kwant.Builder()
......@@ -177,25 +171,23 @@ syst = kwant.Builder()
a, b, c = lat.sublattices # The kagome lattice has 3 sublattices
def family_color(site):
if site.family == a:
return 'red'
if site.family == b:
return 'green'
else:
return 'blue'
def plot_system(syst):
def family_color(site):
if site.family == a:
return 'blue'
if site.family == b:
return 'red'
else:
return 'green'
kwant.plot(syst, site_size=0.15, site_lw=0.05, site_color=family_color)
for i in range(4):
for j in range (4):
syst[a(i, j)] = 4 # red
syst[b(i, j)] = 4 # green
syst[c(i, j)] = 4 # blue
syst[a(i, j)] = 4
syst[b(i, j)] = 4
syst[c(i, j)] = 4
#HIDDEN_BEGIN_direction2
......@@ -213,12 +205,11 @@ syst[kwant.builder.HoppingKind((0, 0), c, b)] = -1
plot_system(syst)
########## How to create the hoppings between adjacent sites? ################
#### How to create the hoppings between adjacent sites?
# Monatomic lattice
#HIDDEN_BEGIN_adjacent1
# Create hoppings with lat.neighbors()
syst = kwant.Builder()
lat = kwant.lattice.square()
......@@ -266,7 +257,7 @@ plot_system(syst)
del syst[lat.neighbors(2)]
##### How to create a lead with a lattice different from the scattering region? ##########
#### How to create a lead with a lattice different from the scattering region?
# Plot sites from different families in different colors
......@@ -324,7 +315,7 @@ syst.attach_lead(lead1)
plot_system(syst)
############# How to cut a finite system out of a system with translationnal symmetries? ###########
#### How to cut a finite system out of a system with translationnal symmetries?
#HIDDEN_BEGIN_fill1
# Create 3d model.
......@@ -363,7 +354,7 @@ cuboid.attach_lead(electrode)
kwant.plot(cuboid);
###### How does Kwant order the propagating modes of a lead? ######
#### How does Kwant order the propagating modes of a lead?
#HIDDEN_BEGIN_pm
lat = kwant.lattice.square()
......@@ -395,7 +386,6 @@ def plot_and_label_modes(lead, E):
plt.show()
plot_and_label_modes(flead, E)
plt.clf()
# More involved example
......@@ -410,11 +400,9 @@ lead2[lat.neighbors()] = -1 * sz
flead2 = lead2.finalized()
plot_and_label_modes(flead2, 1)
plt.clf()
###### How does Kwant order components of an individual wavefunction? ######
#### How does Kwant order components of an individual wavefunction?
def circle(R):
return lambda r: np.linalg.norm(r) < R
......
Frequently asked questions
--------------------------
Frequently Asked Questions
--------------------------
It is important to read the tutorials before looking at the questions. This FAQ
is aimed to add complementary explainations that are not in the tutorials. The `Kwant paper <https://downloads.kwant-project.org/doc/kwant-paper.pdf>`_ also digs deeper into Kwant's structure.
This FAQ complements the regular Kwant tutorials and thus does not cover
questions that are discussed there. The `Kwant paper
<https://downloads.kwant-project.org/doc/kwant-paper.pdf>`_ also digs deeper
into Kwant's structure.
What is a system, and what is a builder?
========================================
A Kwant system represents a tight-binding model. It contains a graph of edges
and vertices that are assigned values, and which is used to construct
the Hamiltonian for the model being simulated.
In Kwant the specification of the tight-binding model is separated from the use
of the model in numerical calculations. The `~kwant.builder.Builder` is used
when specifying/constructing the model, then the
`~kwant.builder.Builder.finalize` method is called, which produces a so-called
low-level `~kwant.system.System` that can be used by Kwant's solvers.
In the documentation and in mailing list discussions, the term general term
"system" can be used to refer either to a ``Builder`` or to a low-level
A Kwant system represents a particular tight-binding model. It contains a graph
whose edges and vertices are assigned values, and that corresponds to the
Hamiltonian matrix of the model being simulated.
In Kwant the creation of the system is separated from its use in numerical
calculations. First an instance of the `~kwant.builder.Builder` class is used
to construct the model, then the `~kwant.builder.Builder.finalize` method is
called, which produces a so-called low-level `~kwant.system.System` that can be
used by Kwant's solvers.
The interface of builders mimics Python mappings (e.g. dictionaries). The
familiar square-bracket syntax allows to set, get and delete items that
correspond to elements of the system graph, e.g. ``syst[key] = value``. An
item consists of a key and an associated value. Keys are `sites <What is a
site?_>`_ and `hoppings <What is a hopping?_>`_. Values can be numbers, arrays
of numbers, or functions that return numbers or arrays.
Finalizing a builder returns a copy of the system with the graph *structure*
frozen. (This can be equivalently seen as freezing the system geometry or the
sparsity structure of the Hamiltonian.) The associated *values* are taken over
verbatim. Note that finalizing does not freeze the Hamiltonian matrix: only
its structure is fixed, values that are functions may depend on an arbitrary
number of parameters.
In the documentation and in mailing list discussions, the general term
"system" can refer either to a ``Builder`` or to a low-level
``System``, and the context will determine which specific class is being
referred to. The terms "builder" and "low-level system" (or "finalized system")
refer respectively to ``Builder`` and ``System``.
......@@ -27,9 +42,9 @@ refer respectively to ``Builder`` and ``System``.
What is a site?
===============
Kwant is a tool for working with tight-binding models, which can be viewed as a
graph composed of edges and vertices. Site objects are Kwant’s abstraction for
the vertices. Sites have two attributes: a **family** and a **tag** . The
combination of family and tag uniquely define a site.
graph composed of edges and vertices. Sites are Kwant’s labels for the
vertices. Sites have two attributes: a *family* and a *tag*. The
combination of family and tag uniquely defines a site.
For example let us create an empty tight binding system and add two sites:
......@@ -39,14 +54,57 @@ For example let us create an empty tight binding system and add two sites:
.. image:: ../images/faq_site.*
In the above snippet we added 2 sites: ``lat(1 ,0)`` and ``lat(0 , 1)``. Both
In the above snippet we added 2 sites: ``lat(1, 0)`` and ``lat(0, 1)``. Both
of these sites belong to the same family, ``lat``, but have different tags:
``(1, 0)`` and ``(0, 1)`` respectively.
Both sites were given the value 4 which means that the above system corresponds
to the Hamiltonian matrix
.. math::
H = \left(
\begin{array}{cc}
4 & 0 \\
0 & 4
\end{array}
\right).
What is a hopping?
==================
A hopping is simply a tuple of two of sites, which defines an edge of the graph
that makes up a tight-binding model. Other sequences of sites that are not
tuples, for example lists, are not treated as hoppings.
Starting from the example code from `What is a site?`_, we can add a hopping
to our system in the following way:
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_hopping
:end-before: #HIDDEN_END_hopping
.. image:: ../images/faq_hopping.*
Visually, a hopping is represented as a line that joins two sites.
The Hamiltonian matrix is now
.. math::
H = \left(
\begin{array}{cc}
4 & i \\
-i & 4
\end{array}
\right).
Note how adding ``(site_a, site_b)`` to a system and assigning it a value
``v``, implicitly adds the hopping ``(site_b, site_a)`` with the Hermitian
conjugate of ``v`` as value.
What is a site family, and what is a tag?
=========================================
a site family "groups" related sites together, and a tag serves as a unique
A site family groups related sites together, and a tag serves as a unique
identifier for a site within a given family.
In the previous example we saw a family that was suggestively called ``lat``,
......@@ -63,48 +121,53 @@ are tagged by letters of the alphabet.
What is a lattice?
==================
Kwant allows users to define and use Bravais lattices for dealing with
collections of regularly placed sites. They know about things like which sites
on the lattice are neighbors, and how to fill a region of realspace with sites.
``Monatomic`` lattices have a single site in their basis, while ``Polyatomic``
have more than one site in their basis.
``Monatomic`` lattices in Kwant *are also site families*, with sites that are
tagged with tuples of integers: the site's coordinates in the basis of
primitive vectors of the lattice. ``Polyatomic`` lattices, however, are *not*
site families, as lattice coordinates are not enough information to uniquely
identify a site if there is more than one site in the basis. ``Polyatomic``
Kwant allows to define and use Bravais lattices for dealing with collections of
regularly placed sites. They know about things like what sites are
neighbors, or what sites belong to a given region of real space.
`~kwant.lattice.Monatomic` lattices have a single site in their basis, while
`~kwant.lattice.Polyatomic` lattices have more than one site in their basis.
Monatomic lattices in Kwant *are also site families*, with sites that are
tagged by tuples of integers: the site's coordinates in the basis of
primitive vectors of the lattice. Polyatomic lattices, however, are *not*
site families, since lattice coordinates are not enough information to uniquely
identify a site if there is more than one site in the basis. Polyatomic
lattices do, however, have an attribute ``sublattices`` that is a list of
``Monatomic`` lattices that together make up the whole ``Polyatomic`` lattice.
monatomic lattices that together make up the whole polyatomic lattice.
For example:
Let's create two monatomic lattices (``lat_a`` and ``lat_b``). ``(1, 0)``
and ``(0, 1)`` will be the primitive vectors and ``(0, 0)`` and ``(0.5, 0.5)``
the origins of the two lattices:
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_lattice
:end-before: #HIDDEN_END_lattice
:start-after: #HIDDEN_BEGIN_lattice_monatomic
:end-before: #HIDDEN_END_lattice_monatomic
.. image:: ../images/faq_lattice.*
Above, we created 2 ``Monatomic`` lattices (``lat1`` and ``lat2``). ``(1, 0)``
and ``(0, 1)`` are the primitive vectors and ``(0, 0)`` and ``(0.5, 0.5)`` are
the origins of the two lattices. Next we create a ``Polyatomic`` lattice with the
same primitive vectors and 2 sites in the basis.
We can also create a ``Polyatomic`` lattice with the same primitive vectors and
two sites in the basis:
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_lattice_polyatomic
:end-before: #HIDDEN_END_lattice_polyatomic
The two sublattices are equivalent to the two monatomic lattices that we
created previously. Because a ``Polyatomic`` lattice knows about its
sublattices, we can do things like calculate neighboring sites, even between
sublattices, which would not be possible with the two separate ``Monatomic``
lattices.
The two sublattices ``sub_a`` and ``sub_b`` are nothing else than ``Monatomic``
instances, and are equivalent to ``lat_a`` and ``lat_b`` that we created
previously. The advantage of the second approach is that there is now a
``Polyatomic`` object that is aware of both of its sublattices, and we can do
things like calculate neighboring sites, even between sublattices, which would
not be possible with the two separate ``Monatomic`` lattices.
the `kwant.lattice` module also defines several functions, such as
`~kwant.lattice.square` and `~kwant.lattice.honeycomb`, which serve as a
convenience for creating lattices of common types, without having to
explicitly specify all of the lattice vectors and basis vectors.
The `kwant.lattice` module also defines several convenience functions, such as
`~kwant.lattice.square` and `~kwant.lattice.honeycomb`, for creating lattices
of common types, without having to explicitly specify all of the lattice
vectors and basis vectors.
How do I plot a polyatomic lattice with different colors?
=========================================================
In the following example we shall use a kagome lattice, which has 3 sublattices.
When plotting, how to color the different sublattices differently?
==================================================================
In the following example we shall use a kagome lattice, which has three sublattices.
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_colors1
......@@ -119,34 +182,18 @@ As we can see below, we create a new plotting function that assigns a color for
.. image:: ../images/faq_colors.*
What is a hopping?
==================
A hopping is simply a pair of sites, which defines an edge of the graph
that makes up our tight-binding model.
How to create many similar hoppings in one go?
==============================================
This can be achieved with an instance of the class `kwant.builder.HoppingKind`.
In fact, sites and hoppings are not the only possible keys when assigning
values to a `~kwant.builder.Builder`. There exists a mechanism to
`~kwant.builder.Builder.expand` more general keys into these simple keys.
Starting from the example code from `What is a site?`_, we can add a hopping
to our system in the following way:
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_hopping
:end-before: #HIDDEN_END_hopping
.. image:: ../images/faq_hopping.*
Visually, we represent a hopping as a line that joins two sites.
Whenever we add a hopping ``(site_a, site_b)`` to a system and assign it a
value ``v``, implicitly the hopping ``(site_b, site_a)`` is also added, with
value the Hermitian conjugate of ``v``.
How do I create all hoppings in a given direction?
==================================================
This can be obtained using a `~kwant.builder.HoppingKind`. A ``HoppingKind`` is
a way of specifying all hoppings of a particular "kind", between two site
families. For example ``HoppingKind((1, 0), lat_a, lat_b)`` represents all
hoppings of the form ``(lat_a(x + (1, 0)), lat_b(x))``, where ``x`` is a tag
(here, a pair of integers).
A ``HoppingKind``, the most comonly used general key, is a way of specifying
all hoppings of a particular "kind", between two site families. For example
``HoppingKind((1, 0), lat_a, lat_b)`` represents all hoppings of the form
``(lat_a(x + (1, 0)), lat_b(x))``, where ``x`` is a tag (here, a pair of
integers).
The following example shows how this can be used:
......@@ -177,10 +224,10 @@ Here, we create hoppings between the sites of the same lattice coordinates but f
.. image:: ../images/faq_direction3.*
How do I create the hoppings between adjacent sites?
====================================================
How to set the hoppings between adjacent sites?
===============================================
``Polyatomic`` and ``Monatomic`` lattices have a method `~kwant.lattice.Polyatomic.neighbors`
that returns a (or several) ``HoppingKind`` that connects sites with their
that returns a list of ``HoppingKind`` instances that connect sites with their
(n-nearest) neighors:
.. literalinclude:: faq.py
......@@ -199,7 +246,6 @@ sublattices:
:start-after: #HIDDEN_BEGIN_adjacent2
:end-before: #HIDDEN_END_adjacent2
.. image:: ../images/faq_adjacent3.*
However, if we use the ``neighbors()`` method of a single sublattice, we will
......@@ -216,10 +262,11 @@ is an artifact of the visualisation: the red and green sites just happen to lie
in the path of the hoppings, but are not connected by them.
How do I make a hole in a system?
=================================
To make a hole in the system, we use ``del syst[site]``. In the following
example we remove all sites inside some "hole" region:
How to make a hole in a system?
===============================
To make a hole in the system, use ``del syst[site]``, just like with any other
mapping. In the following example we remove all sites inside some "hole"
region:
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_hole
......@@ -232,8 +279,8 @@ example we remove all sites inside some "hole" region:
If a site is deleted, then all the hoppings to/from that site are also deleted.
How can I get access to a system's sites?
=========================================
How to access a system's sites?
===============================
The ways of accessing system sites is slightly different depending on whether
we are talking about a ``Builder`` or ``System`` (see `What is a system, and
what is a builder?`_ if you do not know the difference).
......@@ -268,8 +315,8 @@ the index of a given site within the system:
:end-before: #HIDDEN_END_sites3
How do I create a lead with a lattice different from the scattering region?
===========================================================================
How to use different lattices for the scattering region and a lead?
===================================================================
Let us take the example of a system containing sites from a honeycomb lattice,
which we want to connect to leads that contain sites from a square lattice.
......@@ -279,7 +326,7 @@ First we construct the central system:
:start-after: #HIDDEN_BEGIN_different_lattice1
:end-before: #HIDDEN_END_different_lattice1
.. image:: ../images/faq_different_latticea1.*
.. image:: ../images/faq_different_lattice1.*
and the lead:
......@@ -287,7 +334,7 @@ and the lead:
:start-after: #HIDDEN_BEGIN_different_lattice2
:end-before: #HIDDEN_END_different_lattice2
.. image:: ../images/faq_different_latticea2.*
.. image:: ../images/faq_different_lattice2.*
We cannot simply use `~kwant.builder.Builder.attach_lead` to attach this lead to the
system with the honeycomb lattice because Kwant does not know how sites from
......@@ -300,7 +347,7 @@ add the hoppings from these sites to the sites from the honeycomb lattice:
:start-after: #HIDDEN_BEGIN_different_lattice3
:end-before: #HIDDEN_END_different_lattice3
.. image:: ../images/faq_different_latticea3.*
.. image:: ../images/faq_different_lattice3.*
``attach_lead()`` will now be able to attach the lead:
......@@ -308,11 +355,11 @@ add the hoppings from these sites to the sites from the honeycomb lattice:
:start-after: #HIDDEN_BEGIN_different_lattice4
:end-before: #HIDDEN_END_different_lattice4
.. image:: ../images/faq_different_latticea4.*
.. image:: ../images/faq_different_lattice4.*
How do I cut a finite system out of a system with translational symmetries?
===========================================================================
How to cut a finite system out of a system with translational symmetries?
=========================================================================
This can be achieved using the `~kwant.builder.Builder.fill` method to fill a
``Builder`` with a ``Builder`` with higher symmetry.
......@@ -392,9 +439,9 @@ those that have *negative* velocities:
How does Kwant order components of an individual wavefunction?
==============================================================
In `How can I get access to a system's sites?`_ we saw that the sites of a finalized system
are available as a list through the ``sites`` attribute, and that one can look up the index
of a site with the ``id_by_site`` attribute.
In `How to access a system's sites?`_ we saw that the sites of a
finalized system are available as a list through the ``sites`` attribute, and
that one can look up the index of a site with the ``id_by_site`` attribute.
When all the site families present in a system have only 1 degree of freedom
per site (i.e. the all the onsites are scalars) then the index into a
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment