Changes in / [a5af4e1:7904790] in sasmodels
- Files:
-
- 10 added
- 7 deleted
- 17 edited
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/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 = []
Note: See TracChangeset
for help on using the changeset viewer.