Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple PROCAR parsing fix #57

Merged
merged 2 commits into from
Feb 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions easyunfold/procar.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,23 @@
section_counter += 1
_last_kid = _kid

kvec = tuple(round(float(val), 5) for val in tokens[-6:-3] # tuple to make it hashable
) # round to 5 decimal places to ensure proper kpoint matching
kvec = tuple(round(float(val), 5) for val in tokens[-6:-3]) # tuple to make it hashable

Check warning on line 84 in easyunfold/procar.py

View check run for this annotation

Codecov / codecov/patch

easyunfold/procar.py#L84

Added line #L84 was not covered by tests
# (rounded to 5 decimal places to ensure proper kpoint matching)

if (kvec not in parsed_kpoints and (kvec, section_counter) not in this_procar_parsed_kpoints):
this_procar_parsed_kpoints.add((kvec, section_counter))
kvecs.append(list(kvec))
kweights.append(float(tokens[-1]))
else:
# skip ahead to the next instance of two blank lines in a row
while line.strip() or fobj.readline().strip():
else: # previously parsed k-point, skip ahead to the next k-point:
while line:

Check warning on line 92 in easyunfold/procar.py

View check run for this annotation

Codecov / codecov/patch

easyunfold/procar.py#L92

Added line #L92 was not covered by tests
line = fobj.readline()
continue
if line.startswith(' k-point'): # next k-point
break
continue # go back to start of outer while loop, to parse this k-point

Check warning on line 96 in easyunfold/procar.py

View check run for this annotation

Codecov / codecov/patch

easyunfold/procar.py#L94-L96

Added lines #L94 - L96 were not covered by tests

elif (not re.search(r'[a-zA-Z]', line) and line.strip() and len(line.strip().split()) - 2 == len(self.proj_names)):
# only parse data if line is expected length, in case of LORBIT >= 12
# data line, as there is only numerical values, not empty line, and expected number of
# columns (in case of LORBIT >= 12)
proj_data.append([float(token) for token in line.strip().split()[1:-1]])

elif line.startswith('band'):
Expand Down Expand Up @@ -205,9 +208,9 @@
def open_file(fobj_or_path):
if isinstance(fobj_or_path, (str, Path)):
if os.path.exists(fobj_or_path):
return zopen(fobj_or_path, mode='rt') # closed later
return zopen(fobj_or_path, mode='rt', encoding='utf-8') # closed later

Check warning on line 211 in easyunfold/procar.py

View check run for this annotation

Codecov / codecov/patch

easyunfold/procar.py#L211

Added line #L211 was not covered by tests
if os.path.exists(f'{fobj_or_path}.gz'):
return zopen(f'{fobj_or_path}.gz', mode='rt')
return zopen(f'{fobj_or_path}.gz', mode='rt', encoding='utf-8')

Check warning on line 213 in easyunfold/procar.py

View check run for this annotation

Codecov / codecov/patch

easyunfold/procar.py#L213

Added line #L213 was not covered by tests

raise FileNotFoundError( # else raise error
f'File not found: {fobj_or_path} – PROCAR(.gz) file needed for '
Expand Down
Loading