Skip to content

Mapping guide doc#131

Draft
EBB2675 wants to merge 11 commits into
developfrom
mapping-guide-doc
Draft

Mapping guide doc#131
EBB2675 wants to merge 11 commits into
developfrom
mapping-guide-doc

Conversation

@EBB2675

@EBB2675 EBB2675 commented Dec 16, 2025

Copy link
Copy Markdown
Collaborator

here is a PR to work together on a practical guide on mapping annotation

@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 20262837933

Details

  • 45 of 109 (41.28%) changed or added relevant lines in 5 files are covered.
  • 486 unchanged lines in 8 files lost coverage.
  • Overall coverage decreased (-5.6%) to 61.334%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/nomad_simulation_parsers/schema_packages/orca.py 18 20 90.0%
src/nomad_simulation_parsers/parsers/orca/text_parser.py 5 31 16.13%
src/nomad_simulation_parsers/parsers/orca/parser.py 20 56 35.71%
Files with Coverage Reduction New Missed Lines %
tests/parsers/test_lammps_parser.py 6 97.45%
src/nomad_simulation_parsers/parsers/abinit/file_parser.py 32 50.7%
src/nomad_simulation_parsers/parsers/utils/mdparserutils.py 42 47.33%
src/nomad_simulation_parsers/parsers/lammps/trajectory_parsers.py 45 65.28%
src/nomad_simulation_parsers/parsers/lammps/file_parsers.py 57 39.34%
src/nomad_simulation_parsers/parsers/abinit/parser.py 77 32.37%
src/nomad_simulation_parsers/parsers/lammps/parser.py 112 21.79%
src/nomad_simulation_parsers/parsers/utils/mdanalysisparser.py 115 35.48%
Totals Coverage Status
Change from base Build 20136411595: -5.6%
Covered Lines: 4229
Relevant Lines: 6895

💛 - Coveralls

@ndaelman-hu

Copy link
Copy Markdown
Collaborator

I will just for now give a review solely on the docs. Can do one later the rest of the parser, if necessary.

@EBB2675

EBB2675 commented Dec 16, 2025

Copy link
Copy Markdown
Collaborator Author

I will just for now give a review solely on the docs. Can do one later the rest of the parser, if necessary.

yes please 🤝

i have just quickly pushed the doc from a random branch of mine, the rest is indeed not relevant
@ndaelman-hu @JFRudzinski @Bernadette-Mohr @kubanmar

@ndaelman-hu ndaelman-hu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding this. Most of the feedback below comes down to specific phrases.

More importantly, how should we combine this with the docs in nomad-docs?
I would keep both in the same repo, don't have strong feelings which one.


## What a mapping annotation is

- A small note on a schema field that says: *for source `<KEY>`, read value at `<PATH>` and put it here.*

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- A small note on a schema field that says: *for source `<KEY>`, read value at `<PATH>` and put it here.*
- A small note on a schema field that says: *for source `<KEY>`, read value at `<PATH>` and place it in the archive under the path leading to the annotated schema field.*

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what i initially wanted to avoid actually, as this internal document is trying to have a casual and simple approach


- A small note on a schema field that says: *for source `<KEY>`, read value at `<PATH>` and put it here.*
- Stored on any section/quantity: `m_annotations['mapping'][<KEY>] = MapperAnnotation(mapper=...)`.
- `<KEY>` names the source (e.g., `OUT_KEY`, `HDF5_KEY`, `INFO_KEY`, `BAND_KEY`).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add "why we there may be multiple keys". If there was only one, that field would not be necessary.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part is focusing on what, and not why. we should avoid giving out too many details at once

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, then maybe add the "why" above


- A small note on a schema field that says: *for source `<KEY>`, read value at `<PATH>` and put it here.*
- Stored on any section/quantity: `m_annotations['mapping'][<KEY>] = MapperAnnotation(mapper=...)`.
- `<KEY>` names the source (e.g., `OUT_KEY`, `HDF5_KEY`, `INFO_KEY`, `BAND_KEY`).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick: it doesn't "name" the source per se (as in it does not define the source file).
It just defines a particular source format / mapping.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will revise it 👍

- A small note on a schema field that says: *for source `<KEY>`, read value at `<PATH>` and put it here.*
- Stored on any section/quantity: `m_annotations['mapping'][<KEY>] = MapperAnnotation(mapper=...)`.
- `<KEY>` names the source (e.g., `OUT_KEY`, `HDF5_KEY`, `INFO_KEY`, `BAND_KEY`).
- Paths use JMESPath style. Relative paths start with `.` (from the parent’s mapped node). `@` anchors at the source root.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Paths use JMESPath style. Relative paths start with `.` (from the parent’s mapped node). `@` anchors at the source root.
- Paths use [JMESPath](https://jmespath.org/) style. Relative paths start with `.` (from the parent’s mapped node). `@` anchors at the source root.


1) A source parser (`XMLParser`, `HDF5Parser`, `TextParser`, etc.) reads a file into a Python dict.
2) Set `annotation_key` on a `MetainfoParser` to the `<KEY>` that matches the annotations.
3) Call `convert(source_parser, target_parser)`. One key → one `convert`. Multiple keys/sources → run `convert` once per key after switching `annotation_key` each time.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One key → one convert.

Lol, sounds oddly religious.

add_mapping_annotation(general.Simulation.m_def, OUT_KEY, '@')
```

### 2) Nested quantities

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 2) Nested quantities
### 2) Quantities

Quantities can never be at the root.

add_mapping_annotation(general.Program.version, OUT_KEY, '.program_version')
```

### 3) Single nested subsection

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 3) Single nested subsection
### 3) Single subsection

Tautology: the prefix "sub" already clarifies that is "nested" as you refer to it. Moreover, "nested" obtains a very different meaning when talking about serialization and querying. Would avoid it to prevent confusion.

add_mapping_annotation(model_method.DFT.m_def, OUT_KEY, '.dft')
```

### 4) Repeating subsections (lists)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 4) Repeating subsections (lists)
### 4) Repeating subsections & Array-like Quantities

Comment on lines +80 to +87
### 5) Multiple sources into the same schema
Use different keys; run `convert` once per key.
```python
# Octopus uses OUT_KEY + INFO_KEY + EIGENVALUES_KEY on the same schema
# Exciting uses INFO_KEY, INPUT_XML_KEY, EIGVAL_KEY, BANDSTRUCTURE_XML_KEY, DOS_XML_KEY
# Wannier90 uses WOUT_KEY, WIN_KEY, BAND_KEY, WHR_KEY, DOS_KEY
```
Set `annotation_key = <KEY>` before each `convert`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an example, pls?
From memory, I'd say that convert is called at the parser-level instead of the annotations, but might be fuzzy on that one.

Set `annotation_key = <KEY>` before each `convert`.

### 6) Transformations (reshape, filter, apply units)
Use a tuple `(function_name, [paths], {kwargs})` and implement the function on the parser.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Use a tuple `(function_name, [paths], {kwargs})` and implement the function on the parser.
Use a tuple `(function_name, [paths], {kwargs})` and implement the function at the parser level.

Maybe you should introduce the 2 levels.

- Absolute from root: `field.subfield` (no leading dot)
- Root anchor: `@`
- Filter: `.items[?"@name"=="version"] | [0].__value`
- Attributes (XML/HDF5): keys often prefixed with `@`; values with `__value`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "often" here mean that this is a convention, but it would theoretically also be possible, to, e.g., prefix a value with @?

@EBB2675 EBB2675 marked this pull request as draft December 19, 2025 07:53
@EBB2675 EBB2675 added the wontfix This will not be worked on label Dec 19, 2025
@JFRudzinski JFRudzinski self-assigned this Dec 19, 2025
@JFRudzinski JFRudzinski added documentation Improvements or additions to documentation and removed wontfix This will not be worked on labels Dec 19, 2025
@JFRudzinski

Copy link
Copy Markdown
Collaborator

I will tackle this as part of my documentation work: FAIRmat-NFDI/nomad-simulations#311

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants