Examples
This section collects minimal, self-contained scripts for the three standard mcpy workflows: canonical Monte Carlo, grand-canonical Monte Carlo, and replica-exchange GCMC.
Before browsing the individual examples, it is useful to recall the acceptance rules each workflow relies on and the thermodynamic definitions used downstream to build phase diagrams. The full derivations live in Ensembles and Calibrating species_radii; what follows is a quick reference.
Acceptance rules
GCMC insertion and deletion
Number-changing moves carry an extra de-Broglie factor relative to the Metropolis form:
Deletion \((N \rightarrow N-1)\):
Insertion \((N \rightarrow N+1)\):
with activity \(z = e^{\beta \mu}\) and thermal de Broglie wavelength \(\Lambda = h/\sqrt{2\pi m k_B T}\). The accessible free volume \(V_{\mathrm{free}}\) – estimated by the cell, with element-wise exclusion radii – replaces the geometric \(V\) of the textbook expressions (see Calibrating species_radii).
Phase diagrams from GCMC ensembles
For oxidation studies, the relevant thermodynamic potential is the oxygen-dependent formation Gibbs energy. For an Ag-O configuration of energy \(E\) containing \(n_{\mathrm{Ag}}\) silver and \(n_{\mathrm{O}}\) oxygen atoms,
where \(E_{\mathrm{ref}}\) is the energy of a reference clean Ag system (slab or nanoparticle). For surfaces, normalising by the slab area \(A\) yields the surface Gibbs energy
The oxygen chemical potential is varied to mimic a range of environmental conditions:
with \(\Delta \mu_{\mathrm{O}}(T)\) a tabulated temperature-dependent correction and \(p_0\) the reference pressure (typically 1 atm).
Plotting \(\Delta G\) (or \(\gamma\)) against \(\mu_{\mathrm{O}}\) for each candidate configuration produces the phase diagram; the lower envelope (convex hull) is the set of thermodynamically stable phases, and crossings between curves locate the phase transitions.