McStas Tutorial – ISIS-Brazil Neutron School 11/09/2024
1. Log on via the DaaaS Training portal and open a workspace.
         a. Copy the course materials (/mnt/ceph-
            training/course_materials/Goran_Nilsen/) to a convenient
            location (e.g. Desktop)
  2. Open McStas under Software -> McStas -> McStas 3.4 GUI
  3. Click File -> New Instrument, enter a (funny) name, and click Save
  4. First, we need a source. Typically, the source properties are derived from
     neutronics simulations (using codes like MCNP). For the purpose of this
     exercise, we instead with to consider an idealized source with a uniform
     emission in space and a narrow Gaussian emission in neutron wavelength. This
     roughly approximates the neutron spectrum one obtains after the
     monochromator. To insert the source, position the cursor below the “//insert
     components here” comment line, then click the Insert menu. Under Source,
     select Source_simple. This will open a window where the component
     parameters are specified. These are given as follows:
         a. Dimensions: yheight = 0.05, xheight = 0.05
         b. Focusing: dist = 10, focus_xw = 0.003, focus_xh = 0.020
                  • Although the source is an isotropic emitter, we will here only
                     consider the neutrons that hit a 3mm wide and 20mm high spot
                        at a 10m distance from the source. These will also be the
                        dimensions of the sample.
          c. Wavelength: lambda0 = 1.54, dlambda = 0.005, gauss = 1
                     • We will use a typical (thermal) neutron wavelength for powder
                        diffraction. The wavelength spread is set to around 0.5% of
                        lambda, and the wavelength profile is Gaussian.
          d. Insert the source at the origin of the McStas coordinates by leaving the
              position parameters at the bottom unchanged, then clicking Insert.
5.   As mentioned above, we have made the source monochromatic to avoid the
     complication of having to add an actual monochromator. Using focusing also
     means that we will not be simulating any neutrons that miss the sample,
     speeding up the simulation. The next step is to insert the sample. Here, we will
     consider powder diffraction from Si. The sample is inserted by clicking Insert-
     >Sample->PowderN. The powder scattering data is read from files in .laz
     format – these contain all the crystallographic information about the sample as
     well as a list of Bragg reflections.
          a. We wish to simulate a cylindrical sample. Using the parameters from 4b
              above, enter the dimensions and position (along the z axis) of the sample.
6.   Finally, we need a detector to detect the neutrons scattered from the sample.
     This will have a “banana” shape (as is typically used on powder diffractometers)
     and cover a large horizonal scattering angle. Use the monitor_nD component
     with parameters: yheight = 0.1, zdepth = 0, radius = 1.5,
     options="banana, theta limits = [10,130], bins = 500". The
     latter may seem like an arbitrary string of terms: the first keyword specifies the
     geometry of the detector, the second the x-axis and its limits, and the third the
     number of angle bins in the detector. Now we have a complete (if slightly
     unrealistic) instrument!
7.   To see what the instrument looks like, return to the main McStas window and
     click Run. In the dialogue, select Trace from the Simulation/Trace drop-
     down menu. Choose a small number of neutrons in the Ray count box (~100),
     then click Run. A visualization of the instrument should open in your browser
     after a few seconds – this view is often very useful when troubleshooting a
     simulation. Watch the rays propagating from the source to the sample and then
     on to the detector.
          a. What fraction of the rays hit the detector? What is this telling you about
              the scattering of the sample?
8.   It’s finally time to run a simulation: close the instrument visualization, then
     reopen the Run window. Instead of Trace, select Simulation in the
     Simulation/Trace drop-down menu. Choose a large number of rays (~1e8),
     then make sure to set Parallelisation to MPI (recompile) – this will
     distribute the simulation job across 32 cores accessible to the virtual machine,
      considerably speeding up the simulation. Once the simulation has run (this
      should only take a few seconds), plot the results and behold the glory of the Si
      diffraction pattern!
          a. What is the 2θ-dependence of the linewidth? By analogy with the more
              complex case of the powder diffractometer discussed in the lecture,
              which term in Caglioti formula would be expected to cause this effect?
   9. To see the effect of changing the divergence on the resolution, try shortening the
      source to sample distance.
          a. What happens to the width and shape of the Bragg peaks? What is the
              physical origin of these changes?
Some suggested further exercises:
   1. Look at the effect of vertical integration by increasing the height of the detector
      and adding “,y” to the end of the options string. This will produce a 2D
      colour-plot of the Intensity (vertical axis) versus 2θ (horizontal axis). Also make
      the detector taller – 0.4m should be sufficient. The Bragg peaks are now vertical
      lines in the detector.
          a. How do the lines at small angle differ from the ones at higher angle?
          b. From this, what is the effect on the resolution of increasing the detector
              height?
   2. Try simulating a more complex instrument. Click Open, then select d2b_ill.instr.
      This is the model for the D2B high resolution diffractometer at Institut Laue
      Langevin in France. First, look through the .instr file by clicking Edit – this is
      quite a lot more complicated than our simplified example! The instrument
      consists of several slits, then a neutron guide, then the typical combination of 3
      collimators, a monochromator, a sample, and a wide-angle detector that we saw
      in the Instrument Design lecture. The configuration of the instrument can be
      controlled from the Run window using the parameters defined in the DEFINE
      section. Other important parameters are calculated from these in the
      INITIALIZE section.
          a. Make sure you can identify all of the components by making a drawing of
              the instrument.
          b. Calculate U, V, and W for the default parameters given in lines 70-73. Note
              that BETA is called ETA here. Plot the resulting FWHM in 2θ from the
              Caglioti formula in software of your choice.
          c. Run the simulation with the default parameters. This will use a typical
              configuration for D2B with optimized detector collimation ⍺3. The
              simulation will take ~2 minutes to run.
          d. Plot the output of the simulation using Plot in the main McStas window.
              There are now 9 monitors (detectors) along the instrument tracking the
              shape of the beam spot, the wavelength distribution of the beam at the
monochromator, the horizontal and vertical divergences at the primary
and secondary collimation, the spectra in the detector summed over the
full height, the central pixels, and finally, the full 2D detector image.
McStas provides output from each of the monitors (detectors) in the
instrument. These can be loaded and analyzed in other programmes, just
like real data. We therefore call this a virtual experiment.
      i. Load the output file from this run (‘D2B_BananaTheta_xxxxxxxxx.A’)
         in your favourite refinement software. A cif file for the
         Na2Ca3Al2F14 sample may be found at:
         https://legacy.materialsproject.org/materials/mp-555730/
     ii. Refine the pattern following the usual sequence: lattice
         parameters, amplitude, resolution, atomic positions. At the end,
         what are U, V, and W, and do they agree with the parameters you
         calculated in step 3a above?