pykingenie.utils package

Numerical, fitting, processing, and plotting helpers for pykingenie.

Submodules

pykingenie.utils.compound_file module

Minimal reader for Microsoft compound files (OLE2 / MS-CFB), read-only.

Compound files hold a small file system (storages and streams) inside one file. Biacore result files (.blr) use this container. Only what is needed to read every stream is implemented: the header, the DIFAT, the FAT, the directory tree, and the mini stream used for small streams. See the [MS-CFB] specification.

pykingenie.utils.compound_file.read_compound_file(path)[source]

Read every stream of a compound file.

Parameters:

path (str) – Path to the compound file.

Returns:

Stream contents (bytes), keyed by their path inside the file, for example ‘_Cycle 1/_Window 1/_Curve 1/Keywords’. Control characters at the start of names are removed.

Return type:

dict

Raises:

ValueError – If the file is not a compound file or its structure is inconsistent.

pykingenie.utils.compound_file.is_compound_file(path)[source]

Return True if the file starts with the compound file signature.

Parameters:

path (str) – Path to the file.

Returns:

Whether the file is a compound file.

Return type:

bool

pykingenie.utils.fit_results module

Data identity and statistics for saved kinetic fitting results.

pykingenie.utils.fit_results.fitting_data_fingerprint(fitter)[source]

Identify numeric inputs, including trace order, Smax grouping and trimming.

Hash values rather than Python container types, so converting a list to an equivalent array does not invalidate a fit. Display names are excluded.

pykingenie.utils.fit_results.saved_fit_residuals(fitter, state)[source]

Return RSS, observation count and identity for exactly the fitted points.

Missing or non-finite predictions are rejected instead of silently scoring a different set of observations. Dissociation-only time limits are applied to the current, validated raw inputs.

pykingenie.utils.fit_results.saved_fit_statistics(rss, n, k)[source]

Unweighted reduced chi squared and Bayesian information criterion.

BIC = n*log(RSS/n) + k*log(n). A perfect fit has BIC = -infinity. Positive residual degrees of freedom are required for comparison.

pykingenie.utils.fitting_general module

General curve-fitting utilities for exponential signal models.

pykingenie.utils.fitting_general.fit_single_exponential(y, t, min_log_k=-5, max_log_k=5, log_k_points=50)[source]

Fit a single exponential to a signal.

Parameters:
  • y (np.ndarray) – Signal values.

  • t (np.ndarray) – Time values.

  • min_log_k (float, optional) – Minimum logarithmic value for k_obs initial estimation, default is -5.

  • max_log_k (float, optional) – Maximum logarithmic value for k_obs initial estimation, default is 5.

  • log_k_points (int, optional) – Number of points in the logarithmic scale for k_obs initial estimation, default is 50.

Returns:

  • np.ndarray – Fitted parameters (a0, a1, k_obs).

  • np.ndarray – Covariance matrix of the fitted parameters.

  • np.ndarray – Fitted y values.

pykingenie.utils.fitting_general.fit_double_exponential(y, t, min_log_k=-4, max_log_k=4, log_k_points=24)[source]

Fit a double exponential to a signal.

Parameters:
  • y (np.ndarray) – Signal values.

  • t (np.ndarray) – Time values.

  • min_log_k (float, optional) – Minimum logarithmic value for k_obs initial estimation, default is -4.

  • max_log_k (float, optional) – Maximum logarithmic value for k_obs initial estimation, default is 4.

  • log_k_points (int, optional) – Number of points in the logarithmic scale for k_obs initial estimation, default is 22.

Returns:

  • np.ndarray – Fitted parameters (a0, a1, k_obs1, a2, k_obs2).

  • np.ndarray – Covariance matrix of the fitted parameters.

  • np.ndarray – Fitted y values.

pykingenie.utils.fitting_general.re_fit(fit, cov, fit_vals, fit_fx, low_bounds, high_bounds, times, **kwargs)[source]

Re-fit data by evaluating the difference between fitted parameters and bounds.

If the difference is less than 2 percent, the bounds are relaxed by a factor of 10 and the fitting is repeated.

Parameters:
  • fit (list) – Fitted parameters.

  • cov (np.ndarray) – Covariance matrix of the fitted parameters.

  • fit_vals (list) – Fitted values for each signal, same dimensions as signal_lst.

  • fit_fx (callable) – Function to fit the data - returns fit, cov, fit_vals.

  • low_bounds (list) – Lower bounds for the parameters.

  • high_bounds (list) – Upper bounds for the parameters.

  • times (int) – Number of times to re-fit the data.

  • **kwargs – Additional arguments to pass to the fitting function.

Returns:

  • np.ndarray – Fitted parameters after re-fitting.

  • np.ndarray – Covariance matrix of the fitted parameters after re-fitting.

  • list – Fitted values for each signal after re-fitting.

  • np.ndarray – Lower bounds for the parameters after re-fitting.

  • np.ndarray – Upper bounds for the parameters after re-fitting.

pykingenie.utils.fitting_general.re_fit_2(fit, cov, fit_vals_a, fit_vals_b, fit_fx, low_bounds, high_bounds, times, **kwargs)[source]

Re-fit data for two signals by evaluating the difference between fitted parameters and bounds.

If the difference is less than 2 percent, the bounds are relaxed by a factor of 10 and the fitting is repeated. This function is used for fitting two signals at once, e.g. fitting association and dissociation signals simultaneously.

Parameters:
  • fit (list) – Fitted parameters.

  • cov (np.ndarray) – Covariance matrix of the fitted parameters.

  • fit_vals_a (list) – Fitted values for the first set of signals.

  • fit_vals_b (list) – Fitted values for the second set of signals.

  • fit_fx (callable) – Function to fit the data - returns fit, cov, fit_vals_a, fit_vals_b.

  • low_bounds (list) – Lower bounds for the parameters.

  • high_bounds (list) – Upper bounds for the parameters.

  • times (int) – Number of times to re-fit the data.

  • **kwargs – Additional arguments to pass to the fitting function.

Returns:

  • np.ndarray – Fitted parameters after re-fitting.

  • np.ndarray – Covariance matrix of the fitted parameters after re-fitting.

  • list – Fitted values for the first set of signals after re-fitting.

  • list – Fitted values for the second set of signals after re-fitting.

  • np.ndarray – Lower bounds for the parameters after re-fitting.

  • np.ndarray – Upper bounds for the parameters after re-fitting.

pykingenie.utils.fitting_general.curve_fit_log_scale(f, xdata, ydata, p0, bounds, **kwargs)[source]

curve_fit with the strictly positive parameters fitted on a log scale.

Rate constants, Kd and amplitudes span orders of magnitude, so equal steps in each parameter are badly scaled and the optimizer can need many iterations. Parameters whose lower bound is above zero are fitted as log(p); the others (for example a time offset t0) stay on a linear scale.

The covariance is converted back with cov_p = D·cov_q·D, D = diag(p) for the log-scaled parameters. At the same optimum this is the covariance a linear-scale fit reports, and the correlation matrix is the same.

Parameters:
  • f (callable) – Model function f(xdata, *params), as for scipy.optimize.curve_fit.

  • xdata (array_like) – Independent variable, passed to f unchanged.

  • ydata (array_like) – Data to fit.

  • p0 (array_like) – Initial parameters, within the bounds.

  • bounds (tuple) – Lower and upper bounds, each a scalar or one value per parameter.

  • **kwargs – Passed to scipy.optimize.curve_fit.

Returns:

  • np.ndarray – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

pykingenie.utils.fitting_solution module

Fit kinetic models for solution-based experiments.

pykingenie.utils.fitting_solution.fit_one_site_solution(signal_lst, time_lst, ligand_conc_lst, protein_conc_lst, initial_parameters, low_bounds, high_bounds, fit_signal_E=False, fit_signal_S=False, fit_signal_ES=True, fixed_t0=True, fixed_Kd=False, Kd_value=None, fixed_koff=False, koff_value=None)[source]

Global fit to association and dissociation traces - one-to-one binding model.

Parameters:
  • signal_lst (list) – List of signals. We assume initial values as follows: E = E_tot, S = S_tot, ES = 0.

  • time_lst (list) – List of time points for the association signals.

  • ligand_conc_lst (list) – List of ligand concentrations, one per element in signal_lst.

  • protein_conc_lst (list) – List of protein concentrations, one per element in signal_lst.

  • initial_parameters (list) – Initial parameters for the fit.

  • low_bounds (list) – Lower bounds for the fit parameters.

  • high_bounds (list) – Upper bounds for the fit parameters.

  • fit_signal_E (bool, optional) – If True, fit the signal of the free protein, default is False.

  • fit_signal_S (bool, optional) – If True, fit the signal of the free ligand, default is False.

  • fit_signal_ES (bool, optional) – If True, fit the signal of the complex, default is True.

  • fixed_t0 (bool, optional) – If True, the initial time point is zero, default is True.

  • fixed_Kd (bool, optional) – If True, the equilibrium dissociation constant is fixed, default is False.

  • Kd_value (float, optional) – Value of the equilibrium dissociation constant if fixed_Kd is True.

  • fixed_koff (bool, optional) – If True, the dissociation rate constant is fixed, default is False.

  • koff_value (float, optional) – Value of the dissociation rate constant if fixed_koff is True.

Returns:

  • list – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

  • list – Fitted values for each signal, same dimensions as signal_lst.

  • list – Names of the fitted parameters.

pykingenie.utils.fitting_solution.fit_induced_fit_solution(signal_lst, time_lst, ligand_conc_lst, protein_conc_lst, initial_parameters, low_bounds, high_bounds, fit_signal_E=False, fit_signal_S=False, fit_signal_ES=True, ESint_equals_ES=True, fixed_t0=True, fixed_kon=False, kon_value=None, fixed_koff=False, koff_value=None, fixed_kc=False, kc_value=None, fixed_krev=False, krev_value=None, max_nfev=None, fit_scale_factor=False)[source]

Global fit to association and dissociation traces - one-to-one binding model with induced fit.

Parameters:
  • signal_lst (list) – List of signals. We assume initial values as follows: E = E_tot, S = S_tot, ES = 0, ESint = 0.

  • time_lst (list) – List of time points for the association signals.

  • ligand_conc_lst (list) – List of ligand concentrations, one per element in signal_lst.

  • protein_conc_lst (list) – List of protein concentrations, one per element in signal_lst.

  • initial_parameters (list) – Initial parameters for the fit.

  • low_bounds (list) – Lower bounds for the fit parameters.

  • high_bounds (list) – Upper bounds for the fit parameters.

  • fit_signal_E (bool, optional) – If True, fit the signal of the free protein, default is False.

  • fit_signal_S (bool, optional) – If True, fit the signal of the free ligand, default is False.

  • fit_signal_ES (bool, optional) – If True, fit the signal of the complex, default is True.

  • ESint_equals_ES (bool, optional) – If True, the signal of the intermediate complex is equal to the signal of the trapped complex, default is True.

  • fixed_t0 (bool, optional) – If True, the initial time point is zero, default is True.

  • fixed_kon (bool, optional) – If True, the association rate constant is fixed, default is False.

  • kon_value (float, optional) – Value of the association rate constant if fixed_kon is True.

  • fixed_koff (bool, optional) – If True, the dissociation rate constant is fixed, default is False.

  • koff_value (float, optional) – Value of the dissociation rate constant if fixed_koff is True.

  • fixed_kc (bool, optional) – If True, the induced fit rate constant is fixed, default is False.

  • kc_value (float, optional) – Value of the induced fit rate constant if fixed_kc is True.

  • fixed_krev (bool, optional) – If True, the reverse induced fit rate constant is fixed, default is False.

  • krev_value (float, optional) – Value of the reverse induced fit rate constant if fixed_krev is True.

  • max_nfev (int, optional) – Maximum number of function evaluations for the fit.

  • fit_scale_factor (bool, optional) – If True, fit a scale factor for each signal, default is False.

Returns:

  • list – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

  • list – Fitted values for each signal, same dimensions as signal_lst.

  • list – Names of the fitted parameters.

Notes

The initial_parameters are given in the following order:

  • signal_E if fit_signal_E (signal of the free protein)

  • signal_S if fit_signal_S (signal of the free ligand)

  • signal_ES if fit_signal_ES (signal of the trapped complex)

  • signal_ESint if fit_signal_ES and not ESint_equals_ES (signal of the intermediate complex) if ESint_equals_ES is True, then the trapped complex signal is used for both ES and ESint

  • k_on if not fixed_kon (association rate constant)

  • k_off if not fixed_koff (dissociation rate constant)

  • k_c if not fixed_kc (induced fit rate constant)

  • k_rev if not fixed_krev (reverse induced fit rate constant)

  • t0_1 if not fixed_t0 (initial time point for the first signal array, default is 0)

  • t0_2 if not fixed_t0 (initial time point for the second signal array, default is 0)

… - scale_factor_1 if fit_scale_factor (scale factor for the first signal) - scale_factor_2 if fit_scale_factor (scale factor for the second signal) …

pykingenie.utils.fitting_solution.fit_conformational_selection_solution(signal_lst, time_lst, ligand_conc_lst, protein_conc_lst, initial_parameters, low_bounds, high_bounds, fit_signal_E=False, E1_equals_E2=True, fit_signal_S=False, fit_signal_E2S=True, fixed_t0=True, fixed_kon=False, kon_value=None, fixed_koff=False, koff_value=None, fixed_kc=False, kc_value=None, fixed_krev=False, krev_value=None, max_nfev=None, fit_scale_factor=False)[source]

Global fit to association and dissociation traces - one-to-one binding model with conformational selection.

Parameters:
  • signal_lst (list) – List of signals. We assume initial values as follows: E = E_tot, S = S_tot, ES = 0, ESint = 0.

  • time_lst (list) – List of time points for the association signals.

  • ligand_conc_lst (list) – List of ligand concentrations, one per element in signal_lst.

  • protein_conc_lst (list) – List of protein concentrations, one per element in signal_lst.

  • initial_parameters (list) – Initial parameters for the fit.

  • low_bounds (list) – Lower bounds for the fit parameters.

  • high_bounds (list) – Upper bounds for the fit parameters.

  • fit_signal_E (bool, optional) – If True, fit the signal of the free protein, default is False.

  • E1_equals_E2 (bool, optional) – If true the signal in protein state 1 is equal to the signal in protein state 2, default is True.

  • fit_signal_S (bool, optional) – If True, fit the signal of the free ligand, default is False

  • fit_signal_E2S (bool, optional) – If true fit the signal of the complex, default is True.

  • fixed_t0 (bool, optional) – If True, the initial time point is zero, default is True.

  • fixed_kon (bool, optional) – If True, the association rate constant is fixed, default is False.

  • kon_value (float, optional) – Value of the association rate constant if fixed_kon is True.

  • fixed_koff (bool, optional) – If True, the dissociation rate constant is fixed, default is False.

  • koff_value (float, optional) – Value of the dissociation rate constant if fixed_koff is True.

  • fixed_kc (bool, optional) – If True, the induced fit rate constant is fixed, default is False.

  • kc_value (float, optional) – Value of the induced fit rate constant if fixed_kc is True.

  • fixed_krev (bool, optional) – If True, the reverse induced fit rate constant is fixed, default is False.

  • krev_value (float, optional) – Value of the reverse induced fit rate constant if fixed_krev is True.

  • max_nfev (int, optional) – Maximum number of function evaluations for the fit.

  • fit_scale_factor (bool, optional) – If True, fit a scale factor for each signal, default is False.

Returns:

  • list – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

  • list – Fitted values for each signal, same dimensions as signal_lst.

  • list – Names of the fitted parameters.

Notes

The initial_parameters are given in the following order:

  • signal_E1 if fit_signal_E (signal of the free protein state 1)

  • signal_E2 if fit_signal_E and E1_equals_E2 (signal of the free protein state 2)

  • signal_S if fit_signal_S (signal of the free ligand)

  • signal_E2S if fit_signal_E2S (signal of the complex)

  • k_on if not fixed_kon (association rate constant)

  • k_off if not fixed_koff (dissociation rate constant)

  • k_c if not fixed_kc (conformational rate constant)

  • k_rev if not fixed_krev (reverse conformational rate constant)

  • t0_1 if not fixed_t0 (initial time point for the first signal array, default is 0)

  • t0_2 if not fixed_t0 (initial time point for the second signal array, default is 0)

… - scale_factor_1 if fit_scale_factor (scale factor for the first signal) - scale_factor_2 if fit_scale_factor (scale factor for the second signal) …

pykingenie.utils.fitting_solution.find_initial_parameters_induced_fit_solution(signal_lst, time_lst, ligand_conc_lst, protein_conc_lst, fit_signal_E=False, fit_signal_S=False, fit_signal_ES=True, ESint_equals_ES=True, fixed_t0=True, np_linspace_low=-2, np_linspace_high=2, np_linspace_num=5, fit_scale_factor=False, scale_factor_tolerance=0.2)[source]

Find initial parameters for the global fit to association and dissociation traces - one-to-one binding model with induced fit.

Heuristic algorithm to explore a range of fixed kc and krev values, and fit kon and koff. This function is used to find the initial parameters for the fit_induced_fit_solution function.

Parameters:
  • signal_lst (list) – List of signals. We assume initial values as follows: E = E_tot, S = S_tot, ES = 0, ESint = 0.

  • time_lst (list) – List of time points for the association signals.

  • ligand_conc_lst (list) – List of ligand concentrations, one per element in signal_lst.

  • protein_conc_lst (list) – List of protein concentrations, one per element in signal_lst.

  • fit_signal_E (bool, optional) – If True, fit the signal of the free protein, default is False.

  • fit_signal_S (bool, optional) – If True, fit the signal of the free ligand, default is False.

  • fit_signal_ES (bool, optional) – If True, fit the signal of the complex, default is True.

  • ESint_equals_ES (bool, optional) – If True, the signal of the intermediate complex is equal to the signal of the trapped complex, default is True.

  • fixed_t0 (bool, optional) – If True, the initial time point is zero, default is True.

  • np_linspace_low (float, optional) – Lower bound for the logarithmic space to sample kc and krev, default is -2.

  • np_linspace_high (float, optional) – Upper bound for the logarithmic space to sample kc and krev, default is 2.

  • np_linspace_num (int, optional) – Number of points to sample in the logarithmic space, default is 5.

  • fit_scale_factor (bool, optional) – If True, fit a scale factor for each signal, default is False.

  • scale_factor_tolerance (float, optional) – Tolerance for the scale factor fit, default is 0.2.

Returns:

Best initial parameters found by the heuristic algorithm.

Return type:

np.ndarray

pykingenie.utils.fitting_solution.find_initial_parameters_conformational_selection_solution(signal_lst, time_lst, ligand_conc_lst, protein_conc_lst, fit_signal_E=False, E1_equals_E2=False, fit_signal_S=False, fit_signal_E2S=True, fixed_t0=True, np_linspace_low=-2, np_linspace_high=2, np_linspace_num=5, fit_scale_factor=False, scale_factor_tolerance=0.2)[source]

Find initial parameters for the global fit to association and dissociation traces one-to-one binding model with conformational selection.

Heuristic algorithm to explore a range of fixed kc and krev values, and fit kon and koff. This function is used to find the initial parameters for the fit_conformational_selection_solution function.

Parameters:
  • signal_lst (list) – List of signals

  • time_lst (list) – List of time points for the association signals.

  • ligand_conc_lst (list) – List of ligand concentrations, one per element in signal_lst.

  • protein_conc_lst (list) – List of protein concentrations, one per element in signal_lst.

  • fit_signal_E (bool, optional) – If True, fit the signal of the free protein, default is False.

  • fit_signal_S (bool, optional) – If True, fit the signal of the free ligand, default is False.

  • fit_signal_ES (bool, optional) – If True, fit the signal of the complex, default is True.

  • ESint_equals_ES (bool, optional) – If True, the signal of the intermediate complex is equal to the signal of the trapped complex, default is True.

  • fixed_t0 (bool, optional) – If True, the initial time point is zero, default is True.

  • np_linspace_low (float, optional) – Lower bound for the logarithmic space to sample kc and krev, default is -2.

  • np_linspace_high (float, optional) – Upper bound for the logarithmic space to sample kc and krev, default is 2.

  • np_linspace_num (int, optional) – Number of points to sample in the logarithmic space, default is 5.

  • fit_scale_factor (bool, optional) – If True, fit a scale factor for each signal, default is False.

  • scale_factor_tolerance (float, optional) – Tolerance for the scale factor fit, default is 0.2.

Returns:

Best initial parameters found by the heuristic algorithm.

Return type:

np.ndarray

pykingenie.utils.fitting_surface module

Fit steady-state and kinetic models for surface-based experiments.

pykingenie.utils.fitting_surface.guess_initial_signal(assoc_time_lst, assoc_signal_lst, time_limit=30, mask_lst=None)[source]

Guess the initial signal for each signal in the list by fitting single exponentials.

Used only for the one-to-one binding model in case one of the steps is not present.

Parameters:
  • assoc_time_lst (list) – List of association time arrays.

  • assoc_signal_lst (list) – List of association signal arrays.

  • time_limit (float, optional) – Time limit to consider for the fit, default is 30 seconds.

  • mask_lst (list, optional) – Boolean array per trace, True for the points to use (see trim_masks). The exponential is still extrapolated to the first time point. Default uses every point.

Returns:

List of initial signals for each association signal.

Return type:

list

pykingenie.utils.fitting_surface.trim_masks(time_lst, trim_time)[source]

Masks of the points at least trim_time after the start of each step.

Used to leave the first seconds of each association and dissociation out of the fit, for example to skip the bulk refractive index spike at the start of an SPR injection. The model still starts at the first time point of each step.

Parameters:
  • time_lst (list or None) – Time array of each step.

  • trim_time (float) – Time, from the first point of each step, to leave out of the fit.

Returns:

Boolean array per step, True for the points to fit. None if trim_time is 0 or time_lst is None, meaning every point is fitted.

Return type:

list or None

pykingenie.utils.fitting_surface.fit_steady_state_one_site(signal_lst, ligand_lst, initial_parameters, low_bounds, high_bounds, fixed_Kd=False, Kd_value=None)[source]

Fit a one-site binding model to a set of steady state signals.

Parameters:
  • signal_lst (list) – List of signals to fit, each signal is a numpy array.

  • ligand_lst (list) – List of ligand concentrations, each concentration is a numpy array.

  • initial_parameters (list) – Initial guess for the parameters.

  • low_bounds (list) – Lower bounds for the parameters.

  • high_bounds (list) – Upper bounds for the parameters.

  • fixed_Kd (bool, optional) – If True, Kd is fixed to Kd_value, default is False.

  • Kd_value (float, optional) – Value of Kd to use if fixed_Kd is True.

Returns:

  • list – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

  • list – Fitted values for each signal, same dimensions as signal_lst.

pykingenie.utils.fitting_surface.fit_steady_state_two_site(signal_lst, ligand_lst, initial_parameters, low_bounds, high_bounds, fixed_Kd=False, Kd_value=None, fit_sigma=False)[source]

Fit a two-site steady-state binding model with optional cooperativity.

Model parameters are one shared Kd and, for each trace, two response terms: Rmax_PL (singly-bound state) and Rmax_LPL (doubly-bound state). Optionally, a shared cooperativity factor sigma can also be fitted. If fit_sigma=False, the non-cooperative model is used (sigma=1).

Parameter order when fitting: - fixed_Kd=False, fit_sigma=False: [Kd, Rmax_PL_1, Rmax_LPL_1, …] - fixed_Kd=False, fit_sigma=True : [Kd, sigma, Rmax_PL_1, Rmax_LPL_1, …] - fixed_Kd=True, fit_sigma=False: [Rmax_PL_1, Rmax_LPL_1, …] - fixed_Kd=True, fit_sigma=True : [sigma, Rmax_PL_1, Rmax_LPL_1, …]

Parameters:
  • signal_lst (list) – List of steady-state signal arrays.

  • ligand_lst (list) – List of ligand concentration arrays (same structure as signal_lst).

  • initial_parameters (list) – Initial guess vector in the order documented above.

  • low_bounds (list) – Lower bounds for each fitted parameter.

  • high_bounds (list) – Upper bounds for each fitted parameter.

  • fixed_Kd (bool, optional) – If True, keep Kd fixed to Kd_value.

  • Kd_value (float, optional) – Value to use when fixed_Kd=True.

  • fit_sigma (bool, optional) – If True, fit sigma as a shared parameter.

Returns:

  • list – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

  • list – Fitted values for each trace, same dimensions as signal_lst.

pykingenie.utils.fitting_surface.fit_steady_state_two_site_heterogeneous_ligand(signal_lst, ligand_lst, initial_parameters, low_bounds, high_bounds, fixed_Kd1=False, Kd1_value=None, fixed_Kd2=False, Kd2_value=None, fixed_fraction_site1=False, fraction_site1_value=None)[source]

Fit a 2:1 heterogeneous ligand steady-state binding model.

The fitted curve is the sum of two 1:1 binding curves. fraction_site1 sets the fraction of the total response assigned to interaction 1, while 1 - fraction_site1 is assigned to interaction 2. Kd1, Kd2, and fraction_site1 are shared across all traces; each trace gets its own Rmax.

Parameter order when fitting: - default: [Kd1, Kd2, fraction_site1, Rmax_1, Rmax_2, …] - remove Kd1 from the vector when fixed_Kd1=True - remove Kd2 from the vector when fixed_Kd2=True - remove fraction_site1 when fixed_fraction_site1=True

Parameters:
  • signal_lst (list) – List of steady-state signal arrays.

  • ligand_lst (list) – List of ligand concentration arrays (same structure as signal_lst).

  • initial_parameters (list) – Initial guess vector in the order documented above.

  • low_bounds (list) – Lower bounds for each fitted parameter.

  • high_bounds (list) – Upper bounds for each fitted parameter.

  • fixed_Kd1 (bool, optional) – If True, keep Kd1 fixed to Kd1_value.

  • Kd1_value (float, optional) – Value to use when fixed_Kd1=True.

  • fixed_Kd2 (bool, optional) – If True, keep Kd2 fixed to Kd2_value.

  • Kd2_value (float, optional) – Value to use when fixed_Kd2=True.

  • fixed_fraction_site1 (bool, optional) – If True, keep fraction_site1 fixed to fraction_site1_value.

  • fraction_site1_value (float, optional) – Value to use when fixed_fraction_site1=True.

Returns:

  • list – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

  • list – Fitted values for each trace, same dimensions as signal_lst.

pykingenie.utils.fitting_surface.steady_state_one_site_asymmetric_ci95(kd_estimated, signal_lst, ligand_lst, initial_parameters, low_bounds, high_bounds, rss_desired)[source]

Calculate the asymmetric confidence interval for the steady-state signal.

Parameters:
  • kd_estimated (float) – Estimated Kd value.

  • signal_lst (list) – List of signals to fit, each signal is a numpy array.

  • ligand_lst (list) – List of ligand concentrations, each concentration is a numpy array.

  • initial_parameters (list) – Initial guess for the parameters (without the Kd!).

  • low_bounds (list) – Lower bounds for the parameters (without the Kd!).

  • high_bounds (list) – Upper bounds for the parameters (without the Kd!).

  • rss_desired (float) – Maximum residual sum of squares.

Returns:

95% asymmetric confidence interval for the Kd value [lower_bound, upper_bound].

Return type:

np.ndarray

pykingenie.utils.fitting_surface.fit_one_site_association(signal_lst, time_lst, analyte_conc_lst, initial_parameters, low_bounds, high_bounds, smax_idx=None, shared_smax=False, fixed_t0=True, fixed_Kd=False, Kd_value=None, fixed_koff=False, koff_value=None, mask_lst=None)[source]

Global fit to a list of association traces - one-to-one binding model.

Parameters:
  • signal_lst (list) – List of signals to fit, each signal is a numpy array.

  • time_lst (list) – List of time arrays.

  • analyte_conc_lst (list) – List of analyte concentrations, each element is a numpy array.

  • initial_parameters (list) – Initial guess for the parameters.

  • low_bounds (list) – Lower bounds for the parameters.

  • high_bounds (list) – Upper bounds for the parameters.

  • smax_idx (list, optional) – List of indices for the s_max parameters, used if shared_smax is True.

  • shared_smax (bool, optional) – If True, the s_max parameters are shared between the signals, default is False.

  • fixed_t0 (bool, optional) – If True, t0 is fixed to 0, otherwise we fit it, default is True.

  • fixed_Kd (bool, optional) – If True, Kd is fixed to Kd_value, default is False.

  • Kd_value (float, optional) – Value of Kd to use if fixed_Kd is True.

  • fixed_koff (bool, optional) – If True, koff is fixed to koff_value, default is False.

  • koff_value (float, optional) – Value of koff to use if fixed_koff is True.

  • mask_lst (list, optional) – Boolean array per trace, True for the points to fit (see trim_masks). The model is still evaluated at every point. Default fits every point.

Returns:

  • list – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

  • list – Fitted values for each signal, same dimensions as signal_lst.

pykingenie.utils.fitting_surface.fit_one_site_dissociation(signal_lst, time_lst, initial_parameters, low_bounds, high_bounds, fixed_t0=True, fixed_koff=False, koff_value=None, fit_s0=True, mask_lst=None)[source]

Global fit to a list of dissociation traces - one-to-one binding model.

Parameters:
  • signal_lst (list) – List of signals to fit, each signal is a numpy array.

  • time_lst (list) – List of time arrays.

  • initial_parameters (list) – Initial guess for the parameters.

  • low_bounds (list) – Lower bounds for the parameters.

  • high_bounds (list) – Upper bounds for the parameters.

  • fixed_t0 (bool, optional) – If True, t0 is fixed to 0, otherwise we fit it, default is True.

  • fixed_koff (bool, optional) – If True, koff is fixed to koff_value, default is False.

  • koff_value (float, optional) – Value of koff to use if fixed_koff is True.

  • fit_s0 (bool, optional) – If True, s0 is fitted, otherwise it is fixed to the first value of the signal, default is True.

  • mask_lst (list, optional) – Boolean array per trace, True for the points to fit (see trim_masks). The model is still evaluated at every point. Default fits every point.

Returns:

  • list – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

  • list – Fitted values for each signal, same dimensions as signal_lst.

pykingenie.utils.fitting_surface.fit_one_site_assoc_and_disso(assoc_signal_lst, assoc_time_lst, analyte_conc_lst, disso_signal_lst, disso_time_lst, initial_parameters, low_bounds, high_bounds, smax_idx=None, shared_smax=False, fixed_t0=True, fixed_Kd=False, Kd_value=None, fixed_koff=False, koff_value=None, s0_guesses=None, assoc_mask_lst=None, disso_mask_lst=None)[source]

Global fit to a set of association and dissociation traces - one-to-one binding model.

Parameters:
  • assoc_signal_lst (list) – List of association signals to fit, each signal is a numpy array.

  • assoc_time_lst (list) – List of association time arrays.

  • analyte_conc_lst (list) – List of analyte concentrations, each element is a numpy array.

  • disso_signal_lst (list) – List of dissociation signals to fit, each signal is a numpy array.

  • disso_time_lst (list) – List of dissociation time arrays.

  • initial_parameters (list) – Initial guess for the parameters.

  • low_bounds (list) – Lower bounds for the parameters.

  • high_bounds (list) – Upper bounds for the parameters.

  • smax_idx (list, optional) – List of indices for the s_max parameters, used if shared_smax is True.

  • shared_smax (bool, optional) – If True, the s_max parameters are shared between traces, default is False.

  • fixed_t0 (bool, optional) – If True, t0 is fixed to 0, otherwise we fit it, default is True.

  • fixed_Kd (bool, optional) – If True, Kd is fixed to Kd_value, default is False.

  • Kd_value (float, optional) – Value of Kd to use if fixed_Kd is True.

  • fixed_koff (bool, optional) – If True, koff is fixed to koff_value, default is False.

  • koff_value (float, optional) – Value of koff to use if fixed_koff is True.

  • s0_guesses (list, optional) – Initial signal of each association trace that is not continuous with the previous dissociation, from initial_signal_guesses_where_needed. Computed here if None; pass it to avoid recomputing it when fitting the same data many times.

  • assoc_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). The model is still evaluated at every point, from the first time point of each step. Default fits every point.

  • disso_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). The model is still evaluated at every point, from the first time point of each step. Default fits every point.

Returns:

  • list – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

  • list – Fitted values for each association signal, same dimensions as assoc_signal_lst.

  • list – Fitted values for each dissociation signal, same dimensions as disso_signal_lst.

pykingenie.utils.fitting_surface.fit_two_site_assoc_and_disso(assoc_signal_lst, assoc_time_lst, analyte_conc_lst, disso_signal_lst, disso_time_lst, initial_parameters, low_bounds, high_bounds, smax_idx=None, shared_smax=False, fixed_t0=True, fixed_Kd=False, Kd_value=None, fixed_koff=False, koff_value=None, fit_sigma=False, assoc_mask_lst=None, disso_mask_lst=None, *, fit_initial_state_at=None)[source]

Global fit to association and dissociation traces - two-site binding model.

Parameters follow the same structure as fit_one_site_assoc_and_disso, but each trace uses two amplitudes: Rmax_PL and Rmax_LPL. Optional cooperativity can be fitted through a shared sigma.

Parameter order when fitting: - fixed_Kd=False, fixed_koff=False, fit_sigma=False:

[Kd, koff, (t0…), (Rmax_PL, Rmax_LPL)…]

  • fixed_Kd=False, fixed_koff=False, fit_sigma=True: [Kd, koff, sigma, (t0…), (Rmax_PL, Rmax_LPL)…]

Parameters:
  • assoc_signal_lst (list) – List of association signals to fit, each signal is a numpy array.

  • assoc_time_lst (list) – List of association time arrays.

  • analyte_conc_lst (list) – List of analyte concentrations, each element is a numpy array.

  • disso_signal_lst (list) – List of dissociation signals to fit, each signal is a numpy array.

  • disso_time_lst (list) – List of dissociation time arrays.

  • initial_parameters (list) – Initial guess for the parameters.

  • low_bounds (list) – Lower bounds for the parameters.

  • high_bounds (list) – Upper bounds for the parameters.

  • smax_idx (list, optional) – List of indices for the s_max parameters, used if shared_smax is True.

  • shared_smax (bool, optional) – If True, the s_max parameters are shared between traces, default is False.

  • fixed_t0 (bool, optional) – If True, t0 is fixed to 0, otherwise we fit it, default is True.

  • fixed_Kd (bool, optional) – If True, Kd is fixed to Kd_value, default is False.

  • Kd_value (float, optional) – Value of Kd to use if fixed_Kd is True.

  • fixed_koff (bool, optional) – If True, koff is fixed to koff_value, default is False.

  • koff_value (float, optional) – Value of koff to use if fixed_koff is True.

  • fit_sigma (bool, optional) – If True, fit sigma as a shared parameter for cooperativity, default is False.

  • fit_initial_state_at (int, optional) – Association index at which to fit a new starting state. Appends the fraction of bound ligand and the fraction of that ligand that is doubly bound.

  • assoc_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). The model is still evaluated at every point, from the first time point of each step. Default fits every point.

  • disso_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). The model is still evaluated at every point, from the first time point of each step. Default fits every point.

Returns:

  • list – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

  • list – Fitted values for each association signal, same dimensions as assoc_signal_lst.

  • list – Fitted values for each dissociation signal, same dimensions as disso_signal_lst.

pykingenie.utils.fitting_surface.fit_two_site_heterogeneous_ligand_assoc_and_disso(assoc_signal_lst, assoc_time_lst, analyte_conc_lst, disso_signal_lst, disso_time_lst, initial_parameters, low_bounds, high_bounds, smax_idx=None, shared_smax=False, fixed_t0=True, fixed_Kd1=False, Kd1_value=None, fixed_koff1=False, koff1_value=None, fixed_Kd2=False, Kd2_value=None, fixed_koff2=False, koff2_value=None, fixed_fraction_site1=False, fraction_site1_value=None, assoc_mask_lst=None, disso_mask_lst=None, *, fit_initial_state_at=None)[source]

Global fit to association and dissociation traces for a 2:1 heterogeneous ligand model.

The kinetic model is a sum of two independent 1:1 interactions. The shared fraction_site1 parameter splits each trace’s total Rmax between the two interactions. Each trace has one Rmax value, optionally shared through smax_idx.

Parameter order when fitting: - default:

[Kd1, koff1, Kd2, koff2, fraction_site1, (t0…), Rmax_1, Rmax_2, …]

  • remove any fixed kinetic/fraction parameter from the vector when its corresponding fixed_* flag is True

  • remove t0 values when fixed_t0=True

Parameters:
  • assoc_signal_lst (list) – List of association signals to fit, each signal is a numpy array.

  • assoc_time_lst (list) – List of association time arrays.

  • analyte_conc_lst (list) – List of analyte concentrations, one per association trace.

  • disso_signal_lst (list) – List of dissociation signals to fit, each signal is a numpy array.

  • disso_time_lst (list) – List of dissociation time arrays.

  • initial_parameters (list) – Initial guess vector in the order documented above.

  • low_bounds (list) – Lower bounds for each fitted parameter.

  • high_bounds (list) – Upper bounds for each fitted parameter.

  • smax_idx (list, optional) – List of indices for the Rmax parameters, used if shared_smax is True.

  • shared_smax (bool, optional) – If True, Rmax values are shared between traces with the same smax_idx.

  • fixed_t0 (bool, optional) – If True, fix t0 to zero.

  • fixed_Kd1 (bool, optional) – If True, keep Kd1 fixed to Kd1_value.

  • Kd1_value (float, optional) – Value to use when fixed_Kd1=True.

  • fixed_koff1 (bool, optional) – If True, keep koff1 fixed to koff1_value.

  • koff1_value (float, optional) – Value to use when fixed_koff1=True.

  • fixed_Kd2 (bool, optional) – If True, keep Kd2 fixed to Kd2_value.

  • Kd2_value (float, optional) – Value to use when fixed_Kd2=True.

  • fixed_koff2 (bool, optional) – If True, keep koff2 fixed to koff2_value.

  • koff2_value (float, optional) – Value to use when fixed_koff2=True.

  • fixed_fraction_site1 (bool, optional) – If True, keep fraction_site1 fixed to fraction_site1_value.

  • fraction_site1_value (float, optional) – Value to use when fixed_fraction_site1=True.

  • fit_initial_state_at (int, optional) – Association index at which to fit a new starting state. Appends an initial occupancy fraction for each ligand population.

  • assoc_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). The model is still evaluated at every point, from the first time point of each step. Default fits every point.

  • disso_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). The model is still evaluated at every point, from the first time point of each step. Default fits every point.

Returns:

  • list – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

  • list – Fitted values for each association signal, same dimensions as assoc_signal_lst.

  • list – Fitted values for each dissociation signal, same dimensions as disso_signal_lst.

pykingenie.utils.fitting_surface.fit_bivalent_analyte_assoc_and_disso(assoc_signal_lst, assoc_time_lst, analyte_conc_lst, disso_signal_lst, disso_time_lst, initial_parameters, low_bounds, high_bounds, smax_idx=None, shared_smax=False, fixed_t0=True, fixed_ka2=False, ka2_value=None, fixed_kd2=False, kd2_value=None, assoc_mask_lst=None, disso_mask_lst=None, rtol=1e-08, coarse=False, *, fit_initial_state_at=None)[source]

Global fit to association and dissociation traces - bivalent analyte model.

The analyte binds the immobilised ligand with one arm (Kd1, koff1) and the bound analyte binds a second ligand with its other arm (ka2, kd2). See ode_bivalent_analyte in signal_surface for the rate equations.

Parameter order when fitting: [Kd1, koff1, ka2, kd2, (t0…), Rmax_1, Rmax_2, …] ka2 and kd2 are left out when fixed, and t0 when fixed_t0 is True (one t0 per Rmax group otherwise). When fit_initial_state_at is set, the fit appends the initial fraction of occupied ligand and the fraction of that occupancy due to doubly bound analyte.

Parameters:
  • assoc_signal_lst (list) – List of association signals to fit, each signal is a numpy array.

  • assoc_time_lst (list) – List of association time arrays.

  • analyte_conc_lst (list) – Analyte concentration of each association trace, µM.

  • disso_signal_lst (list) – List of dissociation signals to fit, each signal is a numpy array.

  • disso_time_lst (list) – List of dissociation time arrays.

  • initial_parameters (list) – Initial guess, in the order above.

  • low_bounds (list) – Lower bounds for the parameters.

  • high_bounds (list) – Upper bounds for the parameters.

  • smax_idx (list, optional) – Rmax group of each trace, used if shared_smax is True.

  • shared_smax (bool, optional) – If True, traces with the same smax_idx share Rmax, default is False.

  • fixed_t0 (bool, optional) – If True, t0 is fixed to 0, otherwise one t0 per Rmax group is fitted, default is True.

  • fixed_ka2 (bool, optional) – If True, ka2 is fixed to ka2_value, default is False.

  • ka2_value (float, optional) – Value of ka2 [1/(signal·s)] to use if fixed_ka2 is True.

  • fixed_kd2 (bool, optional) – If True, kd2 is fixed to kd2_value, default is False.

  • kd2_value (float, optional) – Value of kd2 [1/s] to use if fixed_kd2 is True.

  • assoc_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). The model is still evaluated at every point, from the first time point of each step. Default fits every point.

  • disso_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). The model is still evaluated at every point, from the first time point of each step. Default fits every point.

  • rtol (float, optional) – Relative tolerance of the ODE integration, default is 1e-8.

  • coarse (bool, optional) – If True, stop the optimizer at a relative change of 1e-4 and use a 1e-3 finite-difference step, so a looser rtol does not make the Jacobian noisy. Used by the grid search, where the fit only ranks starting points. Default is False.

  • fit_initial_state_at (int, optional) – Index of an association trace whose starting state should be fitted from the data, for example after an omitted single-cycle injection. Initial guesses and bounds for the two additional fractions are supplied automatically.

Returns:

  • list – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

  • list – Fitted values for each association signal, same dimensions as assoc_signal_lst.

  • list – Fitted values for each dissociation signal, same dimensions as disso_signal_lst.

pykingenie.utils.fitting_surface.fit_induced_fit_sites_assoc_and_disso(assoc_signal_lst, assoc_time_lst, analyte_conc_lst, disso_signal_lst, disso_time_lst, initial_parameters, low_bounds, high_bounds, smax_idx=None, shared_smax=False, fixed_t0=True, fixed_kon1=False, kon1_value=None, fixed_koff1=False, koff1_value=None, fixed_kon2=False, kon2_value=None, fixed_koff2=False, koff2_value=None, max_nfev=None, fit_signal_ratio=False, signal_ratio_value=1.0, assoc_mask_lst=None, disso_mask_lst=None, *, fit_initial_state_at=None)[source]

Global fit to association and dissociation traces - one-to-one binding model with induced fit.

The parameters are ordered as: kon1, koff1, kon2 (kc), koff2 (krev) - each only if not fixed -, the signal ratio (if fit_signal_ratio), the t0 values (if not fixed_t0), and the Smax values.

Parameters:
  • assoc_signal_lst (list) – List of association signals to fit, each signal is a numpy array.

  • assoc_time_lst (list) – List of association time arrays.

  • analyte_conc_lst (list) – List of analyte concentrations, each element is a numpy array.

  • disso_signal_lst (list) – List of dissociation signals to fit, each signal is a numpy array.

  • disso_time_lst (list) – List of dissociation time arrays.

  • initial_parameters (list) – Initial guess for the parameters.

  • low_bounds (list) – Lower bounds for the parameters.

  • high_bounds (list) – Upper bounds for the parameters.

  • smax_idx (list, optional) – List of indices for the s_max parameters, used if shared_smax is True.

  • shared_smax (bool, optional) – If True, the s_max parameters are shared between traces, default is False.

  • fixed_t0 (bool, optional) – If True, t0 is fixed to 0, otherwise we fit it, default is True.

  • fixed_kon1 (bool, optional) – If True, kon1 is fixed to kon1_value, default is False.

  • kon1_value (float, optional) – Value of kon1 to use if fixed_kon1 is True.

  • fixed_koff1 (bool, optional) – If True, koff1 is fixed to koff1_value, default is False.

  • koff1_value (float, optional) – Value of koff1 to use if fixed_koff1 is True.

  • fixed_kon2 (bool, optional) – If True, kon2 is fixed to kon2_value, default is False.

  • kon2_value (float, optional) – Value of kon2 to use if fixed_kon2 is True.

  • fixed_koff2 (bool, optional) – If True, koff2 is fixed to koff2_value, default is False.

  • koff2_value (float, optional) – Value of koff2 to use if fixed_koff2 is True.

  • max_nfev (int, optional) – Maximum number of function evaluations.

  • fit_signal_ratio (bool, optional) – If True, fit the signal of the induced complex (AL) relative to the intermediate complex (ALint) as one global parameter, default is False. A is the analyte and L the immobilised ligand (E·S and ES in the signal functions).

  • signal_ratio_value (float, optional) – Signal of AL relative to ALint used if fit_signal_ratio is False, default is 1 (both complexes produce the same signal).

  • fit_initial_state_at (int, optional) – Association index at which to fit a new starting state. Appends the fraction of bound ligand and the fraction of that ligand in the induced state.

  • assoc_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). The model is still evaluated at every point, from the first time point of each step. Default fits every point.

  • disso_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). The model is still evaluated at every point, from the first time point of each step. Default fits every point.

Returns:

  • list – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

  • list – Fitted values for each association signal, same dimensions as assoc_signal_lst.

  • list – Fitted values for each dissociation signal, same dimensions as disso_signal_lst.

pykingenie.utils.fitting_surface.fit_one_site_assoc_and_disso_ktr(assoc_signal_lst, assoc_time_lst, analyte_conc_lst, disso_signal_lst, disso_time_lst, initial_parameters, low_bounds, high_bounds, smax_idx=None, shared_smax=False, fixed_t0=True, fixed_Kd=False, Kd_value=None, fixed_koff=False, koff_value=None, start_candidates=None, assoc_mask_lst=None, disso_mask_lst=None, *, fit_initial_state_at=None)[source]

Global fit to a set of association and dissociation traces - one-to-one with mass transport limitation binding model.

Parameters:
  • assoc_signal_lst (list) – List of association signals to fit, each signal is a numpy array.

  • assoc_time_lst (list) – List of association time arrays.

  • analyte_conc_lst (list) – List of analyte concentrations, each element is a numpy array.

  • disso_signal_lst (list) – List of dissociation signals to fit, each signal is a numpy array.

  • disso_time_lst (list) – List of dissociation time arrays.

  • initial_parameters (list) – Initial guess for the parameters.

  • low_bounds (list) – Lower bounds for the parameters.

  • high_bounds (list) – Upper bounds for the parameters.

  • smax_idx (list, optional) – List of indices for the s_max parameters, used if shared_smax is True.

  • shared_smax (bool, optional) – If True, the s_max parameters are shared between traces, default is False.

  • fixed_t0 (bool, optional) – If True, t0 is fixed to 0, otherwise we fit it, default is True.

  • fixed_Kd (bool, optional) – If True, Kd is fixed to Kd_value, default is False.

  • Kd_value (float, optional) – Value of Kd to use if fixed_Kd is True.

  • fixed_koff (bool, optional) – If True, koff is fixed to koff_value, default is False.

  • koff_value (float, optional) – Value of koff to use if fixed_koff is True.

  • start_candidates (list of list, optional) – Other starting points, ordered like initial_parameters. The model is evaluated once at each; a second fit starts from the one with the lowest sum of squared residuals, and the better of the two fits is returned, default is None.

  • fit_initial_state_at (int, optional) – Association index at which to fit a new starting state. Appends the initial fraction of bound ligand.

  • assoc_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). The model is still evaluated at every point, from the first time point of each step. Default fits every point.

  • disso_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). The model is still evaluated at every point, from the first time point of each step. Default fits every point.

Returns:

  • list – Fitted parameters.

  • np.ndarray – Covariance matrix of the fitted parameters.

  • list – Fitted values for each association signal, same dimensions as assoc_signal_lst.

  • list – Fitted values for each dissociation signal, same dimensions as disso_signal_lst.

pykingenie.utils.fitting_surface.one_site_assoc_and_disso_asymmetric_ci95(kd_estimated, rss_desired, assoc_signal_lst, assoc_time_lst, analyte_conc_lst, disso_signal_lst, disso_time_lst, initial_parameters, low_bounds, high_bounds, smax_idx=None, shared_smax=False, fixed_t0=True, fixed_koff=False, koff_value=None, assoc_mask_lst=None, disso_mask_lst=None)[source]

Calculate the asymmetric confidence interval for the Kd value, given a desired RSS value.

Parameters:
  • kd_estimated (float) – Estimated Kd value.

  • rss_desired (float) – Desired RSS value.

  • assoc_signal_lst (list) – List of association signals to fit, each signal is a numpy array.

  • assoc_time_lst (list) – List of association time arrays.

  • analyte_conc_lst (list) – List of analyte concentrations, each element is a numpy array.

  • disso_signal_lst (list) – List of dissociation signals to fit, each signal is a numpy array.

  • disso_time_lst (list) – List of dissociation time arrays.

  • initial_parameters (list) – Initial guess for the parameters, without the Kd value!

  • low_bounds (list) – Lower bounds for the parameters, without the Kd value!

  • high_bounds (list) – Upper bounds for the parameters, without the Kd value!

  • smax_idx (list, optional) – List of indices for the s_max parameters, used if shared_smax is True.

  • shared_smax (bool, optional) – If True, the s_max parameters are shared between traces, default is False.

  • fixed_t0 (bool, optional) – If True, t0 is fixed to 0, otherwise we fit it, default is True.

  • fixed_koff (bool, optional) – If True, koff is fixed to koff_value, default is False.

  • koff_value (float, optional) – Value of koff to use if fixed_koff is True.

  • assoc_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). Only these points count in the RSS. Default fits every point.

  • disso_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). Only these points count in the RSS. Default fits every point.

Returns:

  • float – Minimum Kd value for the 95% confidence interval.

  • float – Maximum Kd value for the 95% confidence interval.

pykingenie.utils.fitting_surface.one_site_assoc_and_disso_asymmetric_ci95_koff(koff_estimated, rss_desired, assoc_signal_lst, assoc_time_lst, analyte_conc_lst, disso_signal_lst, disso_time_lst, initial_parameters, low_bounds, high_bounds, smax_idx=None, shared_smax=False, fixed_t0=True, assoc_mask_lst=None, disso_mask_lst=None)[source]

Calculate the asymmetric confidence interval for the koff value, given a desired RSS value.

Parameters:
  • koff_estimated (float) – Estimated koff value.

  • rss_desired (float) – Desired RSS value.

  • assoc_signal_lst (list) – List of association signals to fit, each signal is a numpy array.

  • assoc_time_lst (list) – List of association time arrays.

  • analyte_conc_lst (list) – List of analyte concentrations, each element is a numpy array.

  • disso_signal_lst (list) – List of dissociation signals to fit, each signal is a numpy array.

  • disso_time_lst (list) – List of dissociation time arrays.

  • initial_parameters (list) – Initial guess for the parameters, without the Kd value!

  • low_bounds (list) – Lower bounds for the parameters, without the Kd value!

  • high_bounds (list) – Upper bounds for the parameters, without the Kd value!

  • smax_idx (list, optional) – List of indices for the s_max parameters, used if shared_smax is TRUE

  • shared_smax (bool, optional) – If True, the s_max parameters are shared between traces

  • fixed_t0 (bool, optional) – If True, t0 is fixed to 0, otherwise we fit it, default is True

  • assoc_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). Only these points count in the RSS. Default fits every point.

  • disso_mask_lst (list, optional) – Boolean array per association / dissociation trace, True for the points to fit (see trim_masks). Only these points count in the RSS. Default fits every point.

Returns:

  • float – Minimum koff value for the 95% confidence interval.

  • float – Maximum koff value for the 95% confidence interval.

pykingenie.utils.fitting_surface.get_smax_upper_bound_factor(Kd_ss)[source]

Get a factor to determine the upper bound for Smax based on Kd_ss value.

Parameters:

Kd_ss (float) – Steady state Kd value.

Returns:

Factor to multiply for setting Smax upper bound, or None if no matching range found.

Return type:

float or None

pykingenie.utils.fitting_surface.fit_single_exponential_fast(y, t, min_log_k=-5, max_log_k=5, log_k_points=50)[source]

Fit a single exponential y = a0 + a1 * exp(-k_obs * t) to a signal.

Gives the same result as fitting_general.fit_single_exponential, faster. Both try a grid of k_obs values and refine the best one with a nonlinear fit. With k_obs fixed, the model is linear in a0 and a1, so here each grid point is solved in closed form instead of with curve_fit.

Parameters:
  • y (np.ndarray) – Signal values.

  • t (np.ndarray) – Time values.

  • min_log_k (float, optional) – Minimum log10 k_obs of the grid, default is -5.

  • max_log_k (float, optional) – Maximum log10 k_obs of the grid, default is 5.

  • log_k_points (int, optional) – Number of grid points, default is 50.

Returns:

  • np.ndarray – Fitted parameters (a0, a1, k_obs).

  • np.ndarray – Covariance matrix of the fitted parameters.

  • np.ndarray – Fitted y values.

pykingenie.utils.math module

Mathematical models and statistics used in kinetic analysis.

pykingenie.utils.math.single_exponential(t, a0, a1, kobs)[source]

Single exponential function for fitting.

Parameters:
  • t (np.ndarray) – Time values.

  • a0 (float) – Offset.

  • a1 (float) – Amplitude.

  • kobs (float) – Observed rate constant.

Returns:

Computed values of the single exponential function.

Return type:

np.ndarray

pykingenie.utils.math.double_exponential(t, a0, a1, kobs1, a2, kobs2)[source]

Double exponential function for fitting.

Parameters:
  • t (np.ndarray) – Time values.

  • a0 (float) – Offset.

  • a1 (float) – Amplitude of the first exponential.

  • kobs1 (float) – Observed rate constant of the first exponential.

  • a2 (float) – Amplitude of the second exponential.

  • kobs2 (float) – Observed rate constant of the second exponential.

Returns:

Computed values of the double exponential function.

Return type:

np.ndarray

pykingenie.utils.math.median_filter(y, x, rolling_window)[source]

Compute the median filter of the input signal using a rolling window.

The x vector is converted into an integer vector and then into a time variable to take advantage of pandas rolling().median(). Returns the y vector passed through the median filter.

Parameters:
  • y (np.ndarray) – Input signal values.

  • x (np.ndarray) – Time or index values corresponding to the signal.

  • rolling_window (int or float) – Size of the median filter window.

Returns:

Filtered signal.

Return type:

np.ndarray

pykingenie.utils.math.rss_p(rrs0, n, p, alfa)[source]

Compute the desired residual sum of squares for a 1-alpha confidence interval.

Given the residuals of the best fitted model, this is used to compute asymmetric confidence intervals for the fitted parameters.

Parameters:
  • rrs0 (float) – Residual sum of squares of the model with the best fit.

  • n (int) – Number of data points.

  • p (int) – Number of parameters.

  • alfa (float) – Desired confidence interval (1 - alpha).

Returns:

Residual sum of squares for the desired confidence interval.

Return type:

float

pykingenie.utils.math.get_rss(y, y_fit)[source]

Compute the residual sum of squares.

Parameters:
  • y (np.ndarray) – Observed values.

  • y_fit (np.ndarray) – Fitted values.

Returns:

Residual sum of squares.

Return type:

float

pykingenie.utils.math.get_desired_rss(y, y_fit, n, p, alpha=0.05)[source]

Find the residual sum of squares required for a 1-alpha confidence interval.

Given the observed and fitted data, computes the RSS for the desired confidence interval.

Parameters:
  • y (np.ndarray) – Observed values.

  • y_fit (np.ndarray) – Fitted values.

  • n (int) – Number of data points.

  • p (int) – Number of parameters.

  • alpha (float, optional) – Desired confidence interval (default is 0.05).

Returns:

Residual sum of squares for the desired confidence interval.

Return type:

float

pykingenie.utils.math.correlation_from_covariance(cov, labels)[source]

Correlation matrix of fitted parameters from their covariance matrix.

The correlation of parameters i and j is cov[i, j] / (sd_i * sd_j), from -1 to 1. Values near ±1 mean the two parameters trade off against each other: the data constrain a combination of them, not each one separately.

Parameters:
  • cov (np.ndarray) – Covariance matrix of the fitted parameters, as returned by curve_fit.

  • labels (list of str) – Parameter names, in the order of the rows of cov.

Returns:

Correlation matrix with labels as index and columns. Entries are NaN for parameters whose variance is not finite and positive (for example when curve_fit cannot estimate the covariance).

Return type:

pd.DataFrame

pykingenie.utils.palettes module

Color palettes for plotting.

This module provides color palettes that can be used for visualizing data in plots. These palettes are collections of colors represented as hex values.

pykingenie.utils.palettes.VIRIDIS = ['#440154', '#471063', '#481d6f', '#472a7a', '#414487', '#3c4f8a', '#375a8c', '#32648e', '#2a788e', '#26828e', '#228b8d', '#1f958b', '#22a884', '#2cb17e', '#3bbb75', '#4ec36b', '#7ad151', '#95d840', '#b0dd2f', '#cae11f', '#fde725']

Viridis color palette.

A perceptually uniform color map that is readable by those with colorblindness. Contains 21 hex color values transitioning from dark purple to yellow.

pykingenie.utils.palettes.BLUES = ['#94c4df', '#87bddc', '#7cb7da', '#6fb0d7', '#64a9d3', '#5ba3d0', '#519ccc', '#4695c8', '#3e8ec4', '#3686c0', '#2e7ebc', '#2676b8', '#1f6eb3', '#1966ad', '#135fa7', '#0d57a1', '#084f99', '#08488e', '#084082', '#083776', '#08306b']

Blues color palette.

A sequential palette (ColorBrewer Blues, without its near-white end) with 21 hex color values from light to dark blue. Used for concentrations, the highest concentration takes the darkest blue.

pykingenie.utils.palettes.CONCENTRATION_PALETTES = {'blues': ['#94c4df', '#87bddc', '#7cb7da', '#6fb0d7', '#64a9d3', '#5ba3d0', '#519ccc', '#4695c8', '#3e8ec4', '#3686c0', '#2e7ebc', '#2676b8', '#1f6eb3', '#1966ad', '#135fa7', '#0d57a1', '#084f99', '#08488e', '#084082', '#083776', '#08306b'], 'viridis': ['#440154', '#471063', '#481d6f', '#472a7a', '#414487', '#3c4f8a', '#375a8c', '#32648e', '#2a788e', '#26828e', '#228b8d', '#1f958b', '#22a884', '#2cb17e', '#3bbb75', '#4ec36b', '#7ad151', '#95d840', '#b0dd2f', '#cae11f', '#fde725']}

Sequential palettes available for coloring by concentration, low to high.

pykingenie.utils.palettes.set1_colors = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999']

Set1 color palette.

A qualitative color palette suitable for categorical data. Contains 9 distinct colors that are visually distinguishable.

pykingenie.utils.palettes.set3_colors = ['#8dd3c7', '#ffffb3', '#bebada', '#fb8072', '#80b1d3', '#fdb462', '#b3de69', '#fccde5', '#d9d9d9', '#bc80bd', '#ccebc5', '#ffed6f']

Set3 color palette.

A qualitative color palette with softer, pastel-like colors. Contains 12 distinct colors suitable for categorical data with many categories.

pykingenie.utils.plotting module

Plotting helpers for kinetic experiments and fit results.

pykingenie.utils.plotting.config_fig(fig, name_for_download, export_format=None, plot_width=10, plot_height=6, scale_factor=50, save=False)[source]

Configure Plotly figure size and optionally save to file.

Parameters:
  • fig (go.Figure) – The Plotly figure.

  • name_for_download (str) – Base name for saving the figure.

  • export_format (str, optional) – ‘png’, ‘svg’, ‘pdf’, etc. (if saving).

  • plot_width (int, optional) – Width in arbitrary units. Default is 10.

  • plot_height (int, optional) – Height in arbitrary units. Default is 6.

  • scale_factor (int, optional) – Multiply width/height to get actual pixels. Default is 50.

  • save (bool, optional) – Whether to save the figure as a file. Default is False.

Returns:

The updated figure.

Return type:

go.Figure

pykingenie.utils.plotting.plot_plate_info(pyKinetics, experiment_name, font_size=18)[source]

Plot the plate layout information from a KineticsAnalyzer experiment.

Parameters:
  • pyKinetics (KineticsAnalyzer) – The KineticsAnalyzer instance containing the experiment data.

  • experiment_name (str) – The name of the experiment to plot.

  • font_size (int, optional) – Font size for the plot. Default is 18.

Returns:

A Plotly figure containing the plate layout.

Return type:

go.Figure

pykingenie.utils.plotting.plot_traces(xs, ys, legends, colors, show, marker_size=1, line_width=2)[source]

Plot sensor traces for a set of sensors.

Parameters:
  • xs (list of np.ndarray) – List of x-axis arrays (time) for each sensor.

  • ys (list of np.ndarray) – List of y-axis arrays (signal) for each sensor.

  • legends (list of str) – List of legend labels for each sensor.

  • colors (list of str) – List of colors for each sensor trace.

  • show (list of bool) – List indicating whether to show each sensor trace.

  • marker_size (int, optional) – Size of the markers. Default is 1.

  • line_width (int, optional) – Width of the lines. Default is 2.

Returns:

A Plotly figure containing the sensor traces.

Return type:

go.Figure

pykingenie.utils.plotting.plot_traces_all(pyKinetics, legends_df, plot_width=16, plot_height=14, plot_type='png', font_size=18, show_grid_x=False, show_grid_y=False, marker_size=1, line_width=2, vertical_spacing=0.08)[source]

Plot all sensor traces in subplots for a KineticsAnalyzer experiment.

Parameters:
  • pyKinetics (KineticsAnalyzer) – The KineticsAnalyzer instance containing the experiment data.

  • legends_df (pandas.DataFrame) – DataFrame containing legend, color, and show information for each sensor.

  • plot_width (int, optional) – Width of the plot. Default is 16.

  • plot_height (int, optional) – Height of the plot. Default is 14.

  • plot_type (str, optional) – Type of plot to export (‘png’, ‘svg’, etc.). Default is ‘png’.

  • font_size (int, optional) – Font size for plot text. Default is 18.

  • show_grid_x (bool, optional) – Whether to show grid lines on the x-axis. Default is False.

  • show_grid_y (bool, optional) – Whether to show grid lines on the y-axis. Default is False.

  • marker_size (int, optional) – Size of the markers. Default is 1.

  • line_width (int, optional) – Width of the lines. Default is 2.

  • vertical_spacing (float, optional) – Vertical spacing between subplots. Default is 0.08.

Returns:

A Plotly figure containing all sensor traces in subplots.

Return type:

go.Figure

pykingenie.utils.plotting.plot_steady_state(pyKinetics, plot_width=30, plot_height=20, plot_type='png', font_size=18, show_grid_x=True, show_grid_y=True, marker_size=5, line_width=2, plot_fit=False)[source]

Plot steady-state data for a KineticsAnalyzer experiment.

Parameters:
  • pyKinetics (KineticsAnalyzer) – The KineticsAnalyzer instance containing the experiment data.

  • plot_width (int, optional) – Width of the plot. Default is 30.

  • plot_height (int, optional) – Height of the plot. Default is 20.

  • plot_type (str, optional) – Type of plot to export (‘png’, ‘svg’, etc.). Default is ‘png’.

  • font_size (int, optional) – Font size for plot text. Default is 18.

  • show_grid_x (bool, optional) – Whether to show grid lines on the x-axis. Default is True.

  • show_grid_y (bool, optional) – Whether to show grid lines on the y-axis. Default is True.

  • marker_size (int, optional) – Size of the markers. Default is 5.

  • line_width (int, optional) – Width of the lines. Default is 2.

  • plot_fit (bool, optional) – Whether to plot fitted curves. Default is False.

Returns:

A Plotly figure containing steady-state plots.

Return type:

go.Figure

pykingenie.utils.plotting.plot_association_dissociation(pyKinetics, plot_width=26, plot_height=20, plot_type='png', font_size=14, show_grid_x=False, show_grid_y=False, marker_size=4, line_width=2, split_by_smax_id=True, max_points_per_plot=2000, smooth_curves_fit=False, rolling_window=0.1, vertical_spacing=0.08)[source]

Plot association and dissociation traces for a KineticsAnalyzer experiment.

Parameters:
  • pyKinetics (KineticsAnalyzer) – The KineticsAnalyzer instance containing the experiment data.

  • plot_width (int, optional) – Width of the plot. Default is 26.

  • plot_height (int, optional) – Height of the plot. Default is 20.

  • plot_type (str, optional) – Type of plot to export (‘png’, ‘svg’, etc.). Default is ‘png’.

  • font_size (int, optional) – Font size for plot text. Default is 14.

  • show_grid_x (bool, optional) – Whether to show grid lines on the x-axis. Default is False.

  • show_grid_y (bool, optional) – Whether to show grid lines on the y-axis. Default is False.

  • marker_size (int, optional) – Size of the markers. Default is 4.

  • line_width (int, optional) – Width of the lines. Default is 2.

  • split_by_smax_id (bool, optional) – Whether to split subplots by Smax ID. Default is True.

  • max_points_per_plot (int, optional) – Maximum number of points per subplot. Default is 2000.

  • smooth_curves_fit (bool, optional) – Whether to apply median filter smoothing. Default is False.

  • rolling_window (float, optional) – Window size for smoothing. Default is 0.1.

  • vertical_spacing (float, optional) – Vertical spacing between subplots. Default is 0.08.

Returns:

A Plotly figure containing association-dissociation traces.

Return type:

go.Figure

pykingenie.utils.plotting_xy module

XY plotting helpers with reusable dataclass configurations.

XY is installed with pykingenie on Python 3.11+. Single-panel helpers return an xy.Chart; subplot helpers return an xy.facets.FacetGrid. Both support show(), to_html(), to_svg(), to_png() and write_image(). No Plotly figures are constructed by this module.

Use PlotConfig, AxisConfig, LayoutConfig, LegendConfig and TraceConfig to share settings across plots. Unspecified fields retain each helper’s defaults. All dimensions are in pixels.

class pykingenie.utils.plotting_xy.PlotConfig(plot_width: int | None = None, plot_height: int | None = None, plot_type: str | None = None, font_size: float | None = None, title: str | None = None, x_range: tuple[float, float] | None = None, y_range: tuple[float, float] | None = None, palette: str | None = None)[source]

Bases: object

General XY settings. Dimensions are pixels; None keeps helper defaults.

Ranges are expressed in data units, including on logarithmic axes. An empty title hides the main title; None keeps the helper’s usual title. palette colors traces by ligand concentration: "viridis" (default) or "blues", where the highest concentration is the darkest blue.

plot_width: int | None = None
plot_height: int | None = None
plot_type: str | None = None
font_size: float | None = None
title: str | None = None
x_range: tuple[float, float] | None = None
y_range: tuple[float, float] | None = None
palette: str | None = None
class pykingenie.utils.plotting_xy.AxisConfig(showgrid_x: bool | None = None, showgrid_y: bool | None = None, n_x_axis_ticks: int | None = None, n_y_axis_ticks: int | None = None, axis_linewidth: float = 1, axis_tickwidth: float = 2, axis_gridwidth: float = 1, tick_length: float = 8, x_label: str | None = None, y_label: str | None = None, x_scale: str | None = None, y_scale: str | None = None, reverse_x: bool | None = None, reverse_y: bool | None = None, x_bounds: tuple[float, float] | str | None = None, y_bounds: tuple[float, float] | str | None = None)[source]

Bases: object

Axis grids, ticks, labels, scales, and navigation limits.

x_bounds="data" / y_bounds="data" constrain navigation to the observations. PlotConfig.x_range / y_range set the initial view.

showgrid_x: bool | None = None
showgrid_y: bool | None = None
n_x_axis_ticks: int | None = None
n_y_axis_ticks: int | None = None
axis_linewidth: float = 1
axis_tickwidth: float = 2
axis_gridwidth: float = 1
tick_length: float = 8
x_label: str | None = None
y_label: str | None = None
x_scale: str | None = None
y_scale: str | None = None
reverse_x: bool | None = None
reverse_y: bool | None = None
x_bounds: tuple[float, float] | str | None = None
y_bounds: tuple[float, float] | str | None = None
class pykingenie.utils.plotting_xy.LayoutConfig(stacked: bool = False, ncols: int | None = None, vertical_spacing: float | None = None, gap: int | None = None, shared_xaxes: bool = False, shared_yaxes: bool = False, show_subplot_titles: bool = True, outer_labels: bool | None = None, extra_padding_y_label: float | None = None, split_by_smax_id: bool = True)[source]

Bases: object

Subplot arrangement, spacing, titles, and shared axis domains.

ncols chooses the number of columns; stacked=True uses one column. gap is in pixels and overrides fractional vertical_spacing; with neither set, panels are 0.6 em (at least 8 px) apart. Shared axes start with a common domain; their interactions are independent. split_by_smax_id groups kinetics panels by response amplitude ID.

stacked: bool = False
ncols: int | None = None
vertical_spacing: float | None = None
gap: int | None = None
shared_xaxes: bool = False
shared_yaxes: bool = False
show_subplot_titles: bool = True
outer_labels: bool | None = None
extra_padding_y_label: float | None = None
split_by_smax_id: bool = True
class pykingenie.utils.plotting_xy.LegendConfig(show: bool | None = None, loc: str | None = None, ncols: int = 1, title: str | None = None, font_size: float | None = None, toggle: bool | None = None, highlight: bool | None = None)[source]

Bases: object

Legend visibility, placement, typography, and interaction.

Unset show/loc/toggle/highlight settings keep the helper’s defaults ("upper right", or "upper left" for steady-state curves). Enabling toggles for a composed line/marker trace toggles its named mark only.

show: bool | None = None
loc: str | None = None
ncols: int = 1
title: str | None = None
font_size: float | None = None
toggle: bool | None = None
highlight: bool | None = None
class pykingenie.utils.plotting_xy.TraceConfig(marker_size: float | None = None, line_width: float | None = None, opacity: float = 1, fit_color: str = 'black', fit_line_width: float | None = None, exact_lines: bool | None = None, max_points: int | None = None, show_fit: bool | None = None, smooth_curves: bool = False, rolling_window: float = 0.1)[source]

Bases: object

Raw marks, fitted lines, and rendering precision.

max_points sets the raw-trace sampling budget (100,000 total sensor points or 2,000 points per kinetics group by default). exact_lines applies to raw sensor traces; it remains False unless explicitly enabled. show_fit defaults to False for steady state and True for kinetics. Kinetics observations can be median-smoothed with smooth_curves=True and a rolling_window in seconds, without changing fitting input.

marker_size: float | None = None
line_width: float | None = None
opacity: float = 1
fit_color: str = 'black'
fit_line_width: float | None = None
exact_lines: bool | None = None
max_points: int | None = None
show_fit: bool | None = None
smooth_curves: bool = False
rolling_window: float = 0.1
pykingenie.utils.plotting_xy.config_fig(fig, name_for_download, plot_config: PlotConfig | None = None, *, save=False)[source]

Configure an XY chart/grid and optionally export it using PlotConfig.

Width and height are pixels. Omitted dimensions keep the current size. Configure before displaying live widgets and retain the returned value: resizing a grid returns a new grid. plot_type selects the saved format.

pykingenie.utils.plotting_xy.plot_plate_info(pyKinetics, experiment_name, *, plot_config: PlotConfig | None = None, axis_config: AxisConfig | None = None, legend_config: LegendConfig | None = None, trace_config: TraceConfig | None = None)[source]

Return a plate chart with well labels and sample metadata on hover.

pykingenie.utils.plotting_xy.plot_traces(xs, ys, legends, colors, show, *, plot_config: PlotConfig | None = None, axis_config: AxisConfig | None = None, legend_config: LegendConfig | None = None, trace_config: TraceConfig | None = None)[source]

Plot selected sensors, optionally connecting every displayed sample.

TraceConfig controls sampling, opacity, marker size and line width. exact_lines=True retains every adjacent pair in standalone HTML; the default uses XY’s faster automatic line reduction. Both modes use the same initial sampling budget for lines and markers.

pykingenie.utils.plotting_xy.plot_traces_all(pyKinetics, legends_df, *, plot_config: PlotConfig | None = None, axis_config: AxisConfig | None = None, layout_config: LayoutConfig | None = None, legend_config: LegendConfig | None = None, trace_config: TraceConfig | None = None)[source]

Plot one sensor panel per experiment using reusable configuration objects.

pykingenie.utils.plotting_xy.plot_steady_state(pyKinetics, *, plot_config: PlotConfig | None = None, axis_config: AxisConfig | None = None, layout_config: LayoutConfig | None = None, legend_config: LegendConfig | None = None, trace_config: TraceConfig | None = None)[source]

Plot steady-state observations on log concentration axes.

Enable fitted curves with TraceConfig(show_fit=True).

pykingenie.utils.plotting_xy.plot_steady_state_residuals(pyKinetics, *, plot_config: PlotConfig | None = None, axis_config: AxisConfig | None = None, layout_config: LayoutConfig | None = None, legend_config: LegendConfig | None = None, trace_config: TraceConfig | None = None)[source]

Plot steady-state residuals (observed minus fitted) on log concentration axes.

Panels match plot_steady_state; samples without a steady-state fit are left out. A horizontal line at zero marks a perfect fit.

pykingenie.utils.plotting_xy.plot_association_dissociation(pyKinetics, *, plot_config: PlotConfig | None = None, axis_config: AxisConfig | None = None, layout_config: LayoutConfig | None = None, legend_config: LegendConfig | None = None, trace_config: TraceConfig | None = None)[source]

Plot kinetics observations and fitted curves, colored by concentration.

One colorbar beside the top-right panel shows the ligand concentration (log-scaled; Viridis, or Blues via PlotConfig(palette="blues")), shared by all panels. LayoutConfig controls splitting by Smax ID. TraceConfig controls fitted overlays, median smoothing and the sampling budget per Smax group.

pykingenie.utils.plotting_xy.plot_association_dissociation_residuals(pyKinetics, *, plot_config: PlotConfig | None = None, axis_config: AxisConfig | None = None, layout_config: LayoutConfig | None = None, legend_config: LegendConfig | None = None, trace_config: TraceConfig | None = None)[source]

Plot kinetics residuals (observed minus fitted) over time.

Panels, colors and the shared concentration colorbar match plot_association_dissociation. Traces without a fitted curve are left out, and a horizontal line at zero marks a perfect fit. TraceConfig(smooth_curves=True) median-smooths the residuals.

pykingenie.utils.processing module

Data processing and experiment metadata helpers.

pykingenie.utils.processing.guess_experiment_name(frd_file)[source]

Given a certain frd file, try to guess the experiment name.

The frd file is the format exported by the Biacore software.

Parameters:

frd_file (str) – Path to the FRD file.

Returns:

Experiment name extracted from the file, or ‘Experiment’ if no name is found.

Return type:

str

pykingenie.utils.processing.remove_at(arr, i)[source]

Remove the element at index i from an array or list.

Parameters:
  • arr (list or np.ndarray) – Input array or list.

  • i (int) – Index of the element to remove.

Returns:

Array or list with the element at index i removed.

Return type:

list or np.ndarray

pykingenie.utils.processing.etree_to_dict(tree)[source]

Converts XML tree to dictionary.

Parameters:

tree (ElementTree) – XML tree to convert.

Returns:

Dictionary representation of the XML tree.

Return type:

dict

pykingenie.utils.processing.combine_dicts(list_dicts)[source]

Combines dictionaries with the same keys into a dictionary with lists as values.

Parameters:

list_dicts (list) – List of dictionaries to combine.

Returns:

Combined dictionary with lists as values.

Return type:

dict

Notes

All dictionaries must have the same keys.

pykingenie.utils.processing.guess_experiment_type(files)[source]

Guess surface- versus solution-based data, preserving the surface fallback.

Use pykingenie.detect_file_format to choose a specific input reader. This legacy helper only returns surface or solution; unrecognized or missing inputs keep its historical surface default.

Parameters:

files (str, path-like, or list) – Path or list of paths to the experiment files.

Returns:

‘surface’ or ‘solution’ indicating the experiment type.

Return type:

str

pykingenie.utils.processing.detect_time_list_continuos(assoc_time_lst, disso_time_lst, tolerance=3)[source]

Detect which association steps come directly after a dissociation step.

Useful for single-cycle kinetics.

Parameters:
  • assoc_time_lst (list) – List of association time arrays.

  • disso_time_lst (list) – List of dissociation time arrays.

  • tolerance (float, optional) – Tolerance for the time difference (in seconds), default is 3.

Returns:

List of booleans indicating if the association phase has a dissociation phase just before.

Return type:

list

pykingenie.utils.processing.find_loading_column(df, step_number)[source]

Find the loading column before the given step number.

Parameters:
  • df (pd.DataFrame) – DataFrame containing the columns ‘Column’, ‘Type’ and ‘StepNumber’.

  • step_number (int) – The step number to find the loading column before.

Returns:

The name of the loading column before the given step number, or None if no loading column is found.

Return type:

str or None

pykingenie.utils.processing.concat_signal_lst(signal_lst)[source]

Concatenate a list of signals into a single array.

Parameters:

signal_lst (list) – List of signals to concatenate, each signal is a numpy array.

Returns:

Concatenated signal.

Return type:

np.ndarray

pykingenie.utils.processing.expand_parameter_list(parameter_lst, id_list)[source]

Expand a parameter list based on ID mapping.

Given a list of n-parameters, such as [1,3] and another list containing IDs, such as [0,0,0,0,0,1,1], create a new list where the elements are repeated according to the IDs. In this case: [1,1,1,1,1,3,3]

Parameters:
  • parameter_lst (list) – List of n-Parameters.

  • id_list (list) – List of m-IDs mapping to parameter indices.

Returns:

m-Parameters list expanded according to the IDs.

Return type:

list

pykingenie.utils.processing.combine_sequences(seq1, seq2)[source]

Combine two sequences to generate all possible combinations of their elements.

Parameters:
  • seq1 (list) – First sequence of elements.

  • seq2 (list) – Second sequence of elements.

Returns:

A list of tuples, where each tuple contains one element from seq1 and one from seq2.

Return type:

list

pykingenie.utils.processing.get_palette(n_colors)[source]

Get a color palette with the specified number of colors.

Parameters:

n_colors (int) – Number of colors to include in the palette.

Returns:

List of hex color codes.

Return type:

list

Notes

Uses Set1 from ColorBrewer for n_colors <= 9, Set3 for n_colors <= 12, and interpolated colors for n_colors > 12.

pykingenie.utils.processing.get_plotting_df(ID, labels=None)[source]

Create a DataFrame for plotting purposes with colors and labels.

Parameters:
  • ID (list) – List of unique identifiers for each entry.

  • labels (list, optional) – List of labels corresponding to each ID. Defaults to None, in which case the ID values are used as labels.

Returns:

DataFrame containing Internal_ID, Color, Legend, and Show columns.

Return type:

pd.DataFrame

pykingenie.utils.processing.subset_data(data, max_points=200)[source]

Subset data to a maximum number of points for plotting.

Parameters:
  • data (list or np.ndarray) – Data to be subsetted.

  • max_points (int, optional) – Maximum number of points to retain, default is 200.

Returns:

Subsetted data with at most max_points points.

Return type:

list or np.ndarray

pykingenie.utils.processing.sample_type_to_letter(string)[source]

Convert sample type string to a single letter code.

Parameters:

string (str) – Sample type string.

Returns:

Single letter code representing the sample type.

Return type:

str

Notes

Mapping: - KSAMPLE/SAMPLE -> S - LOADING/KLOADING -> L - NEUTRALIZATION -> N - REGENERATION -> R - BASELINE/BUFFER -> B - Others -> First letter of the string

pykingenie.utils.processing.get_colors_from_numeric_values(values, min_val, max_val, use_log_scale=True, palette=None)[source]

Map numeric values to colors of a sequential palette over a specified range.

Parameters:
  • values (list or np.ndarray) – Numeric values to map to colors.

  • min_val (float) – Minimum value of the range.

  • max_val (float) – Maximum value of the range.

  • use_log_scale (bool, optional) – Whether to use logarithmic scaling for the values, default is True.

  • palette (list of str, optional) – Colors ordered from the lowest to the highest value. Defaults to VIRIDIS.

Returns:

List of hex color codes corresponding to the input values.

Return type:

list

pykingenie.utils.processing.if_string_to_list(string_or_list)[source]

Convert a string to a list if necessary.

Parameters:

string_or_list (str or list) – Input string or list to convert.

Returns:

Converted list.

Return type:

list

Raises:

TypeError – If input is neither a string nor a list.

pykingenie.utils.processing.find_index_of_previous_step_type(df_steps, step_index, step_type)[source]

Find the index of the first step of a given type before a specified step index.

Parameters:
  • df_steps (pd.DataFrame) – DataFrame containing step information with a ‘Type’ column.

  • step_index (int) – Current step index.

  • step_type (str) – Type of step to search for.

Returns:

Index of the first step of the specified type before the given step index, or None if no matching step is found.

Return type:

int or None

pykingenie.utils.sensorgram_text module

Shared parsing for sensorgram text exports (paired-column SPR and Carterra).

These exports contain sensorgrams, rather than a complete instrument run log. Injection boundaries must be supplied by the caller, directly or through a TitrationAnalysis Data Info Sheet (info=). Responses and individual time grids are retained without interpolation or subtraction.

class pykingenie.utils.sensorgram_text.SensorgramTextExperiment(name, type)[source]

Bases: SurfaceBasedExperiment

Common import for sensorgram exports without an instrument run log.

Subclasses supply a reader returning Trace objects. Each trace becomes a sensor with Baseline, Association and Dissociation steps defined by caller-supplied boundaries; responses and time grids are kept unchanged.

class pykingenie.utils.sensorgram_text.Trace(name: str, time: numpy.ndarray, response: numpy.ndarray)[source]

Bases: object

name: str
time: ndarray
response: ndarray
pykingenie.utils.sensorgram_text.data_rows(lines, start, delimiter, width)[source]
pykingenie.utils.sensorgram_text.detect_decimal(cells, decimal=None)[source]

Return the decimal mark of the measurements, or check the one given.

decimal=None detects it from the cells: ',' when numbers such as 1,5 occur, otherwise '.'. Integers do not decide either way. Cells using both marks are ambiguous and raise an error.

pykingenie.utils.sensorgram_text.find_header(lines, predicate)[source]
pykingenie.utils.sensorgram_text.is_per_curve(value)[source]

Whether a setting gives one value per curve (sequence or mapping).

pykingenie.utils.sensorgram_text.parse_trace(name, points, decimal)[source]
pykingenie.utils.sensorgram_text.text_lines(file, encoding)[source]
pykingenie.utils.sensorgram_text.values_per_curve(value, names, label)[source]

pykingenie.utils.signal_solution module

Calculate solution-phase kinetic signals and numerical trajectories.

pykingenie.utils.signal_solution.solve_ode_one_site_insolution(t, koff, Kd, a_total, b_total, t0=0)[source]

Analytical solution for the one binding site model in solution.

Assumes that the initial concentration of the complex is zero.

The ODE dAB/dt = kon·(A_tot − AB)·(B_tot − AB) − koff·AB is a Riccati equation whose two fixed points x₁ (physical) and x₂ are the roots of

kon·x² − (kon·(A+B) + koff)·x + kon·A·B = 0

Starting from AB(0) = 0 the closed-form solution is

AB(t) = x₁·(1 − e^{λt}) / (1 − (x₁/x₂)·e^{λt})

with λ = −kon·√(p² − 4·A·B), p = A + B + Kd.

Parameters:
  • t (np.ndarray) – Time points to calculate the complex concentration.

  • koff (float) – Off rate constant.

  • Kd (float) – Equilibrium dissociation constant.

  • a_total (float) – Total concentration of the ligand.

  • b_total (float) – Total concentration of the receptor.

  • t0 (float, optional) – Initial time, default is 0.

Returns:

Complex concentration over time.

Return type:

np.ndarray

pykingenie.utils.signal_solution.signal_ode_one_site_insolution(t, koff, Kd, a_total, b_total, t0=0, signal_a=0, signal_b=0, signal_complex=0)[source]

Solve the ODE for the one binding site model and compute the signal.

Parameters:
  • t (np.ndarray) – Time.

  • koff (float) – Off rate constant.

  • Kd (float) – Equilibrium dissociation constant.

  • a_total (float) – Total concentration of the ligand.

  • b_total (float) – Total concentration of the receptor.

  • t0 (float, optional) – Initial time, default is 0.

  • signal_a (float, optional) – Signal for the ligand, default is 0.

  • signal_b (float, optional) – Signal for the receptor, default is 0.

  • signal_complex (float, optional) – Signal for the complex, default is 0.

Returns:

Signal over time.

Return type:

np.ndarray

pykingenie.utils.signal_solution.ode_induced_fit_insolution(t, y, k1, k_minus1, k2, k_minus2, E_tot, S_tot)[source]

Reduced ODEs for induced fit model using conservation of E and S.

Parameters:
  • t (float) – Time.

  • y (list) – Concentrations of E·S and ES.

  • k1 (float) – Rate constant for E + S -> E·S.

  • k_minus1 (float) – Rate constant for E·S -> E + S.

  • k2 (float) – Rate constant for E·S -> ES.

  • k_minus2 (float) – Rate constant for ES -> E·S.

  • E_tot (float) – Total concentration of the enzyme.

  • S_tot (float) – Total concentration of the substrate.

Returns:

[dE_S, dES] - Rate of change for concentrations of E·S and ES.

Return type:

list

pykingenie.utils.signal_solution.solve_ode_induced_fit_insolution(t, y0, k1, k_minus1, k2, k_minus2, E_tot, S_tot, t0=0)[source]

Solve the reduced ODE for the induced fit model in solution.

Parameters:
  • t (np.ndarray) – Time points to calculate the complex concentration.

  • y0 (list) – Initial concentrations of E·S and ES.

  • k1 (float) – Rate constant for E + S -> E·S.

  • k_minus1 (float) – Rate constant for E·S -> E + S.

  • k2 (float) – Rate constant for E·S -> ES.

  • k_minus2 (float) – Rate constant for ES -> E·S.

  • E_tot (float) – Total concentration of the enzyme.

  • S_tot (float) – Total concentration of the substrate.

  • t0 (float, optional) – Time between the start of the reaction and the first time point, default is 0.

Returns:

Solution of the ODE, contains the concentration of E, S, E·S and ES.

Return type:

np.ndarray

pykingenie.utils.signal_solution.signal_ode_induced_fit_insolution(t, y, k1, k_minus1, k2, k_minus2, E_tot, S_tot, t0=0, signal_E=0, signal_S=0, signal_ES_int=0, signal_ES=0)[source]

Solve the reduced ODE for the induced fit model and compute the signal.

Parameters:
  • t (np.ndarray) – Time.

  • y (list) – Concentrations of E·S and ES.

  • k1 (float) – Rate constant for E + S -> E·S.

  • k_minus1 (float) – Rate constant for E·S -> E + S.

  • k2 (float) – Rate constant for E·S -> ES.

  • k_minus2 (float) – Rate constant for ES -> E·S.

  • E_tot (float) – Total concentration of the enzyme.

  • S_tot (float) – Total concentration of the substrate.

  • t0 (float, optional) – Time between the start of the reaction and the first time point, default is 0.

  • signal_E (float, optional) – Signal for E, default is 0.

  • signal_S (float, optional) – Signal for S, default is 0.

  • signal_ES_int (float, optional) – Signal for E·S, default is 0.

  • signal_ES (float, optional) – Signal for ES, default is 0.

Returns:

Signal over time.

Return type:

np.ndarray

pykingenie.utils.signal_solution.ode_conformational_selection_insolution(t, y, k1, k_minus1, k2, k_minus2, E_tot, S_tot)[source]
Reduced ODEs for conformational selection using conservation:

E_tot = E1 + E2 + E2S S_tot = S + E2S

State vector y: [E2, E2S]

Returns: [dE2_dt, dE2S_dt]

pykingenie.utils.signal_solution.solve_ode_conformational_selection_insolution(t, y, k1, k_minus1, k2, k_minus2, E_tot, S_tot, t0=0)[source]

Solve ODE for the conformational selection model.

Parameters:
  • t (np.ndarray) – Time points to calculate the complex concentration.

  • y (list) – Initial concentrations of E2 and E2S.

  • k1 (float) – Rate constant for E1 -> E2.

  • k_minus1 (float) – Rate constant for E2 -> E1.

  • k2 (float) – Rate constant for E2 + S -> E2S.

  • k_minus2 (float) – Rate constant for E2S -> E2 + S.

  • E_tot (float) – total protein concentration

  • S_tot (float) – total substrate concentration

  • t0 (float, optional) – Time between the start of the reaction and the first time point, default is 0.

Returns:

Solution of the ODE, contains the concentration of E1, E2, S, E2S.

Return type:

np.ndarray

pykingenie.utils.signal_solution.signal_ode_conformational_selection_insolution(t, y, k1, k_minus1, k2, k_minus2, E_tot, S_tot, t0=0, signal_E1=0, signal_E2=0, signal_S=0, signal_E2S=0)[source]

Solve the ODE for the conformational selection model and compute the signal.

Parameters:
  • t (np.ndarray) – Time.

  • y (list) – Concentrations of E2 and E2S.

  • k1 (float) – Rate constant for E1 -> E2 (aka kc).

  • k_minus1 (float) – Rate constant for E2 -> E1 (aka krev).

  • k2 (float) – Rate constant for E2 + S -> E2S (aka kon).

  • k_minus2 (float) – Rate constant for E2S -> E2 + S (aka koff).

  • E_tot (float) – total protein concentration

  • S_tot (float) – total substrate concentration

  • t0 (float, optional) – Time between the start of the reaction and the first time point, default is 0.

  • signal_E1 (float, optional) – Signal for E1, default is 0.

  • signal_E2 (float, optional) – Signal for E2, default is 0.

  • signal_S (float, optional) – Signal for S, default is 0.

  • signal_E2S (float, optional) – Signal for E2S, default is 0.

Returns:

Signal over time.

Return type:

np.ndarray

pykingenie.utils.signal_solution.get_initial_concentration_conformational_selection(total_protein, k1, k_minus1)[source]

Obtain the equilibrium concentrations of E1 and E2 for the conformational selection model.

Assumes absence of ligand.

Parameters:
  • total_protein (float) – Total concentration of the protein.

  • k1 (float) – Rate constant for E1 -> E2.

  • k_minus1 (float) – Rate constant for E2 -> E1.

Returns:

[E1, E2] - Equilibrium concentrations of E1 and E2.

Return type:

list

pykingenie.utils.signal_solution.get_kobs_induced_fit(tot_lig, tot_prot, kr, ke, kon, koff, dominant=True)[source]

Calculate the observed rate constant (relaxation rate) for the induced fit model in solution.

Parameters:
  • tot_lig (float) – Total concentration of the ligand.

  • tot_prot (float) – Total concentration of the protein.

  • kr (float) – Rate constant for E2S -> E1S.

  • ke (float) – Rate constant for E1S -> E2S.

  • kon (float) – Rate constant for E1 + S -> E1S.

  • koff (float) – Rate constant for E1S -> E1 + S.

  • dominant (bool, optional) – If True, return the slower equilibrium relaxation rate; otherwise return the faster rate. Default is True.

Returns:

Observed rate constant (in 1/s).

Return type:

float

Notes

These are the two relaxation rates of the reaction equations linearised around equilibrium. ke is the forward conformational rate (k_c), and kr is the reverse rate (k_rev). The apparent dissociation constant is koff * kr / (kon * (ke + kr)).

pykingenie.utils.signal_solution.get_kobs_conformational_selection(tot_lig, tot_prot, kr, ke, kon, koff, dominant=True)[source]

Calculate the observed rate constant (relaxation rate) for the conformational selection model in solution.

Parameters:
  • tot_lig (float) – Total concentration of the ligand.

  • tot_prot (float) – Total concentration of the protein.

  • kr (float) – Rate constant for E2 -> E1.

  • ke (float) – Rate constant for E1 -> E2.

  • kon (float) – Rate constant for E2 + S -> E2S.

  • koff (float) – Rate constant for E2S -> E2 + S.

  • dominant (bool, optional) – If True, calculate the dominant relaxation rate, otherwise calculate the non-dominant relaxation rate, default is True.

Returns:

Observed rate constant (in 1/s).

Return type:

float

pykingenie.utils.signal_surface module

Calculate surface-based kinetic signals and numerical trajectories.

pykingenie.utils.signal_surface.steady_state_one_site(C, Rmax, Kd)[source]

Calculate the steady state signal for a given concentration of ligand.

If the concentration is zero, the signal is zero. If the concentration is infinite, the signal is Rmax. The units of Kd must match the units of C (ligand concentration). Rmax depends on the amount of loaded receptor.

Parameters:
  • C (np.ndarray) – Concentration of the analyte.

  • Rmax (float) – Maximum response of the analyte.

  • Kd (float) – Equilibrium dissociation constant.

Returns:

Steady state signal, according to the given parameters.

Return type:

np.ndarray

pykingenie.utils.signal_surface.one_site_association_analytical(t, s0, s_max, k_off, Kd, A, t0=0)[source]

Analytical solution for the one site association model.

Parameters:
  • t (np.ndarray) – Time variable.

  • s0 (float) – Initial signal.

  • s_max (float) – Maximum signal.

  • k_off (float) – Dissociation rate constant.

  • Kd (float) – Equilibrium dissociation constant.

  • A (float) – Concentration of the analyte.

  • t0 (float, optional) – Initial time offset, default is 0.

Returns:

Signal over time.

Return type:

np.ndarray

pykingenie.utils.signal_surface.one_site_dissociation_analytical(t, s0, k_off, t0=0)[source]

Analytical solution for the one site model - dissociation phase.

Parameters:
  • t (np.ndarray) – Time variable.

  • s0 (float) – Initial signal.

  • k_off (float) – Dissociation rate constant.

  • t0 (float, optional) – Initial time offset, default is 0.

Returns:

Signal over time.

Return type:

np.ndarray

pykingenie.utils.signal_surface.ode_one_site_mass_transport(t, s1, params, analyte_conc)[source]

Quasi-steady-state ODE for mass transport-limited one-site binding.

The thin layer next to the surface is assumed to settle instantly (Svitel et al. 2007, Eq. 8, https://doi.org/10.1529/biophysj.106.094615), which gives

dS/dt = (k_on * c0 * (s_max - S) - k_off * S) / (1 + k_on * (s_max - S) / k_tr)

Used for both phases: association with the injected concentration, dissociation with c0 = 0.

k_tr is a lumped transport coefficient in signal units (signal per µM per second), the product of the physical transport rate and the signal produced per unit of bound analyte. It is not the physical transport coefficient, and it scales with the signal units.

Parameters:
  • t (float) – Time variable.

  • s1 (float or list) – Signal.

  • params (list) – List of the parameters [K_d, k_off, k_tr, s_max].

  • analyte_conc (float) – Concentration of the analyte in the bulk, 0 during dissociation.

Returns:

The derivative of the signal over time.

Return type:

float

pykingenie.utils.signal_surface.solve_ode_one_site_mass_transport_association(t, s1_0, analyte_conc, K_d, k_off, k_tr, s_max, t0=0)[source]

Solves the ODE for the one site mass transport model - association phase.

See ode_one_site_mass_transport.

Parameters:
  • t (np.ndarray) – Time variable.

  • s1_0 (float) – Initial signal.

  • analyte_conc (float) – Concentration of the analyte.

  • K_d (float) – Equilibrium dissociation constant.

  • k_off (float) – Dissociation rate constant.

  • k_tr (float) – Lumped mass transport coefficient (signal per µM per second).

  • s_max (float) – Maximum signal.

  • t0 (float, optional) – Initial time offset, default is 0.

Returns:

Signal over time.

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_ode_one_site_mass_transport_dissociation(t, s1_0, K_d, k_off, k_tr, s_max, t0=0)[source]

Solves the ODE for the one site mass transport model - dissociation phase.

Same model as the association, with no analyte in the bulk. See ode_one_site_mass_transport.

Parameters:
  • t (np.ndarray) – Time variable.

  • s1_0 (float) – Initial signal.

  • K_d (float) – Equilibrium dissociation constant.

  • k_off (float) – Dissociation rate constant.

  • k_tr (float) – Lumped mass transport coefficient (signal per µM per second).

  • s_max (float) – Maximum signal.

  • t0 (float, optional) – Initial time offset, default is 0.

Returns:

Signal over time.

Return type:

np.ndarray

pykingenie.utils.signal_surface.one_site_mass_transport_analytical(t, s1_0, analyte_conc, K_d, k_off, k_tr, s_max, t0=0)[source]

Closed-form solution of the mass transport-limited one-site model.

Solves the same equation as ode_one_site_mass_transport

dS/dt = (k_on * c0 * (s_max - S) - k_off * S) / (1 + k_on * (s_max - S) / k_tr)

without numerical integration. With free sites F = s_max - S, k = k_on / k_tr, k_s = k_on * c0 + k_off, F_eq = k_off * s_max / k_s and B = 1 + k * F_eq, the variables separate and y = k * (F - F_eq) / B satisfies

y * exp(y) = y0 * exp(y0) * exp(-k_s * t / B)

so y(t) = W0(y0 * exp(y0 - k_s * t / B)), with W0 the principal branch of the Lambert W function. The principal branch always applies, because F >= 0 gives y > -1.

The signal is s1_0 at time min(t) + t0, as in one_site_association_analytical. Points before that are the same solution followed backward in time. With t0 = 0 this matches solve_ode_one_site_mass_transport_association; in the ODE solvers t0 has no effect, because the integration always starts at the first time point.

Backward in time from above equilibrium the surface can fill (S = s_max). Before that point the signal follows dS/dt = -k_off * S, as in the ODE, which clips free sites at 0.

Parameters:
  • t (np.ndarray) – Time variable.

  • s1_0 (float) – Signal at time min(t) + t0. Values above s_max are treated as s_max.

  • analyte_conc (float) – Concentration of the analyte in the bulk, 0 during dissociation.

  • K_d (float) – Equilibrium dissociation constant.

  • k_off (float) – Dissociation rate constant.

  • k_tr (float) – Lumped mass transport coefficient (signal per µM per second). np.inf gives the 1:1 model without transport limitation.

  • s_max (float) – Maximum signal.

  • t0 (float, optional) – Time after the first time point at which the signal is s1_0, default is 0.

Returns:

Signal over time.

Return type:

np.ndarray

pykingenie.utils.signal_surface.one_site_mass_transport_association_analytical(t, s1_0, analyte_conc, K_d, k_off, k_tr, s_max, t0=0)[source]

Closed-form mass transport model - association phase.

Drop-in replacement for solve_ode_one_site_mass_transport_association. See one_site_mass_transport_analytical.

Parameters:
  • t (np.ndarray) – Time variable.

  • s1_0 (float) – Initial signal.

  • analyte_conc (float) – Concentration of the analyte.

  • K_d (float) – Equilibrium dissociation constant.

  • k_off (float) – Dissociation rate constant.

  • k_tr (float) – Lumped mass transport coefficient (signal per µM per second).

  • s_max (float) – Maximum signal.

  • t0 (float, optional) – Time after the first time point at which the signal is s1_0, default is 0.

Returns:

Signal over time.

Return type:

np.ndarray

pykingenie.utils.signal_surface.one_site_mass_transport_dissociation_analytical(t, s1_0, K_d, k_off, k_tr, s_max, t0=0)[source]

Closed-form mass transport model - dissociation phase.

Drop-in replacement for solve_ode_one_site_mass_transport_dissociation. See one_site_mass_transport_analytical.

Parameters:
  • t (np.ndarray) – Time variable.

  • s1_0 (float) – Initial signal.

  • K_d (float) – Equilibrium dissociation constant.

  • k_off (float) – Dissociation rate constant.

  • k_tr (float) – Lumped mass transport coefficient (signal per µM per second).

  • s_max (float) – Maximum signal.

  • t0 (float, optional) – Time after the first time point at which the signal is s1_0, default is 0.

Returns:

Signal over time.

Return type:

np.ndarray

pykingenie.utils.signal_surface.differential_matrix_association_induced_fit(koff, kon, kc, krev, a)[source]

Association step set of differential equations for the induced fit model.

Differential equations for -dS/dt and dS1/dt where: S = R([E2S] + [E1S]) ; Total signal S1 = R[E2S] ; Signal produced by E2S Smax = R([Et]) ; Maximum signal

Note: E is here the molecule attached to the surface, S is the substrate. The signal produced by E2S and E1S is the same.

Parameters:
  • koff (float) – Rate constant for E1S -> E1 + S.

  • kon (float) – Rate constant for E1 + S -> E1S.

  • kc (float) – Rate constant for E1S -> E2S.

  • krev (float) – Rate constant for E2S -> E1S.

  • a (float) – Concentration of the analyte (molecule being flown).

Returns:

Differential matrix.

Return type:

np.ndarray

pykingenie.utils.signal_surface.differential_matrix_association_conformational_selection(koff, kon, kc, krev, a)[source]

Conformational selection model for the association step.

E1 <-> E2 E2 + S <-> E2S

Set of differential equations for (d[E1]*R)/dt and d[E2S]*R/dt. The signal is only given by E2S.

Parameters:
  • koff (float) – Rate constant for E2S -> E2 + S.

  • kon (float) – Rate constant for E2 + S -> E2S.

  • kc (float) – Rate constant for E1 -> E2.

  • krev (float) – Rate constant for E2 -> E1.

  • a (float) – Concentration of the analyte (molecule being flown).

Returns:

Differential matrix.

Return type:

np.ndarray

pykingenie.utils.signal_surface.differential_matrix_dissociation_induced_fit(koff, kc, krev)[source]

Dissociation step set of differential equations for the induced fit model.

Differential equations for -ds/dt and ds1/dt.

Parameters:
  • koff (float) – Rate constant for E1S -> E1 + S.

  • kc (float) – Rate constant for E1S -> E2S.

  • krev (float) – Rate constant for E2S -> E1S.

Returns:

Differential matrix.

Return type:

np.ndarray

pykingenie.utils.signal_surface.differential_matrix_dissociation_conformational_selection(koff, kc, krev)[source]

Dissociation step set of differential equations for the conformational selection model.

Differential equations for (d[E1]*R)/dt and d[E2S]*R/dt. The signal is only proportional to E2S.

Parameters:
  • koff (float) – Rate constant for E2S -> E2 + S.

  • kc (float) – Rate constant for E1 -> E2.

  • krev (float) – Rate constant for E2 -> E1.

Returns:

Differential matrix.

Return type:

np.ndarray

pykingenie.utils.signal_surface.constant_vector_induced_fit(koff, a, kc)[source]

Calculate the constant vector for the induced fit model.

Parameters:
  • koff (float) – Rate constant for E·S -> E + S.

  • a (float) – Concentration of the analyte (molecule being flown).

  • kc (float) – Rate constant for E·S -> ES, induced fit step.

Returns:

Constant vector.

Return type:

np.ndarray

pykingenie.utils.signal_surface.constant_vector_conformational_selection(kon, smax, krev, a)[source]

Calculate the constant vector for the conformational selection model.

Parameters:
  • kon (float) – Rate constant for E2 + S -> E2S.

  • smax (float) – Signal proportional to the complex (E2S).

  • krev (float) – Rate constant for E2 -> E1.

  • a (float) – Concentration of the analyte (molecule being flown).

Returns:

Constant vector.

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_steady_state(A, b)[source]

Calculate the steady state solution of the system of equations.

Parameters:
  • A (np.ndarray) – Differential matrix.

  • b (np.ndarray) – Constant vector.

Returns:

Steady state solution.

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_all_states_fast(time, A, initial_conditions, steady_state_value)[source]

Solve the linear system dx/dt = A·x + b for all time points.

The solution is

x(t) = x_ss + exp(A·t) · (x₀ − x_ss)

where x_ss is the steady state. For a 2×2 matrix, the case of every surface model here, exp(A·t) is evaluated in closed form (Putzer):

exp(A·t) = e^(λ1·t)·I + f(t)·(A − λ1·I), f(t) = (e^(λ1·t) − e^(λ2·t)) / (λ1 − λ2)

which also holds when the eigenvalues are equal and A cannot be diagonalised (f(t) then tends to t·e^(λ1·t)). Larger matrices use the eigendecomposition of A. All time points are evaluated at once.

Parameters:
  • time (np.ndarray) – Array of time points to solve the system for.

  • A (np.ndarray) – Differential matrix of the system.

  • initial_conditions (np.ndarray) – Initial conditions for the system.

  • steady_state_value (np.ndarray) – Steady state solution of the system.

Returns:

Array of shape (len(time), len(initial_conditions)) containing the state of the system at each time point.

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_induced_fit_association(time, a_conc, kon, koff, kc, krev, sP1L=0, sP2L=0, smax=0, t0=0, signal_ratio=1.0)[source]

Obtain the signal for the induced fit model (surface-based).

By default the complex before (E·S) and after (ES) the conformational change produce the same signal. Set signal_ratio to let the induced complex ES produce a different signal: the total signal is then R(E·S) + signal_ratio·R(ES), where R is the response of E·S.

Parameters:
  • time (np.ndarray) – Time array.

  • a_conc (float) – Concentration of the analyte (molecule being flown).

  • kon (float) – Rate constant for E + S -> E·S.

  • koff (float) – Rate constant for E·S -> E + S.

  • kc (float) – Rate constant for E·S -> ES.

  • krev (float) – Rate constant for ES -> E·S.

  • sP1L (float, optional) – Initial signal proportional to the concentration of E·S, default is 0.

  • sP2L (float, optional) – Initial signal proportional to the concentration of ES, default is 0.

  • smax (float, optional) – Signal of the surface fully occupied by the intermediate complex (E·S), default is 0.

  • t0 (float, optional) – Time offset; the association starts at time t0 after the first time point, default is 0.

  • signal_ratio (float, optional) – Signal of the induced complex (ES) relative to the intermediate complex (E·S), default is 1 (same signal).

Returns:

Array with three columns: the total signal, the signal of E·S, and the amount of ES expressed in E·S signal units (ES contributes signal_ratio times this column to the total signal).

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_conformational_selection_association(time, a_conc, kon, koff, kc, krev, smax=0, sP1=0, sP2L=0)[source]

Obtain the signal for the conformational selection model (surface-based).

We assume that the signal is given by the complex E2S only.

Parameters:
  • time (np.ndarray) – Time array.

  • a_conc (float) – Concentration of the analyte (molecule being flown).

  • kon (float) – Rate constant for E2 + S -> E2S.

  • koff (float) – Rate constant for E2S -> E2 + S.

  • kc (float) – Rate constant for E1 -> E2.

  • krev (float) – Rate constant for E2 -> E1.

  • smax (float, optional) – Maximum signal that the complex (E2S) can produce, default is 0.

  • sP1 (float, optional) – Initial signal proportional to the concentration of E1, default is 0.

  • sP2L (float, optional) – Initial signal proportional to the concentration of E2S, default is 0.

Returns:

Signal over time, with columns for the signal, sP1, and sP2.

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_induced_fit_dissociation(time, koff, kc, krev, s0=0, sP2L=0, smax=0, signal_ratio=1.0)[source]

Obtain the dissociation signal for the induced fit model (surface-based).

By default the complex before (E·S) and after (ES) the conformational change produce the same signal. Set signal_ratio to let ES produce a different signal (see solve_induced_fit_association).

Parameters:
  • time (np.ndarray) – Time array.

  • koff (float) – Rate constant for E·S -> E + S.

  • kc (float) – Rate constant for E·S -> ES.

  • krev (float) – Rate constant for ES -> E·S.

  • s0 (float, optional) – Initial total signal, default is 0.

  • sP2L (float, optional) – Initial amount of ES in E·S signal units (third column returned by solve_induced_fit_association), default is 0.

  • smax (float, optional) – Signal of the surface fully occupied by E·S, default is 0.

  • signal_ratio (float, optional) – Signal of ES relative to E·S, default is 1 (same signal).

Returns:

Signal over time, with columns for total signal, signal produced by E·S, and amount of ES in E·S signal units.

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_conformational_selection_dissociation(time, koff, kc, krev, smax=0, sP1=0, sP2L=0)[source]

Obtain the signal for the conformational selection model (surface-based) during dissociation.

We assume that the signal is given by the complex E2S only.

Parameters:
  • time (np.ndarray) – Time array.

  • koff (float) – Rate constant for E2S -> E2 + S.

  • kc (float) – Rate constant for E1 -> E2.

  • krev (float) – Rate constant for E2 -> E1.

  • smax (float, optional) – Signal proportional to the complex (E2S), default is 0.

  • sP1 (float, optional) – Initial signal proportional to the concentration of E1, default is 0.

  • sP2L (float, optional) – Initial signal proportional to the concentration of E2S, default is 0.

Returns:

Array with columns for signal (produced by E2S), sP1 (E1 concentration), and sP2 (E2 concentration).

Return type:

np.ndarray

pykingenie.utils.signal_surface.ode_mixture_analyte_association(t, Ris, C_TOT, Fis, Ris_max, koffs, Kds)[source]

We assume a Langmuir 1:1 interaction between each analyte (Ai) and the ligand (L):

Ai + L <-> AiL, ∀i in [1,N]

Based on https://doi.org/10.1038/s41598-022-18450-y

This model is equivalent to the heterogenous analyte model

The parameters to fit are the factor weights (Fis), the maximum response of each analyte (Ris_max), the dissociation rate constants (koffs), and the equilibrium dissociation constants (Kds)

Parameters:
  • t (np.ndarray) – Time variable.

  • Ris (list) – Response of each analyte.

  • C_TOT (float) – Total concentration of the analyte mixture.

  • Fis (np.ndarray) – Factor weights.

  • Ris_max (np.ndarray) – Maximum response of each analyte.

  • koffs (np.ndarray) – Dissociation rate constants.

  • Kds (np.ndarray) – Equilibrium dissociation constants.

Returns:

Rate of change of the response of each analyte.

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_ode_mixture_analyte_association(t, Ris0, C_TOT, Fis, Ris_max, koffs, Kds, t0=0)[source]

Solves the mixture analyte model - association phase.

The equations of ode_mixture_analyte_association are linear,

dR/dt = A·R + b, A = −diag(koffs) − u·vᵀ, b = u,

with u_i = kon_i·F_i·C_TOT·Ris_max_i and v_j = 1/Ris_max_j, so they are solved exactly with solve_all_states_fast instead of numerically.

Parameters:
  • t (np.ndarray) – Time variable.

  • Ris0 (list) – Response of each analyte when the association starts.

  • C_TOT (float) – Total concentration of the analyte mixture.

  • Fis (np.ndarray) – Factor weights.

  • Ris_max (np.ndarray) – Maximum response of each analyte.

  • koffs (np.ndarray) – Dissociation rate constants.

  • Kds (np.ndarray) – Equilibrium dissociation constants.

  • t0 (float, optional) – Time after the first time point at which the association starts (the response is Ris0 then), default is 0.

Returns:

Response of EACH ANALYTE over time, shape (number of analytes, len(t)).

Return type:

np.ndarray

pykingenie.utils.signal_surface.ode_mixture_analyte_dissociation(t, Ris, koffs)[source]

We assume a Langmuir 1:1 interaction between each analyte (Ai) and the ligand (L):

Ai + L <-> AiL, ∀i in [1,N]

Based on https://doi.org/10.1038/s41598-022-18450-y

This model is equivalent to the heterogenous analyte model

The parameters to fit are the dissociation rate constants (koffs)

Parameters:
  • t (np.ndarray) – Time variable.

  • Ris (list) – Response of each analyte.

  • koffs (np.ndarray) – Dissociation rate constants.

Returns:

Rate of change of the response of each analyte.

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_ode_mixture_analyte_dissociation(t, Ris0, koffs, t0=0)[source]

Solves the mixture analyte model - dissociation phase.

Each analyte dissociates on its own, so the solution is exact: R_i(t) = Ris0_i·exp(−koff_i·t).

Parameters:
  • t (np.ndarray) – Time variable.

  • Ris0 (list) – Response of each analyte when the dissociation starts.

  • koffs (np.ndarray) – Dissociation rate constants.

  • t0 (float, optional) – Time after the first time point at which the dissociation starts (the response is Ris0 then), default is 0.

Returns:

Response of EACH ANALYTE over time, shape (number of analytes, len(t)).

Return type:

np.ndarray

pykingenie.utils.signal_surface.steady_state_two_site_heterogeneous_ligand(C, Rmax, Kd1, Kd2, fraction_site1)[source]

Steady state signal for a 2:1 heterogeneous ligand model.

The model is the weighted sum of two independent 1:1 binding signals. fraction_site1 is the fraction of the total binding response contributed by interaction 1; interaction 2 contributes 1 - fraction_site1.

Parameters:
  • C (np.ndarray) – Concentration of the analyte.

  • Rmax (float) – Total maximum response from both ligand interactions.

  • Kd1 (float) – Equilibrium dissociation constant for interaction 1.

  • Kd2 (float) – Equilibrium dissociation constant for interaction 2.

  • fraction_site1 (float) – Fractional contribution of interaction 1, from 0 to 1.

Returns:

Steady state signal.

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_two_site_heterogeneous_ligand_association(time, a_conc, Kd1, koff1, Kd2, koff2, Rmax=0, fraction_site1=0.5, s1_0=0, s2_0=0, t0=0)[source]

Association signal for a 2:1 heterogeneous ligand model.

The association trace is computed as two independent 1:1 association curves added together. The total response is split into two component responses using fraction_site1.

Parameters:
  • time (np.ndarray) – Time array.

  • a_conc (float) – Analyte concentration.

  • Kd1 (float) – Equilibrium dissociation constant for interaction 1.

  • koff1 (float) – Dissociation rate constant for interaction 1.

  • Kd2 (float) – Equilibrium dissociation constant for interaction 2.

  • koff2 (float) – Dissociation rate constant for interaction 2.

  • Rmax (float, optional) – Total maximum response from both ligand interactions, default is 0.

  • fraction_site1 (float, optional) – Fractional contribution of interaction 1, from 0 to 1, default is 0.5.

  • s1_0 (float, optional) – Initial signal from interaction 1, default is 0.

  • s2_0 (float, optional) – Initial signal from interaction 2, default is 0.

  • t0 (float, optional) – Initial time offset, default is 0.

Returns:

Array with columns [total_signal, signal_site1, signal_site2].

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_two_site_heterogeneous_ligand_dissociation(time, koff1, koff2, s0=0, fraction_site1=0.5, s1_0=None, s2_0=None, t0=0)[source]

Dissociation signal for a 2:1 heterogeneous ligand model.

The dissociation trace is computed as two independent 1:1 dissociation curves added together. If component initial signals are not provided, s0 is split using fraction_site1.

Parameters:
  • time (np.ndarray) – Time array.

  • koff1 (float) – Dissociation rate constant for interaction 1.

  • koff2 (float) – Dissociation rate constant for interaction 2.

  • s0 (float, optional) – Initial total signal, default is 0.

  • fraction_site1 (float, optional) – Fractional contribution of interaction 1, from 0 to 1, default is 0.5.

  • s1_0 (float, optional) – Initial signal from interaction 1. If None, use s0 * fraction_site1.

  • s2_0 (float, optional) – Initial signal from interaction 2. If None, use s0 * (1 - fraction_site1).

  • t0 (float, optional) – Initial time offset, default is 0.

Returns:

Array with columns [total_signal, signal_site1, signal_site2].

Return type:

np.ndarray

pykingenie.utils.signal_surface.steady_state_two_site(C, Rmax_PL, Rmax_LPL, Kd)[source]

Steady state signal for a ligand with two identical, independent binding sites.

The immobilized ligand P has two equivalent binding sites for the analyte L. PL (= LP) denotes singly-bound ligand, LPL denotes doubly-bound ligand.

For two identical independent sites with intrinsic dissociation constant Kd, the equilibrium fractions are:

  • fPL = 2 * theta * (1 - theta)

  • fLPL = theta ** 2

where theta = C / (C + Kd) is the single-site occupancy.

Parameters:
  • C (np.ndarray) – Concentration of the analyte.

  • Rmax_PL (float) – Maximum signal when all ligand is singly bound (PL state).

  • Rmax_LPL (float) – Maximum signal when all ligand is doubly bound (LPL state).

  • Kd (float) – Intrinsic equilibrium dissociation constant (per site).

Returns:

Steady state signal.

Return type:

np.ndarray

pykingenie.utils.signal_surface.steady_state_two_site_cooperative(C, Rmax_PL, Rmax_LPL, Kd, sigma)[source]

Steady state signal for a ligand with two identical binding sites and cooperativity.

The cooperativity factor sigma modifies the second binding event. The intrinsic dissociation constant for the second site becomes Kd / sigma.

  • sigma > 1 : positive cooperativity (second binding is tighter).

  • sigma < 1 : negative cooperativity.

  • sigma = 1 : identical independent sites (non-cooperative).

The equilibrium fractions are computed from the partition function:

Z = 1 + 2 * C / Kd + sigma * (C / Kd) ** 2

  • fPL = (2 * C / Kd) / Z

  • fLPL = sigma * (C / Kd) ** 2 / Z

Parameters:
  • C (np.ndarray) – Concentration of the analyte.

  • Rmax_PL (float) – Maximum signal when all ligand is singly bound (PL state).

  • Rmax_LPL (float) – Maximum signal when all ligand is doubly bound (LPL state).

  • Kd (float) – Intrinsic equilibrium dissociation constant (per site).

  • sigma (float) – Cooperativity factor.

Returns:

Steady state signal.

Return type:

np.ndarray

pykingenie.utils.signal_surface.differential_matrix_association_two_site(kon, koff, a)[source]

Differential matrix for the two-site model during association (non-cooperative).

The ligand P (immobilized) has two equivalent, independent binding sites. The analyte L flows at fixed concentration a.

State variables: [fPL, fLPL] where

  • fPL = fraction of ligand in the singly-bound state (PL + LP)

  • fLPL = fraction of ligand in the doubly-bound state (LPL)

  • fP = 1 - fPL - fLPL (free ligand, from conservation)

Reactions with statistical factors:

P  + L  -> PL  : 2 * kon * a * fP    (2 equivalent empty sites)
PL      -> P+L : koff * fPL           (1 occupied site)
PL + L  -> LPL : kon * a * fPL        (1 remaining empty site)
LPL     -> PL+L: 2 * koff * fLPL      (2 occupied sites)

The resulting ODE is d[fPL, fLPL]/dt = A @ [fPL, fLPL] + b where b = constant_vector_two_site(kon, a).

Parameters:
  • kon (float) – Intrinsic association rate constant (per site).

  • koff (float) – Intrinsic dissociation rate constant (per site).

  • a (float) – Analyte concentration.

Returns:

2×2 differential matrix.

Return type:

np.ndarray

pykingenie.utils.signal_surface.differential_matrix_association_two_site_cooperative(kon, koff, sigma, a)[source]

Differential matrix for the two-site model during association (cooperative).

Same as differential_matrix_association_two_site(), but the second binding step is modified by the cooperativity factor sigma.

The kinetic effect is split symmetrically between on-rate and off-rate using sqrt(sigma):

  • Second site on-rate = sqrt(sigma) * kon

  • Second site off-rate = koff / sqrt(sigma)

This gives an effective Kd for the second site of Kd / sigma.

Parameters:
  • kon (float) – Intrinsic association rate constant (per site).

  • koff (float) – Intrinsic dissociation rate constant (per site).

  • sigma (float) – Cooperativity factor. sigma > 1 for positive cooperativity.

  • a (float) – Analyte concentration.

Returns:

2×2 differential matrix.

Return type:

np.ndarray

pykingenie.utils.signal_surface.constant_vector_two_site(kon, a)[source]

Constant vector for the two-site association ODE.

This vector is the same for both cooperative and non-cooperative cases.

Parameters:
  • kon (float) – Intrinsic association rate constant (per site).

  • a (float) – Analyte concentration.

Returns:

Constant vector [2*kon*a, 0].

Return type:

np.ndarray

pykingenie.utils.signal_surface.differential_matrix_dissociation_two_site(koff)[source]

Differential matrix for the two-site model during dissociation (non-cooperative).

When analyte concentration is zero, only dissociation occurs:

PL  -> P + L  : koff * fPL          (1 occupied site)
LPL -> PL + L : 2 * koff * fLPL     (2 occupied sites, either can leave)
Parameters:

koff (float) – Intrinsic dissociation rate constant (per site).

Returns:

2×2 differential matrix.

Return type:

np.ndarray

pykingenie.utils.signal_surface.differential_matrix_dissociation_two_site_cooperative(koff, sigma)[source]

Differential matrix for the two-site model during dissociation (cooperative).

The kinetic effect is split symmetrically using sqrt(sigma), so the per-site off-rate in the doubly-bound state is koff / sqrt(sigma):

PL  -> P + L  : koff * fPL                       (first site, unmodified)
LPL -> PL + L : 2 * (koff / sqrt(sigma)) * fLPL  (second site, modified)
Parameters:
  • koff (float) – Intrinsic dissociation rate constant (per site).

  • sigma (float) – Cooperativity factor.

Returns:

2×2 differential matrix.

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_two_site_association(time, a_conc, kon, koff, Rmax_PL=0, Rmax_LPL=0, fPL_0=0, fLPL_0=0, t0=0)[source]

Solve the two-site binding model (non-cooperative) during association.

The immobilized ligand P has two equivalent, independent binding sites. The analyte L flows at fixed concentration a_conc. The observed signal is a weighted sum of the singly-bound and doubly-bound fractions, with different response factors Rmax_PL and Rmax_LPL.

Parameters:
  • time (np.ndarray) – Time array.

  • a_conc (float) – Analyte concentration.

  • kon (float) – Intrinsic association rate constant (per site).

  • koff (float) – Intrinsic dissociation rate constant (per site).

  • Rmax_PL (float, optional) – Signal when all ligand is singly bound (PL), default is 0.

  • Rmax_LPL (float, optional) – Signal when all ligand is doubly bound (LPL), default is 0.

  • fPL_0 (float, optional) – Initial fraction of singly-bound ligand, default is 0.

  • fLPL_0 (float, optional) – Initial fraction of doubly-bound ligand, default is 0.

  • t0 (float, optional) – Time offset; the association starts at time t0 after the first time point, default is 0.

Returns:

Array with columns [total_signal, signal_PL, signal_LPL].

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_two_site_cooperative_association(time, a_conc, kon, koff, sigma, Rmax_PL=0, Rmax_LPL=0, fPL_0=0, fLPL_0=0, t0=0)[source]

Solve the two-site binding model (cooperative) during association.

Same as solve_two_site_association() but with a cooperativity factor sigma that modifies the second binding step:

  • Second site on-rate = sqrt(sigma) * kon

  • Second site off-rate = koff / sqrt(sigma)

  • Effective Kd for the second site = Kd / sigma

Parameters:
  • time (np.ndarray) – Time array.

  • a_conc (float) – Analyte concentration.

  • kon (float) – Intrinsic association rate constant (per site).

  • koff (float) – Intrinsic dissociation rate constant (per site).

  • sigma (float) – Cooperativity factor. sigma > 1 for positive cooperativity.

  • Rmax_PL (float, optional) – Signal when all ligand is singly bound (PL), default is 0.

  • Rmax_LPL (float, optional) – Signal when all ligand is doubly bound (LPL), default is 0.

  • fPL_0 (float, optional) – Initial fraction of singly-bound ligand, default is 0.

  • fLPL_0 (float, optional) – Initial fraction of doubly-bound ligand, default is 0.

  • t0 (float, optional) – Time offset; the association starts at time t0 after the first time point, default is 0.

Returns:

Array with columns [total_signal, signal_PL, signal_LPL].

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_two_site_dissociation(time, koff, Rmax_PL=0, Rmax_LPL=0, fPL_0=0, fLPL_0=0)[source]

Solve the two-site binding model (non-cooperative) during dissociation.

Analyte concentration is zero. Only dissociation of existing complexes occurs.

Parameters:
  • time (np.ndarray) – Time array.

  • koff (float) – Intrinsic dissociation rate constant (per site).

  • Rmax_PL (float, optional) – Signal when all ligand is singly bound (PL), default is 0.

  • Rmax_LPL (float, optional) – Signal when all ligand is doubly bound (LPL), default is 0.

  • fPL_0 (float, optional) – Initial fraction of singly-bound ligand.

  • fLPL_0 (float, optional) – Initial fraction of doubly-bound ligand.

Returns:

Array with columns [total_signal, signal_PL, signal_LPL].

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_two_site_cooperative_dissociation(time, koff, sigma, Rmax_PL=0, Rmax_LPL=0, fPL_0=0, fLPL_0=0)[source]

Solve the two-site binding model (cooperative) during dissociation.

Same as solve_two_site_dissociation() but with a cooperativity factor sigma that modifies the second site off-rate:

  • First site off-rate = koff (PL -> P + L, unmodified)

  • Second site off-rate = koff / sqrt(sigma) (LPL -> PL + L, modified)

Parameters:
  • time (np.ndarray) – Time array.

  • koff (float) – Intrinsic dissociation rate constant (per site).

  • sigma (float) – Cooperativity factor.

  • Rmax_PL (float, optional) – Signal when all ligand is singly bound (PL), default is 0.

  • Rmax_LPL (float, optional) – Signal when all ligand is doubly bound (LPL), default is 0.

  • fPL_0 (float, optional) – Initial fraction of singly-bound ligand.

  • fLPL_0 (float, optional) – Initial fraction of doubly-bound ligand.

Returns:

Array with columns [total_signal, signal_PL, signal_LPL].

Return type:

np.ndarray

pykingenie.utils.signal_surface.ode_bivalent_analyte(t, x, ka1, kd1, ka2, kd2, a_conc, Rmax)[source]

Rates of change of the bivalent analyte complexes.

Parameters:
  • t (float) – Time (unused; the system is autonomous).

  • x (array_like) – [x1, x2]: singly bound (AL) and doubly bound (AL2) analyte, in response units.

  • ka1 (float) – Association rate constant of the first arm, 1/(µM·s).

  • kd1 (float) – Dissociation rate constant of the first arm, 1/s.

  • ka2 (float) – Association rate constant of the second arm, 1/(signal·s).

  • kd2 (float) – Dissociation rate constant of the second arm, 1/s.

  • a_conc (float) – Analyte concentration, µM (0 during dissociation).

  • Rmax (float) – Response with every ligand bound by one analyte.

Returns:

[dx1/dt, dx2/dt].

Return type:

list

pykingenie.utils.signal_surface.solve_bivalent_analyte_association(time, a_conc, Kd1, koff1, ka2, kd2, Rmax, x1_0=0.0, x2_0=0.0, t0=0, rtol=1e-08)[source]

Association signal of a bivalent analyte binding an immobilised ligand.

See the description of the model above ode_bivalent_analyte.

Parameters:
  • time (np.ndarray) – Time array.

  • a_conc (float) – Analyte concentration, µM.

  • Kd1 (float) – Equilibrium dissociation constant of the first arm (kd1/ka1), µM.

  • koff1 (float) – Dissociation rate constant of the first arm (kd1), 1/s.

  • ka2 (float) – Association rate constant of the second arm, 1/(signal·s).

  • kd2 (float) – Dissociation rate constant of the second arm, 1/s.

  • Rmax (float) – Response with every ligand bound by one analyte.

  • x1_0 (float, optional) – Singly and doubly bound analyte at the start of the step, default is 0.

  • x2_0 (float, optional) – Singly and doubly bound analyte at the start of the step, default is 0.

  • t0 (float, optional) – Time offset; the association starts at time t0 after the first time point, default is 0.

  • rtol (float, optional) – Relative tolerance of the integration, default is 1e-8.

Returns:

Array with columns [total_signal, signal_AL, signal_AL2].

Return type:

np.ndarray

pykingenie.utils.signal_surface.solve_bivalent_analyte_dissociation(time, koff1, ka2, kd2, Rmax, x1_0=0.0, x2_0=0.0, rtol=1e-08)[source]

Dissociation signal of a bivalent analyte from an immobilised ligand.

Without analyte in solution, AL2 can still open one arm and rebind it, and AL loses the analyte with rate kd1. See the description above ode_bivalent_analyte.

Parameters:
  • time (np.ndarray) – Time array; the dissociation starts at the first time point.

  • koff1 (float) – Dissociation rate constant of the first arm (kd1), 1/s.

  • ka2 (float) – Association rate constant of the second arm, 1/(signal·s).

  • kd2 (float) – Dissociation rate constant of the second arm, 1/s.

  • Rmax (float) – Response with every ligand bound by one analyte.

  • x1_0 (float, optional) – Singly and doubly bound analyte at the start of the dissociation.

  • x2_0 (float, optional) – Singly and doubly bound analyte at the start of the dissociation.

  • rtol (float, optional) – Relative tolerance of the integration, default is 1e-8.

Returns:

Array with columns [total_signal, signal_AL, signal_AL2].

Return type:

np.ndarray

pykingenie.utils.text_io module

Shared delimiter handling for exported text tables.

pykingenie.utils.text_io.read_delimited_table(file, *, skiprows=0, header='infer')[source]

Read a comma-, tab- or semicolon-separated table with CSV quoting.

Detect the separator from up to ten non-empty rows, after skiprows. Fall back to the header when optional trailing fields make rows ragged. Limit inference to supported separators so a one-column file cannot be silently split on letters in its header. Pandas’ input handle preserves its normal compression support. Spaces after separators are ignored outside quoted fields; separators within quoted names or values are preserved.