Interacting squares on a torus
Channel: Nils Berglund
Date: 2022-01-24

In this video, 1433 particles interact with a potential that has the symmetry of a square. It is similar to the video https://youtu.be/EVFcJ7gu3Gk but with periodic (wrap-around) boundary conditions: the left and right border of the displayed rectangle are identified, as are the top and bottom borders. 
The temperature is controlled by a thermostat, and is lowered three times and raised twice in the course of the simulation, each time to a lower value. 
This simulation has two parts, showing the same evolution with two different color codings:
Orientation: 0:00
Number of neighbors: 1:28
In the first part, the color of the particles represent their orientation. In the second part,  the color depends on the number of neighbors, defined as particles within a given distance. Blue particles have more neighbors than red ones. Particles considered as neighbors are connected by straight lines, that can be considered as hydrogen bonds. However, particles also interact when they are not connected by bonds. 
The precise form of the interaction potential in polar coordinates is 
V(r,phi) = (req/r)^12 - (9-7*cos(4*phi))*(req/r)^6, 
where req is equal to 5 times the outer radius of the particles. In addition, particles with orientations theta1 and theta2 exert on each other a torque, which is proportional to -sin(4(theta1 - theta2)), and decreases as the inverse of the square of the distance between particles.
The temperature is controlled by a thermostat, which is here 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. 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

Edit: the upward movement of the particles may be due to an artifact of the numerical integration known as "flying ice cube effect", see https://en.wikipedia.org/wiki/Flying_ice_cube

Render time: 17 minutes 30 seconds
Color scheme: Turbo, by Anton Mikhailov
https://gist.github.com/mikhailov-work/6a308c20e494d9e0ccc29036b28faa7a

Music: "See You Soon" by Otis McDonald

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)