Beispiel #1
0
def test_logging():

    tf = tempfile.mktemp()
    manager = EventManager("face", tf)
    initial_cell_event = [
        (division, {
            "face_id": 1,
            "geom": geom
        }),
        (apoptosis, {
            "face_id": 3,
            "shrink_rate": 4
        }),
        (apoptosis, {
            "face_id": 3
        }),
    ]

    manager.extend(initial_cell_event)
    manager.execute(None)
    manager.update()
    with open(tf, "r") as fh:
        l0, l1, l2 = fh.readlines()

    assert l2 == "0, -1, wait\n"
Beispiel #2
0
def test_execute_constriction():
    h5store = os.path.join(stores_dir, "small_hexagonal.hf5")
    datasets = load_datasets(h5store, data_names=["face", "vert", "edge"])
    specs = config.geometry.cylindrical_sheet()
    sheet = Sheet("emin", datasets, specs)
    geom.update_all(sheet)
    sheet.settings["constriction"] = {
        "contractile_increase": 5,
        "critical_area": 5,
        "max_traction": 10,
    }
    sheet.face_df["id"] = sheet.face_df.index.values
    init_nb_cells = len(sheet.face_df)

    sheet.face_df["is_mesoderm"] = 0
    sheet.vert_df["radial_tension"] = 0
    manager = EventManager("face")
    face_id = 17
    sheet.face_df.loc[face_id, "is_mesoderm"] = 1

    sheet.settings["constriction"].update({"face_id": face_id})
    initial_cell_event = (constriction, sheet.settings["constriction"])
    manager.current.append(initial_cell_event)
    manager.execute(sheet)
    manager.update()
    assert len(manager.current) > 0

    for i in range(20):
        manager.execute(sheet)
        manager.update()
    if len(sheet.face_df) == init_nb_cells:
        assert len(manager.current) > 0
def test_execute_division():

    sheet = Sheet('emin', *three_faces_sheet())
    geom.update_all(sheet)
    sheet.face_df['vol'] = 1.
    sheet.specs['face']['prefered_vol'] = 1.
    sheet.face_df['prefered_vol'] = 1.

    sheet.face_df['id'] = sheet.face_df.index.values
    manager = EventManager('face')
    face_id = 1
    event = (division, {
        'face_id': face_id,
        'growth_rate': 0.2,
        'critical_vol': 1.5
    })
    manager.current.append(event)
    V0 = sheet.face_df.loc[1, 'prefered_vol']
    manager.execute(sheet)
    manager.update()
    assert sheet.face_df.loc[1, 'prefered_vol'] == V0 * 1.2
    manager.execute(sheet)
    manager.update()
    assert sheet.face_df.loc[1, 'prefered_vol'] == V0 * 1.44
    sheet.face_df.loc[1, 'vol'] *= 1.6
    manager.execute(sheet)
    assert sheet.Nf == 4
Beispiel #4
0
def test_execute_division():

    sheet = Sheet("emin", *three_faces_sheet())
    geom.update_all(sheet)
    sheet.face_df["vol"] = 1.0
    sheet.specs["face"]["prefered_vol"] = 1.0
    sheet.face_df["prefered_vol"] = 1.0

    sheet.face_df["id"] = sheet.face_df.index.values
    manager = EventManager("face")
    face_id = 1
    event = (division, {
        "face_id": face_id,
        "growth_rate": 1.2,
        "critical_vol": 1.5
    })
    manager.current.append(event)
    V0 = sheet.face_df.loc[1, "prefered_vol"]
    manager.execute(sheet)
    manager.update()
    assert sheet.face_df.loc[1, "prefered_vol"] == V0 * 1.2
    manager.execute(sheet)
    manager.update()
    assert sheet.face_df.loc[1, "prefered_vol"] == V0 * 1.44
    sheet.face_df.loc[1, "vol"] *= 1.6
    manager.execute(sheet)
    assert sheet.Nf == 4
Beispiel #5
0
def test_add_several_time_same_events():
    manager = EventManager("face")
    initial_cell_event = [
        (division, {
            "face_id": 1,
            "geom": geom
        }),
        (contraction, {
            "face_id": 2,
            "unique": False
        }),
        (contraction, {
            "face_id": 3,
            "unique": False
        }),
        (apoptosis, {
            "face_id": 3,
            "shrink_rate": 4
        }),
        (contraction, {
            "face_id": 2,
            "unique": False
        }),
    ]

    manager.extend(initial_cell_event)
    manager.execute(None)
    manager.update()
    assert len(manager.current) == 5
Beispiel #6
0
def test_apoptosis():
    specs = config.geometry.bulk_spec()
    sheet = Sheet.planar_sheet_3d("flat", 4, 5, 1, 1)
    sheet.sanitize()
    datasets = extrude(sheet.datasets, method="translation")
    mono = Monolayer("mono", datasets, specs)
    mono.face_df["id"] = mono.face_df.index.values
    geom.center(mono)
    geom.update_all(mono)
    mono.face_df["contractility"] = 1.0
    manager = EventManager("face")
    cell_id = 0
    apical_face = mono.face_df[
        (mono.face_df.index.isin(mono.get_orbits("cell", "face")[cell_id]))
        & (mono.face_df.segment == "apical")].index[0]
    sheet.settings["apoptosis"] = {"cell_id": cell_id}
    initial_cell_event = [(apoptosis, sheet.settings["apoptosis"])]

    manager.extend(initial_cell_event)
    manager.execute(mono)
    manager.update()
    assert len(manager.current) == 1

    i = 0
    while i < 5:
        manager.execute(mono)
        manager.update()
        i = i + 1

    assert mono.face_df.loc[apical_face, "contractility"] > 1.0
def test_execute_constriction():
    h5store = os.path.join(stores_dir, 'small_hexagonal.hf5')
    datasets = load_datasets(h5store, data_names=['face', 'vert', 'edge'])
    specs = config.geometry.cylindrical_sheet()
    sheet = Sheet('emin', datasets, specs)
    geom.update_all(sheet)
    sheet.settings['constriction'] = {
        'contractile_increase': 5,
        'critical_area': 5,
        'max_traction': 10
    }
    sheet.face_df['id'] = sheet.face_df.index.values
    init_nb_cells = len(sheet.face_df)

    sheet.face_df['is_mesoderm'] = 0
    sheet.vert_df['radial_tension'] = 0
    manager = EventManager('face')
    face_id = 17
    sheet.face_df.loc[face_id, 'is_mesoderm'] = 1

    sheet.settings['constriction'].update({'face_id': face_id})
    initial_cell_event = (constriction, sheet.settings['constriction'])
    manager.current.append(initial_cell_event)
    manager.execute(sheet)
    manager.update()
    assert len(manager.current) > 0

    for i in range(20):
        manager.execute(sheet)
        manager.update()
    if len(sheet.face_df) == init_nb_cells:
        assert len(manager.current) > 0
Beispiel #8
0
def test_execute_apoptosis():
    h5store = os.path.join(stores_dir, "small_hexagonal.hf5")
    datasets = load_datasets(h5store, data_names=["face", "vert", "edge"])
    specs = config.geometry.cylindrical_sheet()
    sheet = Sheet("emin", datasets, specs)
    geom.update_all(sheet)
    sheet.settings["apoptosis"] = {
        "contractile_increase": 2.0,
        "critical_area": 0.1
    }
    sheet.face_df["id"] = sheet.face_df.index.values
    init_nb_faces = len(sheet.face_df)
    manager = EventManager("face")
    face_id = 17
    face_area = sheet.face_df.loc[face_id, "area"]
    initial_nbsides = sheet.face_df.loc[face_id, "num_sides"]

    sheet.settings["apoptosis"].update({"face_id": face_id})
    initial_cell_event = (apoptosis, sheet.settings["apoptosis"])

    manager.current.append(initial_cell_event)
    manager.execute(sheet)
    manager.update()
    assert len(manager.current) > 0
    manager.execute(sheet)
    manager.update()

    sheet.settings["apoptosis"] = {
        "contractile_increase": 2.0,
        "critical_area": 2 * face_area,
    }
    manager.current.clear()
    sheet.settings["apoptosis"].update({"face_id": face_id})
    modified_cell_event = (apoptosis, sheet.settings["apoptosis"])

    manager.current.append(modified_cell_event)
    manager.execute(sheet)
    manager.update()
    next_nbsides = sheet.face_df.loc[sheet.idx_lookup(face_id, "face"),
                                     "num_sides"]
    i = 1
    while next_nbsides > 4:
        assert next_nbsides == initial_nbsides - i
        assert len(manager.current) > 0
        i = i + 1
        manager.execute(sheet)
        manager.update()
        next_nbsides = sheet.face_df.loc[sheet.idx_lookup(face_id, "face"),
                                         "num_sides"]
        if i > 20:
            raise RecursionError
    manager.execute(sheet)
    manager.update()
    assert len(sheet.face_df) < init_nb_faces
def test_face_elimination():
    sheet = Sheet('emin', *three_faces_sheet())
    sheet.face_df['id'] = sheet.face_df.index
    face_id = 0
    manager = EventManager('face')
    event = (face_elimination, {'face_id': face_id})
    manager.current.append(event)
    manager.execute(sheet)
    manager.update()
    assert sheet.Nf == 2
    assert sheet.Nv == 8
    assert sheet.Ne == 10
Beispiel #10
0
def test_face_elimination():
    sheet = Sheet("emin", *three_faces_sheet())
    sheet.face_df["id"] = sheet.face_df.index
    face_id = 0
    manager = EventManager("face")
    event = (face_elimination, {"face_id": face_id})
    manager.current.append(event)
    manager.execute(sheet)
    manager.update()
    assert sheet.Nf == 2
    assert sheet.Nv == 8
    assert sheet.Ne == 10
def test_execute_apoptosis():
    h5store = os.path.join(stores_dir, 'small_hexagonal.hf5')
    datasets = load_datasets(h5store, data_names=['face', 'vert', 'edge'])
    specs = config.geometry.cylindrical_sheet()
    sheet = Sheet('emin', datasets, specs)
    geom.update_all(sheet)
    sheet.settings['apoptosis'] = {
        'contractile_increase': 2.0,
        'critical_area': 0.1
    }
    sheet.face_df['id'] = sheet.face_df.index.values
    init_nb_faces = len(sheet.face_df)
    manager = EventManager('face')
    face_id = 17
    face_area = sheet.face_df.loc[face_id, 'area']
    initial_nbsides = sheet.face_df.loc[face_id, 'num_sides']

    sheet.settings['apoptosis'].update({'face_id': face_id})
    initial_cell_event = (apoptosis, sheet.settings['apoptosis'])

    manager.current.append(initial_cell_event)
    manager.execute(sheet)
    manager.update()
    assert len(manager.current) > 0
    manager.execute(sheet)
    manager.update()

    sheet.settings['apoptosis'] = {
        'contractile_increase': 2.0,
        'critical_area': 2 * face_area
    }
    manager.current.clear()
    sheet.settings['apoptosis'].update({'face_id': face_id})
    modified_cell_event = (apoptosis, sheet.settings['apoptosis'])

    manager.current.append(modified_cell_event)
    manager.execute(sheet)
    manager.update()
    next_nbsides = sheet.face_df.loc[sheet.idx_lookup(face_id, 'face'),
                                     'num_sides']
    i = 1
    while next_nbsides > 4:
        assert next_nbsides == initial_nbsides - i
        assert len(manager.current) > 0
        i = i + 1
        manager.execute(sheet)
        manager.update()
        next_nbsides = sheet.face_df.loc[sheet.idx_lookup(face_id, 'face'),
                                         'num_sides']
    manager.execute(sheet)
    manager.update()
    assert len(sheet.face_df) < init_nb_faces
def test_add_only_once():
    manager = EventManager('face')
    initial_cell_event = [(division, {
        'face_id': 1,
        'geom': geom
    }), (apoptosis, {
        'face_id': 3,
        'shrink_rate': 4
    }), (apoptosis, {
        'face_id': 3
    })]

    manager.extend(initial_cell_event)
    manager.execute(None)
    manager.update()
    assert len(manager.current) == 2
def test_execute_contraction():
    sheet = Sheet('emin', *three_faces_sheet())
    geom.update_all(sheet)
    sheet.face_df['contractility'] = 1.12

    sheet.face_df['id'] = sheet.face_df.index.values
    manager = EventManager('face')
    face_id = 1
    event = (contraction, {
        'face_id': face_id,
        'contractile_increase': 0.2,
        'critical_area': 1e-2
    })
    manager.current.append(event)
    manager.execute(sheet)
    manager.update()
    assert sheet.face_df.loc[face_id, 'contractility'] == 1.32
Beispiel #14
0
def test_check_tri_faces():
    h5store = os.path.join(stores_dir, "small_hexagonal.hf5")
    datasets = load_datasets(h5store, data_names=["face", "vert", "edge"])
    specs = config.geometry.cylindrical_sheet()
    sheet = Sheet("emin", datasets, specs)
    initial_nb_cells = len(sheet.face_df)
    nb_tri_cells = len(sheet.face_df[(sheet.face_df["num_sides"] < 4)])
    geom.update_all(sheet)
    sheet.face_df["id"] = sheet.face_df.index.values
    manager = EventManager("face")
    manager.current.append((check_tri_faces, {}))
    manager.execute(sheet)
    manager.update()

    manager.execute(sheet)
    manager.update()
    assert len(sheet.face_df) == initial_nb_cells - nb_tri_cells
def test_type1_transition():
    sheet = Sheet('emin', *three_faces_sheet())
    geom.update_all(sheet)

    sheet.face_df['id'] = sheet.face_df.index.values
    manager = EventManager('face')
    face_id = 1
    nb_neighbors_start = len(sheet.edge_df[sheet.edge_df['face'] == face_id])
    edge_to_modify = sheet.edge_df[sheet.edge_df['face'] == face_id].index[0]
    sheet.edge_df.loc[edge_to_modify, 'length'] = 0.2
    event = (type1_transition, {'face_id': face_id, 'critical_length': 0.3})
    manager.current.append(event)
    manager.execute(sheet)
    manager.update()

    nb_neighbors_end = len(sheet.edge_df[sheet.edge_df['face'] == face_id])

    assert nb_neighbors_end == nb_neighbors_start - 1
Beispiel #16
0
def test_type1_transition():
    sheet = Sheet("emin", *three_faces_sheet())
    geom.update_all(sheet)

    sheet.face_df["id"] = sheet.face_df.index.values
    manager = EventManager("face")
    face_id = 1
    nb_neighbors_start = len(sheet.edge_df[sheet.edge_df["face"] == face_id])
    edge_to_modify = sheet.edge_df[sheet.edge_df["face"] == face_id].index[0]
    sheet.edge_df.loc[edge_to_modify, "length"] = 0.2
    event = (type1_transition, {"face_id": face_id, "critical_length": 0.3})
    manager.current.append(event)
    manager.execute(sheet)
    manager.update()

    nb_neighbors_end = len(sheet.edge_df[sheet.edge_df["face"] == face_id])

    assert nb_neighbors_end == nb_neighbors_start - 1
def test_add_events():

    manager = EventManager('face')
    initial_cell_event = [(division, {
        'face_id': 1,
        'geom': geom
    }), (wait, {
        'face_id': 3,
        'n_steps': 4
    }), (apoptosis, {
        'face_id': 5
    }), (constriction, {
        'face_id': 2
    })]
    manager.extend(initial_cell_event)
    manager.execute(None)
    manager.update()
    assert len(manager.current) == 4
Beispiel #18
0
def test_add_only_once():
    manager = EventManager("face")
    initial_cell_event = [
        (division, {
            "face_id": 1,
            "geom": geom
        }),
        (apoptosis, {
            "face_id": 3,
            "shrink_rate": 4
        }),
        (apoptosis, {
            "face_id": 3
        }),
    ]

    manager.extend(initial_cell_event)
    manager.execute(None)
    manager.update()
    assert len(manager.current) == 2
Beispiel #19
0
def test_execute_contraction():
    sheet = Sheet("emin", *three_faces_sheet())
    geom.update_all(sheet)
    sheet.face_df["contractility"] = 1.12

    sheet.face_df["id"] = sheet.face_df.index.values
    manager = EventManager("face")
    face_id = 1
    event = (
        contraction,
        {
            "face_id": face_id,
            "contractile_increase": 0.2,
            "critical_area": 1e-2
        },
    )
    manager.current.append(event)
    manager.execute(sheet)
    manager.update()
    assert sheet.face_df.loc[face_id, "contractility"] == 1.32
def test_logging():

    tf = tempfile.mktemp()
    manager = EventManager('face', tf)
    initial_cell_event = [(division, {
        'face_id': 1,
        'geom': geom
    }), (apoptosis, {
        'face_id': 3,
        'shrink_rate': 4
    }), (apoptosis, {
        'face_id': 3
    })]

    manager.extend(initial_cell_event)
    manager.execute(None)
    manager.update()
    with open(tf, 'r') as fh:
        l0, l1, l2 = fh.readlines()

    assert l2 == '0, -1, wait\n'
Beispiel #21
0
def test_add_events():

    manager = EventManager("face")
    initial_cell_event = [
        (division, {
            "face_id": 1,
            "geom": geom
        }),
        (wait, {
            "face_id": 3,
            "n_steps": 4
        }),
        (apoptosis, {
            "face_id": 5
        }),
        (constriction, {
            "face_id": 2
        }),
    ]
    manager.extend(initial_cell_event)
    manager.execute(None)
    manager.update()
    assert len(manager.current) == 4
def test_add_several_time_same_events():
    manager = EventManager('face')
    initial_cell_event = [(division, {
        'face_id': 1,
        'geom': geom
    }), (contraction, {
        'face_id': 2,
        'unique': False
    }), (contraction, {
        'face_id': 3,
        'unique': False
    }), (apoptosis, {
        'face_id': 3,
        'shrink_rate': 4
    }), (contraction, {
        'face_id': 2,
        'unique': False
    })]

    manager.extend(initial_cell_event)
    manager.execute(None)
    manager.update()
    assert len(manager.current) == 5
Beispiel #23
0
def run_sim(
    dirname,
    solver,
    solver_kw,
    sheet,
    geom,
    model,
    max_contractility_rate,
    profile_width,
    k,
    cable_cut=False,
    apical_cut=False,
    nb_apical_cut=2,
):
    """
    Run simulation according to parameters.
    Parameters
    ----------
    dirname: saving directory to hf5 file
    solver:
    solver_kw: solver arguments
    sheet:
    geom:
    model:
    max_contractility_rate: maximal constriction cell for all cell in the tissue.
    k: steepness coefficient characterizing the profile decay
    profile_width: width of the profile
    cable_cut: True/False, define if apico-basal force is exerted
    apical_cut: True/False, define if a domain of cell is isolated
    nb_apical_cut: Define number of apical cut (1 or 2)
    """

    # Initiate manager
    manager = EventManager("face")
    sheet.face_df["enter_in_process"] = 0

    t = 0
    stop = 200
    sheet.face_df["contract_rate"] = 0

    if apical_cut:
        if nb_apical_cut == 1:
            # posterior apical ablation
            apical_cut(sheet, 45.0)

        elif nb_apical_cut == 2:
            # anterior & posterior apical ablation
            apical_cut(sheet, 45.0)
            apical_cut(sheet, -45.0)

    # Add all cells in constriction process
    for f in sheet.face_df[sheet.face_df["is_mesoderm"]].index:
        x = sheet.face_df.loc[f, "x"]
        c_rate = constriction_rate(x, max_contractility_rate, k, profile_width)

        sheet.face_df.loc[f, "contract_rate"] = c_rate
        delam_kwargs = sheet.settings["delamination"].copy()
        delam_kwargs.update({
            "face_id": f,
            "contract_rate": c_rate,
            "current_traction": 0,
            "max_traction": 30,
        })
        manager.append(constriction, **delam_kwargs)

    for f in sheet.face_df[sheet.face_df["is_relaxation"]].index:
        delam_kwargs = sheet.settings["delamination"].copy()
        delam_kwargs.update({
            "face_id": f,
            "contract_rate": max_contractility_rate,
            "current_traction": 0,
            "max_traction": 30,
        })
        manager.append(constriction, **delam_kwargs)

    while manager.current and t < stop:
        # Clean radial tension on all vertices
        sheet.vert_df["radial_tension"] = 0
        manager.execute(sheet)

        if cable_cut:
            # Mettre ici la mise à 0 de la force AB dans la zone -45 45
            sheet.vert_df["radial_tension"] = [
                0 if ((z > -45.0) and (z < 45.0)) else rad
                for (z, rad) in sheet.vert_df[["z", "radial_tension"]].values
            ]

        res = solver.find_energy_min(sheet, geom, model, **solver_kw)

        # add noise on vertex position to avoid local minimal.
        sheet.vert_df[["x", "y"]] += np.random.normal(scale=1e-3,
                                                      size=(sheet.Nv, 2))
        geom.update_all(sheet)

        # Save result in each time step.
        figname = os.path.join(dirname, "invagination_{:04d}.png".format(t))
        hdfname = figname[:-3] + "hf5"
        hdf5.save_datasets(hdfname, sheet)

        # Add cells with initially 3 neighbourghs to be eliminated.
        check_tri_faces(sheet, manager)

        manager.update()
        t += 1

    return sheet
Beispiel #24
0
def run_sim(sim_save_dir,
            original_tissue,
            polarity,
            perturbation,
            ve,
            iteration=0):
    time.sleep(np.random.rand())
    # without copy, dataframe is on read only...
    sheet = original_tissue.copy()
    sheet.settings['lumen_prefered_vol'] = ve

    if perturbation != -1:
        for p in perturbation:
            sheet.face_df.loc[int(p), 'is_mesoderm'] = 1

    define_polarity_old(sheet, 1, polarity)
    geom.normalize_weights(sheet)

    res = solver.find_energy_min(sheet, geom, model, options={"gtol": 1e-8})

    filename = '{}_polarity_{}_perturbation_{}_ve_{}'.format(
        polarity, perturbation, ve, iteration)
    dirname = os.path.join(sim_save_dir, filename)

    print('starting {}'.format(dirname))
    try:
        os.mkdir(dirname)
    except IOError:
        pass

    # Add some information to the sheet and copy initial sheet
    sheet.face_df['id'] = sheet.face_df.index.values

    # Initiate history
    history = HistoryHdf5(sheet,
                          extra_cols={
                              "face": sheet.face_df.columns,
                              "edge": list(sheet.edge_df.columns),
                              "vert": list(sheet.vert_df.columns)
                          },
                          hf5file=os.path.join(dirname, filename + '.hf5'))

    # Initiate manager
    manager = EventManager('face')

    # Update kwargs...
    sheet.settings['apoptosis'].update({
        'contract_rate': 1.08,
        'radial_tension': 50,
    })

    # save settings
    pd.Series(sheet.settings).to_csv(os.path.join(dirname, 'settings.csv'))

    manager.append(reconnect, **sheet.settings['rosette_kwargs'])
    manager.append(apoptosis_patterning,
                   **sheet.settings['apopto_pattern_kwargs'])

    t = 0.
    stop = 150.
    # Run simulation
    while t < stop:
        if t == 5:
            for i in sheet.face_df[sheet.face_df.is_mesoderm == 1].index:
                delamination_kwargs = sheet.settings[
                    'delaminate_setting'].copy()
                delamination_kwargs.update({
                    "face_id": i,
                    #"radial_tension": radial_tension,
                    "radial_tension": 50,
                    "contract_rate": 1.08,
                    "max_traction": 90,
                    "current_traction": 0,
                })
                manager.append(delamination, **delamination_kwargs)

        # Reset radial tension at each time step
        sheet.vert_df.radial_tension = 0.

        manager.execute(sheet)
        res = solver.find_energy_min(sheet,
                                     geom,
                                     model,
                                     options={"gtol": 1e-8})

        # add noise on vertex position to avoid local minimal.
        sheet.vert_df[['x', 'y']] += np.random.normal(scale=1e-3,
                                                      size=(sheet.Nv, 2))
        geom.update_all(sheet)

        # Save result in each time step.
        """figname = os.path.join(
            dirname, 'invagination_{:04.0f}.png'.format(t))
        hdfname = figname[:-3] + 'hf5'
        hdf5.save_datasets(hdfname, sheet)
		"""
        history.record(time_stamp=float(t))

        manager.update()
        t += 1.

    print('{} done'.format(dirname))
    print('~~~~~~~~~~~~~~~~~~~~~\n')
Beispiel #25
0
def test_constriction():
    specs = config.geometry.bulk_spec()
    sheet = Sheet.planar_sheet_3d("flat", 6, 8, 1, 1)
    sheet.sanitize()
    datasets = extrude(sheet.datasets, method="translation")
    mono = Monolayer("mono", datasets, specs)
    geom.center(mono)
    geom.update_all(mono)
    dyn_specs = config.dynamics.quasistatic_bulk_spec()
    dyn_specs["cell"]["area_elasticity"] = 0.05
    dyn_specs["cell"]["prefered_area"] = 6.0
    dyn_specs["cell"]["vol_elasticity"] = 1.0
    dyn_specs["cell"]["prefered_vol"] = 1.2
    dyn_specs["face"]["contractility"] = 0.0
    dyn_specs["edge"]["line_tension"] = 0.0
    mono.update_specs(dyn_specs, reset=True)
    mono.face_df.loc[mono.apical_faces, "contractility"] = 1.12
    mono.face_df.loc[mono.basal_faces, "contractility"] = 1.12

    manager = EventManager("face")
    sheet.face_df["enter_in_process"] = 0

    mono.settings["constriction"] = {}
    mono.cell_df["is_mesoderm"] = False
    mono.face_df["is_mesoderm"] = False

    cell_to_constrict = [12]
    apical_face = mono.face_df[(mono.face_df.index.isin(
        mono.get_orbits("cell", "face")[cell_to_constrict[0]]))
                               & (mono.face_df.segment == "apical")].index[0]
    mono.cell_df.loc[cell_to_constrict, "is_mesoderm"] = True
    mono.cell_df["id"] = mono.cell_df.index.values
    mono.face_df["id"] = mono.face_df.index.values

    list_face_in_cell = mono.get_orbits("cell", "face")
    cell_in_mesoderm = mono.cell_df[mono.cell_df.is_mesoderm].index.values
    for i in cell_in_mesoderm:
        faces_in_cell = mono.face_df.loc[list_face_in_cell[i].unique()]
        for f in faces_in_cell.index.values:
            mono.face_df.loc[f, "is_mesoderm"] = True

    for i in cell_to_constrict:

        delam_kwargs = mono.settings["constriction"].copy()
        delam_kwargs.update({
            "cell_id": i,
            "contract_rate": 2,
            "critical_area": 0.02,
            "shrink_rate": 0.4,
            "critical_volume": 0.1,
            "radial_tension": 3,
            "max_traction": 35,
            "contract_neighbors": True,
            "contract_span": 1,
            "with_rearrangement": True,
            "critical_area_reduction": 5,
        })

        initial_cell_event = [(constriction, delam_kwargs)]
        manager.extend(initial_cell_event)
    manager.execute(mono)
    manager.update()
    assert len(manager.current) == 1

    i = 0
    while i < 10:
        manager.execute(mono)
        manager.update()
        i = i + 1

    assert mono.face_df.loc[apical_face, "contractility"] > 1.0
    for c in cell_to_constrict:
        assert mono.cell_df.loc[c, "num_faces"] <= 4
Beispiel #26
0
def run_sim(
    sim_save_dir,
    _sheet,
    polarity,
    perturbation=-1,
    stop=150.,
    iteration=0,
):

    # Define solver
    solver = QSSolver(with_t1=False, with_t3=False, with_collisions=False)

    filename = '{}_polarity{}_perturbation.hf5'.format(polarity, perturbation)
    try:
        os.mkdir(sim_save_dir)
    except IOError:
        pass

    # without copy, dataframe is on read only...
    sheet = _sheet.copy()

    sheet.face_df['is_mesoderm'] = 0
    if perturbation != -1:
        for p in perturbation:
            sheet.face_df.loc[int(p), 'is_mesoderm'] = 1

    define_polarity(sheet, 1, polarity)
    geom.normalize_weights(sheet)

    # Add some information to the sheet
    sheet.face_df['id'] = sheet.face_df.index.values

    # Initiate history
    history = HistoryHdf5(sheet,
                          extra_cols={
                              "face": sheet.face_df.columns,
                              "edge": list(sheet.edge_df.columns),
                              "vert": list(sheet.vert_df.columns)
                          },
                          hf5file=os.path.join(sim_save_dir, filename))

    # Initiate manager
    manager = EventManager('face')

    # save settings
    pd.Series(sheet.settings).to_csv(
        os.path.join(sim_save_dir, (filename[:-4] + '_settings.csv')))

    manager.append(reconnect, **sheet.settings['rosette_kwargs'])
    manager.append(apoptosis_patterning,
                   **sheet.settings['apopto_pattern_kwargs'])

    t = 0.
    stop = 150.
    # Run simulation
    while t < stop:
        if t == 5:
            for i in sheet.face_df[sheet.face_df.is_mesoderm == 1].index:
                delamination_kwargs = sheet.settings[
                    'delaminate_setting'].copy()
                delamination_kwargs.update({
                    "face_id": i,
                })
                manager.append(delamination, **delamination_kwargs)

        # Reset radial tension at each time step
        sheet.vert_df.radial_tension = 0.

        manager.execute(sheet)
        res = solver.find_energy_min(sheet,
                                     geom,
                                     model,
                                     options={"gtol": 1e-8})
        if res.success is False:
            raise ('Stop because solver didn'
                   't succeed at time t ' + str(t), res)

        # add noise on vertex position to avoid local minimal.
        sheet.vert_df[['x', 'y']] += np.random.normal(scale=1e-3,
                                                      size=(sheet.Nv, 2))
        geom.update_all(sheet)

        history.record(time_stamp=float(t))

        manager.update()
        t += 1.

    return sheet