-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default values of variables is not stored in db
we avoid unnecessary or redundant storing.
- Loading branch information
1 parent
1441d46
commit 76a2ab7
Showing
11 changed files
with
358 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# How to efficiently query properties\n", | ||
"\n", | ||
"In the following we presents first how `StructureData` nodes are store in the AiiDA database and then how to user the `QueryBuilder` to find them.\n", | ||
"\n", | ||
"## How properties are store in the AiiDA database\n", | ||
"\n", | ||
"In the AiiDA database, we store only properties which are defined to be different from the default value. For example, if we provide all the charges to be zero, the `charges` properties will not be stored in the database. This means that the only structures which are in the database and contains also a charges entry, will be about systems with charged different from zero (NB can also be overall neutral).\n", | ||
"\n", | ||
"For a given structure, you can print the list of all the properties stored in the database (and so, queryable), by calling the `get_defined_properties` method and providing `exclude_computed=False` as input (i.e. returning also properties which are computed/derived from the user-defined ones):" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"{'positions', 'dimensionality', 'symbols', 'cell_volume', 'cell', 'kinds', 'masses', 'formula', 'sites'}\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from aiida import load_profile\n", | ||
"from aiida_atomistic import StructureData\n", | ||
"\n", | ||
"load_profile()\n", | ||
"\n", | ||
"structure = StructureData(**{\n", | ||
" 'pbc': [True, True, True],\n", | ||
" 'cell': [[2.75, 2.75, 0.0], [0.0, 2.75, 2.75], [2.75, 0.0, 2.75]],\n", | ||
" 'symbols': ['Si', 'Si'],\n", | ||
" 'charges': [0.0, 0.0],\n", | ||
" 'kinds': ['Si', 'Si'],\n", | ||
" 'positions': [\n", | ||
" [0.0, 0.0, 0.0],\n", | ||
" [3.84, 1.3576450198781713, 1.9200]\n", | ||
" ],\n", | ||
"})\n", | ||
"\n", | ||
"print(\"Properties stored in the database are:\")\n", | ||
"print(structure.get_defined_properties(exclude_computed=False))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Where actually the only properties stored in the AiiDA database are:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"{'positions', 'symbols', 'cell', 'kinds', 'masses'}\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(structure.get_defined_properties())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The only exception will be the `sites` property, which is contained in this list but not stored in the database: this is computed on-the-fly and it does not contains additional information meant to be in the database.\n", | ||
"\n", | ||
":::{note} \n", | ||
":class: dropdown\n", | ||
"To explicitely see how data are stored and represented in the database, you can access the `structure.base.attributes.all` dictionary. \n", | ||
"As you can see, not `sites` entry is present.\n", | ||
"\n", | ||
"```python\n", | ||
"print(structure.base.attributes.all.keys())\n", | ||
"```\n", | ||
"\n", | ||
"returns: \n", | ||
"\n", | ||
"```bash\n", | ||
"dict_keys(['cell', 'symbols', 'positions', 'kinds', 'masses', 'cell_volume', 'dimensionality', 'formula'])\n", | ||
"```\n", | ||
":::" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## How to Query StructureData using properties\n", | ||
"\n", | ||
"In the following we present how to perform advanced query in you database to retrieve `StructureData` with given properties.\n", | ||
"\n", | ||
"Thanks to the additional computed properties in our `StructureData` (*formula*, *symbols*, *kinds*, *masses*, *charges*, *magmoms*, *positions*, *cell_volume*, *dimensionality*), we can easily query for a structure:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from aiida.orm import QueryBuilder\n", | ||
"\n", | ||
"stored = StructureData.from_mutable(mutable_structure).store()\n", | ||
"print(stored.pk)\n", | ||
"\n", | ||
"qb = QueryBuilder()\n", | ||
"qb.append(StructureData, \n", | ||
" filters={'attributes.formula': 'Fe2'},\n", | ||
" )\n", | ||
"\n", | ||
"qb.all()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "base", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.13" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.