source: sasmodels/sesansdemo.py @ 1e11735

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 1e11735 was 10576d1, checked in by pkienzle, 10 years ago

add hankel function and sesans demo (not yet integrated with models)

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[10576d1]1# Example of conversion of scattering cross section from SANS in absolute
2# units into SESANS using a Hankel transformation
3# everything is in units of metres except specified otherwise
4# Wim Bouwman (w.g.bouwman@tudelft.nl), June 2013
5
6from __future__ import division
7
8from pylab import *
9from scipy.special import jv as besselj
10
11# q-range parameters
12q = arange(0.0003, 1.0, 0.0003);    # [nm^-1] range wide enough for  Hankel transform
13dq=(q[1]-q[0])*1e9;   # [m^-1] step size in q, needed for integration
14nq=len(q);
15Lambda=2e-10;   # [m] wavelength
16# sample parameters
17phi=0.1;   # volume fraction
18R=100;       # [nm] radius particles
19DeltaRho=6e14;  # [m^-2]
20V=4/3*pi*R**3 * 1e-27; # [m^3]
21th=0.002;    # [m] thickness sample
22
23#2 PHASE SYSTEM
24st= 1.5*Lambda**2*DeltaRho**2*th*phi*(1-phi)*R*1e-9  # scattering power in sesans formalism
25
26# Form factor solid sphere
27qr=q*R;
28P=(3.*(sin(qr)-qr*cos(qr)) / qr**3)**2;
29# Structure factor dilute
30S=1.;
31#2 PHASE SYSTEM
32# scattered intensity [m^-1] in absolute units according to SANS
33I=phi*(1-phi)*V*(DeltaRho**2)*P*S;
34
35clf()
36subplot(1,2,1)  # plot the SANS calculation
37plot(q,I,'k')
38loglog(q,I)
39xlim([0.01, 1])
40ylim([1, 1e9])
41xlabel(r'$Q [nm^{-1}]$')
42ylabel(r'$d\Sigma/d\Omega [m^{-1}]$')
43
44
45# Hankel transform to nice range for plot
46nz=61;
47zz=linspace(0,240,nz); # [nm], should be less than reciprocal from q
48G=zeros(nz);
49for i in range(len(zz)):
50    integr=besselj(0,q*zz[i])*I*q;
51    G[i]=sum(integr);
52G=G*dq*1e9*2*pi; # integr step, conver q into [m**-1] and 2 pi circle integr
53# plot(zz,G);
54stt= th*Lambda**2/4/pi/pi*G[0]  # scattering power according to SANS formalism
55PP=exp(th*Lambda**2/4/pi/pi*(G-G[0]));
56
57subplot(1,2,2)
58plot(zz,PP,'k',label="Hankel transform") # Hankel transform 1D
59xlabel('spin-echo length [nm]')
60ylabel('polarisation normalised')
61hold(True)
62
63# Cosine transformation of 2D scattering patern
64if True:
65    qy,qz = meshgrid(q,q)
66    qr=R*sqrt(qy**2 + qz**2); # reuse variable names Hankel transform, but now 2D
67    P=(3.*(sin(qr)-qr*cos(qr)) / qr**3)**2;
68    # Structure factor dilute
69    S=1.;
70    # scattered intensity [m^-1] in absolute units according to SANS
71    I=phi*V*(DeltaRho**2)*P*S;
72    GG=zeros(nz);
73    for i in range(len(zz)):
74        integr=cos(qz*zz[i])*I;
75        GG[i]=sum(sum(integr));
76    GG=4*GG* dq**2; # take integration step into account take 4 quadrants
77    # plot(zz,GG);
78    sstt= th*Lambda**2/4/pi/pi*GG[0]  # scattering power according to SANS formalism
79    PPP=exp(th*Lambda**2/4/pi/pi*(GG-GG[0]));
80
81    plot(zz,PPP,label="cosine transform") # cosine transform 2D
82
83# For comparison calculation in SESANS formalism, which overlaps perfectly
84def gsphere(z,r):
85    """
86    Calculate SESANS-correlation function for a solid sphere.
87
88    Wim Bouwman after formulae Timofei Kruglov J.Appl.Cryst. 2003 article
89    """
90    d = z/r
91    g = zeros_like(z)
92    g[d==0] = 1.
93    low = ((d > 0) & (d < 2))
94    dlow = d[low]
95    dlow2 = dlow**2
96    print dlow.shape, dlow2.shape
97    g[low] = sqrt(1-dlow2/4.)*(1+dlow2/8.) + dlow2/2.*(1-dlow2/16.)*log(dlow/(2.+sqrt(4.-dlow2)))
98    return g
99
100if True:
101    plot(zz,exp(st*(gsphere(zz,R)-1)),'r', label="analytical")
102legend()
103show()
Note: See TracBrowser for help on using the repository browser.