{
"cells": [
{
"cell_type": "markdown",
"id": "22d177dc-6cfb-4de2-9509-f1eb45e10cf2",
"metadata": {},
"source": [
"# Elastic constants\n",
"\n",
"For the source code, see [elastic](https://workgraph-collections.readthedocs.io/en/latest/ase/espresso/module.html#workgraph_collections.ase.espresso.elastic.elastic_workgraph).\n",
"\n",
"## Example: Aluminum\n",
"\n",
"\n",
"### Prepare the inputs and submit the workflow\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "8ee799d2-0b5b-4609-957f-6b3f2cd451f0",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from ase.build import bulk\n",
"from aiida import load_profile\n",
"from workgraph_collections.ase.espresso.elastic import ElasticWorkgraph\n",
"from aiida_pythonjob.config import config\n",
"# allow pickle\n",
"config[\"allow_pickle\"] = True\n",
"\n",
"load_profile()\n",
"\n",
"# create input structure\n",
"atoms = bulk(\"Al\")\n",
"\n",
"\n",
"metadata = {\n",
" \"options\": {\n",
" 'prepend_text' : \"\"\"\n",
"eval \"$(conda shell.posix hook)\"\n",
"conda activate aiida\n",
"export OMP_NUM_THREADS=1\n",
"\"\"\",\n",
" }\n",
"}\n",
"\n",
"pseudopotentials = {\"Al\": \"Al.pbe-nl-rrkjus_psl.1.0.0.UPF\"}\n",
"pseudo_dir = \"/home/xing/data/ase/espresso_pseudo\"\n",
"# pseudo_dir = \"/home/wang_x3/datas/pseudos/psl\"\n",
"\n",
"# we need use high conv_thr to get accurate elastic constants\n",
"input_data = {\n",
" \"control\": {\"calculation\": \"relax\", \n",
" \"tstress\": True,\n",
" \"tprnfor\": True,\n",
" \"verbosity\": \"high\",\n",
" \"etot_conv_thr\": 1e-5,\n",
" \"forc_conv_thr\": 1.0e-5,\n",
" },\n",
" \"system\": {\"ecutwfc\": 40, \"ecutrho\": 320,\n",
" \"occupations\": \"smearing\",\n",
" \"smearing\": \"gaussian\",\n",
" \"degauss\": 0.01,\n",
" },\n",
" \"electrons\": {\"conv_thr\": 1e-11}\n",
"}\n",
"#------------------------- Set the inputs -------------------------\n",
"wg = ElasticWorkgraph.build_graph(atoms=atoms,\n",
" computer=\"localhost\",\n",
" command=\"mpirun -np 4 pw.x\",\n",
" pseudopotentials=pseudopotentials,\n",
" pseudo_dir=pseudo_dir,\n",
" input_data=input_data,\n",
" kpts=[25, 25, 25],\n",
" metadata=metadata)\n",
"wg.to_html()\n"
]
},
{
"cell_type": "markdown",
"id": "b5e184eb",
"metadata": {},
"source": [
"Run the calculation"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3d227bea",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"09/04/2025 07:04:36 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179694|WorkGraphEngine|continue_workgraph]: tasks ready to run: pw_calculator\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179694|WorkGraphEngine|continue_workgraph]: tasks ready to run: pw_calculator\n",
"09/04/2025 07:04:38 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179694|WorkGraphEngine|on_wait]: Process status: Waiting for child processes: 179698\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179694|WorkGraphEngine|on_wait]: Process status: Waiting for child processes: 179698\n",
"09/04/2025 07:04:41 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179694|WorkGraphEngine|update_task_state]: Task: pw_calculator, type: PYTHONJOB, finished.\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179694|WorkGraphEngine|update_task_state]: Task: pw_calculator, type: PYTHONJOB, finished.\n",
"09/04/2025 07:04:42 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179694|WorkGraphEngine|continue_workgraph]: tasks ready to run: get_deformed_structure_set\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179694|WorkGraphEngine|continue_workgraph]: tasks ready to run: get_deformed_structure_set\n",
"INFO:aiida_pythonjob.decorator:Executing process function, current stack status: 47 frames of 3000\n",
"09/04/2025 07:04:43 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179694|WorkGraphEngine|update_task_state]: Task: get_deformed_structure_set, type: PYFUNCTION, finished.\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179694|WorkGraphEngine|update_task_state]: Task: get_deformed_structure_set, type: PYFUNCTION, finished.\n",
"09/04/2025 07:04:43 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179694|WorkGraphEngine|continue_workgraph]: tasks ready to run: run_relaxation\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179694|WorkGraphEngine|continue_workgraph]: tasks ready to run: run_relaxation\n",
"09/04/2025 07:04:51 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179694|WorkGraphEngine|on_wait]: Process status: Waiting for child processes: 179749\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179694|WorkGraphEngine|on_wait]: Process status: Waiting for child processes: 179749\n",
"09/04/2025 07:04:57 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179749|WorkGraphEngine|continue_workgraph]: tasks ready to run: pw_calculator,pw_calculator1,pw_calculator2,pw_calculator3,pw_calculator4,pw_calculator5\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179749|WorkGraphEngine|continue_workgraph]: tasks ready to run: pw_calculator,pw_calculator1,pw_calculator2,pw_calculator3,pw_calculator4,pw_calculator5\n",
"09/04/2025 07:05:17 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179749|WorkGraphEngine|on_wait]: Process status: Waiting for child processes: 179753, 179766, 179779, 179792, 179805, 179818\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179749|WorkGraphEngine|on_wait]: Process status: Waiting for child processes: 179753, 179766, 179779, 179792, 179805, 179818\n",
"09/04/2025 07:05:24 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179749|WorkGraphEngine|update_task_state]: Task: pw_calculator, type: PYTHONJOB, finished.\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179749|WorkGraphEngine|update_task_state]: Task: pw_calculator, type: PYTHONJOB, finished.\n",
"09/04/2025 07:05:25 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179749|WorkGraphEngine|update_task_state]: Task: pw_calculator1, type: PYTHONJOB, finished.\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179749|WorkGraphEngine|update_task_state]: Task: pw_calculator1, type: PYTHONJOB, finished.\n",
"09/04/2025 07:05:25 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179749|WorkGraphEngine|update_task_state]: Task: pw_calculator2, type: PYTHONJOB, finished.\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179749|WorkGraphEngine|update_task_state]: Task: pw_calculator2, type: PYTHONJOB, finished.\n",
"09/04/2025 07:05:26 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179749|WorkGraphEngine|update_task_state]: Task: pw_calculator3, type: PYTHONJOB, finished.\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179749|WorkGraphEngine|update_task_state]: Task: pw_calculator3, type: PYTHONJOB, finished.\n",
"09/04/2025 07:05:27 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179749|WorkGraphEngine|update_task_state]: Task: pw_calculator4, type: PYTHONJOB, finished.\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179749|WorkGraphEngine|update_task_state]: Task: pw_calculator4, type: PYTHONJOB, finished.\n",
"09/04/2025 07:05:28 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179749|WorkGraphEngine|update_task_state]: Task: pw_calculator5, type: PYTHONJOB, finished.\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179749|WorkGraphEngine|update_task_state]: Task: pw_calculator5, type: PYTHONJOB, finished.\n",
"09/04/2025 07:05:33 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179749|WorkGraphEngine|continue_workgraph]: tasks ready to run: \n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179749|WorkGraphEngine|continue_workgraph]: tasks ready to run: \n",
"09/04/2025 07:05:34 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179749|WorkGraphEngine|finalize]: Finalize workgraph.\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179749|WorkGraphEngine|finalize]: Finalize workgraph.\n",
"09/04/2025 07:05:36 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179694|WorkGraphEngine|update_task_state]: Task: run_relaxation, type: GRAPH, finished.\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179694|WorkGraphEngine|update_task_state]: Task: run_relaxation, type: GRAPH, finished.\n",
"09/04/2025 07:05:38 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179694|WorkGraphEngine|continue_workgraph]: tasks ready to run: fit_elastic_constants\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179694|WorkGraphEngine|continue_workgraph]: tasks ready to run: fit_elastic_constants\n",
"INFO:aiida_pythonjob.decorator:Executing process function, current stack status: 47 frames of 3000\n",
"/home/xing/apps/miniforge3/envs/aiida/lib/python3.11/site-packages/pymatgen/analysis/elasticity/elastic.py:473: UserWarning: Pseudo-inverse fitting of Strain/Stress lists may yield questionable results from vasp data, use with caution.\n",
" warnings.warn(\n",
"09/04/2025 07:05:39 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179694|WorkGraphEngine|update_task_state]: Task: fit_elastic_constants, type: PYFUNCTION, finished.\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179694|WorkGraphEngine|update_task_state]: Task: fit_elastic_constants, type: PYFUNCTION, finished.\n",
"09/04/2025 07:05:40 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179694|WorkGraphEngine|continue_workgraph]: tasks ready to run: \n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179694|WorkGraphEngine|continue_workgraph]: tasks ready to run: \n",
"09/04/2025 07:05:40 AM <526049> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179694|WorkGraphEngine|finalize]: Finalize workgraph.\n",
"REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179694|WorkGraphEngine|finalize]: Finalize workgraph.\n"
]
}
],
"source": [
"wg.run()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "e14c98b4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Elastic constants: \n",
"[[-109.87 -61.3 -61.3 -0. 4.25 -4.25]\n",
" [ -61.3 -109.87 -61.3 -4.25 0. 4.25]\n",
" [ -61.3 -61.3 -109.87 4.25 -4.25 0. ]\n",
" [ -0. -0. -0. -38.51 -0. -0. ]\n",
" [ -0. -0. -0. 0. -38.51 -0. ]\n",
" [ 0. 0. 0. -0. -0. -38.51]]\n"
]
}
],
"source": [
"#------------------------- Print the output -------------------------\n",
"import numpy as np\n",
"elastic_constants = wg.outputs.result.value.value\n",
"print(\"Elastic constants: \")\n",
"print(np.round(elastic_constants, 2))\n"
]
},
{
"cell_type": "markdown",
"id": "25e5a469",
"metadata": {},
"source": [
"The calcualted elastic constants of aluminum are C11=117.3 GPa, C12=57.6 GPa, and C44=38.1 GPa, compared to the values reported by [experiment](https://pubs.aip.org/aip/jap/article/35/6/1825/133322/Elastic-Constants-of-Aluminum): C11=116.3 GPa, C12=64.8 GPa, and C44=30.9 GPa."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "aiida",
"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.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}