test.py

ganeva, 10 Nov 2017 12:43

Download (1.87 KB)

 
1
"""
2
Spheres on a hexagonal lattice
3
"""
4
import bornagain as ba
5
from bornagain import deg, angstrom, nm
6

    
7

    
8
def get_sample():
9
    """
10
    Returns a sample with spherical particles on a substrate,
11
    forming a hexagonal 2D lattice.
12
    """
13
    m_air = ba.HomogeneousMaterial("Air", 0.0, 0.0)
14
    m_substrate = ba.HomogeneousMaterial("Substrate", 6e-6, 2e-8)
15
    m_particle = ba.HomogeneousMaterial("Particle", 6e-4, 2e-8)
16

    
17
    sphere_ff = ba.FormFactorFullSphere(10.0*nm)
18
    sphere = ba.Particle(m_particle, sphere_ff)
19
    particle_layout = ba.ParticleLayout()
20
    particle_layout.addParticle(sphere)
21
    particle_layout.setTotalParticleSurfaceDensity(1.0e-2)
22

    
23
    interference = ba.InterferenceFunction2DLattice.createHexagonal(20.0*nm)
24
    pdf = ba.FTDecayFunction2DCauchy(10*nm, 10*nm)
25
    interference.setDecayFunction(pdf)
26

    
27
    particle_layout.setInterferenceFunction(interference)
28

    
29
    air_layer = ba.Layer(m_air)
30
    air_layer.addLayout(particle_layout)
31
    air_layer.addLayout(particle_layout)
32
    substrate_layer = ba.Layer(m_substrate, 0)
33
    multi_layer = ba.MultiLayer()
34
    multi_layer.addLayer(air_layer)
35
    multi_layer.addLayer(substrate_layer)
36
    return multi_layer
37

    
38

    
39
def get_simulation():
40
    """
41
    Create and return GISAXS simulation with beam and detector defined
42
    """
43
    simulation = ba.GISASSimulation()
44
    simulation.setDetectorParameters(200, -1.0*deg, 1.0*deg,
45
                                     200, 0.0*deg, 1.0*deg)
46
    simulation.setBeamParameters(1.0*angstrom, 0.2*deg, 0.0*deg)
47
    simulation.getOptions().setUseAvgMaterials(True)
48
    return simulation
49

    
50

    
51
def run_simulation():
52
    """
53
    Runs simulation and returns intensity map.
54
    """
55
    simulation = get_simulation()
56
    simulation.setSample(get_sample())
57
    simulation.runSimulation()
58
    return simulation.getIntensityData()
59

    
60

    
61
if __name__ == '__main__':
62
    result = run_simulation()
63
    ba.plot_intensity_data(result)