{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "(main_calculation_immigrant)=" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Main Calculation Immigration" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In order to immigrate existing CRYSTAL17 calculations,\n", "the {py:mod}`aiida_crystal17.immigration` module has been\n", "created to take a ``.d12`` and ``.out`` file set\n", "and replicate a ``crystal17.main`` calculation:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ":::{note}\n", "This approach may be subject to change,\n", "if a general approach is developed for immigrant calculations\n", "(see [this ongoing issue](https://github.com/aiidateam/aiida_core/issues/1892)).\n", ":::" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "init_cell": true }, "outputs": [], "source": [ "from aiida import load_profile\n", "profile = load_profile()\n", "import os\n", "from aiida_crystal17.tests import resource_context\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.immigration.create_inputs import populate_builder\n", "from aiida_crystal17.immigration.create_calcjob import immigrate_existing\n", "from aiida_crystal17.common import display_json\n", "\n", "from aiida.orm import Code, RemoteData\n", "from aiida.common.folders import Folder\n", "from aiida.tools.visualization import Graph" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "{py:func}`aiida_crystal17.immigration.create_inputs.populate_builder`\n", "will create an input builder for the `crystal17.main` calculation,\n", "from a `FolderData` node, populated with the files, and a `Code` node." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "computer = get_or_create_local_computer('work_directory', 'localhost')\n", "code = get_or_create_code('crystal17.main', computer, 'mock_crystal17')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "```json\n", "{\n", " \"metadata\": {\n", " \"options\": {\n", " \"resources\": {\n", " \"num_machines\": 1,\n", " \"num_mpiprocs_per_machine\": 1\n", " },\n", " \"max_wallclock_seconds\": 1800,\n", " \"withmpi\": false,\n", " \"input_file_name\": \"INPUT\",\n", " \"output_main_file_name\": \"main.out\"\n", " },\n", " \"dry_run\": false\n", " },\n", " \"basissets\": {\n", " \"Ni\": [\n", " \"uuid: 8037949d-6cbd-4941-b380-c7be30dd1d79 (unstored)\"\n", " ],\n", " \"O\": [\n", " \"uuid: c02b6eb8-56e9-4e94-8e0f-f02f41d33302 (unstored)\"\n", " ]\n", " },\n", " \"parameters\": [\n", " \"uuid: 54d33eec-3ff4-4444-9088-48edf9ee5c83 (unstored)\"\n", " ],\n", " \"structure\": [\n", " \"uuid: 25918928-377a-4718-bb29-db44b7e73b06 (unstored)\"\n", " ],\n", " \"symmetry\": [\n", " \"uuid: 9e8d3c76-845b-4aa7-8221-32491953b9e9 (unstored)\"\n", " ],\n", " \"kinds\": [\n", " \"uuid: de13ccd4-22f3-4700-b9e3-b5692815a8cc (unstored)\"\n", " ],\n", " \"code\": [\n", " \"Remote code 'crystal17.main-mock_crystal17@localhost' on localhost,\",\n", " \"pk: 1, uuid: 413a3836-4cf1-4269-9a63-52b2bde99cb4\"\n", " ]\n", "}\n", "```" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "metadata = get_default_metadata()\n", "metadata['options'].update({\n", " \"input_file_name\": 'INPUT',\n", " \"output_main_file_name\": \"main.out\"\n", "})\n", "\n", "with resource_context(\"crystal\", \"nio_sto3g_afm_opt\") as path:\n", " builder = populate_builder(\n", " remote_data=RemoteData(\n", " remote_path=str(path),\n", " computer=computer),\n", " code=code,\n", " metadata=metadata)\n", "\n", "display_json(builder)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "{py:func}`aiida_crystal17.immigration.create_calcjob.immigrate_existing`\n", "creates a `CalcJobNode` and uses the above function,\n", "and the `crystal17.main` parser, to create and attach incoming and outgoing nodes,\n", "replicating a full calculation." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "with resource_context(\"crystal\", \"nio_sto3g_afm_opt\") as path:\n", " calc_node = immigrate_existing(\n", " builder,\n", " remote_data=RemoteData(\n", " remote_path=str(path),\n", " computer=computer))\n", "calc_node" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ipub": { "figure": { "caption": "`crystal17.main` immigrated calculation provenance graph." } } }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "%3\n", "\n", "\n", "\n", "N8\n", "\n", "CryMainCalculation (8)\n", "State: finished\n", "Exit Code: 0\n", "\n", "\n", "\n", "N12\n", "\n", "StructureData (12)\n", "Ni2O2\n", "\n", "\n", "\n", "N8->N12\n", "\n", "\n", "CREATE\n", "structure\n", "\n", "\n", "\n", "N11\n", "\n", "Dict (11)\n", "\n", "\n", "\n", "N8->N11\n", "\n", "\n", "CREATE\n", "results\n", "\n", "\n", "\n", "N10\n", "\n", "FolderData (10)\n", "\n", "\n", "\n", "N8->N10\n", "\n", "\n", "CREATE\n", "retrieved\n", "\n", "\n", "\n", "N9\n", "\n", "RemoteData (9)\n", "@localhost\n", "\n", "\n", "\n", "N8->N9\n", "\n", "\n", "CREATE\n", "remote_folder\n", "\n", "\n", "\n", "N1\n", "\n", "Code (1)\n", "mock_crystal17@localhost\n", "\n", "\n", "\n", "N1->N8\n", "\n", "\n", "INPUT_CALC\n", "code\n", "\n", "\n", "\n", "N7\n", "\n", "KindData (7)\n", "\n", "\n", "\n", "N7->N8\n", "\n", "\n", "INPUT_CALC\n", "kinds\n", "\n", "\n", "\n", "N6\n", "\n", "SymmetryData (6)\n", "symmops: 16\n", "\n", "\n", "\n", "N6->N8\n", "\n", "\n", "INPUT_CALC\n", "symmetry\n", "\n", "\n", "\n", "N5\n", "\n", "StructureData (5)\n", "Ni2O2\n", "\n", "\n", "\n", "N5->N8\n", "\n", "\n", "INPUT_CALC\n", "structure\n", "\n", "\n", "\n", "N4\n", "\n", "CryInputParamsData (4)\n", "\n", "\n", "\n", "N4->N8\n", "\n", "\n", "INPUT_CALC\n", "parameters\n", "\n", "\n", "\n", "N3\n", "\n", "BasisSetData (3)\n", "\n", "\n", "\n", "N3->N8\n", "\n", "\n", "INPUT_CALC\n", "basissets__O\n", "\n", "\n", "\n", "N2\n", "\n", "BasisSetData (2)\n", "\n", "\n", "\n", "N2->N8\n", "\n", "\n", "INPUT_CALC\n", "basissets__Ni\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "graph = Graph(graph_attr={'size': \"6,8!\", \"rankdir\": \"LR\"})\n", "graph.add_node(calc_node)\n", "graph.add_incoming(calc_node, annotate_links=\"both\")\n", "graph.add_outgoing(calc_node, annotate_links=\"both\")\n", "graph.graphviz" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'sealed': True,\n", " 'version': {'core': '1.0.0b5', 'plugin': '0.11.0'},\n", " 'withmpi': False,\n", " 'resources': {'num_machines': 1, 'num_mpiprocs_per_machine': 1},\n", " 'append_text': '',\n", " 'exit_status': 0,\n", " 'parser_name': 'crystal17.main',\n", " 'prepend_text': '',\n", " 'process_label': 'CryMainCalculation',\n", " 'process_state': 'finished',\n", " 'retrieve_list': ['main.out',\n", " 'fort.34',\n", " 'HESSOPT.DAT',\n", " '_scheduler-stdout.txt',\n", " '_scheduler-stderr.txt'],\n", " 'remote_workdir': '/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmp1kqvyzb3',\n", " 'input_file_name': 'INPUT',\n", " 'scheduler_stderr': '_scheduler-stderr.txt',\n", " 'scheduler_stdout': '_scheduler-stdout.txt',\n", " 'mpirun_extra_params': [],\n", " 'environment_variables': {},\n", " 'max_wallclock_seconds': 1800,\n", " 'output_main_file_name': 'main.out',\n", " 'import_sys_environment': True,\n", " 'retrieve_temporary_list': ['opt[ac][0-9][0-9][0-9]'],\n", " 'custom_scheduler_commands': ''}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "calc_node.attributes" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'immigrated': True,\n", " '_aiida_hash': 'e9ec40cc0cfee4e578e567c4087ecc9ca8d706e46f9adeb5380ee363de1fda99',\n", " 'immigration_func': 'aiida_crystal17.immigration.create_calcjob'}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "calc_node.extras" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "```json\n", "{\n", " \"units\": {\n", " \"angle\": \"degrees\",\n", " \"energy\": \"eV\",\n", " \"length\": \"angstrom\",\n", " \"conversion\": \"CODATA2014\"\n", " },\n", " \"energy\": -85125.876675219,\n", " \"errors\": [],\n", " \"header\": {\n", " \"crystal_version\": 17,\n", " \"crystal_subversion\": \"1.0.1\"\n", " },\n", " \"volume\": 42.49241208568,\n", " \"warnings\": [\n", " \"WARNING **** INT_SCREEN **** CELL PARAMETERS OPTIMIZATION ONLY\"\n", " ],\n", " \"calculation\": {\n", " \"n_ao\": 46,\n", " \"spin\": true,\n", " \"type\": \"unrestricted open shell\",\n", " \"n_atoms\": 4,\n", " \"n_shells\": 14,\n", " \"n_symops\": 16,\n", " \"n_core_el\": 40,\n", " \"n_electrons\": 72,\n", " \"n_kpoints_ibz\": 75,\n", " \"n_kpoints_gilat\": 75\n", " },\n", " \"energy_units\": \"eV\",\n", " \"parser_class\": \"CryMainParser\",\n", " \"parser_errors\": [],\n", " \"mulliken_spins\": [\n", " 3.234,\n", " -3.234,\n", " -0.172,\n", " 0.172\n", " ],\n", " \"opt_iterations\": 19,\n", " \"parser_version\": \"0.11.0\",\n", " \"scf_iterations\": 16,\n", " \"number_of_atoms\": 4,\n", " \"parser_warnings\": [],\n", " \"mulliken_charges\": [\n", " 0.363,\n", " 0.363,\n", " -0.363,\n", " -0.363\n", " ],\n", " \"parser_exceptions\": [],\n", " \"mulliken_electrons\": [\n", " 27.637,\n", " 27.637,\n", " 8.363,\n", " 8.363\n", " ],\n", " \"mulliken_spin_total\": 0.0,\n", " \"number_of_assymetric\": 4,\n", " \"execution_time_seconds\": 3018\n", "}\n", "```" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "display_json(calc_node.outputs.results.attributes)" ] } ], "metadata": { "celltoolbar": "Tags", "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 }