def sort_basis(basis, use_copy=True):
    if use_copy:
        basis = copy.deepcopy(basis)
    for k, el in basis['elements'].items():
        if 'electron_shells' in el:
            el['electron_shells'] = sort_shells(el['electron_shells'], False)
        if 'ecp_potentials' in el:
            el['ecp_potentials'] = sort_potentials(el['ecp_potentials'], False)
    return sort_basis_dict(basis)