Commit e2b2a7a5 authored by dmar's avatar dmar
Browse files

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[0],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
}
%% Cell type:code id: tags:
``` python
import numpy as np
import matplotlib.pyplot as plt
```
%% Cell type:markdown id: tags:
Compute correlation as:
$$ corr (t) = \int \dot{\mu}(\tau) \cdot \dot{\mu}(\tau + t) d \tau $$
$\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 id: tags:
``` python
# load file reading only the columns of the derivative and skipping the first 45 rows (~ thermalization)
D_dipole = np.loadtxt('dipolemet.traj',usecols = (4,5,6),skiprows=45,comments=' DIPOLE [Non Periodic](')
Nmax = 500
N = len(D_dipole)
timestep = 0.5 #fs
c_cm_s = 29979245800
corr_time = np.zeros(Nmax)
for tau in range(N-Nmax):
for t in range(tau,tau+Nmax):
corr_time[t-tau] = corr_time[t-tau] + np.dot(D_dipole[tau], D_dipole[t])
for t in range(Nmax):
corr_time[t] /= (N*(N-t))
```
%% Cell type:code id: tags:
``` python
fig = plt.plot(timestep*np.arange(Nmax),corr_time/corr_time[0],color='crimson', lw=2)
ax = plt.gca()
ax.set_xlabel('time')
ax.set_ylabel('correlation')
plt.savefig('METtime_corr', dpi=300,transparent=True)
```
%% Cell type:code id: tags:
``` python
#Fmax up to 4000 cm^-1
Fmax = int((2e-15*np.pi*timestep*c_cm_s)*N*(4000/(2*np.pi)))
corr_freq = np.zeros([Fmax])
freq = np.zeros([Fmax])
for i in range(Fmax):
omega = i*2*np.pi/N
for j in range(Nmax):
corr_freq[i] += np.cos(omega*j)*corr_time[j]
freq[i] = omega/(2e-15*np.pi*timestep*c_cm_s)
#corr_freq
```
%% Cell type:code id: tags:
``` python
fig = plt.plot(freq,corr_freq,color='crimson', lw=2)
ax = plt.gca()
ax.set_xlabel('frequency')
ax.set_ylabel('correlation')
plt.savefig('METfreq_corr', dpi=300,transparent=True)
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
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.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment