# Frequently asked questions

### From Motofit

### How do I calculate a scattering length density?

From Motofit_v3.04 you can use the inbuilt SLD calculator. This calculator performs the same calculation as the NIST NCNR website.

But you should also be able to calculate them for yourself. The formula for calculating a scattering length density is given below. In this equation V_{m} is the molecular volume of the material and *b _{ci}* is the bound coherent scattering length of the i th atom of a molecule with n atoms.

You can also write this as:

Where N_{a} is Avogadro's number, ρ_{mass} is the mass density of the material and M_{R} is its relative molecular mass.

You can find a table of neutron scattering lengths at the NIST website.

For X-rays you have to calculate the scattering length for each atom before doing the calculation.

where e is the charge on a single electron, ε_{0} is the permittivity of free space, m is the mass of an electron and c is the speed of light. f_{1i} is the scattering factor for an atom of element i and may be
found from the Lawrence Livermore website.

To use this website you will need to know the wavelength of the X-ray radiation that you are using (1.54Å=8047eV).

This is an exact way of calculating b_{i}, a much quicker approximation is to use:

Where Z is the atomic number and r_{e} is the Compton radius (Å)

### How do I use the SLD calculator?

Select the SLDdatabase panel (Windows-->SLDdatabase). Enter the chemical formula on the top row. The entry must be rigidly formatted. If you want to select a particular isotope enter an integer number in brackets after the chemical. Then enter a mass density into the box. Valid:

- H(2)2O
- D2O (same as H(2)2O)
- XeF6

Not Valid:

- h(2)2o
- d2o
- xEF6
- XEF6

### Do I need to install Abeles.xop?

Abeles.xop is a pre-compiled function written in C that calculates reflectivity. Although it is not necessary to install this file, I strongly recommend it, as it makes the program run around 5-6 times faster. This means that if you have lots of layers, or prefer to fit with Genetic Optimisation, or want to fit batch data, then the fit is blazing fast, and you don't need to go for a cup of tea in the meantime.

### What is a wave in IGOR?

A wave is a data object, which contains a column of data, similar to Excel. When you load a reflectivity dataset with Q, R and dR, you are loading 3 waves. One wave contains the Q values, and there is a wave for the Reflectivity values and a wave for the error in reflectivity values. Obviously Q,R and dR should have the same number of points. Each of the waves has a different name. If you opened the same dataset in Excel you would see ccolumns containing the Q,R and dR values. IGOR is a program that performs mathematical operations on these waves.

### What is a coefficient wave

A coefficient wave is a wave containing the parameters for the fit. They are saved as IGOR text files (*.itx), which have some extra advantages to normal text files. The program will only load Igor text files.

### Why are the layer thicknesses and roughnesses sometimes negative

Motofit uses the modulus of the thickness and roughness values, so there is no need to worry.

### The model doesn't seem to be sensitive to roughness

Sometimes you may fit some data and some of the roughness parameters appear to go haywire. This is because in a lot of situations the modelled data isn't sensitive to roughness and when you start to fit the roughnesses oscillate dramatically. This often occurs in situations where there aren't many features in the reflectivity profile and where the data doesn't extend to large Q values. To combat this change the troublesome roughnesses to a realistic value, then fix them during the fit. Once you get close to a good solution then this problem usually gets better. Be sure to look at the correlation matrix to determine any problems.

### Can I fit X-ray data and Neutron Data at the same time?

Using global fit you can fit as many neutron contrasts as you like. You can also fit X-ray and neutron data together. However, difficulties may arise because X-ray datasets normally have much better statistics than neutron data. Therefore when you try to fit neutrons and X-rays together the data is sometimes preferentially weighted towards the X-ray set.

### What format should my dataset be in?

The dataset should have either 2,3 or 4 columns. If there is a two column dataset then the columns should consist of Q and R values. For a three column dataset you should have Q, R and dR (where dR is error in reflectivity). For a four column dataset you should have Q, R, dR and dQ (where dQ is uncertainty in Q). The reflectivity values should be a value between 0 and 1. i.e. you cant load in Q, logR, dR or Q, RQ4, dR data. You should get rid of errant datapoints which have R<0 (which may happen if you subtract a background). All columns should be the same length. For best results the file should be saved without a header (i.e. the data starts in the first line), and in the tab delimited format. This manipulation is easy in Excel.

### Why doesn't the global fit produce SLD profiles for each dataset

The global fit procedures don't produce SLD profiles for each dataset and there is no intention at the moment to implement this functionality. To get around this and get SLD profiles for each dataset it is suggested that you fit each dataset individually, but hold all the parameters.

### When should I use Levenberg-Marquardt or genetic optimisation?

I would use Genetic Optimisation to perform the fitting (for both single datasets and multiple contrast fitting), then follow up with Levenberg Marquardt to calculate errors, etc. This is because Genetic Optimisation is very good at finding global minima from poor initial guesses. However, you need to perform Levenberg-Marquardt to get a full statistical analysis on the errors.

### Can I fit normalised Fresnel reflectivity curves?

Yes! Thats what the Fresnel.ipf file is for. However, if you want to fit curves like this you will have to use the curve fitting dialogue. It will help if you are acquainted with the curve fitting dialogue, since all the curve fitting will go on in there.

Follow these steps:

- Load the experimental datasets that you measured, using the "Load data" button.
- Make sure that the plot type is "R vs Q" for all the steps (important).
- subtract the background from your dataset, you can find out the name of the dataset in IGOR by using the databrowser (Data --> Databrowser) OR by using the dataset popup menu in the reflectivity panel. The R data will be something like dataset_extR.
- You subtract the background by using this command in the command window (ctrl-J):
*dataset_extR=dataset_extR-backgroundvalue* - You then need to normalise the dataset by the Fresnel reflectivity. (still keep the plot type as "R vs Q").
- First put the correct parameters in the Reflectivity panel (i.e. number of layers=0, scale=1, SLDtop=SLDtop, SLDbase=SLDbase, bkg=0, sigma_base=0).
- Now enter the following command in the command line:
*Calcfresnel(coef_Cref,dataset_extR,dataset_extQ)*. This will take the Rwave (dataset_extR) and the Q wave (dataset_extQ), calculate the Fresnel reflectivity at each of the points in your experimental dataset, then divide dataset_extR by the Fresnel reflectivity. At this stage you should have the normalised curve. - To display the normalised curve type:
*display dataset_extR vs dataset_extR*in the command line. You will see a line plot, but you can change this by clicking on various aspects of the graph. - Now put the parameters you expect for the system in the Reflectivity panel, i.e. the required number of layers, thicknesses, solvent penetration, roughnesses, etc. This updates the wave "coef_Cref"
- You are now are at a stage to do the fit. Go to the Igor menu and select: Analysis-->Curve Fitting. Use "Fresnelreflectivity" as the fitfunction. Use the normalised reflectivity curve (dataset_extR) as the ydata, and Dataset_extq as the xdata. Go to the coefficients tab and use "coef_Cref" as the coefficient wave.
- Now select the parameters to hold. you must hold parameters 0 to 5 (numlayers, scale=1, sldtop, sldbase, bkg=0, sigma_base). You have to hold these because you have normalised your data by the fresnel reflectivity created by these parameters. Select any other parameters to hold, then do the fit (DO IT button).
- There will be a parameter wave produced as a result, (coef_dataset_extR) and the graph that you produced will have the fit curve on it.
- You can also global fit with this function, once you have normalised all your contrasts by their individual fresnel reflectivity.

caveats: I've tried fitting X-ray data this way, and it works ok. However it doesn't work very well if the data is very different to the fresnel reflectivity (very likely at high Q). This may be true if you have X-ray data extending to high Q (and therefore low reflectivity). Therefore it's VERY, VERY, VERY sensitive to the roughness (sigma_base) of the fresnel reflectivity curve that you normalise by. In order to get this to fit I created a theoretical reflectivity out to Q=0.7, and experimented with different sigma_base. In addition you also have to subtract the right amount of background. You might want to restrict the range you fit over using the "cursors".

If you don't choose the correct values then the reflectivity curve will have a large upturn at high Q, this is bad.

### I want a normalised correlation matrix, how do I do it?

The normalised correlation matrix is automatically produced after a fit. To get this displayed type the following in the command window (Ctrl-J):
*Edit M_Covariance*

### What is a global parameter in IGOR?

If you have several datasets on a particular system, and the data can be described by the same structure, then some of the fit parameters may be the same for all the different datasets. Such parameters are referred to as global because they are common to all the datasets.

### What is SLDtop, or SLDbase?

SLDtop is the scattering length density of the incident medium (sometimes referred to as vacuum). e.g. if you are doing an Si-D2O solid liquid experiment and the neutrons are incident through the Silicon, then SLDtop will be the SLD of the Silicon and SLDbase will be the SLD of the D2O.

### Problems after updating

#### When I load a saved experiment after updating why doesn't the reflectivity panel work

The panel sometimes doesn't work because some controls that initiate various sequences have had their underlying functions changed. Don't worry, you haven't lost your fit coefficients, or your data. Simply close down the reflectivity panel and reflectivity graph, then restart Motofit from the topmenu bar. Everything should work now.

### Getting rid of Bugs

Send me details of any bugs and I'll fix them. I have benchmarked the program against other programs and I know that the reflectivity is calculated correctly. If you have any suggestions on how to improve things/would like to help develop things then please email me.