Friday, July 8, 2016

LMFIT and Peak-Fitting of XRD peaks

I recently added the Non-Linear Least-Squares Minimization and Curve-Fitting (LMFIT) package to my Python. Lately I've made an effort to move away from MATLAB and use Python and the packages available for it to take on some of my scientific problems.

I've been using the Gaussian model and composite model feature of LMFIT to reproduce a fitted diffraction profile as close as possible to what the manufacturer's software provides me. In the software, the fitting procedure determines the position of 2theta to determine the d-spacing of the crystal structure by Bragg's law. The stress is then calculated based on the change in d-spacing or lattice strain (gross oversimplification). The software ignores the information that exists within the peak, such as peak width that can reflect a dislocation content or the peak shape that may influenced by the twin density. Hence my goal is to reproduce the fitting procedure and determine the peak characteristics such to hopefully find more information.

Below outlines my fun so far in trying to replicate what the manufacturer does for peak fitting. This is an example of a diffraction peak, that has been fitted with a Gaussian curve:
This is the output that the software reports:
One distinct difference right away is that two peaks are used to fit the diffraction profile. Obviously I'm already off to a bad start. For those curious, this is because both the K alpha1 and alpha2 are used during the measurement, so there is in fact two signals. This was my next attempt just using two Gaussian curves.
Not even close. Although the fit is actually better than the manufacturers, it has no physical reasoning. So I enforced some rules on the intensity of the two radiations as well as the expected separation of the two peaks and came out with this:
The constraints actually made my fit "worse" compared to when the summation of the two Gaussian curves were left unbounded, but at least now I'm little closer to what the manufacturer reports. The next constraint I added was to assume the interaction profile of both radiation types would be same same in terms of variance, which gave me this:
Then the end of the day rolled around and I called the quits =P

Overall though using LMFIT was pretty intuitive and seemed to offer a lot for optimized fitting routines. I'm hoping to use more of it in the future for my work.


No comments:

Post a Comment