Evolution can create a huge diversity of organisms, but they are all constrained by physics and chemistry. Organisms can never evolve to synthesise novel elements, to generate energy from nothing or to travel faster than light. One of the (few) things that disappointed me about the game Creatures, was that because of the way that enzymes were defined, one of my creatures evolved to synthesise starch from nothing, so never had to eat.
In my simulation, I want cells to be constrained by a realistic chemistry. However, I don't intend to attempt to simulation real-life chemistry; that would be too computationally complex and not necessarily useful for a simulation of evolution. Instead I intend to invent my own simple chemistry, defining all the chemicals that can exist and all the reactions that can inter-convert between them.
With chemistry defined, organisms will have to evolve ways to exploit it to their own ends. I want to avoid defining specific chemicals as 'food' or sugars and instead allow organisms to metabolise whatever suits them. For example, if a large quantity of a waste product is produced by one organism, another might evolve to exploit that concentration gradient.
In my virtual universe there are eight elements, which I've given unimaginative one-letter names [N.B. I use different letters later in my blog and am in the process of updating everything] and arranged in a simple 4 by 2 periodic table.
The elements could represent atomic elements, but they could equally represent functional groups, such as an organic acid group, it's not really important. I arranged them in a table to indicate that elements that in the same column are chemically similar. The properties of elements, such as their stability is also related to their position in the table.
As in our universe, elements can combine to form compounds, but not all combinations of chemicals are possible. In my universe, there are 12 two-element compounds formed by either combining elements from column 1 with elements from column 4 (e.g. AH) or by combining elements from column 2 with elements from column 2 or 3 (e.g. FC or BB). The relative stability of compounds is a function of the properties of the elements.
Since this is a biological simulation, all reactions will occur in water. Water is not defined in the same way as other chemicals in the simulation, but instead a Solution object is defined. This object has a volume property, which defines how many units of water it consists of, and a dictionary of the chemicals it contains. For example, we create a pool of 64 000 units of water like so:
from solutions import Solution pool = Solution(volume=64000)
We can then add 1000 units of chemical AD:
The Cell object inherits from the Solution object because a cell is essentially just a bag of water containing some chemicals (plus DNA and proteins, which are defined separately in this simulation).
Having defined all the possible chemicals in the universe (elements and compounds), I defined all the ways to convert one into another. There are three classes of reaction and they are all reversible.
1. Hydrolysis / Synthesis reactions
In these reactions a compound is split into its constituent elements (or two element combine to form a compound). For example, AD ⇌ A + D
2. Transferase reactions
In these reactions an element reacts with a compound and replaces one of the constituent elements of that compound. For example, AD + H ⇌ AH + D
3. Mutual transferase reactions
In these reactions two compounds reacts and swap constituent elements. For example, AD + EH ⇌ AH + ED
Below is a diagram showing the four possible reactions that compound AD can undergo.
Each reaction (forward and backward) has a rate constant which is calculated based on the relatively stability of the chemicals involved. The rate constant determines how fast a reaction occurs and the ratio of the rate constants for forward and backward reactions implicitly determines where the equilibrium of a reaction lies. I'll explain more how this works in the section about enzymes since I've decided to allow reactions to occur only in the presence of an enzyme that can catalyses it (i.e. no reaction occurs spontaneously).