Changeset 404ebbd in sasmodels


Ignore:
Timestamp:
Jul 29, 2017 10:56:22 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
48462b0
Parents:
a151caa
Message:

tuned random model generation for more models

Location:
sasmodels/models
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/dab.py

    r4962519 r404ebbd  
    6161    double numerator   = cube(cor_length); 
    6262    double denominator = square(1 + square(q*cor_length)); 
    63      
     63 
    6464    return numerator / denominator ; 
    6565    """ 
     66 
     67def random(): 
     68    import numpy as np 
     69    pars = dict( 
     70        scale=10**np.random.uniform(1, 4), 
     71        cor_length=10**np.random.uniform(0.3, 3), 
     72        #background = 0, 
     73    ) 
     74    pars['scale'] /= pars['cor_length']**3 
     75    return pars 
    6676 
    6777# ER defaults to 1.0 
  • sasmodels/models/ellipsoid.py

    r9b79f29 r404ebbd  
    22# Note: model title and parameter table are inserted automatically 
    33r""" 
    4 The form factor is normalized by the particle volume  
     4The form factor is normalized by the particle volume 
    55 
    66Definition 
     
    119119* **Last Modified by:** Paul Kienzle **Date:** March 22, 2017 
    120120""" 
     121from __future__ import division 
    121122 
    122123from numpy import inf, sin, cos, pi 
     
    177178    delta = 0.75 * b1 * b2 
    178179 
    179     ddd = np.zeros_like(radius_polar) 
     180    #ddd = np.zeros_like(radius_polar) 
    180181    ddd[valid] = 2.0 * (delta + 1.0) * radius_polar * radius_equatorial ** 2 
    181182    return 0.5 * ddd ** (1.0 / 3.0) 
    182183 
     184def random(): 
     185    import numpy as np 
     186    V = 10**np.random.uniform(4, 12) 
     187    radius_polar = 10**np.random.uniform(1.3, 4) 
     188    radius_equatorial = np.sqrt(V/radius_polar) # ignore 4/3 pi 
     189    Vf = 10**np.random.uniform(-4, -2) 
     190    pars = dict( 
     191        #background=0, sld=0, sld_solvent=1, 
     192        scale=1e9*Vf/V, 
     193        radius_polar=radius_polar, 
     194        radius_equatorial=radius_equatorial, 
     195    ) 
     196    return pars 
    183197 
    184198demo = dict(scale=1, background=0, 
  • sasmodels/models/elliptical_cylinder.py

    r9802ab3 r404ebbd  
    3333 
    3434    a = qr'\sin(\alpha) 
    35      
     35 
    3636    b = q\frac{L}{2}\cos(\alpha) 
    37      
     37 
    3838    r'=\frac{r_{minor}}{\sqrt{2}}\sqrt{(1+\nu^{2}) + (1-\nu^{2})cos(\psi)} 
    3939 
     
    5757define the axis of the cylinder using two angles $\theta$, $\phi$ and $\Psi$ 
    5858(see :ref:`cylinder orientation <cylinder-angle-definition>`). The angle 
    59 $\Psi$ is the rotational angle around its own long_c axis.  
     59$\Psi$ is the rotational angle around its own long_c axis. 
    6060 
    6161All angle parameters are valid and given only for 2D calculation; ie, an 
     
    7272    detector plane, with $\Psi$ = 0. 
    7373 
    74 The $\theta$ and $\phi$ parameters to orient the cylinder only appear in the model when fitting 2d data.  
     74The $\theta$ and $\phi$ parameters to orient the cylinder only appear in the model when fitting 2d data. 
    7575On introducing "Orientational Distribution" in the angles, "distribution of theta" and "distribution of phi" parameters will 
    76 appear. These are actually rotations about the axes $\delta_1$ and $\delta_2$ of the cylinder, the $b$ and $a$ axes of the  
    77 cylinder cross section. (When $\theta = \phi = 0$ these are parallel to the $Y$ and $X$ axes of the instrument.)  
    78 The third orientation distribution, in $\psi$, is about the $c$ axis of the particle. Some experimentation may be required to  
    79 understand the 2d patterns fully. (Earlier implementations had numerical integration issues in some circumstances when orientation  
    80 distributions passed through 90 degrees, such situations, with very broad distributions, should still be approached with care.)  
     76appear. These are actually rotations about the axes $\delta_1$ and $\delta_2$ of the cylinder, the $b$ and $a$ axes of the 
     77cylinder cross section. (When $\theta = \phi = 0$ these are parallel to the $Y$ and $X$ axes of the instrument.) 
     78The third orientation distribution, in $\psi$, is about the $c$ axis of the particle. Some experimentation may be required to 
     79understand the 2d patterns fully. (Earlier implementations had numerical integration issues in some circumstances when orientation 
     80distributions passed through 90 degrees, such situations, with very broad distributions, should still be approached with care.) 
    8181 
    8282NB: The 2nd virial coefficient of the cylinder is calculated based on the 
     
    110110 
    111111* **Author:** 
    112 * **Last Modified by:**  
     112* **Last Modified by:** 
    113113* **Last Reviewed by:**  Richard Heenan - corrected equation in docs **Date:** December 21, 2016 
    114114 
     
    156156                           + (length + radius) * (length + pi * radius)) 
    157157    return 0.5 * (ddd) ** (1. / 3.) 
     158 
     159def random(): 
     160    import numpy as np 
     161    # V = pi * radius_major * radius_minor * length; 
     162    V = 10**np.random.uniform(3, 9) 
     163    length = 10**np.random.uniform(1, 3) 
     164    axis_ratio = 10**(4*np.random.uniform(-2, 2) 
     165    radius_minor = np.sqrt(V/length/axis_ratio) 
     166    Vf = 10**np.random.uniform(-4, -2) 
     167    pars = dict( 
     168        #background=0, sld=0, sld_solvent=1, 
     169        scale=1e9*Vf/V, 
     170        length=length, 
     171        radius_minor=radius_minor, 
     172        axis_ratio=axis_ratio, 
     173    ) 
     174    return pars 
     175 
    158176q = 0.1 
    159177# april 6 2017, rkh added a 2d unit test, NOT READY YET pull #890 branch assume correct! 
  • sasmodels/models/fcc_paracrystal.py

    r69e1afc r404ebbd  
    7878.. figure:: img/parallelepiped_angle_definition.png 
    7979 
    80     Orientation of the crystal with respect to the scattering plane, when  
     80    Orientation of the crystal with respect to the scattering plane, when 
    8181    $\theta = \phi = 0$ the $c$ axis is along the beam direction (the $z$ axis). 
    8282 
     
    119119source = ["lib/sas_3j1x_x.c", "lib/gauss150.c", "lib/sphere_form.c", "fcc_paracrystal.c"] 
    120120 
     121def random(): 
     122    import numpy as np 
     123    # Define lattice spacing as a multiple of the particle radius 
     124    # using the formulat a = 4 r/sqrt(3).  Systems which are ordered 
     125    # are probably mostly filled, so use a distribution which goes from 
     126    # zero to one, but leaving 90% of them within 80% of the 
     127    # maximum bcc packing.  Lattice distortion values are empirically 
     128    # useful between 0.01 and 0.7.  Use an exponential distribution 
     129    # in this range 'cuz its easy. 
     130    dnn_fraction = np.random.beta(a=10, b=1) 
     131    pars = dict( 
     132        #sld=1, sld_solvent=0, scale=1, background=1e-32, 
     133        radius=10**np.random.uniform(1.3, 4), 
     134        d_factor=10**np.random.uniform(-2, -0.7),  # sigma_d in 0.01-0.7 
     135    ) 
     136    pars['dnn'] = pars['radius']*4/np.sqrt(3)/dnn_fraction 
     137    #pars['scale'] = 1/(0.68*dnn_fraction**3)  # bcc packing fraction is 0.68 
     138    pars['scale'] = 1 
     139    return pars 
     140 
    121141# parameters for demo 
    122142demo = dict(scale=1, background=0, 
  • sasmodels/models/fractal.py

    rdf89d77 r404ebbd  
    2727 
    2828where $\xi$ is the correlation length representing the cluster size and $D_f$ 
    29 is the fractal dimension, representing the self similarity of the structure.  
    30 Note that S(q) here goes negative if $D_f$ is too large, and the Gamma function  
     29is the fractal dimension, representing the self similarity of the structure. 
     30Note that S(q) here goes negative if $D_f$ is too large, and the Gamma function 
    3131diverges at $D_f=0$ and $D_f=1$. 
    3232 
     
    5555 
    5656""" 
     57from __future__ import division 
    5758 
    5859from numpy import inf 
     
    9899source = ["lib/sas_3j1x_x.c", "lib/sas_gamma.c", "lib/fractal_sq.c", "fractal.c"] 
    99100 
     101def random(): 
     102    import numpy as np 
     103    radius = 10**np.random.uniform(0.7, 4) 
     104    #radius = 5 
     105    cor_length = 10**np.random.uniform(0.7, 2)*radius 
     106    #cor_length = 20*radius 
     107    volfraction = 10**np.random.uniform(-3, -1) 
     108    #volfraction = 0.05 
     109    fractal_dim = 2*np.random.beta(3, 4) + 1 
     110    #fractal_dim = 2 
     111    pars = dict( 
     112        #background=0, sld_block=1, sld_solvent=0, 
     113        scale=1e4/radius**(fractal_dim/2), 
     114        volfraction=volfraction, 
     115        radius=radius, 
     116        cor_length=cor_length, 
     117        fractal_dim=fractal_dim, 
     118    ) 
     119    return pars 
     120 
    100121demo = dict(volfraction=0.05, 
    101122            radius=5.0, 
  • sasmodels/models/fractal_core_shell.py

    r925ad6e r404ebbd  
    2424    \frac{\sin(qr_s)-qr_s\cos(qr_s)}{(qr_s)^3}\right]^2 
    2525 
    26     S(q) &= 1 + \frac{D_f\ \Gamma\!(D_f-1)}{[1+1/(q\xi)^2]^{(D_f-1)/2}}  
     26    S(q) &= 1 + \frac{D_f\ \Gamma\!(D_f-1)}{[1+1/(q\xi)^2]^{(D_f-1)/2}} 
    2727    \frac{\sin[(D_f-1)\tan^{-1}(q\xi)]}{(qr_s)^{D_f}} 
    2828 
     
    3333of the whole particle respectively, $D_f$ is the fractal dimension, and |xi| the 
    3434correlation length. 
    35   
     35 
    3636Polydispersity of radius and thickness are also provided for. 
    3737 
     
    9898          "lib/fractal_sq.c", "fractal_core_shell.c"] 
    9999 
     100def random(): 
     101    import numpy as np 
     102    total_radius = 10**np.random.uniform(0.7, 4) 
     103    core_portion = np.random.uniform(0, 1) 
     104    radius = total_radius * core_portion 
     105    thickness = total_radius - radius 
     106    #radius = 5 
     107    cor_length = 10**np.random.uniform(0.7, 2)*radius 
     108    #cor_length = 20*radius 
     109    volfraction = 10**np.random.uniform(-3, -1) 
     110    #volfraction = 0.05 
     111    fractal_dim = 2*np.random.beta(3, 4) + 1 
     112    #fractal_dim = 2 
     113    pars = dict( 
     114        #background=0, sld_block=1, sld_solvent=0, 
     115        scale=1e3/total_radius**(fractal_dim/2), 
     116        volfraction=volfraction, 
     117        radius=radius, 
     118        cor_length=cor_length, 
     119        fractal_dim=fractal_dim, 
     120    ) 
     121    return pars 
     122 
     123 
    100124demo = dict(scale=0.05, 
    101125            background=0, 
  • sasmodels/models/guinier.py

    r3330bb4 r404ebbd  
    3333description = """ 
    3434 I(q) = scale.exp ( - rg^2 q^2 / 3.0 ) 
    35   
     35 
    3636    List of default parameters: 
    3737    scale = scale 
     
    4949""" 
    5050 
     51def random(): 
     52    import numpy as np 
     53    scale = 10**np.random.uniform(1, 5) 
     54    # Note: compare.py has rg cutoff for guinier, so use that 
     55    q_max = 1.0 
     56    rg_max = np.sqrt(90*np.log(10) + 3*np.log(scale))/q_max 
     57    rg = 10**np.random.uniform(0, np.log10(rg_max)) 
     58    pars = dict( 
     59        #background=0, 
     60        scale=scale, 
     61        rg=rg, 
     62    ) 
     63    return pars 
     64 
    5165# parameters for demo 
    5266demo = dict(scale=1.0, rg=60.0) 
  • sasmodels/models/lamellar.py

    r40a87fa r404ebbd  
    8989    """ 
    9090 
     91def random(): 
     92    import numpy as np 
     93    thickness = 10**np.random.uniform(1, 4) 
     94    scale = thickness * 10**np.random.uniform(-7, -4) 
     95    pars = dict( 
     96        scale=scale, 
     97        thickness=thickness, 
     98    ) 
     99    return pars 
     100 
    91101# ER defaults to 0.0 
    92102# VR defaults to 1.0 
  • sasmodels/models/lamellar_hg.py

    ra807206 r404ebbd  
    9898    """ 
    9999 
     100def random(): 
     101    import numpy as np 
     102    thickness = 10**np.random.uniform(1, 4) 
     103    length_head = thickness * np.random.uniform(0, 1) 
     104    length_tail = thickness - length_head 
     105    scale = thickness * 10**np.random.uniform(-7, -4) 
     106    pars = dict( 
     107        scale=scale, 
     108        length_head=length_head, 
     109        length_tail=length_tail, 
     110    ) 
     111    return pars 
     112 
    100113# ER defaults to 0.0 
    101114# VR defaults to 1.0 
  • sasmodels/models/lamellar_hg_stack_caille.py

    ra57b31d r404ebbd  
    123123# VR defaults to 1.0 
    124124 
     125def random(): 
     126    import numpy as np 
     127    total_thickness = 10**np.random.uniform(2, 4.7) 
     128    Nlayers = np.random.randint(2, 200) 
     129    d_spacing = total_thickness / Nlayers 
     130    thickness = d_spacing * np.random.uniform(0, 1) 
     131    length_head = thickness * np.random.uniform(0, 1) 
     132    length_tail = thickness - length_head 
     133    Caille_parameter = np.random.uniform(0, 0.8) 
     134    scale = thickness * 10**np.random.uniform(-7, -4) 
     135    pars = dict( 
     136        scale=1, 
     137        length_head=length_head, 
     138        length_tail=length_tail, 
     139        Nlayers=Nlayers, 
     140        d_spacing=d_spacing, 
     141        Caille_parameter=Caille_parameter, 
     142    ) 
     143    return pars 
     144 
    125145demo = dict( 
    126146    scale=1, background=0, 
  • sasmodels/models/lamellar_stack_caille.py

    ra57b31d r404ebbd  
    9898source = ["lamellar_stack_caille.c"] 
    9999 
     100def random(): 
     101    import numpy as np 
     102    total_thickness = 10**np.random.uniform(2, 4.7) 
     103    Nlayers = np.random.randint(2, 200) 
     104    d_spacing = total_thickness / Nlayers 
     105    thickness = d_spacing * np.random.uniform(0, 1) 
     106    Caille_parameter = np.random.uniform(0, 0.8) 
     107    scale = thickness * 10**np.random.uniform(-7, -4) 
     108    pars = dict( 
     109        scale=1, 
     110        thickness=thickness, 
     111        Nlayers=Nlayers, 
     112        d_spacing=d_spacing, 
     113        Caille_parameter=Caille_parameter, 
     114    ) 
     115    return pars 
     116 
    100117# No volume normalization despite having a volume parameter 
    101118# This should perhaps be volume normalized? 
  • sasmodels/models/lamellar_stack_paracrystal.py

    ra0168e8 r404ebbd  
    130130form_volume = """ 
    131131    return 1.0; 
    132     """ 
     132""" 
     133 
     134def random(): 
     135    import numpy as np 
     136    total_thickness = 10**np.random.uniform(2, 4.7) 
     137    Nlayers = np.random.randint(2, 200) 
     138    d_spacing = total_thickness / Nlayers 
     139    thickness = d_spacing * np.random.uniform(0, 1) 
     140    # Let polydispersity peak around 15%; 95% < 0.4; max=100% 
     141    sigma_d = np.random.beta(1.5, 7) 
     142    scale = thickness * 10**np.random.uniform(-7, -4) 
     143    pars = dict( 
     144        scale=1, 
     145        thickness=thickness, 
     146        Nlayers=Nlayers, 
     147        d_spacing=d_spacing, 
     148        sigma_d=sigma_d, 
     149    ) 
     150    return pars 
    133151 
    134152# ER defaults to 0.0 
  • sasmodels/models/line.py

    r3330bb4 r404ebbd  
    6868Iqxy.vectorized = True  # Iqxy accepts an array of qx qy values 
    6969 
     70def random(): 
     71    import numpy as np 
     72    slope = 1e5*np.random.uniform(-1, 1) 
     73    offset = 1e-5 + (0 if slope > 0 else -slope) 
     74    intercept = 10**np.random.uniform(0, 5) + offset 
     75    pars = dict( 
     76        scale=1, background=0, 
     77        slope=slope, 
     78        intercept=intercept, 
     79    ) 
     80    return pars 
    7081 
    7182tests = [ 
  • sasmodels/models/lorentz.py

    r2c74c11 r404ebbd  
    3030description = """ 
    3131Model that evaluates a Lorentz (Ornstein-Zernicke) model. 
    32          
     32 
    3333I(q) = scale/( 1 + (q*L)^2 ) + bkd 
    34          
    35 The model has three parameters:  
    36     length     = screening Length 
    37     scale  = scale factor 
    38     background    = incoherent background 
     34 
     35The model has three parameters: 
     36    length = screening Length 
     37    scale = scale factor 
     38    background = incoherent background 
    3939""" 
    4040category = "shape-independent" 
     
    4848""" 
    4949 
     50def random(): 
     51    import numpy as np 
     52    pars = dict( 
     53        #background=0, 
     54        scale=10**np.random.uniform(1, 4), 
     55        cor_length=10**np.random.uniform(0, 3), 
     56    ) 
     57    return pars 
     58 
    5059# parameters for demo 
    5160demo = dict(scale=1.0, background=0.0, cor_length=50.0) 
  • sasmodels/models/mass_fractal.py

    r925ad6e r404ebbd  
    8888source = ["lib/sas_3j1x_x.c", "lib/sas_gamma.c", "mass_fractal.c"] 
    8989 
     90def random(): 
     91    import numpy as np 
     92    radius = 10**np.random.uniform(0.7, 4) 
     93    cutoff_length = 10**np.random.uniform(0.7, 2)*radius 
     94    fractal_dim_mass = 2*np.random.beta(3, 4) + 1 
     95    Vf = 10**np.random.uniform(-4, -1) 
     96    pars = dict( 
     97        #background=0, 
     98        scale=1, #1e5*Vf/radius**(fractal_dim_mass), 
     99        radius=radius, 
     100        cutoff_length=cutoff_length, 
     101        fractal_dim_mass=fractal_dim_mass, 
     102    ) 
     103    return pars 
     104 
    90105demo = dict(scale=1, background=0, 
    91106            radius=10.0, 
  • sasmodels/models/mass_surface_fractal.py

    r6d96b66 r404ebbd  
    8989source = ["mass_surface_fractal.c"] 
    9090 
     91def random(): 
     92    import numpy as np 
     93    fractal_dim = np.random.uniform(1, 6) 
     94    surface_portion = np.random.uniform(0, 1) 
     95    fractal_dim_surf = fractal_dim*surface_portion 
     96    fractal_dim_mass = fractal_dim - fractal_dim_surf 
     97    rg_cluster = 10**np.random.uniform(1, 5) 
     98    rg_primary = rg_cluster*10**np.random.uniform(-4, -1) 
     99    scale = 10**np.random.uniform(2, 5) 
     100    pars = dict( 
     101        #background=0, 
     102        scale=scale, 
     103        fractal_dim_mass=fractal_dim_mass, 
     104        fractal_dim_surf=fractal_dim_surf, 
     105        rg_cluster=rg_cluster, 
     106        rg_primary=rg_primary, 
     107    ) 
     108    return pars 
     109 
     110 
    91111demo = dict(scale=1, background=0, 
    92112            fractal_dim_mass=1.8, 
  • sasmodels/models/mono_gauss_coil.py

    r3330bb4 r404ebbd  
    6262 
    6363description = """ 
    64     Evaluates the scattering from  
     64    Evaluates the scattering from 
    6565    monodisperse polymer chains. 
    6666    """ 
     
    8686Iq.vectorized = True # Iq accepts an array of q values 
    8787 
     88def random(): 
     89    import numpy as np 
     90    rg = 10**np.random.uniform(0, 4) 
     91    #rg = 1e3 
     92    pars = dict( 
     93        #scale=1, background=0, 
     94        i_zero=1e7, # i_zero is a simple scale 
     95        rg=rg, 
     96    ) 
     97    return pars 
     98 
    8899demo = dict(scale=1.0, i_zero=70.0, rg=75.0, background=0.0) 
    89100 
  • sasmodels/models/peak_lorentz.py

    r2c74c11 r404ebbd  
    5959Iq.vectorized = True  # Iq accepts an array of q values 
    6060 
     61def random(): 
     62    import numpy as np 
     63    peak_pos = 10**np.random.uniform(-3, -1) 
     64    peak_hwhm = peak_pos * 10**np.random.uniform(-3, 0) 
     65    pars = dict( 
     66        #background=0, 
     67        scale=10**np.random.uniform(2, 6), 
     68        peak_pos=peak_pos, 
     69        peak_hwhm=peak_hwhm, 
     70    ) 
     71    return pars 
     72 
    6173demo = dict(scale=100, background=1.0, 
    6274            peak_pos=0.05, peak_hwhm=0.005) 
  • sasmodels/models/poly_gauss_coil.py

    r3330bb4 r404ebbd  
    6666 
    6767description = """ 
    68     Evaluates the scattering from  
     68    Evaluates the scattering from 
    6969    polydisperse polymer chains. 
    7070    """ 
     
    9696        p = [ 
    9797            #(-1 - 20*u - 155*u**2 - 580*u**3 - 1044*u**4 - 720*u**5) / 2520., 
    98             #( 1 + 14*u + 71*u**2 + 154*u**3 + 120*u**4) / 360., 
     98            #(+1 + 14*u + 71*u**2 + 154*u**3 + 120*u**4) / 360., 
    9999            #(-1 - 9*u - 26*u**2 - 24*u**3) / 60., 
    100             ( 1 + 5*u + 6*u**2) / 12., 
     100            (+1 + 5*u + 6*u**2) / 12., 
    101101            (-1 - 2*u) / 3., 
    102             ( 1 ), 
     102            (+1), 
    103103            ] 
    104104        result = 2.0 * (power(1.0 + u*z, -1.0/u) + z - 1.0) / (1.0 + u) 
     
    108108    return i_zero * result 
    109109Iq.vectorized = True  # Iq accepts an array of q values 
     110 
     111def random(): 
     112    import numpy as np 
     113    rg = 10**np.random.uniform(0, 4) 
     114    #rg = 1e3 
     115    polydispersity = 10**np.random.uniform(0, 3) 
     116    pars = dict( 
     117        #scale=1, background=0, 
     118        i_zero=1e7, # i_zero is a simple scale 
     119        rg=rg, 
     120        polydispersity=polydispersity, 
     121    ) 
     122    return pars 
    110123 
    111124demo = dict(scale=1.0, 
  • sasmodels/models/polymer_excl_volume.py

    r40a87fa r404ebbd  
    108108#   ["name", "units", default, [lower, upper], "type", "description"], 
    109109parameters = [ 
    110     ["rg",        "Ang", 60.0, [0, inf],    "", "Radius of Gyration"], 
    111     ["porod_exp", "",     3.0, [-inf, inf], "", "Porod exponent"], 
     110    ["rg",        "Ang", 60.0, [0, inf], "", "Radius of Gyration"], 
     111    ["porod_exp", "",     3.0, [0, inf], "", "Porod exponent"], 
    112112] 
    113113# pylint: enable=bad-whitespace, line-too-long 
     
    133133Iq.vectorized = True  # Iq accepts an array of q values 
    134134 
     135def random(): 
     136    import numpy as np 
     137    rg = 10**np.random.uniform(0, 4) 
     138    porod_exp = np.random.uniform(1e-3, 6) 
     139    scale = 10**np.random.uniform(1, 5) 
     140    pars = dict( 
     141        #background=0, 
     142        scale=scale, 
     143        rg=rg, 
     144        porod_exp=porod_exp, 
     145    ) 
     146    return pars 
     147 
    135148tests = [ 
    136149    # Accuracy tests based on content in test/polyexclvol_default_igor.txt 
  • sasmodels/models/polymer_micelle.py

    r925ad6e r404ebbd  
    1616which then defines a micelle core of $radius\_core$, which is a separate parameter 
    1717even though it could be directly determined. 
    18 The Gaussian random coil tails, of gyration radius $rg$, are imagined uniformly  
     18The Gaussian random coil tails, of gyration radius $rg$, are imagined uniformly 
    1919distributed around the spherical core, centred at a distance $radius\_core + d\_penetration.rg$ 
    2020from the micelle centre, where $d\_penetration$ is of order unity. 
     
    2727.. math:: 
    2828    P(q) = N^2\beta^2_s\Phi(qR)^2+N\beta^2_cP_c(q)+2N^2\beta_s\beta_cS_{sc}s_c(q)+N(N-1)\beta_c^2S_{cc}(q) 
    29      
     29 
    3030    \beta_s = v\_core(sld\_core - sld\_solvent) 
    31      
     31 
    3232    \beta_c = v\_corona(sld\_corona - sld\_solvent) 
    3333 
    34 where $N = n\_aggreg$, and for the spherical core of radius $R$  
     34where $N = n\_aggreg$, and for the spherical core of radius $R$ 
    3535 
    36 .. math::    
     36.. math:: 
    3737   \Phi(qR)= \frac{\sin(qr) - qr\cos(qr)}{(qr)^3} 
    3838 
     
    4949 
    5050.. math:: 
    51     
     51 
    5252   S_{sc}(q)=\Phi(qR)\psi(Z)\frac{sin(q(R+d.R_g))}{q(R+d.R_g)} 
    53     
     53 
    5454   S_{cc}(q)=\psi(Z)^2\left[\frac{sin(q(R+d.R_g))}{q(R+d.R_g)} \right ]^2 
    55     
     55 
    5656   \psi(Z)=\frac{[1-exp^{-Z}]}{Z} 
    5757 
     
    6060 
    6161$P(q)$ above is multiplied by $ndensity$, and a units conversion of 10^{-13}, so $scale$ 
    62 is likely 1.0 if the scattering data is in absolute units. This model has not yet been  
     62is likely 1.0 if the scattering data is in absolute units. This model has not yet been 
    6363independently validated. 
    6464 
     
    7171""" 
    7272 
    73 from numpy import inf 
     73from numpy import inf, pi 
    7474 
    7575name = "polymer_micelle" 
     
    8080to block copolymer micelles. To work well the Gaussian chains must be much 
    8181smaller than the core, which is often not the case.  Please study the 
    82 reference to Pedersen and full documentation carefully.  
     82reference to Pedersen and full documentation carefully. 
    8383    """ 
    8484 
     
    106106source = ["lib/sas_3j1x_x.c", "polymer_micelle.c"] 
    107107 
    108 demo = dict(scale=1, background=0, 
    109             ndensity=8.94, 
    110             v_core=62624.0, 
    111             v_corona=61940.0, 
    112             sld_solvent=6.4, 
    113             sld_core=0.34, 
    114             sld_corona=0.8, 
    115             radius_core=45.0, 
    116             rg=20.0, 
    117             d_penetration=1.0, 
    118             n_aggreg=6.0) 
    119  
     108def random(): 
     109    import numpy as np 
     110    radius_core = 10**np.random.uniform(1, 3) 
     111    rg = radius_core * 10**np.random.uniform(-2, -0.3) 
     112    d_penetration = np.random.randn()*0.05 + 1 
     113    n_aggreg = np.random.randint(3, 30) 
     114    # volume of head groups is the core volume over the number of groups, 
     115    # with a correction for packing fraction of the head groups. 
     116    v_core = 4*pi/3*radius_core**3/n_aggreg * 0.68 
     117    # Rg^2 for gaussian coil is a^2n/6 => a^2 = 6 Rg^2/n 
     118    # a=2r => r = Rg sqrt(3/2n) 
     119    # v = 4/3 pi r^3 n => v = 4/3 pi Rg^3 (3/2n)^(3/2) n = pi Rg^3 sqrt(6/n) 
     120    tail_segments = np.random.randint(6, 30) 
     121    v_corona = pi * rg**3 * np.sqrt(6/tail_segments) 
     122    V = 4*pi/3*(radius_core + rg)**3 
     123    pars = dict( 
     124        background=0, 
     125        scale=1e7/V, 
     126        ndensity=8.94, 
     127        v_core=v_core, 
     128        v_corona=v_corona, 
     129        radius_core=radius_core, 
     130        rg=rg, 
     131        d_penetration=d_penetration, 
     132        n_aggreg=n_aggreg, 
     133    ) 
     134    return pars 
    120135 
    121136tests = [ 
  • sasmodels/models/power_law.py

    r40a87fa r404ebbd  
    5050Iq.vectorized = True  # Iq accepts an array of q values 
    5151 
     52def random(): 
     53    import numpy as np 
     54    power = np.random.uniform(1, 6) 
     55    pars = dict( 
     56        scale=0.1**power*10**np.random.uniform(-4, 2), 
     57        power=power, 
     58    ) 
     59    return pars 
     60 
    5261demo = dict(scale=1.0, power=4.0, background=0.0) 
    5362 
  • sasmodels/models/sc_paracrystal.py

    r69e1afc r404ebbd  
    138138source = ["lib/sas_3j1x_x.c", "lib/sphere_form.c", "lib/gauss150.c", "sc_paracrystal.c"] 
    139139 
     140def random(): 
     141    import numpy as np 
     142    # Define lattice spacing as a multiple of the particle radius 
     143    # using the formulat a = 4 r/sqrt(3).  Systems which are ordered 
     144    # are probably mostly filled, so use a distribution which goes from 
     145    # zero to one, but leaving 90% of them within 80% of the 
     146    # maximum bcc packing.  Lattice distortion values are empirically 
     147    # useful between 0.01 and 0.7.  Use an exponential distribution 
     148    # in this range 'cuz its easy. 
     149    dnn_fraction = np.random.beta(a=10, b=1) 
     150    pars = dict( 
     151        #sld=1, sld_solvent=0, scale=1, background=1e-32, 
     152        radius=10**np.random.uniform(1.3, 4), 
     153        d_factor=10**np.random.uniform(-2, -0.7),  # sigma_d in 0.01-0.7 
     154    ) 
     155    pars['dnn'] = pars['radius']*4/np.sqrt(3)/dnn_fraction 
     156    #pars['scale'] = 1/(0.68*dnn_fraction**3)  # bcc packing fraction is 0.68 
     157    pars['scale'] = 1 
     158    return pars 
     159 
    140160demo = dict(scale=1, background=0, 
    141161            dnn=220.0, 
  • sasmodels/models/sphere.py

    r925ad6e r404ebbd  
    8484    return radius 
    8585 
     86def random(): 
     87    import numpy as np 
     88    Vf = 10**np.random.uniform(-4, -2) 
     89    radius = 10**np.random.uniform(1.3, 4) 
     90    V = radius**3 
     91    pars = dict( 
     92        #background=0, sld=1, sld_solvent=0, 
     93        scale=1e10*Vf/V, 
     94        radius=radius, 
     95    ) 
     96    return pars 
     97 
    8698# VR defaults to 1.0 
    8799 
Note: See TracChangeset for help on using the changeset viewer.