diff --git a/src/pynxtools/nomad/parser.py b/src/pynxtools/nomad/parser.py index 00ec67b61..dd75c96a0 100644 --- a/src/pynxtools/nomad/parser.py +++ b/src/pynxtools/nomad/parser.py @@ -96,19 +96,12 @@ def _to_section( nomad_def_name = rename_nx_for_nomad(nomad_def_name, is_group=True) - # for groups, get the definition from the package - new_def = current.m_def.all_sub_sections[nomad_def_name] - - new_section: MSection = None # type:ignore - - for section in current.m_get_sub_sections(new_def): - if hdf_name is None or getattr(section, "nx_name", None) == hdf_name: - new_section = section - break - - if new_section is not None: - return new_section if current == nx_root: + # for groups, get the definition from the package + new_def = current.m_def.all_sub_sections["ENTRY"] + for section in current.m_get_sub_sections(new_def): + if hdf_name is None or getattr(section, "nx_name", None) == hdf_name: + return section cls = getattr(nexus_schema, nx_def, None) sec = cls() new_def_spec = sec.m_def.all_sub_sections[nomad_def_name] @@ -117,6 +110,11 @@ def _to_section( current.ENTRY.append(new_section) new_section.__dict__["nx_name"] = hdf_name else: + # for groups, get the definition from the package + new_def = current.m_def.all_sub_sections[nomad_def_name] + for section in current.m_get_sub_sections(new_def): + if hdf_name is None or getattr(section, "nx_name", None) == hdf_name: + return section current.m_create(new_def.section_def.section_cls) new_section = current.m_get_sub_section(new_def, -1) new_section.__dict__["nx_name"] = hdf_name diff --git a/tests/nomad/test_parsing.py b/tests/nomad/test_parsing.py index 8a71f9af3..b1dda4bb3 100644 --- a/tests/nomad/test_parsing.py +++ b/tests/nomad/test_parsing.py @@ -41,7 +41,7 @@ def test_nexus_example(): example_data = "src/pynxtools/data/201805_WSe2_arpes.nxs" NexusParser().parse(example_data, archive, get_logger(__name__)) - arpes_obj = getattr(archive.data, rename_nx_for_nomad("NXarpes")) + arpes_obj = archive.data assert arpes_obj.ENTRY[0].SAMPLE[0].pressure__field == ureg.Quantity( "3.27e-10*millibar" @@ -94,9 +94,9 @@ def test_nexus_example_with_renamed_groups(): os.path.dirname(__file__), "../data/nomad/NXlauetof.hdf5" ) NexusParser().parse(lauetof_data, archive, get_logger(__name__)) - lauetof_obj = getattr(archive.data, rename_nx_for_nomad("NXlauetof")) + lauetof_obj = archive.data - assert lauetof_obj.entry.name__group.time_of_flight__field == ureg.Quantity( + assert lauetof_obj.ENTRY[0].name__group.time_of_flight__field == ureg.Quantity( "1.0*second" ) - assert lauetof_obj.entry.sample.name__field == "SAMPLE-CHAR-DATA" + assert lauetof_obj.ENTRY[0].sample.name__field == "SAMPLE-CHAR-DATA"