# Ground-state calculation from gpaw import GPAW calc = GPAW(mode='lcao', h=0.3, basis='dzp', setups={'Na': '1'}, poissonsolver=poissonsolver, convergence={'density': 1e-8}) atoms.set_calculator(calc) energy = atoms.get_potential_energy() calc.write('gs.gpw', mode='all') # Time-propagation calculation from gpaw.lcaotddft import LCAOTDDFT from gpaw.lcaotddft.dipolemomentwriter import DipoleMomentWriter # Read converged ground-state file td_calc = LCAOTDDFT('gs.gpw') # Attach any data recording or analysis tools DipoleMomentWriter(td_calc, 'dm.dat') # Kick td_calc.absorption_kick([0.0, 0.0, 1e-5]) # Propagate td_calc.propagate(10, 3000) # Save the state for restarting later td_calc.write('td.gpw', mode='all') # Analyze the results from gpaw.tddft.spectrum import photoabsorption_spectrum photoabsorption_spectrum('dm.dat', 'spec.dat')
from gpaw.lcaotddft import LCAOTDDFT from gpaw.lcaotddft.dipolemomentwriter import DipoleMomentWriter from gpaw.lcaotddft.wfwriter import WaveFunctionWriter # Read the ground-state file td_calc = LCAOTDDFT('gs.gpw', txt='td.out') # Attach any data recording or analysis tools DipoleMomentWriter(td_calc, 'dm.dat') WaveFunctionWriter(td_calc, 'wf.ulm') # Kick and propagate td_calc.absorption_kick([1e-5, 0., 0.]) td_calc.propagate(20, 1500) # Save the state for restarting later td_calc.write('td.gpw', mode='all')
from ase import Atoms from gpaw.tddft import photoabsorption_spectrum from gpaw import PoissonSolver from gpaw.lcaotddft.tddfpt import DensityCollector from gpaw.lcaotddft import LCAOTDDFT atoms = Atoms('Na8', positions=[[i * 3.0, 0, 0] for i in range(8)]) atoms.center(vacuum=5.0) # Calculate all bands td_calc = LCAOTDDFT(basis='dzp', setups={'Na': '1'}, xc='LDA', h=0.3, nbands=4, convergence={'density': 1e-7}, poissonsolver=PoissonSolver(eps=1e-14, remove_moment=1 + 3 + 5)) atoms.set_calculator(td_calc) atoms.get_potential_energy() td_calc.write('Na8_gs.gpw', mode='all') td_calc = LCAOTDDFT('Na8_gs.gpw') td_calc.attach(DensityCollector('Na8.TdDen', td_calc)) td_calc.absorption_kick([1e-4, 0.0, 0.0]) td_calc.propagate(20, 1000, 'Na8.dm') photoabsorption_spectrum('Na8.dm', 'Na8.spec', width=0.15)
setups=dict(Na='1'), basis='sz(dzp)', mode='lcao', xc='oldLDA', poissonsolver=PoissonSolver(eps=1e-16), convergence={'density': 1e-8}, txt='gs.out') atoms.set_calculator(calc) energy = atoms.get_potential_energy() calc.write('gs.gpw', mode='all') # Time-propagation calculation td_calc = LCAOTDDFT('gs.gpw', txt='td.out') DipoleMomentWriter(td_calc, 'dm.dat') td_calc.absorption_kick([0, 0, 1e-5]) td_calc.propagate(30, 150) photoabsorption_spectrum('dm.dat', 'spec.dat', e_max=10, width=0.5, delta_e=0.1) # LrTDDFT2 calculation calc = GPAW('gs.gpw', txt='lr.out') lr = LrTDDFT2('lr2', calc, fxc='LDA') lr.calculate() lr.get_spectrum('lr_spec.dat', 0, 10.1, 0.1, width=0.5) world.barrier() # Scale spectra due to slightly different definitions spec1_ej = np.loadtxt('spec.dat')
# Atoms atoms = molecule('Na2') atoms.center(vacuum=4.0) # Ground-state calculation that will never converge maxiter = 100 calc = GPAW(mode='lcao', basis='sz(dzp)', setups='1', convergence={'density': 1e-100}, maxiter=maxiter) atoms.set_calculator(calc) tl = TimeLimiter(calc, timelimit=0, output='scf.txt') tl.reset('scf', min_updates=3) try: atoms.get_potential_energy() except KohnShamConvergenceError: assert calc.scf.maxiter < maxiter, 'TimeLimiter did not break the SCF loop' else: raise AssertionError('SCF loop ended too early') calc.write('gs.gpw', mode='all') # Time-propagation calculation that will never finish td_calc = LCAOTDDFT('gs.gpw') tl = TimeLimiter(td_calc, timelimit=0, output='tddft.txt') tl.reset('tddft', min_updates=3) td_calc.propagate(10, maxiter - td_calc.niter) assert td_calc.maxiter < maxiter, 'TimeLimiter did not break the TDDFT loop'
h=0.4, basis='dzp', mode='lcao', poissonsolver=PoissonSolver(eps=1e-16), convergence={'density': 1e-8}, xc='GLLBSC', txt='gs.out') atoms.set_calculator(calc) energy = atoms.get_potential_energy() calc.write('gs.gpw', mode='all') # Time-propagation calculation td_calc = LCAOTDDFT('gs.gpw', txt='td.out') DipoleMomentWriter(td_calc, 'dm.dat') td_calc.absorption_kick(np.ones(3) * 1e-5) td_calc.propagate(20, 3) # Write a restart point td_calc.write('td.gpw', mode='all') # Keep propagating td_calc.propagate(20, 3) # Restart from the restart point td_calc = LCAOTDDFT('td.gpw', txt='td2.out') DipoleMomentWriter(td_calc, 'dm.dat') td_calc.propagate(20, 3) world.barrier() # Check dipole moment file data_tj = np.loadtxt('dm.dat')
basis='dzp', mode='lcao', poissonsolver=PoissonSolver(eps=1e-16), convergence={'density': 1e-8}, xc='GLLBSC', txt='gs.out') atoms.set_calculator(calc) energy = atoms.get_potential_energy() calc.write('gs.gpw', mode='all') fxc = 'LDA' # Time-propagation calculation with fxc td_calc = LCAOTDDFT('gs.gpw', fxc=fxc, txt='td_fxc.out') DipoleMomentWriter(td_calc, 'dm_fxc.dat') td_calc.absorption_kick(np.ones(3) * 1e-5) td_calc.propagate(20, 4) # Time-propagation calculation with linearize_to_fxc() td_calc = LCAOTDDFT('gs.gpw', txt='td_lin.out') td_calc.linearize_to_xc(fxc) DipoleMomentWriter(td_calc, 'dm_lin.dat') td_calc.absorption_kick(np.ones(3) * 1e-5) td_calc.propagate(20, 4) # Test the equivalence world.barrier() ref = np.loadtxt('dm_fxc.dat').ravel() data = np.loadtxt('dm_lin.dat').ravel() tol = 1e-9 equal(data, ref, tol)
convergence = {'density': 1e-6} # Increase accuracy of Poisson Solver and apply multipole corrections up to l=2 poissonsolver = PoissonSolver(eps=1e-14, remove_moment=1 + 3) td_calc = LCAOTDDFT(xc='GLLBSC', basis='GLLBSC.dz', h=0.3, nbands=352, convergence=convergence, poissonsolver=poissonsolver, occupations=FermiDirac(0.1), parallel={ 'sl_default': (8, 8, 32), 'band': 2 }) atoms.set_calculator(td_calc) # Relax the ground state atoms.get_potential_energy() # For demonstration purposes, save intermediate ground state result to a file td_calc.write('ag55.gpw', mode='all') td_calc = LCAOTDDFT('ag55.gpw', parallel={'sl_default': (8, 8, 32), 'band': 2}) td_calc.absorption_kick([1e-5, 0.0, 0.0]) td_calc.propagate(20, 500, 'ag55.dm') photoabsorption_spectrum('ag55.dm', 'ag55.spec', width=0.2)
calc = GPAW(nbands=2, h=0.4, setups=dict(Na='1'), basis='dzp', mode='lcao', poissonsolver=PoissonSolver(eps=1e-16), convergence={'density': 1e-8}, txt='gs.out') atoms.set_calculator(calc) energy = atoms.get_potential_energy() calc.write('gs.gpw', mode='all') # Time-propagation calculation td_calc = LCAOTDDFT('gs.gpw', txt='td.out') DipoleMomentWriter(td_calc, 'dm.dat') WaveFunctionWriter(td_calc, 'wf.ulm') WaveFunctionWriter(td_calc, 'wf_split.ulm', split=True) td_calc.absorption_kick(np.ones(3) * 1e-5) td_calc.propagate(20, 3) td_calc.write('td.gpw', mode='all') td_calc.propagate(7, 3) # Restart from the restart point td_calc = LCAOTDDFT('td.gpw', txt='td2.out') DipoleMomentWriter(td_calc, 'dm.dat') WaveFunctionWriter(td_calc, 'wf.ulm') WaveFunctionWriter(td_calc, 'wf_split.ulm') td_calc.propagate(20, 3) td_calc.propagate(20, 3) td_calc.propagate(10, 3) photoabsorption_spectrum('dm.dat', 'spec.dat') world.barrier() ref_i = np.loadtxt('spec.dat').ravel()
from gpaw import PoissonSolver # Sodium dimer atoms = Atoms('Na2', positions=[[0.0, 0.0, 0.0], [3.0, 0.0, 0.0]]) atoms.center(vacuum=3.5) from gpaw.lcaotddft import LCAOTDDFT # Increase accuragy of density for ground state convergence = {'density': 1e-7} # Increase accuracy of Poisson Solver and apply multipole corrections up to l=1 poissonsolver = PoissonSolver(eps=1e-14, remove_moment=1 + 3) td_calc = LCAOTDDFT(setups={'Na': '1'}, basis='dzp', xc='LDA', h=0.3, nbands=1, convergence=convergence, poissonsolver=poissonsolver) atoms.set_calculator(td_calc) # Relax the ground state atoms.get_potential_energy() td_calc.absorption_kick([1e-5, 0.0, 0.0]) td_calc.propagate(20, 250, 'Na2.dm') photoabsorption_spectrum('Na2.dm', 'Na2.spec', width=0.4)
setups=dict(Na='1'), basis='dzp', mode='lcao', poissonsolver=PoissonSolver(eps=1e-16), convergence={'density': 1e-8}, xc='LDA', txt='gs.out') atoms.set_calculator(calc) energy = atoms.get_potential_energy() calc.write('gs.gpw', mode='all') # Time-propagation calculation without fxc td_calc = LCAOTDDFT('gs.gpw', txt='td.out') DipoleMomentWriter(td_calc, 'dm.dat') td_calc.absorption_kick(np.ones(3) * 1e-5) td_calc.propagate(20, 4) world.barrier() # Check dipole moment file ref = np.loadtxt('dm.dat').ravel() # Time-propagation calculation with fxc=xc td_calc = LCAOTDDFT('gs.gpw', fxc='LDA', txt='td_fxc.out') DipoleMomentWriter(td_calc, 'dm_fxc.dat') td_calc.absorption_kick(np.ones(3) * 1e-5) td_calc.propagate(20, 1) td_calc.write('td_fxc.gpw', mode='all') # Restart from the restart point td_calc = LCAOTDDFT('td_fxc.gpw', txt='td_fxc2.out') DipoleMomentWriter(td_calc, 'dm_fxc.dat')