aiida.orm.implementation.sqlalchemy package

Submodules

SqlAlchemy implementations for the AuthInfo entity and collection.

class aiida.orm.implementation.sqlalchemy.authinfos.SqlaAuthInfo(backend, computer, user)[source]

Bases: aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, aiida.orm.implementation.authinfos.BackendAuthInfo

AuthInfo implementation for SQLAlchemy.

MODEL_CLASS

alias of aiida.backends.sqlalchemy.models.authinfo.DbAuthInfo

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__init__(backend, computer, user)[source]

Construct an SqlaAuthInfo

Parameters:
  • computer – a Computer instance
  • user – a User instance
Returns:

an AuthInfo object associated with the given computer and user

__module__ = 'aiida.orm.implementation.sqlalchemy.authinfos'
__next_in_mro__

alias of aiida.orm.implementation.authinfos.BackendAuthInfo

__orig_bases__ = (aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity[aiida.backends.sqlalchemy.models.authinfo.DbAuthInfo], <class 'aiida.orm.implementation.authinfos.BackendAuthInfo'>)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926333796219
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of SqlaAuthInfo

computer
dbauthinfo
enabled
get_auth_params()[source]

Get the auth_params dictionary from the DB

Returns:a dictionary
get_metadata()[source]

Get the metadata dictionary from the DB

Returns:a dictionary
id
is_stored

Return whether the AuthInfo is stored

Returns:True if stored, False otherwise
set_auth_params(auth_params)[source]

Replace the auth_params dictionary in the DB with the provided dictionary

set_metadata(metadata)[source]

Replace the metadata dictionary in the DB with the provided dictionary

user
class aiida.orm.implementation.sqlalchemy.authinfos.SqlaAuthInfoCollection(backend)[source]

Bases: aiida.orm.implementation.authinfos.BackendAuthInfoCollection

Collection of AuthInfo instances.

ENTITY_CLASS

alias of SqlaAuthInfo

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__module__ = 'aiida.orm.implementation.sqlalchemy.authinfos'
__next_in_mro__

alias of __builtin__.object

__orig_bases__ = (aiida.orm.implementation.authinfos.BackendAuthInfoCollection,)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926334020639
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of SqlaAuthInfoCollection

delete(authinfo_id)[source]

Remove an AuthInfo from the collection with the given id :param authinfo_id: The ID of the authinfo to delete

get(computer, user)[source]

Return a SqlaAuthInfo given a computer and a user

Parameters:
  • computer – a Computer instance
  • user – a User instance
Returns:

an AuthInfo object associated with the given computer and user

Raises:
  • aiida.common.NotExistent – if the user is not configured to use computer
  • sqlalchemy.orm.exc.MultipleResultsFound – if the user is configured more than once to use the computer! Should never happen

SqlAlchemy implementation of aiida.orm.implementation.backends.Backend.

class aiida.orm.implementation.sqlalchemy.backend.SqlaBackend[source]

Bases: aiida.orm.implementation.sql.backends.SqlBackend

SqlAlchemy implementation of aiida.orm.implementation.backends.Backend.

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__init__()[source]

Construct the backend instance by initializing all the collections.

__module__ = 'aiida.orm.implementation.sqlalchemy.backend'
__next_in_mro__

alias of aiida.orm.implementation.backends.Backend

__orig_bases__ = (aiida.orm.implementation.sql.backends.SqlBackend[sqlalchemy.ext.declarative.api.Model],)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926333483846
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of SqlaBackend

authinfos
comments
computers
cursor(**kwds)[source]

Return a psycopg cursor to be used in a context manager.

Returns:a psycopg cursor
Return type:psycopg2.extensions.cursor
static execute_raw(query)[source]

Execute a raw SQL statement and return the result.

Parameters:query – a string containing a raw SQL statement
Returns:the result of the query
get_backend_entity(model)[source]

Return a BackendEntity instance from a DbModel instance.

static get_connection()[source]

Get the SQLA database connection

Returns:the SQLA database connection
groups
logs
static migrate()[source]
nodes
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
static transaction(*args, **kwds)[source]

Open a transaction to be used as a context manager.

users

Sqla implementations for the Comment entity and collection.

class aiida.orm.implementation.sqlalchemy.comments.SqlaComment(backend, node, user, content=None, ctime=None, mtime=None)[source]

Bases: aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, aiida.orm.implementation.comments.BackendComment

Comment implementation for Sqla.

MODEL_CLASS

alias of aiida.backends.sqlalchemy.models.comment.DbComment

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__init__(backend, node, user, content=None, ctime=None, mtime=None)[source]

Construct a SqlaComment.

Parameters:
  • node – a Node instance
  • user – a User instance
  • content – the comment content
  • ctime – The creation time as datetime object
  • mtime – The modification time as datetime object
Returns:

a Comment object associated to the given node and user

__module__ = 'aiida.orm.implementation.sqlalchemy.comments'
__next_in_mro__

alias of aiida.orm.implementation.comments.BackendComment

__orig_bases__ = (aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity[aiida.backends.sqlalchemy.models.comment.DbComment], <class 'aiida.orm.implementation.comments.BackendComment'>)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926333901643
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of SqlaComment

content
ctime
mtime
node
set_content(value)[source]
set_mtime(value)[source]
set_user(value)[source]
store()[source]

Can only store if both the node and user are stored as well.

user
class aiida.orm.implementation.sqlalchemy.comments.SqlaCommentCollection(backend)[source]

Bases: aiida.orm.implementation.comments.BackendCommentCollection

SqlAlchemy implementation for the CommentCollection.

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__module__ = 'aiida.orm.implementation.sqlalchemy.comments'
__next_in_mro__

alias of __builtin__.object

__orig_bases__ = (aiida.orm.implementation.comments.BackendCommentCollection,)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926334003104
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of SqlaCommentCollection

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

Remove a Comment from the collection with the given id

Parameters:comment – the id of the comment to delete
from_dbmodel(dbmodel)[source]

Create an entity from the backend dbmodel

Parameters:dbmodel – the dbmodel to create the entity from
Returns:the entity instance

SqlAlchemy implementations for the Computer entity and collection.

class aiida.orm.implementation.sqlalchemy.computers.SqlaComputer(backend, **kwargs)[source]

Bases: aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, aiida.orm.implementation.computers.BackendComputer

SqlAlchemy implementation for BackendComputer.

MODEL_CLASS

alias of aiida.backends.sqlalchemy.models.computer.DbComputer

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__init__(backend, **kwargs)[source]

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

__module__ = 'aiida.orm.implementation.sqlalchemy.computers'
__next_in_mro__

alias of aiida.orm.implementation.computers.BackendComputer

__orig_bases__ = (aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity[aiida.backends.sqlalchemy.models.computer.DbComputer], <class 'aiida.orm.implementation.computers.BackendComputer'>)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926334025759
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of SqlaComputer

copy()[source]

Create an unstored clone of an already stored Computer.

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

Return transport params stored in dbcomputer instance

get_transport_type()[source]
hostname
id
is_enabled()[source]
is_stored
name
pk
set_description(val)[source]
set_enabled_state(enabled)[source]
set_hostname(val)[source]

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

set_metadata(metadata_dict)[source]

Set the metadata.

set_name(val)[source]
set_scheduler_type(scheduler_type)[source]
set_transport_params(val)[source]
set_transport_type(transport_type)[source]
store()[source]

Store the Computer instance.

uuid
class aiida.orm.implementation.sqlalchemy.computers.SqlaComputerCollection(backend)[source]

Bases: aiida.orm.implementation.computers.BackendComputerCollection

Collection of Computer instances.

ENTITY_CLASS

alias of SqlaComputer

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__module__ = 'aiida.orm.implementation.sqlalchemy.computers'
__next_in_mro__

alias of __builtin__.object

__orig_bases__ = (aiida.orm.implementation.computers.BackendComputerCollection,)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926334015932
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of SqlaComputerCollection

delete(pk)[source]

Delete an entry with the given pk

Parameters:pk – the pk of the entry to delete
static list_names()[source]

Module to get the backend instance from the Models instance

aiida.orm.implementation.sqlalchemy.convert.get_backend_entity(*args, **kw)[source]

Default get_backend_entity

Classes and methods for Django specific backend entities

class aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity(*args, **kwargs)[source]

Bases: typing.Generic

A mixin that adds some common SQLA backend entity methods

MODEL_CLASS = None
__abstractmethods__ = frozenset([])
__args__ = None
__dict__ = dict_proxy({'__module__': 'aiida.orm.implementation.sqlalchemy.entities', 'from_dbmodel': <classmethod object>, u'__origin__': None, 'is_stored': <property object>, '__dict__': <attribute '__dict__' of 'SqlaModelEntity' objects>, 'dbmodel': <property object>, '__weakref__': <attribute '__weakref__' of 'SqlaModelEntity' objects>, 'id': <property object>, '__init__': <function __init__>, '_dbmodel': None, '_abc_generic_negative_cache_version': 102, '__abstractmethods__': frozenset([]), 'pk': <property object>, '__orig_bases__': (typing.Generic[~ModelType],), '_class_check': <classmethod object>, '__doc__': 'A mixin that adds some common SQLA backend entity methods', 'store': <function store>, '_abc_cache': <_weakrefset.WeakSet object>, '__tree_hash__': 5926333590608, '__args__': None, 'get_dbmodel_attribute_name': <classmethod object>, '__next_in_mro__': <type 'object'>, '__parameters__': (~ModelType,), '_gorg': aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, 'MODEL_CLASS': None, u'__extra__': None, '_abc_registry': <_weakrefset.WeakSet object>, '_abc_generic_negative_cache': <_weakrefset.WeakSet object>})
__extra__ = None
__init__(*args, **kwargs)[source]

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

__module__ = 'aiida.orm.implementation.sqlalchemy.entities'
__next_in_mro__

alias of __builtin__.object

__orig_bases__ = (typing.Generic[~ModelType],)
__origin__ = None
__parameters__ = (~ModelType,)
__tree_hash__ = 5926333590608
__weakref__

list of weak references to the object (if defined)

_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
classmethod _class_check()[source]

Assert that the class is correctly configured

_dbmodel = None
_gorg

alias of SqlaModelEntity

dbmodel

Get the underlying database model instance

Returns:the database model instance
classmethod from_dbmodel(dbmodel, backend)[source]

Create a DjangoEntity from the corresponding db model class

Parameters:
  • dbmodel – the model to create the entity from
  • backend – the corresponding backend
Returns:

the Django entity

classmethod get_dbmodel_attribute_name(attr_name)[source]

Given the name of an attribute of the entity class give the corresponding name of the attribute in the db model. It if doesn’t exit this raises a ValueError

Parameters:attr_name
Returns:the dbmodel attribute name
Return type:str
id

Get the id of this entity

Returns:the entity id
is_stored

Is this entity stored?

Returns:True if stored, False otherwise
pk

Get the principal key for this entry

Returns:the principal key
store()[source]

Store this entity

Returns:the entity itself

SQLA groups

class aiida.orm.implementation.sqlalchemy.groups.SqlaGroup(backend, label, user, description='', type_string='')[source]

Bases: aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, aiida.orm.implementation.groups.BackendGroup

The SQLAlchemy Group object

MODEL_CLASS

alias of aiida.backends.sqlalchemy.models.group.DbGroup

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__init__(backend, label, user, description='', type_string='')[source]

Construct a new SQLA group

Parameters:
  • backend – the backend to use
  • label – the group label
  • user – the owner of the group
  • description – an optional group description
  • type_string – an optional type for the group to contain
__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.sqlalchemy.groups'
__next_in_mro__

alias of aiida.orm.implementation.groups.BackendGroup

__orig_bases__ = (aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity[aiida.backends.sqlalchemy.models.group.DbGroup], <class 'aiida.orm.implementation.groups.BackendGroup'>)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926334030336
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of SqlaGroup

add_nodes(nodes, **kwargs)[source]

Add a node or 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 instance to be added to this group
  • kwargs – skip_orm: When the flag is on, the SQLA ORM is skipped and SQLA is used to create a direct SQL INSERT statement to the group-node relationship table (to improve speed).
count()[source]

Return the number of entities in this group.

Returns:integer number of entities contained within the group
description
is_stored
label
nodes

Get an iterator to all the nodes in the group

pk
remove_nodes(nodes)[source]

Remove a node or 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 instance to be added to this group
store()[source]

Store this entity

Returns:the entity itself
type_string
user
uuid
class aiida.orm.implementation.sqlalchemy.groups.SqlaGroupCollection(backend)[source]

Bases: aiida.orm.implementation.groups.BackendGroupCollection

The SLQA collection of groups

ENTITY_CLASS

alias of SqlaGroup

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__module__ = 'aiida.orm.implementation.sqlalchemy.groups'
__next_in_mro__

alias of __builtin__.object

__orig_bases__ = (aiida.orm.implementation.groups.BackendGroupCollection,)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926334032036
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of SqlaGroupCollection

delete(id)[source]

Delete a group with the given id

Parameters:id – the id of the group to delete
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’.

SQLA Log and LogCollection module

class aiida.orm.implementation.sqlalchemy.logs.SqlaLog(backend, time, loggername, levelname, dbnode_id, message='', metadata=None)[source]

Bases: aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, aiida.orm.implementation.logs.BackendLog

SQLA Log backend entity

MODEL_CLASS

alias of aiida.backends.sqlalchemy.models.log.DbLog

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__init__(backend, time, loggername, levelname, dbnode_id, message='', metadata=None)[source]

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

__module__ = 'aiida.orm.implementation.sqlalchemy.logs'
__next_in_mro__

alias of aiida.orm.implementation.logs.BackendLog

__orig_bases__ = (aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity[aiida.backends.sqlalchemy.models.log.DbLog], <class 'aiida.orm.implementation.logs.BackendLog'>)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926334033354
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of SqlaLog

dbnode_id

Get the id of the object that created the log entry

levelname

The name of the log level

loggername

The name of the logger that created this entry

message

Get the message corresponding to the entry

metadata

Get the metadata corresponding to the entry

time

Get the time corresponding to the entry

uuid

Get the UUID of the log entry

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

Bases: aiida.orm.implementation.logs.BackendLogCollection

The SQLA collection for logs

ENTITY_CLASS

alias of SqlaLog

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__module__ = 'aiida.orm.implementation.sqlalchemy.logs'
__next_in_mro__

alias of __builtin__.object

__orig_bases__ = (aiida.orm.implementation.logs.BackendLogCollection,)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926334033414
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of SqlaLogCollection

delete(log_id)[source]

Remove a Log entry from the collection with the given id

Parameters:log_id – id of the log to delete
delete_many(filters)[source]

Delete all log entries in the table

SqlAlchemy implementation of the BackendNode and BackendNodeCollection classes.

class aiida.orm.implementation.sqlalchemy.nodes.SqlaNode(backend, node_type, user, computer=None, process_type=None, label='', description='', ctime=None, mtime=None)[source]

Bases: aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, aiida.orm.implementation.nodes.BackendNode

SQLA Node backend entity

MODEL_CLASS

alias of aiida.backends.sqlalchemy.models.node.DbNode

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__init__(backend, node_type, user, computer=None, process_type=None, label='', description='', ctime=None, mtime=None)[source]

Construct a new BackendNode instance wrapping a new DbNode instance.

Parameters:
  • backend – the backend
  • node_type – the node type string
  • user – associated BackendUser
  • computer – associated BackendComputer
  • label – string label
  • description – string description
  • ctime – The creation time as datetime object
  • mtime – The modification time as datetime object
__module__ = 'aiida.orm.implementation.sqlalchemy.nodes'
__next_in_mro__

alias of aiida.orm.implementation.nodes.BackendNode

__orig_bases__ = (aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity[aiida.backends.sqlalchemy.models.node.DbNode], <class 'aiida.orm.implementation.nodes.BackendNode'>)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926334030234
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>

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
_gorg

alias of SqlaNode

_increment_version_number()[source]

Increment the node version number of this node by one directly in the database.

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:

aiida.common.ModificationNotAllowed – if either source or target node is not stored

attributes_items()[source]

Return an iterator over the attribute items.

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

Delete an attribute.

Parameters:key – name of the attribute
Raises:AttributeError – if the attribute does not exist
delete_attributes(keys)[source]

Delete multiple attributes.

Note

The implementation should guarantee that all the keys that are to be deleted actually exist or the entire operation should be canceled without any change and an AttributeError should be raised.

Parameters:keys – names of the attributes to delete
Raises:AttributeError – if at least on 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_extras(keys)[source]

Delete multiple extras.

Note

The implementation should guarantee that all the keys that are to be deleted actually exist or the entire operation should be canceled without any change and an AttributeError should be raised.

Parameters:keys – names of the extras to delete
Raises:AttributeError – if at least on of the extra does not exist
extras_items()[source]

Return an iterator over the extra items.

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

Return an iterator over the extras keys.

Returns:an iterator with extras keys
get_attribute(key)[source]

Return an attribute.

Parameters:key – name of the attribute
Returns:the value of the attribute
Raises:AttributeError – if the attribute does not exist
get_attributes(keys)[source]

Return a set of attributes.

Parameters:keys – names of the attributes
Returns:the values of the attributes
Raises:AttributeError – if at least one attribute does not exist
get_extra(key)[source]

Return an extra.

Parameters:key – name of the extra
Returns:the value of the extra
Raises:AttributeError – if the extra does not exist
get_extras(keys)[source]

Return a set of extras.

Parameters:keys – names of the extras
Returns:the values of the extras
Raises:AttributeError – if at least one extra does not exist
reset_attributes(attributes)[source]

Reset the attributes.

Note

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

Parameters:attributes – the new attributes to set
reset_extras(extras)[source]

Reset the extras.

Note

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

Parameters:extras – the new 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_attributes(attributes)[source]

Set attributes.

Note

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

Parameters:attributes – the new attributes to set
set_extra(key, value, increase_version=True)[source]

Set an extra to the given value.

Parameters:
  • key – name of the extra
  • value – value of the extra
  • increase_version – boolean, if True will increase the node version upon successfully setting the extra
set_extras(extras)[source]

Set extras.

Note

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

Parameters:extras – the new extras to set
store(attributes=None, links=None, with_transaction=True)[source]

Store the node in the database.

Parameters:
  • attributes – optional attributes to set before storing, will override any existing attributes
  • links – optional links to add before storing
user

Return the user of this node.

Returns:the user
Return type:BackendUser
class aiida.orm.implementation.sqlalchemy.nodes.SqlaNodeCollection(backend)[source]

Bases: aiida.orm.implementation.nodes.BackendNodeCollection

The collection of Node entries.

ENTITY_CLASS

alias of SqlaNode

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__module__ = 'aiida.orm.implementation.sqlalchemy.nodes'
__next_in_mro__

alias of __builtin__.object

__orig_bases__ = (aiida.orm.implementation.nodes.BackendNodeCollection,)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926334023047
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of SqlaNodeCollection

delete(pk)[source]

Remove a Node entry from the collection with the given id

Parameters:pk – id of the node to delete

Sqla query builder implementation

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

Bases: aiida.orm.implementation.querybuilder.BackendQueryBuilder

QueryBuilder to use with SQLAlchemy-backend and schema defined in backends.sqlalchemy.models

AuthInfo
Comment
Computer
Group
Log
Node
User
__abstractmethods__ = frozenset([])
__module__ = 'aiida.orm.implementation.sqlalchemy.querybuilder'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet 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). Choice (sqlalchemy_utils) will return their value

Parameters:
  • key – The key
  • res – the result returned by the query
Returns:

an aiida-compatible instance

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

Applies a filter on the alias given. Expects the alias of the ORM-class on which to filter, and filter_spec. Filter_spec contains the specification on the filter. Expects:

Parameters:
  • operator – The operator to apply, see below for further details
  • value – The value for the right side of the expression, the value you want to compare with.
  • path – The path leading to the value
  • attr_key – Boolean, whether the value is in a json-column, or in an attribute like table.

Implemented and valid operators:

  • for any type: * == (compare single value, eg: ‘==’:5.0) * in (compare whether in list, eg: ‘in’:[5, 6, 34]

  • for floats and integers:
    • >
    • <
    • <=
    • >=
  • for strings:
    • like (case - sensitive), for example ‘like’:’node.calc.%’ will match node.calc.relax and node.calc.RELAX and node.calc. but not node.CALC.relax
    • ilike (case - unsensitive) will also match node.CaLc.relax in the above example

    Note

    The character % is a reserved special character in SQL, and acts as a wildcard. If you specifically want to capture a % in the string, use: _%

  • for arrays and dictionaries (only for the SQLAlchemy implementation):

    • contains: pass a list with all the items that the array should contain, or that should be among the keys, eg: ‘contains’: [‘N’, ‘H’])
    • has_key: pass an element that the list has to contain or that has to be a key, eg: ‘has_key’:’N’)
  • for arrays only (SQLAlchemy version):
    • of_length
    • longer
    • shorter

All the above filters invoke a negation of the expression if preceded by ~:

# first example:
filter_spec = {
    'name' : {
        '~in':[
            'halle',
            'lujah'
        ]
    } # Name not 'halle' or 'lujah'
}

# second example:
filter_spec =  {
    'id' : {
        '~==': 2
    }
} # id is not 2
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

get_projectable_attribute(alias, column_name, attrpath, cast=None, **kwargs)[source]
Returns:An attribute store in a JSON field of the give column
get_session()[source]
Returns:a valid session, an instance of sqlalchemy.orm.session.Session
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_entity_dict)[source]
Returns:An iterator over all the results of a list of dictionaries.
modify_expansions(alias, expansions)[source]

For sqlalchemy, there are no additional expansions for now, so I am returning an empty list

table_groups_nodes
yield_per(query, batch_size)[source]
Parameters:count – Number of rows to yield per step

Yields count rows at a time

Returns:a generator
class aiida.orm.implementation.sqlalchemy.querybuilder.array_length(*clauses, **kwargs)[source]

Bases: sqlalchemy.sql.functions.FunctionElement

__module__ = 'aiida.orm.implementation.sqlalchemy.querybuilder'
_compiler_dispatch(**kw)
_compiler_dispatcher = <sqlalchemy.ext.compiler._dispatcher object>
name = 'array_len'
aiida.orm.implementation.sqlalchemy.querybuilder.compile(element, compiler, **_kw)[source]

Get length of array defined in a JSONB column

class aiida.orm.implementation.sqlalchemy.querybuilder.jsonb_array_length(*clauses, **kwargs)[source]

Bases: sqlalchemy.sql.functions.FunctionElement

__module__ = 'aiida.orm.implementation.sqlalchemy.querybuilder'
_compiler_dispatch(**kw)
_compiler_dispatcher = <sqlalchemy.ext.compiler._dispatcher object>
name = 'jsonb_array_len'
class aiida.orm.implementation.sqlalchemy.querybuilder.jsonb_typeof(*clauses, **kwargs)[source]

Bases: sqlalchemy.sql.functions.FunctionElement

__module__ = 'aiida.orm.implementation.sqlalchemy.querybuilder'
_compiler_dispatch(**kw)
_compiler_dispatcher = <sqlalchemy.ext.compiler._dispatcher object>
name = 'jsonb_typeof'

SQLA user

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

Bases: aiida.orm.implementation.users.BackendUserCollection

Collection of SQLA Users

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__module__ = 'aiida.orm.implementation.sqlalchemy.users'
__next_in_mro__

alias of __builtin__.object

__orig_bases__ = (aiida.orm.implementation.users.BackendUserCollection,)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926333990738
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of SqlaUserCollection

create(email, first_name='', last_name='', institution='')[source]

Create a user with the provided email address

Returns:A new user object
Return type:aiida.orm.User
find(email=None, id=None)[source]

Find a user in matching the given criteria

Parameters:
  • email – the email address
  • id – the id
Returns:

the matching user

Return type:

aiida.orm.implementation.sqlalchemy.users.SqlaUser

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.sqlalchemy.users.SqlaUser(backend, email, first_name, last_name, institution)[source]

Bases: aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, aiida.orm.implementation.users.BackendUser

SQLA user

MODEL_CLASS

alias of aiida.backends.sqlalchemy.models.user.DbUser

__abstractmethods__ = frozenset([])
__args__ = None
__extra__ = None
__init__(backend, email, first_name, last_name, institution)[source]

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

__module__ = 'aiida.orm.implementation.sqlalchemy.users'
__next_in_mro__

alias of aiida.orm.implementation.users.BackendUser

__orig_bases__ = (aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity[aiida.backends.sqlalchemy.models.user.DbUser], <class 'aiida.orm.implementation.users.BackendUser'>)
__origin__ = None
__parameters__ = ()
__tree_hash__ = 5926334004656
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of SqlaUser

date_joined
email
first_name
get_password()[source]

Get the password for the user

Returns:the password
institution
is_active
last_login
last_name
set_password(new_pass)[source]

Set the password of the user

Parameters:new_pass – the new password
aiida.orm.implementation.sqlalchemy.utils.django_filter(cls_query, **kwargs)[source]
aiida.orm.implementation.sqlalchemy.utils.get_attr(attrs, key)[source]