-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda_growth_janus.py
212 lines (133 loc) · 6.47 KB
/
lambda_growth_janus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# -*- coding: utf-8 -*-
"""
Created on August 10 2016
@author: Inom Mirzaev
"""
from __future__ import division
from constants import mu , Gamma , flow_type, tau_p, gammadot , mu_si, cell_rad
from multiprocessing import Pool
import numpy as np
import deformation as dfm
import move_divide as md
import time , cPickle , os
import dla_3d as dla
def grow_floc( lam , flow_type = flow_type ):
ksi = 6*cell_rad*np.pi *mu_si*lam
sim_step = 1 / gammadot
dt = sim_step / 10
L = np.zeros( [ 3 , 3 ] )
if flow_type == 0:
# Simple shear in one direction
L[0,1] = gammadot
elif flow_type == 1:
# Shear plus elongation flow
L[0,1] = gammadot
L[0,0] = gammadot
L[1, 1] = -gammadot
elif flow_type == 2:
#Elongational flow
L[0,0] = gammadot
L[1, 1] = -gammadot
#L[2, 2] = -gammadot
#L *= 0.1
else:
raise Exception("Please specify a valid flow type")
###########
#Number of generations for to be simulated
num_gen = 8
#Loop adjustment due to number of generation and generation time of a single cell
num_loop = int( tau_p * num_gen / sim_step )
#==============================================================================
# location matrix loc_mat -- coordinate1--coordinate2--coordinate3-- living or
# dead -- age after division
#==============================================================================
shape = 60
scale = 1 / shape
cycle_time = tau_p * np.random.gamma( shape , scale , 10**5 )
floc = dla.dla_generator( num_particles = 5 )
init_loc_mat = np.zeros( ( len(floc) , 7 ) )
init_loc_mat[ : , 0:3 ] = floc
init_loc_mat[ : , 3 ] = 1
deform_radg = np.zeros( num_loop )
deform_cells = np.zeros( num_loop )
loc_mat = init_loc_mat.copy()
axes = np.zeros( ( num_loop + 1 , 3 ) )
G_vector = np.zeros( ( num_loop + 1 , 6 ) )
loc_mat_list = []
frag_list = []
for tt in range( num_loop ):
deform_cells[tt] = len(loc_mat)
#Append loc_mat at each half generation
if np.mod(tt, int( num_loop / 10 ) -1 )==0 or tt == num_loop - 1:
loc_mat_list.append([ loc_mat.copy() , tt])
#==============================================================================
# Since new cells were added we need to change the ellipsoid axis
# in the body frame
#==============================================================================
# set initial radii and return points in body frame
points, radii , shape_tens = dfm.set_initial_pars( loc_mat[ : , 0:3] )
axes[tt] = radii
#Convert shape_tensor to 6x1 vector
G_vector[tt] = dfm.tens2vec( shape_tens )
#==============================================================================
# deform the cell cluster
#==============================================================================
axes[tt+1] , G_vector[tt+1] , Rot = dfm.deform(0 , sim_step , dt , G_vector[tt] , lam , mu , L , Gamma )
dfm_frac = axes[ tt+1 ] / axes[ tt ]
if np.max( dfm_frac ) < 2 and np.min(dfm_frac) > 0.5:
rotation = Rot * dfm_frac
loc_mat[: , 0:3] = np.inner( points , rotation )
#==============================================================================
# move the cells
#==============================================================================
loc_mat = md.hertzian_move( loc_mat , sim_step=sim_step , ksi=ksi )
#radius of gyration
c_mass = np.mean( loc_mat[: , 0:3] , axis=0 )
deform_radg[tt] = ( 1 / len(loc_mat) * np.sum( (loc_mat[: , 0:3] - c_mass )**2 ) ) **(1/2)
#==============================================================================
# divide the cells in loc_mat
#==============================================================================
loc_mat[: , 4] = loc_mat[: , 4] + sim_step
# Cells that have reached cycle time
mitotic_cells1 = np.nonzero( loc_mat[ : , 4 ] > cycle_time[ range( len(loc_mat) ) ] )[0]
# Cells that are not quescent
mitotic_cells2 = np.nonzero( loc_mat[ : , 3] > 0 )[0]
mitotic_cells = np.intersect1d( mitotic_cells1 , mitotic_cells2 )
if len(mitotic_cells) > 0:
loc_mat = md.cell_divide( loc_mat , mitotic_cells , tt)
data_dict = {
'init_loc_mat' : init_loc_mat ,
'loc_mat' : loc_mat ,
'loc_mat_list' : loc_mat_list ,
'frag_list' : frag_list ,
'deform_radg' : deform_radg ,
'deform_cells' : deform_cells ,
'num_loop' : num_loop ,
'axes' : axes,
'G_vector' : G_vector,
'tau_p' : tau_p ,
'sim_step' : sim_step ,
'lam' : lam ,
'mu' : mu ,
'floc' : floc ,
'gammadot' : gammadot ,
'Gamma' : Gamma
}
return data_dict
if __name__=='__main__':
start = time.time()
print time.strftime( "%H_%M" , time.localtime() )
#Usually number of CPUs is good number for number of proccess
pool = Pool( processes = 5 )
#ey_nana = np.array( [1 , 5 , 10 , 15 , 20 ] )
ey_nana = np.array( [ 10 , 20 , 30 , 40 , 50 ] )
if flow_type==2:
ey_nana = np.array( [ 10 , 25 , 50 , 75 , 100 ] )
result = pool.map( grow_floc , ey_nana )
#result = map( deform_floc , ey_nana )
fname = 'data_'+ time.strftime( "_%m_%d_%H_%M_%S" , time.localtime() ) +'_lambda_'+ str( flow_type )+'.pkl'
output_file = open( os.path.join( 'data_files' , fname ) , 'wb')
cPickle.dump(result, output_file)
output_file.close()
end = time.time()
print "Elapsed time " + str( round( (end - start) / 60 , 1) ) + " minutes"