1+ import hashlib
2+
3+
14def classic_structure (
25 pr , structure , structure_name , options , is_init_struct : bool , init_structure = None
36):
@@ -8,6 +11,8 @@ def classic_structure(
811
912 hdf = FileHDFio (structure_path + structure_name + ".h5" )
1013 structure .to_hdf (hdf )
14+ with open (hdf .file_name , "rb" , buffering = 0 ) as f :
15+ hdf5_hash = hashlib .file_digest (f , "md5" ).hexdigest ()
1116
1217 from pyiron_rdm .concept_dict import (
1318 get_unit_cell_parameters ,
@@ -31,6 +36,7 @@ def classic_structure(
3136 structure_path = structure_path ,
3237 structure_parameters = struct_params ,
3338 options = options ,
39+ md5hash = hdf5_hash ,
3440 )
3541
3642 return struct_cdict
@@ -144,7 +150,7 @@ def validate_upload_options(ot_module: str, options: dict):
144150
145151 importlib .import_module (ot_module ).validate_options (** options )
146152
147- if "materials" in options and not isinstance (materials , list ):
153+ if "materials" in options and not isinstance (options [ " materials" ] , list ):
148154 options ["materials" ] = [options ["materials" ]]
149155 if "pseudopotentials" in options and not isinstance (
150156 options ["pseudopotentials" ], list
@@ -260,17 +266,13 @@ def get_cdicts_to_validate(
260266 return cdicts_to_validate
261267
262268
263- def upload_classic_pyiron (
269+ def create_concept_dicts (
264270 job ,
265271 o ,
266- space : str ,
267- project : str ,
268- collection : str | None = None ,
269272 export_env_file : bool = True ,
270273 is_init_struct : bool = True ,
271274 init_structure = None ,
272275 options : dict | None = None ,
273- require_parents : bool = True ,
274276):
275277 # TODO should this return anything?
276278 if options is not None :
@@ -291,12 +293,6 @@ def upload_classic_pyiron(
291293
292294 export_env (pr .path + pr .name )
293295
294- if collection is None :
295- collection = pr .name
296- space = space .upper ()
297- project = project .upper ()
298- collection = collection .upper ()
299-
300296 # ------------------------------------VALIDATION----------------------------------------------
301297 is_sfb = get_datamodel (o ) == "sfb1394"
302298
@@ -309,18 +305,50 @@ def upload_classic_pyiron(
309305 upload_final_struct = is_sfb ,
310306 )
311307
312- from pyiron_rdm .ob_upload import openbis_validate , validate_ob_destination
308+ return cdicts_to_validate
309+
310+
311+ def validate_openbis_destination (o , space : str , project : str , collection : str ):
312+ from pyiron_rdm .ob_upload import validate_ob_destination
313+
314+ space = space .upper ()
315+ project = project .upper ()
316+ collection = collection .upper ()
313317
314318 validate_ob_destination (o = o , space = space , project = project , collection = collection )
319+ return space , project , collection
320+
321+
322+ def validate_concept_dicts (
323+ cdicts_to_validate : list [dict ],
324+ o ,
325+ options : dict | None = None ,
326+ require_parents : bool = True ,
327+ ):
328+
329+ from pyiron_rdm .ob_upload import openbis_validate
330+
331+ options = options if options is not None else {}
315332
316333 validated_to_upload = openbis_validate (
317334 o = o ,
318335 concept_dicts = cdicts_to_validate ,
319336 options = options ,
320337 require_parents = require_parents ,
321338 )
339+
340+ return validated_to_upload
322341 # ---------------------------------------------------------------------------------------------
323342
343+
344+ def upload_cdicts_to_openbis (
345+ validated_to_upload : list [dict ],
346+ o ,
347+ space : str ,
348+ project : str ,
349+ collection : str | None = None ,
350+ ):
351+
324352 # --------------------------------------UPLOAD-------------------------------------------------
325353 from pyiron_rdm .ob_upload import openbis_upload_validated
326354
@@ -332,6 +360,7 @@ def upload_classic_pyiron(
332360 ** validated_to_upload ["structure" ],
333361 )
334362
363+ is_sfb = get_datamodel (o ) == "sfb1394"
335364 if is_sfb :
336365 job_parents = None # job does not have init structure as parent
337366 str_parent = ob_structure_id # equil structure has init as parent
@@ -386,3 +415,51 @@ def upload_classic_pyiron(
386415 ** validated_to_upload ["final_structure" ],
387416 parent_ids = [ob_structure_id , ob_job_id ],
388417 )
418+
419+
420+ def upload_classic_pyiron (
421+ job ,
422+ o ,
423+ space : str ,
424+ project : str ,
425+ collection : str | None = None ,
426+ export_env_file : bool = True ,
427+ is_init_struct : bool = True ,
428+ init_structure = None ,
429+ options : dict | None = None ,
430+ require_parents : bool = True ,
431+ ):
432+ # Create JSON-LD conceptual dictionaries for the job
433+ cdicts_to_validate = create_concept_dicts (
434+ job ,
435+ o ,
436+ export_env_file = export_env_file ,
437+ is_init_struct = is_init_struct ,
438+ init_structure = init_structure ,
439+ options = options ,
440+ )
441+
442+ # Set sensible default if collection is not given
443+ if collection is None :
444+ collection = job .pr .name
445+
446+ # Validate openbis destination
447+ space , project , collection = validate_openbis_destination (
448+ o , space = space , project = project , collection = collection
449+ )
450+
451+ # Validate conceptual dictionary compatibility to openBIS instance
452+ validated_to_upload = validate_concept_dicts (
453+ cdicts_to_validate = cdicts_to_validate ,
454+ o = o ,
455+ options = options ,
456+ require_parents = require_parents ,
457+ )
458+
459+ upload_cdicts_to_openbis (
460+ validated_to_upload = validated_to_upload ,
461+ o = o ,
462+ space = space ,
463+ project = project ,
464+ collection = collection ,
465+ )
0 commit comments