main.py 26.1 KB
Newer Older
1
2
3
4
5
6
# Copyright 2016-2018 Ask Hjorth Larsen, Fawzi Mohamed, Ankit Kariryaa
# 
#   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
# 
Ask Hjorth Larsen's avatar
Ask Hjorth Larsen committed
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.

Ask Hjorth Larsen's avatar
Ask Hjorth Larsen committed
15
16
17
#
# Main author and maintainer: Ask Hjorth Larsen <asklarsen@gmail.com>

Ask Hjorth Larsen's avatar
Ask Hjorth Larsen committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from __future__ import print_function
import os
import sys
import setup_paths
import re

import numpy as np
from ase import Atoms
from ase.spacegroup import crystal
#from ase.data import chemical_symbols

from nomadcore.simple_parser import mainFunction, SimpleMatcher as SM
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.unit_conversion.unit_conversion \
    import register_userdefined_quantity, convert_unit

34
35
from functionals import functionals

Ask Hjorth Larsen's avatar
Ask Hjorth Larsen committed
36
37
38
39
40
41
42
43
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),"../../../../nomad-meta-info/meta_info/nomad_meta_info/molcas.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath=metaInfoPath,
                                     dependencyLoader=None,
                                     extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS,
                                     uri=None)

parser_info = {'name': 'molcas-parser', 'version': '1.0'}

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# OK
#    "program_basis_set_type",
#    "program_name",
#    "program_version",
#    "configuration_periodic_dimensions"
#    "simulation_cell",  # molcas never has a cell



#    "atom_labels",
#    "atom_positions",
#    "energy_total",

#    'section_system',
#    'section_method',
#    'section_frame_sequence',
#    'section_sampling_method',
#    'single_configuration_to_calculation_method_ref',
#    'single_configuration_calculation_to_system_ref',
#    'atom_forces_raw',
#    'frame_sequence_local_frames_ref',
#    'frame_sequence_to_sampling_ref',

#    'XC_functional_name',
#    'smearing_kind',
#    'smearing_width'
#    'eigenvalues_kpoints',
#    'eigenvalues_values',
#    'eigenvalues_occupation',
#    'band_k_points',
#    'band_energies',
#    'band_segm_start_end',
#    'band_segm_labels',
#    'dos_energies',
#    'dos_values',
#    'section_XC_functionals',



Ask Hjorth Larsen's avatar
Ask Hjorth Larsen committed
83
class MolcasContext(object):
84
85
    def __init__(self):
        self.data = {}
86
        self.last_line = None
87
88
        self.current_module_name = None
        self.section_refs = {}
89
90
        self.basis_info = []
        self.buffered_lines = {}
91
92
93
94
95
96

    def onOpen_section_method(self, backend, gindex, section):
        self.section_refs['method'] = gindex

    def onOpen_section_system(self, backend, gindex, section):
        self.section_refs['system'] = gindex
97

Ask Hjorth Larsen's avatar
Ask Hjorth Larsen committed
98
99
100
    def startedParsing(self, fname, parser):
        pass

101
102
103
104
105
106
107
108
109
    def adhoc_store_line(self, parser):
        self.last_line = parser.fIn.readline()

    def adhoc_pushback_last(self, parser):
        assert self.last_line is not None
        parser.fIn.pushbackLine(self.last_line)
        self.last_line = None

    def onClose_section_single_configuration_calculation(self, backend, gindex, section):
110
111
112
113
        backend.addValue('single_configuration_to_calculation_method_ref',
                         self.section_refs['method'])
        backend.addValue('single_configuration_calculation_to_system_ref',
                         self.section_refs['system'])
114

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
        #print(self.buffered_lines.keys())

        def lines2arrays(name):
            elines = self.buffered_lines.pop('energy_%s' % name)
            olines = self.buffered_lines.pop('occupations_%s' % name)
            energies = []
            occupations = []
            assert len(elines) == len(olines)
            for l1, l2 in zip(elines, olines):
                energies += l1.split()[1:]  # Energy <numbers>
                occupations += l2.split()[2:]  # Occ. No.  <numbers>
            assert len(energies) == len(occupations)
            energies = np.array(energies).astype(float)
            energies = convert_unit(energies, 'hartree')
            occupations = np.array(occupations).astype(float)

            # Sort by energy:
            args = np.argsort(energies)
            energies = energies[args]
            occupations = occupations[args]
            return energies.reshape(1, 1, -1), occupations.reshape(1, 1, -1)

        energies = None

        try:
            energies, occupations = lines2arrays('nospin')
            nspins = 1
            nstates = energies.shape[-1]
        except KeyError:
            pass

        try:
            ealpha, oalpha = lines2arrays('alpha')
            ebeta, obeta = lines2arrays('beta')
        except KeyError:
            pass
        else:
            # The spinup and spindown (alpha, beta)
            # arrays can have different lengths
            # so we must allocate arrays that are big enough
            # and fill out with zeros or something else
            assert energies is None
            nspins = 2
            nstates = max(ealpha.shape[-1], ebeta.shape[-1])
            energies = np.empty((nspins, 1, nstates))
            # We will only fill out the values that we have.
            # The rest will be nan:
            energies.fill(np.nan)
            occupations = np.zeros((nspins, 1, nstates))
            energies[0, :, :ealpha.shape[2]] = ealpha[0]
            occupations[0, :, :ealpha.shape[2]] = oalpha[0]
            energies[1, 0, :ebeta.shape[2]] = ebeta[0]
            occupations[1, 0, :ebeta.shape[2]] = obeta[0]

        if energies is not None:
            for arr in [energies, occupations]:
                assert arr.shape == (nspins, 1, nstates)
            g = backend.openSection('section_eigenvalues')
            backend.addArrayValues('eigenvalues_values', energies)
            backend.addArrayValues('eigenvalues_occupation', occupations)
            backend.closeSection('section_eigenvalues', g)


178
    def onClose_section_method(self, backend, gindex, section):
179
180
181
182
183
184
185
186
187
188
189
190
191
192

        for line in self.basis_info:
            m = re.match('\s*Basis set label:(.*?)\.(.*?)\s*$', line)
            atomlabel, name = m.group(1, 2)
            # The terrible syntax in molcas has a lot of dots everywhere.
            # Replace sequences of dots with single dots to make things
            # reasonable.
            name = re.sub(r'\.+', '.', name).strip('.')
            g = backend.openSection('x_molcas_section_basis')
            backend.addValue('x_molcas_basis_atom_label', atomlabel)
            backend.addValue('x_molcas_basis_name', name)
            backend.closeSection('x_molcas_section_basis', g)
        del self.basis_info[:]

193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
        #print('SECTION', section)
        #methods = section['x_molcas_method']
        xc = []

        methods = section['x_molcas_method_name']
        assert len(methods) == 1, methods
        method = methods[0]

        uhf = method.startswith('UHF ')
        if uhf:
            method = method[4:].strip()
        backend.addValue('x_molcas_uhf', uhf)

        if method == 'SCF':
            # XXX distinguish somehow between these two?
            esm = 'DFT'
            xc = ['HF_X']
210
        elif method in ['RASSCF', 'RAS-CI', 'CASPT2', 'CCSDT']:
211
            esm = method
212
213
214
215
216
217
        elif method in ['CASVB', 'MRCI']:
            esm = 'MRCISD'
        elif method == 'MCPF':
            esm = method  ## Not defined by nomad
        elif method == 'MBPT2':
            esm = 'MP2'
218
219
220
221
222
223
224
        elif method in functionals:
            esm = 'DFT'
            xc = functionals[method]
            assert xc is not None, 'no xc: %s' % method
        else:
            raise ValueError('method: %s' % method)

225
        backend.addValue('electronic_structure_method', esm)
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
        for xcfunc in xc:
            g = backend.openSection('section_XC_functionals')
            backend.addValue('XC_functional_name', xcfunc)
            backend.closeSection('section_XC_functionals', g)


        if 0:
            if methods is not None:
                assert len(methods) == 1
                method = methods[0]
                scfnames = section['x_molcas_method_name']
                assert len(scfnames) == 1, scfnames
                scfname = scfnames[0]
                if scfname == 'SCF':
                    backend.addValue('electronic_structure_method', 'DFT')
                    g = backend.openSection('section_XC_functionals')
                    backend.addValue('XC_functional_name', 'HF_X')
                    backend.closeSection('section_XC_functionals', g)

        #print(self.current_module_name)
        #scftype = section['x_molcas_method_name']
247
248
        #if scftype is not None:
        #    print('SCF', scftype)
249
250
251

    def onClose_section_system(self, backend, gindex, section):
        matrix = self.data.pop('coordinates')
252
253
254
255
        assert matrix.shape[1] == 4
        atom_labels = matrix[:, 0]
        coords = matrix[:, 1:4].astype(float)
        assert coords.shape[1] == 3
256
257
258
259
260
261
        coords = convert_unit(coords, 'bohr')

        backend.addArrayValues('atom_labels', atom_labels)
        backend.addArrayValues('atom_positions', coords)
        backend.addArrayValues('configuration_periodic_dimensions', np.zeros(3, bool))

262
263
264
265
266
267
268
269
270
271
272
273
    def adhoc_add_basis_set(self, parser):
        line = parser.fIn.readline()
        self.basis_info.append(line)

    def adhoc_add_energies(self, parser):
        line = parser.fIn.readline()
        self.energies.append(line)

    def adhoc_add_occupations(self, parser):
        line = parser.fIn.readline()
        self.occupations.append(line)

274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
    # multi_sm copied from Siesta/GULP
    def multi_sm(self, name, startpattern, linepattern, endmatcher=None,
                 conflict='fail',  # 'fail', 'keep', 'overwrite'
                 *args, **kwargs):

        pat = re.compile(linepattern)  # XXX how to get compiled pattern?
        ngroups = pat.groups

        allgroups = []
        def addline(parser):
            line = parser.fIn.readline()
            match = pat.match(line)
            assert match is not None
            thislinegroups = match.groups()
            assert len(thislinegroups) == ngroups
            allgroups.append(thislinegroups)

        def savearray(parser):
            arr = np.array(allgroups, dtype=object)
            del allgroups[:]
            if name in self.data:
                if conflict == 'fail':
                    raise ValueError('grrr %s %s' % (name, self.data[name]))
                elif conflict == 'keep':
                    return  # Do not save array
                elif conflict == 'overwrite':
                    pass
                else:
                    raise ValueError('Unknown keyword %s' % conflict)
            #if arr.size > 0:
            if arr.size == 0:
                arr.shape = (0, ngroups)
            self.data[name] = arr

        if endmatcher is None:
            endmatcher = r'.*'

        if hasattr(endmatcher, 'swapcase'):
            endmatcher = SM(endmatcher,
                            endReStr='',
                            forwardMatch=True,
                            name='%s-end' % name,
                            adHoc=savearray)

        sm = SM(startpattern,
                name=name,
                subMatchers=[
                    SM(linepattern,
                       name='%s-line' % name,
                       repeats=True,
                       forwardMatch=True,
                       required=True,
                       adHoc=addline),
                    endmatcher,
                ], **kwargs)
        return sm

Ask Hjorth Larsen's avatar
Ask Hjorth Larsen committed
331
332
context = MolcasContext()

333
334
335
336
337
338
#def get_inputfile_echo_sm():
#    m = SM(r'\+\+\s*----+\s*Input file\s*---+',
#           endReStr='--\s*-------+',
#           sections=['section_method'],
#           name='inputfile')
#    return m
339
340
341
342
343
344
345


def get_system_sm():
    m = SM(r'\s*Molecular structure info:',
           name='structure',
           sections=['section_system'],
           subMatchers=[
346
               SM(r'\s*--------+', name='bar'),
347
348
               SM(r'.*?Cartesian Coordinates / Bohr, Angstrom\s*\*+',
                  name='coords',
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
                  subMatchers=[
                      context.multi_sm('coordinates',
                                       r'\s*Center\s*Label\s*x\s*y\s*z\s*x\s*y\s*z',
                                       r'\s*\d+\s*(\S+)\s*(\S+)\s*(\S+)\s*(\S+)')
                  ])
           ])
    return m


def get_finalresults_sm():  # Other modes than SCF/KS-DFT?
    m = SM(r'\s*\*\s*SCF/KS-DFT Program, Final results',
           endReStr='\s*Molecular Properties',  # No clue when to really stop matching this
           sections=['section_single_configuration_calculation'],
           name='results',
           subMatchers=[
364
               SM(r'\s*Total SCF energy\s*(?P<energy_total__hartree>\S+)', name='etot')
365
366
367
           ])
    return m

368
369
370
371
372
373
374
375
376
377
def get_header_sm():
    m = SM(r'[\s^]*M O L C A S',
           endReStr=r'\s*For the author list and the recommended.*',
           name='header',
           subMatchers=[
               SM(r'[\s^]*version\s*(?P<program_version>.*?)\s*$',
                  name='version')
           ])
    return m

378
# Does not include 'auto'
379
380
381
molcas_modules = ('alaska|caspt2|casvb|ccsdt|cpf|expbas|ffpt|gateway|'
                  'genano|grid_it|guessorb|guga|last_energy|loprop|mbpt2|'
                  'mckinley|mclr|motra|mrci|numerical_gradient|rasscf|'
382
                  'rassi|scf|seward|slapaf|vibrot').split('|')
383

384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
ignore_modules = {'alaska',  # OK
                  'numerical_gradient',  # OK
                  'rassi',  # OK
                  'motra',
                  'guga',
                  'ffpt',
                  'genano',
                  'grid_it',
                  'loprop',
                  'guessorb',
                  'expbas',
                  'vibrot',
                  'mckinley'
                  #'last_energy',
}

400
401
402
def get_anymodule_sms():
    sms = []
    for modulename in molcas_modules:
403
404
405
406
407
408
409
410
411
412
413
        adhoc = None
        if modulename not in ignore_modules:
            class AdHoc:
                def __init__(self, name):
                    self.name = name
                def __call__(self, parser):
                    raise ValueError('module: %s' % self.name)
            adhoc = AdHoc(modulename)
        sms.append(SM(r'--- Start Module:\s*%s' % modulename,
                      adHoc=adhoc,
                      name=modulename))
414
415
    return sms

416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
#def module_sm(name, *args, **kwargs):
#    m = SM(r'--- Start Module:\s*(%s)' % name, *args, name=name, **kwargs)
#    return m

# mw = "module-wrapper" for SM
# The idea is to guarantee that matchers modules that do not always write a proper header (e.g. SLAPAF)
# are invoked when the module starts, but that the matcher's sections are only opened if recognizable
# output is written (sometimes they write nothing).
#
# Typically, pass a matcher which opens some sections but will only match actual output of the module
# This wrapper will call the wrapped matcher when the module is started, but the wrapped matcher
# will only match if the output is actually there, and also will only open its sections in that case.
def mw(modname, *args, **kwargs):
    m = SM(r'--- Start Module:\s*%s' % modname,
           name=modname,
           subMatchers=[
               SM(*args, **kwargs)
           ])
    return m

436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
def mod_pattern(lower, upper=None):
    if upper is None:
        upper = lower.upper()
    return (r'---\s*Start Module:\s*{0}|'
            r'\s*MOLCAS executing module\s*{1}'.format(lower, upper))

# Define these separately or not?
def startmod_pattern(name):
    return r'---\s*Start Module:\s*{}'.format(name)
def execmod_pattern(name):
    return r'\s*MOLCAS executing module\s*{}'.format(name)

def gateway_seward():
    m = SM(mod_pattern(r'(:?gateway|seward)'),
           #weak=True,
           name='gate/seward',
           #r'\s*MOLCAS executing module (GATEWAY|SEWARD)', name='seward',
           subMatchers=[
454
455
456
457
458
               SM(r'\s*Basis set label:(.*?)\s*$',
                  forwardMatch=True,
                  repeats=True,
                  adHoc=context.adhoc_add_basis_set,
                  name='basis'),
459
460
461
462
               get_system_sm()
           ])
    return m

463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
def eigenvalue_line_matcher(pattern, spinname):

    class AdHocLineAccumulator:
        def __init__(self, var):
            self.var = var

        def __call__(self, parser):
            line = parser.fIn.readline()
            context.buffered_lines.setdefault(self.var, []).append(line)
            #print(context.buffered_lines)
            #sdfkjsdfkj

    m = SM(pattern, name=spinname,
           subMatchers=[
               SM(r'\s*Orbital',
                  repeats=True,
                  subMatchers=[
                      SM(r'\s*Energy\s*(.*)', name='energies', adHoc=AdHocLineAccumulator('energy_%s' % spinname),
                         forwardMatch=True),
                      SM(r'\s*Occ\. No\.\s*(.*)', name='occ', adHoc=AdHocLineAccumulator('occupations_%s' % spinname),
                         forwardMatch=True)
                  ])
           ])
    return m

488
489
490
491
492
493
494
495
496
497
498
def scf_rasscf():
    m = SM(mod_pattern(r'(:?ras)?scf'),
           name='(ras)scf', #r'(?:ras)?scf', r'\s*MOLCAS executing module (?:SCF|RASSCF)', name='scf',
           #sections=['section_method', 'section_single_configuration_calculation'],
           subMatchers=[  # XXX opens method section even if there is no outpout
               SM(r'\s*(?P<x_molcas_method_name>.*?)\s*iterations: Energy and convergence statistics',
                  sections=['section_method'],
                  name='scfiter'),
               SM(r'\s*CI only, no orbital optimization',
                  sections=['section_method'],
                  fixedStartValues={'x_molcas_method_name': 'RAS-CI'}),
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
               SM(r'\s*\*\s*Final Results\s*\*',
                  name='finalresults',
                  sections=['section_single_configuration_calculation'],
                  subMatchers=[
                      SM(r'\s*Total \S+ energy\s*(?P<energy_total__hartree>\S+)', name='E-tot'),
                      SM(r'\s*RASSCF root number\s*\d+\s*Total energy\s*=\s*(?P<energy_total__hartree>\S+)', name='E-ras'),
                      SM(r'\s*Molecular orbitals:',
                         name='mol-orb',
                         endReStr=r'\s*Molecular Charges:',
                         subMatchers=[
                             eigenvalue_line_matcher(r'\s*Title:\s*.*?\s*orbitals\s*$', 'nospin'),
                             eigenvalue_line_matcher(r'\s*Title:\s*.*?\s*orbitals\s*\(alpha\)', 'alpha'),
                             eigenvalue_line_matcher(r'\s*Title:\s*.*?\s*orbitals\s*\(beta\)', 'beta')
                         ])
                  ])
514
515
516
517
518
519
520
521
522
523
524
525
526
527
           ])
    return m

def caspt2():
    m = SM(mod_pattern(r'caspt2'),
           #caspt2', r'\s*MOLCAS executing module CASPT2',
           name='caspt2',  # XXX opens section even if there is no output
           sections=['section_method', 'section_single_configuration_calculation'],
           fixedStartValues={'x_molcas_method_name': 'CASPT2'},
           subMatchers=[
               SM(r'\s*Total energy:\s*(?P<energy_total__hartree>\S+)', name='E-caspt2')
           ])
    return m

528
529
def molcas_main_loop_sm():
    m = SM(r'--- Start Module:\s*(?:%s)' % '|'.join(molcas_modules),
530
531
           endReStr='--- Stop Module:',
           repeats=True,
532
           forwardMatch=True,
533
534
           name='module',
           subMatchers=[
535
536
537
538
539
540
               gateway_seward(),
               scf_rasscf(),
               caspt2(),
               SM(r'%s|%s' % (mod_pattern(r'slapaf'),
                              # Sometimes the damn thing starts without a proper header!!  ARGH!
                              r's*Specification of the internal coordinates according to the user-defined'),
541
                  name='slapaf',
542
543
544
545
546
547
548
549
                  # The slapaf module writes forces, but only for a symmetry-reduced set of atoms.
                  # Therefore they are not useful to parse.  We could parse the set of symmetries probably
                  # and somehow make it possible to get the full set of Cartesian forces,
                  # but the operation would be very complicated.
                  #
                  # Let us consider parsing the reduced forces and
                  # symmetries the day that someone wants to implement
                  # this symmetry-unreduction (this will not happen).
550
551
552
553
554
555
556
557
                  subMatchers=[
                      SM(r'\*\s*Energy Statistics for Geometry Optimization',
                         name='opt-loop',
                         endReStr=r'\s*$',
                         sections=['section_single_configuration_calculation'],
                         subMatchers=[
                             SM(r'\s*\d+\s*\S+\s*', name='opt-iter', repeats=True, forwardMatch=True, adHoc=context.adhoc_store_line),
                             SM(r'\s*$', forwardMatch=True, adHoc=context.adhoc_pushback_last, name='pushback'),
558
559
560
561
562
563
                             # Molcas is supposed to have spaces between the numbers, but with grdNorm/Max,
                             # it sometimes writes 0.051834-0.037589 in one.  Thus we use -?[^\s-]+ to match such a number.
                             SM(r'\s*\d+\s*(?P<energy_total__hartree>\S+)\s*'
                                r'\S+\s*(?P<x_molcas_slapaf_grad_norm>-?[^\s-]+)\s*'
                                r'(?P<x_molcas_slapaf_grad_max>\S+)',
                                name='opt-iter', repeats=True),
564
565
566
567
568
569
570
571
572
573
                         ]),
                      SM(r'\s*\*\s*Nuclear coordinates for the next iteration / Bohr',
                         endReStr=r'\s*$',
                         name='newcoords',
                         sections=['section_system'],
                         subMatchers=[
                             context.multi_sm('coordinates',
                                              r'\s*ATOM\s*X\s*Y\s*Z',
                                              r'\s*(\S+)\s*(\S+)\s*(\S+)\s*(\S+)')
                             ])
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
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
633
634
635
636
637
638
639
640
                  ]),
               # last_energy just means it calls some other modules with annoyingly irregular output format
               SM(mod_pattern(r'last_energy'),
                  name='last',
                  subMatchers=[
                      gateway_seward(),
                      scf_rasscf(),
                      caspt2(),
                  ]),
               SM(mod_pattern('casvb'),
                  name='casvb',
                  sections=['section_method'],
                  fixedStartValues={'x_molcas_method_name': 'CASVB'},
                  subMatchers=[
                      SM('\s*CASSCF energy\s*:\s*(?P<energy_total__hartree>\S+)',
                         sections=['section_single_configuration_calculation'],
                         name='e-tot')
                  ]),
               SM(mod_pattern('mrci'),
                  name='mrci',
                  sections=['section_method'],
                  fixedStartValues={'x_molcas_method_name': 'MRCI'},
                  subMatchers=[
                      SM(r'\s*CI ENERGY:\s*(?P<energy_total__hartree>\S+)',
                         sections=['section_single_configuration_calculation'])
                  ]),
               SM(mod_pattern('cpf', 'CPFMCPF'),
                  name='cpf',
                  sections=['section_method'],
                  fixedStartValues={'x_molcas_method_name': 'MCPF'},
                  subMatchers=[
                      SM(r'\s*FINAL MCPF ENERGY\s*(?P<energy_total__hartree>\S+)',
                         sections=['section_single_configuration_calculation'])
                  ]),
               SM(mod_pattern('ccsdt', r'CCSD\(T\)'),
                  name='ccsdt',
                  sections=['section_method'],
                  fixedStartValues={'x_molcas_method_name': 'CCSDT'},
                  subMatchers=[
                      SM(r'\s*Total energy \(diff\)\s*:\s*(?P<energy_total__hartree>\S+)',
                         sections=['section_single_configuration_calculation'])
                  ]),
               SM(mod_pattern('mbpt2'),
                  name='mbpt2',
                  fixedStartValues={'x_molcas_method_name': 'MBPT2'},
                  sections=['section_method', 'section_single_configuration_calculation'],
                  subMatchers=[
                      SM(r'\s*Total energy\s*=\s*(?P<energy_total__hartree>\S+)\s*a\.u\.')
                  ]),
               SM(mod_pattern('mclr'),
                  name='mclr',
                  subMatchers=[
                      SM(r'\s*\*\s*Harmonic frequencies in cm-1\s*\*',
                         endReStr=r'\s*\*\s*THERMOCHEMISTRY',
                         sections=['section_single_configuration_calculation'],
                         subMatchers=[
                             SM(r'\s*Symmetry\s*(?P<x_molcas_frequency_symmetry>\S+)',
                                name='symm',
                                repeats=True,
                                sections=['x_molcas_section_frequency'],
                                subMatchers=[
                                    SM(r'\s*Freq\.\s*i(?P<x_molcas_imaginary_frequency_value__cm_1>\S+)', name='ifreq'),
                                    SM(r'\s*Freq\.\s*(?P<x_molcas_frequency_value>\S+)', name='freq'),
                                    SM(r'\s*Intensity:\s*(?P<x_molcas_frequency_intensity__km_mol_1>\S+)', name='intensity')
                                ])
                         ]),
                  ]),
641
642
643
           ] + get_anymodule_sms())
    return m

Ask Hjorth Larsen's avatar
Ask Hjorth Larsen committed
644
645
646
647
mainFileDescription = SM(
    name='root',
    weak=True,
    startReStr='',
648
649
    fixedStartValues={'program_name': 'Molcas',
                      'program_basis_set_type': 'gaussians'},
Ask Hjorth Larsen's avatar
Ask Hjorth Larsen committed
650
    sections=['section_run'],
651
    subMatchers=[
652
        get_header_sm(),
653
        #get_inputfile_echo_sm(),
654
        molcas_main_loop_sm(),
655
656
657
658
        SM(r'x^',  # force parser to parse the whole file
           name='impossible')
    ])

Ask Hjorth Larsen's avatar
Ask Hjorth Larsen committed
659
660
661
662
663
664
665
666
667
668
669

def main(**kwargs):
    mainFunction(mainFileDescription=mainFileDescription,
                 metaInfoEnv=metaInfoEnv,
                 parserInfo=parser_info,
                 cachingLevelForMetaName={},
                 superContext=context,
                 **kwargs)

if __name__ == '__main__':
    main()