Debian Codegraph @

doc/tutorialsexercises/energetics/rpa_tut/plot_c2cu.py

raw
1 # web-page: c2cu.png
2 from pathlib import Path
3
4 import matplotlib.pyplot as plt
5 import numpy as np
6 from ase.io import read
7
8 fig, ax = plt.subplots()
9
10 for xc in ['LDA', 'vdW-DF', 'PBE']:
11 data = []
12 for p in Path().glob(f'{xc}-*.txt'):
13 atoms = read(p)
14 d = atoms.positions[-1, 2] - atoms.positions[3, 2]
15 e = atoms.get_potential_energy()
16 data.append((d, e / 2))
17 x, y = np.array(sorted(data)).T
18 ax.plot(x, y - y[-1], 'x-', label=xc)
19
20 data = []
21 for p in Path().glob('RPA-*.result'):
22 d, e, _, _ = (float(x) for x in p.read_text().split())
23 data.append((d, e / 2))
24 x, y = np.array(sorted(data)).T
25 ax.plot(x, y - y[-1], 'o-', label='RPA')
26 ax.set_xlim(right=7)
27 ax.set_ylim(top=0.3)
28 ax.set_xlabel('distance [Å]')
29 ax.set_ylabel('energy [eV/C-atom]')
30 plt.legend()
31 plt.savefig('c2cu.png')