aiida.restapi.translator package#

Subpackages#

Submodules#

Base translator class

class aiida.restapi.translator.base.BaseTranslator(**kwargs)[源代码]#

基类:object

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

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

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__()[源代码]#

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__

返回:

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)[源代码]#

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)

参数:

node_id – id (or id starting pattern)

返回:

True if node_id valid, False if invalid. If True, sets the id filter attribute correctly

抛出:

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#
_result_type = None#
_total_count = None#
count()[源代码]#

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

get_default_projections()[源代码]#

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

get_formatted_result(label)[源代码]#

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

参数:

label (str) – the tag of the results to be extracted out of the query rows.

返回:

a list of the query results

static get_projectable_properties()[源代码]#

This method is extended in specific translators classes. It returns a dict as follows: dict(fields=projectable_properties, ordering=ordering) where projectable_properties is a dict and ordering is a list

get_query_help()[源代码]#
返回:

return QB json dictionary

get_results()[源代码]#

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

返回:

either list of nodes or details of single node from database

get_total_count()[源代码]#

Returns the number of rows of the query.

返回:

total_count

init_qb()[源代码]#

Initialize query builder object by means of _query_help

set_default_projections()[源代码]#

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

返回:

None

set_filters(filters=None)[源代码]#

Add filters in query_help.

参数:

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},
}

返回:

query_help dict including filters if any.

set_limit_offset(limit=None, offset=None)[源代码]#

Sets limits and offset directly to the query_builder object

参数:
  • limit

  • offset

返回:

set_order(orders)[源代码]#

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)[源代码]#

Add the projections in query_help

参数:

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

返回:

updated query_help with projections

set_query(filters=None, orders=None, projections=None, query_type=None, node_id=None, attributes=None, attributes_filter=None, extras=None, extras_filter=None)[源代码]#

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

参数:
  • 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

  • filename – name of the file to return its content

  • attributes – flag to show attributes in nodes endpoint

  • attributes_filter – list of node attributes to query

  • extras – flag to show attributes in nodes endpoint

  • extras_filter – list of node extras to query

Translator for computer

class aiida.restapi.translator.computer.ComputerTranslator(**kwargs)[源代码]#

基类:BaseTranslator

Translator relative to resource ‘computers’ and aiida class Computer

__annotations__ = {}#
__label__ = 'computers'#
__module__ = 'aiida.restapi.translator.computer'#
_aiida_class#

Computer 的别名

_aiida_type = 'Computer'#
_has_uuid = True#
_result_type = 'computers'#
get_projectable_properties()[源代码]#

Get projectable properties specific for Computer :return: dict of projectable properties and column_order list

Translator for group

class aiida.restapi.translator.group.GroupTranslator(**kwargs)[源代码]#

基类:BaseTranslator

Translator relative to resource ‘groups’ and aiida class Group

__annotations__ = {}#
__label__ = 'groups'#
__module__ = 'aiida.restapi.translator.group'#
_aiida_class#

Group 的别名

_aiida_type = 'groups.Group'#
_has_uuid = True#
_result_type = 'groups'#
get_projectable_properties()[源代码]#

Get projectable properties specific for Group :return: dict of projectable properties and column_order list

Translator for user

class aiida.restapi.translator.user.UserTranslator(**kwargs)[源代码]#

基类:BaseTranslator

Translator relative to resource ‘users’ and aiida class User

__annotations__ = {}#
__label__ = 'users'#
__module__ = 'aiida.restapi.translator.user'#
_aiida_class#

User 的别名

_aiida_type = 'User'#
_default_projections = ['id', 'first_name', 'last_name', 'institution']#
_has_uuid = False#
_result_type = 'users'#
get_projectable_properties()[源代码]#

Get projectable properties specific for User :return: dict of projectable properties and column_order list