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.

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:
source.zip (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 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:

- Lattice: square or simple cubic.
- Animation speed: very slow, slow, medium, fast, very fast.
- Length: 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000.
- Initialisation.
- Equilibrium option reads from a file a given seed self-avoiding walk which was sampled uniformly at random using the SAW-tree implementation of the pivot algorithm.
- Straight rod is the most commonly
used initial configuration, but it is not very useful if you wish to
see a typical self-avoiding walks of 10000 steps. Note how the
walk diminishes in size as it evolves from typical dimension
*O(N)*to*O(N*.^{ν}) - Random walk option corresponds to seeding the algorithm with a
simple random walk with no immediate reversals. The pivot algorithm as
implemented here then evolves by only allowing updates when the new
walk generated by a pivot move has no more self-intersections than
the current walk. I am not aware of this seed state being used in
the literature, but it could
be regarded as a variant of the Domb-Joyce / weakly avoiding walk
model, where we start at infinitely
high temperature but suddenly cool the system down to the self-avoiding
walk temperature, T=0.
Note how the
walk increases in size as it evolves from typical dimension
*O(N*to^{1/2})*O(N*.^{ν})

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

- Lal (1969) invented the pivot algorithm.
- Madras and Sokal
(1988) studied
the pivot algorithm in depth, and showed for the first time how
powerful it is. Their implementation of the pivot algorithm utilised
a hash table and for an N-step walk takes CPU time
*O(N)*per successful pivot. They applied the pivot algorithm to the calculation of the critical exponent ν for two- and three-dimensional self-avoiding walks. This is the most important paper on the topic, and also serves as an excellent introduction. - Madras, Orlitsky, and Shepp (1990) and Janse van Rensburg, Whittington, and Madras (1990) showed that a variant of the pivot algorithm could be used to sample self-avoiding walks with fixed endpoints, and in particular self-avoiding polygons.
- Li, Madras, and Sokal (1995) accurately calculated ν for two- and three-dimensional self-avoiding walks as well as various amplitude ratios.
- Caracciolo, Pelissetto, and Sokal (1992) and Caracciolo, Causo, and Pelissetto (1998) developed the Join-and-Cut algorithm which utilises pivot moves, and applied it to the estimation of the critical exponent γ for self-avoiding walks.
- Kennedy
(2002) showed that the
pivot algorithm can be implemented in CPU time
*o(N)*for N-step walks. - Clisby
(2010a) and Clisby
(2010b) introduced the SAW-tree
implementation which takes CPU time
*O(log N)*per pivot attempt and used it to estimate the critical exponent ν for self-avoiding walks. - Clisby (2013) accurately calculated the connective constant μ for self-avoiding walks using the pivot algorithm.

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.

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:

- Brute force generation of self-avoiding walks.
- Animation of the SAW-tree intersection testing algorithm, showing how the intersection tests are performed via bounding boxes for successively shorter pieces of the walk.
- New variant of the finite lattice method (link) as applied to the enumeration of self-avoiding polygons on the square lattice.
- BFACF algorithm for sampling self-avoiding polygons.
- Animation of Hamiltonian path generation algorithm (for a generator see this).
- Brute force generation of endless self-avoiding walks (see this).

Statistical mechanics:

- Wolff algorithm for the Ising model on square and simple cubic lattices. (I think this would look beautiful on a 3d lattice if done well.)
- Worm algorithm.
- Sweeny algorithm.
- Hard discs and spheres - various Monte Carlo algorithms including standard Metropolis and the event chain algorithm.

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

- The Hamiltonian path generator generates and then displays Hamiltonian paths and cycles on a grid graph.
- High resolution videos on YouTube of self-avoiding walks with 100 million steps on the square lattice and simple cubic lattice. Both videos look much better in HD, so choose the highest resolution your screen and internet connection will support.
- High resolution 2560x1440 anaglyph (red-blue) 3d videos of walks with 200 million steps: square lattice (100MB) and simple cubic lattice (403MB). To enjoy them you will need to wear red-blue anaglyph glasses, which can be purchased from ebay for a dollar or two. Through the magic of Google Drive these videos can be viewed in your browser as well as downloaded.
- Some high resolution images of self-avoiding walks available here. More to come in future as I have other images floating around.
- Zoomable high resolution images of self-avoiding walks in 2, 3, and 4 dimensions available in my Gigapan self-avoiding walk gallery. The 2d walks are very sparse which makes them hard to see. One future project I have in mind is to create a Processing tool for viewing fractal images which overcomes this problem.
- Preliminary work in creating a game to search for combinatorial objects via a backtracking search tree, in this example Hadamard matrices. In collaboration with Judy-ann Osborn.

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).

- June 28, 2013: Added ability to see ratio of successful pivots to total pivot attempts via pressing 'i'.
- June 28, 2013: Added ability to change the speed of the pivot animation via left and right arrows.
- June 28, 2013: Added ability to zoom in and out of the pivot animation via up and down arrows.
- June 27, 2013: I had trouble following pivot moves for short 3d walks, and so thickened lines for short walks and moved the camera a little further away from the walk. Thicker lines should also improve visibility of walks on poor screens e.g. for seminars and lectures.
- June 27, 2013: Changed menu defaults for pivot algorithm to 5000 step walks on the square lattice.

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.