code: def calculate_ideal_weight_percent(pif):
      
      if not isinstance(pif, ChemicalSystem):
          return pif
      if not pif.chemical_formula:
          return pif
      else:
          expanded_formula_no_special_char = _expand_formula_(
              pif.chemical_formula)
          element_array = _create_emprical_compositional_array_(
              expanded_formula_no_special_char)
          appended_e_array = _add_ideal_atomic_weights_(element_array)
          a_array_with_pcts = _add_ideal_weight_percent_(appended_e_array)
          for e in a_array_with_pcts:
              # Checks if a Composition element decribing that element already
              # exists.
              if _get_element_in_pif_composition_(pif, e["symbol"]):
                  # If it exists, it removes the old Composition object, and
                  # inserts a new one with ideal atomic weight percent added
                  in_pif = _get_element_in_pif_composition_(pif, e["symbol"])
                  comp = in_pif[0]
                  pif.composition.pop(in_pif[1])
                  comp.idealWeightPercent = e["weight_percent"]
                  pif.composition.append(comp)
              else:
                  # If not, it creates a new Composition object with the element
                  # and ideal atomic weight percent.
                  comp = Composition()
                  comp.element = e["symbol"]
                  comp.idealWeightPercent = e["weight_percent"]
                  pif.composition.append(comp)
          return pif
docs: Calculates ideal atomic weight percents from a chemical formula string from a pif. Returns an appended pif with composition elements modified or added.
  
      :param pif: a ChemicalSystem pif
      :return: modified pif object