def gett(r1, r2): """Return hopping given two sets of positions""" if not h.is_sparse: return create_fn_hopping(r1, r2) else: import neighbor pairs = neighbor.find_first_neighbor(r1, r2) if len(pairs) == 0: rows, cols = [], [] else: rows, cols = np.array(pairs).T # transpose data = np.array([1. for c in cols]) n = len(r1) return csc_matrix((data, (rows, cols)), shape=(n, n), dtype=np.complex)
def first_neighbors0d(h): """ Gets a first neighbor hamiltonian""" r = h.geometry.r # x coordinate if h.is_sparse: # for sparse matrix import neighbor pairs = neighbor.find_first_neighbor(r,r) rows,cols = pairs.T # transpose data = np.array([1. for c in cols]) n = len(r) h.intra = csc_matrix((data,(rows,cols)),shape=(n,n)) else: h.intra = create_fn_hopping(r,r) # intracell if h.has_spin: # if it has spin degree of freedom from increase_hilbert import m2spin h.intra = m2spin(h.intra,h.intra) # intracell term
def first_neighbors0d(h): """ Gets a first neighbor hamiltonian""" r = h.geometry.r # x coordinate if h.is_sparse: # for sparse matrix import neighbor pairs = neighbor.find_first_neighbor(r,r) rows,cols = pairs.T # transpose data = np.array([1. for c in cols]) n = len(r) h.intra = csc_matrix((data,(rows,cols)),shape=(n,n)) else: h.intra = create_fn_hopping(r,r) # intracell if h.has_spin: # if it has spin degree of freedom from increase_hilbert import m2spin h.intra = m2spin(h.intra,h.intra) # intracell term
def find_first_neighbor(x1,y1,x2,y2,optimal=False): """ Gets the first neighbors, returns a list of tuples """ if optimal: import neighbor pairs = neighbor.find_first_neighbor(x1,y1,x2,y2) else: from numpy import array n=len(x1) pairs = [] # pairs of neighbors for i in range(n): r1=array([x1[i],y1[i]]) for j in range(n): r2=array([x2[j],y2[j]]) if is_neigh(r1,r2,1.0,0.1): # check if distance is 1 pairs.append([i,j]) # add to the list return pairs # return pairs of first neighbors
def get_first_neighbors(r1,r2,optimal=optimal): """Gets the fist neighbors, input are arrays""" if optimal: import neighbor pairs = neighbor.find_first_neighbor(r1,r2) return pairs else: from numpy import array n=len(r1) pairs = [] # pairs of neighbors for i in range(n): ri=r1[i] for j in range(n): rj=r2[j] dr = ri - rj ; dr = dr.dot(dr) if .9<dr<1.1 : # check if distance is 1 pairs.append([i,j]) # add to the list return pairs # return pairs of first neighbors
def get_first_neighbors(r1,r2,optimal=optimal): """Gets the fist neighbors, input are arrays""" if optimal: import neighbor pairs = neighbor.find_first_neighbor(r1,r2) return pairs else: from numpy import array n=len(r1) pairs = [] # pairs of neighbors for i in range(n): ri=r1[i] for j in range(n): rj=r2[j] dr = ri - rj ; dr = dr.dot(dr) if .9<dr<1.1 : # check if distance is 1 pairs.append([i,j]) # add to the list return pairs # return pairs of first neighbors
def first_neighbors0d(h): """ Gets a first neighbor hamiltonian""" r = h.geometry.r # x coordinate import neighbor pairs = neighbor.find_first_neighbor(r, r) rows, cols = np.array(pairs).T # transpose data = np.array([1. for c in cols]) n = len(r) if h.has_spin: # spinful calculation data = np.concatenate([data, data]) rows = np.array(rows) rows = np.concatenate([2 * rows, 2 * rows + 1]) cols = np.array(cols) cols = np.concatenate([2 * cols, 2 * cols + 1]) n = n * 2 h.intra = csc_matrix((data, (rows, cols)), shape=(n, n), dtype=np.complex) if h.is_sparse: pass # for sparse matrix else: h.intra = h.intra.todense() # intracell
def first_neighbors0d(h): """ Gets a first neighbor hamiltonian""" r = h.geometry.r # x coordinate import neighbor pairs = neighbor.find_first_neighbor(r,r) rows,cols = np.array(pairs).T # transpose data = np.array([1. for c in cols]) n = len(r) if h.has_spin: # spinful calculation data = np.concatenate([data,data]) rows = np.array(rows) rows = np.concatenate([2*rows,2*rows+1]) cols = np.array(cols) cols = np.concatenate([2*cols,2*cols+1]) n = n*2 h.intra = csc_matrix((data,(rows,cols)),shape=(n,n),dtype=np.complex) if h.is_sparse: pass # for sparse matrix else: h.intra = h.intra.todense() # intracell
def setup_interaction(self, mode="Hubbard", g=1.0): """Create the operators that will determine the interactions""" if timing: t0 = time.clock() interactions = [] # empty list has_eh = self.hamiltonian.has_eh # has electron hole nat = self.sites # number of sites # self.correlator_mode = "1by1" # mode to calculate the correlators if has_eh: # for superconducting systems self.scfmode = "fermi" # SCF calculation fixing the fermi energy self.fermi = 0.0 # set the fermi energy in 0 if mode == "Hubbard" or mode == "U": # Hubbard model print("Adding Hubbard interaction") for i in range(nat): interactions.append( meanfield.hubbard_pairing_ud(i, nat, g=g)) interactions.append( meanfield.hubbard_pairing_du(i, nat, g=g)) elif mode == "V": # V interaction print("Adding V interaction") self.bloch_multicorrelator = True import neighbor # self.nkgrid = 1 # only implemented in Gamma point for d in self.hamiltonian.geometry.neighbor_directions( ): # loop ri = self.hamiltonian.geometry.r # positions rj = self.hamiltonian.geometry.replicas(d) # positions ijs = neighbor.find_first_neighbor(ri, rj) # return pairs if len(ijs) > 0: self.mf[tuple( d)] = self.hamiltonian.intra * 0. # initialize for (i, j) in ijs: # loop over pairs of sites # interactions.append(meanfield.v_pairing_du(i,j,nat,g=g,d=d)) # interactions.append(meanfield.v_pairing_du(j,i,nat,g=g,d=d)) interactions.append( meanfield.v_pairing_dd(i, j, nat, g=g, d=d, channel="ee")) interactions.append( meanfield.v_pairing_dd(i, j, nat, g=g, d=d, channel="hh")) interactions.append( meanfield.v_pairing_uu(i, j, nat, g=g, d=d, channel="ee")) interactions.append( meanfield.v_pairing_uu(i, j, nat, g=g, d=d, channel="hh")) else: # no electron hole symmetry if mode == "Hubbard" or mode == "U": # Hubbard model print("Adding Hubbard interaction") for i in range(nat): interactions.append(meanfield.hubbard_density(i, nat, g=g)) interactions.append(meanfield.hubbard_exchange(i, nat, g=g)) elif mode == "Hubbard collinear": # Hubbard model print("Adding Hubbard collinear interaction") for i in range(nat): interactions.append(meanfield.hubbard_density(i, nat, g=g)) # store this interaction elif mode == "V": # V interaction # self.correlator_mode = "1by1" # mode to calculate the correlators self.bloch_multicorrelator = True import neighbor # self.nkgrid = 1 # only implemented in Gamma point for d in self.hamiltonian.geometry.neighbor_directions( ): # loop ri = self.hamiltonian.geometry.r # positions rj = self.hamiltonian.geometry.replicas(d) # positions ijs = neighbor.find_first_neighbor(ri, rj) # return pairs if len(ijs) > 0: self.mf[tuple(d)] = 0.0j # initialize for (i, j) in ijs: # loop over pairs of sites if self.hamiltonian.has_spin: # spinful interactions.append( meanfield.v_ij(i, j, nat, g=g, d=d, spini=0, spinj=0)) interactions.append( meanfield.v_ij(i, j, nat, g=g, d=d, spini=0, spinj=1)) interactions.append( meanfield.v_ij(i, j, nat, g=g, d=d, spini=1, spinj=0)) interactions.append( meanfield.v_ij(i, j, nat, g=g, d=d, spini=1, spinj=1)) else: # spinless # factor 2 in g due to spin degree of freedom interactions.append( meanfield.v_ij_spinless(i, j, nat, g=2 * g, d=d)) else: raise # ups self.interactions += interactions # store list if timing: print("Time in creating MF operators", time.clock() - t0) self.setup_multicorrelator()
import geometry import hamiltonians g = geometry.honeycomb_lattice() g = g.supercell(20) g.dimensionality = 0 h = g.get_hamiltonian() h.remove_spin() import neighbor pairs = neighbor.find_first_neighbor(g.r,g.r) print pairs h.write()
def add_heisenberg(r): """Return pairs and js for a Heisenberg interaction""" pairs = neighbor.find_first_neighbor(r, r) js = np.array([iden for p in pairs]) # array return (pairs, js) # return pairs