Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • nomad-lab/nomad-FAIR
  • pgoel/nomad-FAIR
  • jpd47/nomad-FAIR
3 results
Show changes
Commits on Source (4)
......@@ -69,3 +69,6 @@
[submodule "dependencies/parsers/example"]
path = dependencies/parsers/example
url = https://github.com/nomad-coe/nomad-parser-example.git
[submodule "dependencies/parsers/simulation"]
path = dependencies/parsers/simulation
url = https://github.com/nomad-coe/simulation-parsers.git
......@@ -45,3 +45,6 @@ include dependencies/parsers/simulation/README.md
recursive-include dependencies/parsers/simulation/simulationparsers *.py
include dependencies/schema/nomad-perovskite-solar-cells-database/README.md
recursive-include dependencies/schema/nomad-perovskite-solar-cells-database/perovskite_solar_cell_database *.py nomad_plugin.yaml *.txt
include dependencies/parsers/simulation/README.md
recursive-include dependencies/parsers/simulation/simulationparsers *.py
recursive-include dependencies/parsers/simulation/simulationparsers/abacus *.py nomad_plugin.yaml
Subproject commit 6c351b50b24b83ebdb873eba7491460be3abe747
Subproject commit 4507e3a5528043a9bad076f04da2b6af88f13f39
......@@ -353,7 +353,7 @@ plugins = Plugins(
mainfile_contents_re=(r'Build.+\s+http://www\.yambo-code\.org'),
),
'parsers/abacus': Parser(
python_package='electronicparsers.abacus',
python_package='simulationparsers.abacus',
mainfile_contents_re=(r'\s*\n\s*WELCOME TO ABACUS'),
),
'parsers/amber': Parser(
......
from .file_parser import FileParser
from .file_parser import FileParser, Parser
from .text_parser import TextParser, DataTextParser, Quantity, ParsePattern
from .xml_parser import XMLParser
from .tar_parser import TarParser
......
......@@ -15,7 +15,7 @@
from abc import ABC, abstractmethod
import os
import pint
from typing import Any, Dict, Callable, IO, Union
from typing import Any, Dict, Callable, IO, Union, List
import gzip
import bz2
import lzma
......@@ -23,6 +23,7 @@ import tarfile
from nomad.metainfo import MSection
from nomad.utils import get_logger
from nomad.datamodel import EntryArchive
class FileParser(ABC):
......@@ -52,7 +53,7 @@ class FileParser(ABC):
self.logger = logger if logger is not None else get_logger(__name__)
# a key is necessary for xml parsers, where parsing is done dynamically
self._key: str = None
self._kwargs: Dict[str, Any] = dict()
self._kwargs: Dict[str, Any] = {}
self._results: Dict[str, Any] = None
self._file_handler: Any = None
......@@ -156,7 +157,7 @@ class FileParser(ABC):
self._key = key
self._kwargs = kwargs
val = self.results.get(key, None)
val = self.results.get(key)
if val is None:
val = default
......@@ -175,19 +176,6 @@ class FileParser(ABC):
return val
def __getitem__(self, key):
if isinstance(key, str):
return self.get(key)
elif isinstance(key, int):
return self[int]
def __getattr__(self, key):
if self._results is None:
self._results = dict()
self.parse(key)
return self._results.get(key, None)
def to_dict(self):
"""
Recursively converts the the parser results into a dictionary.
......@@ -214,6 +202,18 @@ class FileParser(ABC):
def parse(self, quantity_key: str = None, **kwargs):
pass
def __getitem__(self, key):
if isinstance(key, str):
return self.get(key)
elif isinstance(key, int):
return self[int]
def __getattr__(self, key):
if self._results is None:
self._results = {}
self.parse(key)
return self._results.get(key)
def __repr__(self) -> str:
results = list(self._results.keys()) if self._results else []
string = f'{self.__class__.__name__}'
......@@ -222,3 +222,49 @@ class FileParser(ABC):
if results:
string += f'--> {len(results)} parsed quantities ({", ".join(results[:5])}{", ..." if len(results) > 5 else ""})'
return string
class Parser(ABC):
mainfile: str = None
archive: EntryArchive = None
logger = None
child_archives = None
def get_mainfile_keys(
self, filename: str, decoded_buffer: str
) -> Union[bool, List[str]]:
"""
If child archives are necessary for the entry, a list of keys for the archives are
returned.
"""
return True
def to_dict(self) -> Dict[str, Any]:
"""
Converts the parsed metadata into a dictionary following the nomad archive schema.
"""
return {}
def write_to_archive(self) -> None:
"""
Abstract method to write the parsed metadata from mainfile to archive. The parser
may directly write to the archive or convert to a dictionary following the archive
schema through the to_dict method which is then used to update the archive.
"""
if self.archive is None:
return
self.archive.m_update_from_dict(self.to_dict())
def parse(
self, mainfile: str, archive: EntryArchive, logger=None, child_archives=None
) -> None:
"""
Main interface to the nomad parsing infrastructure.
"""
self.mainfile = mainfile
self.archive = archive
self.logger = logger if logger else get_logger(__name__)
self.child_archives = child_archives
self.write_to_archive()
......@@ -18,7 +18,9 @@ pip-compile --resolver=backtracking --quiet --annotation-style=line \
dependencies/parsers/eelsdb/pyproject.toml \
dependencies/parsers/electronic/pyproject.toml \
dependencies/parsers/nexus/pyproject.toml \
dependencies/parsers/workflow/pyproject.toml pyproject.toml
dependencies/parsers/workflow/pyproject.toml \
dependencies/parsers/simulation/pyproject.toml \
pyproject.toml
diff requirements.txt requirements.txt.tmp
......@@ -34,6 +36,7 @@ pip-compile --resolver=backtracking --quiet --annotation-style=line \
dependencies/parsers/electronic/pyproject.toml \
dependencies/parsers/nexus/pyproject.toml \
dependencies/parsers/workflow/pyproject.toml \
dependencies/parsers/simulation/pyproject.toml \
pyproject.toml
diff requirements-dev.txt requirements-dev.txt.tmp
......
......@@ -16,7 +16,9 @@ pip-compile --resolver=backtracking --annotation-style=line \
dependencies/parsers/eelsdb/pyproject.toml \
dependencies/parsers/electronic/pyproject.toml \
dependencies/parsers/nexus/pyproject.toml \
dependencies/parsers/workflow/pyproject.toml pyproject.toml
dependencies/parsers/workflow/pyproject.toml \
dependencies/parsers/simulation/pyproject.toml \
pyproject.toml
pip-compile --resolver=backtracking --annotation-style=line \
......@@ -30,4 +32,5 @@ pip-compile --resolver=backtracking --annotation-style=line \
dependencies/parsers/electronic/pyproject.toml \
dependencies/parsers/nexus/pyproject.toml \
dependencies/parsers/workflow/pyproject.toml \
dependencies/parsers/simulation/pyproject.toml \
pyproject.toml
\ No newline at end of file