Changeset 8f04da4 in sasmodels


Ignore:
Timestamp:
Aug 2, 2017 12:53:56 AM (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:
bd21b12
Parents:
1511c37c
Message:

tuned random model generation for more models

Location:
sasmodels
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    r31df0c9 r8f04da4  
    763763    for k in range(opts['sets']): 
    764764        opts['pars'] = parse_pars(opts) 
     765        if opts['pars'] is None: 
     766            return 
    765767        result = run_models(opts, verbose=True) 
    766768        if opts['plot']: 
     
    13951397        elif opts['explore']: 
    13961398            opts['pars'] = parse_pars(opts) 
     1399            if opts['pars'] is None: 
     1400                return 
    13971401            explore(opts) 
    13981402        else: 
  • sasmodels/models/adsorbed_layer.py

    r0bdddc2 r8f04da4  
    9999    #    scale = 6 pi/100 (contrast/density*absorbed_amount)^2 * Vf/radius 
    100100    # the remaining parameters can be randomly generated from zero to 
    101     # twice the default value. 
     101    # twice the default value as done by default in compare.py 
    102102    import numpy as np 
    103103    pars = dict( 
  • sasmodels/models/bcc_paracrystal.py

    r1511c37c r8f04da4  
    154154# april 6 2017, rkh add unit tests, NOT compared with any other calc method, assume correct! 
    155155# add 2d test later 
    156 q =4.*pi/220. 
     156q = 4.*pi/220. 
    157157tests = [ 
    158     [{ }, 
    159      [0.001, q, 0.215268], [1.46601394721, 2.85851284174, 0.00866710287078]], 
     158    [{}, [0.001, q, 0.215268], [1.46601394721, 2.85851284174, 0.00866710287078]], 
    160159    [{'theta': 20.0, 'phi': 30, 'psi': 40.0}, (-0.017, 0.035), 2082.20264399], 
    161160    [{'theta': 20.0, 'phi': 30, 'psi': 40.0}, (-0.081, 0.011), 0.436323144781], 
  • sasmodels/models/be_polyelectrolyte.py

    ra151caa r8f04da4  
    141141def random(): 
    142142    import numpy as np 
     143    # TODO: review random be_polyelectrolyte model generation 
    143144    pars = dict( 
    144145        scale=10000, #background=0, 
  • sasmodels/models/binary_hard_sphere.py

    r925ad6e r8f04da4  
    110110source = ["lib/sas_3j1x_x.c", "binary_hard_sphere.c"] 
    111111 
     112def random(): 
     113    import numpy as np 
     114    # TODO: binary_hard_sphere fails at low qr 
     115    radius_lg = 10**np.random.uniform(2, 4.7) 
     116    radius_sm = 10**np.random.uniform(2, 4.7) 
     117    volfraction_lg = 10**np.random.uniform(-3, -0.3) 
     118    volfraction_sm = 10**np.random.uniform(-3, -0.3) 
     119    # TODO: Get slightly different results if large and small are swapped 
     120    # modify the model so it doesn't care which is which 
     121    if radius_lg < radius_sm: 
     122        radius_lg, radius_sm = radius_sm, radius_lg 
     123        volfraction_lg, volfraction_sm = volfraction_sm, volfraction_lg 
     124    pars = dict( 
     125        radius_lg=radius_lg, 
     126        radius_sm=radius_sm, 
     127        volfraction_lg=volfraction_lg, 
     128        volfraction_sm=volfraction_sm, 
     129    ) 
     130    return pars 
     131 
    112132# parameters for demo and documentation 
    113133demo = dict(sld_lg=3.5, sld_sm=0.5, sld_solvent=6.36, 
  • sasmodels/models/core_shell_bicelle_elliptical.py

    r9802ab3 r8f04da4  
    66core-shell scattering length density profile. Thus this is a variation 
    77of the core-shell bicelle model, but with an elliptical cylinder for the core. 
    8 Outer shells on the rims and flat ends may be of different thicknesses and  
     8Outer shells on the rims and flat ends may be of different thicknesses and 
    99scattering length densities. The form factor is normalized by the total particle volume. 
    1010 
     
    1717.. figure:: img/core_shell_bicelle_parameters.png 
    1818 
    19    Cross section of model used here. Users will have  
    20    to decide how to distribute "heads" and "tails" between the rim, face  
     19   Cross section of model used here. Users will have 
     20   to decide how to distribute "heads" and "tails" between the rim, face 
    2121   and core regions in order to estimate appropriate starting parameters. 
    2222 
     
    2727.. math:: 
    2828 
    29     \rho(r) =  
    30       \begin{cases}  
     29    \rho(r) = 
     30      \begin{cases} 
    3131      &\rho_c \text{ for } 0 \lt r \lt R; -L \lt z\lt L \\[1.5ex] 
    3232      &\rho_f \text{ for } 0 \lt r \lt R; -(L+2t) \lt z\lt -L; 
     
    4848.. math:: 
    4949 
    50         \begin{align}     
    51     F(Q,\alpha,\psi) = &\bigg[  
     50        \begin{align} 
     51    F(Q,\alpha,\psi) = &\bigg[ 
    5252    (\rho_c - \rho_f) V_c \frac{2J_1(QR'sin \alpha)}{QR'sin\alpha}\frac{sin(QLcos\alpha/2)}{Q(L/2)cos\alpha} \\ 
    5353    &+(\rho_f - \rho_r) V_{c+f} \frac{2J_1(QR'sin\alpha)}{QR'sin\alpha}\frac{sin(Q(L/2+t_f)cos\alpha)}{Q(L/2+t_f)cos\alpha} \\ 
    5454    &+(\rho_r - \rho_s) V_t \frac{2J_1(Q(R'+t_r)sin\alpha)}{Q(R'+t_r)sin\alpha}\frac{sin(Q(L/2+t_f)cos\alpha)}{Q(L/2+t_f)cos\alpha} 
    5555    \bigg] 
    56     \end{align}  
     56    \end{align} 
    5757 
    5858where 
     
    6161 
    6262    R'=\frac{R}{\sqrt{2}}\sqrt{(1+X_{core}^{2}) + (1-X_{core}^{2})cos(\psi)} 
    63      
    64      
    65 and $V_t = \pi.(R+t_r)(Xcore.R+t_r)^2.(L+2.t_f)$ is the total volume of the bicelle,  
    66 $V_c = \pi.Xcore.R^2.L$ the volume of the core, $V_{c+f} = \pi.Xcore.R^2.(L+2.t_f)$  
     63 
     64 
     65and $V_t = \pi.(R+t_r)(Xcore.R+t_r)^2.(L+2.t_f)$ is the total volume of the bicelle, 
     66$V_c = \pi.Xcore.R^2.L$ the volume of the core, $V_{c+f} = \pi.Xcore.R^2.(L+2.t_f)$ 
    6767the volume of the core plus the volume of the faces, $R$ is the radius 
    68 of the core, $Xcore$ is the axial ratio of the core, $L$ the length of the core,  
    69 $t_f$ the thickness of the face, $t_r$ the thickness of the rim and $J_1$ the usual  
    70 first order bessel function. The core has radii $R$ and $Xcore.R$ so is circular,  
    71 as for the core_shell_bicelle model, for $Xcore$ =1. Note that you may need to  
    72 limit the range of $Xcore$, especially if using the Monte-Carlo algorithm, as  
     68of the core, $Xcore$ is the axial ratio of the core, $L$ the length of the core, 
     69$t_f$ the thickness of the face, $t_r$ the thickness of the rim and $J_1$ the usual 
     70first order bessel function. The core has radii $R$ and $Xcore.R$ so is circular, 
     71as for the core_shell_bicelle model, for $Xcore$ =1. Note that you may need to 
     72limit the range of $Xcore$, especially if using the Monte-Carlo algorithm, as 
    7373setting radius to $R/Xcore$ and axial ratio to $1/Xcore$ gives an equivalent solution! 
    7474 
     
    7676bicelles is then given by integrating over all possible $\alpha$ and $\psi$. 
    7777 
    78 For oriented bicelles the *theta*, *phi* and *psi* orientation parameters will appear when fitting 2D data,  
     78For oriented bicelles the *theta*, *phi* and *psi* orientation parameters will appear when fitting 2D data, 
    7979see the :ref:`elliptical-cylinder` model for further information. 
    8080 
     
    8282.. figure:: img/elliptical_cylinder_angle_definition.png 
    8383 
    84     Definition of the angles for the oriented core_shell_bicelle_elliptical particles.    
     84    Definition of the angles for the oriented core_shell_bicelle_elliptical particles. 
    8585 
    8686 
     
    105105description = """ 
    106106    core_shell_bicelle_elliptical 
    107     Elliptical cylinder core, optional shell on the two flat faces, and shell of  
    108     uniform thickness on its rim (extending around the end faces).     
     107    Elliptical cylinder core, optional shell on the two flat faces, and shell of 
     108    uniform thickness on its rim (extending around the end faces). 
    109109    Please see full documentation for equations and further details. 
    110110    Involves a double numerical integral around the ellipsoid diameter 
     
    136136          "core_shell_bicelle_elliptical.c"] 
    137137 
    138 demo = dict(scale=1, background=0, 
    139             radius=30.0, 
    140             x_core=3.0, 
    141             thick_rim=8.0, 
    142             thick_face=14.0, 
    143             length=50.0, 
    144             sld_core=4.0, 
    145             sld_face=7.0, 
    146             sld_rim=1.0, 
    147             sld_solvent=6.0, 
    148             theta=90, 
    149             phi=0, 
    150             psi=0) 
     138def random(): 
     139    import numpy as np 
     140    outer_major = 10**np.random.uniform(1, 4.7) 
     141    outer_minor = 10**np.random.uniform(1, 4.7) 
     142    # Use a distribution with a preference for thin shell or thin core, 
     143    # limited by the minimum radius. Avoid core,shell radii < 1 
     144    min_radius = min(outer_major, outer_minor) 
     145    thick_rim = np.random.beta(0.5, 0.5)*(min_radius-2) + 1 
     146    radius_major = outer_major - thick_rim 
     147    radius_minor = outer_minor - thick_rim 
     148    radius = radius_major 
     149    x_core = radius_minor/radius_major 
     150    outer_length = 10**np.random.uniform(1, 4.7) 
     151    # Caps should be a small percentage of the total length, but at least one 
     152    # angstrom long.  Since outer length >= 10, the following will suffice 
     153    thick_face = 10**np.random.uniform(-np.log10(outer_length), -1)*outer_length 
     154    length = outer_length - thick_face 
     155    pars = dict( 
     156        radius=radius, 
     157        x_core=x_core, 
     158        thick_rim=thick_rim, 
     159        thick_face=thick_face, 
     160        length=length 
     161    ) 
     162    return pars 
     163 
    151164 
    152165q = 0.1 
  • sasmodels/models/core_shell_cylinder.py

    r9b79f29 r8f04da4  
    142142    return whole, whole - core 
    143143 
     144def random(): 
     145    import numpy as np 
     146    outer_radius = 10**np.random.uniform(1, 4.7) 
     147    # Use a distribution with a preference for thin shell or thin core 
     148    # Avoid core,shell radii < 1 
     149    radius = np.random.beta(0.5, 0.5)*(outer_radius-2) + 1 
     150    thickness = outer_radius - core 
     151    length = np.random.uniform(1, 4.7) 
     152    pars = dict( 
     153        radius=radius, 
     154        thickness=thickness, 
     155        length=length, 
     156    ) 
     157    return pars 
     158 
    144159demo = dict(scale=1, background=0, 
    145160            sld_core=6, sld_shell=8, sld_solvent=1, 
  • sasmodels/models/core_shell_ellipsoid.py

    r31df0c9 r8f04da4  
    154154    import numpy as np 
    155155    V = 10**np.random.uniform(5, 12) 
    156     radius_polar = 10**np.random.uniform(1.3, 4) 
    157     radius_equatorial = np.sqrt(V/radius_polar) # ignore 4/3 pi 
    158     thickness_polar = np.random.uniform(0.01, 1)*radius_polar 
    159     thickness_equatorial = np.random.uniform(0.01, 1)*radius_equatorial 
    160     radius_polar -= thickness_polar 
    161     radius_equatorial -= thickness_equatorial 
     156    outer_polar = 10**np.random.uniform(1.3, 4) 
     157    outer_equatorial = np.sqrt(V/radius_polar) # ignore 4/3 pi 
     158    # Use a distribution with a preference for thin shell or thin core 
     159    # Avoid core,shell radii < 1 
     160    thickness_polar = np.random.beta(0.5, 0.5)*(outer__polar-2) + 1 
     161    thickness_equatorial = np.random.beta(0.5, 0.5)*(outer_equatorial-2) + 1 
     162    radius_polar = outer_polar - thickness_polar 
     163    radius_equatorial = outer_equatorial - thickness_equatorial 
    162164    x_core = radius_polar/radius_equatorial 
    163165    x_polar_shell = thickness_polar/thickness_equatorial 
  • sasmodels/models/core_shell_parallelepiped.py

    r9b79f29 r8f04da4  
    44 
    55Calculates the form factor for a rectangular solid with a core-shell structure. 
    6 The thickness and the scattering length density of the shell or  
     6The thickness and the scattering length density of the shell or 
    77"rim" can be different on each (pair) of faces. However at this time 
    88the 1D calculation does **NOT** actually calculate a c face rim despite the presence of 
     
    4242 
    4343**meaning that there are "gaps" at the corners of the solid.**  Again note that 
    44 $t_C = 0$ currently.  
     44$t_C = 0$ currently. 
    4545 
    4646The intensity calculated follows the :ref:`parallelepiped` model, with the 
     
    8282based on the the averaged effective radius $(=\sqrt{(A+2t_A)(B+2t_B)/\pi})$ 
    8383and length $(C+2t_C)$ values, after appropriately 
    84 sorting the three dimensions to give an oblate or prolate particle, to give an  
     84sorting the three dimensions to give an oblate or prolate particle, to give an 
    8585effective radius, for $S(Q)$ when $P(Q) * S(Q)$ is applied. 
    8686 
     
    126126title = "Rectangular solid with a core-shell structure." 
    127127description = """ 
    128      P(q)=  
     128     P(q)= 
    129129""" 
    130130category = "shape:parallelepiped" 
     
    179179# VR defaults to 1.0 
    180180 
     181def random(): 
     182    import numpy as np 
     183    outer = 10**np.random.uniform(1, 4.7, size=3) 
     184    thick = np.random.beta(0.5, 0.5, size=3)*(outer-2) + 1 
     185    length = outer - thick 
     186    pars = dict( 
     187        length_a=length[0], 
     188        length_b=length[1], 
     189        length_c=length[2], 
     190        thick_rim_a=thick[0], 
     191        thick_rim_b=thick[1], 
     192        thick_rim_c=thick[2], 
     193    ) 
     194    return pars 
     195 
    181196# parameters for demo 
    182197demo = dict(scale=1, background=0.0, 
  • sasmodels/models/core_shell_sphere.py

    r31df0c9 r8f04da4  
    101101def random(): 
    102102    import numpy as np 
    103     total_radius = 10**np.random.uniform(1.3, 4.3) 
    104     radius = np.random.uniform(0, 1)*total_radius 
    105     thickness = total_radius - radius 
     103    outer_radius = 10**np.random.uniform(1.3, 4.3) 
     104    # Use a distribution with a preference for thin shell or thin core 
     105    # Avoid core,shell radii < 1 
     106    radius = np.random.beta(0.5, 0.5)*(outer_radius-2) + 1 
     107    thickness = outer_radius - core 
    106108    pars = dict( 
    107109        radius=radius, 
     
    112114tests = [ 
    113115    [{'radius': 20.0, 'thickness': 10.0}, 'ER', 30.0], 
    114      # TODO: VR test suppressed until we sort out new product model 
    115      # and determine what to do with volume ratio. 
    116      #[{'radius': 20.0, 'thickness': 10.0}, 'VR', 0.703703704], 
     116    # TODO: VR test suppressed until we sort out new product model 
     117    # and determine what to do with volume ratio. 
     118    #[{'radius': 20.0, 'thickness': 10.0}, 'VR', 0.703703704], 
    117119 
    118      # The SasView test result was 0.00169, with a background of 0.001 
    119      [{'radius': 60.0, 'thickness': 10.0, 'sld_core': 1.0, 'sld_shell':2.0, 
    120        'sld_solvent':3.0, 'background':0.0}, 
    121       0.4, 0.000698838], 
     120    # The SasView test result was 0.00169, with a background of 0.001 
     121    [{'radius': 60.0, 'thickness': 10.0, 'sld_core': 1.0, 'sld_shell': 2.0, 
     122      'sld_solvent': 3.0, 'background': 0.0}, 0.4, 0.000698838], 
    122123] 
  • sasmodels/models/fcc_paracrystal.py

    r1511c37c r8f04da4  
    125125    d_factor = 10**np.random.uniform(-2, -0.7)  # sigma_d in 0.01-0.7 
    126126    dnn_fraction = np.random.beta(a=10, b=1) 
    127     dnn = radius*4/np.sqrt(3)/dnn_fraction 
     127    dnn = radius*4/np.sqrt(2)/dnn_fraction 
    128128    pars = dict( 
    129129        #sld=1, sld_solvent=0, scale=1, background=1e-32, 
     
    135135 
    136136# april 10 2017, rkh add unit tests, NOT compared with any other calc method, assume correct! 
    137 q =4.*pi/220. 
     137q = 4.*pi/220. 
    138138tests = [ 
    139     [{ }, 
    140      [0.001, q, 0.215268], [0.275164706668, 5.7776842567, 0.00958167119232]], 
    141      [{}, (-0.047, -0.007), 238.103096286 ], 
    142      [{}, (0.053, 0.063), 0.863609587796 ], 
     139    [{}, [0.001, q, 0.215268], [0.275164706668, 5.7776842567, 0.00958167119232]], 
     140    [{}, (-0.047, -0.007), 238.103096286], 
     141    [{}, (0.053, 0.063), 0.863609587796], 
    143142] 
  • sasmodels/models/fractal_core_shell.py

    r1511c37c r8f04da4  
    100100def random(): 
    101101    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 
     102    outer_radius = 10**np.random.uniform(0.7, 4) 
     103    # Use a distribution with a preference for thin shell or thin core 
     104    # Avoid core,shell radii < 1 
     105    thickness = np.random.beta(0.5, 0.5)*(outer_radius-2) + 1 
     106    radius = outer_radius - thickness 
     107    cor_length = 10**np.random.uniform(0.7, 2)*outer_radius 
    109108    volfraction = 10**np.random.uniform(-3, -1) 
    110     #volfraction = 0.05 
    111109    fractal_dim = 2*np.random.beta(3, 4) + 1 
    112     #fractal_dim = 2 
    113110    pars = dict( 
    114111        #background=0, sld_block=1, sld_solvent=0, 
     
    119116    ) 
    120117    return pars 
    121  
    122118 
    123119demo = dict(scale=0.05, 
  • sasmodels/models/hardsphere.py

    r40a87fa r8f04da4  
    7575Iq = r""" 
    7676      double D,A,B,G,X,X2,X4,S,C,FF,HARDSPH; 
    77       // these are c compiler instructions, can also put normal code inside the "if else" structure  
     77      // these are c compiler instructions, can also put normal code inside the "if else" structure 
    7878      #if FLOAT_SIZE > 4 
    7979      // double precision    orig had 0.2, don't call the variable cutoff as PAK already has one called that! Must use UPPERCASE name please. 
     
    8282      #else 
    8383      // 0.1 bad, 0.2 OK, 0.3 good, 0.4 better, 0.8 no good 
    84       #define CUTOFFHS 0.4   
     84      #define CUTOFFHS 0.4 
    8585      #endif 
    8686 
     
    110110      if(X < CUTOFFHS) { 
    111111      // RKH Feb 2016, use Taylor series expansion for small X 
    112       // else no obvious way to rearrange the equations to avoid needing a very high number of significant figures.  
    113       // Series expansion found using Mathematica software. Numerical test in .xls showed terms to X^2 are sufficient  
    114       // for 5 or 6 significant figures, but I put the X^4 one in anyway  
     112      // else no obvious way to rearrange the equations to avoid needing a very high number of significant figures. 
     113      // Series expansion found using Mathematica software. Numerical test in .xls showed terms to X^2 are sufficient 
     114      // for 5 or 6 significant figures, but I put the X^4 one in anyway 
    115115            //FF = 8*A +6*B + 4*G - (0.8*A +2.0*B/3.0 +0.5*G)*X2 +(A/35. +B/40. +G/50.)*X4; 
    116116            // refactoring the polynomial makes it very slightly faster (0.5 not 0.6 msec) 
     
    153153   """ 
    154154 
     155def random(): 
     156    import numpy as np 
     157    pars = dict( 
     158        scale=1, background=0, 
     159        radius_effective=10**np.random.uniform(1, 4), 
     160        volfraction=10**np.random.uniform(-2, 0),  # high volume fraction 
     161    ) 
     162    return pars 
     163 
    155164# ER defaults to 0.0 
    156165# VR defaults to 1.0 
  • sasmodels/models/hayter_msa.py

    r5702f52 r8f04da4  
    6464        Routine takes absolute value of charge, use HardSphere if charge 
    6565        goes to zero. 
    66         In sasview the effective radius and volume fraction may be calculated  
     66        In sasview the effective radius and volume fraction may be calculated 
    6767        from the parameters used in P(Q). 
    6868""" 
     
    8989# ER defaults to 0.0 
    9090# VR defaults to 1.0 
     91 
     92def random(): 
     93    import numpy as np 
     94    # TODO: too many failures for random hayter_msa parameters 
     95    pars = dict( 
     96        scale=1, background=0, 
     97        radius_effective=10**np.random.uniform(1, 4.7), 
     98        volfraction=10**np.random.uniform(-2, 0),  # high volume fraction 
     99        charge=min(int(10**np.random.uniform(0, 1.3)+0.5), 200), 
     100        temperature=10**np.random.uniform(0, np.log10(450)), # max T = 450 
     101        #concentration_salt=10**np.random.uniform(-3, 1), 
     102        dialectconst=10**np.random.uniform(0, 6), 
     103        #charge=10, 
     104        #temperature=318.16, 
     105        concentration_salt=0.0, 
     106        #dielectconst=71.08, 
     107    ) 
     108    return pars 
    91109 
    92110# default parameter set,  use  compare.sh -midQ -linear 
  • sasmodels/models/hollow_cylinder.py

    r31df0c9 r8f04da4  
    123123def random(): 
    124124    import numpy as np 
    125     length = 10**np.random.uniform(2, 6) 
    126     radius = 10**np.random.uniform(1, 3) 
    127     kuhn_length = 10**np.random.uniform(-2, -0.7)*length  # at least 10 segments 
     125    length = 10**np.random.uniform(1, 4.7) 
     126    outer_radius = 10**np.random.uniform(1, 4.7) 
     127    # Use a distribution with a preference for thin shell or thin core 
     128    # Avoid core,shell radii < 1 
     129    thickness = np.random.beta(0.5, 0.5)*(outer_radius-2) + 1 
     130    radius = outer_radius - thickness 
    128131    pars = dict( 
    129132        length=length, 
    130133        radius=radius, 
    131         kuhn_length=kuhn_length, 
     134        thickness=thickness, 
    132135    ) 
    133136    return pars 
    134137 
     138# parameters for demo 
     139demo = dict(scale=1.0, background=0.0, length=400.0, radius=20.0, 
     140            thickness=10, sld=6.3, sld_solvent=1, theta=90, phi=0, 
     141            thickness_pd=0.2, thickness_pd_n=9, 
     142            length_pd=.2, length_pd_n=10, 
     143            radius_pd=.2, radius_pd_n=9, 
     144            theta_pd=10, theta_pd_n=5, 
     145           ) 
    135146q = 0.1 
    136147# april 6 2017, rkh added a 2d unit test, assume correct! 
  • sasmodels/models/hollow_rectangular_prism.py

    r31df0c9 r8f04da4  
    149149    import numpy as np 
    150150    a, b, c = 10**np.random.uniform(1, 4.7, size=3) 
    151     thickness = np.random.uniform(0.01, 0.49) * min(a, b, c) 
     151    # Thickness is limited to 1/2 the smallest dimension 
     152    # Use a distribution with a preference for thin shell or thin core 
     153    # Avoid core,shell radii < 1 
     154    min_dim = 0.5*min(a, b, c) 
     155    thickness = np.random.beta(0.5, 0.5)*(min_dim-2) + 1 
     156    #print(a, b, c, thickness, thickness/min_dim) 
    152157    pars = dict( 
    153158        length_a=a, 
  • sasmodels/models/lamellar_stack_paracrystal.py

    r1511c37c r8f04da4  
    140140    # Let polydispersity peak around 15%; 95% < 0.4; max=100% 
    141141    sigma_d = np.random.beta(1.5, 7) 
    142     scale = thickness * 10**np.random.uniform(-7, -4) 
    143142    pars = dict( 
    144         #scale=1, 
    145143        thickness=thickness, 
    146144        Nlayers=Nlayers, 
  • sasmodels/models/linear_pearls.py

    rc3ccaec r8f04da4  
    6565source = ["lib/sas_3j1x_x.c", "linear_pearls.c"] 
    6666 
    67 demo = dict(scale=1.0, background=0.0, 
    68             radius=80.0, 
    69             edge_sep=350.0, 
    70             num_pearls=3, 
    71             sld=1.0, 
    72             sld_solvent=6.3) 
     67def random(): 
     68    import numpy as np 
     69    radius = 10**np.random.uniform(1, 3) # 1 - 1000 
     70    edge_sep = 10**np.random.uniform(0, 3)  # 1 - 1000 
     71    num_pearls = np.round(10**np.random.uniform(0.3, 3)) # 2 - 1000 
     72    pars = dict( 
     73        radius=radius, 
     74        edge_sep=edge_sep, 
     75        num_pearls=num_pearls, 
     76    ) 
     77    return pars 
    7378 
    7479""" 
  • sasmodels/models/multilayer_vesicle.py

    r5d23de2 r8f04da4  
    149149    return radius + n_shells * (thick_shell + thick_solvent) - thick_solvent 
    150150 
    151 demo = dict(scale=1, background=0, 
    152             volfraction=0.05, 
    153             radius=60.0, 
    154             thick_shell=10.0, 
    155             thick_solvent=10.0, 
    156             sld_solvent=6.4, 
    157             sld=0.4, 
    158             n_shells=2.0) 
     151def random(): 
     152    import numpy as np 
     153    volfraction = 10**np.random.uniform(-3, -0.5)  # scale from 0.1% to 30% 
     154    radius = 10**np.random.uniform(0, 2.5) # core less than 300 A 
     155    total_thick = 10**np.random.uniform(2, 4) # up to 10000 A of shells 
     156    # random number of shells, with shell+solvent thickness > 10 A 
     157    n_shells = int(10**np.random.uniform(0, np.log10(total_thick)-1)+0.5) 
     158    # split total shell thickness with preference for shell over solvent; 
     159    # make sure that shell thickness is at least 1 A 
     160    one_thick = total_thick/n_shells 
     161    thick_solvent = 10**np.random.uniform(-2, 0)*(one_thick - 1) 
     162    thick_shell = one_thick - thick_solvent 
     163    pars = dict( 
     164        scale=1, 
     165        volfraction=volfraction, 
     166        radius=radius, 
     167        thick_shell=thick_shell, 
     168        thick_solvent=thick_solvent, 
     169        n_shells=n_shells, 
     170    ) 
     171    return pars 
    159172 
    160173tests = [ 
  • sasmodels/models/parallelepiped.py

    r31df0c9 r8f04da4  
    245245def random(): 
    246246    import numpy as np 
    247     a, b, c = 10**np.random.uniform(1, 4.7, size=3) 
     247    length = 10**np.random.uniform(1, 4.7, size=3) 
    248248    pars = dict( 
    249         length_a=a, 
    250         length_b=b, 
    251         length_c=c, 
     249        length_a=length[0], 
     250        length_b=length[1], 
     251        length_c=length[2], 
    252252    ) 
    253253    return pars 
  • sasmodels/models/pearl_necklace.py

    r1bd1ea2 r8f04da4  
    117117    return rad_out 
    118118 
     119def random(): 
     120    import numpy as np 
     121    radius = 10**np.random.uniform(1, 3) # 1 - 1000 
     122    thick_string = 10**np.random.uniform(0, np.log10(radius)-1) # 1 - radius/10 
     123    edge_sep = 10**np.random.uniform(0, 3)  # 1 - 1000 
     124    num_pearls = np.round(10**np.random.uniform(0.3, 3)) # 2 - 1000 
     125    pars = dict( 
     126        radius=radius, 
     127        edge_sep=edge_sep, 
     128        thick_string=thick_string, 
     129        num_pearls=num_pearls, 
     130    ) 
     131    return pars 
     132 
    119133# parameters for demo 
    120134demo = dict(scale=1, background=0, radius=80.0, edge_sep=350.0, 
  • sasmodels/models/pringle.py

    r30fbe2e r8f04da4  
    8585    return 0.5 * (ddd) ** (1. / 3.) 
    8686 
    87 demo = dict(background=0.0, 
    88             scale=1.0, 
    89             radius=60.0, 
    90             thickness=10.0, 
    91             alpha=0.001, 
    92             beta=0.02, 
    93             sld=1.0, 
    94             sld_solvent=6.35) 
     87def random(): 
     88    import numpy as np 
     89    alpha, beta = 10**np.random.uniform(-1, 1, size=2) 
     90    radius = 10**np.random.uniform(1, 3) 
     91    thickness = 10**np.random.uniform(0.7, 2) 
     92    pars = dict( 
     93        radius=radius, 
     94        thickness=thickness, 
     95        alpha=alpha, 
     96        beta=beta, 
     97    ) 
     98    return pars 
    9599 
    96100tests = [ 
  • sasmodels/models/raspberry.py

    rc3ccaec r8f04da4  
    154154source = ["lib/sas_3j1x_x.c", "raspberry.c"] 
    155155 
     156def random(): 
     157    import numpy as np 
     158    # Limit volume fraction to 20% each 
     159    volfraction_lg = 10**np.random.uniform(-3, -0.3) 
     160    volfraction_sm = 10**np.random.uniform(-3, -0.3) 
     161    # Prefer most particles attached (peak near 60%), but not all or none 
     162    surface_fraction = np.random.beta(6, 4) 
     163    radius_lg = 10**np.random.uniform(1.7, 4.7)  # 500 - 50000 A 
     164    radius_sm = 10**np.random.uniform(-3, -0.3)*radius_lg  # 0.1% - 20% 
     165    penetration = np.random.beta(1, 10) # up to 20% pen. for 90% of examples 
     166    pars = dict( 
     167        volfraction_lg=volfraction_lg, 
     168        volfraction_sm=volfraction_sm, 
     169        surface_fraction=surface_fraction, 
     170        radius_lg=radius_lg, 
     171        radius_sm=radius_sm, 
     172        penetration=penetration, 
     173    ) 
     174    return pars 
     175 
    156176# parameters for demo 
    157177demo = dict(scale=1, background=0.001, 
  • sasmodels/models/sc_paracrystal.py

    r1511c37c r8f04da4  
    144144    d_factor = 10**np.random.uniform(-2, -0.7)  # sigma_d in 0.01-0.7 
    145145    dnn_fraction = np.random.beta(a=10, b=1) 
    146     dnn = radius*4/np.sqrt(3)/dnn_fraction 
     146    dnn = radius*4/np.sqrt(4)/dnn_fraction 
    147147    pars = dict( 
    148148        #sld=1, sld_solvent=0, scale=1, background=1e-32, 
  • sasmodels/models/squarewell.py

    r3330bb4 r8f04da4  
    9191        double S,C,SL,CL; 
    9292        x= q; 
    93          
     93 
    9494        req = radius_effective; 
    9595        phis = volfraction; 
    9696        edibkb = welldepth; 
    9797        lambda = wellwidth; 
    98          
     98 
    9999        sigma = req*2.; 
    100100        eta = phis; 
     
    110110        beta = -(eta/3.0) * ( 18. + 20.*eta - 12.*eta2 + eta4 )/etam14; 
    111111        gamm = 0.5*eta*( sk + eta3*(eta-4.) )/etam14; 
    112          
     112 
    113113        //  calculate the structure factor 
    114          
     114 
    115115        sk = x*sigma; 
    116116        sk2 = sk*sk; 
     
    125125        ck =  -24.0*eta*( t1 + t2 + t3 + t4 )/sk3/sk3; 
    126126        struc  = 1./(1.-ck); 
    127          
     127 
    128128        return(struc); 
    129129""" 
     
    132132# VR defaults to 1.0 
    133133 
     134def random(): 
     135    import numpy as np 
     136    pars = dict( 
     137        scale=1, background=0, 
     138        radius_effective=10**np.random.uniform(1, 4.7), 
     139        volfraction=np.random.uniform(0.00001, 0.08), 
     140        welldepth=np.random.uniform(0, 1.5), 
     141        wellwidth=np.random.uniform(1, 1.2), 
     142    ) 
     143    return pars 
     144 
    134145demo = dict(radius_effective=50, volfraction=0.04, welldepth=1.5, 
    135146            wellwidth=1.2, radius_effective_pd=0, radius_effective_pd_n=0) 
    136147# 
    137148tests = [ 
    138     [{'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 
    139       'volfraction' : 0.04,'welldepth' : 1.5, 'wellwidth' : 1.2, 
    140       'radius_effective_pd' : 0}, 
    141      [0.001], [0.97665742]], 
     149    [{'scale': 1.0, 'background': 0.0, 'radius_effective': 50.0, 
     150      'volfraction': 0.04,'welldepth': 1.5, 'wellwidth': 1.2, 
     151      'radius_effective_pd': 0}, [0.001], [0.97665742]], 
    142152    ] 
    143153# ADDED by: converting from sasview RKH  ON: 16Mar2016 
  • sasmodels/models/stacked_disks.py

    r9d50a1e r8f04da4  
    137137 
    138138source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "stacked_disks.c"] 
     139 
     140def random(): 
     141    import numpy as np 
     142    radius = 10**np.random.uniform(1, 4.7) 
     143    total_stack = 10**np.random.uniform(1, 4.7) 
     144    n_stacking = int(10**np.random.uniform(0, np.log10(total_stack)-1) + 0.5) 
     145    d = total_stack/n_stacking 
     146    thick_core = np.random.uniform(0, d-2)  # at least 1 A for each layer 
     147    thick_layer = (d - thick_core)/2 
     148    # Let polydispersity peak around 15%; 95% < 0.4; max=100% 
     149    sigma_d = d * np.random.beta(1.5, 7) 
     150    pars = dict( 
     151        thick_core=thick_core, 
     152        thick_layer=thick_layer, 
     153        radius=radius, 
     154        n_stacking=n_stacking, 
     155        sigma_d=sigma_d, 
     156    ) 
     157    return pars 
    139158 
    140159demo = dict(background=0.001, 
  • sasmodels/models/stickyhardsphere.py

    r40a87fa r8f04da4  
    9898    ] 
    9999 
     100def random(): 
     101    import numpy as np 
     102    pars = dict( 
     103        scale=1, background=0, 
     104        radius_effective=10**np.random.uniform(1, 4.7), 
     105        volfraction=np.random.uniform(0.00001, 0.74), 
     106        perturb=10**np.random.uniform(-2, -1), 
     107        stickiness=np.random.uniform(0, 1), 
     108    ) 
     109    return pars 
     110 
    100111# No volume normalization despite having a volume parameter 
    101112# This should perhaps be volume normalized? 
  • sasmodels/product.py

    rf88e248 r8f04da4  
    9393    # Remember the component info blocks so we can build the model 
    9494    model_info.composition = ('product', [p_info, s_info]) 
     95    # TODO: delegate random to p_info, s_info 
     96    #model_info.random = lambda: {} 
    9597    model_info.demo = demo 
    9698 
Note: See TracChangeset for help on using the changeset viewer.