# Molecular Simulation/Molecular Dynamics of the Canonical and Isothermal-Isobaric Ensembles
## The Canonical and Isothermal-Isobaric Ensembles

An ensemble is a representation of various stated of the system in the thermodynamic equilibrium. The constraints operating in the system determined the type of ensemble.
A canonical ensemble represents the possible states of a system characterized by constant values of N, V, and T (constant volume and temperature). The energy of the microstates can fluctuate, giving a distribution of energies. In this ensemble, the system is in contact with a heat bath at a fixed temperature.
The isothermal–isobaric ensemble is a collection of systems characterized by the same values of N, P and T (constant temperature and constant pressure ensemble). This ensemble allows the volume and the energy to fluctuate, giving a distribution of energies and volume.This ensemble has Boltzmann-weighted configurations pressure of p, surrounded by a heat bath at temperature T.

## Thermostats/ Barostats

A thermostat is a modification of the equation of motion to generate a statistical ensemble at a constant temperature. The most used thermostats in molecular dynamics are the Langevin, Anderson, and Nosé–Hoover Thermostat.
The Langevin thermostat is a Stochastic thermostat that applies friction and random force to momenta.
The Andersen thermostat assigns velocity of random particle to new velocity from Maxwellian distribution. In this thermostat the system is couple to a heat bath to impose the desired temperature. The equations of motion are Hamiltonian with stochastic collision term.
In this stochastic thermostat, dynamics are not physical, for this is not more time-reversible or deterministic.
The Nose-Hoover thermostat allows to simulate a system which is in the NVT ensemble. The idea is to introduce a fictitious degree of freedom. This approach couples the dynamics to the heat bath through the system Hamiltonian. The Nose equation is reversible and deterministic, and able to represent the distribution sample equivalent to a canonical ensemble.
In barostats, similar to the temperature coupling, an additional term is added to the equations of motion that effect a pressure change. Two of the must used barostat are the Anderson thermostat and the Parrinello-Rahman barostat.

## Nose-Hoover thermostat derivation

In the Nose-Hoover thermostat the Hamiltonian have a fictitious degree of freedom for heat bath:
${\mathcal {H_{N}}}=\sum _{i=1}^{N}{\frac {\mathbf {p} _{i}^{2}}{2ms^{2}}}+\nu (r)+{\frac {p_{s}^{2}}{2Q}}+gk_{B}T\ln \left(s\right),$
Where:
$P_{s}$: is the momentum of the degree of freedom.
Q: is the effective mass
s: extended variable.
$gk_{B}T\ln \left(s\right)$ :is chosen to be the potential energy of the degree of freedom.
Equations of motion follow from Hamilton's equations.
${\operatorname {d} \!r_{i} \over \operatorname {d} \!t}={\partial H_{N} \over \partial p_{i}}={P_{i} \over ms^{2}}$ Velocities of the particles
${\operatorname {d} \!s \over \operatorname {d} \!t}={\partial H_{N} \over \partial p_{s}}={P_{s} \over Q}$ velocity of the "agent"
${\operatorname {d} \!p_{i} \over \operatorname {d} \!t}={\partial H_{N} \over \partial r_{i}}=-{\partial U(r) \over \partial r_{i}}=F_{i}$ Acceleration of the particle
${\displaystyle {\operatorname {d} \!p_{s} \over \operatorname {d} \!t}={\partial H_{N} \over \partial s}={1 \over s}\left(\sum _{i=1}^{N}{\frac {\mathbf {p} _{i}^{2}}{ms^{2}}}-gK_{B}T\right)}$ Acceleration on the agent