From 4ffff3771a4c22fd391e0e1a3bfb758bbd555591 Mon Sep 17 00:00:00 2001 From: Jerome Jackson Date: Thu, 18 Jul 2024 14:22:31 +0100 Subject: [PATCH] add testcode parser for new test --- test-suite/tools/parsers/parse_rmn.py | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test-suite/tools/parsers/parse_rmn.py diff --git a/test-suite/tools/parsers/parse_rmn.py b/test-suite/tools/parsers/parse_rmn.py new file mode 100644 index 00000000..729c8f61 --- /dev/null +++ b/test-suite/tools/parsers/parse_rmn.py @@ -0,0 +1,47 @@ +""" +Parser function parse() to parse the seedname_r.dat output file of Wannier90 ( matrix elements). +""" +from __future__ import print_function, unicode_literals +import inspect +import re +from collections import defaultdict + +from . import show_output + +def parse(fname): + """ + Open the file, parses it and return the values + + For now, I just check that the size of the file is correct, but + I don't check the actual content + """ + retdict = defaultdict(list) + + if show_output: + print("[{}.{}] Parsing file '{}'".format( + __name__, inspect.currentframe().f_code.co_name, fname)) + + with open(fname) as f: + lines = f.readlines() + + # skip the first line, which contains only the date + retdict['num_wann'] = [int(_) for _ in lines[1].split()] + retdict['nrpts'] = [int(_) for _ in lines[2].split()] + retdict['irvec_a'] = [float(line.split()[0]) for line in lines[3:]] + retdict['irvec_b'] = [float(line.split()[1]) for line in lines[3:]] + retdict['irvec_c'] = [float(line.split()[2]) for line in lines[3:]] + retdict['index_i'] = [float(line.split()[3]) for line in lines[3:]] + retdict['index_j'] = [float(line.split()[4]) for line in lines[3:]] + retdict['real_x'] = [float(line.split()[5]) for line in lines[3:]] + retdict['imag_x'] = [float(line.split()[6]) for line in lines[3:]] + retdict['real_y'] = [float(line.split()[7]) for line in lines[3:]] + retdict['imag_y'] = [float(line.split()[8]) for line in lines[3:]] + retdict['real_z'] = [float(line.split()[9]) for line in lines[3:]] + retdict['imag_z'] = [float(line.split()[10]) for line in lines[3:]] + + retdict = dict(retdict) + if show_output: + for k in sorted(retdict): + print(" {}: {}".format(k, retdict[k])) + print("-"*72) + return retdict