Using the MaterialSolvated#

In the first tutorial, we looked at a straight forward example of a polymer film at the solid/liquid interface. To analyse this data, we constructed a model with two layers, one SiO2 and one of the polymer film, and when the analysis was performed, the scattering length density of the polymer film was allowed to vary to find an optimum value. However, it is likely that this scattering length density is in fact a compound value arising from the mixture of the polymer with some D2O intercalated. Therefore, if, for example, the surface covereage of the polymer was known, it may be possible to determine the scattering length density alone. Of course, this could be calculated from the optimal scattering length density for the film, but it is more intuitive to include this in our modelling approach. Here, we will show how to use the MaterialSolvated type to perform this analysis.

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

[1]:
%matplotlib inline

import numpy as np
import scipp as sc
import EasyReflectometry
import refnx
from EasyReflectometry.data import load
from EasyReflectometry.sample import Layer
from EasyReflectometry.sample import Sample
from EasyReflectometry.sample import Material
from EasyReflectometry.sample import MaterialSolvated
from EasyReflectometry.sample import Multilayer
from EasyReflectometry.experiment.model import Model
from EasyReflectometry.calculators import CalculatorFactory
from EasyReflectometry.fitting import Fitter
from EasyReflectometry.plot import plot

Showing the version of specific softare for reproducibility

[2]:
print(f'numpy: {np.__version__}')
print(f'scipp: {sc.__version__}')
print(f'EasyReflectometry: {EasyReflectometry.__version__}')
print(f'refnx: {refnx.__version__}')
numpy: 1.26.4
scipp: 24.02.0
EasyReflectometry: 0.0.0
refnx: 0.1.43

For information about the data being read in and the details of the model see the previous tutorial. We will gloss over these details here.

[3]:
data = load('_static/example.ort')

Constructing the model#

Previously the model consisted of four materials, we will construct those again here.

[4]:
si = Material.from_pars(2.07, 0, 'Si')
sio2 = Material.from_pars(3.47, 0, 'SiO2')
film = Material.from_pars(2.0, 0, 'Film')
d2o = Material.from_pars(6.36, 0, 'D2O')

However, now we will construct a component object (for type MaterialSolvated), based on the knowledge that there is a 75 % surface coverage of the silicon block by the polymer film. Note that this object takes the material (polymer film) and a solvent, which both are instances of Material. The fraction of material and solvent is given by the solvent_fraction, which in this case is 25% solvent.

[5]:
solvated_film = MaterialSolvated.from_pars(
    material=film,
    solvent=d2o,
    solvent_fraction=0.25,
    name='Solvated Film'
)

So for the solvated_film object, the scattering length density is calculated as,

\rho_{\mathrm{solv film}} = (1-\phi)\rho_{\mathrm{film}} + \phi\rho_{\mathrm{D}_2\mathrm{O}},

where the scattering length densities are given with \rho and the coverage with \phi. This means that when we investigate the solvated_film object, the scattering length density will be 3.09e-6 Å-2

[6]:
solvated_film
[6]:
Solvated Film:
  solvent_fraction: 0.25
  sld: 3.090e-6 1 / angstrom ** 2
  isld: 0.000e-6 1 / angstrom ** 2
  material:
    Film:
      sld: 2.000e-6 1 / angstrom ** 2
      isld: 0.000e-6 1 / angstrom ** 2
  solvent:
    D2O:
      sld: 6.360e-6 1 / angstrom ** 2
      isld: 0.000e-6 1 / angstrom ** 2

Now, we can construct our layers, sample and model.

[7]:
si_layer = Layer.from_pars(si, 0, 0, 'Si layer')
sio2_layer = Layer.from_pars(sio2, 30, 3, 'SiO2 layer')
superphase = Multilayer.from_pars([si_layer, sio2_layer], name='Si/SiO2 Superphase')

solvated_film_layer = Layer.from_pars(solvated_film, 250, 3, 'Film Layer')

subphase = Layer.from_pars(d2o, 0, 3, 'D2O Subphase')

sample = Sample.from_pars(superphase, solvated_film_layer, subphase, name='Film Structure')
model = Model.from_pars(sample, 1, 1e-6, 0.02, 'Film Model')

Setting varying parameters#

Previously, the scattering length density of the film_layer was allowed to vary (in addition to other parameters). This time, the scattering length density will for the film be varied, leading to a change in the solvated_film_layer scattering length density. We show this in the four code cells below.

[8]:
film.sld.value = 2.0
[9]:
print(solvated_film_layer.material.sld)
<Parameter 'sld': 3.09+/-0 1/Ų (fixed), bounds=[-inf:inf]>
[10]:
film.sld.value = 2.5
[11]:
print(solvated_film_layer.material.sld)
<Parameter 'sld': 3.465+/-0 1/Ų (fixed), bounds=[-inf:inf]>

The parameter bounds are then set as follows.

[12]:
# Thicknesses
sio2_layer.thickness.bounds = (15, 50)
solvated_film_layer.thickness.bounds = (200, 300)
# Roughnesses
sio2_layer.roughness.bounds = (1, 15)
solvated_film_layer.roughness.bounds = (1, 15)
subphase.roughness.bounds = (1, 15)
# Scattering length density
film.sld.bounds = (0.1, 3)
# Background
model.background.bounds = (1e-8, 1e-5)
# Scale
model.scale.bounds = (0.5, 1.5)

Perform the fitting#

Having constructed the model and set the relevant varying parameters, we run the analysis (using the default refnx engine).

[13]:
interface = CalculatorFactory()
model.interface = interface
fitter = Fitter(model)
analysed = fitter.fit(data)

The model fits well to the data.

[14]:
plot(analysed)
../_images/tutorials_material_solvated_25_0.png

We can probe the MaterialSolvated object to investigate the scattering length density of the polymer film alone.

[15]:
solvated_film
[15]:
Solvated Film:
  solvent_fraction: 0.25
  sld: 2.360e-6 1 / angstrom ** 2
  isld: 0.000e-6 1 / angstrom ** 2
  material:
    Film:
      sld: 1.026e-6 1 / angstrom ** 2
      isld: 0.000e-6 1 / angstrom ** 2
  solvent:
    D2O:
      sld: 6.360e-6 1 / angstrom ** 2
      isld: 0.000e-6 1 / angstrom ** 2

The fit reproducing the measured reflectivity curve yields that the scattering length density (SLD) of the layer is 2.36E-6 Å-2. Remember this layer is composed of 75% of the polymer film layer (SLD of 1.026E-6 Å-2 fitted) and 25% of D2O (SLD of 6.36E-6 Å-2 known) making (0.75 * 1.026 + 0.25 * 6.36)E-6 = 2.36E-6 Å-2. This is the same as the result from the previous tutorial.