Sorry, the above code has two typo's at the end. It should be

sheet_idx_sites = filter(in_sheet, enumerate(sysf.sites))

for i, (idx, site) in enumerate(sheet_idx_sites):
projected_wavefunction[i] = wavefunction[idx]

This now gives the error that
`in_sheet() missing 1 required positional argument: 'site'`

2017-04-25 16:43 GMT+02:00 John Eaves :
Good day,

I'm trying to reconstruct something discussed in http://www.mail-archive.com/kwant-discuss@kwant-project.org/msg00432.html. In this answer it is described how to take the wavefunction from a 3D system and plot it in a 2D slice. This turned out to be something different than what the OP was asking for, but that is not so important. It is also mentioned that this has been asked before, but I couldn't find the right search terms. If my question has already been answered, I'd be very grateful for a referral to the relevant discussion!

Now, as it turns out, I can't seem to get the above to work. I take some small cylinder, I calculate the wavefunction, but then I get stuck at how to extract for example the y = 0 plane and plot this in 2D. Below I'll post how far I got, perhaps the fix would be rather simple.

def onsite(site, p):
return 6*p.t

def hopping(site0, site1, p):
return -p.t

def make_system_cyl(a=1, s=10, L = 15):
lat = kwant.lattice.general([(0, 0, a), (a, 0, 0), (0, a, 0)])

sys = kwant.Builder()

def cyl_shape(pos):
x, y, z = pos
rsq = y ** 2 + z ** 2
return rsq < s^2 and 0 <= x < L

sys[lat.shape(cyl_shape, (1,1,1))] = onsite
sys[lat.neighbors()] = hopping

x, y, z = pos
rsq = y ** 2 + z ** 2
return rsq < s^2

return sys

and I extract the wavefunction at some energy

sys = make_system_cyl(a=1, s=10, L = 15)
kwant.plot(sys)
sysf = sys.finalized()
params = SimpleNamespace(t=1)
wf = kwant.wave_function(sysf, 1.5, args=[params])

And then I try to extract the relevant parts

wavefunction = wf(0)
projected_wavefunction = np.empty((wavefunction.size, 1), dtype=np.complex)

def in_sheet(index, site):
return site.pos[1] == 0  # site in x-z plane

sheet_idx_sites = filter(in_sheet, enumerate(sys.sites)

for i, (idx, site) in enumerate(sheet_idx_sites):
projected_wavefunction[i] = wavefunction[idx]

Now this last part I took from the post referenced at the start, and it gives a syntax error. I'm not really sure how to fix it as it looks fine to me. What's wrong there?

And more importantly, once this is fixed, how can one then make a kwant.plotter.map type of plot at this x-z plane?