# Calculation of optical spectra with TDDFTΒΆ

In this exercise we calculate optical spectrum of Na2 molecule using linear response time-dependent density functional theory (see also Linear response TDDFT). We start with a normal ground state calculation:

```
from gpaw import GPAW
from ase import Atoms
from gpaw.lrtddft import LrTDDFT
molecule = Atoms('Na2', positions=((0.0, 0.0, 0.0), (3.12, 0.0, 0.0)))
molecule.center(vacuum=4.0)
calc = GPAW(mode='fd', xc='PBE', setups={'Na': '1'}, h=0.25)
molecule.calc = calc
molecule.get_potential_energy()
lr = LrTDDFT(calc, xc='LDA')
lr.write('Omega_Na2.gz')
```

Once the ground state calculation with unoccupied states is finished, the last part of the script performs a linear response TDDFT calculation.

As the construction of the Omega matrix is computationally the most intensive part it is sometimes convenient to perform diagonalisation and construction of spectrum in separate calculations:

```
from gpaw.lrtddft import LrTDDFT, photoabsorption_spectrum
lr = LrTDDFT.read('Omega_Na2.gz')
photoabsorption_spectrum(lr, 'Na2_spectrum.dat', e_min=0.0, e_max=10)
```

The number of electron-hole pairs used in the calculation can be controlled with
`istart`

and `jend`

options of LrTDDFT:

```
LrTDDFT(calc, restrict={'istart':0, 'jend': 10})
```

By default only singlet-singlet transitions are calculated, singlet-triplet
transitions can be calculated by giving the `nspins`

parameter:

```
LrTDDFT(calc, restrict={'istart': 0, 'jend': 10}, nspins=2)
```

Check how the results vary with the number of unoccupied states in the calculation (

`jend`

parameter).Calculate also singlet-triplet transitions. Why do they not show up in the spectrum?

Check how the results vary with the empty space around the molecule.

Try to calculate optical spectrum also with the Time-propagation TDDFT approach and see how the results compare to linear response calculation. Note that the Time-propagation TDDFT examples deal with Be2, you can of course modify it to use Na2 instead.