From 1df4bcc757ece4ab9c650565dec49496dd7b94a9 Mon Sep 17 00:00:00 2001
From: Joseph Weston <joseph.weston08@gmail.com>
Date: Mon, 20 Nov 2017 10:18:59 +0100
Subject: [PATCH] mention finalization when user tries to use System API from
 Builder

Closes #177.
---
 kwant/builder.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/kwant/builder.py b/kwant/builder.py
index ca6729e2..096d20c8 100644
--- a/kwant/builder.py
+++ b/kwant/builder.py
@@ -1846,6 +1846,19 @@ class Builder:
         result.symmetry = self.symmetry
         return result
 
+    # Protect novice users from confusing error messages if they
+    # forget to finalize their Builder.
+
+    @staticmethod
+    def _require_system(*args, **kwargs):
+        """You need a finalized system; Use Builder.finalized() first."""
+        raise TypeError('You need a finalized system; '
+                        'use Builder.finalized() first.')
+
+    hamiltonian = hamiltonian_submatrix = modes = selfenergy = \
+    inter_cell_hopping = cell_hamiltonian = precalculated = \
+    _require_system
+
 
 ################ Finalized systems
 
-- 
GitLab