def test_simulate(): dim = 1 cbm_solver = cbmos.CBModel(ff.Cubic(), scpi.solve_ivp, dim) cell_list = [cl.Cell(0, [0]), cl.Cell(1, [1.0], 0.0, True)] cell_list[1].division_time = 1.05 # make sure not to divide at t_data N = 100 t_data = np.linspace(0, 10, N) # stay away from 24 hours t_data_sol, history = cbm_solver.simulate(cell_list, t_data, {}, {}, raw_t=False) assert len(history) == N assert t_data_sol.tolist() == t_data.tolist() assert len(history[10]) == 2 assert np.isclose(abs(history[10][0].position - history[10][1].position), 1) assert len(history[-1]) == 3 scells = sorted(history[-1], key=lambda c: c.position) assert np.isclose(abs(scells[0].position - scells[1].position), 1, atol=1e-03) assert np.isclose(abs(scells[1].position - scells[2].position), 1, atol=1e-03)
def test_cell_list_order(): # 2D honeycomb mesh n_x = 5 n_y = 5 xcrds = [(2 * i + (j % 2)) * 0.5 for j in range(n_y) for i in range(n_x)] ycrds = [np.sqrt(3) * j * 0.5 for j in range(n_y) for i in range(n_x)] # make cell_list for the sheet sheet = [ cl.Cell(i, [x, y], -6.0, True, lambda t: 6 + t) for i, x, y in zip(range(n_x * n_y), xcrds, ycrds) ] # delete cells to make it circular del sheet[24] del sheet[20] del sheet[19] del sheet[9] del sheet[4] del sheet[0] solver = cbmos.CBModel(ff.Cubic(), ef.solve_ivp, 2) dt = 0.01 t_data = np.arange(0, 3, dt) _, history = solver.simulate(sheet, t_data, {"mu": 6.91}, {'dt': dt}, seed=17) history = history[1:] # delete initial data because that's less cells ids = [cell.ID for cell in history[0]] assert np.all([ids == [cell.ID for cell in clt] for clt in history[1:]])
def test_sparse_tdata(): dim = 3 solver_cubic = cbmos.CBModel(ff.Cubic(), ef.solve_ivp, dim) ancestor = [cl.Cell(0, np.zeros((dim, )), -5, True)] dt = 0.1 t_f = 50 t_data = np.linspace(0, t_f, 2) _, tumor_cubic = solver_cubic.simulate(ancestor, t_data, {"mu": 6.91}, {"dt": dt})
def test_cell_birth(caplog): logger = logging.getLogger() logs = io.StringIO() logger.addHandler(logging.StreamHandler(logs)) caplog.set_level(logging.DEBUG) dim = 2 cbm_solver = cbmos.CBModel(ff.Cubic(), ef.solve_ivp, dim) cell_list = [ cl.Cell(0, [0, 0], -5.5, True, division_time_generator=lambda t: 6 + t) ] t_data = np.linspace(0, 1, 10) cbm_solver.simulate(cell_list, t_data, {}, {}) division_times = logs.getvalue() assert parse.search("Division event: t={:f}", division_times)[0] == 0.5
def test_tdata_raw(): n = 100 s = 1.0 # rest length tf = 1.0 # final time rA = 1.5 # maximum interaction distance params_cubic = {"mu": 6.91, "s": s, "rA": rA} solver_ef = cbmos.CBModel(ff.Cubic(), ef.solve_ivp, 1) t_data = np.linspace(0, 1, n) cell_list = [ cl.Cell(0, [0], proliferating=False), cl.Cell(1, [0.3], proliferating=False) ] t_data_sol, sols = solver_ef.simulate(cell_list, t_data, params_cubic, {'dt': 0.03}, raw_t=True) assert len(t_data_sol) == len(sols)
def test_tdata_raw_division(): n = 100 s = 1.0 # rest length tf = 1.0 # final time rA = 1.5 # maximum interaction distance params_cubic = {"mu": 6.91, "s": s, "rA": rA} solver_ef = cbmos.CBModel(ff.Cubic(), ef.solve_ivp, 1) t_data = np.linspace(0, 50, n) cell_list = [ cl.Cell(0, [0], proliferating=True), cl.Cell(1, [0.3], proliferating=True) ] t_data_sol, sols = solver_ef.simulate(cell_list, t_data, params_cubic, {'dt': 0.03}, raw_t=True) assert len(sols[-1]) > len(cell_list) # Make sure some cells multiplied assert len(t_data_sol) == len(sols) assert all([t[0] < t[1] for t in zip(t_data_sol, t_data_sol[1:])])
def test_tdata(): n = 100 s = 1.0 # rest length tf = 1.0 # final time rA = 1.5 # maximum interaction distance params_cubic = {"mu": 6.91, "s": s, "rA": rA} solver_ef = cbmos.CBModel(ff.Cubic(), ef.solve_ivp, 1) t_data = np.linspace(0, 1, n) cell_list = [ cl.Cell(0, [0], proliferating=False), cl.Cell(1, [0.3], proliferating=False) ] _, sols = solver_ef.simulate(cell_list, t_data, params_cubic, {'dt': 0.03}, raw_t=False) y = np.array( [np.squeeze([clt[0].position, clt[1].position]) for clt in sols]) assert y.shape == (n, 2)