Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Binder

Thermodynamic ensembles

Different macroscopic constraints lead to different types of ensembles, with particular statistical characteristics:

Statistical_Ensembles.png

Image by Nzjacobmartin - Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=61475757

\textbf{Microcanonical ensemble (or NVE ensemble):} The total energy of the system, its volume and the number of particles in the system are each fixed to particular values.

Change1.png

\textbf{Canonical ensemble (or NVT ensemble):} The energy is not known exactly but the number of particles is fixed. In place of the energy, the temperature T0T_0 is specified. The system is in weak thermal contact with other systems that are described by ensembles with the same temperature (heat bath).

Change2.png

\textbf{Isobaric-isothermal ensemble (or NPT ensemble):} The energy and volume are not known exactly but the number of particles is fixed. In place of the energy, the temperature T0T_0 is specified; in place of the volume, the pressure P0P_0 is specified. The system is in contact with a heat bath, as well as a “pressure bath”.

Thermodynamic results can be transformed between ensembles only for infinitely large systems (in the thermodynamic limit). For finite systems, it is therefore desirably to directly sample in the ensemble of interest:

  • Constant temperature: Explore behavior of system as a function of temperature (unfolding of a protein, glass formation), simulated annealing (gradual reduction of the temperature), etc

  • Constant temperature and pressure: Modeling of ambient conditions, where the pressure is also constant (which is true for most lab experiments)

What does constant temperature (or pressure) mean?

Temperature: On the molecular level, the temperature of a system is defined by the average kinetic energy of all the particles (atoms, molecules) that make up the system.

Statistical mechanical point of view: Impose a temperature on a system by bringing it into thermal contact with a large heat bath.

Then, the probability of finding the system in a given energy state is given by the Boltzmann distribution and the velocities are described by the Maxwell-Boltzmann distribution. Thus, the particles won’t all have the same velocity but the velocities will follow a distribution that depends on their mass and the temperature of the system.

Boltzmann.png

Important! Constant temperature ≠\neq kinetic energy per particle is constant

I.e. the relative variance of the kinetic energy per particle in a canonical ensemble is NOT zero, and the instantaneous temperature (obtained via the kinetic energy per particle) fluctuates with a magnitude given by the heat capacity.

Velocity-rescaling (1971)

The temperature is related to the total kinetic energy:

32NkBT=Ek=12∑ivi2\frac{3}{2}Nk_BT = E_k = \frac{1}{2} \sum_i v_i^2

To alter the temperature T(t)T(t) at timestep tt, we can therefore scale the velocities by a factor λ\lambda, which yields the change in temperature ΔT=T0−T(t)\Delta T=T_0-T(t):

ΔT=∑i(λvi)23NkB−∑ivi23NkB=(λ2−1)T(t)\Delta T = \frac{\sum_i (\lambda v_i)^2}{3Nk_B} - \frac{\sum_i v_i^2}{3Nk_B} = (\lambda^2-1)T(t)

To change the current temperature to a desired temperature, we can therefore multiply the velocities at each time step by λ=T0/T(t)\lambda= \sqrt{T_0/T(t)}\[0.5cm]

Advantages

  • Simple, easy to understand

  • Straightforward to implement

Disadvantages

  • Discontinuities in the momentum part of the phase space trajectory

  • T(t)T(t) cannot fluctuate

  • Does not generate rigorous canonical averages

  • Artificially prolongs any temperature differences among the components of the system (since only the average temperature is controlled)

Berendsen thermostat (1984)

Couple the system to an external heat bath that is fixed to a desired temperature, which supplies or removes heat from the system. At each timestep, scale the velocities such that the rate of temperature change is proportional to the difference in temperature between the bath and the system:

dT(t)dt=1τ(T0−T(t))\frac{\mathrm{d}T(t)}{\mathrm{d} t} = \frac{1}{\tau}(T_0 - T(t))

with the coupling parameter τ\tau (strong coupling for small τ\tau). For one timestep, we therefore get

ΔT=Δtτ(T0−T(t))\Delta T = \frac{\Delta t}{\tau}(T_0- T(t))

with the scaling factor

λ=1+Δtτ(T0T(t)−1)\lambda = \sqrt{1+\frac{\Delta t}{\tau}\left(\frac{T_0}{T(t)} -1 \right) }

Small τ≃Δt\tau \simeq \Delta t: Berendsen = velocity-rescaling! Usually: 0.4ps for 1fs timestep (τ≃400Δt\tau\simeq 400 \Delta t)

Advantages

  • Simple, easy to understand

  • Straightforward to implement

  • Much smaller discontinuities in the momentum part of the phase space trajectory than velocity-rescaling

  • T(t)T(t) can fluctuate (depending on the value of τ\tau)

Disadvantages

  • Does not generate rigorous canonical averages

  • Artificially prolongs any temperature differences among the components of the system (since only the average temperature is controlled)

Stochastic rescaling (2007)

Extension of velocity-rescaling: Reformulate velocity-rescaling in terms of kinetic energy (instead of temperature):

λ=T0/T(t)=Ek,0/Ek(t)\lambda = \sqrt{T_0/T(t)} = \sqrt{E_{k,0} / E_k(t)}

Instead of forcing Ek(t)E_k(t) to be exactly Ek,0E_{k,0}, the target value Ek,tE_{k,t} is selected stochastically from the canonical equilibrium distribution of the kinetic energy

P(Ek,t)=Ek,tf/2−1eEk,t/(kBT)P(E_{k,t}) = E_{k,t}^{f/2-1} e^{E_{k,t}/(k_BT)}

with ff being the nummber of degrees of freedom. The same procedure can be applied to the Berendsen thermostat which yields a smoother trajectory than the formulation above.

Advantages

  • Simple, easy to understand

  • Straightforward to implement

  • Generates correct canonical averages

  • T(t)T(t) can fluctuate

Disadvantages

  • Stochastic, i.e. trajectories cannot be reproduced exactly

Andersen thermostat (1980)

Stochastic collisions method where a particle is randomly chosen at intervals and its velocity reassigned by random selection from the Maxwell-Boltzmann distribution.

This is equivalent to a heat bath that randomly emits particles that collide with atoms of the system. Between each collision, the system is simulated with constant energy, so that we obtain a series of short NVE simulations (actually, a Markov chain).\[0.5cm]

The mean rate of collisions ν\nu determines the strength of the coupling to the heat bath, where successive collisions occur at time intervals of the Poisson distribution

P(t,ν)=νe−νtP(t,\nu) = \nu e^{-\nu t}

where P(t,ν)dtP(t,\nu)\mathrm{d}t is the probability that the next collision will take place between tt and t+dtt+\mathrm{d}t. For one timestep, the probability of a collision is therefore νΔt\nu\Delta t. A too low ν\nu causes the system to not sample from a canonical distribution. A too high ν\nu leads to too little fluctuations in TT.

Advantages

  • Generates correct canonical averages

Disadvantages

  • Dynamic properties cannot be computed correctly, since the dynamics is not physical (randomly decorrelates velocities)

Nos'e-Hoover thermostat (1985)

Make the thermal reservoir an integral part of the system by introducing an additional degree of freedom, ss, with additional, artificial coordinates and velocities. The states of the simulated extended system (coordinates ri\mathbf{r}_i, momenta pi\mathbf{p}_i, time tt) correspond to the states of the real system (ri′\mathbf{r}_i', pi′\mathbf{p}_i', time t′t'):

ri′=ri,pi′=pi/s,t′=∫0t1sdt\mathbf{r}_i' = \mathbf{r}_i, \quad \mathbf{p}_i' = \mathbf{p}_i/s, \quad t' = \int_0^t\frac{1}{s}\mathrm{d}t

Total energy then gets two additional terms:

  • Potential energy of the reservoir: (f+1)kBT0lns(f+1)k_BT_0\mathrm{ln}s where ff is the degrees of freedom of the physical system

  • Kinetic energy of the reservoir: Q2(dsdt)2\frac{Q}{2}\left( \frac{\mathrm{d}s}{\mathrm{d}t}\right)^2 with QQ being the fictitious mass of the extra degree of freedom (QQ therefore influences the strength of the coupling).

We then simulate in the microcanonical ensemble for the extended system (which produces the canonical ensemble in the physical system). The real velocity is vi′=dri′dt′=sdridt\mathbf{v}_i' = \frac{\mathrm{d}\mathbf{r}_i'}{\mathrm{dt'}} = s\frac{\mathrm{d}\mathbf{r}_i}{\mathrm{dt}} . We can thus think of the transformation as a timescaling by dt′=dt/s\mathrm{d}t' = \mathrm{d}t/s

Advantages

  • Generates correct canonical averages

  • One of the most accurate and efficient methods for constant-temperature MD

Disadvantages

  • Difficult to understand

  • More difficult to implement than other thermostats

  • ss can change, so that regular time intervals in the extended system correspond to a trajectory of the real system with unevenly spaced time intervals (but there is a method to arrive at evenly spaced intervals). The time evolution of ss depends on QQ.

  • Only correct if there is no external force, and the center of mass remains fixed. Possible remedy: A chain of thermostats (Nos'e-Hoover chains with different masses)

  • Can exhibit non-ergodic or oscillatory behavior. Possible remedy: A chain of thermostats (Nos'e-Hoover chains with different masses)

Langevin dynamics

Temperature is roughly regulated through the addition of friction and random forces (simulates interaction with an artificial solvent) to the equations of motion. The friction coefficient γ\gamma determines how strong the system is coupled to the heat bath.

ma=F−mγv+Rm\mathbf{a} = \mathbf{F} - m\gamma\mathbf{v} + \mathbf{R}
  • Friction term mγvm\gamma\mathbf{v} removes energy (like the frictional drag of the system moving through a solvent)

  • Random term R\mathbf{R} adds energy (like collisions/interactions with solvent molecules)

Advantages

  • Allows for large timesteps

Disadvantages

  • Not deterministic

  • Changes dynamics (usually slows down dynamics)

Overview of thermostats

The optimal choice of thermostats depends on the properties of interest, as well as the details of the system:

aichem27.jpg

Let us simulate a box of water using the program OpenMM, once with the Langevin thermostat, and once with the Nose-Hover thermostat to showcase this behavior:

Equilibrating
#"Progress (%)","Step","Potential Energy (kJ/mole)","Kinetic Energy (kJ/mole)","Total Energy (kJ/mole)","Temperature (K)","Box Volume (nm^3)"
3.3%,1000,-21915.86144357429,2953.9852416909616,-18961.87620188333,236.6185559637884,14.987010811375008
6.7%,2000,-21108.04408412681,3392.2927629979495,-17715.75132112886,271.7276321013383,14.987010811375008
10.0%,3000,-20109.145325715403,3517.2108088478426,-16591.93451686756,281.73375102355067,14.987010811375008
13.3%,4000,-20050.41467624412,4053.375521690679,-15997.03915455344,324.6813319122719,14.987010811375008
16.7%,5000,-20182.068822915415,3783.2526472612835,-16398.81617565413,303.0440929788494,14.987010811375008
Running NVT
20.0%,6000,-20345.973748738626,3683.063566955424,-16662.9101817832,295.0188005126818,14.987010811375008
23.3%,7000,-20019.561744983057,3698.93225383864,-16320.629491144417,296.289905636145,14.987010811375008
26.7%,8000,-20030.01718669639,3948.4771765888427,-16081.540010107547,316.27882042010907,14.987010811375008
30.0%,9000,-20166.954561765055,3800.9934503198524,-16365.961111445202,304.4651573572731,14.987010811375008
33.3%,10000,-20187.773235375742,3712.50218327944,-16475.2710520963,297.37687691260766,14.987010811375008
36.7%,11000,-19936.954308564524,3740.6785421934956,-16196.275766371029,299.633844640295,14.987010811375008
40.0%,12000,-19971.06149631248,3705.7843981856513,-16265.277098126828,296.83877246112525,14.987010811375008
43.3%,13000,-20196.056354577402,3758.0441753393116,-16438.01217923809,301.0248573577478,14.987010811375008
46.7%,14000,-19888.23872380958,3795.750525840319,-16092.488197969262,304.0451914069137,14.987010811375008
50.0%,15000,-20108.125117833475,3900.965731419714,-16207.159386413761,312.4730838886576,14.987010811375008
53.3%,16000,-20118.118242795328,3727.18865791409,-16390.92958488124,298.5532850988112,14.987010811375008
56.7%,17000,-20066.597112710337,3687.492672949164,-16379.104439761173,295.37357840718795,14.987010811375008
60.0%,18000,-19983.389431054453,3761.424762665606,-16221.964668388846,301.2956473671791,14.987010811375008
63.3%,19000,-20118.227408463816,3788.556976338331,-16329.670432125484,303.46897752764596,14.987010811375008
66.7%,20000,-20186.002384240488,3698.306295460541,-16487.696088779947,296.23976545080194,14.987010811375008
70.0%,21000,-19958.37157827125,3768.5319615008434,-16189.839616770407,301.86494443122893,14.987010811375008
73.3%,22000,-20086.425015981058,3851.3351253062297,-16235.089890674828,308.49759945344834,14.987010811375008
76.7%,23000,-20137.84334378944,3699.928279449063,-16437.915064340374,296.36968875026326,14.987010811375008
80.0%,24000,-20039.43177610145,3746.2442652080554,-16293.187510893395,300.07966722735904,14.987010811375008
83.3%,25000,-19819.803997809748,3871.1879089772624,-15948.616088832485,310.08783658050055,14.987010811375008
86.7%,26000,-20078.28833060966,3805.7006233945253,-16272.587707215134,304.8422088333201,14.987010811375008
90.0%,27000,-20134.101218755106,3723.6907499572303,-16410.410468797876,298.27309753457934,14.987010811375008
93.3%,28000,-20095.071959073404,3769.3544146293807,-16325.717544444024,301.9308241346465,14.987010811375008
96.7%,29000,-19996.467303807596,3913.9911146055906,-16082.476189202005,313.51643621040205,14.987010811375008
100.0%,30000,-20199.194108540873,3794.2255759150826,-16404.96853262579,303.9230406784219,14.987010811375008
<>:22: SyntaxWarning: invalid escape sequence '\c'
<>:22: SyntaxWarning: invalid escape sequence '\c'
/tmp/ipykernel_87/1112675260.py:22: SyntaxWarning: invalid escape sequence '\c'
  plt.title("Diffusion coefficient = "+str(np.round(D, 2))+"$\cdot 10^{-9}$ m$^2$/s")
/opt/conda/lib/python3.12/site-packages/MDAnalysis/coordinates/DCD.py:171: DeprecationWarning: DCDReader currently makes independent timesteps by copying self.ts while other readers update self.ts inplace. This behavior will be changed in 3.0 to be the same as other readers. Read more at https://github.com/MDAnalysis/mdanalysis/issues/3889 to learn if this change in behavior might affect you.
  warnings.warn("DCDReader currently makes independent timesteps"
  0%|          | 0/501 [00:00<?, ?it/s]
100%|██████████| 501/501 [00:00<00:00, 5413.51it/s]

<Figure size 640x480 with 1 Axes>

Exercise: Repeat the simulation but choose the “LangevinIntegrator” instead of the “NoseHooverIntegrator”. Use the same settings for temperature, frictionCoeff, and time_step as above. Compute the diffusion coefficient. Do you still get the correct value? Why/why not?

Constant pressure

A macroscopic system maintains constant pressure by changing its volume. Similarly, a simulation maintains constant pressure by changing the volume of the simulation cell.

The magnitude of volume fluctuations is related to the isothermal compressibility κ\kappa, where an easily compressible substance undergoes larger pressure fluctuations (similar to the heat capacity being related to energy fluctuations).

κ=1kBT⟨V2⟩−⟨V⟩2⟨V2⟩\kappa = \frac{1}{k_BT}\frac{\langle V^2\rangle - \langle V\rangle^2 }{\langle V^2\rangle}

Important: The magnitude of volume fluctuations >>>> magnitude of temperature fluctuations:

  • Ideal gas (κ≃1\kappa \simeq 1atm−1^{-1}), simulation in a cube with L=2L=2nm (V=8V=8nm3^3) at 300K, the fluctuation in the volume is 18.1nm3^3 (fluctuation in the cell length of L=2.6L=2.6~nm)! This is therefore not an appropriate simulation size!

  • Water (κ≃44.7510−6\kappa \simeq 44.75 10^{-6}atm−1^{-1}), simulation in a cube with L=2L=2nm (V=8V=8~nm3^3) at 300K, the fluctuation in the volume is 0.121nm3^3 (fluctuation in the cell length of L=0.49L=0.49nm)

Many barostats work very similar to the thermostats already discussed:

  • Volume-scaling (not exactly NPT)

  • Berendsen-barostat 1984 (not exactly NPT): Coupling to “pressure bath”,

    dP(t)dt=1τP(P0−P(t))\frac{\mathrm{d}P(t)}{\mathrm{d} t} = \frac{1}{\tau_P}(P_0 - P(t))

    with the coupling parameter τP\tau_P (strong coupling for small τP\tau_P), which determines the scaling factor λ\lambda scaling the volume and thus the atomic coordinates as ri′=λ1/3ri\mathbf{r}_i' = \lambda^{1/3}\mathbf{r}_i

  • Stochastic-cell rescaling 2020: Like Berendsen, but additional stochastic term for the rescaling factor that causes the local pressure fluctuations to be correct for the NPT ensemble.

  • Andersen 1980/Nos'e-Hoover 1986 barostat: Add extra degree of freedom corresponding to the volume of the box (similar to Nos'e-Hoover thermostat), with potential energy PVPV and kinetic energy of the piston of Q2(dVdt)2\frac{Q}{2}\left( \frac{\mathrm{d}V}{\mathrm{d}t}\right)^2 with QQ being the fictitious mass of the piston (small mass yields rapid oscillations). The coordinates in the extended system are then related to the real coordinates by ri′=V−1/3ri\mathbf{r}_i' = V^{-1/3}\mathbf{r}_i

  • Monte-Carlo barostat 2002: Generate a random volume change from a uniform distribution followed by evaluation of the potential energy of the trial system. The volume move is then accepted with the standard Monte-Carlo probability.

Let us use the MonteCarloBarostat in OpenMM and inspect the volume fluctuations:

Running NPT
#"Progress (%)","Step","Potential Energy (kJ/mole)","Kinetic Energy (kJ/mole)","Total Energy (kJ/mole)","Temperature (K)","Box Volume (nm^3)"
4.0%,1000,-20795.167932572054,3442.0231606970115,-17353.144771875042,275.7111099891022,14.843949395013055
8.0%,2000,-20423.28946864314,3644.7698254835104,-16778.519643159627,291.95141558412746,14.725763104944615
12.0%,3000,-20153.46510338817,3643.579853922632,-16509.88524946554,291.8560971145566,15.207290046477668
16.0%,4000,-20012.069276709426,3868.864214751588,-16143.205061957839,309.90170526053976,15.194201123864037
20.0%,5000,-20187.873791429018,3723.1321751186497,-16464.74161631037,298.22835486970837,15.400175523475088
24.0%,6000,-20193.07532984676,3660.895065772535,-16532.180264074224,293.24307101216004,15.260452589233404
28.0%,7000,-19994.030954344096,3598.429289278758,-16395.60166506534,288.2394705802725,15.241150173861472
32.0%,8000,-20231.65778322449,3648.416601372915,-16583.241181851576,292.2435276883777,15.208380213992807
36.0%,9000,-20288.8100335217,3890.135434535045,-16398.674598986654,311.6055612032556,15.207809766820588
40.0%,10000,-19856.820866783113,3759.22792317264,-16097.592943610473,301.11967729760204,15.552239623920231
44.0%,11000,-19972.98039196761,3766.353895791613,-16206.626496175995,301.6904781692996,15.255027002119295
48.0%,12000,-20014.177958165445,3637.6450521416996,-16376.532906023745,291.38071077629183,15.463284623669882
52.0%,13000,-20008.238336338247,3751.212801869998,-16257.025534468248,300.4776543105745,15.501850409097482
56.0%,14000,-20089.80743941509,3591.4299279026873,-16498.3775115124,287.6788114550676,15.2030994337011
60.0%,15000,-20296.127889647232,3743.5200086322666,-16552.607881014967,299.86145027490437,15.194416965890031
64.0%,16000,-20218.708351679335,3737.529255369611,-16481.179096309723,299.38158214078544,15.08431926546028
68.0%,17000,-20326.102088708183,3601.8001778145267,-16724.301910893657,288.50948370233937,15.205408273470077
72.0%,18000,-20233.565216762876,3598.5353630057734,-16635.029853757103,288.24796724158205,15.201118767582622
76.0%,19000,-20156.307961437236,3756.8551316015773,-16399.45282983566,300.9296132081733,15.47407484667433
80.0%,20000,-19889.606672482365,3817.23847709013,-16072.368195392235,305.76640785836764,15.415789136956214
84.0%,21000,-19845.388815207865,3830.401013400897,-16014.987801806968,306.8207463468334,15.492641617675655
88.0%,22000,-19885.90439520506,3819.579807839606,-16066.324587365454,305.9539518897852,15.431532604749872
92.0%,23000,-20006.358357301102,3792.7588052155374,-16213.599552085565,303.8055501913477,15.54141491056909
96.0%,24000,-20064.13486008051,3665.6720818701733,-16398.462778210338,293.62571701691525,15.1730174729274
100.0%,25000,-20018.55267057176,3725.1208183617036,-16293.431852210057,298.3876481139188,15.393122222582853
<Figure size 640x480 with 1 Axes>