Roughness vs GenX

This example compares diffuse scattering from rough interfaces with reference curves computed by the GenX interdiff model. Two samples are shown: a single rough surface, and a 20 nm film on a substrate whose two interfaces are partially correlated.

The wavelength is 0.1 nm and the incident flux is $10^8$ particles/s. The surface has refractive index $1-5\cdot10^{-6}+2\cdot10^{-8}i$ and RMS roughness 2 nm. The film and substrate indices are $1-3\cdot10^{-6}+10^{-8}i$ and $1-7\cdot10^{-6}+3\cdot10^{-8}i$; the top and buried interface RMS heights are 2 and 3 nm.

Both programs compute the same model:

  • sharp reference waves and the lower-field continuation with two terms, setRoughnessApproximation("LowerField", 2). Two terms are the default of GenX, where the parameter is called taylor_n;
  • an exponential height covariance ($H=0.5$, $\xi=1$ µm) without cutoff frequency, a CommonDepthCrosscorrelation with a depth of 40 nm, and no interdiffusion;
  • a detector slit with a full height of 0.1°. The intensity at the centre of the slit is multiplied by the slit height; no resolution function is applied.

The detector scans use $\alpha_i=0.25^\circ$. The rocking scans keep $2\theta=\alpha_i+\alpha_f=0.6^\circ$ fixed. GenX integrates the intensity over the whole direction transverse to the scattering plane. BornAgain integrates here over the azimuthal angle from −1° to 1°, which is wide enough for this lateral correlation length.

With two terms, the sum has not converged at the larger exit angles. The example uses two terms only to match GenX; see Diffuse approximations for how to choose the number of terms.

Result

Detector scans and rocking scans: GenX and BornAgain

Sample

Film with correlated rough interfaces

Data files

Place these files next to the Python script.

Python script

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.10"
# dependencies = ["bornagain>=25,<26"]
# ///
"""
Diffuse detector and rocking scans compared with reference data from GenX.

Both programs use sharp reference waves and the lower-field continuation
(LowerField) with two terms. Place the four GenX data files next to this
script.
"""
from pathlib import Path
import numpy as np
import bornagain as ba
ba.require_versions("bornagain>=25,<26")
from bornagain import deg, nm

ALPHA_I = 0.25*deg  # incident angle of the detector scans
TWO_THETA = 0.6*deg  # scattering angle of the rocking scans
DATA_FILES = {
    ('surface', 'detector'): "genx_roughness_surface_detector.dat.gz",
    ('surface', 'rocking'): "genx_roughness_surface_rocking.dat.gz",
    ('film', 'detector'): "genx_roughness_film_detector.dat.gz",
    ('film', 'rocking'): "genx_roughness_film_rocking.dat.gz",
}


def get_sample(kind, hurst=0.5):
    """
    A rough surface, or a film on a substrate with correlated roughness.
    """
    film_color = (0.4, 0.7, 0.9)
    substrate_color = (0.3, 0.5, 0.7)
    sample = ba.Sample()
    sample.addLayer(ba.Layer(ba.Vacuum()))
    if kind == 'film':
        film = ba.RefractiveMaterial('Film', film_color, 3e-6, 1e-8)
        model = ba.PoweredExponentialModel(2*nm, hurst, 1000*nm)
        roughness = ba.Roughness(model, ba.ErfTransient(),
                                 ba.CommonDepthCrosscorrelation(40*nm))
        sample.addLayer(ba.Layer(film, 20*nm, roughness))
        substrate = ba.RefractiveMaterial('Substrate', substrate_color,
                                          7e-6, 3e-8)
        rms = 3*nm
    else:
        substrate = ba.RefractiveMaterial('Substrate', substrate_color,
                                          5e-6, 2e-8)
        rms = 2*nm
    model = ba.PoweredExponentialModel(rms, hurst, 1000*nm)
    roughness = ba.Roughness(model, ba.ErfTransient(),
                             ba.CommonDepthCrosscorrelation(40*nm))
    sample.addLayer(ba.Layer(substrate, roughness))
    return sample


def get_simulation(sample, alpha_i, alpha_f):
    """
    For each incident angle alpha_i[j], a detector slit at alpha_f[j].
    """
    scan = ba.AlphaScan(alpha_i)
    scan.setWavelength(0.1*nm)
    scan.setIntensity(1e8)
    detector = ba.SlitOffspecDetector(alpha_f, 0.1*deg, -1*deg, 1*deg)
    simulation = ba.OffspecSimulation(scan, sample, detector)
    simulation.options().setIncludeSpecular(False)
    simulation.options().setDwbaReferenceWaves('Sharp')
    simulation.options().setRoughnessApproximation('LowerField', 2)
    return simulation


def simulate(sample, geometry, reference):
    """
    Return the diffuse intensity at the angles of the reference scan.
    """
    angles = np.array(reference.xCenters())
    if geometry == 'detector':
        values = [
            get_simulation(sample, [ALPHA_I], [alpha]).simulate().valAt(0)
            for alpha in angles
        ]
    else:
        simulation = get_simulation(sample, angles, TWO_THETA - angles)
        values = simulation.simulate().flatVector()
    return ba.Datafield(reference.frame(), values)


def load_reference(kind, geometry):
    """
    Return the GenX intensity in particles/s against the scanned angle.
    """
    path = Path(__file__).resolve().parent/DATA_FILES[kind, geometry]
    angles, intensity = np.loadtxt(path, unpack=True)
    label = 'alpha_f (rad)' if geometry == 'detector' else 'alpha_i (rad)'
    frame = ba.Frame(ba.ListScan(label, (angles*deg).tolist()))
    return ba.Datafield(frame, intensity.tolist())


if __name__ == '__main__':
    ba.showSample3D(get_sample('film'), sample_size=120*nm, seed=0)
    fig = ba.plt.figure(figsize=(10, 7.5), layout='constrained')
    axes = fig.subplots(2, 2)
    for axis, (kind, geometry) in zip(axes.flat, DATA_FILES):
        reference = load_reference(kind, geometry)
        result = simulate(get_sample(kind), geometry, reference)
        ba.plot_multicurve([None],
                           measured=[reference],
                           labels=['GenX, 2 terms'],
                           ax=axis,
                           pointargs={
                               'fmt': 'o',
                               'color': 'black',
                               'markersize': 4,
                               'markevery': 0.04
                           })
        ba.plot_multicurve([result],
                           labels=['BornAgain LowerField, 2 terms'],
                           ax=axis,
                           ylabel='Diffuse intensity (particles/s)')
        axis.set_title(f'{kind.capitalize()}: {geometry} scan')
    fig.legend(*axes.flat[0].get_legend_handles_labels(),
               loc='outside upper center',
               ncol=2,
               frameon=False)

    ba.plt.show()
auto/Examples/offspec/RoughnessVsGenx.py