<jupyter_start><jupyter_text>This is the second example about diffusion. In this one, we will show that diffusion, coupled with degradation and non-uniform synthesis, can result in concentration gradients.The code for this example is mostly identical to that of the previous example, therefore we will only explain the parts that differ from the previous example. Preparation<jupyter_code>%matplotlib notebook<jupyter_output><empty_output><jupyter_text>Imports<jupyter_code>import multicell
import numpy as np<jupyter_output><empty_output><jupyter_text>Problem definition Simulation and tissue structure<jupyter_code>sim = multicell.simulation_builder.generate_cell_grid_sim(20, 1, 1, 1e-3)<jupyter_output><empty_output><jupyter_text>Biological species<jupyter_code>sim.register_cell_variable("a")<jupyter_output><empty_output><jupyter_text>ConstantsIn this example, we introduce two additional constants. `mu_a` is the degradation - and turnover - rate of `a` (common to all cells) and `A` is a relative synthesis rate of `a` (20 in the first 10 cells do, 0 in the others).<jupyter_code>A = np.array([20] * 10 + [0] * 10)
sim.set_constants({"D_a": 100., "mu_a": 1., "A": A})<jupyter_output><empty_output><jupyter_text>Differential equationsThis time, the differential equation governing *a* is slightly more complex, as it includes a degradation term and a synthesis term.<jupyter_code>def da_dt(simulation, a, c_a, D_a, mu_a, A, adjacency_matrix, **kwargs):
    return simulation.diffusion(D_a, c_a, adjacency_matrix) - mu_a * a + mu_a * A

sim.set_ODE("a", da_dt)<jupyter_output><empty_output><jupyter_text>The equation is designed so that the system has a steady state, and the total amount of `a` in the system at that steady state is independent of the value of `mu_a`, the turnover rate. We can therefore safely change the value of `mu_a` to modify the turnover without affecting the scale of the concentration values, which is useful for visualization purposes. Initial conditions<jupyter_code>sim.initialize_cell_variables()

a0 = A # Same as in the previous example

sim.set_cell_variable("a", a0)<jupyter_output><empty_output><jupyter_text>Duration<jupyter_code>sim.set_duration(4)
sim.set_time_steps(10, "log2")<jupyter_output><empty_output><jupyter_text>Rendering<jupyter_code>sim.register_renderer(multicell.rendering.MatplotlibRenderer, "c_a", {"max_cmap": 20, "view": (90, -90), "axes": False})<jupyter_output><empty_output><jupyter_text>Visualization of the initial state<jupyter_code>sim.renderer.display("c_a")<jupyter_output><empty_output><jupyter_text>Simulation<jupyter_code>sim.simulate()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09769026883756153, 'fraction_numerical': 0.012873911397198031, 'mean_word_length': 7.865771812080537, 'pattern_counts': {'":': 6, '<': 45, '<?xml version=': 0, '>': 45, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '291037', 'license': 'MIT', 'n_tokens_mistral': 896, 'n_tokens_neox': 852, 'n_words': 245, 'path': 'examples/03 - Diffusion with turnover.ipynb', 'repo_name': 'pauloernestom/multicell', 'size': '2641'}