@@ -279,6 +279,51 @@ def generate_structures(structure: Atoms, factor_lst: list) -> dict:
279279 print (key , value )
280280
281281
282+ ######################################################################
283+ # --------------------------
284+ # Nested Namespace
285+ # --------------------------
286+ #
287+ # One can also define nested namespace outputs by specifying the "ports" parameter.
288+
289+
290+ def generate_structures (structure : Atoms , factor_lst : list ) -> dict :
291+ """Scale the structure by the given factor_lst."""
292+ scaled_structures = {}
293+ volumes = {}
294+ for i in range (len (factor_lst )):
295+ atoms = structure .copy ()
296+ atoms .set_cell (atoms .cell * factor_lst [i ], scale_atoms = True )
297+ scaled_structures [f"s_{ i } " ] = atoms
298+ volumes [f"v_{ i } " ] = atoms .get_volume ()
299+ return {
300+ "outputs" : {
301+ "scaled_structures" : scaled_structures ,
302+ "volume" : volumes ,
303+ }
304+ }
305+
306+
307+ inputs = prepare_pythonjob_inputs (
308+ generate_structures ,
309+ function_inputs = {"structure" : bulk ("Al" ), "factor_lst" : [0.95 , 1.0 , 1.05 ]},
310+ output_ports = [
311+ {
312+ "name" : "outputs" ,
313+ "identifier" : "namespace" ,
314+ "ports" : [
315+ {"name" : "scaled_structures" , "identifier" : "namespace" },
316+ {"name" : "volume" , "identifier" : "namespace" },
317+ ],
318+ }
319+ ],
320+ )
321+
322+ result , node = run_get_node (PythonJob , inputs = inputs )
323+ print ("result: " , result ["outputs" ]["scaled_structures" ])
324+ print ("volumes: " , result ["outputs" ]["volume" ])
325+
326+
282327######################################################################
283328# What if my calculation fails?
284329# --------------------------------
0 commit comments