1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | |
---|
4 | import sys |
---|
5 | from bumps.names import * |
---|
6 | from sasmodels.core import load_model |
---|
7 | from sasmodels.bumps_model import Model, Experiment |
---|
8 | from sasmodels.data import load_data, set_beam_stop, set_top |
---|
9 | |
---|
10 | """ IMPORT THE DATA USED """ |
---|
11 | radial_data = load_data('DEC07267.DAT') |
---|
12 | set_beam_stop(radial_data, 0.00669, outer=0.025) |
---|
13 | set_top(radial_data, -.0185) |
---|
14 | |
---|
15 | tan_data = load_data('DEC07266.DAT') |
---|
16 | set_beam_stop(tan_data, 0.00669, outer=0.025) |
---|
17 | set_top(tan_data, -.0185) |
---|
18 | #sas.set_half(tan_data, 'right') |
---|
19 | |
---|
20 | name = "ellipsoid" if len(sys.argv) < 2 else sys.argv[1] |
---|
21 | section = "radial" if len(sys.argv) < 3 else sys.argv[2] |
---|
22 | if section not in ("radial","tangential","both"): |
---|
23 | raise ValueError("section %r should be 'radial', 'tangential' or 'both'" |
---|
24 | % section) |
---|
25 | data = radial_data if section != "tangential" else tan_data |
---|
26 | theta = 89.9 if section != "tangential" else 0 |
---|
27 | phi = 90 |
---|
28 | kernel = load_model(name, dtype="single") |
---|
29 | cutoff = 1e-3 |
---|
30 | |
---|
31 | if name == "ellipsoid": |
---|
32 | model = Model(kernel, |
---|
33 | scale=0.08, background=35, |
---|
34 | radius_polar=15, radius_equatorial=800, |
---|
35 | sld=.291, sld_solvent=7.105, |
---|
36 | theta=theta, phi=phi, |
---|
37 | theta_pd=0, theta_pd_n=0, theta_pd_nsigma=3, |
---|
38 | phi_pd=0, phi_pd_n=20, phi_pd_nsigma=3, |
---|
39 | radius_polar_pd=0.222296, radius_polar_pd_n=1, radius_polar_pd_nsigma=0, |
---|
40 | radius_equatorial_pd=.000128, radius_equatorial_pd_n=1, radius_equatorial_pd_nsigma=0, |
---|
41 | ) |
---|
42 | |
---|
43 | # SET THE FITTING PARAMETERS |
---|
44 | model.radius_polar.range(15, 1000) |
---|
45 | model.radius_equatorial.range(15, 1000) |
---|
46 | #model.theta.range(0, 90) |
---|
47 | #model.theta_pd.range(0,10) |
---|
48 | model.phi_pd.range(0,20) |
---|
49 | model.phi.range(0, 180) |
---|
50 | model.background.range(0,1000) |
---|
51 | model.scale.range(0, 10) |
---|
52 | |
---|
53 | |
---|
54 | elif name == "lamellar": |
---|
55 | model = Model(kernel, |
---|
56 | scale=0.08, background=0.003, |
---|
57 | thickness=19.2946, |
---|
58 | sld=5.38,sld_sol=7.105, |
---|
59 | thickness_pd= 0.37765, thickness_pd_n=10, thickness_pd_nsigma=3, |
---|
60 | ) |
---|
61 | |
---|
62 | # SET THE FITTING PARAMETERS |
---|
63 | #model.thickness.range(0, 1000) |
---|
64 | #model.scale.range(0, 1) |
---|
65 | #model.thickness_pd.range(0, 1000) |
---|
66 | #model.background.range(0, 1000) |
---|
67 | model.sld.range(0, 1) |
---|
68 | |
---|
69 | |
---|
70 | elif name == "cylinder": |
---|
71 | """ |
---|
72 | pars = dict(scale=0.0023, radius=92.5, length=798.3, |
---|
73 | sld=.29, solvent_sld=7.105, background=5, |
---|
74 | theta=0, phi=phi, |
---|
75 | theta_pd=22.11, theta_pd_n=5, theta_pd_nsigma=3, |
---|
76 | radius_pd=.0084, radius_pd_n=10, radius_pd_nsigma=3, |
---|
77 | length_pd=0.493, length_pd_n=10, length_pd_nsigma=3, |
---|
78 | phi_pd=0, phi_pd_n=5 phi_pd_nsigma=3,) |
---|
79 | """ |
---|
80 | pars = dict( |
---|
81 | scale=.01, background=35, |
---|
82 | sld=.291, sld_solvent=5.77, |
---|
83 | radius=250, length=178, |
---|
84 | radius_pd=0.1, radius_pd_n=5, radius_pd_nsigma=3, |
---|
85 | length_pd=0.1,length_pd_n=5, length_pd_nsigma=3, |
---|
86 | theta=theta, phi=phi, |
---|
87 | theta_pd=0, theta_pd_n=0, theta_pd_nsigma=3, |
---|
88 | phi_pd=10, phi_pd_n=20, phi_pd_nsigma=3) |
---|
89 | model = Model(kernel, **pars) |
---|
90 | |
---|
91 | # SET THE FITTING PARAMETERS |
---|
92 | model.radius.range(1, 500) |
---|
93 | model.length.range(1, 5000) |
---|
94 | #model.theta.range(0, 90) |
---|
95 | model.phi.range(0, 180) |
---|
96 | model.phi_pd.range(0, 30) |
---|
97 | model.radius_pd.range(0, 1) |
---|
98 | model.length_pd.range(0, 1) |
---|
99 | model.scale.range(0, 10) |
---|
100 | model.background.range(0, 100) |
---|
101 | |
---|
102 | |
---|
103 | elif name == "core_shell_cylinder": |
---|
104 | model = Model(kernel, |
---|
105 | scale= .031, background=0, |
---|
106 | radius=19.5, thickness=30, length=22, |
---|
107 | sld_core=7.105, sld_shell=.291, sld_solvent=7.105, |
---|
108 | radius_pd=0.26, radius_pd_n=10, radius_pd_nsigma=3, |
---|
109 | length_pd=0.26, length_pd_n=10, length_pd_nsigma=3, |
---|
110 | thickness_pd=1, thickness_pd_n=1, thickness_pd_nsigma=1, |
---|
111 | theta=theta, phi=phi, |
---|
112 | theta_pd=1, theta_pd_n=1, theta_pd_nsigma=3, |
---|
113 | phi_pd=0, phi_pd_n=20, phi_pd_nsigma=3, |
---|
114 | ) |
---|
115 | |
---|
116 | # SET THE FITTING PARAMETERS |
---|
117 | model.radius.range(115, 1000) |
---|
118 | model.length.range(0, 2500) |
---|
119 | #model.thickness.range(18, 38) |
---|
120 | #model.thickness_pd.range(0, 1) |
---|
121 | #model.phi.range(0, 90) |
---|
122 | model.phi_pd.range(0,20) |
---|
123 | #model.radius_pd.range(0, 1) |
---|
124 | #model.length_pd.range(0, 1) |
---|
125 | #model.theta_pd.range(0, 360) |
---|
126 | #model.background.range(0,5) |
---|
127 | model.scale.range(0, 1) |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | elif name == "capped_cylinder": |
---|
132 | model = Model(kernel, |
---|
133 | scale=.08, background=35, |
---|
134 | radius=20, cap_radius=40, length=400, |
---|
135 | sld=1, sld_solvent=6.3, |
---|
136 | radius_pd=.1, radius_pd_n=5, radius_pd_nsigma=3, |
---|
137 | cap_radius_pd=.1, cap_radius_pd_n=5, cap_radius_pd_nsigma=3, |
---|
138 | length_pd=.1, length_pd_n=1, length_pd_nsigma=0, |
---|
139 | theta=theta, phi=phi, |
---|
140 | theta_pd=0, theta_pd_n=1, theta_pd_nsigma=0, |
---|
141 | phi_pd=10, phi_pd_n=20, phi_pd_nsigma=0, |
---|
142 | ) |
---|
143 | |
---|
144 | model.radius.range(115, 1000) |
---|
145 | model.length.range(0, 2500) |
---|
146 | #model.thickness.range(18, 38) |
---|
147 | #model.thickness_pd.range(0, 1) |
---|
148 | #model.phi.range(0, 90) |
---|
149 | model.phi_pd.range(0,20) |
---|
150 | #model.radius_pd.range(0, 1) |
---|
151 | #model.length_pd.range(0, 1) |
---|
152 | #model.theta_pd.range(0, 360) |
---|
153 | #model.background.range(0,5) |
---|
154 | model.scale.range(0, 1) |
---|
155 | |
---|
156 | |
---|
157 | elif name == "triaxial_ellipsoid": |
---|
158 | model = Model(kernel, |
---|
159 | scale=0.08, background=35, |
---|
160 | radius_equat_minor=15, radius_equat_major=20, radius_polar=500, |
---|
161 | sld=7.105, solvent_sld=.291, |
---|
162 | radius_equat_minor_pd=.1, radius_equat_minor_pd_n=1, radius_equat_minor_pd_nsigma=0, |
---|
163 | radius_equat_major_pd=.1, radius_equat_major_pd_n=1, radius_equat_major_pd_nsigma=0, |
---|
164 | radius_polar_pd=.1, radius_polar_pd_n=1, radius_polar_pd_nsigma=0, |
---|
165 | theta=theta, phi=phi, psi=0, |
---|
166 | theta_pd=20, theta_pd_n=40, theta_pd_nsigma=3, |
---|
167 | phi_pd=.1, phi_pd_n=1, phi_pd_nsigma=0, |
---|
168 | psi_pd=30, psi_pd_n=1, psi_pd_nsigma=0, |
---|
169 | ) |
---|
170 | |
---|
171 | # SET THE FITTING PARAMETERS |
---|
172 | model.radius_equat_minor.range(15, 1000) |
---|
173 | model.radius_equat_major.range(15, 1000) |
---|
174 | #model.radius_polar.range(15, 1000) |
---|
175 | #model.background.range(0,1000) |
---|
176 | #model.theta_pd.range(0, 360) |
---|
177 | #model.phi_pd.range(0, 360) |
---|
178 | #model.psi_pd.range(0, 360) |
---|
179 | |
---|
180 | else: |
---|
181 | print("No parameters for %s"%name) |
---|
182 | sys.exit(1) |
---|
183 | |
---|
184 | model.cutoff = cutoff |
---|
185 | M = Experiment(data=data, model=model) |
---|
186 | if section == "both": |
---|
187 | tan_model = Model(model.sasmodel, **model.parameters()) |
---|
188 | tan_model.phi = model.phi - 90 |
---|
189 | tan_model.cutoff = cutoff |
---|
190 | tan_M = Experiment(data=tan_data, model=tan_model) |
---|
191 | problem = FitProblem([M, tan_M]) |
---|
192 | else: |
---|
193 | problem = FitProblem(M) |
---|
194 | |
---|
195 | if __name__ == "__main__": |
---|
196 | problem.plot() |
---|
197 | import pylab; pylab.show() |
---|