def __init__(self, S, BuildMasterOnly=True): """ Construction : with named arguments only. Possible constructors from source S : - Parameters(d) : d is a dict to be copied (no deepcopy, just updated). - Parameters(f) : f is a string containing the path of a file The type of the file is determined from the extension: - .py, .txt : the file is executed in the Parameters - .xml : to be written MPI : if BuildMasterOnly is true, the contruction is only made on the master, the result is then bcasted to all the nodes. Otherwise, it is done on all nodes (not recommended to read files). """ if MPI.IS_MASTER_NODE() or not BuildMasterOnly: if type(S) == type(''): # detect the type of the file try: extension = S.split('.')[-1].lower() except IndexError: raise ValueError, "I am lost : I can not determine the extension of the file !" if extension in ['py', 'txt']: execfile(S, {}, self) else: raise ValueError, "Extension of the file not recognized" else: # S is therefore a dict try: self.update(S) except: print "Error in Parameter constructor. Is the source an iterable ?" raise # end of master only if BuildMasterOnly: MPI.bcast(self) # bcast it on the nodes
def __should_continue(self,N_Iter_SelfCons_Max) : """ stop test""" should_continue = True if MPI.IS_MASTER_NODE(): if (self.Iteration_Number > N_Iter_SelfCons_Max): should_continue = False should_continue = MPI.bcast(should_continue) return should_continue
def __init__(self, HDFfile, subgroup=None): """Initialises the class. Reads the permutations and rotation matrizes from the file, and constructs the mapping for the given orbitals. For each orbit a matrix is read!!! SO: Flag for SO coupled calculations. SP: Spin polarisation yes/no """ assert type(HDFfile) == StringType, "HDFfile must be a filename" self.HDFfile = HDFfile thingstoread = [ 'Ns', 'Natoms', 'perm', 'orbits', 'SO', 'SP', 'timeinv', 'mat', 'mat_tinv' ] for it in thingstoread: exec "self.%s = 0" % it if (MPI.IS_MASTER_NODE()): #Read the stuff on master: ar = HDF_Archive(HDFfile, 'a') if (subgroup is None): ar2 = ar else: ar2 = ar[subgroup] for it in thingstoread: exec "self.%s = ar2['%s']" % (it, it) del ar2 del ar #broadcasting for it in thingstoread: exec "self.%s = MPI.bcast(self.%s)" % (it, it) # now define the mapping of orbitals: # self.map[iorb]=jorb gives the permutation of the orbitals as given in the list, when the # permutation of the atoms is done: self.N_orbits = len(self.orbits) self.map = [[0 for iorb in range(self.N_orbits)] for iNs in range(self.Ns)] for iNs in range(self.Ns): for iorb in range(self.N_orbits): srch = copy.deepcopy(self.orbits[iorb]) srch[0] = self.perm[iNs][self.orbits[iorb][0] - 1] self.map[iNs][iorb] = self.orbits.index(srch)
def __repack(self): """Calls the h5repack routine, in order to reduce the file size of the hdf5 archive. Should only be used BEFORE the first invokation of HDF_Archive in the program, otherwise the hdf5 linking is broken!!!""" import subprocess if not (MPI.IS_MASTER_NODE()): return MPI.report("Repacking the file %s" % self.HDFfile) retcode = subprocess.call( ["h5repack", "-i%s" % self.HDFfile, "-otemphgfrt.h5"]) if (retcode != 0): MPI.report("h5repack failed!") else: subprocess.call(["mv", "-f", "temphgfrt.h5", "%s" % self.HDFfile])
N_Legendre_Coeffs=50, # Number of Legendre coefficients Random_Generator_Name='mt19937', # Name of the random number generator Use_Segment_Picture=True, # Use the segment picture Measured_Operators={ # Operators to be averaged 'Nimp': N('up', 1) + N('down', 1) }, Global_Moves=[ # Global move in the QMC (0.05, lambda (a, alpha, dag): ({ 'up': 'down', 'down': 'up' }[a], alpha, dag)) ], ) # Initialize the non-interacting Green's function S.G0 for spin, g0 in S.G0: g0 <<= inverse(iOmega_n - e_f - V**2 * Wilson(D)) # Run the solver. The result will be in S.G S.Solve() # Save the results in an hdf5 file (only on the master node) from pytriqs.Base.Archive import HDF_Archive import pytriqs.Base.Utility.MPI as MPI if MPI.IS_MASTER_NODE(): Results = HDF_Archive("solution.h5", 'w') Results["G"] = S.G Results["Gl"] = S.G_Legendre Results["Nimp"] = S.Measured_Operators_Results['Nimp']
def convert_DMFT_input(self): """ Reads the input files, and stores the data in the HDFfile """ if not (MPI.IS_MASTER_NODE()): return # do it only on master: MPI.report("Reading input from %s..." % self.LDA_file) # Read and write only on Master!!! # R is a generator : each R.Next() will return the next number in the file R = Read_Fortran_File(self.LDA_file) try: EnergyUnit = R.next() # read the energy convertion factor Nk = int(R.next()) # read the number of k points k_dep_projection = 1 SP = int(R.next()) # flag for spin-polarised calculation SO = int(R.next()) # flag for spin-orbit calculation charge_below = R.next() # total charge below energy window Density_Required = R.next( ) # total density required, for setting the chemical potential symm_op = 1 # Use symmetry groups for the k-sum # the information on the non-correlated shells is not important here, maybe skip: N_shells = int(R.next( )) # number of shells (e.g. Fe d, As p, O p) in the unit cell, # corresponds to index R in formulas # now read the information about the shells: shells = [[int(R.next()) for i in range(4)] for icrsh in range(N_shells) ] # reads iatom, sort, l, dim N_corr_shells = int(R.next( )) # number of corr. shells (e.g. Fe d, Ce f) in the unit cell, # corresponds to index R in formulas # now read the information about the shells: corr_shells = [[int(R.next()) for i in range(6)] for icrsh in range(N_corr_shells) ] # reads iatom, sort, l, dim, SO flag, irep self.inequiv_shells( corr_shells ) # determine the number of inequivalent correlated shells, has to be known for further reading... use_rotations = 1 rotmat = [ numpy.identity(corr_shells[icrsh][3], numpy.complex_) for icrsh in xrange(N_corr_shells) ] # read the matrices rotmat_timeinv = [0 for i in range(N_corr_shells)] for icrsh in xrange(N_corr_shells): for i in xrange(corr_shells[icrsh][3]): # read real part: for j in xrange(corr_shells[icrsh][3]): rotmat[icrsh][i, j] = R.next() for i in xrange(corr_shells[icrsh][3]): # read imaginary part: for j in xrange(corr_shells[icrsh][3]): rotmat[icrsh][i, j] += 1j * R.next() if (SP == 1): # read time inversion flag: rotmat_timeinv[icrsh] = int(R.next()) # Read here the infos for the transformation of the basis: Nreps = [1 for i in range(self.N_inequiv_corr_shells)] dim_reps = [0 for i in range(self.N_inequiv_corr_shells)] T = [] for icrsh in range(self.N_inequiv_corr_shells): Nreps[icrsh] = int(R.next( )) # number of representatives ("subsets"), e.g. t2g and eg dim_reps[icrsh] = [int(R.next()) for i in range(Nreps[icrsh]) ] # dimensions of the subsets # The transformation matrix: # it is of dimension 2l+1, if no SO, and 2*(2l+1) with SO!! #T = [] #for ish in xrange(self.N_inequiv_corr_shells): ll = 2 * corr_shells[self.invshellmap[icrsh]][2] + 1 lmax = ll * (corr_shells[self.invshellmap[icrsh]][4] + 1) T.append(numpy.zeros([lmax, lmax], numpy.complex_)) # now read it from file: for i in xrange(lmax): for j in xrange(lmax): T[icrsh][i, j] = R.next() for i in xrange(lmax): for j in xrange(lmax): T[icrsh][i, j] += 1j * R.next() # Spin blocks to be read: Nspinblocs = SP + 1 - SO # number of spins to read for Norbs and Ham, NOT Projectors # read the list of N_Orbitals for all k points N_Orbitals = [[0 for isp in range(Nspinblocs)] for ik in xrange(Nk)] for isp in range(Nspinblocs): for ik in xrange(Nk): N_Orbitals[ik][isp] = int(R.next()) #print N_Orbitals # Initialise the projectors: Proj_Mat = [[[ numpy.zeros([corr_shells[icrsh][3], N_Orbitals[ik][isp]], numpy.complex_) for icrsh in range(N_corr_shells) ] for isp in range(Nspinblocs)] for ik in range(Nk)] # Read the projectors from the file: for ik in xrange(Nk): for icrsh in range(N_corr_shells): no = corr_shells[icrsh][3] # first Real part for BOTH spins, due to conventions in dmftproj: for isp in range(Nspinblocs): for i in xrange(no): for j in xrange(N_Orbitals[ik][isp]): Proj_Mat[ik][isp][icrsh][i, j] = R.next() # now Imag part: for isp in range(Nspinblocs): for i in xrange(no): for j in xrange(N_Orbitals[ik][isp]): Proj_Mat[ik][isp][icrsh][i, j] += 1j * R.next() # now define the arrays for weights and hopping ... BZ_weights = numpy.ones([Nk], numpy.float_) / float( Nk) # w(k_index), default normalisation Hopping = [[ numpy.zeros([N_Orbitals[ik][isp], N_Orbitals[ik][isp]], numpy.complex_) for isp in range(Nspinblocs) ] for ik in xrange(Nk)] # weights in the file for ik in xrange(Nk): BZ_weights[ik] = R.next() # if the sum over spins is in the weights, take it out again!! sm = sum(BZ_weights) BZ_weights[:] /= sm # Grab the H # we use now the convention of a DIAGONAL Hamiltonian!!!! for isp in range(Nspinblocs): for ik in xrange(Nk): no = N_Orbitals[ik][isp] for i in xrange(no): Hopping[ik][isp][i, i] = R.next() * EnergyUnit #keep some things that we need for reading parproj: self.N_shells = N_shells self.shells = shells self.N_corr_shells = N_corr_shells self.corr_shells = corr_shells self.Nspinblocs = Nspinblocs self.N_Orbitals = N_Orbitals self.Nk = Nk self.SO = SO self.SP = SP self.EnergyUnit = EnergyUnit except StopIteration: # a more explicit error if the file is corrupted. raise "SumK_LDA : reading file HMLT_file failed!" R.close() #print Proj_Mat[0] #----------------------------------------- # Store the input into HDF5: ar = HDF_Archive(self.HDFfile, 'a') if not (self.LDASubGrp in ar): ar.create_group(self.LDASubGrp) # The subgroup containing the data. If it does not exist, it is created. # If it exists, the data is overwritten!!! ar[self.LDASubGrp]['EnergyUnit'] = EnergyUnit ar[self.LDASubGrp]['Nk'] = Nk ar[self.LDASubGrp]['k_dep_projection'] = k_dep_projection ar[self.LDASubGrp]['SP'] = SP ar[self.LDASubGrp]['SO'] = SO ar[self.LDASubGrp]['charge_below'] = charge_below ar[self.LDASubGrp]['Density_Required'] = Density_Required ar[self.LDASubGrp]['symm_op'] = symm_op ar[self.LDASubGrp]['N_shells'] = N_shells ar[self.LDASubGrp]['shells'] = shells ar[self.LDASubGrp]['N_corr_shells'] = N_corr_shells ar[self.LDASubGrp]['corr_shells'] = corr_shells ar[self.LDASubGrp]['use_rotations'] = use_rotations ar[self.LDASubGrp]['rotmat'] = rotmat ar[self.LDASubGrp]['rotmat_timeinv'] = rotmat_timeinv ar[self.LDASubGrp]['Nreps'] = Nreps ar[self.LDASubGrp]['dim_reps'] = dim_reps ar[self.LDASubGrp]['T'] = T ar[self.LDASubGrp]['N_Orbitals'] = N_Orbitals ar[self.LDASubGrp]['Proj_Mat'] = Proj_Mat ar[self.LDASubGrp]['BZ_weights'] = BZ_weights ar[self.LDASubGrp]['Hopping'] = Hopping del ar # Symmetries are used, # Now do the symmetries for correlated orbitals: self.read_Symmetry_input(orbits=corr_shells, symmfile=self.Symm_file, SymmSubGrp=self.SymmSubGrp, SO=SO, SP=SP)
def read_Symmetry_input(self, orbits, symmfile, SymmSubGrp, SO, SP): """ Reads input for the symmetrisations from symmfile, which is case.sympar or case.symqmc. """ if not (MPI.IS_MASTER_NODE()): return MPI.report("Reading symmetry input from %s..." % symmfile) N_orbits = len(orbits) R = Read_Fortran_File(symmfile) try: Ns = int(R.next()) # Number of symmetry operations Natoms = int(R.next()) # number of atoms involved perm = [[int(R.next()) for i in xrange(Natoms)] for j in xrange(Ns)] # list of permutations of the atoms if SP: timeinv = [int(R.next()) for j in xrange(Ns) ] # timeinversion for SO xoupling else: timeinv = [0 for j in xrange(Ns)] # Now read matrices: mat = [] for iNs in xrange(Ns): mat.append([ numpy.zeros([orbits[orb][3], orbits[orb][3]], numpy.complex_) for orb in xrange(N_orbits) ]) for orb in range(N_orbits): for i in xrange(orbits[orb][3]): for j in xrange(orbits[orb][3]): mat[iNs][orb][i, j] = R.next() # real part for i in xrange(orbits[orb][3]): for j in xrange(orbits[orb][3]): mat[iNs][orb][i, j] += 1j * R.next() # imaginary part # determine the inequivalent shells: #SHOULD BE FINALLY REMOVED, PUT IT FOR ALL ORBITALS!!!!! #self.inequiv_shells(orbits) mat_tinv = [ numpy.identity(orbits[orb][3], numpy.complex_) for orb in range(N_orbits) ] if ((SO == 0) and (SP == 0)): # here we need an additional time inversion operation, so read it: for orb in range(N_orbits): for i in xrange(orbits[orb][3]): for j in xrange(orbits[orb][3]): mat_tinv[orb][i, j] = R.next() # real part for i in xrange(orbits[orb][3]): for j in xrange(orbits[orb][3]): mat_tinv[orb][i, j] += 1j * R.next() # imaginary part except StopIteration: # a more explicit error if the file is corrupted. raise "Symmetry : reading file failed!" R.close() # Save it to the HDF: ar = HDF_Archive(self.HDFfile, 'a') if not (SymmSubGrp in ar): ar.create_group(SymmSubGrp) thingstowrite = [ 'Ns', 'Natoms', 'perm', 'orbits', 'SO', 'SP', 'timeinv', 'mat', 'mat_tinv' ] for it in thingstowrite: exec "ar['%s']['%s'] = %s" % (SymmSubGrp, it, it) del ar
def convert_bands_input(self, BandsSubGrp='SumK_LDA_Bands'): """ Converts the input for momentum resolved spectral functions, and stores it in BandsSubGrp in the HDF5. """ if not (MPI.IS_MASTER_NODE()): return self.BandsSubGrp = BandsSubGrp MPI.report("Reading bands input from %s..." % self.Band_file) R = Read_Fortran_File(self.Band_file) try: Nk = int(R.next()) # read the list of N_Orbitals for all k points N_Orbitals = [[0 for isp in range(self.Nspinblocs)] for ik in xrange(Nk)] for isp in range(self.Nspinblocs): for ik in xrange(Nk): N_Orbitals[ik][isp] = int(R.next()) # Initialise the projectors: Proj_Mat = [[[ numpy.zeros([self.corr_shells[icrsh][3], N_Orbitals[ik][isp]], numpy.complex_) for icrsh in range(self.N_corr_shells) ] for isp in range(self.Nspinblocs)] for ik in range(Nk)] # Read the projectors from the file: for ik in xrange(Nk): for icrsh in range(self.N_corr_shells): no = self.corr_shells[icrsh][3] # first Real part for BOTH spins, due to conventions in dmftproj: for isp in range(self.Nspinblocs): for i in xrange(no): for j in xrange(N_Orbitals[ik][isp]): Proj_Mat[ik][isp][icrsh][i, j] = R.next() # now Imag part: for isp in range(self.Nspinblocs): for i in xrange(no): for j in xrange(N_Orbitals[ik][isp]): Proj_Mat[ik][isp][icrsh][i, j] += 1j * R.next() Hopping = [[ numpy.zeros([N_Orbitals[ik][isp], N_Orbitals[ik][isp]], numpy.complex_) for isp in range(self.Nspinblocs) ] for ik in xrange(Nk)] # Grab the H # we use now the convention of a DIAGONAL Hamiltonian!!!! for isp in range(self.Nspinblocs): for ik in xrange(Nk): no = N_Orbitals[ik][isp] for i in xrange(no): Hopping[ik][isp][i, i] = R.next() * self.EnergyUnit # now read the partial projectors: N_parproj = [int(R.next()) for i in range(self.N_shells)] # Initialise P, here a double list of matrices: Proj_Mat_pc = [[[[ numpy.zeros([self.shells[ish][3], N_Orbitals[ik][isp]], numpy.complex_) for ir in range(N_parproj[ish]) ] for ish in range(self.N_shells)] for isp in range(self.Nspinblocs)] for ik in range(Nk)] for ish in range(self.N_shells): for ik in xrange(Nk): for ir in range(N_parproj[ish]): for isp in range(self.Nspinblocs): for i in xrange( self.shells[ish][3]): # read real part: for j in xrange(N_Orbitals[ik][isp]): Proj_Mat_pc[ik][isp][ish][ir][ i, j] = R.next() for i in xrange(self.shells[ish] [3]): # read imaginary part: for j in xrange(N_Orbitals[ik][isp]): Proj_Mat_pc[ik][isp][ish][ir][ i, j] += 1j * R.next() except StopIteration: # a more explicit error if the file is corrupted. raise "SumK_LDA : reading file HMLT_file failed!" R.close() # reading done! #----------------------------------------- # Store the input into HDF5: ar = HDF_Archive(self.HDFfile, 'a') if not (self.BandsSubGrp in ar): ar.create_group(self.BandsSubGrp) # The subgroup containing the data. If it does not exist, it is created. # If it exists, the data is overwritten!!! thingstowrite = [ 'Nk', 'N_Orbitals', 'Proj_Mat', 'Hopping', 'N_parproj', 'Proj_Mat_pc' ] for it in thingstowrite: exec "ar['%s']['%s'] = %s" % (self.BandsSubGrp, it, it) #ar[self.BandsSubGrp]['Nk'] = Nk #ar[self.BandsSubGrp]['N_Orbitals'] = N_Orbitals #ar[self.BandsSubGrp]['Proj_Mat'] = Proj_Mat #self.Proj_Mat = Proj_Mat #self.N_Orbitals = N_Orbitals #self.Nk = Nk #self.Hopping = Hopping del ar
def convert_Parproj_input(self, ParProjSubGrp='SumK_LDA_ParProj', SymmParSubGrp='SymmPar'): """ Reads the input for the partial charges projectors from case.parproj, and stores it in the SymmParSubGrp group in the HDF5. """ if not (MPI.IS_MASTER_NODE()): return self.ParProjSubGrp = ParProjSubGrp self.SymmParSubGrp = SymmParSubGrp MPI.report("Reading parproj input from %s..." % self.Parproj_file) Dens_Mat_below = [[ numpy.zeros([self.shells[ish][3], self.shells[ish][3]], numpy.complex_) for ish in range(self.N_shells) ] for isp in range(self.Nspinblocs)] R = Read_Fortran_File(self.Parproj_file) #try: N_parproj = [int(R.next()) for i in range(self.N_shells)] # Initialise P, here a double list of matrices: Proj_Mat_pc = [[[[ numpy.zeros([self.shells[ish][3], self.N_Orbitals[ik][isp]], numpy.complex_) for ir in range(N_parproj[ish]) ] for ish in range(self.N_shells)] for isp in range(self.Nspinblocs)] for ik in range(self.Nk)] rotmat_all = [ numpy.identity(self.shells[ish][3], numpy.complex_) for ish in xrange(self.N_shells) ] rotmat_all_timeinv = [0 for i in range(self.N_shells)] for ish in range(self.N_shells): #print ish # read first the projectors for this orbital: for ik in xrange(self.Nk): for ir in range(N_parproj[ish]): for isp in range(self.Nspinblocs): for i in xrange( self.shells[ish][3]): # read real part: for j in xrange(self.N_Orbitals[ik][isp]): Proj_Mat_pc[ik][isp][ish][ir][i, j] = R.next() for isp in range(self.Nspinblocs): for i in xrange( self.shells[ish][3]): # read imaginary part: for j in xrange(self.N_Orbitals[ik][isp]): Proj_Mat_pc[ik][isp][ish][ir][ i, j] += 1j * R.next() # now read the Density Matrix for this orbital below the energy window: for isp in range(self.Nspinblocs): for i in xrange(self.shells[ish][3]): # read real part: for j in xrange(self.shells[ish][3]): Dens_Mat_below[isp][ish][i, j] = R.next() for isp in range(self.Nspinblocs): for i in xrange(self.shells[ish][3]): # read imaginary part: for j in xrange(self.shells[ish][3]): Dens_Mat_below[isp][ish][i, j] += 1j * R.next() if (self.SP == 0): Dens_Mat_below[isp][ish] /= 2.0 # Global -> local rotation matrix for this shell: for i in xrange(self.shells[ish][3]): # read real part: for j in xrange(self.shells[ish][3]): rotmat_all[ish][i, j] = R.next() for i in xrange(self.shells[ish][3]): # read imaginary part: for j in xrange(self.shells[ish][3]): rotmat_all[ish][i, j] += 1j * R.next() #print Dens_Mat_below[0][ish],Dens_Mat_below[1][ish] if (self.SP): rotmat_all_timeinv[ish] = int(R.next()) #except StopIteration : # a more explicit error if the file is corrupted. # raise "SumK_LDA_Wien2k_input: reading file for Projectors failed!" R.close() #----------------------------------------- # Store the input into HDF5: ar = HDF_Archive(self.HDFfile, 'a') if not (self.ParProjSubGrp in ar): ar.create_group(self.ParProjSubGrp) # The subgroup containing the data. If it does not exist, it is created. # If it exists, the data is overwritten!!! thingstowrite = [ 'Dens_Mat_below', 'N_parproj', 'Proj_Mat_pc', 'rotmat_all', 'rotmat_all_timeinv' ] for it in thingstowrite: exec "ar['%s']['%s'] = %s" % (self.ParProjSubGrp, it, it) del ar # Symmetries are used, # Now do the symmetries for all orbitals: self.read_Symmetry_input(orbits=self.shells, symmfile=self.Symmpar_file, SymmSubGrp=self.SymmParSubGrp, SO=self.SO, SP=self.SP)
def spaghettis(self, broadening, shift=0.0, plotrange=None, ishell=None, invertAkw=False, Fermisurface=False): """ Calculates the correlated band structure with a real-frequency self energy. ATTENTION: Many things from the original input file are are overwritten!!!""" assert hasattr(self, "Sigmaimp"), "Set Sigma First!!" thingstoread = [ 'Nk', 'N_Orbitals', 'Proj_Mat', 'Hopping', 'N_parproj', 'Proj_Mat_pc' ] retval = self.read_input_from_HDF(SubGrp=self.Bandsdata, thingstoread=thingstoread) if not retval: return retval if Fermisurface: ishell = None # print hamiltonian for checks: if ((self.SP == 1) and (self.SO == 0)): f1 = open('hamup.dat', 'w') f2 = open('hamdn.dat', 'w') for ik in xrange(self.Nk): for i in xrange(self.N_Orbitals[ik][0]): f1.write('%s %s\n' % (ik, self.Hopping[ik][0][i, i].real)) for i in xrange(self.N_Orbitals[ik][1]): f2.write('%s %s\n' % (ik, self.Hopping[ik][1][i, i].real)) f1.write('\n') f2.write('\n') f1.close() f2.close() else: f = open('ham.dat', 'w') for ik in xrange(self.Nk): for i in xrange(self.N_Orbitals[ik][0]): f.write('%s %s\n' % (ik, self.Hopping[ik][0][i, i].real)) f.write('\n') f.close() #========================================= # calculate A(k,w): mu = self.Chemical_Potential bln = self.blocnames[self.SO] # init DOS: M = [x for x in self.Sigmaimp[0].mesh] N_om = len(M) if plotrange is None: omminplot = M[0] - 0.001 ommaxplot = M[N_om - 1] + 0.001 else: omminplot = plotrange[0] ommaxplot = plotrange[1] if (ishell is None): Akw = {} for ibn in bln: Akw[ibn] = numpy.zeros([self.Nk, N_om], numpy.float_) else: Akw = {} for ibn in bln: Akw[ibn] = numpy.zeros([self.shells[ishell][3], self.Nk, N_om], numpy.float_) if Fermisurface: omminplot = -2.0 * broadening ommaxplot = 2.0 * broadening Akw = {} for ibn in bln: Akw[ibn] = numpy.zeros([self.Nk, 1], numpy.float_) if not (ishell is None): GFStruct_proj = [(al, range(self.shells[ishell][3])) for al in bln] Gproj = GF(Name_Block_Generator=[ (a, GFBloc_ReFreq(Indices=al, Mesh=self.Sigmaimp[0].mesh)) for a, al in GFStruct_proj ], Copy=False) Gproj.zero() for ik in xrange(self.Nk): S = self.latticeGF_realfreq(ik=ik, mu=mu, broadening=broadening) if (ishell is None): # non-projected A(k,w) for iom in range(N_om): if (M[iom] > omminplot) and (M[iom] < ommaxplot): if Fermisurface: for sig, gf in S: Akw[sig][ ik, 0] += gf._data.array[:, :, iom].imag.trace( ) / (-3.1415926535) * (M[1] - M[0]) else: for sig, gf in S: Akw[sig][ ik, iom] += gf._data.array[:, :, iom].imag.trace( ) / (-3.1415926535) Akw[sig][ ik, iom] += ik * shift # shift Akw for plotting in xmgrace else: # projected A(k,w): Gproj.zero() tmp = Gproj.copy() for ir in xrange(self.N_parproj[ishell]): for sig, gf in tmp: tmp[sig] <<= self.downfold_pc(ik, ir, ishell, sig, S[sig], gf) Gproj += tmp # TO BE FIXED: # rotate to local frame #if (self.use_rotations): # for sig,gf in Gproj: Gproj[sig] <<= self.rotloc(0,gf,direction='toLocal') for iom in range(N_om): if (M[iom] > omminplot) and (M[iom] < ommaxplot): for ish in range(self.shells[ishell][3]): for ibn in bln: Akw[ibn][ish, ik, iom] = Gproj[ibn]._data.array[ ish, ish, iom].imag / (-3.1415926535) # END k-LOOP if (MPI.IS_MASTER_NODE()): if (ishell is None): for ibn in bln: # loop over GF blocs: if (invertAkw): maxAkw = Akw[ibn].max() minAkw = Akw[ibn].min() # open file for storage: if Fermisurface: f = open('FS_' + ibn + '.dat', 'w') else: f = open('Akw_' + ibn + '.dat', 'w') for ik in range(self.Nk): if Fermisurface: if (invertAkw): Akw[ibn][ik, 0] = 1.0 / (minAkw - maxAkw) * ( Akw[ibn][ik, iom] - maxAkw) f.write('%s %s\n' % (ik, Akw[ibn][ik, 0])) else: for iom in range(N_om): if (M[iom] > omminplot) and (M[iom] < ommaxplot): if (invertAkw): Akw[ibn][ ik, iom] = 1.0 / (minAkw - maxAkw) * ( Akw[ibn][ik, iom] - maxAkw) if (shift > 0.0001): f.write('%s %s\n' % (M[iom], Akw[ibn][ik, iom])) else: f.write( '%s %s %s\n' % (ik, M[iom], Akw[ibn][ik, iom])) f.write('\n') f.close() else: for ibn in bln: for ish in range(self.shells[ishell][3]): if (invertAkw): maxAkw = Akw[ibn][ish, :, :].max() minAkw = Akw[ibn][ish, :, :].min() f = open('Akw_' + ibn + '_proj' + str(ish) + '.dat', 'w') for ik in range(self.Nk): for iom in range(N_om): if (M[iom] > omminplot) and (M[iom] < ommaxplot): if (invertAkw): Akw[ibn][ish, ik, iom] = 1.0 / ( minAkw - maxAkw ) * (Akw[ibn][ish, ik, iom] - maxAkw) if (shift > 0.0001): f.write( '%s %s\n' % (M[iom], Akw[ibn][ish, ik, iom])) else: f.write('%s %s %s\n' % (ik, M[iom], Akw[ibn][ish, ik, iom])) f.write('\n') f.close()
def DOSpartial(self, broadening=0.01): """calculates the orbitally-resolved DOS""" assert hasattr(self, "Sigmaimp"), "Set Sigma First!!" #thingstoread = ['Dens_Mat_below','N_parproj','Proj_Mat_pc','rotmat_all'] #retval = self.read_input_from_HDF(SubGrp=self.ParProjdata, thingstoread=thingstoread) retval = self.read_ParProj_input_from_HDF() if not retval: return retval if self.symm_op: self.Symm_par = Symmetry(self.HDFfile, subgroup=self.Symmpardata) mu = self.Chemical_Potential GFStruct_proj = [[(al, range(self.shells[i][3])) for al in self.blocnames[self.SO]] for i in xrange(self.N_shells)] Gproj = [ GF(Name_Block_Generator=[ (a, GFBloc_ReFreq(Indices=al, Mesh=self.Sigmaimp[0].mesh)) for a, al in GFStruct_proj[ish] ], Copy=False) for ish in xrange(self.N_shells) ] for ish in range(self.N_shells): Gproj[ish].zero() Msh = [x for x in self.Sigmaimp[0].mesh] N_om = len(Msh) DOS = {} for bn in self.blocnames[self.SO]: DOS[bn] = numpy.zeros([N_om], numpy.float_) DOSproj = [{} for ish in range(self.N_shells)] DOSproj_orb = [{} for ish in range(self.N_shells)] for ish in range(self.N_shells): for bn in self.blocnames[self.SO]: dl = self.shells[ish][3] DOSproj[ish][bn] = numpy.zeros([N_om], numpy.float_) DOSproj_orb[ish][bn] = numpy.zeros([dl, dl, N_om], numpy.float_) ikarray = numpy.array(range(self.Nk)) for ik in MPI.slice_array(ikarray): S = self.latticeGF_realfreq(ik=ik, mu=mu, broadening=broadening) S *= self.BZ_weights[ik] # non-projected DOS for iom in range(N_om): for sig, gf in S: DOS[sig][iom] += gf._data.array[:, :, iom].imag.trace() / ( -3.1415926535) #projected DOS: for ish in xrange(self.N_shells): tmp = Gproj[ish].copy() for ir in xrange(self.N_parproj[ish]): for sig, gf in tmp: tmp[sig] <<= self.downfold_pc(ik, ir, ish, sig, S[sig], gf) Gproj[ish] += tmp # collect data from MPI: for sig in DOS: DOS[sig] = MPI.all_reduce(MPI.world, DOS[sig], lambda x, y: x + y) for ish in xrange(self.N_shells): Gproj[ish] <<= MPI.all_reduce(MPI.world, Gproj[ish], lambda x, y: x + y) MPI.barrier() if (self.symm_op != 0): Gproj = self.Symm_par.symmetrise(Gproj) # rotation to local coord. system: if (self.use_rotations): for ish in xrange(self.N_shells): for sig, gf in Gproj[ish]: Gproj[ish][sig] <<= self.rotloc_all(ish, gf, direction='toLocal') for ish in range(self.N_shells): for sig, gf in Gproj[ish]: for iom in range(N_om): DOSproj[ish][sig][ iom] += gf._data.array[:, :, iom].imag.trace() / ( -3.1415926535) DOSproj_orb[ish][ sig][:, :, :] += gf._data.array[:, :, :].imag / ( -3.1415926535) if (MPI.IS_MASTER_NODE()): # output to files for bn in self.blocnames[self.SO]: f = open('./DOScorr%s.dat' % bn, 'w') for i in range(N_om): f.write("%s %s\n" % (Msh[i], DOS[bn][i])) f.close() # partial for ish in range(self.N_shells): f = open('DOScorr%s_proj%s.dat' % (bn, ish), 'w') for i in range(N_om): f.write("%s %s\n" % (Msh[i], DOSproj[ish][bn][i])) f.close() for i in range(self.shells[ish][3]): for j in range(i, self.shells[ish][3]): Fname = './DOScorr' + bn + '_proj' + str( ish) + '_' + str(i) + '_' + str(j) + '.dat' f = open(Fname, 'w') for iom in range(N_om): f.write("%s %s\n" % (Msh[iom], DOSproj_orb[ish][bn][i, j, iom])) f.close()
def check_inputDOS(self, ommin, ommax, N_om, Beta=10, broadening=0.01): delta_om = (ommax - ommin) / (N_om - 1) Mesh = numpy.zeros([N_om], numpy.float_) DOS = {} for bn in self.blocnames[self.SO]: DOS[bn] = numpy.zeros([N_om], numpy.float_) DOSproj = [{} for icrsh in range(self.N_inequiv_corr_shells)] DOSproj_orb = [{} for icrsh in range(self.N_inequiv_corr_shells)] for icrsh in range(self.N_inequiv_corr_shells): for bn in self.blocnames[self.corr_shells[self.invshellmap[icrsh]] [4]]: dl = self.corr_shells[self.invshellmap[icrsh]][3] DOSproj[icrsh][bn] = numpy.zeros([N_om], numpy.float_) DOSproj_orb[icrsh][bn] = numpy.zeros([dl, dl, N_om], numpy.float_) for i in range(N_om): Mesh[i] = ommin + delta_om * i # init: Gloc = [] for icrsh in range(self.N_corr_shells): b_list = [a for a, al in self.GFStruct_corr[icrsh]] glist = lambda: [ GFBloc_ReFreq(Indices=al, Beta=Beta, MeshArray=Mesh) for a, al in self.GFStruct_corr[icrsh] ] Gloc.append(GF(NameList=b_list, BlockList=glist(), Copy=False)) for icrsh in xrange(self.N_corr_shells): Gloc[icrsh].zero() # initialize to zero for ik in xrange(self.Nk): Gupf = self.latticeGF_realfreq(ik=ik, mu=self.Chemical_Potential, broadening=broadening, Beta=Beta, Mesh=Mesh, withSigma=False) Gupf *= self.BZ_weights[ik] # non-projected DOS for iom in range(N_om): for sig, gf in Gupf: asd = gf._data.array[:, :, iom].imag.trace() / (-3.1415926535) DOS[sig][iom] += asd for icrsh in xrange(self.N_corr_shells): tmp = Gloc[icrsh].copy() for sig, gf in tmp: tmp[sig] <<= self.downfold(ik, icrsh, sig, Gupf[sig], gf) # downfolding G Gloc[icrsh] += tmp if (self.symm_op != 0): Gloc = self.Symm_corr.symmetrise(Gloc) if (self.use_rotations): for icrsh in xrange(self.N_corr_shells): for sig, gf in Gloc[icrsh]: Gloc[icrsh][sig] <<= self.rotloc(icrsh, gf, direction='toLocal') # Gloc can now also be used to look at orbitally resolved quantities for ish in range(self.N_inequiv_corr_shells): for sig, gf in Gloc[self.invshellmap[ish]]: # loop over spins for iom in range(N_om): DOSproj[ish][sig][ iom] += gf._data.array[:, :, iom].imag.trace() / ( -3.1415926535) DOSproj_orb[ish][ sig][:, :, :] += gf._data.array[:, :, :].imag / ( -3.1415926535) # output: if (MPI.IS_MASTER_NODE()): for bn in self.blocnames[self.SO]: f = open('DOS%s.dat' % bn, 'w') for i in range(N_om): f.write("%s %s\n" % (Mesh[i], DOS[bn][i])) f.close() for ish in range(self.N_inequiv_corr_shells): f = open('DOS%s_proj%s.dat' % (bn, ish), 'w') for i in range(N_om): f.write("%s %s\n" % (Mesh[i], DOSproj[ish][bn][i])) f.close() for i in range(self.corr_shells[self.invshellmap[ish]][3]): for j in range( i, self.corr_shells[self.invshellmap[ish]][3]): Fname = 'DOS' + bn + '_proj' + str( ish) + '_' + str(i) + '_' + str(j) + '.dat' f = open(Fname, 'w') for iom in range(N_om): f.write("%s %s\n" % (Mesh[iom], DOSproj_orb[ish][bn][i, j, iom])) f.close()