esfit userdefined function pepper

General forum for EasySpin: questions, how to's, etc.
Post Reply
Christoph
Newbie
Posts: 2
Joined: Mon Feb 11, 2019 2:32 am

esfit userdefined function pepper

Post by Christoph »

Dear community,

I would like to fit an solid state EPR spectrum, using a user defined function for simulation with pepper. There are 2 spin Systems: (S =1/2, 4 equivalent N nuclei, axial system) and (S=1/2, 4 equivalent N nuclei, 1 Au nucleus, rhombic system). I found in the EasySpin documentation of esfit how to define user defined functions for constraint fitting:
http://easyspin.org/easyspin/documentat ... #multicomp
This works well for a one component System. When modifying to a 2 component System, I obtain the following error message:

______________________________________________________________
Struct contents reference from a non-struct array object.
Error in Constraints (line 3)
fullSys0.A = [Sys0.A(1,:); Sys0.A(2,:); Sys0.A(2,:); Sys0.A(2,:); Sys0.A(2,:)];
____________________________________________________________________

esfit is defined as:

esfit('Constraints',spc,{Sys0,Sys1},{Vary0,Vary1},Exp,SimOpt,FitOpt);

with the user defined function Constraints.m:

function y = Constraints(Sys0,Sys1,Exp,Opt)
fullSys0 = Sys0;
fullSys0.A = [Sys0.A(1,:); Sys0.A(2,:); Sys0.A(2,:); Sys0.A(2,:); Sys0.A(2,:)];

% Sys0.A is an 2x3 Array with the A tensor of Au (1st row) and N (2nd row) in the struct Sys0.

fullSys0.Nucs = 'Au,N,N,N,N';


fullSys1 = Sys1;
fullSys1.A = [Sys1.A; Sys1.A; Sys1.A; Sys1.A];
fullSys0.Nucs = 'N,N,N,N';


Opt.Method = 'perturb';
[x,y] = pepper({fullSys0,fullSys1},Exp,Opt)
end


I would be pleased, if somebody could give some hints.

Thank you in Forward,
Christoph
thanasis
Local Expert
Posts: 242
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: esfit userdefined function pepper

Post by thanasis »

When I want to pass multiple systems to a help function, I find it useful to join the Sys and Var structures after they have been defined:

Code: Select all

etc
etc
Sys = {Sys1,Sys2};
Vary = {Vary1,Vary2};
esfit('my_func',spc,Sys,Vary,Exp,[],FitOpt);
Then, I invoke them as substructures of Sys:

Code: Select all

y = my_func(Sys,Exp,Opt);
etc
etc
Sys{1,1}.g <--g structure of 1st component
Sys{1,2}.g <--g structure of 2nd component
etc
As far as the error is concerned, maybe if you provide the full code and the definitions of Sys.A it would be easier to propose a solution.
Christoph
Newbie
Posts: 2
Joined: Mon Feb 11, 2019 2:32 am

Re: esfit userdefined function pepper

Post by Christoph »

Hi,

It works now by defining
Sys = {Sys1,Sys2};
Vary = {Vary1,Vary2};
as 1X2 cells and reading out the relevant entries of the structures:

function y = Constraints(Sys,Exp,Opt)
fullSys0 = Sys{1,1};
fullSys0.A = [Sys{1,1}.A(1,:); Sys{1,1}.A(2,:); Sys{1,1}.A(2,:); Sys{1,1}.A(2,:); Sys{1,1}.A(2,:)];
fullSys0.Nucs = 'Au,N,N,N,N';

fullSys1 = Sys{1,2};
fullSys1.A = [Sys{1,2}.A; Sys{1,2}.A; Sys{1,2}.A; Sys{1,2}.A];
fullSys1.Nucs = 'N,N,N,N';





Opt.Method = 'perturb';
[x,y] = pepper({fullSys0,fullSys1},Exp,Opt)
end



It works now!

Thank You very much!
Post Reply