bug2.py

Script to reproduce the issue - ganeva, 25 Jul 2019 14:39

Download (1.82 KB)

 
1
import numpy as np
2
import bornagain as ba
3
from bornagain import nm
4
import matplotlib.pyplot as plt
5

    
6
DEBUG = True
7

    
8

    
9
def get_sample(sigma=10.0):
10
    """
11
    Returns a sample for given parameter values.
12
    """
13
    # set materials
14
    delta_au = 1.71735e-005
15
    beta_au = 2.08622e-006
16
    delta_si = 2.85817e-006
17
    beta_si = 2.55849e-008
18

    
19
    # defining materials
20
    m_air = ba.HomogeneousMaterial("Air", 0.0, 0.0)
21
    m_au = ba.HomogeneousMaterial("Au", delta_au, beta_au)
22
    m_si = ba.HomogeneousMaterial("Si", delta_si, beta_si)
23

    
24
    # layers
25
    l_air = ba.Layer(m_air)
26
    l_si = ba.Layer(m_si)
27

    
28
    # buried particles
29
    z = -2.0*nm
30
    radius = 7.12
31

    
32
    b_ff = ba.FormFactorFullSphere(radius)
33
    buried_particle = ba.Particle(m_au, b_ff)
34
    buried_particle.setPosition(ba.kvector_t(0.0, 0.0, z))
35

    
36
    # size distribution
37
    b_distr = ba.DistributionLogNormal(radius, sigma)
38
    b_par_distr = ba.ParameterDistribution("*/FullSphere/Radius", b_distr, 3, 2.0,
39
                                           ba.RealLimits.positive())
40
    b_part_coll = ba.ParticleDistribution(buried_particle, b_par_distr)
41

    
42
    buried_layout = ba.ParticleLayout()
43
    buried_layout.addParticle(b_part_coll)
44
    buried_layout.setTotalParticleSurfaceDensity(4e-04)
45
    l_air.addLayout(buried_layout)
46

    
47
    multi_layer = ba.MultiLayer()
48
    multi_layer.addLayer(l_air)
49
    multi_layer.addLayer(l_si)
50

    
51
    if DEBUG:
52
        print(multi_layer.parametersToString())
53

    
54
    return multi_layer
55

    
56

    
57
def plot_sld():
58
    plt.figure(figsize=(10, 5))
59
    sigmas = [1.0, 5.0, 10.0]
60
    for s in sigmas:
61
        sample = get_sample(s)
62
        zpoints, slds = ba.MaterialProfile(sample)
63
        plt.semilogx(zpoints, np.real(slds), label=r"$\sigma={}$".format(s))
64
    plt.xlabel(r"$z$ (nm)")
65
    plt.ylabel(r"$\rho(z)$")
66
    plt.legend()
67
    plt.show()
68

    
69

    
70
if __name__ == '__main__':
71
    plot_sld()