Skip to content

Commit

Permalink
utils/parser/bands: avoid duplicated KPs (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-zero committed Sep 21, 2021
1 parent fffbc32 commit 2e5a57f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 9 additions & 2 deletions aiida_cp2k/utils/parser.py
Expand Up @@ -324,11 +324,11 @@ def _parse_bands(lines, n_start, cp2k_version):

if cp2k_version < 8.1:
parse_one_kpoint = _parse_kpoint_cp2k_lower_81
pattern = re.compile(".*?Nr.*?Spin.*?K-Point.*?", re.DOTALL)
pattern = re.compile(r".*?Nr.*?Spin.*?K-Point.*?", re.DOTALL)
unspecified = ["not", "specified"]
else:
parse_one_kpoint = _parse_bands_cp2k_greater_81
pattern = re.compile(".*?Point.*?Spin.*?", re.DOTALL)
pattern = re.compile(r".*?Point.*?Spin.*?", re.DOTALL)
unspecified = ["not", "specifi"]

selected_lines = lines[n_start:]
Expand All @@ -343,6 +343,13 @@ def _parse_bands(lines, n_start, cp2k_version):
elif pattern.match(line):
spin, kpoint, bands = parse_one_kpoint(selected_lines, line_n)

# When doing a path Γ-X-K, CP2K does Γ-X, X-K and we would
# end up with repeated points in the path. If we already have
# kpoints in the the list and we got exactly the same KP again,
# skip adding the kpoint, the label and the bands.
if kpoints and (kpoints[-1] == kpoint):
continue

if spin == 1:
if kpoint in known_kpoints:
labels.append((len(kpoints), known_kpoints[kpoint]))
Expand Down
6 changes: 2 additions & 4 deletions test/test_parser.py
Expand Up @@ -21,8 +21,7 @@ def test_bands_parser_51():
if "KPOINTS| Band Structure Calculation" in line:
kpoints, labels, bands = _parse_bands(lines, i_line, 5.1)
assert (kpoints[4] == [0.2, 0., 0.2]).all()
assert labels == [(0, 'GAMMA'), (10, 'X'), (11, 'X'), (21, 'U'), (22, 'K'), (32, 'GAMMA'), (33, 'GAMMA'),
(43, 'L'), (44, 'L'), (54, 'W'), (55, 'W'), (65, 'X')]
assert labels == [(0, 'GAMMA'), (10, 'X'), (20, 'U'), (21, 'K'), (31, 'GAMMA'), (41, 'L'), (51, 'W'), (61, 'X')]
assert (bands[0] == [-6.84282475, 5.23143741, 5.23143741, 5.23143741, 7.89232311]).all()


Expand All @@ -35,8 +34,7 @@ def test_bands_parser_81():
if "KPOINTS| Band Structure Calculation" in line:
kpoints, labels, bands = _parse_bands(lines, i_line, 8.1)
assert (kpoints[4] == [0.2, 0., 0.2]).all()
assert labels == [(0, 'GAMMA'), (10, 'X'), (11, 'X'), (21, 'U'), (22, 'K'), (32, 'GAMMA'), (33, 'GAMMA'),
(43, 'L'), (44, 'L'), (54, 'W'), (55, 'W'), (65, 'X')]
assert labels == [(0, 'GAMMA'), (10, 'X'), (20, 'U'), (21, 'K'), (31, 'GAMMA'), (41, 'L'), (51, 'W'), (61, 'X')]
assert (bands[0] == [-6.84282475, 5.23143741, 5.23143741, 5.23143741, 7.89232311]).all()


Expand Down

0 comments on commit 2e5a57f

Please sign in to comment.