From a3bce5d86f7789dac8b1e4d25e56b9358baea3a4 Mon Sep 17 00:00:00 2001 From: Christoph Groth <christoph.groth@cea.fr> Date: Thu, 18 Apr 2013 22:46:20 +0200 Subject: [PATCH] bugfix: make args and kwargs work for bandstructure calculations --- kwant/physics/dispersion.py | 10 +++++++--- kwant/plotter.py | 9 +++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/kwant/physics/dispersion.py b/kwant/physics/dispersion.py index 12245ac0..61562a04 100644 --- a/kwant/physics/dispersion.py +++ b/kwant/physics/dispersion.py @@ -20,6 +20,10 @@ class Bands(object): sys : `kwant.system.InfiniteSystem` The low level infinite system for which the energies are to be calculated. + args : tuple, defaults to empty + Positional arguments to pass to the ``hamiltonian`` method. + kwargs : dictionary, defaults to empty + Keyword arguments to pass to the ``hamiltonian`` method. Notes ----- @@ -37,11 +41,11 @@ class Bands(object): >>> pyplot.show() """ - def __init__(self, sys): - self.ham = sys.slice_hamiltonian() + def __init__(self, sys, args=(), kwargs={}): + self.ham = sys.slice_hamiltonian(args=args, kwargs=kwargs) if not np.allclose(self.ham, self.ham.T.conj()): raise ValueError('The slice Hamiltonian is not Hermitian.') - hop = sys.inter_slice_hopping() + hop = sys.inter_slice_hopping(args=args, kwargs=kwargs) self.hop = np.empty(self.ham.shape, dtype=complex) self.hop[:, : hop.shape[1]] = hop self.hop[:, hop.shape[1]:] = 0 diff --git a/kwant/plotter.py b/kwant/plotter.py index 07201851..2ce80731 100644 --- a/kwant/plotter.py +++ b/kwant/plotter.py @@ -850,13 +850,18 @@ def map(sys, value, colorbar=True, cmap=None, return output_fig(fig, file=file, show=show) -def bands(sys, momenta=65, file=None, show=True, dpi=None, fig_size=None): +def bands(sys, momenta=65, args=(), kwargs={}, + file=None, show=True, dpi=None, fig_size=None): """Plot band structure of a translationally invariant 1D system. Parameters ---------- sys : kwant.system.InfiniteSystem A system bands of which are to be plotted. + args : tuple, defaults to empty + Positional arguments to pass to the ``hamiltonian`` method. + kwargs : dictionary, defaults to empty + Keyword arguments to pass to the ``hamiltonian`` method. momenta : int or 1D array-like Either a number of sampling points on the interval [-pi, pi], or an array of points at which the band structure has to be evaluated. @@ -885,7 +890,7 @@ def bands(sys, momenta=65, file=None, show=True, dpi=None, fig_size=None): if momenta.ndim != 1: momenta = np.linspace(-np.pi, np.pi, momenta) - bands = physics.Bands(sys) + bands = physics.Bands(sys, args=args, kwargs=kwargs) energies = [bands(k) for k in momenta] fig = Figure() -- GitLab