Squirm3 > playground

The Artificial Chemistry Playground

Welcome to the playground! This is a place where you can learn about artificial chemistries with a few hands-on applets.

Below is a very simple example of an artificial chemistry. A rectangular area contains a number of atoms, wandering around at random. The physics of the virtual world determines how they move about and whether two atoms can occupy the same space. The chemistry determines what happens when two or more atoms bump into each other.

If nothing is happening above then the java applet is not working. Either configure your browser to enable java applets or use a different browser.

In the world above there is no chemistry. The physics tells the coloured atoms to move around at random (on a square grid) and not to occupy the same space but nothing happens when two atoms bump into each other.


The simplest kind of chemistry is to say that certain kinds of atoms become bonded with each other. A bond is a physical link between the two atoms. In real-world chemistry two ions (atoms with the too few or too many electrons for equilibrium) can attain a lower energy state (like a ball rolling downhill) by getting together. In our chemistry we model this on an abstract level by saying that certain atoms form a bond with each other and thereafter cannot move apart.

An example of this is shown below. Everything is the same as the world above but we have added one chemical rule: red atoms bond with yellow atoms. Click the applet to start/stop it. To reset the applet hit your browser's 'reload' button.

An important point is that we do not need to use a 2D square grid - we can vary the physics independently of the chemistry. We could use a 3D grid, or a 2D area with atoms as circles, or a 3D area with atoms as spheres, or whatever. Certain aspects of the way the molecules move will be different in the different physics but often the same overall behaviour will be seen. One effect of using a 2D grid is that a molecule consisting of many atoms bonded together can become stuck because it does not have the flexibility to move - in a different physics this might not be the case.

The red-yellow bonding in the applet above is a simple form of self-organization - in a heat bath the atoms self-organize into clumps of red and yellow atoms. But this isn't very sophisticated behaviour, we need to add more reactions.


With the six coloured atoms we've got there are 21 reactions that bond two atoms together (red-red, red-yellow, red-green, etc.). The applet below lets you try different combinations of these reactions to see their effect. In addition to the 'soup' of random atoms there is one molecule (red-yellow-grey-cyan-green) in the world when it starts. As before, click the applet to stop/start it.

red-red     red-yellow     red-green
red-grey     red-cyan     red-blue
yellow-yellow     yellow-green     yellow-grey
yellow-cyan     yellow-blue     green-green
green-grey     green-cyan     green-blue
grey-grey     grey-cyan     grey-blue
cyan-cyan     cyan-blue     blue-blue
Slowdown: milliseconds

While this is a little bit fun, it is still not possible to get very interesting behaviour. In real-world chemistry atoms do not just keep bonding with each other, they have charge that needs to be equalized. For example, two charged atoms (ions), Na+ and Cl-, will get together if given the chance to form the compound NaCl. This compound has no charge and will not react with any more ions. In our artificial chemistry we can model this abstractly by giving each atom a state : 0, 1, 2 . . .

Using this state value we can model ion bonding very easily, by using the reaction:

red(0) + yellow(0) -> red(1)-yellow(1)

(Meaning that when a red and yellow atom bump into each other they become bonded and both adopt state 1.)

Click the applet below to see this rule in action. All the atoms start in state 0, but when a red and yellow pair is formed they take on state 1 and thus do not react any further. Neat red-yellow pairs form all over the world until either there are no more reds or no more yellows. Hit your browser's refresh button to reset the applet.

Slowdown: milliseconds

This is much more controlled than before, and in fact a lot of sophisticated behaviour has now become possible.


In our final applet on this page you can try any reactions you like. There are ten possible reactions to work with (R1 through to R10), you specify the type (colour) and state of each atom involved. We've given each coloured atom a letter to more easily distinguish them: 'a' for yellow, 'b' for grey, 'c' for cyan, 'd' for blue, 'e' for red and 'f' for green. This might look a bit complicated but move your mouse over the atoms in the applet (better when it's not running) it will show you their type and state (eg a0). Check that the molecule we've added is: e8-a1-b1-c1-f1.

There are also two variables avaialable for use: x and y. These stand for any of the types. For example, if you specify the reaction x0 + x0 -> x1-x1 then atoms of the same type will form pairs. Try this!

Remember:

  • hit 'update applet' to feed-in the new reactions
  • use your browser's 'refresh' button to reset the applet
  • " + " means "not bonded with" and "-" means "bonded with"

Here's something even more fun to try. Supply these two reactions:
e8 + x0 -> e1-x2
x2 + y0 -> x1-y2
and watch what happens. Put the delay to zero if it runs too slowly. After a while all the atoms in the soup are linked in a long wiggly line! (This takes about 10000 timesteps - 10s on my 1.7GHz machine with a zero delay.)

typestatetypestatestatestate
R1:bonded withbecomesbonded with
R2:bonded withbecomesbonded with
R3:bonded withbecomesbonded with
R4:bonded withbecomesbonded with
R5:bonded withbecomesbonded with
R6:bonded withbecomesbonded with
R7:bonded withbecomesbonded with
R8:bonded withbecomesbonded with
R9:bonded withbecomesbonded with
R10:bonded withbecomesbonded with

Slowdown: milliseconds


With these controls you can recreate the reaction-set given in the paper that permits the molecule to self-replicate. The reactions are:
e8 + e0 -> e4-e3
x4-y1 -> x2-y5
x5 + x0 -> x7-x6
x3 + y6 -> x2-y3
x7-y3 -> x4-y3
f4-f3 -> f8 + f8
x2-y8 -> x9-y1
x9-y9 -> x8 + y8

One way to achieve communication is to pass signals along a string. Try this:
x8-y1 -> x8-y8


The source code for these five applets are available - for example if you want to make a bigger version of them, with more atoms. The files are Squirm.java, SquirmCell.java, SquirmCellProperties.java, SquirmCellSlot.java, SquirmChemistry.java, SquirmGrid.java and SquirmReaction.java. They live in these five subdirectories of this page: applet1, applet2, applet3, applet4 and applet5. See the development page for more info.

If you have trouble with any of this please feel free to pester me to improve this page. If you get something clever working that I've not mentioned then email it to me and I will put it up here. All comments are welcome.

tim.hutton@gmail.com.