I want to simulate basic cell division using python arrays. I have u, which is an array of arrays as defined by:
n=2 #number of elements that can describe each cell
N=2 # number of cells
u=[np.zeros((n,n)) for i in range(N)]
V=2.0
epsilon=2.0
each u[i] represents a cell in the system and u is the entire system. Next, I define some functions which I will use for my cell division algorithm later.
Mx=np.zeros((n,n))
My=np.zeros((n,n))
for x in range (n):
Mx[x]=x-n/2
for y in range (n):
My[y]=y-n/2
Here I am initializing my cells so they take values of either 1 or 0:
for i in range(N):
for x in range(n):
for y in range(n):
if (x-n/2)**2+(y-n/2)**2<5: u[i][x,y]=1
After I propagate my cell, I want to check for cells that have grown bigger than , let's say, volume V
for i in range (N):
if (np.sum([i]>V):
theta=random.uniform(0, 2*math.pi)
u.append(np.zeros((n,n)))
u[-1]=u[i]/2.0* (1+np.tanh((math.cos(theta)*Mx+math.sin(theta)*My/epsilon))
u[i]=u[i]/2.0* (1-np.tanh((math.cos(theta)*Mx+math.sin(theta)*My)/epsilon))
N+=1
Now I'm saying if my volume is bigger than a specific volume V, then I add a cell to the system (by appending an array of zeros) and I define my two daughter cells as
u[-1]=u[i]/2.0*(1-np.tanh((math.cos(theta)*Mx+math.sin(theta)*My/epsilon))
and
u[i]=u[i]/2.0* (1+np.tanh((math.cos(theta)*Mx+math.sin(theta)*My/epsilon))
where new u[i] array replaces my original one. alternatively, I tried to append two np.zero((n,n)) arrays and defined my two daughter cells as
u[-1] and u[-2]
then deleting the original parent cell with
del u[i]
but that didn't work either. After I run this code, I am getting more arrays in u than I should be getting. If N=2, then I should have N=4 after cell division.
ideally I want my original u array to look something like this:
u=[array([[0,1], [1,0]]), array([[1,1],[1,0]])]
and I want to check if
np.sum(u[0])>V
then I will define two new components into u, namely
u[-1] and u[i]
where the new u[i] replaces the original u[i]
since
np.sum(u[0]) and np.sum(u[1]) are both > V
then my new u array should look similar to this:
u=[array([[1,1], [1,0]]),
array([[1,1], [1,0]]),
array([[1,1], [1,0]]),
array([[1,1], [1,0]])]
(these values in my array are simply example values. The real value depends on my function
u[-1]=u[i]/2.0*(1+np.tanh((math.cos(theta)*Mx+math.sin(theta)*My/epsilon))
u[i]=u[i]/2.0*(1- np.tanh((math.cos(theta)*Mx+math.sin(theta)*My)/epsilon))
I have noticed that the code does not run.
What I think is not correct is:
if (np.sum([i]>V):
to be modified, I guess as if np.sum([i])>V:
One bracket closure missing in:
u[-1]=u[i]/2.0*(1-np.tanh((math.cos(theta)*Mx+math.sin(theta)*My/epsilon))
u[i]=u[i]/2.0*(1+np.tanh((math.cos(theta)*Mx+math.sin(theta)*My/epsilon))
Missing values of V, and epsilon. At least V is required to understand the intended output shape.
Please write an example of the expected output shape in u
to understand what you want to do. Maybe it is better with n = 2
so the size of u
is smaller.
UPDATE: With the new information I think I understand the task better. Please check if the code below makes what you expect.
Check that constant
is the correct equation.
Check that if (np.sum(u[i])>V):
is the correct statement.
import numpy as np
import math
import random
n=2 #number of elements that can describe each cell
N=2 # number of cells
u=[np.zeros((n,n)) for i in range(N)]
V=2.0
epsilon=2.0
Mx=np.zeros((n,n))
My=np.zeros((n,n))
for x in range (n):
Mx[x]=x-n/2
for y in range (n):
My[y]=y-n/2
for i in range(N):
for x in range(n):
for y in range(n):
if (x-n/2)**2+(y-n/2)**2<5: u[i][x,y]=1
lenu = len(u)
for i in range (lenu):
if (np.sum(u[i])>V):
print(u[i], i, u, len(u))
theta=random.uniform(0, 2*math.pi)
constant = np.tanh((math.cos(theta)*Mx+math.sin(theta)*My)/epsilon)
u_end = u[i]/2.0*(1 + constant)
u[i] = u[i]/2.0*(1 - constant)
u.append(u_end)
N+=1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With