Skip to content

Commit a46afaf

Browse files
committed
add peptide plotting example
1 parent 40ff584 commit a46afaf

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

templates/05_SecB_fit_dG.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
# %%
44
from pathlib import Path
55

6+
import numpy as np
7+
import proplot as pplt
8+
import yaml
9+
610
from pyhdx.datasets import HDXDataSet
7-
from pyhdx.models import HDXMeasurement
8-
from pyhdx.fitting import fit_gibbs_global, fit_rates_weighted_average
911
from pyhdx.fileIO import csv_to_dataframe, save_fitresult
12+
from pyhdx.fitting import fit_gibbs_global, fit_rates_weighted_average
1013
from pyhdx.local_cluster import default_client
11-
import yaml
14+
from pyhdx.models import HDXMeasurement
1215

1316
# %%
1417

1518
guess = False # Set to True to redo initial guesses
16-
fit_kwargs = {"epochs": 10000, "lr": 1e4, "stop_loss": 1e-6}
19+
fit_kwargs = {"epochs": 200000, "lr": 1e4, "stop_loss": 1e-6}
1720

1821
# %%
1922
current_dir = Path(__file__).parent
@@ -55,3 +58,36 @@
5558
fr_torch.to_file(output_dir / "SecB_fit_result.csv", fmt="csv")
5659

5760
save_fitresult(output_dir / "SecB_fit", fr_torch)
61+
62+
# %%
63+
# evaluate the fit, plot measured and fitted D-uptake for a few peptides
64+
NUM_EVAL_POINTS = 100
65+
all_timepoints = np.concatenate([hdxm.timepoints for hdxm in fr_torch.hdxm_set])
66+
67+
elem = all_timepoints[np.nonzero(all_timepoints)]
68+
start = np.log10(elem.min())
69+
end = np.log10(elem.max())
70+
pad = (end - start) * 0.1
71+
time = np.logspace(start - pad, end + pad, num=NUM_EVAL_POINTS, endpoint=True)
72+
73+
74+
# %%
75+
# evaluate the fitted model at timepoints
76+
d_calc = fr_torch(time) # Ns x Np x Nt
77+
d_calc
78+
# %%
79+
# choose which sample to plot
80+
# here we plot the first one (= SecB tetramer)
81+
sample_idx = 0
82+
hdxm = fr_torch.hdxm_set.hdxm_list[sample_idx]
83+
d_calc_s = d_calc[sample_idx]
84+
85+
# %%
86+
# make a subplot grid to plot the first 24 peptides
87+
fig, axes = pplt.subplots(ncols=4, nrows=6)
88+
for i, ax in enumerate(axes):
89+
ax.plot(time, d_calc_s[i], color="r")
90+
ax.scatter(hdxm.timepoints, hdxm.d_exp.iloc[i], color="k")
91+
92+
axes.format(xscale="log", xlabel="Time (s)", ylabel="Corrected D-uptake", ylim=(0, None))
93+
# %%

0 commit comments

Comments
 (0)