From dd9fd59ccf93c8a48506e771ce9391bfc02b82ac Mon Sep 17 00:00:00 2001
From: Pablo Piskunow <pablo.perez.piskunow@gmail.com>
Date: Mon, 1 Apr 2019 12:32:51 +0200
Subject: [PATCH] add check for kwant systems, and fix default value of `where`
 in KPM

---
 kwant/kpm.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kwant/kpm.py b/kwant/kpm.py
index eb161de3..a06d7c6d 100644
--- a/kwant/kpm.py
+++ b/kwant/kpm.py
@@ -945,7 +945,7 @@ class LocalVectors:
         must be a list of integers with the indices where column vectors
         are nonzero.
     """
-    def __init__(self, syst, where, *args):
+    def __init__(self, syst, where=None, *args):
         self.tot_norbs, self.orbs = _normalize_orbs_where(syst, where)
         self._idx = 0
 
@@ -1006,7 +1006,11 @@ def _normalize_orbs_where(syst, where):
         tot_norbs = _get_tot_norbs(syst)
         orbs = _from_where_to_orbs(syst, where)
     else:
-        tot_norbs = csr_matrix(syst).shape[0]
+        try:
+            tot_norbs = csr_matrix(syst).shape[0]
+        except TypeError:
+            raise TypeError("'syst' is neither a matrix "
+                             "nor a Kwant system.")
         orbs = (range(tot_norbs) if where is None
                 else np.asarray(where, int))
     return tot_norbs, orbs
-- 
GitLab