`kwant.continuum.sympify` can't replace symbols with `numpy` arrays using `locals`
Minimal meaningful example: I want to define a Rashba-like Hamiltonian with higher spin. (I took spin_matrices
from qsymm
)
def spin_matrices(s):
"""Construct spin-s matrices for any half-integer spin."""
d = np.round(2*s + 1)
assert np.isclose(d, int(d))
d = int(d)
Sz = 1/2 * np.diag(np.arange(d - 1, -d, -2))
# first diagonal for general s from en.wikipedia.org/wiki/Spin_(physics)
diag = [1/2*np.sqrt((s + 1) * 2*i - i * (i + 1)) for i in np.arange(1, d)]
Sx = np.diag(diag, k=1) + np.diag(diag, k=-1)
Sy = -1j*np.diag(diag, k=1) + 1j*np.diag(diag, k=-1)
return np.array([Sx, Sy, Sz])
J_x, J_y, J_z = spin_matrices(3/2)
ham1 = ("hbar^2 / (2 * m) * (k_x**2 + k_y**2 + k_z**2) * eye(4) +" +
"alpha * J_x * k_x + alpha * J_y * k_y + alpha * J_z * k_z")
kwant.continuum.sympify(ham, locals={'J_x': J_x, 'J_y': J_y, 'J_z': J_z})
Edit: my mistake, there was a typo, this actually works.