-
Notifications
You must be signed in to change notification settings - Fork 0
/
lprint
executable file
·257 lines (227 loc) · 9.89 KB
/
lprint
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#! /usr/bin/env python3
from __future__ import print_function, division, absolute_import
import sys
import argparse
import logging
from structure.auxiliary import LogFormatter
from postproc.output import LRTCoutput
from postproc.input import LRTCinput
'''
lprint: Post-processing of LRTC HDF5 files
'''
error = lambda string: sys.exit('lprint: {}'.format(string))
def parse_args(args=None):
parser = argparse.ArgumentParser(
description='''Argument parser for LRTC input and LRTC output data
-------------------------------------------
" lprint <inputfile> info " --- structural information of input file
" lprint -p <inputfile> dos " --- plot density of states [broad, points, emin, emax]
-------------------------------------------
" lprint <outputfile> list " --- list all physical quantities
" lprint <outputfile> olist " --- list all onsager coefficients
-------------------------------------------
" lprint <outputfile> config " --- config information of lrtc run
" lprint -p <outputfile> mu " --- plot chemical potential of latest lrtc run
" lprint -p <outputfile> electrons holes impurity "
--- plot activated electrons/holes/impurity contribution
useful in semiconductors
" lprint <outputfile> c-total uyy " --- print total conductivity of spin up in yy direction
" lprint <outputfile> s-intra xx " --- print intra seebeck (spin summed) in xx direction
" lprint <outputfile> rh-intra xyz " --- print intra hall coefficient (spin summed)
in xy plane with magnetic-field applied in z-direction.''',
formatter_class=argparse.RawTextHelpFormatter,
epilog="That's the end of the help")
parser.add_argument('file', help='LRTC input/output file')
parser.add_argument('output', nargs='+', help='Dataset to print/plot (\'list\' for an overview)')
parser.add_argument('-c', '--compare', nargs='+', help='Comparison of identical dataset from different LRTC output files')
parser.add_argument('-p', '--plot', help='Plot the dataset instead', default=False, action='store_true')
parser.add_argument('-x', '--axis', help='Use alternate axis (T -> beta or mu -> carrier)', default=False, action='store_true')
parser.add_argument('--nothrow', help='Do not throw exception if dataset is missing', default=False, action='store_true')
parser.add_argument('--gap', help='Plot the band gap in combination with mu', default=False, action='store_true')
parser.add_argument('--scale', help='Scale all quantities by factor', default=1, type=float)
parser.add_argument('--imag', help='Plot the imaginary parts as well', default=False, action='store_true') # plot the imaginary parts in addition to the real part
parser.add_argument('--convolve', nargs=1, help='Convolve mu-mode output with Gaussian of standard deviation [eV]', type=float) # convolue mu-mode result with gaussian with sigma = value
parser.add_argument('--diag', help=argparse.SUPPRESS, default=False, action='store_true') # only use the diagonal parts (when no directions supplied
parser.add_argument('--debug', help=argparse.SUPPRESS, default=False, action='store_true')
return parser.parse_args(args)
def directionTransform(string, dims):
'''
transform character input into numerical inpot via mapping
also: pre-check for incorrect characters and incorrect argument lengths
'''
prevstring = string
if len(string)>1 and len(string)<5:
try:
string = string.lower()
''' replace up and down with 1 and 2 '''
for char, nmb in zip(['u','d'],['1','2']):
string = string.replace(char,nmb)
''' if nothing is replaced place a 0 in front '''
if prevstring == string:
string = '0'+string
for char, nmb in zip(['x','y','z'],['1','2','3']):
string = string.replace(char,nmb)
test = int(string)
return string
except:
raise ValueError("Invalid directional argument: {} -- incorrect direction".format(prevstring))
raise ValueError("Invalid directional argument: {} -- incorrect argument length".format(prevstring))
def main():
args = parse_args()
''' define logging '''
logger = logging.getLogger()
logger.setLevel(logging.DEBUG if args.debug else logging.INFO)
console = logging.StreamHandler()
console.setFormatter(LogFormatter())
console.setLevel(logging.DEBUG if args.debug else logging.INFO)
logger.addHandler(console)
if args.plot:
try:
import matplotlib.pyplot as plt
except ImportError:
error('Could not import matplotlib')
inpobj = outobj = None
''' Initiate input / output objects '''
try:
inpobj = LRTCinput(args.file)
except IOError as e1:
try:
outobj = LRTCoutput(args.file, altaxis=args.axis)
except IOError as e2:
error('\n'+str(e1)+'\n'+str(e2))
if outobj is not None and args.compare: # restrict to outputobjects
try:
compareobjs = [outobj]
for cmpfile in args.compare:
if cmpfile == args.file: continue
compareobjs.append(LRTCoutput(cmpfile, altaxis=args.axis))
except Exception as e:
error('\n'+str(e))
cmd = args.output[0].strip()
cmdlength = len(args.output)
''' settings to give to outputData method -- all have proper default values '''
settings = type('', (), {})() # magic -- creates empty object
settings.plot = args.plot
settings.imag = args.imag
settings.diag = args.diag
settings.scale = args.scale
settings.compare = args.compare # if option unused default = None
settings.convolve = args.convolve
''' Output object commands '''
if outobj is not None:
try:
if cmd == 'list':
outobj.outputList(onsager=False)
elif cmd == 'olist':
outobj.outputList(onsager=True)
elif cmd == 'config':
outobj.outputConfig()
# elif cmd == 'dos':
# if cmdlength == 1:
# outobj.outputDOS(args.plot)
# else:
# broadening = float(args.output[1])
# outobj.outputDOS(args.plot, broadening)
# if args.plot:
# plt.title(outobj.fname)
# plt.show()
else:
''' response / quantity plotting / output '''
if cmdlength == 1:
number_commands = 1
if args.compare:
for cmpobj in compareobjs:
ylabel = cmpobj.outputData(cmd, settings)
else:
ylabel = outobj.outputData(cmd, settings)
else:
# we iterate through the list and check the following arguments
number_commands = 0
for i,icmd in enumerate(args.output):
try:
check = int(args.output[i])
continue
except:
try:
check = directionTransform(args.output[i], outobj.dims)
continue
except:
number_commands += 1 # interpret as command and check for directions
# check arguments afterward until we get to an error
directions = []
for j in range(i+1,cmdlength):
try:
check = int(args.output[j])
directions.append(args.output[j])
except:
try:
check = directionTransform(args.output[j], outobj.dims)
directions.append(check)
except:
break
try:
if args.compare:
for cmpobj in compareobjs:
ylabel = cmpobj.outputData(icmd, settings, *directions)
else:
ylabel = outobj.outputData(icmd, settings, *directions)
except Exception as e:
if not args.nothrow:
raise e
''' finally, do some decorating '''
if settings.plot:
plt.xlabel(outobj.axislatex, fontsize=14)
''' if we have one command, plot the y-axis label '''
if number_commands == 1:
plt.ylabel(ylabel, fontsize=14)
if outobj.mode == 'mu':
if args.axis:
plt.axvline(x=0, ls='--', color='gray') # carrier concentration are differences to 0
else:
plt.axvline(x=outobj.mudft, ls='--', color='gray', label=r'$\mu_{\mathrm{DFT}}$') # fermi level
''' for chemical potential plot '''
try:
if outobj.mode == 'temp' and cmd == 'mu' and args.plot:
plt.axhline(y=outobj.mudft, ls='--', color='black', label=r'$\mu_{\mathrm{DFT}}$')
if args.gap:
outobj.plotBandgap()
except:
pass
''' use file name as title if we only show one file '''
if settings.plot:
plt.legend(loc='best')
if not args.compare: plt.title(outobj.fname)
plt.show()
except Exception as e:
error('\nERROR: '+str(e)+'\n')
''' Input object commands '''
if inpobj is not None:
try:
if cmd == 'list':
inpobj.outputList()
elif cmd == 'info':
inpobj.outputStructure()
elif cmd == 'dos':
if cmdlength == 1:
inpobj.outputDOS(args.plot)
else:
''' multi-purpose : allowed arguments 1: broadening - 2: broadening npoints - 4: broadening npoints emin emax
if emin and emax are not provided: define the energywindow according to detected global minima and maxima
'''
inpobj.outputDOS(args.plot, *args.output[1:])
if args.plot:
plt.title(inpobj.fname)
plt.show()
elif cmd == 'path':
if cmdlength == 1:
inpobj.outputPath(args.plot)
else:
inpobj.outputPath(args.plot, args.output[1])
elif cmd == 'hk':
inpobj.outputHk()
else:
raise IOError('lrtc input file command not recognized')
except Exception as e:
error('\nERROR: '+str(e)+'\n')
if __name__ == '__main__':
main()