Commit b49e5210 authored by Kloss's avatar Kloss

handle problem with flat bands to obtain the mode index

parent 848b460e
......@@ -794,7 +794,10 @@ class BandSketching:
mode : int
kwant scattering mode index
kwant scattering mode index.
The mode index fulfills: `0 <= mode < nbands` where `nbands`
is the total number of bands of the spectrum.
If no open mode could be found, `mode = -1` is returned.
# type checks
assert _is_type(k, 'real_number')
......@@ -804,7 +807,15 @@ class BandSketching:
modes = self._modes(energy=energy)[0]
momenta = modes.momenta
velocities = modes.velocities
return np.abs(momenta[velocities > 0] - k).argmin()
# for almost flat bands, small numerical errors (of order 1E-16)
# in the energy from the interpolation function might fail kwant's
# mode calculation. (as the velocity of that modes is zero,
# they do not contribute to a manybody sum anyhow).
return np.abs(momenta[velocities > 0] - k).argmin()
except ValueError:
return -1
def energy_to_scattering_mode(self, energy, band, kmin, kmax):
"""Finds the scattering mode index for a band giving its energy.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment