Commit 195e4249 authored by Christoph Groth's avatar Christoph Groth
Browse files

Merge branch 'python3'

parents 2de760a3 0f3068d1
...@@ -136,5 +136,5 @@ $(foreach name,$(SCRIPTS),$(eval $(call makedep,$(name)))) ...@@ -136,5 +136,5 @@ $(foreach name,$(SCRIPTS),$(eval $(call makedep,$(name))))
# Generation of images # Generation of images
.%_flag: %.py .%_flag: %.py
cd $(dir $<) && python $(notdir $<) cd $(dir $<) && python3 $(notdir $<)
@touch $@ @touch $@
...@@ -42,8 +42,8 @@ source_suffix = '.rst' ...@@ -42,8 +42,8 @@ source_suffix = '.rst'
master_doc = 'index' master_doc = 'index'
# General information about the project. # General information about the project.
project = u'Kwant' project = 'Kwant'
copyright = u'2011-2015, C. W. Groth (CEA), M. Wimmer, A. R. Akhmerov, X. Waintal (CEA), and others' copyright = '2011-2015, C. W. Groth (CEA), M. Wimmer, A. R. Akhmerov, X. Waintal (CEA), and others'
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
...@@ -208,7 +208,7 @@ r"""\makeatletter ...@@ -208,7 +208,7 @@ r"""\makeatletter
# We use "et al." as it is shorter and there's not much space left horizontally. # We use "et al." as it is shorter and there's not much space left horizontally.
latex_documents = [ latex_documents = [
('index', 'kwant.tex', 'Kwant {0} documentation'.format(release), ('index', 'kwant.tex', 'Kwant {0} documentation'.format(release),
u'C. W. Groth, M. Wimmer, A. R. Akhmerov, X. Waintal, et al.', 'C. W. Groth, M. Wimmer, A. R. Akhmerov, X. Waintal, et al.',
'manual'), 'manual'),
] ]
...@@ -249,9 +249,9 @@ class BoundMethodDocumenter(autodoc.FunctionDocumenter): ...@@ -249,9 +249,9 @@ class BoundMethodDocumenter(autodoc.FunctionDocumenter):
# Return True iff `member` is a bound method. Taken from # Return True iff `member` is a bound method. Taken from
# <http://stackoverflow.com/a/1260881>. # <http://stackoverflow.com/a/1260881>.
return (isinstance(member, types.MethodType) and return (isinstance(member, types.MethodType) and
member.im_self is not None and member.__self__ is not None and
not issubclass(member.im_class, type) and not issubclass(member.__self__.__class__, type) and
member.im_class is not types.ClassType) member.__self__.__class__ is not type)
def format_args(self): def format_args(self):
args = super(BoundMethodDocumenter, self).format_args() args = super(BoundMethodDocumenter, self).format_args()
......
--- original --- original
+++ modified +++ modified
@@ -11,6 +11,7 @@ @@ -11,5 +11,6 @@
# lattice, namely graphene # lattice, namely graphene
from __future__ import division # so that 1/2 == 0.5, and not 0
+import _defs +import _defs
from math import pi, sqrt, tanh from math import pi, sqrt, tanh
import kwant import kwant
@@ -97,22 +98,40 @@ @@ -96,22 +97,40 @@
smatrix = kwant.smatrix(sys, energy) smatrix = kwant.smatrix(sys, energy)
data.append(smatrix.transmission(0, 1)) data.append(smatrix.transmission(0, 1))
...@@ -57,7 +56,7 @@ ...@@ -57,7 +56,7 @@
def main(): def main():
@@ -124,8 +143,11 @@ @@ -123,8 +142,11 @@
def family_colors(site): def family_colors(site):
return 0 if site.family == a else 1 return 0 if site.family == a else 1
...@@ -71,7 +70,7 @@ ...@@ -71,7 +70,7 @@
# Compute some eigenvalues. # Compute some eigenvalues.
compute_evs(sys.finalized()) compute_evs(sys.finalized())
@@ -134,9 +156,11 @@ @@ -133,9 +155,11 @@
for lead in leads: for lead in leads:
sys.attach_lead(lead) sys.attach_lead(lead)
......
...@@ -118,7 +118,7 @@ def main(): ...@@ -118,7 +118,7 @@ def main():
# We should see a conductance that is periodic with the flux quantum # 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 plot_conductance(sys, energy=0.15, fluxes=[0.01 * i * 3 * 2 * pi
for i in xrange(100)]) for i in range(100)])
# Call the main function if the script gets executed (as opposed to imported). # Call the main function if the script gets executed (as opposed to imported).
......
...@@ -24,7 +24,7 @@ def make_lead(a=1, t=1.0, W=10): ...@@ -24,7 +24,7 @@ def make_lead(a=1, t=1.0, W=10):
# build up one unit cell of the lead, and add the hoppings # build up one unit cell of the lead, and add the hoppings
# to the next unit cell # to the next unit cell
for j in xrange(W): for j in range(W):
lead[lat(0, j)] = 4 * t lead[lat(0, j)] = 4 * t
if j > 0: if j > 0:
......
...@@ -106,7 +106,7 @@ def main(): ...@@ -106,7 +106,7 @@ def main():
try: try:
# We should observe energy levels that flow towards Landau # We should observe energy levels that flow towards Landau
# level energies with increasing magnetic field. # level energies with increasing magnetic field.
plot_spectrum(sys, [iB * 0.002 for iB in xrange(100)]) plot_spectrum(sys, [iB * 0.002 for iB in range(100)])
# Plot an eigenmode of a circular dot. Here we create a larger system for # Plot an eigenmode of a circular dot. Here we create a larger system for
# better spatial resolution. # better spatial resolution.
...@@ -114,8 +114,8 @@ def main(): ...@@ -114,8 +114,8 @@ def main():
plot_wave_function(sys) plot_wave_function(sys)
except ValueError as e: except ValueError as e:
if e.message == "Input matrix is not real-valued.": if e.message == "Input matrix is not real-valued.":
print "The calculation of eigenvalues failed because of a bug in SciPy 0.9." print("The calculation of eigenvalues failed because of a bug in SciPy 0.9.")
print "Please upgrade to a newer version of SciPy." print("Please upgrade to a newer version of SciPy.")
else: else:
raise raise
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
# - Application of all the aspects of tutorials 1-3 to a more complicated # - Application of all the aspects of tutorials 1-3 to a more complicated
# lattice, namely graphene # lattice, namely graphene
from __future__ import division # so that 1/2 == 0.5, and not 0
from math import pi, sqrt, tanh from math import pi, sqrt, tanh
import kwant import kwant
...@@ -102,7 +101,7 @@ def compute_evs(sys): ...@@ -102,7 +101,7 @@ def compute_evs(sys):
sparse_mat = sys.hamiltonian_submatrix(sparse=True) sparse_mat = sys.hamiltonian_submatrix(sparse=True)
evs = sla.eigs(sparse_mat, 2)[0] evs = sla.eigs(sparse_mat, 2)[0]
print evs.real print(evs.real)
#HIDDEN_END_zydk #HIDDEN_END_zydk
...@@ -166,11 +165,11 @@ def main(): ...@@ -166,11 +165,11 @@ def main():
sys = sys.finalized() sys = sys.finalized()
# Compute the band structure of lead 0. # Compute the band structure of lead 0.
momenta = [-pi + 0.02 * pi * i for i in xrange(101)] momenta = [-pi + 0.02 * pi * i for i in range(101)]
plot_bandstructure(sys.leads[0], momenta) plot_bandstructure(sys.leads[0], momenta)
# Plot conductance. # Plot conductance.
energies = [-2 * pot + 4. / 50. * pot * i for i in xrange(51)] energies = [-2 * pot + 4. / 50. * pot * i for i in range(51)]
plot_conductance(sys, energies) plot_conductance(sys, energies)
......
...@@ -43,7 +43,7 @@ def make_system(a=1, t=1.0, W=10, L=30, L_well=10): ...@@ -43,7 +43,7 @@ def make_system(a=1, t=1.0, W=10, L=30, L_well=10):
#### Define and attach the leads. #### #### Define and attach the leads. ####
lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0))) lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0)))
lead[(lat(0, j) for j in xrange(W))] = 4 * t lead[(lat(0, j) for j in range(W))] = 4 * t
lead[lat.neighbors()] = -t lead[lat.neighbors()] = -t
sys.attach_lead(lead) sys.attach_lead(lead)
sys.attach_lead(lead.reversed()) sys.attach_lead(lead.reversed())
...@@ -79,7 +79,7 @@ def main(): ...@@ -79,7 +79,7 @@ def main():
# We should see conductance steps. # We should see conductance steps.
plot_conductance(sys, energy=0.2, plot_conductance(sys, energy=0.2,
welldepths=[0.01 * i for i in xrange(100)]) welldepths=[0.01 * i for i in range(100)])
# Call the main function if the script gets executed (as opposed to imported). # Call the main function if the script gets executed (as opposed to imported).
......
...@@ -35,8 +35,8 @@ L = 30 ...@@ -35,8 +35,8 @@ L = 30
# Define the scattering region # Define the scattering region
for i in xrange(L): for i in range(L):
for j in xrange(W): for j in range(W):
# On-site Hamiltonian # On-site Hamiltonian
sys[lat(i, j)] = 4 * t sys[lat(i, j)] = 4 * t
...@@ -59,7 +59,7 @@ left_lead = kwant.Builder(sym_left_lead) ...@@ -59,7 +59,7 @@ left_lead = kwant.Builder(sym_left_lead)
#HIDDEN_END_xcmc #HIDDEN_END_xcmc
#HIDDEN_BEGIN_ndez #HIDDEN_BEGIN_ndez
for j in xrange(W): for j in range(W):
left_lead[lat(0, j)] = 4 * t left_lead[lat(0, j)] = 4 * t
if j > 0: if j > 0:
left_lead[lat(0, j), lat(0, j - 1)] = -t left_lead[lat(0, j), lat(0, j - 1)] = -t
...@@ -75,7 +75,7 @@ sys.attach_lead(left_lead) ...@@ -75,7 +75,7 @@ sys.attach_lead(left_lead)
sym_right_lead = kwant.TranslationalSymmetry((a, 0)) sym_right_lead = kwant.TranslationalSymmetry((a, 0))
right_lead = kwant.Builder(sym_right_lead) right_lead = kwant.Builder(sym_right_lead)
for j in xrange(W): for j in range(W):
right_lead[lat(0, j)] = 4 * t right_lead[lat(0, j)] = 4 * t
if j > 0: if j > 0:
right_lead[lat(0, j), lat(0, j - 1)] = -t right_lead[lat(0, j), lat(0, j - 1)] = -t
...@@ -98,7 +98,7 @@ sys = sys.finalized() ...@@ -98,7 +98,7 @@ sys = sys.finalized()
#HIDDEN_BEGIN_buzn #HIDDEN_BEGIN_buzn
energies = [] energies = []
data = [] data = []
for ie in xrange(100): for ie in range(100):
energy = ie * 0.01 energy = ie * 0.01
# compute the scattering matrix at a given energy # compute the scattering matrix at a given energy
......
...@@ -39,7 +39,7 @@ def make_system(a=1, t=1.0, W=10, L=30): ...@@ -39,7 +39,7 @@ def make_system(a=1, t=1.0, W=10, L=30):
# Construct the left lead. # Construct the left lead.
#HIDDEN_BEGIN_iepx #HIDDEN_BEGIN_iepx
lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0))) lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0)))
lead[(lat(0, j) for j in xrange(W))] = 4 * t lead[(lat(0, j) for j in range(W))] = 4 * t
lead[lat.neighbors()] = -t lead[lat.neighbors()] = -t
#HIDDEN_END_iepx #HIDDEN_END_iepx
...@@ -79,7 +79,7 @@ def main(): ...@@ -79,7 +79,7 @@ def main():
sys = sys.finalized() sys = sys.finalized()
# We should see conductance steps. # We should see conductance steps.
plot_conductance(sys, energies=[0.01 * i for i in xrange(100)]) plot_conductance(sys, energies=[0.01 * i for i in range(100)])
#HIDDEN_END_cjel #HIDDEN_END_cjel
......
...@@ -55,7 +55,7 @@ def make_system(a=1, t=1.0, alpha=0.5, e_z=0.08, W=10, L=30): ...@@ -55,7 +55,7 @@ def make_system(a=1, t=1.0, alpha=0.5, e_z=0.08, W=10, L=30):
lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0))) lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0)))
#HIDDEN_BEGIN_yliu #HIDDEN_BEGIN_yliu
lead[(lat(0, j) for j in xrange(W))] = 4 * t * sigma_0 + e_z * sigma_z lead[(lat(0, j) for j in range(W))] = 4 * t * sigma_0 + e_z * sigma_z
# hoppings in x-direction # hoppings in x-direction
lead[kwant.builder.HoppingKind((1, 0), lat, lat)] = \ lead[kwant.builder.HoppingKind((1, 0), lat, lat)] = \
-t * sigma_0 - 1j * alpha * sigma_y -t * sigma_0 - 1j * alpha * sigma_y
...@@ -95,7 +95,7 @@ def main(): ...@@ -95,7 +95,7 @@ def main():
sys = sys.finalized() sys = sys.finalized()
# We should see non-monotonic conductance steps. # We should see non-monotonic conductance steps.
plot_conductance(sys, energies=[0.01 * i - 0.3 for i in xrange(100)]) plot_conductance(sys, energies=[0.01 * i - 0.3 for i in range(100)])
# Call the main function if the script gets executed (as opposed to imported). # Call the main function if the script gets executed (as opposed to imported).
......
...@@ -35,7 +35,7 @@ def make_lead(a=1, t=1.0, mu=0.7, Delta=0.1, W=10): ...@@ -35,7 +35,7 @@ def make_lead(a=1, t=1.0, mu=0.7, Delta=0.1, W=10):
# build up one unit cell of the lead, and add the hoppings # build up one unit cell of the lead, and add the hoppings
# to the next unit cell # to the next unit cell
for j in xrange(W): for j in range(W):
lead[lat(0, j)] = (4 * t - mu) * tau_z + Delta * tau_x lead[lat(0, j)] = (4 * t - mu) * tau_z + Delta * tau_x
if j > 0: if j > 0:
......
...@@ -55,12 +55,12 @@ def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4), ...@@ -55,12 +55,12 @@ def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4),
# left electron lead # left electron lead
lead0 = kwant.Builder(sym_left) lead0 = kwant.Builder(sym_left)
lead0[(lat_e(0, j) for j in xrange(W))] = 4 * t - mu lead0[(lat_e(0, j) for j in range(W))] = 4 * t - mu
lead0[lat_e.neighbors()] = -t lead0[lat_e.neighbors()] = -t
# left hole lead # left hole lead
lead1 = kwant.Builder(sym_left) lead1 = kwant.Builder(sym_left)
lead1[(lat_h(0, j) for j in xrange(W))] = mu - 4 * t lead1[(lat_h(0, j) for j in range(W))] = mu - 4 * t
lead1[lat_h.neighbors()] = t lead1[lat_h.neighbors()] = t
#HIDDEN_END_ttth #HIDDEN_END_ttth
...@@ -72,7 +72,7 @@ def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4), ...@@ -72,7 +72,7 @@ def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4),
lead2 = kwant.Builder(sym_right) lead2 = kwant.Builder(sym_right)
lead2 += lead0 lead2 += lead0
lead2 += lead1 lead2 += lead1
lead2[((lat_e(0, j), lat_h(0, j)) for j in xrange(W))] = Delta lead2[((lat_e(0, j), lat_h(0, j)) for j in range(W))] = Delta
#HIDDEN_END_mhiw #HIDDEN_END_mhiw
#### Attach the leads and return the system. #### #### Attach the leads and return the system. ####
...@@ -113,7 +113,7 @@ def main(): ...@@ -113,7 +113,7 @@ def main():
# Finalize the system. # Finalize the system.
sys = sys.finalized() sys = sys.finalized()
plot_conductance(sys, energies=[0.002 * i for i in xrange(100)]) plot_conductance(sys, energies=[0.002 * i for i in range(100)])
# Call the main function if the script gets executed (as opposed to imported). # Call the main function if the script gets executed (as opposed to imported).
......
from math import sqrt from math import sqrt
import scipy.sparse.linalg as sla import scipy.sparse.linalg as sla
import matplotlib.pyplot from matplotlib import pyplot
import kwant import kwant
sys = kwant.Builder() sys = kwant.Builder()
...@@ -9,11 +9,11 @@ lat = kwant.lattice.general([(1,0,0), (0,1,0), (0,0,1)]) ...@@ -9,11 +9,11 @@ lat = kwant.lattice.general([(1,0,0), (0,1,0), (0,0,1)])
t = 1.0 t = 1.0
R = 10 R = 10
sys[(lat(x,y,z) for x in xrange(-R-1, R+1) sys[(lat(x,y,z) for x in range(-R-1, R+1)
for y in xrange(-R-1, R+1) for z in xrange(R+1) for y in range(-R-1, R+1) for z in range(R+1)
if sqrt(x**2 + y**2 + z**2) < R + 0.01)] = 4 * t if sqrt(x**2 + y**2 + z**2) < R + 0.01)] = 4 * t
sys[(lat(x,y,z) for x in xrange(-2*R, 2*R + 1) sys[(lat(x,y,z) for x in range(-2*R, 2*R + 1)
for y in xrange(-R, R+1) for z in xrange(-R, 0))] = 4 * t for y in range(-R, R+1) for z in range(-R, 0))] = 4 * t
sys[lat.neighbors()] = -t sys[lat.neighbors()] = -t
sys = sys.finalized() sys = sys.finalized()
kwant.plot(sys) kwant.plot(sys)
......
"""An example of advanced system creation.""" """An example of advanced system creation."""
from __future__ import division
from math import tanh from math import tanh
from cmath import exp from cmath import exp
import tinyarray as ta import tinyarray as ta
...@@ -48,7 +47,7 @@ def make_system(R): ...@@ -48,7 +47,7 @@ def make_system(R):
def main(): def main():
sys = make_system(100) sys = make_system(100)
print kwant.smatrix(sys, 1.1, [0.1]).transmission(0, 1) print(kwant.smatrix(sys, 1.1, [0.1]).transmission(0, 1))
if __name__ == '__main__': if __name__ == '__main__':
......
"""The script generating Kwant logo. In addition to Kwant it also needs Python """The script generating Kwant logo. In addition to Kwant it also needs Python
image library (PIL).""" image library Pillow."""
import Image from PIL import Image, ImageFont, ImageDraw
import ImageFont
import ImageDraw
import matplotlib import matplotlib
import numpy as np import numpy as np
import scipy import scipy.misc
import kwant import kwant
def main(): def main():
...@@ -86,7 +84,7 @@ def main(): ...@@ -86,7 +84,7 @@ def main():
# result is not too empty or not too dark. # result is not too empty or not too dark.
out = np.zeros(textpos.shape) out = np.zeros(textpos.shape)
for i, rho in enumerate(ldos**.2): for i, rho in enumerate(ldos**.2):
x1, y1 = sys.site(i).tag x1, y1 = sys.sites[i].tag
out[x1, y1] = rho out[x1, y1] = rho
out = normalize_data(out) out = normalize_data(out)
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
kwant.Builder. kwant.Builder.
""" """
from __future__ import division
import numpy as np import numpy as np
from matplotlib import pyplot from matplotlib import pyplot
import kwant import kwant
...@@ -10,6 +9,7 @@ from kwant.physics.leads import square_selfenergy ...@@ -10,6 +9,7 @@ from kwant.physics.leads import square_selfenergy
__all__ = ['System'] __all__ = ['System']
class Lead(object): class Lead(object):
def __init__(self, width, t, potential): def __init__(self, width, t, potential):
self.width = width self.width = width
...@@ -20,6 +20,7 @@ class Lead(object): ...@@ -20,6 +20,7 @@ class Lead(object):
return square_selfenergy(self.width, self.t, return square_selfenergy(self.width, self.t,
self.potential + fermi_energy) self.potential + fermi_energy)
class System(kwant.system.FiniteSystem): class System(kwant.system.FiniteSystem):
def __init__(self, shape, hopping, def __init__(self, shape, hopping,
potential=0, lead_potentials=(0, 0), potential=0, lead_potentials=(0, 0),
...@@ -56,7 +57,7 @@ class System(kwant.system.FiniteSystem): ...@@ -56,7 +57,7 @@ class System(kwant.system.FiniteSystem):
edges[:shape[across], 1] += increment[along] edges[:shape[across], 1] += increment[along]
edges[shape[across]:, (0, 1)] = edges[:shape[across], (1, 0)] edges[shape[across]:, (0, 1)] = edges[:shape[across], (1, 0)]
g.add_edges(edges) g.add_edges(edges)
for i in xrange(shape[along] - 2): for i in range(shape[along] - 2):
edges += increment[along] edges += increment[along]
g.add_edges(edges) g.add_edges(edges)
self.graph = g.compressed() self.graph = g.compressed()
...@@ -66,7 +67,7 @@ class System(kwant.system.FiniteSystem): ...@@ -66,7 +67,7 @@ class System(kwant.system.FiniteSystem):
# We have to use list here, as numpy.array does not understand # We have to use list here, as numpy.array does not understand
# generators. # generators.
interface = list(self.nodeid_from_pos((x, y)) interface = list(self.nodeid_from_pos((x, y))
for y in xrange(shape[1])) for y in range(shape[1]))
self.lead_interfaces.append(np.array(interface)) self.lead_interfaces.append(np.array(interface))
self.leads = [Lead(shape[1], hopping, lead_potentials[i]) self.leads = [Lead(shape[1], hopping, lead_potentials[i])
...@@ -85,7 +86,7 @@ class System(kwant.system.FiniteSystem): ...@@ -85,7 +86,7 @@ class System(kwant.system.FiniteSystem):
return result return result
def nodeid_from_pos(self, pos): def nodeid_from_pos(self, pos):
for i in xrange(2): for i in range(2):
assert int(pos[i]) == pos[i] assert int(pos[i]) == pos[i]
assert pos[i] >= 0 and pos[i] < self.shape[i] assert pos[i] >= 0 and pos[i] < self.shape[i]
return pos[0] + pos[1] * self.shape[0] return pos[0] + pos[1] * self.shape[0]
...@@ -98,8 +99,8 @@ class System(kwant.system.FiniteSystem): ...@@ -98,8 +99,8 @@ class System(kwant.system.FiniteSystem):
def main(): def main():
sys = System((10, 5), 1) sys = System((10, 5), 1)
energies = [0.04 * i for i in xrange(100)] energies = [0.04 * i for i in range(100)]
data = [kwant.smatrix(sys, energy).transmission(1, 0) data = [kwant.greens_function(sys, energy).transmission(1, 0)
for energy in energies] for energy in energies]
pyplot.plot(energies, data) pyplot.plot(energies, data)
......