exciting_parser_gw.py 21.5 KB
Newer Older
1
2
from builtins import object
import setup_paths
3
import xml.sax
4
5
6
7
from nomadcore.simple_parser import mainFunction, CachingLevel
from nomadcore.simple_parser import SimpleMatcher as SM
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.unit_conversion import unit_conversion
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
8
import os, sys, json, logging
9
10

################################################################
11
# This is the subparser for the exciting GW output
12
13
14
################################################################


Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
15
class GWParser(object):
16
17
18
19
    """context for wien2k In2 parser"""

    def __init__(self):
        self.spinTreat = None
20
21
        self.vertexDist = []
        self.vertexLabels = []
22
        self.vertexNum = 0
23

Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
24
    def parseGW(self, gwFile, backend,  dftMethodSectionGindex, dftSingleConfigurationGindex, xcName, unitCellVol,gmaxvr):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
25
#        logging.error("GW onClose_section_single_configuration_calculation")
26
#        print("xcNameGW=", xcName)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
27
28
        self.gmaxvr = float(gmaxvr[0])
#        print("gkmax= ",self.gmaxvr)
29
        self.unitCellVol = float(unitCellVol[0])
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
30
31
32
33
34
35
        backend.openNonOverlappingSection("section_single_configuration_calculation")
        if dftSingleConfigurationGindex is not None:
            backend.openNonOverlappingSection("section_calculation_to_calculation_refs")
            backend.addValue("calculation_to_calculation_ref", dftSingleConfigurationGindex)
            backend.addValue("calculation_to_calculation_kind", "starting_point")
            backend.closeNonOverlappingSection("section_calculation_to_calculation_refs")
36

Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
37
        dirPath = os.path.dirname(gwFile)
38
39
40
41
42
43
        if os.access(os.path.join(dirPath, "EVALQP.DAT"), os.F_OK):
            eigvalGWFile = os.path.join(dirPath, "EVALQP.DAT")
        elif os.access(os.path.join(dirPath, "EVALQP.TXT"), os.F_OK):
            eigvalGWFile = os.path.join(dirPath, "EVALQP.TXT")
        else:
            pass
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
44
        dosGWFile = os.path.join(dirPath, "TDOS-QP.OUT")
45
46
        bandCarbGWFile = os.path.join(dirPath, "bandstructure-qp.dat")
        bandBorGWFile = os.path.join(dirPath, "BAND-QP.OUT")
47
48
        vertexGWFile = os.path.join(dirPath, "BANDLINES.OUT")
        vertexLabGWFile = os.path.join(dirPath, "bandstructure.xml")
49
        selfCorGWFile = os.path.join(dirPath, "SELFC.DAT")
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
50
51
52
        inputFile = os.path.join(dirPath, "input.xml")

        if os.path.exists(inputFile):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
53
54
            selfGWSetGIndex = backend.openSection("section_method")
            backend.addValue('electronic_structure_method', "G0W0")
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
55
            backend.addValue('gw_starting_point', xcName)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
56
57
58
59
60
            if dftMethodSectionGindex is not None:
                m2mGindex = backend.openNonOverlappingSection("section_method_to_method_refs")
                backend.addValue("method_to_method_ref", dftMethodSectionGindex)
                backend.addValue("method_to_method_kind", "starting_point")
                backend.closeNonOverlappingSection("section_method_to_method_refs")
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
61
62
63
64
            singularity = 'mpd'
            actype = 'pade'
            npol = 0
            scrtype = "rpa"
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
65
            snempty = 0
66
            pnempty = 0
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
67
68
            coreflag = "all"
            fgrid = "gaule2"
69
70
            lmaxmb = 3
            epsmb = 0.0001
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
71
            gmb = 1.0
72
            sciavtype = "isotropic"
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
73
74
75
76
77
            cutofftype = "none"
            pwm = 2.0
            ngridq = [2,2,2]
            freqmax = 1.0
            nomeg = 16
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
78
79
            k1 = 0
            k2 = 0
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
80
81
            #            f1 = 0
            #            f2 = 0
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
82
83
            s1 = 0
            s2 = 0
84
85
86
87
88
89
            m1 = 0
            m2 = 0
            bc1 = 0
            bc2 = 0
            sc1 = 0
            sc2 = 0
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
90
            with open(inputFile) as g:
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
91
                i = 0
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
92
93
                while 1:
                    s = g.readline()
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
94
                    i += 1
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
95
96
97
                    if not s: break
                    s = s.strip()
                    s = s.split('=')
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
98
99
                    if s[0] == "<gw": k1 = i
                    if s[0] == "</gw>": k2 = i
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
100
101
                    if s[0] == "<freqgrid": f1 = i
                    if s[0] == "</freqgrid>": f2 = i
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
102
103
                    if s[0] == "<selfenergy": s1 = i
                    if s[0] == "</selfenergy>": s2 = i
104
105
106
107
108
109
                    if s[0] == "<mixbasis": m1 = i
                    if s[0] == "</mixbasis>": m2 = i
                    if s[0] == "<barecoul": bc1 = i
                    if s[0] == "</barecoul>": bc2 = i
                    if s[0] == "<scrcoul": sc1 = i
                    if s[0] == "</scrcoul>": sc2 = i
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
110
111
#                    print("m1= ",m1)
#                    print("m2= ",m2)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
112
113
114
115
116
117
118
119
            with open(inputFile) as g:
                i = 0
                while 1:
                    s = g.readline()
                    i += 1
                    if not s: break
                    s = s.strip()
                    s = s.split('=')
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
120
                    if (s[0] == "coreflag") and (i >= k1) and (i < (k2-1)):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
121
                        coreflag = s[1][1:-1]
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
122
123
124
                    elif (s[0] == "coreflag") and (i == (k2-1)):
                        coreflag = s[1][1:-2]
                    if (s[0] == "singularity") and (i >= k1) and (i < (k2-1)):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
125
                        freq_conv = s[1][1:-1]
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
126
127
128
                    elif (s[0] == "singularity") and (i == (k2-1)):
                        freq_conv = s[1][1:-2]
                    if (s[0] == "actype") and (i >= k1) and (i < (k2-1)):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
129
                        actype = s[1][1:-1]
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
                    elif (s[0] == "actype") and (i == (k2-1)):
                        actype = s[1][1:-2]
                    if (s[0] == "ngridq") and (i >= k1) and (i < (k2-1)):
                        dummy = s[1].split('"')
                        dummy1 = dummy[1].split()
                        for j in range(0,3):
                            ngridq[j] = int(dummy1[j])
                    elif (s[0] == "ngrid") and (i == (k2-1)):
                        dummy = s[1].split('"')
                        dummy1 = dummy[1].split()
                        for j in range(0,3):
                            ngridq[j] = int(dummy1[j])
                    if (s[0] == "npol") and (i >= k1) and (i < (k2-1)):
                        npol = int(s[1][1:-1])
                    elif (s[0] == "npol") and (i == (k2-1)):
                        npol = int(s[1][1:-2])
                    if (s[0] == "nempty") and (i >= k1) and (i < (k2-1)):
                        pnempty = int(s[1][1:-1])
                    elif (s[0] == "nempty") and (i == (k2-1)):
                        pnempty = int(s[1][1:-2])
                    if (s[0] == "scrtype") and (i >= k1) and (i < (k2-1)):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
151
                        scrtype = s[1][1:-1]
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
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
                    elif (s[0] == "scrtype") and (i == (k2-1)):
                        scrtype = s[1][1:-2]
                    if (s[0] == "nempty") and (i >= s1) and (i < (s2-1)):
                        snempty = int(s[1][1:-1])
                    elif (s[0] == "nempty") and (i == (s2-1)):
                        snempty = int(s[1][1:-2])
                    if (s[0] == "freqmax") and (i >= f1) and (i < (f2-1)):
                        freqmax = float(s[1][1:-1])
                    elif (s[0] == "freqmax") and (i == (f2-1)):
                        freqmax = float(s[1][1:-2])
                    if (s[0] == "nomeg") and (i >= f1) and (i < (f2-1)):
                        nomeg = int(s[1][1:-1])
                    elif (s[0] == "nomeg") and (i == (f2-1)):
                        nomeg = int(s[1][1:-2])
                    if (s[0] == "lmaxmb") and (i >= m1) and (i < (m2-1)):
                        lmaxmb = int(s[1][1:-1])
                    elif (s[0] == "lmaxmb") and (i == (m2-1)):
                        lmaxmb = int(s[1][1:-2])
                    if (s[0] == "epsmb") and (i >= m1) and (i < (m2-1)):
                        epsmb = float(s[1][1:-1])
                    elif (s[0] == "epsmb") and (i == (m2-1)):
                        epsmb = float(s[1][1:-2])
                    if (s[0] == "gmb") and (i >= m1) and (i < (m2-1)):
                        gmb = float(s[1][1:-1])
                    elif (s[0] == "gmb") and (i == (m2-1)):
                        gmb = float(s[1][1:-2])
                    if (s[0] == "sciavtype") and (i >= sc1) and (i < (sc2-1)):
179
                        sciavtype = s[1][1:-1]
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
180
181
182
                    elif (s[0] == "sciavtype") and (i == (sc2-1)):
                        sciavtype = s[1][1:-2]
                    if (s[0] == "fgrid") and (i >= k1) and (i < (k2-1)):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
183
                        fgrid = s[1][1:-1]
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
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
                    elif (s[0] == "fgrid") and (i == (k2-1)):
                        fgrid = s[1][1:-2]
                    if (s[0] == "pwm") and (i >= bc1) and (i < (bc2-1)):
                        pwm = float(s[1][1:-1])
                    elif (s[0] == "pwm") and (i == (bc2-1)):
                        pwm = float(s[1][1:-2])
                    if (s[0] == "cutofftype") and (i >= bc1) and (i < (bc2-1)):
                        cutofftype = s[1][1:-1]
                    elif (s[0] == "cutofftype") and (i == (bc2-1)):
                        cutofftype = s[1][1:-2]
#            gmb = gmb*self.gmaxvr
#            pwm = pwm*gmb*self.gmaxvr
#            print("gmb= ",type(gmb))
#            print("pwm= ", type(pwm))
#            print("self.gmaxvr= ",type(self.gmaxvr))            
            backend.addValue("gw_frequency_grid_type", fgrid)
            backend.addValue("gw_self_energy_c_number_of_empty_states", int(snempty))
            backend.addValue("gw_core_treatment", coreflag)
            backend.addValue("gw_self_energy_singularity_treatment", singularity)
            backend.addValue("gw_self_energy_c_analytical_continuation", actype)
            backend.addValue("gw_self_energy_c_number_of_poles", int(npol))
            backend.addValue("gw_screened_Coulomb", scrtype)
            backend.addValue("gw_polarizability_number_of_empty_states", int(pnempty))
            backend.addValue("gw_basis_set", "mixed")
            backend.addValue("gw_mixed_basis_lmax", lmaxmb)
            backend.addValue("gw_mixed_basis_tolerance", epsmb)
            backend.addValue("gw_mixed_basis_gmax", gmb*self.gmaxvr)
            backend.addValue("gw_screened_coulomb_volume_average",sciavtype)
            backend.addValue("gw_bare_coulomb_gmax", pwm*gmb*self.gmaxvr)
            backend.addValue("gw_ngridq", ngridq)
            backend.addValue("gw_bare_coulomb_cutofftype", cutofftype)
            backend.addValue("gw_max_frequency", freqmax)
            backend.addValue("gw_number_of_frequencies", nomeg)
            backend.addValue("gw_qp_equation_treatment", "linearization")
#    backend.addArrayValues
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
219
            backend.closeSection("section_method",selfGWSetGIndex)
220

221
222
223
224
225
226
227
228
229
230
231
232
        if os.path.exists(vertexGWFile):
            with open(vertexGWFile) as g:
                while 1:
                    s = g.readline()
                    if not s: break
                    s = s.strip()
                    s = s.split()
                    if len(s) > 0:
                        if not self.vertexDist:
                            self.vertexDist.append(float(s[0]))
                        elif float(s[0]) != self.vertexDist[-1]:
                            self.vertexDist.append(float(s[0]))
233
                self.vertexNum = len(self.vertexDist)-1
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
234

235
236
237
238
239
240
241
242
243
244
        if os.path.exists(vertexLabGWFile):
            with open(vertexLabGWFile) as g:
                while 1:
                    s = g.readline()
                    if not s: break
                    s = s.strip()
                    s = s.split()
                    if s[0] == "<vertex":
                        f = s[4].split("\"")
                        self.vertexLabels.append(f[1])
245

246
        if os.path.exists(eigvalGWFile):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
247
            eigvalGWGIndex = backend.openSection("section_eigenvalues")
248
249
            with open(eigvalGWFile) as g:
                qpGWKpoint=[]
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
250
                Vxc = [[],[]]
251
252
253
254
255
256
257
258
259
260
261
262
                Sx = [[],[]]
                Sc = [[],[]]
                qpE = [[],[]]
                Znk = [[],[]]
                fromH = unit_conversion.convert_unit_function("hartree", "J")
                while 1:
                    s = g.readline()
                    if not s: break
                    s = s.strip()
                    if "k-point" in s.split():
                        qpGWKpoint.append([])
                        for i in range(0,2):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
263
                            Vxc[i].append([])
264
265
266
267
                            Sx[i].append([])
                            Sc[i].append([])
                            qpE[i].append([])
                            Znk[i].append([])
268
                        x,y,z = float(s.split()[3]),float(s.split()[4]),float(s.split()[5])
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
                        qpGWKpoint[-1].append(x)
                        qpGWKpoint[-1].append(y)
                        qpGWKpoint[-1].append(z)
                    else:
                        s=s.split()
                        if len(s) == 0:
                            continue
                        else:
                            try: not int(s[0])
                            except ValueError:
                                continue
                            if self.spinTreat:
                                pass
                            else:
                                for i in range(0,2):
284
285
286
                                    Sx[i][-1].append(fromH(float(s[4])))
                                    Sc[i][-1].append(fromH(float(s[5])))
                                    qpE[i][-1].append(fromH(float(s[3])))
287
                                    Znk[i][-1].append(float(s[9]))
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
288
                                    Vxc[i][-1].append(fromH(float(s[6])))
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
289
290
291
292
        backend.addValue("eigenvalues_kpoints", qpGWKpoint)
        backend.addValue("number_of_eigenvalues", len(qpE[0]))
        backend.addValue("number_of_eigenvalues_kpoints", len(qpGWKpoint))
        backend.addValue("eigenvalues_values", qpE)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
293
        backend.addValue("gw_qp_linearization_prefactor", Znk)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
294
        backend.closeSection("section_eigenvalues",eigvalGWGIndex)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
295
296
297
        backend.addValue("gw_self_energy_x", Sx)
        backend.addValue("gw_self_energy_c", Sc)
        backend.addValue("gw_xc_potential", Vxc)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
298
299

        ####################DOS######################
300

Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
301
        if os.path.exists(dosGWFile):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
302
303
            dosGWGIndex = backend.openSection("section_dos")
            ha_per_joule = unit_conversion.convert_unit(1, "hartree", "J")
304
#            bohr_cube_to_m_cube = unit_conversion.convert_unit(1, "bohr^3", "m^3")
305
            fromH = unit_conversion.convert_unit_function("hartree", "J")
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
306
307
308
309
310
311
312
313
            with open(dosGWFile) as g:
                dosValues = [[],[]]
                dosEnergies = []
                while 1:
                    s = g.readline()
                    if not s: break
                    s = s.strip()
                    s = s.split()
314
                    ene, value = fromH(float(s[0])), ha_per_joule*float(s[1])
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
315
316
317
318
319
320
                    dosEnergies.append(ene)
                    if not self.spinTreat:
                        for i in range(0,2):
                            dosValues[i].append(value)
                    else:
                        pass
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
321
322
323
324
325
326
            backend.addValue("dos_energies", dosEnergies)
            backend.addValue("dos_values", dosValues)
            backend.addValue("number_of_dos_values", len(dosEnergies))
            backend.closeSection("section_dos",dosGWGIndex)        

        ##################BANDSTRUCTURE#####################
327

328
        if os.path.exists(bandCarbGWFile):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
329
            bandGWGIndex = backend.openSection("section_k_band")
330
331
            fromH = unit_conversion.convert_unit_function("hartree", "J")

332
            with open(bandCarbGWFile) as g:
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
                bandEnergies = [[],[]]
                kpoint = []
                dist = []
                Kindex = [0]
                segmK = []
                segmLength = []
                bandEnergiesSegm = []
                bandGWBE = []
                while 1:
                    s = g.readline()
                    if not s: break
                    s = s.strip()
                    s = s.split()                
                    if not self.spinTreat:
                        if len(s) == 0:
                            for i in range(0,2):
                                bandEnergies[i].append([])
                        elif s[0] == "#":
                            for i in range(0,2):
                                bandEnergies[i].append([])
                                numBand = int(s[2])
                                numK = int(s[3])          
                        elif len(s) > 0:
                            for i in range(0,2):
                                bandEnergies[i][-1].append(fromH(float(s[6])))
                            if int(s[0]) == 1:
                                kpoint.append([])
                                dist.append(float(s[5]))
                                kpoint[-1].append([float(s[2]),float(s[3]),float(s[4])])
                    else:
                        pass

                for i in range(0,2):
                    bandEnergies[i].pop()

                for i in range(1,numK):
                    if dist[i] == dist[i-1]:
                        Kindex.append(i)
                Kindex.append(numK)
                for i in range(0,len(Kindex)-1): 
                    segmK.append(dist[Kindex[i]:Kindex[i+1]])

                for i in range(0,len(segmK)):
                    segmLength.append(len(segmK[i]))
                for i in range(0,2):
                    bandEnergiesSegm.append([])
                    for j in range(0,numBand):
                         bandEnergiesSegm[i].append([])
                         for k in range (0,len(Kindex)-1):
                             bandEnergiesSegm[i][j].append(bandEnergies[i][j][Kindex[k]:Kindex[k+1]])
            for i in range(0,len(Kindex)-1):
                bandGWBE.append([])
                for j in range(0,2):
                    bandGWBE[i].append([])
                    for k in range(0,segmLength[i]):
                        bandGWBE[i][j].append([])
                        for l in range(0,numBand):
                            bandGWBE[i][j][-1].append(bandEnergiesSegm[j][l][i][k])

392
            for i in range(0,len(Kindex)-1):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
393
394
395
                bandGWSegmGIndex = backend.openSection("section_k_band_segment")
                backend.addValue("band_energies", bandGWBE[i])
                backend.closeSection("section_k_band_segment",bandGWSegmGIndex)
396

Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
397
            backend.closeSection("section_k_band",bandGWGIndex)
398
399

        if os.path.exists(bandBorGWFile) and not os.path.exists(bandCarbGWFile):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
400
            bandGWGIndex = backend.openSection("section_k_band")
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
            fromH = unit_conversion.convert_unit_function("hartree", "J")
            with open(bandBorGWFile) as g:
                bandEnergies = [[[]],[[]]]
                kappa = [[[]],[[]]]
                dist1 = [[]]
                Kindex = [0]
                segmK = []
                segmLength = []
                bandEnergiesSegm = []
                bandGWBE = []
                while 1:
                    s = g.readline()
                    if not s: break
                    s = s.strip()
                    s = s.split()
                    if not self.spinTreat:
                        if len(s) == 0:
                            for i in range(0,2):
                                bandEnergies[i].append([])
                                kappa[i].append([])
                            dist1.append([])
                        elif len(s) > 0:
                            for i in range(0,2):
424
                                bandEnergies[i][-1].append(fromH(float(s[1])))
425
426
427
428
429
430
431
432
433
434
435
                                kappa[i][-1].append(float(s[0]))
                            dist1[-1].append(float(s[0]))
                        numK = len(kappa[0][0])
                        for i in kappa[0][0]:
                            if kappa[0][0].count(i) > 1:
                                kappa[0][0].remove(i)
                    else:
                        pass
                for i in range(0,2):
                    bandEnergies[i].pop()
                numBand = len(bandEnergies[0])
436
                for i in range(1,numK + self.vertexNum-1):
437
438
                    if dist1[0][i] == dist1[0][i-1]:
                        Kindex.append(i)
439
                Kindex.append(numK + self.vertexNum-1)
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
                for i in range(0,len(Kindex)-1):
                    segmK.append(dist1[0][Kindex[i]:Kindex[i+1]])

                for i in range(0,len(segmK)):
                    segmLength.append(len(segmK[i]))
                for i in range(0,2):
                    bandEnergiesSegm.append([])
                    for j in range(0,numBand):
                         bandEnergiesSegm[i].append([])
                         for k in range (0,len(Kindex)-1):
                             bandEnergiesSegm[i][j].append(bandEnergies[i][j][Kindex[k]:Kindex[k+1]])
            for i in range(0,len(Kindex)-1):
                bandGWBE.append([])
                for j in range(0,2):
                    bandGWBE[i].append([])
                    for k in range(0,segmLength[i]):
                        bandGWBE[i][j].append([])
                        for l in range(0,numBand):
                            bandGWBE[i][j][-1].append(bandEnergiesSegm[j][l][i][k])

460
            for i in range(0,len(Kindex)-1):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
461
462
463
                bandGWSegmGIndex = backend.openSection("section_k_band_segment")
                backend.addValue("band_energies", bandGWBE[i])
                backend.closeSection("section_k_band_segment",bandGWSegmGIndex)
464

Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
465
466
467
            backend.closeSection("section_k_band",bandGWGIndex)
        backend.closeNonOverlappingSection("section_single_configuration_calculation")
#        logging.error("done GW onClose_section_single_configuration_calculation")
468