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

make tolerance in neighbor search relative to the shortest lattice vector

parent 864b9df8
No related branches found
No related tags found
No related merge requests found
...@@ -251,15 +251,15 @@ class Polyatomic(object): ...@@ -251,15 +251,15 @@ class Polyatomic(object):
return wire_sites return wire_sites
def neighbors(self, n=1, eps=1e-8): def neighbors(self, n=1, eps=1e-8):
""" """Return n-th nearest neighbor hoppings.
Return n-th nearest neighbor hoppings.
Parameters Parameters
---------- ----------
n : integer n : integer
Order of the hoppings to return. Order of the hoppings to return.
eps : float eps : float
A cutoff for when to consider lengths to be approximately equal. Tolerance relative to the length of the shortest lattice vector for
when to consider lengths to be approximately equal.
Returns Returns
------- -------
...@@ -276,6 +276,9 @@ class Polyatomic(object): ...@@ -276,6 +276,9 @@ class Polyatomic(object):
# This algorithm is not designed to be fast and can be improved, # This algorithm is not designed to be fast and can be improved,
# however there is no real need. # however there is no real need.
sls = self.sublattices sls = self.sublattices
shortest_hopping = sls[0].n_closest(sls[0](*([0] * sls[0].dim)).pos,
2)[-1]
eps *= np.linalg.norm(self.vec(shortest_hopping))
nvec = len(self.prim_vecs) nvec = len(self.prim_vecs)
sublat_pairs = [(i, j) for (i, j) in product(sls, sls) sublat_pairs = [(i, j) for (i, j) in product(sls, sls)
if sls.index(j) >= sls.index(i)] if sls.index(j) >= sls.index(i)]
...@@ -289,6 +292,7 @@ class Polyatomic(object): ...@@ -289,6 +292,7 @@ class Polyatomic(object):
continue continue
return True return True
# Find the correct number of neighbors to calculate on each lattice. # Find the correct number of neighbors to calculate on each lattice.
cutoff = n + 2 cutoff = n + 2
while True: while True:
......
...@@ -44,13 +44,13 @@ def test_general(): ...@@ -44,13 +44,13 @@ def test_general():
def test_neighbors(): def test_neighbors():
lat = lattice.honeycomb() lat = lattice.honeycomb(1e-10)
num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)] num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)]
assert num_nth_nearest == [2, 3, 6, 3, 6] assert num_nth_nearest == [2, 3, 6, 3, 6]
lat = lattice.square() lat = lattice.square(1e8)
num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)] num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)]
assert num_nth_nearest == [1, 2, 2, 2, 4] assert num_nth_nearest == [1, 2, 2, 2, 4]
lat = lattice.chain() lat = lattice.chain(1e-10)
num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)] num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)]
assert num_nth_nearest == 5 * [1] assert num_nth_nearest == 5 * [1]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment