-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPLOT-loss-function.py
executable file
·89 lines (77 loc) · 2.79 KB
/
PLOT-loss-function.py
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
#!/usr/bin/python
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from lxml import etree
import os
import sys
#-------------------------------------------------------------------------------
#Check arguments
nfiles=len(sys.argv)-1
if nfiles<1:
print "\nNothing to plot\n\n*** Usage: ***\n $>PLOT-lossfkt.py path_to_loss_file1.xml path_to_loss_file2.xml ...\n**************\n"
sys.exit()
fnames=[]
for i in range(nfiles):
fnames.append(sys.argv[i+1])
if not os.path.isfile(fnames[i]):
print "Error: file \"%s\" doesn't exist"%(fnames[i])
sys.exit()
#-------------------------------------------------------------------------------
#Parse LOSS function data files
xdata=[]
ydata=[]
labels=[]
legends=[]
function=1
for i,fname in enumerate(fnames):
xdata.append([])
ydata.append([])
labels.append({})
print "Parsing "+fname
sfname = fname.split("/")[-1].split("_")
if "FXCRPA" in sfname: legend="RPA "
if "FXCALDA" in sfname: legend="ALDA "
if "BSEsinglet" in sfname: legend="BSE "
if not "NLF" in sfname: legend=legend+"(LFE) "
if "NLF" in sfname: legend=legend+"(no-LFE) "
if sfname[-2][0:2]=="OC": legend=legend+"Optical(%s)"%(sfname[-2][2:])
legends.append(legend)
tree=etree.parse(fname)
if "LOSS" in sfname: rootelement="loss"
if "EPSILON" in sfname: rootelement="dielectric"
labels[i]["xlabel"] = tree.xpath('/%s/mapdef/variable1'%(rootelement))[0].attrib["name"]
labels[i]["ylabel"] = tree.xpath('/%s/mapdef/function%d'%(rootelement,function))[0].attrib["name"]
for elem in tree.xpath('/%s/map'%(rootelement)):
xdata[i].append(float(elem.attrib["variable1"]))
ydata[i].append(float(elem.attrib["function%d"%(function)]))
#-------------------------------------------------------------------------------
#Plot LOSS function/s
colors=['k','r','g','b','y','c','m']
fig=plt.figure(1,figsize=(8,5.5))
params = {'font.size':15,
'xtick.major.size': 5,
'ytick.major.size': 5,
'patch.linewidth': 1.5,
'axes.linewidth': 2.,
'axes.formatter.limits': (-4, 6),
'lines.linewidth': 1.8,
'lines.markeredgewidth':2.0,
'lines.markersize':18,
'legend.fontsize':11,
'legend.borderaxespad':1,
'legend.borderpad':0.5,
'savefig.dpi':80}
plt.rcParams.update(params)
ax=fig.add_subplot(111)
for i in range(nfiles):
ax.plot(xdata[i],ydata[i],colors[np.mod(i,7)],label=legends[i])
ax.legend(loc=2)
#ax.legend()
ax.set_xlim(0.0,54.0)
ax.set_ylim(0)
ax.set_xlabel(str.capitalize(labels[0]["xlabel"])+" [eV]")
ax.set_ylabel(str.capitalize(labels[0]["ylabel"]))
plt.savefig('PLOT.ps', orientation='portrait',format='eps')
plt.savefig('PLOT.png', orientation='portrait',format='png')
plt.show()