parameters: (self, element)
docstring: Add an element to a work specification if possible.
  
          Adding an element to a WorkSpec must preserve the validity of the workspec, which involves several checks.
          We do not yet check for element uniqueness beyond a string name.
  
          If an element is added that was previously in another WorkSpec, it must first be removed from the
          other WorkSpec.
docstring_summary: Add an element to a work specification if possible.
docstring_tokens: Add an element to a work specification if possible .
function: def add_element(self, element):
          """Add an element to a work specification if possible.
  
          Adding an element to a WorkSpec must preserve the validity of the workspec, which involves several checks.
          We do not yet check for element uniqueness beyond a string name.
  
          If an element is added that was previously in another WorkSpec, it must first be removed from the
          other WorkSpec.
          """
          if hasattr(element, "namespace") and hasattr(element, "operation") and hasattr(element, "serialize"):
              if not hasattr(element, "name") or element.name is None or len(str(element.name)) < 1:
                  raise exceptions.UsageError("Only named elements may be added to a WorkSpec.")
              if element.name in self.elements:
                  raise exceptions.UsageError("Elements in WorkSpec must be uniquely identifiable.")
              if hasattr(element, "depends"):
                  for dependency in element.depends:
                      if not dependency in self.elements:
                          raise exceptions.UsageError(
                              "Element dependencies must already be specified before an Element may be added.")
              # Okay, it looks like we have an element we can add
              if hasattr(element, "workspec") and element.workspec is not None and element.workspec is not self:
                  raise exceptions.Error(
                      "Element must be removed from its current WorkSpec to be added to this WorkSpec, but element "
                      "removal is not yet implemented.")
              self.elements[element.name] = element.serialize()
              element.workspec = self
          else:
              raise exceptions.ValueError(
                  "Provided object does not appear to be compatible with gmx.workflow.WorkElement.")
          logger.info("Added element {} to workspec.".format(element.name))
function_tokens: def add_element ( self , element ) : if hasattr ( element , "namespace" ) and hasattr ( element , "operation" ) and hasattr ( element , "serialize" ) : if not hasattr ( element , "name" ) or element . name is None or len ( str ( element . name ) ) < 1 : raise exceptions . UsageError ( "Only named elements may be added to a WorkSpec." ) if element . name in self . elements : raise exceptions . UsageError ( "Elements in WorkSpec must be uniquely identifiable." ) if hasattr ( element , "depends" ) : for dependency in element . depends : if not dependency in self . elements : raise exceptions . UsageError ( "Element dependencies must already be specified before an Element may be added." ) # Okay, it looks like we have an element we can add if hasattr ( element , "workspec" ) and element . workspec is not None and element . workspec is not self : raise exceptions . Error ( "Element must be removed from its current WorkSpec to be added to this WorkSpec, but element " "removal is not yet implemented." ) self . elements [ element . name ] = element . serialize ( ) element . workspec = self else : raise exceptions . ValueError ( "Provided object does not appear to be compatible with gmx.workflow.WorkElement." ) logger . info ( "Added element {} to workspec." . format ( element . name ) )