Commit aaec79ae by psd

### Exercise 8

parent b95a4bfe
 { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "from ase import Atoms\n", "from ase.io import read,write\n", "from ase.visualize import view\n", "import nglview" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Tasks\n", "\n", "### Task 1\n", "\n", "Let's begin with some theory. The energy of system of atoms is:\n", "\n", "$H = \\sum_i p_i/2m_i + VR_i$.\n", "\n", "Expanding $V$ around equilibrium ($\\sum_i\\partial{V}/\\partial{R_i}=0$):\n", "\n", "$H = V_0 + \\frac{1}{2}\\sum_{ij} \\frac{\\partial{V}}{\\partial{R_i}\\partial{R_j}}\\Delta R_i\\Delta R_j$\n", "\n", "which, in matrix form reads:\n", "\n", "$H = V_0 + \\frac{1}{2}\\{P_{3N}\\}\\begin{bmatrix}{M_i}^{-1} &&\\\\ && \\\\ &&\\\\ \\end{bmatrix}\\{P_{3N}\\}^T + \n", "\\frac{1}{2}\\{\\Delta R_{3N}\\}\\begin{bmatrix}{k_{ij}} &&\\\\ && \\\\ &&\\\\ \\end{bmatrix}\\{\\Delta R_{3N}\\}^T$\n", "\n", "\n", "$H = V_0 + \\frac{1}{2}\\{P_i(\\sqrt{M_i})^{-1}\\}\\{P_i(\\sqrt{M_i})^{-1}\\}^T + \n", "\\frac{1}{2}\\{\\Delta R_i(\\sqrt{M_i})^{-1}\\}\\underbrace{\\begin{bmatrix}{k_{ij}(\\sqrt{M_iM_j})^{-1}} &&\\\\ && \\\\ &&\\\\ \\end{bmatrix}}_{\\text{Hessian matrix}}\\{\\Delta R_i(\\sqrt{M_i})^{-1}\\}^T$\n", "\n", "In the basis basis states of the Hessian matrix, the above equation can be written:\n", "\n", "\n", "$H = V_0 + \\frac{1}{2}\\{\\pi_i\\}\\{\\pi_i\\}^T + \n", "\\frac{1}{2}\\{\\delta\\rho_i\\}\\begin{bmatrix}{\\omega_i} &&\\\\ &\\ddots& \\\\ &&\\\\ \\end{bmatrix}\\{\\delta\\rho_i\\}^T$\n", "\n", "\n", "where ${\\delta\\rho_i},{\\pi_i}$ are the mass normalized position and momentum vectors. The above equation corresponds to a set of **uncoupled harmonic oscillators**:\n", "\n", "$\\boxed{H = V_0 + \\frac{1}{2}\\sum_{\\alpha} \\Big( \\frac{\\pi_{\\alpha}^2}{2} + \\frac{\\omega_{\\alpha}2}{2}\\rho_{\\alpha}^2 \\Big)}$\n", "\n", "The **molden** file contains the eigenvalues and eigenvectors of the Hessian matrix. The eigenvectros corresponds to the atomic displacements and the eigenvalues are the vibrational frequencies. Your task is to devise a method to display the vibrational modes, making use of the *vibr_displacements* and *atoms*(ase.Atoms object) returned by the function *read_molden*. \n", "\n", "For the purpose, complete the skeleton function *get_trajectory*, which is initialized in a cell below, and make use of the ase.Atoms class, which is initialized with a list of atomic elements and their respective coordinates. \n", "\n", "**Hint**: Write the equation of motion (Lagrangian) for the equation above and find the time evolution of the atoms for a given normal mode." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Task 2\n", "- Compare the vibrational frequencies of methanol with experiments (see paper) and the one of benzene with literature on the internet.\n", "- Which kind of modes will correspond to stretching of CH and CC bonds?\n", "- Try to animate some frequencies, and report the kind of mode corresponding to all peaks.\n", "- In the methanol case, you can compare the result you obtained with the one with better basis set and convergence. \n", "- Examine the differences between the file vib.c6h6.inp and the vib.c6h6.ref, and the difference in spectra. Discuss." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Funcitons:\n", "\n", "**read_molden(file):**\n", "\n", " input: \n", " file - molden filename\n", " return:\n", " atoms - ase.Atom object\n", " frequency - vibrational frequencies\n", " vibr_displacements - vibrational atomic displacements in Angstrom \n", " \n", "**get_trajectory(mode):**\n", "\n", " input:\n", " mode - mode number\n", " return:\n", " trajectory - trajectory of atomic displacements for specified mode " ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def read_molden(file):\n", " \n", " with open(file) as f:\n", " data = f.readlines()\n", "\n", " freq = []\n", " info_atoms = [] # element, x, y, z\n", " vibr_displacements = [] # [vibration_nr][coord]\n", "\n", " inten = []\n", "\n", "\n", " section = ''\n", " b2A=0.52917721067\n", " # Parse the datafile\n", " for line in data:\n", " line = line.strip()\n", "\n", " # Are we entering into a new section?\n", " if line[0] == '[':\n", " section = line.strip('[]').lower()\n", " continue\n", "\n", " if section == 'freq':\n", " freq.append(float(line))\n", "\n", " if section == 'fr-coord':\n", " el, x, y, z = line.split()\n", " info_atoms.append([el, float(x)*b2A, float(y)*b2A, float(z)*b2A])\n", "\n", " if section == 'fr-norm-coord':\n", " if line.startswith('vibration'):\n", " vibr_displacements.append([])\n", " continue\n", " coords = [float(x) for x in line.split()]\n", " vibr_displacements[-1].append(coords)\n", "\n", " if section == 'int':\n", " inten.append(float(line))\n", "\n", " vibr_displacements = np.asanyarray(vibr_displacements)\n", " info_atoms = np.asanyarray(info_atoms)\n", " atoms = Atoms(info_atoms[:,0], info_atoms[:,1:4])\n", "\n", " return atoms, freq, vibr_displacements" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def get_trajectory(mode):\n", " '''\n", " TODO: Solve the equation of motion and complete the missing ___ \n", " '''\n", " trajectory = []\n", " for time in time_arr:\n", " vibr_atoms = Atoms(a.get_chemical_symbols(), a.positions+'''___''')\n", " trajectory.append(vibr_atoms)\n", " return trajectory" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read molden file " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "file = \"./C6H6-VIBRATIONS-1.ref.mol\"\n", "a, freq, vibr_displacements = read_molden(file)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## View atoms at equilibrium" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e2d2a73120ff458f8f0a89ad84291be5", "version_major": 2, "version_minor": 0 }, "text/plain": [ "NGLWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "nglview.show_ase(a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot spectrum" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Text(0.5, 0, 'Energy [cm$^{-1}$]')" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlYAAAFKCAYAAADfWRFiAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAFhlJREFUeJzt3X+wZnddH/D3h10CDiALZFXIbthQQ8cMpZCukRkc3ArCJtZEW7DJ1ApKzdQaqaMyjaVNadrOVBy1g02lQShIlRB+ujDLRBQYaEeSbMoSCWnKJhCyJpLlVzAghNBP/3jOpg+Xu3uf3Xzv3ns3r9fMM/ec7/ne83yeT848+84553ludXcAAHjwHrbWBQAAnCwEKwCAQQQrAIBBBCsAgEEEKwCAQQQrAIBBBCsAgEEEKwCAQQQrAIBBNq/VE5966qm9Y8eOtXp6AICF3XDDDZ/r7q0rzVuzYLVjx47s27dvrZ4eAGBhVXX7IvNcCgQAGESwAgAYRLACABhEsAIAGESwAgAYRLACABhEsAIAGGTFYFVVr6+qu6vq40fYXlX16qo6UFU3VtXZ48sEAFj/Fjlj9YYku4+y/dwkZ06Pi5P87oMvCwBg41kxWHX3h5J84ShTLkjy+z3zkSRbquqJowoEANgoRtxjdVqSO+bWD05jAAAPKSOCVS0z1stOrLq4qvZV1b5Dhw4NeOq1sWvXrmzZsiW7du3aMHXs2rXriPOOtu3B2LJlS7Zs2bJq+ztc99H6MPq/1XyvRr++Y6lh9PG3Wsf0WvUIWBuH30sOv5/ML6/1v5knyohgdTDJ9rn1bUnuXG5id1/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OZD1F1JTquqmhvbvmSf70ry9OnLN/9ekj84hlpOny4fAgwnWAGr7bokX55uUP+OqtpUVU+rqu8/wvw/S/LNJJdMN7JfkNklvAd099cy+0TeHya5rrs/cwy13JXkP1bVo6rqkVX17ON6VQDLEKyAY/HuJd9j9c6VfqG7v5nZTeDPSPKpJJ9L8ntJHnuE+fcl+ftJXprkS5ld6ntPkq8vmfrGJH8ri18GnK/le5N8JsnBzG58BxiivvU2BoD1p6quTfKa7v5vc2OnJ/nfSb6nu798lN/9Wmah7NXd/a9XvdijqKr3JXlWZmfZFroJHthYBCtg3amqH0pyS2Znt/5RktckeUp33zVtf1iS30rynd39s2tWKMASbuAE1qO/meTqzD6Bd2tm32Z+OFQ9KrNP6t2e2VctAKwbzlgBAAzi5nUAgEEEKwCAQQQrAIBBBCsAgEEEKwCAQQQrAIBBBCsAgEEEKwCAQQQrAIBBBCsAgEH+HzM1wXDKIRITAAAAAElFTkSuQmCC\n", "text/plain": [ "
 %% Cell type:code id: tags:  python import numpy as np import matplotlib.pyplot as plt from ase import Atoms from ase.io import read,write from ase.visualize import view import nglview  %% Cell type:markdown id: tags: ## Tasks ### Task 1 Let's begin with some theory. The energy of system of atoms is: $H = \sum_i p_i/2m_i + VR_i$. Expanding $V$ around equilibrium ($\sum_i\partial{V}/\partial{R_i}=0$): $H = V_0 + \frac{1}{2}\sum_{ij} \frac{\partial{V}}{\partial{R_i}\partial{R_j}}\Delta R_i\Delta R_j$ which, in matrix form reads: $H = V_0 + \frac{1}{2}\{P_{3N}\}\begin{bmatrix}{M_i}^{-1} &&\\ && \\ &&\\ \end{bmatrix}\{P_{3N}\}^T + \frac{1}{2}\{\Delta R_{3N}\}\begin{bmatrix}{k_{ij}} &&\\ && \\ &&\\ \end{bmatrix}\{\Delta R_{3N}\}^T$ $H = V_0 + \frac{1}{2}\{P_i(\sqrt{M_i})^{-1}\}\{P_i(\sqrt{M_i})^{-1}\}^T + \frac{1}{2}\{\Delta R_i(\sqrt{M_i})^{-1}\}\underbrace{\begin{bmatrix}{k_{ij}(\sqrt{M_iM_j})^{-1}} &&\\ && \\ &&\\ \end{bmatrix}}_{\text{Hessian matrix}}\{\Delta R_i(\sqrt{M_i})^{-1}\}^T$ In the basis basis states of the Hessian matrix, the above equation can be written: $H = V_0 + \frac{1}{2}\{\pi_i\}\{\pi_i\}^T + \frac{1}{2}\{\delta\rho_i\}\begin{bmatrix}{\omega_i} &&\\ &\ddots& \\ &&\\ \end{bmatrix}\{\delta\rho_i\}^T$ where ${\delta\rho_i},{\pi_i}$ are the mass normalized position and momentum vectors. The above equation corresponds to a set of **uncoupled harmonic oscillators**: $\boxed{H = V_0 + \frac{1}{2}\sum_{\alpha} \Big( \frac{\pi_{\alpha}^2}{2} + \frac{\omega_{\alpha}2}{2}\rho_{\alpha}^2 \Big)}$ The **molden** file contains the eigenvalues and eigenvectors of the Hessian matrix. The eigenvectros corresponds to the atomic displacements and the eigenvalues are the vibrational frequencies. Your task is to devise a method to display the vibrational modes, making use of the *vibr_displacements* and *atoms*(ase.Atoms object) returned by the function *read_molden*. For the purpose, complete the skeleton function *get_trajectory*, which is initialized in a cell below, and make use of the ase.Atoms class, which is initialized with a list of atomic elements and their respective coordinates. **Hint**: Write the equation of motion (Lagrangian) for the equation above and find the time evolution of the atoms for a given normal mode. %% Cell type:markdown id: tags: ### Task 2 - Compare the vibrational frequencies of methanol with experiments (see paper) and the one of benzene with literature on the internet. - Which kind of modes will correspond to stretching of CH and CC bonds? - Try to animate some frequencies, and report the kind of mode corresponding to all peaks. - In the methanol case, you can compare the result you obtained with the one with better basis set and convergence. - Examine the differences between the file vib.c6h6.inp and the vib.c6h6.ref, and the difference in spectra. Discuss. %% Cell type:markdown id: tags: ## Funcitons: **read_molden(file):** input: file - molden filename return: atoms - ase.Atom object frequency - vibrational frequencies vibr_displacements - vibrational atomic displacements in Angstrom **get_trajectory(mode):** input: mode - mode number return: trajectory - trajectory of atomic displacements for specified mode %% Cell type:code id: tags:  python def read_molden(file): with open(file) as f: data = f.readlines() freq = [] info_atoms = [] # element, x, y, z vibr_displacements = [] # [vibration_nr][coord] inten = [] section = '' b2A=0.52917721067 # Parse the datafile for line in data: line = line.strip() # Are we entering into a new section? if line[0] == '[': section = line.strip('[]').lower() continue if section == 'freq': freq.append(float(line)) if section == 'fr-coord': el, x, y, z = line.split() info_atoms.append([el, float(x)*b2A, float(y)*b2A, float(z)*b2A]) if section == 'fr-norm-coord': if line.startswith('vibration'): vibr_displacements.append([]) continue coords = [float(x) for x in line.split()] vibr_displacements[-1].append(coords) if section == 'int': inten.append(float(line)) vibr_displacements = np.asanyarray(vibr_displacements) info_atoms = np.asanyarray(info_atoms) atoms = Atoms(info_atoms[:,0], info_atoms[:,1:4]) return atoms, freq, vibr_displacements  %% Cell type:code id: tags:  python def get_trajectory(mode): ''' TODO: Solve the equation of motion and complete the missing ___ ''' trajectory = [] for time in time_arr: vibr_atoms = Atoms(a.get_chemical_symbols(), a.positions+'''___''') trajectory.append(vibr_atoms) return trajectory  %% Cell type:markdown id: tags: ## Read molden file %% Cell type:code id: tags:  python file = "./C6H6-VIBRATIONS-1.ref.mol" a, freq, vibr_displacements = read_molden(file)  %% Cell type:markdown id: tags: ## View atoms at equilibrium %% Cell type:code id: tags:  python nglview.show_ase(a)  %%%% Output: display_data %% Cell type:markdown id: tags: ## Plot spectrum %% Cell type:code id: tags:  python plt.figure(figsize=(10,5)) plt.vlines(freq,np.zeros(len(freq)),np.ones(len(freq))) plt.hlines(0,*plt.xlim()) plt.xlabel('Energy [cm$^{-1}$]',fontsize=12)  %%%% Output: execute_result Text(0.5, 0, 'Energy [cm$^{-1}$]') %%%% Output: display_data %% Cell type:markdown id: tags: ## Visualize vibrational mode %% Cell type:code id: tags:  python mode = 3 trajectory = get_trajectory(mode) nglv = nglview.show_asetraj(trajectory, gui=True) nglv  %%%% Output: display_data %%%% Output: display_data
 { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "from ase import Atoms\n", "from ase.io import read,write\n", "from ase.visualize import view\n", "import nglview" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Tasks\n", "\n", "### Task 1\n", "\n", "Let's begin with some theory. The energy of system of atoms is:\n", "\n", "$H = \\sum_i p_i/2m_i + VR_i$.\n", "\n", "Expanding $V$ around equilibrium ($\\sum_i\\partial{V}/\\partial{R_i}=0$):\n", "\n", "$H = V_0 + \\frac{1}{2}\\sum_{ij} \\frac{\\partial{V}}{\\partial{R_i}\\partial{R_j}}\\Delta R_i\\Delta R_j$\n", "\n", "which, in matrix form reads:\n", "\n", "$H = V_0 + \\frac{1}{2}\\{P_{3N}\\}\\begin{bmatrix}{M_i}^{-1} &&\\\\ && \\\\ &&\\\\ \\end{bmatrix}\\{P_{3N}\\}^T + \n", "\\frac{1}{2}\\{\\Delta R_{3N}\\}\\begin{bmatrix}{k_{ij}} &&\\\\ && \\\\ &&\\\\ \\end{bmatrix}\\{\\Delta R_{3N}\\}^T$\n", "\n", "\n", "$H = V_0 + \\frac{1}{2}\\{P_i(\\sqrt{M_i})^{-1}\\}\\{P_i(\\sqrt{M_i})^{-1}\\}^T + \n", "\\frac{1}{2}\\{\\Delta R_i(\\sqrt{M_i})^{-1}\\}\\underbrace{\\begin{bmatrix}{k_{ij}(\\sqrt{M_iM_j})^{-1}} &&\\\\ && \\\\ &&\\\\ \\end{bmatrix}}_{\\text{Hessian matrix}}\\{\\Delta R_i(\\sqrt{M_i})^{-1}\\}^T$\n", "\n", "In the basis basis states of the Hessian matrix, the above equation can be written:\n", "\n", "\n", "$H = V_0 + \\frac{1}{2}\\{\\pi_i\\}\\{\\pi_i\\}^T + \n", "\\frac{1}{2}\\{\\delta\\rho_i\\}\\begin{bmatrix}{\\omega_i} &&\\\\ &\\ddots& \\\\ &&\\\\ \\end{bmatrix}\\{\\delta\\rho_i\\}^T$\n", "\n", "\n", "where ${\\delta\\rho_i},{\\pi_i}$ are the mass normalized position and momentum vectors. The above equation corresponds to a set of **coupled harmonic hoscillators**:\n", "\n", "$\\boxed{H = V_0 + \\frac{1}{2}\\sum_{\\alpha} \\Big( \\frac{\\pi_{\\alpha}^2}{2} + \\frac{\\omega_{\\alpha}2}{2}\\rho_{\\alpha}^2 \\Big)}$\n", "\n", "The **molden** file contains the eigenvalues and eigenvectors of the Hessian matrix. The eigenvectros corresponds to the atomic displacements and the eigenvalues are the vibrational frequencies. Your task is to devise a method to display the vibrational modes, making use of the *vibr_displacements* and *atoms*(ase.Atoms object) return by the function *read_molden*. \n", "\n", "For the purpose, complete the skeleton function *get_trajectory*, which is initialized in a cell below, and make use of the ase.Atoms class, which is initialized with a list of atomic elements and their respective coordinates. \n", "\n", "**Hint**: Write the equation of motion (Lagrangian) for the equation above and find the time evolution of the atoms for a given normal mode." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Task 2\n", "- Compare the vibrational frequencies of methanol with experiments (see paper) and the one of benzene with literature on the internet.\n", "- Which kind of modes will correspond to stretching of CH and CC bonds?\n", "- Try to animate some frequencies, and report the kind of mode corresponding to all peaks.\n", "- In the methanol case, you can compare the result you obtained with the one with better basis set and convergence. \n", "- Examine the differences between the file vib.c6h6.inp and the vib.c6h6.ref, and the difference in spectra. Discuss." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Funcitons:\n", "\n", "**read_molden(file):**\n", "\n", " input: \n", " file - molden filename\n", " return:\n", " atoms - ase.Atom object\n", " frequency - vibrational frequencies\n", " vibr_displacements - vibrational atomic displacements in Angstrom \n", " \n", "**get_trajectory(mode):**\n", "\n", " input:\n", " mode - mode number\n", " return:\n", " trajectory - trajectory of atomic displacements for specified mode " ] }, { "cell_type": "code",