Page 1 of 2
esfit with my own simulation function
Posted: Mon Apr 20, 2015 12:35 am
by Emilien
Hi,
I try to perform esfit with my own simulation function.
When fitting is started, the current simulation is not shown and rmsd is constant.
When stopped and saved, the simulation is plotted.
Here is my code:
Code: Select all
clear; close;
[B,spc]=eprload('Coli_2.DSC');
load('coli2.mat'); %load Sys Exp
Sys.Aperp=Sys.A(2);
Sys.Apar=Sys.A(1);
Sys=rmfield(Sys,'A');
Vary.Aperp = 15;
%Vary.A = [0 100;0 100];
Vary.Apar =90;
esfit('mysim',spc,Sys,Vary,Exp)
Here is mysim.m
Code: Select all
function [x,y] = mysim(Sys,Exp,SimOpt)
Sys.A = [Sys.Apar Sys.Aperp Sys.Aperp];
[x,y] = chili(Sys,Exp,SimOpt);
end
Here are the data:
- data.zip
- (5.28 KiB) Downloaded 1063 times
Thanks fo your help!
PS:I know that there is an easiest solution for this example...
Re: esfit with my own simulation function
Posted: Mon Apr 20, 2015 11:49 am
by Stefan Stoll
This is a bug in EasySpin 4.5.5. To work around it, define your function with a single output argument:
Code: Select all
function y = mysim(Sys,Exp,SimOpt)
Re: esfit with my own simulation function
Posted: Tue Apr 21, 2015 2:03 am
by Emilien
Stefan, thanks for your answer.
Your solution enables the simulation to be displayed in esfit. But unfortunately, when the fitting process is stoped, an error occured:
??? Error using ==> mysim
Too many output arguments.
Error in ==> C:\easyspin-4.5.5\easyspin\esfit.p>runFitting at 669
??? Error while evaluating uicontrol Callback
leading to another error when trying to save result
??? Reference to non-existent field 'rmsd'.
Error in ==> C:\easyspin-4.5.5\easyspin\esfit.p>refreshFitsetList at 1197
Error in ==> C:\easyspin-4.5.5\easyspin\esfit.p>saveFitsetCallback at 1223
??? Error while evaluating uicontrol Callback
Re: esfit with my own simulation function
Posted: Tue Apr 21, 2015 1:29 pm
by Stefan Stoll
Clearly, at some place
esfit
wants your function to return one output, and at another one it wants two. Try this:
Code: Select all
function varargout = mysim(Sys,Exp,SimOpt)
%...
if nargout==1, varargout = {y}; else varargout = {x,y}; end
return
Re: esfit with my own simulation function
Posted: Wed Apr 22, 2015 12:47 am
by Emilien
Wonderful, it works!
Thanks a lot!
Re: esfit with my own simulation function
Posted: Thu Apr 23, 2015 7:11 am
by Emilien
Hi,
it actually works for one component...
Nevrtheless I need to perform a simulation with 2 components with different restrictions.
For example, one component (Sys1) has restriction and has to be simulated with mysim.m. The other component has no restriction and has to be simulated with chili...
I've naively tried
Code: Select all
esfit({'mysim' 'chili'},spc,{Sys1 Sys2},{Vary1 Vary2},Exp)
but it doesn't work...
Is there a solution for that?
Thanks.
Re: esfit with my own simulation function
Posted: Thu Apr 23, 2015 8:16 am
by Stefan Stoll
Hmm, this is an interesting use case. As it, ES cannot accommodate custom fits of multi-component data in a convenient manner. Internally,
esfit
just runs a for loop and calls the sim function for each component in turn.
But, as often, there's a hack: Merge your two spin system structures into one, and then use myfit to simulate the multicomponent-spectrum:
Code: Select all
Sys.g1 = 2;
Sys.g2 = 2.1;
Sys.weight1 = 0.5;
% Vary.g1 = ... etc
esfit('mysim',Sys,Vary,...);
The custom sim function should do the following:
Code: Select all
Sys1.g = Sys.g1;
[x,y1]= pepper(Sys1,...);
Sys2.g = Sys.g2;
[x,y2] = pepper(Sys2,...)l
y = y1*Sys.weight1 + y2*(1-Sys.weight1).
Ugly, but it should work.
Re: esfit with my own simulation function
Posted: Fri Apr 24, 2015 1:13 am
by Emilien
It works...
But "ugly" as you said, because all fields have to be redefined... Do you think that in a future release of esfit, we could specify the sim function for each component? If "Internally, esfit just runs a for loop and calls the sim function for each component in turn", it could be possible for this loop to call different sim functions, isn't it?
Re: esfit with my own simulation function
Posted: Fri Apr 24, 2015 10:00 am
by Stefan Stoll
That would be one possible approach. I'll put it on the to-do list. Thanks for the suggestion!
Re: esfit with my own simulation function
Posted: Mon Jun 29, 2015 5:51 am
by Emilien
Hello,
does the new version of esfit include this suggestion? That would be great!