Adds the "weight_percent" property to each of the dictionaries in elemental_array

    :param elemental_array: an array of dictionaries containing information about the elements in the system
    :return: the appended elemental_array
348150
def _add_ideal_weight_percent_(elemental_array):
    
    t_mass = _calculate_total_mass_(elemental_array)
    for a in elemental_array:
        a["weight_percent"] = a["weight"] / t_mass * 100
    return elemental_array
324866
def addElement(self, *ele):
        
        for el in list(Models.flatten(ele)):
            e = copy.deepcopy(el)
            self._lattice_eleobjlist.append(e)
            self._lattice_elenamelist.append(e.name)
            self._lattice_elecnt += 1
        # update lattice, i.e. beamline element

        # self._lattice.setConf(Models.makeLatticeString(self._lattice_elenamelist))
        self._lattice.setConf(Models.makeLatticeDict(self._lattice_elenamelist))

        # positioning elements
        self.initPos()

        return self._lattice_elecnt
1264644
def prepend_items(self, items, **kwargs):
        
        rv = self.prepend_multi(items, **kwargs)
        for k, v in items.dict.items():
            if k.success:
                k.value = v['fragment'] + k.value

        return rv
1065053
def add_attribute(self, attribute, value):
        
        class_name = self.__class__.__name__
        if class_name.startswith('ItemData'):
            # ItemData* Elements
            class_name = 'ItemData'
        if attribute not in MODMExtensionRegistry[class_name].value:
            raise ValueError("Can't add {} to {}".format(attribute, self.__class__.__name__))
        self.attributes.append(MODMAttribute(attribute, value))
1337556
def _weighting(weights, exponent):
    """"""
    if np.isscalar(weights):
        weighting = NumpyTensorSpaceConstWeighting(weights, exponent)
    elif weights is None:
        weighting = NumpyTensorSpaceConstWeighting(1.0, exponent)
    else:  # last possibility: make an array
        arr = np.asarray(weights)
        weighting = NumpyTensorSpaceArrayWeighting(arr, exponent)
    return weighting
78260
def generateAcceptHeader(*elements):
    
    parts = []
    for element in elements:
        if type(element) is str:
            qs = "1.0"
            mtype = element
        else:
            mtype, q = element
            q = float(q)
            if q > 1 or q <= 0:
                raise ValueError('Invalid preference factor: %r' % q)

            qs = '%0.1f' % (q,)

        parts.append((qs, mtype))

    parts.sort()
    chunks = []
    for q, mtype in parts:
        if q == '1.0':
            chunks.append(mtype)
        else:
            chunks.append('%s; q=%s' % (mtype, q))

    return ', '.join(chunks)
471855
def literal_array(cls, elems):
        
        tys = [el.type for el in elems]
        if len(tys) == 0:
            raise ValueError("need at least one element")
        ty = tys[0]
        for other in tys:
            if ty != other:
                raise TypeError("all elements must have the same type")
        return cls(types.ArrayType(ty, len(elems)), elems)
831625
def add_element(element)
      raise ArgumentError, "Invalid argument 'element'. Expected DictionaryElement, got #{element.class}" unless element.is_a?(DictionaryElement)
      # We store the elements in a hash with tag as key and the element instance as value:
      @elements[element.tag] = element
      # Populate the method conversion hashes with element data:
      method = element.name.to_element_method
      @methods_from_names[element.name] = method
      @names_from_methods[method] = element.name
    end
498651
def _add_compounds(self, variant_obj, info_dict):
        
        compound_list = []
        compound_entry = info_dict.get('Compounds')
        if compound_entry:
            for family_annotation in compound_entry.split(','):
                compounds = family_annotation.split(':')[-1].split('|')
                for compound in compounds:
                    splitted_compound = compound.split('>')

                    compound_score = None
                    if len(splitted_compound) > 1:
                        compound_id = splitted_compound[0]
                        compound_score = int(splitted_compound[-1])
                    
                    compound_list.append(Compound(
                        variant_id=compound_id,
                        combined_score=compound_score
                        )
                    )
        
        #Sort the compounds based on rank score
        compound_list.sort(key = operator.attrgetter('combined_score'), reverse=True)
        
        for compound in compound_list:
            variant_obj.add_compound(compound)
1327972
def rinseElement(self, ele):
        
        if '*' in ele:
            tmplist = ''.join(ele.split()).split('*')
            tmplist_num = tmplist[[x.isdigit() for x in tmplist].index(True)]
            tmplist_ele = tmplist[[x.isdigit() for x in tmplist].index(False)]
            return dict(zip(('num', 'name'), (int(tmplist_num), tmplist_ele)))
        else:
            return dict(zip(('num', 'name'), (1, ele)))
1319706
def insert_element_to_dict_of_list(dict_of_list, key, parser):
    
    if key in dict_of_list.keys():
        dict_of_list[key].append(parser)
    else:
        dict_of_list[key] = [parser]
1315062
def iscm_md_append_array(self, arraypath, member):
        
        array_path = string.split(arraypath, ".")
        array_key = array_path.pop()
        current = self.metadata
        for k in array_path:
            if not current.has_key(k):
                current[k] = {}
            current = current[k]
        if not current.has_key(array_key):
            current[array_key] = []
        if not type(current[array_key]) == list:
            raise KeyError("%s doesn't point to an array" % arraypath)
        current[array_key].append(member)
959585
def merge_dictionaries(current, new, only_defaults=False, template_special_case=False):
    '''
    

    '''
    changes = 0
    for key, value in new.items():
        if key not in current:
            if hasattr(global_settings, key):
                current[key] = getattr(global_settings, key)
                LOGGER.debug("Set %r to global default %r.", key, current[key])
            else:
                current[key] = copy.copy(value)
                LOGGER.debug("Set %r to %r.", key, current[key])
                changes += 1
                continue
        elif only_defaults:
            continue
        current_value = current[key]
        if hasattr(current_value, 'items'):
            changes += merge_dictionaries(current_value, value)
        elif isinstance(current_value, (list, tuple)):
            for element in value:
                if element not in current_value:
                    if template_special_case and key == 'TEMPLATES':
                        existing_matches = [
                            template for template in current_value if template['BACKEND'] == element['BACKEND']
                        ]
                        if existing_matches:
                            changes += merge_dictionaries(existing_matches[0], element)
                        else:
                            current[key] = list(current_value) + [element]
                            LOGGER.debug("Added %r to %r.", element, key)
                            changes += 1
                    else:
                        current[key] = list(current_value) + [element]
                        LOGGER.debug("Added %r to %r.", element, key)
                        changes += 1
        elif isinstance(current_value, Promise) or isinstance(value, Promise):
            # If we don't know what to do with it, replace it.
            if current_value is not value:
                current[key] = value
                LOGGER.debug("Set %r to %r.", key, current[key])
                changes += 1
        else:
            # If we don't know what to do with it, replace it.
            if current_value != value:
                current[key] = value
                LOGGER.debug("Set %r to %r.", key, current[key])
                changes += 1
    return changes
347406
def user_default_add_related_pks(self, obj):
        """"""
        if not hasattr(obj, '_votes_pks'):
            obj._votes_pks = list(obj.votes.values_list('pk', flat=True))
917932
def add_spectra(self, spectra_dict, key_sort_func=None):
        
        if key_sort_func:
            keys = sorted(spectra_dict.keys(), key=key_sort_func)
        else:
            keys = spectra_dict.keys()
        for label in keys:
            self.add_spectra(label, spectra_dict[label])
1203178
def calculate_ideal_atomic_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_atomic_percents_(element_array)
        for e in appended_e_array:
            # 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 percent added.
                in_pif = _get_element_in_pif_composition_(pif, e["symbol"])
                comp = in_pif[0]
                pif.composition.pop(in_pif[1])
                comp.idealAtomicPercent = e["atomic_percent"]
                pif.composition.append(comp)
            else:
                # If not, it creates a new Composition object with the element
                # and ideal atomic percent.
                comp = Composition()
                comp.element = e["symbol"]
                comp.idealAtomicPercent = e["atomic_percent"]
                pif.composition.append(comp)
        return pif
360388
def indicator_arrays(tc_entity_array):
        
        type_dict = {}
        for ea in tc_entity_array:
            type_dict.setdefault(ea['type'], []).append(ea['value'])
        return type_dict