예제 #1
0
파일: spectrum.py 프로젝트: thonmaker/gpaw
from gpaw import restart
from gpaw.lrtddft import LrTDDFT, photoabsorption_spectrum

atoms, calc = restart('na2_gs_unocc.gpw')

# Calculate the omega matrix
lr = LrTDDFT(calc, xc='LDA', jend=5)
# Use only 5 unoccupied states

# Save the omega matrix
lr.write('Omega_Na2.gz')

# Diagonalize the matrix
lr.diagonalize()

# Analyse 5 lowest excitations
lr.analyse(range(5))
photoabsorption_spectrum(lr, 'Na2_spectrum.dat', e_min=0.0, e_max=10)
예제 #2
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)
예제 #3
0
from gpaw import GPAW
from gpaw.lrtddft import LrTDDFT, photoabsorption_spectrum
from gpaw.inducedfield.inducedfield_lrtddft import LrTDDFTInducedField

# Load LrTDDFT object
lr = LrTDDFT('na2_lr.dat.gz')

# Calculate photoabsorption spectrum as usual
folding = 'Gauss'
width = 0.1
e_min = 0.0
e_max = 4.0
photoabsorption_spectrum(lr,
                         'na2_casida_spectrum.dat',
                         folding=folding,
                         width=width,
                         e_min=e_min,
                         e_max=e_max,
                         delta_e=1e-2)

# Load GPAW object
calc = GPAW('na2_gs_casida.gpw')

# Calculate induced field
frequencies = [1.0, 2.08]  # Frequencies of interest in eV
folding = 'Gauss'  # Folding function
width = 0.1  # Line width for folding in eV
kickdir = 0  # Kick field direction 0, 1, 2 for x, y, z
ind = LrTDDFTInducedField(paw=calc,
                          lr=lr,
                          frequencies=frequencies,
예제 #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
    calc.write('Na2.gpw','all')

if bse:
    
    bse = BSE('Na2.gpw',w=np.linspace(0,15,151),
              q=np.array([0,0,0.0001]),optical_limit=True,ecut=50.,
              nbands=8)
    bse.initialize()
    bse.calculate()
    
    w = np.real(bse.w_S) * Hartree
    energies = np.sort(w[:,np.nonzero(w>0)[0]])
    print energies

if casida:

    from gpaw.lrtddft import LrTDDFT
    from gpaw.lrtddft import photoabsorption_spectrum

    calc = GPAW('Na2.gpw',txt=None)

    lr = LrTDDFT(calc, xc=None, istart=0, jend=7, nspins=1) 
    lr.diagonalize()
    photoabsorption_spectrum(lr, 'Na2_spectrum.dat', width=0.05)   

    energies_lrtddft =  lr.get_energies() * Hartree
    print 'lrTDDFT:', energies_lrtddft
    
if compare:
    assert (np.abs(energies - energies_lrtddft)).max() < 3*1e-3
예제 #6
0
              mode='RPA',
              coupling=True,
              q=np.array([0,0,0.0001]),
              optical_limit=True,
              ecut=50.,
              nbands=8)
    bse.initialize()
    H_SS = bse.calculate()
    bse.diagonalize(H_SS)
    
    w = np.real(bse.w_S) * Hartree
    print np.shape(w)
    energies = np.sort(w)[len(w)/2:]
    print 'BSE:', energies

if casida:
    from gpaw.lrtddft import LrTDDFT
    from gpaw.lrtddft import photoabsorption_spectrum

    calc = GPAW('Na2.gpw',txt=None)

    lr = LrTDDFT(calc, xc=None, istart=0, jend=7, nspins=1) 
    lr.diagonalize()
    photoabsorption_spectrum(lr, 'Na2_spectrum.dat', width=0.05)   

    energies_lrtddft = lr.get_energies() * Hartree
    print 'lrTDDFT:', energies_lrtddft
    
if compare:
    assert (np.abs(energies - energies_lrtddft)).max() < 3*1e-3
from gpaw import GPAW
from gpaw.lrtddft import LrTDDFT, photoabsorption_spectrum
from gpaw.inducedfield.inducedfield_lrtddft import LrTDDFTInducedField

# Load LrTDDFT object
lr = LrTDDFT('na2_lr.dat.gz')

# Calculate photoabsorption spectrum as usual
folding = 'Gauss'
width = 0.1
e_min = 0.0
e_max = 4.0
photoabsorption_spectrum(lr, 'na2_casida_spectrum.dat',
                         folding=folding, width=width,
                         e_min=e_min, e_max=e_max, delta_e=1e-2)

# Load GPAW object
calc = GPAW('na2_gs_casida.gpw')
print calc.wfs.rank_a

# Calculate induced field
frequencies = [1.0, 2.08]     # Frequencies of interest in eV
folding = 'Gauss'             # Folding function
width = 0.1                   # Line width for folding in eV
kickdir = 0                   # Kick field direction 0, 1, 2 for x, y, z
ind = LrTDDFTInducedField(paw=calc,
                          lr=lr,
                          frequencies=frequencies,
                          folding=folding,
                          width=width,
                          kickdir=kickdir)
# GPAW
from gpaw import GPAW
from gpaw.lrtddft import LrTDDFT
from gpaw.lrtddft import photoabsorption_spectrum

print(
    f'------------   Extracting shortened photoabsorption spectrum   ------------'
)

start = time.time()

# Import LrTDDFT results from Task 1
lr = LrTDDFT('../task1/TDDFT_Task1.dat')

lr.diagonalize(energy_range=4)  # Only include up to 4 eV

# Generate spectrum and save it
wd = 0.06
photoabsorption_spectrum(lr, f'spectrum_w{wd}.dat', width=wd)

# Extract all information about all transitions
print('** LrTDDFT.analyse() output **')
lr.analyse()
print('*******************************')

end = time.time()
print('-------- Photoabsorption spectrum extracted in: ' +
      f'{(end-start):.2f} s --------'.rjust(34))
print('----------------------------------------------------------------------')
예제 #9
0
specfile = sy + '_lcao_' + b + '_rt_z.spectrum' + str(world.size)
calc.absorption_kick([0.0, 0, 0.001])
calc.propagate(10, 20, dmfile)
if world.rank == 0:
    photoabsorption_spectrum(dmfile, specfile)

if 0:
    # Reference RS-LR-TDDFT
    calc = GPAW(xc=xc, h=h, charge=c, width=0, nbands=4)
    atoms.set_calculator(calc)
    atoms.get_potential_energy()
    lr = lrtddft.LrTDDFT(calc, finegrid=0)
    lr.diagonalize()
    if world.rank == 0:
        lrtddft.photoabsorption_spectrum(lr,
                                         sy + '_rs_lr.spectrum',
                                         e_min=0.0,
                                         e_max=40)

    # Reference LCAO-LR-TDDFT
    calc = GPAW(mode='lcao', xc=xc, h=h, basis=b, charge=c, width=0)
    atoms.set_calculator(calc)
    atoms.get_potential_energy()
    lr = lrtddft.LrTDDFT(calc, finegrid=0)
    lr.diagonalize()
    if world.rank == 0:
        lrtddft.photoabsorption_spectrum(lr,
                                         sy + '_lcao_' + b + '_lr.spectrum',
                                         e_min=0.0,
                                         e_max=400)

    # XXX Actually check that the spectums match
예제 #10
0
                parallel={'band':2})
atoms.set_calculator(calc)
atoms.get_potential_energy()
dmfile = sy+'_lcao_'+b+'_rt_z.dm'+str(world.size)
specfile = sy+'_lcao_'+b+'_rt_z.spectrum'+str(world.size)
calc.absorption_kick([0.0,0,0.001])
calc.propagate(10, 20, dmfile)
if world.rank == 0:
    photoabsorption_spectrum(dmfile, specfile)

if 0:
    # Reference RS-LR-TDDFT
    calc = GPAW(xc=xc, h=h, charge=c, width=0, nbands=4)
    atoms.set_calculator(calc)
    atoms.get_potential_energy()
    lr = lrtddft.LrTDDFT(calc, finegrid=0)
    lr.diagonalize()
    if world.rank == 0:
        lrtddft.photoabsorption_spectrum(lr, sy+'_rs_lr.spectrum', e_min=0.0, e_max=40)

    # Reference LCAO-LR-TDDFT
    calc = GPAW(mode='lcao', xc=xc, h=h, basis=b, charge=c, width=0)
    atoms.set_calculator(calc)
    atoms.get_potential_energy()
    lr = lrtddft.LrTDDFT(calc, finegrid=0)
    lr.diagonalize()
    if world.rank == 0:
        lrtddft.photoabsorption_spectrum(lr, sy+'_lcao_'+b+'_lr.spectrum', e_min=0.0, e_max=400)

    # XXX Actually check that the spectums match
예제 #11
0
        mode="RPA",
        coupling=True,
        q=np.array([0, 0, 0.0001]),
        optical_limit=True,
        ecut=50.0,
        nbands=8,
    )
    bse.initialize()
    H_SS = bse.calculate()
    bse.diagonalize(H_SS)

    w = np.real(bse.w_S) * Hartree
    energies = np.sort(w[:, np.nonzero(w > 0)[0]])
    print "BSE:", energies

if casida:
    from gpaw.lrtddft import LrTDDFT
    from gpaw.lrtddft import photoabsorption_spectrum

    calc = GPAW("Na2.gpw", txt=None)

    lr = LrTDDFT(calc, xc=None, istart=0, jend=7, nspins=1)
    lr.diagonalize()
    photoabsorption_spectrum(lr, "Na2_spectrum.dat", width=0.05)

    energies_lrtddft = lr.get_energies() * Hartree
    print "lrTDDFT:", energies_lrtddft

if compare:
    assert (np.abs(energies - energies_lrtddft)).max() < 3 * 1e-3