diff --git a/examples/3d_plot.py b/examples/3d_plot.py index 8dcef1f40ca45a341d16afb8a208a9ed523e311a..ed8bccfeaa5bd7ea03cc6236f08a834a0c835f04 100644 --- a/examples/3d_plot.py +++ b/examples/3d_plot.py @@ -1,6 +1,6 @@ from math import sqrt import scipy.sparse.linalg as sla -import matplotlib.pyplot +from matplotlib import pyplot import kwant sys = kwant.Builder() @@ -9,11 +9,11 @@ lat = kwant.lattice.general([(1,0,0), (0,1,0), (0,0,1)]) t = 1.0 R = 10 -sys[(lat(x,y,z) for x in xrange(-R-1, R+1) - for y in xrange(-R-1, R+1) for z in xrange(R+1) +sys[(lat(x,y,z) for x in range(-R-1, 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 -sys[(lat(x,y,z) for x in xrange(-2*R, 2*R + 1) - for y in xrange(-R, R+1) for z in xrange(-R, 0))] = 4 * t +sys[(lat(x,y,z) for x in range(-2*R, 2*R + 1) + for y in range(-R, R+1) for z in range(-R, 0))] = 4 * t sys[lat.neighbors()] = -t sys = sys.finalized() kwant.plot(sys) diff --git a/examples/advanced_construction.py b/examples/advanced_construction.py index dcfcfa92e6291fc577cd529732310b26d7b79c00..1d4806bacbd0eb268e0f9c7524a84b91cf98c0a1 100644 --- a/examples/advanced_construction.py +++ b/examples/advanced_construction.py @@ -1,6 +1,5 @@ """An example of advanced system creation.""" -from __future__ import division from math import tanh from cmath import exp import tinyarray as ta @@ -48,7 +47,7 @@ def make_system(R): def main(): 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__': diff --git a/examples/logo.py b/examples/logo.py index c3dcb1f6e59cef8b4e7427895891767f2fb56043..941c613c8c803205d139a91bb24fd6826f960e0b 100644 --- a/examples/logo.py +++ b/examples/logo.py @@ -1,12 +1,10 @@ """The script generating Kwant logo. In addition to Kwant it also needs Python -image library (PIL).""" +image library Pillow.""" -import Image -import ImageFont -import ImageDraw +from PIL import Image, ImageFont, ImageDraw import matplotlib import numpy as np -import scipy +import scipy.misc import kwant def main(): @@ -86,7 +84,7 @@ def main(): # result is not too empty or not too dark. out = np.zeros(textpos.shape) for i, rho in enumerate(ldos**.2): - x1, y1 = sys.site(i).tag + x1, y1 = sys.sites[i].tag out[x1, y1] = rho out = normalize_data(out) diff --git a/examples/square.py b/examples/square.py index c7df5d54200b247cb7584db9a7e0a9699ebf2f58..c61089cdb56c0f1f7472e4a22896befc2b37bf4b 100644 --- a/examples/square.py +++ b/examples/square.py @@ -2,7 +2,6 @@ kwant.Builder. """ -from __future__ import division import numpy as np from matplotlib import pyplot import kwant @@ -20,6 +19,7 @@ class Lead(object): return square_selfenergy(self.width, self.t, self.potential + fermi_energy) + class System(kwant.system.FiniteSystem): def __init__(self, shape, hopping, potential=0, lead_potentials=(0, 0), @@ -56,7 +56,7 @@ class System(kwant.system.FiniteSystem): edges[:shape[across], 1] += increment[along] edges[shape[across]:, (0, 1)] = edges[:shape[across], (1, 0)] g.add_edges(edges) - for i in xrange(shape[along] - 2): + for i in range(shape[along] - 2): edges += increment[along] g.add_edges(edges) self.graph = g.compressed() @@ -66,7 +66,7 @@ class System(kwant.system.FiniteSystem): # We have to use list here, as numpy.array does not understand # generators. 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.leads = [Lead(shape[1], hopping, lead_potentials[i]) @@ -85,7 +85,7 @@ class System(kwant.system.FiniteSystem): return result def nodeid_from_pos(self, pos): - for i in xrange(2): + for i in range(2): assert int(pos[i]) == pos[i] assert pos[i] >= 0 and pos[i] < self.shape[i] return pos[0] + pos[1] * self.shape[0] @@ -98,8 +98,8 @@ class System(kwant.system.FiniteSystem): def main(): sys = System((10, 5), 1) - energies = [0.04 * i for i in xrange(100)] - data = [kwant.smatrix(sys, energy).transmission(1, 0) + energies = [0.04 * i for i in range(100)] + data = [kwant.greens_function(sys, energy).transmission(1, 0) for energy in energies] pyplot.plot(energies, data) diff --git a/examples/tests/test_square.py b/examples/tests/test_square.py index 4d605368caa4f43660fbd27ea94587aecf09ef3f..f8654c98a50288f49d55a6b079029a959090d5aa 100644 --- a/examples/tests/test_square.py +++ b/examples/tests/test_square.py @@ -4,18 +4,18 @@ from numpy.testing import assert_almost_equal def test_nodeid_to_from_pos(): s = square.System((3, 4), 1) - assert_raises(StandardError, s.nodeid_from_pos, (0, -2)) - assert_raises(StandardError, s.nodeid_from_pos, (-1, 3)) - assert_raises(StandardError, s.nodeid_from_pos, (3, 1)) - assert_raises(StandardError, s.pos_from_nodeid, -1) - assert_raises(StandardError, s.pos_from_nodeid, 12) + assert_raises(Exception, s.nodeid_from_pos, (0, -2)) + assert_raises(Exception, s.nodeid_from_pos, (-1, 3)) + assert_raises(Exception, s.nodeid_from_pos, (3, 1)) + assert_raises(Exception, s.pos_from_nodeid, -1) + assert_raises(Exception, s.pos_from_nodeid, 12) assert_equal(s.nodeid_from_pos((0, 0)), 0) assert_equal(s.nodeid_from_pos(s.pos_from_nodeid(7)), 7) assert_equal(s.pos_from_nodeid(s.nodeid_from_pos((2, 3))), (2, 3)) def test_hamiltonian(): sys = square.System((4, 5), 1) - for i in xrange(sys.graph.num_nodes): + for i in range(sys.graph.num_nodes): shape = sys.hamiltonian(i, i).shape assert_equal(len(shape), 2) assert_equal(shape[0], 1) @@ -28,7 +28,7 @@ def test_hamiltonian(): def test_selfenergy(): sys = square.System((2, 4), 1) - for lead in xrange(len(sys.lead_interfaces)): + for lead in range(len(sys.lead_interfaces)): se = sys.leads[lead].selfenergy(0) assert_equal(len(se.shape), 2) assert_equal(se.shape[0], se.shape[1])