Changeset 7904790 in sasmodels
- Timestamp:
- Mar 18, 2016 10:40:15 AM (9 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:
- 3b12dea
- Parents:
- a5af4e1 (diff), 52a3db3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 4 added
- 20 edited
- 7 moved
Legend:
- Unmodified
- Added
- Removed
-
doc/genmodel.py
rc094758 r044a9c1 2 2 import numpy as np 3 3 import matplotlib.pyplot as plt 4 import pylab 4 5 sys.path.insert(0, os.path.abspath('..')) 5 6 from sasmodels import generate, core … … 28 29 'q_max' : 1.0, 29 30 'nq' : 1000, 30 'nq2d' : 400,31 'nq2d' : 100, 31 32 'vmin' : 1e-3, # floor for the 2D data results 32 33 'qx_max' : 0.5, … … 59 60 if opts['zscale'] == 'log': 60 61 Iq2D = np.log(np.clip(Iq2D, opts['vmin'], np.inf)) 61 h = ax.imshow(Iq2D, interpolation='nearest', aspect=1, origin='upper', 62 extent=[-qx_max, qx_max, -qx_max, qx_max], cmap=ice_cm()) 63 # , vmin=vmin, vmax=vmax) 62 ax.imshow(Iq2D, interpolation='nearest', aspect=1, origin='lower', 63 extent=[-qx_max, qx_max, -qx_max, qx_max], cmap=pylab.cm.jet) 64 64 ax.set_xlabel(r'$Q_x \/(\AA^{-1})$') 65 65 ax.set_ylabel(r'$Q_y \/(\AA^{-1})$') 66 67 # im = self.subplot.imshow(output, interpolation='nearest', 68 # origin='lower', 69 # vmin=zmin_temp, vmax=self.zmax_2D, 70 # cmap=self.cmap, 71 # extent=(self.xmin_2D, self.xmax_2D, 72 # self.ymin_2D, self.ymax_2D)) 66 73 67 74 def ice_cm(): … … 77 84 78 85 79 # Generate image (comment IF for 1D/2D for the moment) and generate only 1D86 # Generate image 80 87 fig_height = 3.0 # in 81 88 fig_left = 0.6 # in … … 97 104 plot_2d(model, opts, ax2d) 98 105 ax1d = fig.add_axes([ax_left, ax_bottom, ax_width, ax_height]) 106 plot_1d(model, opts, ax1d) 99 107 #ax.set_aspect('square') 100 108 else: … … 109 117 fig = plt.figure(figsize=aspect) 110 118 ax1d = fig.add_axes([ax_left, ax_bottom, ax_width, ax_height]) 111 plot_1d(model, opts, ax1d)119 plot_1d(model, opts, ax1d) 112 120 113 121 # Save image in model/img … … 121 129 captionstr += '.. figure:: img/' + model_info['id'] + '_autogenfig.png\n' 122 130 captionstr += '\n' 123 captionstr += ' 1D plot corresponding to the default parameters of the model.\n' 131 if model_info['has_2d']: 132 captionstr += ' 1D and 2D plots corresponding to the default parameters of the model.\n' 133 else: 134 captionstr += ' 1D plot corresponding to the default parameters of the model.\n' 124 135 captionstr += '\n' 125 136 -
example/sesansfit.py
r84db7a5 r170ea69 1 1 from bumps.names import * 2 2 from sasmodels import core, bumps_model, sesans 3 from sas.sascalc.dataloader.loader import Loader 3 4 4 5 HAS_CONVERTER = True … … 8 9 HAS_CONVERTER = False 9 10 11 10 12 def get_bumps_model(model_name): 11 13 kernel = core.load_model(model_name) … … 13 15 return model 14 16 15 def sesans_fit(file, model, initial_vals={}, custom_params={}, param_range=[] ):17 def sesans_fit(file, model, initial_vals={}, custom_params={}, param_range=[], acceptance_angle=None): 16 18 """ 19 17 20 @param file: SESANS file location 18 21 @param model: Bumps model object or model name - can be model, model_1 * model_2, and/or model_1 + model_2 … … 24 27 """ 25 28 try: 26 from sas.sascalc.dataloader.loader import Loader27 29 loader = Loader() 28 30 data = loader.load(file) … … 55 57 dy = err_data 56 58 sample = Sample() 59 needs_all_q = acceptance_angle is not None 57 60 data = SESANSData1D() 61 data.acceptance_angle = acceptance_angle 58 62 63 data.needs_all_q = acceptance_angle is not None 59 64 if "radius" in initial_vals: 60 65 radius = initial_vals.get("radius") -
example/sesansfit.sh
rbdb653c r170ea69 1 1 #!/bin/bash 2 2 3 SASVIEW=$PWD/../../sasview/src 4 PYTHONPATH=$PWD/../:$PWD/../../bumps:$PWD/../../periodictable:$SASVIEW 3 # Need to fix the paths to sasmodels and sasview if no eggs present 4 echo $PWD 5 ONEUP="$(dirname "$PWD")" 6 PROJECTS="$(dirname "$ONEUP")" 7 CCOLON="C:/" 8 CSLASH="/c/" 9 SASMODELSBASE=$PROJECTS/sasmodels/ 10 SASMODELS="${SASMODELSBASE/$CSLASH/$CCOLON}" 11 SASVIEWBASE=$PROJECTS/sasview/src/ 12 SASVIEW="${SASVIEWBASE/$CSLASH/$CCOLON}" 13 PYTHONPATH="$SASVIEW;$SASMODELS" 5 14 export PYOPENCL_CTX PYTHONPATH 6 15 -
sasmodels/convert.py
r78d3341 r74f7238 15 15 'be_polyelectrolyte', 16 16 'correlation_length', 17 'fractal_core_shell' 17 'fractal_core_shell', 18 18 'binary_hard_sphere', 19 19 ] -
sasmodels/core.py
r7b3e62c rd5ba841 170 170 """ 171 171 value, weight = zip(*pars) 172 if len(value) > 1: 173 value = [v.flatten() for v in np.meshgrid(*value)] 174 weight = np.vstack([v.flatten() for v in np.meshgrid(*weight)]) 175 weight = np.prod(weight, axis=0) 172 value = [v.flatten() for v in np.meshgrid(*value)] 173 weight = np.vstack([v.flatten() for v in np.meshgrid(*weight)]) 174 weight = np.prod(weight, axis=0) 176 175 return value, weight 177 176 178 def call_kernel(kernel, pars, cutoff=0 ):177 def call_kernel(kernel, pars, cutoff=0, mono=False): 179 178 """ 180 179 Call *kernel* returned from :func:`make_kernel` with parameters *pars*. … … 189 188 fixed_pars = [pars.get(name, kernel.info['defaults'][name]) 190 189 for name in kernel.fixed_pars] 191 pd_pars = [get_weights(kernel.info, pars, name) for name in kernel.pd_pars] 190 if mono: 191 pd_pars = [( np.array([pars[name]]), np.array([1.0]) ) 192 for name in kernel.pd_pars] 193 else: 194 pd_pars = [get_weights(kernel.info, pars, name) for name in kernel.pd_pars] 192 195 return kernel(fixed_pars, pd_pars, cutoff=cutoff) 193 196 -
sasmodels/direct_model.py
r17bbadd r02e70ff 69 69 70 70 if self.data_type == 'sesans': 71 71 72 q = sesans.make_q(data.sample.zacceptance, data.Rmax) 72 73 index = slice(None, None) … … 77 78 Iq, dIq = None, None 78 79 #self._theory = np.zeros_like(q) 79 q_vectors = [q] 80 q_vectors = [q] 81 q_mono = sesans.make_all_q(data) 80 82 elif self.data_type == 'Iqxy': 81 83 if not partype['orientation'] and not partype['magnetic']: … … 96 98 #self._theory = np.zeros_like(self.Iq) 97 99 q_vectors = res.q_calc 100 q_mono = [] 98 101 elif self.data_type == 'Iq': 99 102 index = (data.x >= data.qmin) & (data.x <= data.qmax) … … 120 123 #self._theory = np.zeros_like(self.Iq) 121 124 q_vectors = [res.q_calc] 125 q_mono = [] 122 126 else: 123 127 raise ValueError("Unknown data type") # never gets here … … 125 129 # Remember function inputs so we can delay loading the function and 126 130 # so we can save/restore state 127 self._kernel_inputs = [v for v in q_vectors] 131 self._kernel_inputs = q_vectors 132 self._kernel_mono_inputs = q_mono 128 133 self._kernel = None 129 134 self.Iq, self.dIq, self.index = Iq, dIq, index … … 149 154 def _calc_theory(self, pars, cutoff=0.0): 150 155 if self._kernel is None: 151 self._kernel = make_kernel(self._model, self._kernel_inputs) # pylint: disable=attribute-defined-outside-init 156 self._kernel = make_kernel(self._model, self._kernel_inputs) # pylint: disable=attribute-dedata_type 157 self._kernel_mono = make_kernel(self._model, self._kernel_mono_inputs) if self._kernel_mono_inputs else None 152 158 153 159 Iq_calc = call_kernel(self._kernel, pars, cutoff=cutoff) 160 Iq_mono = call_kernel(self._kernel_mono, pars, mono=True) if self._kernel_mono_inputs else None 154 161 if self.data_type == 'sesans': 155 result = sesans. hankel(self._data.x, self._data.lam * 1e-9,156 self._ data.sample.thickness / 10,157 self._kernel_ inputs[0], Iq_calc)162 result = sesans.transform(self._data, 163 self._kernel_inputs[0], Iq_calc, 164 self._kernel_mono_inputs, Iq_mono) 158 165 else: 159 166 result = self.resolution.apply(Iq_calc) 160 return result 167 return result 161 168 162 169 -
sasmodels/models/adsorbed_layer.py
rf10bc52 rc079f50 6 6 7 7 r""" 8 This model describes the scattering from a layer of surfactant or polymer adsorbed on spherical particles under the conditions that (i) the particles (cores) are contrast-matched to the dispersion medium, (ii) *S(Q)* ~ 1 (ie, the particle volume fraction is dilute), (iii) the particle radius is >> layer thickness (ie, the interface is locally flat), and (iv) scattering from excess unadsorbed adsorbate in the bulk medium is absent or has been corrected for.8 This model describes the scattering from a layer of surfactant or polymer adsorbed on large, smooth, notionally spherical particles under the conditions that (i) the particles (cores) are contrast-matched to the dispersion medium, (ii) *S(Q)* ~ 1 (ie, the particle volume fraction is dilute), (iii) the particle radius is >> layer thickness (ie, the interface is locally flat), and (iv) scattering from excess unadsorbed adsorbate in the bulk medium is absent or has been corrected for. 9 9 10 10 Unlike many other core-shell models, this model does not assume any form for the density distribution of the adsorbed species normal to the interface (cf, a core-shell model normally assumes the density distribution to be a homogeneous step-function). For comparison, if the thickness of a (traditional core-shell like) step function distribution is *t*, the second moment about the mean of the density distribution (ie, the distance of the centre-of-mass of the distribution from the interface), |sigma| = sqrt((*t* :sup:`2` )/12). … … 34 34 35 35 description = """ 36 Evaluates the scattering from particles36 Evaluates the scattering from large particles 37 37 with an adsorbed layer of surfactant or 38 38 polymer, independent of the form of the … … 42 42 43 43 # ["name", "units", default, [lower, upper], "type", "description"], 44 parameters = [["second_moment", "Ang", 23.0, [0.0, inf], "", "Second moment "],45 ["adsorbed_amount", "mg/m2", 1.9, [0.0, inf], "", "Adsorbed amount "],46 ["density_ poly", "g/cm3", 0.7, [0.0, inf], "", "Polymer density"],47 ["radius", "Ang", 500.0, [0.0, inf], "", " Particle radius"],48 ["volfraction", "None", 0.14, [0.0, inf], "", " Particle volfraction"],49 [" polymer_sld", "1/Ang^2", 1.5e-06, [-inf, inf], "", "PolymerSLD"],50 ["s olvent_sld", "1/Ang^2", 6.3e-06, [-inf, inf], "", "Solvent SLD"]]44 parameters = [["second_moment", "Ang", 23.0, [0.0, inf], "", "Second moment of polymer distribution"], 45 ["adsorbed_amount", "mg/m2", 1.9, [0.0, inf], "", "Adsorbed amount of polymer"], 46 ["density_shell", "g/cm3", 0.7, [0.0, inf], "", "Bulk density of polymer in the shell"], 47 ["radius", "Ang", 500.0, [0.0, inf], "", "Core particle radius"], 48 ["volfraction", "None", 0.14, [0.0, inf], "", "Core particle volume fraction"], 49 ["sld_shell", "1e-6/Ang^2", 1.5, [-inf, inf], "sld", "Polymer shell SLD"], 50 ["sld_solvent", "1e-6/Ang^2", 6.3, [-inf, inf], "sld", "Solvent SLD"]] 51 51 52 52 # NB: Scale and Background are implicit parameters on every model 53 def Iq(q, second_moment, adsorbed_amount, density_ poly, radius,54 volfraction, polymer_sld, solvent_sld):53 def Iq(q, second_moment, adsorbed_amount, density_shell, radius, 54 volfraction, sld_shell, sld_solvent): 55 55 # pylint: disable = missing-docstring 56 deltarhosqrd = (polymer_sld - solvent_sld) * (polymer_sld - solvent_sld) 57 numerator = 6.0 * pi * volfraction * (adsorbed_amount * adsorbed_amount) 58 denominator = (q * q) * (density_poly * density_poly) * radius 59 eterm = exp(-1.0 * (q * q) * (second_moment * second_moment)) 60 #scale by 10^10 for units conversion to cm^-1 61 inten = 1.0e+10 * deltarhosqrd * ((numerator / denominator) * eterm) 56 # deltarhosqrd = (sld_shell - sld_solvent) * (sld_shell - sld_solvent) 57 # numerator = 6.0 * pi * volfraction * (adsorbed_amount * adsorbed_amount) 58 # denominator = (q * q) * (density_shell * density_shell) * radius 59 # eterm = exp(-1.0 * (q * q) * (second_moment * second_moment)) 60 # #scale by 10^-2 for units conversion to cm^-1 61 # inten = 1.0e-02 * deltarhosqrd * ((numerator / denominator) * eterm) 62 aa = (sld_shell - sld_solvent) * adsorbed_amount / q / density_shell 63 bb = q * second_moment 64 #scale by 10^-2 for units conversion to cm^-1 65 inten = 6.0e-02 * pi * volfraction * aa * aa * exp(-bb * bb) / radius 62 66 return inten 63 67 Iq.vectorized = True # Iq accepts an array of q values … … 71 75 second_moment = 23.0, 72 76 adsorbed_amount = 1.9, 73 density_ poly= 0.7,77 density_shell = 0.7, 74 78 radius = 500.0, 75 79 volfraction = 0.14, 76 polymer_sld = 1.5e-06,77 s olvent_sld = 6.3e-06,80 sld_shell = 1.5, 81 sld_solvent = 6.3, 78 82 background = 0.0) 79 83 … … 82 86 second_moment = 'second_moment', 83 87 adsorbed_amount = 'ads_amount', 84 density_ poly= 'density_poly',88 density_shell = 'density_poly', 85 89 radius = 'radius_core', 86 90 volfraction = 'volf_cores', 87 polymer_sld= 'sld_poly',88 s olvent_sld= 'sld_solv',91 sld_shell = 'sld_poly', 92 sld_solvent = 'sld_solv', 89 93 background = 'background') 90 94 … … 92 96 tests = [ 93 97 [{'scale': 1.0, 'second_moment': 23.0, 'adsorbed_amount': 1.9, 94 'density_ poly': 0.7, 'radius': 500.0, 'volfraction': 0.14,95 ' polymer_sld': 1.5e-06, 'solvent_sld': 6.3e-06, 'background': 0.0},98 'density_shell': 0.7, 'radius': 500.0, 'volfraction': 0.14, 99 'sld_shell': 1.5, 'sld_solvent': 6.3, 'background': 0.0}, 96 100 [0.0106939, 0.469418], [73.741, 9.65391e-53]], 97 101 ] 102 # ADDED by: SMK ON: 16Mar2016 convert from sasview, check vs SANDRA, 18Mar2016 RKH some edits & renaming -
sasmodels/models/core_shell_ellipsoid.c
re7678b2 r29172aa 8 8 double equat_shell, 9 9 double polar_shell, 10 double core_sld,11 double s hell_sld,12 double s olvent_sld);10 double sld_core, 11 double sld_shell, 12 double sld_solvent); 13 13 14 14 … … 18 18 double equat_shell, 19 19 double polar_shell, 20 double core_sld,21 double s hell_sld,22 double s olvent_sld,20 double sld_core, 21 double sld_shell, 22 double sld_solvent, 23 23 double theta, 24 24 double phi); … … 40 40 double equat_shell, 41 41 double polar_shell, 42 double core_sld,43 double s hell_sld,44 double s olvent_sld)42 double sld_core, 43 double sld_shell, 44 double sld_solvent) 45 45 { 46 46 … … 51 51 double summ = 0.0; //initialize intergral 52 52 53 const double delpc = core_sld - shell_sld; //core - shell54 const double delps = s hell_sld - solvent_sld; //shell - solvent53 const double delpc = sld_core - sld_shell; //core - shell 54 const double delps = sld_shell - sld_solvent; //shell - solvent 55 55 56 56 for(int i=0;i<N_POINTS_76;i++) { … … 81 81 double equat_shell, 82 82 double polar_shell, 83 double core_sld,84 double s hell_sld,85 double s olvent_sld,83 double sld_core, 84 double sld_shell, 85 double sld_solvent, 86 86 double theta, 87 87 double phi) … … 96 96 const double cyl_y = sin(theta); 97 97 98 const double sldcs = core_sld - shell_sld;99 const double sldss = s hell_sld- solvent_sld;98 const double sldcs = sld_core - sld_shell; 99 const double sldss = sld_shell- sld_solvent; 100 100 101 101 // Compute the angle btw vector q and the … … 124 124 double equat_shell, 125 125 double polar_shell, 126 double core_sld,127 double s hell_sld,128 double s olvent_sld)126 double sld_core, 127 double sld_shell, 128 double sld_solvent) 129 129 { 130 130 double intensity = core_shell_ellipsoid_kernel(q, … … 133 133 equat_shell, 134 134 polar_shell, 135 core_sld,136 s hell_sld,137 s olvent_sld);135 sld_core, 136 sld_shell, 137 sld_solvent); 138 138 139 139 return intensity; … … 146 146 double equat_shell, 147 147 double polar_shell, 148 double core_sld,149 double s hell_sld,150 double s olvent_sld,148 double sld_core, 149 double sld_shell, 150 double sld_solvent, 151 151 double theta, 152 152 double phi) … … 159 159 equat_shell, 160 160 polar_shell, 161 core_sld,162 s hell_sld,163 s olvent_sld,161 sld_core, 162 sld_shell, 163 sld_solvent, 164 164 theta, 165 165 phi); -
sasmodels/models/core_shell_ellipsoid.py
r5111921 r29172aa 1 1 r""" 2 2 This model provides the form factor, $P(q)$, for a core shell ellipsoid (below) 3 where the form factor is normalized by the volume of the cylinder.3 where the form factor is normalized by the volume of the outer [CHECK]. 4 4 5 5 .. math:: … … 7 7 P(q) = scale * \left<f^2\right>/V + background 8 8 9 where the volume $V = (4/3)\pi( r_{maj}r_{min}^2)$ and the averaging $< >$ is9 where the volume $V = (4/3)\pi(R_{major\_outer}R_{minor\_outer}^2)$ and the averaging $< >$ is 10 10 applied over all orientations for 1D. 11 11 … … 22 22 23 23 P(q) = \frac{scale}{V}\int_0^1 24 \left|F(q,r_{min },r_{max},\alpha)\right|^2d\alpha + background24 \left|F(q,r_{minor\_core},r_{major\_core},\alpha) + F(q,r_{major\_outer},r_{major\_outer},\alpha)\right|^2d\alpha + background 25 25 26 \left|F(q,r_{min },r_{max},\alpha)\right|=V\Delta \rho \cdot (3j_1(u)/u)26 \left|F(q,r_{minor},r_{major},\alpha)\right|=(4\pi/3)r_{major}r_{minor}^2 \Delta \rho \cdot (3j_1(u)/u) 27 27 28 u = q\left[ r_{maj }^2\alpha ^2 + r_{min}^2(1-\alpha ^2)\right]^{1/2}28 u = q\left[ r_{major}^2\alpha ^2 + r_{minor}^2(1-\alpha ^2)\right]^{1/2} 29 29 30 30 where … … 43 43 polar core radius, *equat_shell* = $r_{min}$ (or equatorial outer radius), 44 44 and *polar_shell* = $r_{maj}$ (or polar outer radius). 45 46 Note:It is the users' responsibility to ensure that shell radii are larger than 47 the core radii, especially if both are polydisperse, in which case the 48 core_shell_ellipsoid_xt model may be much better. 49 45 50 46 51 .. note:: … … 77 82 single particle scattering amplitude. 78 83 [Parameters]: 79 equat_core = equatorial radius of core, 80 polar_core = polar radius of core, 81 equat_shell = equatorial radius of shell, 82 polar_shell = polar radius (revolution axis) of shell,83 core_sld = SLD_core84 s hell_sld = SLD_shell85 s olvent_sld = SLD_solvent84 equat_core = equatorial radius of core, Rminor_core, 85 polar_core = polar radius of core, Rmajor_core, 86 equat_shell = equatorial radius of shell, Rminor_outer, 87 polar_shell = polar radius of shell, Rmajor_outer, 88 sld_core = scattering length density of core, 89 sld_shell = scattering length density of shell, 90 sld_solvent = scattering length density of solvent, 86 91 background = Incoherent bkg 87 92 scale =scale 88 93 Note:It is the users' responsibility to ensure 89 that shell radii are larger than core radii. 94 that shell radii are larger than core radii, 95 especially if both are polydisperse. 90 96 oblate: polar radius < equatorial radius 91 97 prolate : polar radius > equatorial radius … … 97 103 # ["name", "units", default, [lower, upper], "type", "description"], 98 104 parameters = [ 99 ["equat_core", "Ang", 200, [0, inf], "volume", "Equatorial radius of core "],100 ["polar_core", "Ang", 10, [0, inf], "volume", "Polar radius of core "],101 ["equat_shell", "Ang", 250, [0, inf], "volume", "Equatorial radius of shell "],102 ["polar_shell", "Ang", 30, [0, inf], "volume", "Polar radius of shell "],103 [" core_sld", "1e-6/Ang^2", 2, [-inf, inf], "", "Core scattering length density"],104 ["s hell_sld", "1e-6/Ang^2", 1, [-inf, inf], "", "Shell scattering length density"],105 ["s olvent_sld", "1e-6/Ang^2", 6.3, [-inf, inf], "", "Solvent scattering length density"],105 ["equat_core", "Ang", 200, [0, inf], "volume", "Equatorial radius of core, Rminor_core "], 106 ["polar_core", "Ang", 10, [0, inf], "volume", "Polar radius of core, Rmajor_core"], 107 ["equat_shell", "Ang", 250, [0, inf], "volume", "Equatorial radius of shell, Rminor_outer "], 108 ["polar_shell", "Ang", 30, [0, inf], "volume", "Polar radius of shell, Rmajor_outer"], 109 ["sld_core", "1e-6/Ang^2", 2, [-inf, inf], "sld", "Core scattering length density"], 110 ["sld_shell", "1e-6/Ang^2", 1, [-inf, inf], "sld", "Shell scattering length density"], 111 ["sld_solvent", "1e-6/Ang^2", 6.3, [-inf, inf], "sld", "Solvent scattering length density"], 106 112 ["theta", "degrees", 0, [-inf, inf], "orientation", "Oblate orientation wrt incoming beam"], 107 113 ["phi", "degrees", 0, [-inf, inf], "orientation", "Oblate orientation in the plane of the detector"], … … 116 122 equat_shell=250.0, 117 123 polar_shell=30.0, 118 core_sld=2.0,119 s hell_sld=1.0,120 s olvent_sld=6.3,124 sld_core=2.0, 125 sld_shell=1.0, 126 sld_solvent=6.3, 121 127 theta=0, 122 128 phi=0) … … 124 130 oldname = 'CoreShellEllipsoidModel' 125 131 126 oldpars = dict(core_sld='sld_core', 127 shell_sld='sld_shell', 128 solvent_sld='sld_solvent', 132 oldpars = dict(equat_core='equat_core',polar_core='polar_core',equat_shell='equat_shell',polar_shell='polar_shell', 133 sld_core='sld_core', 134 sld_shell='sld_shell', 135 sld_solvent='sld_solvent', 129 136 theta='axis_theta', 130 137 phi='axis_phi') … … 141 148 'equat_shell': 250.0, 142 149 'polar_shell': 30.0, 143 ' core_sld': 2.0,144 's hell_sld': 1.0,145 's olvent_sld': 6.3,150 'sld_core': 2.0, 151 'sld_shell': 1.0, 152 'sld_solvent': 6.3, 146 153 'background': 0.001, 147 154 'scale': 1.0, … … 155 162 'equat_shell': 54.0, 156 163 'polar_shell': 3.0, 157 ' core_sld': 20.0,158 's hell_sld': 10.0,159 's olvent_sld': 6.0,164 'sld_core': 20.0, 165 'sld_shell': 10.0, 166 'sld_solvent': 6.0, 160 167 'background': 0.0, 161 168 'scale': 1.0, … … 168 175 'equat_shell': 54.0, 169 176 'polar_shell': 3.0, 170 ' core_sld': 20.0,171 's hell_sld': 10.0,172 's olvent_sld': 6.0,177 'sld_core': 20.0, 178 'sld_shell': 10.0, 179 'sld_solvent': 6.0, 173 180 'background': 0.01, 174 181 'scale': 0.01, -
sasmodels/models/core_shell_ellipsoid_xt.py
r5111921 r29172aa 1 1 r""" 2 An alternative version of $P(q)$ for the core -shellellipsoid3 (see CoreShellEllipsoidModel), having as parameters the core axial ratio X 4 and a shell thickness,which are more often what we would like to determine.2 An alternative version of $P(q)$ for the core_shell_ellipsoid 3 having as parameters the core axial ratio X and a shell thickness, 4 which are more often what we would like to determine. 5 5 6 6 This model is also better behaved when polydispersity is applied than the four 7 independent radii in CoreShellEllipsoidModel.7 independent radii in core_shell_ellipsoid model. 8 8 9 9 Definition … … 52 52 ---------- 53 53 54 R K Heenan, *Private communication*54 R K Heenan, 2015, reparametrised the core_shell_ellipsoid model 55 55 56 56 """ … … 69 69 [Parameters]: 70 70 equat_core = equatorial radius of core, 71 x_core = polar radius of core,71 x_core = ratio of core polar/equatorial radii, 72 72 t_shell = equatorial radius of outer surface, 73 x_polar_shell = polar radius (revolution axis) of outer surface74 core_sld= SLD_core75 s hell_sld= SLD_shell76 s olvent_sld= SLD_solvent73 x_polar_shell = ratio of polar shell thickness to equatorial shell thickness, 74 sld_core = SLD_core 75 sld_shell = SLD_shell 76 sld_solvent = SLD_solvent 77 77 background = Incoherent bkg 78 78 scale =scale … … 92 92 ["t_shell", "Ang", 30, [0, inf], "volume", "Equatorial radius of shell"], 93 93 ["x_polar_shell", "", 1, [0, inf], "volume", "Polar radius of shell"], 94 [" core_sld", "1e-6/Ang^2", 2, [-inf, inf], "", "Core scattering length density"],95 ["s hell_sld", "1e-6/Ang^2", 1, [-inf, inf], "", "Shell scattering length density"],96 ["s olvent_sld", "1e-6/Ang^2", 6.3, [-inf, inf], "", "Solvent scattering length density"],94 ["sld_core", "1e-6/Ang^2", 2, [-inf, inf], "", "Core scattering length density"], 95 ["sld_shell", "1e-6/Ang^2", 1, [-inf, inf], "", "Shell scattering length density"], 96 ["sld_solvent", "1e-6/Ang^2", 6.3, [-inf, inf], "", "Solvent scattering length density"], 97 97 ["theta", "degrees", 0, [-inf, inf], "orientation", "Oblate orientation wrt incoming beam"], 98 98 ["phi", "degrees", 0, [-inf, inf], "orientation", "Oblate orientation in the plane of the detector"], … … 108 108 t_shell=30.0, 109 109 x_polar_shell=1.0, 110 core_sld=2.0,111 s hell_sld=1.0,112 s olvent_sld=6.3,110 sld_core=2.0, 111 sld_shell=1.0, 112 sld_solvent=6.3, 113 113 theta=0, 114 114 phi=0) … … 119 119 x_core='X_core', 120 120 t_shell='T_shell', 121 core_sld='sld_core',122 s hell_sld='sld_shell',123 s olvent_sld='sld_solvent',121 sld_core='sld_core', 122 sld_shell='sld_shell', 123 sld_solvent='sld_solvent', 124 124 theta='axis_theta', 125 125 phi='axis_phi') … … 136 136 't_shell': 50.0, 137 137 'x_polar_shell': 0.2, 138 ' core_sld': 2.0,139 's hell_sld': 1.0,140 's olvent_sld': 6.3,138 'sld_core': 2.0, 139 'sld_shell': 1.0, 140 'sld_solvent': 6.3, 141 141 'background': 0.001, 142 142 'scale': 1.0, … … 150 150 't_shell': 54.0, 151 151 'x_polar_shell': 3.0, 152 ' core_sld': 20.0,153 's hell_sld': 10.0,154 's olvent_sld': 6.0,152 'sld_core': 20.0, 153 'sld_shell': 10.0, 154 'sld_solvent': 6.0, 155 155 'background': 0.0, 156 156 'scale': 1.0, … … 163 163 't_shell': 54.0, 164 164 'x_polar_shell': 3.0, 165 ' core_sld': 20.0,166 's hell_sld': 10.0,167 's olvent_sld': 6.0,165 'sld_core': 20.0, 166 'sld_shell': 10.0, 167 'sld_solvent': 6.0, 168 168 'background': 0.01, 169 169 'scale': 0.01, -
sasmodels/models/hardsphere.py
r3bcd03d re98c1e0 58 58 category = "structure-factor" 59 59 structure_factor = True 60 single = False 60 61 61 62 # ["name", "units", default, [lower, upper], "type","description"], -
sasmodels/models/lamellar.py
raa2edb2 r7c391dd 5 5 ---------- 6 6 7 The scattering intensity $I(q)$ is7 The scattering intensity $I(q)$ for dilute, randomly oriented, "infinitely large" sheets or lamellae is 8 8 9 9 .. math:: 10 10 11 I(q) = \frac{2\pi P(q)}{\delta q^2}11 I(q) = scale*\frac{2\pi P(q)}{q^2\delta } 12 12 13 13 … … 16 16 .. math:: 17 17 18 P(q) = \frac{2\Delta\rho^2}{q^2}(1-cos(q\delta))18 P(q) = \frac{2\Delta\rho^2}{q^2}(1-cos(q\delta)) = \frac{4\Delta\rho^2}{q^2}sin^2(\frac{q\delta}{2}) 19 19 20 where $\delta$ is the total layer thickness and $\Delta\rho$ is the scattering length density difference. 20 21 21 where $\delta$ is the bilayer thickness. 22 This is the limiting form for a spherical shell of infinitely large radius. Note that the division by $\delta$ 23 means that $scale$ in sasview is the volume fraction of sheet, $\phi = S\delta$ where $S$ is the area of 24 sheet per unit volume. $S$ is half the Porod surface area per unit volume of a thicker layer (as that would 25 include both faces of the sheet). 22 26 23 27 The 2D scattering intensity is calculated in the same way as 1D, where … … 56 60 57 61 # ["name", "units", default, [lower, upper], "type","description"], 58 parameters = [["sld", "1e-6/Ang^2", 1, [-inf, inf], "", 59 "Layer scattering length density" ], 60 ["solvent_sld", "1e-6/Ang^2", 6, [-inf, inf], "", 61 "Solvent scattering length density" ], 62 ["thickness", "Ang", 50, [0, inf], "volume","Bilayer thickness" ], 62 parameters = [ ["thickness", "Ang", 50, [0, inf], "volume","total layer thickness" ], 63 ["sld", "1e-6/Ang^2", 1, [-inf, inf], "","Layer scattering length density" ], 64 ["sld_solvent", "1e-6/Ang^2", 6, [-inf, inf], "","Solvent scattering length density" ], 63 65 ] 64 66 65 66 67 # No volume normalization despite having a volume parameter 67 # This should perhaps be volume normalized? 68 # This should perhaps be volume normalized? - it is! 68 69 form_volume = """ 69 70 return 1.0; … … 71 72 72 73 Iq = """ 73 const double sub = sld - s olvent_sld;74 const double sub = sld - sld_solvent; 74 75 const double qsq = q*q; 75 76 // Original expression … … 89 90 90 91 demo = dict(scale=1, background=0, 91 sld=6, s olvent_sld=1,92 sld=6, sld_solvent=1, 92 93 thickness=40, 93 94 thickness_pd=0.2, thickness_pd_n=40) 94 95 oldname = 'LamellarModel' 95 oldpars = dict(sld='sld_bi', s olvent_sld='sld_sol', thickness='bi_thick')96 oldpars = dict(sld='sld_bi', sld_solvent='sld_sol', thickness='bi_thick') 96 97 tests = [ 97 [ {'scale': 1.0, 'background' : 0.0, 'thickness' : 50.0, 'sld' : 1.0,'s olvent_sld' : 6.3, 'thickness_pd' : 0.0,98 [ {'scale': 1.0, 'background' : 0.0, 'thickness' : 50.0, 'sld' : 1.0,'sld_solvent' : 6.3, 'thickness_pd' : 0.0, 98 99 }, [0.001], [882289.54309]] 99 100 ] -
sasmodels/models/lamellar_hg.py
raa2edb2 r52a3db3 26 26 27 27 where $\delta_T$ is *tail_length*, $\delta_H$ is *head_length*, 28 $\Delta\rho_H$ is the head contrast (*head_sld* $-$ *solvent_sld*), 29 and $\Delta\rho_T$ is tail contrast (*sld* $-$ *solvent_sld*). 28 $\Delta\rho_H$ is the head contrast (*sld_head* $-$ *sld_solvent*), 29 and $\Delta\rho_T$ is tail contrast (*sld* $-$ *sld_solvent*). 30 31 The total thickness of the lamellar sheet is $\delta_H$ + $\delta_T$ + $\delta_T$ + $\delta_H$. 32 Note that in a non aqueous solvent the chemical "head" group may be the 33 "Tail region" and vice-versa. 30 34 31 35 The 2D scattering intensity is calculated in the same way as 1D, where … … 49 53 from numpy import inf 50 54 51 name = "lamellar_ FFHG"52 title = "Random lamellar phase with Head Groups"55 name = "lamellar_hg" 56 title = "Random lamellar phase with Head and Tail Groups" 53 57 description = """\ 54 [Random lamellar phase with Head Groups]58 [Random lamellar phase with Head and Tail Groups] 55 59 I(q)= 2*pi*P(q)/(2(H+T)*q^(2)), where 56 60 P(q)= see manual 57 61 layer thickness =(H+T+T+H) = 2(Head+Tail) 58 62 sld = Tail scattering length density 59 head_sld = Head scattering length density60 s olvent_sld= solvent scattering length density63 sld_head = Head scattering length density 64 sld_solvent = solvent scattering length density 61 65 background = incoherent background 62 66 scale = scale factor … … 66 70 # pylint: disable=bad-whitespace, line-too-long 67 71 # ["name", "units", default, [lower, upper], "type","description"], 68 parameters = [["tail_length", "Ang", 15, [0, inf], "volume", "Tail thickness "],69 ["head_length", "Ang", 10, [0, inf], "volume", " head thickness"],72 parameters = [["tail_length", "Ang", 15, [0, inf], "volume", "Tail thickness ( total = H+T+T+H)"], 73 ["head_length", "Ang", 10, [0, inf], "volume", "Head thickness"], 70 74 ["sld", "1e-6/Ang^2", 0.4, [-inf,inf], "", "Tail scattering length density"], 71 [" head_sld", "1e-6/Ang^2", 3.0, [-inf,inf], "", "Head scattering length density"],72 ["s olvent_sld", "1e-6/Ang^2", 6, [-inf,inf], "", "Solvent scattering length density"]]75 ["sld_head", "1e-6/Ang^2", 3.0, [-inf,inf], "", "Head scattering length density"], 76 ["sld_solvent", "1e-6/Ang^2", 6, [-inf,inf], "", "Solvent scattering length density"]] 73 77 # pylint: enable=bad-whitespace, line-too-long 74 78 … … 81 85 Iq = """ 82 86 const double qsq = q*q; 83 const double drh = head_sld - solvent_sld;84 const double drt = sld - s olvent_sld; //correction 13FEB06 by L.Porcar87 const double drh = sld_head - sld_solvent; 88 const double drt = sld - sld_solvent; //correction 13FEB06 by L.Porcar 85 89 const double qT = q*tail_length; 86 90 double Pq, inten; … … 106 110 demo = dict(scale=1, background=0, 107 111 tail_length=15, head_length=10, 108 sld=0.4, head_sld=3.0, solvent_sld=6.0,112 sld=0.4, sld_head=3.0, sld_solvent=6.0, 109 113 tail_length_pd=0.2, tail_length_pd_n=40, 110 114 head_length_pd=0.01, head_length_pd_n=40) … … 112 116 oldname = 'LamellarFFHGModel' 113 117 oldpars = dict(head_length='h_thickness', tail_length='t_length', 114 sld='sld_tail', head_sld='sld_head', solvent_sld='sld_solvent')118 sld='sld_tail', sld_head='sld_head', sld_solvent='sld_solvent') 115 119 # 116 120 tests = [[{'scale': 1.0, 'background': 0.0, 'tail_length': 15.0, 'head_length': 10.0, 117 'sld': 0.4, 'head_sld': 3.0, 'solvent_sld': 6.0}, [0.001], [653143.9209]]] 121 'sld': 0.4, 'sld_head': 3.0, 'sld_solvent': 6.0}, [0.001], [653143.9209]]] 122 # ADDED by: RKH ON: 18Mar2016 converted from sasview previously, now renaming everything & sorting the docs -
sasmodels/models/lamellar_hg_stack_caille.py
raa2edb2 r6ab4ed8 9 9 .. math:: 10 10 11 I(q) = 2 \pi \frac{P(q)S(q)}{ \delta q^2}11 I(q) = 2 \pi \frac{P(q)S(q)}{q^2\delta } 12 12 13 13 … … 56 56 results for the next lower and higher values. 57 57 58 Be aware that the computations may be very slow. 59 58 60 The 2D scattering intensity is calculated in the same way as 1D, where 59 61 the $q$ vector is defined as … … 73 75 from numpy import inf 74 76 75 name = "lamellar CailleHG"76 title = "Random lamellar sheet with Caille structure factor"77 name = "lamellar_hg_stack_caille" 78 title = "Random lamellar head/tail/tail/head sheet with Caille structure factor" 77 79 description = """\ 78 80 [Random lamellar phase with Caille structure factor] … … 104 106 ["sld", "1e-6/Ang^2", 0.4, [-inf, inf], "", 105 107 "Tail scattering length density"], 106 [" head_sld", "1e-6/Ang^2", 2.0, [-inf, inf], "",108 ["sld_head", "1e-6/Ang^2", 2.0, [-inf, inf], "", 107 109 "Head scattering length density"], 108 ["s olvent_sld", "1e-6/Ang^2", 6, [-inf, inf], "",110 ["sld_solvent", "1e-6/Ang^2", 6, [-inf, inf], "", 109 111 "Solvent scattering length density"], 110 112 ] 111 113 112 source = ["lamellar CailleHG_kernel.c"]114 source = ["lamellar_hg_stack_caille_kernel.c"] 113 115 114 116 # No volume normalization despite having a volume parameter … … 129 131 Nlayers=20, spacing=200., Caille_parameter=0.05, 130 132 tail_length=15, head_length=10, 131 #sld=-1, head_sld=4.0, solvent_sld=6.0,132 sld=-1, head_sld=4.1, solvent_sld=6.0,133 #sld=-1, sld_head=4.0, sld_solvent=6.0, 134 sld=-1, sld_head=4.1, sld_solvent=6.0, 133 135 tail_length_pd=0.1, tail_length_pd_n=20, 134 136 head_length_pd=0.05, head_length_pd_n=30, … … 140 142 oldpars = dict( 141 143 tail_length='deltaT', head_length='deltaH', Nlayers='n_plates', 142 Caille_parameter='caille', sld='sld_tail', head_sld='sld_head',143 s olvent_sld='sld_solvent')144 Caille_parameter='caille', sld='sld_tail', sld_head='sld_head', 145 sld_solvent='sld_solvent') 144 146 # 145 147 tests = [[{'scale': 1.0, 'background': 0.0, 'tail_length': 10.0, 'head_length': 2.0, 146 148 'Nlayers': 30.0, 'spacing': 40., 'Caille_parameter': 0.001, 'sld': 0.4, 147 ' head_sld': 2.0, 'solvent_sld': 6.0, 'tail_length_pd': 0.0,149 'sld_head': 2.0, 'sld_solvent': 6.0, 'tail_length_pd': 0.0, 148 150 'head_length_pd': 0.0, 'spacing_pd': 0.0}, [0.001], [6838238.571488]]] 151 # ADDED by: RKH ON: 18Mar2016 converted from sasview previously, now renaming everything & sorting the docs -
sasmodels/models/lamellar_stack_caille.py
raa2edb2 r6ab4ed8 11 11 .. math:: 12 12 13 I(q) = 2\pi \frac{P(q)S(q)}{ \delta q^2}13 I(q) = 2\pi \frac{P(q)S(q)}{q^2\delta } 14 14 15 15 The form factor is … … 70 70 from numpy import inf 71 71 72 name = "lamellar PS"72 name = "lamellar_stack_caille" 73 73 title = "Random lamellar sheet with Caille structure factor" 74 74 description = """\ … … 92 92 ["Caille_parameter", "1/Ang^2", 0.1, [0.0,0.8], "", "Caille parameter"], 93 93 ["sld", "1e-6/Ang^2", 6.3, [-inf,inf], "", "layer scattering length density"], 94 ["s olvent_sld", "1e-6/Ang^2", 1.0, [-inf,inf], "", "Solvent scattering length density"],94 ["sld_solvent", "1e-6/Ang^2", 1.0, [-inf,inf], "", "Solvent scattering length density"], 95 95 ] 96 96 # pylint: enable=bad-whitespace, line-too-long 97 97 98 source = ["lamellar Caille_kernel.c"]98 source = ["lamellar_stack_caille_kernel.c"] 99 99 100 100 # No volume normalization despite having a volume parameter … … 113 113 demo = dict(scale=1, background=0, 114 114 thickness=67., Nlayers=3.75, spacing=200., 115 Caille_parameter=0.268, sld=1.0, s olvent_sld=6.34,115 Caille_parameter=0.268, sld=1.0, sld_solvent=6.34, 116 116 thickness_pd=0.1, thickness_pd_n=100, 117 117 spacing_pd=0.05, spacing_pd_n=40) … … 120 120 oldpars = dict(thickness='delta', Nlayers='N_plates', 121 121 Caille_parameter='caille', 122 sld='sld_bi', s olvent_sld='sld_sol')122 sld='sld_bi', sld_solvent='sld_sol') 123 123 # 124 124 tests = [ 125 125 [{'scale': 1.0, 'background': 0.0, 'thickness': 30., 'Nlayers': 20.0, 126 126 'spacing': 400., 'Caille_parameter': 0.1, 'sld': 6.3, 127 's olvent_sld': 1.0, 'thickness_pd': 0.0, 'spacing_pd': 0.0},127 'sld_solvent': 1.0, 'thickness_pd': 0.0, 'spacing_pd': 0.0}, 128 128 [0.001], [28895.13397]] 129 129 ] 130 # ADDED by: RKH ON: 18Mar2016 converted from sasview previously, now renaming everything & sorting the docs -
sasmodels/models/lamellar_stack_paracrystal.py
raa2edb2 r6ab4ed8 16 16 *not* the total excluded volume of the paracrystal), 17 17 18 - *sld* $-$ *s olvent_sld* is the contrast $\Delta \rho$,18 - *sld* $-$ *sld_solvent* is the contrast $\Delta \rho$, 19 19 20 20 - *thickness* is the layer thickness $t$, … … 36 36 37 37 The form factor of the bilayer is approximated as the cross section of an 38 infinite, planar bilayer of thickness $t$ 38 infinite, planar bilayer of thickness $t$ (compare the equations for the 39 lamellar model). 39 40 40 41 .. math:: … … 94 95 from numpy import inf 95 96 96 name = "lamellar PC"97 name = "lamellar_stack_paracrystal" 97 98 title = "Random lamellar sheet with paracrystal structure factor" 98 99 description = """\ … … 120 121 ["sld", "1e-6/Ang^2", 1.0, [-inf, inf], "", 121 122 "layer scattering length density"], 122 ["s olvent_sld", "1e-6/Ang^2", 6.34, [-inf, inf], "",123 ["sld_solvent", "1e-6/Ang^2", 6.34, [-inf, inf], "", 123 124 "Solvent scattering length density"], 124 125 ] 125 126 126 127 127 source = ["lamellar PC_kernel.c"]128 source = ["lamellar_stack_paracrystal_kernel.c"] 128 129 129 130 form_volume = """ … … 140 141 demo = dict(scale=1, background=0, 141 142 thickness=33, Nlayers=20, spacing=250, spacing_polydisp=0.2, 142 sld=1.0, s olvent_sld=6.34,143 sld=1.0, sld_solvent=6.34, 143 144 thickness_pd=0.2, thickness_pd_n=40) 144 145 145 146 oldname = 'LamellarPCrystalModel' 146 147 oldpars = dict(spacing_polydisp='pd_spacing', sld='sld_layer', 147 s olvent_sld='sld_solvent')148 sld_solvent='sld_solvent') 148 149 # 149 150 tests = [ 150 151 [ {'scale': 1.0, 'background' : 0.0, 'thickness' : 33.,'Nlayers' : 20.0, 'spacing' : 250., 'spacing_polydisp' : 0.2, 151 'sld' : 1.0, 's olvent_sld' : 6.34,152 'sld' : 1.0, 'sld_solvent' : 6.34, 152 153 'thickness_pd' : 0.0, 'thickness_pd_n' : 40 }, [0.001, 0.215268], [21829.3, 0.00487686]] 153 154 ] 155 # ADDED by: RKH ON: 18Mar2016 converted from sasview previously, now renaming everything & sorting the docs -
sasmodels/product.py
r3bcd03d rd5ba841 124 124 # so borrow values from end of p_fixed. This makes volfraction the 125 125 # first S parameter. 126 start += num_p_fixed - 2 127 par_map['s_fixed'] = np.arange(start, start+num_s_fixed) 126 start += num_p_fixed 127 par_map['s_fixed'] = np.hstack(([start,start], 128 np.arange(start, start+num_s_fixed-2))) 128 129 par_map['volfraction'] = num_p_fixed 129 start += num_s_fixed 130 start += num_s_fixed-2 130 131 # vol pars offset from the start of pd pars 131 132 par_map['vol_pars'] = [start+k for k in vol_par_idx] 132 133 par_map['p_pd'] = np.arange(start, start+num_p_pd) 133 start += num_p_pd 134 par_map['s_pd'] = np.arange(start-1, start+num_s_pd) # should be empty... 134 start += num_p_pd-1 135 par_map['s_pd'] = np.hstack((start, 136 np.arange(start, start+num_s_pd-1))) 135 137 136 138 self.fixed_pars = model_info['partype']['fixed-' + dim] -
sasmodels/resolution.py
r17bbadd ra146eaa 197 197 198 198 199 **Algorithm** 199 Definition 200 ---------- 200 201 201 202 We are using the mid-point integration rule to assign weights to each … … 441 442 .. math:: 442 443 443 n_\text{extend} = (n-1) (\log q_\text{max} - \log q_n)444 n_\text{extend} = (n-1) (\log q_\text{max} - \log q_n) 444 445 / (\log q_n - log q_1) 445 446 """ -
sasmodels/sasview_model.py
rfcd7bbd r2622b3f 17 17 from copy import deepcopy 18 18 import warnings 19 import collections 19 20 20 21 import numpy as np … … 57 58 ## TODO: reorganize parameter handling 58 59 self.details = dict() 59 self.params = dict()60 self.params = collections.OrderedDict() 60 61 self.dispersion = dict() 61 62 partype = model.info['partype'] 63 62 64 for p in model.info['parameters']: 63 65 self.params[p.name] = p.default -
sasmodels/sesans.py
r190fc2b ra06430c 13 13 from numpy import pi, exp 14 14 from scipy.special import jv as besselj 15 15 #import direct_model.DataMixin as model 16 16 17 def make_q(q_max, Rmax): 17 18 r""" … … 21 22 q_min = dq = 0.1 * 2*pi / Rmax 22 23 return np.arange(q_min, q_max, dq) 24 25 def make_all_q(data): 26 if not data.needs_all_q: 27 return [] 28 elif needs_Iqxy(data): 29 # compute qx, qy 30 Qx, Qy = np.meshgrid(qx, qy) 31 return [Qx, Qy] 32 else: 33 # else only need q 34 return [q] 23 35 36 def transform(data, q_calc, Iq_calc, qmono, Iq_mono): 37 nqmono = len(qmono) 38 if nqmono == 0: 39 result = call_hankel(data, q_calc, Iq_calc) 40 elif nqmono == 1: 41 q = qmono[0] 42 result = call_HankelAccept(data, q_calc, Iq_calc, q, Iq_mono) 43 else: 44 Qx, Qy = [qmono[0], qmono[1]] 45 Qx = np.reshape(Qx, nqx, nqy) 46 Qy = np.reshape(Qy, nqx, nqy) 47 Iq_mono = np.reshape(Iq_mono, nqx, nqy) 48 qx = Qx[0, :] 49 qy = Qy[:, 0] 50 result = call_Cosine2D(data, q_calc, Iq_calc, qx, qy, Iq_mono) 51 52 return result 53 54 def call_hankel(data, q_calc, Iq_calc): 55 return hankel(data.x, data.lam * 1e-9, 56 data.sample.thickness / 10, 57 q_calc, Iq_calc) 58 59 def call_HankelAccept(data, q_calc, Iq_calc, q_mono, Iq_mono): 60 return hankel(data.x, data.lam * 1e-9, 61 data.sample.thickness / 10, 62 q_calc, Iq_calc) 63 64 def Cosine2D(data, q_calc, Iq_calc, qx, qy, Iq_mono): 65 return hankel(data.x, data.y, data.lam * 1e-9, 66 data.sample.thickness / 10, 67 q_calc, Iq_calc) 68 69 def TotalScatter(model, parameters): #Work in progress!! 70 # Calls a model with existing model parameters already in place, then integrate the product of q and I(q) from 0 to (4*pi/lambda) 71 allq = np.linspace(0,4*pi/wavelength,1000) 72 allIq = 1 73 integral = allq*allIq 74 75 76 77 def Cosine2D(wavelength, magfield, thickness, qy, qz, Iqy, Iqz, modelname): #Work in progress!! Needs to call model still 78 #============================================================================== 79 # 2D Cosine Transform if "wavelength" is a vector 80 #============================================================================== 81 #allq is the q-space needed to create the total scattering cross-section 82 83 Gprime = np.zeros_like(wavelength, 'd') 84 s = np.zeros_like(wavelength, 'd') 85 sd = np.zeros_like(wavelength, 'd') 86 Gprime = np.zeros_like(wavelength, 'd') 87 f = np.zeros_like(wavelength, 'd') 88 for i, wavelength_i in enumerate(wavelength): 89 z = magfield*wavelength_i 90 allq=np.linspace() #for calculating the Q-range of the scattering power integral 91 allIq=np.linspace() # This is the model applied to the allq q-space. Needs to refference the model somehow 92 alldq = (allq[1]-allq[0])*1e10 93 sigma[i]=wavelength[i]^2*thickness/2/pi*np.sum(allIq*allq*alldq) 94 s[i]=1-exp(-sigma) 95 for j, Iqy_j, qy_j in enumerate(qy): 96 for k, Iqz_k, qz_k in enumerate(qz): 97 Iq = np.sqrt(Iqy_j^2+Iqz_k^2) 98 q = np.sqrt(qy_j^2 + qz_k^2) 99 Gintegral = Iq*cos(z*Qz_k) 100 Gprime[i] += Gintegral 101 # sigma = wavelength^2*thickness/2/pi* allq[i]*allIq[i] 102 # s[i] += 1-exp(Totalscatter(modelname)*thickness) 103 # For now, work with standard 2-phase scatter 104 105 106 sd[i] += Iq 107 f[i] = 1-s[i]+sd[i] 108 P[i] = (1-sd[i]/f[i])+1/f[i]*Gprime[i] 109 110 111 112 113 def HankelAccept(wavelength, magfield, thickness, q, Iq, theta, modelname): 114 #============================================================================== 115 # HankelTransform with fixed circular acceptance angle (circular aperture) for Time of Flight SESANS 116 #============================================================================== 117 #acceptq is the q-space needed to create limited acceptance effect 118 SElength= wavelength*magfield 119 G = np.zeros_like(SElength, 'd') 120 threshold=2*pi*theta/wavelength 121 for i, SElength_i in enumerate(SElength): 122 allq=np.linspace() #for calculating the Q-range of the scattering power integral 123 allIq=np.linspace() # This is the model applied to the allq q-space. Needs to refference the model somehow 124 alldq = (allq[1]-allq[0])*1e10 125 sigma[i]=wavelength[i]^2*thickness/2/pi*np.sum(allIq*allq*alldq) 126 s[i]=1-exp(-sigma) 127 128 dq = (q[1]-q[0])*1e10 129 a = (x<threshold) 130 acceptq = a*q 131 acceptIq = a*Iq 132 133 G[i] = np.sum(besselj(0, acceptq*SElength_i)*acceptIq*acceptq*dq) 134 135 # G[i]=np.sum(integral) 136 137 G *= dq*1e10*2*pi 138 139 P = exp(thickness*wavelength**2/(4*pi**2)*(G-G[0])) 140 24 141 def hankel(SElength, wavelength, thickness, q, Iq): 25 142 r""" … … 44 161 """ 45 162 G = np.zeros_like(SElength, 'd') 163 #============================================================================== 164 # Hankel Transform method if "wavelength" is a scalar; mono-chromatic SESANS 165 #============================================================================== 46 166 for i, SElength_i in enumerate(SElength): 47 167 integral = besselj(0, q*SElength_i)*Iq*q -
setup.py
r3eb3312 rf903f0a 3 3 packages = find_packages(exclude=['contrib', 'docs', 'tests*']) 4 4 package_data = { 5 'sasmodels.models': ['*.c'], 5 'sasmodels.models': ['*.c','lib/*.c'], 6 'sasmodels': ['*.c'], 6 7 } 7 8 required = [] -
sasmodels/models/bessel.py
rcbd37a7 ra5af4e1 78 78 79 79 Iq = """ 80 return 2.0*j1(q)/q;80 return J1(q); 81 81 """ 82 82 -
sasmodels/models/lib/j1_cephes.c
re2af2a9 ra5af4e1 39 39 Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier 40 40 */ 41 double j1(double );41 double J1(double ); 42 42 43 double j1(double x) {43 double J1(double x) { 44 44 45 45 //Cephes double pression function … … 48 48 double w, z, p, q, xn; 49 49 50 const double DR1 = 5.78318596294678452118E0;51 const double DR2 = 3.04712623436620863991E1;52 50 const double Z1 = 1.46819706421238932572E1; 53 51 const double Z2 = 4.92184563216946036703E1; 54 52 const double THPIO4 = 2.35619449019234492885; 55 53 const double SQ2OPI = 0.79788456080286535588; 56 57 double RP[8] = {58 -8.99971225705559398224E8,59 4.52228297998194034323E11,60 -7.27494245221818276015E13,61 3.68295732863852883286E15,62 0.0,63 0.0,64 0.0,65 0.066 };67 68 double RQ[8] = {69 /* 1.00000000000000000000E0,*/70 6.20836478118054335476E2,71 2.56987256757748830383E5,72 8.35146791431949253037E7,73 2.21511595479792499675E10,74 4.74914122079991414898E12,75 7.84369607876235854894E14,76 8.95222336184627338078E16,77 5.32278620332680085395E18,78 };79 80 double PP[8] = {81 7.62125616208173112003E-4,82 7.31397056940917570436E-2,83 1.12719608129684925192E0,84 5.11207951146807644818E0,85 8.42404590141772420927E0,86 5.21451598682361504063E0,87 1.00000000000000000254E0,88 0.0,89 };90 double PQ[8] = {91 5.71323128072548699714E-4,92 6.88455908754495404082E-2,93 1.10514232634061696926E0,94 5.07386386128601488557E0,95 8.39985554327604159757E0,96 5.20982848682361821619E0,97 9.99999999999999997461E-1,98 0.0,99 };100 101 double QP[8] = {102 5.10862594750176621635E-2,103 4.98213872951233449420E0,104 7.58238284132545283818E1,105 3.66779609360150777800E2,106 7.10856304998926107277E2,107 5.97489612400613639965E2,108 2.11688757100572135698E2,109 2.52070205858023719784E1,110 };111 112 double QQ[8] = {113 /* 1.00000000000000000000E0,*/114 7.42373277035675149943E1,115 1.05644886038262816351E3,116 4.98641058337653607651E3,117 9.56231892404756170795E3,118 7.99704160447350683650E3,119 2.82619278517639096600E3,120 3.36093607810698293419E2,121 0.0,122 };123 54 124 55 w = x; … … 129 60 { 130 61 z = x * x; 131 w = polevl ( z, RP, 3 ) / p1evl( z, RQ, 8 );62 w = polevlRP( z, 3 ) / p1evlRQ( z, 8 ); 132 63 w = w * x * (z - Z1) * (z - Z2); 133 64 return( w ); … … 136 67 w = 5.0/x; 137 68 z = w * w; 138 p = polevl( z, PP, 6)/polevl( z, PQ, 6 ); 139 q = polevl( z, QP, 7)/p1evl( z, QQ, 7 ); 69 70 p = polevlPP( z, 6)/polevlPQ( z, 6 ); 71 q = polevlQP( z, 7)/p1evlQQ( z, 7 ); 72 140 73 xn = x - THPIO4; 141 74 … … 155 88 156 89 157 double JP[8] = {158 -4.878788132172128E-009,159 6.009061827883699E-007,160 -4.541343896997497E-005,161 1.937383947804541E-003,162 -3.405537384615824E-002,163 0.0,164 0.0,165 0.0166 };167 168 double MO1[8] = {169 6.913942741265801E-002,170 -2.284801500053359E-001,171 3.138238455499697E-001,172 -2.102302420403875E-001,173 5.435364690523026E-003,174 1.493389585089498E-001,175 4.976029650847191E-006,176 7.978845453073848E-001177 };178 179 double PH1[8] = {180 -4.497014141919556E+001,181 5.073465654089319E+001,182 -2.485774108720340E+001,183 7.222973196770240E+000,184 -1.544842782180211E+000,185 3.503787691653334E-001,186 -1.637986776941202E-001,187 3.749989509080821E-001188 };189 190 90 xx = x; 191 91 if( xx < 0 ) … … 195 95 { 196 96 z = xx * xx; 197 p = (z-Z1) * xx * polevl ( z, JP, 4 );97 p = (z-Z1) * xx * polevlJP( z, 4 ); 198 98 return( p ); 199 99 } … … 202 102 w = sqrt(q); 203 103 204 p = w * polevl ( q, MO1, 7);104 p = w * polevlMO1( q, 7); 205 105 w = q*q; 206 xn = q * polevl ( w, PH1, 7) - THPIO4F;106 xn = q * polevlPH1( w, 7) - THPIO4F; 207 107 p = p * cos(xn + xx); 208 108 … … 210 110 #endif 211 111 } 212 -
sasmodels/models/lib/polevl.c
re2af2a9 ra5af4e1 51 51 */ 52 52 53 double polevl( double x, double coef[8], int N ); 54 double p1evl( double x, double coef[8], int N ); 55 56 double polevl( double x, double coef[8], int N ) { 57 58 int i = 0; 59 double ans = coef[i]; 60 61 while (i < N) { 62 i++; 63 ans = ans * x + coef[i]; 64 } 65 66 return ans ; 67 68 } 53 double polevlRP(double x, int N ) { 54 55 double coef[8] = { 56 -8.99971225705559398224E8, 57 4.52228297998194034323E11, 58 -7.27494245221818276015E13, 59 3.68295732863852883286E15, 60 0.0, 61 0.0, 62 0.0, 63 0.0 }; 64 65 int i = 0; 66 double ans = coef[i]; 67 68 while (i < N) { 69 i++; 70 ans = ans * x + coef[i]; 71 } 72 return ans ; 73 } 74 75 double polevlRQ(double x, int N ) { 76 77 double coef[8] = { 78 6.20836478118054335476E2, 79 2.56987256757748830383E5, 80 8.35146791431949253037E7, 81 2.21511595479792499675E10, 82 4.74914122079991414898E12, 83 7.84369607876235854894E14, 84 8.95222336184627338078E16, 85 5.32278620332680085395E18 86 }; 87 88 int i = 0; 89 double ans = coef[i]; 90 91 while (i < N) { 92 i++; 93 ans = ans * x + coef[i]; 94 } 95 return ans ; 96 } 97 98 double polevlPP(double x, int N ) { 99 100 double coef[8] = { 101 7.62125616208173112003E-4, 102 7.31397056940917570436E-2, 103 1.12719608129684925192E0, 104 5.11207951146807644818E0, 105 8.42404590141772420927E0, 106 5.21451598682361504063E0, 107 1.00000000000000000254E0, 108 0.0} ; 109 110 int i = 0; 111 double ans = coef[i]; 112 113 while (i < N) { 114 i++; 115 ans = ans * x + coef[i]; 116 } 117 return ans ; 118 } 119 120 double polevlPQ(double x, int N ) { 121 //4: PQ 122 double coef[8] = { 123 5.71323128072548699714E-4, 124 6.88455908754495404082E-2, 125 1.10514232634061696926E0, 126 5.07386386128601488557E0, 127 8.39985554327604159757E0, 128 5.20982848682361821619E0, 129 9.99999999999999997461E-1, 130 0.0 }; 131 132 int i = 0; 133 double ans = coef[i]; 134 135 while (i < N) { 136 i++; 137 ans = ans * x + coef[i]; 138 } 139 return ans ; 140 } 141 142 double polevlQP(double x, int N ) { 143 double coef[8] = { 144 5.10862594750176621635E-2, 145 4.98213872951233449420E0, 146 7.58238284132545283818E1, 147 3.66779609360150777800E2, 148 7.10856304998926107277E2, 149 5.97489612400613639965E2, 150 2.11688757100572135698E2, 151 2.52070205858023719784E1 }; 152 153 int i = 0; 154 double ans = coef[i]; 155 156 while (i < N) { 157 i++; 158 ans = ans * x + coef[i]; 159 } 160 return ans ; 161 162 } 163 164 double polevlQQ(double x, int N ) { 165 double coef[8] = { 166 7.42373277035675149943E1, 167 1.05644886038262816351E3, 168 4.98641058337653607651E3, 169 9.56231892404756170795E3, 170 7.99704160447350683650E3, 171 2.82619278517639096600E3, 172 3.36093607810698293419E2, 173 0.0 }; 174 175 int i = 0; 176 double ans = coef[i]; 177 178 while (i < N) { 179 i++; 180 ans = ans * x + coef[i]; 181 } 182 return ans ; 183 184 } 185 186 double polevlJP( double x, int N ) { 187 double coef[8] = { 188 -4.878788132172128E-009, 189 6.009061827883699E-007, 190 -4.541343896997497E-005, 191 1.937383947804541E-003, 192 -3.405537384615824E-002, 193 0.0, 194 0.0, 195 0.0 196 }; 197 198 int i = 0; 199 double ans = coef[i]; 200 201 while (i < N) { 202 i++; 203 ans = ans * x + coef[i]; 204 } 205 return ans ; 206 207 } 208 209 double polevlMO1( double x, int N ) { 210 double coef[8] = { 211 6.913942741265801E-002, 212 -2.284801500053359E-001, 213 3.138238455499697E-001, 214 -2.102302420403875E-001, 215 5.435364690523026E-003, 216 1.493389585089498E-001, 217 4.976029650847191E-006, 218 7.978845453073848E-001 219 }; 220 221 int i = 0; 222 double ans = coef[i]; 223 224 while (i < N) { 225 i++; 226 ans = ans * x + coef[i]; 227 } 228 return ans ; 229 } 230 231 double polevlPH1( double x, int N ) { 232 233 double coef[8] = { 234 -4.497014141919556E+001, 235 5.073465654089319E+001, 236 -2.485774108720340E+001, 237 7.222973196770240E+000, 238 -1.544842782180211E+000, 239 3.503787691653334E-001, 240 -1.637986776941202E-001, 241 3.749989509080821E-001 242 }; 243 244 int i = 0; 245 double ans = coef[i]; 246 247 while (i < N) { 248 i++; 249 ans = ans * x + coef[i]; 250 } 251 return ans ; 252 } 253 254 /*double polevl( double x, double coef[8], int N ) { 255 256 int i = 0; 257 double ans = coef[i]; 258 259 while (i < N) { 260 i++; 261 ans = ans * x + coef[i]; 262 } 263 264 return ans ; 265 266 }*/ 69 267 70 268 /* p1evl() */ … … 74 272 */ 75 273 76 double p1evl( double x, double coef[8], int N ) { 77 int i=0; 78 double ans = x+coef[i]; 79 80 while (i < N-1) { 81 i++; 82 ans = ans*x + coef[i]; 83 } 84 85 return( ans ); 86 87 } 274 double p1evlRP( double x, int N ) { 275 double coef[8] = { 276 -8.99971225705559398224E8, 277 4.52228297998194034323E11, 278 -7.27494245221818276015E13, 279 3.68295732863852883286E15, 280 0.0, 281 0.0, 282 0.0, 283 0.0 }; 284 285 int i=0; 286 double ans = x+coef[i]; 287 288 while (i < N-1) { 289 i++; 290 ans = ans*x + coef[i]; 291 } 292 293 return( ans ); 294 295 } 296 297 double p1evlRQ( double x, int N ) { 298 //1: RQ 299 double coef[8] = { 300 6.20836478118054335476E2, 301 2.56987256757748830383E5, 302 8.35146791431949253037E7, 303 2.21511595479792499675E10, 304 4.74914122079991414898E12, 305 7.84369607876235854894E14, 306 8.95222336184627338078E16, 307 5.32278620332680085395E18}; 308 309 int i=0; 310 double ans = x+coef[i]; 311 312 while (i < N-1) { 313 i++; 314 ans = ans*x + coef[i]; 315 } 316 317 return( ans ); 318 } 319 320 double p1evlPP( double x, int N ) { 321 //3 : PP 322 double coef[8] = { 323 7.62125616208173112003E-4, 324 7.31397056940917570436E-2, 325 1.12719608129684925192E0, 326 5.11207951146807644818E0, 327 8.42404590141772420927E0, 328 5.21451598682361504063E0, 329 1.00000000000000000254E0, 330 0.0}; 331 332 int i=0; 333 double ans = x+coef[i]; 334 335 while (i < N-1) { 336 i++; 337 ans = ans*x + coef[i]; 338 } 339 340 return( ans ); 341 } 342 343 double p1evlPQ( double x, int N ) { 344 //4: PQ 345 double coef[8] = { 346 5.71323128072548699714E-4, 347 6.88455908754495404082E-2, 348 1.10514232634061696926E0, 349 5.07386386128601488557E0, 350 8.39985554327604159757E0, 351 5.20982848682361821619E0, 352 9.99999999999999997461E-1, 353 0.0}; 354 355 int i=0; 356 double ans = x+coef[i]; 357 358 while (i < N-1) { 359 i++; 360 ans = ans*x + coef[i]; 361 } 362 363 return( ans ); 364 } 365 366 double p1evlQP( double x, int N ) { 367 //5: QP 368 double coef[8] = { 369 5.10862594750176621635E-2, 370 4.98213872951233449420E0, 371 7.58238284132545283818E1, 372 3.66779609360150777800E2, 373 7.10856304998926107277E2, 374 5.97489612400613639965E2, 375 2.11688757100572135698E2, 376 2.52070205858023719784E1 }; 377 378 int i=0; 379 double ans = x+coef[i]; 380 381 while (i < N-1) { 382 i++; 383 ans = ans*x + coef[i]; 384 } 385 386 return( ans ); 387 } 388 389 double p1evlQQ( double x, int N ) { 390 double coef[8] = { 391 7.42373277035675149943E1, 392 1.05644886038262816351E3, 393 4.98641058337653607651E3, 394 9.56231892404756170795E3, 395 7.99704160447350683650E3, 396 2.82619278517639096600E3, 397 3.36093607810698293419E2, 398 0.0}; 399 400 int i=0; 401 double ans = x+coef[i]; 402 403 while (i < N-1) { 404 i++; 405 ans = ans*x + coef[i]; 406 } 407 408 return( ans ); 409 410 } 411 412 double p1evlJP( double x, int N ) { 413 double coef[8] = { 414 -4.878788132172128E-009, 415 6.009061827883699E-007, 416 -4.541343896997497E-005, 417 1.937383947804541E-003, 418 -3.405537384615824E-002, 419 0.0, 420 0.0, 421 0.0}; 422 423 int i=0; 424 double ans = x+coef[i]; 425 426 while (i < N-1) { 427 i++; 428 ans = ans*x + coef[i]; 429 } 430 431 return( ans ); 432 } 433 434 double p1evlMO1( double x, int N ) { 435 double coef[8] = { 436 6.913942741265801E-002, 437 -2.284801500053359E-001, 438 3.138238455499697E-001, 439 -2.102302420403875E-001, 440 5.435364690523026E-003, 441 1.493389585089498E-001, 442 4.976029650847191E-006, 443 7.978845453073848E-001}; 444 445 int i=0; 446 double ans = x+coef[i]; 447 448 while (i < N-1) { 449 i++; 450 ans = ans*x + coef[i]; 451 } 452 453 return( ans ); 454 455 } 456 457 double p1evlPH1( double x, int N ) { 458 double coef[8] = { 459 -4.497014141919556E+001, 460 5.073465654089319E+001, 461 -2.485774108720340E+001, 462 7.222973196770240E+000, 463 -1.544842782180211E+000, 464 3.503787691653334E-001, 465 -1.637986776941202E-001, 466 3.749989509080821E-001}; 467 int i=0; 468 double ans = x+coef[i]; 469 470 while (i < N-1) { 471 i++; 472 ans = ans*x + coef[i]; 473 } 474 475 return( ans ); 476 } 477 478 /*double p1evl( double x, double coef[8], int N ) { 479 int i=0; 480 double ans = x+coef[i]; 481 482 while (i < N-1) { 483 i++; 484 ans = ans*x + coef[i]; 485 } 486 487 return( ans ); 488 489 }*/
Note: See TracChangeset
for help on using the changeset viewer.