diff --git a/kwant/builder.py b/kwant/builder.py index 150c61b4db9d0a49da28585e836d47f3f1613585..2fbbd5756949c51642259f70b505998706b60801 100644 --- a/kwant/builder.py +++ b/kwant/builder.py @@ -726,7 +726,7 @@ class Builder(object): b, a = sym.to_fd(b, a) assert not sym.in_fd(a) value = self._get_edge(b, a) - if hasattr(value, '__call__'): + if callable(value): assert not isinstance(value, HermConjOfFunc) value = HermConjOfFunc(value) else: @@ -1258,7 +1258,7 @@ class FiniteSystem(system.FiniteSystem): def hamiltonian(self, i, j, *args): if i == j: value = self.onsite_hamiltonians[i] - if hasattr(value, '__call__'): + if callable(value): value = value(self.sites[i], *args) else: edge_id = self.graph.first_edge_id(i, j) @@ -1268,8 +1268,9 @@ class FiniteSystem(system.FiniteSystem): i, j = j, i edge_id = self.graph.first_edge_id(i, j) value = self.hoppings[edge_id] - if hasattr(value, '__call__'): - value = value(self.sites[i], self.sites[j], *args) + if callable(value): + sites = self.sites + value = value(sites[i], sites[j], *args) if conj: value = herm_conj(value) return value @@ -1288,9 +1289,8 @@ class InfiniteSystem(system.InfiniteSystem): if i >= self.slice_size: i -= self.slice_size value = self.onsite_hamiltonians[i] - if hasattr(value, '__call__'): - value = value(self.symmetry.to_fd(self.sites[i]), - *args) + if callable(value): + value = value(self.symmetry.to_fd(self.sites[i]), *args) else: edge_id = self.graph.first_edge_id(i, j) value = self.hoppings[edge_id] @@ -1299,9 +1299,10 @@ class InfiniteSystem(system.InfiniteSystem): i, j = j, i edge_id = self.graph.first_edge_id(i, j) value = self.hoppings[edge_id] - if hasattr(value, '__call__'): - site_i = self.sites[i] - site_j = self.sites[j] + if callable(value): + sites = self.sites + site_i = sites[i] + site_j = sites[j] site_i, site_j = self.symmetry.to_fd(site_i, site_j) value = value(site_i, site_j, *args) if conj: diff --git a/kwant/plotter.py b/kwant/plotter.py index 2b68dc78491604ff238b09e9c84f11c4b682670e..4c902e25976047f08d670881ed52814c226def43 100644 --- a/kwant/plotter.py +++ b/kwant/plotter.py @@ -619,9 +619,9 @@ def plot(sys, n_lead_copies=2, site_color='b', hop_color='b', cmap='gray', sites_pos = np.apply_along_axis(pos_transform, 1, sites_pos) end_pos = np.apply_along_axis(pos_transform, 1, end_pos) start_pos = np.apply_along_axis(pos_transform, 1, start_pos) - if hasattr(site_color, '__call__'): + if callable(site_color): site_color = [site_color(i[0]) for i in sites if i[1] is None] - if hasattr(hop_color, '__call__'): + if callable(hop_color): hop_color = [hop_color(*i[0]) for i in hops if i[1] is None] # Choose plot type. dim = 3 if (sites_pos.shape[1] == 3) else 2 @@ -833,7 +833,7 @@ def map(sys, value, colorbar=True, cmap=None, vmin=None, vmax=None, coords = sys_leads_pos(sys, sites) if coords.shape[1] != 2: raise ValueError('Only 2D systems can be plotted this way.') - if hasattr(value, '__call__'): + if callable(value): value = [value(site[0]) for site in sites] else: if not isinstance(sys, system.FiniteSystem):