aiida.backends.djsite package

Submodules

aiida.backends.djsite.cmdline.get_computers_work_dir(calculations, user)[source]
Get a list of computers and their remotes working directory.

calculations should be a list of JobCalculation object.

aiida.backends.djsite.cmdline.get_group_list(user, type_string, n_days_ago=None, name_filters={})[source]
aiida.backends.djsite.cmdline.get_log_messages(obj)[source]

Get the log messages for the object.

aiida.backends.djsite.cmdline.get_workflow_list(pk_list=(), user=None, all_states=False, n_days_ago=None)[source]

Get a list of workflow.

Parameters:
  • user – A ORM User class if you want to filter by user
  • pk_list – Limit the results to this list of PKs
  • all_states – if False, limit results to “active” (e.g., running) wfs
  • n_days_ago – an integer number of days. If specifies, limit results to workflows started up to this number of days ago

Functions to manage the global settings stored in the DB (in the DbSettings table.

aiida.backends.djsite.globalsettings.del_global_setting(key)[source]

Return the value of the given setting, or raise a KeyError if the setting is not present in the DB.

Raises:KeyError – if the setting does not exist in the DB
aiida.backends.djsite.globalsettings.get_global_setting(key)[source]

Return the value of the given setting, or raise a KeyError if the setting is not present in the DB.

Raises:KeyError – if the setting does not exist in the DB
aiida.backends.djsite.globalsettings.get_global_setting_description(key)[source]

Return the description for the given setting variable, as stored in the DB, or raise a KeyError if the setting is not present in the DB or the table doesn’t exist..

aiida.backends.djsite.globalsettings.set_global_setting(key, value, description=None)[source]

Set a global setting in the DbSetting table (therefore, stored at the DB level).

aiida.backends.djsite.globalsettings.table_check_test()[source]

Checks if the db_setting table exists in the database. If it doesn’t exist it rainses a KeyError.

class aiida.backends.djsite.queries.QueryManagerDjango(*args, **kwargs)[source]

Bases: aiida.backends.general.abstractqueries.AbstractQueryManager

__abstractmethods__ = frozenset([])
__module__ = 'aiida.backends.djsite.queries'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 38
_abc_registry = <_weakrefset.WeakSet object>
get_all_parents(node_pks, return_values=['id'])[source]

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

get_bands_and_parents_structure(args)[source]

Returns bands and closest parent structure

get_creation_statistics(user_email=None)[source]

Return a dictionary with the statistics of node creation, summarized by day, optimized for the Django backend.

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

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

query_group(q_object, args)[source]

Subselect to filter data nodes by their group.

Parameters:
  • q_object – a query object
  • args – a namespace with parsed command line parameters.
query_jobcalculations_by_computer_user_state(state, computer=None, user=None, only_computer_user_pairs=False, only_enabled=True, limit=None)[source]

Filter all calculations with a given state.

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

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

a list of calculation objects matching the filters.

query_past_days(q_object, args)[source]

Subselect to filter data nodes by their age.

Parameters:
  • q_object – a query object
  • args – a namespace with parsed command line parameters.
aiida.backends.djsite.queries.get_closest_parents(pks, *args, **kwargs)[source]

Get the closest parents dbnodes of a set of nodes.

Parameters:
  • pks – one pk or an iterable of pks of nodes
  • chunk_size – we chunk the pks into groups of this size, to optimize the speed (default=50)
  • print_progress – print the the progression if True (default=False).
  • args – additional query parameters
  • kwargs – additional query parameters
Returns:

a dictionary of the form pk1: pk of closest parent of node with pk1, pk2: pk of closest parent of node with pk2

Note

It works also if pks is a list of nodes rather than their pks

Todo

find a way to always get a parent (when there is one) from each pk. Now, when the same parent has several children in pks, only one of them is kept. This is a BUG, related to the use of a dictionary (children_dict, see below…). For now a work around is to use chunk_size=1.

aiida.backends.djsite.utils._load_dbenv_noschemacheck(process, profile)[source]

Load the database environment (Django) WITHOUT CHECKING THE SCHEMA VERSION.

Parameters:
  • process – the process that is calling this command (‘verdi’, or ‘daemon’)
  • profile – the string with the profile to use. If not specified, use the default one specified in the AiiDA configuration file.

This should ONLY be used internally, inside load_dbenv, and for schema migrations. DO NOT USE OTHERWISE!

aiida.backends.djsite.utils.check_schema_version()[source]

Check if the version stored in the database is the same of the version of the code.

Note:if the DbSetting table does not exist, this function does not fail. The reason is to avoid to have problems before running the first migrate call.
Note:if no version is found, the version is set to the version of the code. This is useful to have the code automatically set the DB version at the first code execution.
Raises:ConfigurationError – if the two schema versions do not match. Otherwise, just return.
aiida.backends.djsite.utils.delete_nodes_and_connections_django(pks_to_delete)[source]

Delete all nodes corresponding to pks in the input. :param pks_to_delete: A list, tuple or set of pks that should be deleted.

aiida.backends.djsite.utils.get_automatic_user()[source]

Return the default user for this installation of AiiDA.

aiida.backends.djsite.utils.get_daemon_user()[source]

Return the username (email) of the user that should run the daemon, or the default AiiDA user in case no explicit configuration is found in the DbSetting table.

aiida.backends.djsite.utils.get_db_schema_version()[source]

Get the current schema version stored in the DB. Return None if it is not stored.

aiida.backends.djsite.utils.get_log_messages(obj)[source]
aiida.backends.djsite.utils.load_dbenv(process=None, profile=None)[source]

Load the database environment (Django) and perform some checks.

Parameters:
  • process – the process that is calling this command (‘verdi’, or ‘daemon’)
  • profile – the string with the profile to use. If not specified, use the default one specified in the AiiDA configuration file.
aiida.backends.djsite.utils.long_field_length()[source]

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!
aiida.backends.djsite.utils.set_daemon_user(user_email)[source]

Set the username (email) of the user that is allowed to run the daemon.

aiida.backends.djsite.utils.set_db_schema_version(version)[source]

Set the schema version stored in the DB. Use only if you know what you are doing.