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
|
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.10"
# dependencies = ["bornagain>=25,<26"]
# ///
"""
Dense cylinders, approximated as ideal gas or as hard disks.
Horizontal cut through GISAS image.
"""
import bornagain as ba
ba.require_versions("bornagain>=25,<26")
from bornagain import deg, nm, nm2
def get_sample(approx):
# materials
vacuum = ba.Vacuum()
substrate_color = (0.28, 0.57, 0.82)
substrate_mat = ba.RefractiveMaterial("Substrate", substrate_color, 6e-6, 2e-8)
particle_color = (0.86, 0.24, 0.18)
particle_mat = ba.RefractiveMaterial("Particle", particle_color, 3e-5, 2e-8)
# particle
ff = ba.Cylinder(5*nm, 1*nm)
particle = ba.Particle(particle_mat, ff)
# layers
toplayer = ba.Layer(vacuum)
density = 0.008/nm2
if approx == "Dilute":
toplayer.deposit2D(ba.Dilute2D(density, particle))
else:
toplayer.deposit2D(ba.Dense2D(density, particle))
substrate = ba.Layer(substrate_mat)
sample = ba.Sample()
sample.addLayer(toplayer)
sample.addLayer(substrate)
return sample
def simulate(sample, title):
beam = ba.Beam(1e9, 0.03*nm, 0.2*deg)
n = 555
detector = ba.SphericalDetector(n, -1*deg, 1*deg, 1, 0.78*deg, 0.82*deg)
simulation = ba.ScatteringSimulation(beam, sample, detector)
field = simulation.simulate()
field.setTitle(title)
return field.flat()
if __name__ == '__main__':
ba.showSample3D(get_sample("Dilute"), sample_size=80*nm, seed=0)
results = [
simulate(get_sample("Dilute"), "ideal gas"),
simulate(get_sample("Dense"), "hard disks"),
]
ba.plot_multicurve(results)
ba.plt.show()
|