예제 #1
0
파일: folder.py 프로젝트: yihsuanliu/gpaw
 def __init__(self, width, folding='Gauss'):
     self.width = width
     if folding == 'Gauss':
         self.func = Gauss(width)
     elif folding == 'Lorentz':
         self.func = Lorentz(width)
     elif folding == None:
         self.func = None
     else:
         raise RuntimeError('unknown folding "' + folding + '"')
예제 #2
0
 def __init__(self, width,
              folding='Gauss'):
     self.width = width
     if folding == 'Gauss':
         self.func = Gauss(width)
     elif folding == 'Lorentz':
         self.func = Lorentz(width)
     elif folding == 'ComplexGauss':
         self.func = ComplexGauss(width)
     elif folding == 'ComplexLorentz':
         self.func = ComplexLorentz(width)
     elif folding == 'RealLorentzPole':
         self.func = LorentzPole(width, imag=False)
     elif folding == 'ImaginaryLorentzPole':
         self.func = LorentzPole(width, imag=True)
     elif folding == 'Voigt':
         self.func = Voigt(width)
     else:
         raise RuntimeError('unknown folding "' + folding + '"')
예제 #3
0
from math import exp, pi, sqrt
import numpy as np

from gpaw.gauss import Gauss
from gpaw.test import equal
from gpaw.utilities.folder import Folder, Lorentz, Voigt  # noqa

# Gauss and Lorentz functions

width = 0.5
x = 1.5

equal(Gauss(width).get(x),
      exp(- x**2 / 2 / width**2) / sqrt(2 * pi) / width,
      1.e-15)
equal(Gauss(width).fwhm, width * np.sqrt(8 * np.log(2)), 1.e-15) 
equal(Lorentz(width).get(x),
      width / (x**2 + width**2) / pi,
      1.e-15)
equal(Lorentz(width).fwhm, width * 2, 1.e-15) 

# folder function

for func in [Gauss, Lorentz, Voigt]:
    folder = Folder(width, func(width).__class__.__name__)

    x = [0, 2]
    y = [[2, 0, 1], [1, 1, 1]]

    xl, yl = folder.fold(x, y, dx=.7)
예제 #4
0
    print('From analyse           :', Eanalyse, oszanalyse)
    equal(E, Eanalyse, 1e-3)  # Written precision in analyse
    equal(osz[0], oszanalyse, 1e-3)

    E2 = lr2[n].get_energy() * Hartree
    osz2 = lr2[n].get_oscillator_strength()
    print('Written and read object:', E2, osz2[0])

    # Compare values of original and written/read objects
    equal(E, E2, 1e-4)
    for i in range(len(osz)):
        equal(osz[i], osz2[i], 1.7e-4)

    width = 0.05
    photoabsorption_spectrum(lr,
                             spectrum_file='lrtddft3-spectrum.dat',
                             width=width)
    # We need to be able to check the heights in the spectrum
    weight = Gauss(width).get(0)

    spectrum = np.loadtxt('lrtddft3-spectrum.dat', usecols=(0, 1))
    idx = (spectrum[:, 0] >= E - 0.1) & (spectrum[:, 0] <= E + 0.1)
    peak = np.argmax(spectrum[idx, 1]) + np.nonzero(idx)[0][0]
    Espec = spectrum[peak, 0]
    oszspec = spectrum[peak, 1] / weight

    print('Values from spectrum   :', Espec, oszspec)
    # Compare calculated values with values written to file
    equal(E, Espec, 1e-2)  # The spectrum has a low sampling
    equal(osz[0], oszspec, 1e-2)
예제 #5
0
파일: dos.py 프로젝트: robwarm/gpaw-symm
    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()
예제 #6
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()
예제 #7
0
import os
from math import exp, pi, sqrt
import numpy as np

from gpaw.gauss import Gauss, Lorentz
from gpaw.test import equal
from gpaw.utilities.folder import Folder

# Gauss and Lorentz functions

width = 0.5
x = 1.5

equal(Gauss(width).get(x), 
      exp(- x**2 / 2 / width**2) / sqrt(2 * pi) / width, 
      1.e-15)
equal(Lorentz(width).get(x), 
      width / (x**2 + width**2) / pi, 
      1.e-15)

# folder function

for name in ['Gauss', 'Lorentz']:
    folder = Folder(width, name)

    x = [0, 2]
    y = [[2, 0, 1], [1, 1, 1]]

    xl, yl = folder.fold(x, y, dx=.7)

    # check first value
예제 #8
0
from math import exp, pi, sqrt
import numpy as np

from gpaw.gauss import Gauss, Lorentz
from gpaw.test import equal
from gpaw.utilities.folder import Folder, Voigt

# Gauss and Lorentz functions

width = 0.5
x = 1.5

equal(Gauss(width).get(x),
      exp(- x**2 / 2 / width**2) / sqrt(2 * pi) / width,
      1.e-15)
equal(Lorentz(width).get(x),
      width / (x**2 + width**2) / pi,
      1.e-15)

# folder function

for name in ['Gauss', 'Lorentz', 'Voigt']:
    folder = Folder(width, name)

    x = [0, 2]
    y = [[2, 0, 1], [1, 1, 1]]

    xl, yl = folder.fold(x, y, dx=.7)

    # check first value
    exec('func = {0}(width)'.format(name))