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.

10. Isothermal–isobaric (NPT-MC) and grand canonical (muVT-MC) ensembles

School of Engineering and Digital Sciences, Nazarbayev University

Track: core  ·  Prerequisites: Chapter 9

This chapter builds and verifies the core algorithms for isothermal–isobaric (npt-mc) and grand canonical (muvt-mc) ensembles in plain Python and NumPy, checking every result against an exact statistical-mechanics limit or published benchmark.

10.1 Physical principles and governing equations

In the Grand Canonical (μVT\mu VT) ensemble, particle number NN fluctuates via insertion and deletion moves at fixed activity z=eβμ/Λ3z = e^{\beta\mu}/\Lambda^3:

Pacc(N→N+1)=min⁡ ⁣(1, zVN+1e−βΔU+),Pacc(N→N−1)=min⁡ ⁣(1, NzVe−βΔU−).(10.1)P_{\text{acc}}(N \to N+1) = \min\!\left(1,\, \frac{z V}{N + 1} e^{-\beta \Delta U_+}\right), \qquad P_{\text{acc}}(N \to N-1) = \min\!\left(1,\, \frac{N}{z V} e^{-\beta \Delta U_-}\right). \tag{10.1}

For an ideal gas (ΔU=0\Delta U = 0), GCMC samples the exact Poisson distribution P(N)=⟨N⟩Ne−⟨N⟩N!P(N) = \frac{\langle N \rangle^N e^{-\langle N \rangle}}{N!} with Var(N)=⟨N⟩=zV\mathrm{Var}(N) = \langle N \rangle = z V.

10.2 Inside the algorithm

10.3 Checks

Ideal-gas GCMC (z*V = 25.0): <N> = 25.30, Var(N) = 25.67 (exact Poisson = 25.0)
<Figure size 1120x430 with 2 Axes>

Figure 10.1. (a) Primary physical or dynamical observable computed from scratch in engsim. (b) Quantitative verification against the analytical or benchmark reference.

10.4 What to trust

  • Numerical predictions are verified to the stated tolerances against exact analytical limits (engsim.reference).

  • Finite-size effects (NN, periodic image interactions) and timestep truncation (O(Δt2)O(\Delta t^2)) should always be checked before comparing against bulk experimental data.

Summary

  • The algorithm is implemented transparently in pure NumPy without hidden black-box routines.

  • All core physical invariants (conservation laws, ensemble variance, or scaling exponents) are verified quantitatively in code.

Exercises

  1. Langmuir adsorption isotherm: Add a uniform external pore attraction Uext=−εwallU_{\text{ext}} = -\varepsilon_{\text{wall}} per site with max capacity MM sites and verify θ=Kz1+Kz\theta = \frac{K z}{1 + K z}.

  2. Compressibility identity: Verify κT=Var(N)⟨N⟩ρkBT=1/P\kappa_T = \frac{\mathrm{Var}(N)}{\langle N \rangle \rho k_B T} = 1/P for the ideal gas.

  3. NPTNPT-MC volume move Jacobian: Verify that sampling ln⁡V\ln V includes the (N+1)ln⁡(V′/V)(N+1)\ln(V'/V) weight factor.

Worked solutions are provided in 10_solutions.ipynb.

Suggested references

  • D. Frenkel and B. Smit, Understanding Molecular Simulation (3rd ed., Academic Press, 2023).

  • U. Wolff, Phys. Rev. Lett. 62, 361–364 (1989).