Skip to content

Commit

Permalink
Fix for commnet lines inside blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
pointedsphere committed Sep 30, 2024
1 parent 9e4d34a commit bdc9138
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions castep_outputs/test/test_cell_param_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,12 @@ def test_parse_supercell_matrix(self):
def test_parse_symops(self):
test_text = io.StringIO("""
%BLOCK SYMMETRY_OPS
# SYM OP 1
-1.0000000000 0.0000000000 0.0000000000
0.0000000000 -1.0000000000 0.0000000000
0.0000000000 0.0000000000 1.0000000000
0.5000000000 0.0000000000 0.5000000000
# SYM OP 2
1.0000000000 0.0000000000 0.0000000000
0.0000000000 1.0000000000 0.0000000000
0.0000000000 0.0000000000 1.0000000000
Expand Down
5 changes: 5 additions & 0 deletions castep_outputs/utilities/castep_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ def get_atom_parts(spec: str) -> dict[str, str]:
#: :meta hide-value:
EMPTY = r"^\s*$"

#: Comment line RegEx
#:
#: :meta hide-value:
COMMENT_LINE_RE = re.compile(r"^\s*#")

#: CASTEP Atom RegEx with optional index.
#:
#: :meta hide-value:
Expand Down
5 changes: 3 additions & 2 deletions castep_outputs/utilities/filewrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from __future__ import annotations

import re
from itertools import filterfalse
from io import StringIO
from typing import NoReturn, TextIO

from .castep_res import Pattern
from .castep_res import Pattern, COMMENT_LINE_RE


class FileWrapper:
Expand Down Expand Up @@ -203,7 +204,7 @@ def from_re(
data.append(init_line)

found = 0
for line in in_file:
for line in filterfalse(COMMENT_LINE_RE.match,in_file):
data.append(line)
if re.search(end, line):
found += 1
Expand Down

0 comments on commit bdc9138

Please sign in to comment.