Immiscibility doesn't just happen - as you approach it, the solvent molecules tend to fluctuate into clusters. Although KB theory cannot handle the phase separation of immiscibility, it provides a good guide of what is happening to the molecules up to the point of "critical opalescence" when there's strong clustering.
We start with a great simplification of the KB-Binary app which allows us to specify activity coefficient plots in binary mixtures. If one component is not "happy" in another then the activity coefficient is high. The plot is generally in terms of mole fraction, x1 and the activity coefficient of an "unhappy" molecule 1 starts high at low x1 (because it's mostly escaping from molecule 2) falling to 1 when x1 approaches 1. Unfortunately, these plots of activity coefficient reveal very little about what is going on at the molecular level.
This app takes activity coefficient (γ1 and γ2) data, which we create via two sets of sliders, and (behind the scenes) turns it into Kirkwood-Buff Integrals (KBI) from which is is easy to calculate what is happening at the molecular level. A large positive KBI indicates a higher-than-bulk concentration around a given molecule. From the hidden KBI we then create graphs of "Excess Numbers", Δnij which say how many molecules more or less surround a given molecule at any given concentration compared to the bulk average number. A large excess number indicates local clustering typical of blends that are on the border of phase separation. This is when you see "critical opalescence" because the clusters are large enough to scatter visible light.
In addition to the activity coefficients we calculate the change in free energy, ΔG of the mixture. Although most of us think that ΔG is important ("it must be negative"), in fact the key aspect of it is its 2nd derivative. If this ever dips below zero then you have phase separation. So we plot ΔG and its 1st and 2nd derivatives (the 2nd derivative is divided by 10 for the plot to keep the scale reasonable).
As you make the activity coefficients more extreme (start increasing LinA and/or ExpA before playing with the others.) you see the minimum of the 2nd derivative get closer and closer to 0 while the Δn11 and Δn22 values get larger (with reductions in the numbers of 1's clustered around 2 and 2's around 1) - the solvents are clustering more and more upon themselves. Suddenly the Δn plots break up [the values are meaningless and set to 0] because the calculation has failed - we've moved out of a meaningful KB domain. But you also see the reason, the 2nd derivative has started to go negative. So this solvent blend will be immiscible across the x1 range where the values are meaningless.
If you change the pseudo-temperature then raising it restores miscibility, lowering it increases the immiscible range. This is only illustrative via unscientific changes of the activity coefficients, but it shows the sort of behaviour observed when you have a (confusingly named) Upper Critical Solution Temperature, below which you no longer have miscibility.
The real name for KB-style theories is the Fluctuation Theory of Solutions. The focus is on deviations from average concentrations which they call fluctuations. Although, say, Δn11 is a constant (so it's not itself fluctuating!) the idea is that the positions of higher and lower concentration are randomly distributed in space and time. Indeed, when you are near a phase separation you can see a "sparkle" in the solution from these fluctuating domains. And, of course, they can be seen with light, X-ray or neutron scattering.
Most of the time, most of us don't naturally think in terms of fluctuations in solutions. But the fluctuation view of something as apparently simple as phase separation of immiscible solvents is the most insightful way to think of what's going on.
Famously, calculating these fluctuations from first principles is somewhere between hard and impossible - so the prediction of immiscibility is so far an unsolved problem. This is very frustrating for those of us who like to use solvent mixtures. It seems so obvious that solvents in very different parts of solubility space should be immiscible. But famously, ethanol is miscible with just about any reasonable solvent across the whole solubility domain - a fact for which there is no obvious explanation.
Specifying the activity coefficients
It's surprisingly non-intuitive to create plausible activity coefficient curves. It's also surprising (to most of us) that you only need to specify γ1 because γ2 is automatically derived via the Gibbs-Duhem equation. But that only happens if the γ1 is Gibbs-Duhem compliant, something I learned the hard way.
For those who are interested, here are the equations. The 2-term linear (well, smooth line) equation is given by the following. Note that getting a symmetrical plot where γ2 mirrors γ1 involves some non-intuitive fiddling with LinB:
and the curved one, which gives a Gaussian peak of height ExpA (when ExpA > 1) at x1=ExpB with width ExpC, is given by:
`ln(γ_1)="ExpA".e^(-("ExpB" - x_2)^2 / "ExpC")`
They are combined via simple summation.