Commit 3fc6ff94 authored by Christoph Groth's avatar Christoph Groth
Browse files

simplify TranslationalSymmetry: it now takes 1d vectors as parameters directly

parent 8e7924e0
......@@ -9,7 +9,7 @@
# First, define the tight-binding system
@@ -73,8 +75,9 @@
@@ -72,8 +74,9 @@
sys.attach_lead(lead1)
# Plot it, to make sure it's OK
......@@ -21,7 +21,7 @@
# Finalize the system
@@ -98,8 +101,13 @@
@@ -97,8 +100,13 @@
# Use matplotlib to write output
# We should see conductance steps
......
......@@ -22,7 +22,7 @@
+ sys[lat.shape(ring, (0, 11))] = 4 * t
+ for hopping in lat.nearest:
+ sys[sys.possible_hoppings(*hopping)] = -t
+ sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
+ sym_lead0 = kwant.TranslationalSymmetry((-a, 0))
+ lead0 = kwant.Builder(sym_lead0)
+ def lead_shape(pos):
+ (x, y) = pos
......@@ -46,7 +46,7 @@
+ sys[lat.shape(ring, (0, 11))] = 4 * t
+ for hopping in lat.nearest:
+ sys[sys.possible_hoppings(*hopping)] = -t
+ sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
+ sym_lead0 = kwant.TranslationalSymmetry((-a, 0))
+ lead0 = kwant.Builder(sym_lead0)
+ def lead_shape(pos):
+ (x, y) = pos
......
......@@ -8,7 +8,7 @@
# global variable governing the behavior of potential() in
# make_system()
@@ -76,19 +77,25 @@
@@ -74,19 +75,25 @@
smatrix = kwant.solve(sys, energy)
data.append(smatrix.transmission(1, 0))
......
......@@ -8,7 +8,7 @@
def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4),
@@ -95,19 +96,23 @@
@@ -94,19 +95,23 @@
smatrix.transmission(0, 0) +
smatrix.transmission(1, 0))
......
......@@ -49,10 +49,9 @@ for i in xrange(L):
# First the lead to the left
# (Note: in the current version, TranslationalSymmetry takes a
# realspace vector)
# (Note: TranslationalSymmetry takes a real space vector)
#HIDDEN_BEGIN_xcmc
sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
sym_lead0 = kwant.TranslationalSymmetry((-a, 0))
lead0 = kwant.Builder(sym_lead0)
#HIDDEN_END_xcmc
......@@ -69,7 +68,7 @@ for j in xrange(W):
# Then the lead to the right
#HIDDEN_BEGIN_xhqc
sym_lead1 = kwant.TranslationalSymmetry([lat.vec((1, 0))])
sym_lead1 = kwant.TranslationalSymmetry((a, 0))
lead1 = kwant.Builder(sym_lead1)
for j in xrange(W):
......
......@@ -36,10 +36,9 @@ def make_system(a=1, t=1.0, W=10, L=30):
#### Define the leads. ####
# First the lead to the left, ...
# (Note: in the current version, TranslationalSymmetry takes a
# realspace vector)
# (Note: TranslationalSymmetry takes a real space vector)
#HIDDEN_BEGIN_iepx
sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
sym_lead0 = kwant.TranslationalSymmetry((-a, 0))
lead0 = kwant.Builder(sym_lead0)
lead0[(lat(0, j) for j in xrange(W))] = 4 * t
......
......@@ -67,7 +67,7 @@ def make_system(a=1, t=1.0, W=10, r1=10, r2=20):
#### Define the leads. ####
# left lead
#HIDDEN_BEGIN_qwgr
sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
sym_lead0 = kwant.TranslationalSymmetry((-a, 0))
lead0 = kwant.Builder(sym_lead0)
def lead_shape(pos):
......
......@@ -49,9 +49,7 @@ def make_system(a=1, t=1.0, W=10, L=30, L_well=10):
#### Define the leads. ####
# First the lead to the left, ...
# (Note: in the current version, TranslationalSymmetry takes a
# realspace vector)
sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
sym_lead0 = kwant.TranslationalSymmetry((-a, 0))
lead0 = kwant.Builder(sym_lead0)
lead0[(lat(0, j) for j in xrange(W))] = 4 * t
......
......@@ -50,7 +50,7 @@ def make_system(a=1, t=1.0, alpha=0.5, e_z=0.08, W=10, L=30):
#### Define the leads. ####
# left lead
sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
sym_lead0 = kwant.TranslationalSymmetry((-a, 0))
lead0 = kwant.Builder(sym_lead0)
#HIDDEN_BEGIN_yliu
......
......@@ -19,7 +19,7 @@ def make_lead(a=1, t=1.0, W=10):
# Start with an empty lead with a single square lattice
lat = kwant.lattice.Square(a)
sym_lead = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
sym_lead = kwant.TranslationalSymmetry((-a, 0))
lead = kwant.Builder(sym_lead)
# build up one unit cell of the lead, and add the hoppings
......
......@@ -67,7 +67,7 @@ def make_system(r=10, w=2.0, pot=0.1):
#### Define the leads. ####
#HIDDEN_BEGIN_aakh
# left lead
sym0 = kwant.TranslationalSymmetry([graphene.vec((-1, 0))])
sym0 = kwant.TranslationalSymmetry(graphene.vec((-1, 0)))
def lead0_shape(pos):
x, y = pos
......@@ -79,7 +79,7 @@ def make_system(r=10, w=2.0, pot=0.1):
lead0[lead0.possible_hoppings(*hopping)] = -1
# The second lead, going to the top right
sym1 = kwant.TranslationalSymmetry([graphene.vec((0, 1))])
sym1 = kwant.TranslationalSymmetry(graphene.vec((0, 1)))
def lead1_shape(pos):
x, y = pos
......@@ -140,7 +140,7 @@ def plot_bandstructure(flead, momenta):
pyplot.show()
#HIDDEN The part of the following code block which begins with plotter_symbols
#HIDDEN The part of the following code block which begins with group_colors
#HIDDEN is included verbatim in the tutorial text because nested code examples
#HIDDEN are not supported. Remember to update the tutorial text when you
#HIDDEN modify this block.
......
......@@ -26,7 +26,7 @@ def make_lead(a=1, t=1.0, mu=0.7, Delta=0.1, W=10):
# Start with an empty lead with a single square lattice
lat = kwant.lattice.Square(a)
sym_lead = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
sym_lead = kwant.TranslationalSymmetry((-a, 0))
lead = kwant.Builder(sym_lead)
# build up one unit cell of the lead, and add the hoppings
......
......@@ -49,19 +49,18 @@ def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4),
#### Define the leads. ####
#HIDDEN_BEGIN_ttth
# left electron lead
sym_lead0 = kwant.TranslationalSymmetry([lat_e.vec((-1, 0))])
lead0 = kwant.Builder(sym_lead0)
# Symmetry for the left leads.
sym_left = kwant.TranslationalSymmetry((-a, 0))
# left electron lead
lead0 = kwant.Builder(sym_left)
lead0[(lat_e(0, j) for j in xrange(W))] = 4 * t - mu
# hoppings in x and y-direction
lead0[lead0.possible_hoppings((1, 0), lat_e, lat_e)] = -t
lead0[lead0.possible_hoppings((0, 1), lat_e, lat_e)] = -t
# left hole lead
sym_lead1 = kwant.TranslationalSymmetry([lat_h.vec((-1, 0))])
lead1 = kwant.Builder(sym_lead1)
lead1 = kwant.Builder(sym_left)
lead1[(lat_h(0, j) for j in xrange(W))] = mu - 4 * t
# hoppings in x and y-direction
lead1[lead1.possible_hoppings((1, 0), lat_h, lat_h)] = t
......@@ -72,8 +71,8 @@ def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4),
# this one is superconducting and thus is comprised of electrons
# AND holes
#HIDDEN_BEGIN_mhiw
sym_lead2 = kwant.TranslationalSymmetry([lat_e.vec((1, 0))])
lead2 = kwant.Builder(sym_lead2)
sym_right = kwant.TranslationalSymmetry((a, 0))
lead2 = kwant.Builder(sym_right)
lead2[(lat_e(0, j) for j in xrange(W))] = 4 * t - mu
lead2[(lat_h(0, j) for j in xrange(W))] = mu - 4 * t
......
......@@ -66,12 +66,11 @@ system must have a translational symmetry:
:start-after: #HIDDEN_BEGIN_xcmc
:end-before: #HIDDEN_END_xcmc
Here, the `~kwant.builder.Builder` takes the translational symmetry
as an optional parameter. Note that the (real space)
vector ``lat.vec((-1, 0))`` defining the translational symmetry
must point in a direction *away* from the scattering region, *into*
the lead -- hence, lead 0 [#]_ will be the left lead, extending to
infinity to the left.
Here, the `~kwant.builder.Builder` takes a translational symmetry as the
optional parameter. Note that the (real space) vector ``(-a, 0)`` defining the
translational symmetry must point in a direction *away* from the scattering
region, *into* the lead -- hence, lead 0 [#]_ will be the left lead, extending
to infinity to the left.
For the lead itself it is enough to add the points of one unit cell as well
as the hoppings inside one unit cell and to the next unit cell of the lead.
......@@ -233,20 +232,11 @@ subbands that increases with energy.
del sys
sys = fsys
- Note that the vector passed to the `~kwant.lattice.TranslationalSymmetry`
(in fact, what is passed is a list of vectors -- there could be more than
on periodic direction. However, for a lead there is only one.) is
a realspace vector: ``lat.vec((1,0))``. Here, ``lat.vec``
converts the integer indices `(1,0)` into a realspace vector. In
this particular example, this is trivial (even more as ``a=1``),
but it is not so any more for more complicated lattices.
Even though the translational symmetry vector is specified in
realspace, it must be compatible with the lattice symmetries
(in principle, there could be more than one lattice). Hence,
it will be typically specified using ``lat.vec``, as this
is guaranteed to be a proper lattice vector, compatible
with the lattice symmetry.
- Even though the vector passed to the
`~kwant.lattice.TranslationalSymmetry` is specified in real space, it must
be compatible with the lattice symmetries. A single lead can consists of
sites belonging to more than one lattice, but of course the translational
symmetry of the lead has to be shared by all of them.
- Instead of plotting to the screen (which is standard)
`~kwant.plotter.plot` can also write to a file specified by the argument
......
......@@ -76,13 +76,19 @@ as add an additional link:
Note again that the conversion from a tuple `(i,j)` to site
is done by the sublattices `a` and `b`.
The leads are defined as before:
The leads are defined almost as before:
.. literalinclude:: 4-graphene.py
:start-after: #HIDDEN_BEGIN_aakh
:end-before: #HIDDEN_END_aakh
Note that the translational vectors ``graphene.vec((-1, 0))`` and
Note the method `~kwant.lattice.PolyatomicLattice.vec` used in calculating the
parameter for `~kwant.lattice.TranslationalSymmetry`. The latter expects a
real space symmetry vector, but for many lattices symmetry vectors are more
easily expressed in the natural coordinate system of the lattice. The ``vec``
method of lattices maps a lattice vector to a real space vector.
Observe also that the translational vectors ``graphene.vec((-1, 0))`` and
``graphene.vec((0, 1))`` are *not* orthogonal any more as they would have been
in a square lattice -- they follow the non-orthogonal primitive vectors defined
in the beginning.
......
......@@ -49,6 +49,22 @@ 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.
`~kwant.lattice.TranslationalSymmetry` is used differently
----------------------------------------------------------
When constructing an instance of `~kwant.lattice.TranslationalSymmetry` a sole
parameter used to be expected: A sequence of sequences of 1d real space
vectors. Now ``TranslationalSymmetry`` can take an arbitrary number of
parameters, each of them a 1d real space vector. This reduced the number of
parantheses necessary in the common case where there is just a single parameter
Example of old usage::
sym = kwant.TranslationalSymmetry([(-1, 0)])
New usage::
sym = kwant.TranslationalSymmetry((-1, 0))
Calculation of the local density of states
------------------------------------------
The new function of sparse solvers `~kwant.solvers.common.SparseSolver.ldos`
......
......@@ -611,6 +611,7 @@ class Builder(object):
hvhv = self.H.get(tail, ())
return len(hvhv) // 2 - 1
# TODO: write a test for this method.
def reversed(self):
"""Return a shallow copy of the builder with the symmetry reversed.
......
......@@ -29,7 +29,7 @@ def test_rectangle():
for l in [1, 2, 5, 10]:
sys = kwant.Builder()
lead = kwant.Builder(kwant.TranslationalSymmetry([(-1, 0)]))
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0)))
lat = kwant.lattice.Square()
lead[(lat(0, i) for i in xrange(w))] = 0
sys[(lat(j, i) for j in xrange(l) for i in xrange(w))] = 0
......
......@@ -213,8 +213,8 @@ class TranslationalSymmetry(builder.Symmetry):
Parameters
----------
periods : list of lists of real-valued variables
list of symmetry periods in real space.
p0, p1, p2, ... : sequences of real numbers
The symmetry periods in real space.
Notes
-----
......@@ -228,8 +228,14 @@ class TranslationalSymmetry(builder.Symmetry):
The fundamental domain for hoppings are all hoppings ``(a, b)`` with site
`a` in fundamental domain of sites.
"""
def __init__(self, periods):
def __init__(self, *periods):
self.periods = ta.array(periods)
if self.periods.ndim != 2:
# TODO: remove the second part of the following message once
# everybody got used to it.
msg = "TranslationalSymmetry takes 1d sequences as parameters.\n" \
"See What's new in kwant 0.2 in the documentation."
raise ValueError(msg)
# A dictionary containing cached data required for applying the
# symmetry to different site groups.
self.site_group_data = {}
......@@ -342,7 +348,7 @@ class TranslationalSymmetry(builder.Symmetry):
domain.
"""
periods = [[-i for i in j] for j in self.periods]
result = TranslationalSymmetry(periods)
result = TranslationalSymmetry(*periods)
for gr in self.site_group_data:
det_x_inv_m_part, m_part, det_m = self.site_group_data[gr]
if self.num_directions % 2:
......
......@@ -10,7 +10,7 @@ chain = kwant.lattice.Chain()
def _twoterminal_system():
np.random.seed(11)
system = kwant.Builder()
lead = kwant.Builder(kwant.TranslationalSymmetry([(1,)]))
lead = kwant.Builder(kwant.TranslationalSymmetry((1,)))
h = np.random.rand(n, n) + 1j * np.random.rand(n, n)
h += h.conjugate().transpose()
h *= 0.8
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment