MAJOR: main.py successfully produces JSON following NeXus-schema

takes API key and elabid of the "entrypoint" sample as input
returns indented JSON with the reconstructed dataset!
currently lacks instruments_used data (matter of minutes)
and all the layer data (already present in Layer-class objects)
This commit is contained in:
2026-02-13 00:01:24 +01:00
parent 43cfd788f3
commit a12506b8be

View File

@@ -98,9 +98,44 @@ def chain_layer_to_target(layer_object):
material_object = call_material_from_elabid(target_elabid) material_object = call_material_from_elabid(target_elabid)
return material_object return material_object
#sample_object = call_entrypoint_from_elabid(elabid) def make_nexus_schema_dictionary(substrate_object, layers):
#from_entrypoint_to_material(sample_object) pld_fabrication = {
"sample": {
"substrate": {
"name": substrate_object.name,
"chemical_formula" : substrate_object.get_compound_formula(apikey),
"orientation" : substrate_object.orientation,
"miscut_angle" : substrate_object.miscut_angle,
"miscut_direction" : substrate_object.miscut_direction,
"thickness" : substrate_object.thickness,
"dimensions" : substrate_object.dimensions,
"surface_treatment" : substrate_object.surface_treatment,
"manufacturer" : substrate_object.manufacturer,
"batch_id" : substrate_object.batch_id,
},
"multilayer": {},
},
}
multilayer = pld_fabrication["sample"]["multilayer"]
for layer in layers:
name = "layer_" + layer.layer_number
target_object = chain_layer_to_target(layer)
target_dict = {
"name": target_object.name,
"chemical_formula" : target_object.get_compound_formula(apikey),
"description" : target_object.description,
"shape" : target_object.shape,
"dimensions" : target_object.dimensions,
"thickness" : target_object.thickness,
"solid_form" : target_object.solid_form,
"manufacturer" : target_object.manufacturer,
# TO-DO: currently not available:
# "batch_id" : target_object.batch_id,
}
multilayer[name] = {
"target": target_dict
}
return json.dumps(pld_fabrication, indent=2)
if __name__=="__main__": if __name__=="__main__":
print(f"=======================\n===== DEBUG MODE! =====\n=======================\n") print(f"=======================\n===== DEBUG MODE! =====\n=======================\n")
@@ -109,22 +144,23 @@ if __name__=="__main__":
elabid = input("Enter elabid of your starting sample [default= 1111]: ") or 1111 elabid = input("Enter elabid of your starting sample [default= 1111]: ") or 1111
data = APIHandler(apikey).get_entry_from_elabid(elabid) data = APIHandler(apikey).get_entry_from_elabid(elabid)
sample = Entrypoint(data) sample = Entrypoint(data)
batch = chain_entrypoint_to_batch(sample) # Material-class object substrate_object = chain_entrypoint_to_batch(sample) # Substrate-class object
bd = batch.__dict__ # bd = substrate_object.__dict__ # debug
bd.pop("extra") # bd.pop("extra") # debug
layers = chain_entrypoint_to_layers(sample) # list of Layer-class objects layers = chain_entrypoint_to_layers(sample) # list of Layer-class objects
print(f"Sample name:\n{sample.name}\n") # print(f"Sample name:\n{sample.name}\n") # debug
print(f"Substrate data:\n{bd}\n") # print(f"Substrate data:\n{bd}\n") # debug
print(f"Layers data:") # print(f"Layers data:") # debug
print(make_nexus_schema_dictionary(substrate_object, layers)) # debug
for layer in layers: for layer in layers:
ld = layer.__dict__ # ld = layer.__dict__ # debug
ld.pop("extra") # ld.pop("extra") # debug
tgt = chain_layer_to_target(layer) tgt = chain_layer_to_target(layer) # Target-class object
td = tgt.__dict__ # td = tgt.__dict__ # debug
td.pop("extra") # td.pop("extra") # debug
print(ld) # print(ld) # debug
print(td) # # print(td) # debug
print() # print() # debug
# entryType = None # entryType = None
# while entryType not in ["items", "experiments"]: # while entryType not in ["items", "experiments"]: