.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples_generated/03-tutorials/phonons.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_examples_generated_03-tutorials_phonons.py: .. _phonons: =================================================== Phonon calculations with small displacement method =================================================== Simple example showing how to calculate the phonon dispersion for bulk aluminum using a 5x5x5 supercell within effective medium theory: .. GENERATED FROM PYTHON SOURCE LINES 12-19 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from ase.build import bulk from ase.calculators.emt import EMT from ase.phonons import Phonons .. GENERATED FROM PYTHON SOURCE LINES 20-21 Setup Al crystal .. GENERATED FROM PYTHON SOURCE LINES 21-23 .. code-block:: Python atoms = bulk('Al', 'fcc', a=4.05) .. GENERATED FROM PYTHON SOURCE LINES 24-25 Setup phonon calculation with EMT calculator .. GENERATED FROM PYTHON SOURCE LINES 25-35 .. code-block:: Python N = 5 ph = Phonons( atoms, EMT(), supercell=(N, N, N), use_mean_minimum_images=True, minimum_image_tol=1e-6, ) ph.run() .. GENERATED FROM PYTHON SOURCE LINES 36-37 Read forces and assemble the dynamical matrix .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python ph.read() ph.clean() .. rst-class:: sphx-glr-script-out .. code-block:: none 7 .. GENERATED FROM PYTHON SOURCE LINES 41-42 Set and plot phonon band-structure along specific path .. GENERATED FROM PYTHON SOURCE LINES 42-72 .. code-block:: Python path = atoms.cell.bandpath('GXULGK', npoints=100) bs = ph.get_band_structure(path) # Get phonon DoS dos = ph.get_dos(kpts=(20, 20, 20)).sample_grid(npts=100, width=1e-3) fig = plt.figure(figsize=(7, 4)) ax = fig.add_axes([0.12, 0.07, 0.67, 0.85]) # Plot phonon band structure and DoS emax = 0.035 bs.plot(ax=ax, emin=0.0, emax=emax) dosax = fig.add_axes([0.8, 0.07, 0.17, 0.85]) dosax.fill_between( dos.get_weights(), dos.get_energies(), y2=0, color='grey', edgecolor='k', lw=1, ) dosax.set_ylim(0, emax) dosax.set_yticks([]) dosax.set_xticks([]) dosax.set_xlabel('DoS', fontsize=18) plt.show() # fig.savefig('Al_phonon.png') .. image-sg:: /examples_generated/03-tutorials/images/sphx_glr_phonons_001.png :alt: phonons :srcset: /examples_generated/03-tutorials/images/sphx_glr_phonons_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none WARNING, 1 imaginary frequencies at q = ( 0.00, 0.00, 0.00) ; (omega_q = 5.742e-09*i) WARNING, 1 imaginary frequencies at q = ( 0.00, 0.00, 0.00) ; (omega_q = 5.742e-09*i) .. GENERATED FROM PYTHON SOURCE LINES 73-74 You can visualize the modes with the following script: .. GENERATED FROM PYTHON SOURCE LINES 74-94 .. code-block:: Python # Write modes for specific q-vector to trajectory file L = np.array(path.special_points['L']) ph.write_modes( L / 2.0, branches=[2], repeat=(8, 8, 8), kT=3e-4, center=True, ) # Optionally, generate gif animation # from ase.io.trajectory import Trajectory # from ase.io import write # Temporarily disabled due to matplotlib writer compatibility issue. # with Trajectory('phonon.mode.2.traj', 'r') as traj: # write('Al_mode.gif', traj, interval=50, # rotation='-36x,26.5y,-25z') .. _sphx_glr_download_examples_generated_03-tutorials_phonons.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: phonons.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: phonons.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: phonons.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_