From 60d6fb90d7521b15553939595720386d1d21d5ac Mon Sep 17 00:00:00 2001 From: Christoph Groth <christoph.groth@cea.fr> Date: Sat, 17 Nov 2012 10:42:06 +0100 Subject: [PATCH] generate image creation scripts from tutorial scripts by patching --- .gitignore | 1 + doc/Makefile | 9 +- doc/source/images/1-quantum_wire.py | 116 ----------- doc/source/images/1-quantum_wire.py.diff | 39 ++++ doc/source/images/2-ab_ring.py | 190 ----------------- doc/source/images/2-ab_ring.py.diff | 116 +++++++++++ doc/source/images/2-quantum_well.py | 112 ---------- doc/source/images/2-quantum_well.py.diff | 44 ++++ doc/source/images/2-spin_orbit.py | 107 ---------- doc/source/images/2-spin_orbit.py.diff | 43 ++++ doc/source/images/3-band_structure.py | 73 ------- doc/source/images/3-band_structure.py.diff | 35 ++++ doc/source/images/3-closed_system.py | 111 ---------- doc/source/images/3-closed_system.py.diff | 46 +++++ doc/source/images/4-graphene.py | 193 ------------------ doc/source/images/4-graphene.py.diff | 97 +++++++++ .../images/5-superconductor_band_structure.py | 81 -------- .../5-superconductor_band_structure.py.diff | 33 +++ .../images/5-superconductor_transport.py | 126 ------------ .../images/5-superconductor_transport.py.diff | 40 ++++ doc/source/images/generate-diffs.sh | 10 + tutorial/3-closed_system.py | 2 +- tutorial/README | 14 ++ 23 files changed, 526 insertions(+), 1112 deletions(-) delete mode 100644 doc/source/images/1-quantum_wire.py create mode 100644 doc/source/images/1-quantum_wire.py.diff delete mode 100644 doc/source/images/2-ab_ring.py create mode 100644 doc/source/images/2-ab_ring.py.diff delete mode 100644 doc/source/images/2-quantum_well.py create mode 100644 doc/source/images/2-quantum_well.py.diff delete mode 100644 doc/source/images/2-spin_orbit.py create mode 100644 doc/source/images/2-spin_orbit.py.diff delete mode 100644 doc/source/images/3-band_structure.py create mode 100644 doc/source/images/3-band_structure.py.diff delete mode 100644 doc/source/images/3-closed_system.py create mode 100644 doc/source/images/3-closed_system.py.diff delete mode 100644 doc/source/images/4-graphene.py create mode 100644 doc/source/images/4-graphene.py.diff delete mode 100644 doc/source/images/5-superconductor_band_structure.py create mode 100644 doc/source/images/5-superconductor_band_structure.py.diff delete mode 100644 doc/source/images/5-superconductor_transport.py create mode 100644 doc/source/images/5-superconductor_transport.py.diff create mode 100755 doc/source/images/generate-diffs.sh create mode 100644 tutorial/README diff --git a/.gitignore b/.gitignore index af93de50..4493ae39 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ MANIFEST /doc/source/images/*.png /doc/source/images/*.pdf /doc/source/images/.*_flag +/doc/source/images/[0-9]-*.py /build.conf diff --git a/doc/Makefile b/doc/Makefile index 7856c9a1..3de1f635 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -54,7 +54,7 @@ clean: -rm -rf source/reference/generated realclean: clean - -rm -f $(ALL_IMAGES) source/images/.*_flag + -rm -f $(ALL_IMAGES) source/images/.*_flag source/images/[0-9]-*.py html: $(ALL_IMAGES) $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @@ -118,7 +118,12 @@ doctest: inkscape --export-pdf=$@ $< -# Generation of tutorial images. This requires some serious make trickery, see +# Make the image generation scripts by patching tutorial scipts. +%.py: %.py.diff + @cp ../tutorial/$(notdir $@) $(dir $@) + @patch $@ $< + +# Generation of tutorial images. This requires some make trickery, see # http://article.gmane.org/gmane.comp.gnu.make.general/5806 .%_flag: %.py diff --git a/doc/source/images/1-quantum_wire.py b/doc/source/images/1-quantum_wire.py deleted file mode 100644 index 835b0a96..00000000 --- a/doc/source/images/1-quantum_wire.py +++ /dev/null @@ -1,116 +0,0 @@ -# Physics background -# ------------------ -# Conductance of a quantum wire; subbands -# -# Kwant features highlighted -# -------------------------- -# - Builder for setting up transport systems easily -# - Making scattering region and leads -# - Using the simple sparse solver for computing Landauer conductance - -import kwant -import latex, html - -# First, define the tight-binding system - -sys = kwant.Builder() - -# Here, we are only working with square lattices -a = 1 -lat = kwant.lattice.Square(a) - -t = 1.0 -W = 10 -L = 30 - -# Define the scattering region - -for i in xrange(L): - for j in xrange(W): - sys[lat(i, j)] = 4 * t - - # hoppig in y-direction - if j > 0: - sys[lat(i, j), lat(i, j - 1)] = - t - - #hopping in x-direction - if i > 0: - sys[lat(i, j), lat(i - 1, j)] = -t - -# Then, define the leads: - -# First the lead to the left - -# (Note: in the current version, TranslationalSymmetry takes a -# realspace vector) -sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))]) -lead0 = kwant.Builder(sym_lead0) - -for j in xrange(W): - lead0[lat(0, j)] = 4 * t - - if j > 0: - lead0[lat(0, j), lat(0, j - 1)] = - t - - lead0[lat(1, j), lat(0, j)] = - t - -# Then the lead to the right - -sym_lead1 = kwant.TranslationalSymmetry([lat.vec((1, 0))]) -lead1 = kwant.Builder(sym_lead1) - -for j in xrange(W): - lead1[lat(0, j)] = 4 * t - - if j > 0: - lead1[lat(0, j), lat(0, j - 1)] = - t - - lead1[lat(1, j), lat(0, j)] = - t - -# Then attach the leads to the system - -sys.attach_lead(lead0) -sys.attach_lead(lead1) - -# Plot it, to make sure it's OK - -kwant.plot(sys, "1-quantum_wire_sys.pdf", width=latex.figwidth_pt) -kwant.plot(sys, "1-quantum_wire_sys.png", width=html.figwidth_px) - -# Finalize the system - -sys = sys.finalized() - -# Now that we have the system, we can compute conductance - -energies = [] -data = [] -for ie in xrange(100): - energy = ie * 0.01 - - # compute the scattering matrix at energy energy - smatrix = kwant.solve(sys, energy) - - # compute the transmission probability from lead 0 to - # lead 1 - energies.append(energy) - data.append(smatrix.transmission(1, 0)) - -# Use matplotlib to write output -# We should see conductance steps -from matplotlib import pyplot - -fig = pyplot.figure() -pyplot.plot(energies, data) -pyplot.xlabel("energy [in units of t]", - fontsize=latex.mpl_label_size) -pyplot.ylabel("conductance [in units of e^2/h]", - fontsize=latex.mpl_label_size) -pyplot.setp(fig.get_axes()[0].get_xticklabels(), - fontsize=latex.mpl_tick_size) -pyplot.setp(fig.get_axes()[0].get_yticklabels(), - fontsize=latex.mpl_tick_size) -fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) -fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) -fig.savefig("1-quantum_wire_result.pdf") -fig.savefig("1-quantum_wire_result.png", dpi=(html.figwidth_px/latex.mpl_width_in)) diff --git a/doc/source/images/1-quantum_wire.py.diff b/doc/source/images/1-quantum_wire.py.diff new file mode 100644 index 00000000..ed74c097 --- /dev/null +++ b/doc/source/images/1-quantum_wire.py.diff @@ -0,0 +1,39 @@ +--- original ++++ modified +@@ -9,6 +9,7 @@ + # - Using the simple sparse solver for computing Landauer conductance + + import kwant ++import latex, html + + # First, define the tight-binding system + +@@ -73,7 +74,8 @@ + + # Plot it, to make sure it's OK + +-kwant.plot(sys) ++kwant.plot(sys, "1-quantum_wire_sys.pdf", width=latex.figwidth_pt) ++kwant.plot(sys, "1-quantum_wire_sys.png", width=html.figwidth_px) + + # Finalize the system + +@@ -98,8 +100,14 @@ + # We should see conductance steps + from matplotlib import pyplot + +-pyplot.figure() ++fig = pyplot.figure() + pyplot.plot(energies, data) +-pyplot.xlabel("energy [in units of t]") +-pyplot.ylabel("conductance [in units of e^2/h]") +-pyplot.show() ++pyplot.xlabel("energy [in units of t]", fontsize=latex.mpl_label_size) ++pyplot.ylabel("conductance [in units of e^2/h]", fontsize=latex.mpl_label_size) ++pyplot.setp(fig.get_axes()[0].get_xticklabels(), fontsize=latex.mpl_tick_size) ++pyplot.setp(fig.get_axes()[0].get_yticklabels(), fontsize=latex.mpl_tick_size) ++fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) ++fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) ++fig.savefig("1-quantum_wire_result.pdf") ++fig.savefig("1-quantum_wire_result.png", ++ dpi=(html.figwidth_px/latex.mpl_width_in)) diff --git a/doc/source/images/2-ab_ring.py b/doc/source/images/2-ab_ring.py deleted file mode 100644 index ad6ba6e1..00000000 --- a/doc/source/images/2-ab_ring.py +++ /dev/null @@ -1,190 +0,0 @@ -# Physics background -# ------------------ -# Flux-dependent transmission through a quantum ring -# -# Kwant features highlighted -# -------------------------- -# - More complex shapes with lattices -# - Allows for discussion of subtleties of `attach_lead` (not in the -# example, but in the tutorial main text) -# - Modifcations of hoppings/sites after they have been added - -from cmath import exp -from math import pi - -import kwant - -# For plotting -from matplotlib import pyplot - -import latex, html - -def make_system(a=1, t=1.0, W=10, r1=10, r2=20): - # 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) - - sys = kwant.Builder() - - #### Define the scattering region. #### - # Now, we aim for a more complex shape, namely a ring (or annulus) - def ring(pos): - (x, y) = pos - rsq = x ** 2 + y ** 2 - return (r1 ** 2 < rsq < r2 ** 2) - - # and add the corresponding lattice points using the `shape`-function - sys[lat.shape(ring, (0, r1 + 1))] = 4 * t - for hopping in lat.nearest: - sys[sys.possible_hoppings(*hopping)] = - t - - # In order to introduce a flux through the ring, we introduce a phase - # on the hoppings on the line cut through one of the arms - - # since we want to change the flux without modifying Builder repeatedly, - # we define the modified hoppings as a function that takes the flux - # through the global variable phi. - def fluxphase(site1, site2): - return exp(1j * phi) - - def crosses_branchcut(hop): - ix0, iy0 = hop[0].tag - - # possible_hoppings with the argument (1, 0) below - # returns hoppings ordered as ((i+1, j), (i, j)) - return iy0 < 0 and ix0 == 1 # ix1 == 0 then implied - - # Modify only those hopings in x-direction that cross the branch cut - sys[(hop for hop in sys.possible_hoppings((1, 0), lat, lat) - if crosses_branchcut(hop))] = fluxphase - - #### Define the leads. #### - # left lead - sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))]) - lead0 = kwant.Builder(sym_lead0) - - def lead_shape(pos): - (x, y) = pos - return (-1 < x < 1) and (-W / 2 < y < W / 2) - - lead0[lat.shape(lead_shape, (0, 0))] = 4 * t - for hopping in lat.nearest: - lead0[lead0.possible_hoppings(*hopping)] = - t - - # Then the lead to the right - # [again, obtained using reversed()] - lead1 = lead0.reversed() - - #### Attach the leads and return the system. #### - sys.attach_lead(lead0) - sys.attach_lead(lead1) - - return sys - - -def make_system_note1(a=1, t=1.0, W=10, r1=10, r2=20): - lat = kwant.lattice.Square(a) - sys = kwant.Builder() - def ring(pos): - (x, y) = pos - rsq = x**2 + y**2 - return ( r1**2 < rsq < r2**2) - sys[lat.shape(ring, (0, 11))] = 4 * t - for hopping in lat.nearest: - sys[sys.possible_hoppings(*hopping)] = - t - sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))]) - lead0 = kwant.Builder(sym_lead0) - def lead_shape(pos): - (x, y) = pos - return (-1 < x < 1) and ( 0.5 * W < y < 1.5 * W ) - lead0[lat.shape(lead_shape, (0, W))] = 4 * t - for hopping in lat.nearest: - lead0[lead0.possible_hoppings(*hopping)] = - t - lead1 = lead0.reversed() - sys.attach_lead(lead0) - sys.attach_lead(lead1) - return sys - - -def make_system_note2(a=1, t=1.0, W=10, r1=10, r2=20): - lat = kwant.lattice.Square(a) - sys = kwant.Builder() - def ring(pos): - (x, y) = pos - rsq = x**2 + y**2 - return ( r1**2 < rsq < r2**2) - sys[lat.shape(ring, (0, 11))] = 4 * t - for hopping in lat.nearest: - sys[sys.possible_hoppings(*hopping)] = - t - sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))]) - lead0 = kwant.Builder(sym_lead0) - def lead_shape(pos): - (x, y) = pos - return (-1 < x < 1) and ( -W/2 < y < W/2 ) - lead0[lat.shape(lead_shape, (0, 0))] = 4 * t - for hopping in lat.nearest: - lead0[lead0.possible_hoppings(*hopping)] = - t - lead1 = lead0.reversed() - sys.attach_lead(lead0) - sys.attach_lead(lead1, lat(0, 0)) - return sys - - -def plot_conductance(sys, energy, fluxes): - # compute conductance - # global variable phi controls the flux - global phi - - normalized_fluxes = [flux / (2 * pi) for flux in fluxes] - data = [] - for flux in fluxes: - phi = flux - - smatrix = kwant.solve(sys, energy) - data.append(smatrix.transmission(1, 0)) - - fig = pyplot.figure() - pyplot.plot(normalized_fluxes, data) - pyplot.xlabel("flux [in units of the flux quantum]", - fontsize=latex.mpl_label_size) - pyplot.ylabel("conductance [in units of e^2/h]", - fontsize=latex.mpl_label_size) - pyplot.setp(fig.get_axes()[0].get_xticklabels(), - fontsize=latex.mpl_tick_size) - pyplot.setp(fig.get_axes()[0].get_yticklabels(), - fontsize=latex.mpl_tick_size) - fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) - fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) - fig.savefig("2-ab_ring_result.pdf") - fig.savefig("2-ab_ring_result.png", - dpi=(html.figwidth_px/latex.mpl_width_in)) - - -def main(): - sys = make_system() - - # Check that the system looks as intended. - kwant.plot(sys, "2-ab_ring_sys.pdf", width=latex.figwidth_pt) - kwant.plot(sys, "2-ab_ring_sys.png", width=html.figwidth_px) - - # Finalize the system. - sys = sys.finalized() - - # We should see a conductance that is periodic with the flux quantum - plot_conductance(sys, energy=0.15, fluxes=[0.01 * i * 3 * 2 * pi - for i in xrange(100)]) - - # Finally, some plots needed for the notes - sys = make_system_note1() - kwant.plot(sys, "2-ab_ring_note1.pdf", width=latex.figwidth_small_pt) - kwant.plot(sys, "2-ab_ring_note1.png", width=html.figwidth_small_px) - sys = make_system_note2() - kwant.plot(sys, "2-ab_ring_note2.pdf", width=latex.figwidth_small_pt) - kwant.plot(sys, "2-ab_ring_note2.png", width=html.figwidth_small_px) - - -# Call the main function if the script gets executed (as opposed to imported). -# See <http://docs.python.org/library/__main__.html>. -if __name__ == '__main__': - main() diff --git a/doc/source/images/2-ab_ring.py.diff b/doc/source/images/2-ab_ring.py.diff new file mode 100644 index 00000000..29bd464f --- /dev/null +++ b/doc/source/images/2-ab_ring.py.diff @@ -0,0 +1,116 @@ +--- original ++++ modified +@@ -16,6 +16,7 @@ + + # For plotting + from matplotlib import pyplot ++import latex, html + + + def make_system(a=1, t=1.0, W=10, r1=10, r2=20): +@@ -82,6 +83,54 @@ + return sys + + ++def make_system_note1(a=1, t=1.0, W=10, r1=10, r2=20): ++ lat = kwant.lattice.Square(a) ++ sys = kwant.Builder() ++ def ring(pos): ++ (x, y) = pos ++ rsq = x**2 + y**2 ++ return ( r1**2 < rsq < r2**2) ++ sys[lat.shape(ring, (0, 11))] = 4 * t ++ for hopping in lat.nearest: ++ sys[sys.possible_hoppings(*hopping)] = -t ++ sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))]) ++ lead0 = kwant.Builder(sym_lead0) ++ def lead_shape(pos): ++ (x, y) = pos ++ return (-1 < x < 1) and ( 0.5 * W < y < 1.5 * W ) ++ lead0[lat.shape(lead_shape, (0, W))] = 4 * t ++ for hopping in lat.nearest: ++ lead0[lead0.possible_hoppings(*hopping)] = -t ++ lead1 = lead0.reversed() ++ sys.attach_lead(lead0) ++ sys.attach_lead(lead1) ++ return sys ++ ++ ++def make_system_note2(a=1, t=1.0, W=10, r1=10, r2=20): ++ lat = kwant.lattice.Square(a) ++ sys = kwant.Builder() ++ def ring(pos): ++ (x, y) = pos ++ rsq = x**2 + y**2 ++ return ( r1**2 < rsq < r2**2) ++ sys[lat.shape(ring, (0, 11))] = 4 * t ++ for hopping in lat.nearest: ++ sys[sys.possible_hoppings(*hopping)] = -t ++ sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))]) ++ lead0 = kwant.Builder(sym_lead0) ++ def lead_shape(pos): ++ (x, y) = pos ++ return (-1 < x < 1) and ( -W/2 < y < W/2 ) ++ lead0[lat.shape(lead_shape, (0, 0))] = 4 * t ++ for hopping in lat.nearest: ++ lead0[lead0.possible_hoppings(*hopping)] = -t ++ lead1 = lead0.reversed() ++ sys.attach_lead(lead0) ++ sys.attach_lead(lead1, lat(0, 0)) ++ return sys ++ ++ + def plot_conductance(sys, energy, fluxes): + # compute conductance + # global variable phi controls the flux +@@ -95,18 +144,29 @@ + smatrix = kwant.solve(sys, energy) + data.append(smatrix.transmission(1, 0)) + +- pyplot.figure() ++ fig = pyplot.figure() + pyplot.plot(normalized_fluxes, data) +- pyplot.xlabel("flux [in units of the flux quantum]") +- pyplot.ylabel("conductance [in units of e^2/h]") +- pyplot.show() ++ pyplot.xlabel("flux [in units of the flux quantum]", ++ fontsize=latex.mpl_label_size) ++ pyplot.ylabel("conductance [in units of e^2/h]", ++ fontsize=latex.mpl_label_size) ++ pyplot.setp(fig.get_axes()[0].get_xticklabels(), ++ fontsize=latex.mpl_tick_size) ++ pyplot.setp(fig.get_axes()[0].get_yticklabels(), ++ fontsize=latex.mpl_tick_size) ++ fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) ++ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) ++ fig.savefig("2-ab_ring_result.pdf") ++ fig.savefig("2-ab_ring_result.png", ++ dpi=(html.figwidth_px/latex.mpl_width_in)) + + + def main(): + sys = make_system() + + # Check that the system looks as intended. +- kwant.plot(sys) ++ kwant.plot(sys, "2-ab_ring_sys.pdf", width=latex.figwidth_pt) ++ kwant.plot(sys, "2-ab_ring_sys.png", width=html.figwidth_px) + + # Finalize the system. + sys = sys.finalized() +@@ -115,6 +175,15 @@ + plot_conductance(sys, energy=0.15, fluxes=[0.01 * i * 3 * 2 * pi + for i in xrange(100)]) + ++ # Finally, some plots needed for the notes ++ sys = make_system_note1() ++ kwant.plot(sys, "2-ab_ring_note1.pdf", width=latex.figwidth_small_pt) ++ kwant.plot(sys, "2-ab_ring_note1.png", width=html.figwidth_small_px) ++ sys = make_system_note2() ++ kwant.plot(sys, "2-ab_ring_note2.pdf", width=latex.figwidth_small_pt) ++ kwant.plot(sys, "2-ab_ring_note2.png", width=html.figwidth_small_px) ++ ++ + # Call the main function if the script gets executed (as opposed to imported). + # See <http://docs.python.org/library/__main__.html>. + if __name__ == '__main__': diff --git a/doc/source/images/2-quantum_well.py b/doc/source/images/2-quantum_well.py deleted file mode 100644 index 1b90a7e1..00000000 --- a/doc/source/images/2-quantum_well.py +++ /dev/null @@ -1,112 +0,0 @@ -# Physics background -# ------------------ -# transmission through a quantum well -# -# Kwant features highlighted -# -------------------------- -# - Functions as values in Builder - -import kwant - -# For plotting -from matplotlib import pyplot - -import latex, html - -# global variable governing the behavior of potential() in -# make_system() -pot = 0 - - -def make_system(a=1, t=1.0, W=10, L=30, L_well=10): - # 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) - - sys = kwant.Builder() - - #### Define the scattering region. #### - # Potential profile - def potential(site): - (x, y) = site.pos - if (L - L_well) / 2 < x < (L + L_well) / 2: - # The potential value is provided using a global variable - return pot - else: - return 0 - - def onsite(site): - return 4 * t + potential(site) - - sys[(lat(x, y) for x in range(L) for y in range(W))] = onsite - for hopping in lat.nearest: - sys[sys.possible_hoppings(*hopping)] = -t - - #### Define the leads. #### - # First the lead to the left, ... - # (Note: in the current version, TranslationalSymmetry takes a - # realspace vector) - sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))]) - lead0 = kwant.Builder(sym_lead0) - - lead0[(lat(0, j) for j in xrange(W))] = 4 * t - for hopping in lat.nearest: - lead0[lead0.possible_hoppings(*hopping)] = - t - - # ... then the lead to the right. We use a method that returns a copy of - # `lead0` with its direction reversed. - lead1 = lead0.reversed() - - #### Attach the leads and return the finalized system. #### - sys.attach_lead(lead0) - sys.attach_lead(lead1) - - return sys - - -def plot_conductance(sys, energy, welldepths): - # We specify that we want to not only read, but also write to a - # global variable. - global pot - - # Compute conductance - data = [] - for welldepth in welldepths: - # Set the global variable that defines the potential well depth - pot = -welldepth - - smatrix = kwant.solve(sys, energy) - data.append(smatrix.transmission(1, 0)) - - fig = pyplot.figure() - pyplot.plot(welldepths, data) - pyplot.xlabel("well depth [in units of t]", - fontsize=latex.mpl_label_size) - pyplot.ylabel("conductance [in units of e^2/h]", - fontsize=latex.mpl_label_size) - pyplot.setp(fig.get_axes()[0].get_xticklabels(), - fontsize=latex.mpl_tick_size) - pyplot.setp(fig.get_axes()[0].get_yticklabels(), - fontsize=latex.mpl_tick_size) - fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) - fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) - fig.savefig("2-quantum_well_result.pdf") - fig.savefig("2-quantum_well_result.png", - dpi=(html.figwidth_px/latex.mpl_width_in)) - - -def main(): - sys = make_system() - - # Finalize the system. - sys = sys.finalized() - - # We should see conductance steps. - plot_conductance(sys, energy=0.2, - welldepths=[0.01 * i for i in xrange(100)]) - - -# Call the main function if the script gets executed (as opposed to imported). -# See <http://docs.python.org/library/__main__.html>. -if __name__ == '__main__': - main() diff --git a/doc/source/images/2-quantum_well.py.diff b/doc/source/images/2-quantum_well.py.diff new file mode 100644 index 00000000..40988f9f --- /dev/null +++ b/doc/source/images/2-quantum_well.py.diff @@ -0,0 +1,44 @@ +--- original ++++ modified +@@ -10,6 +10,7 @@ + + # For plotting + from matplotlib import pyplot ++import latex, html + + # global variable governing the behavior of potential() in + # make_system() +@@ -75,19 +76,26 @@ + smatrix = kwant.solve(sys, energy) + data.append(smatrix.transmission(1, 0)) + +- pyplot.figure() ++ fig = pyplot.figure() + pyplot.plot(welldepths, data) +- pyplot.xlabel("well depth [in units of t]") +- pyplot.ylabel("conductance [in units of e^2/h]") +- pyplot.show() ++ pyplot.xlabel("well depth [in units of t]", ++ fontsize=latex.mpl_label_size) ++ pyplot.ylabel("conductance [in units of e^2/h]", ++ fontsize=latex.mpl_label_size) ++ pyplot.setp(fig.get_axes()[0].get_xticklabels(), ++ fontsize=latex.mpl_tick_size) ++ pyplot.setp(fig.get_axes()[0].get_yticklabels(), ++ fontsize=latex.mpl_tick_size) ++ fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) ++ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) ++ fig.savefig("2-quantum_well_result.pdf") ++ fig.savefig("2-quantum_well_result.png", ++ dpi=(html.figwidth_px/latex.mpl_width_in)) + + + def main(): + sys = make_system() + +- # Check that the system looks as intended. +- kwant.plot(sys) +- + # Finalize the system. + sys = sys.finalized() + diff --git a/doc/source/images/2-spin_orbit.py b/doc/source/images/2-spin_orbit.py deleted file mode 100644 index cab6df71..00000000 --- a/doc/source/images/2-spin_orbit.py +++ /dev/null @@ -1,107 +0,0 @@ -# Physics background -# ------------------ -# Gaps in quantum wires with spin-orbit coupling and Zeeman splititng, -# as theoretically predicted in -# http://prl.aps.org/abstract/PRL/v90/i25/e256601 -# and (supposedly) experimentally oberved in -# http://www.nature.com/nphys/journal/v6/n5/abs/nphys1626.html -# -# Kwant features highlighted -# -------------------------- -# - Numpy matrices as values in Builder - -import kwant - -# For plotting -from matplotlib import pyplot - -# For matrix support -import numpy - -import latex, html - -# define Pauli-matrices for convenience -sigma_0 = numpy.eye(2) -sigma_x = numpy.array([[0, 1], [1, 0]]) -sigma_y = numpy.array([[0, -1j], [1j, 0]]) -sigma_z = numpy.array([[1, 0], [0, -1]]) - - -def make_system(a=1, t=1.0, alpha=0.5, e_z=0.08, W=10, L=30): - # 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) - - sys = kwant.Builder() - - #### Define the scattering region. #### - sys[(lat(x, y) for x in range(L) for y in range(W))] = 4 * t * sigma_0 + \ - e_z * sigma_z - # hoppings in x-direction - sys[sys.possible_hoppings((1, 0), lat, lat)] = - t * sigma_0 - \ - 1j * alpha * sigma_y - # hoppings in y-directions - sys[sys.possible_hoppings((0, 1), lat, lat)] = - t * sigma_0 + \ - 1j * alpha * sigma_x - - #### Define the leads. #### - # left lead - sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))]) - lead0 = kwant.Builder(sym_lead0) - - lead0[(lat(0, j) for j in xrange(W))] = 4 * t * sigma_0 + e_z * sigma_z - # hoppings in x-direction - lead0[lead0.possible_hoppings((1, 0), lat, lat)] = - t * sigma_0 - \ - 1j * alpha * sigma_y - # hoppings in y-directions - lead0[lead0.possible_hoppings((0, 1), lat, lat)] = - t * sigma_0 + \ - 1j * alpha * sigma_x - - # Then the lead to the right - # (again, obtained using reverse() - lead1 = lead0.reversed() - - #### Attach the leads and return the finalized system. #### - sys.attach_lead(lead0) - sys.attach_lead(lead1) - - return sys - -def plot_conductance(sys, energies): - # Compute conductance - data = [] - for energy in energies: - smatrix = kwant.solve(sys, energy) - data.append(smatrix.transmission(1, 0)) - - fig = pyplot.figure() - pyplot.plot(energies, data) - pyplot.xlabel("energy [in units of t]", - fontsize=latex.mpl_label_size) - pyplot.ylabel("conductance [in units of e^2/h]", - fontsize=latex.mpl_label_size) - pyplot.setp(fig.get_axes()[0].get_xticklabels(), - fontsize=latex.mpl_tick_size) - pyplot.setp(fig.get_axes()[0].get_yticklabels(), - fontsize=latex.mpl_tick_size) - fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) - fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) - fig.savefig("2-spin_orbit_result.pdf") - fig.savefig("2-spin_orbit_result.png", - dpi=(html.figwidth_px/latex.mpl_width_in)) - - -def main(): - sys = make_system() - - # Finalize the system. - sys = sys.finalized() - - # We should see non-monotonic conductance steps. - plot_conductance(sys, energies=[0.01 * i - 0.3 for i in xrange(100)]) - - -# Call the main function if the script gets executed (as opposed to imported). -# See <http://docs.python.org/library/__main__.html>. -if __name__ == '__main__': - main() diff --git a/doc/source/images/2-spin_orbit.py.diff b/doc/source/images/2-spin_orbit.py.diff new file mode 100644 index 00000000..fb74b9ce --- /dev/null +++ b/doc/source/images/2-spin_orbit.py.diff @@ -0,0 +1,43 @@ +--- original ++++ modified +@@ -17,6 +17,7 @@ + + # For matrix support + import numpy ++import latex, html + + # define Pauli-matrices for convenience + sigma_0 = numpy.eye(2) +@@ -72,19 +73,25 @@ + smatrix = kwant.solve(sys, energy) + data.append(smatrix.transmission(1, 0)) + +- pyplot.figure() ++ fig = pyplot.figure() + pyplot.plot(energies, data) +- pyplot.xlabel("energy [in units of t]") +- pyplot.ylabel("conductance [in units of e^2/h]") +- pyplot.show() ++ pyplot.xlabel("energy [in units of t]", fontsize=latex.mpl_label_size) ++ pyplot.ylabel("conductance [in units of e^2/h]", ++ fontsize=latex.mpl_label_size) ++ pyplot.setp(fig.get_axes()[0].get_xticklabels(), ++ fontsize=latex.mpl_tick_size) ++ pyplot.setp(fig.get_axes()[0].get_yticklabels(), ++ fontsize=latex.mpl_tick_size) ++ fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) ++ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) ++ fig.savefig("2-spin_orbit_result.pdf") ++ fig.savefig("2-spin_orbit_result.png", ++ dpi=(html.figwidth_px/latex.mpl_width_in)) + + + def main(): + sys = make_system() + +- # Check that the system looks as intended. +- kwant.plot(sys) +- + # Finalize the system. + sys = sys.finalized() + diff --git a/doc/source/images/3-band_structure.py b/doc/source/images/3-band_structure.py deleted file mode 100644 index 1174523a..00000000 --- a/doc/source/images/3-band_structure.py +++ /dev/null @@ -1,73 +0,0 @@ -# Physics background -# ------------------ -# band structure of a simple quantum wire in tight-binding approximation -# -# Kwant features highlighted -# -------------------------- -# - Computing the band structure of a finalized lead. - -import kwant - -from math import pi - -# For plotting -from matplotlib import pyplot - -import latex, html - - -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) - - sym_lead = kwant.TranslationalSymmetry([lat.vec((-1, 0))]) - lead = kwant.Builder(sym_lead) - - # build up one unit cell of the lead, and add the hoppings - # to the next unit cell - for j in xrange(W): - lead[lat(0, j)] = 4 * t - - if j > 0: - lead[lat(0, j), lat(0, j - 1)] = - t - - lead[lat(1, j), lat(0, j)] = - t - - return lead - - -def plot_bandstructure(lead, momenta): - # Use the method ``energies`` of the finalized lead to compute - # the bandstructure - energy_list = [lead.energies(k) for k in momenta] - - fig = pyplot.figure() - pyplot.plot(momenta, energy_list) - pyplot.xlabel("momentum [in units of (lattice constant)^-1]", - fontsize=latex.mpl_label_size) - pyplot.ylabel("energy [in units of t]", - fontsize=latex.mpl_label_size) - pyplot.setp(fig.get_axes()[0].get_xticklabels(), - fontsize=latex.mpl_tick_size) - pyplot.setp(fig.get_axes()[0].get_yticklabels(), - fontsize=latex.mpl_tick_size) - fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) - fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) - fig.savefig("3-band_structure_result.pdf") - fig.savefig("3-band_structure_result.png", - dpi=(html.figwidth_px/latex.mpl_width_in)) - - -def main(): - lead = make_lead().finalized() - - # list of momenta at which the bands should be computed - momenta = [-pi + 0.02 * pi * i for i in xrange(101)] - - plot_bandstructure(lead, momenta) - - -# Call the main function if the script gets executed (as opposed to imported). -# See <http://docs.python.org/library/__main__.html>. -if __name__ == '__main__': - main() diff --git a/doc/source/images/3-band_structure.py.diff b/doc/source/images/3-band_structure.py.diff new file mode 100644 index 00000000..0ca2e45d --- /dev/null +++ b/doc/source/images/3-band_structure.py.diff @@ -0,0 +1,35 @@ +--- original ++++ modified +@@ -12,6 +12,7 @@ + + # For plotting + from matplotlib import pyplot ++import latex, html + + + def make_lead(a=1, t=1.0, W=10): +@@ -39,11 +40,20 @@ + # the bandstructure + energy_list = [lead.energies(k) for k in momenta] + +- pyplot.figure() ++ fig = pyplot.figure() + pyplot.plot(momenta, energy_list) +- pyplot.xlabel("momentum [in units of (lattice constant)^-1]") +- pyplot.ylabel("energy [in units of t]") +- pyplot.show() ++ pyplot.xlabel("momentum [in units of (lattice constant)^-1]", ++ fontsize=latex.mpl_label_size) ++ pyplot.ylabel("energy [in units of t]", fontsize=latex.mpl_label_size) ++ pyplot.setp(fig.get_axes()[0].get_xticklabels(), ++ fontsize=latex.mpl_tick_size) ++ pyplot.setp(fig.get_axes()[0].get_yticklabels(), ++ fontsize=latex.mpl_tick_size) ++ fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) ++ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) ++ fig.savefig("3-band_structure_result.pdf") ++ fig.savefig("3-band_structure_result.png", ++ dpi=(html.figwidth_px/latex.mpl_width_in)) + + + def main(): diff --git a/doc/source/images/3-closed_system.py b/doc/source/images/3-closed_system.py deleted file mode 100644 index 33a99297..00000000 --- a/doc/source/images/3-closed_system.py +++ /dev/null @@ -1,111 +0,0 @@ -# Physics background -# ------------------ -# Fock-darwin spectrum of a quantum dot (energy spectrum in -# as a function of a magnetic field) -# -# Kwant features highlighted -# -------------------------- -# - Use of `hamiltonian_submatrix` in order to obtain a Hamiltonian -# matrix. - - -from cmath import exp -import kwant - -# For eigenvalue computation -import scipy.linalg as la - -# For plotting -from matplotlib import pyplot - -import latex, html - - -def make_system(a=1, t=1.0, r=10): - # 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) - - sys = kwant.Builder() - - # Define the quantum dot - def circle(pos): - (x, y) = pos - rsq = x ** 2 + y ** 2 - return rsq < r ** 2 - - def hopx(site1, site2): - # The magnetic field is controlled by the global variable B - y = site1.pos[1] - return - t * exp(-1j * B * y) - - sys[lat.shape(circle, (0, 0))] = 4 * t - # hoppings in x-direction - sys[sys.possible_hoppings((1, 0), lat, lat)] = hopx - # hoppings in y-directions - sys[sys.possible_hoppings((0, 1), lat, lat)] = - t - - # It's a closed system for a change, so no leads - return sys - - -def plot_spectrum(sys, Bfields): - # global variable B controls the magnetic field - global B - - # In the following, we compute the spectrum of the quantum dot - # using dense matrix methods. This works in this toy example, as - # the system is tiny. In a real example, one would want to use - # sparse matrix methods - - energies = [] - for Bfield in Bfields: - B = Bfield - - # Obtain the Hamiltonian as a dense matrix - ham_mat = sys.hamiltonian_submatrix() - - ev = la.eigh(ham_mat, eigvals_only=True) - - # we only plot the 15 lowest eigenvalues - energies.append(ev[:15]) - - fig = pyplot.figure() - pyplot.plot(Bfields, energies) - pyplot.xlabel("magnetic field [some arbitrary units]", - fontsize=latex.mpl_label_size) - pyplot.ylabel("energy [in units of t]", - fontsize=latex.mpl_label_size) - pyplot.setp(fig.get_axes()[0].get_xticklabels(), - fontsize=latex.mpl_tick_size) - pyplot.setp(fig.get_axes()[0].get_yticklabels(), - fontsize=latex.mpl_tick_size) - fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) - fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) - fig.savefig("3-closed_system_result.pdf") - fig.savefig("3-closed_system_result.png", - dpi=(html.figwidth_px/latex.mpl_width_in)) - - -def main(): - sys = make_system() - - # Check that the system looks as intended. - kwant.plot(sys, filename="3-closed_system_sys.pdf", - width=latex.figwidth_pt) - kwant.plot(sys, filename="3-closed_system_sys.png", - width=html.figwidth_px) - - # Finalize the system. - sys = sys.finalized() - - # We should observe energy levels that flow towards Landau - # level energies with increasing magnetic field - plot_spectrum(sys, [iB * 0.002 for iB in xrange(100)]) - - -# Call the main function if the script gets executed (as opposed to imported). -# See <http://docs.python.org/library/__main__.html>. -if __name__ == '__main__': - main() diff --git a/doc/source/images/3-closed_system.py.diff b/doc/source/images/3-closed_system.py.diff new file mode 100644 index 00000000..0bb1a9c1 --- /dev/null +++ b/doc/source/images/3-closed_system.py.diff @@ -0,0 +1,46 @@ +--- original ++++ modified +@@ -17,6 +17,7 @@ + + # For plotting + from matplotlib import pyplot ++import latex, html + + + def make_system(a=1, t=1.0, r=10): +@@ -69,18 +70,30 @@ + # we only plot the 15 lowest eigenvalues + energies.append(ev[:15]) + +- pyplot.figure() ++ fig = pyplot.figure() + pyplot.plot(Bfields, energies) +- pyplot.xlabel("magnetic field [some arbitrary units]") +- pyplot.ylabel("energy [in units of t]") +- pyplot.show() ++ pyplot.xlabel("magnetic field [some arbitrary units]", ++ fontsize=latex.mpl_label_size) ++ pyplot.ylabel("energy [in units of t]", fontsize=latex.mpl_label_size) ++ pyplot.setp(fig.get_axes()[0].get_xticklabels(), ++ fontsize=latex.mpl_tick_size) ++ pyplot.setp(fig.get_axes()[0].get_yticklabels(), ++ fontsize=latex.mpl_tick_size) ++ fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) ++ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) ++ fig.savefig("3-closed_system_result.pdf") ++ fig.savefig("3-closed_system_result.png", ++ dpi=(html.figwidth_px/latex.mpl_width_in)) + + + def main(): + sys = make_system() + + # Check that the system looks as intended. +- kwant.plot(sys) ++ kwant.plot(sys, filename="3-closed_system_sys.pdf", ++ width=latex.figwidth_pt) ++ kwant.plot(sys, filename="3-closed_system_sys.png", ++ width=html.figwidth_px) + + # Finalize the system. + sys = sys.finalized() diff --git a/doc/source/images/4-graphene.py b/doc/source/images/4-graphene.py deleted file mode 100644 index 7eabb367..00000000 --- a/doc/source/images/4-graphene.py +++ /dev/null @@ -1,193 +0,0 @@ -# Physics background -# ------------------ -# Transport through a graphene quantum dot with a pn-junction -# -# Kwant features highlighted -# -------------------------- -# - Application of all the aspects of tutorials 1-3 to a more complicated -# lattice, namely graphene - -from __future__ import division # so that 1/2 == 0.5, and not 0 -from math import pi, sqrt, tanh - -import kwant - -# For computing eigenvalues -import scipy.sparse.linalg as sla - -# For plotting -from matplotlib import pyplot - -import latex, html - -# Define the graphene lattice -sin_30, cos_30 = (1 / 2, sqrt(3) / 2) -graphene = kwant.make_lattice([(1, 0), (sin_30, cos_30)], - [(0, 0), (0, 1 / sqrt(3))]) -a, b = graphene.sublattices - - -def make_system(r=10, w=2.0, pot=0.1): - - #### Define the scattering region. #### - # circular scattering region - def circle(pos): - x, y = pos - return x ** 2 + y ** 2 < r ** 2 - - sys = kwant.Builder() - - # w: width and pot: potential maximum of the p-n junction - def potential(site): - (x, y) = site.pos - d = y * cos_30 + x * sin_30 - return pot * tanh(d / w) - - sys[graphene.shape(circle, (0, 0))] = potential - - # specify the hoppings of the graphene lattice in the - # format expected by possibe_hoppings() - hoppings = (((0, 0), b, a), ((0, 1), b, a), ((-1, 1), b, a)) - for hopping in hoppings: - sys[sys.possible_hoppings(*hopping)] = - 1 - - # Modify the scattering region - del sys[a(0, 0)] - sys[a(-2, 1), b(2, 2)] = -1 - - #### Define the leads. #### - # left lead - sym0 = kwant.TranslationalSymmetry([graphene.vec((-1, 0))]) - - def lead0_shape(pos): - x, y = pos - return (-1 < x < 1) and (-0.4 * r < y < 0.4 * r) - - lead0 = kwant.Builder(sym0) - lead0[graphene.shape(lead0_shape, (0, 0))] = - pot - for hopping in hoppings: - lead0[lead0.possible_hoppings(*hopping)] = - 1 - - # The second lead, going to the top right - sym1 = kwant.TranslationalSymmetry([graphene.vec((0, 1))]) - - def lead1_shape(pos): - x, y = pos - u = x * sin_30 + y * cos_30 - v = y * sin_30 - x * cos_30 - return (-1 < u < 1) and (-0.4 * r < v < 0.4 * r) - - lead1 = kwant.Builder(sym1) - lead1[graphene.shape(lead1_shape, (0, 0))] = pot - for hopping in hoppings: - lead1[lead1.possible_hoppings(*hopping)] = - 1 - - return sys, [lead0, lead1] - - -def compute_evs(sys): - # Compute some eigenvalues of the closed system - sparse_mat = sys.hamiltonian_submatrix(sparse=True) - - try: - # This requires scipy version >= 0.9.0 - # Failure (i.e. insufficient scipy version) is not critical - # for the remainder of the tutorial, hence the try-block - evs = sla.eigs(sparse_mat, 2)[0] - print evs - except: - pass - - -def plot_conductance(sys, energies): - # Compute transmission as a function of energy - data = [] - for energy in energies: - smatrix = kwant.solve(sys, energy) - data.append(smatrix.transmission(0, 1)) - - fig = pyplot.figure() - pyplot.plot(energies, data) - pyplot.xlabel("energy [in units of t]", - fontsize=latex.mpl_label_size) - pyplot.ylabel("conductance [in units of e^2/h]", - fontsize=latex.mpl_label_size) - pyplot.setp(fig.get_axes()[0].get_xticklabels(), - fontsize=latex.mpl_tick_size) - pyplot.setp(fig.get_axes()[0].get_yticklabels(), - fontsize=latex.mpl_tick_size) - fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) - fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) - fig.savefig("4-graphene_result.pdf") - fig.savefig("4-graphene_result.png", - dpi=(html.figwidth_px/latex.mpl_width_in)) - - -def plot_bandstructure(flead, momenta): - # Use the method ``energies`` of the finalized lead to compute - # the bandstructure - energy_list = [flead.energies(k) for k in momenta] - - fig = pyplot.figure() - pyplot.plot(momenta, energy_list) - pyplot.xlabel("momentum [in untis of (lattice constant)^-1]", - fontsize=latex.mpl_label_size) - pyplot.ylabel("energy [in units of t]", - fontsize=latex.mpl_label_size) - pyplot.setp(fig.get_axes()[0].get_xticklabels(), - fontsize=latex.mpl_tick_size) - pyplot.setp(fig.get_axes()[0].get_yticklabels(), - fontsize=latex.mpl_tick_size) - fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) - fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) - fig.savefig("4-graphene_bs.pdf") - fig.savefig("4-graphene_bs.png", - dpi=(html.figwidth_px/latex.mpl_width_in)) - - -def main(): - pot = 0.1 - sys, leads = make_system(pot=pot) - - # To highlight the two sublattices of graphene, we plot one with - # a filled, and the other one with an open circle: - plotter_symbols = {a: kwant.plotter.Circle(r=0.3), - b: kwant.plotter.Circle(r=0.3, - fcol=kwant.plotter.white, - lcol=kwant.plotter.black)} - - # Plot the closed system without leads. - kwant.plot(sys, symbols=plotter_symbols, - filename="4-graphene_sys1.pdf", width=latex.figwidth_pt) - kwant.plot(sys, symbols=plotter_symbols, - filename="4-graphene_sys1.png", width=html.figwidth_px) - - # Compute some eigenvalues. - compute_evs(sys.finalized()) - - # Attach the leads to the system. - for lead in leads: - sys.attach_lead(lead) - - # Then, plot the system with leads. - kwant.plot(sys, symbols=plotter_symbols, - filename="4-graphene_sys2.pdf", width=latex.figwidth_pt) - kwant.plot(sys, symbols=plotter_symbols, - filename="4-graphene_sys2.png", width=html.figwidth_px) - - # Finalize the system. - sys = sys.finalized() - - # Compute the band structure of lead 0. - momenta = [-pi + 0.02 * pi * i for i in xrange(101)] - plot_bandstructure(sys.leads[0], momenta) - - # Plot conductance. - energies = [-2 * pot + 4. / 50. * pot * i for i in xrange(51)] - plot_conductance(sys, energies) - - -# Call the main function if the script gets executed (as opposed to imported). -# See <http://docs.python.org/library/__main__.html>. -if __name__ == '__main__': - main() diff --git a/doc/source/images/4-graphene.py.diff b/doc/source/images/4-graphene.py.diff new file mode 100644 index 00000000..b2e31cb2 --- /dev/null +++ b/doc/source/images/4-graphene.py.diff @@ -0,0 +1,97 @@ +--- original ++++ modified +@@ -17,6 +17,7 @@ + + # For plotting + from matplotlib import pyplot ++import latex, html + + + # Define the graphene lattice +@@ -63,7 +64,7 @@ + return (-1 < x < 1) and (-0.4 * r < y < 0.4 * r) + + lead0 = kwant.Builder(sym0) +- lead0[graphene.shape(lead0_shape, (0, 0))] = -pot ++ lead0[graphene.shape(lead0_shape, (0, 0))] = - pot + for hopping in hoppings: + lead0[lead0.possible_hoppings(*hopping)] = -1 + +@@ -105,11 +106,21 @@ + smatrix = kwant.solve(sys, energy) + data.append(smatrix.transmission(0, 1)) + +- pyplot.figure() ++ fig = pyplot.figure() + pyplot.plot(energies, data) +- pyplot.xlabel("energy [in units of t]") +- pyplot.ylabel("conductance [in units of e^2/h]") +- pyplot.show() ++ pyplot.xlabel("energy [in units of t]", ++ fontsize=latex.mpl_label_size) ++ pyplot.ylabel("conductance [in units of e^2/h]", ++ fontsize=latex.mpl_label_size) ++ pyplot.setp(fig.get_axes()[0].get_xticklabels(), ++ fontsize=latex.mpl_tick_size) ++ pyplot.setp(fig.get_axes()[0].get_yticklabels(), ++ fontsize=latex.mpl_tick_size) ++ fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) ++ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) ++ fig.savefig("4-graphene_result.pdf") ++ fig.savefig("4-graphene_result.png", ++ dpi=(html.figwidth_px/latex.mpl_width_in)) + + + def plot_bandstructure(flead, momenta): +@@ -117,11 +128,21 @@ + # the bandstructure + energy_list = [flead.energies(k) for k in momenta] + +- pyplot.figure() ++ fig = pyplot.figure() + pyplot.plot(momenta, energy_list) +- pyplot.xlabel("momentum [in untis of (lattice constant)^-1]") +- pyplot.ylabel("energy [in units of t]") +- pyplot.show() ++ pyplot.xlabel("momentum [in untis of (lattice constant)^-1]", ++ fontsize=latex.mpl_label_size) ++ pyplot.ylabel("energy [in units of t]", ++ fontsize=latex.mpl_label_size) ++ pyplot.setp(fig.get_axes()[0].get_xticklabels(), ++ fontsize=latex.mpl_tick_size) ++ pyplot.setp(fig.get_axes()[0].get_yticklabels(), ++ fontsize=latex.mpl_tick_size) ++ fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) ++ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) ++ fig.savefig("4-graphene_bs.pdf") ++ fig.savefig("4-graphene_bs.png", ++ dpi=(html.figwidth_px/latex.mpl_width_in)) + + + def main(): +@@ -136,17 +157,20 @@ + lcol=kwant.plotter.black)} + + # Plot the closed system without leads. +- kwant.plot(sys, symbols=plotter_symbols) +- +- # Compute some eigenvalues. +- compute_evs(sys.finalized()) ++ kwant.plot(sys, symbols=plotter_symbols, ++ filename="4-graphene_sys1.pdf", width=latex.figwidth_pt) ++ kwant.plot(sys, symbols=plotter_symbols, ++ filename="4-graphene_sys1.png", width=html.figwidth_px) + + # Attach the leads to the system. + for lead in leads: + sys.attach_lead(lead) + + # Then, plot the system with leads. +- kwant.plot(sys, symbols=plotter_symbols) ++ kwant.plot(sys, symbols=plotter_symbols, ++ filename="4-graphene_sys2.pdf", width=latex.figwidth_pt) ++ kwant.plot(sys, symbols=plotter_symbols, ++ filename="4-graphene_sys2.png", width=html.figwidth_px) + + # Finalize the system. + sys = sys.finalized() diff --git a/doc/source/images/5-superconductor_band_structure.py b/doc/source/images/5-superconductor_band_structure.py deleted file mode 100644 index d2bc3276..00000000 --- a/doc/source/images/5-superconductor_band_structure.py +++ /dev/null @@ -1,81 +0,0 @@ -# Physics background -# ------------------ -# band structure of a superconducting quantum wire in tight-binding -# approximation -# -# Kwant features highlighted -# -------------------------- -# - Repetition of previously used concepts (band structure calculations, -# matrices as values in Builder). -# - Main motivation is to contrast to the implementation of superconductivity -# in tutorial5b.py - -import kwant - -import numpy as np -from math import pi - -# For plotting -from matplotlib import pyplot - -import latex, html - -tau_x = np.array([[0, 1], [1, 0]]) -tau_z = np.array([[1, 0], [0, -1]]) - - -def make_lead(a=1, t=1.0, mu=0.7, Delta=0.1, W=10): - # Start with an empty lead with a single square lattice - lat = kwant.lattice.Square(a) - - sym_lead = kwant.TranslationalSymmetry([lat.vec((-1, 0))]) - lead = kwant.Builder(sym_lead) - - # build up one unit cell of the lead, and add the hoppings - # to the next unit cell - for j in xrange(W): - lead[lat(0, j)] = (4 * t - mu) * tau_z + Delta * tau_x - - if j > 0: - lead[lat(0, j), lat(0, j - 1)] = - t * tau_z - - lead[lat(1, j), lat(0, j)] = - t * tau_z - - return lead - - -def plot_bandstructure(lead, momenta): - # Use the method ``energies`` of the finalized lead to compute - # the bandstructure - energy_list = [lead.energies(k) for k in momenta] - - fig = pyplot.figure() - pyplot.plot(momenta, energy_list) - pyplot.xlabel("momentum [in untis of (lattice constant)^-1]") - pyplot.ylabel("energy [in units of t]") - pyplot.ylim([-0.8, 0.8]) - pyplot.setp(fig.get_axes()[0].get_xticklabels(), - fontsize=latex.mpl_tick_size) - pyplot.setp(fig.get_axes()[0].get_yticklabels(), - fontsize=latex.mpl_tick_size) - fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) - fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) - fig.savefig("5-superconductor_band_structure_result.pdf") - fig.savefig("5-superconductor_band_structure_result.png", - dpi=(html.figwidth_px/latex.mpl_width_in)) - - -def main(): - # Make system and finalize it right away. - lead = make_lead().finalized() - - # list of momenta at which the bands should be computed - momenta = np.linspace(-1.5, 1.5, 201) - - plot_bandstructure(lead, momenta) - - -# Call the main function if the script gets executed (as opposed to imported). -# See <http://docs.python.org/library/__main__.html>. -if __name__ == '__main__': - main() diff --git a/doc/source/images/5-superconductor_band_structure.py.diff b/doc/source/images/5-superconductor_band_structure.py.diff new file mode 100644 index 00000000..8b8d6e5a --- /dev/null +++ b/doc/source/images/5-superconductor_band_structure.py.diff @@ -0,0 +1,33 @@ +--- original ++++ modified +@@ -17,6 +17,7 @@ + + # For plotting + from matplotlib import pyplot ++import latex, html + + tau_x = np.array([[0, 1], [1, 0]]) + tau_z = np.array([[1, 0], [0, -1]]) +@@ -47,12 +48,20 @@ + # the bandstructure + energy_list = [lead.energies(k) for k in momenta] + +- pyplot.figure() ++ fig = pyplot.figure() + pyplot.plot(momenta, energy_list) + pyplot.xlabel("momentum [in untis of (lattice constant)^-1]") + pyplot.ylabel("energy [in units of t]") + pyplot.ylim([-0.8, 0.8]) +- pyplot.show() ++ pyplot.setp(fig.get_axes()[0].get_xticklabels(), ++ fontsize=latex.mpl_tick_size) ++ pyplot.setp(fig.get_axes()[0].get_yticklabels(), ++ fontsize=latex.mpl_tick_size) ++ fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) ++ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) ++ fig.savefig("5-superconductor_band_structure_result.pdf") ++ fig.savefig("5-superconductor_band_structure_result.png", ++ dpi=(html.figwidth_px/latex.mpl_width_in)) + + + def main(): diff --git a/doc/source/images/5-superconductor_transport.py b/doc/source/images/5-superconductor_transport.py deleted file mode 100644 index b9a90a61..00000000 --- a/doc/source/images/5-superconductor_transport.py +++ /dev/null @@ -1,126 +0,0 @@ -# Physics background -# ------------------ -# - conductance of a NS-junction (Andreev reflection, superconducting gap) -# -# Kwant features highlighted -# -------------------------- -# - Implementing electron and hole ("orbital") degrees of freedom -# using different lattices - -import kwant - -# For plotting -from matplotlib import pyplot - -import latex, html - -def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4), - mu=0.4, Delta=0.1, Deltapos=4, t=1.0): - # Start with an empty tight-binding system and two square lattices, - # corresponding to electron and hole degree of freedom - lat_e = kwant.lattice.Square(a) - lat_h = kwant.lattice.Square(a) - - sys = kwant.Builder() - - #### Define the scattering region. #### - sys[(lat_e(x, y) for x in range(L) for y in range(W))] = 4 * t - mu - sys[(lat_h(x, y) for x in range(L) for y in range(W))] = mu - 4 * t - - # the tunnel barrier - sys[(lat_e(x, y) for x in range(barrierpos[0], barrierpos[1]) - for y in range(W))] = 4 * t + barrier - mu - sys[(lat_h(x, y) for x in range(barrierpos[0], barrierpos[1]) - for y in range(W))] = mu - 4 * t - barrier - - # hoppings in x and y-directions, for both electrons and holes - sys[sys.possible_hoppings((1, 0), lat_e, lat_e)] = - t - sys[sys.possible_hoppings((0, 1), lat_e, lat_e)] = - t - sys[sys.possible_hoppings((1, 0), lat_h, lat_h)] = t - sys[sys.possible_hoppings((0, 1), lat_h, lat_h)] = t - - # Superconducting order parameter enters as hopping between - # electrons and holes - sys[((lat_e(x, y), lat_h(x, y)) for x in range(Deltapos, L) - for y in range(W))] = Delta - - #### Define the leads. #### - # left electron lead - sym_lead0 = kwant.TranslationalSymmetry([lat_e.vec((-1, 0))]) - lead0 = kwant.Builder(sym_lead0) - - lead0[(lat_e(0, j) for j in xrange(W))] = 4 * t - mu - # hoppings in x and y-direction - lead0[lead0.possible_hoppings((1, 0), lat_e, lat_e)] = - t - lead0[lead0.possible_hoppings((0, 1), lat_e, lat_e)] = - t - - # left hole lead - sym_lead1 = kwant.TranslationalSymmetry([lat_h.vec((-1, 0))]) - lead1 = kwant.Builder(sym_lead1) - - lead1[(lat_h(0, j) for j in xrange(W))] = mu - 4 * t - # hoppings in x and y-direction - lead1[lead1.possible_hoppings((1, 0), lat_h, lat_h)] = t - lead1[lead1.possible_hoppings((0, 1), lat_h, lat_h)] = t - - # Then the lead to the right - # this one is superconducting and thus is comprised of electrons - # AND holes - sym_lead2 = kwant.TranslationalSymmetry([lat_e.vec((1, 0))]) - lead2 = kwant.Builder(sym_lead2) - - lead2[(lat_e(0, j) for j in xrange(W))] = 4 * t - mu - lead2[(lat_h(0, j) for j in xrange(W))] = mu - 4 * t - # hoppings in x and y-direction - lead2[lead2.possible_hoppings((1, 0), lat_e, lat_e)] = - t - lead2[lead2.possible_hoppings((0, 1), lat_e, lat_e)] = - t - lead2[lead2.possible_hoppings((1, 0), lat_h, lat_h)] = t - 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 system. #### - sys.attach_lead(lead0) - sys.attach_lead(lead1) - sys.attach_lead(lead2) - - return sys - - -def plot_conductance(sys, energies): - # Compute conductance - data = [] - for energy in energies: - smatrix = kwant.solve(sys, energy) - # Conductance is N - R_ee + R_he - data.append(smatrix.submatrix(0, 0).shape[0] - - smatrix.transmission(0, 0) + - smatrix.transmission(1, 0)) - - fig = pyplot.figure() - pyplot.plot(energies, data) - pyplot.xlabel("energy [in units of t]") - pyplot.ylabel("conductance [in units of e^2/h]") - pyplot.setp(fig.get_axes()[0].get_xticklabels(), - fontsize=latex.mpl_tick_size) - pyplot.setp(fig.get_axes()[0].get_yticklabels(), - fontsize=latex.mpl_tick_size) - fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) - fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) - fig.savefig("5-superconductor_transport_result.pdf") - fig.savefig("5-superconductor_transport_result.png", - dpi=(html.figwidth_px/latex.mpl_width_in)) - - -def main(): - sys = make_system() - - # Finalize the system. - sys = sys.finalized() - - plot_conductance(sys, energies=[0.002 * i for i in xrange(100)]) - - -# Call the main function if the script gets executed (as opposed to imported). -# See <http://docs.python.org/library/__main__.html>. -if __name__ == '__main__': - main() diff --git a/doc/source/images/5-superconductor_transport.py.diff b/doc/source/images/5-superconductor_transport.py.diff new file mode 100644 index 00000000..241d417d --- /dev/null +++ b/doc/source/images/5-superconductor_transport.py.diff @@ -0,0 +1,40 @@ +--- original ++++ modified +@@ -11,6 +11,7 @@ + + # For plotting + from matplotlib import pyplot ++import latex, html + + + def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4), +@@ -95,19 +96,24 @@ + smatrix.transmission(0, 0) + + smatrix.transmission(1, 0)) + +- pyplot.figure() ++ fig = pyplot.figure() + pyplot.plot(energies, data) + pyplot.xlabel("energy [in units of t]") + pyplot.ylabel("conductance [in units of e^2/h]") +- pyplot.show() ++ pyplot.setp(fig.get_axes()[0].get_xticklabels(), ++ fontsize=latex.mpl_tick_size) ++ pyplot.setp(fig.get_axes()[0].get_yticklabels(), ++ fontsize=latex.mpl_tick_size) ++ fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.) ++ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) ++ fig.savefig("5-superconductor_transport_result.pdf") ++ fig.savefig("5-superconductor_transport_result.png", ++ dpi=(html.figwidth_px/latex.mpl_width_in)) + + + def main(): + sys = make_system() + +- # Check that the system looks as intended. +- kwant.plot(sys) +- + # Finalize the system. + sys = sys.finalized() + diff --git a/doc/source/images/generate-diffs.sh b/doc/source/images/generate-diffs.sh new file mode 100755 index 00000000..e68cacef --- /dev/null +++ b/doc/source/images/generate-diffs.sh @@ -0,0 +1,10 @@ +# !/bin/sh + +# This script regenerates the .diff files in this directory. It's these files +# that are kept under vesion control instead of the scripts themselves. + +for f in [0-9]-*.py; do + # We use custom labels to suppress the time stamps which are unnecessary + # here and would only lead to noise in version control. + diff -u --label original --label modified ../../../tutorial/$f $f >$f.diff +done diff --git a/tutorial/3-closed_system.py b/tutorial/3-closed_system.py index 2cb44f58..82361ebe 100644 --- a/tutorial/3-closed_system.py +++ b/tutorial/3-closed_system.py @@ -36,7 +36,7 @@ def make_system(a=1, t=1.0, r=10): def hopx(site1, site2): # The magnetic field is controlled by the global variable B y = site1.pos[1] - return - t * exp(-1j * B * y) + return -t * exp(-1j * B * y) sys[lat.shape(circle, (0, 0))] = 4 * t # hoppings in x-direction diff --git a/tutorial/README b/tutorial/README new file mode 100644 index 00000000..d77eef72 --- /dev/null +++ b/tutorial/README @@ -0,0 +1,14 @@ +This directory contains the example scripts of the tutorial. + + +Note for kwant developers +------------------------- + +Say you have modified SCRIPT.py in this directory. Make sure that the tutorial +image generation patches still apply by deleting doc/source/images/SCRIPT.py +and running ``make doc/source/images/SCRIPT.py`` in doc. Now examine the newly +created doc/source/images/SCRIPT.py. If you do not like the result or the +patch did not apply, edit doc/source/images/SCRIPT.py until you like it. You +can run `make html` during your edits to check things. Finally, even if you +did not edit the script, execute generate-diffs.sh in doc/source/images. If +the patches applied cleanly the diff files will usually stay unchanged. -- GitLab