| 1 |
""" |
| 2 |
BornAgain functional test. |
| 3 |
Test of rotation/position of core shell particle. |
| 4 |
Reference CoreShell particle is compared against the test CoreShell, |
| 5 |
which has different dimensions but rotated/translated to be like the reference one. |
| 6 |
Particles are placed in the center of middle layer. |
| 7 |
""" |
| 8 |
|
| 9 |
import unittest |
| 10 |
import PyFuTestInfrastructure as infrastruct |
| 11 |
from bornagain import * |
| 12 |
|
| 13 |
mAmbience = Vacuum() |
| 14 |
mSubstrate_color = (0.55, 0.55, 0.55) |
| 15 |
mSubstrate = RefractiveMaterial("Substrate", mSubstrate_color, 3e-6, 3e-8) |
| 16 |
mMiddle_color = (0.70, 0.73, 0.78) |
| 17 |
mMiddle = RefractiveMaterial("Teflon", mMiddle_color, 2.9e-6, 6e-9) |
| 18 |
mCore_color = (0.86, 0.24, 0.18) |
| 19 |
mCore = RefractiveMaterial("Ag", mCore_color, 1.2e-5, 5e-7) |
| 20 |
mShell_color = (0.25, 0.65, 0.35) |
| 21 |
mShell = RefractiveMaterial("AgO2", mShell_color, 8.6e-6, 3.4e-7) |
| 22 |
mOuterShell_color = (0.25, 0.65, 0.35) |
| 23 |
mOuterShell = RefractiveMaterial("SiO2", mOuterShell_color, 6.1e-6, 2.1e-7) |
| 24 |
|
| 25 |
layer_thickness = 100.0 |
| 26 |
|
| 27 |
|
| 28 |
class TransformCoreShellBoxTest(unittest.TestCase): |
| 29 |
|
| 30 |
def get_sample(self, particle): |
| 31 |
vacuum_layer = Layer(mAmbience) |
| 32 |
middle_layer = Layer(mMiddle, layer_thickness) |
| 33 |
middle_layer.deposit2D(Dilute2D(0.001, particle)) |
| 34 |
substrate = Layer(mSubstrate) |
| 35 |
|
| 36 |
sample = Sample() |
| 37 |
sample.addLayer(vacuum_layer) |
| 38 |
sample.addLayer(middle_layer) |
| 39 |
sample.addLayer(substrate) |
| 40 |
return sample |
| 41 |
|
| 42 |
def get_result(self, particle, use_avg_materials=False): |
| 43 |
sample = self.get_sample(particle) |
| 44 |
simulation = infrastruct.get_simulation_MiniGISAS(sample) |
| 45 |
simulation.options().setUseAvgMaterials(use_avg_materials) |
| 46 |
return simulation.simulate() |
| 47 |
|
| 48 |
def test_SameMaterialCoreShellBox(self): |
| 49 |
""" |
| 50 |
Box particle placed in the center of the middle layer is compared against |
| 51 |
CoreShell particle, where core and shell are made of the same material. |
| 52 |
""" |
| 53 |
|
| 54 |
shell_length = 50.0 |
| 55 |
shell_width = 20.0 |
| 56 |
shell_height = 10.0 |
| 57 |
particle = Particle(mCore, Box(shell_length, shell_width, |
| 58 |
shell_height)) |
| 59 |
particle.translate( |
| 60 |
R3(0, 0, -layer_thickness / 2.0 - shell_height / 2)) |
| 61 |
|
| 62 |
reference = self.get_result(particle) |
| 63 |
|
| 64 |
core_length = shell_length / 2.0 |
| 65 |
core_width = shell_width / 2.0 |
| 66 |
core_height = shell_height / 2.0 |
| 67 |
shell = Particle(mCore, Box(shell_length, shell_width, shell_height)) |
| 68 |
core = Particle(mCore, Box(core_length, core_width, core_height)) |
| 69 |
core.translate(R3(0, 0, (shell_height - core_height) / 2)) |
| 70 |
coreshell = CoreAndShell(core, shell) |
| 71 |
coreshell.translate( |
| 72 |
R3(0, 0, -layer_thickness / 2.0 - shell_height / 2)) |
| 73 |
|
| 74 |
data = self.get_result(coreshell) |
| 75 |
|
| 76 |
self.assertTrue(checkRelativeDifference(data, reference, 1e-10)) |
| 77 |
|
| 78 |
def test_CoreShellBoxRotateZ(self): |
| 79 |
""" |
| 80 |
Two CoreShell particles are compared against each other. Reference CoreShell |
| 81 |
particle has dimensions (20,50,10) and is placed in the center of middle layer. |
| 82 |
Second CoreShell particle has dimensions (50,20,10) with one rotationZ to be |
| 83 |
like the reference one. |
| 84 |
""" |
| 85 |
|
| 86 |
|
| 87 |
shell_length = 20.0 |
| 88 |
shell_width = 50.0 |
| 89 |
shell_height = 10.0 |
| 90 |
core_length = shell_length / 2.0 |
| 91 |
core_width = shell_width / 2.0 |
| 92 |
core_height = shell_height / 2.0 |
| 93 |
|
| 94 |
core_ref = Particle(mCore, Box(core_length, core_width, core_height)) |
| 95 |
core_ref.translate(R3(0, 0, (shell_height - core_height) / 2)) |
| 96 |
shell_ref = Particle(mShell, |
| 97 |
Box(shell_length, shell_width, shell_height)) |
| 98 |
coreshell_ref = CoreAndShell(core_ref, shell_ref) |
| 99 |
coreshell_ref.translate( |
| 100 |
R3(0, 0, -layer_thickness / 2.0 - |
| 101 |
shell_height / 2)) |
| 102 |
|
| 103 |
reference = self.get_result(coreshell_ref) |
| 104 |
|
| 105 |
|
| 106 |
shell_length = 50.0 |
| 107 |
shell_width = 20.0 |
| 108 |
shell_height = 10.0 |
| 109 |
core_length = shell_length / 2.0 |
| 110 |
core_width = shell_width / 2.0 |
| 111 |
core_height = shell_height / 2.0 |
| 112 |
|
| 113 |
core = Particle(mCore, Box(core_length, core_width, core_height)) |
| 114 |
core.translate(R3(0, 0, (shell_height - core_height) / 2)) |
| 115 |
shell = Particle(mShell, Box(shell_length, shell_width, shell_height)) |
| 116 |
coreshell = CoreAndShell(core, shell) |
| 117 |
coreshell.rotate(RotationZ(90 * deg)) |
| 118 |
coreshell.translate( |
| 119 |
R3(0, 0, -layer_thickness / 2.0 - shell_height / |
| 120 |
2)) |
| 121 |
|
| 122 |
data = self.get_result(coreshell) |
| 123 |
|
| 124 |
self.assertTrue(checkRelativeDifference(data, reference, 1e-10)) |
| 125 |
|
| 126 |
def test_CoreShellBoxRotateY(self): |
| 127 |
""" |
| 128 |
Two CoreShell particles are compared against each other. Reference CoreShell |
| 129 |
particle has dimensions (10,20,50) and is placed in the center of middle layer. |
| 130 |
Second CoreShell particle has dimensions (50,20,10) with one rotationZ to be |
| 131 |
like the reference one. |
| 132 |
""" |
| 133 |
|
| 134 |
shell_length = 10.0 |
| 135 |
shell_width = 20.0 |
| 136 |
shell_height = 50.0 |
| 137 |
core_length = shell_length / 2.0 |
| 138 |
core_width = shell_width / 2.0 |
| 139 |
core_height = shell_height / 2.0 |
| 140 |
|
| 141 |
core_ref = Particle(mCore, Box(core_length, core_width, core_height)) |
| 142 |
core_ref.translate(R3(0, 0, (shell_height - core_height) / 2)) |
| 143 |
shell_ref = Particle(mShell, |
| 144 |
Box(shell_length, shell_width, shell_height)) |
| 145 |
coreshell_ref = CoreAndShell(core_ref, shell_ref) |
| 146 |
coreshell_ref.translate( |
| 147 |
R3(0, 0, -layer_thickness / 2.0 - |
| 148 |
shell_height / 2)) |
| 149 |
|
| 150 |
reference = self.get_result(coreshell_ref) |
| 151 |
|
| 152 |
|
| 153 |
shell_length = 50.0 |
| 154 |
shell_width = 20.0 |
| 155 |
shell_height = 10.0 |
| 156 |
core_length = shell_length / 2.0 |
| 157 |
core_width = shell_width / 2.0 |
| 158 |
core_height = shell_height / 2.0 |
| 159 |
|
| 160 |
core = Particle(mCore, Box(core_length, core_width, core_height)) |
| 161 |
core.translate(R3(0, 0, (shell_height - core_height) / 2)) |
| 162 |
shell = Particle(mShell, Box(shell_length, shell_width, shell_height)) |
| 163 |
coreshell = CoreAndShell(core, shell) |
| 164 |
coreshell.rotate(RotationY(90. * deg)) |
| 165 |
coreshell.translate( |
| 166 |
R3(0, 0, -layer_thickness / |
| 167 |
2)) |
| 168 |
|
| 169 |
data = self.get_result(coreshell) |
| 170 |
|
| 171 |
self.assertTrue(checkRelativeDifference(data, reference, 1e-10)) |
| 172 |
|
| 173 |
def test_CoreShellBoxRotateZandY(self): |
| 174 |
""" |
| 175 |
Two CoreShell particles are compared against each other. Reference CoreShell |
| 176 |
particle has dimensions (10,50,20) and is placed in the center of middle layer. |
| 177 |
Second CoreShell particle has dimensions (50,20,10) with two rotations to be |
| 178 |
like the reference one. |
| 179 |
""" |
| 180 |
|
| 181 |
|
| 182 |
shell_length = 10.0 |
| 183 |
shell_width = 50.0 |
| 184 |
shell_height = 20.0 |
| 185 |
core_length = shell_length / 2.0 |
| 186 |
core_width = shell_width / 2.0 |
| 187 |
core_height = shell_height / 2.0 |
| 188 |
|
| 189 |
core_ref = Particle(mCore, Box(core_length, core_width, core_height)) |
| 190 |
core_ref.translate(R3(0, 0, (shell_height - core_height) / 2)) |
| 191 |
shell_ref = Particle(mShell, |
| 192 |
Box(shell_length, shell_width, shell_height)) |
| 193 |
coreshell_ref = CoreAndShell(core_ref, shell_ref) |
| 194 |
coreshell_ref.translate( |
| 195 |
R3(0, 0, -layer_thickness / 2.0 - |
| 196 |
shell_height / 2)) |
| 197 |
|
| 198 |
reference = self.get_result(coreshell_ref) |
| 199 |
|
| 200 |
|
| 201 |
shell_length = 50.0 |
| 202 |
shell_width = 20.0 |
| 203 |
shell_height = 10.0 |
| 204 |
core_length = shell_length / 2.0 |
| 205 |
core_width = shell_width / 2.0 |
| 206 |
core_height = shell_height / 2.0 |
| 207 |
|
| 208 |
core = Particle(mCore, Box(core_length, core_width, core_height)) |
| 209 |
core.translate(R3(0, 0, (shell_height - core_height) / 2)) |
| 210 |
shell = Particle(mShell, Box(shell_length, shell_width, shell_height)) |
| 211 |
coreshell = CoreAndShell(core, shell) |
| 212 |
coreshell.rotate(RotationZ(90 * deg)) |
| 213 |
coreshell.rotate(RotationY(90 * deg)) |
| 214 |
|
| 215 |
coreshell.translate( |
| 216 |
R3(0, 0, -layer_thickness / |
| 217 |
2)) |
| 218 |
|
| 219 |
data = self.get_result(coreshell) |
| 220 |
|
| 221 |
self.assertTrue(checkRelativeDifference(data, reference, 1e-10)) |
| 222 |
|
| 223 |
def test_SameMaterialOnionBox(self): |
| 224 |
""" |
| 225 |
Nested onion particle with identical SLD in all layers must be equivalent |
| 226 |
to a single particle with the outermost geometry. |
| 227 |
""" |
| 228 |
outer_length = 40.0 |
| 229 |
outer_width = 16.0 |
| 230 |
outer_height = 8.0 |
| 231 |
inner_shell_length = 30.0 |
| 232 |
inner_shell_width = 12.0 |
| 233 |
inner_shell_height = 6.0 |
| 234 |
inner_core_length = 20.0 |
| 235 |
inner_core_width = 8.0 |
| 236 |
inner_core_height = 4.0 |
| 237 |
|
| 238 |
reference = Particle(mCore, Box(outer_length, outer_width, outer_height)) |
| 239 |
reference.translate(R3(0, 0, -layer_thickness / 2.0 - outer_height / 2.0)) |
| 240 |
|
| 241 |
inner_core = Particle(mCore, Box(inner_core_length, inner_core_width, inner_core_height)) |
| 242 |
inner_core.translate(R3(0, 0, (inner_shell_height - inner_core_height) / 2.0)) |
| 243 |
inner_shell = Particle(mCore, Box(inner_shell_length, inner_shell_width, inner_shell_height)) |
| 244 |
inner_onion = CoreAndShell(inner_core, inner_shell) |
| 245 |
inner_onion.translate(R3(0, 0, (outer_height - inner_shell_height) / 2.0)) |
| 246 |
outer_shell = Particle(mCore, Box(outer_length, outer_width, outer_height)) |
| 247 |
onion = CoreAndShell(inner_onion, outer_shell) |
| 248 |
onion.translate(R3(0, 0, -layer_thickness / 2.0 - outer_height / 2.0)) |
| 249 |
|
| 250 |
reference_no_avg = self.get_result(reference, False) |
| 251 |
onion_no_avg = self.get_result(onion, False) |
| 252 |
self.assertTrue(checkRelativeDifference(onion_no_avg, reference_no_avg, 1e-10)) |
| 253 |
|
| 254 |
reference_avg = self.get_result(reference, True) |
| 255 |
onion_avg = self.get_result(onion, True) |
| 256 |
self.assertTrue(checkRelativeDifference(onion_avg, reference_avg, 1e-10)) |
| 257 |
|
| 258 |
def test_SameShellMaterialOnionBox(self): |
| 259 |
""" |
| 260 |
Onion with identical inner and outer shell SLD must be equivalent to a |
| 261 |
simple core-shell particle with the same core and the outermost shell. |
| 262 |
""" |
| 263 |
outer_length = 40.0 |
| 264 |
outer_width = 16.0 |
| 265 |
outer_height = 8.0 |
| 266 |
inner_shell_length = 30.0 |
| 267 |
inner_shell_width = 12.0 |
| 268 |
inner_shell_height = 6.0 |
| 269 |
inner_core_length = 20.0 |
| 270 |
inner_core_width = 8.0 |
| 271 |
inner_core_height = 4.0 |
| 272 |
|
| 273 |
reference_core = Particle(mCore, Box(inner_core_length, inner_core_width, inner_core_height)) |
| 274 |
reference_core.translate(R3(0, 0, 2.0)) |
| 275 |
reference_shell = Particle(mShell, Box(outer_length, outer_width, outer_height)) |
| 276 |
reference = CoreAndShell(reference_core, reference_shell) |
| 277 |
reference.translate(R3(0, 0, -layer_thickness / 2.0 - outer_height / 2.0)) |
| 278 |
|
| 279 |
inner_core = Particle(mCore, Box(inner_core_length, inner_core_width, inner_core_height)) |
| 280 |
inner_core.translate(R3(0, 0, 1.0)) |
| 281 |
inner_shell = Particle(mShell, Box(inner_shell_length, inner_shell_width, inner_shell_height)) |
| 282 |
inner_onion = CoreAndShell(inner_core, inner_shell) |
| 283 |
inner_onion.translate(R3(0, 0, 1.0)) |
| 284 |
outer_shell = Particle(mShell, Box(outer_length, outer_width, outer_height)) |
| 285 |
onion = CoreAndShell(inner_onion, outer_shell) |
| 286 |
onion.translate(R3(0, 0, -layer_thickness / 2.0 - outer_height / 2.0)) |
| 287 |
|
| 288 |
reference_data = self.get_result(reference) |
| 289 |
onion_data = self.get_result(onion) |
| 290 |
self.assertTrue(checkRelativeDifference(onion_data, reference_data, 1e-10)) |
| 291 |
|
| 292 |
def test_SameCoreAndInnerShellMaterialOnionBoxRotateZ(self): |
| 293 |
""" |
| 294 |
Onion with identical core and inner-shell SLD must be equivalent to a |
| 295 |
simple core-shell particle whose core has the inner-shell geometry. |
| 296 |
""" |
| 297 |
outer_length = 40.0 |
| 298 |
outer_width = 16.0 |
| 299 |
outer_height = 8.0 |
| 300 |
inner_shell_length = 30.0 |
| 301 |
inner_shell_width = 12.0 |
| 302 |
inner_shell_height = 6.0 |
| 303 |
inner_core_length = 20.0 |
| 304 |
inner_core_width = 8.0 |
| 305 |
inner_core_height = 4.0 |
| 306 |
|
| 307 |
reference_core = Particle(mCore, Box(inner_shell_length, inner_shell_width, |
| 308 |
inner_shell_height)) |
| 309 |
reference_core.translate(R3(0, 0, 1.0)) |
| 310 |
reference_shell = Particle(mOuterShell, Box(outer_length, outer_width, outer_height)) |
| 311 |
reference = CoreAndShell(reference_core, reference_shell) |
| 312 |
reference.rotate(RotationZ(90 * deg)) |
| 313 |
reference.translate(R3(0, 0, -layer_thickness / 2.0 - outer_height / 2.0)) |
| 314 |
|
| 315 |
inner_core = Particle(mCore, Box(inner_core_length, inner_core_width, inner_core_height)) |
| 316 |
inner_core.translate(R3(0, 0, 1.0)) |
| 317 |
inner_shell = Particle(mCore, Box(inner_shell_length, inner_shell_width, inner_shell_height)) |
| 318 |
inner_onion = CoreAndShell(inner_core, inner_shell) |
| 319 |
inner_onion.translate(R3(0, 0, 1.0)) |
| 320 |
outer_shell = Particle(mOuterShell, Box(outer_length, outer_width, outer_height)) |
| 321 |
onion = CoreAndShell(inner_onion, outer_shell) |
| 322 |
onion.rotate(RotationZ(90 * deg)) |
| 323 |
onion.translate(R3(0, 0, -layer_thickness / 2.0 - outer_height / 2.0)) |
| 324 |
|
| 325 |
reference_data = self.get_result(reference) |
| 326 |
onion_data = self.get_result(onion) |
| 327 |
self.assertTrue(checkRelativeDifference(onion_data, reference_data, 1e-10)) |
| 328 |
|
| 329 |
|
| 330 |
if __name__ == '__main__': |
| 331 |
unittest.main() |