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({'get_auth_params', 'computer', 'get_metadata', 'is_stored', 'id', 'user', 'set_auth_params', 'store', 'enabled', 'set_metadata'})
__module__ = 'aiida.orm.implementation.authinfos'
_abc_impl = <_abc_data object>
computer

Return the computer associated with this instance.

Returns:aiida.orm.implementation.computers.BackendComputer
enabled

Return whether this instance is enabled.

Returns:boolean, True if enabled, False otherwise
get_auth_params()[source]

Return the dictionary of authentication parameters

Returns:a dictionary with authentication parameters
get_metadata()[source]

Return the dictionary of metadata

Returns:a dictionary with metadata
set_auth_params(auth_params)[source]

Set the dictionary of authentication parameters

Parameters:auth_params – a dictionary with authentication parameters
set_metadata(metadata)[source]

Set the dictionary of metadata

Parameters:metadata – a dictionary with metadata
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({'get', 'delete'})
__module__ = 'aiida.orm.implementation.authinfos'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.authinfos.BackendAuthInfo],)
__parameters__ = ()
_abc_impl = <_abc_data object>
delete(pk)[source]

Delete an entry from the collection.

Parameters:pk – the pk of the entry to delete
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({'comments', 'query_manager', 'transaction', 'migrate', 'groups', 'authinfos', 'computers', 'users', 'query', 'nodes', 'logs'})
__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', 'query_manager', 'transaction', 'migrate', 'groups', 'authinfos', 'computers', 'users', 'query', 'nodes', 'logs'}), '_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>
authinfos

Return the collection of authorisation information objects

Returns:the authinfo collection
Return type:aiida.orm.implementation.BackendAuthInfoCollection
comments

Return the collection of comments

Returns:the comment collection
Return type:aiida.orm.implementation.BackendCommentCollection
computers

Return the collection of computers

Returns:the computers collection
Return type:aiida.orm.implementation.BackendComputerCollection
groups

Return the collection of groups

Returns:the groups collection
Return type:aiida.orm.implementation.BackendGroupCollection
logs

Return the collection of logs

Returns:the log collection
Return type:aiida.orm.implementation.BackendLogCollection
migrate()[source]

Migrate the database to the latest schema version.

nodes

Return the collection of nodes

Returns:the nodes collection
Return type:aiida.orm.implementation.BackendNodeCollection
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
query_manager

Return the query manager for the objects stored in the backend

Returns:The query manger
Return type:aiida.backends.general.abstractqueries.AbstractQueryManager
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
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({'store', 'is_stored', 'id'})
__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>
backend

Return the backend this entity belongs to

Returns:the backend instance
dbmodel
id

Return the id for this entity.

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

Returns:the entity id
is_stored

Return whether the entity is stored.

Returns:True if stored, False otherwise
Return type:bool
pk

Return the id for this entity.

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

Returns:the entity id
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)

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({'set_content', 'content', 'set_mtime', 'mtime', 'is_stored', 'id', 'user', 'set_user', 'ctime', 'node', 'store'})
__module__ = 'aiida.orm.implementation.comments'
_abc_impl = <_abc_data object>
content
ctime
mtime
node
set_content(value)[source]
set_mtime(value)[source]
set_user(value)[source]
user
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({'delete', 'delete_all', 'create', '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>
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

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
delete_all()[source]

Delete all Comment entries.

Raises:IntegrityError – if all Comments could not be deleted
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({'hostname', 'get_transport_type', 'set_transport_type', 'get_metadata', 'description', 'name', 'is_stored', 'get_name', 'get_description', 'set_description', 'id', 'get_scheduler_type', 'set_scheduler_type', 'set_name', 'store', 'set_hostname', 'set_metadata'})
__module__ = 'aiida.orm.implementation.computers'
_abc_impl = <_abc_data object>
_logger = <Logger aiida.orm.implementation.computers (REPORT)>
description
get_description()[source]
get_hostname()[source]

Get this computer hostname :rtype: str

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

Is the computer stored?

Returns:True if stored, False otherwise
Return type:bool
name
set_description(val)[source]
set_hostname(val)[source]

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

set_metadata(metadata)[source]

Set the metadata.

set_name(val)[source]
set_scheduler_type(scheduler_type)[source]
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>
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({'type_string', 'clear', 'count', 'description', 'is_stored', 'id', 'label', 'user', 'uuid', '__int__', 'store', 'nodes'})
__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
clear()[source]

Remove all the nodes from this group.

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
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
id
Returns:the principal key (the ID) as an integer, or None if the node was not stored yet
is_stored

Return whether the group is stored.

Returns:boolean, True if the group is stored, False otherwise
label
Returns:the name of the group as a string
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
store()[source]

Store this entity in the backend.

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

type_string
Returns:the string defining the type of the group
user
Returns:a backend user object, representing the user associated to this group.
Return type:aiida.orm.implementation.BackendUser
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>
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
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({'message', 'dbnode_id', 'levelname', 'loggername', 'metadata', 'is_stored', 'id', 'time', 'uuid', 'store'})
__module__ = 'aiida.orm.implementation.logs'
_abc_impl = <_abc_data object>
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
levelname

The name of the log level

Returns:The entry log level name
Return type:basestring
loggername

The name of the logger that created this entry

Returns:The entry loggername
Return type:basestring
message

Get the message corresponding to the entry

Returns:The entry message
Return type:basestring
metadata

Get the metadata corresponding to the entry

Returns:The entry metadata
Return type:dict
time

Get the time corresponding to the entry

Returns:The entry timestamp
Return type:datetime.datetime
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_all', 'delete', '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>
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
delete_all()[source]

Delete all Log entries.

Raises:IntegrityError – if all Logs could not be deleted
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({'get_attribute', 'set_attribute', 'delete_extra', 'attributes_items', 'get_extra', 'reset_attributes', 'extras', 'attributes', 'clear_attributes', 'add_incoming', 'delete_extra_many', 'set_attribute_many', 'delete_attribute_many', 'id', 'extras_items', 'user', 'set_extra', 'attributes_keys', 'extras_keys', 'get_attribute_many', 'get_extra_many', 'reset_extras', 'clone', 'delete_attribute', 'computer', 'set_extra_many', 'is_stored', 'clear_extras', 'store'})
__module__ = 'aiida.orm.implementation.nodes'
_abc_impl = <_abc_data object>
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
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
attributes_items()[source]

Return an iterator over the attributes.

Returns:an iterator with attribute key value pairs
attributes_keys()[source]

Return an iterator over the attribute keys.

Returns:an iterator with attribute keys
clear_attributes()[source]

Delete all attributes.

clear_extras()[source]

Delete all extras.

clone()[source]

Return an unstored clone of ourselves.

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

Return the computer of this node.

Returns:the computer or None
Return type:BackendComputer or None
ctime

Return the node ctime.

Returns:the ctime
delete_attribute(key)[source]

Delete an attribute.

Parameters:key – name of the attribute
Raises:AttributeError – if the attribute does not exist
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
delete_extra(key)[source]

Delete an extra.

Parameters:key – name of the extra
Raises:AttributeError – if the extra does not exist
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
description

Return the node description.

Returns:the description
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
extras_items()[source]

Return an iterator over the extras.

Returns:an iterator with extra key value pairs
extras_keys()[source]

Return an iterator over the extra keys.

Returns:an iterator with extra keys
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
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
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
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
label

Return the node label.

Returns:the label
mtime

Return the node mtime.

Returns:the mtime
node_type

Return the node type.

Returns:the node type
process_type

Return the node process type.

Returns:the process type
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
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
set_attribute(key, value)[source]

Set an attribute to the given value.

Parameters:
  • key – name of the attribute
  • value – value of the attribute
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
set_extra(key, value)[source]

Set an extra to the given value.

Parameters:
  • key – name of the extra
  • value – value of the extra
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
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
user

Return the user of this node.

Returns:the user
Return type:BackendUser
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({'get', 'delete'})
__module__ = 'aiida.orm.implementation.nodes'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.nodes.BackendNode],)
__parameters__ = ()
_abc_impl = <_abc_data object>
delete(pk)[source]

Remove a Node entry from the collection with the given id

Parameters:pk – id of the node to delete
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

AiidaNode

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

AuthInfo()[source]

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

Comment()[source]

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

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

Log()[source]

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

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({'Log', 'get_projectable_attribute', 'Computer', 'get_session', 'modify_expansions', 'get_filter_expr_from_attributes', 'count', 'Comment', 'Node', 'first', 'iterdict', 'table_groups_nodes', 'Link', 'AuthInfo', 'Group', 'yield_per', 'User', 'get_aiida_res', 'get_column_names', 'iterall'})
__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({'Log', 'get_projectable_attribute', 'Computer', 'get_session', 'modify_expansions', 'get_filter_expr_from_attributes', 'count', 'Comment', 'Node', 'first', 'iterdict', 'table_groups_nodes', 'Link', 'AuthInfo', 'Group', 'yield_per', 'User', 'get_aiida_res', 'get_column_names', 'iterall'}), '_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>
count(query)[source]
Returns:the number of results
first(query)[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_column(colname, alias)[source]

Return the column for a given projection.

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.

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

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
inner_to_outer_schema = None
iterall(query, batch_size, tag_to_index_dict)[source]
Returns:An iterator over all the results of a list of lists.
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.
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
table_groups_nodes()[source]

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

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({'last_name', 'is_stored', 'institution', 'email', 'id', 'first_name', 'store'})
__module__ = 'aiida.orm.implementation.users'
_abc_impl = <_abc_data object>
email

Get the email address of the user

Returns:the email address
first_name

Get the user’s first name

Returns:the first name
Return type:str
institution

Get the user’s institution

Returns:the institution
Return type:str
last_name

Get the user’s last name

Returns:the last name
Return type:str
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({'get_auth_params', 'computer', 'get_metadata', 'is_stored', 'id', 'user', 'set_auth_params', 'store', 'enabled', 'set_metadata'})
__module__ = 'aiida.orm.implementation.authinfos'
_abc_impl = <_abc_data object>
computer

Return the computer associated with this instance.

Returns:aiida.orm.implementation.computers.BackendComputer
enabled

Return whether this instance is enabled.

Returns:boolean, True if enabled, False otherwise
get_auth_params()[source]

Return the dictionary of authentication parameters

Returns:a dictionary with authentication parameters
get_metadata()[source]

Return the dictionary of metadata

Returns:a dictionary with metadata
set_auth_params(auth_params)[source]

Set the dictionary of authentication parameters

Parameters:auth_params – a dictionary with authentication parameters
set_metadata(metadata)[source]

Set the dictionary of metadata

Parameters:metadata – a dictionary with metadata
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({'get', 'delete'})
__module__ = 'aiida.orm.implementation.authinfos'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.authinfos.BackendAuthInfo],)
__parameters__ = ()
_abc_impl = <_abc_data object>
delete(pk)[source]

Delete an entry from the collection.

Parameters:pk – the pk of the entry to delete
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({'comments', 'query_manager', 'transaction', 'migrate', 'groups', 'authinfos', 'computers', 'users', 'query', 'nodes', 'logs'})
__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', 'query_manager', 'transaction', 'migrate', 'groups', 'authinfos', 'computers', 'users', 'query', 'nodes', 'logs'}), '_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>
authinfos

Return the collection of authorisation information objects

Returns:the authinfo collection
Return type:aiida.orm.implementation.BackendAuthInfoCollection
comments

Return the collection of comments

Returns:the comment collection
Return type:aiida.orm.implementation.BackendCommentCollection
computers

Return the collection of computers

Returns:the computers collection
Return type:aiida.orm.implementation.BackendComputerCollection
groups

Return the collection of groups

Returns:the groups collection
Return type:aiida.orm.implementation.BackendGroupCollection
logs

Return the collection of logs

Returns:the log collection
Return type:aiida.orm.implementation.BackendLogCollection
migrate()[source]

Migrate the database to the latest schema version.

nodes

Return the collection of nodes

Returns:the nodes collection
Return type:aiida.orm.implementation.BackendNodeCollection
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
query_manager

Return the query manager for the objects stored in the backend

Returns:The query manger
Return type:aiida.backends.general.abstractqueries.AbstractQueryManager
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
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({'store', 'is_stored', 'id'})
__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>
backend

Return the backend this entity belongs to

Returns:the backend instance
dbmodel
id

Return the id for this entity.

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

Returns:the entity id
is_stored

Return whether the entity is stored.

Returns:True if stored, False otherwise
Return type:bool
pk

Return the id for this entity.

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

Returns:the entity id
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)

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({'set_content', 'content', 'set_mtime', 'mtime', 'is_stored', 'id', 'user', 'set_user', 'ctime', 'node', 'store'})
__module__ = 'aiida.orm.implementation.comments'
_abc_impl = <_abc_data object>
content
ctime
mtime
node
set_content(value)[source]
set_mtime(value)[source]
set_user(value)[source]
user
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({'delete', 'delete_all', 'create', '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>
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

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
delete_all()[source]

Delete all Comment entries.

Raises:IntegrityError – if all Comments could not be deleted
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({'hostname', 'get_transport_type', 'set_transport_type', 'get_metadata', 'description', 'name', 'is_stored', 'get_name', 'get_description', 'set_description', 'id', 'get_scheduler_type', 'set_scheduler_type', 'set_name', 'store', 'set_hostname', 'set_metadata'})
__module__ = 'aiida.orm.implementation.computers'
_abc_impl = <_abc_data object>
_logger = <Logger aiida.orm.implementation.computers (REPORT)>
description
get_description()[source]
get_hostname()[source]

Get this computer hostname :rtype: str

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

Is the computer stored?

Returns:True if stored, False otherwise
Return type:bool
name
set_description(val)[source]
set_hostname(val)[source]

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

set_metadata(metadata)[source]

Set the metadata.

set_name(val)[source]
set_scheduler_type(scheduler_type)[source]
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>
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({'type_string', 'clear', 'count', 'description', 'is_stored', 'id', 'label', 'user', 'uuid', '__int__', 'store', 'nodes'})
__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
clear()[source]

Remove all the nodes from this group.

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
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
id
Returns:the principal key (the ID) as an integer, or None if the node was not stored yet
is_stored

Return whether the group is stored.

Returns:boolean, True if the group is stored, False otherwise
label
Returns:the name of the group as a string
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
store()[source]

Store this entity in the backend.

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

type_string
Returns:the string defining the type of the group
user
Returns:a backend user object, representing the user associated to this group.
Return type:aiida.orm.implementation.BackendUser
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>
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
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({'message', 'dbnode_id', 'levelname', 'loggername', 'metadata', 'is_stored', 'id', 'time', 'uuid', 'store'})
__module__ = 'aiida.orm.implementation.logs'
_abc_impl = <_abc_data object>
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
levelname

The name of the log level

Returns:The entry log level name
Return type:basestring
loggername

The name of the logger that created this entry

Returns:The entry loggername
Return type:basestring
message

Get the message corresponding to the entry

Returns:The entry message
Return type:basestring
metadata

Get the metadata corresponding to the entry

Returns:The entry metadata
Return type:dict
time

Get the time corresponding to the entry

Returns:The entry timestamp
Return type:datetime.datetime
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_all', 'delete', '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>
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
delete_all()[source]

Delete all Log entries.

Raises:IntegrityError – if all Logs could not be deleted
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({'get_attribute', 'set_attribute', 'delete_extra', 'attributes_items', 'get_extra', 'reset_attributes', 'extras', 'attributes', 'clear_attributes', 'add_incoming', 'delete_extra_many', 'set_attribute_many', 'delete_attribute_many', 'id', 'extras_items', 'user', 'set_extra', 'attributes_keys', 'extras_keys', 'get_attribute_many', 'get_extra_many', 'reset_extras', 'clone', 'delete_attribute', 'computer', 'set_extra_many', 'is_stored', 'clear_extras', 'store'})
__module__ = 'aiida.orm.implementation.nodes'
_abc_impl = <_abc_data object>
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
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
attributes_items()[source]

Return an iterator over the attributes.

Returns:an iterator with attribute key value pairs
attributes_keys()[source]

Return an iterator over the attribute keys.

Returns:an iterator with attribute keys
clear_attributes()[source]

Delete all attributes.

clear_extras()[source]

Delete all extras.

clone()[source]

Return an unstored clone of ourselves.

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

Return the computer of this node.

Returns:the computer or None
Return type:BackendComputer or None
ctime

Return the node ctime.

Returns:the ctime
delete_attribute(key)[source]

Delete an attribute.

Parameters:key – name of the attribute
Raises:AttributeError – if the attribute does not exist
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
delete_extra(key)[source]

Delete an extra.

Parameters:key – name of the extra
Raises:AttributeError – if the extra does not exist
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
description

Return the node description.

Returns:the description
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
extras_items()[source]

Return an iterator over the extras.

Returns:an iterator with extra key value pairs
extras_keys()[source]

Return an iterator over the extra keys.

Returns:an iterator with extra keys
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
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
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
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
label

Return the node label.

Returns:the label
mtime

Return the node mtime.

Returns:the mtime
node_type

Return the node type.

Returns:the node type
process_type

Return the node process type.

Returns:the process type
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
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
set_attribute(key, value)[source]

Set an attribute to the given value.

Parameters:
  • key – name of the attribute
  • value – value of the attribute
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
set_extra(key, value)[source]

Set an extra to the given value.

Parameters:
  • key – name of the extra
  • value – value of the extra
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
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
user

Return the user of this node.

Returns:the user
Return type:BackendUser
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({'get', 'delete'})
__module__ = 'aiida.orm.implementation.nodes'
__orig_bases__ = (aiida.orm.implementation.backends.BackendCollection[aiida.orm.implementation.nodes.BackendNode],)
__parameters__ = ()
_abc_impl = <_abc_data object>
delete(pk)[source]

Remove a Node entry from the collection with the given id

Parameters:pk – id of the node to delete
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

AiidaNode

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

AuthInfo()[source]

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

Comment()[source]

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

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

Log()[source]

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

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({'Log', 'get_projectable_attribute', 'Computer', 'get_session', 'modify_expansions', 'get_filter_expr_from_attributes', 'count', 'Comment', 'Node', 'first', 'iterdict', 'table_groups_nodes', 'Link', 'AuthInfo', 'Group', 'yield_per', 'User', 'get_aiida_res', 'get_column_names', 'iterall'})
__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({'Log', 'get_projectable_attribute', 'Computer', 'get_session', 'modify_expansions', 'get_filter_expr_from_attributes', 'count', 'Comment', 'Node', 'first', 'iterdict', 'table_groups_nodes', 'Link', 'AuthInfo', 'Group', 'yield_per', 'User', 'get_aiida_res', 'get_column_names', 'iterall'}), '_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>
count(query)[source]
Returns:the number of results
first(query)[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_column(colname, alias)[source]

Return the column for a given projection.

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.

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

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
inner_to_outer_schema = None
iterall(query, batch_size, tag_to_index_dict)[source]
Returns:An iterator over all the results of a list of lists.
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.
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
table_groups_nodes()[source]

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

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({'last_name', 'is_stored', 'institution', 'email', 'id', 'first_name', 'store'})
__module__ = 'aiida.orm.implementation.users'
_abc_impl = <_abc_data object>
email

Get the email address of the user

Returns:the email address
first_name

Get the user’s first name

Returns:the first name
Return type:str
institution

Get the user’s institution

Returns:the institution
Return type:str
last_name

Get the user’s last name

Returns:the last name
Return type:str
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