# Symbolic Calculation of Optimal Ribosomal Allocation
(c) This work is licensed under a Creative Commons Attribution License CC-BY 4.0. All code contained herein is licensed under an MIT license




```python
import sympy as sp
```

In the main text of this work, we present analytical solutions for the steady-state growth rate and potential ribosomal allocations as functions of the simple model parameters. While we drive almost all of these explicitly in the Supplementary Text, we state that the optimal allocation towards ribosomes was computed through differentiation of a complex function. Here, we perform this calculation symbolically to yield an identical result as Eq. S30 of the supplemental text.


We begin by definiting the necessary symbols we will use in [SymPy](https://www.sympy.org/en/index.html), the symbolic computing library for Python.


```python
# Define symbols
gamma_max = sp.Symbol(r'{{\gamma_{max}}}') # Translation rate
nu_max = sp.Symbol(r'{{\nu_{max}}}') # Maximal metabolic rate
phi_Rb = sp.Symbol(r'{{\phi_R}}') # Allocation towards ribosomes
phi_O = sp.Symbol(r'{{\phi_O}}') # Allocation towards other proteins
K_M = sp.Symbol(r'{{K_M^{c_{pc}}}}')  # Michaelis-Menten constant for translatio
cpc = sp.Symbol(r'{{c_{pc}}}') # Concentration of precursors
```




$\displaystyle \frac{\lambda \left(\lambda {{K_M^{c_{pc}}}} - \lambda + {{\gamma_{max}}} {{\phi_R}}\right)}{\lambda {{\phi_R}} - \lambda - {{\gamma_{max}}} {{\phi_R}}^{2} + {{\gamma_{max}}} {{\phi_R}}}$



We can now define the necessary equations. Specifically, we define here the equation defined in Eq. S24,
including the short-hand notation for the maximal metabolic output $\mathsf{N}$ and maximal translational outpu $\Gamma$.


```python
# Define the metbolic outputs
Nu = nu_max * (1 - phi_O - phi_Rb);
Gamma = gamma_max * phi_Rb;

# Define the equation for the steady-state growth rate piecewise using the 
# quadratic form, Eq. S22.
a =  (1 - K_M)
b = Nu + Gamma
c = Nu * Gamma
lam = (-b + sp.sqrt(b**2 - 4 * a * c)) / (2 * a)
lam
```




$\displaystyle \frac{- {{\gamma_{max}}} {{\phi_R}} - {{\nu_{max}}} \left(- {{\phi_O}} - {{\phi_R}} + 1\right) + \sqrt{- {{\gamma_{max}}} {{\nu_{max}}} {{\phi_R}} \left(4 - 4 {{K_M^{c_{pc}}}}\right) \left(- {{\phi_O}} - {{\phi_R}} + 1\right) + \left({{\gamma_{max}}} {{\phi_R}} + {{\nu_{max}}} \left(- {{\phi_O}} - {{\phi_R}} + 1\right)\right)^{2}}}{2 - 2 {{K_M^{c_{pc}}}}}$



With the steady-state growth rate now defined, we can compute the derivative with respect to $\phi_{Rb}$,


```python
dlam_dphiRb = lam.diff(phi_Rb)
dlam_dphiRb
```




$\displaystyle \frac{- {{\gamma_{max}}} + {{\nu_{max}}} + \frac{\frac{{{\gamma_{max}}} {{\nu_{max}}} {{\phi_R}} \left(4 - 4 {{K_M^{c_{pc}}}}\right)}{2} - \frac{{{\gamma_{max}}} {{\nu_{max}}} \left(4 - 4 {{K_M^{c_{pc}}}}\right) \left(- {{\phi_O}} - {{\phi_R}} + 1\right)}{2} + \frac{\left(2 {{\gamma_{max}}} - 2 {{\nu_{max}}}\right) \left({{\gamma_{max}}} {{\phi_R}} + {{\nu_{max}}} \left(- {{\phi_O}} - {{\phi_R}} + 1\right)\right)}{2}}{\sqrt{- {{\gamma_{max}}} {{\nu_{max}}} {{\phi_R}} \left(4 - 4 {{K_M^{c_{pc}}}}\right) \left(- {{\phi_O}} - {{\phi_R}} + 1\right) + \left({{\gamma_{max}}} {{\phi_R}} + {{\nu_{max}}} \left(- {{\phi_O}} - {{\phi_R}} + 1\right)\right)^{2}}}}{2 - 2 {{K_M^{c_{pc}}}}}$



which is equivalent to Eq. S28 upon some manual rearrangement. We can now solve this derivative for the value of $\phi_{Rb}$ when $\tfrac{\partial \lambda}{\partial \phi_{Rb}} = 0$.


```python
# Solve for the optimal phiRb
opt_phiRb = sp.solve(dlam_dphiRb, phi_Rb)[0]
opt_phiRb
```




$\displaystyle \frac{\left({{\phi_O}} - 1\right) \left(- {{\nu_{max}}} \left(- 2 {{K_M^{c_{pc}}}} {{\gamma_{max}}} + {{\gamma_{max}}} + {{\nu_{max}}}\right) + \sqrt{{{K_M^{c_{pc}}}} {{\gamma_{max}}} {{\nu_{max}}}} \left(- {{\gamma_{max}}} + {{\nu_{max}}}\right)\right)}{- 4 {{K_M^{c_{pc}}}} {{\gamma_{max}}} {{\nu_{max}}} + {{\gamma_{max}}}^{2} + 2 {{\gamma_{max}}} {{\nu_{max}}} + {{\nu_{max}}}^{2}}$



The above equation is idential to Eq. S30 upon some algebraic rearrangement.

60b8005e18468d55ad79242d336e433fe3ae4c46
ipynb
Jupyter Notebook
code/symbolic_calculations.ipynb
cremerlab/ribosomal_allocation
a48828e00906c18bc3c49d109b3874c531098ce1
MIT
code/symbolic_calculations.ipynb
cremerlab/ribosomal_allocation
a48828e00906c18bc3c49d109b3874c531098ce1
MIT
code/symbolic_calculations.ipynb
cremerlab/ribosomal_allocation
a48828e00906c18bc3c49d109b3874c531098ce1
MIT
Qwen/Qwen-72B
1. YES
2. YES