# ReMagX

### Site Tools

documentation:script_examples

### Add Lorentzian to the refractive index

```-- energy is a predefined variable
e = energy

-- Ni L2
alpha1 = 85000.2;
beta1 = 2.97885;
e01 = 870.5;

-- Ni L3
alpha2          = 26162.2;
beta2           = 0.853558;
e02             = 852.216;

-- calculate classical lorentzians
del1 = alpha1 * (e*e - e01*e01) / ((e01*e01 - e*e)*(e01*e01 - e*e) + beta1*beta1 * e*e);
bet1 = alpha1 * beta1*e         / ((e01*e01 - e*e)*(e01*e01 - e*e) + beta1*beta1 * e*e);

del2 = alpha2 * (e*e - e02*e02) / ((e02*e02 - e*e)*(e02*e02 - e*e) + beta2*beta2 * e*e);
bet2 = alpha2 * beta2*e         / ((e02*e02 - e*e)*(e02*e02 - e*e) + beta2*beta2 * e*e);

-- subtract current lorentzian in the substrate and add a new one with a new amplitude par[0]
delta[0] = delta[0] - del1 + del1*par[0];
beta[0]  = beta[0]  - bet1 + bet1*par[0];

delta[0] = delta[0] - del2 + del2*par[1];
beta[0]  = beta[0]  - bet2 + bet2*par[1];
```

### Special conditions for the element specific mode

Sample is PrNiO3 on LSAT

```-- roughness of the interface between substrate and first layer should be the same for each element.
s = La:getsigma(0);
Sr:setsigma(0,s);
Al:setsigma(0,s);
Ta:setsigma(0,s);
Ni:setsigma(0,s);
Pr:setsigma(0,s);
O:setsigma(0,s);

-- thickness should be the same for the first layer. Fit only Ni.
s = Ni:getthickness(1);
Pr:setthickness(1, s);
O:setthickness(1, s);```

### Calculate reflectivities for an animation

This code was used to get an animation for a talk. The code must be copied and executed in the “default” tab. Beta of one layer is changed with a sinus function. The output is written to the debug window. This data can be used e.g. in gnuplot.

```betatemp = beta[0]
for j=0,50,1 do
beta[0] = betatemp + math.sin(j / 50. * 2. * 3.141)*betatemp*0.5;
CalculateReflectivity()
for i=0,299,1 do
write(solution_qz[i], " ", solution_R[i]);
end
write("");
end
beta[0] = betatemp;
```