Page 1 of 4

Fitting of magnetic susceptibility data

Posted: Mon Feb 01, 2016 5:12 pm
by thanasis
I have searched Easyspin's documentation and examples, but I haven't seen any implementations of fitting SQUID data with easyspin (only simulations). So, I have a few questions:

1. using the textread function as described in http://easyspin.org/easyspin/documentat ... xport.html, the '%g %g' argument threw an error, as %g seems not to be supported by Matlab (http://fr.mathworks.com/help/matlab/ref/textread.html). Using %f did the trick, but it cut down some decimals, which change the form of the experimental curve at some regions.
I used:

Code: Select all

[T,chi] = textread('data.dat','%f %f');
to read the T, chi values. Is that a valid instruction?

2. If I understand correctly, ES calculates muz and chizz by default, and then averages over all orientations to yield the mu and chi values. Is that correct, or is it the other way around? How should I instruct ES to read the experimental data (which are powder values) and export them, again as averaged powder values?

3. To start the fit, I give the experimental conditions and minimisation details. E.g.:

Code: Select all

Exp.Field = 1000;
FitOpt.OutArg = [2 2];   % to fit the magnetic susceptibility chizz (second output)
FitOpt.nKnots = 31;
esfit('curry',chi,Sys,Vary,Exp,[],FitOpt);
However, although the experimental data are loaded, ES throws an error that

Code: Select all

Exp.Temperature is missing
.
Apparently, I haven't successfully instructed it that T in the [T,chi] declaration refers to temperature. I guess, ES does not read the first column like in the case of EPR spectra, where it knows that B refers to magnetic fields.

Thanks in advance for helping me out with this.

Re: Fitting of magnetic susceptibility data

Posted: Mon Feb 01, 2016 7:31 pm
by Stefan Stoll
Please post your data file (including explanations of what's in it), so we can have a look.

Re: Fitting of magnetic susceptibility data

Posted: Tue Feb 02, 2016 2:08 am
by thanasis
Please find attached the data file.
First column T (in K), second column chi (in emu).

All T and chi values are consistently rounded to 4 decimals.

EDIT 1: txt, dat and csv extensions are not allowed in attachments, so I will try to PM it to you
EDIT 2: Data PM'd as straight text

Re: Fitting of magnetic susceptibility data

Posted: Thu Feb 04, 2016 10:33 am
by Stefan Stoll
Your textread usage is correct. The data file is read in correctly by Matlab. No worries: the values are not rounded, they are only displayed to 4 digits. With format long you can see the full numerical precision. If you plot the data, the full precision is used.

We'll fix the %g vs. %f typo in the documentation - thanks for pointing it out!

Please post your full script that runs the fitting, so we can have a look why it throws an error.

Re: Fitting of magnetic susceptibility data

Posted: Thu Feb 04, 2016 11:33 am
by thanasis
Thanks for this info!

My script is the following:

Code: Select all

clear all;
close all;

cm=2.99793e4; % Conversion constant from cm-1 to MHz (~ 100*clight/1e6)
path = '/home/path/to/file/';
cd(path);
[T,chi] = textread('data_easyspin.dat','%f %f');

format long; % added as per your suggestion

J = -22;
gxy = 2;
gz = 2;

Sys1.S=[5/2 5/2 5/2];
Sys1.g=[gxy gz; gxy gz; gxy gz];
Sys1.ee = -2*cm*[J J J];

Vary1.ee = [2]*cm
Vary1.g = [0.01 0.01];
Exp.Field = 1000;

FitOpt.OutArg = [2 2];   % to fit the magnetic susceptibility chizz (second output)
FitOpt.nKnots = 31;
esfit('constrainJg',chi,Sys1,Vary1,Exp,[],FitOpt);
and calls function constrainJg.m:

Code: Select all

function y = constrainJg(Sys1,Exp,Opt)
fullSys = Sys1;
fullSys.g = [Sys1.g;Sys1.g;Sys1.g];
fullSys.ee = [Sys1.ee; Sys1.ee; Sys1.ee];
[x,y] = pepper(fullSys,Exp,Opt);
return
which fixes together the three J's and g's.

However, please note that the experimental points seem a little strange on the fitting window. Like rounded values are plotted instead of the full decimals (even if I added format long like you suggested).
Maybe it's just me?

Re: Fitting of magnetic susceptibility data

Posted: Thu Feb 04, 2016 9:58 pm
by Stefan Stoll
The data you sent is quantized. The last few lines (at high temperatures) read:

286.1843 0.0168437487951064
286.1843 0.0168437487951064
291.5212 0.0167332155810638
291.5212 0.0167332155810638
295.6907 0.0166444542031915
295.6907 0.0166444542031915
300.2205 0.0165662495795745
300.2205 0.0165662495795745
305.3089 0.0164768439810638
305.3089 0.0164768439810638
310.6186 0.0164172653278723
310.6186 0.0164172653278723

Your function constrainJg calls pepper instead of curry. You need the latter if you want to fit magnetization data.

Also, your function only returns 1 output, so you should set FitOpt.OutArg = [1 1].

Then, you also need to pass the temperature range to curry, with Exp.Temperature = T.

Re: Fitting of magnetic susceptibility data

Posted: Fri Feb 05, 2016 12:08 am
by thanasis
Thanks for pointing this out! A copy-paste error crept through.

Now I corrected my data and my code is:

Code: Select all

clear all;
close all;

cm=2.99793e4; % Conversion constant from cm-1 to MHz (~ 100*clight/1e6)
path = '/home/thanasis/magnet/Natassa/Fe3O/Ph_py_NG471/';
cd(path);
[T,chi] = textread('data_easyspin.dat','%f %f');
format long;

J = -22;
gxy = 2;
gz = 2;
Sys1.S=[5/2 5/2 5/2];
Sys1.g=[gxy gz; gxy gz; gxy gz];
Sys1.ee = -2*cm*[J J J];
Vary1.ee = [2]*cm
Vary1.g = [0.01 0.01];
Exp.Field = 1000; Exp.Temperature = T;
FitOpt.OutArg = [1 1];   % to fit the magnetic susceptibility chizz (second output)
FitOpt.nKnots = 31;
esfit('constrainJg',chi,Sys1,Vary1,Exp,[],FitOpt);
and my constrainJg.m is:

Code: Select all

function y = constrainJg(Sys1,Exp,Opt)
fullSys = Sys1;
fullSys.g = [Sys1.g;Sys1.g;Sys1.g];
fullSys.ee = [Sys1.ee; Sys1.ee; Sys1.ee];
[x,y] = curry(fullSys,Exp,Opt);
return
When I run, the error I get is:

Code: Select all

Error using sham (line 31)
Sys.g has wrong size.
Error in curry (line 118)
Error in constrainJg (line 5)
[x,y] = curry(fullSys,Exp,Opt);
Error in esfit>assess (line 794)
Error in esfit_simplex (line 77)
Error in esfit>runFitting (line 651)
Error while evaluating UIControl Callback

Re: Fitting of magnetic susceptibility data

Posted: Fri Feb 05, 2016 10:18 am
by Stefan Stoll
The error message points you to what is wrong. Sys.g has the wrong size. You set it in your script to a 3x2 array - that's correct. But then, in constrainJg, you blow it up to a 9x2 array, which is wrong.

Re: Fitting of magnetic susceptibility data

Posted: Wed Feb 10, 2016 5:34 am
by thanasis
Thank you for the reply and sorry for the delay in responding.

I must have misunderstood the way matrices are built, as I built the g tensor matrix in analogy to the hyperfine tensor matrix I posted at viewtopic.php?f=3&t=260.

So, in my current script I understood that I should define 3 g's as I had previously defined 3 hyperfines (Sys1.A=[0 ACuz; 0 ACuz; 0 ACuz]) and in my external function I should define a system which had a common value for three different hyperfines (fullSys.A = [Sys1.A; Sys1.A; Sys1.A];). And then I should call my external function fitting only one variable (Vary1.A = [0 50]).

In any case, I now changed the code in my external function to fullSys.g = [Sys1.g]; and I get the error:

Code: Select all

Error using  * 
Inner matrix dimensions must agree.
Error in curry (line 157)
Error in constrainJg (line 5)
[x,y] = curry(fullSys,Exp,Opt);
Error in esfit>assess (line 794)
Error in esfit_simplex (line 77)
Error in esfit>runFitting (line 651)
Error while evaluating UIControl Callback

Re: Fitting of magnetic susceptibility data

Posted: Tue Feb 16, 2016 8:17 pm
by Stefan Stoll
This is a bug in curry. We'll fix it - thanks for reporting!

You can work around it easily by making the temperature a row vector (the read-in returns a column vector):

Code: Select all

T = T(:).'