How to write a program for pattern formation

15
How to write a program for pattern formation Hans Meinhardt Max-Planck-Institut für Entwicklungsbiologie Tübingen / Germany

description

How to write a program for pattern formation. Hans Meinhardt Max-Planck-Institut für Entwicklungsbiologie Tübingen / Germany. The activator-inhibitor mechanism: how to read the equations. Kybernetik 12, 30-39 (1972). - PowerPoint PPT Presentation

Transcript of How to write a program for pattern formation

Page 1: How to write a program for pattern formation

How to write a program for pattern formation

Hans Meinhardt Max-Planck-Institut für Entwicklungsbiologie

Tübingen / Germany

Page 2: How to write a program for pattern formation

The activator-inhibitor mechanism:how to read the equations

Kybernetik 12, 30-39 (1972)

2 2

2a

a a

a a abD

br

ts a

x

Using our standard equation it should be illustrated how to write a computer program that simulates pattern formation. First it should be mentioned that such equations are easy to read: The equations describe the changes of the activator per time unit. The change of the activator concentration depends on a non-linear positive feedback of the activator on its own production; the inhibitor slows down the activator production. The activator displays normal decay (- ra a) and diffusion. The inhibitor production also depends on the activator concentration in a non-linear fashion. The diffusion of inhibitor is assumed to be much more rapid than that of the activator (Db >> Da). The activator-independent activator production ba is required to initiate the self-enhancing process, e.g. during regeneration.

22

2b b b

b bbr

xa D bs

t

Page 3: How to write a program for pattern formation

Flow diagram

Setting parameters

Setting initial concentration

Calculating changes / new distributions

Display ?

To program such a reaction, one has to discretize the process; the space into units (such as cells) and the time into small time steps. The computer has to calculate the concentration change for each cell at each time step and add this change to the existing concentrations. In this way we obtain the new distribution after a certain time unit. Many such “iterations” gives the complete time course.

Page 4: How to write a program for pattern formation

How to code such a reaction?

ai,t+1 = ai,t + si (ai,t2 + ba) /bi,t

– ra ai,t + Da ( ( ai-1,t - ai,t ) + (ai+1,i – ai,t ) )

The new concentrations in the cells have to be computed sequentially from cell i = 1 to cell n (assuming a linear array of cells) :

This equation has to be re-written as a difference equation: Thus, the new concentration of a cell i ( i = 1…n) at the time t +1 (i.e., after a time unit) is given by the old concentration plus the concentration change according to the equation:

2 2

2a

a ab

aa br D

t

as a

x

1 ni

This is the concentration change per time unit according to our original equation:

Page 5: How to write a program for pattern formation

Handling diffusion

1

Concentrations are stored in arrays, e.g. the activator in

ax(i) , i = 1…n; the actual local concentrations in the cell i are stored in a, b.., e.g. a = ax(i) [Left cell => al (see below)]

Diffusion: Da (aleft cell – aactual cell ) + Da (aright cell – aactual cell )

=> Da ((al – a) + (ax(i+1) – a ))

ni

Important: For calculating diffusion use always non-updated concentrations ! In a sequential updating, the left cell will be already updated, the right cell not. This leads to severe errors. To avoid this problem, the non-updated concentration a is saved as al. During calculation for the next cell, al is used as activator concentration in the left cell, which is the correct non-updated concentration. Note that the present cell will be the left cell when the next cell is calculated.

al ax(i) ax(i+1)

Page 6: How to write a program for pattern formation

Boundary condition

ax(n+1) = ax( n)al = ax(1)

1 n

Boundary condition: impermeable

Special conditions have to be introduced for the cells at the boundaries as they do not have left or right neighbors. Impermeable boundaries can be introduced by assuming virtual cells to the left and to the right of the terminal cells that have the same concentrations as the terminal cells:

(no exchange by diffusion takes place if two cells have the same concentrations, i.e., nothing leaks out at the boundaries)

Page 7: How to write a program for pattern formation

Danger: numerical instability

Da = 1

Da = 0.33

Be careful: the numerical value of the diffusion constant should not exceed a certain limit, otherwise numerical instabilities will occur. In other words, the time steps have to be small enough. In the two examples below a central cell has the concentration one, the neighbors zero. With Da = 1 the central cell would become negative (-2), the concentration of the two others would be one, which is nonsense! In linear calculations Da should be not larger than about 0.4.

Page 8: How to write a program for pattern formation

The code for a BASIC-program

The updating has to proceed in a sequential way in a loop, i is the running index, going from 1 to n (number of cells). First, the array values (e.g., ax(i) for the activator) are stored as local concentrations (e.g., a). Then, the new concentration depending only on the decay and diffusion is calculated (e.g., olddecaydiffuseA), followed by the change due to the reaction.

FOR i = 1 TO n' i = current cell, n = right cella = ax(i) 'local activator-concentrationb = bx(i) 'local inhibitor-concentrations = sx(i) 'local ability to perform the pattern-forming reaction‘REM olddecaydiffA contains the new concentration considering diffusion and decayolddecaydiffA = a - RA * a + DA * ((al - a) + (ax(i + 1) - a))olddecaydiffB = b - RB * b + DB * ((bl - b) + (bx(i + 1) - b))‘ adding the concentration change based on the reaction:ax(i) = olddecaydiffA + s * (a * a + ba) / b ’ updating of the activatorbx(i) = olddecaydiffB + s * a * a ‘ updating the inhibitor concentrational = a: bl = b 'The not yet changed concentrations are used as left cell 'concentrations when the subsequent cell is calculatedNEXT i

Page 9: How to write a program for pattern formation

Activator-Inhibitor Mechanism:

2 2

2a aaa b a

ra

tD

xbas

ax(i) = olddecaydiffA + s * (a * a + ba) / b bx(i) = olddecaydiffB + s * a * a

Thus, the concentration change per time unit as used in the original equation…

…and the code for the new concentrations after a time unit loo very similar and are thus easy to read:

Page 10: How to write a program for pattern formation

To obtain a running program, few additional things have to be done:

KT = 100 'Number of displaysKP = 20 ' number of iterations between the displays‘( KT * KP = number of iterations in total)n = 40 ' number of cellsDA = .01 ' Diffusion of the activatorRA = .02 ' Removal rate of the activatorBA = .001 ' Activator-independent activator production rateDB = .4 ' Diffusion of the inhibitorRB = .03 ' Removal rate of the inhibitor

’ 2. ------- Setting the initial conditions --------------------------KR = 0: AA = 1.2: GA = 1REM KR = 1: AA = 1: GA = 1 ' removal of the REM{ark} leads ' initiation by random fluctuationsFOR i = 1 TO ns(i) = RA * (.99 + KR / 100 * RND)'"Source density" = Production of the'activator, proportional to the decay rate + KR% fluctuationax(i) = GA'general initial activator concentrationbx(i) = 1'general initial inhibitor concentrationNEXTax(n/3) = AA ‘ one cell may have a different concentration

1. Setting parameters

Page 11: How to write a program for pattern formation

To obtain a running program, few additional things have to be done:

‘3. setting boundary conditions (impermeable)

al = ax(1): bl = bx(1): 'al is the concentration in the cell left of the' actual cell. Left-most cell = virtual cell with the same concentrationax(n + 1) = ax(n)' concentration in a virtual cell to the right of thebx(n + 1) = bx(n)' right-most cell is equal to the concentration in the

‘right terminal cell

Page 12: How to write a program for pattern formation

plott: ' REM ----------------Plot -------------LINE (20, 45)-(620, 50), 1, BFx1 = 20' Position of the first rectangleFOR i = 1 TO nx2 = x1 + idxafl = 51 + ax(i) * fa: LINE (x1, 51)-(x2, afl), 2, BF'green=activatorLINE (x1, afl)-(x2, 450), 15, BF 'remaining part white: erase old plotbfl = 51 + bx(i) * fb: LINE (x1, bfl)-(x2, bfl + 10), 12, BFsfl = 51 + s(i) * fs: LINE (x1, sfl)-(x2, sfl + 3), 1, BFx1 = x2:NEXTIF itot >= KT OR INKEY$ > "" GOTO alldone

FOR iprint% = 1 TO KP' Calculations between plots‘-----------' BOUNDARIES IMPERMEABLE ------------al = ax(1): bl = bx(1): 'al is the concentration in the cell left of the' actual cell. Left-most cell = virtual cell with the same concentrationax(n + 1) = ax(n)' concentration in a virtual cell to the right of thebx(n + 1) = bx(n)' right-most cell is equal to the concentration in the

REM ---------- Reactions ------FOR i = 1 TO n' i = current cell, n = right cella = ax(i) 'local activator-concentrationb = bx(i) 'local inhibitor1-concentration

REM ----- Calculation of a new activator and inhibitor concentration in cell iolddecaydiffA = a * (1 - RA) + DA * ((al - a) + (ax(i + 1) - a))olddecaydiffB = b * (1 - RB) + DB * ((bl - b) + (bx(i + 1) - b))

ax(i) = olddecaydiffA + s(i) * (a * a + ba) / bbx(i) = olddecaydiffB + s(i) * a * aal = a: bl = b 'The not yet changed concentrations are used as left cell 'concentrations in the subsequent cellNEXT iNEXT iprint%Itot = itot + 1: GOTO plott

This is the essential part of the program

Page 13: How to write a program for pattern formation

'------------------------------------------------------------' A simple program to simulate biological pattern formation' (C) Hans Meinhardt, MPI TuebingenDEFDBL A-GDEFDBL O-ZDEFINT H-NDEFINT H-N' A simple program to simulate biological pattern formation' (C) Hans Meinhardt, MPI Tuebingen

' i = 1 ... n= Nsumber of cellimax = 640: DIM ax(imax), bx(imax), cx(imax), s(imax)start:'ParameterKT = 100 'Number of displaysKP = 20 ' 'number of iterations between the displays'KT*KP = number of iterations in totaln = 40' number of cellsDA = .01' Diffusion of the activatorRA = .02' Removal rate of the activatorBA = .001 ' Activator-independent activator production rateDB = .4' Diffusion of the inhibitorRB = .03' Removal rate of the inhibitorfa = 60: fb = 40' Scaling factors for display

KR = 0: AA = 1.2: GA = 1REM KR = 1: AA = 1: GA = 1 ' removal of the REM{ark} leads ' initiation by random fluctuationsREM ----------- Initial conditions --------------------------FOR i = 1 TO ns(i) = RA * (.99 + KR / 100 * RND)'"Source density" = Production of the'activator, proportional to the decay rate +KR% fluctuationax(i) = GA ‘ general initial activator concentrationbx(i) = 1 ‘ general initial inhibitor concentrationNEXTax(n / 3) = AA ‘ initial perturbationSCREEN 12: t = TIMER: CLS 'Initialization of graphic and timingWINDOW (1, 1)-(640, 480) ' coordinate systemLINE (1, 1)-(640, 480), 15, BF 'background whiteigraph = 1continuo: ' if calculation is continued...idx = 600 / n: fs = 350 / RA 'Pixel-size of a cellitot = 0

plott: ' REM ----------------Plot -------------LINE (20, 45)-(620, 50), 1, BFx1 = 20' Position of the first rectangleFOR i = 1 TO nx2 = x1 + idxafl = 51 + ax(i) * fa: LINE (x1, 51)-(x2, afl), 2, BF'green=activatorLINE (x1, afl)-(x2, 450), 15, BF 'remaining part white: erase old plotbfl = 51 + bx(i) * fb: LINE (x1, bfl)-(x2, bfl + 10), 12, BFsfl = 51 + s(i) * fs: LINE (x1, sfl)-(x2, sfl + 3), 1, BFx1 = x2:NEXT

IF itot = 0 THENLOCATE 30, 1: PRINT SPACE$(79);LOCATE 30, 1: PRINT " That is the initial situation, green: Activator, red: Inhibitor ";t = TIMER: DO UNTIL TIMER - t > 2: IF INKEY$ > "" THEN EXIT DO:LOOP'END IF

DO UNTIL TIMER - t > .1: LOOP: t = TIMER'slow down if computer is too fastIF itot >= KT OR INKEY$ > "" GOTO alldoneLOCATE 30, 1:PRINT "green = Activator, red = Inhibitor, blue = Source density; any key: stop";

FOR iprint% = 1 TO KP' Calculations between plotsREM ------' boundaries tight ------------al = ax(1): bl = bx(1): 'al is the concentration in the cell left of the' actual cell. Left-most cell = virtual cell with the same concentrationax(n + 1) = ax(n)' concentration in a virtual cell to the right of thebx(n + 1) = bx(n)' right-most cell is equal to the concentration in the

REM ---------- Reactions ------FOR i = 1 TO n' i = current cell, n = right cella = ax(i) 'local activator-concentrationb = bx(i) 'local inhibitor1-concentration

REM ----- Calculation of a new activator and inhibitor concentration in cell iolddecaydiffA = a * (1 - RA) + DA * ((al - a) + (ax(i + 1) - a))olddecaydiffB = b * (1 - RB) + DB * ((bl - b) + (bx(i + 1) - b))

ax(i) = olddecaydiffA + s(i) * (a * a + ba) / bbx(i) = olddecaydiffB + s(i) * a * aal = a: bl = b 'The not yet changed concentrations are used as left cell 'concentrations in the subsequent cellNEXT iNEXT iprint%itot = itot + 1: GOTO plott

alldone:LOCATE 30, 1: PRINT SPACE$(79);LOCATE 30, 1: PRINT "c = continue; s = start again, other key: END";a$ = "": DO UNTIL a$ > "": a$ = INKEY$: LOOP' wait for keySELECT CASE a$CASE "c", "C": GOTO continuoCASE "s", "S":

GOTO startEND SELECTTheEND:LOCATE 30, 1: t = TIMERPRINT ".... a program for simulation of biol. pattern formation;(c) Hans Meinhardt";DO UNTIL TIMER - t > 1: LOOP'-------------------End of the Program-------------------------------

This is the complete program for copy and paste

On our website one can find information how to find the (free) FreeBasic compiler and an appropriate editorhttp://www.eb.tuebingen.mpg.de/de/forschung/emeriti/hans-meinhardt/biuprom.html

Page 14: How to write a program for pattern formation

…and these are screenshots from the display

Green = activator aRed = Inhibitor bBlue = source density of competence s(in this case without random fluctuations, thus a local perturbation is required for initiation.

Page 15: How to write a program for pattern formation

Academic Press (1982)

For more information, visit our websitehttp://www.eb.tuebingen.mpg.de/meinhardt

Awailable for download