Commit a81d781f authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Metainfo improvements (#419): aliases instead of synonyms, documentation, browser improvements.

parent aca34b3a
......@@ -134,7 +134,9 @@ export function metainfoAdaptorFactory(obj) {
class MetainfoAdaptor extends Adaptor {
itemAdaptor(key) {
if (key.startsWith('_category:')) {
if (key === '_reference') {
return metainfoAdaptorFactory(resolveRef(this.e.type.type_data))
} else if (key.startsWith('_category:')) {
const categoryName = key.split(':')[1]
return metainfoAdaptorFactory( => resolveRef(ref)).find(categoryDef => === categoryName))
} else if (key === '_metainfo') {
......@@ -216,8 +218,13 @@ export class PackagePrefixAdaptor extends MetainfoAdaptor {
function Metainfo(props) {
return <Content>
<Compartment title="root sections">
{ => (
<Compartment title="archive root section">
<Item itemKey="EntryArchive">
<Compartment title="other root sections">
{rootSections.filter(def => !== 'EntryArchive').map(def => (
<Item key={} itemKey={}>
......@@ -263,6 +270,7 @@ class CategoryDefAdaptor extends MetainfoAdaptor {
render() {
return <Content>
<Definition def={this.e} />
<DefinitionDetails def={this.e} />
......@@ -324,6 +332,7 @@ function SectionDef({def}) {
<DefinitionDetails def={def} />
SectionDef.propTypes = ({
......@@ -333,6 +342,28 @@ SectionDef.propTypes = ({
function QuantityDef({def}) {
return <Content>
<Definition def={def} kindLabel="quantity definition"/>
<Compartment title="properties">
{def.type.type_kind !== 'reference'
? <Typography>
{def.type.type_kind !== 'data' && `(${def.type.type_kind})`}
: <Item itemKey="_reference">
<b>referenced section</b>
[{def.shape.join(', ')}]
{def.unit &&
{def.aliases && def.aliases !== [] && <Typography><b>aliases</b>:&nbsp;{ => `"${a}"`).join(', ')}</Typography>}
{def.derived && <Typography><b>derived</b></Typography>}
<DefinitionDetails def={def} />
QuantityDef.propTypes = ({
......@@ -340,6 +371,22 @@ QuantityDef.propTypes = ({
function Definition({def, ...props}) {
return <React.Fragment>
<Title def={def} isDefinition {...props} />
{def.description && !def.extends_base_section &&
<Compartment title="description">
<Box marginTop={1} marginBottom={1}>
Definition.propTypes = {
def: PropTypes.object.isRequired
function DefinitionDetails({def, ...props}) {
const {api} = useContext(apiContext)
const lane = useContext(laneContext)
const isLast = !
......@@ -356,14 +403,14 @@ function Definition({def, ...props}) {
}, [api,, setUsage])
return <React.Fragment>
<Title def={def} isDefinition {...props} />
{isLast && def.description && !def.extends_base_section &&
<Compartment title="description">
<Box marginTop={1} marginBottom={1}>
{def.categories && def.categories.length > 0 && <Compartment title="Categories">
{ => {
const categoryDef = resolveRef(categoryRef)
return <Item key={categoryRef} itemKey={'_category:' +}>
{isLast && !def.extends_base_section && !== 'EntryArchive' &&
<Compartment title="graph">
<VicinityGraph def={def} />
......@@ -388,17 +435,9 @@ function Definition({def, ...props}) {
{def.categories && def.categories.length > 0 && <Compartment title="Categories">
{ => {
const categoryDef = resolveRef(categoryRef)
return <Item key={categoryRef} itemKey={'_category:' +}>
Definition.propTypes = {
DefinitionDetails.propTypes = {
def: PropTypes.object.isRequired
......@@ -5102,6 +5102,7 @@ class section_system(MSection):
atom_labels = Quantity(
Labels of the atoms. These strings identify the atom kind and conventionally start
with the symbol of the atomic species, possibly followed by the atomic number. The
......@@ -48,18 +48,18 @@ Starting example
pbc = Quantity(type=bool, shape=[3])
class Run(MSection):
systems = SubSection(sub_section=System, repeats=True)
section_system = SubSection(sub_section=System, repeats=True)
We define simple metainfo schema with two `sections` called ``System`` and ``Run``. Sections
allow to organize related data into, well, `sections`. Each section can have two types of
allow to organize related data into, well, `sections`. Each section can have two types of
properties: `quantities` and `sub-sections`. Sections and their properties are defined with
Python classes and their attributes.
Each `quantity` defines a piece of data. Basic quantity attributes are its `type`, `shape`,
`unit`, and `description`.
`Sub-sections` allow to place section into each other and there allow to form containment
`Sub-sections` allow to place section into each other and therefore allow to form containment
hierarchies or sections and the respective data in them. Basic sub-section attributes are
`sub_section`(i.e. a reference to the section definition of the sub-section) and `repeats`
(determines if a sub-section can be contained once or multiple times).
......@@ -107,8 +107,45 @@ This will serialize the data into JSON:
Definitions and Instances
As you already saw in the example, we first need to define what data can look like (schema),
before we can actually program with data. Because schema and data are often discussed in the
same context, it is paramount to clearly distingish between both. For example, if we
just say "system", it is unclear what we refer to. We could mean the idea of a system, i.e. all
possible systems, a data structure that comprises a lattice, atoms with their elements and
positions in the lattice. Or we mean a specific system of a specific calculation, with
a concrete set of atoms, real numbers for lattice vectors and atoms positions as concrete data.
The NOMAD Metainfo is just a collection of definition that describe what materials science
data could be (a schema). The NOMAD Archive is all the data that we extract from all data
provided to NOMAD. The data in the NOMAD Archive follows the definitions of the NOMAD metainfo.
Similarely, we need to distingish between the NOMAD Metainfo as a collection of definitions
and the Metainfo system that defines how to define a section or a quantity. In this sense,
we have a three layout model, were the Archive (data) is an instance of the Metainfo (schema)
and the Metainfo is an instance of the Metainfo system (schema of the schema).
This documentation describes the Metainfo by explaining the means of how to write down definitions
in Python. Conceptually we map the Metainfo system to Python language constructs, e.g.
a section definition is a Python class, a quantity a Python property, etc. If you are
familiar with databases, this is similar to what an object relational mapping (ORM) would do.
Common attributes of Metainfo Definitions
In the example, you already saw the basic Python interface to the Metainfo. *Sections* are
represented in Python as objects. To define a section, you write a Python classes that inherits
from ``MSection``. To define sub-sections and quantities you use Python properties. The
definitions themselves are also objects derived from classes. For sub-sections and
quantities, you directly instantiate :class:`SubSection` and :class`Quantity`. For sections
there is a generated object derived from :class:`Section` that is available via
`m_def` from each `section class` and `section instance`.
These Python classes that are used to represent metainfo definitions form an inheritance
hierarchy to share common properties
.. autoclass:: Definition
......@@ -116,66 +153,45 @@ Definitions
.. autoclass:: Quantity
.. _metainfo-sections:
Quantity definitions are the main building block of meta-info schemas. Each quantity
represents a single piece of data.
.. autoclass:: Quantity
With sections it is paramount to always be clear what is talked about. The lose
term `section` can reference one of the following three:
* `section definition`
Which is a Python object that represents the definition of
a section, its sub-sections and quantities. `Section definitions` should not be not
written directly. `Section definitions` are objects of :class:`Section`.
* `secton class`
Which is a Python class and :class:`MSection` decendant that is
used to express a `section defintion` in Python. Each `section class` is tightly
associated with its `section definition`. The `section definition` can be access
with the class attribute ``m_def``. The `section definition` is automatically created
from the `section class` upon defining the class through metaclass vodoo.
* `section instance`
The instance (object) of a `section class`, it `follows` the
definition associated with the instantiated `section class`. The followed
section definition can be accessed with the object attribute ``m_def``.
A `section class` looks like this:
.. code-block:: python
Sections and Sub-Sections
class SectionName(BaseSection):
\'\'\' Section description \'\'\'
m_def = Section(**section_attributes)
.. _metainfo-sections:
quantity_name = Quantity(**quantity_attributes)
sub_section_name = SubSection(**sub_section_attributes)
The various Python elements of this class are mapped to a respective *section definition*.
The ``SectionName`` becomes the *name*. The
``BaseSection`` is either :class:`MSection` or another *section class*. The
``section_attributes`` become additional attributes of the `section definition`. The
various ``Quantity`` and ``SubSection`` become the *quantities* and *sub sections*.
The NOMAD Metainfo allows to create hierarchical (meta-)data structures. A hierarchy
is basically a tree, where *sections* make up the root and inner nodes of the tree,
and *quantities* are the leaves of the tree. In this sense a section can hold further
sub-sections (more branches of the tree) and quantities (leaves). We say a section can
have two types of *properties*: *sub-sections* and *quantities*.
Each *section class* has to directly or indirectly extend :class:`MSection`. This will
provided certain class and object features to all *section classes* and all *section instances*.
Read :ref:metainfo-reflection to learn more.
There is a clear distinction between *section* and *sub-section*. The term *section*
refers to an object that holds data (*properties*) and the term *sub-section* refers to a
relation between *sections*, i.e. between the containing section and the contained
sections of the same type. Furthermore, we have to distinguish between *sections* and
*section definitions*, as well as *sub-sections* and *sub-section definitions*. A *section
definition* defines the possible properties of its instances, and an instantiating *section*
can store quantities and sub-sections according to its definition. A *sub-section*
definition defines a principle containment relationship between two *section definitions*
and a *sub-section* is a set of *sections* (contents) contained in another *section* (container).
*Sub-section definitions* are parts (*properties*) of the definition of containing sections.
.. autoclass:: Section
.. autoclass:: SubSection
.. _metainfo-categories:
.. autoclass:: Quantity
In the old meta-info this was known as `abstract types`.
Categories are defined with Python classes that have :class:`MCategory` as base class.
......@@ -210,6 +226,7 @@ Custom data types
.. autoclass:: MEnum
.. _metainfo-reflection:
Reflection and custom data storage
......@@ -253,7 +270,7 @@ object when a respective quantity is accessed.
.. autoclass:: MProxy
.. autoclass:: MResource
# Copyright 2018 Markus Scheidgen
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an"AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.
''' An example metainfo package. '''
import numpy as np
......@@ -63,10 +49,9 @@ class System(MSection):
lattice_vectors = Quantity(
type=np.dtype('f'), shape=[3, 3], unit=ureg.m, categories=[SystemHash],
description='The lattice vectors of the simulated unit cell.')
unit_cell = Quantity(synonym_for='lattice_vectors')
periodic_dimensions = Quantity(
type=bool, shape=[3], default=[False, False, False], categories=[SystemHash],
description='A vector of booleans indicating in which dimensions the unit cell is repeated.')
This diff is collapsed.
......@@ -198,6 +198,29 @@ class TestM2:
m_def = Section(extends_base_section=True)
name = Quantity(type=int)
def test_alias(self):
class SubTest(MSection):
class Test(MSection):
one = Quantity(type=str, aliases=['two', 'three'])
section_one = SubSection(sub_section=SubTest, aliases=['section_two'])
t = Test() = 'value 1'
assert == 'value 1'
assert t.two == 'value 1'
assert t.three == 'value 1'
t.two = 'value 2'
assert == 'value 2'
assert t.two == 'value 2'
assert t.three == 'value 2'
sub_section = t.m_create(SubTest)
assert t.section_one == sub_section
assert t.section_two == sub_section
def test_multiple_sub_sections(self):
class TestSection(MSection): # pylint: disable=unused-variable
one = SubSection(sub_section=System)
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