-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample_homodimer_formation_fit.py
38 lines (28 loc) · 1.35 KB
/
example_homodimer_formation_fit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Fitting example, determining Kd for homodimer breaking data"""
import numpy as np
import pybindingcurve as pbc
import sys
# We can choose to work in a common unit, typically nM, or uM, as long as all
# numbers are in the same unit, the result is valid. We assume uM for all
# concentrations bellow.
# Experimental data
xcoords = np.array([0.0, 2, 4, 6, 8, 10])
ycoords = np.array([0.0, 0.22, 0.71, 1.24, 1.88, 2.48])
# Construct the PyBindingCurve object, operating on a homodimer formation
# system and add experimental data to the plot
my_system = pbc.BindingCurve("homodimer formation")
my_system.add_scatter(xcoords, ycoords)
# Known system parameters, kdpp will be added to this by fitting
system_parameters = {"p": xcoords}
# Now we call fit, passing the known parameters, followed by a dict of parameters to be fitted along
# with an initial guess, pass the ycoords, and what the readout (ycoords) is
fitted_system, fit_accuracy = my_system.fit(system_parameters, {"kdpp": 0}, ycoords)
# Print out the fitted parameters
for k, v in fit_accuracy.items():
print(f"Fit: {k}={fitted_system[k]} +/- {v}")
# Assign more points to 'p' to make a smooth plot
fitted_system["p"] = np.linspace(0, np.max(xcoords))
# Add a new curve, simulated using fitted parameters to our BindingCurve object
my_system.add_curve(fitted_system)
# Show the plot
my_system.show_plot()