From 0512ad1edeed551de96caff831f1f79d5e3020d2 Mon Sep 17 00:00:00 2001 From: Jacob Wilkins <46597752+oerc0122@users.noreply.github.com> Date: Sun, 28 Jul 2024 23:15:54 +0100 Subject: [PATCH] Sort phonon parsing pylint to avoid other issues (#143) --- castep_outputs/parsers/phonon_file_parser.py | 35 ++++++++++---------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/castep_outputs/parsers/phonon_file_parser.py b/castep_outputs/parsers/phonon_file_parser.py index e746f41..45abe4d 100755 --- a/castep_outputs/parsers/phonon_file_parser.py +++ b/castep_outputs/parsers/phonon_file_parser.py @@ -2,19 +2,17 @@ Parse the following castep outputs: .phonon """ -import re from collections import defaultdict from typing import Any, Dict, TextIO -from ..utilities import castep_res as REs -from ..utilities.castep_res import get_block, labelled_floats -from ..utilities.utility import fix_data_types, log_factory, stack_dict +from ..utilities.castep_res import get_block +from ..utilities.utility import fix_data_types, log_factory from .parse_utilities import parse_regular_header def parse_phonon_file(phonon_file: TextIO) -> Dict[str, Any]: """ Parse castep .phonon file """ - + # pylint: disable=too-many-locals logger = log_factory(phonon_file) phonon_info = defaultdict(list) evals = [] @@ -25,43 +23,46 @@ def parse_phonon_file(phonon_file: TextIO) -> Dict[str, Any]: data = parse_regular_header(block) phonon_info.update(data) - phonon_info.pop("",None) - eigenvectors_endblock = (format(phonon_info["branches"], ">4")) + (format(phonon_info["ions"], ">4")) + phonon_info.pop("", None) + eigenvectors_endblock = (format(phonon_info["branches"], ">4") + + format(phonon_info["ions"], ">4")) elif block := get_block(line, phonon_file, "q-pt", "Phonon Eigenvectors", out_fmt=list): logger("Found eigenvalue block") for line in block: if "q-pt" in line: - _, _, posx,posy,posz, *weight = line.split() - qdata = {'pos':[posx,posy,posz], 'weight':weight} + _, _, posx, posy, posz, *weight = line.split() + qdata = {'pos': [posx, posy, posz], 'weight': weight} fix_data_types(qdata, {'pos': float, 'weight': float}) phonon_info["qpt_pos"].append(qdata['pos']) elif "Eigenvectors" not in line: _, e_val, *_ = line.split() - qdata = {'eval':e_val} + qdata = {'eval': e_val} fix_data_types(qdata, {'eval': float}) evals.append(qdata['eval']) if len(evals) == phonon_info["branches"]: phonon_info["evals"].append(evals) evals = [] - + elif block := get_block(line, phonon_file, "Mode Ion", eigenvectors_endblock, out_fmt=list): - + logger("Found eigenvector block") for line in block: if "Mode" not in line: _, _, *vectors = line.split() - - qdata = {'evec':vectors} + + qdata = {'evec': vectors} fix_data_types(qdata, {'evec': float}) - qdata['evec'] = [complex(qdata['evec'][i],qdata['evec'][i+1])for i in range(0,len(vectors),2)] + qdata['evec'] = [complex(qdata['evec'][i], + qdata['evec'][i+1]) + for i in range(0, len(vectors), 2)] evecs.append(qdata['evec']) if len(evecs) == phonon_info["branches"]*phonon_info["ions"]: phonon_info["evecs"].append(evecs) evecs = [] - - return phonon_info \ No newline at end of file + + return phonon_info