From bab68fe78033a2316b81883597ddf34c98c5f76c Mon Sep 17 00:00:00 2001 From: Joseph Weston <joseph@weston.cloud> Date: Wed, 13 Feb 2019 15:18:42 +0100 Subject: [PATCH] add basic pretty printing for finalized systems Closes #270. --- kwant/system.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/kwant/system.py b/kwant/system.py index d7253597..e6dd5ddf 100644 --- a/kwant/system.py +++ b/kwant/system.py @@ -70,6 +70,20 @@ class System(metaclass=abc.ABCMeta): return DiscreteSymmetry() + def __str__(self): + items = [ + # (format, extractor, skip if info not present) + ('{} sites', self.graph.num_nodes, False), + ('{} hoppings', self.graph.num_edges, False), + ('parameters: {}', tuple(self.parameters), True), + ] + # Skip some information when it's not present (parameters) + details = [fmt.format(info) for fmt, info, skip in items + if (info or not skip)] + details = ', and '.join((', '.join(details[:-1]), details[-1])) + return '<{} with {}>'.format(self.__class__.__name__, details) + + # Add a C-implemented function as an unbound method to class System. System.hamiltonian_submatrix = _system.HamiltonianSubmatrix() -- GitLab