-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vasp mapping parser #3
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
from nomad.config.models.plugins import ParserEntryPoint | ||
from pydantic import Field | ||
|
||
|
||
class EntryPoint(ParserEntryPoint): | ||
parser_class_name: str = Field( | ||
description=""" | ||
The fully qualified name of the Python class that implements the parser. | ||
This class must have a function `def parse(self, mainfile, archive, logger)`. | ||
""" | ||
) | ||
|
||
def load(self): | ||
from nomad.parsing.parser import MatchingParserInterface | ||
|
||
return MatchingParserInterface( | ||
parser_class_name='nomad_simulation_parsers.parsers.exciting.parser.ExcitingParser', | ||
self.parser_class_name, | ||
**self.dict(), | ||
) | ||
|
||
|
@@ -15,9 +23,27 @@ def load(self): | |
name='parsers/exciting', | ||
aliases=['parsers/exciting'], | ||
description='NOMAD parser for EXCITING.', | ||
parser_class_name='nomad_simulation_parsers.parsers.exciting.parser.ExcitingParser', | ||
python_package='nomad_simulation_parsers', | ||
mainfile_contents_re=r'EXCITING.*started[\s\S]+?All units are atomic ', | ||
mainfile_name_re=r'^.*.OUT(\.[^/]*)?$', | ||
code_name='exciting', | ||
code_homepage='http://exciting-code.org/', | ||
) | ||
|
||
vasp_parser_entry_point = EntryPoint( | ||
name='parsers/vasp', | ||
description='Parser for VASP XML and OUTCAR outputs', | ||
parser_class_name='nomad_simulation_parsers.parsers.vasp.parser.VASPParser', | ||
python_package='nomad_simulation_parsers', | ||
code_name='VASP', | ||
mainfile_contents_re=( | ||
r'^\s*<\?xml version="1\.0" encoding="ISO-8859-1"\?>\s*?\s*<modeling>?\s*' | ||
r'<generator>?\s*<i name="program" type="string">\s*vasp\s*</i>?|' | ||
r'^\svasp[\.\d]+.+?(?:\(build|complex)[\s\S]+?executed on' | ||
), | ||
mainfile_mime_re='(application/.*)|(text/.*)', | ||
mainfile_name_re='.*[^/]*xml[^/]*', | ||
mainfile_alternative=True, | ||
supported_compressions=['gz', 'bz2', 'xz'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the compression support be specified at a higher level? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is in the correct place, in MatchingParser |
||
) |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import os | ||
import re | ||
from glob import glob | ||
from typing import Union | ||
|
||
from nomad.metainfo import Section, SubSection | ||
|
||
|
||
def search_files( | ||
pattern: str, | ||
basedir: str, | ||
deep: bool = True, | ||
max_dirs: int = 10, | ||
re_pattern: str = '', | ||
) -> list[str]: | ||
"""Search files following the `pattern` starting from `basedir`. The search is | ||
performed recursively in all sub-folders (deep=True) or parent folders (deep=False). | ||
A futher regex search with `re_pattern` is done to filter the matching files. | ||
|
||
Args: | ||
pattern (str): pattern to match the files in the folder | ||
basedir (str): directory to start the search | ||
deep (bool, optional): folders search direction (True=down, False=up) | ||
re_pattern (str, optional): additional regex pattern to filter matching files | ||
|
||
Returns: | ||
list: list of matching files | ||
""" | ||
|
||
for _ in range(max_dirs): | ||
filenames = glob(f'{basedir}/{pattern}') | ||
pattern = os.path.join('**' if deep else '..', pattern) | ||
if filenames: | ||
break | ||
|
||
if len(filenames) > 1: | ||
# filter files that match | ||
matches = [f for f in filenames if re.search(re_pattern, f)] | ||
filenames = matches if matches else filenames | ||
|
||
filenames = [f for f in filenames if os.access(f, os.F_OK)] | ||
return filenames | ||
|
||
|
||
def remove_mapping_annotations(property: Section, max_depth: int = 5) -> None: | ||
""" | ||
Remove mapping annotations from the input section definition, all its quantities | ||
and sub-sections recursively. | ||
|
||
Args: | ||
property (Section): The section definition to remove the annotations from. | ||
max_depth (int, optional): The maximum depth of the recursion for sub-sections | ||
using the same section as parent. | ||
""" | ||
|
||
def _remove(property: Union[Section, SubSection], depth: int = 0): | ||
if depth > max_depth: | ||
return | ||
|
||
annotation_key = 'mapping' | ||
property.m_annotations.pop(annotation_key, None) | ||
|
||
depth += 1 | ||
property_section = ( | ||
property.sub_section if isinstance(property, SubSection) else property | ||
) | ||
for quantity in property_section.all_quantities.values(): | ||
quantity.m_annotations.pop(annotation_key, None) | ||
|
||
for sub_section in property_section.all_sub_sections.values(): | ||
if sub_section.m_annotations.get(annotation_key): | ||
_remove(sub_section, depth) | ||
elif sub_section.sub_section.m_annotations.get(annotation_key): | ||
_remove(sub_section.sub_section, depth) | ||
else: | ||
for ( | ||
inheriting_section | ||
) in sub_section.sub_section.all_inheriting_sections: | ||
if inheriting_section.m_annotations.get(annotation_key): | ||
_remove(inheriting_section, depth) | ||
|
||
_remove(property) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put the HDF5 parser above xml in the matching priority
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which hdf5 parser?