From 7b2e2a3b6e8df33d1223579adc70f663b330902a Mon Sep 17 00:00:00 2001 From: Oleg Peil Date: Mon, 24 Aug 2015 19:10:29 +0200 Subject: [PATCH] Implemented 'read_header_and_data()' and 'read_data()' 'read_data()' is a generator interpreting a file as a sequence of floats. Lines starting with '#' are ignored. 'read_header_and_data()' reads the header string until a line "# END ...", initializes a generator 'read_data()', and returns them. --- .../converters/vasp/python/vasp_converter.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/python/converters/vasp/python/vasp_converter.py b/python/converters/vasp/python/vasp_converter.py index 3de09dc7..2450e671 100644 --- a/python/converters/vasp/python/vasp_converter.py +++ b/python/converters/vasp/python/vasp_converter.py @@ -25,6 +25,7 @@ import numpy from pytriqs.archive import * from converter_tools import * import os.path +import simplejson as json class VaspConverter(ConverterTools): """ @@ -64,11 +65,30 @@ class VaspConverter(ConverterTools): """ Generator for reading plain data. """ + for line in fh: + line_ = line.strip() + if line_[0] == '#' or line_ == '': + continue + + for val in map(float, line.split()): + yield val def read_header_and_data(self, filename): """ Opens a file and returns a JSON-header and the generator for the plain data. """ + fh = open(filename, 'rt') + header = "" + for line in fh: + if not "# END" in line: + header += line + else: + break + + f_gen = self.read_data(fh) + + return header, f_gen + def convert_dft_input(self): """ Reads the input files, and stores the data in the HDFfile