velocity operator raises error when System contains sites with norbs = None
When computing for example the conductivity of a honeycomb lattice using the kpm module, the following code:
import kwant
def circle(pos):
x, y = pos
return x**2 + y**2 < 100
lat = kwant.lattice.honeycomb()
syst = kwant.Builder()
syst[lat.shape(circle, (0, 0))] = 0
syst[lat.neighbors()] = -1
fsyst = syst.finalized()
kwant.kpm.conductivity(fsyst, alpha='x', beta='x')
raises an error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-45-26e18445c11f> in <module>()
10 syst[lat.neighbors()] = -1
11 fsyst = syst.finalized()
---> 12 kwant.kpm.conductivity(fsyst, alpha='x', beta='x')
/usr/local/lib/python3.6/dist-packages/kwant/kpm.py in conductivity(hamiltonian, alpha, beta, positions, **kwargs)
819
820 params = kwargs.get('params')
--> 821 alpha = _velocity(hamiltonian, params, alpha, positions)
822 beta = _velocity(hamiltonian, params, beta, positions)
823
/usr/local/lib/python3.6/dist-packages/kwant/kpm.py in _velocity(hamiltonian, params, op_type, positions)
1044 operator = hamiltonian.hamiltonian_submatrix(params=params,
1045 sparse=True)
-> 1046 positions = np.array([site.pos for site in hamiltonian.sites
1047 for iorb in range(site.family.norbs)])
1048 elif positions is not None:
/usr/local/lib/python3.6/dist-packages/kwant/kpm.py in <listcomp>(.0)
1045 sparse=True)
1046 positions = np.array([site.pos for site in hamiltonian.sites
-> 1047 for iorb in range(site.family.norbs)])
1048 elif positions is not None:
1049 operator = coo_matrix(hamiltonian, copy=True)
TypeError: 'NoneType' object cannot be interpreted as an integer
The velocity operator that is called is not compatible with a kwant System that has at least one site with unspecified norbs. Is this behavior intended? If not, a simple fix would be to catch the norbs==None case in an if/else statement inside the range statement:
positions = np.array([site.pos for site in hamiltonian.sites
for iorb in range(site.family.norbs
if site.family.norbs is not None else 1)])