Ejemplo n.º 1
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')
Ejemplo n.º 2
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
Ejemplo n.º 3
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