Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Biophysics 2S03

NetLogo Assignment #1


SIMULATION OF BROWNIAN MOTION

Goal: The goal of this tutorial is to simulate the Brownian motion of diffusing particles, and to characterize their dynamics by plotting their mean-squared displacement.


Deliverable: When you are finished, submit the .nlogo file containing the program you have written in the Dropbox on Avenue to Learn, and a document containing answers to the orange questions below on Crowdmark. You will get a mark based both on your code and the answer to these questions. Note that section 4 (including question 11) are optional - you do not need to complete this question to get a perfect mark (but you might get bonus marks if you do). Sections 1, 2 and 3 (including questions 1 to 10) on the other hand, are mandatory.


Remember: Part of the note you will receive for your code will reflect how clear this code is.

So before submitting your code, don’t forget to:

Fill out the Info tab. Once in the Info tab, use the Edit command at the top to add information in the different sections. Explain very briefly (one sentence per section will be more than enough) what your model does (What is it?), what are the rules your turtles are following (How it works), what is the function of the different items found in your interface tab (How to use it), etc… Sections can be left blank if they are not relevant to your model.

Annotate your code, by using the symbol “;” to introduce comments to label all the main parts of your code.


Tips:

- All NetLogo commands are listed and explained at http://ccl.northwestern.edu/netlogo/docs/ dictionary.html

- Remember that, whenever you modify your code, you can check whether it contains any grammatical error by pressing the “Check” icon at the top of the Code window.

- If you see your program regularly with different version name (version1, version2, etc…), it will allow you to go back to a “working version” if you mess things up at any point.

- Each time you introduce a new variable, you need to define it at the beginning of the program as a “globals”, “turtles-own” or “patches-own variable. The exception to this rule is that, if a variable is defined in a Slider, it doesn’t need to be defined again in the code.


Short Lexicon:

- Particles are called “agents” or “turtles”

- Quantities (variables) can be:

- “globals” : if they pertain to all agents (for example their average position)

- “turtles-own”: if they take a different value for each agent (for example their distance from the origin). Some are predefined: e.g. heading

- “patches-own”: if they pertain to the spatial position of your 2D space (for example, the concentration of particles at that point).

- To define several new globals variable called “a”, “b” and "c" just include the following command at the very beginning of your code (a similar procedure can be use to define turtles-own and patches-own variables:

globals [ a b c]

- To define a command (i.e. a set of instruction that you can call with a single word, for example here the “setup” command activated by the “setup” button on the Interface panel) just write:

to setup

instruction 1

instruction 2

instruction 3

end

- To apply a set of instructions to each of the turtles in the simulation one after the other, write:

ask turtles [

instruction A

instruction B

instruction C

]

- To assign the value 1230 to a variable named largenumber, write:

set largenumber 1230

- To order the simulation to do A or B depending on whether a statement P is true:

ifelse P [A] [B]

For example: ifelse largenumber > 1 [Print “Yes!”][Print “No!”]


1 - BROWNIAN MOTION OF A SINGLE PARTICLE

1a. Setting up your model

Open NetLogo and start a new model (File > New).

In the Interface tab, add a setup button.

In the Code tab, write the corresponding setup procedure to create a single "turtle" in the centre of the simulation window (that is at position x= 0 and y = 0). Do not forget to add the “clear-all” and “reset-ticks” commands in your setup procedure.

Make the background of the simulation window white by asking the patches to change the value of pcolor to white


1b. Setting the particle in motion

You are now going to write the instructions related to the motion of the turtle. Particles undergoing Brownian motion follow a random walk, with can be modelled by a series of steps of constant length, a, each taken in a completely random direction.

In the Interface tab, add a go button. Remember to make it a “Forever" button so that the orders you are going to include in that procedure are repeated over and over again.

Add a slider to let the user control the random walk’s step size, a. Make sure you chose an appropriate range of step size, given that the world the turtle will evolve in has dimensions 32 x 32 (the turtle should not reach the edge of the world too quickly).

In the Code tab, write a go procedure that tells the turtle to 1) chose a random direction and 2) move forward by a distance equal to the length of the step controlled by the slider you just added (you did something very similar in section 3b of your previous NetLogo tutorial). Do not forget to include the command “tick" in your go procedure.

Check that your turtle does something that looks like Brownian motion when you press the “go" button (you might have to run the simulation “slower" to follow the motion of the turtle).

Use the command “pen-down” in the setup procedure to visualize the trajectory of your turtle.

Add the command: "if ticks = 1000 [stop]” in your go procedure to run the simulation only for a limited number of steps (here 1000 - chose a different number if you want).

Question 1: Run your model for two different values of the step sizes, and export the resulting simulations (control click on the simulation windows, then chose “Export View” and save the image) to include in your report. What do you notice in terms of the surface area covered by the turtles in each case?


1c. Plotting the displacement of the particle

You are now going to add two plots to the figure, a first one that shows the displacement of the particle along the x-axis, and a second one that shows its squared-displacement.

In the Code tab, define a turtles-own variable called “xd” (for “displacement along the x-axis”) and another one called "sd" (for "squared displacement”). This declaration should be made at the very beginning of your program, before the setup and go procedures.

In the go procedure, ask the turtle to calculate, after each step, the values of “xd" (how much the turtle has moved along the x axis since the beginning of its trajectory) and “sd" (the square of the total displacement of the particle, both in the x-direction and y-direction). You will need to use the value of the turtle’s coordinates (xcor and ycor).

Add a plot to the Interface tab. Name it “displacement”, and label the axes “time" and “displacement”. To plot the displacement of the turtle, replace “count turtles" by "[xd] of turtle n", where n is the who number of your turtle. If you do not know what the who number of the turtle is, control-click on the turtle.

Repeat the same procedure to add a plot of the turtle’s squared displacement.

Question 2: What do you expect the mean displacement of a particle undergoing Brownian motion to be? What do you expect its mean-squared displacement to be?


2 - BROWNIAN MOTION OF AN ENSEMBLE OF PARTICLES

In order to obtain average values for the displacement and squared displacement, we are now going to observe the motion of many Brownian particles in parallel.

Modify your program so that N particles are created instead of just 1, where N is an integer that can be chosen by the user.

As it might become messy to track the trajectories of many turtles, modify your setup procedure so that only one turtle (for example the turtle with who = 0) has its pen-mode set to down.

In the displacement plot, replace "[xd] of turtle 0" by “mean [xd] of turtles” to plot the average displacement of the turtles (where the average is taken over the whole turtle population), as a function of time (where n ticks corresponds to a time of n).

Repeat this operation for the second plot, in order to visualize the average squared displacement (known as “mean-squared displacement”) of the turtles.

Question 3: When you run your model, do the average displacement and mean-squared displacement have the form that you expect (see your answer to question 2)?

Question 4: Run your model for a chosen value of a and N, and export the data obtained for the mean-squared displacement (for this, control-click on the mean-squared displacement plot, then chose “Export”, then save the .csv file). Use Excel, or an equivalent program, to plot your data, and fit it to a linear function.

Question 5: Estimate how long it will take for a turtle to reach the border region on average (in number of ticks, just give an estimate).

Question 6: What happens when the turtles reach the border region? How does that affect the value of the displacement and squared-displacement that you measure? Does this happen at the time you expect?


3 - DIFFUSION COEFFICIENT OF THE PARTICLES

Question 7: What is the formula that relates the mean-squared displacement of a Brownian particle and its diffusion coefficient, D (for two-dimensional trajectories)?

Add a monitor window to your Interface tab, and chose the Display Name “Diffusion coefficient”. In the Reporter field of this window, enters a formula that will return the value of the particle’s diffusion coefficient in μm^2/s (for this, we will imagine that each patch is 1 μm in size, and that each tick represents 1s - in other words, if you set a = 1, then the particles take a step of length 1 μm every second).

Run your model to check that you obtain a value of the diffusion coefficient that is more or less stable in time. You might want to adjust the value of the number of steps for which you run the model to make sure that the particles do not reach the edges of the simulation window, or (even better) insert a line in your program that stops the simulation as soon as a particle reaches the border so that the measurement of the diffusion coefficient is not affected.

Question 8: Run your model for different values of the step size (a), and write down the value of the diffusion coefficient (D) that you obtain each time. Plot D as a function of a.

Question 9: Can you tell from your data what is the dependence of D on a? Remember that plotting log(D) as a function of log(a) can help you find out what the nature of this dependence is (linear, quadratic, exponential, etc…)

Question 10: Is the dependence you uncovered in question 9 what you would expect for a random walker?


4 - BROWNIAN MOTION IN A HETEROGENOUS ENVIRONMENT

In this part, we will model a heterogenous environment and test the hypothesis that particles accumulate in places where they diffuse more slowly. Imagine that your simulation window represents a square section in a cell membrane, and that the turtles are diffusing proteins.

Chose a region in your membrane (for example, a circular region in the centre of the simulation window, or the region comprised between two values of x) where the particles will diffuse more slowly. In your setup procedure, color this region in a different color from the rest of the “membrane”.

Define a patches-own variable called slowdown, and attribute a value slowdown = 1 for all patches, except the ones in your chosen region, where you can set slowdown = s, where s is a variable comprised between 0 and 1, chosen by the user.

Modify the instructions to the turtles in your go procedure, so that the size of a step is now: a * slowdown (so that the turtles now diffuse more slowly in the regions where slowdown is less than 1).

Run your model long enough so that the system equilibrates.

Question 11: Is our hypothesis (particles accumulate in a places where they diffuse more slowly) correct? (Tip: you might want to create your turtles in a part of the simulation window outside of the slow diffusion area in order for the system to equilibrate faster).