File: sesans_fitting.rst

package info (click to toggle)
sasmodels 1.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,464 kB
  • sloc: python: 26,296; ansic: 8,051; makefile: 148; sh: 63
file content (150 lines) | stat: -rw-r--r-- 4,429 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
.. currentmodule:: sasmodels
.. Wim Bouwman, DUT, written at codecamp-V, Oct2016
.. Minor tweaks to accommodate updates in SasView, Steve King, Oct 2021

.. _sesans_fitting:

Fitting SESANS Data from the Command Line
=========================================

.. note::

    A proper installation of the developers setup of SasView
    (https://github.com/SasView/sasview/wiki/DevNotes_DevEnviroment) is a
    prerequisite for using these instructions. There is also separate help
    available on the :ref:`Scripting_Interface` .

Simple Fits
...........
In the folder sasmodels/example the file sesans_sphere_2micron.py gives
an example of how to fit a shape to a measurement.

The command::

  >python fit_sesans.py sesans_sphere_2micron.py

then results in a GUI from which you can control the fit.

.. image:: sesans_img/SphereLineFitSasView.png

All the parameters and names in sesans_sphere_2micron.py (shown below) can
be adjusted to fit your own problem::

  """
  This is a data file  used to load in sesans data and fit it using the bumps engine
  """
  from bumps.names import *

  import sesansfit

  # Enter the model name to use
  model_name = "sphere"

  # DO NOT MODIFY THIS LINE
  model = sesansfit.get_bumps_model(model_name)

  # Enter any custom parameters
  # name = Parameter(initial_value, name='name')
  phi = Parameter(0.0855, name='phi')
  # Add the parameters to this list that should be displayed in the fitting window
  custom_params = {"phi" : phi}

  # SESANS data file name
  sesans_file = "spheres2micron.ses"

  # Initial parameter values (if other than defaults)
  # "model_parameter_name" : value
  initial_vals = {
    "sld" : 1.41,
    "radius" : 10000,
    "sld_solvent" : 2.70,
  }

  # Ranges for parameters if other than default
  # "model_parameter_name" : [min, max]
  param_range = {
    "phi" : [0.001, 0.5],
    "radius" : [100, 100000]
  }

  # Constraints
  # model.param_name = f(other params)
  # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius
  # and scale are model functions and phi is a custom parameter
  model.scale = phi*(1-phi)

  # Send to the fitting engine
  # DO NOT MODIFY THIS LINE
  problem = sesansfit.sesans_fit(sesans_file, model, initial_vals, custom_params, param_range)

Incorporating a Structure Factor
................................
An example of how to also include a structure factor can be seen in the
following example taken from Washington et al., *Soft Matter*\, (2014), 10, 3016
(`DOI 10.1039/C3SM53027B <https://doi.org/10.1039/C3SM53027B>`_). These are
time-of-flight measurements, which is the reason that the polarisation is not
plotted, but the function :math:`\frac{log(P/P_0)}{\lambda^2}` . The sample is
a dispersion of core-shell colloids at a high volume fraction with hard sphere
interactions.

The fit can be started by::

 >python fit_sesans.py sesans_parameters_css-hs.py

This yields after the fitting:

.. image:: sesans_img/HardSphereLineFitSasView.png

The code sesans_parameters_css-hs.py can then be used as a template for a
fitting problem with a structure factor::

 """
 This is a data file  used to load in sesans data and fit it using the bumps engine
 """
 from bumps.names import *

 import sesansfit

 # Enter the model name to use
 model_name = "core_shell_sphere*hardsphere"

 # DO NOT MODIFY THIS LINE
 model = sesansfit.get_bumps_model(model_name)

 # Enter any custom parameters
 phi = Parameter(0.45, name='phi')
 pen = Parameter(0.95, name='solvent penetration')
 custom_params = {"phi" : phi, "pen" : pen}

 # SESANS data file
 sesans_file = "core_shell.ses"

 # Initial parameter values (if other than defaults)
 initial_vals = {
    "sld_core" : 1.05,
    "sld_shell" : 2.88*pen-0.05*(1-pen),
    "sld_solvent" : 2.88,
    "radius" : 730,
    "thickness" : 20,
    "volfraction" : phi,
    "scale" : (1-phi)
 }

 # Ranges for parameters if other than default
 param_range = {
    "phi" : [0.2, 0.5],
    "pen" : [0,1],
    "radius" : [500, 3000],
    "thickness" : [0,200]
 }

 # Constraints
 # model.param_name = f(other params)
 # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius
 # and scale are model functions and phi is a custom parameter
 model.scale = phi*(1-phi)
 model.volfraction = phi
 model.shell_sld = pen*2.88

 # Send to the fitting engine
 problem = sesansfit.sesans_fit(sesans_file, model_name, initial_vals, custom_params, param_range)