Changeset 6530963 in sasmodels


Ignore:
Timestamp:
Sep 9, 2018 6:46:10 AM (6 years ago)
Author:
ajj
Branches:
ticket_1156
Children:
78f8308
Parents:
2c12061
Message:

Updating paracrystal models as per ticket #1156 to rename parameters
from nearest neighbour to lattice spacing

Location:
sasmodels/models
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/bcc_paracrystal.c

    r108e70e r6530963  
    11static double 
    2 bcc_Zq(double qa, double qb, double qc, double dnn, double d_factor) 
     2bcc_Zq(double qa, double qb, double qc, double lattice_spacing, double lattice_distortion) 
    33{ 
    44    // Equations from Matsuoka 26-27-28, multiplied by |q| 
     
    1717    //         => exp(a)^2 - 2 cos(d ak) exp(a) + 1) 
    1818    //         => (exp(a) - 2 cos(d ak)) * exp(a) + 1 
    19     const double arg = -0.5*square(dnn*d_factor)*(a1*a1 + a2*a2 + a3*a3); 
     19    const double arg = -0.5*square(lattice_spacing*lattice_distortion)*(a1*a1 + a2*a2 + a3*a3); 
    2020    const double exp_arg = exp(arg); 
    2121    const double Zq = -cube(expm1(2.0*arg)) 
    22         / ( ((exp_arg - 2.0*cos(dnn*a1))*exp_arg + 1.0) 
    23           * ((exp_arg - 2.0*cos(dnn*a2))*exp_arg + 1.0) 
    24           * ((exp_arg - 2.0*cos(dnn*a3))*exp_arg + 1.0)); 
     22        / ( ((exp_arg - 2.0*cos(lattice_spacing*a1))*exp_arg + 1.0) 
     23          * ((exp_arg - 2.0*cos(lattice_spacing*a2))*exp_arg + 1.0) 
     24          * ((exp_arg - 2.0*cos(lattice_spacing*a3))*exp_arg + 1.0)); 
    2525 
    2626#elif 0 
     
    3636    //            = tanh(-a) / [1 - cos(d a_k)/cosh(-a)] 
    3737    // 
    38     const double arg = 0.5*square(dnn*d_factor)*(a1*a1 + a2*a2 + a3*a3); 
     38    const double arg = 0.5*square(lattice_spacing*lattice_distortion)*(a1*a1 + a2*a2 + a3*a3); 
    3939    const double sinh_qd = sinh(arg); 
    4040    const double cosh_qd = cosh(arg); 
    41     const double Zq = sinh_qd/(cosh_qd - cos(dnn*a1)) 
    42                     * sinh_qd/(cosh_qd - cos(dnn*a2)) 
    43                     * sinh_qd/(cosh_qd - cos(dnn*a3)); 
     41    const double Zq = sinh_qd/(cosh_qd - cos(lattice_spacing*a1)) 
     42                    * sinh_qd/(cosh_qd - cos(lattice_spacing*a2)) 
     43                    * sinh_qd/(cosh_qd - cos(lattice_spacing*a3)); 
    4444#else 
    45     const double arg = 0.5*square(dnn*d_factor)*(a1*a1 + a2*a2 + a3*a3); 
     45    const double arg = 0.5*square(lattice_spacing*lattice_distortion)*(a1*a1 + a2*a2 + a3*a3); 
    4646    const double tanh_qd = tanh(arg); 
    4747    const double cosh_qd = cosh(arg); 
    48     const double Zq = tanh_qd/(1.0 - cos(dnn*a1)/cosh_qd) 
    49                     * tanh_qd/(1.0 - cos(dnn*a2)/cosh_qd) 
    50                     * tanh_qd/(1.0 - cos(dnn*a3)/cosh_qd); 
     48    const double Zq = tanh_qd/(1.0 - cos(lattice_spacing*a1)/cosh_qd) 
     49                    * tanh_qd/(1.0 - cos(lattice_spacing*a2)/cosh_qd) 
     50                    * tanh_qd/(1.0 - cos(lattice_spacing*a3)/cosh_qd); 
    5151#endif 
    5252 
     
    5757// occupied volume fraction calculated from lattice symmetry and sphere radius 
    5858static double 
    59 bcc_volume_fraction(double radius, double dnn) 
     59bcc_volume_fraction(double radius, double lattice_spacing) 
    6060{ 
    61     return 2.0*sphere_volume(sqrt(0.75)*radius/dnn); 
     61    return 2.0*sphere_volume(sqrt(0.75)*radius/lattice_spacing); 
    6262} 
    6363 
     
    6969 
    7070 
    71 static double Iq(double q, double dnn, 
    72     double d_factor, double radius, 
     71static double Iq(double q, double lattice_spacing, 
     72    double lattice_distortion, double radius, 
    7373    double sld, double solvent_sld) 
    7474{ 
     
    9494            const double qa = qab*cos_phi; 
    9595            const double qb = qab*sin_phi; 
    96             const double form = bcc_Zq(qa, qb, qc, dnn, d_factor); 
     96            const double form = bcc_Zq(qa, qb, qc, lattice_spacing, lattice_distortion); 
    9797            inner_sum += GAUSS_W[j] * form; 
    9898        } 
     
    103103    const double Zq = outer_sum/(4.0*M_PI); 
    104104    const double Pq = sphere_form(q, radius, sld, solvent_sld); 
    105     return bcc_volume_fraction(radius, dnn) * Pq * Zq; 
     105    return bcc_volume_fraction(radius, lattice_spacing) * Pq * Zq; 
    106106} 
    107107 
    108108 
    109109static double Iqabc(double qa, double qb, double qc, 
    110     double dnn, double d_factor, double radius, 
     110    double lattice_spacing, double lattice_distortion, double radius, 
    111111    double sld, double solvent_sld) 
    112112{ 
    113113    const double q = sqrt(qa*qa + qb*qb + qc*qc); 
    114     const double Zq = bcc_Zq(qa, qb, qc, dnn, d_factor); 
     114    const double Zq = bcc_Zq(qa, qb, qc, lattice_spacing, lattice_distortion); 
    115115    const double Pq = sphere_form(q, radius, sld, solvent_sld); 
    116     return bcc_volume_fraction(radius, dnn) * Pq * Zq; 
     116    return bcc_volume_fraction(radius, lattice_spacing) * Pq * Zq; 
    117117} 
  • sasmodels/models/bcc_paracrystal.py

    r2d81cfe r6530963  
    123123# pylint: disable=bad-whitespace, line-too-long 
    124124#             ["name", "units", default, [lower, upper], "type","description" ], 
    125 parameters = [["dnn",         "Ang",       220,    [-inf, inf], "",            "Nearest neighbour distance"], 
    126               ["d_factor",    "",            0.06, [-inf, inf], "",            "Paracrystal distortion factor"], 
     125parameters = [["lattice_spacing",         "Ang",       220,    [-inf, inf], "",            "Lattice spacing"], 
     126              ["lattice_distortion",    "",            0.06, [-inf, inf], "",            "Paracrystal distortion factor"], 
    127127              ["radius",      "Ang",        40,    [0, inf],    "volume",      "Particle radius"], 
    128128              ["sld",         "1e-6/Ang^2",  4,    [-inf, inf], "sld",         "Particle scattering length density"], 
     
    145145    # in this range 'cuz its easy. 
    146146    radius = 10**np.random.uniform(1.3, 4) 
    147     d_factor = 10**np.random.uniform(-2, -0.7)  # sigma_d in 0.01-0.7 
    148     dnn_fraction = np.random.beta(a=10, b=1) 
    149     dnn = radius*4/np.sqrt(3)/dnn_fraction 
     147    lattice_distortion = 10**np.random.uniform(-2, -0.7)  # sigma_d in 0.01-0.7 
     148    lattice_spacing_fraction = np.random.beta(a=10, b=1) 
     149    lattice_spacing = radius*4/np.sqrt(3)/lattice_spacing_fraction 
    150150    pars = dict( 
    151151        #sld=1, sld_solvent=0, scale=1, background=1e-32, 
    152         dnn=dnn, 
    153         d_factor=d_factor, 
     152        lattice_spacing=lattice_spacing, 
     153        lattice_distortion=lattice_distortion, 
    154154        radius=radius, 
    155155    ) 
  • sasmodels/models/fcc_paracrystal.c

    r108e70e r6530963  
    11static double 
    2 fcc_Zq(double qa, double qb, double qc, double dnn, double d_factor) 
     2fcc_Zq(double qa, double qb, double qc, double lattice_spacing, double lattice_distortion) 
    33{ 
    44    // Equations from Matsuoka 17-18-19, multiplied by |q| 
     
    1616    //         => exp(a)^2 - 2 cos(d ak) exp(a) + 1) 
    1717    //         => (exp(a) - 2 cos(d ak)) * exp(a) + 1 
    18     const double arg = -0.5*square(dnn*d_factor)*(a1*a1 + a2*a2 + a3*a3); 
     18    const double arg = -0.5*square(lattice_spacing*lattice_distortion)*(a1*a1 + a2*a2 + a3*a3); 
    1919    const double exp_arg = exp(arg); 
    2020    const double Zq = -cube(expm1(2.0*arg)) 
    21         / ( ((exp_arg - 2.0*cos(dnn*a1))*exp_arg + 1.0) 
    22           * ((exp_arg - 2.0*cos(dnn*a2))*exp_arg + 1.0) 
    23           * ((exp_arg - 2.0*cos(dnn*a3))*exp_arg + 1.0)); 
     21        / ( ((exp_arg - 2.0*cos(lattice_spacing*a1))*exp_arg + 1.0) 
     22          * ((exp_arg - 2.0*cos(lattice_spacing*a2))*exp_arg + 1.0) 
     23          * ((exp_arg - 2.0*cos(lattice_spacing*a3))*exp_arg + 1.0)); 
    2424 
    2525    return Zq; 
     
    2929// occupied volume fraction calculated from lattice symmetry and sphere radius 
    3030static double 
    31 fcc_volume_fraction(double radius, double dnn) 
     31fcc_volume_fraction(double radius, double lattice_spacing) 
    3232{ 
    33     return 4.0*sphere_volume(M_SQRT1_2*radius/dnn); 
     33    return 4.0*sphere_volume(M_SQRT1_2*radius/lattice_spacing); 
    3434} 
    3535 
     
    4141 
    4242 
    43 static double Iq(double q, double dnn, 
    44   double d_factor, double radius, 
     43static double Iq(double q, double lattice_spacing, 
     44  double lattice_distortion, double radius, 
    4545  double sld, double solvent_sld) 
    4646{ 
     
    6666            const double qa = qab*cos_phi; 
    6767            const double qb = qab*sin_phi; 
    68             const double form = fcc_Zq(qa, qb, qc, dnn, d_factor); 
     68            const double form = fcc_Zq(qa, qb, qc, lattice_spacing, lattice_distortion); 
    6969            inner_sum += GAUSS_W[j] * form; 
    7070        } 
     
    7676    const double Pq = sphere_form(q, radius, sld, solvent_sld); 
    7777 
    78     return fcc_volume_fraction(radius, dnn) * Pq * Zq; 
     78    return fcc_volume_fraction(radius, lattice_spacing) * Pq * Zq; 
    7979} 
    8080 
    8181 
    8282static double Iqabc(double qa, double qb, double qc, 
    83     double dnn, double d_factor, double radius, 
     83    double lattice_spacing, double lattice_distortion, double radius, 
    8484    double sld, double solvent_sld) 
    8585{ 
    8686    const double q = sqrt(qa*qa + qb*qb + qc*qc); 
    8787    const double Pq = sphere_form(q, radius, sld, solvent_sld); 
    88     const double Zq = fcc_Zq(qa, qb, qc, dnn, d_factor); 
    89     return fcc_volume_fraction(radius, dnn) * Pq * Zq; 
     88    const double Zq = fcc_Zq(qa, qb, qc, lattice_spacing, lattice_distortion); 
     89    return fcc_volume_fraction(radius, lattice_spacing) * Pq * Zq; 
    9090} 
  • sasmodels/models/fcc_paracrystal.py

    r2d81cfe r6530963  
    111111# pylint: disable=bad-whitespace, line-too-long 
    112112#             ["name", "units", default, [lower, upper], "type","description"], 
    113 parameters = [["dnn", "Ang", 220, [-inf, inf], "", "Nearest neighbour distance"], 
    114               ["d_factor", "", 0.06, [-inf, inf], "", "Paracrystal distortion factor"], 
     113parameters = [["lattice_spacing", "Ang", 220, [-inf, inf], "", "Lattice spacing"], 
     114              ["lattice_distortion", "", 0.06, [-inf, inf], "", "Paracrystal distortion factor"], 
    115115              ["radius", "Ang", 40, [0, inf], "volume", "Particle radius"], 
    116116              ["sld", "1e-6/Ang^2", 4, [-inf, inf], "sld", "Particle scattering length density"], 
     
    127127    # copied from bcc_paracrystal 
    128128    radius = 10**np.random.uniform(1.3, 4) 
    129     d_factor = 10**np.random.uniform(-2, -0.7)  # sigma_d in 0.01-0.7 
    130     dnn_fraction = np.random.beta(a=10, b=1) 
    131     dnn = radius*4/np.sqrt(2)/dnn_fraction 
     129    lattice_distortion = 10**np.random.uniform(-2, -0.7)  # sigma_d in 0.01-0.7 
     130    lattice_spacing_fraction = np.random.beta(a=10, b=1) 
     131    lattice_spacing = radius*4/np.sqrt(2)/lattice_spacing_fraction 
    132132    pars = dict( 
    133133        #sld=1, sld_solvent=0, scale=1, background=1e-32, 
    134         dnn=dnn, 
    135         d_factor=d_factor, 
     134        latice_spacing=lattice_spacing, 
     135        lattice_distortion=d_factor, 
    136136        radius=radius, 
    137137    ) 
  • sasmodels/models/sc_paracrystal.c

    r108e70e r6530963  
    11static double 
    2 sc_Zq(double qa, double qb, double qc, double dnn, double d_factor) 
     2sc_Zq(double qa, double qb, double qc, double lattice_spacing, double lattice_distortion) 
    33{ 
    44    // Equations from Matsuoka 9-10-11, multiplied by |q| 
     
    1616    //         => exp(a)^2 - 2 cos(d ak) exp(a) + 1) 
    1717    //         => (exp(a) - 2 cos(d ak)) * exp(a) + 1 
    18     const double arg = -0.5*square(dnn*d_factor)*(a1*a1 + a2*a2 + a3*a3); 
     18    const double arg = -0.5*square(lattice_spacing*lattice_distortion)*(a1*a1 + a2*a2 + a3*a3); 
    1919    const double exp_arg = exp(arg); 
    2020    const double Zq = -cube(expm1(2.0*arg)) 
    21         / ( ((exp_arg - 2.0*cos(dnn*a1))*exp_arg + 1.0) 
    22           * ((exp_arg - 2.0*cos(dnn*a2))*exp_arg + 1.0) 
    23           * ((exp_arg - 2.0*cos(dnn*a3))*exp_arg + 1.0)); 
     21        / ( ((exp_arg - 2.0*cos(lattice_spacing*a1))*exp_arg + 1.0) 
     22          * ((exp_arg - 2.0*cos(lattice_spacing*a2))*exp_arg + 1.0) 
     23          * ((exp_arg - 2.0*cos(lattice_spacing*a3))*exp_arg + 1.0)); 
    2424 
    2525    return Zq; 
     
    2828// occupied volume fraction calculated from lattice symmetry and sphere radius 
    2929static double 
    30 sc_volume_fraction(double radius, double dnn) 
     30sc_volume_fraction(double radius, double lattice_spacing) 
    3131{ 
    32     return sphere_volume(radius/dnn); 
     32    return sphere_volume(radius/lattice_spacing); 
    3333} 
    3434 
     
    4141 
    4242static double 
    43 Iq(double q, double dnn, 
    44     double d_factor, double radius, 
     43Iq(double q, double lattice_spacing, 
     44    double lattice_distortion, double radius, 
    4545    double sld, double solvent_sld) 
    4646{ 
     
    6767            const double qa = qab*cos_phi; 
    6868            const double qb = qab*sin_phi; 
    69             const double form = sc_Zq(qa, qb, qc, dnn, d_factor); 
     69            const double form = sc_Zq(qa, qb, qc, lattice_spacing, lattice_distortion); 
    7070            inner_sum += GAUSS_W[j] * form; 
    7171        } 
     
    7777    const double Pq = sphere_form(q, radius, sld, solvent_sld); 
    7878 
    79     return sc_volume_fraction(radius, dnn) * Pq * Zq; 
     79    return sc_volume_fraction(radius, lattice_spacing) * Pq * Zq; 
    8080} 
    8181 
     
    8383static double 
    8484Iqabc(double qa, double qb, double qc, 
    85     double dnn, double d_factor, double radius, 
     85    double lattice_spacing, double lattice_distortion, double radius, 
    8686    double sld, double solvent_sld) 
    8787{ 
    8888    const double q = sqrt(qa*qa + qb*qb + qc*qc); 
    8989    const double Pq = sphere_form(q, radius, sld, solvent_sld); 
    90     const double Zq = sc_Zq(qa, qb, qc, dnn, d_factor); 
    91     return sc_volume_fraction(radius, dnn) * Pq * Zq; 
     90    const double Zq = sc_Zq(qa, qb, qc, lattice_spacing, lattice_distortion); 
     91    return sc_volume_fraction(radius, lattice_spacing) * Pq * Zq; 
    9292} 
  • sasmodels/models/sc_paracrystal.py

    r2d81cfe r6530963  
    116116        scale: volume fraction of spheres 
    117117        bkg:background, R: radius of sphere 
    118         dnn: Nearest neighbor distance 
    119         d_factor: Paracrystal distortion factor 
     118        lattice_spacing: Nearest neighbor distance 
     119        lattice_distortion: Paracrystal distortion factor 
    120120        radius: radius of the spheres 
    121121        sldSph: SLD of the sphere 
     
    126126# pylint: disable=bad-whitespace, line-too-long 
    127127#             ["name", "units", default, [lower, upper], "type","description"], 
    128 parameters = [["dnn",         "Ang",       220.0, [0.0, inf],  "",            "Nearest neighbor distance"], 
    129               ["d_factor",    "",           0.06, [-inf, inf], "",            "Paracrystal distortion factor"], 
     128parameters = [["lattice_spacing",         "Ang",       220.0, [0.0, inf],  "",  "Lattice spacing"], 
     129              ["lattice_distortion",    "",           0.06, [-inf, inf], "",   "Paracrystal distortion factor"], 
    130130              ["radius",      "Ang",        40.0, [0.0, inf],  "volume",      "Radius of sphere"], 
    131131              ["sld",  "1e-6/Ang^2",         3.0, [0.0, inf],  "sld",         "Sphere scattering length density"], 
     
    142142    # copied from bcc_paracrystal 
    143143    radius = 10**np.random.uniform(1.3, 4) 
    144     d_factor = 10**np.random.uniform(-2, -0.7)  # sigma_d in 0.01-0.7 
    145     dnn_fraction = np.random.beta(a=10, b=1) 
    146     dnn = radius*4/np.sqrt(4)/dnn_fraction 
     144    lattice_distortion = 10**np.random.uniform(-2, -0.7)  # sigma_d in 0.01-0.7 
     145    lattice_spacing_fraction = np.random.beta(a=10, b=1) 
     146    lattice_spacing = radius*4/np.sqrt(4)/lattice_spacing_fraction 
    147147    pars = dict( 
    148148        #sld=1, sld_solvent=0, scale=1, background=1e-32, 
    149         dnn=dnn, 
    150         d_factor=d_factor, 
     149        lattice_spacing=lattice_spacing, 
     150        lattice_distortion=lattice_distortion, 
    151151        radius=radius, 
    152152    ) 
Note: See TracChangeset for help on using the changeset viewer.