#!/usr/bin/env python
# coding: utf-8

# In[1]:


# Tutorial 2.2.3. Building the same system with less code
# =======================================================
#
# Physics background
# ------------------
#  Conductance of a quantum wire; subbands
#
# Kwant features highlighted
# --------------------------
#  - Using iterables and builder.HoppingKind for making systems
#  - introducing `reversed()` for the leads
#
# Note: Does the same as tutorial1a.py, but using other features of Kwant.


# In[2]:


import kwant

# For plotting
from matplotlib import pyplot


# In[3]:


import matplotlib
import matplotlib.pyplot
from matplotlib_inline.backend_inline import set_matplotlib_formats

matplotlib.rcParams['figure.figsize'] = matplotlib.pyplot.figaspect(1) * 2
set_matplotlib_formats('svg')


# In[4]:


a = 1
t = 1.0
W, L = 10, 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).
# Each lattice site has 1 degree of freedom, hence norbs=1.
lat = kwant.lattice.square(a, norbs=1)

syst = kwant.Builder()


# In[5]:


syst[(lat(x, y) for x in range(L) for y in range(W))] = 4 * t


# In[6]:


syst[lat.neighbors()] = -t


# In[7]:


lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0)))
lead[(lat(0, j) for j in range(W))] = 4 * t
lead[lat.neighbors()] = -t


# In[8]:


syst.attach_lead(lead)
syst.attach_lead(lead.reversed())


# In[9]:


syst = syst.finalized()


# In[10]:


energies = []
data = []
for ie in range(100):
    energy = ie * 0.01
    smatrix = kwant.smatrix(syst, energy)
    energies.append(energy)
    data.append(smatrix.transmission(1, 0))

pyplot.figure()
pyplot.plot(energies, data)
pyplot.xlabel("energy [t]")
pyplot.ylabel("conductance [e^2/h]")
pyplot.show()

