py_dot_array_nonmag.py

Script 1x1 basis - a.glavic, 08 Aug 2016 18:00

Download (2.95 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
    particle_1 = ba.Particle(material_1, formFactor_1)
24

    
25
    # Defining Interference Functions
26
    interference_1 = ba.InterferenceFunction2DLattice(70.0*nm, 70.0*nm, 90.0*deg, 0.0*deg)
27
    interference_1_pdf  = ba.FTDecayFunction2DVoigt(100000.0*nm, 100000.0*nm, 0.5)
28
    interference_1.setDecayFunction(interference_1_pdf)
29

    
30
    # Defining Particle Layouts and adding Particles
31
    layout_1 = ba.ParticleLayout()
32
    layout_1.addParticle(particle_1, 1.0)
33
    layout_1.addInterferenceFunction(interference_1)
34
    layout_1.setTotalParticleSurfaceDensity(0.000204081632653)
35

    
36
    # Adding layouts to layers
37
    layer_1.addLayout(layout_1)
38

    
39
    # Defining Multilayers
40
    multiLayer_1 = ba.MultiLayer()
41
    multiLayer_1.addLayer(layer_1)
42
    multiLayer_1.addLayer(layer_2)
43
    return multiLayer_1
44

    
45

    
46
def getSimulation():
47
    simulation = ba.GISASSimulation()
48
    
49
    detector = ba.RectangularDetector(128, 960.0, 128, 960.0)
50
    detector.setPerpendicularToDirectBeam(18000.0, 480.0, 280.0)
51
    simulation.setDetector(detector)
52

    
53
    simulation.setBeamParameters(0.6*nm, 0.1*deg, 0.0*deg)
54
    simulation.setBeamIntensity(1.0e+12)
55
    distribution_1 = ba.DistributionGaussian(0.6, 0.026)
56
    simulation.addParameterDistribution("*/Beam/Wavelength", distribution_1, 9, 2.0)
57
    distribution_2 = ba.DistributionGate(0.00146607657168, 0.00202458193231)
58
    simulation.addParameterDistribution("*/Beam/Alpha", distribution_2, 5, 2.0)
59
    distribution_3 = ba.DistributionGate(-0.000279252680319, 0.000279252680319)
60
    simulation.addParameterDistribution("*/Beam/Phi", distribution_3, 5, 2.0)
61
    return simulation
62

    
63

    
64
def plotSimulation(simulation):
65
    result = simulation.getIntensityData()
66
    im=plt.imshow(result.getArray(), norm=matplotlib.colors.LogNorm(1e6, 1e12),
67
                    extent=[-960./2, 960./2,-960./2, 960./2])
68
    plt.colorbar(im)
69
    plt.show()
70

    
71

    
72
def runSimulation(filename = ''):
73
    # Run Simulation
74
    sample = getSample()
75
    simulation = getSimulation()
76
    simulation.setSample(sample)
77
    simulation.runSimulation()
78
    if filename != '':
79
        ba.IntensityDataIOFactory.writeIntensityData(simulation.getIntensityData(), filename + '.int')
80

    
81

    
82
if __name__ == '__main__': 
83
    #runSimulation('output')
84

    
85
    sample=getSample()
86
    simulation = getSimulation()
87
    simulation.setSample(sample)
88
    simulation.runSimulation()
89
    plotSimulation(simulation)