aiida.restapi.translator package

Submodules

Base translator class

class aiida.restapi.translator.base.BaseTranslator(Class=None, **kwargs)[source]

Bases: object

Generic class for translator. It contains the methods required to build a related QueryBuilder object

__dict__ = dict_proxy({'get_results': <function get_results>, 'set_query': <function set_query>, '__module__': 'aiida.restapi.translator.base', '_aiida_type': None, '_schema_projections': {'additional_info': {}, 'column_order': []}, 'set_order': <function set_order>, '_is_qb_initialized': False, '_is_id_query': None, '__label__': None, '_result_type': None, '__dict__': <attribute '__dict__' of 'BaseTranslator' objects>, '__weakref__': <attribute '__weakref__' of 'BaseTranslator' objects>, '_qb_type': None, '__init__': <function __init__>, 'count': <function count>, '_aiida_class': None, 'get_schema': <function get_schema>, 'set_filters': <function set_filters>, '_default_projections': ['**'], 'set_default_projections': <function set_default_projections>, 'get_total_count': <function get_total_count>, 'get_default_projections': <function get_default_projections>, 'get_formatted_result': <function get_formatted_result>, 'set_limit_offset': <function set_limit_offset>, '_total_count': None, '_has_uuid': None, '_check_id_validity': <function _check_id_validity>, 'init_qb': <function init_qb>, 'set_projections': <function set_projections>, '_default': ['**'], 'get_query_help': <function get_query_help>, '__doc__': '\n Generic class for translator. It contains the methods\n required to build a related QueryBuilder object\n ', '__repr__': <function __repr__>})
__init__(Class=None, **kwargs)[source]

Initialise the parameters. Create the basic query_help

keyword Class (default None but becomes this class): is the class from which one takes the initial values of the attributes. By default is this class so that class atributes are translated into object attributes. In case of inheritance one cane use the same constructore but pass the inheriting class to pass its attributes.

__label__ = None
__module__ = 'aiida.restapi.translator.base'
__repr__()[source]

This function is required for the caching system to be able to compare two NodeTranslator objects. Comparison is done on the value returned by __repr__

Returns:representation of NodeTranslator objects. Returns nothing because the inputs of self.get_nodes are sufficient to determine the identity of two queries.
__weakref__

list of weak references to the object (if defined)

_aiida_class = None
_aiida_type = None
_check_id_validity(node_id)[source]

Checks whether id corresponds to an object of the expected type, whenever type is a valid column of the database (ex. for nodes, but not for users)

Parameters:node_id – id (or id starting pattern)
Returns:True if node_id valid, False if invalid. If True, sets the id filter attribute correctly
Raises:RestValidationError – if no node is found or id pattern does not identify a unique node
_default = ['**']
_default_projections = ['**']
_has_uuid = None
_is_id_query = None
_is_qb_initialized = False
_qb_type = None
_result_type = None
_schema_projections = {'additional_info': {}, 'column_order': []}
_total_count = None
count()[source]

Count the number of rows returned by the query and set total_count

get_default_projections()[source]

method to get default projections of the node :return: self._default_projections

get_formatted_result(label)[source]

Runs the query and retrieves results tagged as “label”.

Parameters:label (str) – the tag of the results to be extracted out of the query rows.
Returns:a list of the query results
get_query_help()[source]
Returns:return QB json dictionary
get_results()[source]

Returns either list of nodes or details of single node from database.

Returns:either list of nodes or details of single node from database
get_schema()[source]

Get node schema :return: node schema

get_total_count()[source]

Returns the number of rows of the query.

Returns:total_count
init_qb()[source]

Initialize query builder object by means of _query_help

set_default_projections()[source]

It calls the set_projections() methods internally to add the default projections in query_help

Returns:None
set_filters(filters=None)[source]

Add filters in query_help.

Parameters:filters

it is a dictionary where keys are the tag names given in the path in query_help and their values are the dictionary of filters want to add for that tag name. Format for the Filters dictionary:

filters = {
    "tag1" : {k1:v1, k2:v2},
    "tag2" : {k1:v1, k2:v2},
}
Returns:query_help dict including filters if any.
set_limit_offset(limit=None, offset=None)[source]

sets limits and offset directly to the query_builder object

Parameters:
  • limit
  • offset
Returns:

set_order(orders)[source]

Add order_by clause in query_help :param orders: dictionary of orders you want to apply on final results :return: None or exception if any.

set_projections(projections)[source]

add the projections in query_help

Parameters:projections – it is a dictionary where keys are the tag names given in the path in query_help and values are the list of the names you want to project in the final output
Returns:updated query_help with projections
set_query(filters=None, orders=None, projections=None, query_type=None, node_id=None, alist=None, nalist=None, elist=None, nelist=None, downloadformat=None, visformat=None, filename=None, rtype=None)[source]

Adds filters, default projections, order specs to the query_help, and initializes the qb object

Parameters:
  • filters – dictionary with the filters
  • orders – dictionary with the order for each tag
  • projections – dictionary with the projection. It is discarded if query_type==’attributes’/’extras’
  • query_type – (string) specify the result or the content (“attr”)
  • id – (integer) id of a specific node
  • alist – list of attributes queried for node
  • nalist – list of attributes, returns all attributes except this for node
  • elist – list of extras queries for node
  • nelist – list of extras, returns all extras except this for node
  • downloadformat – file format to download e.g. cif, xyz
  • visformat – data format to visualise the node. Mainly used for structure, cif, kpoints. E.g. jsmol, chemdoodle
  • filename – name of the file to return its content
  • rtype – return type of the file

Translator for code

class aiida.restapi.translator.code.CodeTranslator(**kwargs)[source]

Bases: aiida.restapi.translator.node.NodeTranslator

Translator relative to resource ‘codes’ and aiida class Code

__init__(**kwargs)[source]

Initialise the parameters. Create the basic query_help

__label__ = 'codes'
__module__ = 'aiida.restapi.translator.code'
_aiida_class

alias of aiida.orm.nodes.data.code.Code

_aiida_type = 'data.code.Code'
_qb_type = 'data.code.Code.'
_result_type = 'codes'

Translator for computer

class aiida.restapi.translator.computer.ComputerTranslator(**kwargs)[source]

Bases: aiida.restapi.translator.base.BaseTranslator

Translator relative to resource ‘computers’ and aiida class Computer

__init__(**kwargs)[source]

Initialise the parameters. Create the basic query_help

__label__ = 'computers'
__module__ = 'aiida.restapi.translator.computer'
_aiida_class

alias of aiida.orm.computers.Computer

_aiida_type = 'Computer'
_has_uuid = True
_qb_type = 'computer'
_result_type = 'computers'
_schema_projections = {'additional_info': {'description': {'is_display': False}, 'enabled': {'is_display': True}, 'hostname': {'is_display': True}, 'id': {'is_display': True}, 'name': {'is_display': True}, 'scheduler_type': {'is_display': True}, 'transport_params': {'is_display': False}, 'transport_type': {'is_display': False}, 'uuid': {'is_display': False}}, 'column_order': ['id', 'name', 'hostname', 'description', 'enabled', 'scheduler_type', 'transport_type', 'transport_params', 'uuid']}

Translator for group

class aiida.restapi.translator.group.GroupTranslator(**kwargs)[source]

Bases: aiida.restapi.translator.base.BaseTranslator

Translator relative to resource ‘groups’ and aiida class Group

__init__(**kwargs)[source]

Initialise the parameters. Create the basic query_help

__label__ = 'groups'
__module__ = 'aiida.restapi.translator.group'
_aiida_class

alias of aiida.orm.groups.Group

_aiida_type = 'groups.Group'
_has_uuid = True
_qb_type = 'group'
_result_type = 'groups'
_schema_projections = {'additional_info': {'description': {'is_display': False}, 'id': {'is_display': True}, 'label': {'is_display': True}, 'type_string': {'is_display': True}, 'user_email': {'is_display': True}, 'user_id': {'is_display': False}, 'uuid': {'is_display': False}}, 'column_order': ['id', 'label', 'type_string', 'description', 'user_id', 'user_email', 'uuid']}

Translator for node

class aiida.restapi.translator.node.NodeTranslator(Class=None, **kwargs)[source]

Bases: aiida.restapi.translator.base.BaseTranslator

Translator relative to resource ‘nodes’ and aiida class Node

__init__(Class=None, **kwargs)[source]

Initialise the parameters. Create the basic query_help

__label__ = 'nodes'
__module__ = 'aiida.restapi.translator.node'
_aiida_class

alias of aiida.orm.nodes.node.Node

_aiida_type = 'node.Node'
_alist = None
_content_type = None
_downloadformat = None
_elist = None
_filename = None
_get_content()[source]

Used by get_results() in case of endpoint include “content” option :return: data: a dictionary containing the results obtained by running the query

_get_subclasses(parent=None, parent_class=None, recursive=True)[source]

Import all submodules of the package containing the present class. Includes subpackages recursively, if specified.

Parameters:
  • parent – package/class. If package looks for the classes in submodules. If class, first lookss for the package where it is contained
  • parent_class – class of which to look for subclasses
  • recursive – True/False (go recursively into submodules)
_has_uuid = True
_nalist = None
_nelist = None
_qb_type = 'node.Node.'
_result_type = 'nodes'
_rtype = None
_visformat = None
get_downloadable_data(node, download_format=None)[source]

Generic function to download file in specified format. Actual definition is in child classes as the content to be returned and its format depends on the visualization plugin specific to the resource

Parameters:
  • node – node object
  • download_format – file extension format
Returns:

data in selected format to download

If this method is called by Node resource it will look for the type of object and invoke the correct method in the lowest-compatibel subclass

static get_file_content(node, file_name)[source]

It reads the file from directory and returns its content.

Instead of using “send_from_directory” from flask, this method is written because in next aiida releases the file can be stored locally or in object storage.

Parameters:
  • node – aiida folderData node which contains file
  • file_name – name of the file to return its contents
Returns:

get_io_tree(uuid_pattern, tree_in_limit, tree_out_limit)[source]

json data to display nodes in tree format :param uuid_pattern: main node uuid :return: json data to display node tree

get_results()[source]

Returns either a list of nodes or details of single node from database

Returns:either a list of nodes or the details of single node from the database
static get_retrieved_inputs(node, filename=None, rtype=None)[source]

Generic function to return output of calc inputls verdi command. Actual definition is in child classes as the content to be returned and its format depends on the visualization plugin specific to the resource

Parameters:node – node object
Returns:list of calc inputls command
static get_retrieved_outputs(node, filename=None, rtype=None)[source]

Generic function to return output of calc outputls verdi command. Actual definition is in child classes as the content to be returned and its format depends on the visualization plugin specific to the resource

Parameters:node – node object
Returns:list of calc outputls command
get_statistics(user_pk=None)[source]

Return statistics for a given node

get_visualization_data(node, visformat=None)[source]

Generic function to get the data required to visualize the node with a specific plugin. Actual definition is in child classes as the content to be be returned and its format depends on the visualization plugin specific to the resource

Parameters:
  • node – node object that has to be visualized
  • visformat – visualization format
Returns:

data selected and serialized for visualization

If this method is called by Node resource it will look for the type of object and invoke the correct method in the lowest-compatibel subclass

set_query(filters=None, orders=None, projections=None, query_type=None, node_id=None, alist=None, nalist=None, elist=None, nelist=None, downloadformat=None, visformat=None, filename=None, rtype=None)[source]

Adds filters, default projections, order specs to the query_help, and initializes the qb object

Parameters:
  • filters – dictionary with the filters
  • orders – dictionary with the order for each tag
  • projections – dictionary with the projection. It is discarded if query_type==’attributes’/’extras’
  • query_type – (string) specify the result or the content (“attr”)
  • id – (integer) id of a specific node
  • alist – list of attributes queried for node
  • nalist – list of attributes, returns all attributes except this for node
  • elist – list of extras queries for node
  • nelist – list of extras, returns all extras except this for node
  • downloadformat – file format to download e.g. cif, xyz
  • visformat – data format to visualise the node. Mainly used for structure, cif, kpoints. E.g. jsmol, chemdoodle
  • filename – name of the file to return its content
  • rtype – return type of the file
set_query_type(query_type, alist=None, nalist=None, elist=None, nelist=None, downloadformat=None, visformat=None, filename=None, rtype=None)[source]

sets one of the mutually exclusive values for self._result_type and self._content_type.

:param query_type:(string) the value assigned to either variable.

Translator for user

class aiida.restapi.translator.user.UserTranslator(**kwargs)[source]

Bases: aiida.restapi.translator.base.BaseTranslator

Translator relative to resource ‘users’ and aiida class User

__init__(**kwargs)[source]

Initialise the parameters. Create the basic query_help

__label__ = 'users'
__module__ = 'aiida.restapi.translator.user'
_aiida_class

alias of aiida.orm.users.User

_aiida_type = 'User'
_default_projections = ['id', 'first_name', 'last_name', 'institution', 'date_joined']
_has_uuid = False
_qb_type = 'user'
_result_type = 'users'
_schema_projections = {'additional_info': {'date_joined': {'is_display': False}, 'email': {'is_display': True}, 'first_name': {'is_display': True}, 'id': {'is_display': True}, 'institution': {'is_display': True}, 'is_active': {'is_display': False}, 'last_login': {'is_display': False}, 'last_name': {'is_display': True}}, 'column_order': ['id', 'first_name', 'last_name', 'email', 'institution', 'date_joined', 'last_login', 'is_active']}