From 82b6ed960dd8fc39ce28ad20b7470ec4e066a692 Mon Sep 17 00:00:00 2001
From: Christoph Groth <christoph.groth@cea.fr>
Date: Fri, 4 May 2012 11:47:44 +0200
Subject: [PATCH] make tutorial 5 consistent with the others by finalizing in
 main()

---
 doc/source/images/tutorial5a.py   |  6 +++---
 doc/source/images/tutorial5b.py   |  6 +++---
 doc/source/tutorial/tutorial5.rst |  2 +-
 examples/tutorial5a.py            |  6 +++---
 examples/tutorial5b.py            | 11 +++++++----
 5 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/doc/source/images/tutorial5a.py b/doc/source/images/tutorial5a.py
index 8d54f0ef..359c3a35 100644
--- a/doc/source/images/tutorial5a.py
+++ b/doc/source/images/tutorial5a.py
@@ -40,8 +40,7 @@ def make_lead(a=1, t=1.0, mu=0.7, Delta=0.1, W=10):
 
         lead[(1, j), (0, j)] = - t * tau_z
 
-    # return a finalized lead
-    return lead.finalized()
+    return lead
 
 
 def plot_bandstructure(flead, momenta):
@@ -66,7 +65,8 @@ def plot_bandstructure(flead, momenta):
 
 
 def main():
-    flead = make_lead()
+    # Make system and finalize it right away.
+    flead = make_lead().finalized()
 
     # list of momenta at which the bands should be computed
     momenta = np.arange(-1.5, 1.5 + .0001, 0.002 * pi)
diff --git a/doc/source/images/tutorial5b.py b/doc/source/images/tutorial5b.py
index 322b1201..1ed8213f 100644
--- a/doc/source/images/tutorial5b.py
+++ b/doc/source/images/tutorial5b.py
@@ -80,12 +80,12 @@ def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4),
     lead2[lead2.possible_hoppings((0, 1), lat_h, lat_h)] = t
     lead2[((lat_e(0, j), lat_h(0, j)) for j in xrange(W))] = Delta
 
-    #### Attach the leads and return the finalized system. ####
+    #### Attach the leads and return the system. ####
     sys.attach_lead(lead0)
     sys.attach_lead(lead1)
     sys.attach_lead(lead2)
 
-    return sys.finalized()
+    return sys
 
 def plot_conductance(fsys, energies):
     # Compute conductance
@@ -114,7 +114,7 @@ def plot_conductance(fsys, energies):
 
 
 def main():
-    fsys = make_system()
+    fsys = make_system().finalized()
 
     plot_conductance(fsys, energies=[0.002 * i for i in xrange(100)])
 
diff --git a/doc/source/tutorial/tutorial5.rst b/doc/source/tutorial/tutorial5.rst
index bd572b00..c7f5a9a3 100644
--- a/doc/source/tutorial/tutorial5.rst
+++ b/doc/source/tutorial/tutorial5.rst
@@ -31,7 +31,7 @@ The most natural way to implement the BdG Hamiltonian is by using a
 2x2 matrix structure for all Hamiltonian matrix elements:
 
 .. literalinclude:: ../../../examples/tutorial5a.py
-    :lines: 21-45
+    :lines: 21-42
 
 As you see, the example is syntactically equivalent to our
 :ref:`spin example <tutorial_spinorbit>`, the only difference
diff --git a/examples/tutorial5a.py b/examples/tutorial5a.py
index 995c5b96..60bf12ef 100644
--- a/examples/tutorial5a.py
+++ b/examples/tutorial5a.py
@@ -39,8 +39,7 @@ def make_lead(a=1, t=1.0, mu=0.7, Delta=0.1, W=10):
 
         lead[(1, j), (0, j)] = - t * tau_z
 
-    # return a finalized lead
-    return lead.finalized()
+    return lead
 
 
 def plot_bandstructure(flead, momenta):
@@ -56,7 +55,8 @@ def plot_bandstructure(flead, momenta):
 
 
 def main():
-    flead = make_lead()
+    # Make system and finalize it right away.
+    flead = make_lead().finalized()
 
     # list of momenta at which the bands should be computed
     momenta = np.arange(-1.5, 1.5 + .0001, 0.002 * pi)
diff --git a/examples/tutorial5b.py b/examples/tutorial5b.py
index 19bd8466..2771599c 100644
--- a/examples/tutorial5b.py
+++ b/examples/tutorial5b.py
@@ -79,12 +79,12 @@ def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4),
     lead2[lead2.possible_hoppings((0, 1), lat_h, lat_h)] = t
     lead2[((lat_e(0, j), lat_h(0, j)) for j in xrange(W))] = Delta
 
-    #### Attach the leads and return the finalized system. ####
+    #### Attach the leads and return the system. ####
     sys.attach_lead(lead0)
     sys.attach_lead(lead1)
     sys.attach_lead(lead2)
 
-    return sys.finalized()
+    return sys
 
 def plot_conductance(fsys, energies):
     # Compute conductance
@@ -103,10 +103,13 @@ def plot_conductance(fsys, energies):
 
 
 def main():
-    fsys = make_system()
+    sys = make_system()
 
     # Check that the system looks as intended.
-    kwant.plot(fsys)
+    kwant.plot(sys)
+
+    # Finalize the system.
+    fsys = sys.finalized()
 
     plot_conductance(fsys, energies=[0.002 * i for i in xrange(100)])
 
-- 
GitLab