## BATest2.py

 1 ```import numpy ``` ```import bornagain as ba ``` ```from bornagain import deg, angstrom, nm, kvector_t ``` ```def get_sample(): ``` ``` # Defining Materials ``` ``` material_1 = ba.HomogeneousMaterial("example01_Air", 0.0, 0.0) ``` ``` material_2 = ba.HomogeneousMaterial("example01_Particle", 0.0006, 2e-08) ``` ``` material_3 = ba.HomogeneousMaterial("example01_Substrate", 6e-06, 2e-08) ``` ``` # Defining Layers ``` ``` layer_1 = ba.Layer(material_1) ``` ``` layer_2 = ba.Layer(material_3) ``` ``` # Defining Form Factors ``` ``` formFactor_1 = ba.FormFactorCylinder(5.0*nm, 5.0*nm) ``` ``` formFactor_2 = ba.FormFactorPrism3(10.0*nm, 5.0*nm) ``` ``` # Defining Particles ``` ``` particle_1 = ba.Particle(material_2, formFactor_1) ``` ``` particle_2 = ba.Particle(material_2, formFactor_2) ``` ``` # Defining Particle Layouts and adding Particles ``` ``` layout_1 = ba.ParticleLayout() ``` ``` layout_1.addParticle(particle_1, 0.5) ``` ``` layout_1.addParticle(particle_2, 0.5) ``` ``` layout_1.setTotalParticleSurfaceDensity(1) ``` ``` # 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_simulation(): ``` ``` simulation = ba.GISASSimulation() ``` ``` simulation.setDetectorParameters(100, -1.0*deg, 1.0*deg, 100, 0.0*deg, 2.0*deg) ``` ``` ``` ``` simulation.setBeamParameters(0.1*nm, 0.2*deg, 0.0*deg) ``` ``` simulation.setBeamIntensity(1.0e+08) ``` ``` return simulation ``` ```def run_simulation(): ``` ``` sample = get_sample() ``` ``` simulation = get_simulation() ``` ``` simulation.setSample(sample) ``` ``` simulation.runSimulation() ``` ``` return simulation.result() ``` ```if __name__ == '__main__': ``` ``` result = run_simulation() ``` ``` ba.plot_simulation_result(result) ```