1 | from sans_extension.prototypes.c_models import CCanvas |
---|
2 | from sans.models.SphereModel import SphereModel |
---|
3 | from sans.models.CoreShellModel import CoreShellModel |
---|
4 | |
---|
5 | import math |
---|
6 | |
---|
7 | # Sphere ############################### |
---|
8 | sphere = SphereModel() |
---|
9 | sphere.setParam('radius',40.0) |
---|
10 | sphere.setParam('contrast',1.0) |
---|
11 | sphere.setParam('scale',1.0) |
---|
12 | sphere.setParam('background',0.0) |
---|
13 | |
---|
14 | can = CCanvas() |
---|
15 | |
---|
16 | print "ID", can.add() |
---|
17 | can.setParam(0,1,40.0) |
---|
18 | |
---|
19 | |
---|
20 | for q in [1,0.1,0.05,0.02,0.01,0.001,0.0001]: |
---|
21 | ana = sphere.run([q,1.0]) |
---|
22 | sim = can.evaluate([q,1.0]) |
---|
23 | |
---|
24 | print "Sphere: ANA = %g SIM = %g (%g)" %(ana, sim, sim/ana) |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | # Core-shell ########################### |
---|
30 | # This is a core shell model where the weight-average |
---|
31 | # of the SLDs is zero. The I(q) should go to zero as q->0. |
---|
32 | |
---|
33 | import time |
---|
34 | t_0 = time.time() |
---|
35 | |
---|
36 | sphere = CoreShellModel() |
---|
37 | # Core radius |
---|
38 | radius = 10.0 |
---|
39 | thickness = 5.0 |
---|
40 | sphere.setParam('radius', radius) |
---|
41 | # Shell thickness |
---|
42 | sphere.setParam('thickness', thickness) |
---|
43 | sphere.setParam('core_sld', 1.0) |
---|
44 | |
---|
45 | core_vol = 4.0/3.0*math.pi*radius*radius*radius |
---|
46 | outer_radius = radius+thickness |
---|
47 | shell_vol = 4.0/3.0*math.pi*outer_radius*outer_radius*outer_radius - core_vol |
---|
48 | shell_sld = -1.0*core_vol/shell_vol |
---|
49 | print "Shell SLD", shell_sld |
---|
50 | |
---|
51 | sphere.setParam('shell_sld', shell_sld) |
---|
52 | sphere.setParam('solvent_sld',0.0) |
---|
53 | sphere.setParam('background',0.0) |
---|
54 | sphere.setParam('scale',1.0) |
---|
55 | |
---|
56 | can = CCanvas() |
---|
57 | |
---|
58 | print "ID", can.add() |
---|
59 | can.setParam(0,1, outer_radius) |
---|
60 | can.setParam(0,2, shell_sld) |
---|
61 | |
---|
62 | |
---|
63 | print "ID", can.add() |
---|
64 | can.setParam(1,1, radius) |
---|
65 | can.setParam(1,2, 1.0) |
---|
66 | |
---|
67 | print "VOLS inner = %g, outer = %g, shell = %g" % (core_vol, shell_vol+core_vol, shell_vol) |
---|
68 | |
---|
69 | f = open('core-shell.txt','w') |
---|
70 | f.write("<q_cs> <ans_cs> <sim_cs>\n") |
---|
71 | for q in [1,0.1,0.05,0.04,0.03,0.02,0.01,0.005,0.001,0.0001]: |
---|
72 | #for i in range(400): |
---|
73 | #q = 0.0001+i*0.005 |
---|
74 | ana = sphere.run([q,1.0]) |
---|
75 | sim = can.evaluate([q,1.0]) |
---|
76 | f.write("%g %g %g\n" %(q, ana, sim)) |
---|
77 | print "Core-shell: q=%g ANA = %g SIM = %g (%g)" %(q, ana, sim, sim/ana) |
---|
78 | |
---|
79 | f.close() |
---|
80 | |
---|
81 | |
---|
82 | print "Time: ", time.time()-t_0 |
---|