From 18a08c37b1bb794d5b9ee98882ea68fc5df0fd5f Mon Sep 17 00:00:00 2001
From: Joseph Weston <joseph@weston.cloud>
Date: Wed, 21 Aug 2019 10:53:40 +0200
Subject: [PATCH] specify 'norbs' on lattice creation in all tutorials

---
 doc/source/tutorial/faq.rst                  | 32 ++++++++++----------
 doc/source/tutorial/first_steps.rst          | 11 ++++---
 doc/source/tutorial/graphene.rst             |  3 +-
 doc/source/tutorial/magnetic_field.rst       |  2 +-
 doc/source/tutorial/plotting.rst             |  5 +--
 doc/source/tutorial/spectrum.rst             |  2 +-
 doc/source/tutorial/spin_potential_shape.rst | 13 +++++---
 doc/source/tutorial/superconductors.rst      |  2 +-
 8 files changed, 39 insertions(+), 31 deletions(-)

diff --git a/doc/source/tutorial/faq.rst b/doc/source/tutorial/faq.rst
index 22f0ad71..e82d0f18 100644
--- a/doc/source/tutorial/faq.rst
+++ b/doc/source/tutorial/faq.rst
@@ -68,7 +68,7 @@ For example let us create an empty tight binding system and add two sites:
 .. jupyter-execute::
 
     a = 1
-    lat = kwant.lattice.square(a)
+    lat = kwant.lattice.square(a, norbs=1)
     syst = kwant.Builder()
 
     syst[lat(1, 0)] = 4
@@ -165,9 +165,9 @@ the origins of the two lattices:
 
     # 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()
+    lat_a = kwant.lattice.Monatomic(primitive_vectors, offset=(0, 0), norbs=1)
+    lat_b = kwant.lattice.Monatomic(primitive_vectors, offset=(0.5, 0.5), norbs=1)
+    # lat1 is equivalent to kwant.lattice.square(norbs=1)
 
     syst = kwant.Builder()
 
@@ -182,7 +182,7 @@ two sites in the basis:
 .. jupyter-execute::
 
     # One polyatomic lattice containing two sublattices
-    lat = kwant.lattice.Polyatomic([(1, 0), (0, 1)], [(0, 0), (0.5, 0.5)])
+    lat = kwant.lattice.Polyatomic([(1, 0), (0, 1)], [(0, 0), (0.5, 0.5)], norbs=1)
     sub_a, sub_b = lat.sublattices
 
 The two sublattices ``sub_a`` and ``sub_b`` are nothing else than ``Monatomic``
@@ -204,7 +204,7 @@ In the following example we shall use a kagome lattice, which has three sublatti
 
 .. jupyter-execute::
 
-    lat = kwant.lattice.kagome()
+    lat = kwant.lattice.kagome(norbs=1)
     syst = kwant.Builder()
 
     a, b, c = lat.sublattices  # The kagome lattice has 3 sublattices
@@ -258,7 +258,7 @@ The following example shows how this can be used:
     # Create hopping between neighbors with HoppingKind
     a = 1
     syst = kwant.Builder()
-    lat = kwant.lattice.square(a)
+    lat = kwant.lattice.square(a, norbs=1)
     syst[ (lat(i, j) for i in range(5) for j in range(5)) ] = 4
 
     syst[kwant.builder.HoppingKind((1, 0), lat)] = -1
@@ -271,7 +271,7 @@ the sublattices when creating a ``HoppingKind``:
 .. jupyter-execute::
     :hide-code:
 
-    lat = kwant.lattice.kagome()
+    lat = kwant.lattice.kagome(norbs=1)
     syst = kwant.Builder()
 
     a, b, c = lat.sublattices  # The kagome lattice has 3 sublattices
@@ -323,7 +323,7 @@ that returns a list of ``HoppingKind`` instances that connect sites with their
 
     # Create hoppings with lat.neighbors()
     syst = kwant.Builder()
-    lat = kwant.lattice.square()
+    lat = kwant.lattice.square(norbs=1)
     syst[(lat(i, j) for i in range(3) for j in range(3))] = 4
 
     syst[lat.neighbors()] = -1  # Equivalent to lat.neighbors(1)
@@ -344,7 +344,7 @@ sublattices:
 .. jupyter-execute::
 
     # Create the system
-    lat = kwant.lattice.kagome()
+    lat = kwant.lattice.kagome(norbs=1)
     syst = kwant.Builder()
     a, b, c = lat.sublattices  # The kagome lattice has 3 sublattices
 
@@ -382,7 +382,7 @@ region:
 
     # Define the lattice and the (empty) system
     a = 2
-    lat = kwant.lattice.cubic(a)
+    lat = kwant.lattice.cubic(a, norbs=1)
     syst = kwant.Builder()
 
     L = 10
@@ -424,7 +424,7 @@ We can access the sites of a ``Builder`` by using its `~kwant.builder.Builder.si
     :hide-code:
 
     builder = kwant.Builder()
-    lat = kwant.lattice.square()
+    lat = kwant.lattice.square(norbs=1)
     builder[(lat(i, j) for i in range(3) for j in range(3))] = 4
 
 .. jupyter-execute::
@@ -472,7 +472,7 @@ First we construct the central system:
     L = 5
     W = 5
 
-    lat = kwant.lattice.honeycomb()
+    lat = kwant.lattice.honeycomb(norbs=1)
     subA, subB = lat.sublattices
 
     syst = kwant.Builder()
@@ -487,7 +487,7 @@ and the lead:
 .. jupyter-execute::
 
     # Create a lead
-    lat_lead = kwant.lattice.square()
+    lat_lead = kwant.lattice.square(norbs=1)
     sym_lead1 = kwant.TranslationalSymmetry((0, 1))
 
     lead1 = kwant.Builder(sym_lead1)
@@ -535,7 +535,7 @@ For example, say we want to create a simple model on a cubic lattice:
 .. jupyter-execute::
 
     # Create 3d model.
-    cubic = kwant.lattice.cubic()
+    cubic = kwant.lattice.cubic(norbs=1)
     sym_3d = kwant.TranslationalSymmetry([1, 0, 0], [0, 1, 0], [0, 0, 1])
     model = kwant.Builder(sym_3d)
     model[cubic(0, 0, 0)] = 4
@@ -587,7 +587,7 @@ system in a `~kwant.physics.PropagatingModes` object:
 
 .. jupyter-execute::
 
-    lat = kwant.lattice.square()
+    lat = kwant.lattice.square(norbs=1)
 
     lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0)))
     lead[(lat(0, i) for i in range(3))] = 4
diff --git a/doc/source/tutorial/first_steps.rst b/doc/source/tutorial/first_steps.rst
index 801bb3e5..41ed21bb 100644
--- a/doc/source/tutorial/first_steps.rst
+++ b/doc/source/tutorial/first_steps.rst
@@ -128,14 +128,16 @@ a square lattice. For simplicity, we set the lattice constant to unity:
 .. jupyter-execute::
 
     a = 1
-    lat = kwant.lattice.square(a)
+    lat = kwant.lattice.square(a, norbs=1)
 
 Since we work with a square lattice, we label the points with two
 integer coordinates `(i, j)`. `~kwant.builder.Builder` then
 allows us to add matrix elements corresponding to lattice points:
 ``syst[lat(i, j)] = ...`` sets the on-site energy for the point `(i, j)`,
 and ``syst[lat(i1, j1), lat(i2, j2)] = ...`` the hopping matrix element
-**from** point `(i2, j2)` **to** point `(i1, j1)`.
+**from** point `(i2, j2)` **to** point `(i1, j1)`. In specifying ``norbs=1``
+in the definition of the lattice we tell Kwant that there is 1 degree
+of freedom per lattice site.
 
 Note that we need to specify sites for `~kwant.builder.Builder`
 in the form ``lat(i, j)``. The lattice object `lat` does the
@@ -472,7 +474,8 @@ file and defining the a square lattice and empty scattering region.
 
     # Start with an empty tight-binding system and a single square lattice.
     # `a` is the lattice constant (by default set to 1 for simplicity).
-    lat = kwant.lattice.square(a)
+    # Each lattice site has 1 degree of freedom, hence norbs=1.
+    lat = kwant.lattice.square(a, norbs=1)
 
     syst = kwant.Builder()
 
@@ -681,7 +684,7 @@ return a Kwant ``Builder``:
 .. jupyter-execute::
 
     def make_system(L, W, a=1, t=1.0):
-        lat = kwant.lattice.square(a)
+        lat = kwant.lattice.square(a, norbs=1)
 
         syst = kwant.Builder()
         syst[(lat(i, j) for i in range(L) for j in range(W))] = 4 * t
diff --git a/doc/source/tutorial/graphene.rst b/doc/source/tutorial/graphene.rst
index 4243b7ff..792d4521 100644
--- a/doc/source/tutorial/graphene.rst
+++ b/doc/source/tutorial/graphene.rst
@@ -59,7 +59,8 @@ explicitly here to show how to define a new lattice:
 .. jupyter-execute::
 
     graphene = kwant.lattice.general([(1, 0), (sin_30, cos_30)],
-                                     [(0, 0), (0, 1 / sqrt(3))])
+                                     [(0, 0), (0, 1 / sqrt(3))],
+                                     norbs=1)
     a, b = graphene.sublattices
 
 The first argument to the `~kwant.lattice.general` function is the list of
diff --git a/doc/source/tutorial/magnetic_field.rst b/doc/source/tutorial/magnetic_field.rst
index add388bf..a3c98b95 100644
--- a/doc/source/tutorial/magnetic_field.rst
+++ b/doc/source/tutorial/magnetic_field.rst
@@ -137,7 +137,7 @@ a discretization in realspace.
 
 .. jupyter-execute::
 
-    lat = kwant.lattice.square()
+    lat = kwant.lattice.square(norbs=1)
     syst = kwant.Builder(kwant.TranslationalSymmetry((-1, 0)))
 
     def peierls(to_site, from_site, B):
diff --git a/doc/source/tutorial/plotting.rst b/doc/source/tutorial/plotting.rst
index fc4b65c8..bf6b51ae 100644
--- a/doc/source/tutorial/plotting.rst
+++ b/doc/source/tutorial/plotting.rst
@@ -53,7 +53,7 @@ to previous examples, we will also use hoppings beyond next-nearest neighbors:
 
 .. jupyter-execute::
 
-    lat = kwant.lattice.honeycomb()
+    lat = kwant.lattice.honeycomb(norbs=1)
     a, b = lat.sublattices
 
     def make_system(r=8, t=-1, tp=-0.1):
@@ -241,7 +241,8 @@ It is very easily generated in Kwant with `kwant.lattice.general`:
 .. jupyter-execute::
 
     lat = kwant.lattice.general([(0, 0.5, 0.5), (0.5, 0, 0.5), (0.5, 0.5, 0)],
-                                [(0, 0, 0), (0.25, 0.25, 0.25)])
+                                [(0, 0, 0), (0.25, 0.25, 0.25)],
+                                norbs=1)
     a, b = lat.sublattices
 
 Note how we keep references to the two different sublattices for later use.
diff --git a/doc/source/tutorial/spectrum.rst b/doc/source/tutorial/spectrum.rst
index 5e70ba9b..2b6d86a0 100644
--- a/doc/source/tutorial/spectrum.rst
+++ b/doc/source/tutorial/spectrum.rst
@@ -54,7 +54,7 @@ usual way:
 
     def make_lead(a=1, t=1.0, W=10):
         # Start with an empty lead with a single square lattice
-        lat = kwant.lattice.square(a)
+        lat = kwant.lattice.square(a, norbs=1)
 
         sym_lead = kwant.TranslationalSymmetry((-a, 0))
         lead = kwant.Builder(sym_lead)
diff --git a/doc/source/tutorial/spin_potential_shape.rst b/doc/source/tutorial/spin_potential_shape.rst
index 05aad2e6..b87eaa7f 100644
--- a/doc/source/tutorial/spin_potential_shape.rst
+++ b/doc/source/tutorial/spin_potential_shape.rst
@@ -109,7 +109,7 @@ we can simply write:
 .. jupyter-execute::
     :hide-code:
 
-    lat = kwant.lattice.square()
+    lat = kwant.lattice.square(norbs=2)
     syst = kwant.Builder()
 
 .. jupyter-execute::
@@ -124,6 +124,9 @@ we can simply write:
     syst[kwant.builder.HoppingKind((0, 1), lat, lat)] = \
         -t * sigma_0 - 1j * alpha * sigma_x / 2
 
+Note that we specify ``norbs=2`` when creating the lattice, as each site
+has 2 degrees of freedom associated with it, giving us 2x2 matrices as
+onsite/hopping terms.
 Note that the Zeeman energy adds to the onsite term, whereas the Rashba
 spin-orbit term adds to the hoppings (due to the derivative operator).
 Furthermore, the hoppings in x and y-direction have a different matrix
@@ -298,7 +301,7 @@ Kwant now allows us to pass a function as a value to
     def onsite(site, pot):
         return 4 * t + potential(site, pot)
 
-    lat = kwant.lattice.square(a)
+    lat = kwant.lattice.square(a, norbs=1)
     syst = kwant.Builder()
 
     syst[(lat(x, y) for x in range(L) for y in range(W))] = onsite
@@ -457,7 +460,7 @@ provided by the lattice:
     a = 1
     t = 1.0
 
-    lat = kwant.lattice.square(a)
+    lat = kwant.lattice.square(a, norbs=1)
     syst = kwant.Builder()
 
     syst[lat.shape(ring, (0, r1 + 1))] = 4 * t
@@ -620,7 +623,7 @@ period of one flux quantum.
         W = 10
         r1, r2 = 10, 20
 
-        lat = kwant.lattice.square()
+        lat = kwant.lattice.square(norbs=1)
         syst = kwant.Builder()
         def ring(pos):
             (x, y) = pos
@@ -675,7 +678,7 @@ period of one flux quantum.
         W = 10
         r1, r2 = 10, 20
 
-        lat = kwant.lattice.square(a)
+        lat = kwant.lattice.square(a, norbs=1)
         syst = kwant.Builder()
         def ring(pos):
             (x, y) = pos
diff --git a/doc/source/tutorial/superconductors.rst b/doc/source/tutorial/superconductors.rst
index 9e0b1d7a..f2e3b323 100644
--- a/doc/source/tutorial/superconductors.rst
+++ b/doc/source/tutorial/superconductors.rst
@@ -133,7 +133,7 @@ and we declare the square lattice and construct the scattering region with the f
     # Hoppings
     syst[lat.neighbors()] = -t * tau_z
 
-Note the new argument ``norbs`` to `~kwant.lattice.square`. This is
+Note the argument ``norbs`` to `~kwant.lattice.square`. This is
 the number of orbitals per site in the discretized BdG Hamiltonian - of course,
 ``norbs = 2``, since each site has one electron orbital and one hole orbital.
 It is necessary to specify ``norbs`` here, such that we may later separate the
-- 
GitLab