From f790909a2ecfdc888c9c4c71f78b0c8ed0e68fd7 Mon Sep 17 00:00:00 2001 From: Julia Schumann <32182254+schumannj@users.noreply.github.com> Date: Fri, 26 Jul 2024 14:34:52 +0000 Subject: [PATCH] rename schema to catalysis --- .../{schema.py => catalysis.py} | 8 +++- .../schema_packages/mypackage.py | 38 ------------------- tests/data/test.archive.yaml | 2 +- 3 files changed, 7 insertions(+), 41 deletions(-) rename src/nomad_catalysis/schema_packages/{schema.py => catalysis.py} (98%) delete mode 100644 src/nomad_catalysis/schema_packages/mypackage.py diff --git a/src/nomad_catalysis/schema_packages/schema.py b/src/nomad_catalysis/schema_packages/catalysis.py similarity index 98% rename from src/nomad_catalysis/schema_packages/schema.py rename to src/nomad_catalysis/schema_packages/catalysis.py index d96a51c..250fef6 100644 --- a/src/nomad_catalysis/schema_packages/schema.py +++ b/src/nomad_catalysis/schema_packages/catalysis.py @@ -60,7 +60,10 @@ class CatalysisElnCategory(EntryDataCategory): def add_catalyst(archive: 'EntryArchive') -> None: - """Adds metainfo structure for catalysis data to the results section of the supplied archive.""" + ''' + Adds metainfo structure for catalysis data to the results section of the supplied + archive. + ''' if not archive.results: archive.results = Results() if not archive.results.properties: @@ -71,8 +74,8 @@ def add_catalyst(archive: 'EntryArchive') -> None: archive.results.properties.catalytic.catalyst = Catalyst() -# helper function to retrieve nested attributes def get_nested_attr(obj, attr_path): + '''helper function to retrieve nested attributes''' for attr in attr_path.split('.'): obj = getattr(obj, attr, None) if obj is None: @@ -81,6 +84,7 @@ def get_nested_attr(obj, attr_path): def set_nested_attr(obj, attr_path, value): + '''helper function to set nested attributes''' for attr in attr_path.split('.'): obj = getattr(obj, attr, None) if obj is None: diff --git a/src/nomad_catalysis/schema_packages/mypackage.py b/src/nomad_catalysis/schema_packages/mypackage.py deleted file mode 100644 index 1bdc891..0000000 --- a/src/nomad_catalysis/schema_packages/mypackage.py +++ /dev/null @@ -1,38 +0,0 @@ -from typing import ( - TYPE_CHECKING, -) - -if TYPE_CHECKING: - from nomad.datamodel.datamodel import ( - EntryArchive, - ) - from structlog.stdlib import ( - BoundLogger, - ) - -from nomad.config import config -from nomad.datamodel.data import Schema -from nomad.datamodel.metainfo.annotations import ELNAnnotation, ELNComponentEnum -from nomad.metainfo import Quantity, SchemaPackage - -configuration = config.get_plugin_entry_point( - 'nomad_catalysis.schema_packages:mypackage' -) - -m_package = SchemaPackage() - - -class MySchema(Schema): - name = Quantity( - type=str, a_eln=ELNAnnotation(component=ELNComponentEnum.StringEditQuantity) - ) - message = Quantity(type=str) - - def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: - super().normalize(archive, logger) - - logger.info('MySchema.normalize', parameter=configuration.parameter) - self.message = f'Hello {self.name}!' - - -m_package.__init_metainfo__() diff --git a/tests/data/test.archive.yaml b/tests/data/test.archive.yaml index 22be3a7..c57f444 100644 --- a/tests/data/test.archive.yaml +++ b/tests/data/test.archive.yaml @@ -1,5 +1,5 @@ data: - m_def: nomad_catalysis.schema_packages.schema.CatalystSample + m_def: nomad_catalysis.schema_packages.catalysis.CatalystSample name: MoO3 catalyst_type: ['bulk catalyst'] description: 'Pressing and sieving of 24.22 g, Pressing conditions: 3 t, 1 min'