def __init__(self, generator, name=None, run=True, gtxt='-', non_relativistic_guess=False, xc='PBE'): if isinstance(generator, str): # treat 'generator' as symbol generator = Generator(generator, scalarrel=True, xcname=xc, txt=gtxt, nofiles=True) generator.N *= 4 self.generator = generator self.rgd = AERadialGridDescriptor(generator.beta, generator.N, default_spline_points=100) self.name = name if run: if non_relativistic_guess: ae0 = AllElectron(generator.symbol, scalarrel=False, nofiles=False, txt=gtxt, xcname=xc) ae0.N = generator.N ae0.beta = generator.beta ae0.run() # Now files will be stored such that they can # automagically be used by the next run() generator.run(write_xml=False, use_restart_file=False, **parameters[generator.symbol])
def get_core_eigenvalues(self, a, scalarrel=True): """Return the core eigenvalues by solving the radial schrodinger equation. Using AllElectron potential class, the spherically averaged Kohn--Sham potential is obtained around the spesified atom. The eigenstates for this potential are solved, the the resulting core states returned. Still experimental. """ r, v_g = self.get_spherical_ks_potential(a) # Get xccorr for atom a setup = self.paw.density.setups[a] xccorr = setup.xc_correction symbol = setup.symbol # Create AllElectron object for eigensolver atom = AllElectron(symbol, txt=None, scalarrel=scalarrel) # Calculate initial guess atom.run() # Set the potential atom.vr[:len(v_g)] = v_g # After the setups cutoff, arbitrary barrier is used atom.vr[len(v_g):] = 10.0 # Solve the eigenstates atom.solve() # The display format is just copy paste from AllElectron class # TODO: Make it a method in AllElectron class, thus it can be called directly def t(a): print(a) t('Calculated core eigenvalues of atom ' + str(a) + ':' + symbol) t('state eigenvalue ekin rmax') t('-----------------------------------------------') for m, l, f, e, u in zip(atom.n_j, atom.l_j, atom.f_j, atom.e_j, atom.u_j): # Find kinetic energy: k = e - np.sum(( np.where(abs(u) < 1e-160, 0, u)**2 * #XXXNumeric! atom.vr * atom.dr)[1:] / atom.r[1:]) # Find outermost maximum: g = atom.N - 4 while u[g - 1] >= u[g]: g -= 1 x = atom.r[g - 1:g + 2] y = u[g - 1:g + 2] A = np.transpose(np.array([x**i for i in range(3)])) c, b, a = np.linalg.solve(A, y) assert a < 0.0 rmax = -0.5 * b / a s = 'spdf'[l] t('%d%s^%-4.1f: %12.6f %12.6f %12.3f' % (m, s, f, e, k, rmax)) t('-----------------------------------------------') t('(units: Bohr and Hartree)') return atom.e_j
def _calculate_bound(self): from gpaw.atom.all_electron import AllElectron check_valid_quantum_number(self.Z, self.n, self.l) config_tuples = config_str_to_config_tuples( load_electronic_configurations()[chemical_symbols[self.Z]]) subshell_index = [shell[:2] for shell in config_tuples].index( (self.n, self.l)) with open(os.devnull, "w") as f, contextlib.redirect_stdout(f): ae = AllElectron(chemical_symbols[self.Z], xcname=self.xc) ae.run() # wave = interp1d(ae.r, ae.u_j[subshell_index], kind='cubic', fill_value='extrapolate', bounds_error=False) return ae.ETotal * units.Hartree, (ae.r, ae.u_j[subshell_index])
def __init__(self, generator, name=None, run=True, gtxt='-', non_relativistic_guess=False, xc='PBE', save_setup=False): if isinstance(generator, str): # treat 'generator' as symbol generator = Generator(generator, scalarrel=True, xcname=xc, txt=gtxt, nofiles=True) generator.N *= 4 self.generator = generator self.rgd = AERadialGridDescriptor(generator.beta / generator.N, 1.0 / generator.N, generator.N, default_spline_points=100) self.name = name if run: if non_relativistic_guess: ae0 = AllElectron(generator.symbol, scalarrel=False, nofiles=False, txt=gtxt, xcname=xc) ae0.N = generator.N ae0.beta = generator.beta ae0.run() # Now files will be stored such that they can # automagically be used by the next run() setup = generator.run(write_xml=False, use_restart_file=False, name=name, **parameters[generator.symbol]) if save_setup: setup.write_xml() else: if save_setup: raise ValueError('cannot save setup here because setup ' 'was already generated before basis ' 'generation.')
def write_spherical_ks_potentials(self, txt): f = open(txt, 'w') for a in self.paw.density.D_asp: r_g, vKS_g = self.get_spherical_ks_potential(a) setup = self.paw.density.setups[a] # Calculate also atomic LDA for reference g = AllElectron(setup.symbol, xcname='LDA', nofiles=True, scalarrel=True, txt=None) g.run() print(r_g[0], vKS_g[0], g.vr[0], 0.0, file=f) for r, vKS, vr in zip(r_g[1:], vKS_g[1:], g.vr[1:]): print(r, vKS, vr, (vKS - vr) / r, file=f) f.close()
def _calculate_continuum(self): from gpaw.atom.all_electron import AllElectron check_valid_quantum_number(self.Z, self.n, self.l) config_tuples = config_str_to_config_tuples( load_electronic_configurations()[chemical_symbols[self.Z]]) subshell_index = [shell[:2] for shell in config_tuples].index( (self.n, self.l)) with open(os.devnull, "w") as f, contextlib.redirect_stdout(f): ae = AllElectron(chemical_symbols[self.Z], xcname=self.xc) ae.f_j[subshell_index] -= 1. ae.run() vr = interp1d(ae.r, -ae.vr, fill_value='extrapolate', bounds_error=False) def schroedinger_derivative(y, r, l, e, vr): (u, up) = y return np.array([up, (l * (l + 1) / r**2 - 2 * vr(r) / r - e) * u]) r = np.geomspace(1e-7, 200, 1000000) continuum_waves = {} for lprime in self.lprimes: ur = integrate.odeint(schroedinger_derivative, [0.0, 1.], r, args=(lprime, self.epsilon, vr)) sqrt_k = 1 / ( 2 * self.epsilon / units.Hartree * (1 + units.alpha**2 * self.epsilon / units.Hartree / 2))**.25 ur = ur[:, 0] / ur[:, 0].max( ) / self.epsilon**.5 * units.Rydberg**0.25 / sqrt_k / np.sqrt( np.pi) continuum_waves[lprime] = ( r, ur ) # interp1d(r, ur, kind='cubic', fill_value='extrapolate', bounds_error=False) return ae.ETotal * units.Hartree, continuum_waves
#!/usr/bin/env python # coding: utf-8 # In[1]: from gpaw.atom.all_electron import AllElectron import numpy as np import matplotlib.pyplot as plt # In[2]: ti = AllElectron('Ti', xcname='LDA', scalarrel=True) ti.run() # In[4]: fig = plt.figure(figsize=(10, 7)) for i in range(len(ti.n_j)): plt.plot(ti.rgd.r_g, ti.u_j[i, :], label='n=%i, l=%i' % (ti.n_j[i], ti.l_j[i])) plt.legend() plt.xlim(0, 5) plt.show() # In[5]: rgd = ti.rgd phi, c0 = rgd.pseudize(ti.u_j[6], gc=rgd.ceil(3.0), l=0) # In[6]:
ETotal = { 'Be': -14.572 + 0.012, 'Ne': -128.548 - 0.029, 'Mg': -199.612 - 0.005 } EX = {'Be': -2.666 - 0.010, 'Ne': -12.107 - 0.122, 'Mg': -15.992 - 0.092} EHOMO = {'Be': -0.309 + 0.008, 'Ne': -0.851 + 0.098, 'Mg': -0.253 + 0.006} eignum = {'Be': 0, 'Ne': 3, 'Mg': 0} for xcname in ['GLLB', 'GLLBSC']: atoms = ['Be', 'Ne', 'Mg'] for atom in atoms: # Test AllElectron GLLB GLLB = AllElectron(atom, xcname=xcname, scalarrel=False, gpernode=600) GLLB.run() out("Total energy", xcname + "1D", atom, ETotal[atom], GLLB.ETotal, "Ha") out("Exchange energy", xcname + "1D", atom, EX[atom], GLLB.Exc, "Ha") out("H**O Eigenvalue", xcname + "1D", atom, EHOMO[atom], GLLB.e_j[-1], "Ha") if xcname == 'GLLB': equal(GLLB.ETotal, ETotal[atom], tolerance=1e-2) equal(GLLB.Exc, EX[atom], tolerance=1e-2) equal(GLLB.e_j[-1], EHOMO[atom], tolerance=1e-2) print( " Quanity Method Symbol Ref[1] GPAW Unit " )
def main(): parser = build_parser() opt, args = parser.parse_args() import sys from gpaw.atom.generator import Generator from gpaw.atom.configurations import parameters, tf_parameters from gpaw.atom.all_electron import AllElectron from gpaw import ConvergenceError if args: atoms = args else: atoms = parameters.keys() bad_density_warning = """\ Problem with initial electron density guess! Try to run the program with the '-nw' option (non-scalar-relativistic calculation + write density) and then try again without the '-n' option (this will generate a good initial guess for the density).""" for symbol in atoms: scalarrel = not opt.non_scalar_relativistic corehole = None if opt.core_hole is not None: state, occ = opt.core_hole.split(',') # Translate corestate string ('1s') to n and l: ncorehole = int(state[0]) lcorehole = 'spdf'.find(state[1]) fcorehole = float(occ) corehole = (ncorehole, lcorehole, fcorehole) if opt.all_electron_only: a = AllElectron(symbol, opt.xcfunctional, scalarrel, corehole, opt.configuration, not opt.write_files, '-', opt.points_per_node, opt.orbital_free, opt.tw_coefficient) try: a.run() except ConvergenceError: print(bad_density_warning, file=sys.stderr) continue g = Generator(symbol, opt.xcfunctional, scalarrel, corehole, opt.configuration, not opt.write_files, '-', opt.points_per_node, orbital_free=opt.orbital_free, tw_coeff=opt.tw_coefficient) if opt.orbital_free: p = tf_parameters.get(symbol, {'rcut': 0.9}) else: p = parameters.get(symbol, {}) if opt.core is not None: p['core'] = opt.core if opt.radius is not None: p['rcut'] = [float(x) for x in opt.radius.split(',')] if opt.extra_projectors is not None: extra = {} if opt.extra_projectors != '': for l, x in enumerate(opt.extra_projectors.split(';')): if x != '': extra[l] = [float(y) for y in x.split(',')] p['extra'] = extra if opt.normconserving is not None: p['normconserving'] = opt.normconserving if opt.filter is not None: p['filter'] = [float(x) for x in opt.filter.split(',')] if opt.compensation_charge_radius is not None: p['rcutcomp'] = opt.compensation_charge_radius if opt.zero_potential is not None: vbar = opt.zero_potential.split(',') p['vbar'] = (vbar[0], float(vbar[1])) if opt.empty_states is not None: p['empty_states'] = opt.empty_states try: g.run(logderiv=opt.logarithmic_derivatives, exx=opt.exact_exchange, name=opt.name, use_restart_file=opt.use_restart_file, **p) except ConvergenceError: print(bad_density_warning, file=sys.stderr) except RuntimeError as m: if len(m.__str__()) == 0: raise print(m) if opt.plot: from gpaw.atom.analyse_setup import analyse analyse(g, show=True)
ref2 = 'Gritsenko IntJQuanChem 76, 407 (2000)' # H**O energy in mHa for closed shell atoms e_HOMO_cs = { 'He': 851, 'Be': 321, 'Ne': 788, 'Ar': 577, 'Kr': 529, 'Xe': 474, 'Mg' : 281 + 8 } #e_HOMO_cs = { 'Ne': 788 } txt=None print('--- Comparing LB94 with', ref1) print('and', ref2) print('**** all electron calculations') print('atom [refs] -e_homo diff all in mHa') if rank == 0: for atom in e_HOMO_cs.keys(): ae = AllElectron(atom, 'LB94', txt=txt) ae.run() e_homo = int( ae.e_j[-1] * 10000 + .5 ) / 10. diff = e_HOMO_cs[atom] + e_homo print('%2s %8g %6.1f %4.1g' % (atom, e_HOMO_cs[atom], -e_homo, diff)) assert abs(diff) < 6 barrier() setup_paths.insert(0, '.') setups = {} print('**** 3D calculations') print('atom [refs] -e_homo diff all in mHa') for atom in e_HOMO_cs.keys(): e_ref = e_HOMO_cs[atom]
from gpaw.atom.all_electron import AllElectron a = AllElectron("C") a.run()
# creates: paw_note.pdf import os from distutils.version import LooseVersion import matplotlib import matplotlib.pyplot as plt from gpaw.atom.all_electron import AllElectron ae = AllElectron('Pt') ae.run() fig = plt.figure(figsize=(7, 4), dpi=80) fig.subplots_adjust(left=0.05, bottom=0.11, right=0.85, top=0.95) for n, l, u in zip(ae.n_j, ae.l_j, ae.u_j): plt.plot(ae.r, u, label='%i%s' % (n, 'spdf'[l])) rcut = 2.5 lim = [0, 3.5, -2, 3] plt.plot([rcut, rcut], lim[2:], 'k--', label='_nolegend_') plt.axis(lim) # The pad keyword to legend was deprecated in MPL v. 0.98.4 if LooseVersion(matplotlib.__version__) < '0.98.4': kwpad = {'pad': 0.05} else: kwpad = {'borderpad': 0.05, 'labelspacing': 0.01} plt.legend(loc=(1.02, 0.03), markerscale=1, **kwpad) plt.xlabel(r'$r$ [Bohr]')
from gpaw import * from ase import * from gpaw.atom.all_electron import AllElectron # Calculate Helium atom using 3D-code he = Atoms(positions=[(0,0,0)], symbols='He') he.center(vacuum=3.0) calc = GPAW(h=0.17) he.set_calculator(calc) he.get_potential_energy() # Get the all-electron potential around the nucleus vKS_sLg = calc.nuclei[0].calculate_all_electron_potential(calc.hamiltonian.vHt_g) # Calculate Helium atom using 1D-code he_atom =AllElectron('He') he_atom.run() # Get the KS-potential vKS_atom = he_atom.vr / he_atom.r vKS_atom[0] = vKS_atom[1] # Get the spherical symmetric part and multiply with Y_00 vKS = vKS_sLg[0][0] / sqrt(4*pi) # Compare avg_diff = 0.0 for i, v in enumerate(vKS): avg_diff += abs(vKS_atom[i]-v) avg_diff /= len(vKS)
from gpaw.atom.all_electron import AllElectron def check(name, atomE, atomeig, total, H**O): #print name, " ", atomE,"/", total, " | ", atomeig,"/",H**O," |" print "|", name, " |%12.4f/%12.4f | %12.4f/%12.4f |" % (atomE, total, atomeig, H**O) assert abs(atomE - total) < 8e-3 assert abs(atomeig - H**O) < 1e-3 A = AllElectron('He', 'KLI', False) A.run() HeE = A.Ekin + A.Epot + A.Exc Heeig = A.e_j[0] A = AllElectron('Be', 'KLI', False) A.run() BeE = A.Ekin + A.Epot + A.Exc Beeig = A.e_j[1] A = AllElectron('Ne', 'KLI', False) A.run() NeE = A.Ekin + A.Epot + A.Exc Neeig = A.e_j[2] A = AllElectron('Mg', 'KLI', False) A.run() MgE = A.Ekin + A.Epot + A.Exc