{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Phonon calculations with small displacement method\n\nSimple example showing how to calculate the phonon dispersion for bulk aluminum\nusing a 5x5x5 supercell within effective medium theory:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nfrom ase.build import bulk\nfrom ase.calculators.emt import EMT\nfrom ase.phonons import Phonons" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Setup Al crystal\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "atoms = bulk('Al', 'fcc', a=4.05)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Setup phonon calculation with EMT calculator\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "N = 5\nph = Phonons(\n atoms,\n EMT(),\n supercell=(N, N, N),\n use_mean_minimum_images=True,\n minimum_image_tol=1e-6,\n)\nph.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Read forces and assemble the dynamical matrix\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "ph.read()\nph.clean()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set and plot phonon band-structure along specific path\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "path = atoms.cell.bandpath('GXULGK', npoints=100)\nbs = ph.get_band_structure(path)\n\n# Get phonon DoS\ndos = ph.get_dos(kpts=(20, 20, 20)).sample_grid(npts=100, width=1e-3)\nfig = plt.figure(figsize=(7, 4))\nax = fig.add_axes([0.12, 0.07, 0.67, 0.85])\n\n# Plot phonon band structure and DoS\nemax = 0.035\nbs.plot(ax=ax, emin=0.0, emax=emax)\n\ndosax = fig.add_axes([0.8, 0.07, 0.17, 0.85])\ndosax.fill_between(\n dos.get_weights(),\n dos.get_energies(),\n y2=0,\n color='grey',\n edgecolor='k',\n lw=1,\n)\n\ndosax.set_ylim(0, emax)\ndosax.set_yticks([])\ndosax.set_xticks([])\ndosax.set_xlabel('DoS', fontsize=18)\nplt.show()\n\n# fig.savefig('Al_phonon.png')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can visualize the modes with the following script:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Write modes for specific q-vector to trajectory file\nL = np.array(path.special_points['L'])\nph.write_modes(\n L / 2.0,\n branches=[2],\n repeat=(8, 8, 8),\n kT=3e-4,\n center=True,\n)\n\n# Optionally, generate gif animation\n\n# from ase.io.trajectory import Trajectory\n# from ase.io import write\n\n# Temporarily disabled due to matplotlib writer compatibility issue.\n# with Trajectory('phonon.mode.2.traj', 'r') as traj:\n# write('Al_mode.gif', traj, interval=50,\n# rotation='-36x,26.5y,-25z')" ] } ], "metadata": { "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.14.5" } }, "nbformat": 4, "nbformat_minor": 0 }