Beispiel #1
0
    def write_mies_weights(self, wfs, file=None):
        if file is None:
            file = 'eed_mies.dat'

        if isinstance(file, str):
            out = paropen(file, 'aw')
        else:
            out = file

        fmf = FMF(['exterior electron density weights after',
                   'Y. Harada et al., Chem. Rev. 97 (1997) 1897'])
        print >> out, fmf.header(),
        print >> out, fmf.data(['band index: n',
                                'k-point index: k',
                                'spin index: s',
                                'k-point weight: weight',
                                'energy: energy [eV]',
                                'occupation number: occ',
                                'relative EED weight: eed_weight']),
        
        print >> out, '#; n   k s   weight      energy         occ  eed_weight'
        for kpt in wfs.kpt_u:
            for n in range(wfs.nbands):
                print  >> out, '%4d %3d %1d %8.5f  %10.5f  %10.5f  %10.5f' % \
                    (n, kpt.k, kpt.s, kpt.weight,
                     kpt.eps_n[n] * Hartree,
                     kpt.f_n[n], 
                     self.get_weight(kpt.psit_nG[n])
                     )
                if hasattr(out, 'flush'):
                    out.flush()
Beispiel #2
0
    def write_mies_weights(self, wfs, file=None):
        if file is None:
            file = 'eed_mies.dat'

        if isinstance(file, str):
            out = paropen(file, 'aw')
        else:
            out = file

        fmf = FMF([
            'exterior electron density weights after',
            'Y. Harada et al., Chem. Rev. 97 (1997) 1897'
        ])
        print >> out, fmf.header(),
        print >> out, fmf.data([
            'band index: n', 'k-point index: k', 'spin index: s',
            'k-point weight: weight', 'energy: energy [eV]',
            'occupation number: occ', 'relative EED weight: eed_weight'
        ]),

        print >> out, '#; n   k s   weight      energy         occ  eed_weight'
        for kpt in wfs.kpt_u:
            for n in range(wfs.nbands):
                print  >> out, '%4d %3d %1d %8.5f  %10.5f  %10.5f  %10.5f' % \
                    (n, kpt.k, kpt.s, kpt.weight,
                     kpt.eps_n[n] * Hartree,
                     kpt.f_n[n],
                     self.get_weight(kpt.psit_nG[n])
                     )
                if hasattr(out, 'flush'):
                    out.flush()
Beispiel #3
0
    def to_file(self, 
                ldbe,
                filename=None,
                width=None,
                shift=True,
                bound=False):
        """Write the LDOS to a file.

        If a width is given, the LDOS will be Gaussian folded and shifted to set 
        Fermi energy to 0 eV. The latter can be avoided by setting shift=False. 

        If you use fixmagmom=true, you will get two fermi-levels, one for each 
        spin-setting. Normaly these will shifted individually to 0 eV. If you
        want to shift them as pair to the higher energy use bound=True.
        """

        f = paropen(filename, 'w')

        def append_weight_strings(ldbe, data):
            s = ''
            for key in ldbe:
                for l in 'spd':
                    data.append(key + '(' + l + ')-weight')
                if len(key) == 1: 
                    key = ' ' + key
                s +=  ' ' + key + ':s     p        d       '
            return s

        wfs = self.paw.wfs
        
        if width is None:
            # unfolded ldos
            fmf = FMF(['Raw LDOS obtained from projector weights'])
            print >> f, fmf.header(),
            data = ['energy: energy [eV]',
                    'occupation number: occ',
                    'spin index: s',
                    'k-point index: k',
                    'band index: n',
                    'k-point weight: weight']
            string = '# e_i[eV]  occ     s     k      n   kptwght '
            string += append_weight_strings(ldbe, data)
            data.append('summed weights: sum')
            string += ' sum'
            print >> f, fmf.data(data),
            print >> f, string
            for k in range(wfs.nibzkpts):
                for s in range(wfs.nspins):
                    e_n = self.paw.get_eigenvalues(kpt=k, spin=s)
                    f_n = self.paw.get_occupation_numbers(kpt=k, spin=s)
                    if e_n is None:
                        continue
                    w = wfs.weight_k[k]
                    for n in range(wfs.bd.nbands):
                        sum = 0.0
                        print >> f, '%10.5f %6.4f %2d %5d' % (e_n[n], f_n[n], 
                                                              s, k), 
                        print >> f, '%6d %8.4f' % (n, w),
                        for key in ldbe:
                            spd = ldbe[key][s, k, n]
                            for l in range(3):
                                sum += spd[l]
                                print >> f, '%8.4f' % spd[l],
                        print >> f, '%8.4f' % sum
        else:
            # folded ldos
            fmf = FMF(['Folded raw LDOS obtained from projector weights'])
            print >> f, fmf.header(),

            gauss = Gauss(width)
            print >> f, fmf.field('folding',
                                  ['function: Gauss',
                                   'width: ' + str(width) + ' [eV]']),

            data = ['energy: energy [eV]',
                    'spin index: s',
                    'k-point index: k',
                    'band index: n',
                    'k-point weight: weight']

            # minimal and maximal energies
            emin = 1.e32
            emax = -1.e32
            for k in range(wfs.nibzkpts):
                for s in range(wfs.nspins):
                    e_n = self.paw.get_eigenvalues(kpt=k, spin=s,
                                                   broadcast=True)
                    emin = min(e_n.min(), emin)
                    emax = max(e_n.max(), emax)
            emin -= 4 * width
            emax += 4 * width

            # Fermi energy
            try:
                if self.paw.occupations.fixmagmom:
                    efermi = self.paw.get_fermi_levels()
                else:
                    efermi = self.paw.get_fermi_level()
            except:
                # set Fermi level half way between H**O and LUMO
                hl = self.paw.occupations.get_homo_lumo(wfs)
                efermi = (hl[0] + hl[1]) * Hartree / 2

            eshift = 0.0

            if shift and not self.paw.occupations.fixmagmom:
                eshift = -efermi

            # set de to sample 4 points in the width
            de = width / 4
            
            string = '# e[eV]     s  '
            string += append_weight_strings(ldbe, data)

            for s in range(wfs.nspins):
                if self.paw.occupations.fixmagmom:
                    if not bound:
                        eshift = - efermi[s]
                    else:
                        eshift = - efermi.max()

                print >> f, fmf.data(data),

                print >> f, '# Gauss folded, width=%g [eV]' % width
                if shift:
                    print >> f, '# shifted to Fermi energy = 0'
                    print >> f, '# Fermi energy was', 
                else:
                    print >> f, '# Fermi energy',
                print  >> f, efermi, 'eV'
                print >> f, string

                # loop over energies
                emax=emax+.5*de
                e=emin
                while e<emax:
                    val = {}
                    for key in ldbe:
                        val[key] = np.zeros((3))
                    for k in range(wfs.nibzkpts):
                        w = wfs.kpt_u[k].weight
                        e_n = self.paw.get_eigenvalues(kpt=k, spin=s,
                                                       broadcast=True)
                        for n in range(wfs.bd.nbands):
                            w_i = w * gauss.get(e_n[n] - e)
                            for key in ldbe:
                                val[key] += w_i * ldbe[key][s, k, n]

                    print >> f, '%10.5f %2d' % (e + eshift, s), 
                    for key in val:
                        spd = val[key]
                        for l in range(3):
                            print >> f, '%8.4f' % spd[l],
                    print >> f
                    e += de
                            

        f.close()
Beispiel #4
0
    def to_file(self,
                ldbe,
                filename=None,
                width=None,
                shift=True,
                bound=False):
        """Write the LDOS to a file.

        If a width is given, the LDOS will be Gaussian folded and shifted to set
        Fermi energy to 0 eV. The latter can be avoided by setting shift=False.

        If you use fixmagmom=true, you will get two fermi-levels, one for each
        spin-setting. Normaly these will shifted individually to 0 eV. If you
        want to shift them as pair to the higher energy use bound=True.
        """

        f = paropen(filename, 'w')

        def append_weight_strings(ldbe, data):
            s = ''
            for key in ldbe:
                for l in 'spd':
                    data.append(key + '(' + l + ')-weight')
                if len(key) == 1:
                    key = ' ' + key
                s += ' ' + key + ':s     p        d       '
            return s

        wfs = self.paw.wfs

        if width is None:
            # unfolded ldos
            fmf = FMF(['Raw LDOS obtained from projector weights'])
            print(fmf.header(), end=' ', file=f)
            data = [
                'energy: energy [eV]', 'occupation number: occ',
                'spin index: s', 'k-point index: k', 'band index: n',
                'k-point weight: weight'
            ]
            string = '# e_i[eV]  occ     s     k      n   kptwght '
            string += append_weight_strings(ldbe, data)
            data.append('summed weights: sum')
            string += ' sum'
            print(fmf.data(data), end=' ', file=f)
            print(string, file=f)
            for k in range(wfs.kd.nibzkpts):
                for s in range(wfs.nspins):
                    e_n = self.paw.get_eigenvalues(kpt=k, spin=s)
                    f_n = self.paw.get_occupation_numbers(kpt=k, spin=s)
                    if e_n is None:
                        continue
                    w = wfs.kd.weight_k[k]
                    for n in range(wfs.bd.nbands):
                        sum = 0.0
                        print('%10.5f %6.4f %2d %5d' % (e_n[n], f_n[n], s, k),
                              end=' ',
                              file=f)
                        print('%6d %8.4f' % (n, w), end=' ', file=f)
                        for key in ldbe:
                            spd = ldbe[key][s, k, n]
                            for l in range(3):
                                sum += spd[l]
                                print('%8.4f' % spd[l], end=' ', file=f)
                        print('%8.4f' % sum, file=f)
        else:
            # folded ldos
            fmf = FMF(['Folded raw LDOS obtained from projector weights'])
            print(fmf.header(), end=' ', file=f)

            gauss = Gauss(width)
            print(fmf.field(
                'folding',
                ['function: Gauss', 'width: ' + str(width) + ' [eV]']),
                  end=' ',
                  file=f)

            data = [
                'energy: energy [eV]', 'spin index: s', 'k-point index: k',
                'band index: n', 'k-point weight: weight'
            ]

            # minimal and maximal energies
            emin = 1.e32
            emax = -1.e32
            for k in range(wfs.kd.nibzkpts):
                for s in range(wfs.nspins):
                    e_n = self.paw.get_eigenvalues(kpt=k,
                                                   spin=s,
                                                   broadcast=True)
                    emin = min(e_n.min(), emin)
                    emax = max(e_n.max(), emax)
            emin -= 4 * width
            emax += 4 * width

            # Fermi energy
            try:
                if self.paw.occupations.fixmagmom:
                    efermi = self.paw.get_fermi_levels()
                else:
                    efermi = self.paw.get_fermi_level()
            except:
                # set Fermi level half way between H**O and LUMO
                hl = wfs.get_homo_lumo()
                efermi = (hl[0] + hl[1]) * Hartree / 2

            eshift = 0.0

            if shift and not self.paw.occupations.fixmagmom:
                eshift = -efermi

            # set de to sample 4 points in the width
            de = width / 4

            string = '# e[eV]     s  '
            string += append_weight_strings(ldbe, data)

            for s in range(wfs.nspins):
                if self.paw.occupations.fixmagmom:
                    if not bound:
                        eshift = -efermi[s]
                    else:
                        eshift = -efermi.max()

                print(fmf.data(data), end=' ', file=f)

                print('# Gauss folded, width=%g [eV]' % width, file=f)
                if shift:
                    print('# shifted to Fermi energy = 0', file=f)
                    print('# Fermi energy was', end=' ', file=f)
                else:
                    print('# Fermi energy', end=' ', file=f)
                print(efermi, 'eV', file=f)
                print(string, file=f)

                # loop over energies
                emax = emax + .5 * de
                e = emin
                while e < emax:
                    val = {}
                    for key in ldbe:
                        val[key] = np.zeros((3))
                    for k in range(wfs.kd.nibzkpts):
                        w = wfs.kpt_u[k].weight
                        e_n = self.paw.get_eigenvalues(kpt=k,
                                                       spin=s,
                                                       broadcast=True)
                        for n in range(wfs.bd.nbands):
                            w_i = w * gauss.get(e_n[n] - e)
                            for key in ldbe:
                                val[key] += w_i * ldbe[key][s, k, n]

                    print('%10.5f %2d' % (e + eshift, s), end=' ', file=f)
                    for key in val:
                        spd = val[key]
                        for l in range(3):
                            print('%8.4f' % spd[l], end=' ', file=f)
                    print(file=f)
                    e += de

        f.close()