Custom simulation function: fit single-crystal rotation

General forum for EasySpin: questions, how to's, etc.
Post Reply
thanasis
Local Expert
Posts: 245
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Custom simulation function: fit single-crystal rotation

Post by thanasis »

I am trying to better understand how to create custom simulation functions to invoke with esfit.
So far, I have understood that we can use custom functions to tie together parameters defined in Sys (e.g. J couplings, or hyperfine couplings) and to fit experimental parameters defined in Exp, such as the microwave phase (as described in the documentation).
However, what about entirely arbitrarily defined parameters. E.g. in single-crystal experiments, the rotation of the EPR tube αround the vertical axis is described by an angle that is neither in Sys, nor in Exp. It does enter in Exp.CrystalOrientation at some point, but can we fit just that angle? I have tried to follow the instructions which say: "put the parameter you want to fit into the first input structure (called Sys), even if it is not a spin system parameter".
I have set up the code as follows for a S = 3/2 system:

Code: Select all

cm=100*clight/1e6;
g = 2.18;
D32 = [0.105 0];
tilt = 14; % molecular axis tilt from the horizontal plane (in degrees)
rot = 150; % rotation of the crystal with respect to the magnetic field (in degrees)
w1 = 16; w2 = 10;

Sys1.S=3/2;
Sys1.g=g;
Sys1.D=D32*cm;
Sys1.tilt = tilt;
Sys1.rot = rot;
Sys1.lwpp=[w1 w2];

Exp.Temperature = 290; Exp.mwFreq=params.MF; Exp.CenterSweep=[params.HCF/10 params.HSW/10]; Exp.nPoints=2048;
Exp.CrystalSymmetry = 2;        % space group P-1
Exp.MolFrame = [0 tilt 0]*pi/180;  % molecular frame tilted towards the horizontal plane
cori0 = [0 0 0]*pi/180;              % initial crystal orientation in lab frame
nRot_L = [1;0;0];               % rotation axis = x-axis of lab frame i.e. the EPR tube axis (as per ES frame definitions)
rho = rot*pi/180;               % rotation angle (in radians)
cori = rotatecrystal(cori0,nRot_L,rho);   % rotate crystal by rho around nRot
Exp.CrystalOrientation = cori; % final crystal orientation

Vary1.g = 0;
Vary1.D = [0 0]*cm;
Vary1.lwpp = [ 0 ];
Vary1.tilt = 2;
Vary1.rot = 4;

FitOpt.Method = 'simplex fcn'; FitOpt.Scaling = 'maxabs';
esfit('fitrot',spc,Sys1,Vary1,Exp,[],FitOpt);
My fitrot function is:

Code: Select all

function y = fitrot(Sys1,Exp,Opt);
rot = 0;
tilt = 0;
Sys1.rot = rot;
Sys1.tilt = tilt;
[x,y] = pepper(Sys1,Exp,Opt);
return
However, upon launching the fit with only the two angles as variables, the rmsd is a flat line and there is no minimization.

How should I correct my custom function?
Stefan Stoll
EasySpin Creator
Posts: 1073
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Custom simulation function: fit single-crystal rotation

Post by Stefan Stoll »

In your custom function, you should use your user-defined parameters to calculate whatever you need to perform the actual simulation. The presence of Sys.tilt, together with Vary.tilt, tells esfit that you want to vary a parameter called tilt, but EasySpin's simulation function has no clue what that is and ignores it. In your custom function, you should take Sys.tilt to set up the appropriate Exp.CrystalOrientations that you then feed into the simulation function.
Yahor Savich
Newbie
Posts: 6
Joined: Sun Aug 14, 2016 5:38 pm

Re: Custom simulation function: fit single-crystal rotation

Post by Yahor Savich »

Dear Dr. Stoll, these two sentences in your previous post were so useful! After a week of reading documentation I finally found it.
Post Reply