<jupyter_start><jupyter_text>PyFolding SI Notebook 2---[Author] ERGM--- Fitting Gankyrin Data to various kinetic models in seriesIn this notebook we will fit more complicated models to some example data. Here the idea is to show that we can fit multiple models in series to folding data. The models are slightly more complex than two-state folding (Pyfolding SI Notebook 1.) These models can be used with in bought software, but with PyFolding we can automate and is Free!If you are less script/computer orientated, you can simply change the data paths/variables, etc for your proteins and re-run the jupyter notebook ( "Kernal/Restart & Run all" from the menu above).In this notebook I will be using data from the paper below:```Mapping the Topography of a Protein Energy Landscape<NAME>., <NAME>., <NAME>., <NAME>., <NAME>., <NAME>., <NAME>. & <NAME> Am Chem Soc (2015) 127, 46: 14610-25```[http://pubs.acs.org/doi/10.1021/jacs.5b07370] Data FormatSee PyFolding SI Notebook 1 for how to set up your .csv files for import  Special Considerations1. If you wish to perform global analyses on folding data, the datasets of the same WT/mutant concerned must be in the same .csv2. Kinetics data should be entered as rate constants ( *k* ) and NOT as the `log` of the rate constant.3. There can be no "empty" cells in the x-axis variables in the .csv file for kinetics data.---Example .csv structure:urea   |k1	      |k2:-----: |:------: |:-------:8.59   |	1.72  |		8.77   |	1.96  |		9.00   |	2.41  |		0.54   |	5.44  |	23.60.79   |	5.94  |	21.21.02   |	6.56  |	21.6...    | ...      | ...---<jupyter_code># As in previous notebook, lets load pyfolding & pyplot into this ipython notebook 
#(pyplot allows us to plot more complex figures of our results):

%matplotlib inline
import pyfolding
from pyfolding import models

# let's use some other libraries also
import matplotlib.pyplot as plt
import numpy as np<jupyter_output><empty_output><jupyter_text>--- Now, we need to load some data to analyse.---<jupyter_code># loading the data - 
pth = "../examples/Gankyrin"
GankyrinChevron = pyfolding.read_kinetic_data(pth,"GankyrinWTChevron.csv")

# let's give this dataset a good name
GankyrinChevron.ID = 'Gankyrin WT'<jupyter_output><empty_output><jupyter_text>--- Let's plot the chevron phases:---<jupyter_code># easy plotting of the entire dataset ...
GankyrinChevron.plot()<jupyter_output><empty_output><jupyter_text>---Note that the measurements were performed at $25^\text{o}$C.  This is the default for pyFolding.  However lets set this to show you how.---<jupyter_code>pyfolding.set_temperature(25.0)<jupyter_output>Set temperature to 25.00°C
(NOTE: Careful, this sets the temperature for all subsequent calculations)<jupyter_text>--- OK, now we can try fitting the data to a series of protein folding models automatically Lets first list the models that are already in PyFolding. We can list the models in pyfolding:---<jupyter_code># Command imports pyfolding models
from pyfolding.models import *

# command lists models
list_models()

# After the model name:
#'Verified: True' - the model rigourously tested and it functions as expected.
#'Verified:False' - the model has not been rigourously tested.<jupyter_output><empty_output><jupyter_text>---If you want to see more remember you can print out the model for viewing and then print out the variables of the model as per the commands given in PyFolding SI Notebook 1.--- Now lets fit to multiple models---<jupyter_code># make a list of models to be used to fit in the square brackets
test_models = [models.TwoStateChevron, 
               models.ThreeStateChevron, 
               models.ThreeStateSequentialChevron,
               models.ThreeStateFastPhaseChevron,
               models.TwoStateChevronMovingTransition,
               models.ChevronPolynomialFit]

#now tell Pyfolding to fit your data to each model
for model in test_models:
    GankyrinChevron.fit_func = model   # selects the fit function & associates it with the data
    GankyrinChevron.fit()              # then fit it. 
    GankyrinChevron.plot()             # then plot them, can add (components=True) to plot component rate constants<jupyter_output>================================================================================
Fitting results
================================================================================
ID: Gankyrin WT
Model: TwoStateChevron
Optimiser: pyfolding.GlobalFit and scipy.optimize.curve_fit
Temperature: 25.00°C

(f) kf   42.82617 ± 7.83661    	 95% CI[  40.86319,   44.78916]
(f) mf    1.32179 ± 0.06202    	 95% CI[   1.30625,    1.33733]
(f) ku    0.00005 ± 0.00004    	 95% CI[   0.00004,    0.00006]
(f) mu    1.21849 ± 0.09285    	 95% CI[   1.19524,    1.24175]
--------------------------------------------------------------------------------
R^2: 0.89052
================================================================================<jupyter_text>--- We can also fit to multiple models and output the "prettier" graphics (as in PyFolding SI Notebook 1)---<jupyter_code># First load in the Equilm denaturation (as per PyFolding SI Notebook 1)
pth = "../examples/Gankyrin"
GankyrinEquilm = pyfolding.read_equilibrium_data(pth,"GankyrinEquilmDenaturationCurve.csv")

# 1st select the fit function and associates it with the data
GankyrinEquilm.fit_func = models.TwoStateEquilibriumSloping

# then fit it. 
# the brackets enable you to define starting values for the variables see notebook 1
GankyrinEquilm.fit(p0=[-37, 0.1, -15, 0.1, 3,4]) 

# and plot to check all it OK
GankyrinEquilm.plot()


# again make a list of models to be used to fit in the square brackets
test_models = [models.TwoStateChevron,
               models.ThreeStateChevron, 
               models.ThreeStateSequentialChevron,  
               models.ThreeStateFastPhaseChevron,
               models.TwoStateChevronMovingTransition,
               models.ChevronPolynomialFit]

#now tell Pyfolding to fit your data to each model
for model in test_models:
    GankyrinChevron.fit_func = model               # 1st select the fit function & associate it with the data
    GankyrinChevron.fit()                          # then fit it. 
    pyfolding.plot_figure(GankyrinEquilm, GankyrinChevron, display=True) # then plot them with output parameters<jupyter_output>================================================================================
Fitting results
================================================================================
ID: <NAME>
Model: TwoStateChevron
Optimiser: pyfolding.GlobalFit and scipy.optimize.curve_fit
Temperature: 25.00°C

(f) kf   42.82617 ± 7.83661    	 95% CI[  40.86319,   44.78916]
(f) mf    1.32179 ± 0.06202    	 95% CI[   1.30625,    1.33733]
(f) ku    0.00005 ± 0.00004    	 95% CI[   0.00004,    0.00006]
(f) mu    1.21849 ± 0.09285    	 95% CI[   1.19524,    1.24175]
--------------------------------------------------------------------------------
R^2: 0.89052
================================================================================
{'fraction_non_alphanumeric': 0.1739192263936291, 'fraction_numerical': 0.048777019340159274, 'mean_word_length': 3.3683229813664597, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '361287', 'license': 'MIT', 'n_tokens_mistral': 2386, 'n_tokens_neox': 2109, 'n_words': 753, 'path': 'notebooks/SI2_FoldingModels2.ipynb', 'repo_name': 'quantumjot/PyFolding-Notebooks', 'size': '7089'}