{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "(props_ech3)=\n", "\n", "# Properties: Charge Density (ECH3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The {py:class}`~.aiida_crystal17.calculations.prop_ech3.CryEch3Calculation` can be used to run the `properties`\n", "executable for ECH3 calculations, from an existing `fort.9`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ":::{seealso}\n", "{ref}`props_workflow` to run multiple properties calculations\n", "(and optional initial SCF).\n", ":::" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[31m\u001b[1mInputs\u001b[0m\n", "\u001b[1m code: required Code The Code to use for this job.\u001b[0m\n", "\u001b[1m parameters: required Dict the input parameters to create the properties input file.\u001b[0m\n", "\u001b[1m wf_folder: required FolderData, RemoteData, SinglefileData the folder containing the wavefunction fort.9 file\u001b[0m\n", " metadata: optional \u001b[0m\n", "\u001b[31m\u001b[1mOutputs\u001b[0m\n", "\u001b[1m charge: required GaussianCube The charge density cube\u001b[0m\n", "\u001b[1m remote_folder: required RemoteData Input files necessary to run the process will be stored in this folder node ...\u001b[0m\n", "\u001b[1m results: required Dict Summary Data extracted from the output file(s)\u001b[0m\n", "\u001b[1m retrieved: required FolderData Files that are retrieved by the daemon will be stored in this node. By defa ...\u001b[0m\n", " spin: optional GaussianCube The spin density cube\u001b[0m\n", "\u001b[31m\u001b[1mExit codes\u001b[0m\n", " 1: The process has failed with an unspecified error.\u001b[0m\n", " 2: The process failed with legacy failure mode.\u001b[0m\n", " 10: The process returned an invalid output.\u001b[0m\n", " 11: The process did not register a required output.\u001b[0m\n", " 200: The retrieved folder data node could not be accessed.\u001b[0m\n", " 210: The main (stdout) output file was not found\u001b[0m\n", " 211: The temporary retrieved folder was not found\u001b[0m\n", " 300: An error was flagged trying to parse the crystal exec stdout file\u001b[0m\n", " 350: The input file could not be read by crystal\u001b[0m\n", " 351: Crystal could not find the required wavefunction file\u001b[0m\n", " 352: Parser could not find the output density file\u001b[0m\n", " 353: Error parsing output density file\u001b[0m\n", " 400: The calculation stopped prematurely because it ran out of walltime.\u001b[0m\n", " 401: The calculation stopped prematurely because it ran out of memory.\u001b[0m\n", " 402: The calculation stopped prematurely because it ran out of virtual memory.\u001b[0m\n", " 413: An error encountered usually during geometry optimisation\u001b[0m\n", " 414: An error was encountered during an scf computation\u001b[0m\n", " 415: An unknown error was encountered, causing the mpi to abort\u001b[0m\n", " 499: The main crystal output file flagged an unhandled error\u001b[0m\n" ] } ], "source": [ "!verdi plugin list aiida.calculations crystal17.ech3" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'test_crystal17'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from aiida import engine, load_profile, orm, plugins\n", "from aiida.tools.visualization import Graph\n", "from aiida_crystal17.common import recursive_round\n", "from aiida_crystal17.tests.utils import (\n", " get_or_create_local_computer, get_or_create_code,\n", " get_default_metadata)\n", "from aiida_crystal17.tests import open_resource_binary\n", "profile = load_profile()\n", "profile.name" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Running a calculation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The {ref}`ech3_input_schema` gives the allowed format of the input dictionary, for example:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "computer = get_or_create_local_computer('work_directory', 'localhost')\n", "code = get_or_create_code('crystal17.ech3', computer, 'mock_properties17')\n", "\n", "builder = code.get_builder()\n", "builder.metadata = get_default_metadata()\n", "builder.parameters = orm.Dict(dict={\n", " 'npoints': 20\n", "})\n", "with open_resource_binary('ech3', 'mgo_sto3g_scf', 'fort.9') as handle:\n", " builder.wf_folder = orm.SinglefileData(handle)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "result, calcnode = engine.run_get_node(builder)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[22mProperty Value\n", "------------- ------------------------------------\n", "type CalcJobNode\n", "pk 974\n", "uuid 4dd70b8f-e7b6-4684-84e2-69f5db4ddbb8\n", "label\n", "description\n", "ctime 2019-09-24 15:45:47.628170+00:00\n", "mtime 2019-09-24 15:46:01.609931+00:00\n", "process state Finished\n", "exit status 0\n", "computer [1] localhost\n", "\n", "Inputs PK Type\n", "---------- ---- --------------\n", "code 971 Code\n", "parameters 972 Dict\n", "wf_folder 973 SinglefileData\n", "\n", "Outputs PK Type\n", "------------- ---- ------------\n", "charge 978 GaussianCube\n", "remote_folder 975 RemoteData\n", "results 977 Dict\n", "retrieved 976 FolderData\u001b[0m\n" ] } ], "source": [ "!verdi process show {calcnode.pk}" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ipub": { "figure": { "caption": "`crystal17.ech3` calculation provenance graph." } } }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "%3\n", "\n", "\n", "\n", "N974\n", "\n", "CryEch3Calculation (974)\n", "State: finished\n", "Exit Code: 0\n", "\n", "\n", "\n", "N978\n", "\n", "GaussianCube (978)\n", "\n", "\n", "\n", "N974->N978\n", "\n", "\n", "CREATE\n", "charge\n", "\n", "\n", "\n", "N977\n", "\n", "Dict (977)\n", "\n", "\n", "\n", "N974->N977\n", "\n", "\n", "CREATE\n", "results\n", "\n", "\n", "\n", "N976\n", "\n", "FolderData (976)\n", "\n", "\n", "\n", "N974->N976\n", "\n", "\n", "CREATE\n", "retrieved\n", "\n", "\n", "\n", "N975\n", "\n", "RemoteData (975)\n", "@localhost\n", "\n", "\n", "\n", "N974->N975\n", "\n", "\n", "CREATE\n", "remote_folder\n", "\n", "\n", "\n", "N973\n", "\n", "SinglefileData (973)\n", "fort.9\n", "\n", "\n", "\n", "N973->N974\n", "\n", "\n", "INPUT_CALC\n", "wf_folder\n", "\n", "\n", "\n", "N972\n", "\n", "Dict (972)\n", "\n", "\n", "\n", "N972->N974\n", "\n", "\n", "INPUT_CALC\n", "parameters\n", "\n", "\n", "\n", "N971\n", "\n", "Code (971)\n", "mock_properties17@localhost\n", "\n", "\n", "\n", "N971->N974\n", "\n", "\n", "INPUT_CALC\n", "code\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "graph = Graph(graph_attr={'size': \"6,8!\", \"rankdir\": \"LR\"})\n", "graph.add_node(calcnode)\n", "graph.add_incoming(calcnode, annotate_links=\"both\")\n", "graph.add_outgoing(calcnode, annotate_links=\"both\")\n", "graph.graphviz" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Analysing the outputs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The outputs are:\n", "\n", "- **results** a dict of computation input and output parameters, parsed from the stdout file.\n", "- **charge** a data node containing the gaussian cube file for the charge density.\n", "- **spin** a data node containing the gaussian cube file for the spin density (if the original computation included spin)." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'units': {'energy': 'eV', 'conversion': 'CODATA2014'},\n", " 'errors': [],\n", " 'header': {'crystal_version': 17, 'crystal_subversion': '1.0.1'},\n", " 'warnings': [],\n", " 'wf_input': {'n_ao': 14,\n", " 'n_atoms': 2,\n", " 'k_points': [8, 8, 8],\n", " 'n_shells': 5,\n", " 'n_symops': 48,\n", " 'gilat_net': 8,\n", " 'n_core_el': 12,\n", " 'n_electrons': 20,\n", " 'energy_fermi': -4.0,\n", " 'energy_total': -7380.2,\n", " 'n_kpoints_ibz': 29,\n", " 'energy_kinetic': 7269.0},\n", " 'parser_class': 'CryEch3Parser',\n", " 'parser_errors': [],\n", " 'parser_version': '0.11.0',\n", " 'parser_exceptions': [],\n", " 'execution_time_seconds': 0}" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "recursive_round(calcnode.outputs.results.get_dict(), 1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The {py:class}`~aiida_crystal17.data.gcube.GaussianCube` data node stores a [gaussian cube](http://h5cube-spec.readthedocs.io/en/latest/cubeformat.html) in a compressed zip file." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'cell': [[0.0, 2.2157919831613, 2.2157919831613],\n", " [2.2157919831613, 0.0, 2.2157919831613],\n", " [2.2157919831613, 2.2157919831613, 0.0]],\n", " 'units': {'length': 'angstrom', 'conversion': 'CODATA2014'},\n", " 'header': ['Charge density - 3D GRID - GAUSSIAN CUBE FORMAT MgO Bulk',\n", " '5.62556267 5.62556267 5.62556267 60.000000 60.000000 60.000000'],\n", " 'elements': ['Mg', 'O'],\n", " 'voxel_grid': [20, 20, 20],\n", " 'zip_filename': 'gcube.zip',\n", " 'cube_filename': 'gaussian.cube',\n", " 'compression_method': 8}" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "calcnode.outputs.charge.attributes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The full file can be accessed *via*:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Charge density - 3D GRID - GAUSSIAN CUBE FORMAT MgO Bulk \n", "\n" ] } ], "source": [ "with calcnode.outputs.charge.open_cube_file() as handle:\n", " print(handle.readline())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There is also methods available to parse the file to a dict or structure:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[12, 8]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = calcnode.outputs.charge.get_cube_data()\n", "data.atoms_atomic_number" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Atoms(symbols='MgO', pbc=True, cell=[[0.0, 2.2157919831613384, 2.2157919831613384], [2.2157919831613384, 0.0, 2.2157919831613384], [2.2157919831613384, 2.2157919831613384, 0.0]])" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "calcnode.outputs.charge.get_ase()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Some experimental methods also exist, for basic analysis of the density." ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "18.60283258916424" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "calcnode.outputs.charge.compute_integration_cell()" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[17.16956646407823, 1.1837163766941237]" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "calcnode.outputs.charge.compute_integration_atom([0, 1], radius=1.0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualising the density in VESTA" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The {py:mod}`~aiida_crystal17.parsers.raw.vesta` module\n", "contains functions, to convert cube data to input files that can be opened in [VESTA](http://jp-minerals.org/vesta).\n", "The {ref}`vesta_input_schema` gives the allowed format of the input settings dictionary, for example:" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['mgo.cube', 'mgo.vesta']\n", "#VESTA_FORMAT_VERSION 3.3.0\n", "\n", "CRYSTAL\n", "\n", "TITLE\n", "GAUSSIAN_CUBE_DATA\n", "\n", "IMPORT_DENSITY 1\n", "+1.000000 mgo.cube\n", "\n" ] } ], "source": [ "from aiida.common.folders import SandboxFolder\n", "from aiida_crystal17.parsers.raw.vesta import (\n", " create_vesta_input, write_gcube_to_vesta)\n", "\n", "settings = {\n", " \"2d_display\": {\n", " \"h\": 1.0,\n", " \"k\": -1.0,\n", " \"l\": 0.0,\n", " \"dist_from_o\": 0.0\n", " }\n", "}\n", "\n", "with SandboxFolder() as folder:\n", " write_gcube_to_vesta(\n", " calcnode.outputs.charge,\n", " folder.abspath, 'mgo', settings)\n", " print(folder.get_content_list())\n", " with folder.open('mgo.vesta') as handle:\n", " print(handle.read()[:100])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![VESTA 3D Density Visualisation](vesta_screenshots/main.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![VESTA 2D Density Visualisation](vesta_screenshots/2d_display.png)" ] } ], "metadata": { "celltoolbar": "Edit Metadata", "hide_input": false, "jupytext": { "formats": "ipynb,md:myst" }, "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.6.7" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }