aiida.backends.djsite documentation

Database schema

class aiida.backends.djsite.db.models.DbAttribute(*args, **kwargs)[source]

This table stores attributes that uniquely define the content of the node. Therefore, their modification corrupts the data.

class aiida.backends.djsite.db.models.DbAttributeBaseClass(*args, **kwargs)[source]

Abstract base class for tables storing element-attribute-value data. Element is the dbnode; attribute is the key name. Value is the specific value to store.

This table had different SQL columns to store different types of data, and a datatype field to know the actual datatype.

Moreover, this class unpacks dictionaries and lists when possible, so that it is possible to query inside recursive lists and dicts.

classmethod del_value_for_node(dbnode, key)[source]

Delete an attribute from the database for the given dbnode.

Note:

no exception is raised if no attribute with the given key is found in the DB.

Parameters:
  • dbnode – the dbnode for which you want to delete the key.
  • key – the key to delete.
classmethod get_all_values_for_node(dbnode)[source]

Return a dictionary with all attributes for the given dbnode.

Returns:a dictionary where each key is a level-0 attribute stored in the Db table, correctly converted to the right type.
classmethod get_all_values_for_nodepk(dbnodepk)[source]

Return a dictionary with all attributes for the dbnode with given PK.

Returns:a dictionary where each key is a level-0 attribute stored in the Db table, correctly converted to the right type.
classmethod get_value_for_node(dbnode, key)[source]

Get an attribute from the database for the given dbnode.

Returns:the value stored in the Db table, correctly converted to the right type.
Raises:AttributeError – if no key is found for the given dbnode
classmethod has_key(dbnode, key)[source]

Return True if the given dbnode has an attribute with the given key, False otherwise.

classmethod list_all_node_elements(dbnode)[source]

Return a django queryset with the attributes of the given node, only at deepness level zero (i.e., keys not containing the separator).

classmethod set_value_for_node(dbnode, key, value, with_transaction=True, stop_if_existing=False)[source]

This is the raw-level method that accesses the DB. No checks are done to prevent the user from (re)setting a valid key. To be used only internally.

Todo:

there may be some error on concurrent write; not checked in this unlucky case!

Parameters:
  • dbnode – the dbnode for which the attribute should be stored; in an integer is passed, this is used as the PK of the dbnode, without any further check (for speed reasons)
  • key – the key of the attribute to store; must be a level-zero attribute (i.e., no separators in the key)
  • value – the value of the attribute to store
  • with_transaction – if True (default), do this within a transaction, so that nothing gets stored if a subitem cannot be created. Otherwise, if this parameter is False, no transaction management is performed.
  • stop_if_existing – if True, it will stop with an UniquenessError exception if the key already exists for the given node. Otherwise, it will first delete the old value, if existent. The use with True is useful if you want to use a given attribute as a “locking” value, e.g. to avoid to perform an action twice on the same node. Note that, if you are using transactions, you may get the error only when the transaction is committed.
Raises:

ValueError – if the key contains the separator symbol used internally to unpack dictionaries and lists (defined in cls._sep).

class aiida.backends.djsite.db.models.DbAuthInfo(*args, **kwargs)[source]

Table that pairs aiida users and computers, with all required authentication information.

get_transport()[source]

Given a computer and an aiida user (as entries of the DB) return a configured transport to connect to the computer.

class aiida.backends.djsite.db.models.DbCalcState(*args, **kwargs)[source]

Store the state of calculations.

The advantage of a table (with uniqueness constraints) is that this disallows entering twice in the same state (e.g., retrieving twice).

class aiida.backends.djsite.db.models.DbComment(id, uuid, dbnode_id, ctime, mtime, user_id, content)[source]
class aiida.backends.djsite.db.models.DbComputer(*args, **kwargs)[source]

Table of computers or clusters.

Attributes: * name: A name to be used to refer to this computer. Must be unique. * hostname: Fully-qualified hostname of the host * transport_type: a string with a valid transport type

Note: other things that may be set in the metadata:

  • mpirun command
  • num cores per node
  • max num cores
  • workdir: Full path of the aiida folder on the host. It can contain the string {username} that will be substituted by the username of the user on that machine. The actual workdir is then obtained as workdir.format(username=THE_ACTUAL_USERNAME) Example: workdir = “/scratch/{username}/aiida/”
  • allocate full node = True or False
  • ... (further limits per user etc.)
classmethod get_dbcomputer(computer)[source]

Return a DbComputer from its name (or from another Computer or DbComputer instance)

class aiida.backends.djsite.db.models.DbExtra(*args, **kwargs)[source]

This table stores extra data, still in the key-value format, that the user can attach to a node. Therefore, their modification simply changes the user-defined data, but does not corrupt the node (it will still be loadable without errors). Could be useful to add “duplicate” information for easier querying, or for tagging nodes.

class aiida.backends.djsite.db.models.DbGroup(*args, **kwargs)[source]

A group of nodes.

Any group of nodes can be created, but some groups may have specific meaning if they satisfy specific rules (for instance, groups of UpdData objects are pseudopotential families - if no two pseudos are included for the same atomic element).

Direct connection between two dbnodes. The label is identifying the link type.

class aiida.backends.djsite.db.models.DbLock(key, creation, timeout, owner)[source]
class aiida.backends.djsite.db.models.DbLog(id, time, loggername, levelname, objname, objpk, message, metadata)[source]
class aiida.backends.djsite.db.models.DbMultipleValueAttributeBaseClass(*args, **kwargs)[source]

Abstract base class for tables storing attribute + value data, of different data types (without any association to a Node).

classmethod create_value(key, value, subspecifier_value=None, other_attribs={})[source]

Create a new list of attributes, without storing them, associated with the current key/value pair (and to the given subspecifier, e.g. the DbNode for DbAttributes and DbExtras).

Note:

No hits are done on the DB, in particular no check is done on the existence of the given nodes.

Parameters:
  • key – a string with the key to create (can contain the separator cls._sep if this is a sub-attribute: indeed, this function calls itself recursively)
  • value – the value to store (a basic data type or a list or a dict)
  • subspecifier_value – must be None if this class has no subspecifier set (e.g., the DbSetting class). Must be the value of the subspecifier (e.g., the dbnode) for classes that define it (e.g. DbAttribute and DbExtra)
  • other_attribs – a dictionary of other parameters, to store only on the level-zero attribute (e.g. for description in DbSetting).
Returns:

always a list of class instances; it is the user responsibility to store such entries (typically with a Django bulk_create() call).

classmethod del_value(key, only_children=False, subspecifier_value=None)[source]

Delete a value associated with the given key (if existing).

Note:

No exceptions are raised if no entry is found.

Parameters:
  • key – the key to delete. Can contain the separator cls._sep if you want to delete a subkey.
  • only_children – if True, delete only children and not the entry itself.
  • subspecifier_value – must be None if this class has no subspecifier set (e.g., the DbSetting class). Must be the value of the subspecifier (e.g., the dbnode) for classes that define it (e.g. DbAttribute and DbExtra)
classmethod get_query_dict(value)[source]

Return a dictionary that can be used in a django filter to query for a specific value. This takes care of checking the type of the input parameter ‘value’ and to convert it to the right query.

Parameters:value – The value that should be queried. Note: can only be base datatype, not a list or dict. For those, query directly for one of the sub-elements.
Todo:see if we want to give the possibility to query for the existence of a (possibly empty) dictionary or list, of for their length.
Note:this will of course not find a data if this was stored in the DB as a serialized JSON.
Returns:a dictionary to be used in the django .filter() method. For instance, if ‘value’ is a string, it will return the dictionary {'datatype': 'txt', 'tval': value}.
Raise:ValueError if value is not of a base datatype (string, integer, float, bool, None, or date)
getvalue()[source]

This can be called on a given row and will get the corresponding value, casting it correctly.

long_field_length()

Return the length of “long” fields. This is used, for instance, for the ‘key’ field of attributes. This returns 1024 typically, but it returns 255 if the backend is mysql.

Note:Call this function only AFTER having called load_dbenv!
classmethod set_value(key, value, with_transaction=True, subspecifier_value=None, other_attribs={}, stop_if_existing=False)[source]

Set a new value in the DB, possibly associated to the given subspecifier.

Note:

This method also stored directly in the DB.

Parameters:
  • key – a string with the key to create (must be a level-0 attribute, that is it cannot contain the separator cls._sep).
  • value – the value to store (a basic data type or a list or a dict)
  • subspecifier_value – must be None if this class has no subspecifier set (e.g., the DbSetting class). Must be the value of the subspecifier (e.g., the dbnode) for classes that define it (e.g. DbAttribute and DbExtra)
  • with_transaction – True if you want this function to be managed with transactions. Set to False if you already have a manual management of transactions in the block where you are calling this function (useful for speed improvements to avoid recursive transactions)
  • other_attribs – a dictionary of other parameters, to store only on the level-zero attribute (e.g. for description in DbSetting).
  • stop_if_existing – if True, it will stop with an UniquenessError exception if the new entry would violate an uniqueness constraint in the DB (same key, or same key+node, depending on the specific subclass). Otherwise, it will first delete the old value, if existent. The use with True is useful if you want to use a given attribute as a “locking” value, e.g. to avoid to perform an action twice on the same node. Note that, if you are using transactions, you may get the error only when the transaction is committed.
subspecifier_pk

Return the subspecifier PK in the database (or None, if no subspecifier should be used)

subspecifiers_dict

Return a dict to narrow down the query to only those matching also the subspecifier.

classmethod validate_key(key)[source]

Validate the key string to check if it is valid (e.g., if it does not contain the separator symbol.).

Returns:None if the key is valid
Raises:ValidationError – if the key is not valid
class aiida.backends.djsite.db.models.DbNode(*args, **kwargs)[source]

Generic node: data or calculation or code.

Nodes can be linked (DbLink table) Naming convention for Node relationships: A –> C –> B.

  • A is ‘input’ of C.
  • C is ‘output’ of A.
  • A is ‘parent’ of B,C
  • C,B are ‘children’ of A.
Note:parents and children are stored in the DbPath table, the transitive closure table, automatically updated via DB triggers whenever a link is added to or removed from the DbLink table.

Internal attributes, that define the node itself, are stored in the DbAttribute table; further user-defined attributes, called ‘extra’, are stored in the DbExtra table (same schema and methods of the DbAttribute table, but the code does not rely on the content of the table, therefore the user can use it at his will to tag or annotate nodes.

Note:Attributes in the DbAttribute table have to be thought as belonging to the DbNode, (this is the reason for which there is no ‘user’ field in the DbAttribute field). Moreover, Attributes define uniquely the Node so should be immutable (except for the few ones defined in the _updatable_attributes attribute of the Node() class, that are updatable: these are Attributes that are set by AiiDA, so the user should not modify them, but can be changed (e.g., the append_text of a code, that can be redefined if the code has to be recompiled).
attributes

Return all attributes of the given node as a single dictionary.

extras

Return all extras of the given node as a single dictionary.

get_aiida_class()[source]

Return the corresponding aiida instance of class aiida.orm.Node or a appropriate subclass.

get_simple_name(invalid_result=None)[source]

Return a string with the last part of the type name.

If the type is empty, use ‘Node’. If the type is invalid, return the content of the input variable invalid_result.

Parameters:invalid_result – The value to be returned if the node type is not recognized.
class aiida.backends.djsite.db.models.DbPath(*args, **kwargs)[source]

Transitive closure table for all dbnode paths.

expand()[source]

Method to expand a DbPath (recursive function), i.e., to get a list of all dbnodes that are traversed in the given path.

Returns:list of DbNode objects representing the expanded DbPath
class aiida.backends.djsite.db.models.DbSetting(*args, **kwargs)[source]

This will store generic settings that should be database-wide.

class aiida.backends.djsite.db.models.DbUser(*args, **kwargs)[source]

This class replaces the default User class of Django

class aiida.backends.djsite.db.models.DbWorkflow(id, uuid, ctime, mtime, user_id, label, description, nodeversion, lastsyncedversion, state, report, module, module_class, script_path, script_md5)[source]
get_aiida_class()[source]

Return the corresponding aiida instance of class aiida.worflow

is_subworkflow()[source]

Return True if this is a subworkflow, False if it is a root workflow, launched by the user.

class aiida.backends.djsite.db.models.DbWorkflowData(id, parent_id, name, time, data_type, value_type, json_value, aiida_obj_id)[source]
class aiida.backends.djsite.db.models.DbWorkflowStep(id, parent_id, name, user_id, time, nextcall, state)[source]
aiida.backends.djsite.db.models.deserialize_attributes(data, sep, original_class=None, original_pk=None)[source]

Deserialize the attributes from the format internally stored in the DB to the actual format (dictionaries, lists, integers, ...

Parameters:
  • data – must be a dictionary of dictionaries. In the top-level dictionary, the key must be the key of the attribute. The value must be a dictionary with the following keys: datatype, tval, fval, ival, bval, dval. Other keys are ignored. NOTE that a type check is not performed! tval is expected to be a string, dval a date, etc.
  • sep – a string, the separator between subfields (to separate the name of a dictionary from the keys it contains, for instance)
  • original_class – if these elements come from a specific subclass of DbMultipleValueAttributeBaseClass, pass here the class (note: the class, not the instance!). This is used only in case the wrong number of elements is found in the raw data, to print a more meaningful message (if the class has a dbnode associated to it)
  • original_pk – if the elements come from a specific subclass of DbMultipleValueAttributeBaseClass that has a dbnode associated to it, pass here the PK integer. This is used only in case the wrong number of elements is found in the raw data, to print a more meaningful message
Returns:

a dictionary, where for each entry the corresponding value is returned, deserialized back to lists, dictionaries, etc. Example: if data = {'a': {'datatype': "list", "ival": 2, ...}, 'a.0': {'datatype': "int", "ival": 2, ...}, 'a.1': {'datatype': "txt", "tval":  "yy"}], it will return {"a": [2, "yy"]}