File: plot_g2.py

package info (click to toggle)
gpaw 25.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 18,888 kB
  • sloc: python: 174,804; ansic: 17,564; cpp: 5,668; sh: 972; csh: 139; makefile: 45
file content (70 lines) | stat: -rw-r--r-- 1,995 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# web-page: g2.png
import matplotlib.pyplot as plt
import numpy as np
from doc.documentation.directmin import tools_and_data


def read_molecules(filename, molnames):

    with open(filename, 'r') as fd:
        calculated_data_string = fd.read()
        calculated_data = \
            tools_and_data.read_data(calculated_data_string)

    data2return = []
    for _ in molnames:
        data2return.append(_)
        data2return.append(calculated_data[_][0])

    return data2return


f = plt.figure(figsize=(12, 4), dpi=240)
plt.subplot(121)
mollist = \
    ['PH3', 'P2', 'CH3CHO', 'H2COH', 'CS', 'OCHCHO',
     'C3H9C', 'CH3COF', 'CH3CH2OCH3', 'HCOOH']
data = read_molecules('scf-g2-results.txt', mollist)
# scf
x = data[::2]
y = data[1::2]
plt.xticks(range(len(x)), x, rotation=45)
plt.grid(color='k', linestyle=':', linewidth=0.3)
plt.plot(range(len(x)), y, 'b^-', label='SCF', fillstyle='none')

# direct_min
data = read_molecules('dm-g2-results.txt', mollist)
x = data[::2]
# 2 is added to account for the diagonalization
# performed at the beginning and at the end of etdm
y = np.asarray(data[1::2]) + 2

plt.plot(range(len(x)), y, 'ro-', label='ETDM',
         fillstyle='none')
plt.legend()
plt.ylabel('Number of iterations (energy and gradients calls)')

plt.subplot(122)
# direct_min
mollist = \
    ['NO', 'CH', 'OH', 'ClO', 'SH']
data = read_molecules('dm-g2-results.txt', mollist)
x = data[::2]
y = np.asarray(data[1::2]) + 2

plt.xticks(range(len(x)), x, rotation=45)
plt.grid(color='k', linestyle=':', linewidth=0.3)
plt.plot(range(len(x)), y, 'ro-', label='ETDM',
         fillstyle='none')
# scf
data = read_molecules('scf-g2-results.txt', mollist)
x = data[::2]
y = np.asarray(data[1::2])
plt.xticks(range(len(x)), x, rotation=45)
plt.grid(color='k', linestyle=':', linewidth=0.3)
plt.plot(range(len(x)), y, 'bo-', label='SCF',
         fillstyle='none')
plt.legend()
plt.ylabel('Number of iterations (energy and gradients calls)')

f.savefig("g2.png", bbox_inches='tight')