Example #1
0
def trajectory_list(raw, past_days, groups, all_users):
    """List TrajectoryData objects stored in the database."""
    from aiida.orm import TrajectoryData
    from tabulate import tabulate

    elements = None
    elements_only = False
    formulamode = None
    entry_list = data_list(TrajectoryData, LIST_PROJECT_HEADERS, elements,
                           elements_only, formulamode, past_days, groups,
                           all_users)

    counter = 0
    struct_list_data = list()
    if not raw:
        struct_list_data.append(LIST_PROJECT_HEADERS)
    for entry in entry_list:
        for i, value in enumerate(entry):
            if isinstance(value, list):
                entry[i] = ','.join(value)
        for i in range(len(entry), len(LIST_PROJECT_HEADERS)):
            entry.append(None)
        counter += 1
    struct_list_data.extend(entry_list)
    if raw:
        echo.echo(tabulate(struct_list_data, tablefmt='plain'))
    else:
        echo.echo(tabulate(struct_list_data, headers='firstrow'))
        echo.echo('\nTotal results: {}\n'.format(counter))
Example #2
0
def cif_list(raw, formula_mode, past_days, groups, all_users):
    """List store CifData objects."""
    from aiida.orm import CifData
    from tabulate import tabulate

    elements = None
    elements_only = False

    entry_list = data_list(CifData, LIST_PROJECT_HEADERS, elements,
                           elements_only, formula_mode, past_days, groups,
                           all_users)

    counter = 0
    cif_list_data = list()

    if not raw:
        cif_list_data.append(LIST_PROJECT_HEADERS)
    for entry in entry_list:
        for i, value in enumerate(entry):
            if isinstance(value, list):
                new_entry = list()
                for elm in value:
                    if elm is None:
                        new_entry.append('')
                    else:
                        new_entry.append(elm)
                entry[i] = ','.join(new_entry)
        for i in range(len(entry), len(LIST_PROJECT_HEADERS)):
            entry.append(None)
        counter += 1
    cif_list_data.extend(entry_list)
    if raw:
        echo.echo(tabulate(cif_list_data, tablefmt='plain'))
    else:
        echo.echo(tabulate(cif_list_data, headers='firstrow'))
        echo.echo('\nTotal results: {}\n'.format(counter))
Example #3
0
def structure_list(elements, raw, formula_mode, past_days, groups, all_users):
    """List StructureData objects."""
    from aiida.orm.nodes.data.structure import StructureData, get_formula, get_symbols_string
    from tabulate import tabulate

    elements_only = False
    lst = data_list(StructureData, ['Id', 'Label', 'Kinds', 'Sites'], elements,
                    elements_only, formula_mode, past_days, groups, all_users)

    entry_list = []
    for [pid, label, akinds, asites] in lst:
        # If symbols are defined there is a filtering of the structures
        # based on the element
        # When QueryBuilder will support this (attribute)s filtering,
        # it will be pushed in the query.
        if elements is not None:
            all_symbols = [_['symbols'][0] for _ in akinds]
            if not any([s in elements for s in all_symbols]):
                continue

            if elements_only:
                echo.echo_critical('Not implemented elements-only search')

        # We want only the StructureData that have attributes
        if akinds is None or asites is None:
            continue

        symbol_dict = {}
        for k in akinds:
            symbols = k['symbols']
            weights = k['weights']
            symbol_dict[k['name']] = get_symbols_string(symbols, weights)

        try:
            symbol_list = []
            for site in asites:
                symbol_list.append(symbol_dict[site['kind_name']])
            formula = get_formula(symbol_list, mode=formula_mode)
        # If for some reason there is no kind with the name
        # referenced by the site
        except KeyError:
            formula = '<<UNKNOWN>>'
        entry_list.append([str(pid), label, str(formula)])

    counter = 0
    struct_list_data = list()
    if not raw:
        struct_list_data.append(LIST_PROJECT_HEADERS)
    for entry in entry_list:
        for i, value in enumerate(entry):
            if isinstance(value, list):
                entry[i] = ','.join(value)
        for i in range(len(entry), len(LIST_PROJECT_HEADERS)):
            entry.append(None)
        counter += 1
    struct_list_data.extend(entry_list)
    if raw:
        echo.echo(tabulate(struct_list_data, tablefmt='plain'))
    else:
        echo.echo(tabulate(struct_list_data, headers='firstrow'))
        echo.echo('\nTotal results: {}\n'.format(counter))