Commit 8beaa8c3 authored by Anton Akhmerov's avatar Anton Akhmerov
Browse files

Merge branch 'fix_eradicate' into 'master'

fix eradicate dangling across translational symmetry

See merge request kwant/kwant!369
parents e2a4343e 47d7302e
Pipeline #38352 passed with stages
in 11 minutes and 28 seconds
......@@ -888,20 +888,30 @@ class Builder:
"""
sites = list(site for site in self.H
if self._out_degree(site) < 2)
for site in sites:
# We could have deleted the site already if there was e.g. an
# isolated hopping.
if site not in self.H:
continue
while site:
while self._out_degree(site) < 2:
neighbors = tuple(self._out_neighbors(site))
if neighbors:
assert len(neighbors) == 1
neighbor = neighbors[0]
self._del_edge(neighbor, site)
if self._out_degree(neighbor) > 1:
neighbor = False
if not neighbors:
del self.H[site]
break
(neighbor,) = neighbors
if neighbor in self.H:
# neighbor is in the fundamental domain
edge = (neighbor, site)
else:
neighbor = False
edge = self.symmetry.to_fd(neighbor, site)
neighbor = self.symmetry.to_fd(neighbor)
self._del_edge(*edge)
del self.H[site]
# Neighbor could become dangling now.
site = neighbor
def __iter__(self):
......
......@@ -862,6 +862,21 @@ def test_dangling():
assert (sorted(site.tag for site in syst0.sites()) ==
sorted(site.tag for site in syst1.sites()))
def test_dangling_with_symmetry():
# lenght = 3 is the special case that gives all dangling bonds
# lenght = 4 is the standard case of dangling bonds across the symmetry
for length in [3, 4]:
symm = kwant.TranslationalSymmetry((length, 0))
lat = kwant.lattice.square(norbs=1)
syst = kwant.Builder(symmetry=symm)
for x in range(length):
syst[lat(x, 0)] = 0
syst[lat(x, 1)] = 0
syst[lat.neighbors()] = -1
# remove neighbors of site at (lenght-1, 0), dangling across symm
del syst[lat(length - 2, 0)]
del syst[lat(length - 1, 1)]
syst.eradicate_dangling()
def test_builder_with_symmetry():
g = kwant.lattice.general(ta.identity(3), norbs=1)
......
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