Commit 7663844b authored by Joseph Weston's avatar Joseph Weston
Browse files

Merge branch 'fixup/kpm' into 'stable'

fix kpm.conductivity in the case where 'norbs' is not set

See merge request !321
parents 2bb9ff6d b0825885
......@@ -778,6 +778,8 @@ def conductivity(hamiltonian, alpha='x', beta='x', positions=None, **kwargs):
hamiltonian : `~kwant.system.FiniteSystem` or matrix Hamiltonian
If a system is passed, it should contain no leads.
alpha, beta : str, or operators
If ``hamiltonian`` is a kwant system, or if the ``positions``
are provided, ``alpha`` and ``beta`` can be the directions of the
......@@ -1049,10 +1051,11 @@ def _velocity(hamiltonian, params, op_type, positions):
elif isinstance(op_type, str):
direction = directions[op_type]
if isinstance(hamiltonian, system.System):
operator = hamiltonian.hamiltonian_submatrix(params=params,
positions = np.array([site.pos for site in hamiltonian.sites
for iorb in range(])
operator, norbs, norbs = hamiltonian.hamiltonian_submatrix(
params=params, sparse=True, return_norb=True
positions = np.vstack([[hamiltonian.pos(i)] * norb
for i, norb in enumerate(norbs)])
elif positions is not None:
operator = coo_matrix(hamiltonian, copy=True)
displacements = positions[operator.col] - positions[operator.row]
......@@ -80,6 +80,13 @@ def test_conductivity():
cond = kwant.kpm.conductivity(syst, alpha=alpha, beta=beta,
positions=None, **kpm_params)
# test when 'norbs' not provided
n = lat.norbs
lat.norbs = None
cond = kwant.kpm.conductivity(syst, alpha=alpha, beta=beta,
positions=None, **kpm_params)
lat.norbs = n
# test system or hamiltonian, no positions, but velocity operators
cond_xx = kwant.kpm.conductivity(syst, alpha='x', beta='x',
positions=None, **kpm_params)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment