Anda di halaman 1dari 13

MA579 Homework 5

Xin Zhao

U27066919

Problem 1
a
From Fig. 1 we can see that by correctly setting the reflecting boundary
condition, the molecule is indeed constrained in the cubic box. Confirming that
our code is working correctly.

Figure 1: Random Walk Pathway with Neumann BC

b
In Fig. 2, I included the molecule pathway from 2 simulations. We can see that
both the 2 molecules ended binding to the target site in the center of the cube
but experiencing really different pathway which will leads to different binding
time.

c
By having a much flatter cell, the searching time incresed from 133 to 298. By
setting the cell much flatter, the surface-to-volume ratio of the cell increased
which means increased. In this way, we will have higher chance of fictitious
jump when applying the Neumann BC which will make the searching time
longer.

Page 1 of 13

MA579 Homework 5

Xin Zhao

U27066919

Figure 2: Random Walk Pathway with Neumann BC and binding target

d
By having a much smaller and flat cell, the searching time of the molecule
decreased significantly to 20.17 which makes sense. Small volume means less
mesh points thus less possible state the molecule can be. If this is a cubic
cell with 1/10 of the size as before, we will expect to have a searching time
approximately 13.3/10. However, here we have a flat cell, which , from the
result we gained above, will have longer existing time compared to cubic cell.

Problem 2
Looking at the one-variable TS first

(xi , tn ) + ...
t
(t)2 2
(t)3 3
(xi , tn ) +
(xi , tn ) + ...
2
2 t
6 t3
(t)4 4
(xi , tn ) + O((t)5 )
24 t4

(1)

(x)2 2
(xi , tn ) +
(xi , tn ) ...
x
2 x2
(x)3 3
(x)4 4
(xi , tn ) +
(xi , tn ) O((x)5 )
3
6 x
24 x4

(2)

(xi , tn+1 ) = (xi , tn ) + t

(xi1 , tn ) = (xi , tn ) x

Page 2 of 13

MA579 Homework 5

Xin Zhao

U27066919

Now the two-variable TS

(xi , tn ) + t (xi , tn ) + ...


x
t
2
2
1

2
(x
,
t
)

2
(xi , tn )] + ...
[(x)2
(x
,
t
)xt
+
(t)
i
n
i
n
2
x2
xt
t2
1
3
3
[(x)3 2 (xi , tn ) + 2(x)2 t 2 (xi , tn ) ...
6
x
x t
3
3

(xi , tn ) + (t)3 3 (xi , tn )] + ...


2(t)2 x
xt2
t
4
1

4
(xi , tn ) + ...
[(x)4 4 (xi , tn ) 4(x)3 t
24
x
tx3
4
4
6(x)2 (t)2 2 2 (xi , tn ) 4(t)3 x
(xi , tn ) + ...
t x
xt3
4
(t)4 4 (xi , tn )] O((x)5 ) + O((t)5 )
t
(3)

(xi1 , tn+1 ) = (xi , tn ) x

Then
(xi , tn+1 ) (xi , tn )

=
(xi , tn ) + ...
t
t
2
t
(t)2 3
(x
,
t
)
+
(xi , tn ) + ...
i
n
2 t2
6 t3
(t)3 4
(xi , tn ) + O((t)4 )
24 t4
(xi+1 , tn+1 ) 2(xi , tn+1 ) + (xi1 , tn+1 )
=
2(x)2
1 2
1
3
[(
(xi , tn )] + [2t 2 (xi , tn )] + ...
2
2 x
6
x t
4
1

4
[(x)2 4 (xi , tn ) + 6(t)2 2 2 (xi , tn )+] O((x)3 ) + O((t)3 )
24
x
t x
Similarly
(xi+1 , tn ) 2(xi , tn ) + (xi1 , tn )
=
2(x)2
1 2
(x)2 4
(x
,
t
)
+
(xi , tn ) O((x)3 )
i
n
2 x2
24 x4

Page 3 of 13

(4)

(5)

(6)

MA579 Homework 5

Xin Zhao

U27066919

Thus
(t)2 3

t 2
(x
,
t
)
+
(xi , tn ) ...
(xi , tn ) +
i
n
t
2 t2
6 t3
2
3
1
1

D( [
(xi , tn )] + [2t 2 (xi , tn )] + ...
2
2 x
6
x t
4
4
1
2
(xi , tn ) + 6(t)2 2 2 (xi , tn )+] + ...
[(x)
4
24
x
t x
(x)2 4
1 2
(xi , tn ) +
(xi , tn )) + O(x3 + t3 )
2 x2
24 x4

in+1 =

since the diffusion equation tells us

t (xi , tn )

(7)

= D x
2 (xi , tn )

t (x)2 2
(t)2 3

) 2 (xi , tn )
(xi , tn ) + O(x3 + t3 )
(8)
6
12 t
12 t3
= O(x2 + t2 )

in+1 = (

Problem 3
a
The range of the start time of the second stimuli is approximately from 815 to
899.

Figure 3: When the 2nd stimuli starts too early


From Figure 3 we can see that if the second stimuli starts too early, the
entire wave occur during the refractory period of the first action and it is completely blocked and no wave will be formed. From Figure 4 we can see that if
the second stimuli late which means far after the first wave, its not affected by
the first wave thus a full normal wave pattern will be produced.

Page 4 of 13

MA579 Homework 5

Xin Zhao

U27066919

Figure 4: When the 2nd stimuli starts too late

Figure 5: When the 2nd stimuli starts too early


When the second stimuli starts at 830, we have the second wave starts in the
wake of the first wave so that it is blocked in the direction toward the first wave
since the cells closer to the first wave are not recovered yet. So, no bidirectional
wave. However, it can still propagate away from the first wave and as the tissue
closer to the first wave recovers, the new wave can curl around and propagate in
that direction as well, producing a pair of counter-rotating spiral waves.Thats
why it doesnt form a simple straight wave to one side.

Python Code
Only included code for 1a and 1b, 1c and 1d are similar to that of 1b only
adding a line to save the searching time T [n] = t and compute the mean by
np.mean().

Code for 1a
from __future__ import division

Page 5 of 13

MA579 Homework 5

Xin Zhao

U27066919

import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# number of simulations to run


Nsims = 1
# lattice spacing, units of um, assume dx=dy=dz
# (keep this fixed or else the exit times you get arent comparable!)
h
= .01
#dx dy dz
# length of domain in each coordinate, not used initially, but
# you will use for the homework problem
L
= np.array([1., 1., 2])
# micrometers, E.Coli. size ~ 1x1x1
# lattice indices of initial position
i0
= np.array([0, 0, 0])
# diffusion constant
D
= 1.
# true if you want to plot the spatial path, only use if Nsims=1!
# FOR c) and d) set to False
doPlot = True
# binding site radius and location, only used when you add in binding
Xtarg
= L * np.array([0.5, 0.5, 0.5]) # target is at the center of the domain
targRad = .025
# 50 nanometers in diameter
# time to run simulation until, when you add binding this is only used
# for saving paths as the simulation instead should terminate upon binding.
#tf
= 500.
tf=100. #1(a)
# number of time steps to save at
Nt
= 10**4
####################### End of USER PARAMETERS ############################
# number of mesh points in each coordinate, only used for Neumann BC
# we use the "array" command to convert to an array of integers after rounding
N
= np.array( np.round( L / h ), dtype=int )
# initial spatial position, note we use cell-centered points so shift by h/2
Page 6 of 13

MA579 Homework 5

x0

Xin Zhao

U27066919

= h * i0 + .5 * h

# rates to hop in each of the six possible directions


totrate = 6. * h * h / D
# each row corresponds to hopping in one of the 6 3D directions
jmps
= np.array( [[-1, 0, 0],
[ 1, 0, 0],
[ 0, -1, 0],
[ 0, 1, 0],
[ 0, 0, -1],
[ 0, 0, 1]])
# vector to save the times at which the protein binds for 1b/1c/1d
T
= np.zeros(Nsims)
# how often to save the position (for plotting only)
dt
= tf / Nt
# times to save position at (for plotting only)
times = np.linspace(0., tf, Nt+1)
# square of target radius
targRadSq = targRad * targRad
if doPlot:
# pretty up plots
mpl.rcParams.update({font.size: 12})
mpl.rcParams[axes.labelsize] = 14
mpl.rcParams[lines.linewidth] = 2

# this sets the default font size in plots


# make the xlabel/ylabel text size a bit bigger
# change the default linewidth in plots

# create the figure for 3D curve plotting


fig = plt.figure()
ax = fig.gca(projection=3d)

# run Nsims simulations


for n in range(0, Nsims):
print( "n = " + str(n) + " / " + str(Nsims) )
iloc
t
notDone
X

=
=
=
=

i0
0.
True
x0

#
#
#
#

current lattice indices of molecules position


start simulation at time 0
true when t<tf, or FOR 1b when binding site is found
current position

Page 7 of 13

MA579 Homework 5

Xin Zhao

# if plotting, save path


if doPlot:
Xv
= np.zeros( (Nt+1,3) )
Xv[0,:] = x0
idx
= 1

U27066919

# positions after hops

# until protein finds the target


while notDone:
# time of next hop
t = t - totrate * np.log( np.random.rand() )
# where hop to, as dx=dy=dz, equally likely to be any direction
nxtRx
= np.random.randint(0, 6)
# hop (using lattice indices, not actual position)
iloc
= iloc + jmps[nxtRx,:]
# FOR a), ADD CODE to test if hopped out of domain, and put back
# i.e. enforce Neumann BC at boundary by modifying iloc.
# hint, iloc should have values from 0 to N-1 for each entry in the domain,
# consider using np.maximum and np.minimum to enforce this.
if min(N-1-iloc)<0 or min(iloc)<0 :
iloc=iloc-jmps[nxtRx,:]
else:
iloc=iloc
# update spatial position
Xold = X
X
= iloc * h + .5*h

# FOR b), CHANGE THIS if statement to test if hopped into binding region (Dirichlet BC)
# hint, consider using np.linalg.norm or np.dot
if t > tf:
notDone = False
# save position if plotting and past a time step
if doPlot and ( t > times[idx] ):
Xv[idx,:] = Xold
idx
= idx + 1
if
Nt
l
Xv

idx
=
=
=

>= np.size( times ):


2 * Nt
np.zeros( np.shape(Xv) )
np.concatenate( (Xv, l) )
Page 8 of 13

MA579 Homework 5

Xin Zhao

U27066919

times = np.linspace( 0, tf, Nt+1 )

# FOR b), ADD CODE to add the final position, X, to Xv (for plotting only)
# FOR c), ADD CODE to save the exit time in T
# plot
if doPlot:
# FOR b)/c)/d) COMMENT OUT THIS LINE
idx = idx - 1
# only plot at times that actually occurred in the simulation
Xv = Xv[0:idx,:]
# plot exact paths here
ax.plot( Xv[:,0], Xv[:,1], Xv[:,2], k )
ax.set_xlabel(x)
ax.set_ylabel(y)
ax.set_zlabel(z)
# initial position is green, final position is red
ax.scatter( [Xv[0,0]], [Xv[0,1]], [Xv[0,2]], c=g, s=150 )
ax.scatter( [Xv[-1,0]], [Xv[-1,1]], [Xv[-1,2]], c=r, s=150 )
# FOR a), uncomment this code to zoom in on the box with sides of len L
ax.set_xlim3d(-.1*L[0], 1.1*L[0])
ax.set_ylim3d(-.1*L[1], 1.1*L[1])
ax.set_zlim3d(-.1*L[2], 1.1*L[2])

code for 1b
from __future__ import division
import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# number of simulations to run


Nsims = 1
# lattice spacing, units of um, assume dx=dy=dz
Page 9 of 13

MA579 Homework 5

Xin Zhao

U27066919

# (keep this fixed or else the exit times you get arent comparable!)
h
= .01
#dx dy dz
# length of domain in each coordinate, not used initially, but
# you will use for the homework problem
L
= np.array([1., 1., 1.])
# micrometers, E.Coli. size ~ 1x1x1
# lattice indices of initial position
i0
= np.array([0, 0, 0])
# diffusion constant
D
= 1.
# true if you want to plot the spatial path, only use if Nsims=1!
# FOR c) and d) set to False
doPlot = True
# binding site radius and location, only used when you add in binding
Xtarg
= L * np.array([0.5, 0.5, 0.5]) # target is at the center of the domain
targRad = .025
# 50 nanometers in diameter
# time to run simulation until, when you add binding this is only used
# for saving paths as the simulation instead should terminate upon binding.
#tf
= 500.
tf=10. #1(a)
# number of time steps to save at
Nt
= 250
####################### End of USER PARAMETERS ############################
# number of mesh points in each coordinate, only used for Neumann BC
# we use the "array" command to convert to an array of integers after rounding
N
= np.array( np.round( L / h ), dtype=int )
# initial spatial position, note we use cell-centered points so shift by h/2
x0
= h * i0 + .5 * h
# rates to hop in each of the six possible directions
totrate = 6. * h * h / D
# each row corresponds to hopping in one of the 6 3D directions
jmps
= np.array( [[-1, 0, 0],
[ 1, 0, 0],
[ 0, -1, 0],
[ 0, 1, 0],
[ 0, 0, -1],
Page 10 of 13

MA579 Homework 5

[ 0,

0,

Xin Zhao

U27066919

1]])

# vector to save the times at which the protein binds for 1b/1c/1d
T
= np.zeros(Nsims)
# how often to save the position (for plotting only)
dt
= tf / Nt
# times to save position at (for plotting only)
times = np.linspace(0., tf, Nt+1)
# square of target radius
targRadSq = targRad * targRad
if doPlot:
# pretty up plots
mpl.rcParams.update({font.size: 12})
mpl.rcParams[axes.labelsize] = 14
mpl.rcParams[lines.linewidth] = 2

# this sets the default font size in plots


# make the xlabel/ylabel text size a bit bigger
# change the default linewidth in plots

# create the figure for 3D curve plotting


fig = plt.figure()
ax = fig.gca(projection=3d)

# run Nsims simulations


for n in range(0, Nsims):
print( "n = " + str(n) + " / " + str(Nsims) )
iloc
t
notDone
X

=
=
=
=

i0
0.
True
x0

#
#
#
#

current lattice indices of molecules position


start simulation at time 0
true when t<tf, or FOR 1b when binding site is found
current position

# if plotting, save path


if doPlot:
Xv
= np.zeros( (Nt+1,3) )
Xv[0,:] = x0
idx
= 1

# positions after hops

# until protein finds the target


while notDone:
# time of next hop
t = t - totrate * np.log( np.random.rand() )
Page 11 of 13

MA579 Homework 5

Xin Zhao

U27066919

# where hop to, as dx=dy=dz, equally likely to be any direction


nxtRx
= np.random.randint(0, 6)
# hop (using lattice indices, not actual position)
iloc
= iloc + jmps[nxtRx,:]
# FOR a), ADD CODE to test if hopped out of domain, and put back
# i.e. enforce Neumann BC at boundary by modifying iloc.
# hint, iloc should have values from 0 to N-1 for each entry in the domain,
# consider using np.maximum and np.minimum to enforce this.
if min(N-1-iloc)<0 or min(iloc)<0 :
iloc=iloc-jmps[nxtRx,:]
else:
iloc=iloc
# update spatial position
Xold = X
X
= iloc * h + .5*h

# FOR b), CHANGE THIS if statement to test if hopped into binding region (Dirichlet BC)
# hint, consider using np.linalg.norm or np.dot
if np.sqrt(np.dot(X-Xtarg,X-Xtarg))< targRad:
notDone = False

# save position if plotting and past a time step


if doPlot and ( t > times[idx] ):
Xv[idx,:] = Xold
idx
= idx + 1
if idx
Nt
=
l
=
Xv
=
times =

>= np.size( times ):


2 * Nt
np.zeros( np.shape(Xv) )
np.concatenate( (Xv, l) )
np.linspace( 0, tf, Nt+1 )

# FOR b), ADD CODE to add the final position, X, to Xv (for plotting only)
Xv[-1,:]=X
# FOR c), ADD CODE to save the exit time in T
# plot
if doPlot:

Page 12 of 13

MA579 Homework 5

Xin Zhao

U27066919

# FOR b)/c)/d) COMMENT OUT THIS LINE


#idx = idx - 1
# only plot at times that actually occurred in the simulation
Xv = Xv[0:idx,:]
# plot exact paths here
ax.plot( Xv[:,0], Xv[:,1], Xv[:,2], k )
ax.set_xlabel(x)
ax.set_ylabel(y)
ax.set_zlabel(z)
# initial position is green, final position is red
ax.scatter( [Xv[0,0]], [Xv[0,1]], [Xv[0,2]], c=g, s=150 )
ax.scatter( [Xv[-1,0]], [Xv[-1,1]], [Xv[-1,2]], c=r, s=150 )
# FOR a), uncomment this code to zoom in on the box with sides of len L
ax.set_xlim3d(-.1*L[0], 1.1*L[0])
ax.set_ylim3d(-.1*L[1], 1.1*L[1])
ax.set_zlim3d(-.1*L[2], 1.1*L[2])
# FOR b), uncomment this code to plot the binding sphere:
Nc = 10
for k in range(0, Nc):
th = np.linspace(0, 2*np.pi, 101)
ph = (k * np.pi/(Nc+1) - .5*np.pi) * np.ones( np.size(th) )
ax.plot( targRad*np.cos(th)*np.cos(ph)+Xtarg[0], targRad*np.sin(th)*np.cos(ph)+Xtarg[1],
targRad*np.sin(ph)+Xtarg[2], bo,markersize=10)

# FOR c), add code to calculate mean of exit time


if doPlot:
plt.show()

Page 13 of 13

Anda mungkin juga menyukai