コード例 #1
0
ファイル: densityofstates_new.py プロジェクト: gjenness/Pykit
    def __dos_integrate(self, band='d', atomtype=None, exclude=None,
                         include=None, erange=None, rank=0):
        labels = {'s': 0, 'p': 1, 'd': 2}
        spinlabels = {'s': [0, 1], 'p': [2, 3], 'd': [4, 5]}
        allowed_bands = ['s', 'p', 'd']  # List of allowed bands
        bandlist = list()  # List of bands to be analyzed

        if (self.spin):
            totaldos = np.zeros((self.npoints, 6))
        elif (not self.spin):
            totaldos = np.zeros((self.npoints, 3)) 

        dosband = np.zeros((self.npoints))

        atomlist = convert2list(atomtype)
        excludelist = convert2list(exclude)
        includelist = convert2list(include)

        for ban in band:
            if (ban.lower() not in allowed_bands):
                raise RuntimeError('Unknown band type: %s' % ban)
            else:
                bandlist.append(ban.lower())

# Here we get the totaldos for each atom in the system
        for label in self.atom_labels:
            for atom in atomlist:
                if ((atom in label) or (label in includelist)) and (label not in excludelist):
                    totaldos += self.get_total_atom_dos(atomtype=atom,
                                                        exclude=excludelist,
                                                        include=includelist)

        if (erange == None):
            emin = self.energies[0]
            emax = self.energies[-1]
        elif (erange == 'fermi'):
            emin = self.energies[0]
            emax = 0.0
        else:
            emin = erange[0]
            emax = erange[1]

        energylist = list()
        indexlist = list()

        for n,e in enumerate(self.energies):
            if (e > emin) and (e < emax):
                energylist.append(e)
                indexlist.append(n)

        start = indexlist[0]
        finish = indexlist[-1]
        if (self.spin):
            for b in band:
                colup = spinlabels[b][0]
                coldown = spinlabels[b][1]
                dosband += (totaldos[:, colup] + totaldos[:, coldown]) 
        elif (not self.spin):
            for b in band:
                col = labels[b]
                dosband += totaldos[:, col]

        if (rank == 0):
            trimdos = dosband[start:finish+1]
        elif (rank == 1):
            trimdos = dosband[start:finish+1] * energylist
        elif (rank == 2):
            trimdos = dosband[start:finish+1] * energylist *energylist
        else:
            raise RuntimeError('Rank %i not recognized' % rank)

        return integrate(grid=energylist, data=trimdos)
コード例 #2
0
ファイル: densityofstates_old.py プロジェクト: gjenness/Pykit
    def get_band_width(self, band='d', atomtype=None, exclude=None,
                         include=None, erange=None):
# Yes I'm lazy, sue me.
        labels = {'s': 0, 'p': 1, 'd': 2}
        spinlabels = {'s': [0, 1], 'p': [2, 3], 'd': [4, 5]}
        allowed_bands = ['s', 'p', 'd']  # List of allowed bands
        bandlist = list()  # List of bands to be analyzed

        if (self.spin):
            totaldos = np.zeros((self.npoints, 6))
        elif (not self.spin):
            totaldos = np.zeros((self.npoints, 3)) 

        dosband = np.zeros((self.npoints))

        atomlist = convert2list(atomtype)
        excludelist = convert2list(exclude)
        includelist = convert2list(include)

        for ban in band:
            if (ban.lower() not in allowed_bands):
                raise RuntimeError('Unknown band type: %s' % ban)
            else:
                bandlist.append(ban.lower())

# Here we get the totaldos for each atom in the system
        for label in self.atom_labels:
            for atom in atomlist:
                if ((atom in label) or (label in includelist)) and (label not in excludelist):
                    totaldos += self.get_total_atom_dos(atomtype=atom,
                                                        exclude=excludelist,
                                                        include=includelist)

        if (erange == None):
#            print 'Integrating over whole range up to the Fermi level.'
            emin = self.energies[0]
            emax = 0.0
        elif (erange[1] == 'fermi'):
            emin = erange[0]
            emax = 0.0
        else:
            emin = erange[0]
            emax = erange[1]

        energylist = list()
        indexlist = list()

        for n,e in enumerate(self.energies):
            if (e > emin) and (e < emax):
                energylist.append(e)
                indexlist.append(n)

        start = indexlist[0]
        finish = indexlist[-1]
        if (self.spin):
            for b in band:
                colup = spinlabels[b][0]
                coldown = spinlabels[b][1]
                dosband += (totaldos[:, colup] + totaldos[:, coldown]) 
        elif (not self.spin):
            for b in band:
                col = labels[b]
                dosband += totaldos[:, col]

        trimdos = dosband[start:finish+1] * energylist * energylist

        filling = self.get_band_filling(band=band, atomtype=atomtype,
                                      include=include, exclude=exclude, erange=erange)

        return math.sqrt(integrate(grid=energylist, data=trimdos) / filling)