StollLab / EasySpin

MATLAB toolbox for Electron Paramagnetic Resonance (EPR) spectroscopy
http://easyspin.org
MIT License
48 stars 25 forks source link

Errors caused by inconsistent data types for multi-component systems #288

Closed cerium1925 closed 1 year ago

cerium1925 commented 1 year ago
  1. In easyspin, the {} operation is generally used for multi-components, but the result of this matlab operation is a cell array, and the system and experimental parameters defined by easypin are all structures. Therefore, for some mixed spin systems, it will cause bugs or confusion. For example, some functions need to specify the isotope. The pepper function accepts the operation result of {}, but other functions such as levelplot directly report an error. Therefore I suggest that easyspin discard this matlab{} operation when defining a hybrid system.

  2. The demo code is as follows:

clear, clc, clf;

% Experimental parameter---------- Exp.mwFreq = 9.8; Exp.Range = [0 1000]; Exp.nPoints = 1e4;

Opt.Verbosity = 2; Opt.GridSize = [60 3];

% ion with The assumed natural abundance .............. Sys1.S = 1/2; Sys1.g = [1 2 3]; Sys1.Nucs = '143Nd'; Sys1.A = [257 112]*2.9979; Sys1.lw = [2 2]; Sys1.weight = 0.1;

Sys2.S = 1/2; Sys2.g = [1.2 2.2 3.3]; Sys2.Nucs = '145Nd'; Sys2.A = [160 70]*2.9979; Sys2.lw = [2 2]; Sys2.weight = 0.2;

Sys = {Sys1,Sys2};

[b,spc,trans] = pepper(Sys,Exp); spc = normalize(spc,'range');

% ploting..................

subplot(2,2,1); plot(b,spc,'linewidth',1); axis tight;

subplot(2,2,2); levelsplot(Sys1,'y',Exp.Range,Exp.mwFreq);

subplot(2,2,3); levelsplot(Sys2,'y',Exp.Range,Exp.mwFreq);

subplot(2,2,4); levelsplot(Sys,'y',Exp.Range,Exp.mwFreq);

  1. demo results
Screenshot 2023-05-02 232144 Screenshot 2023-05-02 232245
cerium1925 commented 1 year ago

Sys.Ori According to the instructions of easyspin, it should be similar to other Euler angles (Exp.CrystalOrientation, Exp.MolFrame, Sys.gFrame....) It should also be an experimental setting parameter, so it should be defined as Exp.Ori?

At present, it is obvious that the validatespinsys(Sys) function built in easyspin does not consider Sys.Ori is a spin system parameter.

Screenshot 2023-05-02 235431
stestoll commented 1 year ago

Thanks for your feedback. If I understand correctly, you are suggesting to remove the {Sys1,Sys2} input for pepper and other functions, right? What alternative would you suggest?

cerium1925 commented 1 year ago

nested structure of MATLAB is a candidate.

demo code;

Sys1 % struct Sys2 % struct ... Sysn % struct

Sys = struct('Sys',{Sys1,Sys2,...Sysn});

Screenshot 2023-05-03 195005

However, this may require modifications to other functions as well.

ghost commented 1 year ago

Matlab supports structure arrays, e.g.

sys(n).whatever

then any function using that argument simply needs to check and call itself recursively.

IK

From: Yanqing Luo @.> Sent: Wednesday, May 3, 2023 12:55 PM To: StollLab/EasySpin @.> Cc: Subscribed @.***> Subject: Re: [StollLab/EasySpin] Errors caused by inconsistent data types for multi-component systems (Issue #288)

CAUTION: This e-mail originated outside the University of Southampton.

nested structure of MATLAB is a candidate.

demo code;

Sys1 % struct Sys2 % struct ... Sysn % struct

Sys = struct('Sys',{Sys1,Sys2,...Sysn});

[Screenshot 2023-05-03 195005]https://user-images.githubusercontent.com/110143023/235908051-b7231210-5f07-49a1-9fb7-7f12851d856d.png

However, this may require modifications to other functions as well.

— Reply to this email directly, view it on GitHubhttps://github.com/StollLab/EasySpin/issues/288#issuecomment-1532894195, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAT2CQ4ZQUWS4NGQ5RF3XXDXEJBQVANCNFSM6AAAAAAXTG5XCI. You are receiving this because you are subscribed to this thread.Message ID: @.**@.>>

cerium1925 commented 1 year ago

I suggest modifying Sys.Ori to Exp.Ori as well, so that all Euler angles correspond to experimental parameters. Currently, for most of the built-in easyspin functions, only level and levelplot functions consider it as a Sys parameter.

cerium1925 commented 1 year ago

I personally think that the Ori parameter should be expanded or directly defined as other Euler angles as experimental parameters (Exp.Ori). This is very convenient and useful since there are many results in the literature for magnetic fields parallel or perpendicular to a particular axis or plane of a certain crystal.

Screenshot 2023-05-04 003829
cerium1925 commented 1 year ago

Ori's definition feels inconvenient. Perhaps it is more appropriate to define the magnetic field B and the specific axis or crystal plane of the sample (crystal), because the actual experiment is along these crystal axes or planes, not along the molecular axes or planes. The current definition requires an additional Euler angle transformation.

cerium1925 commented 1 year ago

Thanks for your feedback. If I understand correctly, you are suggesting to remove the {Sys1,Sys2} input for pepper and other functions, right? What alternative would you suggest?

At present, functions such as pepper do not strictly check the data type of {Sys1, Sys2,...Sysn}, although it is indeed a cell. Define Sys = {Sys1, Sys2,...Sysn} in this way, pepper can also be called by Sys{1}, Sys{2},...Sys{n)} respectively, at least no error is reported in the matlab 2023a.

stestoll commented 1 year ago

Thanks for your input.