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.
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
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)
(xi1 , tn ) = (xi , tn ) x
Page 2 of 13
MA579 Homework 5
Xin Zhao
U27066919
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
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)
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 =
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.
Page 4 of 13
MA579 Homework 5
Xin Zhao
U27066919
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
MA579 Homework 5
x0
Xin Zhao
U27066919
= h * i0 + .5 * h
=
=
=
=
i0
0.
True
x0
#
#
#
#
Page 7 of 13
MA579 Homework 5
Xin Zhao
U27066919
# 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
=
=
=
MA579 Homework 5
Xin Zhao
U27066919
# 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
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
=
=
=
=
i0
0.
True
x0
#
#
#
#
MA579 Homework 5
Xin Zhao
U27066919
# 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
# 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
Page 13 of 13