Commit ea1bd298 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Merge branch 'wien2k-fixes' into 'v0.9.8'

Wien2k fixes #445

See merge request !230
parents 2c17a832 e8b85c22
Pipeline #90534 failed with stages
in 34 minutes and 19 seconds
Subproject commit cf6abfe712ff2d0052947f46bdb27131ac6fbaf8
Subproject commit 0bfb17daec156d26110d55cd0918d8fb584f7fac
......@@ -19,6 +19,9 @@
from typing import List
from abc import ABCMeta, abstractmethod
import re
import os
import os.path
from functools import lru_cache
from nomad import config
from nomad.datamodel import EntryArchive, UserProvidableMetadata, EntryMetadata
......@@ -105,6 +108,8 @@ class MatchingParser(Parser):
mainfile_contents_re: A regexp that is used to match the first 1024 bytes of a
potential mainfile.
mainfile_name_re: A regexp that is used to match the paths of potential mainfiles
mainfile_alternative: If True files are mainfile if no mainfile_name_re matching file
is present in the same directory.
domain: The domain that this parser should be used for. Default is 'dft'.
supported_compressions: A list of [gz, bz2], if the parser supports compressed files
'''
......@@ -114,6 +119,7 @@ class MatchingParser(Parser):
mainfile_binary_header: bytes = None,
mainfile_mime_re: str = r'text/.*',
mainfile_name_re: str = r'.*',
mainfile_alternative: bool = False,
domain='dft',
supported_compressions: List[str] = []) -> None:
......@@ -125,6 +131,7 @@ class MatchingParser(Parser):
self._mainfile_binary_header = mainfile_binary_header
self._mainfile_mime_re = re.compile(mainfile_mime_re)
self._mainfile_name_re = re.compile(mainfile_name_re)
self._mainfile_alternative = mainfile_alternative
# Assign private variable this way to avoid static check issue.
if mainfile_contents_re is not None:
self._mainfile_contents_re = re.compile(mainfile_contents_re)
......@@ -132,6 +139,8 @@ class MatchingParser(Parser):
self._mainfile_contents_re = None
self._supported_compressions = supported_compressions
self._ls = lru_cache(maxsize=16)(lambda directory: os.listdir(directory))
def is_mainfile(
self, filename: str, mime: str, buffer: bytes, decoded_buffer: str,
compression: str = None) -> bool:
......@@ -139,15 +148,34 @@ class MatchingParser(Parser):
if self._mainfile_binary_header is not None:
if self._mainfile_binary_header not in buffer:
return False
if self._mainfile_contents_re is not None:
if decoded_buffer is not None:
if self._mainfile_contents_re.search(decoded_buffer) is None:
return False
else:
return False
return self._mainfile_mime_re.match(mime) is not None and \
self._mainfile_name_re.fullmatch(filename) is not None and \
(compression is None or compression in self._supported_compressions)
if self._mainfile_mime_re.match(mime) is None:
return False
if compression is not None and compression not in self._supported_compressions:
return False
if self._mainfile_name_re.fullmatch(filename) is None:
if not self._mainfile_alternative:
return False
directory = os.path.dirname(filename)
for sibling in self._ls(directory):
sibling = os.path.join(directory, sibling)
sibling_is_mainfile = sibling != filename and \
self._mainfile_name_re.fullmatch(sibling) is not None and \
os.path.isfile(sibling)
if sibling_is_mainfile:
return False
return True
def __repr__(self):
return self.name
......
......@@ -217,6 +217,8 @@ parsers = [
LegacyParser(
name='parsers/wien2k', code_name='WIEN2k', code_homepage='http://www.wien2k.at/',
parser_class_name='wien2kparser.Wien2kParser',
mainfile_name_re=r'.*\.scf$',
mainfile_alternative=True,
mainfile_contents_re=r'\s*---------\s*:ITE[0-9]+:\s*[0-9]+\.\s*ITERATION\s*---------'
),
LegacyParser(
......
......@@ -23,6 +23,7 @@ elasticsearch-dsl==6.4.0
jmespath
# [parsing]
netCDF4==1.5.4
pandas
h5py
hjson
......
This diff is collapsed.
AlN_ZB
F LATTICE,NONEQUIV.ATOMS: 2
MODE OF CALC=RELA unit=bohr
8.277004 8.277004 8.277004 90.000000 90.000000 90.000000
ATOM 1: X=0.00000000 Y=0.00000000 Z=0.00000000
MULT= 1 ISPLIT= 2
Al NPT= 781 R0=0.00010000 RMT= 1.75000 Z: 13.0
LOCAL ROT MATRIX: 1.0000000 0.0000000 0.0000000
0.0000000 1.0000000 0.0000000
0.0000000 0.0000000 1.0000000
ATOM 2: X=0.25000000 Y=0.25000000 Z=0.25000000
MULT= 1 ISPLIT= 2
N NPT= 781 R0=0.00010000 RMT= 1.49000 Z: 7.0
LOCAL ROT MATRIX: 1.0000000 0.0000000 0.0000000
0.0000000 1.0000000 0.0000000
0.0000000 0.0000000 1.0000000
24 NUMBER OF SYMMETRY OPERATIONS
1 0 0 0.00000000
0-1 0 0.00000000
0 0-1 0.00000000
1
1 0 0 0.00000000
0 0-1 0.00000000
0-1 0 0.00000000
2
0 1 0 0.00000000
-1 0 0 0.00000000
0 0-1 0.00000000
3
0 0 1 0.00000000
-1 0 0 0.00000000
0-1 0 0.00000000
4
0 1 0 0.00000000
0 0-1 0.00000000
-1 0 0 0.00000000
5
0 0 1 0.00000000
0-1 0 0.00000000
-1 0 0 0.00000000
6
0-1 0 0.00000000
1 0 0 0.00000000
0 0-1 0.00000000
7
0 0-1 0.00000000
1 0 0 0.00000000
0-1 0 0.00000000
8
-1 0 0 0.00000000
0 1 0 0.00000000
0 0-1 0.00000000
9
-1 0 0 0.00000000
0 0 1 0.00000000
0-1 0 0.00000000
10
0-1 0 0.00000000
0 0-1 0.00000000
1 0 0 0.00000000
11
0 0-1 0.00000000
0-1 0 0.00000000
1 0 0 0.00000000
12
0 0 1 0.00000000
0 1 0 0.00000000
1 0 0 0.00000000
13
0 1 0 0.00000000
0 0 1 0.00000000
1 0 0 0.00000000
14
-1 0 0 0.00000000
0 0-1 0.00000000
0 1 0 0.00000000
15
-1 0 0 0.00000000
0-1 0 0.00000000
0 0 1 0.00000000
16
0 0 1 0.00000000
1 0 0 0.00000000
0 1 0 0.00000000
17
0 1 0 0.00000000
1 0 0 0.00000000
0 0 1 0.00000000
18
0 0-1 0.00000000
0 1 0 0.00000000
-1 0 0 0.00000000
19
0-1 0 0.00000000
0 0 1 0.00000000
-1 0 0 0.00000000
20
0 0-1 0.00000000
-1 0 0 0.00000000
0 1 0 0.00000000
21
0-1 0 0.00000000
-1 0 0 0.00000000
0 0 1 0.00000000
22
1 0 0 0.00000000
0 0 1 0.00000000
0 1 0 0.00000000
23
1 0 0 0.00000000
0 1 0 0.00000000
0 0 1 0.00000000
24
......@@ -85,7 +85,7 @@ for parser, mainfile in parser_examples:
parser_examples = fixed_parser_examples
correct_num_output_files = 114
correct_num_output_files = 115
class TestBackend(object):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment