In the following example we shall use a kagome lattice, which has three sublattices.
In the following example we shall use a kagome lattice, which has three sublattices.
.. literalinclude:: /code/include/faq.py
.. jupyter-execute::
:start-after: #HIDDEN_BEGIN_colors1
:end-before: #HIDDEN_END_colors1
lat = kwant.lattice.kagome()
syst = kwant.Builder()
a, b, c = lat.sublattices # The kagome lattice has 3 sublattices
As we can see below, we create a new plotting function that assigns a color for each family, and a different size for the hoppings depending on the family of the two sites. Finally we add sites and hoppings to our system and plot it with the new function.
As we can see below, we create a new plotting function that assigns a color for each family, and a different size for the hoppings depending on the family of the two sites. Finally we add sites and hoppings to our system and plot it with the new function.
.. literalinclude:: /code/include/faq.py
.. jupyter-execute::
:start-after: #HIDDEN_BEGIN_colors2
:end-before: #HIDDEN_END_colors2
# Plot sites from different families in different colors
Here, we create hoppings between the sites of the same lattice coordinates but from different families.
Here, we create hoppings between the sites of the same lattice coordinates but from different families.
.. image:: /code/figure/faq_direction3.*
.. jupyter-execute::
plot_system(syst)
How to set the hoppings between adjacent sites?
How to set the hoppings between adjacent sites?
...
@@ -230,32 +310,53 @@ How to set the hoppings between adjacent sites?
...
@@ -230,32 +310,53 @@ How to set the hoppings between adjacent sites?
that returns a list of ``HoppingKind`` instances that connect sites with their
that returns a list of ``HoppingKind`` instances that connect sites with their
(n-nearest) neighors:
(n-nearest) neighors:
.. literalinclude:: /code/include/faq.py
.. jupyter-execute::
:start-after: #HIDDEN_BEGIN_adjacent1
:end-before: #HIDDEN_END_adjacent1
# Create hoppings with lat.neighbors()
syst = kwant.Builder()
lat = kwant.lattice.square()
syst[(lat(i, j) for i in range(3) for j in range(3))] = 4
.. image:: /code/figure/faq_adjacent1.*
syst[lat.neighbors()] = -1 # Equivalent to lat.neighbors(1)
.. image:: /code/figure/faq_adjacent2.*
kwant.plot(syst);
As we can see in the figure above, ``lat.neighbors()`` (on the left) returns the hoppings between the first nearest neighbors and ``lat.neighbors(2)`` (on the right) returns the hoppings between the second nearest neighbors.
.. jupyter-execute::
del syst[lat.neighbors()] # Delete all nearest-neighbor hoppings
syst[lat.neighbors(2)] = -1
kwant.plot(syst);
As we can see in the figures above, ``lat.neighbors()`` returns the hoppings between the first nearest neighbors and ``lat.neighbors(2)`` returns the hoppings between the second nearest neighbors.
When using a ``Polyatomic`` lattice ``neighbors()`` knows about the different
When using a ``Polyatomic`` lattice ``neighbors()`` knows about the different
sublattices:
sublattices:
.. literalinclude:: /code/include/faq.py
.. jupyter-execute::
:start-after: #HIDDEN_BEGIN_adjacent2
:end-before: #HIDDEN_END_adjacent2
# Create the system
lat = kwant.lattice.kagome()
syst = kwant.Builder()
a, b, c = lat.sublattices # The kagome lattice has 3 sublattices
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
.. image:: /code/figure/faq_adjacent3.*
syst[lat.neighbors()] = -1
plot_system(syst)
However, if we use the ``neighbors()`` method of a single sublattice, we will
However, if we use the ``neighbors()`` method of a single sublattice, we will
only get the neighbors *on that sublattice*:
only get the neighbors *on that sublattice*:
.. literalinclude:: /code/include/faq.py
.. jupyter-execute::
:start-after: #HIDDEN_BEGIN_adjacent3
:end-before: #HIDDEN_END_adjacent3
.. image:: /code/figure/faq_adjacent4.*
del syst[lat.neighbors()] # Delete the hoppings previously created
syst[a.neighbors()] = -1
plot_system(syst)
Note in the above that there are *only* hoppings between the red sites. This
Note in the above that there are *only* hoppings between the red sites. This
is an artifact of the visualisation: the blue and green sites just happen to lie
is an artifact of the visualisation: the blue and green sites just happen to lie
...
@@ -268,12 +369,35 @@ To make a hole in the system, use ``del syst[site]``, just like with any other
...
@@ -268,12 +369,35 @@ 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"
mapping. In the following example we remove all sites inside some "hole"
region:
region:
.. literalinclude:: /code/include/faq.py
.. jupyter-execute::
:start-after: #HIDDEN_BEGIN_hole
:end-before: #HIDDEN_END_hole
# Define the lattice and the (empty) system
a = 2
lat = kwant.lattice.cubic(a)
syst = kwant.Builder()
L = 10
W = 10
H = 2
# Add sites to the system in a cuboid
syst[(lat(i, j, k) for i in range(L) for j in range(W) for k in range(H))] = 4
kwant.plot(syst);
.. jupyter-execute::
# Delete sites to create a hole
def in_hole(site):
x, y, z = site.pos / a - (L/2, W/2, H/2) # position relative to centre
return abs(x) < L / 4 and abs(y) < W / 4
for site in filter(in_hole, list(syst.sites())):
del syst[site]
kwant.plot(syst);
.. image:: /code/figure/faq_hole1.*
.. image:: /code/figure/faq_hole2.*
``del syst[site]`` also works after hoppings have been added to the system.
``del syst[site]`` also works after hoppings have been added to the system.
If a site is deleted, then all the hoppings to/from that site are also deleted.
If a site is deleted, then all the hoppings to/from that site are also deleted.
...
@@ -287,9 +411,18 @@ what is a builder?`_ if you do not know the difference).
...
@@ -287,9 +411,18 @@ what is a builder?`_ if you do not know the difference).
We can access the sites of a ``Builder`` by using its `~kwant.builder.Builder.sites` method:
We can access the sites of a ``Builder`` by using its `~kwant.builder.Builder.sites` method:
.. literalinclude:: /code/include/faq.py
.. jupyter-execute::
:start-after: #HIDDEN_BEGIN_sites1
:hide-code:
:end-before: #HIDDEN_END_sites1
builder = kwant.Builder()
lat = kwant.lattice.square()
builder[(lat(i, j) for i in range(3) for j in range(3))] = 4
.. jupyter-execute::
# Before finalizing the system
sites = list(builder.sites()) # sites() doe *not* return a list
The ``sites()`` method returns an *iterator* over the system sites, and in the
The ``sites()`` method returns an *iterator* over the system sites, and in the
above example we create a list from the contents of this iterator, which
above example we create a list from the contents of this iterator, which
...
@@ -300,9 +433,11 @@ well be returned in a different order.
...
@@ -300,9 +433,11 @@ well be returned in a different order.
After finalization, when we are dealing with a ``System``, the sites themselves
After finalization, when we are dealing with a ``System``, the sites themselves
are stored in a list, which can be accessed via the ``sites`` attribute:
are stored in a list, which can be accessed via the ``sites`` attribute:
.. literalinclude:: /code/include/faq.py
.. jupyter-execute::
:start-after: #HIDDEN_BEGIN_sites2
:end-before: #HIDDEN_END_sites2
# After finalizing the system
syst = builder.finalized()
sites = syst.sites # syst.sites is an actual list
The order of sites in a ``System`` is fixed, and also defines the ordering of
The order of sites in a ``System`` is fixed, and also defines the ordering of
the system Hamiltonian, system wavefunctions etc. (see `How does Kwant order components of an individual wavefunction?`_ for details).
the system Hamiltonian, system wavefunctions etc. (see `How does Kwant order components of an individual wavefunction?`_ for details).
...
@@ -310,9 +445,9 @@ the system Hamiltonian, system wavefunctions etc. (see `How does Kwant order com
...
@@ -310,9 +445,9 @@ the system Hamiltonian, system wavefunctions etc. (see `How does Kwant order com
``System`` also contains the inverse mapping, ``id_by_site`` which gives us
``System`` also contains the inverse mapping, ``id_by_site`` which gives us
the index of a given site within the system:
the index of a given site within the system:
.. literalinclude:: /code/include/faq.py
.. jupyter-execute::
:start-after: #HIDDEN_BEGIN_sites3
:end-before: #HIDDEN_END_sites3
i = syst.id_by_site[lat(0, 2)] # we want the id of the site lat(0, 2)
How to use different lattices for the scattering region and a lead?
How to use different lattices for the scattering region and a lead?
...
@@ -322,19 +457,35 @@ which we want to connect to leads that contain sites from a square lattice.
...
@@ -322,19 +457,35 @@ which we want to connect to leads that contain sites from a square lattice.
First we construct the central system:
First we construct the central system:
.. literalinclude:: /code/include/faq.py
.. jupyter-execute::
:start-after: #HIDDEN_BEGIN_different_lattice1
:end-before: #HIDDEN_END_different_lattice1
.. image:: /code/figure/faq_different_lattice1.*
# Define the scattering Region
L = 5
W = 5
lat = kwant.lattice.honeycomb()
subA, subB = lat.sublattices
syst = kwant.Builder()
syst[(subA(i, j) for i in range(L) for j in range(W))] = 4
syst[(subB(i, j) for i in range(L) for j in range(W))] = 4
syst[lat.neighbors()] = -1
kwant.plot(syst);
and the lead:
and the lead:
.. literalinclude:: /code/include/faq.py
.. jupyter-execute::
:start-after: #HIDDEN_BEGIN_different_lattice2
:end-before: #HIDDEN_END_different_lattice2
# Create a lead
lat_lead = kwant.lattice.square()
sym_lead1 = kwant.TranslationalSymmetry((0, 1))
lead1 = kwant.Builder(sym_lead1)
lead1[(lat_lead(i, 0) for i in range(2, 7))] = 4
lead1[lat_lead.neighbors()] = -1
.. image:: /code/figure/faq_different_lattice2.*
kwant.plot(syst);
We cannot simply use `~kwant.builder.Builder.attach_lead` to attach this lead to the
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
system with the honeycomb lattice because Kwant does not know how sites from
...
@@ -343,19 +494,22 @@ these two lattices should be connected.
...
@@ -343,19 +494,22 @@ these two lattices should be connected.
We must first add a layer of sites from the square lattice to the system and manually
We must first add a layer of sites from the square lattice to the system and manually
add the hoppings from these sites to the sites from the honeycomb lattice:
add the hoppings from these sites to the sites from the honeycomb lattice:
.. literalinclude:: /code/include/faq.py
.. jupyter-execute::
:start-after: #HIDDEN_BEGIN_different_lattice3
:end-before: #HIDDEN_END_different_lattice3
.. image:: /code/figure/faq_different_lattice3.*
syst[(lat_lead(i, 5) for i in range(2, 7))] = 4
syst[lat_lead.neighbors()] = -1
# Manually attach sites from graphene to square lattice
syst[((lat_lead(i+2, 5), subB(i, 4)) for i in range(5))] = -1
kwant.plot(syst);
``attach_lead()`` will now be able to attach the lead:
``attach_lead()`` will now be able to attach the lead:
.. literalinclude:: /code/include/faq.py
.. jupyter-execute::
:start-after: #HIDDEN_BEGIN_different_lattice4
:end-before: #HIDDEN_END_different_lattice4
.. image:: /code/figure/faq_different_lattice4.*
syst.attach_lead(lead1)
kwant.plot(syst);
How to cut a finite system out of a system with translational symmetries?
How to cut a finite system out of a system with translational symmetries?
...
@@ -369,30 +523,50 @@ will be repeated in the desired shape to create the final system.
...
@@ -369,30 +523,50 @@ will be repeated in the desired shape to create the final system.
For example, say we want to create a simple model on a cubic lattice:
For example, say we want to create a simple model on a cubic lattice: