aiida.backends.general package

Submodules

class aiida.backends.general.abstractqueries.AbstractQueryManager(*args, **kwargs)[source]

Bases: object

__abstractmethods__ = frozenset([])
__dict__ = dict_proxy({'__module__': 'aiida.backends.general.abstractqueries', '__metaclass__': <class 'abc.ABCMeta'>, '_abc_negative_cache': <_weakrefset.WeakSet object>, 'get_all_parents': <function get_all_parents>, '__dict__': <attribute '__dict__' of 'AbstractQueryManager' objects>, 'get_creation_statistics': <function get_creation_statistics>, '__weakref__': <attribute '__weakref__' of 'AbstractQueryManager' objects>, '__init__': <function __init__>, '_abc_cache': <_weakrefset.WeakSet object>, 'get_bands_and_parents_structure': <function get_bands_and_parents_structure>, 'query_jobcalculations_by_computer_user_state': <function query_jobcalculations_by_computer_user_state>, '__abstractmethods__': frozenset([]), '_abc_negative_cache_version': 39, '_abc_registry': <_weakrefset.WeakSet object>, '__doc__': None})
__init__(*args, **kwargs)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__metaclass__

alias of abc.ABCMeta

__module__ = 'aiida.backends.general.abstractqueries'
__weakref__

list of weak references to the object (if defined)

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 39
_abc_registry = <_weakrefset.WeakSet object>
get_all_parents(node_pks, return_values=['id'])[source]

Get all the parents of given nodes :param node_pks: one node pk or an iterable of node pks :return: a list of aiida objects with all the parents of the nodes

get_bands_and_parents_structure(args)[source]

Search for bands and return bands and the closest structure that is a parent of the instance. This is the backend independent way, can be overriden for performance reason

Returns:
A list of sublists, each latter containing (in order):
pk as string, formula as string, creation date, bandsdata-label
get_creation_statistics(user_pk=None)[source]

Return a dictionary with the statistics of node creation, summarized by day.

Note:Days when no nodes were created are not present in the returned ctime_by_day dictionary.
Parameters:user_pk – If None (default), return statistics for all users. If user pk is specified, return only the statistics for the given user.
Returns:a dictionary as follows:
{
   "total": TOTAL_NUM_OF_NODES,
   "types": {TYPESTRING1: count, TYPESTRING2: count, ...},
   "ctime_by_day": {'YYYY-MMM-DD': count, ...}

where in ctime_by_day the key is a string in the format ‘YYYY-MM-DD’ and the value is an integer with the number of nodes created that day.

query_jobcalculations_by_computer_user_state(state, computer=None, user=None, only_computer_user_pairs=False, only_enabled=True, limit=None)[source]

Filter all calculations with a given state.

Issue a warning if the state is not in the list of valid states.

Parameters:
  • state (str) – The state to be used to filter (should be a string among those defined in aiida.common.datastructures.calc_states)
  • computer – a Django DbComputer entry, or a Computer object, of a computer in the DbComputer table. A string for the hostname is also valid.
  • user – a Django entry (or its pk) of a user in the DbUser table; if present, the results are restricted to calculations of that specific user
  • only_computer_user_pairs (bool) – if False (default) return a queryset where each element is a suitable instance of Node (it should be an instance of Calculation, if everything goes right!) If True, return only a list of tuples, where each tuple is in the format (‘dbcomputer__id’, ‘user__id’) [where the IDs are the IDs of the respective tables]
  • limit (int) – Limit the number of rows returned
Returns:

a list of calculation objects matching the filters.

class aiida.backends.general.querybuilder_interface.QueryBuilderInterface(*args, **kwargs)[source]

Bases: object

AiidaComputer()[source]

A property, decorated with @property. Returns the implementation for the AiiDA-class for Computer

AiidaGroup()[source]

A property, decorated with @property. Returns the implementation for the AiiDA-class for Group

AiidaNode()[source]

A property, decorated with @property. Returns the implementation for the AiiDA-class for Node

AiidaUser()[source]

A property, decorated with @property. Returns the implementation for the AiiDA-class for User

Computer()[source]

A property, decorated with @property. Returns the implementation for the Computer

Group()[source]

A property, decorated with @property. Returns the implementation for the Group

A property, decorated with @property. Returns the implementation for the DbLink

Node()[source]

Decorated as a property, returns the implementation for DbNode. It needs to return a subclass of sqlalchemy.Base, which means that for different ORM’s a corresponding dummy-model must be written.

User()[source]

A property, decorated with @property. Returns the implementation for the User

__abstractmethods__ = frozenset(['count', 'get_session', 'Group', 'AiidaUser', 'get_projectable_attribute', '__init__', 'Node', 'AiidaComputer', 'get_aiida_res', 'modify_expansions', 'table_groups_nodes', 'yield_per', 'get_filter_expr_from_attributes', 'AiidaNode', 'Computer', 'Link', 'User', 'iterall', 'AiidaGroup', 'first', 'iterdict', 'get_ormclass'])
__dict__ = dict_proxy({'count': <function count>, '__module__': 'aiida.backends.general.querybuilder_interface', '__abstractmethods__': frozenset(['count', 'get_session', 'Group', 'AiidaUser', 'get_projectable_attribute', '__init__', 'Node', 'AiidaComputer', 'get_aiida_res', 'modify_expansions', 'table_groups_nodes', 'yield_per', 'get_filter_expr_from_attributes', 'AiidaNode', 'Computer', 'Link', 'User', 'iterall', 'AiidaGroup', 'first', 'iterdict', 'get_ormclass']), '__metaclass__': <class 'abc.ABCMeta'>, '_abc_negative_cache': <_weakrefset.WeakSet object>, 'AiidaUser': <function AiidaUser>, 'get_session': <function get_session>, 'get_projectable_attribute': <function get_projectable_attribute>, '__dict__': <attribute '__dict__' of 'QueryBuilderInterface' objects>, 'Group': <function Group>, '__weakref__': <attribute '__weakref__' of 'QueryBuilderInterface' objects>, '__init__': <function __init__>, 'Node': <function Node>, '_abc_negative_cache_version': 40, 'AiidaComputer': <function AiidaComputer>, 'get_aiida_res': <function get_aiida_res>, 'modify_expansions': <function modify_expansions>, 'table_groups_nodes': <function table_groups_nodes>, 'yield_per': <function yield_per>, 'get_filter_expr_from_attributes': <function get_filter_expr_from_attributes>, 'AiidaNode': <function AiidaNode>, '_abc_cache': <_weakrefset.WeakSet object>, 'Computer': <function Computer>, 'Link': <function Link>, 'User': <function User>, 'iterall': <function iterall>, 'AiidaGroup': <function AiidaGroup>, 'first': <function first>, '_abc_registry': <_weakrefset.WeakSet object>, '__doc__': None, 'iterdict': <function iterdict>, 'get_ormclass': <function get_ormclass>})
__init__(*args, **kwargs)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__metaclass__

alias of abc.ABCMeta

__module__ = 'aiida.backends.general.querybuilder_interface'
__weakref__

list of weak references to the object (if defined)

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 40
_abc_registry = <_weakrefset.WeakSet object>
count()[source]
Returns:the number of results
first()[source]

Executes query in the backend asking for one instance.

Returns:One row of aiida results
get_aiida_res(key, res)[source]

Some instance returned by ORM (django or SA) need to be converted to Aiida instances (eg nodes)

Parameters:
  • key – the key that this entry would be returned with
  • res – the result returned by the query
Returns:

an aiida-compatible instance

get_filter_expr_from_attributes(operator, value, attr_key, column=None, column_name=None, alias=None)[source]

A classmethod that returns an valid SQLAlchemy expression.

Parameters:
  • operator – The operator provided by the user (‘==’, ‘>’, …)
  • value – The value to compare with, e.g. (5.0, ‘foo’, [‘a’,’b’])
  • attr_key (str) – The path to that attribute as a tuple of values. I.e. if that attribute I want to filter by is the 2nd element in a list stored under the key ‘mylist’, this is (‘mylist’, ‘2’).
  • column – Optional, an instance of sqlalchemy.orm.attributes.InstrumentedAttribute or
  • column_name (str) – The name of the column, and the backend should get the InstrumentedAttribute.
  • alias – The aliased class.
Returns:

An instance of sqlalchemy.sql.elements.BinaryExpression

get_ormclass(cls, ormclasstype)[source]
get_projectable_attribute(alias, column_name, attrpath, cast=None, **kwargs)[source]
get_session()[source]
Returns:a valid session, an instance of sqlalchemy.orm.session.Session
iterall(batch_size=100)[source]
Returns:An iterator over all the results of a list of lists.
iterdict(batch_size=100)[source]
Returns:An iterator over all the results of a list of dictionaries.
modify_expansions(alias, expansions)[source]

Modify names of projections if ** was specified. This is important for the schema having attributes in a different table.

table_groups_nodes()[source]

A property, decorated with @property. Returns the implementation for the many-to-many relationship between group and nodes.

yield_per(batch_size)[source]
Parameters:batch_size (int) – Number of rows to yield per step

Yields count rows at a time

Returns:a generator