Changeset 745b7bb in sasmodels
- Timestamp:
- Aug 4, 2016 11:32:17 PM (8 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 4e0968b
- Parents:
- 54bcd4a
- Files:
-
- 1 added
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/genmodel.py
ra5b8477 r745b7bb 6 6 sys.path.insert(0, os.path.abspath('..')) 7 7 from sasmodels import generate, core 8 from sasmodels.direct_model import DirectModel 8 from sasmodels.direct_model import DirectModel, call_profile 9 9 from sasmodels.data import empty_data1D, empty_data2D 10 10 … … 17 17 from sasmodels.kernel import KernelModel 18 18 from sasmodels.modelinfo import ModelInfo 19 19 20 20 21 def plot_1d(model, opts, ax): … … 55 56 ax.set_xlabel(r'$Q_x \/(\AA^{-1})$') 56 57 ax.set_ylabel(r'$Q_y \/(\AA^{-1})$') 58 59 def plot_profile_inset(model_info, ax): 60 p = ax.get_position() 61 width, height = 0.4*(p.x1-p.x0), 0.4*(p.y1-p.y0) 62 left, bottom = p.x1-width, p.y1-height 63 inset = plt.gcf().add_axes([left, bottom, width, height]) 64 x, y, labels = call_profile(model_info) 65 inset.plot(x, y, '-') 66 inset.locator_params(nbins=4) 67 #inset.set_xlabel(labels[0]) 68 #inset.set_ylabel(labels[1]) 69 inset.text(0.99, 0.99, "profile", 70 horizontalalignment="right", 71 verticalalignment="top", 72 transform=inset.transAxes) 57 73 58 74 def figfile(model_info): … … 100 116 ax1d = fig.add_axes([ax_left, ax_bottom, ax_width, ax_height]) 101 117 plot_1d(model, opts, ax1d) 118 119 if model_info.profile: 120 plot_profile_inset(model_info, ax1d) 102 121 103 122 # Save image in model/img -
sasmodels/direct_model.py
r9eb3632 r745b7bb 73 73 #print("values:", values) 74 74 return calculator(call_details, values, cutoff, is_magnetic) 75 75 76 76 77 def get_weights(parameter, values): … … 95 96 disperser, npts, width, nsigma, value, limits, relative) 96 97 return value, weight / np.sum(weight) 98 99 100 def call_profile(model_info, **pars): 101 args = {} 102 for p in model_info.parameters.kernel_parameters: 103 if p.length > 1: 104 value = np.array([pars.get(p.id+str(j), p.default) 105 for j in range(1, p.length+1)]) 106 else: 107 value = pars.get(p.id, p.default) 108 args[p.id] = value 109 x, y = model_info.profile(**args) 110 return x, y, model_info.profile_axes 111 97 112 98 113 class DataMixin(object): … … 290 305 self._set_data(Iq, noise=noise) 291 306 307 def profile(self, **pars): 308 # type: (**float) -> None 309 """ 310 Generate a plottable profile. 311 """ 312 return call_profile(self.model.info, **pars) 313 292 314 def main(): 293 315 # type: () -> None -
sasmodels/models/spherical_sld.py
r54bcd4a r745b7bb 1 1 r""" 2 This model calculates an empirical functional form for SAS data using 3 SpericalSLD profile 4 5 Similarly to the OnionExpShellModel, this model provides the form factor, 6 P(q), for a multi-shell sphere, where the interface between the each neighboring 7 shells can be described by one of a number of functions including error, 8 power-law, and exponential functions. 9 This model is to calculate the scattering intensity by building a continuous 10 custom SLD profile against the radius of the particle. 11 The SLD profile is composed of a flat core, a flat solvent, a number (up to 9 ) 12 flat shells, and the interfacial layers between the adjacent flat shells 13 (or core, and solvent) (see below). 14 15 .. figure:: img/spherical_sld_profile.gif 16 17 Exemplary SLD profile 2 Similarly to the onion, this model provides the form factor, $P(q)$, for 3 a multi-shell sphere, where the interface between the each neighboring 4 shells can be described by the error function, power-law, or exponential 5 functions. The scattering intensity is computed by building a continuous 6 custom SLD profile along the radius of the particle. The SLD profile is 7 composed of a number of uniform shells with interfacial shells between them. 8 9 .. figure:: img/spherical_sld_profile.png 10 11 Example SLD profile 18 12 19 13 Unlike the <onion> model (using an analytical integration), the interfacial 20 layers here are sub-divided and numerically integrated assuming each of the 21 sub-layers are described by a line function. 22 The number of the sub-layer can be given by users by setting the integer values 23 of npts_inter. The form factor is normalized by the total volume of the sphere. 14 shells here are sub-divided and numerically integrated assuming each 15 sub-shell is described by a line function, with *n_steps* sub-shells per 16 interface. The form factor is normalized by the total volume of the sphere. 24 17 25 18 Definition … … 42 35 43 36 44 so that individual terms can be calcu alted as follows:37 so that individual terms can be calculated as follows: 45 38 46 39 .. math:: … … 72 65 73 66 74 Here we assumed that the SLDs of the core and solvent are constant against$r$.67 Here we assumed that the SLDs of the core and solvent are constant in $r$. 75 68 The SLD at the interface between shells, $\rho_{\text {inter}_i}$ 76 69 is calculated with a function chosen by an user, where the functions are … … 107 100 The functions are normalized so that they vary between 0 and 1, and they are 108 101 constrained such that the SLD is continuous at the boundaries of the interface 109 as well as each sub- layers. Thus B and C are determined.110 111 Once $\rho_{\text{inter}_i}$ is found at the boundary of the sub- layerof the102 as well as each sub-shell. Thus B and C are determined. 103 104 Once $\rho_{\text{inter}_i}$ is found at the boundary of the sub-shell of the 112 105 interface, we can find its contribution to the form factor $P(q)$ 113 106 … … 121 114 4 \pi \sum_{j=0}^{npts_{\text{inter}_i} -1 } \Big[ 122 115 3 ( \rho_{ \text{inter}_i } ( r_{j+1} ) - \rho_{ \text{inter}_i } 123 ( r_{j} ) V ( r_{ \text{sub layer}_j } )116 ( r_{j} ) V ( r_{ \text{subshell}_j } ) 124 117 \Big[ \frac {r_j^2 \beta_\text{out}^2 \sin(\beta_\text{out}) 125 118 - (\beta_\text{out}^2-2) \cos(\beta_\text{out}) } … … 127 120 128 121 - 3 ( \rho_{ \text{inter}_i } ( r_{j+1} ) - \rho_{ \text{inter}_i } 129 ( r_{j} ) V ( r_{ \text{sub layer}_j-1 } )122 ( r_{j} ) V ( r_{ \text{subshell}_j-1 } ) 130 123 \Big[ \frac {r_{j-1}^2 \sin(\beta_\text{in}) 131 124 - (\beta_\text{in}^2-2) \cos(\beta_\text{in}) } … … 152 145 153 146 154 We assume the $\rho_{\text{inter}_i} (r)$ can beapproximately linear155 within a sub-layer $j$156 157 Finally form factor can be calculated by147 We assume $\rho_{\text{inter}_j} (r)$ is approximately linear 148 within the sub-shell $j$. 149 150 Finally the form factor can be calculated by 158 151 159 152 .. math:: … … 169 162 q = \sqrt{q_x^2 + q_y^2} 170 163 171 172 .. figure:: img/spherical_sld_1d.jpg173 174 1D plot using the default values (w/400 data point).175 176 .. figure:: img/spherical_sld_default_profile.jpg177 178 SLD profile from the default values.179 180 164 .. note:: 165 181 166 The outer most radius is used as the effective radius for S(Q) 182 167 when $P(Q) * S(Q)$ is applied. … … 206 191 # pylint: disable=bad-whitespace, line-too-long 207 192 # ["name", "units", default, [lower, upper], "type", "description"], 208 parameters = [["n_shells", "", 1, [1, 1 1], "volume", "number of shells"],193 parameters = [["n_shells", "", 1, [1, 10], "volume", "number of shells"], 209 194 ["sld_solvent", "1e-6/Ang^2", 1.0, [-inf, inf], "sld", "solvent sld"], 210 195 ["sld[n_shells]", "1e-6/Ang^2", 4.06, [-inf, inf], "sld", "sld of the shell"], … … 258 243 rho.append(sld_solvent) 259 244 # return sld profile (r, beta) 260 return np.asarray(z), np.asarray(rho) *1e-6245 return np.asarray(z), np.asarray(rho) 261 246 262 247 -
sasmodels/sasview_model.py
r4edec6f r745b7bb 323 323 beta is a list of the corresponding SLD values 324 324 """ 325 args = [] # type: List[Union[float, np.ndarray]]325 args = {} # type: Dict[str, Any] 326 326 for p in self._model_info.parameters.kernel_parameters: 327 327 if p.id == self.multiplicity_info.control: 328 args.append(float(self.multiplicity))328 value = float(self.multiplicity) 329 329 elif p.length == 1: 330 args.append(self.params.get(p.id, np.NaN))330 value = self.params.get(p.id, np.NaN) 331 331 else: 332 args.append([self.params.get(p.id+str(k), np.NaN) 333 for k in range(1,p.length+1)]) 334 return self._model_info.profile(*args) 332 value = np.array([self.params.get(p.id+str(k), np.NaN) 333 for k in range(1,p.length+1)] 334 args[p.id] = value 335 336 return self._model_info.profile(**args) 335 337 336 338 def setParam(self, name, value):
Note: See TracChangeset
for help on using the changeset viewer.