Minimal Vicsek model in Python

The Vicsek model is one of the simplest models for active matter. It displays interesting features, such as swarming.

Large scale simulations are often needed in order to provide firm statements on the statistical properties of this kind of models. However, for a pedagogical and illustrative purpose it may be useful to have an elementary code to play with. For this purpose, I have written a relatively simple Python code which implements the model with a few clever tricks to make simulations of a few thousands of agents possible on a standard laptop.

We follow Gregoire and Chaté in the formalism: point-wise particles move synchronously at constant speed v in discretised time of steps Δt=1. The particles have an orientation described by an angle θ which evolves taking into account all particles k within a given radius of interaction

\theta_{j}^{t+1}=\arg \left[\sum_{k \sim j} e^{i \theta_{k}^{t}}\right]+\eta \xi_{j}^{t}

For the neighbourhood calculations, cell-lists would be ideal, but they are too complex for the kind of elementary code that we want to write. What we are going to use is the kd-tree quick nearest neighbour lookup algorithm as implemented in Scipy and some clever sparse matrix manipulation. For visualisation, we employ matplotlib, so that the resulting code is just 60 lines with only very popular libraries.

import numpy as np
import scipy as sp
from scipy import sparse
from scipy.spatial import cKDTree
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

L = 32.0
rho = 3.0
N =	int(rho*L**2)
print(" N",N)

r0 = 1.0
deltat = 1.0
factor =0.5
v0 = r0/deltat*factor
iterations = 10000
eta = 0.15

pos = np.random.uniform(0,L,size=(N,2))
orient = np.random.uniform(-np.pi, np.pi,size=N)

fig, ax= plt.subplots(figsize=(6,6))

qv = ax.quiver(pos[:,0], pos[:,1], np.cos(orient[0]), np.sin(orient), orient, clim=[-np.pi, np.pi])

def animate(i):

	global orient
	tree = cKDTree(pos,boxsize=[L,L])
	dist = tree.sparse_distance_matrix(tree, max_distance=r0,output_type='coo_matrix')

	#important 3 lines: we evaluate a quantity for every column j
	data = np.exp(orient[dist.col]*1j)
	# construct  a new sparse marix with entries in the same places ij of the dist matrix
	neigh = sparse.coo_matrix((data,(dist.row,dist.col)), shape=dist.get_shape())
	# and sum along the columns (sum over j)
	S = np.squeeze(np.asarray(neigh.tocsr().sum(axis=1)))
	orient = np.angle(S)+eta*np.random.uniform(-np.pi, np.pi, size=N)

	cos, sin= np.cos(orient), np.sin(orient)
	pos[:,0] += cos*v0
	pos[:,1] += sin*v0

	pos[pos>L] -= L
	pos[pos<0] += L

	qv.set_UVC(cos, sin,orient)
	return qv,

FuncAnimation(fig,animate,np.arange(1, 200),interval=1, blit=True)

The result is the following animation (the colour indicates the orientation):

Structural Ordering in Liquid Gallium under Extreme Conditions

Last May, James Drewitt from the School of Earth Science here in Bristol asked me to have a look at his data on ver high pressure and temperature gallium. Used to my idealised particles in box, I thought that it would be interesting to look understand what information can reasonably emerge in this more realistic setting.

It turns out that gallium is a liquid with a number of noticeable physical characteristics: a melting point just above room temperature at ambient pressure conditions, high thermal conductivity and a strong tendency to undercooling, i.e. to remain disordered well below its melting temperature (which is even enhanced with respect to the bulk behaviour when small droplets of gallium as considered). To my surprise, it also appears that many of the tools that I have employed to study the structure of simple liquids are useful to understand how extreme pressure and temperatures affect this metallic liquid.

We have shown, for example, that as the pressure increases the liquid shows a preference to form local motifs of radically different nature in somewhat similar proportions, as opposed to what would happen in purely repulsive systems. This is interesting, as this competition between different forms of local order provides a mechanism for the enhanced stability in supercooled conditions. We also have found out that simplistic approaches to the modelling of the three dimensional structure of the liquid (such as naive Reverse Monte Carlo methods) overlook these changes in structure and are strongly biased by their initial guesses.

The reference to the full work, that combines new experimental evidence with a detailed numerical simulation analysis, is

James W. E. Drewitt, Francesco Turci, Benedict J. Heinen, Simon G. Macleod, Fei Qin, Annette K. Kleppe, and Oliver T. Lord, Phys. Rev. Lett. 124, 145501 (2020)

Pentagonal bipyramids and dynamic arrest

Hard colloidal spheres present a certain degree of local ordering that has been in the past described in different (related) ways: one can identify an increased role played by tetrahedral arrangements, or focus on icosahedral or partially icosahedral structures.

Expanding on a previous work, James Hallett (now in Oxford) has produced earlier this year a detailed analysis of very high density experiments where we show that increased local ordering can be described in terms of the number of interlacing pentagonal rings formed by neighbouring particles. This provides a finer description of the changes that high densities impose on the local structure and on the geometric constraints that are satisfied (or not) by the microscopic reordering.

The full work is available on the Journal of Statistical Mechanics.

James E Hallett, Francesco Turci, C. Patrick Royall J. Stat. Mech.014001 (2020)

Many-body correlations from integral geometry

Computing high order correlations in liquids is not easy. Josh Robinson – with the help of Paddy Royall, Roland Roth and myself – has shown earlier in 2019 that with employing mostly geometrical principles one can accurately estimate the free energy of different motifs in a simple hard sphere fluid, see here  10.1103/PhysRevLett.122.068004 .

In more detailed paper we now show how this approach can be connected to classical liquid state theory and seen as an extension of so-called scaled-particle theory, where one computes the work of insertion of solutes in a fluid in order to estimate their free energy (see, for example, the Widom insertion method.)

Our approach allows us to write down a potential of mean force for interactions between a subset of n particles and a fluid, generalising previous methods and opening a way to accurate measurement of free energy barriers in the formation of local structural inhomogeneities in fluids, as in the formation of crystalline precursors.

The full article reference is:

Joshua F. Robinson , Francesco Turci, Roland Roth, and C. Patrick Royall, Many-body correlations from integral geometry, Physical Review E 100, 062126 (2019)

Dynamical solid–liquid transition through oscillatory shear

During the summer of a few years ago Eric Brillaux, a student of the Ecole Normale Superieure de Lyon, visited Bristol for a summer project. Thinking of something moderately ambitious that could (in theory) be achieved in a few months, we started to explore how simple crystals respond to oscillatory shear.

The original motivation of the work was rather speculative: I was wondering if it could be possible to transform mechanically an ordered system (a crystal) into an amorphous system (a glass) whilst preserving some degree of local order. To this purpose, the ideal model to consider was an atomistic binary mixture whose supercooled liquid state presents local structural motifs that are identical to the repeated units of its crystalline state (as we have previously shown, see here) .

In particular, we considered an oscillatory shear protocol. This is interesting not only because it mirrors more closely actual experimental methods, but also because it allows the system to behave either reversibly or irreversibly: if the oscillations are small, the crystal survives; if the deformations are large, amorphisation takes place.

In our article just out on Soft Matter, we discuss how this dynamical transition between the reversible and irreversible regime takes place in actual three dimensional crystals and how it depends on the crystal composition. For example, single-component crystals can transform structurally, from face-centred cubic structures to more body-centred cubic structures before becoming disordered. Instead, crystals of two components either transform reversibly or become amorphous at a critical oscillation amplitude.

The dynamics is also rather interesting: for instance, the growth of amorphous regions follows a coarsening pattern that is reminiscent of spinodal decomposition in non-driven systems.

In the end, the amorphous states that we obtain are not as rich in local structural motifs as I hoped, but the dynamical transition in itself has appeared to be very intriguing!

More details in the original article

Eric Brillaux, Francesco Turci, Soft Matter, 2019, doi 10.1039/C8SM01950A

Progress of the amorphisation of a binary crystal upon several oscillations of period τ0.

Morphometric approach to many-body correlations in hard spheres

Supercooled liquids become more and more viscous as their temperature is reduced. The increased viscosity corresponds to an enormous increase in the characteristic time for the relaxation of density fluctuations. What is often puzzling is that, differently from many other physical phenomena, this dramatic change in the correlations in time appears to be weakly reflected in conventional measures of spatial correlations. These are typically so-called pair or two-body correlations, measuring how likely it is to find randomly chosen pairs of particles at particular characteristic distances.

The lack of strong correlations between two-body spatial correlation and the emergent, enormous relaxation times of supercooled liquids suggests that more complex, eventually multi-body correlations may be at play.

Thanks to the work of a very gifted PhD student in Paddy Royall‘s group, Joshua F. Robinson, we have obtained a first theoretical insight on the origin of such emergent correlations in a reference model for supercooled liquids, i.e. hard spheres, which are often employed to understand the behaviour of colloidal particles and as a basis to develop approximate theories of liquids.

We rooted our work in a geometric approach to treat the free energy of thermal hard spheres developed by Roland Roth (a co-author of our work) termed morphometric theory and this has allowed us to study the free energy of a certain number of thermal structural motifs of hard spheres immersed in an effective medium and predict with a high degree of precision their respective populations. Furthermore, the approach that we have used has revealed that it is possible to follow local deformations of the motifs and compute the free energy barriers between them.

The work appeared as an Editor’s Suggestion in Physical Review Letters:

Joshua F. Robinson, Francesco Turci, Roland Roth, C. Patrick Royall, Phys. Rev. Lett. 122, 068004 (2019) doi: 10.1103/PhysRevLett.122.068004

and it has also been paired by a Viewpoint in Physics by Thomas Speck.

Coupling of sedimentation and liquid structure: Influence on hard sphere nucleation

Colloidal hard spheres at high volume fractions (beyond ~0.49) can crystallise: up to to 0.54, they coexist with a fluid phase, and at even higher densities they completely crystallise. The way the hard sphere fluid transforms into the solid is called crystal nucleation: due to thermal fluctuations, every now and then locally denser and more ordered regions appear and disappear; occasionally, these are large enough to further grow irreversibly, and form a crystalline region.

Nucleation is a generic process: in hard spheres, it should present its simplest traits, as it can be driven only by entropic forces. Yet, nucleation rates in colloidal hard spheres are rather different from what can be predicted from theory and numerical simulations. In particular, the discrepancy between the two increases of many orders of magnitude with decreasing the volume fraction from, for example, 0.55 to 0.53. Simulations normally consider idealised hard spheres in an ideal solvent. What could possibly go wrong?

Nick Wood, a talented PhD student here in Bristol, has taken care of some potential origins of the discrepancy analysing the effect of sedimentation on local order. Together with John Russo and Paddy Royall, we have considered in our recent paper how the flow induced by sedimentation may, via hydrodynamics interactions, transform the structure of the liquid, compared to the case in absence of sedimentation, and how such changes would impact on the nucleation barriers. The result is that some structural signatures clearly vary as a function of the density mismatch between colloids and solvent and that this leads to an estimated correction of the rates in the right direction, but by an amount that is not sufficent to address the entire discrepancy.

The complete article can be found here:
Nicholas Wood, John Russo, Francesco Turci and C. Patrick Royall J. Chem. Phys. 149, 204506 (2018);

Structure of the colloidal hard-sphere fluid with (left) and without (right) sedimentation. In green are highlighted motifs that hinder the crystal formation and anti-correlate with it, as demonstrated here.

Segmenting 3d biological data

I have recently been given the opportunity to study the segmentation of 3D data.  The group of Dr. C. Hammond of the School of Physiology, Pharmacology and Neuroscience in Bristol studies malformation in tissues of  Zebrafish  a model organism which can be genetically manipulated relatively easily .

A major task is to identify bone malformation or osteoarthritis. Hammond’s group manages to image hundreds of Zebrafish in three dimensions so that bone structures can be visualised. Identifying bone deformations in the spine, for example, is key to associate them to specific genetic marker. To do so, a quantitative analysis of the structure of the individual vertebrae is necessary.

It turned out that it is possible to do this via image analysis techniques that are publicly available in Python: the key libraries that I employed are scipy. ndimage and scikit-image.  Identifying the vertebrae in 3d means to perform  a segmentation of volumes and surfaces in 3d images.

An example of the vertebrae, individually resolved, can be visualised in 3d here below:

Nonequilibrium Phase Transition in an Atomistic Glassformer: the Connection to Thermodynamics

One central piece of the problem of dynamic arrest is whether the phenomenology of slow relaxation, increasing dynamical length scales, mild (or dramatic) structural changes are somewhat related to the existence of a zero entropy amorphous state emerging at a non-zero temperature.

A comprehensive theory would need on the one hand to take into account of the well established phenomenon of dynamical heterogeneitiesi.e. the non-homogenous patterns of diffusion that emerge together with the glassy dynamics itself; on the other hand, it should also rationalise the many findings that point (for several model systems) to a dramatic reduction of the so-called configurational entropy as one approaches a finite temperature (sometimes termed Kauzmann temperature) at which also the relaxation times appear to diverge.

In our recent work (Physical Review X 7, 031028) Thomas Speck,  C. Patrick Royall and I discuss a unified scenario that combines dynamical aspects to structural ones in order to sample very low energy and entropy states, employing dynamical large deviations.

We find that the equilibrium supercooled liquid competes with a secondary metastable  amorphous liquid rich in long-lived structural motifs, hidden in the tails of probability distributions in trajectory space. We also show that sampling the tails of such probabilities at a single moderate temperature allows us to retrieve the thermodynamic properties of the ordinary liquid in much wider range of temperatures, down to very low temperatures. We can then draw a diagram for the stable and metastable phase, pointing towards critical-like fluctuations in the region where the Kauzmann temperature is normally located, and allowing us to review currently proposed scenarios from an alternative point of view, rooted in the large deviation theory of metastability.


Searching for a module

When installing software on an High Performance Computing unit, additional packages are often handled by the module package.

To have a list of all the modules available it is sufficient to type

module avail

Often one then retrieves a very long list of possible modules, in alphabetic order. This is not very convenient if one is looking for a particular feature and dos not really know how it has been categorised.

One may think that grep would suffice to filter the results. This is almost true: in order to use grep first one needs to reformat the result of module avail with the -t  option into a single column, redirect the standard error output (labelled by 2 in Bash) to the standard output (labelled by 1, so that the redirection is 2>&1) and then pipe it with grep.

For example, if we want to search for all the modules containing “python” in their name we would type:

module avail -t 2>&1 | grep -i python

and eventually just write a convenient script named modsearch in our ~/bin :

module avail -t 2>&1 | grep -i $1

so that in the future we will just have to type

modsearch python