Thanks again for your prompt answer. I want to access wavefunction elements by their site which are located in a plane for 3D or a line in 2D, I mean no projected wavefunction, just those elements which are related to sites on a plane in 3D system or a line in 2D one. I implemented what you said for 2D system, but I don't get any array for "better_wf(lat(i.j))". It should give me an array (4 elements due to 4 degrees of freedom) for a specific site. If it works, I can change it to the ones I want, but it does not. Here you can find my code:  

Your time and consideration are much appreciated.

Best regards,


On Thu, Jul 30, 2015 at 5:04 PM, Joseph Weston <> wrote:

I think I misunderstood what you are trying to do. You talked about
"filtering" only the sites which were in a plane, so I thought you
wanted to produce a projection of the wavefunction onto the sites in the
plane. If you just want to be able to access wavefunction elements "by
their site" you could do something like the following

        def site_indexer(wavefunction, sites, n_orbs=4):
            site_idx_map = {site: i for i, site in enumerate(sites)}

            def indexer(site):
                orbital = site_idx_map[site] * n_orbs
                return wavefunction[orbital: orbital + n_orbs]

            return indexer

       lat = kwant.lattice.square()
       sys = make_system()
       fsys = sys.finalized()
       wf = kwant.wavefunction(...)

       better_wf = site_indexer(wf, fsys.sites)

       # we get an array of length 4, for the 4 orbitals on the site
       print better_wf(lat(0, 2))

You could then use `better_wf` to access the wavefunction on the
orbitals belonging to different sites.