Debian Codegraph @

doc/tutorialsexercises/opticalresponse/tddft/inducedfield/timepropagation_plot.py

raw
1 # web-page: na2_td_Ffe.png, na2_td_Frho.png, na2_td_Fphi.png
2 from gpaw.mpi import world
3
4 import numpy as np
5 import matplotlib.pyplot as plt
6
7 from gpaw.inducedfield.inducedfield_base import BaseInducedField
8 from gpaw.tddft.units import aufrequency_to_eV
9
10 assert world.size == 1, 'Script should be run in serial mode (one process).'
11
12
13 # Helper function
14 def do_plot(d_g, ng, box, atoms):
15 # Take slice of data array
16 d_yx = d_g[:, ng[1] // 2, :]
17 y = np.linspace(0, box[0], ng[0])
18 ylabel = u'x / Å'
19 x = np.linspace(0, box[2], ng[2])
20 xlabel = u'z / Å'
21
22 # Plot
23 plt.figure()
24 ax = plt.subplot(1, 1, 1)
25 X, Y = np.meshgrid(x, y)
26 plt.contourf(X, Y, d_yx, 40)
27 plt.colorbar()
28 for atom in atoms:
29 pos = atom.position
30 plt.scatter(pos[2], pos[0], s=50, c='k', marker='o')
31 plt.xlabel(xlabel)
32 plt.ylabel(ylabel)
33 plt.xlim([x[0], x[-1]])
34 plt.ylim([y[0], y[-1]])
35 ax.set_aspect('equal')
36
37
38 # Read InducedField object
39 ind = BaseInducedField('na2_td_field.ind', readmode='all')
40
41 # Choose array
42 w = 1 # Frequency index
43 freq = ind.omega_w[w] * aufrequency_to_eV # Frequency
44 box = np.diag(ind.atoms.get_cell()) # Calculation box
45 d_g = ind.Ffe_wg[w] # Data array
46 ng = d_g.shape # Size of grid
47 atoms = ind.atoms # Atoms
48
49 do_plot(d_g, ng, box, atoms)
50 plt.title(f'Field enhancement @ {freq:.2f} eV')
51 plt.savefig('na2_td_Ffe.png', bbox_inches='tight')
52
53 # Imaginary part of density
54 d_g = ind.Frho_wg[w].imag
55 ng = d_g.shape
56 do_plot(d_g, ng, box, atoms)
57 plt.title(f'Imaginary part of induced charge density @ {freq:.2f} eV')
58 plt.savefig('na2_td_Frho.png', bbox_inches='tight')
59
60 # Imaginary part of potential
61 d_g = ind.Fphi_wg[w].imag
62 ng = d_g.shape
63 do_plot(d_g, ng, box, atoms)
64 plt.title(f'Imaginary part of induced potential @ {freq:.2f} eV')
65 plt.savefig('na2_td_Fphi.png', bbox_inches='tight')