|
| 1 | +.. gsc_ex_magnetic_cylinder.rst |
| 2 | +
|
| 3 | +.. _gsc_ex_magnetic_cylinder: |
| 4 | + |
| 5 | +Example 2: A Magnetic Cylinder |
| 6 | +================================== |
| 7 | + |
| 8 | +In this example we will generate an SLD file describing a single solid |
| 9 | +cylinder, with both nuclear and magnetic scattering length densities (SLDs). |
| 10 | +We will then use the calculator to create scattering intensity patterns for |
| 11 | +both a non-magnetised and magnetised cylinder. |
| 12 | + |
| 13 | +Our cylinder will have a radius of 20\ |Ang| and a |
| 14 | +length of 40\ |Ang|, with its axis |
| 15 | +at a 60° polar angle to the $z$-axis. The cylinder will have equal nuclear and |
| 16 | +magnetic SLDs, with the magnetic SLD along the cylinder's axis. |
| 17 | +We will write first an SLD file for an cylinder aligned along the $z$ axis - |
| 18 | +and perform the rotation within the calculator. |
| 19 | + |
| 20 | +The file should describe a cylinder as below, with a constant nuclear |
| 21 | +scattering length density of |
| 22 | +1x10\ :sup:`-6`\ |Ang|:sup:`-2` and |
| 23 | +a constant magnetic scattering length density of |
| 24 | +(0, 0, 1x10\ :sup:`-6`)\ |Ang|:sup:`-2`: |
| 25 | + |
| 26 | +.. figure:: gsc_ex_magnetic_cylinder_assets/cylinder_graphic.png |
| 27 | + |
| 28 | +The following code generates a SLD file describing such a sample, using the SLD |
| 29 | +file format as given in the documentation for the generic scattering |
| 30 | +calculator:: |
| 31 | + |
| 32 | + import numpy as np |
| 33 | + |
| 34 | + size = np.linspace(-35.0, 35.0, 50) # describe each axis of the grid |
| 35 | + # create a full 3D grid |
| 36 | + xs, ys, zs = np.meshgrid(size, size, size) |
| 37 | + xs = xs.flatten() |
| 38 | + ys = ys.flatten() |
| 39 | + zs = zs.flatten() |
| 40 | + # create arrays to hold the SLDs |
| 41 | + N = np.zeros_like(xs) |
| 42 | + Mx = np.zeros_like(xs) |
| 43 | + My = np.zeros_like(xs) |
| 44 | + Mz = np.zeros_like(xs) |
| 45 | + # fill in the values of the non-zero SLDs within the cylinder |
| 46 | + inside_cylinder = np.bitwise_and(np.float_power(xs, 2) + np.float_power(ys, 2) <= 20**2, np.abs(zs) <= 20) |
| 47 | + N[inside_cylinder] = 1e-6 |
| 48 | + Mz[inside_cylinder] = 1e-6 |
| 49 | + # save the output to an sld file |
| 50 | + output = np.column_stack((xs, ys, zs, N, Mx, My, Mz)) |
| 51 | + np.savetxt("mag_cylinder.sld", output, header="x y z N mx my mz") |
| 52 | + |
| 53 | +We do not need to worry that the large number of pixels with zero valued SLD |
| 54 | +around the cylinder slows down the computation, as such pixels are |
| 55 | +stripped before the calculation begins. |
| 56 | + |
| 57 | +Structural Scattering |
| 58 | +^^^^^^^^^^^^^^^^^^^^^ |
| 59 | + |
| 60 | +First we consider the scattering pattern of a non-magnetic cylinder. We open |
| 61 | +the scattering calculator and use the nuclear datafile `load` button to load |
| 62 | +the nuclear SLD for this sample into the calculator. |
| 63 | + |
| 64 | + |
| 65 | +.. figure:: gsc_ex_magnetic_cylinder_assets/gsc_tool_1.png |
| 66 | + |
| 67 | +By pressing the `draw` button we can see a view of the pixels describing the |
| 68 | +sample. Pixels with 0 SLD are coloured in yellow, all others are given a colour |
| 69 | +related |
| 70 | +to their SLD, which in this case is a constant. |
| 71 | + |
| 72 | +.. figure:: gsc_ex_magnetic_cylinder_assets/cylinder_draw_output.png |
| 73 | + |
| 74 | +In order to set the cylinder at an angle of 60° to the $z$ axis we use the |
| 75 | +sample coordinates highlighted in red below. We also want a 100x100 pixel |
| 76 | +binning in $Q$. |
| 77 | +Unlike the default data in example 1, this value is not given a warning orange |
| 78 | +background, due to the higher discretisation of the real space data for the |
| 79 | +cylinder. |
| 80 | + |
| 81 | +.. figure:: gsc_ex_magnetic_cylinder_assets/gsc_tool_2.png |
| 82 | + |
| 83 | +Pressing compute gives us the following output in the main window: |
| 84 | + |
| 85 | +.. figure:: gsc_ex_magnetic_cylinder_assets/nuclear_output.png |
| 86 | + |
| 87 | +This relatively simple system can be compared with the analytical model in the |
| 88 | +fitting calculator to test the correctness of our results. |
| 89 | +We send the output of the scattering calculator to the fitting panel as in |
| 90 | +example 1 :ref:`gsc_ex_default_data` and choose the `cylinder` category and `cylinder` model. |
| 91 | +We then set the following settings to match the fitting calculator to the |
| 92 | +scattering calculator settings: |
| 93 | + |
| 94 | + - *scale*: 1.0 |
| 95 | + - *background*: 0.0 |
| 96 | + - *sld*: 1 ($\times 10^{-6}$ in units) |
| 97 | + - *sld_solvent*: 0 |
| 98 | + - *radius*: 20 |
| 99 | + - *length*: 40 |
| 100 | + - *theta*: 60 |
| 101 | + - *phi*: 0 |
| 102 | + |
| 103 | +Computing this gives us the model and residual plots: |
| 104 | + |
| 105 | +.. figure:: gsc_ex_magnetic_cylinder_assets/main_window_3.png |
| 106 | + |
| 107 | +The value of $\chi^2 = 5.65\times 10^{-6}$ demonstrates that the calculator has |
| 108 | +produced very accurate results. |
| 109 | + |
| 110 | +For a better comparison of the results, we can adjust the colour scales by |
| 111 | +right-clicking on each of the scattering intensity plots and selecting `2D |
| 112 | +Color Map` to set the maximum and minimum ranges of the plots: |
| 113 | + |
| 114 | +.. figure:: gsc_ex_magnetic_cylinder_assets/color_map_4.png |
| 115 | + |
| 116 | +We also need to adjust the scale for the residuals plot. Since the residuals |
| 117 | +for this fit include negative values we need to change from a log to a linear |
| 118 | +scale |
| 119 | +by right clicking the plot and selecting `Toggle Linear/Log Scale`. We can then |
| 120 | +adjust the range of the color map as before - in this case to the range from |
| 121 | +-0.01 to 0.01. |
| 122 | + |
| 123 | +.. figure:: gsc_ex_magnetic_cylinder_assets/main_window_5.png |
| 124 | + |
| 125 | +Magnetic Scattering |
| 126 | +^^^^^^^^^^^^^^^^^^^^^ |
| 127 | + |
| 128 | +We will now add the magnetic SLD to the cylinder. We load our magnetic cylinder |
| 129 | +SLD file into the magnetic datafile slot, and alter the magnetic beamline |
| 130 | +settings |
| 131 | +to put the polarisation direction along the $U$ axis (the horizontal direction) |
| 132 | +and to record the ++ cross-section ("+" state as defined in Moon, Riste, and |
| 133 | +Koehler, 1969 [#MRK1969]_ corresponds to 0 in the textbox for up_frac). |
| 134 | + |
| 135 | +.. figure:: gsc_ex_magnetic_cylinder_assets/gsc_tool_5b.png |
| 136 | + |
| 137 | +Running the calculation gives us the following output in the main window: |
| 138 | + |
| 139 | +.. figure:: gsc_ex_magnetic_cylinder_assets/magnetic_output.png |
| 140 | + |
| 141 | +Additional to the structural scattering pattern now an angular anisotropy due |
| 142 | +to the magnetisation occurs. |
| 143 | + |
| 144 | +Again we can compare our result to the analytic result of the fitting |
| 145 | +calculator. We set the same settings as before for the cylinder model but also |
| 146 | +check the |
| 147 | +`Magnetism` checkbox in the fitting window. We then navigate to the `Magnetism` |
| 148 | +tab and set the following settings to match with the scattering calculator: |
| 149 | + |
| 150 | + - *up_frac_i*: 0 |
| 151 | + - *up_frac_f*: 0 |
| 152 | + - *up_angle*: 90 (corresponds to up_theta in the calculator) |
| 153 | + - *up_phi*: 0 |
| 154 | + - *sld_M0*: 1 (corresponds to sample magnetic SLD) |
| 155 | + - *sld_mtheta*: 60 (gives the direction of the magnetic SLD in polar angles) |
| 156 | + - *sld_mphi*: 0 |
| 157 | + - *sld_solvent_M0*: 0 (the magnetic SLD of the solvent) |
| 158 | + - *sld_solvent_mtheta*: 0 |
| 159 | + - *sld_solvent_mphi*: 0 |
| 160 | + |
| 161 | +.. figure:: gsc_ex_magnetic_cylinder_assets/magnetism_fitting.png |
| 162 | + |
| 163 | +Carrying out the fitting gives the following results (after adjusting scales to |
| 164 | +match): |
| 165 | + |
| 166 | +.. figure:: gsc_ex_magnetic_cylinder_assets/main_window_6.png |
| 167 | + |
| 168 | +Again the value of $\chi^2 = 1.92\times 10^{-7}$ shows an excellent fit. |
| 169 | + |
| 170 | +References |
| 171 | +---------- |
| 172 | + |
| 173 | + .. [#MRK1969] Polarization Analysis of Thermal-Neutron Scattering |
| 174 | + (1969) R. M. Moon, T. Riste, and W. C. Koehler Phys. Rev. 181, 920 |
| 175 | + `DOI <https://doi.org/10.1103/PhysRev.181.920>`__ |
| 176 | +
|
| 177 | +*Document History* |
| 178 | + |
| 179 | +| 2021-09-14 Robert Bourne |
0 commit comments