ems.py 5.41 KB
Newer Older
Markus Scheidgen's avatar
Markus Scheidgen committed
1
2
3
4
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
5
6
7
8
9
#
# 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
#
Markus Scheidgen's avatar
Markus Scheidgen committed
10
#     http://www.apache.org/licenses/LICENSE-2.0
11
12
#
# Unless required by applicable law or agreed to in writing, software
Markus Scheidgen's avatar
Markus Scheidgen committed
13
# distributed under the License is distributed on an "AS IS" BASIS,
14
15
16
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Markus Scheidgen's avatar
Markus Scheidgen committed
17
#
18

19
'''
20
Experimental material science specific metadata
21
'''
22
from nomad import config
Markus Scheidgen's avatar
Markus Scheidgen committed
23
from nomad.metainfo import Quantity, MSection, Section, Datetime
24
from nomad.metainfo.search_extension import Search
25
26


27
28
29
30
31
32
33
def _unavailable(value):
    if value is None:
        return config.services.unavailable_value

    return value


34
35
class EMSMetadata(MSection):
    m_def = Section(a_domain='ems')
36

37
    # sample quantities
38
39
40
    chemical = Quantity(type=str, a_search=Search())
    sample_constituents = Quantity(type=str, a_search=Search())
    sample_microstructure = Quantity(type=str, a_search=Search())
41

42
    # general metadata
43
44
45
    experiment_summary = Quantity(type=str, a_search=Search())
    origin_time = Quantity(type=Datetime, a_search=Search())
    experiment_location = Quantity(type=str, a_search=Search())
46

47
    # method
48
49
50
    method = Quantity(type=str, a_search=Search())
    data_type = Quantity(type=str, a_search=Search())
    probing_method = Quantity(type=str, a_search=Search())
51

52
    # origin metadata
53
54
55
56
    repository_name = Quantity(type=str, a_search=Search())
    repository_url = Quantity(type=str, a_search=Search())
    entry_repository_url = Quantity(type=str, a_search=Search())
    preview_url = Quantity(type=str, a_search=Search())
57

58
    # TODO move to more a general metadata section
59
60
    quantities = Quantity(type=str, shape=['0..*'], default=[], a_search=Search())
    group_hash = Quantity(type=str, a_search=Search())
61

Markus Scheidgen's avatar
Markus Scheidgen committed
62
    def apply_domain_metadata(self, entry_archive):
63
64
        from nomad import utils

Markus Scheidgen's avatar
Markus Scheidgen committed
65
        if entry_archive is None:
66
67
            return

68
        entry = self.m_parent
69

70
        root_section = entry_archive.section_measurement[0]
71

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
        sample = root_section.section_metadata.section_sample
        entry.formula = config.services.unavailable_value
        if sample:
            # TODO deal with multiple materials
            material = sample.section_material[0] if len(sample.section_material) > 0 else None
            if material:
                entry.formula = _unavailable(material.formula)
                atoms = material.elements

                if atoms is None:
                    entry.atoms = []
                else:
                    if hasattr(atoms, 'tolist'):
                        atoms = atoms.tolist()
                    entry.n_atoms = len(atoms)

                    atoms = list(set(atoms))
                    atoms.sort()
                    entry.atoms = atoms

                if material.name:
                    self.chemical = _unavailable(material.name)
                else:
                    self.chemical = _unavailable(material.formula)

            self.sample_microstructure = _unavailable(sample.sample_microstructure)
            self.sample_constituents = _unavailable(sample.sample_constituents)
99
100

        self.experiment_summary = root_section.section_metadata.section_experiment.notes
101
102
103
104
105
106
107
        location = root_section.section_metadata.section_experiment.experiment_location
        if location is not None:
            location_str = ', '.join([
                getattr(location, prop)
                for prop in ['facility', 'institution', 'address']
                if getattr(location, prop) is not None])
            self.experiment_location = location_str
108
109
110
111
112

        if root_section.section_metadata.section_experiment.experiment_start_time:
            self.origin_time = root_section.section_metadata.section_experiment.experiment_start_time
        elif root_section.section_metadata.section_experiment.experiment_publish_time:
            self.origin_time = root_section.section_metadata.section_experiment.experiment_publish_time
113
114
115
        else:
            self.origin_time = self.m_parent.upload_time

116
117
118
        # self.data_type = _unavailable(root_section.section_method.data_type)
        self.method = _unavailable(root_section.section_metadata.section_experiment.method_name)
        # self.probing_method = _unavailable(root_section.section_method.probing_method)
119

120
        self.repository_name = _unavailable(root_section.section_metadata.section_origin.repository_name)
121
122
123
        self.repository_url = root_section.section_metadata.section_origin.repository_url
        self.preview_url = root_section.section_metadata.section_origin.preview_url
        self.entry_repository_url = root_section.section_metadata.section_origin.entry_repository_url
124
125

        self.group_hash = utils.hash(
126
            entry.formula,
127
            self.method,
128
            self.experiment_location,
129
130
            entry.with_embargo,
            entry.uploader)
131
132
133

        quantities = set()

134
135
136
        quantities.add(root_section.m_def.name)
        for _, property_def, _ in root_section.m_traverse():
            quantities.add(property_def.name)
137
138

        self.quantities = list(quantities)
139
140
141

        if self.m_parent.references is None:
            self.m_parent.references = [self.entry_repository_url]