Changeset 97be877 in sasmodels for explore


Ignore:
Timestamp:
Jan 11, 2018 11:58:23 AM (7 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:
8fb2a94
Parents:
e077231
Message:

update authorship/verification for core-shell parallelepiped

File:
1 edited

Legend:

Unmodified
Added
Removed
  • explore/realspace.py

    r2ab331f r97be877  
    399399    #ax.axis([low[0], high[0], low[1], high[1], low[2], high[2]]) 
    400400    ax.autoscale(True) 
     401 
     402def check_shape(shape, fn=None): 
     403    rho_solvent = 0 
     404    q = np.logspace(-3, 0, 200) 
     405    r = shape.r_bins(q, r_step=0.01) 
     406    sampling_density = 50000 / shape.volume() 
     407    rho, points = shape.sample(sampling_density) 
     408    Pr = calc_Pr(r, rho-rho_solvent, points) 
     409    Iq = calc_Iq(q, r, Pr) 
     410    theory = (q, fn(q)) if fn is not None else None 
     411 
     412    import pylab 
     413    #plot_points(rho, points); pylab.figure() 
     414    plot_calc(r, Pr, q, Iq, theory=theory) 
     415    pylab.show() 
     416 
     417def check_shape_2d(shape, fn=None, view=(0, 0, 0)): 
     418    rho_solvent = 0 
     419    nq, qmax = 100, 1.0 
     420    qx = np.linspace(0.0, qmax, nq) 
     421    qy = np.linspace(0.0, qmax, nq) 
     422    Qx, Qy = np.meshgrid(qx, qy) 
     423    sampling_density = 50000 / shape.volume() 
     424    #t0 = time.time() 
     425    rho, points = shape.sample(sampling_density) 
     426    #print("sample time", time.time() - t0) 
     427    t0 = time.time() 
     428    Iqxy = calc_Iqxy(Qx, Qy, rho, points, view=view) 
     429    print("calc time", time.time() - t0) 
     430    theory = fn(Qx, Qy) if fn is not None else None 
     431    Iqxy += 0.001 * Iqxy.max() 
     432    if theory is not None: 
     433        theory += 0.001 * theory.max() 
     434 
     435    import pylab 
     436    #plot_points(rho, points); pylab.figure() 
     437    plot_calc_2d(qx, qy, Iqxy, theory=theory) 
     438    pylab.show() 
     439 
     440def sas_sinx_x(x): 
     441    with np.errstate(all='ignore'): 
     442        retvalue = sin(x)/x 
     443    retvalue[x == 0.] = 1. 
     444    return retvalue 
    401445 
    402446def sas_2J1x_x(x): 
     
    473517    return Iq/Iq[0] 
    474518 
    475 def check_shape(shape, fn=None): 
    476     rho_solvent = 0 
    477     q = np.logspace(-3, 0, 200) 
    478     r = shape.r_bins(q, r_step=0.01) 
    479     sampling_density = 50000 / shape.volume() 
    480     rho, points = shape.sample(sampling_density) 
    481     Pr = calc_Pr(r, rho-rho_solvent, points) 
    482     Iq = calc_Iq(q, r, Pr) 
    483     theory = (q, fn(q)) if fn is not None else None 
    484  
    485     import pylab 
    486     #plot_points(rho, points); pylab.figure() 
    487     plot_calc(r, Pr, q, Iq, theory=theory) 
    488     pylab.show() 
    489  
    490 def check_shape_2d(shape, fn=None, view=(0, 0, 0)): 
    491     rho_solvent = 0 
    492     nq, qmax = 100, 0.1 
    493     nq, qmax = 100, 0.03 
    494     qx = np.linspace(0.0, qmax, nq) 
    495     qy = np.linspace(0.0, qmax, nq) 
    496     Qx, Qy = np.meshgrid(qx, qy) 
    497     sampling_density = 15000 / shape.volume() 
    498     #t0 = time.time() 
    499     rho, points = shape.sample(sampling_density) 
    500     #print("sample time", time.time() - t0) 
    501     t0 = time.time() 
    502     Iqxy = calc_Iqxy(Qx, Qy, rho, points, view=view) 
    503     print("calc time", time.time() - t0) 
    504     theory = fn(Qx, Qy) if fn is not None else None 
    505     Iqxy += 0.001 * Iqxy.max() 
    506     if theory is not None: 
    507         theory += 0.001 * theory.max() 
    508  
    509     import pylab 
    510     #plot_points(rho, points); pylab.figure() 
    511     plot_calc_2d(qx, qy, Iqxy, theory=theory) 
    512     pylab.show() 
     519def csbox_Iqxy(qx, qy, a, b, c, da, db, dc, slda, sldb, sldc, sld_core, view=(0,0,0)): 
     520    qa, qb, qc = invert_view(qx, qy, view) 
     521 
     522    sld_solvent = 0 
     523    overlapping = False 
     524    dr0 = sld_core - sld_solvent 
     525    drA, drB, drC = slda-sld_solvent, sldb-sld_solvent, sldc-sld_solvent 
     526    tA, tB, tC = a + 2*da, b + 2*db, c + 2*dc 
     527    siA = a*sas_sinx_x(a*qa/2) 
     528    siB = b*sas_sinx_x(b*qb/2) 
     529    siC = c*sas_sinx_x(c*qc/2) 
     530    siAt = tA*sas_sinx_x(tA*qa/2) 
     531    siBt = tB*sas_sinx_x(tB*qb/2) 
     532    siCt = tC*sas_sinx_x(tC*qc/2) 
     533    Fq = (dr0*siA*siB*siC 
     534          + drA*(siAt-siA)*siB*siC 
     535          + drB*siA*(siBt-siB)*siC 
     536          + drC*siA*siB*(siCt-siC)) 
     537    Iq = Fq**2 
     538    return Iq.reshape(qx.shape) 
    513539 
    514540def check_cylinder(radius=25, length=125, rho=2.): 
     
    558584    side_c2 = copy(side_c).shift(0, 0, -c-dc) 
    559585    shape = Composite((core, side_a, side_b, side_c, side_a2, side_b2, side_c2)) 
    560     fn = lambda q: csbox_Iq(q, a, b, c, da, db, dc, slda, sldb, sldc, sld_core) 
     586    def fn(q): 
     587        return csbox_Iq(q, a, b, c, da, db, dc, slda, sldb, sldc, sld_core) 
    561588    check_shape(shape, fn) 
     589 
     590    view = (20, 30, 40) 
     591    def fn_xy(qx, qy): 
     592        return csbox_Iqxy(qx, qy, a, b, c, da, db, dc, 
     593                          slda, sldb, sldc, sld_core, view=view) 
     594    #check_shape_2d(shape, fn_xy, view=view) 
    562595 
    563596if __name__ == "__main__": 
Note: See TracChangeset for help on using the changeset viewer.