multifrequency esfit?
multifrequency esfit?
Hi,
I know that some fitting programs can perform several correlated simulations at the same time.
For example, it could be of interest to simulate spectra of a given sample recorded at multiple frequencies with the same parameters.
I don't know how difficult it is, but it could be great to add this possibility to esfit...
One can dream...
I know that some fitting programs can perform several correlated simulations at the same time.
For example, it could be of interest to simulate spectra of a given sample recorded at multiple frequencies with the same parameters.
I don't know how difficult it is, but it could be great to add this possibility to esfit...
One can dream...
-
- EasySpin Guru
- Posts: 154
- Joined: Tue Jul 22, 2014 11:01 am
- Location: Northwestern University
Re: multifrequency esfit?
You can do that, without too much difficulty.
First you create a new function such as
Then you setup the problem with:
You can use similar tricks with phony variables in Sys, assign them correctly in your custom function and vary them within esfit.
First you create a new function such as
Code: Select all
function y = multifreq(Sys,Exp)
% you could also hardcode some of this
Exp.Range = [Exp.f(1) Exp.f(2)];
Exp.nPoints = Exp.n(1);
Exp.mwFreq = Exp.mw(1);
freq1 = pepper(Sys,Exp);
Exp.Range = [Exp.f(3) Exp.f(4)];
Exp.nPoints = Exp.n(2);
Exp.mwFreq = Exp.mw(2);
freq2 = pepper(Sys,Exp);
y = [freq1(:); freq2(:)];
return
Code: Select all
clear
[b1,y1,p1] = eprload(somefilelocationbrukerformat);
[b2,y2,p2] = eprload(somefilelocationbrukerformat);
y = [y1(:); y2(:)];
% setup your spin system
Sys.S = 1;
Sys.g = 2.004;
D = 230;
E = 0;
Sys.D = [D E];
Sys.lwpp = 2;
% setup the Experimental portion, but we need to tweak a bit here
% we need to provide these even though we overwrite them later(I think)
Exp.mwFreq = Pars.MWFQ/10^9;
Exp.Range = [min(y1) max(y2)];
Exp.nPoints = length(y);
% then we setup the actual experimental bits we'll use
Exp.f = [min(b1) max(b1) min(b1) max(b1)];
Exp.n = [length(b1) length(b2)];
Exp.mw = [p1.MWFQ/10^9 p2.MWFQ/10^9];
% and toss it all into esfit
Vary.g = 0.01;
Vary.D = [100 70];
Vary.lwpp = 1;
esfit('multifreq',y,Sys,Vary,Exp)
Re: multifrequency esfit?
Thanks a lot!
I'll try!
I'll try!
-
- EasySpin Creator
- Posts: 1108
- Joined: Mon Jul 21, 2014 10:11 pm
- Location: University of Washington
Re: multifrequency esfit?
There is a little bit about custom fitting functions in the documentation - check here.
Re: multifrequency esfit?
Hi,
I've been trying to do something similar and the examples above have helped a great deal. However, I've run into an issue when it gets to actually running a fitting function. As soon as I hit 'run' I receive an error telling me the 'multifreq' function has too many input arguments. The scripts I have been running are modified versions of the ones above, just using appropriate values for my system and the 'cwzero' function from EPRToolbox; if you want me to post these let me know. Any help or insight would be greatly appreciated.
Thanks,
Anna
I've been trying to do something similar and the examples above have helped a great deal. However, I've run into an issue when it gets to actually running a fitting function. As soon as I hit 'run' I receive an error telling me the 'multifreq' function has too many input arguments. The scripts I have been running are modified versions of the ones above, just using appropriate values for my system and the 'cwzero' function from EPRToolbox; if you want me to post these let me know. Any help or insight would be greatly appreciated.
Thanks,
Anna
-
- EasySpin Guru
- Posts: 154
- Joined: Tue Jul 22, 2014 11:01 am
- Location: Northwestern University
Re: multifrequency esfit?
That sounds like you might be trying to pass an options structure or you provided esfit with an empty structure for options, you can fix that by giving the multifreq function a third input, even if you don't actually use it.
Re: multifrequency esfit?
It seems that adding in a third input for the function has fixed it. Thanks for your help!
Re: multifrequency esfit?
Hi Matt,Matt Krzyaniak wrote:You can do that, without too much difficulty.
First you create a new function such asThen you setup the problem with:Code: Select all
function y = multifreq(Sys,Exp) % you could also hardcode some of this Exp.Range = [Exp.f(1) Exp.f(2)]; Exp.nPoints = Exp.n(1); Exp.mwFreq = Exp.mw(1); freq1 = pepper(Sys,Exp); Exp.Range = [Exp.f(3) Exp.f(4)]; Exp.nPoints = Exp.n(2); Exp.mwFreq = Exp.mw(2); freq2 = pepper(Sys,Exp); y = [freq1(:); freq2(:)]; return
You can use similar tricks with phony variables in Sys, assign them correctly in your custom function and vary them within esfit.Code: Select all
clear [b1,y1,p1] = eprload(somefilelocationbrukerformat); [b2,y2,p2] = eprload(somefilelocationbrukerformat); y = [y1(:); y2(:)]; % setup your spin system Sys.S = 1; Sys.g = 2.004; D = 230; E = 0; Sys.D = [D E]; Sys.lwpp = 2; % setup the Experimental portion, but we need to tweak a bit here % we need to provide these even though we overwrite them later(I think) Exp.mwFreq = Pars.MWFQ/10^9; Exp.Range = [min(y1) max(y2)]; Exp.nPoints = length(y); % then we setup the actual experimental bits we'll use Exp.f = [min(b1) max(b1) min(b1) max(b1)]; Exp.n = [length(b1) length(b2)]; Exp.mw = [p1.MWFQ/10^9 p2.MWFQ/10^9]; % and toss it all into esfit Vary.g = 0.01; Vary.D = [100 70]; Vary.lwpp = 1; esfit('multifreq',y,Sys,Vary,Exp)
Thanks a lot, this is very useful for me.
One question about rescaling in this context: what if the spectra at different frequencies have been measured under non-identical experimental conditions, and the amplitudes differ? In this case, the spectra would need to be rescaled individually. I assume that the 'rescale' function would do the trick, but I'm not sure how to implement this in the user-defined simulation function. Could you please comment on this?
Thanks a lot,
Hans
Re: multifrequency esfit?
We've recently implemented a workaround for the scaling issue. Essentially, we use 'rescale' at each frequency to rescale the model to our data. That eliminates the need for the amplitude factors - possibly a large number of additional fit parameters. We describe the EasySpin code in the Supplemental Material to https://doi.org/10.1103/PhysRevB.97.161201 (section 8.3). I hope this helps.hmalissa wrote:Hi Matt,Matt Krzyaniak wrote:You can do that, without too much difficulty.
First you create a new function such asThen you setup the problem with:Code: Select all
function y = multifreq(Sys,Exp) % you could also hardcode some of this Exp.Range = [Exp.f(1) Exp.f(2)]; Exp.nPoints = Exp.n(1); Exp.mwFreq = Exp.mw(1); freq1 = pepper(Sys,Exp); Exp.Range = [Exp.f(3) Exp.f(4)]; Exp.nPoints = Exp.n(2); Exp.mwFreq = Exp.mw(2); freq2 = pepper(Sys,Exp); y = [freq1(:); freq2(:)]; return
You can use similar tricks with phony variables in Sys, assign them correctly in your custom function and vary them within esfit.Code: Select all
clear [b1,y1,p1] = eprload(somefilelocationbrukerformat); [b2,y2,p2] = eprload(somefilelocationbrukerformat); y = [y1(:); y2(:)]; % setup your spin system Sys.S = 1; Sys.g = 2.004; D = 230; E = 0; Sys.D = [D E]; Sys.lwpp = 2; % setup the Experimental portion, but we need to tweak a bit here % we need to provide these even though we overwrite them later(I think) Exp.mwFreq = Pars.MWFQ/10^9; Exp.Range = [min(y1) max(y2)]; Exp.nPoints = length(y); % then we setup the actual experimental bits we'll use Exp.f = [min(b1) max(b1) min(b1) max(b1)]; Exp.n = [length(b1) length(b2)]; Exp.mw = [p1.MWFQ/10^9 p2.MWFQ/10^9]; % and toss it all into esfit Vary.g = 0.01; Vary.D = [100 70]; Vary.lwpp = 1; esfit('multifreq',y,Sys,Vary,Exp)
Thanks a lot, this is very useful for me.
One question about rescaling in this context: what if the spectra at different frequencies have been measured under non-identical experimental conditions, and the amplitudes differ? In this case, the spectra would need to be rescaled individually. I assume that the 'rescale' function would do the trick, but I'm not sure how to implement this in the user-defined simulation function. Could you please comment on this?
Thanks a lot,
Hans