def testSphericalLacuneInSubstrate(self): """ Similar to previous. Truncated sphere and sphere are made of air material. From scattering point of view, both cases should look like an air lacune in substrate. """ sphere_radius = 10.0 sphere_shift = 4.0 # shift beneath interface in absolute units # Sphere truncated from top. Intended to go below interface. truncatedSphere = ba.Particle( mAmbience, ba.FormFactorTruncatedSphere(sphere_radius, sphere_radius * 2, sphere_radius * 2 - sphere_shift)) truncatedSphere.setPosition(0, 0, -sphere_shift) reference = self.get_result(truncatedSphere) # sphere crossing interface to look like truncated sphere above sphere = ba.Particle(mAmbience, ba.FormFactorFullSphere(sphere_radius)) sphere.setPosition(0, 0, -sphere_shift) data = self.get_result(sphere) diff = ba.RelativeDifference(data, reference) print(diff) self.assertLess(diff, 1e-10)
def testSpheresCrossingInterface(self): """ Compares two simulation intended to provide identical results. Simulation #1: full sphere inserted in air layer to cross interface Simulation #2: full sphere inserted in substrate layer to cross interface Both spheres are made of same material. """ mParticle = ba.HomogeneousMaterial("Ag", 1.245e-5, 5.419e-7) sphere_radius = 10.0 sphere_shift = 4.0 # shift beneath interface in absolute units # Sphere intended for air layer and crossing interface sphere1 = ba.Particle(mParticle, ba.FormFactorFullSphere(sphere_radius)) sphere1.setPosition(0, 0, -sphere_shift) reference = self.get_result(particle_to_air=sphere1) # Sphere intended for substrate layer and crossing interface sphere2 = ba.Particle(mParticle, ba.FormFactorFullSphere(sphere_radius)) sphere2.setPosition(0, 0, -sphere_shift) data = self.get_result(particle_to_substrate=sphere2) diff = ba.RelativeDifference(data, reference) print(diff) self.assertLess(diff, 1e-10)
def testSphericalCupOnTopOfSubstrate(self): """ Compares two simulation intended to provide identical results. Simulation #1: truncated sphere on top of substrate. Simulation #2: spherical particle crossing the interface. Both particles are made of same material as substrate. From scattering point of view, both cases should look like a truncated sphere on top of substrate. """ sphere_radius = 10.0 sphere_shift = 4.0 # shift beneath interface in absolute units # truncated sphere on top of substrate with height 16nm truncatedSphere = ba.Particle( mSubstrate, ba.FormFactorTruncatedSphere(sphere_radius, sphere_radius * 2 - sphere_shift)) reference = self.get_result(truncatedSphere) # sphere crossing interface to look like truncated sphere above sphere = ba.Particle(mSubstrate, ba.FormFactorFullSphere(sphere_radius)) sphere.setPosition(0, 0, -sphere_shift) data = self.get_result(sphere) diff = ba.RelativeDifference(data, reference) print(diff) self.assertLess(diff, 1e-10)
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 testSphericalCupOnTopOfSubstrate(self): """ Compares two simulation intended to provide identical results. Simulation #1: truncated sphere on top of substrate. Simulation #2: spherical particle composition crossing the interface. Bottom part of composition is made from substrate material. both cases should look like a truncated sphere on top of substrate. """ # truncated sphere on top of substrate with height 16nm truncatedSphere = ba.Particle( mParticle, ba.FormFactorTruncatedSphere(sphere_radius, sphere_radius * 2 - bottom_cup_height)) reference = self.get_intensity_data(truncatedSphere) # Particle composition, top part made of same material, as particle. Bottom part made of same material as substrate. composition = self.get_composition(mParticle, mSubstrate) composition_shift = bottom_cup_height composition.setPosition(0, 0, -composition_shift) data = self.get_intensity_data(composition) diff = ba.getRelativeDifference(data, reference) print(diff) self.assertLess(diff, 1e-10)
def runSimulation(): # defining materials mAmbience = ba.HomogeneousMaterial("Air", 0.0, 0.0) mSubstrate = ba.HomogeneousMaterial("Substrate", 6e-6, 2e-8) magnetic_field = ba.kvector_t(0, 0, 0) magParticle = ba.HomogeneousMaterial("magParticle", 6e-4, 2e-8, magnetic_field) # collection of particles cylinder_ff = ba.FormFactorCylinder(5 * nanometer, 5 * nanometer) cylinder = ba.Particle(magParticle, cylinder_ff) particle_layout = ba.ParticleLayout() particle_layout.addParticle(cylinder, 1.0) interference = ba.InterferenceFunctionNone() particle_layout.setInterferenceFunction(interference) # air layer with particles and substrate form multi layer air_layer = ba.Layer(mAmbience) air_layer.addLayout(particle_layout) substrate_layer = ba.Layer(mSubstrate, 0) multi_layer = ba.MultiLayer() multi_layer.addLayer(air_layer) multi_layer.addLayer(substrate_layer) # build and run experiment simulation = ba.GISASSimulation() simulation.setDetectorParameters(100, 0 * degree, 2.0 * degree, 100, 0.0 * degree, 2.0 * degree) simulation.setBeamParameters(1.0 * angstrom, 0.2 * degree, 0.0 * degree) simulation.setSample(multi_layer) simulation.runSimulation() ## intensity data return simulation.getIntensityData()
def get_composition_v2(self, top_material, bottom_material): """ Returns particle composition representing sphere made of two different materials. Alternative to previous method. Rotation is used to get bottom part """ topCup = ba.Particle( top_material, ba.FormFactorTruncatedSphere(sphere_radius, sphere_radius * 2 - bottom_cup_height)) bottomCup = ba.Particle( bottom_material, ba.FormFactorTruncatedSphere(sphere_radius, bottom_cup_height)) bottomCup.setRotation(ba.RotationX(180 * deg)) # origin of resulting sphere will be at the bottom result = ba.ParticleComposition() result.addParticle(topCup, kvector_t(0.0, 0.0, bottom_cup_height)) result.addParticle(bottomCup, kvector_t(0.0, 0.0, bottom_cup_height)) return result
def get_composition(self, top_material, bottom_material): """ Returns particle composition representing sphere made of two different materials. Origin of new object is at the bottom of resulting sphere. """ topCup = ba.Particle( top_material, ba.FormFactorTruncatedSphere(sphere_radius, sphere_radius * 2 - bottom_cup_height)) bottomCup = ba.Particle( bottom_material, ba.FormFactorTruncatedSphere(sphere_radius, sphere_radius * 2, sphere_radius * 2 - bottom_cup_height)) # origin of resulting sphere will be at the bottom result = ba.ParticleComposition() result.addParticle(topCup, kvector_t(0.0, 0.0, bottom_cup_height)) result.addParticle(bottomCup, kvector_t(0.0, 0.0, 0.0)) return result
def testComposition(self): """ Compares two simulation intended to provide identical results. Simulation #1: spherical particle on top of substrate Simulation #2: spherical composition on top of substrate, where top and bottom are made of same material """ # spherical particle sphere = ba.Particle(mParticle, ba.FormFactorFullSphere(sphere_radius)) reference = self.get_intensity_data(sphere) # spherical composition composition = self.get_composition(mParticle, mParticle) data = self.get_intensity_data(composition) diff = ba.getRelativeDifference(data, reference) print(diff) self.assertLess(diff, 1e-10)
def testSlicedComposition(self): """ Compares two simulation intended to provide identical results. Simulation #1: spherical particle on top of substrate Simulation #2: spherical composition on top of substrate, where top and bottom are made of same material Both particles are inserted in air layer with shift to go below interface """ shift = 3 * nm # spherical particle sphere = ba.Particle(mParticle, ba.FormFactorFullSphere(sphere_radius)) sphere.setPosition(0, 0, -shift) reference = self.get_intensity_data(sphere) # spherical composition composition = self.get_composition(mParticle, mParticle) composition.setPosition(0, 0, -shift) data = self.get_intensity_data(composition) diff = ba.getRelativeDifference(data, reference) print(diff) self.assertLess(diff, 1e-10)