Skip to content

Commit 1ff3610

Browse files
Added Activity ID to ExperiementStep
Added a `lab_id` property to the `ExperimentStep` section for specifying the activity by readable ID. Added a normalizer to the `ExperimentStep` section which fetches the activity reference from the readable ID and vice versa. The normlizer also fills the start time of the `ExperimentStep` with the `datetime` property of the referenced activity if no start time is given. Changelog: Added
1 parent 0cc1f74 commit 1ff3610

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

gui/tests/artifacts.js

+19
Original file line numberDiff line numberDiff line change
@@ -62724,6 +62724,25 @@ window.nomadArtifacts = {
6272462724
"type_kind": "reference",
6272562725
"type_data": "/packages/15/section_definitions/3"
6272662726
}
62727+
},
62728+
{
62729+
"m_def": "nomad.metainfo.metainfo.Quantity",
62730+
"m_parent_index": 1,
62731+
"m_parent_sub_section": "quantities",
62732+
"m_annotations": {
62733+
"eln": [
62734+
{
62735+
"component": "StringEditQuantity",
62736+
"label": "Activity ID"
62737+
}
62738+
]
62739+
},
62740+
"name": "lab_id",
62741+
"description": "The readable identifier for the activity.",
62742+
"type": {
62743+
"type_kind": "python",
62744+
"type_data": "str"
62745+
}
6272762746
}
6272862747
]
6272962748
},

nomad/datamodel/metainfo/basesections.py

+53
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,59 @@ class ExperimentStep(ActivityStep):
471471
component='ReferenceEditQuantity',
472472
),
473473
)
474+
lab_id = Quantity(
475+
type=str,
476+
description='''
477+
The readable identifier for the activity.
478+
''',
479+
a_eln=ELNAnnotation(
480+
component='StringEditQuantity',
481+
label='Activity ID',
482+
),
483+
)
484+
485+
def normalize(self, archive, logger: 'BoundLogger') -> None:
486+
'''
487+
The normalizer for the `ExperimentStep` class.
488+
Will attempt to fill the `activity` from the `lab_id` or vice versa.
489+
If the activity reference is filled but the start time is not the time will be
490+
taken from the `datetime` property of the referenced activity.
491+
492+
Args:
493+
archive (EntryArchive): The archive containing the section that is being
494+
normalized.
495+
logger ('BoundLogger'): A structlog logger.
496+
'''
497+
super(ExperimentStep, self).normalize(archive, logger)
498+
if self.activity is None and self.lab_id is not None:
499+
from nomad.search import search, MetadataPagination
500+
query = {
501+
'results.eln.lab_ids': self.lab_id
502+
}
503+
search_result = search(
504+
owner='all',
505+
query=query,
506+
pagination=MetadataPagination(page_size=1),
507+
user_id=archive.metadata.main_author.user_id)
508+
if search_result.pagination.total > 0:
509+
entry_id = search_result.data[0]["entry_id"]
510+
upload_id = search_result.data[0]["upload_id"]
511+
self.activity = f'../uploads/{upload_id}/archive/{entry_id}#data'
512+
if search_result.pagination.total > 1:
513+
logger.warn(
514+
f'Found {search_result.pagination.total} entries with lab_id: '
515+
f'"{self.lab_id}". Will use the first one found.'
516+
)
517+
else:
518+
logger.warn(
519+
f'Found no entries with lab_id: "{self.lab_id}".'
520+
)
521+
elif self.lab_id is None and self.activity is not None:
522+
self.lab_id = self.activity.lab_id
523+
if self.name is None and self.lab_id is not None:
524+
self.name = self.lab_id
525+
if self.activity is not None and self.start_time is None and self.activity.datetime:
526+
self.start_time = self.activity.datetime
474527

475528

476529
class Experiment(Activity):

0 commit comments

Comments
 (0)