Compare the distribution of the instantaneous temperature estimator
to the theoretical distribution in the canonical ensemble,
Notes on how to do this:
SciPy’s scipy.optimize.leastsq() function finds a set of \(M\) parameters \(\{p_k\}_{1\leq k \leq M}\) that minimizes the square of the deviations of a fit function from the \(N\) data points \((x_i, y_i)\). The residual is
and the function that is minimized over all parameters is the sum of the squared residuals
The example shows how to fit a straight line, i.e. the fit function is simply
It has two parameters \(p_0, p_1\). The code only requires you to define the residual in the function errfunc()
You can write your own function fit_P_NVT() by using the following code as a template
# simple linear fitting with SciPy
import scipy.optimize
def fit_linear(x, y, pinitial):
"""Fit a straight line to the data in *x* and *y*.
The fitted function is ``y = m*x + t``.
:Arguments:
*x*
array of x values
*y*
array of y values
*pinitial*
initial guess [slope, offset] e.g. ``[1.0, 0.0]``; this
must always be a list
:Returns: Parameters ``[m, t]``
"""
def errfunc(p,x,y):
return y - (p[0]*x + p[1]) # residuals
p, msg = scipy.optimize.leastsq(errfunc, pinitial[:], args=(x, y))
print msg
return p
Before programming, think about the following:
Your output should be similar to the example below.
The figure below shows the output from 100 ps of NVT MD with a coupling time of 1 ps. The tempoerature was recorded every 0.5 ps and thus the histogram is rather jagged. Nevertheless, it agrees with the expected canonical distribution \(P(\mathcal{T})\) and a fit of the distribution to the histogrammed data recovers the average temperature over the simulation (309.9 K (fit) vs 310.6±8.9 K).
Distribution of instantaneous temperature from NVT simulation with Nosé-Hoover thermostat (coupling time 1 ps). Simulation cell with 506 TIP4P water molecules.
Extract the conserved quantity from the energy (EDR) file with g_energy and plot a time series. Is it conserved?
If you have time, also analyze the following:
timeseries for
Use g_energy (and possibly tools like grep or Python to extract data from log).
square of the fluctuations (i.e. the variance <(X-<X>)**2> for
histograms
self diffusion coefficient (g_msd)
radial pair distribution function between the oxygens (OW-OW)
To get the OW create an index file with make_ndx:
make_ndx -f md.tpr -o OW.ndx <<EOF
keep 0
del 0
a OW
q
EOF
Then run g_rdf with only on the selected OW atoms:
g_rdf -n OW.ndx -s md.tpr -f md.xtc -xvg none -o rdf.xvg
Plot rdf.xvg in matplotlib.
Integrate \(4\pi r g(r) dr\) to the first minimum: how many waters are in the first hydration shell?