Commit 9dc3dfad authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Legacy backend now actually considers the legacy names.

parent 0c48d7aa
......@@ -2377,7 +2377,7 @@ class section_k_band(MSection):
brillouin_zone = SubSection(
section_band_gap = SubSection(
......@@ -18,7 +18,7 @@ new nomad@fairdi infrastructure. This covers aspects like the new metainfo, a un
wrapper for parsers, parser logging, and a parser backend.
from typing import cast, Dict, List, Union, Any, Set, Iterable, Tuple
from typing import cast, Dict, List, Union, Any, Set, Iterable, Tuple, Type
import numpy as np
from pint.errors import UndefinedUnitError
import os.path
......@@ -31,7 +31,7 @@ from nomad import utils
from nomad.units import ureg
from nomad.metainfo import (
Definition, SubSection, Package, Quantity, Category, Section, Reference,
Environment, MEnum, MSection, DefinitionAnnotation)
Environment, MEnum, MSection, DefinitionAnnotation, MetainfoError, MSectionBound)
logger = utils.get_logger(__name__)
......@@ -127,6 +127,26 @@ class LegacyMetainfoEnvironment(Environment):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__section_to_sub_section_name = None
self.__legacy_names = None
def from_legacy_name(self, name: str, section_cls: Type[MSectionBound]) -> MSectionBound:
''' Returns the definition of the given globally unique legacy metainfo name. '''
if self.__legacy_names is None:
self.__legacy_names = dict()
for definition in self.m_all_contents():
if isinstance(definition, Section):
if definition.extends_base_section:
legacy = definition.a_legacy
key = (, definition.m_def.section_cls)
if key in self.__legacy_names:
raise MetainfoError('Legacy name %s is not globally unique' %
self.__legacy_names[key] = definition
except AttributeError:
return self.__legacy_names.get((name, section_cls))
def section_to_sub_section_name(self) -> Dict[str, str]:
......@@ -260,6 +260,10 @@ class Backend(AbstractParserBackend):
return self.__legacy_env
def resolve_definition(self, name, section_cls: Type[MSectionBound]) -> MSectionBound:
definition = self.env.from_legacy_name(name, section_cls)
if definition:
return definition
return self.env.resolve_definition(
normalize_name(name), section_cls, Backend.filter_legacy_defs)
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