Skip to content
Snippets Groups Projects

Draft: Sample ID ELn base class draft

Merged Jose Marquez Prieto requested to merge Sample_id_baseclass into develop
1 unresolved thread
@@ -18,8 +18,9 @@
from nomad import utils
from nomad.datamodel.data import EntryData, ArchiveSection
from nomad.metainfo.metainfo import SectionProxy
from nomad.datamodel.results import ELN, Results, Material
from nomad.metainfo import Package, Quantity, Datetime
from nomad.metainfo import Package, Quantity, Datetime, Reference
m_package = Package(name='material_library')
@@ -186,4 +187,87 @@ class Measurement(ElnActivityBaseSecton):
pass
class SampleID(ArchiveSection):
''' A ELN base section that can be used for sample IDs.
If the `sample_owner`, `sample_short_name`, `ìnstitute`, and `creation_datetime`
quantities are provided, the sample_id will be automatically created as a combination
of these four quantities.'''
# m_def = Section(
# a_eln=dict(hide=['name', 'lab_id']))
institute = Quantity(
type=str,
description='Alias/short name of the home institute of the owner, i.e. *HZB*.',
a_eln=dict(component='StringEditQuantity'))
sample_owner = Quantity(
type=str,
shape=[],
description='Name or alias of the process operator, e.g. jmp',
a_eln=dict(component='StringEditQuantity'))
creation_datetime = Quantity(
type=Datetime,
description='Creation date of the sample.',
a_eln=dict(component='DateTimeEditQuantity'))
sample_short_name = Quantity(
type=str,
description='''A short name of the sample (the identifier scribed on the smaple,
or in the sample container), e.g. 4001-8, YAG-2-34.
This is to be managed and decided internally by the labs,
although we recomend to avoid the following characters on it: "_", "/", "\" and "."''',
a_eln=dict(component='StringEditQuantity'))
sample_id = Quantity(
type=str,
description='''Full sample id. Ideally a human readable sample id convention,
which is simple, understandable and still having chances of becoming unique.
If the `sample_owner`, `sample_short_name`, `ìnstitute`, and `creation_datetime`
are provided, this will be formed automatically by joining these components by an underscore (_).
Spaces in any of the individual components will be replaced with hyphens (-).
An example would be hzb_oah_20200602_4001-08''',
a_eln=dict(component='StringEditQuantity'))
children = Quantity(
type=Reference(SectionProxy('SampleID')),
shape=["*"],
descriptions='A reference to a sample which are children of this one.',
a_eln=dict(component='ReferenceEditQuantity'))
parents = Quantity(
type=Reference(SectionProxy('SampleID')),
descriptions='A reference to sample which are parents of this one.',
a_eln=dict(component='ReferenceEditQuantity'))
def normalize(self, archive, logger):
super().normalize(archive, logger)
if self.institute and self.sample_short_name and self.sample_owner and self.creation_datetime:
Please register or sign in to reply
creation_date = self.creation_datetime.strftime('%Y%m%d')
sample_owner = self.sample_owner.replace(' ', '-')
sample_id_list = [self.institute, sample_owner, creation_date, self.sample_short_name]
self.sample_id = '_'.join(sample_id_list)
if isinstance(self, EntryData):
if archive.data == self and self.sample_id:
archive.metadata.entry_name = self.sample_id.replace('_', ' ')
EntryData.normalize(self, archive, logger)
if not archive.results:
archive.results = Results(eln=ELN())
if not archive.results.eln:
archive.results.eln = ELN()
if self.sample_id:
if archive.results.eln.lab_ids is None:
archive.results.eln.lab_ids = []
archive.results.eln.lab_ids.append(self.sample_id)
if not archive.results.eln.sections:
archive.results.eln.sections = []
archive.results.eln.sections.append(self.m_def.name)
m_package.__init_metainfo__()
Loading