-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbm_reader.py
More file actions
128 lines (106 loc) · 3.12 KB
/
Copy pathbm_reader.py
File metadata and controls
128 lines (106 loc) · 3.12 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# This script reads the energies and volumes of the optimised
# structures with the directories generated before and
# generates a plot to show the minimum E, V.
import re
from ase import Atoms
from ase.io import read
from ase.eos import EquationOfState
from glob import glob
import os
from matplotlib import pyplot as plt
import sys
def energy():
outcar_lines = []
lines = []
with open('OUTCAR', 'rt') as energy_file:
for energy_line in energy_file:
outcar_lines.append(energy_line)
substr = "energy(sigma->0)"
for linenum, line in enumerate(outcar_lines):
index = 0
str = outcar_lines[linenum]
index = str.find(substr, index)
correct_lines = 0
if index != -1:
correct_lines = linenum
if correct_lines != 0:
line = correct_lines
lines.append(line)
number = max(lines)
return re.findall("[-+]?\d+\.\d+", outcar_lines[max(lines)])[1]
def plot(self, filename=None, show=False, ax=None):
"""Plot fitted energy curve.
Uses Matplotlib to plot the energy curve. Use *show=True* to
show the figure and *filename='abc.png'* or
*filename='abc.eps'* to save the figure to a file."""
import matplotlib.pyplot as plt
plotdata = self.getplotdata()
ax = plot(*plotdata, ax=ax)
if index != -1:
correct_lines = linenum
if correct_lines != 0:
line = correct_lines
lines.append(line)
number = max(lines)
return re.findall("[-+]?\d+\.\d+", outcar_lines[max(lines)])[1]
def plot(self, filename=None, show=False, ax=None):
"""Plot fitted energy curve.
Uses Matplotlib to plot the energy curve. Use *show=True* to
show the figure and *filename='abc.png'* or
*filename='abc.eps'* to save the figure to a file."""
import matplotlib.pyplot as plt
plotdata = self.getplotdata()
ax = plot(*plotdata, ax=ax)
if show:
plt.show()
if filename is not None:
fig = ax.get_figure()
fig.savefig(filename)
return ax
energies = []
volumes = []
lst = sys.argv.copy()
lst.pop(0)
for i in lst:
os.chdir(str(i) + "/")
cell = read("CONTCAR")
#print(energy())
#print(str(cell.get_volume()))
energies.append(float(energy()))
volumes.append(cell.get_volume())
os.chdir("..")
c = cell.get_cell_lengths_and_angles()[2]
return re.findall("[-+]?\d+\.\d+", outcar_lines[max(lines)])[1]
def plot(self, filename=None, show=False, ax=None):
"""Plot fitted energy curve.
Uses Matplotlib to plot the energy curve. Use *show=True* to
show the figure and *filename='abc.png'* or
*filename='abc.eps'* to save the figure to a file."""
import matplotlib.pyplot as plt
plotdata = self.getplotdata()
ax = plot(*plotdata, ax=ax)
if show:
plt.show()
if filename is not None:
fig = ax.get_figure()
fig.savefig(filename)
return ax
energies = []
volumes = []
lst = sys.argv.copy()
lst.pop(0)
for i in lst:
os.chdir(str(i) + "/")
cell = read("CONTCAR")
#print(energy())
#print(str(cell.get_volume()))
energies.append(float(energy()))
volumes.append(cell.get_volume())
os.chdir("..")
c = cell.get_cell_lengths_and_angles()[2]
eos = EquationOfState(volumes, energies, eos='murnaghan')
v0, e0, B = eos.fit()
print(v0, c, e0)
#print(e0)
#eos.plot.set_title('R2: ' + str(r2_score(y_test, y_predicted)))
eos.plot(filename='plot.pdf')