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

Refactored the parser list.

parent 65a51a79
Pipeline #78747 passed with stages
in 19 minutes and 44 seconds
...@@ -20,7 +20,8 @@ from typing import Dict, Any ...@@ -20,7 +20,8 @@ from typing import Dict, Any
from flask_restplus import Resource, fields from flask_restplus import Resource, fields
from datetime import datetime from datetime import datetime
from nomad import config, parsing, normalizing, datamodel, gitinfo, search from nomad import config, normalizing, datamodel, gitinfo, search
from nomad.parsing import parsers, MatchingParser
from .api import api from .api import api
...@@ -94,8 +95,8 @@ class InfoResource(Resource): ...@@ -94,8 +95,8 @@ class InfoResource(Resource):
def get(self): def get(self):
''' Return information about the nomad backend and its configuration. ''' ''' Return information about the nomad backend and its configuration. '''
codes_dict = {} codes_dict = {}
for parser in parsing.parser_dict.values(): for parser in parsers.parser_dict.values():
if isinstance(parser, parsing.MatchingParser) and parser.domain == 'dft': if isinstance(parser, MatchingParser) and parser.domain == 'dft':
code_name = parser.code_name code_name = parser.code_name
if code_name in codes_dict: if code_name in codes_dict:
continue continue
...@@ -105,10 +106,10 @@ class InfoResource(Resource): ...@@ -105,10 +106,10 @@ class InfoResource(Resource):
return { return {
'parsers': [ 'parsers': [
key[key.index('/') + 1:] key[key.index('/') + 1:]
for key in parsing.parser_dict.keys()], for key in parsers.parser_dict.keys()],
'metainfo_packages': ['general', 'general.experimental', 'common', 'public'] + sorted([ 'metainfo_packages': ['general', 'general.experimental', 'common', 'public'] + sorted([
key[key.index('/') + 1:] key[key.index('/') + 1:]
for key in parsing.parser_dict.keys()]), for key in parsers.parser_dict.keys()]),
'codes': codes, 'codes': codes,
'normalizers': [normalizer.__name__ for normalizer in normalizing.normalizers], 'normalizers': [normalizer.__name__ for normalizer in normalizing.normalizers],
'statistics': statistics(), 'statistics': statistics(),
......
...@@ -22,7 +22,7 @@ import importlib ...@@ -22,7 +22,7 @@ import importlib
from nomad.metainfo.legacy import python_package_mapping, LegacyMetainfoEnvironment from nomad.metainfo.legacy import python_package_mapping, LegacyMetainfoEnvironment
from nomad.metainfo import Package from nomad.metainfo import Package
from nomad.parsing import parsers from nomad.parsing.parsers import parsers
from .api import api from .api import api
......
...@@ -4,10 +4,9 @@ import json ...@@ -4,10 +4,9 @@ import json
import click import click
import sys import sys
from nomad import utils from nomad import utils, parsing, normalizing, datamodel
from nomad import parsing from nomad.parsing.parsers import parser_dict, match_parser
from nomad import normalizing
from nomad import datamodel
import nomadcore import nomadcore
from .cli import cli from .cli import cli
...@@ -27,10 +26,10 @@ def parse( ...@@ -27,10 +26,10 @@ def parse(
if logger is None: if logger is None:
logger = utils.get_logger(__name__) logger = utils.get_logger(__name__)
if parser_name is not None: if parser_name is not None:
parser = parsing.parser_dict.get(parser_name) parser = parser_dict.get(parser_name)
assert parser is not None, 'the given parser must exist' assert parser is not None, 'the given parser must exist'
else: else:
parser = parsing.match_parser(mainfile_path, strict=strict) parser = match_parser(mainfile_path, strict=strict)
if isinstance(parser, parsing.MatchingParser): if isinstance(parser, parsing.MatchingParser):
parser_name = parser.name parser_name = parser.name
else: else:
......
...@@ -266,7 +266,7 @@ class DFTMetadata(MSection): ...@@ -266,7 +266,7 @@ class DFTMetadata(MSection):
def code_name_from_parser(self): def code_name_from_parser(self):
entry = self.m_parent entry = self.m_parent
if entry.parser_name is not None: if entry.parser_name is not None:
from nomad.parsing import parser_dict from nomad.parsing.parsers import parser_dict
parser = parser_dict.get(entry.parser_name) parser = parser_dict.get(entry.parser_name)
if hasattr(parser, 'code_name'): if hasattr(parser, 'code_name'):
return parser.code_name return parser.code_name
......
This diff is collapsed.
This diff is collapsed.
...@@ -38,7 +38,8 @@ from structlog.processors import StackInfoRenderer, format_exc_info, TimeStamper ...@@ -38,7 +38,8 @@ from structlog.processors import StackInfoRenderer, format_exc_info, TimeStamper
from nomad import utils, config, infrastructure, search, datamodel from nomad import utils, config, infrastructure, search, datamodel
from nomad.files import PathObject, UploadFiles, ExtractError, ArchiveBasedStagingUploadFiles, PublicUploadFiles, StagingUploadFiles from nomad.files import PathObject, UploadFiles, ExtractError, ArchiveBasedStagingUploadFiles, PublicUploadFiles, StagingUploadFiles
from nomad.processing.base import Proc, process, task, PENDING, SUCCESS, FAILURE from nomad.processing.base import Proc, process, task, PENDING, SUCCESS, FAILURE
from nomad.parsing import parser_dict, match_parser, Backend from nomad.parsing import Backend
from nomad.parsing.parsers import parser_dict, match_parser
from nomad.normalizing import normalizers from nomad.normalizing import normalizers
from nomad.datamodel import EntryArchive from nomad.datamodel import EntryArchive
from nomad.archive import query_archive from nomad.archive import query_archive
...@@ -1036,7 +1037,7 @@ class Upload(Proc): ...@@ -1036,7 +1037,7 @@ class Upload(Proc):
modified_upload = self._get_collection().find_one_and_update( modified_upload = self._get_collection().find_one_and_update(
{'_id': self.upload_id, 'joined': {'$ne': True}}, {'_id': self.upload_id, 'joined': {'$ne': True}},
{'$set': {'joined': True}}) {'$set': {'joined': True}})
if modified_upload['joined'] is False: if modified_upload is None or modified_upload['joined'] is False:
self.get_logger().info('join') self.get_logger().info('join')
# Before cleaning up, run an additional normalizer on phonon # Before cleaning up, run an additional normalizer on phonon
......
...@@ -3,7 +3,7 @@ if __name__ == '__main__': ...@@ -3,7 +3,7 @@ if __name__ == '__main__':
import logging import logging
import time import time
from nomad import config, utils from nomad import config, utils
from nomad.parsing import parser_dict from nomad.parsing.parsers import parser_dict
from nomad.cli.parse import normalize_all from nomad.cli.parse import normalize_all
from nomad.metainfo.legacy import LegacyMetainfoEnvironment from nomad.metainfo.legacy import LegacyMetainfoEnvironment
from nomad.parsing.legacy import Backend from nomad.parsing.legacy import Backend
......
...@@ -22,7 +22,8 @@ import datetime ...@@ -22,7 +22,8 @@ import datetime
from ase.data import chemical_symbols from ase.data import chemical_symbols
from ase.spacegroup import Spacegroup from ase.spacegroup import Spacegroup
from nomad import datamodel, parsing, utils, files from nomad import datamodel, utils, files
from nomad.parsing.parsers import parser_dict
number_of = 20 number_of = 20
...@@ -37,7 +38,7 @@ systems = ['atom', 'molecule/cluster', '2D/surface', 'bulk'] ...@@ -37,7 +38,7 @@ systems = ['atom', 'molecule/cluster', '2D/surface', 'bulk']
comments = [gen.sentence() for _ in range(0, number_of)] comments = [gen.sentence() for _ in range(0, number_of)]
references = [(i + 1, gen.url()) for i in range(0, number_of)] references = [(i + 1, gen.url()) for i in range(0, number_of)]
datasets = [(i + 1, gen.slug()) for i in range(0, number_of)] datasets = [(i + 1, gen.slug()) for i in range(0, number_of)]
codes = list(set([parser.code_name for parser in parsing.parser_dict.values() if hasattr(parser, 'code_name')])) # type: ignore codes = list(set([parser.code_name for parser in parser_dict.values() if hasattr(parser, 'code_name')])) # type: ignore
filepaths = ['/'.join(gen.url().split('/')[3:]) for _ in range(0, number_of)] filepaths = ['/'.join(gen.url().split('/')[3:]) for _ in range(0, number_of)]
low_numbers_for_atoms = [1, 1, 2, 2, 2, 2, 2, 3, 3, 4] low_numbers_for_atoms = [1, 1, 2, 2, 2, 2, 2, 3, 3, 4]
......
...@@ -20,7 +20,8 @@ import os ...@@ -20,7 +20,8 @@ import os
from shutil import copyfile from shutil import copyfile
from nomad import utils, files, datamodel from nomad import utils, files, datamodel
from nomad.parsing import parser_dict, match_parser, BrokenParser, BadContextUri, Backend from nomad.parsing import BrokenParser, BadContextUri, Backend
from nomad.parsing.parsers import parser_dict, match_parser
from nomad.app import dump_json from nomad.app import dump_json
from nomad.metainfo import MSection from nomad.metainfo import MSection
......
Supports Markdown
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