def set_folding(self, folding, width): BaseInducedField.set_folding(self, folding, width) if self.folding is None: self.folder = Folder(None, None) else: if self.folding == 'Gauss': self.folder = Folder(self.width, 'ComplexGauss') elif self.folding == 'Lorentz': self.folder = Folder(self.width, 'ComplexLorentz') else: raise RuntimeError('unknown folding "' + self.folding + '"')
def rotatory_spectrum(exlist=None, filename=None, emin=None, emax=None, de=None, energyunit='eV', folding='Gauss', width=0.08, # Gauss/Lorentz width comment=None ): """Write out a folded rotatory spectrum. See spectrum() for explanation of the parameters. """ # output out = sys.stdout if filename is not None: out = open(filename, 'w') if comment: print('#', comment, file=out) print('# Rotatory spectrum from linear response TD-DFT', file=out) print('# GPAW version:', version, file=out) if folding is not None: # fold the spectrum print('# %s folded, width=%g [%s]' % (folding, width, energyunit), file=out) print('# om [%s] R [cgs]' % energyunit, file=out) x = [] y = [] for ex in exlist: x.append(ex.get_energy() * Hartree) y.append(ex.get_rotatory_strength()) if energyunit == 'nm': # transform to experimentally used wavelength [nm] x = 1.e+9 * 2 * np.pi * _hbar * _c / _e / np.array(x) y = np.array(y) elif energyunit != 'eV': raise RuntimeError('currently only eV and nm are supported') energies, values = Folder(width, folding).fold(x, y, de, emin, emax) for e, val in zip(energies, values): print('%10.5f %12.7e' % (e, val), file=out) if filename is not None: out.close()
def get_folded_spectrum( exlist=None, emin=None, emax=None, de=None, energyunit='eV', folding='Gauss', width=0.08, # Gauss/Lorentz width form='r'): """Return folded spectrum.""" x = [] y = [] for ex in exlist: x.append(ex.get_energy() * Hartree) y.append(ex.get_oscillator_strength(form)) if energyunit == 'nm': # transform to experimentally used wavelength [nm] x = 1.e+9 * 2 * np.pi * _hbar * _c / _e / np.array(x) elif energyunit != 'eV': raise RuntimeError('currently only eV and nm are supported') return Folder(width, folding).fold(x, y, de, emin, emax)
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) # check first value yy = np.dot(np.array(y)[:, 0], func(width).get(xl[0] - np.array(x))) equal(yl[0, 0], yy, 1.e-15)
def spectrum( exlist=None, filename=None, emin=None, emax=None, de=None, energyunit='eV', folding='Gauss', width=0.08, # Gauss/Lorentz width comment=None): """Write out a folded spectrum. Parameters: =============== =================================================== ``exlist`` ExcitationList ``filename`` File name for the output file, STDOUT if not given ``emin`` min. energy, set to cover all energies if not given ``emax`` max. energy, set to cover all energies if not given ``de`` energy spacing ``energyunit`` Energy unit 'eV' or 'nm', default 'eV' ``folding`` Gauss (default) or Lorentz ``width`` folding width in terms of the chosen energyunit =============== =================================================== all energies in [eV] """ # output out = sys.stdout if filename != None: out = open(filename, 'w') if comment: print >> out, '#', comment print >> out, '# Photoabsorption spectrum from linear response TD-DFT' print >> out, '# GPAW version:', version if folding is not None: # fold the spectrum print >> out, '# %s folded, width=%g [%s]' % (folding, width, energyunit) print >> out,\ '# om [%s] osz osz x osz y osz z'\ % energyunit x = [] y = [] for ex in exlist: x.append(ex.get_energy() * Hartree) y.append(ex.get_oscillator_strength()) if energyunit == 'nm': # transform to experimentally used wavelength [nm] x = 1.e+9 * 2 * np.pi * _hbar * _c / _e / np.array(x) y = np.array(y) elif energyunit != 'eV': raise RuntimeError('currently only eV and nm are supported') energies, values = Folder(width, folding).fold(x, y, de, emin, emax) for e, val in zip(energies, values): print >> out, "%10.5f %12.7e %12.7e %11.7e %11.7e" % \ (e,val[0],val[1],val[2],val[3]) if filename != None: out.close()
# 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 if name == 'Lorentz': func = Lorentz(width) else: func = Gauss(width) yy = np.dot(np.array(y)[:, 0], func.get(xl[0] - np.array(x))) equal(yl[0, 0], yy, 1.e-15) # write spectrum
plt.axis([-1000, 6000, 0, 1.05]) plt.ylabel('HR factors [a.u.]') plt.xlabel('frequency [cm-1]') plt.show() #Plot Franck-Condon factors FC, f = a.get_Franck_Condon_factors(n, T, F) for l in range(len(FC)): plt.vlines(f[l], 0, FC[l], color=colors[l], label=labels[l], linewidth=2.0) #Fold the spectrum with a gaussian function width = 300 folding = 'Gauss' x = [j for j in chain(*f)] y = [j for j in chain(*FC)] X, Y = Folder(width, folding).fold(x, y) plt.plot(X, Y * 750, color='black', linewidth=2.0, label='Temperature=' + str(T) + 'K, #quanta=' + str(n) + ', width of gaussian=' + str(width) + 'cm^-1', linestyle='dashed') plt.legend(loc='upper right') plt.axis([-1000, 6000, 0, 0.6]) plt.ylabel('FC factors [a.u.]') plt.xlabel('frequency [cm-1]') plt.show()
def dielectric( exlist, volume, filename=None, emin=None, emax=None, de=None, energyunit='eV', width=0.08, # width in energyunit comment=None, form='v'): """Write out the dielectric function Parameters: =============== =================================================== ``exlist`` ExcitationList ``volume`` Unit cell volume in Angstrom**3 ``filename`` File name for the output file, STDOUT if not given ``emin`` min. energy, set to cover all energies if not given ``emax`` max. energy, set to cover all energies if not given ``de`` energy spacing ``energyunit`` Energy unit 'eV' or 'nm', default 'eV' ``width`` folding width in terms of the chosen energyunit =============== =================================================== all energies in [eV] """ # output out = sys.stdout if filename is not None: out = open(filename, 'w') if comment: print('#', comment, file=out) print('# Dielec function', file=out) print('# GPAW version:', gpaw.__version__, file=out) print('# width={0} [{1}]'.format(width, energyunit), file=out) if form == 'r': print('# length form', file=out) else: assert (form == 'v') print('# velocity form', file=out) print( '# om [{0}] eps1/eps0 eps2/eps0 n k R'.format( energyunit), file=out) x = [] y = [] for ex in exlist: x.append(ex.get_energy() * Hartree) y.append(ex.get_oscillator_strength(form)) if energyunit != 'eV': raise RuntimeError('currently only eV is supported') pre = 4. * np.pi / volume * Bohr**3 * Hartree**2 energies, values = Folder(width, 'RealLorentzPole').fold(x, y, de, emin, emax) eps1 = 1 + pre * values.T[0] energies, values = Folder(width, 'ImaginaryLorentzPole').fold( x, y, de, emin, emax) eps2 = pre * values.T[0] N = np.sqrt(0.5 * (np.sqrt(eps1**2 + eps2**2) + eps1)) K = np.sqrt(0.5 * (np.sqrt(eps1**2 + eps2**2) - eps1)) R = ((N - 1)**2 + K**2) / ((N + 1)**2 + K**2) for e, e1, e2, n, k, r in zip(energies, eps1, eps2, N, K, R): print('%10.5f %12.7e %12.7e %12.7e %12.7e %12.7e' % (e, e1, e2, n, k, r), file=out) if filename is not None: out.close()