A multilayer fitting model#

One of the main tools in easyreflectometry is the assemblies library. This allows the user to define their model, using specific parameters for their system of interest (if it is included in the assemblies library). These assemblies will impose necessary constraints and computational efficiencies based on the assembly that is used.

In this tutorial, we will look at one of these assemblies, that of a RepeatingMultilayer (documented here). This tutorial is based on an example from the BornAgain documentation looking at specular reflectivity analysis. Before performing analysis, we should import the packages that we need.

First configure matplotlib to place figures in notebook and import needed modules

%matplotlib inline

import numpy as np
import scipp as sc
import easyreflectometry
import refl1d
from easyreflectometry.data import load
from easyreflectometry.sample import Layer
from easyreflectometry.sample import Sample
from easyreflectometry.sample import Material
from easyreflectometry.sample import RepeatingMultilayer
from easyreflectometry.experiment import Model
from easyreflectometry.experiment import PercentageFhwm
from easyreflectometry.calculators import CalculatorFactory
from easyreflectometry.fitting import Fitter
from easyreflectometry.plot import plot

As mentioned in the previous tutorial, we share the version of the software packages we will use.

print(f'numpy: {np.__version__}')
print(f'scipp: {sc.__version__}')
print(f'easyreflectometry: {easyreflectometry.__version__}')
print(f'Refl1D: {refl1d.__version__}')
numpy: 1.26.4
scipp: 24.02.0
easyreflectometry: 1.0.2
Refl1D: 0.8.16

Reading in experimental data#

The data that we will investigate in this tutorial was generated with GenX and is stored in an .ort format file. Use link to download the ort data.

data = load('repeating_layers.ort')
  • data
    {'R_0': <scipp.Variable> (Qz_0: 400) float64 [dimensionless] [1, 1, ..., 8....
  • coords
    {'Qz_0': <scipp.Variable> (Qz_0: 400) float64 [1/Å] [0.000712093, ...
  • attrs
    {'R_0': {'orso_header': <scipp.Variable> () PyObject <no unit> {'data_...

This data is very featureful, with many fringes present (arising from the multilayer structure)


Building our model#

The system that was used to produce the data shown above is based on a silicon subphase, with a repeating multilayer of nickel and titanium grown upon it. Typcially, under experimental conditions, the producer of the sample will know how many repeats there will be of the multilayer system (as these are grown using some vapour disposition or sputtering method that the producer controls). We show the model that will be used graphically below.

A slab model description of the repeating multilayer system.

A slab model description of the repeating multilayer, showing the four layers of vacuum, titanium, nickel and silicon, with the titanium/nickel layers being repeated 10 times.

To construct such a layer structure, first we create each of the materials and associated layers

vacuum = Material(sld=0, isld=0, name='Vacuum')
ti = Material(sld=-1.9493, isld=0, name='Ti')
ni = Material(sld=9.4245, isld=0, name='Ni')
si = Material(sld=2.0704, isld=0, name='Si')
superphase = Layer(material=vacuum, thickness=0, roughness=0, name='Vacuum Superphase')
ti_layer = Layer(material=ti, thickness=40, roughness=0, name='Ti Layer')
ni_layer = Layer(material=ni, thickness=70, roughness=0, name='Ni Layer')
subphase = Layer(material=si, thickness=0, roughness=0, name='Si Subphase')

Then, to produce the repeating multilayer, we use the RepeatingMultilayer assembly type. This can be constructed in a range of different ways, however here we pass a list of Layer type objects and a number of repetitions.

rep_multilayer = RepeatingMultilayer([ti_layer, ni_layer], repetitions=10, name='NiTi Multilayer')
NiTi Multilayer:
  Ti Layer/Ni Layer:
  - Ti Layer:
          sld: -1.949e-6 1 / angstrom ** 2
          isld: 0.000e-6 1 / angstrom ** 2
      thickness: 40.000 angstrom
      roughness: 0.000 angstrom
  - Ni Layer:
          sld: 9.425e-6 1 / angstrom ** 2
          isld: 0.000e-6 1 / angstrom ** 2
      thickness: 70.000 angstrom
      roughness: 0.000 angstrom
  repetitions: 10.0

From these objects, we can construct our structure and combine this with a scaling, background and resolution (since this data is simulated there is no background or resolution smearing).

resolution_function = PercentageFhwm(0)
sample = Sample(superphase, rep_multilayer, subphase, name='Multilayer Structure')
model = Model(
    name='Multilayer Model'

In the analysis, we will only vary a single parameter, the thickness of titanium layer.

ti_layer.thickness.bounds = (10, 60)

Choosing our calculation engine#

In the previous tutorial, we used the default refnx engine for our analysis. Here, we will change our engine to be Refl1D. This is achieved with the interface.switch('refl1d') method below.

interface = CalculatorFactory()
model.interface = interface

Performing an optimisation#

The easyScience framework allows us to access a broad range of optimisation methods. Below, we have selected the differential evolution method from lmfit.

fitter = Fitter(model)
analysed = fitter.fit(data, method='differential_evolution')
  • data
    {'R_0': <scipp.Variable> (Qz_0: 400) float64 [dimensionless] [1, 1, ..., 8....
  • coords
    {'Qz_0': <scipp.Variable> (Qz_0: 400) float64 [1/Å] [0.000712093, ...
  • attrs
    {'R_0': {'orso_header': <scipp.Variable> () PyObject <no unit> {'data_...
  • R_0_model
    (Qz_0: 400)
    1.000, 1.000, ..., 9.474e-08, 4.953e-09
  • SLD_0
    (z_0: 10200)
    8.882e-22, 8.882e-22, ..., 2.070e-06, 2.070e-06

We can visualise the analysed model and SLD profile with the plot function.


The value of the titanium layer thickness that gives this best fit can be found from the relavant object. Note that the uncertainty of 0 is due to the use of the lmfit differential evolution algorithm, which does not include uncertainty analysis.

<Parameter 'thickness': 29.987946085994974+/-0 Å, bounds=[10:60]>

This result of a thickness of 30 Å is the same as that which is used to produce the data.