Debian Codegraph @

docs/source/api/ex_analyze_profile.rst

raw
1 Analyzing a scattering profile
2 ********************************
3
4 .. _profile_analysis:
5
6 One of the most common tasks is analyzing a scattering profile. Here's
7 an example of how that might be done, from Guinier analysis through creating
8 a 3D reconstruction.
9
10 Guinier fit and MW
11 +++++++++++++++++++++
12
13 .. code-block:: python
14
15 import os
16 import shutil
17 import numpy as np
18 import bioxtasraw.RAWAPI as raw
19
20
21 #Load the settings
22 settings = raw.load_settings('./standards_data/SAXS.cfg')
23
24
25 #Load the profile of interest
26 profile_names = ['./reconstruction_data/glucose_isomerase.dat']
27 profiles = raw.load_profiles(profile_names)
28
29 gi_prof = profiles[0]
30
31
32 #Automatically calculate the Guinier range and fit
33 (rg, i0, rg_err, i0_err, qmin, qmax, qrg_min, qrg_max, idx_min, idx_max,
34 r_sq) = raw.auto_guinier(gi_prof, settings=settings)
35
36
37 #Calculate M.W. using 6 different methods
38 mw_ref = raw.mw_ref(gi_prof, 0.47, settings=settings)
39 mw_abs = raw.mw_abs(gi_prof, 0.47, settings=settings)
40 mw_vp, pvol_cor, pvol, vp_qmax = raw.mw_vp(gi_prof, settings=settings)
41 mw_vc, vcor, mw_err, vc_qmax = raw.mw_vc(gi_prof, settings=settings)
42 mw_bayes, mw_prob, ci_lower, ci_upper, ci_prob = raw.mw_bayes(gi_prof)
43 mw_datclass, shape, dmax_datclass = raw.mw_datclass(gi_prof)
44
45
46 Calculate IFTs
47 +++++++++++++++
48
49 .. code-block:: python
50
51 #Calculate the IFT using BIFT
52 (gi_bift, gi_bift_dmax, gi_bift_rg, gi_bift_i0, gi_bift_dmax_err,
53 gi_bift_rg_err, gi_bift_i0_err, gi_bift_chi_sq, gi_bift_log_alpha,
54 gi_bift_log_alpha_err, gi_bift_evidence,
55 gi_bift_evidence_err) = raw.bift(gi_prof, settings=settings, single_proc=True)
56
57
58 #Calculate the IFT using DATGNOM
59 (gi_datgnom_ift, gi_datgnom_dmax, gi_datgnom_rg, gi_datgnom_i0,
60 gi_datgnom_rg_err, gi_datgnom_i0_err, gi_datgnom_total_est,
61 gi_datgnom_chi_sq, gi_datgnom_alpha, gi_datgnom_quality) = raw.datgnom(gi_prof)
62
63
64 #Use the auto_dmax function to find the best Dmax and then calculate the IFT using GNOM
65 dmax = raw.auto_dmax(gi_prof)
66
67 (gi_gnom_ift, gi_gnom_dmax, gi_gnom_rg, gi_gnom_i0, gi_gnom_rg_err,
68 gi_gnom_i0_err, gi_gnom_total_est, gi_gnom_chi_sq, gi_gnom_alpha,
69 gi_gnom_quality) = raw.gnom(gi_prof, dmax)
70
71
72 Save the profile, IFTs, and analysis summary
73 ++++++++++++++++++++++++++++++++++++++++++++++
74
75 .. code-block:: python
76
77 #Save the profile, IFTs, and analysis summary
78 if not os.path.exists('./api_results'):
79 os.mkdir('./api_results')
80
81 raw.save_profile(gi_prof, 'gi.dat', './api_results')
82 raw.save_ift(gi_bift, 'gi.ift', './api_results')
83 raw.save_ift(gi_gnom_ift, 'gi.out', './api_results')
84
85 raw.save_report('gi_report.pdf', './api_results', [gi_prof],
86 [gi_gnom_ift, gi_bift])
87
88
89 Create a bead model reconstruction
90 +++++++++++++++++++++++++++++++++++
91
92 .. code-block:: python
93
94 #Calculate the ambiguity using AMBIMETER
95 a_score, a_cats, a_eval = raw.ambimeter(gi_gnom_ift)
96
97
98 #Create individual bead model reconstructions
99 if not os.path.exists('./api_results/gi_dammif'):
100 os.mkdir('./api_results/gi_dammif')
101 else:
102 files = os.listdir('./api_results/gi_dammif')
103 for f in files:
104 os.remove(os.path.join('./api_results/gi_dammif', f))
105
106 chi_sq_vals = []
107 rg_vals = []
108 dmax_vals = []
109 mw_vals = []
110 ev_vals = []
111
112 for i in range(3):
113 chi_sq, rg, dmax, mw, ev = raw.dammif(gi_gnom_ift,
114 'gi_{:02d}'.format(i+1), './api_results/gi_dammif', mode='Fast')
115
116 chi_sq_vals.append(chi_sq)
117 rg_vals.append(rg)
118 dmax_vals.append(dmax)
119 mw_vals.append(mw)
120 ev_vals.append(ev)
121
122
123 #Average the bead model reconstructions
124 damaver_files = ['gi_{:02d}-1.cif'.format(i+1) for i in range(3)]
125
126 (mean_nsd, stdev_nsd, rep_model, result_dict, res, res_err,
127 res_unit, cluster_list) = raw.damaver(damaver_files, 'gi',
128 './api_results/gi_dammif')
129
130 #Refine the bead model
131 chi_sq, rg, dmax, mw, ev = raw.dammin(gi_gnom_ift, 'refine_gi',
132 './api_results/gi_dammif', 'Fast',
133 initial_dam='gi-global-damstart.cif')
134
135
136 #Align the refined bead model with a high resolution structure
137 shutil.copy('./reconstruction_data/gi_complete/1XIB_4mer.pdb',
138 './api_results/gi_dammif')
139
140 raw.cifsup('refine_gi-1.cif', '1XIB_4mer.pdb', './api_results/gi_dammif')
141
142
143 Create an electron density reconstruction
144 +++++++++++++++++++++++++++++++++++++++++++
145
146 .. code-block:: python
147
148 #Create individual electron density reconstructions
149 if not os.path.exists('./api_results/gi_denss'):
150 os.mkdir('./api_results/gi_denss')
151 else:
152 files = os.listdir('./api_results/gi_denss')
153 for f in files:
154 os.remove(os.path.join('./api_results/gi_denss', f))
155
156 rhos = []
157 chi_vals = []
158 rg_vals = []
159 support_vol_vals = []
160 sides = []
161 fit_data = []
162
163 for i in range(5):
164 (rho, chi_sq, rg, support_vol, side, q_fit, I_fit, I_extrap,
165 err_extrap, all_chi_sq, all_rg, all_support_vol) = raw.denss(gi_gnom_ift,
166 'gi_{:02d}'.format(i+1), './api_results/gi_denss', mode='Fast')
167
168 rhos.append(rho)
169 chi_vals.append(chi_sq)
170 rg_vals.append(rg)
171 support_vol_vals.append(support_vol)
172 sides.append(side)
173 fit_data.append([q_fit, I_fit, I_extrap, err_extrap])
174
175
176 #Average the electron reconstructions
177 (average_rho, mean_cor, std_cor, threshold, res, scores,
178 fsc) = raw.denss_average(np.array(rhos), side, 'gi_average',
179 './api_results/gi_denss')
180
181
182 #Refine the electron density
183 (refined_rho, refined_chi_sq, refined_rg, refined_support_vol, refined_side,
184 refined_q_fit, refined_I_fit, refined_I_extrap,
185 refined_err_extrap, all_chi_sq, all_rg,
186 all_support_vol) = raw.denss(gi_gnom_ift, 'gi_refine',
187 './api_results/gi_denss', mode='Fast',
188 initial_model=average_rho)
189
190
191 #Align the electron density with a high resolution structure
192 shutil.copy('./reconstruction_data/gi_complete/1XIB_4mer.pdb',
193 './api_results/gi_denss')
194
195 aligned_density, score = raw.denss_align(refined_rho, refined_side,
196 '1XIB_4mer.pdb', './api_results/gi_denss',
197 'gi_refined_aligned', './api_results/gi_denss')