Exemplo n.º 1
0
def read_multicell_hamiltonian(input_file="hr_truncated.dat",
                               ncells=None,
                               win_file="wannier.win",
                               dim=2):
    """Reads an output hamiltonian from wannier"""
    mt = np.genfromtxt(input_file)  # get file
    m = mt.transpose()  # transpose matrix
    if ncells is None:  # use all the hoppings
        nmax = int(np.max([np.max(m[i]) for i in range(3)]))
        ncells = [nmax, nmax, nmax]
    # read the hamiltonian matrices
    class Hopping:
        pass  # create empty class

    tlist = []

    def get_t(i, j, k):
        norb = np.max([np.max(np.abs(m[3])), np.max(np.abs(m[4]))])
        mo = np.matrix(np.zeros((norb, norb), dtype=np.complex))
        found = False
        for l in mt:  # look into the file
            if i == int(l[0]) and j == int(l[1]) and k == int(l[2]):
                mo[int(l[3]) - 1,
                   int(l[4]) - 1] = l[5] + 1j * l[6]  # store element
                found = True  # matrix has been found
        if found: return mo  # return the matrix
        else: return None  # return nothing if not found

    for i in range(-ncells[0], ncells[0] + 1):
        for j in range(-ncells[1], ncells[1] + 1):
            for k in range(-ncells[2], ncells[2] + 1):
                if (i, j, k) == (0, 0, 0): continue  # skip intracell
                matrix = get_t(i, j, k)  # read the matrix
                if matrix is None: continue
                else:  # store hopping
                    t = Hopping()  # create hopping
                    t.dir = [i, j, k]  # direction
                    t.m = get_t(i, j, k)  # read the matrix
                    tlist.append(t)  # store hopping
    # the previous is not used yet...
    g = geometry.kagome_lattice()  # create geometry
    h = g.get_hamiltonian()  # build hamiltonian
    h.is_multicell = True
    h.orbitals = get_all_orbitals()
    h.hopping = tlist  # list of hoppings
    h.has_spin = False  # if not spin polarized
    h.geometry = read_geometry(
        input_file=win_file)  # read the geometry of the system
    h.geometry.center()  # center the geometry
    h.intra = get_t(0, 0, 0)
    if len(h.geometry.r) != len(h.intra):
        print("Dimensions do not match", len(g.r), len(h.intra))
        print(h.geometry.r)
    #  raise # error if dimensions dont match
    h.dimensionality = dim
    return h
Exemplo n.º 2
0
def read_multicell_hamiltonian(input_file="hr_truncated.dat",
                                ncells=None,win_file="wannier.win",
                                dim=2,skip_win=False):
  """Reads an output hamiltonian from wannier"""
  mt = np.genfromtxt(input_file) # get file
  m = mt.transpose() # transpose matrix
  if ncells is None: # use all the hoppings
    nmax = int(np.max([np.max(m[i])for i in range(3)]))
    ncells = [nmax,nmax,nmax]
  # read the hamiltonian matrices
  class Hopping: pass # create empty class
  tlist = []
  def get_t(i,j,k):
    norb = np.max([np.max(np.abs(m[3])),np.max(np.abs(m[4]))])
    norb = int(norb)
    mo = np.matrix(np.zeros((norb,norb),dtype=np.complex))  
    found = False
    for l in mt: # look into the file
      if i==int(l[0]) and j==int(l[1]) and k==int(l[2]):
        mo[int(l[3])-1,int(l[4])-1] = l[5] + 1j*l[6] # store element
        found  = True # matrix has been found
    if found:  return mo # return the matrix
    else: return None # return nothing if not found
  for i in range(-ncells[0],ncells[0]+1):
    for j in range(-ncells[1],ncells[1]+1):
      for k in range(-ncells[2],ncells[2]+1):
        if (i,j,k)==(0,0,0): continue # skip intracell
        matrix = get_t(i,j,k) # read the matrix
        if matrix is None: continue
        else: # store hopping
          t = Hopping() # create hopping
          t.dir = [i,j,k] # direction
          t.m = get_t(i,j,k) # read the matrix
          tlist.append(t) # store hopping
  # the previous is not used yet...
  g = geometry.kagome_lattice() # create geometry
  h = g.get_hamiltonian() # build hamiltonian
  h.is_multicell = True
  if not skip_win: # do not skip wannier.win
    h.orbitals = get_all_orbitals(input_file=win_file)
  h.hopping = tlist # list of hoppings
  h.has_spin = False  # if not spin polarized
  if not skip_win: # do not skip readin wannier.win
    h.geometry = read_geometry(input_file=win_file) # read the geometry of the system
    h.geometry.center() # center the geometry
  h.intra = get_t(0,0,0)
  if not skip_win: # do not skip reading wannier.win
    if len(h.geometry.r)!=len(h.intra): 
      print("Dimensions do not match",len(g.r),len(h.intra))
      print(h.geometry.r)
  #  raise # error if dimensions dont match
  h.dimensionality = dim 
  return h
Exemplo n.º 3
0
def read_hamiltonian(input_file="hr_truncated.dat", is_real=False):
    """Reads an output hamiltonian from wannier"""
    mt = np.genfromtxt(input_file)  # get file
    m = mt.transpose()  # transpose matrix

    # read the hamiltonian matrices
    class Hopping:
        pass  # create empty class

    tlist = []

    def get_t(i, j, k):
        norb = np.max([np.max(np.abs(m[3])), np.max(np.abs(m[4]))])
        mo = np.matrix(np.zeros((norb, norb), dtype=np.complex))
        for l in mt:  # look into the file
            if i == int(l[0]) and j == int(l[1]) and k == int(l[2]):
                if is_real:
                    mo[int(l[3]) - 1, int(l[4]) - 1] = l[5]  # store element
                else:
                    mo[int(l[3]) - 1,
                       int(l[4]) - 1] = l[5] + 1j * l[6]  # store element
        return mo  # return the matrix


#  for i in range(-nmax,nmax):
#    for j in range(-nmax,nmax):
#      for k in range(-nmax,nmax):
#        t = Hopping() # create hopping
#        t.dir = [i,j,k] # direction
#        t.m = get_t(i,j,k) # read the matrix
#        tlist.append(t) # store hopping
# the previous is not used yet...

    g = geometry.kagome_lattice()  # create geometry
    h = g.get_hamiltonian()  # build hamiltonian
    h.intra = get_t(0, 0, 0)
    h.tx = get_t(1, 0, 0)
    h.ty = get_t(0, 1, 0)
    h.txy = get_t(1, 1, 0)
    h.txmy = get_t(1, -1, 0)
    h.has_spin = False  # if not spin polarized
    h.geometry = read_geometry()  # read the geometry of the system
    if len(h.geometry.r) != len(h.intra):
        print("Dimensions do not match", len(g.r), len(h.intra))
        print(h.geometry.r)
        raise  # error if dimensions dont match
    return h
Exemplo n.º 4
0
def add_frustrated_antiferromagnetism(h, m):
    """Add frustrated magnetism"""
    import geometry
    if h.geometry.sublattice_number == 3:
        g = geometry.kagome_lattice()
    elif h.geometry.sublattice_number == 4:
        g = geometry.pyrochlore_lattice()
        g.center()
    else:
        raise  # not implemented
    ms = []
    for i in range(len(h.geometry.r)):  # loop
        ii = h.geometry.sublattice[i]  # index of the sublattice
        if callable(m):
            ms.append(-g.r[int(ii)] * m(h.geometry.r[i]))  # save this one
        else:
            ms.append(-g.r[int(ii)] * m)  # save this one
    h.add_magnetism(ms)  # add the magnetization
Exemplo n.º 5
0
def read_hamiltonian(input_file="hr_truncated.dat",is_real=False):
  """Reads an output hamiltonian from wannier"""
  mt = np.genfromtxt(input_file) # get file
  m = mt.transpose() # transpose matrix
  # read the hamiltonian matrices
  class Hopping: pass # create empty class
  tlist = []
  def get_t(i,j,k):
    norb = np.max([np.max(np.abs(m[3])),np.max(np.abs(m[4]))])
    mo = np.matrix(np.zeros((norb,norb),dtype=np.complex))  
    for l in mt: # look into the file
      if i==int(l[0]) and j==int(l[1]) and k==int(l[2]):
        if is_real:
          mo[int(l[3])-1,int(l[4])-1] = l[5] # store element
        else:
          mo[int(l[3])-1,int(l[4])-1] = l[5] + 1j*l[6] # store element
    return mo # return the matrix
#  for i in range(-nmax,nmax):
#    for j in range(-nmax,nmax):
#      for k in range(-nmax,nmax):
#        t = Hopping() # create hopping
#        t.dir = [i,j,k] # direction
#        t.m = get_t(i,j,k) # read the matrix
#        tlist.append(t) # store hopping
  # the previous is not used yet...
  g = geometry.kagome_lattice() # create geometry
  h = g.get_hamiltonian() # build hamiltonian
  h.intra = get_t(0,0,0)
  h.tx = get_t(1,0,0)
  h.ty = get_t(0,1,0)
  h.txy = get_t(1,1,0)
  h.txmy = get_t(1,-1,0)
  h.has_spin = False  # if not spin polarized
  h.geometry = read_geometry() # read the geometry of the system
  if len(h.geometry.r)!=len(h.intra): 
    print("Dimensions do not match",len(g.r),len(h.intra))
    print(h.geometry.r)
    raise # error if dimensions dont match
  return h
Exemplo n.º 6
0
def read_multicell_hamiltonian(input_file="hr_truncated.dat",ncells=[3,3,0]):
  """Reads an output hamiltonian from wannier"""
  mt = np.genfromtxt(input_file) # get file
  m = mt.transpose() # transpose matrix
  # read the hamiltonian matrices
  class Hopping: pass # create empty class
  tlist = []
  def get_t(i,j,k):
    norb = np.max([np.max(np.abs(m[3])),np.max(np.abs(m[4]))])
    mo = np.matrix(np.zeros((norb,norb),dtype=np.complex))  
    for l in mt: # look into the file
      if i==int(l[0]) and j==int(l[1]) and k==int(l[2]):
        mo[int(l[3])-1,int(l[4])-1] = l[5] + 1j*l[6] # store element
    return mo # return the matrix
  for i in range(-ncells[0],ncells[0]+1):
    for j in range(-ncells[1],ncells[1]+1):
      for k in range(-ncells[2],ncells[2]+1):
        if (i,j,k)==(0,0,0): continue # skip intracell
        print i,j,k
        t = Hopping() # create hopping
        t.dir = [i,j,k] # direction
        t.m = get_t(i,j,k) # read the matrix
        tlist.append(t) # store hopping
  # the previous is not used yet...
  g = geometry.kagome_lattice() # create geometry
  h = g.get_hamiltonian() # build hamiltonian
  h.is_multicell = True
  h.hopping = tlist # list of hoppings
  h.has_spin = False  # if not spin polarized
  h.geometry = read_geometry() # read the geometry of the system
  h.intra = get_t(0,0,0)
  if len(h.geometry.r)!=len(h.intra): 
    print "Dimensions do not match",len(g.r),len(h.intra)
    print h.geometry.r
    raise # error if dimensions dont match
  return h
Exemplo n.º 7
0
import sys
import numpy as np
import os
sys.path.append("../../pygra")

import geometry
import sculpt

g = geometry.kagome_lattice()
#g = geometry.honeycomb_lattice()
g.has_sublattice = True
g.sublattice = [-1, 1, 0]
import ribbon

g = ribbon.bulk2ribbon(g, n=20)
h = g.get_hamiltonian()
ms = []  # zeeman fields
m1 = np.array([1., 0., 0.])
m2 = np.array([-.5, np.sqrt(3.) / 2., 0.])
m3 = np.array([-.5, -np.sqrt(3.) / 2., 0.])
mm = 3.0
for (r, s) in zip(g.r, g.sublattice):
    if r[1] < 0.0:
        if s == -1: ms.append(m1 * mm)
        if s == 1: ms.append(m2 * mm)
        if s == 0: ms.append(m3 * mm)
    else: ms.append([0., 0., 0.])


# swave
def fs(r):
Exemplo n.º 8
0
def read_supercell_hamiltonian(input_file="hr_truncated.dat",
                               is_real=False,
                               nsuper=1):
    """Reads an output hamiltonian for a supercell from wannier"""
    mt = np.genfromtxt(input_file)  # get file
    m = mt.transpose()  # transpose matrix

    # read the hamiltonian matrices
    class Hopping:
        pass  # create empty class

    tlist = []

    def get_t(i, j, k):
        norb = int(np.max([np.max(np.abs(m[3])), np.max(np.abs(m[4]))]))
        mo = np.matrix(np.zeros((norb, norb), dtype=np.complex))
        for l in mt:  # look into the file
            if i == int(l[0]) and j == int(l[1]) and k == int(l[2]):
                if is_real:
                    mo[int(l[3]) - 1, int(l[4]) - 1] = l[5]  # store element
                else:
                    mo[int(l[3]) - 1,
                       int(l[4]) - 1] = l[5] + 1j * l[6]  # store element
        return mo  # return the matrix

    # this function will be called in a loop
    g = geometry.kagome_lattice()  # create geometry
    h = g.get_hamiltonian()  # build hamiltonian
    h.has_spin = False
    nstot = nsuper**2
    intra = [[None for i in range(nstot)] for j in range(nstot)]
    tx = [[None for i in range(nstot)] for j in range(nstot)]
    ty = [[None for i in range(nstot)] for j in range(nstot)]
    txy = [[None for i in range(nstot)] for j in range(nstot)]
    txmy = [[None for i in range(nstot)] for j in range(nstot)]
    from scipy.sparse import csc_matrix as csc
    vecs = []
    # create the identifacion vectors
    inds = []
    acu = 0
    try:  # read different supercells
        nsuperx = nsuper[0]
        nsupery = nsuper[1]
        nsuperz = nsuper[2]
    except:  # read different supercells
        nsuperx = nsuper
        nsupery = nsuper
        nsuperz = nsuper
    for i in range(nsuperx):  # loop over first replica
        for j in range(nsupery):  # loop over second replica
            vecs.append(np.array([i, j]))  # append vector
            inds.append(acu)
            acu += 1  # add one to the accumulator
    for i in inds:  # loop over first vector
        for j in inds:  # loop over second vector
            v1 = vecs[i]  # position of i esim cell
            v2 = vecs[j]  # position of j esim cell
            dv = v2 - v1  # difference in vector
            # get the different block elements
            intra[i][j] = csc(get_t(dv[0], dv[1], 0))
            tx[i][j] = csc(get_t(dv[0] + nsuper, dv[1], 0))
            ty[i][j] = csc(get_t(dv[0], dv[1] + nsuper, 0))
            txy[i][j] = csc(get_t(dv[0] + nsuper, dv[1] + nsuper, 0))
            txmy[i][j] = csc(get_t(dv[0] + nsuper, dv[1] - nsuper, 0))
    h.intra = bmat(intra).todense()
    h.tx = bmat(tx).todense()
    h.ty = bmat(ty).todense()
    h.txy = bmat(txy).todense()
    h.txmy = bmat(txmy).todense()
    h.geometry = read_geometry()  # read the geometry of the system
    if nsuper > 1:
        h.geometry = h.geometry.supercell(nsuper)  # create supercell
    if len(h.geometry.r) != len(h.intra):
        print("Dimensions do not match", len(g.r), len(h.intra))
        print(h.geometry.r)

#   raise # error if dimensions dont match
# names of the orbitals
    h.orbitals = get_all_orbitals() * nsuper**2

    return h
Exemplo n.º 9
0
def read_supercell_hamiltonian(input_file="hr_truncated.dat",is_real=False,nsuper=1):
  """Reads an output hamiltonian for a supercell from wannier"""
  mt = np.genfromtxt(input_file) # get file
  m = mt.transpose() # transpose matrix
  # read the hamiltonian matrices
  class Hopping: pass # create empty class
  tlist = []
  def get_t(i,j,k):
    norb = int(np.max([np.max(np.abs(m[3])),np.max(np.abs(m[4]))]))
    mo = np.matrix(np.zeros((norb,norb),dtype=np.complex))  
    for l in mt: # look into the file
      if i==int(l[0]) and j==int(l[1]) and k==int(l[2]):
        if is_real:
          mo[int(l[3])-1,int(l[4])-1] = l[5] # store element
        else:
          mo[int(l[3])-1,int(l[4])-1] = l[5] + 1j*l[6] # store element
    return mo # return the matrix
  # this function will be called in a loop
  g = geometry.kagome_lattice() # create geometry
  h = g.get_hamiltonian() # build hamiltonian
  h.has_spin = False
  nstot = nsuper**2
  intra = [[None for i in range(nstot)] for j in range(nstot)]
  tx = [[None for i in range(nstot)] for j in range(nstot)]
  ty = [[None for i in range(nstot)] for j in range(nstot)]
  txy = [[None for i in range(nstot)] for j in range(nstot)]
  txmy = [[None for i in range(nstot)] for j in range(nstot)]
  from scipy.sparse import csc_matrix as csc
  vecs = []
  # create the identifacion vectors
  inds = []
  acu = 0
  try: # read different supercells
    nsuperx = nsuper[0]
    nsupery = nsuper[1]
    nsuperz = nsuper[2]
  except: # read different supercells
    nsuperx = nsuper
    nsupery = nsuper
    nsuperz = nsuper
  for i in range(nsuperx): # loop over first replica
    for j in range(nsupery): # loop over second replica
      vecs.append(np.array([i,j])) # append vector
      inds.append(acu)
      acu += 1 # add one to the accumulator
  for i in inds: # loop over first vector
    for j in inds:  # loop over second vector
      v1 = vecs[i] # position of i esim cell
      v2 = vecs[j] # position of j esim cell
      dv = v2 - v1 # difference in vector
      # get the different block elements
      intra[i][j] = csc(get_t(dv[0],dv[1],0))
      tx[i][j] = csc(get_t(dv[0]+nsuper,dv[1],0))
      ty[i][j] = csc(get_t(dv[0],dv[1]+nsuper,0))
      txy[i][j] = csc(get_t(dv[0]+nsuper,dv[1]+nsuper,0))
      txmy[i][j] = csc(get_t(dv[0]+nsuper,dv[1]-nsuper,0))
  h.intra = bmat(intra).todense()
  h.tx = bmat(tx).todense()
  h.ty = bmat(ty).todense()
  h.txy = bmat(txy).todense()
  h.txmy = bmat(txmy).todense()
  h.geometry = read_geometry() # read the geometry of the system
  if nsuper>1:
    h.geometry = h.geometry.supercell(nsuper) # create supercell
  if len(h.geometry.r)!=len(h.intra): 
    print("Dimensions do not match",len(g.r),len(h.intra))
    print(h.geometry.r)
 #   raise # error if dimensions dont match
  # names of the orbitals
  h.orbitals = get_all_orbitals()*nsuper**2

  return h
Exemplo n.º 10
0
def read_supercell_hamiltonian(input_file="hr_truncated.dat",
                               is_real=False,
                               nsuper=1):
    """Reads an output hamiltonian for a supercell from wannier"""
    mt = np.genfromtxt(input_file)  # get file
    m = mt.transpose()  # transpose matrix

    # read the hamiltonian matrices
    class Hopping:
        pass  # create empty class

    tlist = []

    def get_t(i, j, k):
        norb = np.max([np.max(np.abs(m[3])), np.max(np.abs(m[4]))])
        mo = np.matrix(np.zeros((norb, norb), dtype=np.complex))
        for l in mt:  # look into the file
            if i == int(l[0]) and j == int(l[1]) and k == int(l[2]):
                if is_real:
                    mo[int(l[3]) - 1, int(l[4]) - 1] = l[5]  # store element
                else:
                    mo[int(l[3]) - 1,
                       int(l[4]) - 1] = l[5] + 1j * l[6]  # store element
        return mo  # return the matrix

    # the previous is not used yet...
    g = geometry.kagome_lattice()  # create geometry
    h = g.get_hamiltonian()  # build hamiltonian
    nstot = nsuper**2
    intra = [[None for i in range(nstot)] for j in range(nstot)]
    tx = [[None for i in range(nstot)] for j in range(nstot)]
    ty = [[None for i in range(nstot)] for j in range(nstot)]
    txy = [[None for i in range(nstot)] for j in range(nstot)]
    txmy = [[None for i in range(nstot)] for j in range(nstot)]
    from scipy.sparse import csc_matrix as csc
    vecs = []
    # create the identifacion vectors
    inds = []
    acu = 0
    for i in range(nsuper):  # loop over first replica
        for j in range(nsuper):  # loop over second replica
            vecs.append(np.array([i, j]))  # append vector
            inds.append(acu)
            acu += 1  # increase counter
    for i in inds:  # loop over first vector
        for j in inds:  # loop over second vector
            v1 = vecs[i]
            v2 = vecs[j]
            dv = v1 - v2  # difference in vector
            intra[i][j] = csc(get_t(dv[0], dv[1], 0))
            tx[i][j] = csc(get_t(dv[0] + 1, dv[1], 0))
            ty[i][j] = csc(get_t(dv[0], dv[1] + 1, 0))
            txy[i][j] = csc(get_t(dv[0] + 1, dv[1] + 1, 0))
            txmy[i][j] = csc(get_t(dv[0] + 1, dv[1] - 1, 0))
    h.intra = bmat(intra).todense()
    h.tx = bmat(tx).todense()
    h.ty = bmat(tx).todense()
    h.txy = bmat(txy).todense()
    h.txmy = bmat(txmy).todense()
    h.geometry = read_geometry()  # read the geometry of the system
    h.geometry = h.geometry.supercell(nsuper)  # create supercell
    if len(h.geometry.r) != len(h.intra):
        print "Dimensions do not match", len(g.r), len(h.intra)
        print h.geometry.r
        raise  # error if dimensions dont match
    return h
Exemplo n.º 11
0
def read_multicell_hamiltonian(input_file="hr_truncated.dat",
                                ncells=None,win_file="wannier.win",
                                dim=2,skip_win=False,path=None):
  """Reads an output hamiltonian from wannier"""
  if path is not None: 
      inipath = os.getcwd() # current path
      os.chdir(path) # go there
  mt = np.genfromtxt(input_file) # get file
  m = mt.transpose() # transpose matrix
  if ncells is None: # use all the hoppings
    nmax = int(np.max([np.max(m[i])for i in range(3)]))
    ncells = [nmax,nmax,nmax]
  # read the hamiltonian matrices
  class Hopping: pass # create empty class
  tlist = []
  def get_t(i,j,k):
    norb = np.max([np.max(np.abs(m[3])),np.max(np.abs(m[4]))])
    norb = int(norb)
    mo = np.matrix(np.zeros((norb,norb),dtype=np.complex))  
    found = False
    for l in mt: # look into the file
      if i==int(l[0]) and j==int(l[1]) and k==int(l[2]):
        mo[int(l[3])-1,int(l[4])-1] = l[5] + 1j*l[6] # store element
        found  = True # matrix has been found
    if found:  return mo # return the matrix
    else: return None # return nothing if not found
  for i in range(-ncells[0],ncells[0]+1):
    for j in range(-ncells[1],ncells[1]+1):
      for k in range(-ncells[2],ncells[2]+1):
        if (i,j,k)==(0,0,0): continue # skip intracell
        matrix = get_t(i,j,k) # read the matrix
        if matrix is None: continue
        else: # store hopping
          t = Hopping() # create hopping
          t.dir = [i,j,k] # direction
          t.m = get_t(i,j,k) # read the matrix
          tlist.append(t) # store hopping
  # the previous is not used yet...
  g = geometry.kagome_lattice() # create geometry
  h = g.get_hamiltonian() # build hamiltonian
  h.is_multicell = True
  if not skip_win: # do not skip wannier.win
    h.orbitals = get_all_orbitals(input_file=win_file)
  h.hopping = tlist # list of hoppings
  h.has_spin = False  # if not spin polarized
  if not skip_win: # do not skip readin wannier.win
    h.geometry = read_geometry(input_file=win_file) # read the geometry of the system
    h.geometry.center() # center the geometry
  h.intra = get_t(0,0,0)
  if not skip_win: # do not skip reading wannier.win
    if len(h.geometry.r)!=len(h.intra): 
      print("Dimensions do not match",len(g.r),len(h.intra))
      print(h.geometry.r)
  #  raise # error if dimensions dont match
  h.dimensionality = dim 
  if path is not None: 
      os.chdir(inipath) # go back
      h.wannierpath = path # store
    else: h.wannierpath = None
  # now lets add the SOC method
  def get_soc(self,name,soc):
      if not self.has_spin: raise # only for spinful
      self.intra = self.intra + generate_soc(name,soc,path=self.wannierpath) 
  import types
  h.get_soc = types.MethodType(get_soc,h) # add the method
  return h