py_dot_array_nonmag_22.py

Script 2x2 basis - a.glavic, 08 Aug 2016 18:00

Download (3.31 KB)

 
1
import numpy
2
#NOTE: Uncomment the next import statements for plotting
3
import matplotlib
4
from matplotlib import pyplot as plt
5
import bornagain as ba
6
from bornagain import deg, angstrom, nm, kvector_t
7

    
8

    
9
def getSample():
10
    # Defining Materials
11
    material_1 = ba.HomogeneousMaterial("Py", 9.05722e-06, 0.0)
12
    material_2=ba.HomogeneousMaterial("Air", 0.0, 0.0)
13
    material_3=ba.HomogeneousMaterial("Silicon", 2.07287999998e-06, 0.0)
14

    
15
    # Defining Layers
16
    layer_1=ba.Layer(material_2)
17
    layer_2=ba.Layer(material_3)
18

    
19
    # Defining Form Factors
20
    formFactor_1 = ba.FormFactorCylinder(20.0*nm, 40.0*nm)
21

    
22
    # Defining Particles
23
    nano_dot = ba.Particle(material_1, formFactor_1)
24
    particle_1_position = kvector_t(0.0*nm, 0.0*nm, 0.0*nm)
25
    particle_2_position = kvector_t(70.0*nm, 0.0*nm, 0.0*nm)
26
    particle_3_position = kvector_t(0.0*nm, 70.0*nm, 0.0*nm)
27
    particle_4_position = kvector_t(70.0*nm, 70.0*nm, 0.0*nm)
28
    basis = ba.ParticleComposition()
29
    basis.addParticles(nano_dot, [particle_1_position, particle_2_position, particle_3_position, particle_4_position])
30

    
31
    # Defining Interference Functions
32
    interference_1 = ba.InterferenceFunction2DLattice(140.0*nm, 140.0*nm, 90.0*deg, 0.0*deg)
33
    interference_1_pdf=ba.FTDecayFunction2DVoigt(100000.0*nm, 100000.0*nm, 0.5)
34
    interference_1.setDecayFunction(interference_1_pdf)
35

    
36
    # Defining Particle Layouts and adding Particles
37
    layout_1 = ba.ParticleLayout()
38
    layout_1.addParticle(basis)
39
    layout_1.addInterferenceFunction(interference_1)
40
    layout_1.setTotalParticleSurfaceDensity(0.000204081632653/4.)
41

    
42
    # Adding layouts to layers
43
    layer_1.addLayout(layout_1)
44

    
45
    # Defining Multilayers
46
    multiLayer_1 = ba.MultiLayer()
47
    multiLayer_1.addLayer(layer_1)
48
    multiLayer_1.addLayer(layer_2)
49
    return multiLayer_1
50

    
51

    
52
def getSimulation():
53
    simulation = ba.GISASSimulation()
54
    
55
    detector = ba.RectangularDetector(128, 960.0, 128, 960.0)
56
    detector.setPerpendicularToDirectBeam(18000.0, 480.0, 280.0)
57
    simulation.setDetector(detector)
58

    
59
    simulation.setBeamParameters(0.6*nm, 0.1*deg, 0.0*deg)
60
    simulation.setBeamIntensity(1.0e+12)
61
    distribution_1 = ba.DistributionGaussian(0.6, 0.026)
62
    simulation.addParameterDistribution("*/Beam/Wavelength", distribution_1, 9, 2.0)
63
    distribution_2 = ba.DistributionGaussian(0.00174532925199, 0.000174532925199)
64
    simulation.addParameterDistribution("*/Beam/Alpha", distribution_2, 5, 2.0)
65
    distribution_3 = ba.DistributionGaussian(0.0, 0.000174532925199)
66
    simulation.addParameterDistribution("*/Beam/Phi", distribution_3, 5, 2.0)
67
    return simulation
68

    
69

    
70
def plotSimulation(simulation):
71
    result = simulation.getIntensityData()
72
    im=plt.imshow(result.getArray(), norm=matplotlib.colors.LogNorm(1e6, 1e12),
73
                    extent=[-960./2, 960./2,-960./2, 960./2])
74
    plt.colorbar(im)
75
    plt.show()
76

    
77

    
78
def runSimulation(filename = ''):
79
    # Run Simulation
80
    sample = getSample()
81
    simulation = getSimulation()
82
    simulation.setSample(sample)
83
    simulation.runSimulation()
84
    if filename != '':
85
        ba.IntensityDataIOFactory.writeIntensityData(simulation.getIntensityData(), filename + '.int')
86

    
87

    
88
if __name__ == '__main__': 
89
    #runSimulation('output')
90

    
91
    sample=getSample()
92
    simulation=getSimulation()
93
    simulation.setSample(sample)
94
    simulation.runSimulation()
95
    plotSimulation(simulation)