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.

9. Metropolis Monte Carlo in the canonical ensemble (NVT-MC)

School of Engineering and Digital Sciences, Nazarbayev University

Track: core  ·  Prerequisites: Part I–II, Markov chains (engstoch)

This chapter builds and verifies the core algorithms for metropolis monte carlo in the canonical ensemble (nvt-mc) in plain Python and NumPy, checking every result against an exact statistical-mechanics limit or published benchmark.

9.1 Physical principles and governing equations

Metropolis Monte Carlo generates a Markov chain of configurations RN\mathbf{R}^N sampling the Boltzmann distribution π(RN)∝exp⁡(−βU(RN))\pi(\mathbf{R}^N) \propto \exp(-\beta U(\mathbf{R}^N)) by enforcing detailed balance:

Pacc(o→n)=min⁡ ⁣(1, exp⁡ ⁣[−β(Un−Uo)]).(9.1)P_{\text{acc}}(o \to n) = \min\!\left(1,\, \exp\!\left[-\beta (U_n - U_o)\right]\right). \tag{9.1}

Because only a single particle moves per trial, ΔU=Un−Uo\Delta U = U_n - U_o costs O(N)O(N) instead of O(N2)O(N^2). By ergodic equivalence, equilibrium averages ⟨U/N⟩\langle U/N \rangle and g(r)g(r) from NVTNVT-MC must match NVTNVT-MD identically!

9.2 Inside the algorithm

9.3 Checks

NVT-MC (acc=37.6%): <U/N> = -4.432 vs. NVT-MD: <U/N> = -4.356
<Figure size 1120x430 with 2 Axes>

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

9.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. Exact O(N)O(N) vs O(N2)O(N^2) energy difference: Verify lj_single_particle_energy matches full recomputation to <10−11<10^{-11}.

  2. Acceptance rate vs step size Δrmax⁡\Delta r_{\max}: Scan Δrmax⁡∈[0.05,0.50]\Delta r_{\max} \in [0.05, 0.50] and verify monotonic decrease in acceptance probability.

  3. Detailed balance check on 2-state system: Verify Metropolis sampling reproduces exact Boltzmann occupation ratios p2/p1=e−βΔEp_2/p_1 = e^{-\beta \Delta E}.

Worked solutions are provided in 09_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).