<jupyter_start><jupyter_text>In this example, we will show how to create a very simple tissue structure comprised of cubic cells and visualize it using Multicell. PreparationVisualizations rely on the matplotlib module. In order for visualizations to work interactively in this Jupyter notebook, we need to run the following command.<jupyter_code>%matplotlib notebook<jupyter_output><empty_output><jupyter_text>ImportsIn Python, it is common practice to import the modules we will be using at the beginning of the script. To create a simple virtual tissue, we will need the Multicell module.<jupyter_code>import multicell<jupyter_output><empty_output><jupyter_text>We then need to define the problem Problem definition Tissue structureThe simulation_builder module can be used to create a virtual tissue, e.g. in this case a cubic cell grid.As the grid is regular, aside from a small amount of random noise used to break symmetry, all cells have identical sizes measured in arbitrary units, with sides 1 arb. unit-long. The neighbors of a cell are cells that are in direct contact. In this simple case, as we have a single layer of identical and aligned cells, each cell will have between two and four neighbors, depending on its position in the grid. The contact surface of any two adjacent cells will always be equal to $1 (arb. unit)^2$. All cells also have a volume of $1 (arb. unit)^3$ (Fig. 1).Figure 1: Structure of a grid tissue comprised of cubic cells. (a) Each cell is a cube whose sides are 1 arb. unit long. (b) Depending on its position within the tissue, the red cell can have 2, 3 or 4 neighbors (in green).As grid tissues are convenient to quickly build prototype models, multicell provides a function, `generate_cell_grid_sim` that automatically prepares simulations based on grid tissues.<jupyter_code>sim = multicell.generate_cell_grid_sim(x=20,y=20, z=1, noise_amplitude=1e-3)<jupyter_output><empty_output><jupyter_text>The usage of this function (and others) can be checked out in its documentation.<jupyter_code>help(multicell.generate_cell_grid_sim)<jupyter_output>Help on function generate_cell_grid_sim in module multicell.simulation_builder:

generate_cell_grid_sim(x, y=0, z=0, noise_amplitude=0.001, sim_class=<class 'multicell.simulation.Simulation'>)
    Builds a Simulation object with a grid-shaped tissue.
    
    Parameters
    ----------
        x : int
            Number of cells along the x axis
        y : int
            Number of cells along the y axis, not used if 0 (default: 0)
        z : int
            Number of cells along the z axis, not used if 0 (default: 0)
        noise_amplitude : double
            Amplitude of the random noise applied to the position of vertices.
            The perturbations applied to each vertex are independent and
            follow a uniform distribution between -noise_amplitude/2. and
            noise_amplitude/2. (default: 1e-3)
    
    Returns
    -------
        Simulation
            Simulation object containing the grid.<jupyter_text>Behind the scenes, this function performs several operations. Knowing what they are is not necessary for the series of examples presented in this chapter, but would be useful, should Multicell be used to run simulations in custom tissue structures. First a simulation object is created.<jupyter_code>sim = multicell.Simulation()<jupyter_output><empty_output><jupyter_text>Then a grid tissue is created using a function provided by Virtual Plants. It contains topological information (information about which vertices are connected by edges, which edges form faces and which faces form cells). This is stored in the `mesh` variable. It also contains information about the positions of all vertices. This is stored in the `pos` variable.<jupyter_code>from openalea.tissueshape import tovec, grid_tissue
tissuedb = grid_tissue.regular_grid((20, 20, 1))
mesh = tissuedb.get_topology("mesh_id")
pos = tovec(tissuedb.get_property("position"))<jupyter_output><empty_output><jupyter_text>Vertex positions are then modified. The tissue is centered in space (this is not necessary) and a small noise is applied (this is important when symmetry needs to be broken, e.g. in the division algorithm we will use in a later example).<jupyter_code>import numpy as np
bary = reduce(lambda x,y: x + y,pos.itervalues() ) / len(pos)
pos = dict((pid,vec - bary + np.random.uniform(-5e-4, 5e-4, 3)) for pid,vec in pos.iteritems())<jupyter_output><empty_output><jupyter_text>Finally, `mesh` and `pos` are imported into the simulation.<jupyter_code>sim.import_topomesh(mesh, pos)<jupyter_output><empty_output><jupyter_text>In this example, `mesh` and `pos` correspond to a regular grid, but they could represent any tissue structure, as long as it is defined in the correct format (OpenAlea TopoMesh).  VisualizationTo display the tissue we just created, we register a renderer. A renderer is an object with a `display()` method, whose purpose is to display a graphical representation of the simulation. A renderer is registered by passing the class of the renderer to the `register_renderer` method of our simulation object. The additional arguments are the name of the variable to plot on the tissue (if any), and a dictionary of arguments for the renderer class. Here, we supply (optional) arguments to `MatplotlibRenderer`: `view` defines the default angle of the 3D visualization (a top view in this case), and `axes` determines whether axes should be visible or not.<jupyter_code>sim.register_renderer(multicell.rendering.MatplotlibRenderer, None, {"view": (90, -90), "axes":False})
sim.renderer.display()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06604107648725212, 'fraction_numerical': 0.008321529745042492, 'mean_word_length': 4.660320641282565, 'pattern_counts': {'":': 2, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '482910', 'license': 'MIT', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1492, 'n_words': 714, 'path': 'examples/01 - Creating a simple tissue.ipynb', 'repo_name': 'pauloernestom/multicell', 'size': '5648'}