### Exercise-9

parent aaec79ae
 { "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compute correlation as:\n", "$$corr (t) = \\int \\dot{\\mu}(\\tau) \\cdot \\dot{\\mu}(\\tau + t) d \\tau$$\n", " $\\tau$ will be an index that runs on all the simulation time. For every value of $\\tau$ $t$ varies and we compute the single integrand elements and sum (~integrate) it to $corr(t - \\tau)$ " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# load file reading only the columns of the derivative and skipping the first 45 rows (~ thermalization)\n", "\n", "D_dipole = np.loadtxt('dipolemet.traj',usecols = (4,5,6),skiprows=45,comments=' DIPOLE [Non Periodic](')\n", "Nmax = 500\n", "N = len(D_dipole)\n", "timestep = 0.5 #fs\n", "c_cm_s = 29979245800\n", "corr_time = np.zeros(Nmax)\n", "\n", "for tau in range(N-Nmax):\n", " for t in range(tau,tau+Nmax):\n", " corr_time[t-tau] = corr_time[t-tau] + np.dot(D_dipole[tau], D_dipole[t])\n", "\n", "for t in range(Nmax):\n", " corr_time[t] /= (N*(N-t))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plt.plot(timestep*np.arange(Nmax),corr_time/corr_time,color='crimson', lw=2)\n", "ax = plt.gca()\n", "ax.set_xlabel('time')\n", "ax.set_ylabel('correlation')\n", "plt.savefig('METtime_corr', dpi=300,transparent=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Fmax up to 4000 cm^-1\n", "Fmax = int((2e-15*np.pi*timestep*c_cm_s)*N*(4000/(2*np.pi)))\n", "corr_freq = np.zeros([Fmax])\n", "freq = np.zeros([Fmax])\n", "\n", "for i in range(Fmax):\n", " omega = i*2*np.pi/N\n", " for j in range(Nmax):\n", " corr_freq[i] += np.cos(omega*j)*corr_time[j] \n", " freq[i] = omega/(2e-15*np.pi*timestep*c_cm_s)\n", "#corr_freq" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "fig = plt.plot(freq,corr_freq,color='crimson', lw=2)\n", "ax = plt.gca()\n", "ax.set_xlabel('frequency')\n", "ax.set_ylabel('correlation')\n", "plt.savefig('METfreq_corr', dpi=300,transparent=True)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.7.0" } }, "nbformat": 4, "nbformat_minor": 2 }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!