exported-script.py

pospelov, 02 Jul 2015 09:33

Download (3.69 KB)

 
1
import numpy
2
#NOTE: Uncomment the next import statements for plotting
3
import pylab #@GENNADY: I removed the comment for plotting
4
import matplotlib #@GENNADY: I removed the comment for plotting
5
from bornagain import *
6

    
7
phi_min, phi_max = -1.4, 1.4 #@GENNADY: I added this two lines for plotting
8
alpha_min, alpha_max = 0.0, 3.0
9

    
10
def getSample():
11
    # Defining Materials
12
    material_1 = HomogeneousMaterial("Air", 0.0, 0.0)
13
    material_2 = HomogeneousMaterial("PS", 3.46157e-06, 4.9183e-09)
14
    material_3 = HomogeneousMaterial("PEO", 3.5269999999e-06, 8.05e-09)
15
    material_4 = HomogeneousMaterial("Substrate (Si)", 7.563e-06, 1.748e-07)
16

    
17
    # Defining Layers
18
    layer_1 = Layer(material_1)
19
    layer_2 = Layer(material_2, 70)
20
    layer_3 = Layer(material_4)
21

    
22
    # Defining Form Factors
23
    formFactor_1 = FormFactorCylinder(11*nanometer, 40*nanometer) #@GENNADY: I corrected the radius height order
24

    
25
    # Defining Particles
26
    particle_1 = Particle(material_3, formFactor_1)
27

    
28
    # Defining collection of particles with size distribution
29
    distr_1 = DistributionGaussian(40.0, 20.0) 
30
    par_distr_1 = ParameterDistribution("/Particle/FormFactorCylinder/height", distr_1, 5, 2.0)
31
    particleDistribution_1 = ParticleDistribution(particle_1, par_distr_1)
32

    
33
    particleDistribution_1.setPosition(kvector_t(0.0, 0.0, -70.0))
34

    
35
    # Defining Interference Functions
36
    interference_1 = InterferenceFunction2DParaCrystal.createHexagonal(37*nanometer, 1000*nanometer, 1000*nanometer, 1000*nanometer)
37
    interference_1_pdf_1 = FTDistribution2DGauss(1*nanometer, 1*nanometer)
38
    interference_1_pdf_2 = FTDistribution2DGauss(1*nanometer, 1*nanometer)
39
    interference_1.setProbabilityDistributions(interference_1_pdf_1, interference_1_pdf_2) #@GENNADY: I corrected the typo here
40

    
41
    # Defining Particle Layouts and adding Particles
42
    layout_1 = ParticleLayout()
43
#    layout_1.addParticle(particle_1, 70, 1.0)
44
    layout_1.addParticle(particleDistribution_1, 1.0) #@GENNADY: I corrected the -0.0 error
45
    layout_1.addInterferenceFunction(interference_1)
46
    layout_1.setTotalParticleSurfaceDensity(1)
47

    
48
    # Adding layouts to layers
49
    layer_2.addLayout(layout_1)
50

    
51
    # Defining Multilayers
52
    multiLayer_1 = MultiLayer()
53
    multiLayer_1.addLayer(layer_1)
54
    multiLayer_1.addLayer(layer_2)
55
    multiLayer_1.addLayer(layer_3)
56
    return multiLayer_1
57

    
58

    
59
def getSimulation():
60
    simulation = GISASSimulation()
61
    simulation.setDetectorParameters(100, phi_min*degree, phi_max*degree, 100, alpha_min*degree, alpha_max*degree) #@GENNADY: I changed this for using variables
62
    simulation.setBeamParameters(0.1542*nanometer, 0.17*degree, 0.0*degree)
63
    simulation.setBeamIntensity(1E08) #@GENNADY: for some reasons I added this line
64
    return simulation
65

    
66

    
67
def runSimulation(filename = ''):
68
    # Run Simulation
69
    sample = getSample()
70
    simulation = getSimulation()
71
    simulation.setSample(sample)
72
    simulation.runSimulation()
73
#    if filename != '':
74
#    IntensityDataIOFactory.writeIntensityData(simulation.getIntensityData(), filename + '.int')
75
    IntensityDataIOFactory.writeIntensityData(simulation.getIntensityData(), filename + '.int')
76
    result = simulation.getIntensityData().getArray() #@GENNADY: I removed the +1 in intensity
77
    im = pylab.imshow(numpy.rot90(result, 1), norm=matplotlib.colors.LogNorm(), extent=[phi_min, phi_max, alpha_min, alpha_max], aspect='auto', vmin=0.001, vmax=10) #@GENNADY: I changed this for using variables and vmin,vmax
78
    cb = pylab.colorbar(im) #@GENNADY: I added some lines for plotting
79
    cb.set_label(r'Intensity (arb. u.)', size=16)
80
    pylab.xlabel(r'$\phi_f (^{\circ})$', fontsize=16)
81
    pylab.ylabel(r'$\alpha_f (^{\circ})$', fontsize=16)
82
    pylab.show()
83

    
84
if __name__ == '__main__': 
85
    runSimulation('output')