| 1 |
# web-page: tcm_1.12.png, tcm_2.48.png, table_1.12.txt, table_2.48.txt |
| 2 |
import numpy as np |
| 3 |
from matplotlib import pyplot as plt |
| 4 |
|
| 5 |
from gpaw import GPAW |
| 6 |
from gpaw.tddft.units import au_to_eV |
| 7 |
from gpaw.lcaotddft.ksdecomposition import KohnShamDecomposition |
| 8 |
from gpaw.lcaotddft.densitymatrix import DensityMatrix |
| 9 |
from gpaw.lcaotddft.frequencydensitymatrix import FrequencyDensityMatrix |
| 10 |
from gpaw.lcaotddft.tcm import TCMPlotter |
| 11 |
|
| 12 |
# Load the objects |
| 13 |
calc = GPAW('unocc.gpw', txt=None) |
| 14 |
ksd = KohnShamDecomposition(calc, 'ksd.ulm') |
| 15 |
dmat = DensityMatrix(calc) |
| 16 |
fdm = FrequencyDensityMatrix(calc, dmat, 'fdm.ulm') |
| 17 |
|
| 18 |
plt.figure(figsize=(8, 8)) |
| 19 |
|
| 20 |
|
| 21 |
def do(w): |
| 22 |
# Select the frequency and the density matrix |
| 23 |
rho_uMM = fdm.FReDrho_wuMM[w] |
| 24 |
freq = fdm.freq_w[w] |
| 25 |
frequency = freq.freq * au_to_eV |
| 26 |
print(f'Frequency: {frequency:.2f} eV') |
| 27 |
print(f'Folding: {freq.folding}') |
| 28 |
|
| 29 |
# Transform the LCAO density matrix to KS basis |
| 30 |
rho_up = ksd.transform(rho_uMM) |
| 31 |
|
| 32 |
# Photoabsorption decomposition |
| 33 |
dmrho_vp = ksd.get_dipole_moment_contributions(rho_up) |
| 34 |
weight_p = 2 * freq.freq / np.pi * dmrho_vp[0].imag / au_to_eV * 1e5 |
| 35 |
print(f'Total absorption: {np.sum(weight_p):.2f} eV^-1') |
| 36 |
|
| 37 |
# Print contributions as a table |
| 38 |
table = ksd.get_contributions_table(weight_p, minweight=0.1) |
| 39 |
print(table) |
| 40 |
with open(f'table_{frequency:.2f}.txt', 'w') as f: |
| 41 |
f.write(f'Frequency: {frequency:.2f} eV\n') |
| 42 |
f.write(f'Folding: {freq.folding}\n') |
| 43 |
f.write(f'Total absorption: {np.sum(weight_p):.2f} eV^-1\n') |
| 44 |
f.write(table) |
| 45 |
|
| 46 |
# Plot the decomposition as a TCM |
| 47 |
de = 0.01 |
| 48 |
energy_o = np.arange(-3, 0.1 + 1e-6, de) |
| 49 |
energy_u = np.arange(-0.1, 3 + 1e-6, de) |
| 50 |
plt.clf() |
| 51 |
plotter = TCMPlotter(ksd, energy_o, energy_u, sigma=0.1) |
| 52 |
plotter.plot_TCM(weight_p) |
| 53 |
plotter.plot_DOS(fill={'color': '0.8'}, line={'color': 'k'}) |
| 54 |
plotter.plot_TCM_diagonal(freq.freq * au_to_eV, color='k') |
| 55 |
plotter.set_title(f'Photoabsorption TCM of Na8 at {frequency:.2f} eV') |
| 56 |
|
| 57 |
# Check that TCM integrates to correct absorption |
| 58 |
tcm_ou = ksd.get_TCM(weight_p, ksd.get_eig_n()[0], |
| 59 |
energy_o, energy_u, sigma=0.1) |
| 60 |
print(f'TCM absorption: {np.sum(tcm_ou) * de ** 2:.2f} eV^-1') |
| 61 |
|
| 62 |
# Save the plot |
| 63 |
plt.savefig(f'tcm_{frequency:.2f}.png') |
| 64 |
|
| 65 |
|
| 66 |
do(0) |
| 67 |
do(1) |