Hi Luca,
syst[lat(0)] = -(1/2)*(mu + W*(2*onsite - 1))*pauli3
for i in range(1,L):
syst[lat(i)] = -(1/2)*(mu + W*(2*onsite - 1))*pauli3
syst[lat(i), lat(i - 1)] = -(t/2)*pauli3 + 1j*(Delta/2)*pauli2
----------------------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-10-12a574eefcd0> in <module> 3 4 mub = 3 ----> 5 systb = kitaev(L ,1, mub, 1, W) 6 systb = systb.finalized() 7 hamatb = systb.hamiltonian_submatrix(sparse = False)
<ipython-input-9-661d5ddb539a> in kitaev(L, t, mu, Delta, W) 4 lat = kwant.lattice.chain(norbs=2) 5 ----> 6 syst[lat(0)] = -(1/2)*(mu + W*(2*onsite - 1))*pauli3 7 8 for i in range(1,L):
TypeError: unsupported operand type(s) for *: 'int' and 'function'
—————————————————————————————------
You get this error because in your code, 'onsite' is a function, and you are trying to multiply it by an integer (2). You should instead *call* the onsite function with the appropriate site: syst[lat(i)] = -(1/2) * (mu + W * ( 2 * onsite(lat(i), salt) - 1) * pauli3 where I have defined 'onsite' as: def onsite(site, salt): return uniform(repr(site)) Note that in your example 'onsite' took a parameter 'phi' which was not used (and hence unnecessary). In order for this to work, your 'kitaev' function will also have to take a 'salt' parameter. The disadvantage of this approach is that you have to re-build the system from scratch every time you want to change any of the parameters. If you want to do many calculations for different parameter values (but same system geometry; i.e. value of 'L' in your example) then I would recommend constructing the system only once, and using *functions* for the Hamiltonian values: def onsite(site, mu, W, salt): disorder = W * (2 * uniform(repr(site), salt) - 1) return -0.5 * (mu + disorder) * pauli3 def hopping(site1, site2, t, Delta): return -(t / 2) * pauli3 + 1j * (Delta / 2) * pauli2 def kitaev(L): syst = kwant.Builder() lat = kwant.lattice.chain(norbs=2) syst[(lat(i) for i in range(L))] = onsite syst[lat.neighbors()] = hopping return syst systb = kitaev(...).finalized() systb.hamiltonian_submatrix(params=dict(mu=..., W=..., t=..., Delta=..., salt=...)) Happy Kwanting, Joe