[untested] creates child classes of Material for Substrates and Targets
This commit is contained in:
@@ -108,8 +108,10 @@ class Material:
|
|||||||
'''
|
'''
|
||||||
def __init__(self, material_data):
|
def __init__(self, material_data):
|
||||||
try:
|
try:
|
||||||
|
self.name = material_data["title"] # required
|
||||||
self.extra = material_data["metadata_decoded"]["extra_fields"]
|
self.extra = material_data["metadata_decoded"]["extra_fields"]
|
||||||
self.compound_elabid = self.extra["Compound"]["value"]
|
self.compound_elabid = self.extra["Compound"]["value"]
|
||||||
|
self.dimensions = self.extra["Size"]["value"]
|
||||||
except KeyError as k:
|
except KeyError as k:
|
||||||
# Some keys are not required and can be called through the .get() method - which is permissive and allows null values;
|
# Some keys are not required and can be called through the .get() method - which is permissive and allows null values;
|
||||||
# Other keys are required so if they can't be called (invalid or null) raise error and stop execution of the program:
|
# Other keys are required so if they can't be called (invalid or null) raise error and stop execution of the program:
|
||||||
@@ -130,6 +132,32 @@ class Material:
|
|||||||
formula = self.get_compound_data(apikey).get("chemical_formula")
|
formula = self.get_compound_data(apikey).get("chemical_formula")
|
||||||
return formula
|
return formula
|
||||||
|
|
||||||
|
class Substrate(Material):
|
||||||
|
def __init__(self, material_data):
|
||||||
|
super().__init__(material_data)
|
||||||
|
try:
|
||||||
|
self.orientation = self.extra["Orientation"]["value"]
|
||||||
|
self.miscut_angle = self.extra["Miscut Angle"]["value"]
|
||||||
|
self.miscut_direction = self.extra["Miscut Direction"]["value"]
|
||||||
|
# Not present (yet) on eLabFTW for Substrates:
|
||||||
|
self.thickness = None #self.extra["Thickness"]["value"]
|
||||||
|
self.surface_treatment = self.extra["Surface treatment"]["value"]
|
||||||
|
self.manufacturer = self.extra["Supplier"]["value"]
|
||||||
|
self.batch_id = self.extra["Batch ID"]["value"]
|
||||||
|
except KeyError as k:
|
||||||
|
raise KeyError(f"The provided dictionary lacks a \"{k}\" key - which is specific for substrates. Check the {self.name} substrate entry on eLabFTW and make sure you used the correct Resource template.")
|
||||||
|
|
||||||
|
class Target(Material):
|
||||||
|
def __init__(self, material_data):
|
||||||
|
super().__init__(material_data)
|
||||||
|
try:
|
||||||
|
self.thickness = self.extra["Thickness"]["value"]
|
||||||
|
self.shape = self.extra["shape"]["value"]
|
||||||
|
self.solid_form = self.extra["Solid form"]["value"]
|
||||||
|
self.manufacturer = self.extra["Supplier"]["value"]
|
||||||
|
except KeyError as k:
|
||||||
|
raise KeyError(f"The provided dictionary lacks a \"{k}\" key - which is specific for PLD targets. Check the {self.name} target entry on eLabFTW and make sure you used the correct Resource template.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user