| 1 |
import numpy as np |
| 2 |
|
| 3 |
from ase.io import write |
| 4 |
from gpaw import GPAW |
| 5 |
from gpaw.tddft.units import au_to_eV |
| 6 |
from gpaw.lcaotddft.ksdecomposition import KohnShamDecomposition |
| 7 |
from gpaw.lcaotddft.densitymatrix import DensityMatrix |
| 8 |
from gpaw.lcaotddft.frequencydensitymatrix import FrequencyDensityMatrix |
| 9 |
|
| 10 |
# Load the objects |
| 11 |
calc = GPAW('unocc.gpw', txt=None) |
| 12 |
calc.initialize_positions() # Initialize in order to calculate density |
| 13 |
ksd = KohnShamDecomposition(calc, 'ksd.ulm') |
| 14 |
dmat = DensityMatrix(calc) |
| 15 |
fdm = FrequencyDensityMatrix(calc, dmat, 'fdm.ulm') |
| 16 |
|
| 17 |
|
| 18 |
def do(w): |
| 19 |
# Select the frequency and the density matrix |
| 20 |
rho_uMM = fdm.FReDrho_wuMM[w] |
| 21 |
freq = fdm.freq_w[w] |
| 22 |
print(f'Frequency: {freq.freq * au_to_eV:.2f} eV') |
| 23 |
print(f'Folding: {freq.folding}') |
| 24 |
|
| 25 |
# Transform the LCAO density matrix to KS basis |
| 26 |
rho_up = ksd.transform(rho_uMM, broadcast=True) |
| 27 |
|
| 28 |
# Induced density |
| 29 |
rho_g = ksd.get_density(calc.wfs, [rho_up[0].imag]) |
| 30 |
|
| 31 |
# Save as a cube file |
| 32 |
write(f'ind_{freq.freq * au_to_eV:.2f}.cube', calc.atoms, data=rho_g) |
| 33 |
|
| 34 |
# Calculate dipole moment for reference |
| 35 |
dm_v = ksd.density.finegd.calculate_dipole_moment(rho_g, center=True) |
| 36 |
absorption = 2 * freq.freq / np.pi * dm_v[0] / au_to_eV * 1e5 |
| 37 |
print(f'Total absorption: {absorption:.2f} eV^-1') |
| 38 |
|
| 39 |
|
| 40 |
do(0) |
| 41 |
do(1) |