def create_element_data(bs_data, element_Z, key, key_exist_ok=False,
    element_exist_ok=True, create=list):
    """Creates an element and a subkey of the element in bs_data

    Note that bs_data is modified!
    """
    if element_Z not in bs_data:
        bs_data[element_Z] = {}
    elif not element_exist_ok:
        raise RuntimeError('Element {} already exists in basis data'.format
            (element_Z))
    if key not in bs_data[element_Z]:
        bs_data[element_Z][key] = create()
    elif not key_exist_ok:
        raise RuntimeError('Key {} already exists in basis data for element {}'
            .format(key, element_Z))
    return bs_data[element_Z]
