an esfit problem - more details

General forum for EasySpin: questions, how to's, etc.
Post Reply
Svist
Newbie
Posts: 9
Joined: Fri Aug 09, 2019 9:25 am

an esfit problem - more details

Post by Svist »

Ok, 20 reads of my first post and no comments - I have to do better than that. My problem is in the following. I wrote a script for tyrosine radical EPR spectra simulation, in which three principal g values, hyperfine splittings, and Euler angles are functions of just two input variables. The script works fine and I can see differences in the simulated spectra when I change these two input numbers (and the differences are quite right). However, what I cannot do at this stage is to fit the simulated spectrum to the experimental one using esfit. I setup my two input variables as Sys parameters, for example,

Sys0.theta = 56;
Vary.theta = 2;

Sys0.ro = 38;
Vary.ro = 3;

but when I run esfit asking to vary just these two parameters it all comes back to the starting point, as a matter of fact it doesn't move away from the starting point, which is probably understandable - the script reads the zero values every cycle.

So my question is whether there is a way around this and I could use esfit to vary two variables on which the Hamiltonian parameters are defined (without explicitly varying the latter) or should I write a different fitting routine?

I will appreciate any feedback,

Dima Svistunenko
Last edited by Svist on Mon Aug 26, 2019 5:17 am, edited 2 times in total.
Stefan Stoll
EasySpin Creator
Posts: 1108
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: an esfit problem - more detals

Post by Stefan Stoll »

Dima, please post a minimal working script that shows all the inputs you give to esfit, and also post the data if possible. Then somebody might be able to help.
Svist
Newbie
Posts: 9
Joined: Fri Aug 09, 2019 9:25 am

Re: an esfit problem - more details

Post by Svist »

OK, I will make another attempt to describe the code.
Here is the bottom of the script:

Code: Select all

% Spin system and Optional paramters:ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
Sys.S = 1/2;
Sys.g = [gx gy gz];
Sys.HStrain = [deltaHx deltaHy deltaHz];                      
Sys.Nucs = '1H,1H,1H,1H,1H,1H';
Sys.A = [Ab1Para Ab1Perp Ab1Perp; 
         Ab2Para Ab2Perp Ab2Perp;
         25.9 8.1 20.5; 
         25.9 8.1 20.5; 
          7.5 5.0 1.5; 
          7.5 5.0 1.5
         ]; 
Sys.AFrame = [euler11 euler12 euler13;
              euler21 euler22 euler23; 
              -23.0 0 0; 
               23.0 0 0; 
              -40 0 0; 
               40 0 0    
              ]*pi/180;
 
Opt.Method='perturb'; 
% Spin system and Optional paramters end:ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
 
[BestSys,BestSpc] = esfit('pepper',a4,Sys0,Vary,Exp,Opt);
As you can see, many of these Sys. parameters (all that are not numbers) are functions. They are functions of one, two or three variables - roC1, theta and cAm. I can vary manually these three, separately or together; a reasonable simulation comes up for these values, for example:

Code: Select all

roC1= 0.38;     % spin density on C1, might be varied between 0.35 and 0.42
theta= 56;      % in degrees; should be between -90 and +90 degrees
cAm = -0.5;     % positive or negative correction value to be added to the line widths, typically within a range -1.2 - +1.2 Gauss
Now, I would like to run a fit when only these three numbers are varied. To make the things simpler, I want to vary only cAm first, starting from a random value of, say, 0.1 and to cover a range of +/- 1 around it. So, a successful fit should be giving me something close to cAm = -0.5

So, cAm is embedded in Sys.HStrain = [deltaHx deltaHy deltaHz];
so that deltaHx deltaHy deltaHz are functions of roC1 (a constant in my fitting attempts) and cAm (to be varied during the fit)

To vary just cAm, I set

Code: Select all

Sys0.cAm = 0.01; 
Vary.cAm = 1; 
at the top of the script, that is before the Sys0.cAm is used in calculation of [deltaHx deltaHy deltaHz]:

Code: Select all

deltaHb=[widthonK*a6];                                         % delta H BASIC, a column
deltaH=[deltaHb+[Am; Am; Am]+[Sys0.cAm; Sys0.cAm; Sys0.cAm]];  % delta H, a column of full width components
I am not surprised that when running esfit:

Code: Select all

[BestSys,BestSpc] = esfit('pepper',a4,Sys0,Vary,Exp,Opt);
it does not move way from Sys0.cAm since in the second cycle it reads again Sys0.cAm but I don’t know how to fix it.

I guess I am basically asking if a Sys.X variable can be set as a function of another Sys.Y variable and an esfit routine executed when only Sys.Y is varied.

Stefan, I sent an email to you at stst on 20 August with a full script and experimental spectrum. If you received it, I would greatly appreciate your comments and I would perfectly understand if whatever I am asking is going to take more efforts and time than you are prepared to invest.

Dima Svistunenko
Stefan Stoll
EasySpin Creator
Posts: 1108
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: an esfit problem - more details

Post by Stefan Stoll »

In this situation, use a custom simulation function, as described here.

Code: Select all

clear

% load data here

Sys.S = 1/2;
Sys.g = [gx gy gz];
Sys.Nucs = '1H,1H,1H,1H,1H,1H';

Exp.mwFreq = 9.5;
Exp.Range = [300 400]
Opt.Method='perturb';

Sys.roC1 = 0.38;
Sys.theta = deg2rad(56);
Sys.cAm = -0.5;

Vary.rhoc1 = 0.1;
Vary.theta = deg2rad(30);
Vary.cAm = 0.2;

[BestSys,BestSpc] = esfit(@mysimfun,a4,Sys0,Vary,Exp,Opt);

function spc = mysimfun(Sys,Exp,Opt)

roC1 = Sys.r0C1;
cAm = Sys.cAm;
theta = Sys.theta;

% calculate deltaHx, deltaHy, deltaHz from these parameters
% calculate all A and Euler angles

Sys.HStrain = [deltaHx deltaHy deltaHz];                     
Sys.A = [Ab1Para Ab1Perp Ab1Perp;
         Ab2Para Ab2Perp Ab2Perp;
         25.9 8.1 20.5;
         25.9 8.1 20.5;
          7.5 5.0 1.5;
          7.5 5.0 1.5
         ];
Sys.AFrame = [euler11 euler12 euler13;
              euler21 euler22 euler23;
              -23.0 0 0;
               23.0 0 0;
              -40 0 0;
               40 0 0   
              ]*pi/180;

spc = pepper(Sys,Exp,Opt);
end
Svist
Newbie
Posts: 9
Joined: Fri Aug 09, 2019 9:25 am

Re: an esfit problem - more details

Post by Svist »

Thank you very much, Stefan, it works now, hurray!!

It took me some time though to realise I have to make a separate file to be called in by the main script. Anyway, it works now and I will investigate how to optimise the fit process - how it depends on the starting point, on the range to vary within and on the number of variables (total of three) to vary at a time, and if the order of the variables in the script (when greater than one) matters.

Thanks a lot , I am very greatful,

Dima
Post Reply