.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_phonopy_bands_and_dos.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_phonopy_bands_and_dos.py: Band structure and DOS from Phonopy input ============================================ Read force constants from **Phonopy** output (NaCl: ``phonopy.yaml`` + ``FORCE_CONSTANTS`` + ``BORN``) as a ``PythonJob``, then reuse the *same* :class:`~aiida_pythonjob_ins.workflows.DispersionWorkChain` and :class:`~aiida_pythonjob_ins.workflows.DosWorkChain` -- they accept a ``force_constants`` node, so nothing about them is CASTEP-specific. .. GENERATED FROM PYTHON SOURCE LINES 12-14 Set up AiiDA ------------ .. GENERATED FROM PYTHON SOURCE LINES 14-22 .. code-block:: Python from _aiida_setup import example_data, get_python_code, show_provenance from aiida import orm from aiida.engine import run_get_node from aiida_pythonjob import PythonJob code = get_python_code() .. GENERATED FROM PYTHON SOURCE LINES 23-26 Read force constants from Phonopy --------------------------------- A PythonJob stages the Phonopy files and returns a ``ForceConstantsData`` node. .. GENERATED FROM PYTHON SOURCE LINES 26-41 .. code-block:: Python from aiida_pythonjob_ins.pythonjobs import prepare_read_phonopy_inputs read_results, _ = run_get_node( PythonJob, **prepare_read_phonopy_inputs( summary=example_data("phonopy", "NaCl_default", "phonopy.yaml"), force_constants=example_data("phonopy", "NaCl_default", "FORCE_CONSTANTS"), born=example_data("phonopy", "NaCl_default", "BORN"), code=code, ), ) force_constants = read_results["result"] print(f"Force constants: {force_constants.get_force_constants().crystal.n_atoms} atoms") .. rst-class:: sphx-glr-script-out .. code-block:: none Written to /tmp/tmp31g5bnr8/euphonic_object.json Force constants: 8 atoms .. GENERATED FROM PYTHON SOURCE LINES 42-45 Band structure -------------- Feed the Phonopy-derived force constants straight into the dispersion workflow. .. GENERATED FROM PYTHON SOURCE LINES 45-61 .. code-block:: Python from aiida.plugins import WorkflowFactory # Load via WorkflowFactory (direct imports like # `from aiida_pythonjob_ins.workflows import ...` also work) DispersionWorkChain = WorkflowFactory("pythonjob_ins.dispersion") DosWorkChain = WorkflowFactory("pythonjob_ins.dos") bands_results, bands_node = run_get_node( DispersionWorkChain, force_constants=force_constants, q_spacing=orm.Float(0.1), code=code, ) bands_results["band_structure"].show_mpl() .. image-sg:: /auto_examples/images/sphx_glr_plot_phonopy_bands_and_dos_001.png :alt: plot phonopy bands and dos :srcset: /auto_examples/images/sphx_glr_plot_phonopy_bands_and_dos_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/aiida_pythonjob_ins/aiida_pythonjob_ins/.venv/lib/python3.12/site-packages/seekpath/getpaths.py:427: SupercellWarning: The provided cell is a supercell: the returned k-path is the standard k-path of the associated primitive cell in the basis of the supercell reciprocal lattice. warnings.warn( Written to /tmp/tmpq2cvb2mk/euphonic_object.json .. GENERATED FROM PYTHON SOURCE LINES 62-64 Density of states ----------------- .. GENERATED FROM PYTHON SOURCE LINES 64-86 .. code-block:: Python dos_results, _ = run_get_node( DosWorkChain, force_constants=force_constants, q_spacing=orm.Float(0.2), energy_spacing=orm.Float(1.0), code=code, ) import matplotlib.pyplot as plt dos = dos_results["dos"] _, energy, energy_unit = dos.get_x() ((_, density, dos_unit),) = dos.get_y() fig, ax = plt.subplots() ax.plot(energy, density) ax.set_xlabel(f"Energy ({energy_unit})") ax.set_ylabel(f"Density of states ({dos_unit})") ax.set_title("NaCl phonon DOS (from Phonopy)") fig.tight_layout() .. image-sg:: /auto_examples/images/sphx_glr_plot_phonopy_bands_and_dos_002.png :alt: NaCl phonon DOS (from Phonopy) :srcset: /auto_examples/images/sphx_glr_plot_phonopy_bands_and_dos_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 87-91 Provenance ---------- The graph traces the band structure back through the dispersion workflow to the Phonopy read job -- the full history in one picture. .. GENERATED FROM PYTHON SOURCE LINES 91-93 .. code-block:: Python show_provenance(bands_node, title="Phonopy -> dispersion provenance") .. image-sg:: /auto_examples/images/sphx_glr_plot_phonopy_bands_and_dos_003.png :alt: Phonopy -> dispersion provenance :srcset: /auto_examples/images/sphx_glr_plot_phonopy_bands_and_dos_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 9.967 seconds) .. _sphx_glr_download_auto_examples_plot_phonopy_bands_and_dos.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_phonopy_bands_and_dos.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_phonopy_bands_and_dos.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_phonopy_bands_and_dos.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_