From 0ffd680076effb0d9cd7f76765363f3756bdc8d2 Mon Sep 17 00:00:00 2001 From: Christoph Groth <christoph.groth@cea.fr> Date: Tue, 12 Feb 2013 16:12:09 +0100 Subject: [PATCH] minor bugfix: no longer allow hoppings between a site and itself --- kwant/builder.py | 2 ++ kwant/tests/test_builder.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/kwant/builder.py b/kwant/builder.py index a4ba1f52..59cdf2b8 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 44b73f88..cbb8e27b 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) -- GitLab