An attempt at simulating interacting water molecules
Channel: Nils Berglund
Date: 2022-03-18

This is a first attempt at simulating interacting H2O molecules, as suggested by several viewers. The result is still far from perfect, in particular careful observers will note some glitches that are probably due to the thermostat. The simulation shows 489 interacting molecules, subjected to gravity, and confined to a rectangular box by a harmonic potential.
My aim here was to reproduce the polar behavior of water molecules, with the two hydrogen atoms each having a charge e, while the oxygen atom carries a charge -2*e. Modeling the interaction of the molecules by the Coulomb potential alone makes the simulation unstable, and is probably not so realistic anyway because of quantum mechanical effects. One way I found in the literature is to have the centers of mass of the molecules interact via a Lennard-Jones potential, and then add the Coulomb interaction between the atoms of different molecules. The sum of all Coulomb forces adds to the linear acceleration of the molecules, while the total torque modifies their angular velocity. An alternative would have been to use a multipole expansion for the interaction.
There are two parts in this simulation, showing the same evolution with two different visualizations:
Kinetic energy: 0:00
Orientation: 1:41
In the first part, colors depend on the particles' kinetic energy, red particles are moving or rotating faster than blue ones. In the second part, the colors show the orientation of the molecules. 
The temperature is controlled by a thermostat, implemented here with the "Nosé-Hoover-Langevin" algorithm introduced by Ben Leimkuhler,  Emad Noorizadeh and Florian Theil, see reference below. The idea of the algorithm is to couple the momenta of the system to a single random process, which fluctuates around a temperature-dependent mean value. Lower temperatures lead to lower mean values. The temperature shown on the top right is in fact the temperature multiplied by Boltzmann's constant. To save on computation time, particles are placed into a "hash grid", each cell of which contains between 3 and 10 particles. Then only the influence of other particles in the same or neighboring cells is taken into account for each particle. 
The Lennard-Jones potential is strongly repulsive at short distance, and mildly attracting at long distance. It is widely used as a simple yet realistic model for the motion of electrically neutral molecules. The force results from the repulsion between electrons due to Pauli's exclusion principle, while the attractive part is a more subtle effect appearing in a multipole expansion. For more details, see https://en.wikipedia.org/wiki/Lennard-Jones_potential

Render time: 40 minutes
Color gradients: Part 1 - Turbo, by Anton Mikhailov
https://gist.github.com/mikhailov-work/6a308c20e494d9e0ccc29036b28faa7a
Part 2 - JET.

Music:  Groove Grove by Kevin MacLeod is licensed under a Creative Commons Attribution 4.0 licence. https://creativecommons.org/licenses/by/4.0/
Source: http://incompetech.com/music/royalty-free/index.html?isrc=USUAN1200054
Artist: http://incompetech.com/ 

Reference: Leimkuhler, B., Noorizadeh, E. & Theil, F. A Gentle Stochastic Thermostat for Molecular Dynamics. J Stat Phys 135, 261–277 (2009). https://doi.org/10.1007/s10955-009-9734-0
http://www.maths.warwick.ac.uk/~theil/HL12-3-2009.pdf

Current version of the C code used to make these animations: 
https://github.com/nilsberglund-orleans/YouTube-simulations
https://www.idpoisson.fr/berglund/software.html
Some outreach articles on mathematics:
https://images.math.cnrs.fr/_Berglund-Nils-1343_.html
(in French, some with a Spanish translation)