source: sasmodels/doc/guide/sesans/sesans_fitting.rst @ ff31782

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since ff31782 was 8ae8532, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

doc reorg

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[3330bb4]1.. currentmodule:: sasmodels
2.. Wim Bouwman, DUT, written at codecamp-V, Oct2016
3
4.. _sesans_fitting:
5
6Fitting SESANS Data
7===================
8
[8ae8532]9.. note::
10
11    A proper installation of the developers setup of SasView
12    (http://trac.sasview.org/wiki/AnacondaSetup) is a prerequisite for
13    using these instructions.
[3330bb4]14
15It is possible to fit SESANS measurements from the command line in Python.
16
17Simple Fits
18...........
[8ae8532]19In the folder sasmodels/example the file sesans_sphere_2micron.py gives
20an example of how to fit a shape to a measurement.
[3330bb4]21
22The command::
23
24  >python fit_sesans.py sesans_sphere_2micron.py
25
26then results in a GUI from which you can control the fit.
27
28.. image:: sesans_img/SphereLineFitSasView.png
29
[8ae8532]30All the parameters and names in sesans_sphere_2micron.py (shown below) can
31be adjusted to fit your own problem::
[3330bb4]32
33  """
34  This is a data file  used to load in sesans data and fit it using the bumps engine
35  """
36  from bumps.names import *
37
38  import sesansfit
39
40  # Enter the model name to use
41  model_name = "sphere"
42
43  # DO NOT MODIFY THIS LINE
44  model = sesansfit.get_bumps_model(model_name)
45
46  # Enter any custom parameters
47  # name = Parameter(initial_value, name='name')
48  phi = Parameter(0.0855, name='phi')
49  # Add the parameters to this list that should be displayed in the fitting window
50  custom_params = {"phi" : phi}
51
52  # SESANS data file name
53  sesans_file = "spheres2micron.ses"
54
55  # Initial parameter values (if other than defaults)
56  # "model_parameter_name" : value
57  initial_vals = {
58    "sld" : 1.41,
59    "radius" : 10000,
60    "sld_solvent" : 2.70,
61  }
62
63  # Ranges for parameters if other than default
64  # "model_parameter_name" : [min, max]
65  param_range = {
66    "phi" : [0.001, 0.5],
67    "radius" : [100, 100000]
68  }
69
70  # Constraints
71  # model.param_name = f(other params)
[8ae8532]72  # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius
73  # and scale are model functions and phi is a custom parameter
[3330bb4]74  model.scale = phi*(1-phi)
75
76  # Send to the fitting engine
77  # DO NOT MODIFY THIS LINE
78  problem = sesansfit.sesans_fit(sesans_file, model, initial_vals, custom_params, param_range)
79
80Incorporating a Structure Factor
81................................
[8ae8532]82An example of how to also include a structure factor can be seen in the
83following example taken from Washington et al., *Soft Matter*\, (2014), 10, 3016
84(dx.doi.org/10.1039/C3SM53027B). These are time-of-flight measurements, which
85is the reason that not the polarisation is plotted, but the
86:math:`\frac{log(P/P_0)}{\lambda^2}` . The sample is a dispersion of
87core-shell colloids at a high volume fraction with hard sphere interactions.
[3330bb4]88
89The fit can be started by::
90
91 >python fit_sesans.py sesans_parameters_css-hs.py
92
93This yields after the fitting:
94
95.. image:: sesans_img/HardSphereLineFitSasView.png
96
[8ae8532]97The code sesans_parameters_css-hs.py can then be used as a template for a
98fitting problem with a structure factor::
[3330bb4]99
100 """
101 This is a data file  used to load in sesans data and fit it using the bumps engine
102 """
103 from bumps.names import *
104
105 import sesansfit
106
107 # Enter the model name to use
108 model_name = "core_shell_sphere*hardsphere"
109
110 # DO NOT MODIFY THIS LINE
111 model = sesansfit.get_bumps_model(model_name)
112
113 # Enter any custom parameters
114 phi = Parameter(0.45, name='phi')
115 pen = Parameter(0.95, name='solvent penetration')
116 custom_params = {"phi" : phi, "pen" : pen}
117
118 # SESANS data file
119 sesans_file = "core_shell.ses"
120
121 # Initial parameter values (if other than defaults)
122 initial_vals = {
123    "sld_core" : 1.05,
124    "sld_shell" : 2.88*pen-0.05*(1-pen),
125    "sld_solvent" : 2.88,
126    "radius" : 730,
127    "thickness" : 20,
128    "volfraction" : phi,
129    "scale" : (1-phi)
130 }
131
132 # Ranges for parameters if other than default
133 param_range = {
134    "phi" : [0.2, 0.5],
135    "pen" : [0,1],
136    "radius" : [500, 3000],
137    "thickness" : [0,200]
138 }
139
140 # Constraints
141 # model.param_name = f(other params)
[8ae8532]142 # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius
143 # and scale are model functions and phi is a custom parameter
[3330bb4]144 model.scale = phi*(1-phi)
145 model.volfraction = phi
146 model.shell_sld = pen*2.88
147
148 # Send to the fitting engine
149 problem = sesansfit.sesans_fit(sesans_file, model_name, initial_vals, custom_params, param_range)
Note: See TracBrowser for help on using the repository browser.