4747 InstrumentReference ,
4848 Measurement ,
4949 )
50+ from nomad .datamodel .metainfo .workflow import Link , Task , Workflow
5051 from nomad .metainfo import (
5152 Attribute ,
5253 Bytes ,
@@ -118,11 +119,14 @@ def normalize(self, archive, logger):
118119 app_entry = getattr (self , "ENTRY" )
119120 if len (app_entry ) < 1 :
120121 raise AttributeError ()
121- self .steps = app_entry
122+ self .steps = []
122123 for entry in app_entry :
124+ sec_c = entry .m_copy ()
125+ self .steps .append (sec_c )
123126 for sec in entry .m_all_contents ():
124127 if isinstance (sec , ActivityStep ):
125- self .steps .append (sec )
128+ sec_c = sec .m_copy ()
129+ self .steps .append (sec_c )
126130 elif isinstance (sec , basesections .Instrument ):
127131 ref = InstrumentReference (name = sec .name )
128132 ref .reference = sec
@@ -132,14 +136,52 @@ def normalize(self, archive, logger):
132136 ref .reference = sec
133137 self .samples .append (ref )
134138 elif isinstance (sec , ActivityResult ):
135- self .results .append (sec )
139+ sec_c = sec .m_copy ()
140+ self .results .append (sec_c )
136141 if self .m_def .name == "Root" :
137142 self .method = "Generic Experiment"
138143 else :
139144 self .method = self .m_def .name + " Experiment"
140145 except (AttributeError , TypeError ):
141146 pass
142- super (NexusMeasurement , self ).normalize (archive , logger )
147+ super (basesections .Activity , self ).normalize (archive , logger )
148+
149+ if archive .results .eln .methods is None :
150+ archive .results .eln .methods = []
151+ if self .method :
152+ archive .results .eln .methods .append (self .method )
153+ else :
154+ archive .results .eln .methods .append (self .m_def .name )
155+ if archive .workflow2 is None :
156+ archive .workflow2 = Workflow (name = self .name )
157+ # steps to tasks
158+ act_array = archive .workflow2 .tasks
159+ existing_items = {(task .name , task .section ) for task in act_array }
160+ new_items = [
161+ item .to_task ()
162+ for item in self .steps
163+ if (item .name , item ) not in existing_items
164+ ]
165+ act_array .extend (new_items )
166+ # samples to inputs
167+ act_array = archive .workflow2 .inputs
168+ existing_items = {(link .name , link .section ) for link in act_array }
169+ new_items = [
170+ Link (name = item .name , section = item .reference )
171+ for item in self .samples
172+ if (item .name , item .reference ) not in existing_items
173+ ]
174+ act_array .extend (new_items )
175+
176+ # results to outputs
177+ act_array = archive .workflow2 .outputs
178+ existing_items = {(link .name , link .section ) for link in act_array }
179+ new_items = [
180+ Link (name = item .name , section = item )
181+ for item in self .results
182+ if (item .name , item ) not in existing_items
183+ ]
184+ act_array .extend (new_items )
143185
144186
145187VALIDATE = False
@@ -952,7 +994,7 @@ def normalize_sample(self, archive, logger):
952994 """Normalizer for sample section."""
953995 current_cls = __section_definitions [__rename_nx_for_nomad ("NXsample" )].section_cls
954996 self .name = self .__dict__ ["nx_name" ] + (
955- "(" + self .name__field + ")" if self .name__field else ""
997+ " (" + self .name__field + ")" if self .name__field else ""
956998 )
957999 # one could also copy local ids to identifier for search purposes
9581000 super (current_cls , self ).normalize (archive , logger )
@@ -964,7 +1006,7 @@ def normalize_entry(self, archive, logger):
9641006 if self .start_time__field :
9651007 self .start_time = self .start_time__field
9661008 self .name = self .__dict__ ["nx_name" ] + (
967- "(" + self .title__field + ")" if self .title__field is not None else ""
1009+ " (" + self .title__field + ")" if self .title__field is not None else ""
9681010 )
9691011 # one could also copy local ids to identifier for search purposes
9701012 super (current_cls , self ).normalize (archive , logger )
@@ -998,7 +1040,7 @@ def create_Entity(lab_id, archive, f_name):
9981040 data = entitySec ,
9991041 m_context = archive .m_context ,
10001042 metadata = EntryMetadata (
1001- entry_type = "identifier" , domain = "nexus"
1043+ entry_type = "identifier" , domain = "nexus" , readonly = True
10021044 ), # upload_id=archive.m_context.upload_id,
10031045 )
10041046 with archive .m_context .raw_file (f_name , "w" ) as f_obj :
@@ -1039,8 +1081,12 @@ def get_entry_reference(archive, f_name):
10391081 __rename_nx_for_nomad ("NXsample" ): normalize_sample ,
10401082 __rename_nx_for_nomad ("NXsample_component" ): normalize_sample_component ,
10411083 __rename_nx_for_nomad ("NXidentifier" ): normalize_identifier ,
1042- __rename_nx_for_nomad ("NXentry" ): normalize_entry ,
1043- __rename_nx_for_nomad ("NXprocess" ): normalize_process ,
1084+ __rename_nx_for_nomad ("NXentry" ): {
1085+ "normalize" : normalize_entry ,
1086+ },
1087+ __rename_nx_for_nomad ("NXprocess" ): {
1088+ "normalize" : normalize_process ,
1089+ },
10441090 __rename_nx_for_nomad ("NXdata" ): normalize_data ,
10451091}
10461092
@@ -1053,4 +1099,8 @@ def get_entry_reference(archive, f_name):
10531099
10541100 # Append the normalize method from a function
10551101 if normalize_func :
1056- section .section_cls .normalize = normalize_func
1102+ if isinstance (normalize_func , dict ):
1103+ for key , value in normalize_func .items ():
1104+ setattr (section .section_cls , key , value )
1105+ else :
1106+ section .section_cls .normalize = normalize_func
0 commit comments