Changeset a1c32c2 in sasmodels


Ignore:
Timestamp:
Dec 12, 2017 11:08:07 AM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
c11d09f
Parents:
cfa28d3
Message:

Use gauss-legendre integration for cross-checking against P(r)

Location:
explore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • explore/asymint.py

    ra189283 ra1c32c2  
    223223    DA, DB, DC = 2300, 21, 58 
    224224    SLDA, SLDB, SLDC = "5", "-0.3", "11.5" 
     225    #A,B,C,DA,DB,DC,SLDA,SLDB,SLDC = 10,20,30,100,200,300,1,2,3 
     226    #SLD_SOLVENT,CONTRAST = 0, 4 
    225227    if 1: # C shortest 
    226228        B, C = C, B 
  • explore/realspace.py

    rcfa28d3 ra1c32c2  
    77from numpy import pi, radians, sin, cos, sqrt 
    88from numpy.random import poisson, uniform 
     9from numpy.polynomial.legendre import leggauss 
    910from scipy.integrate import simps 
    1011from scipy.special import j1 as J1 
     
    362363 
    363364def cylinder_Iq(q, radius, length): 
    364     height = length/2 
     365    z, w = leggauss(76) 
     366    cos_alpha = (z+1)/2 
     367    sin_alpha = sqrt(1.0 - cos_alpha**2) 
    365368    Iq = np.empty_like(q) 
    366     theta = np.linspace(0.0, pi/2, 500) 
    367369    for k, qk in enumerate(q): 
    368         qab, qc = qk*sin(theta), qk*cos(theta) 
    369         Iq[k] = simps((j0(qc*height)*sas_2J1x_x(qab*radius))**2 * sin(theta)) 
     370        qab, qc = qk*sin_alpha, qk*cos_alpha 
     371        Fq = sas_2J1x_x(qab*radius) * j0(qc*length/2) 
     372        Iq[k] = np.sum(w*Fq**2) 
    370373    Iq = Iq/Iq[0] 
    371374    return Iq 
     
    376379 
    377380def csbox_Iq(q, a, b, c, da, db, dc, slda, sldb, sldc, sld_core): 
     381    z, w = leggauss(76) 
     382 
    378383    sld_solvent = 0 
    379384    overlapping = False 
     
    382387    tA, tB, tC = a + 2*da, b + 2*db, c + 2*dc 
    383388 
    384     Iq = np.zeros_like(q) 
    385     for cos_alpha in np.linspace(0.0, 1.0, 100): 
     389    outer_sum = np.zeros_like(q) 
     390    for cos_alpha, outer_w in zip((z+1)/2, w): 
    386391        sin_alpha = sqrt(1.0-cos_alpha*cos_alpha) 
    387392        qc = q*cos_alpha 
    388393        siC = c*j0(c*qc/2) 
    389394        siCt = tC*j0(tC*qc/2) 
    390         for beta in np.linspace(0.0, pi/2, 100): 
     395        inner_sum = np.zeros_like(q) 
     396        for beta, inner_w in zip((z + 1)*pi/4, w): 
    391397            qa, qb = q*sin_alpha*sin(beta), q*sin_alpha*cos(beta) 
    392398            siA = a*j0(a*qa/2) 
     
    395401            siBt = tB*j0(tB*qb/2) 
    396402            if overlapping: 
    397                 Iq += (dr0*siA*siB*siC 
    398                        + drA*(siAt-siA)*siB*siC 
    399                        + drB*siAt*(siBt-siB)*siC 
    400                        + drC*siAt*siBt*(siCt-siC))**2 
     403                Fq = (dr0*siA*siB*siC 
     404                      + drA*(siAt-siA)*siB*siC 
     405                      + drB*siAt*(siBt-siB)*siC 
     406                      + drC*siAt*siBt*(siCt-siC)) 
    401407            else: 
    402                 Iq += (dr0*siA*siB*siC 
    403                        + drA*(siAt-siA)*siB*siC 
    404                        + drB*siA*(siBt-siB)*siC 
    405                        + drC*siA*siB*(siCt-siC))**2 
     408                Fq = (dr0*siA*siB*siC 
     409                      + drA*(siAt-siA)*siB*siC 
     410                      + drB*siA*(siBt-siB)*siC 
     411                      + drC*siA*siB*(siCt-siC)) 
     412            inner_sum += inner_w * Fq**2 
     413        outer_sum += outer_w * inner_sum 
     414    Iq = outer_sum / 4  # = outer*um*zm*8.0/(4.0*M_PI) 
    406415    return Iq/Iq[0] 
    407416 
Note: See TracChangeset for help on using the changeset viewer.