[5378e40] | 1 | #!/usr/bin/env python |
---|
| 2 | # -*- coding: utf-8 -*- |
---|
| 3 | |
---|
[87985ca] | 4 | import sys |
---|
[5378e40] | 5 | from bumps.names import * |
---|
[346bc88] | 6 | from sasmodels.core import load_model |
---|
[7cf2cfd] | 7 | from sasmodels.bumps_model import Model, Experiment |
---|
| 8 | from sasmodels.data import load_data, set_beam_stop, set_top |
---|
[d772f5d] | 9 | |
---|
| 10 | """ IMPORT THE DATA USED """ |
---|
[7cf2cfd] | 11 | radial_data = load_data('DEC07267.DAT') |
---|
| 12 | set_beam_stop(radial_data, 0.00669, outer=0.025) |
---|
| 13 | set_top(radial_data, -.0185) |
---|
[87985ca] | 14 | |
---|
[7cf2cfd] | 15 | tan_data = load_data('DEC07266.DAT') |
---|
| 16 | set_beam_stop(tan_data, 0.00669, outer=0.025) |
---|
| 17 | set_top(tan_data, -.0185) |
---|
[87985ca] | 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] |
---|
[5d3d7b4] | 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 |
---|
[f4b36fa] | 26 | theta = 89.9 if section != "tangential" else 0 |
---|
| 27 | phi = 90 |
---|
[346bc88] | 28 | kernel = load_model(name, dtype="single") |
---|
[abb22f4] | 29 | cutoff = 1e-3 |
---|
[87985ca] | 30 | |
---|
| 31 | if name == "ellipsoid": |
---|
[7cf2cfd] | 32 | model = Model(kernel, |
---|
[f4b36fa] | 33 | scale=0.08, background=35, |
---|
| 34 | radius_polar=15, radius_equatorial=800, |
---|
[1182da5] | 35 | sld=.291, sld_solvent=7.105, |
---|
[f4b36fa] | 36 | theta=theta, phi=phi, |
---|
| 37 | theta_pd=0, theta_pd_n=0, theta_pd_nsigma=3, |
---|
[346bc88] | 38 | phi_pd=0, phi_pd_n=20, phi_pd_nsigma=3, |
---|
[f4b36fa] | 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, |
---|
[346bc88] | 41 | ) |
---|
[8cdb9f1] | 42 | |
---|
| 43 | # SET THE FITTING PARAMETERS |
---|
[f4b36fa] | 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) |
---|
[346bc88] | 50 | model.background.range(0,1000) |
---|
[abb22f4] | 51 | model.scale.range(0, 10) |
---|
[8cdb9f1] | 52 | |
---|
| 53 | |
---|
[87985ca] | 54 | elif name == "lamellar": |
---|
[7cf2cfd] | 55 | model = Model(kernel, |
---|
[f4b36fa] | 56 | scale=0.08, background=0.003, |
---|
[346bc88] | 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 | |
---|
[8cdb9f1] | 62 | # SET THE FITTING PARAMETERS |
---|
[87985ca] | 63 | #model.thickness.range(0, 1000) |
---|
[8cdb9f1] | 64 | #model.scale.range(0, 1) |
---|
[87985ca] | 65 | #model.thickness_pd.range(0, 1000) |
---|
[8cdb9f1] | 66 | #model.background.range(0, 1000) |
---|
[87985ca] | 67 | model.sld.range(0, 1) |
---|
[8cdb9f1] | 68 | |
---|
| 69 | |
---|
[87985ca] | 70 | elif name == "cylinder": |
---|
[1726b21] | 71 | """ |
---|
| 72 | pars = dict(scale=0.0023, radius=92.5, length=798.3, |
---|
[87985ca] | 73 | sld=.29, solvent_sld=7.105, background=5, |
---|
[5d3d7b4] | 74 | theta=0, phi=phi, |
---|
[87985ca] | 75 | theta_pd=22.11, theta_pd_n=5, theta_pd_nsigma=3, |
---|
[1726b21] | 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, |
---|
[f4b36fa] | 78 | phi_pd=0, phi_pd_n=5 phi_pd_nsigma=3,) |
---|
[1726b21] | 79 | """ |
---|
| 80 | pars = dict( |
---|
[abb22f4] | 81 | scale=.01, background=35, |
---|
[1182da5] | 82 | sld=.291, sld_solvent=5.77, |
---|
[f4b36fa] | 83 | radius=250, length=178, |
---|
[abb22f4] | 84 | radius_pd=0.1, radius_pd_n=5, radius_pd_nsigma=3, |
---|
[1726b21] | 85 | length_pd=0.1,length_pd_n=5, length_pd_nsigma=3, |
---|
[f4b36fa] | 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) |
---|
[7cf2cfd] | 89 | model = Model(kernel, **pars) |
---|
[a42fec0] | 90 | |
---|
| 91 | # SET THE FITTING PARAMETERS |
---|
[1726b21] | 92 | model.radius.range(1, 500) |
---|
[4001d6e] | 93 | model.length.range(1, 5000) |
---|
[f4b36fa] | 94 | #model.theta.range(0, 90) |
---|
| 95 | model.phi.range(0, 180) |
---|
| 96 | model.phi_pd.range(0, 30) |
---|
[abb22f4] | 97 | model.radius_pd.range(0, 1) |
---|
[f4b36fa] | 98 | model.length_pd.range(0, 1) |
---|
[abb22f4] | 99 | model.scale.range(0, 10) |
---|
| 100 | model.background.range(0, 100) |
---|
[a42fec0] | 101 | |
---|
| 102 | |
---|
[87985ca] | 103 | elif name == "core_shell_cylinder": |
---|
[7cf2cfd] | 104 | model = Model(kernel, |
---|
[f4b36fa] | 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, |
---|
[346bc88] | 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, |
---|
[f4b36fa] | 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, |
---|
[346bc88] | 114 | ) |
---|
[a42fec0] | 115 | |
---|
| 116 | # SET THE FITTING PARAMETERS |
---|
[f4b36fa] | 117 | model.radius.range(115, 1000) |
---|
| 118 | model.length.range(0, 2500) |
---|
[a42fec0] | 119 | #model.thickness.range(18, 38) |
---|
| 120 | #model.thickness_pd.range(0, 1) |
---|
[87985ca] | 121 | #model.phi.range(0, 90) |
---|
[f4b36fa] | 122 | model.phi_pd.range(0,20) |
---|
[a42fec0] | 123 | #model.radius_pd.range(0, 1) |
---|
| 124 | #model.length_pd.range(0, 1) |
---|
[87985ca] | 125 | #model.theta_pd.range(0, 360) |
---|
[a42fec0] | 126 | #model.background.range(0,5) |
---|
| 127 | model.scale.range(0, 1) |
---|
[09e15be] | 128 | |
---|
[8faffcd] | 129 | |
---|
[ca6c007] | 130 | |
---|
[87985ca] | 131 | elif name == "capped_cylinder": |
---|
[7cf2cfd] | 132 | model = Model(kernel, |
---|
[f4b36fa] | 133 | scale=.08, background=35, |
---|
| 134 | radius=20, cap_radius=40, length=400, |
---|
[1182da5] | 135 | sld=1, sld_solvent=6.3, |
---|
[346bc88] | 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, |
---|
[f4b36fa] | 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, |
---|
[346bc88] | 142 | ) |
---|
[8cdb9f1] | 143 | |
---|
[f4b36fa] | 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) |
---|
[8cdb9f1] | 154 | model.scale.range(0, 1) |
---|
| 155 | |
---|
| 156 | |
---|
[87985ca] | 157 | elif name == "triaxial_ellipsoid": |
---|
[7cf2cfd] | 158 | model = Model(kernel, |
---|
[f4b36fa] | 159 | scale=0.08, background=35, |
---|
| 160 | radius_equat_minor=15, radius_equat_major=20, radius_polar=500, |
---|
[1182da5] | 161 | sld=7.105, solvent_sld=.291, |
---|
[f4b36fa] | 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, |
---|
[346bc88] | 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 | ) |
---|
[8cdb9f1] | 170 | |
---|
| 171 | # SET THE FITTING PARAMETERS |
---|
[f4b36fa] | 172 | model.radius_equat_minor.range(15, 1000) |
---|
| 173 | model.radius_equat_major.range(15, 1000) |
---|
| 174 | #model.radius_polar.range(15, 1000) |
---|
[8cdb9f1] | 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 | |
---|
[87985ca] | 180 | else: |
---|
[1ee5ac6] | 181 | print("No parameters for %s"%name) |
---|
[87985ca] | 182 | sys.exit(1) |
---|
[8cdb9f1] | 183 | |
---|
[abb22f4] | 184 | model.cutoff = cutoff |
---|
[7cf2cfd] | 185 | M = Experiment(data=data, model=model) |
---|
[5d3d7b4] | 186 | if section == "both": |
---|
[f4b36fa] | 187 | tan_model = Model(model.sasmodel, **model.parameters()) |
---|
[87985ca] | 188 | tan_model.phi = model.phi - 90 |
---|
[5d3d7b4] | 189 | tan_model.cutoff = cutoff |
---|
[7cf2cfd] | 190 | tan_M = Experiment(data=tan_data, model=tan_model) |
---|
[346bc88] | 191 | problem = FitProblem([M, tan_M]) |
---|
[87985ca] | 192 | else: |
---|
[346bc88] | 193 | problem = FitProblem(M) |
---|
[1ee5ac6] | 194 | |
---|
| 195 | if __name__ == "__main__": |
---|
| 196 | problem.plot() |
---|
| 197 | import pylab; pylab.show() |
---|