Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pablo Piskunow
kwant
Commits
714daa26
Commit
714daa26
authored
Aug 08, 2015
by
Anton Akhmerov
Committed by
Joseph Weston
Nov 05, 2015
Browse files
update examples to py3
parent
fe7f875d
Changes
5
Hide whitespace changes
Inline
Side-by-side
examples/3d_plot.py
View file @
714daa26
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
x
range
(
-
R
-
1
,
R
+
1
)
for
y
in
x
range
(
-
R
-
1
,
R
+
1
)
for
z
in
x
range
(
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
x
range
(
-
2
*
R
,
2
*
R
+
1
)
for
y
in
x
range
(
-
R
,
R
+
1
)
for
z
in
x
range
(
-
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
)
...
...
examples/advanced_construction.py
View file @
714daa26
"""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__'
:
...
...
examples/logo.py
View file @
714daa26
"""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
.
site
s
[
i
]
.
tag
out
[
x1
,
y1
]
=
rho
out
=
normalize_data
(
out
)
...
...
examples/square.py
View file @
714daa26
...
...
@@ -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
x
range
(
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
x
range
(
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
x
range
(
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
x
range
(
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
)
...
...
examples/tests/test_square.py
View file @
714daa26
...
...
@@ -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
x
range
(
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
x
range
(
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
])
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment