Ejemplo n.º 1
0
lr2.diagonalize()

# Unfortunately not all of the lrtddft code is parallel
if rank == 0:
    Epeak = 19.5# The peak we want to investigate (this is alone)
    Elist = np.asarray([lrsingle.get_energy() * Hartree for lrsingle in lr])
    n = np.argmin(np.abs(Elist - Epeak)) # Index of the peak

    E = lr[n].get_energy() * Hartree
    osz = lr[n].get_oscillator_strength()
    print 'Original object        :', E, osz[0]

    # Test the output of analyse
    origstdout = sys.stdout
    sys.stdout = sio = StringIO()
    lr.analyse(n)
    s = sio.getvalue() 
    sys.stdout = origstdout
    match = re.findall(r'%i: E=([0-9]*\.[0-9]*) eV, f=([0-9]*\.[0-9]*)*' % n, s)
    Eanalyse = float(match[0][0])
    oszanalyse = float(match[0][1])
    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)
Ejemplo n.º 2
0
lr2.diagonalize()

# Unfortunately not all of the lrtddft code is parallel
if rank == 0:
    Epeak = 19.5  # The peak we want to investigate (this is alone)
    Elist = np.asarray([lrsingle.get_energy() * Hartree for lrsingle in lr])
    n = np.argmin(np.abs(Elist - Epeak))  # Index of the peak

    E = lr[n].get_energy() * Hartree
    osz = lr[n].get_oscillator_strength()
    print('Original object        :', E, osz[0])

    # Test the output of analyse
    origstdout = sys.stdout
    sys.stdout = sio = StringIO()
    lr.analyse(n)
    s = sio.getvalue()
    sys.stdout = origstdout
    match = re.findall(r'%i: E=([0-9]*\.[0-9]*) eV, f=([0-9]*\.[0-9]*)*' % n,
                       s)
    Eanalyse = float(match[0][0])
    oszanalyse = float(match[0][1])
    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
Ejemplo n.º 3
0
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)
# 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('----------------------------------------------------------------------')