(2025/08/30)
Recently, I stumbled upon a 3Blue1Brown video on simulating phase change. There, Vilas Weinstein explained a powerful but relatively simple way of modeling the phase transition between liquid and vapor/gas. I was quickly interested and decided to give the implementation a shot in Python.
Rudimentary visualizations (UI, etc.) were built through TKinter. Here’s I show a quick look at the final interactive simulations I made. To try it out for yourself, visit the repo at my GitHub and run the code locally.
Here, the parameter you control is the temperature of the system. At low temperatures, you can notice that the molecules bundle up together into blobs—indicating a liquid phase. At higher temperatures, the molecules are more random and entropic, thereby exhibiting the gas phase.

In an actual phase diagram, the two parameters are temperature and pressure. However, as explained in the 3B1B video, pressure is tricky to implement because it requires dynamically changing the volume or size of the system. Because of that, we can instead control the amount of molecules through something called the chemical potential of the system. In this implementation, you can use the 2D slider to control temperature (x-axis) and potential (y-axis).
The background of the 2D slider is actually the phase diagram I sampled from this very simulation (with a bit of blur post-processing). Blue color indicates a more liquid phase. At high temperatures (right side of the slider), the boundary between liquid and gas becomes “blurry”. This roughly models a supercritical fluid phase.

First of all, I highly recommend watching the 3B1B video for the amazing visualizations and intuitive explanations behind the derivation of the model. Here, I’ll try to give a gist of my implementation.
Consider the system to be at some temperature . In this simulation, the energy at some system state is modeled as the negative of the number of pairs of adjacent molecules. To propagate the simulation, the following rules are followed:
Consider the system to be at some temperature and chemical potential . Here, the energy is modeled as , where is the same as in Kawasaki dynamics, and simply refers to the number of molecules at some state . Then, it iterates by:
Running the simulations as is will make the visualization appear stagnant and slow to converge (mainly due to my weaker laptop). To make the phase changes more apparent, my implementation involved running the simulations above multiple times before rendering a frame.
The (obviously much better) Glauber dynamics simulation by Vilas Weinstein is also publicly available here. It runs on the browser so everyone can easily try it out—no downloads required!
Also, as someone from a non-physics background, I was pleasantly surprised to see how Kawasaki and Glauber dynamics are actually more well-known for the Ising model in ferromagnetism!