def reduce_k(self,Cfunc,klist): ''' Get the new C+\dag C type operator(like non-interacting Hamiltonian) for specific k. Parameters: :Cfunc: function, Cfunc(k) gives the expectation matrix at k. :klist: ndarray(Nk,vdim), the k-space. Return: The reduced operator. ''' nband=Cfunc(zeros(2)).shape[-1] ncell=prod(self.size) offsets=self.offsets.reshape([-1,self.lattice.dimension]) slist=offsets[:,0,newaxis]*self.lattice.a[0]+offsets[:,1,newaxis]*self.lattice.a[1] #get the equivalent k-points. b=toreciprocal(self.lattice.a*self.L[:,newaxis]) Q=(b[0]+b[1])/2. equivk=meshgrid_v([arange(l) for l in self.L],vecs=b).reshape([-1,b.shape[-1]]) if self.form=='x': equivk=concatenate([equivk,equivk+Q]) #calculate C matrix. C=ndarray([len(klist),ncell,ncell,nband,nband],dtype=complex128) for ik,k in enumerate(klist): print '@%s'%ik cs=[Cfunc(k+q) for q in equivk] for s1 in xrange(ncell): for s2 in xrange(ncell): C[ik,s1,s2]=sum([ci*exp(1j*(k+q).dot(slist[s2]-slist[s1])) for ci,q in zip(cs,equivk)],axis=0)/prod(self.L)/(1. if self.form=='#' else 2.) return swapaxes(C,2,3).reshape([len(klist),ncell*nband,ncell*nband])
def get_kspace(self): ''' Get the new k space. ''' a=self.lattice.a L=self.L if self.form=='x': a=array([L[0]*a[0]+L[1]*a[1],L[0]*a[0]-L[1]*a[1]]) else: a=array([L[0]*a[0],L[1]*a[1]]) b=toreciprocal(a) ks=KSpace(b,N=self.lattice.N/L) ks.special_points['X']=array([b[0]/2.,b[1]/2.,-b[0]/2.,-b[1]/2.]) ks.special_points['M']=array([(b[0]+b[1])/2.,(b[0]-b[1])/2.,(-b[0]-b[1])/2.,(-b[0]+b[1])/2.]) return ks