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 | phi = 0 if section != "tangential" else 90 |
---|
27 | kernel = load_model(name, dtype="single") |
---|
28 | cutoff = 1e-3 |
---|
29 | |
---|
30 | if name == "ellipsoid": |
---|
31 | model = Model(kernel, |
---|
32 | scale=0.08, |
---|
33 | rpolar=15, requatorial=800, |
---|
34 | sld=.291, solvent_sld=7.105, |
---|
35 | background=0, |
---|
36 | theta=90, phi=phi, |
---|
37 | theta_pd=15, theta_pd_n=40, theta_pd_nsigma=3, |
---|
38 | rpolar_pd=0.222296, rpolar_pd_n=1, rpolar_pd_nsigma=0, |
---|
39 | requatorial_pd=.000128, requatorial_pd_n=1, requatorial_pd_nsigma=0, |
---|
40 | phi_pd=0, phi_pd_n=20, phi_pd_nsigma=3, |
---|
41 | ) |
---|
42 | |
---|
43 | |
---|
44 | # SET THE FITTING PARAMETERS |
---|
45 | model.rpolar.range(15, 1000) |
---|
46 | model.requatorial.range(15, 1000) |
---|
47 | model.theta_pd.range(0, 360) |
---|
48 | model.background.range(0,1000) |
---|
49 | model.scale.range(0, 10) |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | elif name == "lamellar": |
---|
54 | model = Model(kernel, |
---|
55 | scale=0.08, |
---|
56 | thickness=19.2946, |
---|
57 | sld=5.38,sld_sol=7.105, |
---|
58 | background=0.003, |
---|
59 | thickness_pd= 0.37765, thickness_pd_n=10, thickness_pd_nsigma=3, |
---|
60 | ) |
---|
61 | |
---|
62 | |
---|
63 | # SET THE FITTING PARAMETERS |
---|
64 | #model.thickness.range(0, 1000) |
---|
65 | #model.scale.range(0, 1) |
---|
66 | #model.thickness_pd.range(0, 1000) |
---|
67 | #model.background.range(0, 1000) |
---|
68 | model.sld.range(0, 1) |
---|
69 | |
---|
70 | |
---|
71 | elif name == "cylinder": |
---|
72 | """ |
---|
73 | pars = dict(scale=0.0023, radius=92.5, length=798.3, |
---|
74 | sld=.29, solvent_sld=7.105, background=5, |
---|
75 | theta=0, phi=phi, |
---|
76 | theta_pd=22.11, theta_pd_n=5, theta_pd_nsigma=3, |
---|
77 | radius_pd=.0084, radius_pd_n=10, radius_pd_nsigma=3, |
---|
78 | length_pd=0.493, length_pd_n=10, length_pd_nsigma=3, |
---|
79 | phi_pd=0, phi_pd_n=5, phi_pd_nsigma=3,) |
---|
80 | """ |
---|
81 | pars = dict( |
---|
82 | scale=.01, background=35, |
---|
83 | sld=.291, solvent_sld=5.77, |
---|
84 | radius=250, length=178, |
---|
85 | theta=90, phi=phi, |
---|
86 | radius_pd=0.1, radius_pd_n=5, radius_pd_nsigma=3, |
---|
87 | length_pd=0.1,length_pd_n=5, length_pd_nsigma=3, |
---|
88 | theta_pd=10, theta_pd_n=50, theta_pd_nsigma=3, |
---|
89 | phi_pd=0, phi_pd_n=10, phi_pd_nsigma=3) |
---|
90 | model = Model(kernel, **pars) |
---|
91 | |
---|
92 | # SET THE FITTING PARAMETERS |
---|
93 | model.radius.range(1, 500) |
---|
94 | model.length.range(1, 5000) |
---|
95 | model.theta.range(-90,100) |
---|
96 | model.theta_pd.range(0, 30) |
---|
97 | model.theta_pd_n = model.theta_pd + 5 |
---|
98 | model.radius_pd.range(0, 1) |
---|
99 | model.length_pd.range(0, 2) |
---|
100 | model.scale.range(0, 10) |
---|
101 | model.background.range(0, 100) |
---|
102 | |
---|
103 | |
---|
104 | elif name == "core_shell_cylinder": |
---|
105 | model = Model(kernel, |
---|
106 | scale= .031, radius=19.5, thickness=30, length=22, |
---|
107 | core_sld=7.105, shell_sld=.291, solvent_sld=7.105, |
---|
108 | background=0, theta=0, phi=phi, |
---|
109 | |
---|
110 | radius_pd=0.26, radius_pd_n=10, radius_pd_nsigma=3, |
---|
111 | length_pd=0.26, length_pd_n=10, length_pd_nsigma=3, |
---|
112 | thickness_pd=1, thickness_pd_n=1, thickness_pd_nsigma=1, |
---|
113 | theta_pd=1, theta_pd_n=10, theta_pd_nsigma=3, |
---|
114 | phi_pd=0.1, phi_pd_n=1, phi_pd_nsigma=1, |
---|
115 | ) |
---|
116 | |
---|
117 | # SET THE FITTING PARAMETERS |
---|
118 | #model.radius.range(115, 1000) |
---|
119 | #model.length.range(0, 2500) |
---|
120 | #model.thickness.range(18, 38) |
---|
121 | #model.thickness_pd.range(0, 1) |
---|
122 | #model.phi.range(0, 90) |
---|
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, radius=20, cap_radius=40, length=400, |
---|
134 | sld_capcyl=1, sld_solv=6.3, |
---|
135 | background=0, theta=0, phi=phi, |
---|
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_pd=.1, theta_pd_n=1, theta_pd_nsigma=0, |
---|
140 | phi_pd=.1, phi_pd_n=1, phi_pd_nsigma=0, |
---|
141 | ) |
---|
142 | |
---|
143 | model.scale.range(0, 1) |
---|
144 | |
---|
145 | |
---|
146 | elif name == "triaxial_ellipsoid": |
---|
147 | model = Model(kernel, |
---|
148 | scale=0.08, req_minor=15, req_major=20, rpolar=500, |
---|
149 | sldEll=7.105, solvent_sld=.291, |
---|
150 | background=5, theta=0, phi=phi, psi=0, |
---|
151 | theta_pd=20, theta_pd_n=40, theta_pd_nsigma=3, |
---|
152 | phi_pd=.1, phi_pd_n=1, phi_pd_nsigma=0, |
---|
153 | psi_pd=30, psi_pd_n=1, psi_pd_nsigma=0, |
---|
154 | req_minor_pd=.1, req_minor_pd_n=1, req_minor_pd_nsigma=0, |
---|
155 | req_major_pd=.1, req_major_pd_n=1, req_major_pd_nsigma=0, |
---|
156 | rpolar_pd=.1, rpolar_pd_n=1, rpolar_pd_nsigma=0, |
---|
157 | ) |
---|
158 | |
---|
159 | # SET THE FITTING PARAMETERS |
---|
160 | model.req_minor.range(15, 1000) |
---|
161 | model.req_major.range(15, 1000) |
---|
162 | #model.rpolar.range(15, 1000) |
---|
163 | #model.background.range(0,1000) |
---|
164 | #model.theta_pd.range(0, 360) |
---|
165 | #model.phi_pd.range(0, 360) |
---|
166 | #model.psi_pd.range(0, 360) |
---|
167 | |
---|
168 | else: |
---|
169 | print "No parameters for %s"%name |
---|
170 | sys.exit(1) |
---|
171 | |
---|
172 | model.cutoff = cutoff |
---|
173 | M = Experiment(data=data, model=model) |
---|
174 | if section == "both": |
---|
175 | tan_model = Model(model.kernel, **model.parameters()) |
---|
176 | tan_model.phi = model.phi - 90 |
---|
177 | tan_model.cutoff = cutoff |
---|
178 | tan_M = Experiment(data=tan_data, model=tan_model) |
---|
179 | problem = FitProblem([M, tan_M]) |
---|
180 | else: |
---|
181 | problem = FitProblem(M) |
---|