aiida.orm.implementation package

Module with the implementations of the various backend entities for various database backends.

class aiida.orm.implementation.BackendAuthInfo(backend)[source]

Bases: aiida.orm.implementation.backends.BackendEntity

Backend implementation for the AuthInfo ORM class.

METADATA_WORKDIR = 'workdir'
__abstractmethods__ = frozenset({'computer', 'enabled', 'get_auth_params', 'get_metadata', 'id', 'is_stored', 'set_auth_params', 'set_metadata', 'store', 'user'})
__module__ = 'aiida.orm.implementation.authinfos'
_abc_impl = <_abc_data object>
abstract property computer

Return the computer associated with this instance.

Returns

aiida.orm.implementation.computers.BackendComputer

abstract property enabled

Return whether this instance is enabled.

Returns

boolean, True if enabled, False otherwise

abstract get_auth_params()[source]

Return the dictionary of authentication parameters

Returns

a dictionary with authentication parameters

abstract get_metadata()[source]

Return the dictionary of metadata

Returns

a dictionary with metadata

abstract set_auth_params(auth_params)[source]

Set the dictionary of authentication parameters

Parameters

auth_params – a dictionary with authentication parameters

abstract set_metadata(metadata)[source]

Set the dictionary of metadata

Parameters

metadata – a dictionary with metadata

abstract property user

Return the user associated with this instance.

Returns

aiida.orm.implementation.users.BackendUser

class aiida.orm.implementation.BackendAuthInfoCollection(backend)[source]

Bases: aiida.orm.implementation.backends.BackendCollection

The collection of backend AuthInfo entries.

ENTITY_CLASS

alias of BackendAuthInfo

__abstractmethods__ = frozenset({'delete', 'get'})
__module__ = 'aiida.orm.implementation.authinfos'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.authinfos.BackendAuthInfo],)
__parameters__ = ()
_abc_impl = <_abc_data object>
abstract delete(pk)[source]

Delete an entry from the collection.

Parameters

pk – the pk of the entry to delete

abstract get(computer, user)[source]

Return an entry from the collection that is configured for the given computer and user

Parameters
Returns

aiida.orm.implementation.authinfos.BackendAuthInfo

Raises
class aiida.orm.implementation.Backend[source]

Bases: object

The public interface that defines a backend factory that creates backend specific concrete objects.

__abstractmethods__ = frozenset({'authinfos', 'comments', 'computers', 'groups', 'logs', 'migrate', 'nodes', 'query', 'query_manager', 'transaction', 'users'})
__dict__ = mappingproxy({'__module__': 'aiida.orm.implementation.backends', '__doc__': 'The public interface that defines a backend factory that creates backend specific concrete objects.', 'migrate': <function Backend.migrate>, 'authinfos': <abc.abstractproperty object>, 'comments': <abc.abstractproperty object>, 'computers': <abc.abstractproperty object>, 'groups': <abc.abstractproperty object>, 'logs': <abc.abstractproperty object>, 'nodes': <abc.abstractproperty object>, 'query_manager': <abc.abstractproperty object>, 'query': <function Backend.query>, 'users': <abc.abstractproperty object>, 'transaction': <function Backend.transaction>, '__dict__': <attribute '__dict__' of 'Backend' objects>, '__weakref__': <attribute '__weakref__' of 'Backend' objects>, '__abstractmethods__': frozenset({'comments', 'groups', 'authinfos', 'logs', 'query_manager', 'transaction', 'nodes', 'computers', 'query', 'migrate', 'users'}), '_abc_impl': <_abc_data object>})
__module__ = 'aiida.orm.implementation.backends'
__weakref__

list of weak references to the object (if defined)

_abc_impl = <_abc_data object>
abstract property authinfos

Return the collection of authorisation information objects

Returns

the authinfo collection

Return type

aiida.orm.implementation.BackendAuthInfoCollection

abstract property comments

Return the collection of comments

Returns

the comment collection

Return type

aiida.orm.implementation.BackendCommentCollection

abstract property computers

Return the collection of computers

Returns

the computers collection

Return type

aiida.orm.implementation.BackendComputerCollection

abstract property groups

Return the collection of groups

Returns

the groups collection

Return type

aiida.orm.implementation.BackendGroupCollection

abstract property logs

Return the collection of logs

Returns

the log collection

Return type

aiida.orm.implementation.BackendLogCollection

abstract migrate()[source]

Migrate the database to the latest schema version.

abstract property nodes

Return the collection of nodes

Returns

the nodes collection

Return type

aiida.orm.implementation.BackendNodeCollection

abstract query()[source]

Return an instance of a query builder implementation for this backend

Returns

a new query builder instance

Return type

aiida.orm.implementation.BackendQueryBuilder

abstract property query_manager

Return the query manager for the objects stored in the backend

Returns

The query manger

Return type

aiida.backends.general.abstractqueries.AbstractQueryManager

abstract transaction()[source]

Get a context manager that can be used as a transaction context for a series of backend operations. If there is an exception within the context then the changes will be rolled back and the state will be as before entering. Transactions can be nested.

Returns

a context manager to group database operations

abstract property users

Return the collection of users

Returns

the users collection

Return type

aiida.orm.implementation.BackendUserCollection

class aiida.orm.implementation.BackendEntity(backend)[source]

Bases: object

An first-class entity in the backend

__abstractmethods__ = frozenset({'id', 'is_stored', 'store'})
__dict__ = mappingproxy({'__module__': 'aiida.orm.implementation.backends', '__doc__': 'An first-class entity in the backend', '__init__': <function BackendEntity.__init__>, 'backend': <property object>, 'dbmodel': <property object>, 'id': <abc.abstractproperty object>, 'pk': <property object>, 'store': <function BackendEntity.store>, 'is_stored': <abc.abstractproperty object>, '__dict__': <attribute '__dict__' of 'BackendEntity' objects>, '__weakref__': <attribute '__weakref__' of 'BackendEntity' objects>, '__abstractmethods__': frozenset({'store', 'is_stored', 'id'}), '_abc_impl': <_abc_data object>})
__init__(backend)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.orm.implementation.backends'
__weakref__

list of weak references to the object (if defined)

_abc_impl = <_abc_data object>
property backend

Return the backend this entity belongs to

Returns

the backend instance

property dbmodel
abstract property id

Return the id for this entity.

This is unique only amongst entities of this type for a particular backend.

Returns

the entity id

abstract property is_stored

Return whether the entity is stored.

Returns

True if stored, False otherwise

Return type

bool

property pk

Return the id for this entity.

This is unique only amongst entities of this type for a particular backend.

Returns

the entity id

abstract store()[source]

Store this entity in the backend.

Whether it is possible to call store more than once is delegated to the object itself

class aiida.orm.implementation.BackendCollection(backend)[source]

Bases: typing.Generic

Container class that represents a collection of entries of a particular backend entity.

ENTITY_CLASS = None
__dict__ = mappingproxy({'__module__': 'aiida.orm.implementation.backends', '__doc__': 'Container class that represents a collection of entries of a particular backend entity.', 'ENTITY_CLASS': None, '__init__': <function BackendCollection.__init__>, 'from_dbmodel': <function BackendCollection.from_dbmodel>, 'backend': <property object>, 'create': <function BackendCollection.create>, '__orig_bases__': (typing.Generic[~EntityType],), '__dict__': <attribute '__dict__' of 'BackendCollection' objects>, '__weakref__': <attribute '__weakref__' of 'BackendCollection' objects>, '__parameters__': (~EntityType,)})
__init__(backend)[source]
Parameters

backend (aiida.orm.implementation.Backend) – the backend this collection belongs to

__module__ = 'aiida.orm.implementation.backends'
__orig_bases__ = (typing.Generic[~EntityType],)
__parameters__ = (~EntityType,)
__weakref__

list of weak references to the object (if defined)

property backend

Return the backend.

Return type

aiida.orm.implementation.Backend

create(**kwargs)[source]

Create new a entry and set the attributes to those specified in the keyword arguments

Returns

the newly created entry of type ENTITY_CLASS

from_dbmodel(dbmodel)[source]

Create an entity from the backend dbmodel

Parameters

dbmodel – the dbmodel to create the entity from

Returns

the entity instance

class aiida.orm.implementation.BackendComment(backend)[source]

Bases: aiida.orm.implementation.backends.BackendEntity

Base class for a node comment.

__abstractmethods__ = frozenset({'content', 'ctime', 'id', 'is_stored', 'mtime', 'node', 'set_content', 'set_mtime', 'set_user', 'store', 'user'})
__module__ = 'aiida.orm.implementation.comments'
_abc_impl = <_abc_data object>
abstract property content
abstract property ctime
abstract property mtime
abstract property node
abstract set_content(value)[source]
abstract set_mtime(value)[source]
abstract set_user(value)[source]
abstract property user
property uuid
class aiida.orm.implementation.BackendCommentCollection(backend)[source]

Bases: aiida.orm.implementation.backends.BackendCollection

The collection of Comment entries.

ENTITY_CLASS

alias of BackendComment

__abstractmethods__ = frozenset({'create', 'delete', 'delete_all', 'delete_many'})
__module__ = 'aiida.orm.implementation.comments'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.comments.BackendComment],)
__parameters__ = ()
_abc_impl = <_abc_data object>
abstract create(node, user, content=None, **kwargs)[source]

Create a Comment for a given node and user

Parameters
  • node – a Node instance

  • user – a User instance

  • content – the comment content

Returns

a Comment object associated to the given node and user

abstract delete(comment_id)[source]

Remove a Comment from the collection with the given id

Parameters

comment_id (int) – the id of the comment to delete

Raises
  • TypeError – if comment_id is not an int

  • NotExistent – if Comment with ID comment_id is not found

abstract delete_all()[source]

Delete all Comment entries.

Raises

IntegrityError – if all Comments could not be deleted

abstract delete_many(filters)[source]

Delete Comments based on filters

Parameters

filters (dict) – similar to QueryBuilder filter

Returns

(former) PK s of deleted Comments

Return type

list

Raises
  • TypeError – if filters is not a dict

  • ValidationError – if filters is empty

class aiida.orm.implementation.BackendComputer(backend)[source]

Bases: aiida.orm.implementation.backends.BackendEntity

Base class to map a node in the DB + its permanent repository counterpart.

Stores attributes starting with an underscore.

Caches files and attributes before the first save, and saves everything only on store(). After the call to store(), attributes cannot be changed.

Only after storing (or upon loading from uuid) metadata can be modified and in this case they are directly set on the db.

In the plugin, also set the _plugin_type_string, to be set in the DB in the ‘type’ field.

__abstractmethods__ = frozenset({'description', 'get_description', 'get_metadata', 'get_name', 'get_scheduler_type', 'get_transport_type', 'hostname', 'id', 'is_stored', 'name', 'set_description', 'set_hostname', 'set_metadata', 'set_name', 'set_scheduler_type', 'set_transport_type', 'store'})
__module__ = 'aiida.orm.implementation.computers'
_abc_impl = <_abc_data object>
_logger = <Logger aiida.orm.implementation.computers (REPORT)>
abstract property description
abstract get_description()[source]
get_hostname()[source]

Get this computer hostname :rtype: str

abstract get_metadata()[source]
abstract get_name()[source]
abstract get_scheduler_type()[source]
abstract get_transport_type()[source]
abstract property hostname
abstract property is_stored

Is the computer stored?

Returns

True if stored, False otherwise

Return type

bool

abstract property name
abstract set_description(val)[source]
abstract set_hostname(val)[source]

Set the hostname of this computer :param val: The new hostname :type val: str

abstract set_metadata(metadata)[source]

Set the metadata.

abstract set_name(val)[source]
abstract set_scheduler_type(scheduler_type)[source]
abstract set_transport_type(transport_type)[source]
class aiida.orm.implementation.BackendComputerCollection(backend)[source]

Bases: aiida.orm.implementation.backends.BackendCollection

The collection of Computer entries.

ENTITY_CLASS

alias of BackendComputer

__abstractmethods__ = frozenset({'delete'})
__module__ = 'aiida.orm.implementation.computers'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.computers.BackendComputer],)
__parameters__ = ()
_abc_impl = <_abc_data object>
abstract delete(pk)[source]

Delete an entry with the given pk

Parameters

pk – the pk of the entry to delete

class aiida.orm.implementation.BackendGroup(backend)[source]

Bases: aiida.orm.implementation.backends.BackendEntity

An AiiDA ORM implementation of group of nodes.

__abstractmethods__ = frozenset({'__int__', 'clear', 'count', 'description', 'id', 'is_stored', 'label', 'nodes', 'store', 'type_string', 'user', 'uuid'})
abstract __int__()[source]

Convert the class to an integer. This is needed to allow querying with Django. Be careful, though, not to pass it to a wrong field! This only returns the local DB principal key (pk) value.

Returns

the integer pk of the node or None if not stored.

__module__ = 'aiida.orm.implementation.groups'
__repr__()[source]

Return repr(self).

__str__()[source]

Return str(self).

_abc_impl = <_abc_data object>
add_nodes(nodes, **kwargs)[source]

Add a set of nodes to the group.

Note

all the nodes and the group itself have to be stored.

Parameters

nodes – a list of BackendNode instances to be added to this group

abstract clear()[source]

Remove all the nodes from this group.

abstract property count

Return the number of entities in this group.

Returns

integer number of entities contained within the group

classmethod create(*args, **kwargs)[source]

Create and store a new group.

Note: This method does not check for presence of the group. You may want to use get_or_create().

Returns

group

abstract property description
Returns

the description of the group as a string

classmethod get_or_create(*args, **kwargs)[source]

Try to retrieve a group from the DB with the given arguments; create (and store) a new group if such a group was not present yet.

Returns

(group, created) where group is the group (new or existing, in any case already stored) and created is a boolean saying

abstract property id
Returns

the principal key (the ID) as an integer, or None if the node was not stored yet

abstract property is_stored

Return whether the group is stored.

Returns

boolean, True if the group is stored, False otherwise

abstract property label
Returns

the name of the group as a string

abstract property nodes

Return a generator/iterator that iterates over all nodes and returns the respective AiiDA subclasses of Node, and also allows to ask for the number of nodes in the group using len().

remove_nodes(nodes)[source]

Remove a set of nodes from the group.

Note

all the nodes and the group itself have to be stored.

Parameters

nodes – a list of BackendNode instances to be removed from this group

abstract store()[source]

Store this entity in the backend.

Whether it is possible to call store more than once is delegated to the object itself

abstract property type_string
Returns

the string defining the type of the group

abstract property user
Returns

a backend user object, representing the user associated to this group.

Return type

aiida.orm.implementation.BackendUser

abstract property uuid
Returns

a string with the uuid

class aiida.orm.implementation.BackendGroupCollection(backend)[source]

Bases: aiida.orm.implementation.backends.BackendCollection

The collection of Group entries.

ENTITY_CLASS

alias of BackendGroup

__abstractmethods__ = frozenset({'delete', 'query'})
__module__ = 'aiida.orm.implementation.groups'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.groups.BackendGroup],)
__parameters__ = ()
_abc_impl = <_abc_data object>
abstract delete(id)[source]

Delete a group with the given id

Parameters

id – the id of the group to delete

get(**filters)[source]

Get the group matching the given filters

Parameters

filters – the attributes of the group to get

Returns

the group

Return type

aiida.orm.implementation.BackendGroup

abstract query(label=None, type_string=None, pk=None, uuid=None, nodes=None, user=None, node_attributes=None, past_days=None, label_filters=None, **kwargs)[source]

Query for groups.

Note

By default, query for user-defined groups only (type_string==””). If you want to query for all type of groups, pass type_string=None. If you want to query for a specific type of groups, pass a specific string as the type_string argument.

Parameters
  • name – the name of the group

  • nodes – a node or list of nodes that belongs to the group (alternatively, you can also pass a DbNode or list of DbNodes)

  • pk – the pk of the group

  • uuid – the uuid of the group

  • type_string – the string for the type of node; by default, look only for user-defined groups (see note above).

  • user – by default, query for groups of all users; if specified, must be a DbUser object, or a string for the user email.

  • past_days – by default, query for all groups; if specified, query the groups created in the last past_days. Must be a datetime object.

  • name_filters – dictionary that can contain ‘startswith’, ‘endswith’ or ‘contains’ as keys

  • node_attributes – if not None, must be a dictionary with format {k: v}. It will filter and return only groups where there is at least a node with an attribute with key=k and value=v. Different keys of the dictionary are joined with AND (that is, the group should satisfy all requirements. v can be a base data type (str, bool, int, float, …) If it is a list or iterable, that the condition is checked so that there should be at least a node in the group with key=k and value=each of the values of the iterable.

  • kwargs

    any other filter to be passed to DbGroup.objects.filter

    Example: if node_attributes = {'elements': ['Ba', 'Ti'], 'md5sum': 'xxx'},

    it will find groups that contain the node with md5sum = ‘xxx’, and moreover contain at least one node for element ‘Ba’ and one node for element ‘Ti’.

class aiida.orm.implementation.BackendLog(backend)[source]

Bases: aiida.orm.implementation.backends.BackendEntity

Backend Log interface

__abstractmethods__ = frozenset({'dbnode_id', 'id', 'is_stored', 'levelname', 'loggername', 'message', 'metadata', 'store', 'time', 'uuid'})
__module__ = 'aiida.orm.implementation.logs'
_abc_impl = <_abc_data object>
abstract property dbnode_id

Get the id of the object that created the log entry

Returns

The id of the object that created the log entry

Return type

int

abstract property levelname

The name of the log level

Returns

The entry log level name

Return type

basestring

abstract property loggername

The name of the logger that created this entry

Returns

The entry loggername

Return type

basestring

abstract property message

Get the message corresponding to the entry

Returns

The entry message

Return type

basestring

abstract property metadata

Get the metadata corresponding to the entry

Returns

The entry metadata

Return type

dict

abstract property time

Get the time corresponding to the entry

Returns

The entry timestamp

Return type

datetime.datetime

abstract property uuid

Get the UUID of the log entry

Returns

The entry’s UUID

Return type

uuid.UUID

class aiida.orm.implementation.BackendLogCollection(backend)[source]

Bases: aiida.orm.implementation.backends.BackendCollection

The collection of Log entries.

ENTITY_CLASS

alias of BackendLog

__abstractmethods__ = frozenset({'delete', 'delete_all', 'delete_many'})
__module__ = 'aiida.orm.implementation.logs'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.logs.BackendLog],)
__parameters__ = ()
_abc_impl = <_abc_data object>
abstract delete(log_id)[source]

Remove a Log entry from the collection with the given id

Parameters

log_id (int) – id of the Log to delete

Raises
  • TypeError – if log_id is not an int

  • NotExistent – if Log with ID log_id is not found

abstract delete_all()[source]

Delete all Log entries.

Raises

IntegrityError – if all Logs could not be deleted

abstract delete_many(filters)[source]

Delete Logs based on filters

Parameters

filters (dict) – similar to QueryBuilder filter

Returns

(former) PK s of deleted Logs

Return type

list

Raises
  • TypeError – if filters is not a dict

  • ValidationError – if filters is empty

class aiida.orm.implementation.BackendNode(backend)[source]

Bases: aiida.orm.implementation.backends.BackendEntity

Wrapper around a DbNode instance to set and retrieve data independent of the database implementation.

__abstractmethods__ = frozenset({'add_incoming', 'attributes', 'attributes_items', 'attributes_keys', 'clear_attributes', 'clear_extras', 'clone', 'computer', 'delete_attribute', 'delete_attribute_many', 'delete_extra', 'delete_extra_many', 'extras', 'extras_items', 'extras_keys', 'get_attribute', 'get_attribute_many', 'get_extra', 'get_extra_many', 'id', 'is_stored', 'reset_attributes', 'reset_extras', 'set_attribute', 'set_attribute_many', 'set_extra', 'set_extra_many', 'store', 'user'})
__module__ = 'aiida.orm.implementation.nodes'
_abc_impl = <_abc_data object>
abstract add_incoming(source, link_type, link_label)[source]

Add a link of the given type from a given node to ourself.

Parameters
  • source – the node from which the link is coming

  • link_type – the link type

  • link_label – the link label

Returns

True if the proposed link is allowed, False otherwise

Raises
  • TypeError – if source is not a Node instance or link_type is not a LinkType enum

  • ValueError – if the proposed link is invalid

abstract property attributes

Return the complete attributes dictionary.

Warning

While the node is unstored, this will return references of the attributes on the database model, meaning that changes on the returned values (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the node is stored, the returned attributes will be a deep copy and mutations of the database attributes will have to go through the appropriate set methods. Therefore, once stored, retrieving a deep copy can be a heavy operation. If you only need the keys or some values, use the iterators attributes_keys and attributes_items, or the getters get_attribute and get_attribute_many instead.

Returns

the attributes as a dictionary

abstract attributes_items()[source]

Return an iterator over the attributes.

Returns

an iterator with attribute key value pairs

abstract attributes_keys()[source]

Return an iterator over the attribute keys.

Returns

an iterator with attribute keys

abstract clear_attributes()[source]

Delete all attributes.

abstract clear_extras()[source]

Delete all extras.

abstract clone()[source]

Return an unstored clone of ourselves.

Returns

an unstored BackendNode with the exact same attributes and extras as self

abstract property computer

Return the computer of this node.

Returns

the computer or None

Return type

BackendComputer or None

property ctime

Return the node ctime.

Returns

the ctime

abstract delete_attribute(key)[source]

Delete an attribute.

Parameters

key – name of the attribute

Raises

AttributeError – if the attribute does not exist

abstract delete_attribute_many(keys)[source]

Delete multiple attributes.

Parameters

keys – names of the attributes to delete

Raises

AttributeError – if at least one of the attribute does not exist

abstract delete_extra(key)[source]

Delete an extra.

Parameters

key – name of the extra

Raises

AttributeError – if the extra does not exist

abstract delete_extra_many(keys)[source]

Delete multiple extras.

Parameters

keys – names of the extras to delete

Raises

AttributeError – if at least one of the extra does not exist

property description

Return the node description.

Returns

the description

abstract property extras

Return the complete extras dictionary.

Warning

While the node is unstored, this will return references of the extras on the database model, meaning that changes on the returned values (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the node is stored, the returned extras will be a deep copy and mutations of the database extras will have to go through the appropriate set methods. Therefore, once stored, retrieving a deep copy can be a heavy operation. If you only need the keys or some values, use the iterators extras_keys and extras_items, or the getters get_extra and get_extra_many instead.

Returns

the extras as a dictionary

abstract extras_items()[source]

Return an iterator over the extras.

Returns

an iterator with extra key value pairs

abstract extras_keys()[source]

Return an iterator over the extra keys.

Returns

an iterator with extra keys

abstract get_attribute(key)[source]

Return the value of an attribute.

Warning

While the node is unstored, this will return a reference of the attribute on the database model, meaning that changes on the returned value (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the node is stored, the returned attribute will be a deep copy and mutations of the database attributes will have to go through the appropriate set methods.

Parameters

key – name of the attribute

Returns

the value of the attribute

Raises

AttributeError – if the attribute does not exist and no default is specified

abstract get_attribute_many(keys)[source]

Return the values of multiple attributes.

Warning

While the node is unstored, this will return references of the attributes on the database model, meaning that changes on the returned values (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the node is stored, the returned attributes will be a deep copy and mutations of the database attributes will have to go through the appropriate set methods. Therefore, once stored, retrieving a deep copy can be a heavy operation. If you only need the keys or some values, use the iterators attributes_keys and attributes_items, or the getters get_attribute and get_attribute_many instead.

Parameters

keys – a list of attribute names

Returns

a list of attribute values

Raises

AttributeError – if at least one attribute does not exist

abstract get_extra(key)[source]

Return the value of an extra.

Warning

While the node is unstored, this will return a reference of the extra on the database model, meaning that changes on the returned value (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the node is stored, the returned extra will be a deep copy and mutations of the database extras will have to go through the appropriate set methods.

Parameters

key – name of the extra

Returns

the value of the extra

Raises

AttributeError – if the extra does not exist and no default is specified

abstract get_extra_many(keys)[source]

Return the values of multiple extras.

Warning

While the node is unstored, this will return references of the extras on the database model, meaning that changes on the returned values (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the node is stored, the returned extras will be a deep copy and mutations of the database extras will have to go through the appropriate set methods. Therefore, once stored, retrieving a deep copy can be a heavy operation. If you only need the keys or some values, use the iterators extras_keys and extras_items, or the getters get_extra and get_extra_many instead.

Parameters

keys – a list of extra names

Returns

a list of extra values

Raises

AttributeError – if at least one extra does not exist

property label

Return the node label.

Returns

the label

property mtime

Return the node mtime.

Returns

the mtime

property node_type

Return the node type.

Returns

the node type

property process_type

Return the node process type.

Returns

the process type

abstract reset_attributes(attributes)[source]

Reset the attributes.

Note

This will completely clear any existing attributes and replace them with the new dictionary.

Parameters

attributes – a dictionary with the attributes to set

abstract reset_extras(extras)[source]

Reset the extras.

Note

This will completely clear any existing extras and replace them with the new dictionary.

Parameters

extras – a dictionary with the extras to set

abstract set_attribute(key, value)[source]

Set an attribute to the given value.

Parameters
  • key – name of the attribute

  • value – value of the attribute

abstract set_attribute_many(attributes)[source]

Set multiple attributes.

Note

This will override any existing attributes that are present in the new dictionary.

Parameters

attributes – a dictionary with the attributes to set

abstract set_extra(key, value)[source]

Set an extra to the given value.

Parameters
  • key – name of the extra

  • value – value of the extra

abstract set_extra_many(extras)[source]

Set multiple extras.

Note

This will override any existing extras that are present in the new dictionary.

Parameters

extras – a dictionary with the extras to set

abstract store(links=None, with_transaction=True, clean=True)[source]

Store the node in the database.

Parameters
  • links – optional links to add before storing

  • with_transaction – if False, do not use a transaction because the caller will already have opened one.

  • clean – boolean, if True, will clean the attributes and extras before attempting to store

abstract property user

Return the user of this node.

Returns

the user

Return type

BackendUser

property uuid

Return the node UUID.

Returns

the string representation of the UUID

Return type

str or None

class aiida.orm.implementation.BackendNodeCollection(backend)[source]

Bases: aiida.orm.implementation.backends.BackendCollection

The collection of BackendNode entries.

ENTITY_CLASS

alias of BackendNode

__abstractmethods__ = frozenset({'delete', 'get'})
__module__ = 'aiida.orm.implementation.nodes'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.nodes.BackendNode],)
__parameters__ = ()
_abc_impl = <_abc_data object>
abstract delete(pk)[source]

Remove a Node entry from the collection with the given id

Parameters

pk – id of the node to delete

abstract get(pk)[source]

Return a Node entry from the collection with the given id

Parameters

pk – id of the node

class aiida.orm.implementation.BackendQueryBuilder(backend)[source]

Bases: object

Backend query builder interface

property AiidaNode

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

abstract AuthInfo()[source]

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

abstract Comment()[source]

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

abstract Computer()[source]

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

abstract Group()[source]

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

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

abstract Log()[source]

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

abstract 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.

abstract User()[source]

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

__abstractmethods__ = frozenset({'AuthInfo', 'Comment', 'Computer', 'Group', 'Link', 'Log', 'Node', 'User', 'count', 'first', 'get_aiida_res', 'get_column_names', 'get_filter_expr_from_attributes', 'get_projectable_attribute', 'get_session', 'iterall', 'iterdict', 'modify_expansions', 'table_groups_nodes', 'yield_per'})
__dict__ = mappingproxy({'__module__': 'aiida.orm.implementation.querybuilder', '__doc__': 'Backend query builder interface', 'outer_to_inner_schema': None, 'inner_to_outer_schema': None, '__init__': <function BackendQueryBuilder.__init__>, 'Node': <function BackendQueryBuilder.Node>, 'Link': <function BackendQueryBuilder.Link>, 'Computer': <function BackendQueryBuilder.Computer>, 'User': <function BackendQueryBuilder.User>, 'Group': <function BackendQueryBuilder.Group>, 'AuthInfo': <function BackendQueryBuilder.AuthInfo>, 'Comment': <function BackendQueryBuilder.Comment>, 'Log': <function BackendQueryBuilder.Log>, 'table_groups_nodes': <function BackendQueryBuilder.table_groups_nodes>, 'AiidaNode': <property object>, 'get_session': <function BackendQueryBuilder.get_session>, 'modify_expansions': <function BackendQueryBuilder.modify_expansions>, 'get_filter_expr_from_attributes': <aiida.common.lang.abstractclassmethod object>, 'get_corresponding_properties': <classmethod object>, 'get_corresponding_property': <classmethod object>, 'get_filter_expr_from_column': <classmethod object>, 'get_projectable_attribute': <function BackendQueryBuilder.get_projectable_attribute>, 'get_aiida_res': <function BackendQueryBuilder.get_aiida_res>, 'yield_per': <function BackendQueryBuilder.yield_per>, 'count': <function BackendQueryBuilder.count>, 'first': <function BackendQueryBuilder.first>, 'iterall': <function BackendQueryBuilder.iterall>, 'iterdict': <function BackendQueryBuilder.iterdict>, 'get_column_names': <function BackendQueryBuilder.get_column_names>, 'get_column': <function BackendQueryBuilder.get_column>, '__dict__': <attribute '__dict__' of 'BackendQueryBuilder' objects>, '__weakref__': <attribute '__weakref__' of 'BackendQueryBuilder' objects>, '__abstractmethods__': frozenset({'modify_expansions', 'count', 'Comment', 'first', 'get_session', 'iterdict', 'iterall', 'AuthInfo', 'Link', 'Node', 'User', 'get_aiida_res', 'table_groups_nodes', 'Group', 'Log', 'yield_per', 'get_filter_expr_from_attributes', 'get_projectable_attribute', 'get_column_names', 'Computer'}), '_abc_impl': <_abc_data object>})
__init__(backend)[source]
Parameters

backend – the backend

__module__ = 'aiida.orm.implementation.querybuilder'
__weakref__

list of weak references to the object (if defined)

_abc_impl = <_abc_data object>
abstract count(query)[source]
Returns

the number of results

abstract first(query)[source]

Executes query in the backend asking for one instance.

Returns

One row of aiida results

abstract 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_column(colname, alias)[source]

Return the column for a given projection.

abstract get_column_names(alias)[source]

Return the column names of the given table (alias).

classmethod get_corresponding_properties(entity_table, given_properties, mapper)[source]

This method returns a list of updated properties for a given list of properties. If there is no update for the property, the given property is returned in the list.

classmethod get_corresponding_property(entity_table, given_property, mapper)[source]

This method returns an updated property for a given a property. If there is no update for the property, the given property is returned.

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

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

classmethod get_filter_expr_from_column(operator, value, column)[source]

A method 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’])

  • column – an instance of sqlalchemy.orm.attributes.InstrumentedAttribute or

Returns

An instance of sqlalchemy.sql.elements.BinaryExpression

abstract get_projectable_attribute(alias, column_name, attrpath, cast=None, **kwargs)[source]
abstract get_session()[source]
Returns

a valid session, an instance of sqlalchemy.orm.session.Session

inner_to_outer_schema = None
abstract iterall(query, batch_size, tag_to_index_dict)[source]
Returns

An iterator over all the results of a list of lists.

abstract iterdict(query, batch_size, tag_to_projected_properties_dict, tag_to_alias_map)[source]
Returns

An iterator over all the results of a list of dictionaries.

abstract modify_expansions(alias, expansions)[source]

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

outer_to_inner_schema = None
abstract table_groups_nodes()[source]

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

abstract yield_per(query, batch_size)[source]
Parameters

batch_size (int) – Number of rows to yield per step

Yields count rows at a time

Returns

a generator

class aiida.orm.implementation.BackendUser(backend)[source]

Bases: aiida.orm.implementation.backends.BackendEntity

This is the base class for User information in AiiDA. An implementing backend needs to provide a concrete version.

REQUIRED_FIELDS = ['first_name', 'last_name', 'institution']
__abstractmethods__ = frozenset({'email', 'first_name', 'id', 'institution', 'is_stored', 'last_name', 'store'})
__module__ = 'aiida.orm.implementation.users'
_abc_impl = <_abc_data object>
abstract property email

Get the email address of the user

Returns

the email address

abstract property first_name

Get the user’s first name

Returns

the first name

Return type

str

abstract property institution

Get the user’s institution

Returns

the institution

Return type

str

abstract property last_name

Get the user’s last name

Returns

the last name

Return type

str

property uuid

For now users do not have UUIDs so always return false

Returns

None

class aiida.orm.implementation.BackendUserCollection(backend)[source]

Bases: aiida.orm.implementation.backends.BackendCollection

ENTITY_CLASS

alias of BackendUser

__module__ = 'aiida.orm.implementation.users'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.users.BackendUser],)
__parameters__ = ()

Submodules

Module for the backend implementation of the AuthInfo ORM class.

class aiida.orm.implementation.authinfos.BackendAuthInfo(backend)[source]

Bases: aiida.orm.implementation.backends.BackendEntity

Backend implementation for the AuthInfo ORM class.

METADATA_WORKDIR = 'workdir'
__abstractmethods__ = frozenset({'computer', 'enabled', 'get_auth_params', 'get_metadata', 'id', 'is_stored', 'set_auth_params', 'set_metadata', 'store', 'user'})
__module__ = 'aiida.orm.implementation.authinfos'
_abc_impl = <_abc_data object>
abstract property computer

Return the computer associated with this instance.

Returns

aiida.orm.implementation.computers.BackendComputer

abstract property enabled

Return whether this instance is enabled.

Returns

boolean, True if enabled, False otherwise

abstract get_auth_params()[source]

Return the dictionary of authentication parameters

Returns

a dictionary with authentication parameters

abstract get_metadata()[source]

Return the dictionary of metadata

Returns

a dictionary with metadata

abstract set_auth_params(auth_params)[source]

Set the dictionary of authentication parameters

Parameters

auth_params – a dictionary with authentication parameters

abstract set_metadata(metadata)[source]

Set the dictionary of metadata

Parameters

metadata – a dictionary with metadata

abstract property user

Return the user associated with this instance.

Returns

aiida.orm.implementation.users.BackendUser

class aiida.orm.implementation.authinfos.BackendAuthInfoCollection(backend)[source]

Bases: aiida.orm.implementation.backends.BackendCollection

The collection of backend AuthInfo entries.

ENTITY_CLASS

alias of BackendAuthInfo

__abstractmethods__ = frozenset({'delete', 'get'})
__module__ = 'aiida.orm.implementation.authinfos'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.authinfos.BackendAuthInfo],)
__parameters__ = ()
_abc_impl = <_abc_data object>
abstract delete(pk)[source]

Delete an entry from the collection.

Parameters

pk – the pk of the entry to delete

abstract get(computer, user)[source]

Return an entry from the collection that is configured for the given computer and user

Parameters
Returns

aiida.orm.implementation.authinfos.BackendAuthInfo

Raises

Generic backend related objects

class aiida.orm.implementation.backends.Backend[source]

Bases: object

The public interface that defines a backend factory that creates backend specific concrete objects.

__abstractmethods__ = frozenset({'authinfos', 'comments', 'computers', 'groups', 'logs', 'migrate', 'nodes', 'query', 'query_manager', 'transaction', 'users'})
__dict__ = mappingproxy({'__module__': 'aiida.orm.implementation.backends', '__doc__': 'The public interface that defines a backend factory that creates backend specific concrete objects.', 'migrate': <function Backend.migrate>, 'authinfos': <abc.abstractproperty object>, 'comments': <abc.abstractproperty object>, 'computers': <abc.abstractproperty object>, 'groups': <abc.abstractproperty object>, 'logs': <abc.abstractproperty object>, 'nodes': <abc.abstractproperty object>, 'query_manager': <abc.abstractproperty object>, 'query': <function Backend.query>, 'users': <abc.abstractproperty object>, 'transaction': <function Backend.transaction>, '__dict__': <attribute '__dict__' of 'Backend' objects>, '__weakref__': <attribute '__weakref__' of 'Backend' objects>, '__abstractmethods__': frozenset({'comments', 'groups', 'authinfos', 'logs', 'query_manager', 'transaction', 'nodes', 'computers', 'query', 'migrate', 'users'}), '_abc_impl': <_abc_data object>})
__module__ = 'aiida.orm.implementation.backends'
__weakref__

list of weak references to the object (if defined)

_abc_impl = <_abc_data object>
abstract property authinfos

Return the collection of authorisation information objects

Returns

the authinfo collection

Return type

aiida.orm.implementation.BackendAuthInfoCollection

abstract property comments

Return the collection of comments

Returns

the comment collection

Return type

aiida.orm.implementation.BackendCommentCollection

abstract property computers

Return the collection of computers

Returns

the computers collection

Return type

aiida.orm.implementation.BackendComputerCollection

abstract property groups

Return the collection of groups

Returns

the groups collection

Return type

aiida.orm.implementation.BackendGroupCollection

abstract property logs

Return the collection of logs

Returns

the log collection

Return type

aiida.orm.implementation.BackendLogCollection

abstract migrate()[source]

Migrate the database to the latest schema version.

abstract property nodes

Return the collection of nodes

Returns

the nodes collection

Return type

aiida.orm.implementation.BackendNodeCollection

abstract query()[source]

Return an instance of a query builder implementation for this backend

Returns

a new query builder instance

Return type

aiida.orm.implementation.BackendQueryBuilder

abstract property query_manager

Return the query manager for the objects stored in the backend

Returns

The query manger

Return type

aiida.backends.general.abstractqueries.AbstractQueryManager

abstract transaction()[source]

Get a context manager that can be used as a transaction context for a series of backend operations. If there is an exception within the context then the changes will be rolled back and the state will be as before entering. Transactions can be nested.

Returns

a context manager to group database operations

abstract property users

Return the collection of users

Returns

the users collection

Return type

aiida.orm.implementation.BackendUserCollection

class aiida.orm.implementation.backends.BackendEntity(backend)[source]

Bases: object

An first-class entity in the backend

__abstractmethods__ = frozenset({'id', 'is_stored', 'store'})
__dict__ = mappingproxy({'__module__': 'aiida.orm.implementation.backends', '__doc__': 'An first-class entity in the backend', '__init__': <function BackendEntity.__init__>, 'backend': <property object>, 'dbmodel': <property object>, 'id': <abc.abstractproperty object>, 'pk': <property object>, 'store': <function BackendEntity.store>, 'is_stored': <abc.abstractproperty object>, '__dict__': <attribute '__dict__' of 'BackendEntity' objects>, '__weakref__': <attribute '__weakref__' of 'BackendEntity' objects>, '__abstractmethods__': frozenset({'store', 'is_stored', 'id'}), '_abc_impl': <_abc_data object>})
__init__(backend)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.orm.implementation.backends'
__weakref__

list of weak references to the object (if defined)

_abc_impl = <_abc_data object>
property backend

Return the backend this entity belongs to

Returns

the backend instance

property dbmodel
abstract property id

Return the id for this entity.

This is unique only amongst entities of this type for a particular backend.

Returns

the entity id

abstract property is_stored

Return whether the entity is stored.

Returns

True if stored, False otherwise

Return type

bool

property pk

Return the id for this entity.

This is unique only amongst entities of this type for a particular backend.

Returns

the entity id

abstract store()[source]

Store this entity in the backend.

Whether it is possible to call store more than once is delegated to the object itself

class aiida.orm.implementation.backends.BackendCollection(backend)[source]

Bases: typing.Generic

Container class that represents a collection of entries of a particular backend entity.

ENTITY_CLASS = None
__dict__ = mappingproxy({'__module__': 'aiida.orm.implementation.backends', '__doc__': 'Container class that represents a collection of entries of a particular backend entity.', 'ENTITY_CLASS': None, '__init__': <function BackendCollection.__init__>, 'from_dbmodel': <function BackendCollection.from_dbmodel>, 'backend': <property object>, 'create': <function BackendCollection.create>, '__orig_bases__': (typing.Generic[~EntityType],), '__dict__': <attribute '__dict__' of 'BackendCollection' objects>, '__weakref__': <attribute '__weakref__' of 'BackendCollection' objects>, '__parameters__': (~EntityType,)})
__init__(backend)[source]
Parameters

backend (aiida.orm.implementation.Backend) – the backend this collection belongs to

__module__ = 'aiida.orm.implementation.backends'
__orig_bases__ = (typing.Generic[~EntityType],)
__parameters__ = (~EntityType,)
__weakref__

list of weak references to the object (if defined)

property backend

Return the backend.

Return type

aiida.orm.implementation.Backend

create(**kwargs)[source]

Create new a entry and set the attributes to those specified in the keyword arguments

Returns

the newly created entry of type ENTITY_CLASS

from_dbmodel(dbmodel)[source]

Create an entity from the backend dbmodel

Parameters

dbmodel – the dbmodel to create the entity from

Returns

the entity instance

Module for comment backend classes.

class aiida.orm.implementation.comments.BackendComment(backend)[source]

Bases: aiida.orm.implementation.backends.BackendEntity

Base class for a node comment.

__abstractmethods__ = frozenset({'content', 'ctime', 'id', 'is_stored', 'mtime', 'node', 'set_content', 'set_mtime', 'set_user', 'store', 'user'})
__module__ = 'aiida.orm.implementation.comments'
_abc_impl = <_abc_data object>
abstract property content
abstract property ctime
abstract property mtime
abstract property node
abstract set_content(value)[source]
abstract set_mtime(value)[source]
abstract set_user(value)[source]
abstract property user
property uuid
class aiida.orm.implementation.comments.BackendCommentCollection(backend)[source]

Bases: aiida.orm.implementation.backends.BackendCollection

The collection of Comment entries.

ENTITY_CLASS

alias of BackendComment

__abstractmethods__ = frozenset({'create', 'delete', 'delete_all', 'delete_many'})
__module__ = 'aiida.orm.implementation.comments'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.comments.BackendComment],)
__parameters__ = ()
_abc_impl = <_abc_data object>
abstract create(node, user, content=None, **kwargs)[source]

Create a Comment for a given node and user

Parameters
  • node – a Node instance

  • user – a User instance

  • content – the comment content

Returns

a Comment object associated to the given node and user

abstract delete(comment_id)[source]

Remove a Comment from the collection with the given id

Parameters

comment_id (int) – the id of the comment to delete

Raises
  • TypeError – if comment_id is not an int

  • NotExistent – if Comment with ID comment_id is not found

abstract delete_all()[source]

Delete all Comment entries.

Raises

IntegrityError – if all Comments could not be deleted

abstract delete_many(filters)[source]

Delete Comments based on filters

Parameters

filters (dict) – similar to QueryBuilder filter

Returns

(former) PK s of deleted Comments

Return type

list

Raises
  • TypeError – if filters is not a dict

  • ValidationError – if filters is empty

Backend specific computer objects and methods

class aiida.orm.implementation.computers.BackendComputer(backend)[source]

Bases: aiida.orm.implementation.backends.BackendEntity

Base class to map a node in the DB + its permanent repository counterpart.

Stores attributes starting with an underscore.

Caches files and attributes before the first save, and saves everything only on store(). After the call to store(), attributes cannot be changed.

Only after storing (or upon loading from uuid) metadata can be modified and in this case they are directly set on the db.

In the plugin, also set the _plugin_type_string, to be set in the DB in the ‘type’ field.

__abstractmethods__ = frozenset({'description', 'get_description', 'get_metadata', 'get_name', 'get_scheduler_type', 'get_transport_type', 'hostname', 'id', 'is_stored', 'name', 'set_description', 'set_hostname', 'set_metadata', 'set_name', 'set_scheduler_type', 'set_transport_type', 'store'})
__module__ = 'aiida.orm.implementation.computers'
_abc_impl = <_abc_data object>
_logger = <Logger aiida.orm.implementation.computers (REPORT)>
abstract property description
abstract get_description()[source]
get_hostname()[source]

Get this computer hostname :rtype: str

abstract get_metadata()[source]
abstract get_name()[source]
abstract get_scheduler_type()[source]
abstract get_transport_type()[source]
abstract property hostname
abstract property is_stored

Is the computer stored?

Returns

True if stored, False otherwise

Return type

bool

abstract property name
abstract set_description(val)[source]
abstract set_hostname(val)[source]

Set the hostname of this computer :param val: The new hostname :type val: str

abstract set_metadata(metadata)[source]

Set the metadata.

abstract set_name(val)[source]
abstract set_scheduler_type(scheduler_type)[source]
abstract set_transport_type(transport_type)[source]
class aiida.orm.implementation.computers.BackendComputerCollection(backend)[source]

Bases: aiida.orm.implementation.backends.BackendCollection

The collection of Computer entries.

ENTITY_CLASS

alias of BackendComputer

__abstractmethods__ = frozenset({'delete'})
__module__ = 'aiida.orm.implementation.computers'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.computers.BackendComputer],)
__parameters__ = ()
_abc_impl = <_abc_data object>
abstract delete(pk)[source]

Delete an entry with the given pk

Parameters

pk – the pk of the entry to delete

Backend group module

class aiida.orm.implementation.groups.BackendGroup(backend)[source]

Bases: aiida.orm.implementation.backends.BackendEntity

An AiiDA ORM implementation of group of nodes.

__abstractmethods__ = frozenset({'__int__', 'clear', 'count', 'description', 'id', 'is_stored', 'label', 'nodes', 'store', 'type_string', 'user', 'uuid'})
abstract __int__()[source]

Convert the class to an integer. This is needed to allow querying with Django. Be careful, though, not to pass it to a wrong field! This only returns the local DB principal key (pk) value.

Returns

the integer pk of the node or None if not stored.

__module__ = 'aiida.orm.implementation.groups'
__repr__()[source]

Return repr(self).

__str__()[source]

Return str(self).

_abc_impl = <_abc_data object>
add_nodes(nodes, **kwargs)[source]

Add a set of nodes to the group.

Note

all the nodes and the group itself have to be stored.

Parameters

nodes – a list of BackendNode instances to be added to this group

abstract clear()[source]

Remove all the nodes from this group.

abstract property count

Return the number of entities in this group.

Returns

integer number of entities contained within the group

classmethod create(*args, **kwargs)[source]

Create and store a new group.

Note: This method does not check for presence of the group. You may want to use get_or_create().

Returns

group

abstract property description
Returns

the description of the group as a string

classmethod get_or_create(*args, **kwargs)[source]

Try to retrieve a group from the DB with the given arguments; create (and store) a new group if such a group was not present yet.

Returns

(group, created) where group is the group (new or existing, in any case already stored) and created is a boolean saying

abstract property id
Returns

the principal key (the ID) as an integer, or None if the node was not stored yet

abstract property is_stored

Return whether the group is stored.

Returns

boolean, True if the group is stored, False otherwise

abstract property label
Returns

the name of the group as a string

abstract property nodes

Return a generator/iterator that iterates over all nodes and returns the respective AiiDA subclasses of Node, and also allows to ask for the number of nodes in the group using len().

remove_nodes(nodes)[source]

Remove a set of nodes from the group.

Note

all the nodes and the group itself have to be stored.

Parameters

nodes – a list of BackendNode instances to be removed from this group

abstract store()[source]

Store this entity in the backend.

Whether it is possible to call store more than once is delegated to the object itself

abstract property type_string
Returns

the string defining the type of the group

abstract property user
Returns

a backend user object, representing the user associated to this group.

Return type

aiida.orm.implementation.BackendUser

abstract property uuid
Returns

a string with the uuid

class aiida.orm.implementation.groups.BackendGroupCollection(backend)[source]

Bases: aiida.orm.implementation.backends.BackendCollection

The collection of Group entries.

ENTITY_CLASS

alias of BackendGroup

__abstractmethods__ = frozenset({'delete', 'query'})
__module__ = 'aiida.orm.implementation.groups'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.groups.BackendGroup],)
__parameters__ = ()
_abc_impl = <_abc_data object>
abstract delete(id)[source]

Delete a group with the given id

Parameters

id – the id of the group to delete

get(**filters)[source]

Get the group matching the given filters

Parameters

filters – the attributes of the group to get

Returns

the group

Return type

aiida.orm.implementation.BackendGroup

abstract query(label=None, type_string=None, pk=None, uuid=None, nodes=None, user=None, node_attributes=None, past_days=None, label_filters=None, **kwargs)[source]

Query for groups.

Note

By default, query for user-defined groups only (type_string==””). If you want to query for all type of groups, pass type_string=None. If you want to query for a specific type of groups, pass a specific string as the type_string argument.

Parameters
  • name – the name of the group

  • nodes – a node or list of nodes that belongs to the group (alternatively, you can also pass a DbNode or list of DbNodes)

  • pk – the pk of the group

  • uuid – the uuid of the group

  • type_string – the string for the type of node; by default, look only for user-defined groups (see note above).

  • user – by default, query for groups of all users; if specified, must be a DbUser object, or a string for the user email.

  • past_days – by default, query for all groups; if specified, query the groups created in the last past_days. Must be a datetime object.

  • name_filters – dictionary that can contain ‘startswith’, ‘endswith’ or ‘contains’ as keys

  • node_attributes – if not None, must be a dictionary with format {k: v}. It will filter and return only groups where there is at least a node with an attribute with key=k and value=v. Different keys of the dictionary are joined with AND (that is, the group should satisfy all requirements. v can be a base data type (str, bool, int, float, …) If it is a list or iterable, that the condition is checked so that there should be at least a node in the group with key=k and value=each of the values of the iterable.

  • kwargs

    any other filter to be passed to DbGroup.objects.filter

    Example: if node_attributes = {'elements': ['Ba', 'Ti'], 'md5sum': 'xxx'},

    it will find groups that contain the node with md5sum = ‘xxx’, and moreover contain at least one node for element ‘Ba’ and one node for element ‘Ti’.

Backend group module

class aiida.orm.implementation.logs.BackendLog(backend)[source]

Bases: aiida.orm.implementation.backends.BackendEntity

Backend Log interface

__abstractmethods__ = frozenset({'dbnode_id', 'id', 'is_stored', 'levelname', 'loggername', 'message', 'metadata', 'store', 'time', 'uuid'})
__module__ = 'aiida.orm.implementation.logs'
_abc_impl = <_abc_data object>
abstract property dbnode_id

Get the id of the object that created the log entry

Returns

The id of the object that created the log entry

Return type

int

abstract property levelname

The name of the log level

Returns

The entry log level name

Return type

basestring

abstract property loggername

The name of the logger that created this entry

Returns

The entry loggername

Return type

basestring

abstract property message

Get the message corresponding to the entry

Returns

The entry message

Return type

basestring

abstract property metadata

Get the metadata corresponding to the entry

Returns

The entry metadata

Return type

dict

abstract property time

Get the time corresponding to the entry

Returns

The entry timestamp

Return type

datetime.datetime

abstract property uuid

Get the UUID of the log entry

Returns

The entry’s UUID

Return type

uuid.UUID

class aiida.orm.implementation.logs.BackendLogCollection(backend)[source]

Bases: aiida.orm.implementation.backends.BackendCollection

The collection of Log entries.

ENTITY_CLASS

alias of BackendLog

__abstractmethods__ = frozenset({'delete', 'delete_all', 'delete_many'})
__module__ = 'aiida.orm.implementation.logs'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.logs.BackendLog],)
__parameters__ = ()
_abc_impl = <_abc_data object>
abstract delete(log_id)[source]

Remove a Log entry from the collection with the given id

Parameters

log_id (int) – id of the Log to delete

Raises
  • TypeError – if log_id is not an int

  • NotExistent – if Log with ID log_id is not found

abstract delete_all()[source]

Delete all Log entries.

Raises

IntegrityError – if all Logs could not be deleted

abstract delete_many(filters)[source]

Delete Logs based on filters

Parameters

filters (dict) – similar to QueryBuilder filter

Returns

(former) PK s of deleted Logs

Return type

list

Raises
  • TypeError – if filters is not a dict

  • ValidationError – if filters is empty

Abstract BackendNode and BackendNodeCollection implementation.

class aiida.orm.implementation.nodes.BackendNode(backend)[source]

Bases: aiida.orm.implementation.backends.BackendEntity

Wrapper around a DbNode instance to set and retrieve data independent of the database implementation.

__abstractmethods__ = frozenset({'add_incoming', 'attributes', 'attributes_items', 'attributes_keys', 'clear_attributes', 'clear_extras', 'clone', 'computer', 'delete_attribute', 'delete_attribute_many', 'delete_extra', 'delete_extra_many', 'extras', 'extras_items', 'extras_keys', 'get_attribute', 'get_attribute_many', 'get_extra', 'get_extra_many', 'id', 'is_stored', 'reset_attributes', 'reset_extras', 'set_attribute', 'set_attribute_many', 'set_extra', 'set_extra_many', 'store', 'user'})
__module__ = 'aiida.orm.implementation.nodes'
_abc_impl = <_abc_data object>
abstract add_incoming(source, link_type, link_label)[source]

Add a link of the given type from a given node to ourself.

Parameters
  • source – the node from which the link is coming

  • link_type – the link type

  • link_label – the link label

Returns

True if the proposed link is allowed, False otherwise

Raises
  • TypeError – if source is not a Node instance or link_type is not a LinkType enum

  • ValueError – if the proposed link is invalid

abstract property attributes

Return the complete attributes dictionary.

Warning

While the node is unstored, this will return references of the attributes on the database model, meaning that changes on the returned values (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the node is stored, the returned attributes will be a deep copy and mutations of the database attributes will have to go through the appropriate set methods. Therefore, once stored, retrieving a deep copy can be a heavy operation. If you only need the keys or some values, use the iterators attributes_keys and attributes_items, or the getters get_attribute and get_attribute_many instead.

Returns

the attributes as a dictionary

abstract attributes_items()[source]

Return an iterator over the attributes.

Returns

an iterator with attribute key value pairs

abstract attributes_keys()[source]

Return an iterator over the attribute keys.

Returns

an iterator with attribute keys

abstract clear_attributes()[source]

Delete all attributes.

abstract clear_extras()[source]

Delete all extras.

abstract clone()[source]

Return an unstored clone of ourselves.

Returns

an unstored BackendNode with the exact same attributes and extras as self

abstract property computer

Return the computer of this node.

Returns

the computer or None

Return type

BackendComputer or None

property ctime

Return the node ctime.

Returns

the ctime

abstract delete_attribute(key)[source]

Delete an attribute.

Parameters

key – name of the attribute

Raises

AttributeError – if the attribute does not exist

abstract delete_attribute_many(keys)[source]

Delete multiple attributes.

Parameters

keys – names of the attributes to delete

Raises

AttributeError – if at least one of the attribute does not exist

abstract delete_extra(key)[source]

Delete an extra.

Parameters

key – name of the extra

Raises

AttributeError – if the extra does not exist

abstract delete_extra_many(keys)[source]

Delete multiple extras.

Parameters

keys – names of the extras to delete

Raises

AttributeError – if at least one of the extra does not exist

property description

Return the node description.

Returns

the description

abstract property extras

Return the complete extras dictionary.

Warning

While the node is unstored, this will return references of the extras on the database model, meaning that changes on the returned values (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the node is stored, the returned extras will be a deep copy and mutations of the database extras will have to go through the appropriate set methods. Therefore, once stored, retrieving a deep copy can be a heavy operation. If you only need the keys or some values, use the iterators extras_keys and extras_items, or the getters get_extra and get_extra_many instead.

Returns

the extras as a dictionary

abstract extras_items()[source]

Return an iterator over the extras.

Returns

an iterator with extra key value pairs

abstract extras_keys()[source]

Return an iterator over the extra keys.

Returns

an iterator with extra keys

abstract get_attribute(key)[source]

Return the value of an attribute.

Warning

While the node is unstored, this will return a reference of the attribute on the database model, meaning that changes on the returned value (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the node is stored, the returned attribute will be a deep copy and mutations of the database attributes will have to go through the appropriate set methods.

Parameters

key – name of the attribute

Returns

the value of the attribute

Raises

AttributeError – if the attribute does not exist and no default is specified

abstract get_attribute_many(keys)[source]

Return the values of multiple attributes.

Warning

While the node is unstored, this will return references of the attributes on the database model, meaning that changes on the returned values (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the node is stored, the returned attributes will be a deep copy and mutations of the database attributes will have to go through the appropriate set methods. Therefore, once stored, retrieving a deep copy can be a heavy operation. If you only need the keys or some values, use the iterators attributes_keys and attributes_items, or the getters get_attribute and get_attribute_many instead.

Parameters

keys – a list of attribute names

Returns

a list of attribute values

Raises

AttributeError – if at least one attribute does not exist

abstract get_extra(key)[source]

Return the value of an extra.

Warning

While the node is unstored, this will return a reference of the extra on the database model, meaning that changes on the returned value (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the node is stored, the returned extra will be a deep copy and mutations of the database extras will have to go through the appropriate set methods.

Parameters

key – name of the extra

Returns

the value of the extra

Raises

AttributeError – if the extra does not exist and no default is specified

abstract get_extra_many(keys)[source]

Return the values of multiple extras.

Warning

While the node is unstored, this will return references of the extras on the database model, meaning that changes on the returned values (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the node is stored, the returned extras will be a deep copy and mutations of the database extras will have to go through the appropriate set methods. Therefore, once stored, retrieving a deep copy can be a heavy operation. If you only need the keys or some values, use the iterators extras_keys and extras_items, or the getters get_extra and get_extra_many instead.

Parameters

keys – a list of extra names

Returns

a list of extra values

Raises

AttributeError – if at least one extra does not exist

property label

Return the node label.

Returns

the label

property mtime

Return the node mtime.

Returns

the mtime

property node_type

Return the node type.

Returns

the node type

property process_type

Return the node process type.

Returns

the process type

abstract reset_attributes(attributes)[source]

Reset the attributes.

Note

This will completely clear any existing attributes and replace them with the new dictionary.

Parameters

attributes – a dictionary with the attributes to set

abstract reset_extras(extras)[source]

Reset the extras.

Note

This will completely clear any existing extras and replace them with the new dictionary.

Parameters

extras – a dictionary with the extras to set

abstract set_attribute(key, value)[source]

Set an attribute to the given value.

Parameters
  • key – name of the attribute

  • value – value of the attribute

abstract set_attribute_many(attributes)[source]

Set multiple attributes.

Note

This will override any existing attributes that are present in the new dictionary.

Parameters

attributes – a dictionary with the attributes to set

abstract set_extra(key, value)[source]

Set an extra to the given value.

Parameters
  • key – name of the extra

  • value – value of the extra

abstract set_extra_many(extras)[source]

Set multiple extras.

Note

This will override any existing extras that are present in the new dictionary.

Parameters

extras – a dictionary with the extras to set

abstract store(links=None, with_transaction=True, clean=True)[source]

Store the node in the database.

Parameters
  • links – optional links to add before storing

  • with_transaction – if False, do not use a transaction because the caller will already have opened one.

  • clean – boolean, if True, will clean the attributes and extras before attempting to store

abstract property user

Return the user of this node.

Returns

the user

Return type

BackendUser

property uuid

Return the node UUID.

Returns

the string representation of the UUID

Return type

str or None

class aiida.orm.implementation.nodes.BackendNodeCollection(backend)[source]

Bases: aiida.orm.implementation.backends.BackendCollection

The collection of BackendNode entries.

ENTITY_CLASS

alias of BackendNode

__abstractmethods__ = frozenset({'delete', 'get'})
__module__ = 'aiida.orm.implementation.nodes'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.nodes.BackendNode],)
__parameters__ = ()
_abc_impl = <_abc_data object>
abstract delete(pk)[source]

Remove a Node entry from the collection with the given id

Parameters

pk – id of the node to delete

abstract get(pk)[source]

Return a Node entry from the collection with the given id

Parameters

pk – id of the node

Backend query implementation classes

class aiida.orm.implementation.querybuilder.BackendQueryBuilder(backend)[source]

Bases: object

Backend query builder interface

property AiidaNode

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

abstract AuthInfo()[source]

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

abstract Comment()[source]

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

abstract Computer()[source]

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

abstract Group()[source]

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

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

abstract Log()[source]

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

abstract 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.

abstract User()[source]

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

__abstractmethods__ = frozenset({'AuthInfo', 'Comment', 'Computer', 'Group', 'Link', 'Log', 'Node', 'User', 'count', 'first', 'get_aiida_res', 'get_column_names', 'get_filter_expr_from_attributes', 'get_projectable_attribute', 'get_session', 'iterall', 'iterdict', 'modify_expansions', 'table_groups_nodes', 'yield_per'})
__dict__ = mappingproxy({'__module__': 'aiida.orm.implementation.querybuilder', '__doc__': 'Backend query builder interface', 'outer_to_inner_schema': None, 'inner_to_outer_schema': None, '__init__': <function BackendQueryBuilder.__init__>, 'Node': <function BackendQueryBuilder.Node>, 'Link': <function BackendQueryBuilder.Link>, 'Computer': <function BackendQueryBuilder.Computer>, 'User': <function BackendQueryBuilder.User>, 'Group': <function BackendQueryBuilder.Group>, 'AuthInfo': <function BackendQueryBuilder.AuthInfo>, 'Comment': <function BackendQueryBuilder.Comment>, 'Log': <function BackendQueryBuilder.Log>, 'table_groups_nodes': <function BackendQueryBuilder.table_groups_nodes>, 'AiidaNode': <property object>, 'get_session': <function BackendQueryBuilder.get_session>, 'modify_expansions': <function BackendQueryBuilder.modify_expansions>, 'get_filter_expr_from_attributes': <aiida.common.lang.abstractclassmethod object>, 'get_corresponding_properties': <classmethod object>, 'get_corresponding_property': <classmethod object>, 'get_filter_expr_from_column': <classmethod object>, 'get_projectable_attribute': <function BackendQueryBuilder.get_projectable_attribute>, 'get_aiida_res': <function BackendQueryBuilder.get_aiida_res>, 'yield_per': <function BackendQueryBuilder.yield_per>, 'count': <function BackendQueryBuilder.count>, 'first': <function BackendQueryBuilder.first>, 'iterall': <function BackendQueryBuilder.iterall>, 'iterdict': <function BackendQueryBuilder.iterdict>, 'get_column_names': <function BackendQueryBuilder.get_column_names>, 'get_column': <function BackendQueryBuilder.get_column>, '__dict__': <attribute '__dict__' of 'BackendQueryBuilder' objects>, '__weakref__': <attribute '__weakref__' of 'BackendQueryBuilder' objects>, '__abstractmethods__': frozenset({'modify_expansions', 'count', 'Comment', 'first', 'get_session', 'iterdict', 'iterall', 'AuthInfo', 'Link', 'Node', 'User', 'get_aiida_res', 'table_groups_nodes', 'Group', 'Log', 'yield_per', 'get_filter_expr_from_attributes', 'get_projectable_attribute', 'get_column_names', 'Computer'}), '_abc_impl': <_abc_data object>})
__init__(backend)[source]
Parameters

backend – the backend

__module__ = 'aiida.orm.implementation.querybuilder'
__weakref__

list of weak references to the object (if defined)

_abc_impl = <_abc_data object>
abstract count(query)[source]
Returns

the number of results

abstract first(query)[source]

Executes query in the backend asking for one instance.

Returns

One row of aiida results

abstract 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_column(colname, alias)[source]

Return the column for a given projection.

abstract get_column_names(alias)[source]

Return the column names of the given table (alias).

classmethod get_corresponding_properties(entity_table, given_properties, mapper)[source]

This method returns a list of updated properties for a given list of properties. If there is no update for the property, the given property is returned in the list.

classmethod get_corresponding_property(entity_table, given_property, mapper)[source]

This method returns an updated property for a given a property. If there is no update for the property, the given property is returned.

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

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

classmethod get_filter_expr_from_column(operator, value, column)[source]

A method 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’])

  • column – an instance of sqlalchemy.orm.attributes.InstrumentedAttribute or

Returns

An instance of sqlalchemy.sql.elements.BinaryExpression

abstract get_projectable_attribute(alias, column_name, attrpath, cast=None, **kwargs)[source]
abstract get_session()[source]
Returns

a valid session, an instance of sqlalchemy.orm.session.Session

inner_to_outer_schema = None
abstract iterall(query, batch_size, tag_to_index_dict)[source]
Returns

An iterator over all the results of a list of lists.

abstract iterdict(query, batch_size, tag_to_projected_properties_dict, tag_to_alias_map)[source]
Returns

An iterator over all the results of a list of dictionaries.

abstract modify_expansions(alias, expansions)[source]

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

outer_to_inner_schema = None
abstract table_groups_nodes()[source]

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

abstract yield_per(query, batch_size)[source]
Parameters

batch_size (int) – Number of rows to yield per step

Yields count rows at a time

Returns

a generator

Backend user

class aiida.orm.implementation.users.BackendUser(backend)[source]

Bases: aiida.orm.implementation.backends.BackendEntity

This is the base class for User information in AiiDA. An implementing backend needs to provide a concrete version.

REQUIRED_FIELDS = ['first_name', 'last_name', 'institution']
__abstractmethods__ = frozenset({'email', 'first_name', 'id', 'institution', 'is_stored', 'last_name', 'store'})
__module__ = 'aiida.orm.implementation.users'
_abc_impl = <_abc_data object>
abstract property email

Get the email address of the user

Returns

the email address

abstract property first_name

Get the user’s first name

Returns

the first name

Return type

str

abstract property institution

Get the user’s institution

Returns

the institution

Return type

str

abstract property last_name

Get the user’s last name

Returns

the last name

Return type

str

property uuid

For now users do not have UUIDs so always return false

Returns

None

class aiida.orm.implementation.users.BackendUserCollection(backend)[source]

Bases: aiida.orm.implementation.backends.BackendCollection

ENTITY_CLASS

alias of BackendUser

__module__ = 'aiida.orm.implementation.users'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.users.BackendUser],)
__parameters__ = ()

Utility functions for AiiDA ORM implementations.

aiida.orm.implementation.utils.get_attr(attrs, key)[source]

Get the attribute that corresponds to the given key