Environment Simulation

In any simulation of life, the surrounding environment in which the life lives must also be simulated to some degree. Life is intimately bound up with its environment, taking in substrates and energy to create copies of itself. At the very least, a simulation of life must include the a source of energy and the building blocks that will be arranged to replicate life. The environment may also contain other organisms which will create competition.

In the simplest simulation an environment could be modelled as homogeneous and unchanging. However, life left to evolve in such an environment is is unlikely to evolve very much. Cells will evolve to replicate a fast as possible given the specific amounts of energy and substrates provided; there is unlikely to many different paths for evolution. Gause’s Law of competitive exclusion suggests that such a system would be unable to support more than one species (i.e. evolution will only find one way to optimise how cells function).

Giving evolution a chance

Although I want my simulation of evolution to be open-ended as possible and not directed in any particular way, I also want to ensure that certain characteristics have the potential to evolve. For example, I would like cells to evolve regulatory systems and signalling pathways. As such, I need make to sure that not only can such proteins be made by the cells (so proteins must be able to bind substrates and other proteins), but also that there is a selective pressure for regulatory systems.

Regulation and signalling are only required if the inputs into the cell (i.e. the environment) change. One way to simulate this would be make the concentration of the cell's building blocks and the amount of available energy fluctuate over time. One simple way we could imagine doing this is to have two substrates, say sugars like glucose and fructose, and have their concentration fluctuate in cycles that are out of sync with one another. This would create a selection pressure for cells to respond to changes in sugar concentrations and alter their gene expression appropriately.

A more complex (and realistic) way to ensure that chemical concentrates change is to create a space in which cells can move and distribute chemicals heterogeneously in this environment. This will also allow cells to interact with one another directly. In my simulation, cells will exist with in a pool of water (which will be two-dimensional, having width and depth). This environment seems best for simple cells to exist and should be simplest to model. Cells will be free to move through the environment and resources will diffuse and flow through the pool. Energy will be provided in the form of light hitting the top of the pool. This light will fluctuate over time, mimicking days and nights. The heterogeneous distribution of chemicals can be induced by adding some simple physics.

Gravity

By introducing gravity and a mass parameter for chemicals, concentration gradients of these chemicals are spontaneously set up. We might then imagine that some cells would stay near the bottom of the pool, where the heavy chemicals are more concentrated while others would prefer the top of the pool and the lighter chemicals. In addition, as light enters the ecosystem from the top of the pool and is absorbed by the water (and later by the organisms ), there will be a concentration gradient for light. We could create a dilemma for the organisms by making a crucial chemical heavy, therefore concentrated in the depths where there is little light for photosynthesis.

Temperature

Another concequence of having a directional light is that there will be a difference in temperature in the environment. This is not only the source of energy for organism, but will affect the rate at which chemical reactions, be they for metabolism or degradation, occur. By having the a light/dark cycle and having the light move over the course of the day, we can introduce variations in temperature that give the organisms something else to cope with. By having a pool with various depths we can introduce further differences as shallow regions will warm up faster than deeper regions. Variations in temperature should also result in currents, which provide further interest in the environment, drawing up nurients from the depths, or requiring organisms to swim against the current to maintain its position in the pool where it is optimum.

Simulation

I have created a fairly flexible (in terms of ease of altering parameter) simulation of a pool of water, with a simple, and hopefully reasonably accurate, simulation of diffusion and gravity. Running the simulation results in warm, less dense water at the top of the pool and cooler, denser water at the bottom. There is a bit too much of a difference (the water at the bottom is about five times as dense), but fiddling with the parameters should easily sort that out. Or maybe I should make it much harder for the water to become so dense (it is almost incompressible after all).

Once that's sorted I want to see if a convection current spontaneously forms if I heat a small area at the bottom of the pool. However, this will require introducing a way for the system to lose heat. The simulation is currently a completely closed system, so if I continually add energy, it will just get hotter and hotter.

Convection currents

I've finally stopped messing about with learning languages, messing about with my blog and sorting out photos, and have done some actual programming. After spending way too much time on what were effectively cosmetic changes to make the code more readable and adaptable, I finally got around to attempting to generate a convection current. Well, first I changed the display system so it always showed the minimum temperature as a deep blue, and the maximum as the lightest blue, and played with the diffusion and gravity constants to get a less extreme difference between the top and bottom of the pool, but after that I got started.

Implementation

First, I had to add some borders to the pool: rock (temperature of 10 degrees – I’m not actually sure whether it should be hotter or colder than the water) at the bottom and edges and air (temperature of 20 degrees, same as the water) on the top. Then I adapted the diffusion system to allow for exchange of energy at the surfaces (but it’s not a true exchange as the temperature of the rock and air is current fixed) and was awed by the ease of adapting Python code. Then it was simply a case of making one of the pieces of rock 80 degrees. The effect, when the grid is a decent resolution (I’m now using a 20 x 12 grid, number fans), is quite pretty, with a bright spot above the heated rock that diffuses up and out over the pool.

Detection

Whether the water is actually forming a current, I can’t yet say for sure. It certainly looks promising. By looking at the density of water in various sectors (using a very simple click-to-display-in-the-command-line-interface), it looks like the water should be moving in the way I would expect, but I’d like to be able to visualise it. There are a couple of ways I can think of doing and I’ll probably implement both. Both will take a bit of work (probably less than I expect because it’s Python), which is why I stopped last night. One way is to simulate the release of a chemical at the point where the water is heated and see where it goes. This should look quite pretty, but I’m not sure how well it will actually show the convection. It would be interesting to see what happens anyhow and at some point I’ll have to add chemicals to the water if I want life to exist there, so I might as well start now. The second way would be clearer, but less useful in the long run and would be to simply draw arrows showing which way the water is moving between each sector. This will require a bit of work because currently, the net flow is not calculated. Instead the individual flows are calculated, and the flows due to diffusion and gravity are separated, so I’d need to sum them. Maybe this could result in a more efficient program, but I’m not convinced.

Future plans

After I have tested to see whether I can actually get currents, then I’d like to add some chemicals, play with their properties (such as their mass and buoyancy) and see what sort of gradients are set up. I’d also like to see whether I can change the shape of the pool from a dull rectangle to something more interesting without too much hassle. The first shape I’d like to try, and what should be easiest, is a pool of two depth, with a shallow half and a deeper half. I’d also like to introduce another ‘element’: light. The idea is that this would come from above and be absorbed by the water, heating it. Some would make to it the bottom of the pool (especially a shallow end, should there be one), heating that too. Then I would have to model the heat of the rock in a more sophisticated way, to allow it to change and also diffuse (I’m hoping I can co-opt the water diffusion equations for that). From there I can model light with varying intensities. Firstly, a simple light-dark, day-night cycle, and later a light that moves across the sky. Is this going too far? Am I just wasting time so I can put off the hard part of modelling the actual cell?

Convection current analysis

Arrows indicate the movement of water. Colour indicates pressure.

I wrote previously about a very simple simulated environment I had created, which was basically a rectangular body of water, split into discrete sectors. Each sector of water had a number of particles (molecules of water) and a temperature. Based on these values, the particles moved between sectors; the more particles or the higher the temperature, the more particles would leave a sector. Gravity also acted to move particles downwards, which particles with a higher energy (temperature), would be more likely to avoid. To close the system, the water was surrounded by invisible sectors of air on top and rock on the sides and bottom, which had a fixed temperature (which allowed the system to lose energy when I later heated up a block).

If the simulation was left for a while, the result was that sectors lower down were colder and more dense (contained more particles), as one would expect I have since added the ability to arrows that indicate the net direction and amount of water moving between each neighbouring sector, so currents can be seen. If a single sector of rock is heated to about four times the temperature than the water, a convection current is induced, as the image above shows. In fact, at first what happens is that there is an explosion, as shown in the video clearly demonstrates. I guess this is quite a realistic simulation of what would happen if you could instantaneously heat the bottom of a pool of water to four times the surrounding temperature.

N.B. The video shows temperature, while the picture at the top shows pressure, hence the different appearance.

Building simulation actually helped me to better understand a few principles of physics I assumed that I already understood, such as the concept that heat rises. The question is: why? I had thought it was because the particles have more energy, and are therefore more likely to overcome the pull of gravity compared to colder particles, which is true. However, when you heat a sector of water, you increase the number of particles moving in all directions. In fact, there will be a greater increase in the number of particles moving sideways than there are moving up. The reason, the simulation ends up with a net movement of particles upwards rather than sideways is because the pressure of the sectors on either side is much higher, whereas the pressure of sectors above are lower. The reason for this is of the particles moving upwards, more are likely to have a high energy than those moving sideways. I’m not sure how well I’ve explained this, but I feel than in simulating this simple phenomenon I have gained a much deeper understanding of what is going on at a molecular level.

A more challenging environment

The motivation behind creating such a ‘universe’ is to so I have somewhere where simulated cells can exist. The idea is that the universe will contain different niches that organisms can adapt to. For example, organisms might adapt to different temperatures. If metabolites have different buoyancies, they will accumulate in different areas, and organisms would hopefully adapt to preferring different metabolite concentrations. However, the number of niches in this simulation would be very limited, so I’ve started to create a more ambitious model.

In this model, additional niches were created by creating, different depths to the water. On the surface, this might not seem to create any further niches since it is removing sectors. However, I’m also changing the way the universe get energy. While a heated sector at the bottom of the pool of water might be a good simulation of a black smoker, I wanted a more familiar environment, heated by the sun. Therefore, in my new simulation light enters the simulation from the top. It is partially absorbed by the a few sectors of air, and sectors of water, and what remains is absorbed by the rock. Absorbing light causes the sectors to gain energy, which they can then radiate to other sectors. The rock in the shallows therefore heat up quickly, warming the water above, while the rock in the depths sees little light and remains cool.

The addition of light to the simulation will provide energy for my cells which will do the equivalent of photosynthesis. In addition, I added a day-night cycle to the light, so intensity increases for the first half of the day, and decreases in the second half, as indicated by the colour and position of the sun that looks like it was drawn by a child. Half the simulation is then spent in the dark. This will hopefully provide the selection pressure for regulatory systems to evolve, and perhaps create organisms that specialise at using different intensities of light. Below shows the simulation early in morning with a low sun (though the angle of light doesn’t change), beginning to warm the sectors. Due to the starting parameters, the rock is being cooled by the water. The rock is much cooler along the bottom as below, off the bottom of the simulation are sectors with a fixed temperature. Unlike the previous simulation, the sector on the far right are now considered to neighbour those on the far left.

Later in the day, the light has warmed the exposed rock, which is warming the water (which for the most part, isn’t warmed directly by the sunlight). The air above the rock has also begun to warm. Currently, particles are unable to move between sectors (though energy can be transferred between sectors). This is why the rock is efficiently conducting heat, while air (which is a poor conductor) is efficiently insulating the rock at surface. Later I hope to add the particle-movement equations from the previous simulation to this one, and see what currents can be generated. By allowing water particles to move into sectors of air, I can also create my own weather simulation by tracking temperature and humidity. This should provide a very stimulated environment for any virtual organisms.

In creating this simulation, I had to find a simple way to store the layout of the environment, which I have currently saved as an array of letters standing for Air, Water or Earth. I also finally found a question that Wolfram Alpha can answer: how many atoms are there in a 1m cubed of air? It could even answer the same question for earth (once I was more specific and asked about limestone, which it converted to chalk, but I’m not complaining). I had to go to Wikipedia to find thermal conductances for various materials however. Wolfram Alpha was also a bit hit-and-miss when it came to specific heat capacity, a property that I vaguely remembered from GCSE physics and have been learning about again. I decided to simplify things by make specific heat capacity a function of the number of atoms in an area, thought this doesn’t work well with air, which has a much hight specific heat capacity than its density ought to allow. Again, I’m learning that I don’t understand these simple physical phenomena as well as I first thought. I was pleased to discover, however, that the ratio of conductances for earth, water and air I was using in my simulation, we essentially spot on (namely 1:0.2:0.01 for earth:water:air).

This simulation could easily end up a lot more complex than I first intended and there is much more I still would love to add (e.g. reflecting light, which means I need to find the albedo of earth, water and air). This would result in a very slow simulation. However, I’m currently looking into using the GPU, which should speed things up hugely and might not be too difficult. I will have to write about my experiences attempting to use my GPU for my image evolution algorithm some other time. The result of my experimentation is that there is no easy way to do with my graphics card, but it should be doable on Victoria’s computer (and maybe I should get a new computer).