Skip to content

Instantly share code, notes, and snippets.

@oroszl
Created July 6, 2017 20:23
Show Gist options
  • Save oroszl/022b56f58ecffa4026271a873d2de8dd to your computer and use it in GitHub Desktop.
Save oroszl/022b56f58ecffa4026271a873d2de8dd to your computer and use it in GitHub Desktop.
dense sisl routines
def Skd_MK2(dh, k=(0, 0, 0)):
dtype = np.complex128
k = np.asarray(k, np.float64)
k.shape = (-1,)
# sparse matrix dimension (dh.no)
V = zeros((len(dh), len(dh)), dtype=dtype)
# Get the reciprocal lattice vectors dotted with k
kr = dot(dh.rcell, k)
# Calculate all phases
phases = exp(-1j * dot(kr, dot(dh.cell, dh.sc.sc_off.T)))
# Now create offsets
offsets = - np.arange(len(phases)) * dh.no
dia = diags(phases, offsets, shape=(dh.shape[1], dh.shape[0]), dtype=dtype).todense()
#dia = diags(phases, offsets, shape=(dh.shape[1], dh.shape[0]), dtype=dtype).todense()
V = (dh.tocsr(dh.S_idx)).todense().dot(dia)
return kron(V,eye(2))
def Hkd_MK2(dh, k=(0, 0, 0)):
dtype = np.complex128
k = np.asarray(k, np.float64)
k.shape = (-1,)
# sparse matrix dimension (2 * dh.no)
V = zeros((len(dh), len(dh)), dtype=dtype)
# Get the reciprocal lattice vectors dotted with k
kr = np.dot(dh.rcell, k)
# Calculate all phases
phases = exp(-1j * dot(kr, dot(dh.cell, dh.sc.sc_off.T)))
# Now create offsets
offsets = - arange(len(phases)) * dh.no
dia = diags(phases, offsets, shape=(dh.shape[1], dh.shape[0]), dtype=dtype).todense()
V[::2, ::2] = (dh.tocsr(0) + 1j * dh.tocsr(4)).todense().dot(dia)
V[1::2, 1::2] = (dh.tocsr(1) + 1j * dh.tocsr(5)).todense().dot(dia)
V[1::2, ::2] = (dh.tocsr(2) - 1j * dh.tocsr(3)).todense().dot(dia)
V[::2, 1::2] = (dh.tocsr(6) + 1j * dh.tocsr(7)).todense().dot(dia)
return V
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment