-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_structural_param.py
More file actions
executable file
·64 lines (51 loc) · 1.83 KB
/
get_structural_param.py
File metadata and controls
executable file
·64 lines (51 loc) · 1.83 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
import argparse
import graph as gg
from itertools import chain
from parse_pv import parse_file
import subprocess
import os
def main(file_name, trimmed='trimmed.out'):
"""
This script greps the unit cell parameters, pressure and volume
parsing a cp2k output
"""
# trimmed files
cmd = 'grep -A16 "STEP NUMBER" {} > {}'.format(file_name, trimmed)
subprocess.run(cmd, shell=True)
rs = parse_file(trimmed)
# remove temporary file
os.remove(trimmed)
xlabel = 'Step'
# thingsToPlot = ['Pressure', 'Pressure[avg.]','Volume', 'Volume[Avg.]','a', 'b', 'c', 'alpha', 'beta', 'gamma']
ylabel = 'Pressure'
title = 'Pressure [Avg.]'
output = 'pressur.png'
gg.simplePlot(rs[:, 0], rs[:, 2], xlabel, ylabel, title, output)
ylabel = 'Volume (Bohr^3)'
title = 'Volume [Avg.]'
output = 'volume.png'
gg.simplePlot(rs[:, 0], rs[:, 4], xlabel, ylabel, title, output)
formats = ['g-', 'b-', 'r-']
args1 = createArgs(rs[:, 0], rs[:, 5:8].transpose(), formats)
ylabel = 'Cell lenghts (Bohr)'
title = 'Cell lengths [Avg.]'
output = 'lengths.png'
gg.plotLengths(xlabel, ylabel, title, output, args1)
args2 = createArgs(rs[:, 0], rs[:, 8:11].transpose(), formats)
ylabel = 'Cell angles (deg)'
title = 'Cell angles [Avg.]'
output = 'angles.png'
gg.plotLengths(xlabel, ylabel, title, output, args2)
def createArgs(x, ys, formats):
"""
generates a list for matplotlib
[ x, y1, 'format', x, y2, 'format' ]
"""
args = [(x, y, f) for y, f in zip(ys, formats)]
return list(chain(*args))
if __name__ == "__main__":
msg = " get_structural_param -p <path/to/output>"
parser = argparse.ArgumentParser(description=msg)
parser.add_argument('-p', required=True, help='path to the cp2k output')
args = parser.parse_args()
main(args.p)