| 1 |
# web-page: ind_1.12.png, ind_2.48.png |
| 2 |
import numpy as np |
| 3 |
import matplotlib.pyplot as plt |
| 4 |
|
| 5 |
from ase.io import read |
| 6 |
from gpaw.mpi import world |
| 7 |
|
| 8 |
assert world.size == 1, 'This script should be run in serial mode.' |
| 9 |
|
| 10 |
|
| 11 |
def do(freq): |
| 12 |
# Read cube file |
| 13 |
cube = read(f'ind_{freq:.2f}.cube', full_output=True) |
| 14 |
d_g = cube['data'] |
| 15 |
atoms = cube['atoms'] |
| 16 |
box = np.diag(atoms.get_cell()) |
| 17 |
ng = d_g.shape |
| 18 |
|
| 19 |
# Take slice of data array |
| 20 |
d_yx = d_g[:, :, ng[2] // 2] |
| 21 |
x = np.linspace(0, box[0], ng[0]) |
| 22 |
xlabel = u'x (Å)' |
| 23 |
y = np.linspace(0, box[1], ng[1]) |
| 24 |
ylabel = u'y (Å)' |
| 25 |
|
| 26 |
# Plot |
| 27 |
plt.figure(figsize=(8, 3.5)) |
| 28 |
ax = plt.subplot(1, 1, 1) |
| 29 |
X, Y = np.meshgrid(x, y) |
| 30 |
dmax = max(d_yx.min(), d_yx.max()) |
| 31 |
vmax = 0.9 * dmax |
| 32 |
vmin = -vmax |
| 33 |
plt.pcolormesh(X, Y, d_yx.T, cmap='RdBu_r', vmin=vmin, vmax=vmax, |
| 34 |
shading='auto') |
| 35 |
contours = np.sort(np.outer([-1, 1], [0.02]).ravel() * dmax) |
| 36 |
plt.contour(X, Y, d_yx.T, contours, cmap='RdBu_r', vmin=-1e-10, vmax=1e-10) |
| 37 |
for atom in atoms: |
| 38 |
pos = atom.position |
| 39 |
plt.scatter(pos[0], pos[1], s=100, c='k', marker='o') |
| 40 |
plt.xlabel(xlabel) |
| 41 |
plt.ylabel(ylabel) |
| 42 |
plt.xlim([x[0], x[-1]]) |
| 43 |
plt.ylim([y[0], y[-1]]) |
| 44 |
ax.set_aspect('equal') |
| 45 |
|
| 46 |
plt.title(f'Induced density of Na8 at {freq:.2f} eV') |
| 47 |
plt.tight_layout() |
| 48 |
plt.savefig(f'ind_{freq:.2f}.png') |
| 49 |
|
| 50 |
|
| 51 |
do(1.12) |
| 52 |
do(2.48) |