A blog of Python-related topics and code.

Exploring the Schottky anomaly in hydrogen

The temperature-dependence of the rotational contribution to the heat capacity of gaseous molecular hydrogen shows a Schottky anomaly: whereas for many systems the heat capacity can be expected to increase with increasing temperature, for $\mathrm{H_2}$ there is an temperature range within which it reaches a maximum before decreasing. Only at higher temperatures does it revert to "conventional" behaviour.

Calculating the heat capacity from the partition sum

It is a standard result of statistical thermodynamics that the molar heat capacity at constant volume, $C_{V,\mathrm{m}}$, is related to the molecular partition sum, $q$, through the relation $$ C_{V,\mathrm{m}} = R\beta^2\left[\frac{\ddot{q}}{q} - \left( \frac{\dot{q}}{q}\right)^2\right], $$ where $\dot{q}$ and $\ddot{q}$ represent the first and second derivative of $q$ with respect to the "thermodynamic beta", $\beta = \frac{1}{k_\mathrm{B}T}$:

Interactive particle-in-a-box wavefunctions in Jupyter

A very quick plot of particle-in-a-box wavefunctions with interactive control over the box length, $L$ – this kind of thing is very easy with Jupyter and ipywidgets' interact method: Just define a function to plot the wavefunction for a provided argument $L$ and pass it to interact along with a range and stepsize of values of $L$ and a slider will appear above the plot. Event callbacks and range-checking are all handled for you.

The arcsine law

Suppose a fair coin is tossed $N$ times and the number of "heads", $n_\mathrm{heads}$, and "tails", $n_\mathrm{tails}$, recorded after each toss. Over the course of the trial, how many times is the number of heads recorded greater than the number of tails? Naive intuition might lead to the expectation that as $N$ increases the number of times "heads" is in the lead increases in proportion.

Atomic term symbols

The problem of predicting the term symbols for states derived from a $nl^r$ atomic configuration (without using group theory!) provides a good use of Python's collections and itertools libraries.