Changeset 485aee2 in sasmodels


Ignore:
Timestamp:
Mar 9, 2015 2:45:01 PM (9 years ago)
Author:
Doucet, Mathieu <doucetm@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
3e428ec
Parents:
5ef0633
Message:

Trying to get us starting on the right foot with code style.

Location:
sasmodels/models
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/bcc.py

    r3c56da87 r485aee2  
    113113    assumed to be isotropic and characterized by a Gaussian distribution. 
    114114    """ 
    115 category="shape:paracrystal" 
     115category = "shape:paracrystal" 
    116116 
    117 parameters = [ 
    118 #   [ "name", "units", default, [lower, upper], "type","description" ], 
    119     [ "dnn", "Ang", 220, [-inf,inf],"","Nearest neighbour distance"], 
    120     [ "d_factor", "", 0.06,[-inf,inf],"","Paracrystal distortion factor" ], 
    121     [ "radius", "Ang",  40, [0, inf], "volume","Particle radius" ], 
    122     [ "sld", "1e-6/Ang^2", 4, [-inf,inf], "", "Particle scattering length density" ], 
    123     [ "solvent_sld", "1e-6/Ang^2", 1, [-inf,inf], "", "Solvent scattering length density" ], 
    124     [ "theta", "degrees", 60, [-inf, inf], "orientation","In plane angle" ], 
    125     [ "phi", "degrees", 60, [-inf, inf], "orientation","Out of plane angle" ], 
    126     [ "psi", "degrees", 60, [-inf,inf], "orientation","Out of plane angle"] 
    127     ] 
     117#             ["name", "units", default, [lower, upper], "type","description" ], 
     118parameters = [["dnn", "Ang", 220, [-inf, inf], "", "Nearest neighbour distance"], 
     119              ["d_factor", "", 0.06, [-inf, inf], "", "Paracrystal distortion factor"], 
     120              ["radius", "Ang", 40, [0, inf], "volume", "Particle radius"], 
     121              ["sld", "1e-6/Ang^2", 4, [-inf, inf], "", "Particle scattering length density"], 
     122              ["solvent_sld", "1e-6/Ang^2", 1, [-inf, inf], "", "Solvent scattering length density"], 
     123              ["theta", "degrees", 60, [-inf, inf], "orientation", "In plane angle"], 
     124              ["phi", "degrees", 60, [-inf, inf], "orientation", "Out of plane angle"], 
     125              ["psi", "degrees", 60, [-inf, inf], "orientation", "Out of plane angle"] 
     126             ] 
    128127 
    129 source = [ "lib/J1.c", "lib/gauss150.c", "bcc.c" ] 
     128source = ["lib/J1.c", "lib/gauss150.c", "bcc.c"] 
    130129 
    131130# parameters for demo 
     
    143142# For testing against the old sasview models, include the converted parameter 
    144143# names and the target sasview model name. 
    145 oldname='BCCrystalModel' 
    146 oldpars=dict(sld='sldSph', 
    147              solvent_sld='sldSolv') 
     144oldname = 'BCCrystalModel' 
     145oldpars = dict(sld='sldSph', solvent_sld='sldSolv') 
  • sasmodels/models/broad_peak.py

    r3c56da87 r485aee2  
    6060      lorentz_exp = Lorentzian exponent 
    6161      background = Incoherent background""" 
    62 category="shape-independent" 
     62category = "shape-independent" 
    6363 
    64 parameters = [ 
    65 #   [ "name", "units", default, [lower, upper], "type", 
    66 #     "description" ], 
    67  
    68     [ "porod_scale", "", 1.0e-05, [-inf,inf], "", 
    69       "Power law scale factor" ], 
    70     [ "porod_exp", "", 3.0, [-inf,inf], "", 
    71       "Exponent of power law" ], 
    72     [ "lorentz_scale", "", 10.0, [-inf,inf], "", 
    73       "Scale factor for broad Lorentzian peak" ], 
    74     [ "lorentz_length", "Ang",  50.0, [-inf, inf], "", 
    75       "Lorentzian screening length" ], 
    76     [ "peak_pos", "1/Ang",  0.1, [-inf, inf], "", 
    77       "Peak postion in q" ], 
    78     [ "lorentz_exp", "",  2.0, [-inf, inf], "", 
    79       "exponent of Lorentz function" ], 
    80     ] 
    81  
     64#             ["name", "units", default, [lower, upper], "type", "description"], 
     65parameters = [["porod_scale", "", 1.0e-05, [-inf, inf], "", "Power law scale factor"], 
     66              ["porod_exp", "", 3.0, [-inf, inf], "", "Exponent of power law"], 
     67              ["lorentz_scale", "", 10.0, [-inf, inf], "", "Scale factor for broad Lorentzian peak"], 
     68              ["lorentz_length", "Ang", 50.0, [-inf, inf], "", "Lorentzian screening length"], 
     69              ["peak_pos", "1/Ang", 0.1, [-inf, inf], "", "Peak postion in q"], 
     70              ["lorentz_exp", "", 2.0, [-inf, inf], "", "exponent of Lorentz function"], 
     71             ] 
    8272 
    8373def Iq(q, porod_scale, porod_exp, lorentz_scale, lorentz_length, peak_pos, lorentz_exp): 
    84     inten = (porod_scale/q**porod_exp + lorentz_scale 
    85         / (1.0 + (abs(q-peak_pos)*lorentz_length)**lorentz_exp)) 
     74    inten = (porod_scale / q ** porod_exp + lorentz_scale 
     75             / (1.0 + (abs(q - peak_pos) * lorentz_length) ** lorentz_exp)) 
    8676    return inten 
    8777Iq.vectorized = True  # Iq accepts an array of Q values 
    8878 
    8979def Iqxy(qx, qy, *args): 
    90     return Iq(sqrt(qx**2 + qy**2), *args) 
     80    return Iq(sqrt(qx ** 2 + qy ** 2), *args) 
    9181Iqxy.vectorized = True # Iqxy accepts an array of Qx, Qy values 
    9282 
    9383 
    94 demo = dict( 
    95     scale=1, background=0, 
    96     porod_scale=1.0e-05, porod_exp=3, 
    97     lorentz_scale=10,lorentz_length=50, peak_pos=0.1, lorentz_exp=2, 
    98     ) 
     84demo = dict(scale=1, background=0, 
     85            porod_scale=1.0e-05, porod_exp=3, 
     86            lorentz_scale=10, lorentz_length=50, peak_pos=0.1, lorentz_exp=2) 
    9987 
    10088oldname = "BroadPeakModel" 
    10189oldpars = dict(porod_scale='scale_p', porod_exp='exponent_p', 
    102         lorentz_scale='scale_l', lorentz_length='length_l', peak_pos='q_peak', 
    103         lorentz_exp='exponent_l', scale=None) 
     90               lorentz_scale='scale_l', lorentz_length='length_l', peak_pos='q_peak', 
     91               lorentz_exp='exponent_l', scale=None) 
  • sasmodels/models/capped_cylinder.py

    ra5d0d00 r485aee2  
    115115title = "Right circular cylinder with spherical end caps and uniform SLD" 
    116116description = """That is, a sphereocylinder 
    117         with end caps that have a radius larger than 
    118         that of the cylinder and the center of the 
    119         end cap radius lies within the cylinder. 
    120         Note: As the length of cylinder -->0, 
    121         it becomes a ConvexLens. 
    122         It must be that radius <(=) cap_radius. 
    123         [Parameters]; 
    124         scale: volume fraction of spheres, 
    125         background:incoherent background, 
    126         radius: radius of the cylinder, 
    127         length: length of the cylinder, 
    128         cap_radius: radius of the semi-spherical cap, 
    129         sld: SLD of the capped cylinder, 
    130         solvent_sld: SLD of the solvent. 
     117    with end caps that have a radius larger than 
     118    that of the cylinder and the center of the 
     119    end cap radius lies within the cylinder. 
     120    Note: As the length of cylinder -->0, 
     121    it becomes a ConvexLens. 
     122    It must be that radius <(=) cap_radius. 
     123    [Parameters]; 
     124    scale: volume fraction of spheres, 
     125    background:incoherent background, 
     126    radius: radius of the cylinder, 
     127    length: length of the cylinder, 
     128    cap_radius: radius of the semi-spherical cap, 
     129    sld: SLD of the capped cylinder, 
     130    solvent_sld: SLD of the solvent. 
    131131""" 
    132132category = "shape:cylinder" 
    133133 
    134 parameters = [ 
    135     #   [ "name", "units", default, [lower, upper], "type", 
    136     #     "description" ], 
    137     [ "sld", "1e-6/Ang^2", 4, [-inf,inf], "", 
    138       "Cylinder scattering length density" ], 
    139     [ "solvent_sld", "1e-6/Ang^2", 1, [-inf,inf], "", 
    140       "Solvent scattering length density" ], 
    141     [ "radius", "Ang",  20, [0, inf], "volume", 
    142       "Cylinder radius" ], 
    143     # TODO: use an expression for cap radius with fixed bounds. 
    144     # The current form requires cap radius R bigger than cylinder radius r. 
    145     # Could instead use R/r in [1,inf], r/R in [0,1], or the angle between 
    146     # cylinder and cap in [0,90].  The problem is similar for the barbell 
    147     # model.  Propose r/R in [0,1] in both cases, with the model specifying 
    148     # cylinder radius in the capped cylinder model and sphere radius in the 
    149     # barbell model.  This leads to the natural value of zero for no cap 
    150     # in the capped cylinder, and zero for no bar in the barbell model.  In 
    151     # both models, one would be a pill. 
    152     [ "cap_radius", "Ang", 20, [0, inf], "volume", 
    153       "Cap radius" ], 
    154     [ "length", "Ang",  400, [0, inf], "volume", 
    155       "Cylinder length" ], 
    156     [ "theta", "degrees", 60, [-inf, inf], "orientation", 
    157       "In plane angle" ], 
    158     [ "phi", "degrees", 60, [-inf, inf], "orientation", 
    159       "Out of plane angle" ], 
    160     ] 
     134#             ["name", "units", default, [lower, upper], "type", "description"], 
     135parameters = [["sld", "1e-6/Ang^2", 4, [-inf, inf], "", 
     136               "Cylinder scattering length density"], 
     137              ["solvent_sld", "1e-6/Ang^2", 1, [-inf, inf], "", 
     138               "Solvent scattering length density"], 
     139              ["radius", "Ang", 20, [0, inf], "volume", "Cylinder radius"], 
     140              # TODO: use an expression for cap radius with fixed bounds. 
     141              # The current form requires cap radius R bigger than cylinder radius r. 
     142              # Could instead use R/r in [1,inf], r/R in [0,1], or the angle between 
     143              # cylinder and cap in [0,90].  The problem is similar for the barbell 
     144              # model.  Propose r/R in [0,1] in both cases, with the model specifying 
     145              # cylinder radius in the capped cylinder model and sphere radius in the 
     146              # barbell model.  This leads to the natural value of zero for no cap 
     147              # in the capped cylinder, and zero for no bar in the barbell model.  In 
     148              # both models, one would be a pill. 
     149              ["cap_radius", "Ang", 20, [0, inf], "volume", "Cap radius"], 
     150              ["length", "Ang", 400, [0, inf], "volume", "Cylinder length"], 
     151              ["theta", "degrees", 60, [-inf, inf], "orientation", "In plane angle"], 
     152              ["phi", "degrees", 60, [-inf, inf], "orientation", "Out of plane angle"], 
     153             ] 
    161154 
    162 source = [ "lib/J1.c", "lib/gauss76.c", "capped_cylinder.c" ] 
     155source = ["lib/J1.c", "lib/gauss76.c", "capped_cylinder.c"] 
    163156 
    164  
    165 demo = dict( 
    166     scale=1, background=0, 
    167     sld=6, solvent_sld=1, 
    168     radius=260, cap_radius=290, length=290, 
    169     theta=30, phi=15, 
    170     radius_pd=.2, radius_pd_n=1, 
    171     cap_radius_pd=.2, cap_radius_pd_n=1, 
    172     length_pd=.2, length_pd_n=10, 
    173     theta_pd=15, theta_pd_n=45, 
    174     phi_pd=15, phi_pd_n=1, 
    175     ) 
     157demo = dict(scale=1, background=0, 
     158            sld=6, solvent_sld=1, 
     159            radius=260, cap_radius=290, length=290, 
     160            theta=30, phi=15, 
     161            radius_pd=.2, radius_pd_n=1, 
     162            cap_radius_pd=.2, cap_radius_pd_n=1, 
     163            length_pd=.2, length_pd_n=10, 
     164            theta_pd=15, theta_pd_n=45, 
     165            phi_pd=15, phi_pd_n=1) 
    176166oldname = 'CappedCylinderModel' 
    177167oldpars = dict(sld='sld_capcyl', solvent_sld='sld_solv', 
  • sasmodels/models/core_shell_cylinder.py

    ra5d0d00 r485aee2  
    111111P(q,alpha)= scale/Vs*f(q)^(2) + background, 
    112112      where: f(q)= 2(core_sld - solvant_sld) 
    113                 * Vc*sin[qLcos(alpha/2)] 
    114                 /[qLcos(alpha/2)]*J1(qRsin(alpha)) 
    115                 /[qRsin(alpha)]+2(shell_sld-solvent_sld) 
    116                 *Vs*sin[q(L+T)cos(alpha/2)][[q(L+T) 
    117                 *cos(alpha/2)]*J1(q(R+T)sin(alpha)) 
    118                 /q(R+T)sin(alpha)] 
     113        * Vc*sin[qLcos(alpha/2)] 
     114        /[qLcos(alpha/2)]*J1(qRsin(alpha)) 
     115        /[qRsin(alpha)]+2(shell_sld-solvent_sld) 
     116        *Vs*sin[q(L+T)cos(alpha/2)][[q(L+T) 
     117        *cos(alpha/2)]*J1(q(R+T)sin(alpha)) 
     118        /q(R+T)sin(alpha)] 
    119119 
    120         alpha:is the angle between the axis of 
    121                 the cylinder and the q-vector 
    122         Vs: the volume of the outer shell 
    123         Vc: the volume of the core 
    124         L: the length of the core 
    125         shell_sld: the scattering length density of the shell 
    126         solvent_sld: the scattering length density of the solvent 
    127         background: the background 
    128         T: the thickness 
    129         R+T: is the outer radius 
    130         L+2T: The total length of the outershell 
    131         J1: the first order Bessel function 
    132         theta: axis_theta of the cylinder 
    133         phi: the axis_phi of the cylinder 
     120    alpha:is the angle between the axis of 
     121        the cylinder and the q-vector 
     122    Vs: the volume of the outer shell 
     123    Vc: the volume of the core 
     124    L: the length of the core 
     125        shell_sld: the scattering length density of the shell 
     126    solvent_sld: the scattering length density of the solvent 
     127    background: the background 
     128    T: the thickness 
     129        R+T: is the outer radius 
     130     L+2T: The total length of the outershell 
     131    J1: the first order Bessel function 
     132     theta: axis_theta of the cylinder 
     133     phi: the axis_phi of the cylinder 
    134134""" 
    135135category = "shape:cylinder" 
    136136 
    137 parameters = [ 
    138 #   [ "name", "units", default, [lower, upper], "type", 
    139 #     "description" ], 
    140     [ "core_sld", "1e-6/Ang^2", 4, [-inf,inf], "", 
    141       "Cylinder core scattering length density" ], 
    142     [ "shell_sld", "1e-6/Ang^2", 4, [-inf,inf], "", 
    143       "Cylinder shell scattering length density" ], 
    144     [ "solvent_sld", "1e-6/Ang^2", 1, [-inf,inf], "", 
    145       "Solvent scattering length density" ], 
    146     [ "radius", "Ang",  20, [0, inf], "volume", 
    147       "Cylinder core radius" ], 
    148     [ "thickness", "Ang",  20, [0, inf], "volume", 
    149       "Cylinder shell thickness" ], 
    150     [ "length", "Ang",  400, [0, inf], "volume", 
    151       "Cylinder length" ], 
    152     [ "theta", "degrees", 60, [-inf, inf], "orientation", 
    153       "In plane angle" ], 
    154     [ "phi", "degrees", 60, [-inf, inf], "orientation", 
    155       "Out of plane angle" ], 
    156     ] 
     137#             ["name", "units", default, [lower, upper], "type", "description"], 
     138parameters = [["core_sld", "1e-6/Ang^2", 4, [-inf, inf], "", 
     139               "Cylinder core scattering length density"], 
     140              ["shell_sld", "1e-6/Ang^2", 4, [-inf, inf], "", 
     141               "Cylinder shell scattering length density"], 
     142              ["solvent_sld", "1e-6/Ang^2", 1, [-inf, inf], "", 
     143               "Solvent scattering length density"], 
     144              ["radius", "Ang", 20, [0, inf], "volume", 
     145               "Cylinder core radius"], 
     146              ["thickness", "Ang", 20, [0, inf], "volume", 
     147               "Cylinder shell thickness"], 
     148              ["length", "Ang", 400, [0, inf], "volume", 
     149               "Cylinder length"], 
     150              ["theta", "degrees", 60, [-inf, inf], "orientation", 
     151               "In plane angle"], 
     152              ["phi", "degrees", 60, [-inf, inf], "orientation", 
     153               "Out of plane angle"], 
     154             ] 
    157155 
    158 source = [ "lib/J1.c", "lib/gauss76.c", "core_shell_cylinder.c"] 
     156source = ["lib/J1.c", "lib/gauss76.c", "core_shell_cylinder.c"] 
    159157 
    160158def ER(radius, thickness, length): 
    161159    radius = radius + thickness 
    162     length = length + 2*thickness 
    163     ddd = 0.75*radius*(2*radius*length + (length+radius)*(length+pi*radius)) 
    164     return 0.5 * (ddd)**(1./3.) 
     160    length = length + 2 * thickness 
     161    ddd = 0.75 * radius * (2 * radius * length + (length + radius) * (length + pi * radius)) 
     162    return 0.5 * (ddd) ** (1. / 3.) 
    165163 
    166164def VR(radius, thickness, length): 
    167     whole = pi * (radius+thickness)**2 * (length+2*thickness) 
    168     core = pi * radius**2 * length 
    169     return whole, whole-core 
     165    whole = pi * (radius + thickness) ** 2 * (length + 2 * thickness) 
     166    core = pi * radius ** 2 * length 
     167    return whole, whole - core 
    170168 
    171 demo = dict( 
    172     scale=1, background=0, 
    173     core_sld=6, shell_sld=8, solvent_sld=1, 
    174     radius=45, thickness=25, length=340, 
    175     theta=30, phi=15, 
    176     radius_pd=.2, radius_pd_n=1, 
    177     length_pd=.2, length_pd_n=10, 
    178     thickness_pd=.2, thickness_pd_n=10, 
    179     theta_pd=15, theta_pd_n=45, 
    180     phi_pd=15, phi_pd_n=1, 
    181     ) 
     169demo = dict(scale=1, background=0, 
     170            core_sld=6, shell_sld=8, solvent_sld=1, 
     171            radius=45, thickness=25, length=340, 
     172            theta=30, phi=15, 
     173            radius_pd=.2, radius_pd_n=1, 
     174            length_pd=.2, length_pd_n=10, 
     175            thickness_pd=.2, thickness_pd_n=10, 
     176            theta_pd=15, theta_pd_n=45, 
     177            phi_pd=15, phi_pd_n=1) 
    182178oldname = 'CoreShellCylinderModel' 
    183179oldpars = dict(theta='axis_theta', phi='axis_phi') 
Note: See TracChangeset for help on using the changeset viewer.