source: sasmodels/doc/ref/sesans/sesans_fitting.rst @ dedcf34

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since dedcf34 was 3330bb4, checked in by ajj, 8 years ago

Normalise line endings

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