Exemplo n.º 1
0
def lowest_bands(h,nkpoints=100,nbands=10,operator = None,info = False):
  """ Returns a figure with the bandstructure of the system"""
  from scipy.sparse import csc_matrix
  intra = csc_matrix(h.intra)
  t = csc_matrix(h.inter)
  k = np.arange(0.,1.,1./nkpoints) # list of kpoints
  import scipy.sparse.linalg as lg
  fo = open("BANDS.OUT","w")
  if operator==None: # if there is not an operator
    for ik in k:
      tk = t*np.exp(1j*2.*np.pi*ik)
      hk = intra +tk + tk.H
      eig,eigvec = lg.eigsh(hk,k=nbands,which="LM",sigma=0.0)
      for e in eig:
        fo.write(str(ik)+"     "+str(e)+"\n")
  else:  # if there is an operator
    for ik in k:
      tk = t*np.exp(1j*2.*np.pi*ik)
      hk = intra +tk + tk.H
      eig,eigvec = lg.eigsh(hk,k=nbands,which="LM",sigma=0.0)
      eigvec = eigvec.transpose() # tranpose the matrix
      if info:  print "Done",ik
      for (e,v) in zip(eig,eigvec): # loop over eigenvectors
        v = csc_matrix(v)
      #  print v.shape,type(v),operator.shape
        a = np.conjugate(v) * operator * v.T
        a = a.data[0]
        a = a.real # real part
      #  print a 
        fo.write(str(ik)+"     "+str(e)+"     "+str(a)+"\n")
  fo.close()
Exemplo n.º 2
0
def beam_FDM_eigs(L, N):
    x = np.linspace(0, L, N)
    dx = x[1] - x[0]
    stiff = np.diag(6*np.ones(N - 2)) -\
            np.diag(4*np.ones(N - 3), -1) - np.diag(4*np.ones(N - 3), 1) +\
            np.diag(1*np.ones(N - 4), 2) + np.diag(1*np.ones(N - 4), -2)
    vals, vecs = eigsh(stiff / dx**4)
    return vals, vecs, x
def get_eigvector(m):
    '''
    Return the eigenvector of the second smallest eigenvalue
    Noted that the return type is numpy.narray
    '''

    # v is the eigenvalue and d is the eigen matrix
    from scipy.sparse import linalg
    v,d=linalg.eigsh(A=m,k=2,which='SA')
Exemplo n.º 4
0
def lowest_bands(h,nkpoints=100,nbands=10,operator = None,
                   info = False,kpath = None):
  """ Returns a figure with the bandstructure of the system"""
  from scipy.sparse import csc_matrix
  if kpath is None: k = np.linspace(0.,1.,nkpoints) # list of kpoints
  else: k = kpath
  import scipy.sparse.linalg as lg
  import gc # garbage collector
  fo = open("BANDS.OUT","w")
  if operator is None: # if there is not an operator
    if h.dimensionality==0:  # dot
      eig,eigvec = lg.eigsh(csc_matrix(h.intra),k=nbands,which="LM",sigma=0.0)
      for i in range(len(eig)):
        fo.write(str(i)+"     "+str(eig[i])+"\n")
    if h.dimensionality==1:
      hkgen = h.get_hk_gen() # get generator
      for ik in k:  # ribbon
        hk = hkgen(ik) # get hamiltonians
        gc.collect() # clean memory
        eig,eigvec = lg.eigsh(hk,k=nbands,which="LM",sigma=0.0)
        del eigvec # clean eigenvectors
        del hk # clean hk
        for e in eig:
          fo.write(str(ik)+"     "+str(e)+"\n")
        if info:  print("Done",ik)
  else:  # if there is an operator
    if h.dimensionality==1:
      hkgen = h.get_hk_gen() # get generator
      for ik in k:
        hk = hkgen(ik) # get hamiltonians
        eig,eigvec = lg.eigsh(hk,k=nbands,which="LM",sigma=0.0)
        eigvec = eigvec.transpose() # tranpose the matrix
        if info:  print("Done",ik)
        for (e,v) in zip(eig,eigvec): # loop over eigenvectors
          v = csc_matrix(v)
        #  print v.shape,type(v),operator.shape
          a = np.conjugate(v) * operator * v.T
          a = a.data[0]
          a = a.real # real part
        #  print a 
          fo.write(str(ik)+"     "+str(e)+"     "+str(a)+"\n")
  fo.close()
Exemplo n.º 5
0
def lowest_bands(h,nkpoints=100,nbands=10,operator = None,
                   info = False,kpath = None):
  """ Returns a figure with the bandstructure of the system"""
  from scipy.sparse import csc_matrix
  if kpath is None: k = np.linspace(0.,1.,nkpoints) # list of kpoints
  else: k = kpath
  import scipy.sparse.linalg as lg
  import gc # garbage collector
  fo = open("BANDS.OUT","w")
  if operator==None: # if there is not an operator
    if h.dimensionality==0:  # dot
      eig,eigvec = lg.eigsh(csc_matrix(h.intra),k=nbands,which="LM",sigma=0.0)
      for i in range(len(eig)):
        fo.write(str(i)+"     "+str(eig[i])+"\n")
    if h.dimensionality==1:
      hkgen = h.get_hk_gen() # get generator
      for ik in k:  # ribbon
        hk = hkgen(ik) # get hamiltonians
        gc.collect() # clean memory
        eig,eigvec = lg.eigsh(hk,k=nbands,which="LM",sigma=0.0)
        del eigvec # clean eigenvectors
        del hk # clean hk
        for e in eig:
          fo.write(str(ik)+"     "+str(e)+"\n")
        if info:  print("Done",ik)
  else:  # if there is an operator
    if h.dimensionality==1:
      hkgen = h.get_hk_gen() # get generator
      for ik in k:
        hk = hkgen(ik) # get hamiltonians
        eig,eigvec = lg.eigsh(hk,k=nbands,which="LM",sigma=0.0)
        eigvec = eigvec.transpose() # tranpose the matrix
        if info:  print("Done",ik)
        for (e,v) in zip(eig,eigvec): # loop over eigenvectors
          v = csc_matrix(v)
        #  print v.shape,type(v),operator.shape
          a = np.conjugate(v) * operator * v.T
          a = a.data[0]
          a = a.real # real part
        #  print a 
          fo.write(str(ik)+"     "+str(e)+"     "+str(a)+"\n")
  fo.close()
Exemplo n.º 6
0
def states0d(h,ewindow=[-.5,.5]):
  """Write in files the different states"""
  if not h.dimensionality==0: raise
  (evals,evecs) = lg.eigsh(h.intra)
  evecs = evecs.transpose() # transpose list
  for i in range(len(evals)):
    if ewindow[0]<evals[i]<ewindow[1]: # if in the interval
      den = np.abs(evecs[i])**2
      den = spatial_wave(h,den) # resum if other degrees of freedom
      name "WAVE_"+str(i)+".OUT"
      write_wave(h.geometry.x,h.geometry.y,den,output_file=name)
Exemplo n.º 7
0
def lowest_bands(h,nkpoints=100,nbands=10,operator = None):
  """ Returns a figure with the bandstructure of the system"""
  from scipy.sparse import csc_matrix
  intra = csc_matrix(h.intra)
  t = csc_matrix(h.inter)
  k = np.arange(0.,1.,1./nkpoints) # list of kpoints
  import scipy.sparse.linalg as lg
  fo = open("BANDS.OUT","w")
  if operator==None: # if there is not an operator
    for ik in k:
      tk = t*np.exp(1j*2.*np.pi*ik)
      hk = intra +tk + tk.H
      eig,eigvec = lg.eigsh(hk,k=nbands,which="LM",sigma=0.0)
      for e in eig:
        fo.write(str(ik)+"     "+str(e)+"\n")
  else:  # if there is an operator
      tk = t*np.exp(1j*2.*np.pi*ik)
      hk = intra +tk + tk.H
      eig,eigvec = lg.eigsh(hk,k=nbands,which="LM",sigma=0.0)
      for e in eig:
        fo.write(str(ik)+"     "+str(e)+"\n")
  fo.close()
Exemplo n.º 8
0
def lowest_bands(h,nkpoints=100,nbands=10,operator = None,info = False):
  """ Returns a figure with the bandstructure of the system"""
  from scipy.sparse import csc_matrix
  intra = csc_matrix(h.intra)
  t = csc_matrix(h.inter)
  k = np.arange(0.,1.,1./nkpoints) # list of kpoints
  import scipy.sparse.linalg as lg
  fo = open("BANDS.OUT","w")
  if operator==None: # if there is not an operator
    if h.dimensionality==0:  # dot
      eig,eigvec = lg.eigsh(csc_matrix(h.intra),k=nbands,which="LM",sigma=0.0)
      for i in range(len(eig)):
        fo.write(str(i)+"     "+str(eig[i])+"\n")


    if h.dimensionality==1:
      for ik in k:  # ribbon
        tk = t*np.exp(1j*2.*np.pi*ik)
        hk = intra +tk + tk.H
        eig,eigvec = lg.eigsh(hk,k=nbands,which="LM",sigma=0.0)
        for e in eig:
          fo.write(str(ik)+"     "+str(e)+"\n")
  else:  # if there is an operator
    if h.dimensionality==1:
      for ik in k:
        tk = t*np.exp(1j*2.*np.pi*ik)
        hk = intra +tk + tk.H
        eig,eigvec = lg.eigsh(hk,k=nbands,which="LM",sigma=0.0)
        eigvec = eigvec.transpose() # tranpose the matrix
        if info:  print "Done",ik
        for (e,v) in zip(eig,eigvec): # loop over eigenvectors
          v = csc_matrix(v)
        #  print v.shape,type(v),operator.shape
          a = np.conjugate(v) * operator * v.T
          a = a.data[0]
          a = a.real # real part
        #  print a 
          fo.write(str(ik)+"     "+str(e)+"     "+str(a)+"\n")
  fo.close()
Exemplo n.º 9
0
def eigenvalues(hetero, numeig=10, effective=False, gf=None, full=False):
    """ Gets the lowest eigenvalues of the central part of the hamiltonian"""
    if not hetero.block_diagonal:
        print(""" heterounction in eigenvalues must be block diagonal""")
        raise
    # if effective hamiltonian, just calculate the eigenvalues
    if effective:  # effective hamiltonian
        print("Calculating eigenvalues of effective hamiltonian...")
        if hetero.heff is None:  #if hasn't been calculated so far
            effective_central_hamiltonian(hetero, write=False)
        heff = hetero.heff  # store the list of list with central EFF ham
        import scipy.sparse.linalg as lg
        eig, eigvec = lg.eigs(heff, k=numeig, which="LM", sigma=0.0)
        return eig

    from scipy.sparse import csc_matrix, bmat
    import scipy.sparse.linalg as lg
    if not effective:  # do not use the effective hamiltonian, only the central
        intra = hetero.central_intra  # store the list of list with central ham
    numb = len(intra)  # number of central blocks
    intrasp = [[None for i in range(numb)] for j in range(numb)]
    # assign onsite and couplings in sparse form
    if not hetero.is_sparse:
        for i in range(numb):
            intrasp[i][i] = csc_matrix(intra[i][i])
        for i in range(numb - 1):
            intrasp[i][i + 1] = csc_matrix(intra[i][i + 1])
            intrasp[i + 1][i] = csc_matrix(intra[i + 1][i])
    if hetero.is_sparse:
        for i in range(numb):
            intrasp[i][i] = intra[i][i]
        for i in range(numb - 1):
            intrasp[i][i + 1] = intra[i][i + 1]
            intrasp[i + 1][i] = intra[i + 1][i]
    intrasp = bmat(intrasp)  # create sparse matrix
    if effective:
        evals, evecs = lg.eigs(intrasp, k=numeig, which="LM", sigma=0.0)
    if not effective:
        if full:  # full diagonalization
            from scipy.linalg import eigvalsh
            evals = eigvalsh(intrasp.todense())
        else:
            evals, evecs = lg.eigsh(intrasp, k=numeig, which="LM", sigma=0.0)
    return evals