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

make cosmetic fixes to the FAQ source

lowercase FAQ.rst, FAQ.py, etc., give meaningful names to labels,
and stop building an user-visible tutorial/faq.py
parent 8fdc965a
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@
syst[lat(1, 1)] = 4
kwant.plot(syst)
+save_figure("FAQ122")
+save_figure("faq_site")
......@@ -33,7 +33,7 @@
syst[lat2(0, 0)] = 4 # syst[subB(0, 0)] = 4
kwant.plot(syst)
+save_figure("FAQ123")
+save_figure("faq_lattice")
########## What is a hopping? #######################
......@@ -41,7 +41,7 @@
syst[(lat(1, 0), lat(1, 1))] = -1
kwant.plot(syst)
+save_figure("FAQ124")
+save_figure("faq_hopping")
########### How to make a hole in a system? ###################"
......@@ -49,7 +49,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)
+save_figure("FAQ1")
+save_figure("faq_hole1")
# Delete sites to create a hole
......@@ -57,7 +57,7 @@
del syst[site]
kwant.plot(syst)
+save_figure("FAQ2")
+save_figure("faq_hole2")
################ How can we get access to the sites of our system? ####################
......@@ -66,15 +66,15 @@
## Plotting the system
plot_system(syst)
-
+save_figure("FAQ6B")
+save_figure("faq_colors")
############### How to create every hoppings in a given direction using Hoppingkind? ################
############### How to create all hoppings in a given direction using Hoppingkind? ################
@@ -149,6 +161,7 @@
syst[kwant.builder.HoppingKind((1, 0), lat)] = -1
kwant.plot(syst)
+save_figure("FAQ3")
+save_figure("faq_direction1")
# Polyatomic lattice
......@@ -82,14 +82,14 @@
# equivalent to syst[kwant.builder.HoppingKind((0, 1), b)] = -1
syst[kwant.builder.HoppingKind((0, 1), b, b)] = -1
plot_system(syst)
+save_figure("FAQ10")
+save_figure("faq_direction2")
# Delete the hoppings previously created
del syst[kwant.builder.HoppingKind((0, 1), b, b)]
syst[kwant.builder.HoppingKind((0, 0), a, b)] = -1
syst[kwant.builder.HoppingKind((0, 0), a, c)] = -1
syst[kwant.builder.HoppingKind((0, 0), c, b)] = -1
plot_system(syst)
+save_figure("FAQ11")
+save_figure("faq_direction3")
########## How to create the hoppings between adjacent sites? ################
......@@ -97,108 +97,102 @@
syst[lat.neighbors()] = -1 # Equivalent to lat.neighbors(1)
kwant.plot(syst)
+save_figure("FAQ4")
+save_figure("faq_adjacent1")
del syst[lat.neighbors()] # Delete all nearest-neighbor hoppings
syst[lat.neighbors(2)] = -1
kwant.plot(syst)
+save_figure("FAQ5")
+save_figure("faq_adjacent2")
# Polyatomic lattice
@@ -224,14 +241,17 @@
@@ -224,9 +241,11 @@
syst[lat.neighbors()] = -1
plot_system(syst)
+save_figure("FAQ7")
+save_figure("faq_adjacent3")
del syst[lat.neighbors()] # Delete the hoppings previously created
syst[a.neighbors()] = -1
plot_system(syst)
+save_figure("FAQ8")
+save_figure("faq_adjacent4")
del syst[a.neighbors()] # Delete the hoppings previously created
syst[lat.neighbors(2)] = -1
plot_system(syst)
+save_figure("FAQ9")
del syst[lat.neighbors(2)]
@@ -264,6 +284,7 @@
@@ -264,6 +283,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("FAQAA")
+save_figure("faq_different_latticea1")
# Create a lead
lat_lead = kwant.lattice.square()
@@ -273,6 +294,7 @@
@@ -273,6 +293,7 @@
lead1[(lat_lead(i, 0) for i in range(2, 7))] = 4
lead1[lat_lead.neighbors()] = -1
plot_system(lead1)
+save_figure("FAQAB")
+save_figure("faq_different_latticea2")
syst[(lat_lead(i, 5) for i in range(2, 7))] = 4
syst[lat_lead.neighbors()] = -1
@@ -280,9 +302,11 @@
@@ -280,9 +301,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("FAQAC")
+save_figure("faq_different_latticea3")
syst.attach_lead(lead1)
plot_system(syst)
+save_figure("FAQAD")
+save_figure("faq_different_latticea4")
############# How to cut a finite system out of a system with translationnal symmetries? ###########
@@ -302,6 +326,7 @@
@@ -302,6 +325,7 @@
cuboid = kwant.Builder()
cuboid.fill(model, cuboid_shape, (0, 0, 0));
kwant.plot(cuboid);
+save_figure("FAQaaa")
+save_figure("faq_fill2")
# Build electrode (black).
def electrode_shape(site):
@@ -316,6 +341,7 @@
@@ -316,6 +340,7 @@
cuboid.attach_lead(electrode)
kwant.plot(cuboid);
+save_figure("FAQbbb")
+save_figure("faq_fill3")
###### How does Kwant order the propagating modes of a lead? ######
@@ -348,6 +374,7 @@
@@ -348,6 +373,7 @@
plt.show()
plot_and_label_modes(flead, E)
+save_figure('FAQPM')
+save_figure('faq_pm1')
plt.clf()
# More involved example
@@ -363,6 +390,7 @@
@@ -363,6 +389,7 @@
flead2 = lead2.finalized()
plot_and_label_modes(flead2, 1)
+save_figure('FAQPMC')
+save_figure('faq_pm2')
plt.clf()
@@ -395,7 +423,8 @@
@@ -395,7 +422,8 @@
idx = syst.id_by_site[lat(0, 0)] # look up index of site
-print('wavefunction on lat(0, 0): ', wf[idx])
+with open('FAQORD1.txt', 'w') as f:
+with open('faq_ord1.txt', 'w') as f:
+ print('wavefunction on lat(0, 0): ', wf[idx], file=f)
lat = kwant.lattice.square(norbs=2)
syst = make_system(lat)
@@ -408,4 +437,5 @@
@@ -408,4 +436,5 @@
# to degrees of freedom on the same site.
wf = wf.reshape(-1, 2)
-print('wavefunction on lat(0, 0): ', wf[idx])
+with open('FAQORD2.txt', 'w') as f:
+with open('faq_ord2.txt', 'w') as f:
+ print('wavefunction on lat(0, 0): ', wf[idx], file=f)
......@@ -11,7 +11,7 @@ matplotlib.rcParams['figure.figsize'] = (3.5, 3.5)
######## What is a Site? ##############
#HIDDEN_BEGIN_FAQ122
#HIDDEN_BEGIN_site
a = 1
lat = kwant.lattice.square(a)
syst = kwant.Builder()
......@@ -20,13 +20,13 @@ syst[lat(1, 0)] = 4
syst[lat(1, 1)] = 4
kwant.plot(syst)
#HIDDEN_END_FAQ122
#HIDDEN_END_site
################# What is a family? a tag? a lattice? ##################
#HIDDEN_BEGIN_FAQ123
#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()
......@@ -43,7 +43,7 @@ syst[lat1(0, 0)] = 4 # syst[subA(0, 0)] = 4
syst[lat2(0, 0)] = 4 # syst[subB(0, 0)] = 4
kwant.plot(syst)
#HIDDEN_END_FAQ123
#HIDDEN_END_lattice
########## What is a hopping? #######################
......@@ -54,15 +54,15 @@ syst = kwant.Builder()
syst[lat(1, 0)] = 4
syst[lat(1, 1)] = 4
#HIDDEN_BEGIN_FAQ124
#HIDDEN_BEGIN_hopping
syst[(lat(1, 0), lat(1, 1))] = -1
#HIDDEN_END_FAQ124
#HIDDEN_END_hopping
kwant.plot(syst)
########### How to make a hole in a system? ###################"
#HIDDEN_BEGIN_FAQ2
#HIDDEN_BEGIN_hole
# Define the lattice and the (empty) system
a = 2
lat = kwant.lattice.cubic(a)
......@@ -87,7 +87,7 @@ for site in filter(in_hole, list(syst.sites())):
del syst[site]
kwant.plot(syst)
#HIDDEN_END_FAQ2
#HIDDEN_END_hole
################ How can we get access to the sites of our system? ####################
......@@ -95,32 +95,32 @@ kwant.plot(syst)
builder = kwant.Builder()
lat = kwant.lattice.square()
builder[(lat(i, j) for i in range(3) for j in range(3))] = 4
#HIDDEN_BEGIN_FAQ3
#HIDDEN_BEGIN_sites1
# Before finalizing the system
sites = list(builder.sites()) # sites() doe *not* return a list
#HIDDEN_END_FAQ3
#HIDDEN_BEGIN_FAQ7
#HIDDEN_END_sites1
#HIDDEN_BEGIN_sites2
# After finalizing the system
syst = builder.finalized()
sites = syst.sites # syst.sites is an actual list
#HIDDEN_END_FAQ7
#HIDDEN_BEGIN_FAQ72
#HIDDEN_END_sites2
#HIDDEN_BEGIN_sites3
i = syst.id_by_site[lat(0, 2)] # we want the id of the site lat(0, 2)
#HIDDEN_END_FAQ72
#HIDDEN_END_sites3
################ How to plot a polyatomic lattice with different colors? ##############"
#HIDDEN_BEGIN_FAQ8
#HIDDEN_BEGIN_colors1
lat = kwant.lattice.kagome()
syst = kwant.Builder()
a, b, c = lat.sublattices # The kagome lattice has 3 sublattices
#HIDDEN_END_FAQ8
#HIDDEN_END_colors1
#HIDDEN_BEGIN_FAQ9
#HIDDEN_BEGIN_colors2
# Plot sites from different families in different colors
def plot_system(syst):
......@@ -151,14 +151,14 @@ syst[lat.neighbors()] = -1
## Plotting the system
plot_system(syst)
#HIDDEN_END_FAQ9
#HIDDEN_END_colors2
############### How to create every hoppings in a given direction using Hoppingkind? ################
############### How to create all hoppings in a given direction using Hoppingkind? ################
# Monatomic lattice
#HIDDEN_BEGIN_FAQ4
#HIDDEN_BEGIN_direction1
# Create hopping between neighbors with HoppingKind
a = 1
......@@ -168,7 +168,7 @@ syst[ (lat(i, j) for i in range(5) for j in range(5)) ] = 4
syst[kwant.builder.HoppingKind((1, 0), lat)] = -1
kwant.plot(syst)
#HIDDEN_END_FAQ4
#HIDDEN_END_direction1
# Polyatomic lattice
......@@ -198,18 +198,18 @@ for i in range(4):
syst[c(i, j)] = 4 # blue
#HIDDEN_BEGIN_FAQ13
#HIDDEN_BEGIN_direction2
# equivalent to syst[kwant.builder.HoppingKind((0, 1), b)] = -1
syst[kwant.builder.HoppingKind((0, 1), b, b)] = -1
#HIDDEN_END_FAQ13
#HIDDEN_END_direction2
plot_system(syst)
# Delete the hoppings previously created
del syst[kwant.builder.HoppingKind((0, 1), b, b)]
#HIDDEN_BEGIN_FAQ14
#HIDDEN_BEGIN_direction3
syst[kwant.builder.HoppingKind((0, 0), a, b)] = -1
syst[kwant.builder.HoppingKind((0, 0), a, c)] = -1
syst[kwant.builder.HoppingKind((0, 0), c, b)] = -1
#HIDDEN_END_FAQ14
#HIDDEN_END_direction3
plot_system(syst)
......@@ -217,7 +217,7 @@ plot_system(syst)
# Monatomic lattice
#HIDDEN_BEGIN_FAQ5
#HIDDEN_BEGIN_adjacent1
# Create hoppings with lat.neighbors()
syst = kwant.Builder()
......@@ -231,14 +231,14 @@ del syst[lat.neighbors()] # Delete all nearest-neighbor hoppings
syst[lat.neighbors(2)] = -1
kwant.plot(syst)
#HIDDEN_END_FAQ5
#HIDDEN_END_adjacent1
# Polyatomic lattice
#HIDDEN_BEGIN_FAQ6
# Hoppings using .neighbors()
#HIDDEN_BEGIN_FAQ10
#HIDDEN_BEGIN_adjacent2
# Create the system
lat = kwant.lattice.kagome()
syst = kwant.Builder()
......@@ -251,19 +251,17 @@ for i in range(4):
syst[c(i, j)] = 4 # blue
syst[lat.neighbors()] = -1
#HIDDEN_END_FAQ10
#HIDDEN_END_adjacent2
plot_system(syst)
del syst[lat.neighbors()] # Delete the hoppings previously created
#HIDDEN_BEGIN_FAQ11
#HIDDEN_BEGIN_adjacent3
syst[a.neighbors()] = -1
#HIDDEN_END_FAQ11
#HIDDEN_END_adjacent3
plot_system(syst)
del syst[a.neighbors()] # Delete the hoppings previously created
#HIDDEN_BEGIN_FAQ12A
syst[lat.neighbors(2)] = -1
#HIDDEN_END_FAQ12A
plot_system(syst)
del syst[lat.neighbors(2)]
......@@ -285,7 +283,7 @@ def plot_system(syst):
kwant.plot(syst, site_lw=0.1, site_color=family_color)
#HIDDEN_BEGIN_FAQAA
#HIDDEN_BEGIN_different_lattice1
# Define the scattering Region
L = 5
W = 5
......@@ -297,10 +295,10 @@ 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
#HIDDEN_END_FAQAA
#HIDDEN_END_different_lattice1
plot_system(syst)
#HIDDEN_BEGIN_FAQAB
#HIDDEN_BEGIN_different_lattice2
# Create a lead
lat_lead = kwant.lattice.square()
sym_lead1 = kwant.TranslationalSymmetry((0, 1))
......@@ -308,36 +306,36 @@ 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
#HIDDEN_END_FAQAB
#HIDDEN_END_different_lattice2
plot_system(lead1)
#HIDDEN_BEGIN_FAQAC
#HIDDEN_BEGIN_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
#HIDDEN_END_FAQAC
#HIDDEN_END_different_lattice3
plot_system(syst)
#HIDDEN_BEGIN_FAQAD
#HIDDEN_BEGIN_different_lattice4
syst.attach_lead(lead1)
#HIDDEN_END_FAQAD
#HIDDEN_END_different_lattice4
plot_system(syst)
############# How to cut a finite system out of a system with translationnal symmetries? ###########
#HIDDEN_BEGIN_FAQccc
#HIDDEN_BEGIN_fill1
# Create 3d model.
cubic = kwant.lattice.cubic()
sym_3d = kwant.TranslationalSymmetry([1, 0, 0], [0, 1, 0], [0, 0, 1])
model = kwant.Builder(sym_3d)
model[cubic(0, 0, 0)] = 4
model[cubic.neighbors()] = -1
#HIDDEN_END_FAQccc
#HIDDEN_END_fill1
#HIDDEN_BEGIN_FAQddd
#HIDDEN_BEGIN_fill2
# Build scattering region (white).
def cuboid_shape(site):
x, y, z = abs(site.pos)
......@@ -345,10 +343,10 @@ def cuboid_shape(site):
cuboid = kwant.Builder()
cuboid.fill(model, cuboid_shape, (0, 0, 0));
#HIDDEN_END_FAQddd
#HIDDEN_END_fill2
kwant.plot(cuboid);
#HIDDEN_BEGIN_FAQeee
#HIDDEN_BEGIN_fill3
# Build electrode (black).
def electrode_shape(site):
x, y, z = site.pos - (0, 5, 2)
......@@ -361,13 +359,13 @@ electrode.fill(model, electrode_shape, (0, 5, 2)) # lead
cuboid.fill(electrode, lambda s: abs(s.pos[0]) < 7, (0, 5, 4))
cuboid.attach_lead(electrode)
#HIDDEN_END_FAQeee
#HIDDEN_END_fill3
kwant.plot(cuboid);
###### How does Kwant order the propagating modes of a lead? ######
#HIDDEN_BEGIN_PM
#HIDDEN_BEGIN_pm
lat = kwant.lattice.square()
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0)))
......@@ -378,7 +376,7 @@ flead = lead.finalized()
E = 2.5
prop_modes, _ = flead.modes(energy=E)
#HIDDEN_END_PM
#HIDDEN_END_pm
def plot_and_label_modes(lead, E):
# Plot the different modes
......@@ -437,7 +435,7 @@ def make_system(lat):
return syst.finalized()
#HIDDEN_BEGIN_ORD1
#HIDDEN_BEGIN_ord1
lat = kwant.lattice.square(norbs=1)
syst = make_system(lat)
scattering_states = kwant.wave_function(syst, energy=1)
......@@ -446,9 +444,9 @@ wf = scattering_states(0)[0] # scattering state from lead 0 incoming in mode 0
idx = syst.id_by_site[lat(0, 0)] # look up index of site
print('wavefunction on lat(0, 0): ', wf[idx])
#HIDDEN_END_ORD1
#HIDDEN_END_ord1
#HIDDEN_BEGIN_ORD2
#HIDDEN_BEGIN_ord2
lat = kwant.lattice.square(norbs=2)
syst = make_system(lat)
scattering_states = kwant.wave_function(syst, energy=1)
......@@ -461,4 +459,4 @@ idx = syst.id_by_site[lat(0, 0)] # look up index of site
wf = wf.reshape(-1, 2)
print('wavefunction on lat(0, 0): ', wf[idx])
#HIDDEN_END_ORD2
#HIDDEN_END_ord2
......@@ -33,11 +33,11 @@ combination of family and tag uniquely define a site.
For example let us create an empty tight binding system and add two sites:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQ122
:end-before: #HIDDEN_END_FAQ122
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_site
:end-before: #HIDDEN_END_site
.. image:: ../images/FAQ122.*
.. image:: ../images/faq_site.*
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:
......@@ -79,11 +79,11 @@ lattices do, however, have an attribute ``sublattices`` that is a list of
For example:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQ123
:end-before: #HIDDEN_END_FAQ123
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_lattice
:end-before: #HIDDEN_END_lattice
.. image:: ../images/FAQ123.*
.. 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
......@@ -106,17 +106,17 @@ How do I plot a polyatomic lattice with different colors?
=========================================================
In the following example we shall use a kagome lattice, which has 3 sublattices.
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQ8
:end-before: #HIDDEN_END_FAQ8
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_colors1
:end-before: #HIDDEN_END_colors1
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:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQ9
:end-before: #HIDDEN_END_FAQ9
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_colors2
:end-before: #HIDDEN_END_colors2
.. image:: ../images/FAQ6B.*
.. image:: ../images/faq_colors.*
What is a hopping?
......@@ -127,11 +127,11 @@ that makes up our tight-binding model.
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_FAQ124
:end-before: #HIDDEN_END_FAQ124
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_hopping
:end-before: #HIDDEN_END_hopping
.. image:: ../images/FAQ124.*
.. image:: ../images/faq_hopping.*
Visually, we represent a hopping as a line that joins two sites.
......@@ -150,31 +150,31 @@ hoppings of the form ``(lat_a(x + (1, 0)), lat_b(x))``, where ``x`` is a tag
The following example shows how this can be used:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQ4
:end-before: #HIDDEN_END_FAQ4
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_direction1
:end-before: #HIDDEN_END_direction1
.. image:: ../images/FAQ3.*
.. image:: ../images/faq_direction1.*
Note that ``HoppingKind`` only works with site families so you cannot use
them directly with ``Polyatomic`` lattices; you have to explicitly specify
the sublattices when creating a ``HoppingKind``:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQ13
:end-before: #HIDDEN_END_FAQ13
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_direction2
:end-before: #HIDDEN_END_direction2
Here, we want the hoppings between the sites from sublattice b with a direction of (0,1) in the lattice coordinates.
.. image:: ../images/FAQ10.*
.. image:: ../images/faq_direction2.*
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQ14
:end-before: #HIDDEN_END_FAQ14
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_direction3
:end-before: #HIDDEN_END_direction3
Here, we create hoppings between the sites of the same lattice coordinates but from different families.
.. image:: ../images/FAQ11.*
.. image:: ../images/faq_direction3.*
How do I create the hoppings between adjacent sites?
......@@ -183,33 +183,33 @@ How do I create the hoppings between adjacent sites?
that returns a (or several) ``HoppingKind`` that connects sites with their
(n-nearest) neighors:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQ5
:end-before: #HIDDEN_END_FAQ5
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_adjacent1
:end-before: #HIDDEN_END_adjacent1
.. image:: ../images/FAQ4.*
.. image:: ../images/FAQ5.*
.. image:: ../images/faq_adjacent1.*
.. image:: ../images/faq_adjacent2.*
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.
When using a ``Polyatomic`` lattice ``neighbors()`` knows about the different
sublattices:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQ10
:end-before: #HIDDEN_END_FAQ10
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_adjacent2
:end-before: #HIDDEN_END_adjacent2
.. image:: ../images/FAQ7.*
.. image:: ../images/faq_adjacent3.*
However, if we use the ``neighbors()`` method of a single sublattice, we will
only get the neighbors *on that sublattice*:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQ11
:end-before: #HIDDEN_END_FAQ11
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_adjacent3
:end-before: #HIDDEN_END_adjacent3
.. image:: ../images/FAQ8.*
.. image:: ../images/faq_adjacent4.*
Note in the above that there are *only* hoppings between the blue sites. This
is an artifact of the visualisation: the red and green sites just happen to lie
......@@ -221,12 +221,12 @@ 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:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQ2
:end-before: #HIDDEN_END_FAQ2
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_hole
:end-before: #HIDDEN_END_hole
.. image:: ../images/FAQ1.*
.. image:: ../images/FAQ2.*
.. image:: ../images/faq_hole1.*
.. image:: ../images/faq_hole2.*
``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.
......@@ -240,9 +240,9 @@ 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:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQ3
:end-before: #HIDDEN_END_FAQ3
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_sites1
:end-before: #HIDDEN_END_sites1
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
......@@ -253,9 +253,9 @@ well be returned in a different order.
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:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQ7
:end-before: #HIDDEN_END_FAQ7
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_sites2
:end-before: #HIDDEN_END_sites2
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).
......@@ -263,9 +263,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
the index of a given site within the system:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQ72
:end-before: #HIDDEN_END_FAQ72
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_sites3
:end-before: #HIDDEN_END_sites3
How do I create a lead with a lattice different from the scattering region?
......@@ -275,19 +275,19 @@ which we want to connect to leads that contain sites from a square lattice.
First we construct the central system:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQAA
:end-before: #HIDDEN_END_FAQAA
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_different_lattice1
:end-before: #HIDDEN_END_different_lattice1
.. image:: ../images/FAQAA.*
.. image:: ../images/faq_different_latticea1.*
and the lead:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQAB
:end-before: #HIDDEN_END_FAQAB
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_different_lattice2
:end-before: #HIDDEN_END_different_lattice2
.. image:: ../images/FAQAB.*
.. image:: ../images/faq_different_latticea2.*
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
......@@ -296,19 +296,19 @@ these two lattices should be connected.
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:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQAC
:end-before: #HIDDEN_END_FAQAC
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_different_lattice3
:end-before: #HIDDEN_END_different_lattice3
.. image:: ../images/FAQAC.*
.. image:: ../images/faq_different_latticea3.*
``attach_lead()`` will now be able to attach the lead:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQAD
:end-before: #HIDDEN_END_FAQAD
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_different_lattice4
:end-before: #HIDDEN_END_different_lattice4
.. image:: ../images/FAQAD.*
.. image:: ../images/faq_different_latticea4.*
How do I cut a finite system out of a system with translational symmetries?
......@@ -322,29 +322,29 @@ 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:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQccc
:end-before: #HIDDEN_END_FAQccc
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_fill1
:end-before: #HIDDEN_END_fill1
We have now created our "template" ``Builder`` which has 3 translational
symmetries. Next we will fill a system with no translational symmetries with
sites and hoppings from the template inside a cuboid:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQddd
:end-before: #HIDDEN_END_FAQddd
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_fill2
:end-before: #HIDDEN_END_fill2
.. image:: ../images/FAQaaa.*
.. image:: ../images/faq_fill2.*
We can then use the original template to create a lead, which has 1 translational
symmetry. We can then use this lead as a template to fill another section of
the system with a cylinder of sites and hoppings:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_FAQeee
:end-before: #HIDDEN_END_FAQeee
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_fill3
:end-before: #HIDDEN_END_fill3
.. image:: ../images/FAQbbb.*
.. image:: ../images/faq_fill3.*
How does Kwant order the propagating modes of a lead?
......@@ -355,16 +355,16 @@ achieved with the `~kwant.system.InfiniteSystem.modes` method, which returns a
pair of objects, the first of which contains the propagating modes of the
system in a `~kwant.physics.PropagatingModes` object:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_PM
:end-before: #HIDDEN_END_PM
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_pm
:end-before: #HIDDEN_END_pm
``PropagatingModes`` contains the wavefunctions, velocities and momenta of the
modes at the requested energy (2.5 in this example). In order to understand
the order in which these quantities are returned it is often useful to look at
the a section of the band structure for the system in question:
.. image:: ../images/FAQPM.*
.. image:: ../images/faq_pm1.*
On the above band structure we have labelled the 4 modes in the order
that they appear in the output of ``modes()`` at energy 2.5. Note that
......@@ -378,7 +378,7 @@ the modes are sorted in the following way:
For more complicated systems and band structures this can lead to some
possibly unintuitive orderings:
.. image:: ../images/FAQPMC.*
.. image:: ../images/faq_pm2.*
How does Kwant order scattering states?
......@@ -400,10 +400,10 @@ 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
wavefunction defined over the system is exactly the site index:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_ORD1
:end-before: #HIDDEN_END_ORD1
.. literalinclude:: ../images/FAQORD1.txt
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_ord1
:end-before: #HIDDEN_END_ord1
.. literalinclude:: ../images/faq_ord1.txt
We see that the wavefunction on a single site is a single complex number, as
expected.
......@@ -415,10 +415,10 @@ to one another. In the case where all site families in the system have the
wavefunction into a matrix, where the row number indexes the site, and the
column number indexes the degree of freedom on that site:
.. literalinclude:: FAQ.py
:start-after: #HIDDEN_BEGIN_ORD2
:end-before: #HIDDEN_END_ORD2
.. literalinclude:: ../images/FAQORD2.txt
.. literalinclude:: faq.py
:start-after: #HIDDEN_BEGIN_ord2
:end-before: #HIDDEN_END_ord2
.. literalinclude:: ../images/faq_ord2.txt
We see that the wavefunction on a single site is a *vector* of 2 complex numbers,
as we expect.
......
......@@ -12,4 +12,4 @@ Tutorial: learning Kwant through examples
plotting
kpm
discretize
FAQ
faq
......@@ -242,7 +242,11 @@ class build_tut(Command):
if not os.path.exists(tut_dir):
os.mkdir(tut_dir)
for in_fname in glob.glob('doc/source/tutorial/*.py'):
out_fname = os.path.join(tut_dir, os.path.basename(in_fname))
basename = os.path.basename(in_fname)
if basename == 'faq.py':
# The FAQ script is not meant as an example.
continue
out_fname = os.path.join(tut_dir, basename)
with open(in_fname, 'rb') as in_file:
with open(out_fname, 'wb') as out_file:
for line in in_file:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment