Skip to content

Exercises for MDanse 2024

Tobias Weber (Institut Laue-Langevin) edited this page Nov 5, 2024 · 56 revisions

Back to Contents.

This tutorial is used for the ILL's MDanse School 2024, it introduces Magdyn, Takin's magnon calculator.

Takin is available via the ILL's data analysis cluster, or can be installed using one of the binary packages here.

Exercise 1: Resolution convolution fitting of a 1d antiferromagnetic spin chain.

Exercise 1a: Modelling a 1d antiferromagnetic chain

First, we create a simple one-dimensional antiferromagnetic spin chain in Takin/Magdyn.

  1. Select "Tools" -> "Magnetic Dynamics..." from the main window's menu.

  2. In the first step, one magnetic site is placed: Select the "Sites" tab and enter an a site with the coordinates (0, 0, 0), and |S| = 1 and the name "spin" (for example).

  3. Next we create the couplings, which will generate the spin chain:

    • Go to the "Couplings" tab and enter an interaction between the site and the corresponding one in the next cell using the parameters:
      Site 1 = "spin", Site 2 = "spin" (where "spin" is the name of the site that was chosen above), Cell Δx = 1, Cell Δy = 0 Cell Δz = 0, J = Jafm.
    • If you wish to see more sites in the chain, you can add more couplings having J = 0, e.g.:
      Site 1 = "spin", Site 2 = "spin", Cell Δx = -1, -2, 2, ..., Cell Δy = 0 Cell Δz = 0, J = 0.
  4. Since the structure is incommensurate, i.e. the magnetic Brillouin zone is half the size of the nuclear one, enter the following ordering vector:
    Oh = 0.5, Ok = 0, Ol = 0 and the rotation axis Nh = 0, Nk = 1, Nl = 0.

  5. Notice that in step 3, we specified a variable name, "Jafm", in the "Exch. J" column instead of a constant. This way it can later be used as a parameter for fitting. Go to the "Variables" tab, add a new variable named "Jafm" and give it a value, for example 0.5.

  6. Clicking on "View..." shows a 3d representation of the magnetic sites and their couplings.

Exercise 1b: Calculating the dispersion

  1. The dispersion relation can be plotted using the "Dispersion" tab on the right-hand side of the window. Enter a start and an end (hkl) coordinate as well as the number of points ("Q Count") to plot a specific branch, for the 1d spin chain along x choose (000) as start and (100) as end Q coordinate.

  2. The thickness of the line corresponds to the value of the spin-spin correlation function. For the antiferromagnetic chain you should notice that the correlation function diverges at the points of the magnetic satellites at (0.5 0 0). You may therefore need to adjust the plotted line thickness using the "Weight Scale", "Min. Weight" and "Max. Weight" fields. You can also disable the Bose factor to get a clearer picture: Select "Calculation" in the menu and de-select "Use Bose Factor".

  3. Save the model you have created using "File" -> "Save As...", for example under the name "model.magdyn". We will use it for resolution convolution in the next step.

Exercise 1c: Modelling a 1d antiferromagnetic chain (alternative way)

Incommensurate magnetic structures can alternatively be modeled by extended commensurate structures.

  1. Clear the previous model using "File" -> "New". (Save before!)

  2. Create two magnetic sites named "up" and "down" at positions (0, 0, 0) and (1, 0, 0), having spins (0, 0, 1) and (0, 0, -1), respectively. As before, the total spin S is 1.

  3. Create two couplings: One between "up" and "down" with distance ("Cell Δx") 0, the other one between "down" and "up" with a distance of 2. (Why 2? Visualise the structure!) Use the same exchange variable Jafm = 1 meV as in exercise 1a for both couplings.

  4. If everything is set up correctly (also think of lowering the "Max. Weight!"), it should give the same dispersion and correlation as before.

Exercise 1d: Resolution convolution fitting

  1. Open the convolution fitter using "Resolution" -> "Convolution..." in Takin's main menu.

  2. Click "..." next to the field "Resolution File" and select the provided instrument file, instr.taz. This file contains all the parameters of the neutron-optical components needed for resolution calculation. Make sure that both the monochromator and the analyser are not focusing by setting "M. Focus" and "A. Focus" both to "Flat".

  3. Tick the check box left to "Measurement" and click "..." to choose the provided data file, data.dat. Apart from the scan data, the headers of the data file also contains sample information which is needed to transform between the lab and crystal coordinates systems.

  4. Select "Magnetic Dynamics" in the field "Model Source". Click "Browse..." and select the model file that you created in exercise 1b, e.g. "model.magdyn".

  5. You can change model parameters by clicking on "Parameters...". Choose a linewidth "sigma" of 0.5 meV and a temperature "T" of 10 K and click "Apply".

  6. Click on "Start Sim." to simulate a resolution convolution using the current parameters. They are not yet correct, so the calculated curve will be off.

  7. In the "Plot" tab choose an absolute scaling parameter ("Scale") of 22 and an "offset" of 7e-4. The offset is the background of the instrument, the scaling parameter scales the correlation function, which is not normalised by default.

  8. The calculated curve should now be in the correct scale, but still is not correct because the exchange constant "Jafm" does not correspond to the data. Go back to the model parameters dialog ("Parameters...") and declare "Jafm" a fit variable by setting an "Error" of, e.g., 0.5 and checking the box "Fit". Click "Apply" and "Start Fit". If everything is set up correctly, the fitter should find the correct constant of Jafm = 1 meV.

  9. Fit the "Jafm" parameter for the data2.dat file.

  10. Fit the magnon linewidth "sig" for the data3.dat file. Here, the temperature is T = 20 K and Jafm = 1 meV.

Exercise 2: Using a custom Python model for a 1d ferromagnetic spin chain

To demonstrate both Takin's plug-in mechanism and the mathematics of linear spin-wave theory, we directly implement a 1d ferromagnetic chain without the Magdyn program. For this purpose, we use a Python-based S(Q, E) model, which can be found in the file fm.py. (Further info, for the interested: A fully general, but still minimal Python implementation of linear spin-wave theory can be found in this file.)

The most important (and only mandatory) interface function for Takin is "TakinSqw(h, k, l, E)", which receives the (hkl) coordinates (in rlu) and the energy transfer E (in meV) of each random Monte-Carlo neutron event, and returns the dynamical structure factor S(h, k, l, E).

Each parameter in the Python script which is global and whose name begins with "g_" is a parameter that can be changed directly from within Takin and that can also be defined as a fit parameter. In the convolution dialog, these parameters can be inspected and modified by clicking on the "Parameters..." button.

Exercise 2a: Using the Python Model

  1. Set up everything as in exercise 1d, steps 1-3, using the same instrument file, but this data file instead: data.dat.

  2. As "Model Source" choose "Python Scripting", click "Browse..." and select the provided fm.py file.

  3. In the parameters dialog ("Parameters...") set the temperature to 50 K and apply the settings.

  4. Click "Start Sim." In the "Plot" tab, set the scaling and offset parameters to 30 and 1e-3, respectively.

  5. Fit the magnon linewidth by declaring it a fit parameter in the parameters dialog.

Exercise 2b: Modifying the Python Model

  1. Load the second date file, data2.dat.

  2. Set the temperature to 50 K and the linewidth to 0.45 meV.

  3. The exchange constant J is wrong for this data, we want to find the correct one by fitting. This is not yet possible, since J is hard-coded to -1 meV in the Python model. Open fm.py in a text editor, add a global variable named "g_J" and set it some default value. Find the place where the exchange constant is used in the source code and replace it with the variable.

  4. For easier debugging, scripts can also be run directly from the console. Run fm.py, it should plot the dispersion. Change "g_J" to verify that it has the desired effect.

  5. Back in Takin, "g_J" should now appear as open parameter after reloading the Python model. Find its correct value by fitting. In case it does not run, errors are output in the log (Takin's main menu -> "Help" -> "Log...").

  6. Modify the script so that the analytical formula for an 1d ferromagnetic chain, $2J S \cdot \left[\cos\left(2 \pi Q d\right) - 1\right]$, is directly used instead of the full linear spin-wave calculation from the function "get_energies". To achieve this, replace the call to "get_energies" in the function "TakinDisp" with your own function.

  7. As a bonus, add a global variable named, e.g., "g_switch" to have the possibility to switch between using either linear spin-wave calculation or the analytical formula directly from within Takin.

Exercise 3: Modelling a real system

As an example for modelling complex magnetic structures, we re-create the theoretical model of the compound Cu2OSeO3 given by (Luo 2020) in this exercise and calculate its dynamics.

The 16 copper atoms in the unit cell of Cu2OSeO3 form four effective tetrahedral clusters with spin 1, as shown in figure 1 (a), (c), and (d) in (Luo 2020).

  1. In the first step, the spin-1 sites are created using these steps:

    • In the Takin/Magdyn select the "Sites" tab and enter a site with the coordinates (0, 0, 0), and |S| = 1.
    • To generate the other symmetry-equivalent sites, enter the space group #198 $P2_13$ in the "Sample" tab and click "Generate".
  2. Before creating the couplings, it is useful to define a few variables:

    • Go to the "Variables" tab to enter the coupling constants from table 1 in (Luo 2020) (Note that our order of the DMI vector components is changed with respect to the paper because of our choice of the reference couplings in the next step.):
      Variable Value Variable Value
      J1 -0.58 J2 -0.93
      D1x 0.15 D2x 0.16
      D1y -0.24 D2y 0.1
      D1z -0.05 D2z 0.36
  3. Finally, we model the couplings between the sites using the following steps:

    • Go to the "Couplings" tab to generate the interactions between the spin sites that are shown in figure 1 (d) of the paper (Luo 2020).
    • Enter, for example, an interaction between the site at (0 0.5 0.5) and (0.5 0 0.5) using the J1 and D1 constants.
    • Next, enter another interaction between the site at (0 0 0) and (0.5 0 0.5) using the J2 and D2 constants.
    • Generate the symmetry-equivalent couplings by clicking "Generate". This will again use the space group #198 $P2_13$ selected in the "Sample" tab
  4. Plot a dispersion branch, for example from (-100) to (100), to verify that the model works.

References

(Luo 2020) Y. Luo, et al., Phys. Rev. B 101, 144411 (2020), DOI: 10.1103/PhysRevB.101.144411.

Exercise 4: Helix

In this exercise we will model a helical spin structure as another example of an incommensurate system besides the antiferromagnetic chain. With the helix we can also see one of the limits of linear spin-wave calculations.

  1. Start by defining a commensurate spin chain with a ferromagnetic coupling.
  2. Make it incommensurate by defining a small ordering vector and its rotation axis along the helix axis (perpendicular to the spin directions).
  3. To shift the spectrum in energy, add a small single-ion anisotropy along the initial spin direction.
  4. Plot the spectrum along the helix axis (i.e. the rotation axis you defined) and perpendicular to it. One of the spectra would have strong Umklapp scattering which is not considered within linear spin-wave theory.