From 3fc6ff94d027ae1b50c068af37c56d55a45799b7 Mon Sep 17 00:00:00 2001 From: Christoph Groth <christoph.groth@cea.fr> Date: Sat, 17 Nov 2012 23:05:09 +0100 Subject: [PATCH] simplify TranslationalSymmetry: it now takes 1d vectors as parameters directly --- doc/source/images/1-quantum_wire.py.diff | 4 +-- doc/source/images/2-ab_ring.py.diff | 4 +-- doc/source/images/2-quantum_well.py.diff | 2 +- .../images/5-superconductor_transport.py.diff | 2 +- doc/source/tutorial/1-quantum_wire.py | 7 ++--- .../tutorial/1-quantum_wire_revisited.py | 5 ++-- doc/source/tutorial/2-ab_ring.py | 2 +- doc/source/tutorial/2-quantum_well.py | 4 +-- doc/source/tutorial/2-spin_orbit.py | 2 +- doc/source/tutorial/3-band_structure.py | 2 +- doc/source/tutorial/4-graphene.py | 6 ++-- .../5-superconductor_band_structure.py | 2 +- .../tutorial/5-superconductor_transport.py | 15 +++++----- doc/source/tutorial/tutorial1.rst | 30 +++++++------------ doc/source/tutorial/tutorial4.rst | 10 +++++-- doc/source/whatsnew/0.2.rst | 16 ++++++++++ kwant/builder.py | 1 + kwant/graph/tests/test_slicer.py | 2 +- kwant/lattice.py | 14 ++++++--- kwant/physics/tests/test_noise.py | 2 +- kwant/solvers/tests/_test_sparse.py | 30 +++++++++---------- kwant/tests/test_builder.py | 4 +-- kwant/tests/test_lattice.py | 20 ++++++------- kwant/tests/test_plotter.py | 4 +-- kwant/tests/test_system.py | 2 +- 25 files changed, 103 insertions(+), 89 deletions(-) diff --git a/doc/source/images/1-quantum_wire.py.diff b/doc/source/images/1-quantum_wire.py.diff index 30d2dc99..1e90308d 100644 --- a/doc/source/images/1-quantum_wire.py.diff +++ b/doc/source/images/1-quantum_wire.py.diff @@ -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 diff --git a/doc/source/images/2-ab_ring.py.diff b/doc/source/images/2-ab_ring.py.diff index 1075a5ce..c9b1c697 100644 --- a/doc/source/images/2-ab_ring.py.diff +++ b/doc/source/images/2-ab_ring.py.diff @@ -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 diff --git a/doc/source/images/2-quantum_well.py.diff b/doc/source/images/2-quantum_well.py.diff index 579ba294..af25ac0d 100644 --- a/doc/source/images/2-quantum_well.py.diff +++ b/doc/source/images/2-quantum_well.py.diff @@ -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)) diff --git a/doc/source/images/5-superconductor_transport.py.diff b/doc/source/images/5-superconductor_transport.py.diff index 8f6d6d9d..66fd4b7f 100644 --- a/doc/source/images/5-superconductor_transport.py.diff +++ b/doc/source/images/5-superconductor_transport.py.diff @@ -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)) diff --git a/doc/source/tutorial/1-quantum_wire.py b/doc/source/tutorial/1-quantum_wire.py index 670f99a5..62a7e050 100644 --- a/doc/source/tutorial/1-quantum_wire.py +++ b/doc/source/tutorial/1-quantum_wire.py @@ -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): diff --git a/doc/source/tutorial/1-quantum_wire_revisited.py b/doc/source/tutorial/1-quantum_wire_revisited.py index f673dc7f..0290ed62 100644 --- a/doc/source/tutorial/1-quantum_wire_revisited.py +++ b/doc/source/tutorial/1-quantum_wire_revisited.py @@ -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 diff --git a/doc/source/tutorial/2-ab_ring.py b/doc/source/tutorial/2-ab_ring.py index 52c08259..3abe11df 100644 --- a/doc/source/tutorial/2-ab_ring.py +++ b/doc/source/tutorial/2-ab_ring.py @@ -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): diff --git a/doc/source/tutorial/2-quantum_well.py b/doc/source/tutorial/2-quantum_well.py index 38b100eb..21960659 100644 --- a/doc/source/tutorial/2-quantum_well.py +++ b/doc/source/tutorial/2-quantum_well.py @@ -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 diff --git a/doc/source/tutorial/2-spin_orbit.py b/doc/source/tutorial/2-spin_orbit.py index 8d42f1d8..18c22593 100644 --- a/doc/source/tutorial/2-spin_orbit.py +++ b/doc/source/tutorial/2-spin_orbit.py @@ -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 diff --git a/doc/source/tutorial/3-band_structure.py b/doc/source/tutorial/3-band_structure.py index 3b8fe8e0..ac26fb51 100644 --- a/doc/source/tutorial/3-band_structure.py +++ b/doc/source/tutorial/3-band_structure.py @@ -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 diff --git a/doc/source/tutorial/4-graphene.py b/doc/source/tutorial/4-graphene.py index 147fd890..38d655cd 100644 --- a/doc/source/tutorial/4-graphene.py +++ b/doc/source/tutorial/4-graphene.py @@ -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. diff --git a/doc/source/tutorial/5-superconductor_band_structure.py b/doc/source/tutorial/5-superconductor_band_structure.py index 79badae5..db1c9985 100644 --- a/doc/source/tutorial/5-superconductor_band_structure.py +++ b/doc/source/tutorial/5-superconductor_band_structure.py @@ -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 diff --git a/doc/source/tutorial/5-superconductor_transport.py b/doc/source/tutorial/5-superconductor_transport.py index 1e0e3bb3..1ba94510 100644 --- a/doc/source/tutorial/5-superconductor_transport.py +++ b/doc/source/tutorial/5-superconductor_transport.py @@ -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 diff --git a/doc/source/tutorial/tutorial1.rst b/doc/source/tutorial/tutorial1.rst index 0c1c98f2..2e3f02c7 100644 --- a/doc/source/tutorial/tutorial1.rst +++ b/doc/source/tutorial/tutorial1.rst @@ -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 diff --git a/doc/source/tutorial/tutorial4.rst b/doc/source/tutorial/tutorial4.rst index 354d87f6..fa6a7eb6 100644 --- a/doc/source/tutorial/tutorial4.rst +++ b/doc/source/tutorial/tutorial4.rst @@ -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. diff --git a/doc/source/whatsnew/0.2.rst b/doc/source/whatsnew/0.2.rst index 2fc2710d..aaf904fc 100644 --- a/doc/source/whatsnew/0.2.rst +++ b/doc/source/whatsnew/0.2.rst @@ -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` diff --git a/kwant/builder.py b/kwant/builder.py index cbe061b8..2b674f57 100644 --- a/kwant/builder.py +++ b/kwant/builder.py @@ -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. diff --git a/kwant/graph/tests/test_slicer.py b/kwant/graph/tests/test_slicer.py index e9ba6c76..3b0850de 100644 --- a/kwant/graph/tests/test_slicer.py +++ b/kwant/graph/tests/test_slicer.py @@ -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 diff --git a/kwant/lattice.py b/kwant/lattice.py index 070cf003..d8198efb 100644 --- a/kwant/lattice.py +++ b/kwant/lattice.py @@ -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: diff --git a/kwant/physics/tests/test_noise.py b/kwant/physics/tests/test_noise.py index 11ccea1e..d5109201 100644 --- a/kwant/physics/tests/test_noise.py +++ b/kwant/physics/tests/test_noise.py @@ -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 diff --git a/kwant/solvers/tests/_test_sparse.py b/kwant/solvers/tests/_test_sparse.py index d95eb21c..1b595dbf 100644 --- a/kwant/solvers/tests/_test_sparse.py +++ b/kwant/solvers/tests/_test_sparse.py @@ -14,8 +14,8 @@ square = kwant.lattice.Square() def test_output(solve): np.random.seed(3) system = kwant.Builder() - left_lead = kwant.Builder(kwant.TranslationalSymmetry([(-1,)])) - right_lead = kwant.Builder(kwant.TranslationalSymmetry([(1,)])) + left_lead = kwant.Builder(kwant.TranslationalSymmetry((-1,))) + right_lead = kwant.Builder(kwant.TranslationalSymmetry((1,))) for b, site in [(system, chain(0)), (system, chain(1)), (left_lead, chain(0)), (right_lead, chain(0))]: h = np.random.rand(n, n) + 1j * np.random.rand(n, n) @@ -54,7 +54,7 @@ def test_output(solve): def test_one_lead(solve): np.random.seed(3) system = kwant.Builder() - lead = kwant.Builder(kwant.TranslationalSymmetry([(-1,)])) + lead = kwant.Builder(kwant.TranslationalSymmetry((-1,))) for b, site in [(system, chain(0)), (system, chain(1)), (system, chain(2)), (lead, chain(0))]: h = np.random.rand(n, n) + 1j * np.random.rand(n, n) @@ -76,8 +76,8 @@ def test_one_lead(solve): # 0x0 S-matrix. def test_smatrix_shape(solve): system = kwant.Builder() - lead0 = kwant.Builder(kwant.TranslationalSymmetry([(-1,)])) - lead1 = kwant.Builder(kwant.TranslationalSymmetry([(1,)])) + lead0 = kwant.Builder(kwant.TranslationalSymmetry((-1,))) + lead1 = kwant.Builder(kwant.TranslationalSymmetry((1,))) for b, site in [(system, chain(0)), (system, chain(1)), (system, chain(2))]: b[site] = 2 @@ -131,7 +131,7 @@ def test_two_equal_leads(solve): assert_almost_equal(sol.transmission(1,0), n_modes) 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 @@ -157,7 +157,7 @@ def test_two_equal_leads(solve): def test_graph_system(solve): np.random.seed(11) system = kwant.Builder() - lead = kwant.Builder(kwant.TranslationalSymmetry([(-1, 0)])) + lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0))) lead.default_site_group = system.default_site_group = square h = np.random.rand(n, n) + 1j * np.random.rand(n, n) @@ -192,7 +192,7 @@ def test_singular_graph_system(solve): np.random.seed(11) system = kwant.Builder() - lead = kwant.Builder(kwant.TranslationalSymmetry([(-1, 0)])) + lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0))) lead.default_site_group = system.default_site_group = square h = np.random.rand(n, n) + 1j * np.random.rand(n, n) h += h.conjugate().transpose() @@ -226,7 +226,7 @@ def test_singular_graph_system(solve): def test_tricky_singular_hopping(solve): system = kwant.Builder() - lead = kwant.Builder(kwant.TranslationalSymmetry([(4, 0)])) + lead = kwant.Builder(kwant.TranslationalSymmetry((4, 0))) lead.default_site_group = system.default_site_group = square interface = [] @@ -266,8 +266,8 @@ def test_self_energy(solve): np.random.seed(4) system = kwant.Builder() - left_lead = kwant.Builder(kwant.TranslationalSymmetry([(-1,)])) - right_lead = kwant.Builder(kwant.TranslationalSymmetry([(1,)])) + left_lead = kwant.Builder(kwant.TranslationalSymmetry((-1,))) + right_lead = kwant.Builder(kwant.TranslationalSymmetry((1,))) for b, site in [(system, chain(0)), (system, chain(1)), (left_lead, chain(0)), (right_lead, chain(0))]: h = np.random.rand(n, n) + 1j * np.random.rand(n, n) @@ -315,7 +315,7 @@ def test_self_energy_reflection(solve): np.random.seed(4) system = kwant.Builder() - left_lead = kwant.Builder(kwant.TranslationalSymmetry([(-1,)])) + left_lead = kwant.Builder(kwant.TranslationalSymmetry((-1,))) for b, site in [(system, chain(0)), (system, chain(1)), (left_lead, chain(0))]: h = np.random.rand(n, n) + 1j * np.random.rand(n, n) @@ -337,8 +337,8 @@ def test_self_energy_reflection(solve): def test_very_singular_leads(solve): sys = kwant.Builder() gr = kwant.lattice.Chain() - left_lead = kwant.Builder(kwant.TranslationalSymmetry([(-1,)])) - right_lead = kwant.Builder(kwant.TranslationalSymmetry([(1,)])) + left_lead = kwant.Builder(kwant.TranslationalSymmetry((-1,))) + right_lead = kwant.Builder(kwant.TranslationalSymmetry((1,))) sys.default_site_group = gr left_lead.default_site_group = right_lead.default_site_group = gr sys[(0,)] = left_lead[(0,)] = right_lead[(0,)] = np.identity(2) @@ -353,7 +353,7 @@ def test_very_singular_leads(solve): def test_ldos(ldos): sys = kwant.Builder() gr = kwant.lattice.Chain() - lead = kwant.Builder(kwant.TranslationalSymmetry((gr.vec((1,)),))) + lead = kwant.Builder(kwant.TranslationalSymmetry(gr.vec((1,)))) sys.default_site_group = lead.default_site_group = gr sys[(0,)] = sys[(1,)] = lead[(0,)] = 0 sys[(0,), (1,)] = lead[(0,), (1,)] = 1 diff --git a/kwant/tests/test_builder.py b/kwant/tests/test_builder.py index 434a670d..e3ff2bc1 100644 --- a/kwant/tests/test_builder.py +++ b/kwant/tests/test_builder.py @@ -266,7 +266,7 @@ def test_finalization(): check_hoppings(fsys, sr_hops) # Build lead from blueprint and test it. - lead = builder.Builder(kwant.TranslationalSymmetry([(size, 0)])) + lead = builder.Builder(kwant.TranslationalSymmetry((size, 0))) lead.default_site_group = sg for site, value in lead_sites.iteritems(): shift = rng.randrange(-5, 6) * size @@ -367,7 +367,7 @@ def test_dangling(): def test_builder_with_symmetry(): g = kwant.make_lattice(ta.identity(3)) - sym = kwant.TranslationalSymmetry([(0, 0, 3), (0, 2, 0)]) + sym = kwant.TranslationalSymmetry((0, 0, 3), (0, 2, 0)) bob = builder.Builder(sym) bob.default_site_group = g diff --git a/kwant/tests/test_lattice.py b/kwant/tests/test_lattice.py index b42a902e..9c8a5495 100644 --- a/kwant/tests/test_lattice.py +++ b/kwant/tests/test_lattice.py @@ -41,31 +41,31 @@ def test_translational_symmetry(): g2 = lattice.make_lattice(np.identity(2)) g3 = lattice.make_lattice(np.identity(3)) - sym = ts([(0, 0, 4), (0, 5, 0), (0, 0, 2)]) + sym = ts((0, 0, 4), (0, 5, 0), (0, 0, 2)) assert_raises(ValueError, sym.add_site_group, g3) - sym = ts([(3.3, 0)]) + sym = ts((3.3, 0)) assert_raises(ValueError, sym.add_site_group, g2) # Test lattices with dimension smaller than dimension of space. g2in3 = lattice.make_lattice([[4, 4, 0], [4, -4, 0]]) - sym = ts([(8, 0, 0)]) + sym = ts((8, 0, 0)) sym.add_site_group(g2in3) - sym = ts([(8, 0, 1)]) + sym = ts((8, 0, 1)) assert_raises(ValueError, sym.add_site_group, g2in3) # Test automatic fill-in of transverse vectors. - sym = ts([(1, 2)]) + sym = ts((1, 2)) sym.add_site_group(g2) assert_not_equal(sym.site_group_data[g2][2], 0) - sym = ts([(1, 0, 2), (3, 0, 2)]) + sym = ts((1, 0, 2), (3, 0, 2)) sym.add_site_group(g3) assert_not_equal(sym.site_group_data[g3][2], 0) transl_vecs = np.array([[10, 0], [7, 7]], dtype=int) - sym = ts(transl_vecs) + sym = ts(*transl_vecs) assert_equal(sym.num_directions, 2) - sym2 = ts(transl_vecs[: 1, :]) + sym2 = ts(*transl_vecs[: 1, :]) sym2.add_site_group(g2, transl_vecs[1:, :]) for site in [g2(0, 0), g2(4, 0), g2(2, 1), g2(5, 5), g2(15, 6)]: assert sym.in_fd(site) @@ -103,12 +103,12 @@ def test_translational_symmetry_reversed(): ([(3, 1, 1), (1, 4, 1)], [(1, 1, 5)]), ([(3, 1, 1)], [(1, 4, 1), (1, 1, 5)])] for periods, other_vectors in params: - sym = lattice.TranslationalSymmetry(periods) + sym = lattice.TranslationalSymmetry(*periods) gr = lattice.make_lattice(np.identity(len(periods[0]))) sym.add_site_group(gr, other_vectors) rsym = sym.reversed() assert_equal_symmetry(sym, rsym.reversed()) rperiods = -np.array(periods, dtype=int) - rsym2 = lattice.TranslationalSymmetry(rperiods) + rsym2 = lattice.TranslationalSymmetry(*rperiods) rsym2.add_site_group(gr, other_vectors) assert_equal_symmetry(rsym, rsym2) diff --git a/kwant/tests/test_plotter.py b/kwant/tests/test_plotter.py index 61fffe20..2e7f5ebb 100644 --- a/kwant/tests/test_plotter.py +++ b/kwant/tests/test_plotter.py @@ -21,7 +21,7 @@ def sys_2d(W=3, r1=3, r2=8): sys[lat.shape(ring, (0, r1 + 1))] = 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(lat.vec((-1, 0))) lead0 = kwant.Builder(sym_lead0) def lead_shape(pos): @@ -50,7 +50,7 @@ def sys_3d(W=3, r1=2, r2=4, a=1, t=1.0): sys[lat.shape(ring, (0, -r2 + 1, 0))] = 4 * t for hopping in lat.nearest: sys[sys.possible_hoppings(*hopping)] = - t - sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0, 0))]) + sym_lead0 = kwant.TranslationalSymmetry(lat.vec((-1, 0, 0))) lead0 = kwant.Builder(sym_lead0) def lead_shape(pos): diff --git a/kwant/tests/test_system.py b/kwant/tests/test_system.py index eea7869a..4fc133e5 100644 --- a/kwant/tests/test_system.py +++ b/kwant/tests/test_system.py @@ -60,7 +60,7 @@ def test_hamiltonian_submatrix(): assert_raises(ValueError, sys2.hamiltonian_submatrix, None, None, True) def test_energies(): - sys = kwant.Builder(kwant.TranslationalSymmetry([(-1, 0)])) + sys = kwant.Builder(kwant.TranslationalSymmetry((-1, 0))) sys.default_site_group = kwant.lattice.Square() sys[[(0, 0), (0, 1)]] = complex(0) sys[[((0, 0), (0, 1)), -- GitLab