diff --git a/kwant/builder.py b/kwant/builder.py index 2c2d620fd374327fcaa51671b0c4e2a34334daa6..588af41b53f25a06b57802740a4de545a58fe89d 100644 --- a/kwant/builder.py +++ b/kwant/builder.py @@ -74,33 +74,6 @@ class Site(tuple): raise t(msg.format(repr(tag), repr(group), v)) return tuple.__new__(cls, (group, tag)) - def shifted(self, delta, group=None): - """Return a copy of the site, displaced by delta. - - Parameters - ---------- - delta : sequence of integers - The vector by which to displace the site. - group : `SiteGroup` - Site group of the returned site. If no site group is provided, the - original one is kept. - - Returns - ------- - new_site : `Site` - A site shifted by `delta` with site group optionally set to - `group`. - - Notes - ----- - This method *works* only if the site for which it is called has a tag - which is a sequences of integers. It *makes sense* only when this - sites lives on a regular lattice, like one provided by `kwant.lattice`. - """ - if group is None: - group = self.group - return Site(group, ta.add(self.tag, delta)) - def __repr__(self): return 'Site({0}, {1})'.format(repr(self.group), repr(self.tag)) diff --git a/kwant/tests/test_builder.py b/kwant/tests/test_builder.py index 27b4454e9ec2cbf4bb3d0b1d375040790a0fafd3..fb1ce2675d8479c1f370174f42f38c8e9d8eb930 100644 --- a/kwant/tests/test_builder.py +++ b/kwant/tests/test_builder.py @@ -32,8 +32,6 @@ def test_site_groups(): assert_equal(sys[sg(1)], 123) assert_raises(KeyError, sys.__getitem__, osg(1)) - assert_equal(sg(-5).shifted((-2,), osg), osg(-7)) - class VerySimpleSymmetry(builder.Symmetry): def __init__(self, period): @@ -47,11 +45,12 @@ class VerySimpleSymmetry(builder.Symmetry): return ta.array((site.tag[0] // self.period,), int) def act(self, element, a, b=None): + shifted = lambda site, delta: site.group(*ta.add(site.tag, delta)) delta = (self.period * element[0],) + (len(a.tag) - 1) * (0,) if b is None: - return a.shifted(delta) + return shifted(a, delta) else: - return a.shifted(delta), b.shifted(delta) + return shifted(a, delta), shifted(b, delta) # The hoppings have to form a ring. Some other implicit assumptions are also diff --git a/kwant/tests/test_lattice.py b/kwant/tests/test_lattice.py index ac687907eada251c525329dc595fb7217c9edfc4..f3cce0ba19a566f3c4173e47e168ffd7d2f807cf 100644 --- a/kwant/tests/test_lattice.py +++ b/kwant/tests/test_lattice.py @@ -9,9 +9,10 @@ from __future__ import division from math import sqrt import numpy as np +import tinyarray as ta from nose.tools import assert_raises, assert_not_equal from numpy.testing import assert_equal -from kwant import lattice, builder +from kwant import lattice def test_make_lattice(): @@ -48,6 +49,7 @@ def test_translational_symmetry(): ts = lattice.TranslationalSymmetry g2 = lattice.make_lattice(np.identity(2)) g3 = lattice.make_lattice(np.identity(3)) + shifted = lambda site, delta: site.group(*ta.add(site.tag, delta)) sym = ts((0, 0, 4), (0, 5, 0), (0, 0, 2)) assert_raises(ValueError, sym.add_site_group, g3) @@ -81,7 +83,7 @@ def test_translational_symmetry(): assert_equal(sym.which(site), (0, 0)) assert_equal(sym2.which(site), (0,)) for v in [(1, 0), (0, 1), (-1, 0), (0, -1), (5, 10), (-111, 573)]: - site2 = site.shifted(np.dot(v, transl_vecs)) + site2 = shifted(site, np.dot(v, transl_vecs)) assert not sym.in_fd(site2) assert (v[0] != 0) != sym2.in_fd(site2) assert_equal(sym.to_fd(site2), site) @@ -90,8 +92,8 @@ def test_translational_symmetry(): assert_equal(sym2.which(site2), v[:1]) for hop in [(0, 0), (100, 0), (0, 5), (-2134, 3213)]: - assert_equal(sym.to_fd(site2, site2.shifted(hop)), - (site, site.shifted(hop))) + assert_equal(sym.to_fd(site2, shifted(site2, hop)), + (site, shifted(site, hop))) def test_translational_symmetry_reversed():