Fit multiple systems from FOR loop

General forum for EasySpin: questions, how to's, etc.
Post Reply
thanasis
Local Expert
Posts: 245
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Fit multiple systems from FOR loop

Post by thanasis »

I am working on the problem previously described in viewtopic.php?f=3&t=282. I am now implementing an automated fitting of EPR spectra based on a set of subspectra automatically generated by a FOR loop, based on a theoretical model.

My main function is:

Code: Select all

clear all; close all; format long;
[B,spc,params] = eprload('AKB1004A_4.3K_X_powder_01.DTA');
%--------------------------------------------------------------------------
Si = 3/2; % The spin of the individual ions
Jav=-10.9; % Isotropic exchange in cm-1 according to the -2JSiSj formalism
r=0.05; % Radial distortion coefficient
gz=1.971; %g|| common for all ions
gxy=1.971; %gperpendicular common for all ions
iter=3; %Number of subspectra
wG=0; %Gaussian linewidth
wL=2; %Lorentzian linewidth
Gx = 0; Gy = 0; Gz = 0.2; % Antisymmetric exchange pseudovector components

SysA.Si = Si;
SysA.Jav = Jav;
SysA.r = r;
SysA.gz = gz;
SysA.gxy = gxy;
SysA.iter = iter;
SysA.wG = wG;
SysA.wL = wL;
SysA.Gx = Gx;
SysA.Gy = Gy;
SysA.Gz = Gz;

VaryA.Jav = 0;
VaryA.r = SysA.r;
VaryA.Gz = Gz;
VaryA.gz = 0.0;
VaryA.gxy = 0.0;
VaryA.wG = 0;
VaryA.wL = 0;

Exp.Temperature = 4.3; Exp.mwFreq=params.MWFQ/1e9; Exp.CenterSweep=[params.A1CT*1e3 params.A1SW*1e3]; Exp.nPoints=params.XPTS;
FitOpt.Method = 'simplex fcn'; % simplex algorithm, data as is
FitOpt.Scaling = 'lsq0';
esfit('constrainJg_equilateral_dynamic_EPR_fit',spc,SysA,VaryA,Exp,[],FitOpt);
My custom function is:

Code: Select all

function y = constrainJg_equilateral_dynamic_EPR_fit(SysA,Exp,Opt)
cm=100*clight/1e6; % Conversion constant from cm-1 to MHz
%Define the theta angles (y-O-Mj) for each metal center
theta1=0;
theta2=-2*pi/3;
theta3=2*pi/3;
GG = [0 SysA.Gz -SysA.Gy; -SysA.Gz 0 SysA.Gx; SysA.Gy -SysA.Gx 0];

%Variation of phi angles of the central oxide
for i=1:SysA.iter
phi(i)=((i-1)/SysA.iter)*(2*pi/3);
%Construct multiplicative factors for each spin pair and for each iteration
a12(i)=SysA.r*(cos(phi(i)-theta1)+cos(phi(i)-theta2));
a13(i)=SysA.r*(cos(phi(i)-theta1)+cos(phi(i)-theta3));
a23(i)=SysA.r*(cos(phi(i)-theta2)+cos(phi(i)-theta3));

% Individual isotropic exchange constants
J12(i)=SysA.Jav*(1+a12(i));
J13(i)=SysA.Jav*(1+a13(i));
J23(i)=SysA.Jav*(1+a23(i));

%The individual systems
%--------------------------------------------------------------------------
Sys(i).S=[SysA.Si SysA.Si SysA.Si];
Sys(i).g=[SysA.gxy SysA.gz; SysA.gxy SysA.gz; SysA.gxy SysA.gz];
Sys(i).gFrame = [90 90 -45; 30 -90 235; -30 90 -45]*pi/180;
% Sys(i).weight = 1/SysA.iter;
Sys(i).ee = [-2*J12(i)*eye(3) - 2*GG; -2*J13(i)*eye(3) + 2*GG; -2*J23(i)*eye(3) - 2*GG]*cm;
Sys(i).lwpp=[SysA.wG SysA.wL];
[B,calc] = pepper(Sys(i),Exp); % Calculate subspectrum No (i)
calcspc(i,:) = calc; % Put the result in a row of an array
end

y = sum(calcspc); % Sum each subspectrum in the array

figure(1)
plot(B,calcspc)
hold on
plot(B,y)
legend('show')
hold off

figure(2)
plot(phi,J12,phi,J13,phi,J23)
legend('show')

return
The problem is that each subspectrum seems to be almost identical, despite the variations of the Jij values, which should greatly influence the gperp components. I suspect that there is a problem in the invocation of pepper in:

Code: Select all

[B,calc] = pepper(Sys(i),Exp); % Calculate subspectrum No (i)
calcspc(i,:) = calc; % Put the result in a row of an array
I have double-checked with a model with two manually created subsystems and it works as predicted. Does anyone see an error that eludes me?

Thanks!
Last edited by thanasis on Wed Apr 04, 2018 2:47 am, edited 2 times in total.
thanasis
Local Expert
Posts: 245
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Fit multiple systems from FOR loop

Post by thanasis »

And the spectrum
Attachments
AKB1004A_4.3K_X_powder_01.zip
(4.94 KiB) Downloaded 164 times
katarkon
Local Expert
Posts: 186
Joined: Mon Jan 12, 2015 4:01 am

Re: Fit multiple systems from FOR loop

Post by katarkon »

I suggest You have to check the dimensions of the pepper output and Your array calcspc as well as the result or the sum(calcspc). I'm afraid that pepper returns column vector instead row. In this case calcspc(i,:) = calc'; should solve the problem.
thanasis
Local Expert
Posts: 245
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Fit multiple systems from FOR loop

Post by thanasis »

Thanks katarkon.

In my installation (Matlab R2015a on Linux), pepper returns B and calc as row vectors. So calcspc contains the spectra along the rows.
Stefan Stoll
EasySpin Creator
Posts: 1073
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Fit multiple systems from FOR loop

Post by Stefan Stoll »

What microwave frequency are you running this at? Based on your Jav value, this appears to be in the strong-exchange regime, where the spectra will not be affected by small changes in Jav (the factors a12 etc are much smaller than 1).
thanasis
Local Expert
Posts: 245
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Fit multiple systems from FOR loop

Post by thanasis »

I am working at 9.31 GHz.

After some experimentation, I discovered that it was an issue of parameters: I needed to increase Gz (to ~0.8 cm-1) so that the Jij differences became visible in gperp. Then, with r ~ 0.2, I started seeing the effect.

Indeed, as you say the spectra are insensitive to Jav, but their gperp is sensitive to ΔJij due to the antisymmetric exchange.
Post Reply