From 9245b5b9e923bb5f0f504aa4d44ced5aff74a919 Mon Sep 17 00:00:00 2001 From: Anton Akhmerov <anton.akhmerov@gmail.com> Date: Mon, 18 Feb 2013 18:02:53 -0500 Subject: [PATCH] detect a faulty TranslationalSymmetry when it is created --- kwant/lattice.py | 3 +++ kwant/tests/test_lattice.py | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/kwant/lattice.py b/kwant/lattice.py index 1d4855b8..4b1b67d3 100644 --- a/kwant/lattice.py +++ b/kwant/lattice.py @@ -239,6 +239,9 @@ class TranslationalSymmetry(builder.Symmetry): msg = "TranslationalSymmetry takes 1d sequences as parameters.\n" \ "See What's new in kwant 0.2 in the documentation." raise ValueError(msg) + if np.linalg.matrix_rank(periods) < len(periods): + raise ValueError("Translational symmetry periods must be " + "linearly independent") # A dictionary containing cached data required for applying the # symmetry to different site groups. self.site_group_data = {} diff --git a/kwant/tests/test_lattice.py b/kwant/tests/test_lattice.py index 45e0d279..dd5dac79 100644 --- a/kwant/tests/test_lattice.py +++ b/kwant/tests/test_lattice.py @@ -46,8 +46,7 @@ def test_translational_symmetry(): g2 = lattice.make_lattice(np.identity(2)) g3 = lattice.make_lattice(np.identity(3)) - sym = ts((0, 0, 4), (0, 5, 0), (0, 0, 2)) - assert_raises(ValueError, sym.add_site_group, g3) + assert_raises(ValueError, ts, (0, 0, 4), (0, 5, 0), (0, 0, 2)) sym = ts((3.3, 0)) assert_raises(ValueError, sym.add_site_group, g2) -- GitLab