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.

Open Systems

Grand Canonical Ensemble

  • Consider small system S S in thermal and particle exchange with a large reservoir R R .

  • The total system S+R S + R is isolated: total energy Etot=E+ER E_{\text{tot}} = E + E_R , total particle number Ntot=N+NR N_{\text{tot}} = N + N_R .

  • Total volume is constant, and the reservoir is much larger: EER E \ll E_R , NNR N \ll N_R .

<Figure size 700x600 with 1 Axes>

Grand Canonical Probability

  • The probability that the system has energy E E and particle number N N is proportional to the number of microstates of the reservoir with ER=EtotE E_R = E_{\text{tot}} - E , NR=NtotN N_R = N_{\text{tot}} - N :

P(E,N)ΩR(EtotE,NtotN)P(E, N) \propto \Omega_R(E_{\text{tot}} - E, N_{\text{tot}} - N)
  • Define entropy of the reservoir SR=kBlnΩR S_R = k_B \ln \Omega_R . Then:

lnΩR(ER,NR)=lnΩR(EtotE,NtotN)\ln \Omega_R(E_R, N_R) = \ln \Omega_R(E_{\text{tot}} - E, N_{\text{tot}} - N)
  • Expand to first order:

lnΩRlnΩR(Etot,Ntot)(SRER)NREkB(SRNR)ERNkB\ln \Omega_R \approx \ln \Omega_R(E_{\text{tot}}, N_{\text{tot}}) - \left( \frac{\partial S_R}{\partial E_R} \right)_{N_R} \frac{E}{k_B} - \left( \frac{\partial S_R}{\partial N_R} \right)_{E_R} \frac{N}{k_B}
  • Use thermodynamic definitions:

1T=(SRER)NR,μT=(SRNR)ER\frac{1}{T} = \left( \frac{\partial S_R}{\partial E_R} \right)_{N_R}, \quad \frac{\mu}{T} = -\left( \frac{\partial S_R}{\partial N_R} \right)_{E_R}
lnΩR(ER,NR)=constEkBT+μNkBT\ln \Omega_R(E_R, N_R) = \text{const} - \frac{E}{k_B T} + \frac{\mu N}{k_B T}
P(E,N)eβ(EμN)P(E, N) \propto e^{-\beta (E - \mu N)}

Grand Canonical Distribution and Partition Function

Define the grand canonical partition function:

Ξ=Nstates at Neβ(EμN)=NzNZN\Xi = \sum_N \sum_{\text{states at } N} e^{-\beta (E - \mu N)} = \sum_N z^N Z_N

where:

  • z=eβμ z = e^{\beta \mu} is called the fugacity.

  • ZN=states at fixed NeβE Z_N = \sum_{\text{states at fixed } N} e^{-\beta E} is the canonical partition function at fixed N N

  • The microstate probability in grand canonical ensemble is:

Pmicro(Ei,N)=eβ(EiμN)ΞP_{\text{micro}}(E_i, N) = \frac{e^{-\beta (E_i - \mu N)}}{\Xi}
  • The macrostate probability over different energy values in grand canonical ensemble is:

Pmacro(E,N)=Ω(E)eβ(EμN)ΞP_{\text{macro}}(E, N) = \frac{\Omega(E) e^{-\beta (E - \mu N)}}{\Xi}

Connections with NVENVE and NVTNVT

Each ensemble arises from a different choice of what the system exchanges with its surroundings. The table below summarizes how the three ensembles we have encountered so far are related:

PropertyNVENVE (Microcanonical)NVTNVT (Canonical)μVT\mu VT (Grand Canonical)
Fixed variablesN,V,EN, V, EN,V,TN, V, Tμ,V,T\mu, V, T
Fluctuating quantitiesEEE,NE, N
Exchange with reservoirNothing (isolated)EnergyEnergy + Particles
Partition functionΩ(E)\Omega(E)Z=eβEZ = \sum e^{-\beta E}Ξ=eβ(EμN)\Xi = \sum e^{-\beta(E - \mu N)}
Thermodynamic potentialS=kBlnΩS = k_B \ln \OmegaF=kBTlnZF = -k_BT \ln ZΨ=kBTlnΞ=PV\Psi = -k_BT \ln \Xi = -PV
Fluctuation-responseσE2=kBT2CV\sigma_E^2 = k_BT^2 C_VσN2=N2kBTκTV\sigma_N^2 = \frac{N^2 k_BT \kappa_T}{V}
  • Each successive ensemble is obtained by “opening up” one more variable: NVEallow E to fluctuateNVTallow N to fluctuateμVTNVE \xrightarrow{\text{allow } E \text{ to fluctuate}} NVT \xrightarrow{\text{allow } N \text{ to fluctuate}} \mu VT.

  • The corresponding partition function is a Laplace transform of the previous one, and the thermodynamic potential is related by a Legendre transform.

Statistical Dominance of Average Energy and Particle Number

  • Recall that the canonical ensemble emerges by weighting microcanonical contributions at different energies with an exponential factor eβE e^{-\beta E} .

  • Similarly, the grand canonical ensemble arises by further summing over all particle numbers N N , each weighted by the fugacity factor eβμN e^{\beta \mu N} . This yields the grand canonical partition function:

    Ξ(T,V,μ)=N=0[ieβEi]eβμN=N=0Z(N,V,T)eβμN\Xi(T, V, \mu) = \sum_{N=0}^{\infty} \left[ \sum_i e^{-\beta E_i} \right] e^{\beta \mu N} = \sum_{N=0}^{\infty} Z(N, V, T) \, e^{\beta \mu N}
  • In the thermodynamic limit, the sum is dominated by the most probable energy and particle number, giving:

    Ξeβ(FμNˉ)=eβ(EˉTSμNˉ)=eβΨ(T,V,μ)\Xi \approx e^{-\beta (F - \mu \bar{N})} = e^{-\beta (\bar{E} - T S - \mu \bar{N})} = e^{-\beta \Psi(T, V, \mu)}
  • We identify a new thermodynamic potential for the grand canonical ensemble that plays same role as free energy in canonical ensemble:

:class: - Unknown Directive
$$
  \Psi(T, V, \mu) = E - T S - \mu N
$$

Thermodynamics and Legendre transform

  • In thermodynamics grand potential Ψ \Psi is derived from the internal energy E(S,V,N) E(S, V, N) via a Legendre transform that replaces the natural variables ST S \to T and Nμ N \to \mu :

    E(S,V,N)E(ES)S(EN)N=ETSμNE(S, V, N) \rightarrow E - \left( \frac{\partial E}{\partial S} \right) S - \left( \frac{\partial E}{\partial N} \right) N = E - T S - \mu N

Grand Potential and Pressure

  • Using Euler’s relation for extensive thermodynamic variables:

    E=TS+PV+μNE = T S + P V + \mu N
  • Substituting into the definition of Ψ \Psi , we find:

    Ψ=ETSμN=PV\Psi = E - T S - \mu N = -P V
  • Hence, the grand potential is directly related to the pressure and volume:

    Ψ(T,V,μ)=PV{\Psi(T, V, \mu) = -P V}

Fluctuations in particle numbers

N=ipiNi=logΞ(βμ)\langle N \rangle = \sum_i p_i N_i = \frac{\partial \log \Xi}{\partial (\beta \mu)}
σN2=N2N2=2logΞ(βμ)2=N(βμ)\sigma_N^2 = \langle N^2 \rangle - \langle N \rangle^2 = \frac{\partial^2 \log \Xi}{\partial (\beta \mu)^2} = \frac{\partial \langle N \rangle}{\partial (\beta \mu)}
  • We once again find that the relative fluctuation of an extensive quantity scales as N1/2N^{-1/2}, a consequence of extensivity and the law of large numbers:

σNNO(N1/2)\frac{\sigma_N}{\langle N \rangle} \sim O(N^{-1/2})
  • Using thermodynamics we could also link number fluctuations with isothermal compressibility κT\kappa_T

κT=1VVp0\kappa_T = -\frac{1}{V} \frac{\partial V}{\partial p} \geq 0
  • The relationship is analogous to what we had established in NVTNVT between energy fluctuations and heat capacity.

σN2=N2kBTκTVO(N)\sigma_N^2 = \frac{N^2 k_B T \kappa_T}{V} \sim O(N)
  • It takes a bit more work manipulating variables to get there in this case. See below for derivation:

Intuition for Chemical Potential

  • In the canonical ensemble, temperature controls energy flow: energy flows from hot to cold until temperatures equalize. Chemical potential plays the exact same role for particle flow: particles flow from regions of high μ\mu to regions of low μ\mu until chemical potentials equalize across the system.

  • For an ideal gas, μ=kBTln(nλ3)\mu = k_BT \ln(n\lambda^3), which reveals two competing effects:

    • μ\mu increases with density nn: a crowded system has high chemical potential and tends to “push” particles out

    • μ\mu decreases with temperature TT (through λT1/2\lambda \propto T^{-1/2}): thermal agitation makes adding a particle less costly in free energy

  • In the classical regime (nλ31n\lambda^3 \ll 1), the chemical potential is always negative. This means adding a particle to a dilute gas at fixed TT and VV always lowers the free energy: the entropy gain from having more accessible states outweighs the (zero) interaction energy cost.

  • The chemical potential becomes zero and eventually positive only in the quantum regime (nλ31n\lambda^3 \gtrsim 1), where quantum statistics (Fermi-Dirac or Bose-Einstein) become important.

Source
import numpy as np
import matplotlib.pyplot as plt

n_lambda3 = np.linspace(0.001, 0.8, 500)  # classical regime n*lambda^3 << 1
mu_over_kT = np.log(n_lambda3)

fig, ax = plt.subplots(figsize=(7, 4))
ax.plot(n_lambda3, mu_over_kT, lw=2, color='steelblue')
ax.axhline(0, color='gray', ls='--', lw=1)
ax.fill_between(n_lambda3, mu_over_kT, 0, where=(n_lambda3 < 0.3), alpha=0.15, color='steelblue')
ax.set_xlabel(r'$n\lambda^3$ (dimensionless density)', fontsize=12)
ax.set_ylabel(r'$\mu / k_BT$', fontsize=12)
ax.set_title('Chemical Potential of Classical Ideal Gas', fontsize=14, weight='bold')
ax.annotate('Classical regime\n' + r'($n\lambda^3 \ll 1$, $\mu < 0$)',
            xy=(0.1, np.log(0.1)), fontsize=11,
            xytext=(0.4, -4), arrowprops=dict(arrowstyle='->', color='red', lw=1.5))
ax.annotate(r'$\mu = 0$ at $n\lambda^3 = 1$' + '\n(quantum degeneracy)',
            xy=(0.75, np.log(0.75)), fontsize=10,
            xytext=(0.4, -1), arrowprops=dict(arrowstyle='->', color='darkgreen', lw=1.5))
ax.grid(True, alpha=0.3)
ax.set_xlim(0, 0.8)
ax.set_ylim(-7, 0.5)
plt.tight_layout()
plt.show()
<Figure size 700x400 with 1 Axes>

Ideal Gas in the Grand Canonical Ensemble

  • We begin by considering an ideal gas of indistinguishable, non-interacting particles in a volume V V , in thermal and chemical equilibrium with a reservoir at temperature T T and chemical potential μ \mu .

  • The canonical partition function for N N particles is:

Z(T,V,N)=1N!(Vλ3)NZ(T, V, N) = \frac{1}{N!} \left( \frac{V}{\lambda^3} \right)^N
  • Where the thermal de Broglie wavelength is:

λ=h2πmkBT\lambda = \frac{h}{\sqrt{2 \pi m k_B T}}

Grand Canonical Partition Function

  • To account for fluctuations in particle number, we compute the grand canonical partition function:

Ξ(T,V,μ)=N=0Z(T,V,N)eβμN=N=01N!(eβμVλ3)N=exp(zVλ3)\Xi(T, V, \mu) = \sum_{N=0}^\infty Z(T, V, N)\, e^{\beta \mu N} = \sum_{N=0}^\infty \frac{1}{N!} \left( e^{\beta \mu} \frac{V}{\lambda^3} \right)^N = \exp\left( z \frac{V}{\lambda^3} \right)
  • Fugacity: z=eβμ z = e^{\beta \mu} , a dimensionless measure of how favorable it is to add a particle to the system.

  • The average particle number is then obtained by taking first derivative with respect to μ\mu

N=logΞ(βμ)=Vλ3eβμ=zVλ3\langle N \rangle = \frac{\partial \log \Xi}{\partial (\beta \mu)} = \frac{V}{\lambda^3} e^{\beta \mu} = z \frac{V}{\lambda^3}

Chemical Potential in Terms of Pressure and Density

  • We can invert the relation for N \langle N \rangle to express the chemical potential:

μ=kBTlog(Nλ3V)\mu = k_B T \log \left( \frac{N \lambda^3}{V} \right)
  • Noting that for an ideal gas p=NkBTV p = \frac{N k_B T}{V} , this becomes:

Number Fluctuations

  • In the grand canonical ensemble, number fluctuations are given by:

σN2=N2N2=N(βμ)=N=N\sigma_N^2 = \langle N^2 \rangle - \langle N \rangle^2 = \frac{\partial \langle N \rangle}{\partial (\beta \mu)} = \langle N \rangle = N
  • So the standard deviation σNN \sigma_N \sim \sqrt{N} , and relative fluctuations vanish as N1/2 N^{-1/2} in the thermodynamic limit.

Isothermal Compressibility

  • We relate number fluctuations to the isothermal compressibility κT \kappa_T :

σN2=N2kBTκTVκT=VN2kBTσN2=VNkBT=1p\sigma_N^2 = \frac{N^2 k_B T \kappa_T}{V} \quad \Rightarrow \quad \kappa_T = \frac{V}{N^2 k_B T} \cdot \sigma_N^2 = \frac{V}{N k_B T} = \frac{1}{p}
  • This is the well-known result for the ideal gas compressibility:

  • κT=1p0 \kappa_T = \frac{1}{p} \geq 0 , a positive quantity ensuring mechanical stability.

Molecular Adsorption of Ideal Gas on Surfaces

One Site–One Molecule Model

We consider a simple model where each adsorption site can hold at most one molecule. The surface is in thermal and chemical equilibrium with a gas reservoir at temperature T T and chemical potential μ \mu .

  • Each site has two possible states:

    • Empty: energy E=0 E = 0

    • Occupied: energy E=ϵ E = \epsilon

  • Then the grand partition function for a single site is:

Ξ=1+eβ(ϵμ)\Xi = 1 + e^{-\beta(\epsilon - \mu)}

N N Independent Sites

  • If there are N N independent and identical adsorption sites, then the total grand partition function is:

Ξtotal=ΞN=(1+eβ(ϵμ))N\Xi_{\text{total}} = \Xi^N = \left(1 + e^{-\beta(\epsilon - \mu)}\right)^N
  • Since the sites do not interact, their contributions multiply.

Average Number of Adsorbed Molecules

The average occupation number per site is:

n=1eβ(μϵ)+1\langle n \rangle = \frac{1}{e^{-\beta(\mu - \epsilon)} + 1}

The total number of adsorbed molecules is:

Nads=Nn=Neβ(μϵ)+1\langle N_{\text{ads}} \rangle = N \langle n \rangle = \frac{N}{e^{-\beta(\mu - \epsilon)} + 1}

Average Energy

The average energy per site is:

E=ϵn\langle E \rangle = \epsilon \langle n \rangle

The total energy of the system is:

Etotal=Nϵn\langle E_{\text{total}} \rangle = N \epsilon \langle n \rangle

Connecting to Pressure

  • For an ideal gas in the reservoir, the chemical potential is related to pressure via:

μ=kBTlog(pp0)\mu = k_B T \log \left( \frac{p}{p_0} \right)

where p0 p_0 is a reference pressure determined by the internal partition function of the gas.

  • Substituting this into the expression for n \langle n \rangle :

n=pp0eβϵ+p\langle n \rangle = \frac{p}{p_0 e^{\beta \epsilon} + p}
  • and thus the total number of adsorbed molecules becomes:

Nads=Npp0eβϵ+p\langle N_{\text{ads}} \rangle = N \cdot \frac{p}{p_0 e^{\beta \epsilon} + p}
  • This is the Langmuir adsorption isotherm, describing how the fraction of occupied adsorption sites depends on gas pressure. It captures saturation behavior as p p \to \infty , where n1 \langle n \rangle \to 1 .

Source
import matplotlib.pyplot as plt
import numpy as np

# Use dimensionless units: energies in units of epsilon
epsilon = 1.0  # binding energy (reference unit)
p0 = 1.0       # reference pressure

p = np.linspace(0, 10, 500)

fig, ax = plt.subplots(figsize=(8, 5))
for kT in [0.2, 0.5, 1.0, 2.0, 5.0]:
    n_avg = p / (p0 * np.exp(epsilon / kT) + p)
    ax.plot(p, n_avg, lw=2, label=rf'$k_BT/\epsilon = {kT}$')

ax.set_xlabel(r'Pressure $p / p_0$', fontsize=12)
ax.set_ylabel(r'Average Occupancy $\langle n \rangle$', fontsize=12)
ax.set_title('Langmuir Adsorption Isotherm', fontsize=14, weight='bold')
ax.legend(fontsize=11)
ax.set_ylim(0, 1.05)
ax.set_xlim(0, 10)
ax.axhline(1.0, color='gray', ls='--', lw=1, alpha=0.5)
ax.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()
<Figure size 800x500 with 1 Axes>

Chemical Equilibrium in gas mixtures

For each species i i , the canonical partition function is:

Zi=ziNiNi!withzi=Vλi3qiint(T)Z_i = \frac{z_i^{N_i}}{N_i!} \quad \text{with} \quad z_i = \frac{V}{\lambda_i^3} q_i^{\text{int}}(T)

where:

  • λi=h2πmikBT \lambda_i = \frac{h}{\sqrt{2\pi m_i k_B T}} is the thermal wavelength,

  • qiint q_i^{\text{int}} is the internal partition function (rotations, vibrations, etc.),

  • Ni N_i is the number of molecules of species i i .

  • For convenience lets use the Helmholtz free energy (same result with Gibbs Free energy):

F=kBTlogZ=kBTilogZi=kBTi[NilogzilogNi!]F = -k_B T \log Z = -k_B T \sum_i \log Z_i = -k_B T \sum_i \left[ N_i \log z_i - \log N_i! \right]
  • Using Stirling’s approximation logNi!NilogNiNi \log N_i! \approx N_i \log N_i - N_i :

FkBTiNi(logNizi1)F \approx k_B T \sum_i N_i \left( \log \frac{N_i}{z_i} - 1 \right)

Equilibrium via minimization of free energy

  • Now, we consider a chemical reaction:

aA+bBcC+dDaA + bB \rightleftharpoons cC + dD
  • We introduce an extent of reaction ξ \xi which measures how far reaction has progressed from reactants to products:

NA=NA0aξ,NB=NB0bξ,NC=NC0+cξ,ND=ND0+dξN_A = N_A^0 - a\xi,\quad N_B = N_B^0 - b\xi,\quad N_C = N_C^0 + c\xi,\quad N_D = N_D^0 + d\xi
  • We minimize F(ξ) F(\xi) at constant T,V T, V by setting:

dFdξ=0\frac{dF}{d\xi} = 0
  • Computing the derivative:

dFdξ=iFNidNidξ=iμiνi=0\frac{dF}{d\xi} = \sum_i \frac{\partial F}{\partial N_i} \frac{dN_i}{d\xi} = \sum_i \mu_i \nu_i = 0
  • with νi \nu_i the stoichiometric coefficient (<0 < 0 for reactants, >0 > 0 for products). Or we can write it in terms of positive stoichiometric coefficients:

μi=FNi=kBTlog(Nizi)\mu_i = \frac{\partial F}{\partial N_i} = k_B T \log \left( \frac{N_i}{z_i} \right)
  • So the equilibrium condition is:

iνiμi=kBTiνilog(Nizi)=0\sum_i \nu_i \mu_i = k_B T \sum_i \nu_i \log \left( \frac{N_i}{z_i} \right) = 0
  • Exponentiating both sides we relate ratio of equilibrium numbers or concentrations to partition functions

i(Nizi)νi=1\prod_i \left( \frac{N_i}{z_i} \right)^{\nu_i} = 1

Grand Canonical Monte Carlo: Particle Number Fluctuations in Action

The formulas above predict that particle number fluctuates in the grand canonical ensemble with σNN\sigma_N \sim \sqrt{N}. We can see this directly using a simple Grand Canonical Monte Carlo (GCMC) simulation on a lattice. At each step, we randomly attempt to insert or delete a particle, accepting moves with probability determined by βμ\beta\mu.

Source
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
from matplotlib.colors import ListedColormap
from IPython.display import HTML

def gcmc_animation_frames(beta_mu, L=25, n_steps=30000, n_frames=80):
    """Run GCMC and collect frames for animation."""
    grid = np.zeros((L, L), dtype=int)
    N = 0
    p_ins = min(1.0, np.exp(beta_mu))
    p_del = min(1.0, np.exp(-beta_mu))
    
    steps_per_frame = n_steps // n_frames
    frames = []
    N_vals = []
    
    for step in range(n_steps):
        x, y = np.random.randint(0, L, 2)
        if grid[x, y] == 0:
            if np.random.rand() < p_ins:
                grid[x, y] = 1; N += 1
        else:
            if np.random.rand() < p_del:
                grid[x, y] = 0; N -= 1
        if (step + 1) % steps_per_frame == 0:
            frames.append(grid.copy())
            N_vals.append(N)
    return frames, N_vals

# Generate frames for low and high mu
np.random.seed(42)
frames_low, N_low = gcmc_animation_frames(-2, L=25, n_steps=30000, n_frames=80)
frames_high, N_high = gcmc_animation_frames(2, L=25, n_steps=30000, n_frames=80)

cmap = ListedColormap(['#f0f0f0', '#2c7bb6'])

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4.5))
im1 = ax1.imshow(frames_low[0], cmap=cmap, vmin=0, vmax=1, interpolation='nearest')
im2 = ax2.imshow(frames_high[0], cmap=cmap, vmin=0, vmax=1, interpolation='nearest')

ax1.set_title(r'Low $\mu$: $\beta\mu = -2$', fontsize=13, fontweight='bold')
ax2.set_title(r'High $\mu$: $\beta\mu = +2$', fontsize=13, fontweight='bold')

for ax in [ax1, ax2]:
    ax.set_xticks([]); ax.set_yticks([])
    for spine in ax.spines.values():
        spine.set_linewidth(2)

txt1 = ax1.text(0.5, -0.07, '', transform=ax1.transAxes, ha='center', fontsize=11)
txt2 = ax2.text(0.5, -0.07, '', transform=ax2.transAxes, ha='center', fontsize=11)

fig.suptitle('GCMC Animation: Lattice Filling at Different Chemical Potentials',
             fontsize=14, fontweight='bold')
plt.tight_layout()

def update(frame):
    im1.set_data(frames_low[frame])
    im2.set_data(frames_high[frame])
    L = 25
    txt1.set_text(rf'$N = {N_low[frame]}$, $\theta = {N_low[frame]/(L*L):.2f}$')
    txt2.set_text(rf'$N = {N_high[frame]}$, $\theta = {N_high[frame]/(L*L):.2f}$')
    return [im1, im2, txt1, txt2]

plt.close(fig)
ani = animation.FuncAnimation(fig, update, frames=len(frames_low), 
                               interval=80, blit=True)
HTML(ani.to_jshtml())
Loading...
Source
import numpy as np
import matplotlib.pyplot as plt

def gcmc_lattice_gas(beta_mu, n_steps=50000, L=20):
    """Simple GCMC for non-interacting lattice gas.
    Each lattice site is either empty (0) or occupied (1).
    Acceptance probability for insertion/deletion depends on beta*mu.
    """
    grid = np.zeros((L, L), dtype=int)
    N = 0
    N_history = []
    p_accept_insert = min(1.0, np.exp(beta_mu))
    p_accept_delete = min(1.0, np.exp(-beta_mu))
    
    for _ in range(n_steps):
        x, y = np.random.randint(0, L, 2)
        if grid[x, y] == 0:  # try to insert
            if np.random.rand() < p_accept_insert:
                grid[x, y] = 1
                N += 1
        else:  # try to delete
            if np.random.rand() < p_accept_delete:
                grid[x, y] = 0
                N -= 1
        N_history.append(N)
    return np.array(N_history)

# Run GCMC at different chemical potentials
fig, axes = plt.subplots(1, 2, figsize=(13, 4.5))
colors = ['#1f77b4', '#ff7f0e', '#2ca02c']
beta_mu_values = [-2, 0, 1.5]

for beta_mu, color in zip(beta_mu_values, colors):
    N_hist = gcmc_lattice_gas(beta_mu, n_steps=50000)
    burn_in = 5000
    N_eq = N_hist[burn_in:]
    
    # Time series (last 10000 steps)
    axes[0].plot(N_hist[-10000:], alpha=0.7, color=color, 
                 label=rf'$\beta\mu = {beta_mu}$')
    
    # Histogram
    rel_fluct = np.std(N_eq) / np.mean(N_eq) if np.mean(N_eq) > 0 else 0
    axes[1].hist(N_eq, bins=30, alpha=0.5, density=True, color=color,
                 label=rf'$\beta\mu={beta_mu}$, $\sigma_N/\langle N\rangle={rel_fluct:.3f}$')

axes[0].set_xlabel('MC Step', fontsize=12)
axes[0].set_ylabel('N (particle number)', fontsize=12)
axes[0].set_title('Particle Number Fluctuations (GCMC)', fontsize=13, weight='bold')
axes[0].legend(fontsize=10)
axes[0].grid(True, alpha=0.3)

axes[1].set_xlabel('N', fontsize=12)
axes[1].set_ylabel('P(N)', fontsize=12)
axes[1].set_title('Distribution of Particle Number', fontsize=13, weight='bold')
axes[1].legend(fontsize=9)
axes[1].grid(True, alpha=0.3)

plt.tight_layout()
plt.show()
<Figure size 1300x450 with 2 Axes>

Isothermal-Isobaric (NPT) Ensemble

Most experiments in chemistry and biology are performed at constant temperature and pressure (e.g., reactions in open flasks, protein folding in solution). The appropriate statistical ensemble is the NPT ensemble, where the system exchanges energy and volume with a reservoir while keeping particle number fixed.

Derivation

  • Consider a system SS in thermal and mechanical contact with a large reservoir RR. The total system is isolated with fixed total energy Etot=E+ERE_{\text{tot}} = E + E_R and total volume Vtot=V+VRV_{\text{tot}} = V + V_R.

  • The probability of finding the system in a state with energy EE and volume VV is:

P(E,V)ΩR(EtotE,VtotV)P(E, V) \propto \Omega_R(E_{\text{tot}} - E,\, V_{\text{tot}} - V)
  • Expanding the reservoir entropy to first order (same logic as for NVT and μ\muVT):

lnΩRconstEkBTpVkBT\ln \Omega_R \approx \text{const} - \frac{E}{k_BT} - \frac{pV}{k_BT}

where we used:

1T=(SRER)VR,pT=(SRVR)ER\frac{1}{T} = \left(\frac{\partial S_R}{\partial E_R}\right)_{V_R}, \qquad \frac{p}{T} = \left(\frac{\partial S_R}{\partial V_R}\right)_{E_R}
  • This gives the NPT probability distribution:

P(E,V)eβ(E+pV)P(E, V) \propto e^{-\beta(E + pV)}

Partition Function and Gibbs Free Energy

  • The thermodynamic potential is the Gibbs free energy:

G(T,p,N)=kBTlnΔ=ETS+pV=HTSG(T, p, N) = -k_BT \ln \Delta = E - TS + pV = H - TS

where H=E+pVH = E + pV is the enthalpy.

  • The Gibbs free energy arises from the internal energy via Legendre transform replacing STS \to T and VpV \to p:

E(S,V,N)ETS+pV=G(T,p,N)E(S, V, N) \rightarrow E - TS + pV = G(T, p, N)

Volume Fluctuations

  • Just as energy fluctuates in NVT and particle number fluctuates in μ\muVT, volume fluctuates in NPT:

V=lnΔ(βp)\langle V \rangle = -\frac{\partial \ln \Delta}{\partial (\beta p)}
σV2=V2V2=V(βp)=kBTVκT\sigma_V^2 = \langle V^2 \rangle - \langle V \rangle^2 = -\frac{\partial \langle V \rangle}{\partial (\beta p)} = k_BT V \kappa_T
  • The relative volume fluctuation follows the same N1/2N^{-1/2} scaling:

σVV=kBTκTVO(N1/2)\frac{\sigma_V}{\langle V \rangle} = \sqrt{\frac{k_BT \kappa_T}{V}} \sim O(N^{-1/2})

Complete Ensemble Comparison

PropertyNVENVENVTNVTNPTNPTμVT\mu VT
FixedN,V,EN, V, EN,V,TN, V, TN,p,TN, p, Tμ,V,T\mu, V, T
FluctuatingEEE,VE, VE,NE, N
Partition fnΩ\OmegaZZΔ\DeltaΞ\Xi
PotentialSSF=ETSF = E - TSG=ETS+pVG = E - TS + pVΨ=ETSμN\Psi = E - TS - \mu N
Fluctuation-responseσE2=kBT2CV\sigma_E^2 = k_BT^2 C_VσV2=kBTVκT\sigma_V^2 = k_BT V \kappa_TσN2=N2kBTκTV\sigma_N^2 = \frac{N^2 k_BT \kappa_T}{V}

Problems

NVTNVEμVTNVT-NVE-\mu V T

  1. Consider a three level single particle system with five microstates with energies 0, ε, ε, ε, and 2ε. What is Ω(ϵ,n)\Omega(\epsilon, n) n=0,1,2 for this system? What is the mean energy of the system if it is in equilibrium with a heat bath at temperature T ?

  2. Derive an expression for the chemical potential of an ideal gas using classical mechanics model for energy E=p22mE=\frac{p^2}{2m} in the μVT\mu VT ensemble evaluate the fluctuations in particle number.

  3. Consider a system in equilibrium with a heat bath at temperature TT and a particle reservoir at chemical potential μ\mu. The system can have a minimum of one and a maximum of four distinguishable particles. The particles in the system do not interact and can be in one of two states with energies zero or Δ\Delta. Determine the (grand) partition function of the system.

  4. Combine the Gibbs formula of Entropy S=kBipilogpiS=-k_B \sum_i p_i log p_i with the Grand canonical probability distribution P(Ei,N)=eβEi+βμNΞP(E_i,N)=\frac{e^{-\beta E_i+ \beta \mu N}}{\Xi} to show that βPV=logΞ\beta PV=\log \Xi

  5. Derive partition function for a pressure ensemble (T,p,N)(T, p, N) and show its connection with microcanonical ensemble NVEN V E

  6. At a given temperature T a surface with N0N_0 adsorption centers has on average NN0N\neq N_0 number of adsorbed molecules. Suppose that there are no interactions between molecules.

    • Show that the chemical potential of adsorbed gas is given by: μ=kBTlogNN0Na(T)\mu = k_B T log \frac{N}{N_0 - N a(T)}

    • What is the meaning of a(T)a(T)