.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_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_dos.py: Phonon density of states from CASTEP force constants ====================================================== Run :class:`~aiida_pythonjob_ins.workflows.DosWorkChain` on quartz force constants (a CASTEP ``.castep_bin``), plot the density of states, and visualise the AiiDA provenance graph. .. GENERATED FROM PYTHON SOURCE LINES 10-13 Set up AiiDA ------------ A shared helper loads a temporary in-memory profile and a localhost Python code. .. GENERATED FROM PYTHON SOURCE LINES 13-20 .. 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 code = get_python_code() .. GENERATED FROM PYTHON SOURCE LINES 21-25 Run the DOS workflow -------------------- The workflow reads the force constants (a PythonJob), then samples a Monkhorst-Pack grid and computes the DOS with adaptive broadening. .. GENERATED FROM PYTHON SOURCE LINES 25-41 .. code-block:: Python from aiida.plugins import WorkflowFactory # Load via WorkflowFactory (direct imports like # `from aiida_pythonjob_ins.workflows import DosWorkChain` also work) DosWorkChain = WorkflowFactory("pythonjob_ins.dos") results, node = run_get_node( DosWorkChain, castep_file=orm.SinglefileData(example_data("quartz.castep_bin")), q_spacing=orm.Float(0.15), # MP-grid spacing (1/Angstrom) energy_spacing=orm.Float(1.0), # DOS bin width (meV) code=code, ) print(f"WorkChain finished OK: {node.is_finished_ok}") .. rst-class:: sphx-glr-script-out .. code-block:: none Written to /tmp/tmpphb2ho04/euphonic_object.json WorkChain finished OK: True .. GENERATED FROM PYTHON SOURCE LINES 42-45 Plot the density of states -------------------------- The output is a native AiiDA ``XyData`` (energy vs DOS). .. GENERATED FROM PYTHON SOURCE LINES 45-59 .. code-block:: Python import matplotlib.pyplot as plt 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("Quartz phonon DOS") fig.tight_layout() .. image-sg:: /auto_examples/images/sphx_glr_plot_dos_001.png :alt: Quartz phonon DOS :srcset: /auto_examples/images/sphx_glr_plot_dos_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 60-62 Provenance ---------- .. GENERATED FROM PYTHON SOURCE LINES 62-64 .. code-block:: Python show_provenance(node, title="DOS workflow provenance") .. image-sg:: /auto_examples/images/sphx_glr_plot_dos_002.png :alt: DOS workflow provenance :srcset: /auto_examples/images/sphx_glr_plot_dos_002.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 7.073 seconds) .. _sphx_glr_download_auto_examples_plot_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_dos.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_dos.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_dos.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_