57
57
58
58
def _get_lines (filename ) -> list [str ]:
59
59
with zopen (filename , mode = "rt" , encoding = "utf-8" ) as file :
60
- return file .read ().split ( " \n " ) # type:ignore[return-value,arg-type]
60
+ return cast ( "list[str]" , file .read ().splitlines ())
61
61
62
62
63
63
class Cohpcar :
@@ -109,7 +109,7 @@ def __init__(
109
109
or (are_coops and are_multi_center_cobis )
110
110
or (are_cobis and are_multi_center_cobis )
111
111
):
112
- raise ValueError ("You cannot have info about COOPs, COBIs and/or multi-center COBIS in the same file." )
112
+ raise ValueError ("You cannot have info about COOPs, COBIs and/or multi-center COBIs in the same file." )
113
113
114
114
self .are_coops = are_coops
115
115
self .are_cobis = are_cobis
@@ -125,7 +125,7 @@ def __init__(
125
125
else :
126
126
self ._filename = "COHPCAR.lobster"
127
127
128
- lines = _get_lines (filename )
128
+ lines : list [ str ] = _get_lines (self . _filename )
129
129
130
130
# The parameters line is the second line in a COHPCAR file.
131
131
# It contains all parameters that are needed to map the file.
@@ -136,24 +136,23 @@ def __init__(
136
136
self .is_spin_polarized = int (parameters [1 ]) == 2
137
137
spins = [Spin .up , Spin .down ] if int (parameters [1 ]) == 2 else [Spin .up ]
138
138
cohp_data : dict [str , dict [str , Any ]] = {}
139
+
140
+ # The COHP/COBI data start from line num_bonds + 3
141
+ data = np .array ([np .array (line .split (), dtype = float ) for line in lines [num_bonds + 3 :]]).transpose ()
142
+
139
143
if not self .are_multi_center_cobis :
140
- # The COHP data start in line num_bonds + 3
141
- data = np .array ([np .array (line .split (), dtype = float ) for line in lines [num_bonds + 3 :]]).transpose ()
142
144
cohp_data = {
143
145
"average" : {
144
146
"COHP" : {spin : data [1 + 2 * s * (num_bonds + 1 )] for s , spin in enumerate (spins )},
145
147
"ICOHP" : {spin : data [2 + 2 * s * (num_bonds + 1 )] for s , spin in enumerate (spins )},
146
148
}
147
149
}
148
- else :
149
- # The COBI data start in line num_bonds + 3 if multi-center cobis exist
150
- data = np .array ([np .array (line .split (), dtype = float ) for line in lines [num_bonds + 3 :]]).transpose ()
151
150
152
151
self .energies = data [0 ]
153
152
154
153
orb_cohp : dict [str , Any ] = {}
155
154
# Present for LOBSTER versions older than 2.2.0
156
- very_old = False
155
+ older_than_2_2_0 : bool = False
157
156
158
157
# The label has to be changed: there are more than one COHP for each atom combination
159
158
# this is done to make the labeling consistent with ICOHPLIST.lobster
@@ -192,8 +191,8 @@ def __init__(
192
191
else :
193
192
# Present for LOBSTER versions older than 2.2.0
194
193
if bond_num == 0 :
195
- very_old = True
196
- if very_old :
194
+ older_than_2_2_0 = True
195
+ if older_than_2_2_0 :
197
196
bond_num += 1
198
197
label = str (bond_num )
199
198
@@ -245,8 +244,8 @@ def __init__(
245
244
else :
246
245
# Present for LOBSTER versions older than 2.2.0
247
246
if bond_num == 0 :
248
- very_old = True
249
- if very_old :
247
+ older_than_2_2_0 = True
248
+ if older_than_2_2_0 :
250
249
bond_num += 1
251
250
label = str (bond_num )
252
251
@@ -261,7 +260,7 @@ def __init__(
261
260
}
262
261
263
262
# Present for LOBSTER older than 2.2.0
264
- if very_old :
263
+ if older_than_2_2_0 :
265
264
for bond_str in orb_cohp :
266
265
cohp_data [bond_str ] = {
267
266
"COHP" : None ,
@@ -405,14 +404,10 @@ def __init__(
405
404
else :
406
405
self ._filename = "ICOHPLIST.lobster"
407
406
408
- # LOBSTER list files have an extra trailing blank line
409
- # and we don't need the header.
410
407
if self ._icohpcollection is None :
411
408
with zopen (self ._filename , mode = "rt" , encoding = "utf-8" ) as file :
412
- all_lines : list [str ] = file .read ().splitlines () # type:ignore[assignment]
409
+ all_lines : list [str ] = cast ( "list[str]" , file .read ().splitlines ())
413
410
414
- # strip *trailing* blank lines only
415
- all_lines = [line for line in all_lines if line .strip ()]
416
411
# --- detect header length robustly ---
417
412
header_len = 0
418
413
try :
@@ -442,7 +437,7 @@ def __init__(
442
437
# If the calculation is spin polarized, the line in the middle
443
438
# of the file will be another header line.
444
439
# TODO: adapt this for orbital-wise stuff
445
- if version in ( "3.1.1" , "2.2.1" ) :
440
+ if version in { "3.1.1" , "2.2.1" } :
446
441
self .is_spin_polarized = "distance" in lines [len (lines ) // 2 ]
447
442
else : # if version == "5.1.0":
448
443
self .is_spin_polarized = len (lines [0 ].split ()) == 9
@@ -637,10 +632,8 @@ def __init__(self, filename: PathLike = "NcICOBILIST.lobster") -> None:
637
632
Args:
638
633
filename: Name of the NcICOBILIST file.
639
634
"""
640
-
641
- # LOBSTER list files have an extra trailing blank line
642
- # and we don't need the header
643
- lines = _get_lines (filename )[1 :- 1 ]
635
+ # We don't need the header
636
+ lines = _get_lines (filename )[1 :]
644
637
if len (lines ) == 0 :
645
638
raise RuntimeError ("NcICOBILIST file contains no data." )
646
639
@@ -930,7 +923,7 @@ def __init__(
930
923
self .loewdin = [] if loewdin is None else loewdin
931
924
932
925
if self .num_atoms is None :
933
- lines = _get_lines (filename )[3 :- 3 ] # type:ignore[arg-type,assignment ]
926
+ lines = _get_lines (filename )[3 :- 2 ]
934
927
if len (lines ) == 0 :
935
928
raise RuntimeError ("CHARGES file contains no data." )
936
929
@@ -1105,10 +1098,12 @@ def __init__(self, filename: PathLike | None, **kwargs) -> None:
1105
1098
self .has_doscar_lso = (
1106
1099
"writing DOSCAR.LSO.lobster..." in lines and "SKIPPING writing DOSCAR.LSO.lobster..." not in lines
1107
1100
)
1101
+
1108
1102
try :
1109
1103
version_number = float ("." .join (self .lobster_version .strip ("v" ).split ("." )[:2 ]))
1110
1104
except ValueError :
1111
1105
version_number = 0.0
1106
+
1112
1107
if version_number < 5.1 :
1113
1108
self .has_cohpcar = (
1114
1109
"writing COOPCAR.lobster and ICOOPLIST.lobster..." in lines
@@ -1452,9 +1447,7 @@ def __init__(
1452
1447
for name in os .listdir (filenames ):
1453
1448
if fnmatch .fnmatch (name , "FATBAND_*.lobster" ):
1454
1449
filenames_new .append (os .path .join (filenames , name ))
1455
- filenames = filenames_new # type: ignore[assignment]
1456
-
1457
- filenames = cast ("list[PathLike]" , filenames )
1450
+ filenames = cast ("list[PathLike]" , filenames_new )
1458
1451
1459
1452
if len (filenames ) == 0 :
1460
1453
raise ValueError ("No FATBAND files in folder or given" )
@@ -1546,7 +1539,7 @@ def __init__(
1546
1539
1547
1540
idx_kpt = - 1
1548
1541
linenumber = iband = 0
1549
- for line in lines [1 :- 1 ]:
1542
+ for line in lines [1 :]:
1550
1543
if line .split ()[0 ] == "#" :
1551
1544
KPOINT = np .array (
1552
1545
[
@@ -1600,7 +1593,7 @@ def get_bandstructure(self) -> LobsterBandStructureSymmLine:
1600
1593
lattice = self .lattice ,
1601
1594
efermi = self .efermi , # type: ignore[arg-type]
1602
1595
labels_dict = self .label_dict ,
1603
- structure = self .structure , # type:ignore[arg-type]
1596
+ structure = self .structure , # type: ignore[arg-type]
1604
1597
projections = self .p_eigenvals ,
1605
1598
)
1606
1599
@@ -2159,7 +2152,7 @@ def __init__(
2159
2152
self ._filename = filename
2160
2153
self .ewald_splitting = float (lines [0 ].split ()[9 ])
2161
2154
2162
- lines = lines [5 :- 1 ]
2155
+ lines = lines [5 :]
2163
2156
self .num_atoms = len (lines ) - 2
2164
2157
for atom in range (self .num_atoms ):
2165
2158
line_parts = lines [atom ].split ()
@@ -2305,7 +2298,7 @@ def __init__(
2305
2298
2306
2299
self ._filename = str (filename )
2307
2300
with zopen (self ._filename , mode = "rt" , encoding = "utf-8" ) as file :
2308
- lines : list [str ] = file .readlines () # type:ignore[assignment]
2301
+ lines : list [str ] = cast ( "list[str]" , file .readlines ())
2309
2302
if len (lines ) == 0 :
2310
2303
raise RuntimeError ("Please check provided input file, it seems to be empty" )
2311
2304
0 commit comments