Statistical mechanics simulator

Statistical mechanics simulator due to Nathan Clisby, 2013.

The statistical mechanics simulator provides a platform for the visualisation of various algorithms for studying statistical mechanical systems. For the moment the only simulation is of the pivot algorithm for self-avoiding walks, but more will be added in future.

The code is written in Processing and released under the GPL.

Quick links: simulator, instructions, “How to”, download, pivot algorithm, future simulations, other visualisations, technical details, updates, acknowledgments.

The statistical mechanics simulator should be visible immediately below the instructions for compatible browsers. If there is a blank space, please visit the “How to” section further below for information on how to either enable WebGL for your browser, or download the application and run it on your computer via the Java Virtual Machine.

Brief instructions: click on “Pivot algorithm” on the initial screen to take you to the options menu. Clicking on menu items will change the corresponding value, and the simulation is run by clicking “START”. Selecting the exit button in the top right corner will return you to the parent menu, or terminate the application if you are at the root menu screen. New: Holding down the up and down arrow keys during the animation allows you to zoom in and out of the walk (this takes some getting used to, as there is some lag so that the change occurs smoothly). New: Pressing the left arrow once selects the next slowest animation speed, and pressing the right arrow once selects the next fastest. New: Pressing “i” will toggle the display of auxiliary information. From the top this displays t, the number of pivot attempts (Markov chain time), f, the fraction of pivot attempts which are successful, R, the square root of the mean square end-to-end distance, and z, the zoom factor relative to the default value.

How to run the simulator

Browser compatibility: needs WebGL enabled, and thus works with recent versions of Chrome, Firefox and Safari, but not Internet Explorer (Internet Explorer will have support from version 11 which will be released soon). For Safari, I had to enable WebGL by clicking on Safari → Preferences → Advanced → “Show Develop in menu bar”, and then selecting Develop → “Enable WebGL”. If your browser does not work, and you are sufficiently keen to view this simulation, I recommend installing Chrome.

Download: The simulation runs significantly faster and better on your computer as an application. The simulator is written in Processing, which is based on Java and runs in the Java Virtual Machine or JVM. Download files: (1 MB, to run in the Processing interpreter), Linux 32 bit (6.4 MB), Linux 64 bit (6.4 MB), MacOS X (6.7 MB), Windows 32 bit (6.4 MB), and Windows 64 bit (6.4 MB).

If you have trouble running the application, you may be interested in seeing this demo video to get an idea of what the simulation looks like: simulatorDemo.mp4 (25 MB). This demo is not intended to teach you how to use the simulator, as it is not possible to follow what options are selected.

Please let me know of your failures and successes when using this software! Any feedback welcome, including positive comments, criticisms, bugs found or requests for features. Here are my contact details.

The pivot algorithm

The pivot algorithm is the most efficient known method for sampling self-avoiding walks of fixed length, or equivalently sampling polymer configurations for a polymer in a good solvent.

The simulator shows how the pivot algorithm works when applied to self-avoiding walks on the square and simple cubic lattices. All possible lattice symmetries are used; only successful pivot moves are shown. The colours used in the walk have no particular meaning, their primary purpose is to allow one's eye to follow the motion of the walk in three dimensions.

Simulation options:

Here are links to some important papers on the topic. This list is not exhaustive by any means!

This section on the pivot algorithm will be incrementally expanded in future to provide a guide to the literature which I hope will prove useful to newcomers to the field.

Future simulations

This is a list of simulations which I'm interested in adding in the future. If you have any suggestions please let me know.

Please note that my time is quite limited and so there may not be much progress in the immediate future (as of June 2013). Each of the proposed applications will take in the range of 1 day - 1 week of work to pull something together which will do a decent job.

Walks and polymers:

Statistical mechanics:

Other visualisations

This is a brief advertisement for some other work I've done producing visualisations.

Technical details

The simulator is written in Processing which is a beautiful language for this purpose. For scientific visualisation it is a remarkably powerful tool.

The statistical mechanics simulator is written in such a manner that it is fully compatible with Processing.js, which is a javascript interpreter of Processing. This allows for Processing animations to be viewed directly in html5 compliant browsers, with the only (slight) downside that one can no longer leverage the full power of Java. This is because although Processing.js can interpret the full Processing language, it cannot interpret Java, and so Java libraries must be re-written if they are to be used. For the statistical mechanics simulator this means that I have developed my own rudimentary menu system, rather than relying on the much better libraries which others have created. It would be possible to have a “pretty” application version and “ugly” web version, but I do not have time to maintain two separate versions. Another minor downside from maintaining compatibility is that all files (including data files) need to be kept in the source directory (at least this is my understanding, I haven't actually tested whether it is possible to store the files elsewhere).

The programming style in this simulator is frankly terrible, as it has been rapidly developed and should be regarded as a prototype. If you have sufficient time and interest to re-factor the code please go ahead!

If you are interested in contributing to this project either by improving existing code or by adding additional simulations then I strongly encourage you to so. I would really like to hear from you if you're considering this (my contact details).


I'm an inveterate tinkerer, so there will be various tweaks and improvements while I'm actively working on this.


Thanks to Mireille Bousquet-Mélou for her initial inquiry as to whether I knew of any nice pivot algorithm videos, which led to me developing the simulator after discovering what a great tool Processing is.

Thanks to the ARC Centre of Excellence for Mathematics and Statistics of Complex Systems (MASCOS) for funding my work.

Thanks to the developers of Processing and Processing.js for creating such marvellous tools, and then making them freely available.

My homepage.