Arrays indexable by site/hopping
Often users will calculate quantities defined over sites/hoppings.
Presently, they have to map high-level Site
objects to the corresponding index using the sites
list
in the system.
This is unnecessarily cumbersome given how often this issue comes up. What we would like to have instead is an array-like object that can be indexed using sites:
ld = kwant.ldos(syst, ...)
ld[lat(0, 0)]
Similarly, objects that are defined on hoppings (e.g. kwant.operator.Current
) could be indexed with
pairs of sites:
current = J(psi)
current[lat(0, 0), lat(0, 1)]
Also the wavefunction returned by kwant could be indexed by site and return a sub-array over the orbitals on that site (this is related to #9)
I could imagine the following hierarchy:
class Indexable:
def __init__(self, syst, data):
pass
def _index(self, obj):
pass
def __getitem__(self, obj):
return data[self._index(obj)]
class SiteIndexable(Indexable):
# acts on arrays defined over all sites, indexable by site
# (_index returns an integer)
...
class HoppingIndexable(Indexable):
# acts on arrays defined over all hoppings (hoppings ordered
# in the same way as when we iterate over the graph), indexable by hopping
# (_index returns an integer)
...
class OrbitalIndexable(Indexable):
# acts on arrays defined over all orbitals, indexable by site
# (_index returns a slice over -- this can be obtained almost trivially
# from `syst.site_ranges` (see `_get_orbs` in `kwant/operator.pyx`))
...