From 11d2ead31dcbc496602b924e45eecfa7e6c7bcc3 Mon Sep 17 00:00:00 2001 From: Ask Hjorth Larsen <asklarsen@gmail.com> Date: Wed, 6 Jul 2016 18:39:07 +0200 Subject: [PATCH] I can't get it to use the simplematchers without them having opinions about how sections should open and close, so for now, let's just do some hacks. --- parser/parser-octopus/octopus_info_parser.py | 40 +++++++++++++++++-- .../parser-octopus/octopus_logfile_parser.py | 23 +++++++++-- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/parser/parser-octopus/octopus_info_parser.py b/parser/parser-octopus/octopus_info_parser.py index 08f69f2..c5d96d7 100644 --- a/parser/parser-octopus/octopus_info_parser.py +++ b/parser/parser-octopus/octopus_info_parser.py @@ -5,7 +5,7 @@ import setup_paths from nomadcore.simple_parser import SimpleMatcher as SM from nomadcore.local_meta_info import loadJsonFile, InfoKindEl from nomadcore.unit_conversion.unit_conversion \ - import register_userdefined_quantity + import register_userdefined_quantity, convert_unit import os, sys, json from util import OCT_ENERGY_UNIT_NAME, f_num, i_num, numpattern, integer,\ @@ -80,6 +80,40 @@ class OctopusParserContext(object): #logging.getLogger("nomadcore.parsing").info("closing section_scf_iteration bla gIndex %d %s", gIndex, section.simpleValues) #self.scfIterNr += 1 +#def parse_infofile(meta_info_env, pew, fname): +# parse_file_without_decorations(pew, meta_info_env, infoFileDescription, +# parserInfo, OctopusParserContext(), fname) + + def parse_infofile(meta_info_env, pew, fname): - parse_file_without_decorations(pew, meta_info_env, infoFileDescription, - parserInfo, OctopusParserContext(), fname) + with open(fname) as fd: + for line in fd: + if line.startswith('SCF converged'): + iterations = int(line.split()[-2]) + pew.addValue('x_octopus_info_scf_converged_iterations', + iterations) + break + for line in fd: # Jump down to energies: + if line.startswith('Energy ['): + octunit = line.strip().split()[-1].strip('[]:') + nomadunit = {'eV': 'eV', 'H': 'hartree'}[octunit] + break + + names = {'Total': 'energy_total', + 'Free': 'energy_free', + 'Ion-ion': 'x_octopus_info_energy_ion_ion', + 'Eigenvalues': 'energy_sum_eigenvalues', + 'Hartree': 'energy_electrostatic', + 'Exchange': 'energy_X', + 'Correlation': 'energy_C', + 'vanderWaals': 'energy_van_der_Waals', + '-TS': 'energy_correction_entropy', + 'Kinetic': 'electronic_kinetic_energy'} + + for line in fd: + tokens = line.split() + if len(tokens) < 3: + continue + if tokens[0] in names: + pew.addValue(names[tokens[0]], + convert_unit(float(tokens[2]), nomadunit)) diff --git a/parser/parser-octopus/octopus_logfile_parser.py b/parser/parser-octopus/octopus_logfile_parser.py index e02cd7e..b6ce3c3 100644 --- a/parser/parser-octopus/octopus_logfile_parser.py +++ b/parser/parser-octopus/octopus_logfile_parser.py @@ -15,7 +15,7 @@ logFileDescription = SM( weak=True, startReStr='', fixedStartValues={'program_name': 'octopus'}, - sections=['section_run'], + #sections=['section_run'], subFlags=SM.SubFlags.Sequenced, subMatchers=[ SM(r'Version\s*:\s*%s' % word('program_version')), @@ -29,6 +29,21 @@ class OctopusLogFileParserContext(object): def parse_logfile(meta_info_env, pew, fname): - parse_file_without_decorations(pew, meta_info_env, logFileDescription, - parserInfo, OctopusLogFileParserContext(), - fname) + # XXX this is just a hack until we decide to do more + maxlines = 100 + with open(fname) as fd: + for i in range(maxlines): + line = next(fd) + if line.startswith('Version'): + version = line.split()[-1] + pew.addValue('program_version', version) + elif line.startswith('Revision'): + revision = line.split()[-1] + pew.addValue('x_octopus_log_svn_revision', revision) + # XXX more info + + +#def parse_logfile(meta_info_env, pew, fname): +# parse_file_without_decorations(pew, meta_info_env, logFileDescription, +# parserInfo, OctopusLogFileParserContext(), +# fname) -- GitLab