def set_next_state( self, next_state_array, close_point_smoothness_factors, x_cils, x_coas, ): self.tpoint += self.dt self.insert_state_array_into_system_history(next_state_array) verts = self.curr_state[:, [parameters.x_ix, parameters.y_ix]] edge_displacement_vectors_plus = geometry.calculate_edge_vectors(verts) edge_lengths = geometry.calculate_vec_mags( edge_displacement_vectors_plus) self.curr_state[:, parameters.edge_lengths_ix] = edge_lengths self.curr_state[:, parameters.old_x_coa_ix] = x_coas self.curr_state[:, parameters.old_x_cil_ix] = x_cils # ================================== if self.tpoint == self.next_randomization_event_tpoint: self.next_randomization_event_tpoint += 1200 # randomization event has occurred, so renew Rac kgtp rate # multipliers self.rac_rands = \ self.renew_rac_rands( self.tpoint) # store the Rac randomization factors for this timestep self.curr_state[:, parameters.rac_rands_ix] = self.rac_rands # ================================== rac_acts = self.curr_state[:, parameters.rac_act_ix] rho_acts = self.curr_state[:, parameters.rho_act_ix] self.curr_state[:, parameters.old_x_cil_ix] = x_cils self.curr_state[:, parameters.old_x_coa_ix] = x_coas rac_cyto = (1 - np.sum(rac_acts) - np.sum(self.curr_state[:, parameters.rac_inact_ix])) rho_cyto = (1 - np.sum(rho_acts) - np.sum(self.curr_state[:, parameters.rho_inact_ix])) insertion_array = np.zeros(16) insertion_array[0] = 1 self.curr_state[:, parameters.rac_cyto_ix] = (rac_cyto * insertion_array) self.curr_state[:, parameters.rho_cyto_ix] = (rho_cyto * insertion_array) sum_forces, edge_forces_plus, edge_forces_minus, uevs, rgtp_forces, \ cyto_forces, \ edge_strains, local_strains, unit_inside_pointing_vecs = \ mechanics.calculate_forces( verts, rac_acts, rho_acts, self.rest_edge_len, self.stiffness_edge, self.halfmax_vertex_rgtp, self.const_protrusive, self.const_retractive, self.rest_area, self.stiffness_cyto, ) self.curr_state[:, parameters.local_strains_ix] = local_strains edgeplus_lengths = geometry.calculate_edgeplus_lengths(verts) avg_edge_lengths = geometry.calculate_average_edge_length_around_nodes( edgeplus_lengths) conc_rac_acts = chemistry.calc_concs(rac_acts, avg_edge_lengths) conc_rho_acts = chemistry.calc_concs(rho_acts, avg_edge_lengths) self.curr_state[:, parameters.rac_rands_ix] = self.rac_rands kgtp_racs = chemistry.calculate_kgtp_rac( conc_rac_acts, self.halfmax_vertex_rgtp_conc, self.kgtp_rac, self.kgtp_rac_auto, x_coas, self.rac_rands, x_cils, close_point_smoothness_factors, ) kdgtps_rac = chemistry.calculate_kdgtp_rac( conc_rho_acts, self.halfmax_vertex_rgtp_conc, self.kdgtp_rac, self.kdgtp_rho_on_rac, x_cils, self.halfmax_tension_inhib, self.tension_inhib, np.array([ls if ls > 0 else 0.0 for ls in local_strains]), ) kdgtps_rho = chemistry.calculate_kdgtp_rho( conc_rac_acts, self.halfmax_vertex_rgtp_conc, self.kdgtp_rho, self.kdgtp_rac_on_rho, ) kgtp_rhos = chemistry.calculate_kgtp_rho( conc_rho_acts, x_cils, self.halfmax_vertex_rgtp_conc, self.kgtp_rho, self.kgtp_rho_auto, ) self.curr_state[:, parameters.kgtp_rac_ix] = kgtp_racs self.curr_state[:, parameters.kgtp_rho_ix] = kgtp_rhos self.curr_state[:, parameters.kdgtp_rac_ix] = kdgtps_rac self.curr_state[:, parameters.kdgtp_rho_ix] = kdgtps_rho # update mechanics parameters self.curr_state[:, [ parameters.sum_forces_x_ix, parameters.sum_forces_y_ix ]] = sum_forces self.curr_state[:, [parameters.edge_forces_plus_x_ix, parameters.edge_forces_plus_y_ix]] = \ edge_forces_plus self.curr_state[:, [parameters.edge_forces_minus_x_ix, parameters.edge_forces_minus_y_ix]] = \ edge_forces_minus self.curr_state[:, [ parameters.rgtp_forces_x_ix, parameters.rgtp_forces_y_ix ]] = rgtp_forces self.curr_state[:, [ parameters.cyto_forces_x_ix, parameters.cyto_forces_y_ix ]] = cyto_forces self.curr_state[:, [parameters.uiv_x_ix, parameters. uiv_y_ix]] = unit_inside_pointing_vecs self.curr_verts = verts
def __init__( self, cell_group_ix, cell_ix, params, dt, ): self.cell_group_ix = cell_group_ix self.cell_ix = cell_ix self.num_int_steps = params["num_int_steps"] self.dt = dt self.tpoint = 0.0 self.num_cells = params["num_cells"] self.tot_rac = params["tot_rac"] self.tot_rho = params["tot_rho"] self.curr_state = np.zeros(( 16, len(parameters.output_info_labels), )) self.length = params["l"] self.t = params["t"] self.f = params["f"] self.vertex_eta = params["vertex_eta"] self.curr_verts = params["init_verts"] self.radius_resting = params["cell_r"] self.rest_edge_len = params["rest_edge_len"] edgeplus_lengths = geometry.calculate_edgeplus_lengths(self.curr_verts) self.init_average_edge_lengths = np.average( geometry.calculate_average_edge_length_around_nodes( edgeplus_lengths)) self.rest_area = params["rest_area"] # ====================================================== self.close_zero_at = params["close_zero_at"]**2 self.close_one_at = params["close_one_at"]**2 self.kgtp_rac = params["kgtp_rac"] self.kgtp_rac_auto = params["kgtp_rac_auto"] self.halfmax_vertex_rgtp = params["halfmax_vertex_rgtp"] self.halfmax_vertex_rgtp_conc = params["halfmax_vertex_rgtp_conc"] self.kdgtp_rac = params["kdgtp_rac"] self.kdgtp_rho_on_rac = params["kdgtp_rho_on_rac"] self.halfmax_tension_inhib = params["halfmax_tension_inhib"] self.tension_inhib = params["tension_inhib"] self.k_mem_off = params["k_mem_off"] self.k_mem_on_vertex = params["k_mem_on_vertex"] self.diffusion_rgtp = params["diffusion_rgtp"] # ====================================================== self.kgtp_rho = params["kgtp_rho"] self.kgtp_rho_auto = params["kgtp_rho_auto"] self.kdgtp_rho = params["kdgtp_rho"] self.kdgtp_rac_on_rho = params["kdgtp_rac_on_rho"] # ============================================================== self.cil_mag = params["cil_mag"] self.coa_mag = params["coa_vertex_mag"] self.coa_distrib_exp = params["coa_distrib_exp"] self.coa_los_penalty = params["coa_los_penalty"] # ============================================================= self.stiffness_edge = params["stiffness_edge"] self.stiffness_cyto = params["stiffness_cyto"] self.const_protrusive = params["const_protrusive"] self.const_retractive = params["const_retractive"] # ============================================================= self.phase_var_indices = [ parameters.rac_act_ix, parameters.rac_inact_ix, parameters.rho_act_ix, parameters.rho_inact_ix, parameters.x_ix, parameters.y_ix, ] self.num_phase_vars = len(self.phase_var_indices) self.total_num_phase_vars = self.num_phase_vars * \ 16 self.initialize_phase_var_indices() # ============================================================= self.rand_avg_t = params["rand_avg_t"] self.rand_std_t = params["rand_std_t"] self.rand_mag = params["rand_mag"] self.num_rand_vs = params["num_rand_vs"] self.randomization = params["randomization"] self.rac_rands = self.renew_rac_rands(0) self.next_randomization_event_tpoint = 1200 # ============================================================= self.all_cellwide_phase_var_indices = [ parameters.rac_cyto_ix, parameters.rho_cyto_ix, ] self.ode_cellwide_phase_var_indices = [] self.num_all_cellwide_phase_vars = len( self.all_cellwide_phase_var_indices) self.num_ode_cellwide_phase_vars = len( self.ode_cellwide_phase_var_indices) self.initialize_all_cellwide_phase_var_indices() self.initialize_ode_cellwide_phase_var_indices() # ============================================================= self.pars_indices = [ parameters.kgtp_rac_ix, parameters.kgtp_rho_ix, parameters.kdgtp_rac_ix, parameters.kdgtp_rho_ix, parameters.local_strains_ix, parameters.old_x_cil_ix, ] self.initialize_pars_indices() # ============================================================= self.init_inact_rgtp = params["init_inact_rgtp"] self.init_act_rgtp = params["init_act_rgtp"] self.rgtp_distrib_def_for_randomization = [ "unbiased random", 0.0, 0.0, ] self.init_rac = params["init_rac"] self.init_rho = params["init_rho"]
def cell_dynamics( focus_verts, tpoint, int_step, dt, writer, cell_ix, state_array, num_cells, all_cells_verts, num_phase_vars, rac_act_ix, rest_edge_len, rac_inact_ix, rho_act_ix, rho_inact_ix, x_ix, y_ix, kgtp_rac, kdgtp_rac, kgtp_rho, kdgtp_rho, kgtp_rac_auto, kgtp_rho_auto, kdgtp_rho_on_rac, kdgtp_rac_on_rho, k_mem_on_vertex, k_mem_off, halfmax_vertex_rgtp_conc, diffusion_rgtp, vertex_eta, stiffness_edge, halfmax_vertex_rgtp, const_protrusive, const_retractive, rest_area, stiffness_cyto, x_coas, close_point_smoothness_factors, x_cils, halfmax_tension_inhib, tension_inhib, rac_rands, coa_updates, cil_updates): phase_vars = state_array rac_mem_active_start_ix = rac_act_ix * 16 rac_mem_active_end_ix = rac_mem_active_start_ix + 16 rac_acts = phase_vars[rac_mem_active_start_ix:rac_mem_active_end_ix] rac_mem_inactive_start_ix = rac_inact_ix * 16 rac_mem_inactive_end_ix = rac_mem_inactive_start_ix + 16 rac_inacts = phase_vars[rac_mem_inactive_start_ix:rac_mem_inactive_end_ix] rho_mem_active_start_ix = rho_act_ix * 16 rho_mem_active_end_ix = rho_mem_active_start_ix + 16 rho_acts = phase_vars[rho_mem_active_start_ix:rho_mem_active_end_ix] rho_mem_inactive_start_ix = rho_inact_ix * 16 rho_mem_inactive_end_ix = rho_mem_inactive_start_ix + 16 rho_inacts = phase_vars[rho_mem_inactive_start_ix:rho_mem_inactive_end_ix] x_start_ix = x_ix * 16 x_end_ix = x_start_ix + 16 x = phase_vars[x_start_ix:x_end_ix] y_start_ix = y_ix * 16 y_end_ix = y_start_ix + 16 y = phase_vars[y_start_ix:y_end_ix] poly = general_utilities.make_verts_array_given_xs_and_ys(x, y) rac_cyto = (1 - calculate_sum(16, rac_acts) - calculate_sum(16, rac_inacts)) rho_cyto = (1 - calculate_sum(16, rho_acts) - calculate_sum(16, rho_inacts)) sum_forces, edge_forces_plus, edge_forces_minus, uevs, rgtp_forces, \ cyto_forces, \ edge_strains, local_strains, \ uivs = mechanics.calculate_forces( poly, rac_acts, rho_acts, rest_edge_len, stiffness_edge, halfmax_vertex_rgtp, const_protrusive, const_retractive, rest_area, stiffness_cyto, ) sum_forces_x = sum_forces[:, 0] sum_forces_y = sum_forces[:, 1] only_tensile_local_strains = np.zeros_like(local_strains) for i in range(16): local_strain = local_strains[i] if local_strain > 0: only_tensile_local_strains[i] = local_strain edgeplus_lengths = geometry.calculate_edgeplus_lengths(poly) avg_edge_lengths = geometry.calculate_average_edge_length_around_nodes( edgeplus_lengths) conc_rac_acts = chemistry.calc_concs(rac_acts, avg_edge_lengths) kgtps_rac = chemistry.calculate_kgtp_rac( conc_rac_acts, halfmax_vertex_rgtp_conc, kgtp_rac, kgtp_rac_auto, x_coas, rac_rands, x_cils, close_point_smoothness_factors, ) conc_rho_acts = chemistry.calc_concs(rho_acts, avg_edge_lengths) global_tension = np.sum(only_tensile_local_strains) / 16 if global_tension < 0.0: global_tension = 0.0 strain_inhibition = tension_inhib * \ chemistry.hill_function3( halfmax_tension_inhib, global_tension ) kdgtps_rac = chemistry.calculate_kdgtp_rac( conc_rho_acts, halfmax_vertex_rgtp_conc, kdgtp_rac, kdgtp_rho_on_rac, x_cils, halfmax_tension_inhib, tension_inhib, only_tensile_local_strains, ) kgtps_rho = chemistry.calculate_kgtp_rho( conc_rho_acts, x_cils, halfmax_vertex_rgtp_conc, kgtp_rho, kgtp_rho_auto, ) kdgtps_rho = chemistry.calculate_kdgtp_rho( conc_rac_acts, halfmax_vertex_rgtp_conc, kdgtp_rho, kdgtp_rac_on_rho, ) conc_rac_inacts = chemistry.calc_concs(rac_inacts, avg_edge_lengths) conc_rho_inact = chemistry.calc_concs(rho_inacts, avg_edge_lengths) rac_act_net_fluxes = chemistry.calculate_net_fluxes( conc_rac_acts, diffusion_rgtp, edgeplus_lengths, ) rac_inact_net_fluxes = chemistry.calculate_net_fluxes( conc_rac_inacts, diffusion_rgtp, edgeplus_lengths, ) rho_act_net_fluxes = chemistry.calculate_net_fluxes( conc_rho_acts, diffusion_rgtp, edgeplus_lengths, ) rho_inact_net_fluxes = chemistry.calculate_net_fluxes( conc_rho_inact, diffusion_rgtp, edgeplus_lengths, ) delta_rac_activated = np.zeros(16, dtype=np.float64) delta_rac_inactivated = np.zeros(16, dtype=np.float64) delta_rac_cytosol_to_membrane = np.zeros(16, dtype=np.float64) delta_rho_activated = np.zeros(16, dtype=np.float64) delta_rho_inactivated = np.zeros(16, dtype=np.float64) delta_rho_cytosol_to_membrane = np.zeros(16, dtype=np.float64) delta_x = np.zeros(16, dtype=np.float64) delta_y = np.zeros(16, dtype=np.float64) new_verts = np.zeros((16, 2), dtype=np.float64) np.zeros(2, dtype=np.float64) np.zeros(2, dtype=np.float64) # logging.log(level=DYNAMICS_INFO, # msg="tstep: {}, int_step: {}".format(tpoint, int_step)) # logging.log(level=DYNAMICS_INFO, msg="eta: {}".format(vertex_eta)) # logging.log(level=DYNAMICS_INFO, msg="1/eta: {}".format(1 / vertex_eta)) # for ix in focus_verts: # logging.log(level=DYNAMICS_INFO, # msg="rgtp_forces[{}]: {}".format(ix, rgtp_forces[ix])) # logging.log(level=DYNAMICS_INFO, # msg="edge_forces[{}]: {}".format(ix, # edge_forces_plus[ix])) # logging.log(level=DYNAMICS_INFO, # msg="cyto_forces[{}]: {}".format(ix, cyto_forces[ix])) # logging.log(level=DYNAMICS_INFO, # msg="expected sum forces ({}) = {}".format(ix, # rgtp_forces[ # ix] + # edge_forces_plus[ # ix] + # edge_forces_minus[ # ix] + # cyto_forces[ # ix])) # logging.log(level=DYNAMICS_INFO, # msg="sum_forces[{}]: {}".format(ix, sum_forces[ix])) poly_area = geometry.calculate_polygon_area(poly) data = [("tpoint", tpoint), ("poly", [[float(v) for v in x] for x in poly]), ("rac_acts", [float(v) for v in rac_acts]), ("rac_inacts", [float(v) for v in rac_inacts]), ("rho_acts", [float(v) for v in rho_acts]), ("rho_inacts", [float(v) for v in rho_inacts]), ("sum_forces", [ list([float(x), float(y)]) for x, y in zip(sum_forces_x, sum_forces_y) ]), ("uivs", [[float(v) for v in x] for x in uivs]), ("rgtp_forces", [[float(v) for v in x] for x in rgtp_forces]), ("edge_forces", [[float(v) for v in x] for x in edge_forces_plus]), ("cyto_forces", [[float(v) for v in x] for x in cyto_forces]), ("kgtps_rac", [float(v) for v in kgtps_rac]), ("kdgtps_rac", [float(v) for v in kdgtps_rac]), ("kgtps_rho", [float(v) for v in kgtps_rho]), ("kdgtps_rho", [float(v) for v in kdgtps_rho]), ("x_cils", [float(v) for v in x_cils]), ("x_coas", [float(v) for v in x_coas]), ("edge_strains", [float(v) for v in local_strains]), ("avg_tens_strain", [float(global_tension) for _ in local_strains]), ("poly_area", poly_area), ("rac_act_net_fluxes", [float(v) for v in rac_act_net_fluxes]), ("rac_inact_net_fluxes", [float(v) for v in rac_inact_net_fluxes]), ("rho_act_net_fluxes", [float(v) for v in rho_act_net_fluxes]), ("rho_inact_net_fluxes", [float(v) for v in rho_inact_net_fluxes]), ("x_tens", [float(strain_inhibition) for _ in local_strains])] # for d in data: # logging.log(level=99, msg="{}: {}".format(d[0], d[1])) writer.save_int_step(data) for ni in range(16): old_coord = poly[ni] new_verts[ni][0] = old_coord[0] + dt * sum_forces_x[ni] / vertex_eta new_verts[ni][1] = old_coord[1] + dt * sum_forces_y[ni] / vertex_eta # for ix in focus_verts: # logging.log(level=DYNAMICS_INFO, msg="delta.poly[{}]: {}" # .format(ix, (new_verts[0] - poly[0]) / dt) # ) # logging.log(level=DYNAMICS_INFO, # msg="expected Delta poly 0 ({}): {}" # .format(ix, dt * sum_forces[0] / vertex_eta) # ) verts_before_ve = copy.deepcopy(new_verts) # calculate volume exclusion effects num_bisection_iterations = 10 max_movement_mag = dt * const_protrusive / vertex_eta for other_ci in range(num_cells): if other_ci != cell_ix: # logging.log(level=VOL_EX_INFO, msg="testing poly: {}".format( # other_ci)) # logging.log(level=VOL_EX_INFO, # msg="coords: {}".format(all_cells_verts[other_ci])) # logging.log(level=VOL_EX_INFO, # msg="max movement mag: {}".format(max_movement_mag)) are_new_nodes_inside_other_cell = \ geometry.are_points_inside_polygon( new_verts, all_cells_verts[other_ci] ) # logging.log(level=VOL_EX_INFO, msg="in poly: {}".format( # [i for (i, x) in # enumerate(are_new_nodes_inside_other_cell) if x]) # ) for ni in range(16): if are_new_nodes_inside_other_cell[ni]: # logging.log(level=VOL_EX_INFO, # msg="fixing vertex {} violation (current: {})".format( # ni, new_verts[ni])) new_verts[ni] = enforce_volume_exclusion_for_vertex( poly[ni], new_verts[ni], uivs[ni], all_cells_verts[other_ci], num_bisection_iterations, max_movement_mag, ) verts_after_ve = copy.deepcopy(new_verts) for ni in range(16): new_coord = new_verts[ni] old_coord = poly[ni] delta_x[ni] = (new_coord[0] - old_coord[0]) / dt delta_y[ni] = (new_coord[1] - old_coord[1]) / dt for ni in range(16): # finish assigning chemistry variables delta_rac_activated[ni] = kgtps_rac[ni] * rac_inacts[ni] delta_rac_inactivated[ni] = kdgtps_rac[ni] * rac_acts[ni] delta_rac_on = k_mem_on_vertex * rac_cyto delta_rac_off = k_mem_off * rac_inacts[ni] delta_rac_cytosol_to_membrane[ni] = delta_rac_on - delta_rac_off delta_rho_activated[ni] = kgtps_rho[ni] * rho_inacts[ni] delta_rho_inactivated[ni] = kdgtps_rho[ni] * rho_acts[ni] delta_rho_on = k_mem_on_vertex * rho_cyto delta_rho_off = k_mem_off * rho_inacts[ni] delta_rho_cytosol_to_membrane[ni] = delta_rho_on - delta_rho_off # set up ode array ode_array = np.empty(num_phase_vars * 16) for i in range(16): ode_array[i] = (delta_rac_activated[i] - delta_rac_inactivated[i] + rac_act_net_fluxes[i]) ode_array[i + 16] = (delta_rac_inactivated[i] - delta_rac_activated[i] + rac_inact_net_fluxes[i] + delta_rac_cytosol_to_membrane[i]) ode_array[i + 2 * 16] = (delta_rho_activated[i] - delta_rho_inactivated[i] + rho_act_net_fluxes[i]) ode_array[i + 3 * 16] = (delta_rho_inactivated[i] - delta_rho_activated[i] + rho_inact_net_fluxes[i] + delta_rho_cytosol_to_membrane[i]) ode_array[i + 4 * 16] = delta_x[i] ode_array[i + 5 * 16] = delta_y[i] return ode_array, sum_forces, edge_forces_plus, edge_forces_minus, \ rgtp_forces, cyto_forces, verts_before_ve, verts_after_ve
def initialize_cell( self, close_point_smoothness_factors, x_cils, x_coas, ): verts = self.curr_verts self.curr_state[:, [parameters.x_ix, parameters.y_ix]] = verts self.curr_state[:, parameters.edge_lengths_ix] = \ self.rest_edge_len * np.ones(16) if self.cell_ix == 0: self.set_rgtp_distrib( self.init_rac, self.init_rho, ) else: self.set_rgtp_distrib( self.init_rho, self.init_rac, ) rac_acts = self.curr_state[:, parameters.rac_act_ix] rho_acts = self.curr_state[:, parameters.rho_act_ix] self.curr_state[:, parameters.old_x_coa_ix] = x_coas self.curr_state[:, parameters.old_x_cil_ix] = x_cils sum_forces, edge_forces_plus, edge_forces_minus, uevs, rgtpase_forces, \ cyto_forces, \ edge_strains, local_strains, uivs = \ mechanics.calculate_forces( verts, rac_acts, rho_acts, self.rest_edge_len, self.stiffness_edge, self.halfmax_vertex_rgtp, self.const_protrusive, self.const_retractive, self.rest_area, self.stiffness_cyto, ) self.curr_state[:, parameters.local_strains_ix] = local_strains edgeplus_lengths = geometry.calculate_edgeplus_lengths(verts) avg_edge_lengths = geometry.calculate_average_edge_length_around_nodes( edgeplus_lengths) conc_rac_acts = chemistry.calc_concs(rac_acts, avg_edge_lengths) conc_rho_acts = chemistry.calc_concs(rho_acts, avg_edge_lengths) self.curr_state[:, parameters.rac_rands_ix] = self.rac_rands kgtp_racs = chemistry.calculate_kgtp_rac( conc_rac_acts, self.halfmax_vertex_rgtp_conc, self.kgtp_rac, self.kgtp_rac_auto, x_coas, self.rac_rands, x_cils, close_point_smoothness_factors, ) self.curr_state[:, parameters.kgtp_rac_ix] = kgtp_racs kgtp_rhos = chemistry.calculate_kgtp_rho( conc_rho_acts, x_cils, self.halfmax_vertex_rgtp_conc, self.kgtp_rho, self.kgtp_rho_auto, ) self.curr_state[:, parameters.kgtp_rho_ix] = kgtp_rhos self.curr_state[:, parameters.kdgtp_rac_ix] = \ chemistry.calculate_kdgtp_rac( conc_rho_acts, self.halfmax_vertex_rgtp_conc, self.kdgtp_rac, self.kdgtp_rho_on_rac, x_cils, self.halfmax_tension_inhib, self.tension_inhib, np.array([ls if ls > 0 else 0.0 for ls in local_strains]), ) self.curr_state[:, parameters.kdgtp_rho_ix] = \ chemistry.calculate_kdgtp_rho( conc_rac_acts, self.halfmax_vertex_rgtp_conc, self.kdgtp_rho, self.kdgtp_rac_on_rho, ) # update mechanics parameters self.curr_state[:, [parameters.sum_forces_x_ix, parameters.sum_forces_y_ix]] \ = sum_forces self.curr_state[:, [parameters.edge_forces_plus_x_ix, parameters.edge_forces_plus_y_ix]] = \ edge_forces_plus self.curr_state[:, [parameters.edge_forces_minus_x_ix, parameters.edge_forces_minus_y_ix]] = \ edge_forces_minus self.curr_state[:, [parameters.rgtp_forces_x_ix, parameters.rgtp_forces_y_ix]] \ = rgtpase_forces self.curr_state[:, [parameters.cyto_forces_x_ix, parameters.cyto_forces_y_ix]] = \ cyto_forces self.curr_state[:, [parameters.uiv_x_ix, parameters.uiv_y_ix]] = uivs self.curr_verts = verts
def cell_dynamics(state_array, t0, state_parameters, this_cell_index, num_nodes, num_nodal_phase_vars, num_ode_cellwide_phase_vars, nodal_rac_membrane_active_index, length_edge_resting, nodal_rac_membrane_inactive_index, nodal_rho_membrane_active_index, nodal_rho_membrane_inactive_index, nodal_x_index, nodal_y_index, kgtp_rac_baseline, kdgtp_rac_baseline, kgtp_rho_baseline, kdgtp_rho_baseline, kgtp_rac_autoact_baseline, kgtp_rho_autoact_baseline, kdgtp_rho_mediated_rac_inhib_baseline, kdgtp_rac_mediated_rho_inhib_baseline, kgdi_rac, kdgdi_rac, kgdi_rho, kdgdi_rho, threshold_rac_autoact, threshold_rho_autoact, threshold_rho_mediated_rac_inhib, threshold_rac_mediated_rho_inhib, exponent_rac_autoact, exponent_rho_autoact, exponent_rho_mediated_rac_inhib, exponent_rac_mediated_rho_inhib, diffusion_const_active, diffusion_const_inactive, nodal_intercellular_contact_factor_magnitudes_index, nodal_migr_bdry_contact_index, space_at_node_factor_rac, space_at_node_factor_rho, eta, num_cells, all_cells_node_coords, intercellular_squared_dist_array, stiffness_edge, force_rac_exp, force_rac_threshold, force_rac_max_mag, force_rho_exp, force_rho_threshold, force_rho_max_mag, area_resting, stiffness_cytoplasmic, transduced_coa_signals, space_physical_bdry_polygon, exists_space_physical_bdry_polygon, are_nodes_inside_other_cells, close_point_on_other_cells_to_each_node_exists, intercellular_contact_factors, tension_mediated_rac_inhibition_exponent, tension_mediated_rac_inhibition_multiplier, tension_mediated_rac_hill_exponent, tension_mediated_rac_inhibition_half_strain, tension_fn_type, external_gradient_on_nodes, intercellular_contact_factor_magnitudes): nodal_phase_vars = state_array rac_mem_active_start_index = nodal_rac_membrane_active_index*num_nodes rac_mem_active_end_index = rac_mem_active_start_index + num_nodes rac_membrane_active = nodal_phase_vars[rac_mem_active_start_index:rac_mem_active_end_index] rac_mem_inactive_start_index = nodal_rac_membrane_inactive_index*num_nodes rac_mem_inactive_end_index = rac_mem_inactive_start_index + num_nodes rac_membrane_inactive = nodal_phase_vars[rac_mem_inactive_start_index:rac_mem_inactive_end_index] rho_mem_active_start_index = nodal_rho_membrane_active_index*num_nodes rho_mem_active_end_index = rho_mem_active_start_index + num_nodes rho_membrane_active = nodal_phase_vars[rho_mem_active_start_index:rho_mem_active_end_index] rho_mem_inactive_start_index = nodal_rho_membrane_inactive_index*num_nodes rho_mem_inactive_end_index = rho_mem_inactive_start_index + num_nodes rho_membrane_inactive = nodal_phase_vars[rho_mem_inactive_start_index:rho_mem_inactive_end_index] nodal_x_start_index = nodal_x_index*num_nodes nodal_x_end_index = nodal_x_start_index + num_nodes nodal_x = nodal_phase_vars[nodal_x_start_index:nodal_x_end_index] nodal_y_start_index = nodal_y_index*num_nodes nodal_y_end_index = nodal_y_start_index + num_nodes nodal_y = nodal_phase_vars[nodal_y_start_index:nodal_y_end_index] node_coords = general_utilities.make_node_coords_array_given_xs_and_ys(num_nodes, nodal_x, nodal_y) rac_cytosolic_gdi_bound = 1 - calculate_sum(num_nodes, rac_membrane_active) - calculate_sum(num_nodes, rac_membrane_inactive) rho_cytosolic_gdi_bound = 1 - calculate_sum(num_nodes, rho_membrane_active) - calculate_sum(num_nodes, rho_membrane_inactive) # calculate forces F, EFplus, EFminus, F_rgtpase, F_cytoplasmic, local_strains, unit_inside_pointing_vectors = mechanics.calculate_forces(num_nodes, node_coords, rac_membrane_active, rho_membrane_active, length_edge_resting, stiffness_edge, force_rac_exp, force_rac_threshold, force_rac_max_mag, force_rho_exp, force_rho_threshold, force_rho_max_mag, area_resting, stiffness_cytoplasmic) F_x = F[:, 0] F_y = F[:, 1] migr_bdry_contact_factors = state_parameters[nodal_migr_bdry_contact_index] only_tensile_local_strains = np.zeros_like(local_strains) for i in range(num_nodes): local_strain = local_strains[i] if local_strain > 0: only_tensile_local_strains[i] = local_strain kgtps_rac = chemistry.calculate_kgtp_rac(num_nodes, rac_membrane_active, migr_bdry_contact_factors, exponent_rac_autoact, threshold_rac_autoact, kgtp_rac_baseline, kgtp_rac_autoact_baseline, transduced_coa_signals, external_gradient_on_nodes) kdgtps_rac = chemistry.calculate_kdgtp_rac(num_nodes, rho_membrane_active, exponent_rho_mediated_rac_inhib, threshold_rho_mediated_rac_inhib, kdgtp_rac_baseline, kdgtp_rho_mediated_rac_inhib_baseline, intercellular_contact_factors, migr_bdry_contact_factors, tension_mediated_rac_inhibition_exponent, tension_mediated_rac_inhibition_multiplier, tension_mediated_rac_hill_exponent, tension_mediated_rac_inhibition_half_strain, local_strains, tension_fn_type) kdgdis_rac = kdgdi_rac*np.ones(num_nodes, dtype=np.float64) kgtps_rho = chemistry.calculate_kgtp_rho(num_nodes, rho_membrane_active, intercellular_contact_factors, migr_bdry_contact_factors, exponent_rho_autoact, threshold_rho_autoact, kgtp_rho_baseline, kgtp_rho_autoact_baseline) kdgtps_rho = chemistry.calculate_kdgtp_rho(num_nodes, rac_membrane_active, exponent_rac_mediated_rho_inhib, threshold_rac_mediated_rho_inhib, kdgtp_rho_baseline, kdgtp_rac_mediated_rho_inhib_baseline) kdgdis_rho = kdgdi_rho*np.ones(num_nodes, dtype=np.float64) edgeplus_lengths = geometry.calculate_edgeplus_lengths(num_nodes, node_coords) diffusion_rac_membrane_active = chemistry.calculate_diffusion(num_nodes, rac_membrane_active, diffusion_const_active, edgeplus_lengths) diffusion_rac_membrane_inactive = chemistry.calculate_diffusion(num_nodes, rac_membrane_inactive, diffusion_const_inactive, edgeplus_lengths) diffusion_rho_membrane_active = chemistry.calculate_diffusion(num_nodes, rho_membrane_active, diffusion_const_active, edgeplus_lengths) diffusion_rho_membrane_inactive = chemistry.calculate_diffusion(num_nodes, rho_membrane_inactive, diffusion_const_active, edgeplus_lengths) delta_rac_activated = np.zeros(num_nodes, dtype=np.float64) delta_rac_inactivated = np.zeros(num_nodes, dtype=np.float64) delta_rac_cytosol_to_membrane = np.zeros(num_nodes, dtype=np.float64) delta_rho_activated = np.zeros(num_nodes, dtype=np.float64) delta_rho_inactivated = np.zeros(num_nodes, dtype=np.float64) delta_rho_cytosol_to_membrane = np.zeros(num_nodes, dtype=np.float64) delta_nodal_x = np.zeros(num_nodes, dtype=np.float64) delta_nodal_y = np.zeros(num_nodes, dtype=np.float64) new_node_coords = np.zeros((num_nodes, 2), dtype=np.float64) new_coord = np.zeros(2, dtype=np.float64) old_coord = np.zeros(2, dtype=np.float64) for ni in range(num_nodes): old_coord = node_coords[ni] new_node_coords[ni][0] = old_coord[0] + F_x[ni]/eta new_node_coords[ni][1] = old_coord[1] + F_y[ni]/eta # calculate volume exclusion effects num_bisection_iterations = 2 max_movement_mag = (force_rac_max_mag/eta) success_condition_stay_out = 0 success_condition_stay_in = 1 are_new_nodes_inside_other_cell = np.zeros(num_nodes, dtype=np.int64) for other_ci in range(num_cells): if other_ci != this_cell_index: are_new_nodes_inside_other_cell = geometry.are_points_inside_polygon(num_nodes, new_node_coords, num_nodes, all_cells_node_coords[other_ci]) for ni in range(num_nodes): if are_new_nodes_inside_other_cell[ni] != success_condition_stay_out: new_node_coords[ni] = calculate_volume_exclusion_effects(node_coords[ni], new_node_coords[ni], unit_inside_pointing_vectors[ni], all_cells_node_coords[other_ci], num_bisection_iterations, max_movement_mag, success_condition_stay_out) if exists_space_physical_bdry_polygon == 1: are_new_nodes_inside_space_physical_bdry_polygon = geometry.are_points_inside_polygon(num_nodes, new_node_coords, space_physical_bdry_polygon.shape[0], space_physical_bdry_polygon) for ni in range(num_nodes): if are_new_nodes_inside_space_physical_bdry_polygon[ni] != success_condition_stay_in: new_node_coords[ni] = calculate_volume_exclusion_effects(node_coords[ni], new_node_coords[ni], unit_inside_pointing_vectors[ni], space_physical_bdry_polygon, num_bisection_iterations, max_movement_mag, success_condition_stay_in) for ni in range(num_nodes): new_coord = new_node_coords[ni] old_coord = node_coords[ni] delta_nodal_x[ni] = new_coord[0] - old_coord[0] delta_nodal_y[ni] = new_coord[1] - old_coord[1] for ni in range(num_nodes): # finish assigning chemistry variables delta_rac_activated[ni] = kgtps_rac[ni]*rac_membrane_inactive[ni] delta_rac_inactivated[ni] = kdgtps_rac[ni]*rac_membrane_active[ni] delta_rac_on = kdgdis_rac[ni]*rac_cytosolic_gdi_bound delta_rac_off = kgdi_rac*rac_membrane_inactive[ni] delta_rac_cytosol_to_membrane[ni] = delta_rac_on - delta_rac_off delta_rho_activated[ni] = kgtps_rho[ni]*rho_membrane_inactive[ni] delta_rho_inactivated[ni] = kdgtps_rho[ni]*rho_membrane_active[ni] delta_rho_on = kdgdis_rho[ni]*rho_cytosolic_gdi_bound delta_rho_off = kgdi_rho*rho_membrane_inactive[ni] delta_rho_cytosol_to_membrane[ni] = delta_rho_on - delta_rho_off # set up ode array ode_array = np.empty(num_nodal_phase_vars*num_nodes) for i in range(num_nodes): ode_array[i] = delta_rac_activated[i] - delta_rac_inactivated[i] + diffusion_rac_membrane_active[i] ode_array[i + num_nodes] = delta_rac_inactivated[i] - delta_rac_activated[i] + diffusion_rac_membrane_inactive[i] + delta_rac_cytosol_to_membrane[i] ode_array[i + 2*num_nodes] = delta_rho_activated[i] - delta_rho_inactivated[i] + diffusion_rho_membrane_active[i] ode_array[i + 3*num_nodes] = delta_rho_inactivated[i] - delta_rho_activated[i] + diffusion_rho_membrane_inactive[i] + delta_rho_cytosol_to_membrane[i] ode_array[i + 4*num_nodes] = delta_nodal_x[i] ode_array[i + 5*num_nodes] = delta_nodal_y[i] return ode_array