From 70065a072a7f4969bbd453345841ea0cffbc682c Mon Sep 17 00:00:00 2001
From: Michael Wimmer <wimmer@lorentz.leidenuniv.nl>
Date: Tue, 1 Apr 2014 09:42:37 +0200
Subject: [PATCH] fix momentum sign convention of Bands (k -> -k)

---
 doc/source/pre/whatsnew/1.1.rst        | 12 ++++++++++++
 doc/source/pre/whatsnew/index.rst      |  1 +
 kwant/physics/dispersion.py            |  4 +++-
 kwant/physics/tests/test_dispersion.py | 17 +++++++++++++++--
 kwant/system.py                        |  4 ++--
 5 files changed, 33 insertions(+), 5 deletions(-)
 create mode 100644 doc/source/pre/whatsnew/1.1.rst

diff --git a/doc/source/pre/whatsnew/1.1.rst b/doc/source/pre/whatsnew/1.1.rst
new file mode 100644
index 0000000..6e9a4fd
--- /dev/null
+++ b/doc/source/pre/whatsnew/1.1.rst
@@ -0,0 +1,12 @@
+What's new in Kwant 1.1
+=======================
+
+This article explains the user-visible changes in Kwant 1.1.
+
+Harmonize `~kwant.physics.Bands` with `~kwant.physics.modes`
+------------------------------------------------------------
+Kwant's convention is that momenta are positive in the direction of
+`~kwant.lattice.TranslationalSymmetry`.  While the momenta returned by
+`~kwant.physics.modes` did respect this convention, the momenta read off the
+band structure as given by `~kwant.physics.Bands` had the wrong sign.  This has
+been fixed now.
diff --git a/doc/source/pre/whatsnew/index.rst b/doc/source/pre/whatsnew/index.rst
index fc007c3..b97a4f1 100644
--- a/doc/source/pre/whatsnew/index.rst
+++ b/doc/source/pre/whatsnew/index.rst
@@ -2,5 +2,6 @@ What's new in Kwant
 ===================
 
 .. toctree::
+    1.1
     1.0
     0.2
diff --git a/kwant/physics/dispersion.py b/kwant/physics/dispersion.py
index 1c8bb20..312c07d 100644
--- a/kwant/physics/dispersion.py
+++ b/kwant/physics/dispersion.py
@@ -49,6 +49,8 @@ class Bands(object):
         self.hop[:, hop.shape[1]:] = 0
 
     def __call__(self, k):
-        mat = self.hop * complex(math.cos(k), math.sin(k))
+        # Note: Equation to solve is
+        #       (V^\dagger e^{ik} + H + V e^{-ik}) \psi = E \psi
+        mat = self.hop * complex(math.cos(k), -math.sin(k))
         mat += mat.conjugate().transpose() + self.ham
         return np.sort(np.linalg.eigvalsh(mat).real)
diff --git a/kwant/physics/tests/test_dispersion.py b/kwant/physics/tests/test_dispersion.py
index cf41d48..e2d7595 100644
--- a/kwant/physics/tests/test_dispersion.py
+++ b/kwant/physics/tests/test_dispersion.py
@@ -6,9 +6,9 @@
 # the AUTHORS file at the top-level directory of this distribution and at
 # http://kwant-project.org/authors.
 
-from numpy.testing import assert_array_almost_equal
+from numpy.testing import assert_array_almost_equal, assert_almost_equal
 import kwant
-from math import pi, cos
+from math import pi, cos, sin
 
 def test_band_energies(N=5):
     sys = kwant.Builder(kwant.TranslationalSymmetry((-1, 0)))
@@ -23,3 +23,16 @@ def test_band_energies(N=5):
         energies = band_energies(k)
         assert_array_almost_equal(sorted(energies),
                                   sorted([2 - 2 * cos(k), 4 - 2 * cos(k)]))
+
+def test_same_as_lead():
+    sys = kwant.Builder(kwant.TranslationalSymmetry((-1,)))
+    lat = kwant.lattice.chain()
+    sys[lat(0)] = 0
+    sys[lat(0), lat(1)] = complex(cos(0.2), sin(0.2))
+
+    sys = sys.finalized()
+    momenta = sys.modes()[0].momenta
+    bands = kwant.physics.Bands(sys)
+
+    for momentum in momenta:
+        assert_almost_equal(bands(momentum)[0], 0)
diff --git a/kwant/system.py b/kwant/system.py
index 8497b81..3d9f0b3 100644
--- a/kwant/system.py
+++ b/kwant/system.py
@@ -194,8 +194,8 @@ class InfiniteSystem(System):
     def inter_cell_hopping(self, args=(), sparse=False):
         """Hopping Hamiltonian between two cells of the infinite system."""
         cell_sites = xrange(self.cell_size)
-        neighbor_sites = xrange(self.cell_size, self.graph.num_nodes)
-        return self.hamiltonian_submatrix(args, cell_sites, neighbor_sites,
+        interface_sites = xrange(self.cell_size, self.graph.num_nodes)
+        return self.hamiltonian_submatrix(args, cell_sites, interface_sites,
                                           sparse=sparse)
 
     def modes(self, energy=0, args=()):
-- 
GitLab