def get_sample_rot_distr(): # create materials substrate_material = ba.HomogeneousMaterial("Substrate", 6.05878e-6, 6.94321e-11) particle_material = ba.HomogeneousMaterial("ParticleCore", -0.609e-6, 0.183e-6) layer_material = ba.HomogeneousMaterial("D2O", 1.85762e-5, 3.31309e-11) # create mesocrystal # lattice lat = create_hex_lattice(distance, length) # basis particle ff = ba.FormFactorCylinder(radius, length) particle = ba.Particle(particle_material, ff) # rotate cylinder to make it parallel to the substrate rotation = ba.RotationY(90.0 * ba.degree) particle.setRotation(rotation) basis = ba.ParticleComposition(particle) # mesocrystal total_height = nbr_layers * distance * np.sin(hex_angle) # using a Gaussian form factor as the overall shape of where the cylinders are meso_ff = ba.FormFactorGauss(meso_width, total_height) # assemble them into mesocrystal npc = ba.Crystal(basis, lat) dw_factor = 0.2 npc.setDWFactor(dw_factor) meso = ba.MesoCrystal(npc, meso_ff) # rotate mesocrystal rot_y = ba.RotationY(180.0 * ba.degree) meso.setRotation(rot_y) # turn upside down rot_z = ba.RotationZ(0.1 * ba.degree) meso.applyRotation(rot_z) # rotate around Z meso.setPosition(0.0, 0.0, 0.0) # add uniform distribution of the domain orientations rot_distr = ba.DistributionGate((90.0 - rz_range) * ba.degree, (90.0 + rz_range) * ba.degree) ang_distr = ba.ParameterDistribution("*MesoCrystal/EulerRotation/Gamma", rot_distr, rz_num) part_coll = ba.ParticleDistribution(meso, ang_distr) # Create multilayer multi_layer = ba.MultiLayer() d2o_layer = ba.Layer(layer_material) substrate_layer = ba.Layer(substrate_material) particle_layout = ba.ParticleLayout() particle_layout.addParticle(part_coll) d2o_layer.addLayout(particle_layout) # the sample is upside down multi_layer.addLayer(substrate_layer) multi_layer.addLayer(d2o_layer) return multi_layer
def testBoxTransform(self): """ Reference box of (10,50,20) size is compared against the box (50,20,10) with two rotations applied to get reference one """ mParticle = ba.HomogeneousMaterial("Ag", 1.245e-5, 5.419e-7) # reference box length = 10 width = 50 height = 20 box = ba.Particle(mParticle, ba.FormFactorBox(length, width, height)) box.setPosition(kvector_t(0, 0, -layer_thickness / 2 - height / 2)) reference_data = self.get_result(box) #IntensityDataIOFactory.writeIntensityData(reference_data, "ref_TransformBox.int") # second box length = 50 width = 20 height = 10 box = ba.Particle(mParticle, ba.FormFactorBox(length, width, height)) box.setRotation(ba.RotationZ(90 * deg)) box.rotate(ba.RotationY(90 * deg)) box.setPosition(kvector_t(0, 0, -layer_thickness / 2)) data = self.get_result(box) diff = ba.RelativeDifference(data, reference_data) print(diff) self.assertLess(diff, 1e-10)
def get_sample(): # Defining Materials material_1 = ba.HomogeneousMaterial("Air", 0.0, 0.0) material_2 = ba.HomogeneousMaterial("Au", 3.53665637e-05, 2.9383311e-06) material_3 = ba.HomogeneousMaterial("Si", 5.73327e-06, 1.006366e-07) # Defining Layers layer_1 = ba.Layer(material_1) layer_2 = ba.Layer(material_3) # Defining Form Factors formFactor_1 = ba.FormFactorTruncatedSphere(159.0 * nm, 244.0 * nm, 0.0 * nm) # Defining Particles particle_1 = ba.Particle(material_2, formFactor_1) particle_1_rotation = ba.RotationY(60.0 * deg) particle_1.setRotation(particle_1_rotation) particle_1_position = kvector_t(0.0 * nm, 0.0 * nm, 439.0 * nm) particle_1.setPosition(particle_1_position) # Defining composition of particles at specific positions z1 = j z2 = j + 120 z3 = j + 240 particleComposition_1 = ba.ParticleComposition() particleComposition_1.addParticle(particle_1) particleComposition_1_rotation = ba.RotationZ(z1 * deg) particleComposition_1.setRotation(particleComposition_1_rotation) particleComposition_2 = ba.ParticleComposition() particleComposition_2.addParticle(particle_1) particleComposition_2_rotation = ba.RotationZ(z2 * deg) particleComposition_2.setRotation(particleComposition_2_rotation) particleComposition_3 = ba.ParticleComposition() particleComposition_3.addParticle(particle_1) particleComposition_3_rotation = ba.RotationZ(z3 * deg) particleComposition_3.setRotation(particleComposition_3_rotation) # Defining Particle Layouts and adding Particles layout_1 = ba.ParticleLayout() layout_1.addParticle(particleComposition_1, 1.0) layout_1.addParticle(particleComposition_2, 1.0) layout_1.addParticle(particleComposition_3, 1.0) layout_1.setTotalParticleSurfaceDensity(0.001) # Adding layouts to layers layer_1.addLayout(layout_1) # Defining Multilayers multiLayer_1 = ba.MultiLayer() multiLayer_1.addLayer(layer_1) multiLayer_1.addLayer(layer_2) return multiLayer_1
def get_sample(): # Defining Materials material_1 = ba.HomogeneousMaterial("example01_Air", 0.0, 0.0) material_2 = ba.HomogeneousMaterial("Si", 5.73327e-06, 1.006366e-07) # Defining Layers layer_1 = ba.Layer(material_1) layer_2 = ba.Layer(material_2) particleComposition_1 = ba.ParticleComposition() for i in range(nslices): r = 159 * nm - i * 2 z = i * 15 * nm y = z + 15 * nm # Defining Form Factors formFactor_1 = ba.FormFactorCone6(r, 5.0 * nm, 68.0 * deg) formFactor_2 = ba.FormFactorCone6(r, 10.0 * nm, 78.0 * deg) # Defining Particles particle_1 = ba.Particle(material_2, formFactor_1) particle_1_rotation = ba.RotationY(180.0 * deg) particle_1.setRotation(particle_1_rotation) particle_1_position = kvector_t(0.0 * nm, 0.0 * nm, y * nm) particle_1.setPosition(particle_1_position) particle_2 = ba.Particle(material_2, formFactor_2) particle_2_position = kvector_t(0.0 * nm, 0.0 * nm, z * nm) particle_2.setPosition(particle_2_position) # Defining composition of particles at specific positions particleComposition_1.addParticle(particle_1) particleComposition_1.addParticle(particle_2) particleComposition_1_rotation = ba.RotationZ(j * deg) particleComposition_1.setRotation(particleComposition_1_rotation) # Defining Particle Layouts and adding Particles layout_1 = ba.ParticleLayout() layout_1.addParticle(particleComposition_1, 1.0) layout_1.setTotalParticleSurfaceDensity(0.001) # Adding layouts to layers layer_1.addLayout(layout_1) # Defining Multilayers multiLayer_1 = ba.MultiLayer() multiLayer_1.addLayer(layer_1) multiLayer_1.addLayer(layer_2) return multiLayer_1
def get_sample(): """ Returns a sample """ # defining materials m_si = ba.MaterialBySLD("Si", sld_Si, sld_Si_im) m_d2o = ba.MaterialBySLD("D2O", sld_D2O, sld_D2O_im) m_core = ba.MaterialBySLD("Me3O5:D2O2", 2.0 * 1.0e-06, 0.0) m_shell = ba.MaterialBySLD("Me3O5:D2O", 3.9 * 1.0e-06, 0.0) # layer with particles # calculate average SLD Vcore = vol(core_radius, core_height) Vshell = vol(radius, height) - Vcore f_d2o = 0.7 f_core = (1.0 - f_d2o) / (1 + Vshell / Vcore) f_shell = (1.0 - f_d2o) / (1 + Vcore / Vshell) sld_mix = f_d2o * sld_D2O + f_shell * 3.9 * 1.0e-06 + f_core * 2.0 * 1.0e-06 m_mix = ba.MaterialBySLD("mix", sld_mix, 0.0) # fluctuation component ff_microgel = FormFactorMicrogel(b, xi, xiz) microgel = ba.Particle(m_core, ff_microgel) microgel_layout = ba.ParticleLayout() microgel_layout.addParticle(microgel, 1.0) # collection of particles ff = ba.FormFactorTruncatedSphere(radius=radius, height=height) ff_core = ba.FormFactorTruncatedSphere(radius=core_radius, height=core_height) transform = ba.RotationY(180.0 * deg) shell_particle = ba.Particle(m_shell, ff) core_particle = ba.Particle(m_core, ff_core) core_position = ba.kvector_t(0.0, 0.0, 0.0) particle = ba.ParticleCoreShell(shell_particle, core_particle, core_position) particle.setPosition(ba.kvector_t(0.0, 0.0, 0.0)) particle.setRotation(transform) nparticles = 2 # the larger is this number, the more slow will be the simulation. 10 is usually enough sigma = 0.2 * radius gauss_distr = ba.DistributionGaussian(radius, sigma) sigma_factor = 2.0 par_distr = ba.ParameterDistribution( "/ParticleCoreShell/Particle1/TruncatedSphere/Radius", gauss_distr, nparticles, sigma_factor, ba.RealLimits.lowerLimited(core_radius + 1.0)) par_distr.linkParameter( "/ParticleCoreShell/Particle1/TruncatedSphere/Height") par_distr.linkParameter( "/ParticleCoreShell/Particle0/TruncatedSphere/Height") par_distr.linkParameter( "/ParticleCoreShell/Particle0/TruncatedSphere/Radius") part_coll = ba.ParticleDistribution(particle, par_distr) microgel_layout.addParticle(part_coll, 1.2e-05) # interference can be neglected interference = ba.InterferenceFunctionNone() microgel_layout.setInterferenceFunction(interference) # describe layer roughness roughness = ba.LayerRoughness() roughness.setSigma(1.2 * ba.nm) roughness.setHurstParameter(0.8) roughness.setLatteralCorrLength(570.0 * ba.nm) # create layers d2o_layer = ba.Layer(m_d2o) mix_layer = ba.Layer(m_mix, 2.0 * height) mix_layer.addLayout(microgel_layout) si_layer = ba.Layer(m_si) multi_layer = ba.MultiLayer() multi_layer.addLayer(si_layer) multi_layer.addLayer(mix_layer) multi_layer.addLayerWithTopRoughness(d2o_layer, roughness) return multi_layer
""" Plot form factors. """ import bornagain as ba from bornagain import nanometer, degree import bornplot as bp import math det = bp.Detector(200, -5, 5, -5, 5) n = 3 results = [] edge = 3.2 title = 'face normal' trafo = ba.RotationY(26.5651 * degree) ff = ba.FormFactorDodecahedron(edge * nanometer) data = bp.run_simulation(det, ff, trafo) results.append(bp.Result(0, data, title)) title = 'vertex normal' trafo = ba.RotationY(-52.6226 * degree) ff = ba.FormFactorDodecahedron(edge * nanometer) data = bp.run_simulation(det, ff, trafo) results.append(bp.Result(1, data, title)) title = 'edge normal' trafo = ba.RotationY(58.2825 * degree) ff = ba.FormFactorDodecahedron(edge * nanometer) data = bp.run_simulation(det, ff, trafo) results.append(bp.Result(2, data, title))
""" Plot form factor. """ import bornagain as ba from bornagain import nanometer, degree import bornplot as bp det = bp.Detector(200, 0, 5, 0, 5) n = 4 results = [] for i in range(n): theta = 30 * i / (n - 1) title = r'$\vartheta=%d^\circ$' % theta ff = ba.FormFactorTruncatedSphere(4.2 * nanometer, 6.1 * nanometer) trafo = ba.RotationY(theta * degree) data = bp.run_simulation(det, ff, trafo) results.append(bp.Result(i, data, title)) bp.make_plot(results, det, "ff_TruncatedSphere")
""" Plot form factors. """ import bornagain as ba from bornagain import nanometer, degree import bornplot as bp import math det = bp.Detector( 200, -5, 5, -5, 5 ) n = 3 results = [] edge = 4.8 title = 'face normal' trafo = ba.RotationY(48.1897*degree) ff = ba.FormFactorIcosahedron(edge*nanometer) data = bp.run_simulation(det,ff,trafo) results.append( bp.Result(0, data, title) ) title = 'vertex normal' trafo = ba.RotationY(-52.6226*degree) ff = ba.FormFactorIcosahedron(edge*nanometer) data = bp.run_simulation(det,ff,trafo) results.append( bp.Result(1, data, title) ) title = 'edge normal' trafo = ba.RotationY(69.0948*degree) ff = ba.FormFactorIcosahedron(edge*nanometer) data = bp.run_simulation(det,ff,trafo) results.append( bp.Result(2, data, title) )
""" Plot form factors. """ import bornagain as ba from bornagain import nanometer, degree import bornplot2 as bp import math import inspect det = bp.DetPars(400, -.25, .25, -.25, .25) n = 3 results = [] edge = 30 title = 'E=30' trafo = ba.RotationY(26.5651 * degree) ff = ba.FormFactorTruncatedCube(edge * nanometer, 2 * nanometer) sim = bp.get_simulation(det, ff, trafo) data = bp.run_sim(sim, det) results.append(bp.Result(0, data, title)) pool = ff.getParameterPool() print(pool.getParameterNames()) print(ff.getLength()) print(ff.volume()) pool.setParameterValue('Length', 10) print(ff.getLength()) print(ff.volume()) title = 'E=10'
def get_sample(): # Defining Materials material_1 = ba.HomogeneousMaterial("example01_Air", 0.0, 0.0) material_2 = ba.HomogeneousMaterial("Si", 5.73327e-06, 1.006366e-07) # Defining Layers layer_1 = ba.Layer(material_1) layer_2 = ba.Layer(material_2) # Defining Form Factors formFactor_1 = ba.FormFactorCone6(159.0 * nm, 10.0 * nm, 78.0 * deg) formFactor_2 = ba.FormFactorCone6(159.0 * nm, 5.0 * nm, 66.0 * deg) formFactor_3 = ba.FormFactorPrism6(159.0 * nm, 300.0 * nm) particleComposition_11 = ba.ParticleComposition() for i in range(nslices): z = i * 15.0 * nm y = z + 15.0 * nm # Defining Particles particle_1 = ba.Particle(material_2, formFactor_1) particle_1_position = kvector_t(0.0 * nm, 0.0 * nm, z * nm) particle_1.setPosition(particle_1_position) particle_2 = ba.Particle(material_2, formFactor_2) particle_2_rotation = ba.RotationY(180.0 * deg) particle_2.setRotation(particle_2_rotation) particle_2_position = kvector_t(0.0 * nm, 0.0 * nm, y * nm) particle_2.setPosition(particle_2_position) particleComposition_11.addParticle(particle_1) particleComposition_11.addParticle(particle_2) particleComposition_11_rotation = ba.RotationZ(j * deg) particleComposition_11.setRotation(particleComposition_11_rotation) particle_3 = ba.Particle(material_2, formFactor_3) particle_3_rotation = ba.RotationY(30.0 * deg) particle_3.setRotation(particle_3_rotation) particle_3_position = kvector_t(0.0 * nm, 0.0 * nm, 79.5 * nm) particle_3.setPosition(particle_3_position) z1 = j z2 = j + 120 z3 = j + 240 particleComposition_1 = ba.ParticleComposition() particleComposition_1.addParticle(particle_3) particleComposition_1_rotation = ba.RotationZ(z1 * deg) particleComposition_1.setRotation(particleComposition_1_rotation) particleComposition_2 = ba.ParticleComposition() particleComposition_2.addParticle(particle_3) particleComposition_2_rotation = ba.RotationZ(z2 * deg) particleComposition_2.setRotation(particleComposition_2_rotation) particleComposition_3 = ba.ParticleComposition() particleComposition_3.addParticle(particle_3) particleComposition_3_rotation = ba.RotationZ(z3 * deg) particleComposition_3.setRotation(particleComposition_3_rotation) # Defining Particle Layouts and adding Particles layout_1 = ba.ParticleLayout() layout_1.addParticle(particleComposition_11, 0.7) layout_1.addParticle(particleComposition_1, 0.1) layout_1.addParticle(particleComposition_2, 0.1) layout_1.addParticle(particleComposition_3, 0.1) layout_1.setTotalParticleSurfaceDensity(0.001) # Adding layouts to layers layer_1.addLayout(layout_1) # Defining Multilayers multiLayer_1 = ba.MultiLayer() multiLayer_1.addLayer(layer_1) multiLayer_1.addLayer(layer_2) return multiLayer_1