aiida.backends.djsite package

Submodules

class aiida.backends.djsite.queries.DjangoQueryManager(backend)[source]

Bases: aiida.backends.general.abstractqueries.AbstractQueryManager

__abstractmethods__ = frozenset({})
__init__(backend)[source]
Parameters

backend (aiida.orm.implementation.sql.SqlBackend) – The AiiDA backend

__module__ = 'aiida.backends.djsite.queries'
_abc_impl = <_abc_data object>
get_bands_and_parents_structure(args)[source]

Returns bands and closest parent structure

get_creation_statistics(user_pk=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_pk – If None (default), return statistics for all users. If user pk 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_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.

Django settings for the AiiDA project.

Utility functions specific to the Django backend.

class aiida.backends.djsite.utils.DjangoSettingsManager[source]

Bases: aiida.backends.utils.SettingsManager

Class to get, set and delete settings from the DbSettings table.

__module__ = 'aiida.backends.djsite.utils'
delete(key)[source]

Delete the setting with the given key.

Parameters

key – the key identifying the setting

Raises

~aiida.common.exceptions.NotExistent if the settings does not exist

get(key)[source]

Return the setting with the given key.

Parameters

key – the key identifying the setting

Returns

Setting

Raises

~aiida.common.exceptions.NotExistent if the settings does not exist

set(key, value, description=None)[source]

Return the settings with the given key.

Parameters
  • key – the key identifying the setting

  • value – the value for the setting

  • description – optional setting description

table_name = 'db_dbsetting'
validate_table_existence()[source]

Verify that the DbSetting table actually exists.

Raises

~aiida.common.exceptions.NotExistent if the settings table does not exist

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

Load the database environment without checking that code and database schema versions are compatible.

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

Parameters

profile – instance of Profile whose database to load

aiida.backends.djsite.utils.check_schema_version(profile_name)[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

aiida.common.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_db_schema_version()[source]

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

aiida.backends.djsite.utils.load_dbenv(profile)[source]

Load the database environment and ensure that the code and database schema versions are compatible.

Parameters

profile – instance of Profile whose database to load

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

Migrate the database to the latest schema version.

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.

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

Unload the database environment.

This means that the settings in aiida.backends.djsite.settings are “unset”. This needs to implemented and will address #2813