예제 #1
0
def solve_mb(reverse, N_points, K1, K2, K3, n_oligL, n_oligP, Pt, Lt):
    """
    Solve mass balance equations for the Assembly AutoInhibition model.
    
    Returns a tuple of arrays for the free protein and free ligand concentrations.
    """

    p = np.zeros(N_points)
    l = np.zeros(N_points)

    # if reverse titration setup swap titrant and stationary
    if (reverse):
        tmp = Pt
        Pt = Lt
        Lt = tmp

    p[0] = Pt[0]
    l[0] = Lt[0]

    for i in range(N_points - 1):

        # mass balance equations
        def equations(x):
            p, l = x
            return [p + K1*p*l + K1*K2*p*l**2. + n_oligP*(K3**(n_oligL+n_oligP-1))*p**n_oligP*l**n_oligL - Pt[i+1], \
                    l + K1*p*l + 2.*K1*K2*p*l**2. + n_oligL*(K3**(n_oligL+n_oligP-1))*p**n_oligP*l**n_oligL - Lt[i+1]]

        sol = OptimizeResult(success=False)
        ptmp = -1
        ltmp = -1
        j = 1.
        # try to solve using previous free concentrations as initial guesses. Maximum number of iterations is large as gradient may be very shallow
        sol = solve_mass_balance(equations, (p[i], l[i]),
                                 method='lm',
                                 options={'maxiter': 2000})
        ptmp, ltmp = sol.x
        # if no solution try to solve with different initial conditions and solver options
        if (not sol.success):
            sol = solve_mass_balance(equations, (Pt[i], Lt[i]),
                                     method='lm',
                                     options={
                                         'factor': 1,
                                         'maxiter': 8000
                                     })
            ptmp, ltmp = sol.x
            # if still no solution...bugger
            if (not sol.success):
                print("ERROR: Could not find solution...")

        l[i + 1] = ltmp
        p[i + 1] = ptmp

    return (p, l)
예제 #2
0
def solve_mb(N_points, K_AB, K_AL, K_BL, a, At, Bt, Lt):
    """
    Solve mass balance equations for the model.
    
    [A]t = [A] + K_AB*[A]*[B] + K_AL*[A]*[L] + a*K_AB*K_AL*K_BL*[A]*[B]*[L]
    [B]t = [B] + K_AB*[A]*[B] + K_BL*[B]*[L] + a*K_AB*K_AL*K_BL*[A]*[B]*[L]
    [L]t = [L] + K_AL*[A]*[L] + K_BL*[B]*[L] + a*K_AB*K_AL*K_BL*[A]*[B]*[L]
    """

    A = np.zeros(N_points)
    B = np.zeros(N_points)
    L = np.zeros(N_points)

    for i in range(N_points):

        # mass balance equations
        def equations(x):
            A, B, L = x
            return [A + K_AB*A*B + K_AL*A*L + a*K_AB*K_AL*K_BL*A*B*L - At[i], \
                    B + K_AB*A*B + K_BL*B*L + a*K_AB*K_AL*K_BL*A*B*L - Bt[i], \
                    L + K_AL*A*L + K_BL*B*L + a*K_AB*K_AL*K_BL*A*B*L - Lt[i]]

        sol = OptimizeResult(success=False)
        Atmp = -1
        Btmp = -1
        Ltmp = -1
        j = 1.
        # try to solve using total concentrations as initial guesses. Maximum number of iterations is large as gradient may be very shallow
        sol = solve_mass_balance(equations, (At[i], Bt[i], Lt[i]),
                                 method='lm',
                                 options={'maxiter': 2000})
        Atmp, Btmp, Ltmp = sol.x
        # if no solution try to solve with different initial conditions and solver options
        if (not sol.success and i != 0):
            sol = solve_mass_balance(equations, (A[i - 1], B[i - 1], L[i - 1]),
                                     method='lm',
                                     options={
                                         'factor': 1,
                                         'maxiter': 8000
                                     })
            Atmp, Btmp, Ltmp = sol.x
            # if still no solution...bugger
            if (not sol.success):
                print("ERROR: Could not find solution...")

        A[i] = Atmp
        B[i] = Btmp
        L[i] = Ltmp

    return (A, B, L)
예제 #3
0
def solve_mb(reverse, N_points, K1, K2, K3, m, n_oligL, n_oligP, Pt, Lt):
    """
    Solve mass balance equations for the Assembly AutoInhibition model.
    
    Returns a tuple of arrays for the free protein and free ligand concentrations.
    """
                
    p = np.zeros(N_points)
    l = np.zeros(N_points)
    
    # if reverse titration setup swap titrant and stationary    
    if(reverse):
        tmp = Pt
        Pt = Lt
        Lt = tmp
    
    p[0] = Pt[0]
    l[0] = Lt[0]
    
    for i in range(N_points-1):
        
        # mass balance equations
        def equations(x):
            p,l = x
            return [p + K1*p*l + K1*K2**(m-1.)*p*l**m + n_oligP*(K3**(n_oligL+n_oligP-1))*p**n_oligP*l**n_oligL - Pt[i+1], \
                    l + K1*p*l + m*K1*K2**(m-1.)*p*l**m + n_oligL*(K3**(n_oligL+n_oligP-1))*p**n_oligP*l**n_oligL - Lt[i+1]]
    
        sol = OptimizeResult(success=False)
        ptmp = -1
        ltmp = -1
        j = 1.
        # try to solve using previous free concentrations as initial guesses. Maximum number of iterations is large as gradient may be very shallow
        sol = solve_mass_balance(equations,(p[i],l[i]),method='lm',options={'maxiter':2000})
        ptmp,ltmp = sol.x
        # if no solution try to solve with different initial conditions and solver options
        if(not sol.success):
            sol = solve_mass_balance(equations,(Pt[i],Lt[i]),method='lm',options={'factor':1,'maxiter':8000})
            ptmp,ltmp = sol.x
            # if still no solution...bugger
            if(not sol.success):
                print("ERROR: Could not find solution...")
    
        l[i+1] = ltmp
        p[i+1] = ptmp
        
    return (p,l)
예제 #4
0
def solve_mb(N_points, K1, K2, At, BCt):
    """
    Solve mass balance equations for the model.
    
    [A]t  = [A] + K1*K2*[BC]^2*[A]
    [BC]t = [BC] + K1*[BC]^2 + K1*K2*[BC]^2*[A]
    """
                
    A = np.zeros(N_points)
    BC = np.zeros(N_points)
    
    for i in range(N_points):
        
        # mass balance equations
        def equations(x):
            A,BC = x
            return [A + K1*K2*BC**2*A - At[i], \
                    BC + K1*BC**2 + K1*K2*BC**2*A - BCt[i]]
    
        sol = OptimizeResult(success=False)
        Atmp = -1
        BCtmp = -1
        j = 1.
        # try to solve using total concentrations as initial guesses. Maximum number of iterations is large as gradient may be very shallow
        sol = solve_mass_balance(equations,(At[i],BCt[i]),method='lm',options={'maxiter':2000})
        Atmp,BCtmp = sol.x
        # if no solution try to solve with different initial conditions and solver options
        if(not sol.success and i!=0):
            sol = solve_mass_balance(equations,(A[i-1],BC[i-1]),method='lm',options={'factor':1,'maxiter':8000})
            Atmp,BCtmp = sol.x
            # if still no solution...bugger
            if(not sol.success):
                print("ERROR: Could not find solution...")
    
        A[i] = Atmp
        BC[i] = BCtmp
        
    return (A,BC)