From be05505b659dd623a460dfb38e5a3619f403eff1 Mon Sep 17 00:00:00 2001 From: fvmunoz Date: Tue, 24 Sep 2024 19:36:51 -0300 Subject: [PATCH] Bug fix in filter. With more than 10K kpoints the bands where not properly filtered --- pyprocar/utils/procarfilefilter.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pyprocar/utils/procarfilefilter.py b/pyprocar/utils/procarfilefilter.py index 39493a37..d4b7f95b 100644 --- a/pyprocar/utils/procarfilefilter.py +++ b/pyprocar/utils/procarfilefilter.py @@ -49,7 +49,7 @@ class ProcarFileFilter: """ - def __init__(self, infile=None, outfile=None, loglevel=logging.WARNING): + def __init__(self, infile=None, outfile=None, loglevel=logging.DEBUG): """Initialize the class. Params: `infile=None`, input fileName @@ -313,10 +313,14 @@ def FilterBands(self, Min, Max): line = fin.readline() # the third value needs to be changed, however better print it self.log.debug("The line contaning bands number is " + line) - line = line.split() - self.log.debug("The number of bands is: " + line[7]) - line[7] = str(Max - Min + 1) - line = " ".join(line) + + pattern = r"# of bands:\s*(\d+)" + replacement = "# of bands: " + str(Max - Min + 1) + line = re.sub(pattern, replacement, line) + + + self.log.debug("The new line with # of bands is: " + line) + fout.write(line + "\n") # now parsing the rest of the file