Commit 2ed4cae2 authored by Anton Akhmerov's avatar Anton Akhmerov Committed by Christoph Groth
Browse files

rewrite plotter for matplotlib

parent 726ee7ae
--- original
+++ modified
@@ -9,6 +9,7 @@
# - Using the simple sparse solver for computing Landauer conductance
@@ -10,6 +10,8 @@
from matplotlib import pyplot
import kwant
+import latex, html
+import latex
+import html
# First, define the tight-binding system
@@ -73,7 +74,8 @@
@@ -73,8 +75,9 @@
sys.attach_lead(lead1)
# 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)
+size = (latex.figwidth_in, 0.3 * latex.figwidth_in)
+kwant.plot(sys, file="1-quantum_wire_sys.pdf", fig_size=size, dpi=html.dpi)
+kwant.plot(sys, file="1-quantum_wire_sys.png", fig_size=size, dpi=html.dpi)
# Finalize the system
@@ -98,8 +100,14 @@
@@ -98,8 +101,13 @@
# Use matplotlib to write output
# We should see conductance steps
from matplotlib import pyplot
-pyplot.figure()
+fig = pyplot.figure()
......@@ -32,8 +35,7 @@
+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.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))
+fig.savefig("1-quantum_wire_result.png", dpi=html.dpi)
......@@ -81,11 +81,10 @@
+ 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.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))
+ fig.savefig("2-ab_ring_result.png", dpi=html.dpi)
def main():
......@@ -93,8 +92,9 @@
# 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)
+ size = (latex.figwidth_in, latex.figwidth_in)
+ kwant.plot(sys, file="2-ab_ring_sys.pdf", fig_size=size, dpi=html.dpi)
+ kwant.plot(sys, file="2-ab_ring_sys.png", fig_size=size, dpi=html.dpi)
# Finalize the system.
sys = sys.finalized()
......@@ -104,11 +104,11 @@
+ # 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)
+ kwant.plot(sys, file="2-ab_ring_note1.pdf", fig_size=size, dpi=html.dpi)
+ kwant.plot(sys, file="2-ab_ring_note1.png", fig_size=size, dpi=html.dpi)
+ 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)
+ kwant.plot(sys, file="2-ab_ring_note2.pdf", fig_size=size, dpi=html.dpi)
+ kwant.plot(sys, file="2-ab_ring_note2.png", fig_size=size, dpi=html.dpi)
+
+
# Call the main function if the script gets executed (as opposed to imported).
......
......@@ -8,7 +8,7 @@
# global variable governing the behavior of potential() in
# make_system()
@@ -76,19 +77,26 @@
@@ -76,19 +77,25 @@
smatrix = kwant.solve(sys, energy)
data.append(smatrix.transmission(1, 0))
......@@ -26,11 +26,10 @@
+ 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.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))
+ fig.savefig("2-quantum_well_result.png", dpi=html.dpi)
def main():
......
......@@ -8,7 +8,7 @@
# define Pauli-matrices for convenience
sigma_0 = numpy.eye(2)
@@ -73,19 +74,25 @@
@@ -73,19 +74,24 @@
smatrix = kwant.solve(sys, energy)
data.append(smatrix.transmission(1, 0))
......@@ -25,11 +25,10 @@
+ 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.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))
+ fig.savefig("2-spin_orbit_result.png", dpi=html.dpi)
def main():
......
......@@ -8,7 +8,7 @@
def make_lead(a=1, t=1.0, W=10):
@@ -39,11 +40,20 @@
@@ -39,11 +40,19 @@
# the bandstructure
energy_list = [lead.energies(k) for k in momenta]
......@@ -25,11 +25,10 @@
+ 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.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))
+ fig.savefig("3-band_structure_result.png", dpi=html.dpi)
def main():
......@@ -8,7 +8,7 @@
def make_system(a=1, t=1.0, r=10):
@@ -69,18 +70,30 @@
@@ -69,19 +70,24 @@
# we only plot the 15 lowest eigenvalues
energies.append(ev[:15])
......@@ -25,22 +25,18 @@
+ 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.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))
+ fig.savefig("3-closed_system_result.png", dpi=html.dpi)
def main():
sys = make_system()
# Check that the system looks as intended.
- # 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()
--- original
+++ modified
@@ -17,6 +17,7 @@
@@ -17,6 +17,8 @@
# For plotting
from matplotlib import pyplot
+import latex, html
+import latex
+import html
# Define the graphene lattice
@@ -63,7 +64,7 @@
@@ -63,7 +65,7 @@
return (-1 < x < 1) and (-0.4 * r < y < 0.4 * r)
lead0 = kwant.Builder(sym0)
......@@ -17,7 +18,7 @@
for hopping in hoppings:
lead0[lead0.possible_hoppings(*hopping)] = -1
@@ -105,11 +106,21 @@
@@ -105,11 +107,20 @@
smatrix = kwant.solve(sys, energy)
data.append(smatrix.transmission(0, 1))
......@@ -35,15 +36,14 @@
+ 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.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))
+ fig.savefig("4-graphene_result.png", dpi=html.dpi)
def plot_bandstructure(flead, momenta):
@@ -117,11 +128,21 @@
@@ -117,11 +128,20 @@
# the bandstructure
energy_list = [flead.energies(k) for k in momenta]
......@@ -61,37 +61,38 @@
+ 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.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))
+ fig.savefig("4-graphene_bs.png", dpi=html.dpi)
def main():
@@ -136,17 +157,20 @@
lcol=kwant.plotter.black)}
@@ -134,17 +154,22 @@
return 0 if site.group == a else 1
# Plot the closed system without leads.
- kwant.plot(sys, symbols=plotter_symbols)
- kwant.plot(sys, site_color=group_colors, colorbar=False)
-
- # 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)
+ size = (latex.figwidth_in, latex.figwidth_in)
+ kwant.plot(sys, site_color=group_colors, colorbar=False,
+ file="4-graphene_sys1.pdf", fig_size=size, dpi=html.dpi)
+ kwant.plot(sys, site_color=group_colors, colorbar=False,
+ file="4-graphene_sys1.png", fig_size=size, dpi=html.dpi)
# 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)
- kwant.plot(sys, site_color=group_colors, colorbar=False)
+ size = (latex.figwidth_in, 0.9 * latex.figwidth_in)
+ kwant.plot(sys, site_color=group_colors, colorbar=False,
+ file="4-graphene_sys2.pdf", fig_size=size, dpi=html.dpi)
+ kwant.plot(sys, site_color=group_colors, colorbar=False,
+ file="4-graphene_sys2.png", fig_size=size, dpi=html.dpi)
# Finalize the system.
sys = sys.finalized()
......@@ -8,7 +8,7 @@
tau_x = np.array([[0, 1], [1, 0]])
tau_z = np.array([[1, 0], [0, -1]])
@@ -46,12 +47,20 @@
@@ -46,12 +47,19 @@
# the bandstructure
energy_list = [lead.energies(k) for k in momenta]
......@@ -23,11 +23,10 @@
+ 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.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))
+ fig.savefig("5-superconductor_band_structure_result.png", dpi=html.dpi)
def main():
......@@ -8,7 +8,7 @@
def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4),
@@ -95,19 +96,24 @@
@@ -95,19 +96,23 @@
smatrix.transmission(0, 0) +
smatrix.transmission(1, 0))
......@@ -22,11 +22,10 @@
+ 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.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))
+ fig.savefig("5-superconductor_transport_result.png", dpi=html.dpi)
def main():
......
# Default width of figures in pixels
figwidth_px = 600
# Width for smaller figures
figwidth_small_px = 400
# dpi for conversion from inches
dpi = 90
pt_to_in = 1./72.
pt_to_in = 1. / 72.
# Default width of figures in pts
figwidth_pt = 300
figwidth_pt = 600
figwidth_in = figwidth_pt * pt_to_in
# Width for smaller figures
figwidth_small_pt = 200
figwidth_small_pt = 400
figwidth_small_in = figwidth_small_pt * pt_to_in
# Sizes for matplotlib figures
mpl_width_in = figwidth_pt * pt_to_in
mpl_label_size = 10 # font sizes in points
mpl_tick_size = 9
mpl_label_size = None # font sizes in points
mpl_tick_size = None
......@@ -10,30 +10,16 @@ Plotting routine
:toctree: generated/
plot
show
interpolate
map
Auxiliary types
----------------
Data-generating functions
-------------------------
.. autosummary::
:toctree: generated/
Circle
Polygon
Line
LineStyle
Color
sys_leads_sites
sys_leads_hoppings
sys_leads_pos
sys_leads_hopping_pos
mask_interpolate
Pre-defined colors
------------------
+------------------------+
| `~kwant.plotter.black` |
+------------------------+
| `~kwant.plotter.white` |
+------------------------+
| `~kwant.plotter.red` |
+------------------------+
| `~kwant.plotter.green` |
+------------------------+
| `~kwant.plotter.blue` |
+------------------------+
......@@ -8,6 +8,7 @@
# - Making scattering region and leads
# - Using the simple sparse solver for computing Landauer conductance
from matplotlib import pyplot
#HIDDEN_BEGIN_dwhx
import kwant
#HIDDEN_END_dwhx
......@@ -119,7 +120,6 @@ for ie in xrange(100):
# Use matplotlib to write output
# We should see conductance steps
#HIDDEN_BEGIN_lliv
from matplotlib import pyplot
pyplot.figure()
pyplot.plot(energies, data)
......
......@@ -151,13 +151,11 @@ def main():
# 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)}
def group_colors(site):
return 0 if site.group == a else 1
# Plot the closed system without leads.
kwant.plot(sys, symbols=plotter_symbols)
kwant.plot(sys, site_color=group_colors, colorbar=False)
#HIDDEN_END_itkk
# Compute some eigenvalues.
......@@ -170,7 +168,7 @@ def main():
sys.attach_lead(lead)
# Then, plot the system with leads.
kwant.plot(sys, symbols=plotter_symbols)
kwant.plot(sys, site_color=group_colors, colorbar=False)
# Finalize the system.
sys = sys.finalized()
......
......@@ -118,27 +118,16 @@ plot the system:
:start-after: #HIDDEN_BEGIN_itkk
:end-before: #HIDDEN_END_itkk
We customize the plotting: `plotter_symbols` is a dictionary with the
sublattice objects `a` and `b` as keys, and the `~kwant.plotter.Circle` objects
specify that the sublattice `a` should be drawn using a filled black circle,
and `b` using a white circle with a black outline. ::
plotter_symbols = {a: kwant.plotter.Circle(r=0.3),
b: kwant.plotter.Circle(r=0.3,
fcol=kwant.plotter.white,
lcol=kwant.plotter.black)}
The radius of the circle is given in relative units: `~kwant.plotter.plot` uses
a typical length scale as a reference length. By default, the typical length
scale is the smallest distance between lattice points. `~kwant.plotter.plot`
can find this length by itself, but must then go through all
hoppings. Alternatively, one can specify the typical length scale using the
argument `a` as in the example (not to be confused with the sublattice `a`)
which is here set to the distance between carbon atoms in the graphene
lattice. Specifying ``r=0.3`` in `~kwant.plotter.Circle` hence means that the
radius of the circle is 30% of the carbon-carbon distance. Using this relative
unit it is easy to make good-looking plots where the symbols cover a
well-defined part of the plot.
We customize the plotting: we set the `site_colors` argument of
`~kwant.plotter.plot` to a function which returns 0 for
sublattice `a` and 1 for sublattice `b`::
def group_colors(site):
return 0 if site.group == a else 1
The function `~kwant.plotter.plot` shows these values using a color scale
(grayscale by default). The symbol `size` is specified in points, and is
independent on the overall figure size.
Plotting the closed system gives this result:
......
......@@ -29,33 +29,31 @@ New tutorial dealing with superconductivity
-------------------------------------------
:doc:`../tutorial/tutorial5`
`~kwant.plotter.plot` more useful for low level systems
-------------------------------------------------------
The behavior of `~kwant.plotter.plot` has been changed when a `low level system
<kwant.system.System>` is plotted. Previously, only low level systems which
were finalized `builders <kwant.builder.Builder>` were supported and there was
no difference between plotting a low-level system and a builder.
New `~kwant.plotter` module
---------------------------
`~kwant.plotter` has been rewritten using `matplotlib`, which allows
plot post-processing, basic 3D plotting and many other features. Due to the
possibility to easily modify a `matplotlib` plot after it has been generated,
function `~kwant.plotter.plot` has much fewer input parameters, and is less
flexible than its previous implementation. Its interface is also much more
similar to that of `matplotlib`. For the detailed interface and input
description check `~kwant.plotter.plot` documentation.
* Arguments of plot which are functions are given site numbers in place of
`~kwant.builder.Site` objects when plotting a low level system. This
provides an easy way to make the appearance of lines and symbols depend on
computation results.
The behavior of `~kwant.plotter.plot` with low level systems has changed.
Arguments of plot which are functions are given site numbers in place of
`~kwant.builder.Site` objects when plotting a low level system. This
provides an easy way to make the appearance of lines and symbols depend on
computation results.
* Only the scattering region (without leads) is plotted for low level systems.
* For plotting low level systems, dictionaries with site group keys are no
longer supported as plot arguments.
A new function `~kwant.plotter.map` was implemented. It allows to show a map of
spatial dependence of a function of a system site (e.g. density of states)
without showing the sites themselves.
Calculation of the local density of states
------------------------------------------
The new function of sparse solvers `~kwant.solvers.common.SparseSolver.ldos`
allows the calculation of the local density of states.
Plotting of functions of system sites
-------------------------------------
The new function `kwant.plotter.show` plots functions of the system, i.e. the
potential or the LDOS.
Return value of sparse solver
-----------------------------
The function `~kwant.solvers.common.SparseSolver.solve` of sparse solvers now
......@@ -63,6 +61,6 @@ always returns a single instance of `~kwant.solvers.common.BlockResult`. The
latter has been generalized to include more information for leads defined as
infinite systems.
Return value of `~kwant.solvers.sparse.make_linear_sys` has changed
-------------------------------------------------------------------
Return value of `~kwant.solvers.common.SparseSolver.make_linear_sys` has changed
--------------------------------------------------------------------------------
A namedtuple is used for more clarity.
This diff is collapsed.
import tempfile, os
from nose.tools import assert_raises
import numpy as np
import tempfile
import nose
import kwant
from kwant import plotter
if plotter._mpl_enabled:
from mpl_toolkits import mplot3d
from matplotlib import pyplot
def sys_2d(W=3, r1=3, r2=8):
a = 1
t = 1.0
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, r1 + 1))] = 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)
return sys
def sys_3d(W=3, r1=2, r2=4, a=1, t=1.0):
lat = kwant.make_lattice(((a, 0, 0), (0, a, 0), (0, 0, a)))
lat.nearest = (((1, 0, 0), lat, lat), ((0, 1, 0), lat, lat),
((0, 0, 1), lat, lat))
sys = kwant.Builder()
def ring(pos):
(x, y, z) = pos
rsq = x ** 2 + y ** 2
return (r1 ** 2 < rsq < r2 ** 2) and abs(z) < 2
sys[lat.shape(ring, (0, -r2 + 1, 0))] = 4 * t
for hopping in lat.nearest:
sys[sys.possible_hoppings(*hopping)] = - t
sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0, 0))])
lead0 = kwant.Builder(sym_lead0)
def lead_shape(pos):
(x, y, z) = pos
return (-1 < x < 1) and (-W / 2 < y < W / 2) and abs(z) < 2
lead0[lat.shape(lead_shape, (0, 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)
return sys
lat = kwant.lattice.Square()