parser_exciting.py 58.6 KB
Newer Older
1
2
3
4
5
6
# Copyright 2015-2018 Franz Knuth, Fawzi Mohamed, Wael Chibani, Ankit Kariryaa, Lauri Himanen, Danio Brambila
# 
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
# 
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
9
10
11
12
13
14
# 
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

15
16
#
# Main author and maintainer: Lorenzo Pardini <loren.pard@gmail.com>
17
from builtins import object
18
import setup_paths
19
import numpy as np
20
from nomadcore.simple_parser import AncillaryParser, CachingLevel
21
from nomadcore.simple_parser import SimpleMatcher as SM, mainFunction
22
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
23
from nomadcore.caching_backend import CachingLevel
24
from nomadcore.unit_conversion import unit_conversion
25
from nomadcore.unit_conversion.unit_conversion import convert_unit_function
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
26
import os, sys, json, exciting_parser_dos,exciting_parser_bandstructure, exciting_parser_gw, exciting_parser_GS_input
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
27
import exciting_parser_XS_input, exciting_parser_xs, exciting_parser_eps
28
from ase import Atoms
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
29
import logging
30

31
32
class ExcitingParserContext(object):

33
34
  def __init__(self):
    self.parser = None
35
36
37
38
39
40
41
#    self.mainFileUri = sys.argv[1]    #exciting !!!!!!LOCAL HOME!!!!!!!!             OKOKOKOK
    self.mainFileUri = sys.argv[2]  #exciting !!! FOR NOMAD URI nmd:// or sbt -> zip file!!!!!!!!   OKOKKOOK
    self.mainFilePath = None
    self.mainFile = None
    self.volumeCubOpt = False
    self.volumeOpt = False
    self.volumeCubOptIndex = 0
42
43
44

  def initialize_values(self):
    self.metaInfoEnv = self.parser.parserBuilder.metaInfoEnv
45
46
    self.atom_pos = []
    self.atom_labels = []
47

48
49
  def startedParsing(self, path, parser):
    self.parser=parser
50
    self.initialize_values()
51
52
#    self.atom_pos = []
#    self.atom_labels = []
53
    self.secMethodIndex = None  
54
    self.secSystemIndex = None
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
55
    self.secSingleConfIndex = None
56
    self.spinTreat = None
57
58
    self.sim_cell = []
    self.cell_format = ''
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
59
    self.secRunIndex = None
60
61
    self.unit_cell_vol = 0
    self.xcName = None
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
62
    self.gmaxvr = 0
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
63
    self.rgkmax = 0
64
    self.energy_thresh = []
65
66
67
68
69
70
    self.samplingMethod = None
    self.secSamplingMethodIndex = None
    self.geometryForceThreshold = 0
    self.frameSequence = []
    self.samplingGIndex = 0
    self.dummy = 0
71
72
    self.i=0
    self.clathrates = False
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
73
74
75
76
    self.bsetype = None
    self.screentype = None
    self.tensorComp = []
    self.excitonEnergies = []
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
#    self.volumeOptIndex = 0

  def onOpen_section_run(self, backend, gIndex, section):
#    self.i=self.i+1
#    print("self.i=",self.i)
    curDir = os.getcwd()
    mainFile = self.parser.fIn.fIn.name           #####exciting sbt -> zip filei r from NOMAD URI nmd:// ####     YES ?????????? sure???? check first    OKOKOKKO
    self.mainFilePath = os.path.dirname(mainFile)           #####exciting sbt -> zip file####     YES ?????????? sure???? check first    OKOKOKKO
#    self.mainFilePath = self.mainFileUri[0:-9]     #####exciting LOCAL HOME #######   YES                      OKOKOKOK
#    print("self.mainFilePath===",self.mainFilePath)
    os.chdir(self.mainFilePath)
    os.chdir('../')
#    self.i=self.i+1
#    print("self.i=",self.i)
#    self.volumeOptIndex = 0
#    for root, dirs, files in os.walk('.'):
#      if root == '.':
#        for directory in dirs:
#          if directory[-4:-1]==
#        print("root=",root)
#        print("dirs=",dirs)
#        print("files=",files)     
#####volume optimization for simple cubic systems########
    if 'INFO_VOL' in os.listdir('.'):
      self.volumeOpt = True
#      print("self.volumeOpt=",self.volumeOpt)
      with open('INFO_VOL') as g:
          while 1:
            s = g.readline()
            if not s: break
            s = s.strip()

    else:
      for files in os.listdir('.'):
#      print("files=",files)
#      backend.addValue("x_exciting_dummy2", files)
        if files[0:7] == 'rundir-':
          self.volumeCubOptIndex+=1
    os.chdir(curDir)
#    curDir = os.getcwd()
#    dirPath = self.mainFileUri[0:-9]
#    os.chdir(dirPath)
#    os.chdir('../')
#    i = 0
#    for files in os.listdir('.'):
#      if files[0:7] == 'rundir-':
#        i+=1
#      if i>1:
#        self.volumeOpt = True
#        optGindex = backend.openSection("section_method")
#        print("optGindex=",optGindex)
#        backend.addValue("x_exciting_volume_optimization", self.volumeOpt)
#        backend.closeSection("section_method", optGindex)        
#    os.chdir(curDir)
131
132
133
134
135
136
137
138

  def onOpen_section_sampling_method(self, backend, gIndex, section):
    self.secSamplingMethodIndex = gIndex
    backend.addValue("sampling_method", "geometry_optimization")
#    print("self.secSamplingMethodIndex=",self.secSamplingMethodIndex)
    self.samplingMethod = "geometry_optimization"
#    print("self.samplingMethod=",self.samplingMethod)
    
139
140
  def onOpen_section_system(self, backend, gIndex, section):
    self.secSystemIndex = gIndex
141
142
143
144
145
146
147
148
149
    curDir = os.getcwd()
    mainFile = self.parser.fIn.fIn.name           #####exciting sbt -> zip file or from NOMAD URI nmd:// ####     YES ?????????? sure???? check first    OKOKOKKO
    self.mainFilePath = os.path.dirname(mainFile)           #####exciting sbt -> zip file####     YES ?????????? sure???? check first    OKOKOKKO
#    self.mainFilePath = self.mainFileUri[0:-9]     #####exciting LOCAL HOME#######   YES                      OKOKOKOK
#    print("self.mainFilePath===",self.mainFilePath)
    os.chdir(self.mainFilePath)
#    print("listdir=",os.listdir('.'))
    if 'str.out' in os.listdir('.'):
      self.clathrates = True
Pardini, Lorenzo (lopa)'s avatar
BSE Xas    
Pardini, Lorenzo (lopa) committed
150
#      print("clathrate_vero===",self.clathrates)
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
      backend.addValue("x_exciting_clathrates", True)
      clathrate_labels = []
      clathrate_coordinates = []
      with open('str.out') as g:
          while 1:
            s = g.readline()
            if not s: break
            s = s.strip()
            s = s.split()
            if len(s) == 4:
#              print("s=",s[0],float(s[0]))
              clathrate_coordinates.append([float(s[0]),float(s[1]),float(s[2])])
              clathrate_labels.append(s[3])
#      print("clathrate_coordinates=",clathrate_coordinates)
      backend.addArrayValues("x_exciting_clathrates_atom_coordinates", np.asarray(clathrate_coordinates))
      backend.addValue("x_exciting_clathrates_atom_labels", clathrate_labels)
    else:
Pardini, Lorenzo (lopa)'s avatar
BSE Xas    
Pardini, Lorenzo (lopa) committed
168
#      print("clathrate_falso===",self.clathrates)
169
170
171
172
      backend.addValue("x_exciting_clathrates", False)
#    backend.addArrayValues("x_exciting_clathrates_atom_coordinates", np.array(clathrate_coordinates)) 
#    backend.addValue("x_exciting_clathrates_atom_labels", clathrate_labels)
    os.chdir(curDir)            
173

Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
174
175
176
  def onOpen_section_single_configuration_calculation(self, backend, gIndex, section):
    if self.secSingleConfIndex is None:
      self.secSingleConfIndex = gIndex
177
    self.frameSequence.append(gIndex)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
178

179
  def onOpen_section_method(self, backend, gIndex, section):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
180
181
182
    if self.secMethodIndex is None:
      self.secMethodIndex = gIndex

183
184
185
186
187
  def onOpen_x_exciting_section_geometry_optimization(self, backend, gIndex, section):
#    """Trigger called when x_abinit_section_dataset is opened.
#    """
    self.samplingGIndex = backend.openSection("section_sampling_method")

Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
188
189
  def onClose_section_run(self, backend, gIndex, section):
    self.secRunIndex = gIndex
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#    backend.addValue("x_exciting_dummy", self.volumeOptIndex)
########### VOLUME OPTIMIZATION #########################
#    curDir = os.getcwd()
##    mainFile = self.parser.fIn.fIn.name           #####exciting sbt -> zip file####     YES ?????????? sure???? check first    OKOKOKKO
##    dirPath = os.path.dirname(mainFile)           #####exciting sbt -> zip file####     YES ?????????? sure???? check first    OKOKOKKO
#    dirPath = self.mainFileUri[0:-9]     #####exciting LOCAL HOME or from NOMAD URI nmd://  #######   YES                      OKOKOKOK
#    os.chdir(dirPath)
#    os.chdir('../')
#    self.volumeOptIndex = 0
#    for files in os.listdir('.'):
#      if files[0:7] == 'rundir-':
#        self.volumeOptIndex+=1
######################independent from above#################
    if self.volumeCubOptIndex>1:
      self.volumeCubOpt = True
      optGindex = backend.openSection("section_method")
      backend.addValue("x_exciting_volume_optimization", self.volumeCubOpt)
      backend.closeSection("section_method", optGindex)
#    os.chdir(curDir)
209

Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
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
####################################TEST############################
    mainFile = self.parser.fIn.fIn.name
    dirPath = os.path.dirname(self.parser.fIn.name)
#    print("dirPath===",dirPath)
    gw_File = os.path.join(dirPath, "GW_INFO.OUT")
    gwFile = os.path.join(dirPath, "GWINFO.OUT")
    xsFile = os.path.join(dirPath, "INFOXS.OUT")
    for gFile in [gw_File, gwFile]:
      if os.path.exists(gFile):
        gwParser = exciting_parser_gw.GWParser()
        gwParser.parseGW(gFile, backend,
                         dftMethodSectionGindex = self.secMethodIndex,
                         dftSingleConfigurationGindex = self.secSingleConfIndex,
                         xcName = self.xcName,
                         unitCellVol = self.unit_cell_vol,
                         gmaxvr = self.gmaxvr)

        subParser = AncillaryParser(
            fileDescription = exciting_parser_gw.buildGWMatchers(),
            parser = self.parser,
            cachingLevelForMetaName = exciting_parser_gw.get_cachingLevelForMetaName(self.metaInfoEnv, CachingLevel.PreOpenedIgnore),
            superContext = gwParser)
        with open(gFile) as fIn:
            subParser.parseFile(fIn)
        break

    if os.path.exists(xsFile):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
237
238
239
240
241
      excNum = []
      excEn = []
      excBindEn = []
      osclStr = []
      transCoeff = []
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
242
243
244
245
246
247
248
      epsEn = []
      sigmaEn = []
      epsilon = []
      sigma = []
      lossEn = []
      loss = []
      lossDummy = []
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
249
250
251
252
253
254
255
256
257
258
259
#      print("BSE!!!")
#        if os.path.exists(inputgwFile):
      inputXSFile = os.path.join(dirPath, "input.xml")
      selfXSSetGIndex = backend.openSection("section_method")
#      backend.addValue('x_exciting_electronic_structure_method', "BSE")   ########!!!!!!!!!!! So far, BSE is not a valid value for electronic_structure_method. It must be added! #########
      backend.addValue('x_exciting_xs_starting_point', self.xcName)
      if self.secMethodIndex is not None:
        m2mGindex = backend.openNonOverlappingSection("section_method_to_method_refs")
        backend.addValue("method_to_method_ref", self.secMethodIndex)
        backend.addValue("method_to_method_kind", "starting_point")
        backend.closeNonOverlappingSection("section_method_to_method_refs")
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

        for files in os.listdir(dirPath):
            if files[0:11] == "EXCITON_BSE":
                dummyBse = files[11:13]
#                self.tensorComp = files[-6:-4]
                self.tensorComp.append(files[-6:-4])

                if dummyBse == 'si':
                    self.bsetype = 'singlet'
#                  name = "EXCITON_BSE" + self.bsetype
                elif dummyBse == 'tr':
                    self.bsetype = 'triplet'
                elif dummyBse == 'RP':
                    self.bsetype = 'RPA'
                elif dummyBse == 'IP':
                    self.bsetype = 'IP'
                name = "EXCITON_BSE" + self.bsetype + '_SCR'
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
277
#                nameEps = "EPSILON_BSE" + self.bsetype + '_SCR'
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
278
279
280
281
282
283
284
285
286
287
288
289
                if files[len(name):len(name)+4] == 'full':
                    self.screentype = 'full'
                elif files[len(name):len(name)+4] == 'diag':
                    self.screentype = 'diag'
                elif files[len(name):len(name)+4] == 'noin':
                    self.screentype = 'noinvdiag'
                elif files[len(name):len(name)+4] == 'long':
                    self.screentype = 'longrange'
                
        backend.addValue("x_exciting_xs_screening_type", self.screentype)
        backend.addValue("x_exciting_xs_bse_type", self.bsetype)
#        print("===", self.tensorComp[0])
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
290
291
292
        with open(inputXSFile) as f:
          exciting_parser_XS_input.parseInput(f, backend, self.rgkmax)
      backend.closeSection("section_method",selfXSSetGIndex)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
293
294
295
296
297
298
299
300
301
302
303
304
      numberOfComponents = len(self.tensorComp)

      backend.openNonOverlappingSection("section_single_configuration_calculation")
      if self.secSingleConfIndex is not None:
          backend.openNonOverlappingSection("section_calculation_to_calculation_refs")
          backend.addValue("calculation_to_calculation_ref", self.secSingleConfIndex)
          backend.addValue("calculation_to_calculation_kind", "starting_point")
          backend.closeNonOverlappingSection("section_calculation_to_calculation_refs")

      for i in range(numberOfComponents):
          excNum.append([])
          excEn.append([])
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
305
306
          epsEn.append([])
          sigmaEn.append([])
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
307
308
309
          excBindEn.append([])
          osclStr.append([])
          transCoeff.append([[],[]])
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
310
311
312
313
314
315
          epsilon.append([[],[]])
          sigma.append([[],[]])
          lossEn.append([])
          loss.append([[],[]])
#          lossDummy.append([])

Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
316
          outputXSFile = os.path.join(dirPath, "EXCITON_BSE" + self.bsetype + '_SCR' + self.screentype + "_OC" + self.tensorComp[i] + ".OUT")
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
317
318
319
          outputEpsFile = os.path.join(dirPath, "EPSILON_BSE" + self.bsetype + '_SCR' + self.screentype + "_OC" + self.tensorComp[i] + ".OUT")
          outputSigmaFile = os.path.join(dirPath, "SIGMA_BSE" + self.bsetype + '_SCR' + self.screentype + "_OC" + self.tensorComp[i] + ".OUT")
          outputLossFile = os.path.join(dirPath, "LOSS_BSE" + self.bsetype + '_SCR' + self.screentype + "_OC" + self.tensorComp[i] + ".OUT")
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
320
321
322
          with open(outputXSFile) as g:
              xsParser = exciting_parser_xs.XSParser()
              xsParser.parseExciton(outputXSFile, backend, excNum, excEn, excBindEn, osclStr, transCoeff) #, dftMethodSectionGindex = self.secMethodIndex,
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
323
324
325
326
327
328
329
330
331
          with open(outputEpsFile) as g:
              epsParser = exciting_parser_eps.EPSParser()
              epsParser.parseEpsilon(outputEpsFile, backend, epsEn, epsilon) #, dftMethodSectionGindex = self.secMethodIndex,
          with open(outputSigmaFile) as g:
              sigmaParser = exciting_parser_eps.EPSParser()
              sigmaParser.parseEpsilon(outputSigmaFile, backend, sigmaEn, sigma) #, dftMethodSectionGindex = self.secMethodIndex,
          with open(outputLossFile) as g:
              lossParser = exciting_parser_eps.EPSParser()
              lossParser.parseEpsilon(outputLossFile, backend, lossEn, loss) #, dftMethodSectionGindex = self.secMethodIndex,
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
332
#                                    dftSingleConfigurationGindex = self.secSingleConfIndex)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
333
334
      backend.addValue("x_exciting_xs_bse_number_of_components",numberOfComponents)
      backend.addValue("x_exciting_xs_bse_number_of_excitons",len(excNum))
Pardini, Lorenzo (lopa)'s avatar
BSE Xas    
Pardini, Lorenzo (lopa) committed
335
      backend.addValue("x_exciting_xs_bse_number_of_energy_points",len(epsEn))
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
336
      backend.addValue("x_exciting_xs_bse_exciton_energies",excEn) 
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
337
338
339
340
341
342
343
344
345
346
347
348
      backend.addValue("x_exciting_xs_bse_exciton_binding_energies",excBindEn)
      backend.addValue("x_exciting_xs_bse_exciton_oscillator_strength",osclStr)
      backend.addValue("x_exciting_xs_bse_exciton_amplitude_re",transCoeff[0])
      backend.addValue("x_exciting_xs_bse_exciton_amplitude_im",transCoeff[1])
      backend.addValue("x_exciting_xs_bse_epsilon_energies",epsEn)
      backend.addValue("x_exciting_xs_bse_epsilon_re",epsilon[0])
      backend.addValue("x_exciting_xs_bse_epsilon_im",epsilon[1])
      backend.addValue("x_exciting_xs_bse_sigma_energies",sigmaEn)
      backend.addValue("x_exciting_xs_bse_sigma_re",sigma[0])
      backend.addValue("x_exciting_xs_bse_sigma_im",sigma[1])
      backend.addValue("x_exciting_xs_bse_loss_energies",lossEn)
      backend.addValue("x_exciting_xs_bse_loss",loss[0])
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
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
      backend.closeNonOverlappingSection("section_single_configuration_calculation")


#              print(outputXSFile)

#      for files in os.listdir(dirPath):
#          if files[0:11] == "EXCITON_BSE":
#              dummyBse = files[11:13]
#              dummyTenCom = files[-6:-4]
#              if dummyBse == 'si':
#                  self.bsetype = 'singlet'
##                  name = "EXCITON_BSE" + self.bsetype
#              elif dummyBse == 'tr':
#                  self.bsetype = 'triplet'
#              elif dummyBse == 'RP':
#                  self.bsetype = 'RPA'
#              elif dummyBse == 'IP':
#                  self.bsetype = 'IP'
#              name = "EXCITON_BSE" + self.bsetype + '_SCR'
#              if files[len(name):len(name)+4] == 'full':
#                  self.screentype = 'full'
#              elif files[len(name):len(name)+4] == 'diag':
#                  self.screentype = 'diag'
#              elif files[len(name):len(name)+4] == 'noin':
#                  self.screentype = 'noinvdiag'
#              elif files[len(name):len(name)+4] == 'long':
#                  self.screentype = 'longrange'
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
376

Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
377
#              print("===",self.screentype)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
378
379
380

###########################TEST#############################

381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
  def onClose_x_exciting_section_geometry_optimization(self, backend, gIndex, section):
    """Trigger called when x_abinit_section_dataset is closed.
    """
#    print("len(self.frameSequence)=",len(self.frameSequence))
    if len(self.frameSequence) > 1:
      frameGIndex = backend.openSection("section_frame_sequence")
#        if section["x_abinit_geometry_optimization_converged"] is not None:
#          if section["x_abinit_geometry_optimization_converged"][-1] == "are converged":
      backend.addValue("geometry_optimization_converged", True)
#          else:
#            backend.addValue("geometry_optimization_converged", False)
      backend.closeSection("section_frame_sequence", frameGIndex)
#    self.frameSequence = []
    backend.closeSection("section_sampling_method", self.samplingGIndex)

  def onClose_section_frame_sequence(self, backend, gIndex, section):
    """Trigger called when section_framce_sequence is closed.
    """
    backend.addValue("number_of_frames_in_sequence", len(self.frameSequence))
    backend.addArrayValues("frame_sequence_local_frames_ref", np.array(self.frameSequence))
    backend.addValue("frame_sequence_to_sampling_ref", self.samplingGIndex)

#    print("self.samplingMethod=",self.samplingMethod)
    if self.samplingMethod == "geometry_optimization":
#        gix = backend.openSection("section_sampling_method")
#        backend.addValue("XC_functional_name", xcName)
#        backend.closeSection("section_sampling_method", gix)
#        geometryForceThreshold = section["x_exciting_geometry_optimization_threshold_force"]
#        print("geometryForceThreshold=",self.geometryForceThreshold)
        gi = backend.openSection("section_sampling_method")
        backend.addValue("geometry_optimization_threshold_force", self.geometryForceThreshold)
        backend.closeSection("section_sampling_method", gi)
    else:
        pass
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
################################TESDT###########################
#    mainFile = self.parser.fIn.fIn.name
#    dirPath = os.path.dirname(self.parser.fIn.name)
#    print("dirPath===",dirPath)
#    gw_File = os.path.join(dirPath, "GW_INFO.OUT")
#    gwFile = os.path.join(dirPath, "GWINFO.OUT")
#    bseFile = os.path.join(dirPath, "INFOXS.OUT")
#    for gFile in [gw_File, gwFile]:
#      if os.path.exists(gFile):
#        gwParser = exciting_parser_gw.GWParser()
#        gwParser.parseGW(gFile, backend,
#                         dftMethodSectionGindex = self.secMethodIndex,
#                         dftSingleConfigurationGindex = self.secSingleConfIndex,
#                         xcName = self.xcName,
#                         unitCellVol = self.unit_cell_vol,
#                         gmaxvr = self.gmaxvr)
#
#        subParser = AncillaryParser(
#            fileDescription = exciting_parser_gw.buildGWMatchers(),
#            parser = self.parser,
#            cachingLevelForMetaName = exciting_parser_gw.get_cachingLevelForMetaName(self.metaInfoEnv, CachingLevel.PreOpenedIgnore),
#            superContext = gwParser)
#        with open(gFile) as fIn:
#            subParser.parseFile(fIn)
#        break
#
#    if os.path.exists(bseFile):
#      print("BSE!!!")
###########################TEST##########################
444
445
446
447
  def onClose_x_exciting_section_lattice_vectors(self, backend, gIndex, section):
    latticeX = section["x_exciting_geometry_lattice_vector_x"]
    latticeY = section["x_exciting_geometry_lattice_vector_y"]
    latticeZ = section["x_exciting_geometry_lattice_vector_z"]
448
    cell = [[latticeX[0],latticeY[0],latticeZ[0]],
449
            [latticeX[1],latticeY[1],latticeZ[1]],
450
            [latticeX[2],latticeY[2],latticeZ[2]]]
451
    self.sim_cell = cell
452
    backend.addValue("simulation_cell", cell)
453

Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
454
455
456
457
  def onClose_x_exciting_section_reciprocal_lattice_vectors(self, backend, gIndex, section):
    recLatticeX = section["x_exciting_geometry_reciprocal_lattice_vector_x"]
    recLatticeY = section["x_exciting_geometry_reciprocal_lattice_vector_y"]
    recLatticeZ = section["x_exciting_geometry_reciprocal_lattice_vector_z"]
458
    recCell = [[recLatticeX[0],recLatticeY[0],recLatticeZ[0]],
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
459
            [recLatticeX[1],recLatticeY[1],recLatticeZ[1]],
460
461
            [recLatticeX[2],recLatticeY[2],recLatticeZ[2]]]
    backend.addValue("x_exciting_simulation_reciprocal_cell", recCell)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
462

463
464
  def onClose_x_exciting_section_xc(self, backend, gIndex, section):
    xcNr = section["x_exciting_xc_functional"][0]
465
466
    xc_internal_map = {
        2: ['LDA_C_PZ', 'LDA_X_PZ'],
467
        3: ['LDA_C_PW', 'LDA_X_PZ'],
468
469
        4: ['LDA_C_XALPHA'],
        5: ['LDA_C_VBH'],
470
471
472
473
474
475
476
        20: ['GGA_C_PBE', 'GGA_X_PBE'],
        21: ['GGA_C_PBE', 'GGA_X_PBE_R'],
        22: ['GGA_C_PBE_SOL', 'GGA_X_PBE_SOL'],
        26: ['GGA_C_PBE', 'GGA_X_WC'],
        30: ['GGA_C_AM05', 'GGA_C_AM05'],
        300: ['GGA_C_BGCP', 'GGA_X_PBE'],
        406: ['HYB_GGA_XC_PBEH']
477
        }
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
478
479
480
481
482
483
484
485
486
487
488
    if xcNr == 100:
        dirPath = os.path.dirname(self.parser.fIn.name)
        inputGSFile = os.path.join(dirPath, "input.xml") 
        with open(inputGSFile) as f:
            exciting_parser_GS_input.parseInput(f, backend)
    else:
        for xcName in xc_internal_map[xcNr]:
          self.xcName = xcName
          gi = backend.openSection("section_XC_functionals")
          backend.addValue("XC_functional_name", xcName)
          backend.closeSection("section_XC_functionals", gi)
489

490
  def onClose_section_single_configuration_calculation(self, backend, gIndex, section):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
491
#    logging.error("BASE onClose_section_single_configuration_calculation")
492
493
    backend.addValue('single_configuration_to_calculation_method_ref', self.secMethodIndex)
    backend.addValue('single_configuration_calculation_to_system_ref', self.secSystemIndex)
494
#    print("self.samplingMethod=",self.samplingMethod)
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
####################VOLUME TEST BEGIN################################
    ext_uri = []
#    backend.addValue("x_exciting_dummy=",self.volumeOptIndex)
#    backend.addValue("x_exciting_dummy", self.volumeOptIndex)
    if self.volumeCubOptIndex > 1:
      for j in range(1, self.volumeCubOptIndex):
        if (j<10):
          ext_uri.append(self.mainFilePath[0:-9] + 'rundir-0' + str(j) + '/INFO.OUT')
#          backend.addValue("x_exciting_dummy2", ext_uri[-1])
#          print("ext_uri===",ext_uri)
        else:
          ext_uri.append(self.mainFilePath[0:-9] + 'rundir-' + str(j) + '/INFO.OUT')
#          backend.addValue("x_exciting_dummy2", ext_uri[-1])
#          print("ext_uri===",ext_uri)
#    backend.addArrayValues("x_exciting_dummy2", np.asarray(ext_uri))
    for ref in ext_uri:
      refGindex = backend.openSection("section_calculation_to_calculation_refs")
      backend.addValue("calculation_to_calculation_external_url", ref)
      backend.addValue("calculation_to_calculation_kind", "source_calculation")
      backend.closeSection("section_calculation_to_calculation_refs", refGindex)

####################VOLUME TEST END############################


519
520
    if self.samplingMethod == "geometry_optimization":
        self.geometryForceThreshold = section["x_exciting_geometry_optimization_threshold_force"][0]
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
521
522
523
524
525
526
527
528
529
    forceX = section["x_exciting_geometry_atom_forces_x"]
    if forceX:
      forceY = section["x_exciting_geometry_atom_forces_y"]
      forceZ = section["x_exciting_geometry_atom_forces_z"]
      atoms = len(forceX)
      atom_geometry_forces = []
      for i in range(0,atoms):
          atom_geometry_forces.append([forceX[i],forceY[i],forceZ[i]])
      backend.addValue("atom_forces",atom_geometry_forces)
530
531
532
533
#        print("geometryForceThreshold=",geometryForceThreshold)
#        backend.addValue("geometry_optimization_threshold_force", geometryForceThreshold)
#    else:
#        pass
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
#
##############TO DO. FIX FORCES#####################
#    forceX = section["x_exciting_atom_forces_x"]
#    if forceX:
#      forceY = section["x_exciting_atom_forces_y"]
#      forceZ = section["x_exciting_atom_forces_z"]
#      print("forceX===",forceX)
#      print("forceY===",forceY)
#      print("forceZ===",forceZ)
#      forceCoreX = section["x_exciting_atom_core_forces_x"]
#      forceCoreY = section["x_exciting_atom_core_forces_y"]
#      forceCoreZ = section["x_exciting_atom_core_forces_z"]
#      print("forceCoreX===",forceCoreX)
##      print("forceCoreY===",forceCoreY)
#      print("forceCoreZ===",forceCoreZ)
#      forceIBSX = section["x_exciting_atom_IBS_forces_x"]
#      forceIBSY = section["x_exciting_atom_IBS_forces_y"]
#      forceIBSZ = section["x_exciting_atom_IBS_forces_z"]
#      print("forceIBSX===",forceIBSX)
#      print("forceIBSY===",forceIBSY)
#      print("forceIBSZ===",forceIBSZ)
#      forceHFX = section["x_exciting_atom_HF_forces_x"]
#      forceHFY = section["x_exciting_atom_HF_forces_y"]
#      forceHFZ = section["x_exciting_atom_HF_forces_z"]
#      fConv = convert_unit_function("hartree/bohr", "N")
#      atoms = len(forceX)
#      atom_forces = []
#      atom_core_forces = []
#      atom_IBS_forces = []
#      atom_HF_forces = []
#      for i in range(0,atoms):
#        print("atoms===",atoms)
#        print("i===",i)
#        print("atom_forces===",atom_forces)
#        print("forceX[i]===",forceX[i])
#        print("forceY[i]===",forceY[i])
#        print("forceZ[i]===",forceZ[i])
#        print("forceCoreX[i]===",forceCoreX[i])
#        print("forceCoreY[i]===",forceCoreY[i])
#        print("forceCoreZ[i]===",forceCoreZ[i])
#        print("forceIBSX[i]===",forceIBSX[i])
#        print("forceIBSY[i]===",forceIBSY[i])
#        print("forceIBSZ[i]===",forceIBSZ[i])
#        atom_forces.append([fConv(forceX[i]),fConv(forceY[i]),fConv(forceZ[i])])
#        atom_core_forces.append([fConv(forceCoreX[i]),fConv(forceCoreY[i]),fConv(forceCoreZ[i])])
#        atom_IBS_forces.append([fConv(forceIBSX[i]),fConv(forceIBSY[i]),fConv(forceIBSZ[i])])
#        atom_HF_forces.append([fConv(forceHFX[i]),fConv(forceHFY[i]),fConv(forceHFZ[i])])
#      backend.addValue("atom_forces",atom_forces)
#      backend.addValue("x_exciting_atom_core_forces",atom_core_forces)
#      backend.addValue("x_exciting_atom_IBS_forces",atom_IBS_forces)
#      backend.addValue("x_exciting_atom_HF_forces",atom_HF_forces)
585
#    print("atom_forces=",atom_forces)
586
#
587
588
    dirPath = os.path.dirname(self.parser.fIn.name)
    dosFile = os.path.join(dirPath, "dos.xml")
589
    bandFile = os.path.join(dirPath, "bandstructure.xml")
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
590
    fermiSurfFile = os.path.join(dirPath, "FERMISURF.bxsf")
591
    eigvalFile = os.path.join(dirPath, "EIGVAL.OUT")    
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
592
#    logging.error("done BASE onClose_section_single_configuration_calculation")
593

594
595
    if os.path.exists(dosFile):
      with open(dosFile) as f:
596
        exciting_parser_dos.parseDos(f, backend, self.spinTreat, self.unit_cell_vol)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
597
598
    if os.path.exists(bandFile):
      with open(bandFile) as g:
599
        exciting_parser_bandstructure.parseBand(g, backend, self.spinTreat)
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
    if os.path.exists(eigvalFile):
      eigvalGIndex = backend.openSection("section_eigenvalues")
      with open(eigvalFile) as g:
          eigvalKpoint=[]
          eigvalVal=[]
          eigvalOcc=[]
          eigvalValSpin = [[],[]]
          eigvalOccSpin = [[],[]]
          fromH = unit_conversion.convert_unit_function("hartree", "J")
          while 1:
            s = g.readline()
            if not s: break
            s = s.strip()              
            if len(s) < 20:
              if "nstsv" in s.split():
                 nstsv = int(s.split()[0])
                 nstsv2=int(nstsv/2)
              elif "nkpt" in s.split():
                 nkpt = int(s.split()[0])
              continue
            elif len(s) > 50:
              eigvalVal.append([])
              eigvalOcc.append([])
              eigvalKpoint.append([float(x) for x in s.split()[1:4]])
            else:
              try: int(s[0])
              except ValueError:
                continue
              else:
                n, e, occ = s.split()
                eigvalVal[-1].append(fromH(float(e)))
                eigvalOcc[-1].append(float(occ))
          if not self.spinTreat:
633
634
635
636
637
638
639
            for i in range(0,nkpt):
              eigvalValSpin[0].append(eigvalVal[i][0:nstsv])
              eigvalOccSpin[0].append(eigvalOcc[i][0:nstsv])
              eigvalValSpin[1].append(eigvalVal[i][0:nstsv])
              eigvalOccSpin[1].append(eigvalOcc[i][0:nstsv])
            backend.addValue("eigenvalues_values", eigvalValSpin)
            backend.addValue("eigenvalues_occupation", eigvalOccSpin)
640
641
642
643
644
645
          else:
            for i in range(0,nkpt):
              eigvalValSpin[0].append(eigvalVal[i][0:nstsv2])
              eigvalOccSpin[0].append(eigvalOcc[i][0:nstsv2])
              eigvalValSpin[1].append(eigvalVal[i][nstsv2:nstsv])
              eigvalOccSpin[1].append(eigvalOcc[i][nstsv2:nstsv])
646
647
648
            backend.addValue("eigenvalues_values", eigvalValSpin)
            backend.addValue("eigenvalues_occupation", eigvalOccSpin)
          backend.addValue("eigenvalues_kpoints", eigvalKpoint)
649
          backend.closeSection("section_eigenvalues",eigvalGIndex)
Pardini, Lorenzo (lopa)'s avatar
test    
Pardini, Lorenzo (lopa) committed
650
651
652

##########################Parsing Fermi surface##################

653
654
655
656
657
    if os.path.exists(fermiSurfFile):
      fermiGIndex = backend.openSection("x_exciting_section_fermi_surface")
      with open(fermiSurfFile) as g:
        grid = []
        all_vectors = []
658
        values = []
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
        origin = []
        vectors = []
        fermi = 0
        number_of_bands = 0
        mesh_size = 0
        fromH = unit_conversion.convert_unit_function("hartree", "J")
        while 1:
          s = g.readline()
          if not s: break
          s = s.strip()
          st = s.split()
          if len(st) == 3:
            if len(s) >= 40:
              all_vectors.append([])
              i = 0
              while i < 3:
                all_vectors[-1].append(float(st[i]))
                i += 1
            elif st[0] == "Fermi":
              fermi = fromH(float(st[2]))
            else:
              j = 0
              while j < 3:
                grid.append(int(st[j]))
                j += 1
          elif len(st) == 2:
685
            values.append([])
686
          elif len(s) >= 12 and len(st) == 1:
687
688
689
690
            try: float(st[0])
            except ValueError:
              continue
            else:
691
              values[-1].append(float(st[0]))
692
          elif len(s) < 5 and len(st) == 1:
693
            number_of_bands = st[0] 
694
        mesh_size = grid[0]*grid[1]*grid[2]
695
696
697
698
699
        origin = all_vectors[0]
        vectors = all_vectors[1:]
        backend.addValue("x_exciting_number_of_bands_fermi_surface", int(number_of_bands))
        backend.addValue("x_exciting_number_of_mesh_points_fermi_surface", int(mesh_size))
        backend.addValue("x_exciting_fermi_energy_fermi_surface", float(fermi))
700
701
702
703
704
        backend.addArrayValues("x_exciting_grid_fermi_surface", np.asarray(grid))
        backend.addArrayValues("x_exciting_origin_fermi_surface", np.asarray(origin))
        backend.addArrayValues("x_exciting_vectors_fermi_surface", np.asarray(vectors))
        backend.addArrayValues("x_exciting_values_fermi_surface", np.asarray(values))
        backend.closeSection("x_exciting_section_fermi_surface",fermiGIndex)
705

706
  def onClose_x_exciting_section_spin(self, backend, gIndex, section):
707

708
709
710
711
712
713
    spin = section["x_exciting_spin_treatment"][0]
    spin = spin.strip()
    if spin == "spin-polarised":
      self.spinTreat = True
    else:
      self.spinTreat = False
714

715
  def onClose_section_system(self, backend, gIndex, section):
716

717
    self.unit_cell_vol = section["x_exciting_unit_cell_volume"]
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
718
    self.gmaxvr = section["x_exciting_gmaxvr"]
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
719
    self.rgkmax = section["x_exciting_rgkmax"]
720
    backend.addArrayValues('configuration_periodic_dimensions', np.asarray([True, True, True]))
721

722
    self.secSystemDescriptionIndex = gIndex
723

724
    if self.atom_pos and self.cell_format[0] == 'cartesian':
725
#       print("self.atom_pos=",self.atom_pos)
726
       backend.addArrayValues('atom_positions', np.asarray(self.atom_pos))
727
    elif self.atom_pos and self.cell_format[0] == 'lattice':
728
729
#       print("aaaself.atom_pos=",self.atom_pos)
#       print("aaaself.atom_labels=",self.atom_labels)
730
731
732
733
       atoms = Atoms(self.atom_labels, self.atom_pos, cell=[(1, 0, 0),(0, 1, 0),(0, 0, 1)])
       atoms.set_cell(self.sim_cell, scale_atoms=True)
       self.atom_pos = atoms.get_positions()
       backend.addArrayValues('atom_positions', np.asarray(self.atom_pos))
734
    if self.atom_labels is not None:
735
#       print("aaaself.atom_labels=",self.atom_labels)
736
       backend.addArrayValues('atom_labels', np.asarray(self.atom_labels))
737
738
    self.atom_labels = []

739
740
741
742
    excSmearingKind = section["x_exciting_smearing_type"]
 
    smearing_internal_map = {
        "Gaussian": ['gaussian'],
743
744
        "Methfessel-Paxton": ['methfessel-paxton'],
        "Fermi-Dirac": ['fermi'],
745
        "Extended": ['tetrahedra']
746
747
        }

748
749
750
751
752
    if self.samplingMethod is not "geometry_optimization":
        for smName in smearing_internal_map[excSmearingKind[0]]:
          backend.addValue("smearing_kind", smName)
    else:
        pass
753

754
  def onClose_x_exciting_section_atoms_group(self, backend, gIndex, section):
755
#    print("start.self.atom_labels=",self.atom_labels)
756
757
    fromB = unit_conversion.convert_unit_function("bohr", "m")
    formt = section['x_exciting_atom_position_format']
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
758
759
760
761
762
    if self.samplingMethod is not "geometry_optimization":
      pass
    else:
      if self.atom_pos is not None: self.atom_pos = []
      if self.atom_labels is not None: self.atom_labels = []
763
    self.cell_format = formt
Mohamed, Fawzi Roberto (fawzi)'s avatar
Mohamed, Fawzi Roberto (fawzi) committed
764
    pos = [section['x_exciting_geometry_atom_positions_' + i] for i in ['x', 'y', 'z']]
765
#    print("pos=",pos)
Mohamed, Fawzi Roberto (fawzi)'s avatar
Mohamed, Fawzi Roberto (fawzi) committed
766
    pl = [len(comp) for comp in pos]
767
768
769
770
    natom = pl[0]
    if pl[1] != natom or pl[2] != natom:
      raise Exception("invalid number of atoms in various components %s" % pl)
    for i in range(natom):
771
#      print("nattom=",natom)  
772
773
774
775
776
777
#      print("i=",i)
#      print("natom=",natom)
#      print("[pos[0][i]=",pos[0][i])
#      print("[pos[1][i]=",pos[1][i])
#      print("[pos[2][i]=",pos[2][i])
#      print("self.atom_pos=",self.atom_pos)
778
779
780
      if formt[0] == 'cartesian':
        self.atom_pos.append([fromB(pos[0][i]), fromB(pos[1][i]), fromB(pos[2][i])])
      else:
781
782
#        print("self.atom_labels_prima=",self.atom_labels)
#        print("self.atom_pos_prima=",self.atom_pos)
783
        self.atom_pos.append([pos[0][i], pos[1][i], pos[2][i]])
784
785
786
787
788
789
#        print("self.atom_pos_dopo=",self.atom_pos)
#        print("self.atom_labels_dopo=",self.atom_labels)
#    print("natom=",natom)
#    print("section['x_exciting_geometry_atom_labels']=",section['x_exciting_geometry_atom_labels'])
#    print("self.samplingMethod[0]=",self.samplingMethod)
    if self.samplingMethod is not "geometry_optimization":
790
#        print("prima=",self.atom_labels)
791
        self.atom_labels = self.atom_labels + (section['x_exciting_geometry_atom_labels'] * natom)
792
793
#        print("self.atom_labels=",self.atom_labels)
#        print("section['x_exciting_geometry_atom_labels']=",section['x_exciting_geometry_atom_labels'])
794
795
796
    else:
        self.atom_labels = self.atom_labels + section['x_exciting_geometry_atom_labels']
#    print("self.atom_labels_dopodopo=",self.atom_labels)
797

798
  def onClose_section_method(self, backend, gIndex, section):
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
799
800
    if gIndex == self.secMethodIndex:
      backend.addValue('electronic_structure_method', "DFT")
801
802
803
804
805
806
807
808
809
810
811
812
      try:
        energy_thresh = section["x_exciting_scf_threshold_energy_change"][0]
      except:
        pass
      try:
        potential_thresh = section["x_exciting_scf_threshold_potential_change_list"][0]
      except:
        pass
      try:
        charge_thresh = section["x_exciting_scf_threshold_charge_change_list"][0]
      except:
        pass
813
814
      if section["x_exciting_scf_threshold_force_change_list"]:
        force_thresh = section["x_exciting_scf_threshold_force_change_list"][0]
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
        try:
          backend.addValue('x_exciting_scf_threshold_force_change', force_thresh)
        except:
          pass
      try:
        backend.addValue('scf_threshold_energy_change', energy_thresh)
      except:
        pass
      try:
        backend.addValue('x_exciting_scf_threshold_potential_change', potential_thresh)
      except:
        pass
      try:
        backend.addValue('x_exciting_scf_threshold_charge_change', charge_thresh)
      except:
        pass
##########BELOW VOLUME OPTIMIZATION######################
#    if self.volumeOptIndex>1:
#      self.volumeOpt = True
#      optGindex = backend.openSection("section_method")
#      backend.addValue("x_exciting_volume_optimization", self.volumeOpt)
#      backend.closeSection("section_method", optGindex)
#
#    ext_uri = []
#    backend.addValue("x_exciting_dummy", self.volumeOptIndex)
#    if self.volumeOptIndex > 1:
#      for j in range(1, self.volumeOptIndex):
#        if (j<10):
#          ext_uri.append(self.mainFilePath[0:-9] + 'rundir-0' + str(j) + '/INFO.OUT')
#        else:
#          ext_uri.append(self.mainFilePath[0:-9] + 'rundir-' + str(j) + '/INFO.OUT')
#    for ref in ext_uri:
#      refGindex = backend.openSection("section_calculation_to_calculation_refs")
#      backend.addValue("calculation_to_calculation_external_url", ref)
#      backend.addValue("calculation_to_calculation_kind", "source_calculation")
#      backend.closeSection("section_calculation_to_calculation_refs", refGindex)
851

852
853
854
855
856
857
858
mainFileDescription = \
    SM(name = "root matcher",
       startReStr = "",
       weak = True,
       subMatchers = [
         SM(name = "header",
         startReStr = r"\s*\|\s*EXCITING\s*(?P<program_version>[-a-zA-Z0-9]+)\s*started\s*=",
859
         fixedStartValues={'program_name': 'exciting', 'program_basis_set_type': '(L)APW+lo' },
860
            sections = ["section_run", "section_method"],
861
862
863
864
         subMatchers = [
	   SM(name = 'input',
              startReStr = r"\|\sStarting initialization",
              endReStr = r"\|\sEnding initialization",
865
              sections = ['section_system'],
866
867
              subMatchers = [
                SM(startReStr = r"\sLattice vectors \(cartesian\) :",
868
                sections = ["x_exciting_section_lattice_vectors"],
869
                subMatchers = [
870

871
    SM(startReStr = r"\s*(?P<x_exciting_geometry_lattice_vector_x__bohr>[-+0-9.]+)\s+(?P<x_exciting_geometry_lattice_vector_y__bohr>[-+0-9.]+)\s+(?P<x_exciting_geometry_lattice_vector_z__bohr>[-+0-9.]+)", repeats = True)
872
                ]),
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
873
                SM(startReStr = r"\sReciprocal lattice vectors \(cartesian\) :",
874
                sections = ["x_exciting_section_reciprocal_lattice_vectors"],
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
875
876
                subMatchers = [

877
    SM(startReStr = r"\s*(?P<x_exciting_geometry_reciprocal_lattice_vector_x__bohr_1>[-+0-9.]+)\s+(?P<x_exciting_geometry_reciprocal_lattice_vector_y__bohr_1>[-+0-9.]+)\s+(?P<x_exciting_geometry_reciprocal_lattice_vector_z__bohr_1>[-+0-9.]+)", repeats = True)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
878
                ]),
879
880
881
    SM(r"\s*Unit cell volume\s*:\s*(?P<x_exciting_unit_cell_volume__bohr3>[-0-9.]+)"),
    SM(r"\s*Brillouin zone volume\s*:\s*(?P<x_exciting_brillouin_zone_volume__bohr_3>[-0-9.]+)"),
    SM(r"\s*Species\s*:\s*[0-9]\s*\((?P<x_exciting_geometry_atom_labels>[-a-zA-Z0-9]+)\)", repeats = True,
882
      sections = ["x_exciting_section_atoms_group"],
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
883
       subMatchers = [
884
885
        SM(r"\s*muffin-tin radius\s*:\s*(?P<x_exciting_muffin_tin_radius__bohr>[-0-9.]+)", repeats = True),
        SM(r"\s*# of radial points in muffin-tin\s*:\s*(?P<x_exciting_muffin_tin_points>[-0-9.]+)", repeats = True),
886
        SM(startReStr = r"\s*atomic positions\s*\((?P<x_exciting_atom_position_format>[-a-zA-Z]+)\)\s*:\s*",
887
           endReStr = r"\s*magnetic fields\s*",
888
           subMatchers = [
889
                    SM(r"\s*(?P<x_exciting_geometry_atom_number>[+0-9]+)\s*:\s*(?P<x_exciting_geometry_atom_positions_x>[-+0-9.]+)\s*(?P<x_exciting_geometry_atom_positions_y>[-+0-9.]+)\s*(?P<x_exciting_geometry_atom_positions_z>[-+0-9.]+)", repeats = True)
890
891
892
893
894
         ]) #,
#        SM(startReStr = r"\s*magnetic fields\s*\((?P<x_exciting_magnetic_field_format>[-a-zA-Z]+)\)\s*:\s*",
#           subMatchers = [
#                    SM(r"\s*(?P<x_exciting_MT_external_magnetic_field_atom_number>[+0-9]+)\s*:\s*(?P<x_exciting_MT_external_magnetic_field_x>[-+0-9.]+)\s*(?P<x_exciting_MT_external_magnetic_field_y>[-+0-9.]+)\s*(?P<x_exciting_MT_external_magnetic_field_z>[-+0-9.]+)", repeats = True)
#         ])
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
895
    ]),
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
896
    SM(r"\s*Total number of atoms per unit cell\s*:\s*(?P<x_exciting_number_of_atoms>[-0-9.]+)"),
897
898
    SM(r"\s*Spin treatment\s*:\s*(?P<x_exciting_spin_treatment>[-a-zA-Z\s*]+)",
       sections = ["x_exciting_section_spin"]),
899
900
901
    SM(r"\s*k-point grid\s*:\s*(?P<x_exciting_number_kpoint_x>[-0-9.]+)\s+(?P<x_exciting_number_kpoint_y>[-0-9.]+)\s+(?P<x_exciting_number_kpoint_z>[-0-9.]+)"),
    SM(r"\s*k-point offset\s*:\s*(?P<x_exciting_kpoint_offset_x>[-0-9.]+)\s+(?P<x_exciting_kpoint_offset_y>[-0-9.]+)\s+(?P<x_exciting_kpoint_offset_z>[-0-9.]+)"),
    SM(r"\s*Total number of k-points\s*:\s*(?P<x_exciting_number_kpoints>[-0-9.]+)"),
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
902
    SM(r"\s*R\^MT_min \* \|G\+k\|_max \(rgkmax\)\s*:\s*(?P<x_exciting_rgkmax>[-0-9.]+)"),
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
903
    SM(r"\s*Maximum \|G\+k\| for APW functions\s*:\s*(?P<x_exciting_gkmax__bohr_1>[-0-9.]+)"),
904
905
906
    SM(r"\s*Maximum \|G\| for potential and density\s*:\s*(?P<x_exciting_gmaxvr__bohr_1>[-0-9.]+)"),
    SM(r"\s*G-vector grid sizes\s*:\s*(?P<x_exciting_gvector_size_x>[-0-9.]+)\s+(?P<x_exciting_gvector_size_y>[-0-9.]+)\s+(?P<x_exciting_gvector_size_z>[-0-9.]+)"),
    SM(r"\s*Total number of G-vectors\s*:\s*(?P<x_exciting_gvector_total>[-0-9.]+)"),
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
907
908
    SM(startReStr = r"\s*Maximum angular momentum used for\s*",
        subMatchers = [
909
          SM(r"\s*APW functions\s*:\s*(?P<x_exciting_lmaxapw>[-0-9.]+)")
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
910
        ]),
911
912
    SM(r"\s*Total nuclear charge\s*:\s*(?P<x_exciting_nuclear_charge>[-0-9.]+)"),
    SM(r"\s*Total electronic charge\s*:\s*(?P<x_exciting_electronic_charge>[-0-9.]+)"),
913
914
    SM(r"\s*Total core charge\s*:\s*(?P<x_exciting_core_charge_initial>[-0-9.]+)"),
    SM(r"\s*Total valence charge\s*:\s*(?P<x_exciting_valence_charge_initial>[-0-9.]+)"),
915
916
917
918
919
920
    SM(r"\s*Effective Wigner radius, r_s\s*:\s*(?P<x_exciting_wigner_radius>[-0-9.]+)"),
    SM(r"\s*Number of empty states\s*:\s*(?P<x_exciting_empty_states>[-0-9.]+)"),
    SM(r"\s*Total number of valence states\s*:\s*(?P<x_exciting_valence_states>[-0-9.]+)"),
    SM(r"\s*Maximum Hamiltonian size\s*:\s*(?P<x_exciting_hamiltonian_size>[-0-9.]+)"),
    SM(r"\s*Maximum number of plane-waves\s*:\s*(?P<x_exciting_pw>[-0-9.]+)"),
    SM(r"\s*Total number of local-orbitals\s*:\s*(?P<x_exciting_lo>[-0-9.]+)"),
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
921
922
    SM(startReStr = r"\s*Exchange-correlation type\s*:\s*(?P<x_exciting_xc_functional>[-0-9.]+)",
       sections = ['x_exciting_section_xc']),
923
    SM(r"\s*Smearing scheme\s*:\s*(?P<x_exciting_smearing_type>[-a-zA-Z0-9]+)"),
924
    SM(r"\s*Smearing width\s*:\s*(?P<smearing_width__hartree>[-0-9.]+)"),
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
925
    SM(r"\s*Using\s*(?P<x_exciting_potential_mixing>[-a-zA-Z\s*]+)\s*potential mixing")
926
    ]),
927
928
929
930
931
932
933
934
935
936
            SM(name = "single configuration iteration",
              startReStr = r"\|\s*Self-consistent loop started\s*\+",
              sections = ["section_single_configuration_calculation"],
              repeats = True,
              subMatchers = [
                SM(name = "scfi totE",
                 startReStr =r"\|\s*SCF iteration number\s*:",
                  sections = ["section_scf_iteration"],
                  repeats = True,
                  subMatchers = [
937
                   SM(r"\s*Total energy\s*:\s*(?P<energy_total_scf_iteration__hartree>[-0-9.]+)"),
938
                   SM(r"\s*Fermi energy\s*:\s*(?P<x_exciting_fermi_energy_scf_iteration__hartree>[-0-9.]+)"),
939
                   SM(r"\s*Kinetic energy\s*:\s*(?P<electronic_kinetic_energy_scf_iteration__hartree>[-0-9.]+)"),
940
941
942
                   SM(r"\s*Coulomb energy\s*:\s*(?P<x_exciting_coulomb_energy_scf_iteration__hartree>[-0-9.]+)"),
                   SM(r"\s*Exchange energy\s*:\s*(?P<x_exciting_exchange_energy_scf_iteration__hartree>[-0-9.]+)"),
                   SM(r"\s*Correlation energy\s*:\s*(?P<x_exciting_correlation_energy_scf_iteration__hartree>[-0-9.]+)"),
943
                   SM(r"\s*Sum of eigenvalues\s*:\s*(?P<energy_sum_eigenvalues_scf_iteration__hartree>[-0-9.]+)"),
944
945
                   SM(r"\s*Effective potential energy\s*:\s*(?P<x_exciting_effective_potential_energy_scf_iteration__hartree>[-0-9.]+)"),
                   SM(r"\s*Coulomb potential energy\s*:\s*(?P<x_exciting_coulomb_potential_energy_scf_iteration__hartree>[-0-9.]+)"),
946
                   SM(r"\s*xc potential energy\s*:\s*(?P<energy_XC_potential_scf_iteration__hartree>[-0-9.]+)"),
947
948
949
950
951
                   SM(r"\s*Hartree energy\s*:\s*(?P<x_exciting_hartree_energy_scf_iteration__hartree>[-0-9.]+)"),
                   SM(r"\s*Electron-nuclear energy\s*:\s*(?P<x_exciting_electron_nuclear_energy_scf_iteration__hartree>[-0-9.]+)"),
                   SM(r"\s*Nuclear-nuclear energy\s*:\s*(?P<x_exciting_nuclear_nuclear_energy_scf_iteration__hartree>[-0-9.]+)"),
                   SM(r"\s*Madelung energy\s*:\s*(?P<x_exciting_madelung_energy_scf_iteration__hartree>[-0-9.]+)"),
                   SM(r"\s*Core-electron kinetic energy\s*:\s*(?P<x_exciting_core_electron_kinetic_energy_scf_iteration__hartree>[-0-9.]+)"),
952
                   SM(r"\s*Absolute change in total energy   (target)\s*:\s*(?P<energy_change_scf_iteration__hartree>[-0-9.]+)\s*(\s*(?P<scf_threshold_energy_change__hartree>[-0-9.]+))"),
953
                   SM(r"\s*DOS at Fermi energy \(states\/Ha\/cell\)\s*:\s*(?P<x_exciting_dos_fermi_scf_iteration__hartree_1>[-0-9.]+)"),
954
                   SM(r"\s*core\s*:\s*(?P<x_exciting_core_charge_scf_iteration>[-0-9.]+)"),
955
                   SM(r"\s*core leakage\s*:\s*(?P<x_exciting_core_leakage_scf_iteration>[-0-9.]+)"),
956
                   SM(r"\s*valence\s*:\s*(?P<x_exciting_valence_charge_scf_iteration>[-0-9.]+)"),
957
958
959
960
                   SM(r"\s*interstitial\s*:\s*(?P<x_exciting_interstitial_charge_scf_iteration>[-0-9.]+)"),
                   SM(r"\s*total charge in muffin-tins\s*:\s*(?P<x_exciting_total_MT_charge_scf_iteration>[-0-9.]+)"),
                   SM(r"\s*Estimated fundamental gap\s*:\s*(?P<x_exciting_gap_scf_iteration__hartree>[-0-9.]+)"),
                   SM(r"\s*Wall time \(seconds\)\s*:\s*(?P<x_exciting_time_scf_iteration>[-0-9.]+)"),
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
961
                   SM(r"\s*RMS change in effective potential \(target\)\s*:\s*(?P<x_exciting_effective_potential_convergence_scf_iteration__hartree>[0-9]+\.[0-9]*([E]?[-]?[0-9]+))\s*\(\s*(?P<x_exciting_scf_threshold_potential_change_list__hartree>[0-9]\.[0-9]*([E]?[-]?[0-9]+))\)"),
962
                   SM(r"\s*Absolute change in total energy\s*\(target\)\s*:\s*(?P<x_exciting_energy_convergence_scf_iteration>[0-9]+\.[0-9]*([E]?[-]?[0-9]+))\s*\(\s*(?P<x_exciting_scf_threshold_energy_change__hartree>[0-9]\.[0-9]*([E]?[-]?[0-9]+))\)"),
963
                   SM(r"\s*Absolute change in total energy\s*\(target\)\s*\:\s*\s*\(\s*[0-9]+\.[0-9]+\s*[0-9]+\.[0-9]+\s*[0-9]+\.[0-9]+\s*\)\s*avg =\s*[0-9]+\.[0-9]+\s*\(\s*(?P<x_exciting_scf_threshold_energy_change__hartree>[0-9.]+E?[-][0-9]+)\s*\)"),
964
965
                   SM(r"\s*Charge distance\s*\(target\)\s*:\s*(?P<x_exciting_charge_convergence_scf_iteration>[0-9]\.[0-9]*([E]?[-]?[0-9]+))\s*\(\s*(?P<x_exciting_scf_threshold_charge_change_list>[0-9]\.[0-9]*([E]?[-]?[0-9]+))\)"),
                   SM(r"\s*Abs. change in max-nonIBS-force\s*\(target\)\s*:\s*(?P<x_exciting_force_convergence_scf_iteration>[0-9]\.[0-9]*([E]?[-]?[0-9]+))\s*\(\s*(?P<x_exciting_scf_threshold_force_change_list>[0-9]\.[0-9]*([E]?[-]?[0-9]+))\)")
966
                  ]),
967
                SM(name="final_quantities",
968
969
970
                  startReStr = r"\| Convergence targets achieved. Performing final SCF iteration\s*\+",
                  endReStr = r"\| Self-consistent loop stopped\s*\+",
                   subMatchers = [
971
                     SM(r"\s*Total energy\s*:\s*(?P<energy_total__hartree>[-0-9.]+)"),
972
                     SM(r"\s*Fermi energy\s*:\s*(?P<x_exciting_fermi_energy__hartree>[-0-9.]+)"),
973
                     SM(r"\s*Kinetic energy\s*:\s*(?P<electronic_kinetic_energy__hartree>[-0-9.]+)"),
974
975
976
                     SM(r"\s*Coulomb energy\s*:\s*(?P<x_exciting_coulomb_energy__hartree>[-0-9.]+)"),
                     SM(r"\s*Exchange energy\s*:\s*(?P<x_exciting_exchange_energy__hartree>[-0-9.]+)"),
                     SM(r"\s*Correlation energy\s*:\s*(?P<x_exciting_correlation_energy__hartree>[-0-9.]+)"),
977
                     SM(r"\s*Sum of eigenvalues\s*:\s*(?P<energy_sum_eigenvalues__hartree>[-0-9.]+)"),
978
979
                     SM(r"\s*Effective potential energy\s*:\s*(?P<x_exciting_effective_potential_energy__hartree>[-0-9.]+)"),
                     SM(r"\s*Coulomb potential energy\s*:\s*(?P<x_exciting_coulomb_potential_energy__hartree>[-0-9.]+)"),
980
                     SM(r"\s*xc potential energy\s*:\s*(?P<energy_XC_potential__hartree>[-0-9.]+)"),
981
982
983
984
985
986
987
988
989
990
                     SM(r"\s*Hartree energy\s*:\s*(?P<x_exciting_hartree_energy__hartree>[-0-9.]+)"),
                     SM(r"\s*Electron-nuclear energy\s*:\s*(?P<x_exciting_electron_nuclear_energy__hartree>[-0-9.]+)"),
                     SM(r"\s*Nuclear-nuclear energy\s*:\s*(?P<x_exciting_nuclear_nuclear_energy__hartree>[-0-9.]+)"),
                     SM(r"\s*Madelung energy\s*:\s*(?P<x_exciting_madelung_energy__hartree>[-0-9.]+)"),
                     SM(r"\s*Core-electron kinetic energy\s*:\s*(?P<x_exciting_core_electron_kinetic_energy__hartree>[-0-9.]+)"),
                     SM(r"\s*DOS at Fermi energy \(states\/Ha\/cell\)\s*:\s*(?P<x_exciting_dos_fermi__hartree_1>[-0-9.]+)"),
                     SM(r"\s*core leakage\s*:\s*(?P<x_exciting_core_leakage>[-0-9.]+)"),
                     SM(r"\s*interstitial\s*:\s*(?P<x_exciting_interstitial_charge>[-0-9.]+)"),
                     SM(r"\s*total charge in muffin-tins\s*:\s*(?P<x_exciting_total_MT_charge>[-0-9.]+)"),
                     SM(r"\s*Estimated fundamental gap\s*:\s*(?P<x_exciting_gap__hartree>[-0-9.]+)")
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
                   ]) #,
#                SM(name="final_forces",
##                  startReStr = r"\| Writing atomic positions and forces\s*\-",
#                  startReStr = r"\s*Total atomic forces including IBS \(cartesian\) \s*:",
#                  endReStr = r"\|\s*Groundstate module stopped\s*\*",
##                  endReStr = r"\s* Atomic force components including IBS \(cartesian\)\s*:",
#                  floating = True,
#                   subMatchers = [
##                     SM(name="total_forces",
##                     startReStr = r"\s*Total atomic forces including IBS \(cartesian\)\s*:",
#                       SM(r"\s*atom\s*[0-9]+\s*[A-Za-z]+\s*\:\s*(?P<x_exciting_atom_forces_x>[-0-9.]+)\s*(?P<x_exciting_atom_forces_y>[-0-9.]+)\s*(?P<x_exciting_atom_forces_z>[-0-9.]+)",
#                          repeats = True )    
######                     subMatchers = [
######                     SM(r"\s*atom\s*(?P<x_exciting_store_total_forces>[0-9]+\s*[A-Za-z]+\s*\:+\s*[-\d\.]+\s*[-\d\.]+\s*[-\d\.]+)",
######                          repeats = True)
######                   ] )
##)
##                     print ("number atoms=", x_exciting_number_of_atoms)
##                     SM(name="force_components",
##                     startReStr = r"\s*Atomic force components including IBS \(cartesian\)\s*:",
##                     forwardMatch = True,
##                     subMatchers = [
##                     SM(r"\s*atom\s*(?P<x_exciting_store_total_forces>[0-9]+\s*[A-Za-z]+\s*\:+\s*[-\d\.]+\s*[-\d\.]+\s*[-\d\.]+\s*[A-Za-z]+\s*[A-Za-z]+)", weak = True),
##                     SM(r"\s*(?P<x_exciting_store_total_forces>\s*\:+\s*[-\d\.]+\s*[-\d\.]+\s*[-\d\.]+\s*[A-Za-z]+\s*[A-Za-z]+)"),
##                     SM(r"\s*(?P<x_exciting_store_total_forces>\s*\:+\s*[-\d\.]+\s*[-\d\.]+\s*[-\d\.]+\s*[A-Za-z]+\s*[A-Za-z]+)")
##                     SM(r"\s*(?P<x_exciting_store_total_forces>\s*\:+\s*[-\d\.]+\s*[-\d\.]+\s*[-\d\.]+\s*[A-Za-z]+\s*[A-Za-z]+)"),
##                   ] 
##                    )
#                   ]),
#                 SM(name="force_components",
1021
#                  startReStr = r"\s* Atomic force components including IBS \(cartesian\)\s*:",
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
#                  endReStr = r"\|\s* Groundstate module stopped\s* \*",
#                  subMatchers = [
##                  startReStr = r"\s* Atomic force components including IBS \(cartesian\)\s*:",
#                   SM(r"\s*atom\s*[0-9]+\s*[A-Za-z]+\s*\:\s*(?P<x_exciting_atom_HF_forces_x>[-0-9.]+)\s*(?P<x_exciting_atom_HF_forces_y>[-0-9.]+)\s*(?P<x_exciting_atom_HF_forces_z>[-0-9.]+)\s*HF force",
#                     repeats = True,
#                     floating = True),
#                   SM(r"\s*\:\s*(?P<x_exciting_atom_core_forces_x>[-0-9.]+)\s*(?P<x_exciting_atom_core_forces_y>[-0-9.]+)\s*(?P<x_exciting_atom_core_forces_z>[-0-9.]+)\s*core correction",
#                     repeats = True,
#                     floating = True),
#                   SM(r"\s*\:\s*(?P<x_exciting_atom_IBS_forces_x>[-0-9.]+)\s*(?P<x_exciting_atom_IBS_forces_y>[-0-9.]+)\s*(?P<x_exciting_atom_IBS_forces_z>[-0-9.]+)\s*IBS correction",
#                     repeats = True,
#                     floating = True),
##                   SM(r"(?P<x_exciting_store_total_forces>.*)",
##                          repeats = True, 
#                ] )
1037
               ]
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
            ),
            SM(name = "geometry optimization",
              startReStr = r"\|\s*Structure-optimization module started*\s*\*",
              sections = ["section_sampling_method","x_exciting_section_geometry_optimization"],
#              fixedStartValues={'sampling_method': 'geometry_optimization'},
#              repeats = True,
              subMatchers = [
                   SM(name = "optimization steps",
                   startReStr = r"\|\s*Optimization step\s*(?P<x_exciting_geometry_optimization_step>[-0-9]+)\s*\(method = (?P<x_exciting_geometry_optimization_method>[A-Za-z]+)\)\s*\-",
                   sections = ["section_single_configuration_calculation"],
#                   SM(r"\s*Output level for this task is set to normal\s*"),
#                   SM(r"\|\s*Optimization step (?P<x_exciting_geometry_optimization_step>[-0-9]+)\: Initialize optimization\s*\-"),
                   repeats = True,
                   subMatchers = [
                   SM(r"\s*Maximum force magnitude\s*\(target\)\s*:\s*(?P<x_exciting_maximum_force_magnitude__hartree_bohr_1>[0-9]+\.[0-9]*([E]?[-]?[0-9]+))\s*\(\s*(?P<x_exciting_geometry_optimization_threshold_force__hartree_bohr_1>[0-9]\.[0-9]*([E]?[-]?[0-9]+))\)"),
                   SM(r"\s*Total energy at this optimization step\s*:\s*(?P<energy_total__hartree>[-0-9.]+)"),
                   SM(startReStr = r"\s*Atomic positions at this step \s*\((?P<x_exciting_atom_position_format>[-a-zA-Z]+)\)\s*:\s*",
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
1055
1056
#                   endReStr = r"\s*Total atomic forces including IBS \(cartesian\) \:",
#                   weak = True,
1057
1058
1059
1060
                   sections = ["section_system","x_exciting_section_atoms_group"],
#           endReStr = r"\s*magnetic fields\s*",
           subMatchers = [
                    SM(r"\s*atom\s*(?P<x_exciting_atom_number>[+0-9]+)\s*(?P<x_exciting_geometry_atom_labels>[A-Za-z]+)\s*\:\s*(?P<x_exciting_geometry_atom_positions_x>[-+0-9.]+)\s*(?P<x_exciting_geometry_atom_positions_y>[-+0-9.]+)\s*(?P<x_exciting_geometry_atom_positions_z>[-+0-9.]+)", repeats = True)
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
1061
1062
1063
1064
1065
1066
1067
         ]),
                   SM(startReStr = r"\s*Total atomic forces including IBS \(cartesian\) \:",
                    endReStr = r"\s*Time spent in this optimization step\s*\:\s*(?P<x_exciting_geometry_dummy>[+0-9.]+)\s*seconds",
                    subMatchers = [
                    SM(r"\s*atom\s*[+0-9]+\s*[A-Za-z]+\s*\:\s*(?P<x_exciting_geometry_atom_forces_x__hartree_bohr_1>[-+0-9.]+)\s*(?P<x_exciting_geometry_atom_forces_y__hartree_bohr_1>[-+0-9.]+)\s*(?P<x_exciting_geometry_atom_forces_z__hartree_bohr_1>[-+0-9.]+)", repeats = True)
         ])
         ])
1068
1069
           ]
           )
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
          ])
    ])




parserInfo = {
  "name": "exciting_parser",
  "version": "1.0"
}

metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),"../../../../nomad-meta-info/meta_info/nomad_meta_info/exciting.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath = metaInfoPath, dependencyLoader = None, extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
1083

1084
cachingLevelForMetaName = {
1085
1086
1087
                            "x_exciting_geometry_lattice_vector_x":CachingLevel.Cache,
                            "x_exciting_geometry_lattice_vector_y":CachingLevel.Cache,
                            "x_exciting_geometry_lattice_vector_z":CachingLevel.Cache,
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
1088
1089
1090
1091
                            "x_exciting_section_lattice_vectors": CachingLevel.Ignore,
                            "x_exciting_geometry_reciprocal_lattice_vector_x":CachingLevel.Cache,
                            "x_exciting_geometry_reciprocal_lattice_vector_y":CachingLevel.Cache,
                            "x_exciting_geometry_reciprocal_lattice_vector_z":CachingLevel.Cache,
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
                            "x_exciting_section_reciprocal_lattice_vectors": CachingLevel.Ignore,
                            "x_exciting_atom_forces_x":CachingLevel.Cache,
                            "x_exciting_atom_forces_y":CachingLevel.Cache,
                            "x_exciting_atom_forces_z":CachingLevel.Cache,
                            "x_exciting_atom_HF_forces_x":CachingLevel.Cache,
                            "x_exciting_atom_HF_forces_y":CachingLevel.Cache,
                            "x_exciting_atom_HF_forces_z":CachingLevel.Cache,
                            "x_exciting_atom_core_forces_x":CachingLevel.Cache,
                            "x_exciting_atom_core_forces_y":CachingLevel.Cache,
                            "x_exciting_atom_core_forces_z":CachingLevel.Cache,
                            "x_exciting_atom_IBS_forces_x":CachingLevel.Cache,
                            "x_exciting_atom_IBS_forces_y":CachingLevel.Cache,
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
1104
1105
1106
1107
                            "x_exciting_atom_IBS_forces_z":CachingLevel.Cache,
                            "x_exciting_geometry_atom_forces_x":CachingLevel.Cache,
                            "x_exciting_geometry_atom_forces_y":CachingLevel.Cache,
                            "x_exciting_geometry_atom_forces_z":CachingLevel.Cache
1108
                          }
1109
if __name__ == "__main__":
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
1110
    mainFunction(mainFileDescription, metaInfoEnv, parserInfo, cachingLevelForMetaName = cachingLevelForMetaName, superContext=ExcitingParserContext())