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
|
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.10"
# dependencies = ["bornagain>=25,<26"]
# ///
"""
Compare ordered A/B spheres with the same structure at the mean SLD.
Within reciprocal-space summation, the selection rule removes the A/B
ordering reflections and gives the pattern of the mean-SLD model.
"""
import bornagain as ba
ba.require_versions("bornagain>=25,<26")
from bornagain import deg, nm, nm2, R3
def get_sample(use_selection_rule=False, average_material=False):
# Scattering length densities in inverse square angstroms
sld_a, sld_b = 6e-5, 1e-5
if average_material:
sld_a = sld_b = (sld_a + sld_b)/2
particle_color = (0.86, 0.24, 0.18)
material_a = ba.SLDMaterial("A", particle_color, sld_a, 0)
b_color = (0.25, 0.65, 0.35)
material_b = ba.SLDMaterial("B", b_color, sld_b, 0)
substrate_color = (0.28, 0.57, 0.82)
substrate_mat = ba.SLDMaterial("Substrate", substrate_color, 2e-5, 0)
# Ordered binary cell: A at the corner, B at the centre
a = 8*nm
sphere = ba.Sphere(2*nm)
basis = ba.Compound()
basis.addComponent(ba.Particle(material_a, sphere), R3(0, 0, 0))
basis.addComponent(ba.Particle(material_b, sphere), R3(a/2, a/2, a/2))
lattice = ba.CubicLattice(a)
if use_selection_rule:
lattice.setSelectionRule(ba.SimpleSelectionRule(1, 1, 1, 2))
crystal = ba.Crystal(basis, lattice)
mesocrystal = ba.Mesocrystal(crystal, ba.Cylinder(20*nm, 50*nm))
# Mesocrystals on a substrate, with a sliced particle layer
layer = ba.Layer(ba.Vacuum())
layer.deposit2D(ba.Dilute2D(0.0001/nm2, mesocrystal))
layer.setNumberOfSlices(5)
sample = ba.Sample()
sample.addLayer(layer)
sample.addLayer(ba.Layer(substrate_mat))
return sample
def get_simulation(sample):
beam = ba.Beam(1e9, 0.1*nm, 0.2*deg)
n = 200
detector = ba.SphericalDetector(n, -2*deg, 2*deg, n, 0, 2*deg)
simulation = ba.ScatteringSimulation(beam, sample, detector)
return simulation
def simulate(title, use_selection_rule=False, average_material=False):
sample = get_sample(use_selection_rule, average_material)
simulation = get_simulation(sample)
simulation.options().setMesoReciprocalSum(True, 2.5)
result = simulation.simulate()
result.setTitle(title)
return result
if __name__ == '__main__':
results = [
simulate('Ordered A/B'),
simulate('Mean SLD (selection rule)', use_selection_rule=True),
]
ba.showSample3D(get_sample(), sample_size=250*nm, seed=189)
ba.plot2d_to_row(results, unit_aspect=1)
ba.plt.show()
|