Skip to content

Commit

Permalink
add testcode parser for new test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Jackson authored and JeromeCCP9 committed Jan 14, 2025
1 parent b43628d commit 4ffff37
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test-suite/tools/parsers/parse_rmn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
Parser function parse() to parse the seedname_r.dat output file of Wannier90 (<i|r|j> 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

0 comments on commit 4ffff37

Please sign in to comment.