diff --git a/kwant/builder.py b/kwant/builder.py index a4ba1f52e31d5d1a6ea618bf70f641ba1e92aa77..59cdf2b8fa2ae20c8c52bc32e0c1b66070c26243 100644 --- a/kwant/builder.py +++ b/kwant/builder.py @@ -672,6 +672,8 @@ class Builder(object): a, b = hopping except: raise KeyError(hopping) + if a == b: + raise KeyError(hopping) if isinstance(value, HermConjOfFunc): a, b = b, a value = value.function diff --git a/kwant/tests/test_builder.py b/kwant/tests/test_builder.py index 44b73f889c910b2ff7007bcc028ef40f5d860403..cbb8e27b6b5992339cde14cd650ff293722f00c0 100644 --- a/kwant/tests/test_builder.py +++ b/kwant/tests/test_builder.py @@ -114,7 +114,9 @@ def test_construction_and_indexing(): hoppings = [(gr(0, 0), gr(0, 1)), (gr(0, 1), gr(1, 0)), (gr(1, 0), gr(0, 0))] - failing_hoppings = [(gr(0, 1), gr(7, 8)), (gr(12, 14), gr(0, 1))] + failing_hoppings = [(gr(0, 1), gr(0, 1)), + (gr(0, 1), gr(7, 8)), + (gr(12, 14), gr(0, 1))] check_construction_and_indexing(sites, sites, hoppings, hoppings, failing_hoppings)