@staticmethod
def _update_dist(distance_matrix, global_linkage, local_linkage_tr,
    global_elements, criterion=None):
    """
        Updates the general distance matrix to take the new clusters into account

        Replaces the elements added to the new clusters with these clusters as elements.
        Requires the recalculation of the distance matrix to determine the distance from
        new clusters to other elements.

        A criterion function may be given for calculation of the new distances from a new cluster to other
        elements based on the distances of elements included in a cluster. The default method is the weighted
        average of distances based on the number of atoms in each of the two elements.

        :param distance_matrix: (pd.dataframe) Previous distance matrix
        :param global_linkage: (np.array) Global linkage object that includes new clusters
        :param local_linkage_tr: (np.array) Local linkage object transformed (global names of elements and atoms count)
        :param global_elements: (list) Global list with names of all elements
        :param criterion: (function) Function to apply to a dataframe of distances to adjust them
        :return: (np.array) Updated distance matrix
        """
    num_atoms = len(global_elements) - global_linkage.shape[0]
    new_items = global_elements[-local_linkage_tr.shape[0]:]
    for i in range(local_linkage_tr.shape[0]):
        elem_1, elem_2 = global_elements[int(local_linkage_tr[i, 0])
            ], global_elements[int(local_linkage_tr[i, 1])]
        if criterion is None:
            if local_linkage_tr[i, 0] < num_atoms:
                elem_1_weight = 1
            else:
                elem_1_weight = global_linkage[int(local_linkage_tr[i, 0]) -
                    num_atoms, 3]
            if local_linkage_tr[i, 1] < num_atoms:
                elem_2_weight = 1
            else:
                elem_2_weight = global_linkage[int(local_linkage_tr[i, 1]) -
                    num_atoms, 3]
            dist_vector = (distance_matrix[elem_1] * elem_1_weight + 
                distance_matrix[elem_2] * elem_2_weight) / (elem_1_weight +
                elem_2_weight)
        else:
            dist_vector = criterion(distance_matrix[[elem_1, elem_2]], axis=1)
        distance_matrix[new_items[i]] = dist_vector
        distance_matrix.loc[new_items[i]] = dist_vector
        distance_matrix.loc[new_items[i], new_items[i]] = 0
        distance_matrix = distance_matrix.drop([elem_1, elem_2], axis=0)
        distance_matrix = distance_matrix.drop([elem_1, elem_2], axis=1)
    return distance_matrix
