Skip to content

Commit

Permalink
Merge pull request #2 from JuDFTteam/fleur_2021
Browse files Browse the repository at this point in the history
Add FLEUR 2021 workshop tutorial
  • Loading branch information
Tseplyaev authored Apr 21, 2021
2 parents 2b712d4 + 5021678 commit 86b9b15
Show file tree
Hide file tree
Showing 32 changed files with 8,985 additions and 0 deletions.

Large diffs are not rendered by default.

235 changes: 235 additions & 0 deletions tutorials/aiida_fleur_workshop_2021/A1/2_AiiDA_Fleur_input_file.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*please execute the cell below before starting the tutorial by selecting it and pressing Ctrl+Enter*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# imports correct environment\n",
"from aiida import load_profile\n",
"load_profile()\n",
"\n",
"# imports load_node() \n",
"from aiida.orm import load_node\n",
"from pprint import pprint"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# AiiDA-Fleur input file"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Introduction"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In previous tutorial, we learnt about AiiDA data types and found out how files and folders can be stored in the database. It makes sense to extend some of the AiiDA types to represent not a general file - but input files, specific for the Fleur code. There is a special class in AiiDA-Fleur to represent input files for Fleur which is called `FleurinpData`. It represents xml input files needed for a Fleur calculation and also contains some helpful methods to work with them.\n",
"\n",
"**NOTE** : Creation and usage of these data objects via the input generator (`inpgen`) are described in the notebook 4. For this tutorial we assume that we already have an `inp.xml` file."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## FleurinpData"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`FleurinpData` is an AiiDA datastructure specific to the AiiDA-Fleur plugin. One can access this class using the `DataFactory` class provided by the `aiida.orm` module:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from aiida.plugins import DataFactory\n",
"FleurinpData = DataFactory('fleur.fleurinp') "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"or importing it directly:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from aiida_fleur.data.fleurinp import FleurinpData"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`FleurinpData` can be initialized with an absolute path to an ``inp.xml`` file or a\n",
"`FolderData` node containing ``inp.xml``.\n",
"Other files can also be added to a `FleurinpData` object that will be copied to the calculation folder."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# you need to modify this - replace /path/to/inp.xml\n",
"inpxmlfile = '../files/Si/inp.xml'\n",
"fleurinp = FleurinpData(files = [inpxmlfile])\n",
"print(fleurinp) # not stored\n",
"\n",
"fleurinp.store() # to store the node in the database\n",
"print('The PK of stored FleurinpData is {}'.format(fleurinp.pk))\n",
"print('The FleurinpData contains a list of files: {}.'.format(fleurinp.files))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`FleurinpData` stores the files in the repository and saves the input parameters of the\n",
"``inp.xml`` file of FLEUR in the database as a python dictionary which can be accessed via:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fleurinp.inp_dict"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`FleurinpData` also provides the user with methods to extract some AiiDA object such as `StructureData` and `KpointsData` or a `DictData` node which can be used again for an inpgen calculation from an `inp.xml` file:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# The _ncf methods will not keep the provenance for the operation and will return a yet unstored node\n",
"kpoints = fleurinp.get_kpointsdata_ncf()\n",
"kpoints"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"kpoints.get_kpoints()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Notice that this keeps the provenance and returns an already stored node.\n",
"structure = fleurinp.get_structuredata()\n",
"structure"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"para_dict = fleurinp.get_parameterdata(fleurinp)\n",
"print(para_dict)\n",
"pprint(para_dict.get_dict())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Remember, most attributes of AiiDA nodes can not be changed after they\n",
"had been stored in the database! Therefore, we can not change stored `FleurinpData` in-place. \n",
"One has to use the `FleurinpModifier` class and its\n",
"methods to change something in the ``inp.xml`` file. We will learn how to do it in next tutorial."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit 86b9b15

Please sign in to comment.