Skip to content

Commit 68a071d

Browse files
committed
Fix regex
1 parent bb0d4b0 commit 68a071d

File tree

2 files changed

+11
-70
lines changed

2 files changed

+11
-70
lines changed

src/nomad_simulation_parsers/parsers/crystal/file_parser.py

Lines changed: 11 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,7 @@ def init_quantities(self):
275275
rf'\s+{INTEGER}{BR}'
276276
rf'\s+ATOM\s+X(?:/A|\(ANGSTROM\))\s+Y(?:/B|\(ANGSTROM\))\s+'
277277
rf'Z(?:/C|\(ANGSTROM\))\s*{BR}'
278-
rf'{
279-
re.escape(
280-
" ************************************************************"
281-
"*******************"
282-
)
283-
}'
278+
rf' \*+?'
284279
rf'((?:\s+{INTEGER}\s+(?:T|F)\s+{INTEGER}\s+[\s\S]*?\s+{FLT}\s+{FLT}\s+'
285280
rf'{FLT}{BR})+)',
286281
shape=(-1, 7),
@@ -316,12 +311,7 @@ def init_quantities(self):
316311
'labels_positions',
317312
rf'\s+ATOM\s+X(?:/A|\(ANGSTROM\))\s+Y(?:/B|\(ANGSTROM\))\s+'
318313
rf'Z(?:/C|\(ANGSTROM\))\s*{BR}'
319-
rf'{
320-
re.escape(
321-
" ************************************************"
322-
"*******************************"
323-
)
324-
}'
314+
rf' \*+?'
325315
rf'((?:\s+{INTEGER}\s+(?:T|F)\s+{INTEGER}\s+[\s\S]*?\s+'
326316
rf'{FLT}\s+{FLT}\s+{FLT}{BR})+)',
327317
shape=(-1, 7),
@@ -332,12 +322,7 @@ def init_quantities(self):
332322
'labels_positions_nanotube',
333323
rf'\s+ATOM\s+X/A\s+Y\(ANGSTROM\)\s+Z\(ANGSTROM\)\s+'
334324
rf'R\(ANGS\)\s*{BR}'
335-
rf'{
336-
re.escape(
337-
" ************************************************"
338-
"*******************************"
339-
)
340-
}'
325+
rf' \*+?'
341326
rf'((?:\s+{INTEGER}\s+(?:T|F)\s+{INTEGER}\s+[\s\S]*?\s+'
342327
rf'{FLT}\s+{FLT}\s+{FLT}\s+{FLT}{BR})+)',
343328
shape=(-1, 8),
@@ -362,12 +347,7 @@ def init_quantities(self):
362347
'labels_positions_restart',
363348
rf' ATOM N\.AT\. SHELL X\(A\) Y\(A\) Z\(A\) EXAD '
364349
rf' N\.ELECT\.{BR}'
365-
rf'{
366-
re.escape(
367-
" ************************************************************"
368-
"*******************"
369-
)
370-
}'
350+
rf' \*+?'
371351
rf'((?:\s+{INTEGER}\s+{INTEGER}\s+{WORD}\s+{INTEGER}\s+{FLT}\s+{FLT}'
372352
rf'\s+{FLT}\s+{FLT}\s+{FLT}{BR})+)',
373353
shape=(-1, 9),
@@ -382,19 +362,9 @@ def init_quantities(self):
382362
# Method
383363
Quantity(
384364
'basis_set',
385-
rf'{
386-
re.escape(
387-
" ***********************************************************"
388-
"********************"
389-
)
390-
}'
365+
rf' \*+?'
391366
rf'{BR} LOCAL ATOMIC FUNCTIONS BASIS SET{BR}'
392-
rf'{
393-
re.escape(
394-
" **********************************************************"
395-
"*********************"
396-
)
397-
}'
367+
rf' \*+?'
398368
rf'{BR} ATOM X\(AU\) Y\(AU\) Z\(AU\) N. TYPE EXPONENT'
399369
rf' S COEF P COEF D/F/G COEF{BR}'
400370
rf'([\s\S]*?){BR} INFORMATION',
@@ -730,12 +700,7 @@ def init_quantities(self):
730700
rf'( (?:COORDINATE AND CELL OPTIMIZATION|COORDINATE OPTIMIZATION) - '
731701
rf'POINT\s+1{BR}'
732702
rf'[\s\S]*?'
733-
rf'{
734-
re.escape(
735-
r" ***********************************************************"
736-
r"*******"
737-
)
738-
}'
703+
rf' \*+?'
739704
rf'{BR}'
740705
rf'\s*\* OPT END - CONVERGED \* E\(AU\)\:\s+{FLT}\s+POINTS\s+{INTEGER})'
741706
rf'\s+\*{BR}',
@@ -767,13 +732,7 @@ def init_quantities(self):
767732
rf'\s+ATOM\s+X(?:/A|\(ANGSTROM\))\s+'
768733
rf'Y(?:/B|\(ANGSTROM\))\s+Z(?:/C|\(ANGSTROM\))'
769734
rf'\s*{BR}'
770-
rf'{
771-
re.escape(
772-
" ************************************"
773-
"*************************************"
774-
"******"
775-
)
776-
}'
735+
rf' \*+?'
777736
rf'((?:\s+{INTEGER}\s+(?:T|F)\s+{INTEGER}\s+'
778737
rf'[\s\S]*?\s+{FLT}\s+{FLT}\s+{FLT}{BR})+)',
779738
shape=(-1, 7),
@@ -784,13 +743,7 @@ def init_quantities(self):
784743
'labels_positions_nanotube',
785744
rf'\s+ATOM\s+X/A\s+Y\(ANGSTROM\)\s+Z'
786745
rf'\(ANGSTROM\)\s+R\(ANGS\)\s*{BR}'
787-
rf'{
788-
re.escape(
789-
" ************************************"
790-
"*************************************"
791-
"******"
792-
)
793-
}'
746+
rf' \*+?'
794747
rf'((?:\s+{INTEGER}\s+(?:T|F)\s+{INTEGER}\s+'
795748
rf'[\s\S]*?\s+{FLT}\s+{FLT}\s+{FLT}\s+{FLT}'
796749
rf'{BR})+)',
@@ -826,12 +779,7 @@ def init_quantities(self):
826779
# Band structure
827780
Quantity(
828781
'band_structure',
829-
rf'{
830-
re.escape(
831-
r" ***********************************************************"
832-
r"********************"
833-
)
834-
}'
782+
rf' \*+?'
835783
rf'{BR}'
836784
rf' \* '
837785
rf' \*{BR}'
@@ -842,12 +790,7 @@ def init_quantities(self):
842790
rf' \* TOTAL OF\s+{INTEGER} K-POINTS ALONG THE PATH\s+\*{BR}'
843791
rf' \* '
844792
rf' \*{BR}'
845-
rf'{
846-
re.escape(
847-
r" ***********************************************************"
848-
r"********************"
849-
)
850-
}'
793+
rf' \*+?'
851794
rf'{BR}'
852795
rf'([\s\S]*?'
853796
rf' ENERGY RANGE \(A\.U\.\)\s*{FLT} - \s*{FLT} EFERMI\s*{FLT_C}{BR})',

tests/parsers/test_crystal_parser.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@ def test_parse_file():
99
parser = CrystalParser()
1010
archive = EntryArchive()
1111
parser.parse('tests/data/crystal/single_point/dft/output.out', archive, LOGGER)
12-
13-
assert archive.data.wall_start == 1476100785.2

0 commit comments

Comments
 (0)