def __init__(self,
                 name: str,
                 *,
                 spec: Union[MaterialSpec, LinkByUID] = None,
                 process: Union[ProcessRun, LinkByUID] = None,
                 sample_type: Union[SampleType, str] = "unknown",
                 uids: Mapping[str, str] = None,
                 tags: Iterable[str] = None,
                 notes: str = None,
                 file_links: Optional[Union[Iterable[FileLink],
                                            FileLink]] = None):
        from gemd.entity.object.measurement_run import MeasurementRun
        BaseObject.__init__(self,
                            name=name,
                            uids=uids,
                            tags=tags,
                            notes=notes,
                            file_links=file_links)
        HasSpec.__init__(self, spec=spec)
        self._process = None
        self._measurements = validate_list(None, [MeasurementRun, LinkByUID])
        self._sample_type = None

        self.process = process
        self.sample_type = sample_type
    def parameters(self, parameters):
        lst = validate_list(parameters, (ParameterTemplate, LinkByUID, list, tuple))

        # make sure attribute can be a Parameter
        # TODO: list.map(_.validate_scope(AttributeType.PARAMETER)) all true

        self._parameters = list(map(BaseTemplate._homogenize_ranges, lst))
Example #3
0
    def conditions(self,
                   conditions: Iterable[Union[Union[ConditionTemplate,
                                                    LinkByUID],
                                              Tuple[Union[ConditionTemplate,
                                                          LinkByUID],
                                                    Optional[BaseBounds]]]]):
        """
        Set the list of condition templates.

        Parameters
        ----------
        conditions: List[(ConditionTemplate, bounds)]
            A list of tuples containing this entity's condition templates as well
            as any restrictions on those templates' bounds.

        Returns
        -------
        List[(ConditionTemplate, bounds)]
            List of this entity's condition template/bounds pairs

        """
        if isinstance(conditions, Iterable):
            if any(isinstance(x, BaseBounds) for x in conditions):
                conditions = [conditions
                              ]  # It's a template/bounds tuple (probably)
        self._conditions = validate_list(
            conditions, (ConditionTemplate, LinkByUID, list, tuple),
            trigger=BaseTemplate._homogenize_ranges)
 def parameters(self, parameters: Iterable[Parameter]):
     """Set the list of parameters."""
     checker = self._generate_template_check(
         HasParameterTemplates.validate_parameter)
     self._parameters = validate_list(parameters,
                                      Parameter,
                                      trigger=checker)
Example #5
0
 def properties(self, properties: Iterable[PropertyAndConditions]):
     """Set the list of property-and-conditions."""
     checker = self._generate_template_check(
         HasPropertyTemplates.validate_property)
     self._properties = validate_list(properties,
                                      PropertyAndConditions,
                                      trigger=checker)
    def __init__(self,
                 name: str,
                 *,
                 template: Optional[Union[ProcessTemplate, LinkByUID]] = None,
                 conditions: Iterable[Condition] = None,
                 parameters: Iterable[Parameter] = None,
                 uids: Mapping[str, str] = None,
                 tags: Iterable[str] = None,
                 notes: str = None,
                 file_links: Optional[Union[Iterable[FileLink],
                                            FileLink]] = None):
        from gemd.entity.object.ingredient_spec import IngredientSpec
        from gemd.entity.link_by_uid import LinkByUID

        BaseObject.__init__(self,
                            name=name,
                            uids=uids,
                            tags=tags,
                            notes=notes,
                            file_links=file_links)
        HasTemplate.__init__(self, template=template)
        HasParameters.__init__(self, parameters=parameters)
        HasConditions.__init__(self, conditions=conditions)

        # By default, a ProcessSpec is not linked to any MaterialSpec.
        # If a MaterialSpec is linked to this ProcessSpec,
        # then the field self._output_material will be automatically populated
        self._output_material = None
        self._ingredients = validate_list(None, [IngredientSpec, LinkByUID])
    def conditions(self, conditions):
        lst = validate_list(conditions, (ConditionTemplate, list, tuple))

        # make sure attribute can be a Condition
        # TODO: list.map(_.validate_scope(AttributeType.CONDITION)) all true

        self._conditions = list(map(BaseTemplate._homogenize_ranges, lst))
Example #8
0
 def spec(self, spec: Union[IngredientSpec, LinkByUID]):
     """Set the spec."""
     if isinstance(self.spec,
                   IngredientSpec):  # Store values if you had them
         self._name = self.spec.name
         self._labels = validate_list(self.spec.labels, str)
     # Note that the super() mechanism does not work properly for overloaded setters
     getattr(HasSpec, "spec").fset(self, spec)
Example #9
0
    def properties(self, properties):
        # make sure the properties are a list
        lst = validate_list(properties, (PropertyTemplate, list, tuple))

        # make sure attribute can be a Property
        # TODO: list.map(_.validate_scope(AttributeType.PROPERTY)) all true

        # convert any templates into (template, bounds) pairs and
        # validate that any (template, bounds) pairs are consistent
        self._properties = list(map(BaseTemplate._homogenize_ranges, lst))
 def process(self, process):
     from gemd.entity.object import ProcessRun
     from gemd.entity.link_by_uid import LinkByUID
     if self._process is not None and isinstance(self._process, ProcessRun):
         self._process._unset_ingredient(self)
     if process is None:
         self._process = None
     elif isinstance(process, ProcessRun):
         self._process = process
         if not isinstance(process.ingredients, ValidList):
             process._ingredients = validate_list(
                 self, [IngredientRun, LinkByUID])
         else:
             process._ingredients.append(self)
     elif isinstance(process, LinkByUID):
         self._process = process
     else:
         raise TypeError("IngredientRun.process must be a ProcessRun or "
                         "LinkByUID: {}".format(process))
Example #11
0
 def material(self, value):
     from gemd.entity.object import MaterialRun
     from gemd.entity.link_by_uid import LinkByUID
     if self._material is not None and isinstance(self._material,
                                                  MaterialRun):
         self._material._unset_measurement(self)
     if value is None:
         self._material = value
     elif isinstance(value, MaterialRun):
         self._material = value
         if not isinstance(value.measurements, ValidList):
             value._measurements = validate_list(
                 self, [MeasurementRun, LinkByUID])
         else:
             value._measurements.append(self)
     elif isinstance(value, LinkByUID):
         self._material = value
     else:
         raise TypeError(
             "material must be a MaterialRun or LinkByUID: {}".format(
                 value))
    def __init__(self,
                 name: str,
                 *,
                 spec: Union[ProcessSpec, LinkByUID] = None,
                 conditions: Iterable[Condition] = None,
                 parameters: Iterable[Parameter] = None,
                 uids: Mapping[str, str] = None,
                 tags: Iterable[str] = None,
                 notes: str = None,
                 file_links: Optional[Union[Iterable[FileLink], FileLink]] = None,
                 source: PerformedSource = None):
        from gemd.entity.object.ingredient_run import IngredientRun

        BaseObject.__init__(self, name=name, uids=uids, tags=tags, notes=notes,
                            file_links=file_links)
        HasSpec.__init__(self, spec=spec)
        HasConditions.__init__(self, conditions)
        HasParameters.__init__(self, parameters)
        HasSource.__init__(self, source)

        self._ingredients = validate_list(None, [IngredientRun, LinkByUID])
        self._output_material = None
Example #13
0
    def from_dict(cls, d: Mapping[str, Any]) -> DictSerializable:
        """
        Overloaded method from DictSerializable to intercept `name` and `labels` fields.

        Parameters
        ----------
        d: dict
            The object as a dictionary of key-value pairs that correspond to the object's fields.

        Returns
        -------
        DictSerializable
            The deserialized object.

        """
        name = d.pop("name", None)
        labels = d.pop("labels", None)
        obj = super().from_dict(d)
        if name is not None:
            obj._name = name
        if labels is not None:
            obj._labels = validate_list(labels, str)
        return obj
    def properties(self,
                   properties: Iterable[Union[Union[PropertyTemplate,
                                                    LinkByUID],
                                              Tuple[Union[PropertyTemplate,
                                                          LinkByUID],
                                                    Optional[BaseBounds]]]]):
        """
        Set the list of parameter templates.

        Parameters
        ----------
        properties: List[(PropertyTemplate, bounds)]
            A list of tuples containing this entity's property templates as well
            as any restrictions on those templates' bounds.

        """
        if isinstance(properties, Iterable):
            if any(isinstance(x, BaseBounds) for x in properties):
                properties = [properties
                              ]  # It's a template/bounds tuple (probably)
        self._properties = validate_list(
            properties, (PropertyTemplate, LinkByUID, list, tuple),
            trigger=BaseTemplate._homogenize_ranges)
 def tags(self, tags: Iterable[str]):
     self._tags = validate_list(tags, str)
Example #16
0
 def properties(self, properties):
     self._properties = validate_list(properties, PropertyAndConditions)
 def file_links(self, file_links: Union[Iterable[FileLink], FileLink]):
     self._file_links = validate_list(file_links, FileLink)
 def file_links(self, file_links):
     self._file_links = validate_list(file_links, FileLink)
 def allowed_labels(self, allowed_labels):
     # if none, leave as none; don't set to the empty set
     if allowed_labels is None:
         self._allowed_labels = allowed_labels
     else:
         self._allowed_labels = validate_list(allowed_labels, str)
 def allowed_labels(self, allowed_labels):
     if allowed_labels is None:
         self._allowed_labels = validate_list([], str)
     else:
         self._allowed_labels = validate_list(allowed_labels, str)
 def allowed_names(self, allowed_names):
     if allowed_names is None:
         self._allowed_names = validate_list([], str)
     else:
         self._allowed_names = validate_list(allowed_names, str)
 def labels(self, labels: Iterable[str]):
     self._labels = validate_list(labels, str)
 def properties(self, properties):
     self._properties = validate_list(properties, Property)
 def labels(self, labels):
     self._labels = validate_list(labels, str)
 def conditions(self, conditions: Iterable[Condition]):
     self._conditions = validate_list(conditions, Condition)
Example #26
0
 def conditions(self, conditions):
     self._conditions = validate_list(conditions, Condition)
 def conditions(self, conditions: Iterable[Condition]):
     """Set the list of conditions."""
     checker = self._generate_template_check(HasConditionTemplates.validate_condition)
     self._conditions = validate_list(conditions, Condition, trigger=checker)