Changeset 66ebdd6 in sasmodels


Ignore:
Timestamp:
Nov 19, 2015 2:47:50 PM (9 years ago)
Author:
krzywon
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:
5d80bbf
Parents:
8fe0b9b
Message:

Finished the hollow_cylinder model and added unit tests to guinier and
lorentz models.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    rd6adfbe r66ebdd6  
    1414/coverage.xml 
    1515/.coverage 
     16/.project 
     17/.pydevproject 
  • sasmodels/models/guinier.py

    reff3d66 r66ebdd6  
    2626description = """ 
    2727 I(q) = scale exp ( - rg^2 q^2 / 3.0 ) 
    28          
     28  
    2929    List of default parameters: 
    3030    scale = scale 
     
    3434 
    3535#             ["name", "units", default, [lower, upper], "type","description"], 
    36 parameters = [["rg", "Ang", 60.0, [0, inf], "", "Radius of Gyration"],] 
     36parameters = [ 
     37              ["rg", "Ang", 60.0, [0, inf], "", "Radius of Gyration"], 
     38              ] 
    3739 
    3840Iq = """ 
    39     double value = rg*rg*q*q/3.0; 
    40     return exp(-value); 
     41    double exponent = rg*rg*q*q/3.0; 
     42    double value = exp(-exponent); 
     43    return value; 
    4144""" 
    4245 
     
    5255oldname = 'GuinierModel' 
    5356oldpars = dict(rg='rg') 
     57 
     58# parameters for unit tests 
     59tests = [ 
     60         [{'rg' : 31.5}, 0.005, 0.991756] 
     61         ] 
  • sasmodels/models/hollow_cylinder.c

    r6cf1cb3 r66ebdd6  
    1 double _hollow_cylinder_kernel(double q, double core_radius, double radius,  
     1static double _hollow_cylinder_kernel(double q, double core_radius, double radius,  
    22        double length, double dum); 
     3static double hollow_cylinder_analytical_2D_scaled(double q, double q_x, double q_y, double radius, double core_radius, double length, double sld, 
     4        double solvent_sld, double theta, double phi); 
     5static double hollow_cylinder_scaling(double integrand, double delrho, double volume); 
     6         
     7double form_volume(double radius, double core_radius, double length); 
    38 
    4 double form_volume(double radius, double core_radius, double length); 
    59double Iq(double q, double radius, double core_radius, double length, double sld, 
    610        double solvent_sld); 
     
    913 
    1014// From Igor library 
    11 double _hollow_cylinder_kernel(double q, double core_radius, double radius,  
     15static double _hollow_cylinder_kernel(double q, double core_radius, double radius,  
    1216        double length, double dum) 
    1317{ 
     
    4044    return(retval); 
    4145} 
     46static double hollow_cylinder_analytical_2D_scaled(double q, double q_x, double q_y, double radius, double core_radius, double length, double sld, 
     47        double solvent_sld, double theta, double phi) { 
     48        double cyl_x, cyl_y; //, cyl_z 
     49        //double q_z; 
     50        double vol, cos_val, delrho; 
     51        double answer; 
     52        //convert angle degree to radian 
     53        double pi = 4.0*atan(1.0); 
     54        theta = theta * pi/180.0; 
     55        phi = phi * pi/180.0; 
     56        delrho = solvent_sld - sld; 
     57 
     58        // Cylinder orientation 
     59        cyl_x = cos(theta) * cos(phi); 
     60        cyl_y = sin(theta); 
     61        //cyl_z = -cos(theta) * sin(phi); 
     62 
     63        // q vector 
     64        //q_z = 0; 
     65 
     66        // Compute the angle btw vector q and the 
     67        // axis of the cylinder 
     68        cos_val = cyl_x*q_x + cyl_y*q_y;// + cyl_z*q_z; 
     69 
     70        // The following test should always pass 
     71        if (fabs(cos_val)>1.0) { 
     72                printf("core_shell_cylinder_analytical_2D: Unexpected error: cos(alpha)=%g\n", cos_val); 
     73                return 0; 
     74        } 
     75 
     76        answer = _hollow_cylinder_kernel(q, core_radius, radius, length, cos_val); 
     77 
     78        vol = form_volume(radius, core_radius, length); 
     79        answer = hollow_cylinder_scaling(answer, delrho, vol); 
     80 
     81        return answer; 
     82} 
     83static double hollow_cylinder_scaling(double integrand, double delrho, double volume) 
     84{ 
     85        double answer; 
     86        // Multiply by contrast^2 
     87        answer = integrand*delrho*delrho; 
     88 
     89        //normalize by cylinder volume 
     90        answer *= volume*volume; 
     91 
     92        //convert to [cm-1] 
     93        answer *= 1.0e-4; 
     94         
     95        return answer; 
     96} 
     97 
    4298 
    4399double form_volume(double radius, double core_radius, double length) 
     
    48104} 
    49105 
     106 
    50107double Iq(double q, double radius, double core_radius, double length, double sld, 
    51108        double solvent_sld) 
     
    55112        double lower,upper,zi, inter;           //upper and lower integration limits 
    56113        double summ,answer,delrho;                      //running tally of integration 
    57         double norm,scale,volume,convert;       //final calculation variables 
     114        double norm,volume;     //final calculation variables 
    58115         
    59116        delrho = solvent_sld - sld; 
     
    69126         
    70127        norm = summ*(upper-lower)/2.0; 
    71         // Multiply by contrast^2 
    72         scale = delrho*delrho; 
    73         //normalize by volume 
    74128        volume = form_volume(radius, core_radius, length); 
    75         //convert to [cm-1] given sld*1e6 
    76         convert = 1.0e-4; 
    77         answer = norm*scale*convert*volume*volume; 
     129        answer = hollow_cylinder_scaling(norm, delrho, volume); 
    78130         
    79131        return(answer); 
    80132} 
    81133 
    82 //TODO: Add this in 
     134//FIXME: Factor of two difference 
    83135double Iqxy(double qx, double qy, double radius, double core_radius, double length, double sld, 
    84136        double solvent_sld, double theta, double phi) 
    85137{ 
    86     return(0.0); 
     138        double q; 
     139        q = sqrt(qx*qx+qy*qy); 
     140        return hollow_cylinder_analytical_2D_scaled(q, qx/q, qy/q, radius, core_radius, length, sld, solvent_sld, theta, phi); 
    87141} 
  • sasmodels/models/hollow_cylinder.py

    r6cf1cb3 r66ebdd6  
    4949.. image:: img/image061.jpg 
    5050 
    51 *Figure. Definition of the angles for the oriented HollowCylinderModel.* 
     51*Figure. Definition of the angles for the oriented hollow_cylinder model.* 
    5252 
    5353.. image:: img/image062.jpg 
     
    103103               core_radius='core_radius',sld='sldCyl',length='length', 
    104104               solvent_sld='sldSolv',phi='axis_phi',theta='axis_theta') 
     105 
     106# Parameters for unit tests 
     107tests = [ 
     108         [{"radius" : 30.0},0.00005,1764.926] 
     109         ] 
  • sasmodels/models/lorentz.py

    r77ad412 r66ebdd6  
    6060oldname = 'LorentzModel' 
    6161oldpars = dict(cor_length='length') 
     62 
     63# parameters for unit tests 
     64tests = [ 
     65         [{'cor_length' : 250},0.01,0.137931] 
     66         ] 
Note: See TracChangeset for help on using the changeset viewer.