| 1 |
+++ |
| 2 |
title = "Compound particle" |
| 3 |
weight = 80 |
| 4 |
+++ |
| 5 |
|
| 6 |
## Compound particle |
| 7 |
|
| 8 |
This tutorial demonstrates how to construct complex shape particles. |
| 9 |
|
| 10 |
All particles implemented in BornAgain are defined by their form factors, |
| 11 |
their sizes and the materials they are made of. The form factor library |
| 12 |
provides access to elementary shapes. A `Compound` object composes simple |
| 13 |
particles and other composite particles into one coherent particle object: |
| 14 |
it can be rotated, translated and used wherever an `IParticle` is accepted. |
| 15 |
|
| 16 |
The scattering from such a particle accounts for coherent interference between |
| 17 |
sub-particles. |
| 18 |
|
| 19 |
### Creating particle composition |
| 20 |
|
| 21 |
Create an empty composition with |
| 22 |
|
| 23 |
```python |
| 24 |
composition = ba.Compound() |
| 25 |
``` |
| 26 |
|
| 27 |
Particle placement inside the composition is controlled by the positions |
| 28 |
passed to `addComponent` or `addComponents`: |
| 29 |
|
| 30 |
```python |
| 31 |
composition.addComponent(particle) # at origin |
| 32 |
composition.addComponent(particle, ba.R3(0, 0, 0)) |
| 33 |
composition.addComponents(particle, [pos1, pos2]) |
| 34 |
``` |
| 35 |
|
| 36 |
The existing composition can be composed to the new one: |
| 37 |
|
| 38 |
```python |
| 39 |
composition.addComponent(particle, pos1) |
| 40 |
composition.addComponent(compound, pos2) |
| 41 |
composition.addComponent(coreshell, pos3) |
| 42 |
composition.addComponent(mesocrystal, pos4) |
| 43 |
``` |
| 44 |
|
| 45 |
### Examples |
| 46 |
|
| 47 |
In the following plot we demonstrate the creation of three different |
| 48 |
compositions. |
| 49 |
|
| 50 |
{{< figscg src="/img/draw/tutorial_composition_examples.png" class="center">}} |
| 51 |
|
| 52 |
The hollow cross-shape on the left is constructed by adding four copies of the |
| 53 |
same box-shaped particle at different positions: |
| 54 |
|
| 55 |
```python |
| 56 |
length, width, height = 10*nm, 10*nm, 3*nm |
| 57 |
box = ba.Particle(box_material, ba.Box(length, width, height)) |
| 58 |
|
| 59 |
positions = [ |
| 60 |
ba.R3(length, 0, 0), |
| 61 |
ba.R3(0, -width, 0), |
| 62 |
ba.R3(-length, 0, 0), |
| 63 |
ba.R3(0, width, 0), |
| 64 |
] |
| 65 |
composition = ba.Compound() |
| 66 |
composition.addComponents(box, positions) |
| 67 |
``` |
| 68 |
|
| 69 |
The stack of boxes at the center is constructed by placing three boxes made of |
| 70 |
different materials on top of each other: |
| 71 |
|
| 72 |
```python |
| 73 |
length, width, height = 10*nm, 10*nm, 5*nm |
| 74 |
ff_box = ba.Box(length, width, height) |
| 75 |
|
| 76 |
composition = ba.Compound() |
| 77 |
composition.addComponent(ba.Particle(material1, ff_box), ba.R3(0, 0, 0)) |
| 78 |
composition.addComponent(ba.Particle(material2, ff_box), ba.R3(0, 0, height)) |
| 79 |
composition.addComponent( |
| 80 |
ba.Particle(material3, ff_box), ba.R3(0, 0, 2*height) |
| 81 |
) |
| 82 |
``` |
| 83 |
|
| 84 |
The full sphere on the right is composed of two spherical segments, each made |
| 85 |
of a different material. The bottom half is rotated first by 180 degrees about |
| 86 |
the Y axis before adding it to the composition. |
| 87 |
|
| 88 |
```python |
| 89 |
radius = 16*nm |
| 90 |
top_half = ba.Particle(material1, ba.SphericalSegment(radius, 0, radius)) |
| 91 |
bottom_half = ba.Particle(material2, ba.SphericalSegment(radius, 0, radius)) |
| 92 |
bottom_half.rotate(ba.RotationY(180*deg)) |
| 93 |
|
| 94 |
composition = ba.Compound() |
| 95 |
composition.addComponent(top_half) |
| 96 |
composition.addComponent(bottom_half) |
| 97 |
``` |