1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.10"
# dependencies = ["bornagain>=25,<26"]
# ///
"""
SAS form-factor examples.
Demonstrates the scattered intensity for a dilute layer of particles
with a given form factor. The particle geometry and the relative
absorption are selected via command-line arguments:
particle_geometry=<name> (required)
relative_absorption=<float> (default 0; beta = value * delta)
"""
import sys
import bornagain as ba
ba.require_versions("bornagain>=25,<26")
from bornagain import deg, nm
# ---------------------------------------------------------------------------
# Per-geometry factory functions
# Each returns a list of (particle, title) pairs.
# ---------------------------------------------------------------------------
def particles_BarLorentz(material):
ff = ba.BarLorentz(20*nm, 6.3*nm, 4.7*nm)
result = []
for omega in [0, 45, 90]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_Bipyramid4(material):
ff = ba.Bipyramid4(8*nm, 4.3*nm, 0.5, 70*deg)
result = []
for omega in [0, 30, 45]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_Box(material):
ff = ba.Box(12*nm, 4.1*nm, 6*nm)
result = []
for omega in [0, 30, 45]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_CantellatedCube(material):
ff = ba.CantellatedCube(8*nm, 2.5*nm)
result = []
for omega in [0, 45]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_Cone(material):
ff = ba.Cone(4.25*nm, 12*nm, 75*deg)
result = []
for theta in [0, 45, 90]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationY(theta*deg))
result.append((p, r'$\theta=%d^\circ$' % theta))
return result
def particles_CosineRippleBox(material):
ff = ba.CosineRippleBox(20*nm, 6.3*nm, 4.7*nm)
result = []
for omega in [0, 45, 90]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_Cylinder(material):
ff = ba.Cylinder(3.6*nm, 7.2*nm)
result = []
for theta in [0, 45, 90]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationY(theta*deg))
result.append((p, r'$\theta=%d^\circ$' % theta))
return result
def particles_Dodecahedron(material):
ff = ba.Dodecahedron(3.38*nm)
titles = ['face normal', 'vertex normal', 'edge normal']
angles = [26.5651, -52.6226, 58.2825]
result = []
for angle, title in zip(angles, titles):
p = ba.Particle(material, ff)
p.rotate(ba.RotationY(angle*deg))
result.append((p, title))
return result
def particles_Ellipsoid(material):
ff = ba.Ellipsoid(4.4*nm, 8*nm, 4*nm)
result = []
for omega in [0, 45, 90]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_EllipsoidalCylinder(material):
ff = ba.EllipsoidalCylinder(7.8*nm, 3*nm, 4*nm)
result = []
for omega in [0, 45, 90]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_EllipsoidalSegment(material):
ff = ba.EllipsoidalSegment(4.4*nm, 8*nm, 4*nm, 0, 4*nm)
result = []
for omega in [0, 45, 90]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_HorizontalCylinder(material):
ff = ba.HorizontalCylinder(4*nm, 9*nm, 1.7*nm, 2*nm)
result = []
for omega in [0, 45, 90]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_Icosahedron(material):
ff = ba.Icosahedron(5.13*nm)
titles = ['face normal', 'vertex normal', 'edge normal']
angles = [48.1897, -52.6226, 69.0948]
result = []
for angle, title in zip(angles, titles):
p = ba.Particle(material, ff)
p.rotate(ba.RotationY(angle*deg))
result.append((p, title))
return result
def particles_PlatonicOctahedron(material):
ff = ba.PlatonicOctahedron(8.55*nm)
titles = ['face normal', 'vertex normal', 'edge normal']
angles = [30, 90, 0]
result = []
for angle, title in zip(angles, titles):
p = ba.Particle(material, ff)
p.rotate(ba.RotationY(angle*deg))
result.append((p, title))
return result
def particles_PlatonicTetrahedron(material):
ff = ba.PlatonicTetrahedron(13.6*nm)
titles = ['vertex normal', 'edge normal']
angles = [-90, 38.68218]
result = []
for angle, title in zip(angles, titles):
p = ba.Particle(material, ff)
p.rotate(ba.RotationY(angle*deg))
result.append((p, title))
return result
def particles_Prism3(material):
ff = ba.Prism3(9.2*nm, 8*nm)
result = []
for omega in [0, 15, 30]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_Prism6(material):
ff = ba.Prism6(3.77*nm, 8*nm)
result = []
for omega in [0, 15, 30]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_Pyramid2(material):
ff = ba.Pyramid2(6.4*nm, 13*nm, 7*nm, 70*deg, 70*deg)
result = []
for omega in [0, 45, 90]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_Pyramid3(material):
ff = ba.Pyramid3(14*nm, 6.8*nm, 70*deg)
result = []
for omega in [0, 15, 30]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_Pyramid4(material):
ff = ba.Pyramid4(10*nm, 4*nm, 70*deg)
result = []
for omega in [0, 30]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_Pyramid6(material):
ff = ba.Pyramid6(5.43*nm, 6.8*nm, 70*deg)
result = []
for omega in [0, 15, 30]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_SawtoothRippleBox(material):
ff = ba.SawtoothRippleBox(20*nm, 6.3*nm, 4.7*nm, 3*nm)
result = []
for omega in [0, 45, 90]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
def particles_Sphere(material):
ff = ba.Sphere(4.13*nm)
return [(ba.Particle(material, ff), None)]
def particles_SphericalSegment(material):
ff = ba.SphericalSegment(7*nm, 1*nm, 9.75*nm)
result = []
for theta in [0, 45, 90]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationY(theta*deg))
result.append((p, r'$\theta=%d^\circ$' % theta))
return result
def particles_Spheroid(material):
ff = ba.Spheroid(6.85*nm, 1.5*nm)
result = []
for theta in [0, 45, 90]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationY(theta*deg))
result.append((p, r'$\theta=%d^\circ$' % theta))
return result
def particles_SpheroidalSegment(material):
ff = ba.SpheroidalSegment(7*nm, 13.3*nm, 2.3*nm, 20.6*nm)
result = []
for theta in [0, 45, 90]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationY(theta*deg))
result.append((p, r'$\theta=%d^\circ$' % theta))
return result
def particles_TruncatedCube(material):
ff = ba.TruncatedCube(6.74*nm, 2*nm)
result = []
for omega in [0, 15, 45]:
p = ba.Particle(material, ff)
p.rotate(ba.RotationZ(omega*deg))
result.append((p, r'$\omega=%d^\circ$' % omega))
return result
# ---------------------------------------------------------------------------
# Simulation
# ---------------------------------------------------------------------------
def get_simulation(particle):
n = 201
beam = ba.Beam(1, 1*ba.angstrom, 0)
detector = ba.SphericalDetector(
n, -4.5*deg, 4.5*deg, n, -4.5*deg, 4.5*deg)
return ba.ParticleSimulation(beam, particle, detector)
# ---------------------------------------------------------------------------
# Main
# ---------------------------------------------------------------------------
if __name__ == '__main__':
# Extract script-specific args and clean sys.argv so that
# ba_check.persistence_test only sees datfile/reference/tolerance.
particle_geometry = None
relative_absorption = 0.0
clean_argv = [sys.argv[0]]
for arg in sys.argv[1:]:
s = arg.split('=', 1)
if s[0] == 'particle_geometry':
particle_geometry = s[1]
elif s[0] == 'relative_absorption':
relative_absorption = float(s[1])
else:
clean_argv.append(arg)
sys.argv = clean_argv
if particle_geometry is None:
raise ValueError("Required argument 'particle_geometry' is missing")
delta = 1e-6
particle_color = (0.86, 0.24, 0.18)
material = ba.RefractiveMaterial(
"Particle", particle_color, delta, relative_absorption*delta)
factory = globals()[f'particles_{particle_geometry}']
pairs = factory(material)
results = []
for particle, title in pairs:
simulation = get_simulation(particle)
result = simulation.simulate()
if title is not None:
result.setTitle(title)
results.append(result)
ba.plot_ff_to_row(results)
ba.plt.show()
|