Skip to content
Snippets Groups Projects
Commit 0ee95bfc authored by Anton Akhmerov's avatar Anton Akhmerov Committed by Christoph Groth
Browse files

remove builder.Site.shifted

It only made sense for tinyarray tags, and was largely unused.
parent e001ab42
No related branches found
No related tags found
No related merge requests found
......@@ -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))
......
......@@ -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
......
......@@ -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():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment