RDF Demo

Quick Start

In the RDF app we looked at how the Radial Distribution Function gave us Gij values. Here we take a simplified world of molecules bouncing around and calculate the RDF. We control the world by altering the relative attractions, Aij between molecules so you can build your intuitions about how the RDF (and Gij values) should change if, say A12 is larger than the 11 and 22 values. You would expect to see (and you will see!) the RDF of the 12 pair to become larger. You can also explore the effect of relative size. Making 2 larger has a big effect on the RDF and Gij values, even if attractions remain the same. Size effects are important, and in conventional thermodynamics they are obscure. Here they are crystal clear.

Rather than explain what all the buttons do, just click Start and see what happens. Once things settle down, start playing with the relative Attractions. You can read a detailed explanation once you've seen what is going on.

RDF Demo

N/Edge
Size2
x2
T-Step
Attr11
Attr22
Attr12
PerFrame
Steps/s
N atoms
μ1
μ2
G11
G22
G12

This shows how the Radial Distribution Function, RDF, changes with the relative sizes of the molecules, their relative amounts and relative attractions, and the density of the liquid.

The top image shows the "liquid". By changing the sliders N/Side (Number of atoms per grid edge), Size2 and x2 (x is the mole fraction) you re-set the liquid to a start position with your choice of settings then clicking Start sets the liquid into motion. The other sliders can be changed while the simulation is running so you can see their effects "live".

The bottom image is the RDF computed in real time. This slows things down a bit but is useful to quickly build up your intuitions. If you change the relative attractions of 11, 22 and 12 you see the RDFs change appropriately.

Before trying to understand it all, just click the Start button and watch what happens. More details are provided below.

This app is based on the excellent code from Dr Daniel V. Schroeder's Interactive Molecular Dynamics app and I warmly thank Dr Schroeder for his generosity in allowing me to use the code from that app plus extracts from some of his other MD code.

Don't be disconcerted by artefacts during the "annealing" process at the start. Setting up a grid of molecules isn't easy and the initial annealing gets rid of many of the start-up artefacts.

Like all powerful models it takes some getting used to. The first problem is setting up the simulation. The molecules can have different relative sizes ("1" is fixed and "2" is sized relative to 1), and there can be a different mole fraction, x2. Each time you adjust these sliders the calculation resets with a regular grid of the molecules according to your wishes.

Because we do not want wall effects, the grid wraps around itself - so a molecule near the right-hand edge can be attracted to one on the left-hand edge, and a molecule moving off the right-hand edge will appear on the left. Similarly for top and bottom.

Molecules have different attractions to themselves or the other. These can be set independently, relative to an average value of 1. These values can be set via the Attrij sliders while the simulation is running and you can see visually the subtle changes in the molecular distribution and how the RDF changes.

There are two "system" settings. The first is the Time Step. Small values mean more accurate simulations, but much slower. Too large a time step will lead to artefacts as molecules will move further than they otherwise would have been able to. The second is the PerFrame value which is the number of time steps before the graphics update. A large value is faster because the graphics and calculation of the RDF take up resource. But of course you miss the fine detail of what is going on. You can alter both values "live" to see what happens.

You can Pause at any time then hit Resume to continue. You can single Step if you want to look at things in detail. The Heat and Cool buttons make the molecules go faster or slower each time you click them.

In terms of simulation speed, it's not great, but even on an old iPad it's not unbearable if you don't have too many molecules. RDF equilibrium is reached surprisingly quickly, so you can learn a lot even on a slow machine. On a good modern laptop it is not bad at all.

So what is the RDF? The distance between each molecule is calculated and "binned" into a histogram. The histogram is then plotted, with a normalisation factor that represents the average expected if there were no interactions. The binning depends on whether the pair are 1-1, 2-2 or 1-2. When, for example, there are many pairs of molecules, these will show up as a large peak at the pair-wise distance. Below the pair-wise distance molecules are excluded (the "excluded volume" effect) so the RDF is below 1, and similarly after the first peak there is often a dip as it is impossible for molecules to get close if there are already other molecules around.

You will find that the RDFs all neatly average out to 1, as, indeed, they should. This is a numerical trick in the code; the statistics are such that the average for each RDF can vary around 1. This makes computation of the Gij values (discussed below) highly unreliable. So the actual average near the end of the RDF is used to offset each plot. Given a supercomputer running larger simulations, such tricks would not be needed. As this is only a toy system, it is important to remove distractions, and this coding trick achieve that purpose.

One of the important lessons from the RDF, and the reason for the visualisation, is that a peak at a given distance does not mean that there are "complexes". The whole system is random and the RDF represents some modest amount of ordering in the disordered system. However this modest amount of ordering (or the opposite, which is the absence or reduction of a peak) is crucial to the realities of solution behaviour.

For those who know about the Widom insertion method, the chemical potentials μ1 and μ2 are calculated via that method. The Widom insertion method is an amazing trick. You simply find what are the chances of inserting a fresh molecule into ensemble without hitting another molecule. This sounds as though it could not possibly be a good way to calculate chemical potential but it happens to be a fundamental principle of thermodynamics so gives (within the numerical limits) an accurate value. At this prototype stage the Widom values have not been validated.

This simple, toy, system reveals a lot of profound truth about molecular thermodynamics and the gij values which then become the Gij values shown in the RDF app and in turn these KB integrals tell us a lot about what is really going on and, importantly, what effects are, or are not, significant in any given solubility issue.