MaxParadiz
MaxParadiz

Reputation: 15

Unable to find a symbolic solution using Sympy solve

I am working with a kinetic model that describes the fluorescence emission of a molecule.

I am able to experimentally measure four parameters: Two lifetimes (τ1, τ2) the fluorescence quantum yield (ϕf), and a radiative rate (kr).

My model contains three unkown rates, kMR, kRM, and knr. I have a set of three equations that involve all of these values, and I want to solve for the three unknowns using sympy.

Here is the code:

from sympy import *                                                                                                                                         
                                                                                                                                                            
kr, k1, k2, phi, kMR,kRM,knr = symbols('kr k1 k2 phi kMR kRM knr', real=True)                                                                               
                                                                                                                                                            
                                                                                                                                                            
#kr = 0.00014                                                                                                                                               
#k1 = 1/9                                                                                                                                                   
#k2 = 1/49                                                                                                                                                  
#phi= 0.005                                                                                                                                                 
                                                                                                                                                            
Phi = kr/(kr+kMR-kMR*kRM/(kRM+knr))                                                                                                                         
X = kr + kMR                                                                                                                                                
Y = kRM + knr                                                                                                                                               
K1 = (X+Y+sqrt(X**2-2*X*Y+Y**2+4*kMR*kRM))/2                                                                                                                
K2 = (X+Y-sqrt(X**2-2*X*Y+Y**2+4*kMR*kRM))/2                                                                                                                
                                                                                                                                                            
solutions = solve([K1-k1,K2-k2,Phi-phi],(kMR,kRM,knr))                                                                                                      
print(solutions) 

If I uncomment the measured values, a numerical solution will be found within a few seconds. However, my measurements are prone to errors, so I am interested in exploring the whole space of solutions to see how sensitive the model is to each parameter. I also have different measured values from different experiments. So, I want to obtain symbolic expressions for kMR, kRM, and knr in terms of the measured values. Unfortunately, if I run this it just does not converge.

Could you help me obtain the symbolic solution that I am looking for?

Thank you!

Upvotes: 1

Views: 122

Answers (1)

Oscar Benjamin
Oscar Benjamin

Reputation: 14480

I'm not sure what exactly solve is doing but I suggest rewriting your equations without the square root which you can do with unrad. For example your first equation is:

In [50]: K1 - k1                                                                                                                               
Out[50]: 
                                _____________________________________________________________________
                               ╱                       2                                           2 
      kMR   kRM   knr   kr   ╲╱  4⋅kMR⋅kRM + (kMR + kr)  - (2⋅kMR + 2⋅kr)⋅(kRM + knr) + (kRM + knr)  
-k₁ + ─── + ─── + ─── + ── + ────────────────────────────────────────────────────────────────────────
       2     2     2    2                                       2                                    

In [51]: from sympy.solvers.solvers import unrad                                                                                               

In [52]: unrad(K1 - k1)                                                                                                                        
Out[52]: 
⎛  2                                                                   ⎞
⎝k₁  - k₁⋅kMR - k₁⋅kRM - k₁⋅knr - k₁⋅kr + kMR⋅knr + kRM⋅kr + knr⋅kr, []⎠

Applying this gives a system of polynomials whose solutions are possibly a superset of the solutions of the original system.

That gives:

In [53]: eq1 = unrad(K1-k1)[0]                                                                                                                 

In [54]: eq2 = unrad(K2-k2)[0]                                                                                                                 

In [55]: solve([eq1, eq2, Phi-phi], [kMR, kRM, knr])                                                                                           
Out[55]: 
⎡⎛  k₁⋅k₂⋅φ                   k₁⋅k₂⋅(k₁⋅φ - kr)⋅(k₂⋅φ - kr)            k₁⋅k₂⋅kr⋅(φ - 1)      ⎞⎤
⎢⎜- ─────── + k₁ + k₂ - kr, ──────────────────────────────────, ─────────────────────────────⎟⎥
⎢⎜     kr                      ⎛                            2⎞                              2⎟⎥
⎣⎝                          kr⋅⎝k₁⋅k₂⋅φ - k₁⋅kr - k₂⋅kr + kr ⎠  k₁⋅k₂⋅φ - k₁⋅kr - k₂⋅kr + kr ⎠⎦

Upvotes: 3

Related Questions