0% found this document useful (0 votes)
78 views

Virtual Experiments With Mcstas Inserting MD Into Simulated Instruments

The Monte-Carlo code URANOS was specifically tailored to address the open questions of cosmic-ray neutron sensing for environmental applications (Köhli et al. 2015).

Uploaded by

Ngôn Nguyễn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Virtual Experiments With Mcstas Inserting MD Into Simulated Instruments

The Monte-Carlo code URANOS was specifically tailored to address the open questions of cosmic-ray neutron sensing for environmental applications (Köhli et al. 2015).

Uploaded by

Ngôn Nguyễn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Virtual experiments with McStas

Inserting MD into simulated instruments


E. Farhi, ILL/Computing for Science

McStas – Farhi – ILL/CS – May 2014 - 1/32


Outline

Monte-Carlo: not only a casino...

Simulating instruments: what for ?

The McStas software: presentation, principle, components, tools, ...

Samples in a McStas simulation: from experiment, from MD (nMoldyn)

What can be simulated (and what can not)

A short demo: a diffractometer, out of the box

The Tutorial: water in a neutron diffractometer and a ToF spectrometer

McStas – Farhi – ILL/CS – May 2014 - 2/32


Origin of Monte-Carlo methods

Used by Nature since ... (a long time) : diversity of Life
Examples: flies in the kitchen, kids running everywhere, ...

First application using computers:
Metropolis, Ulam and Von Neumann at Los Alamos, 1943
Neutron Scattering and Absorption in U and Pu, Origin of MCNP

Name: 
Monte Carlo Casino, a random generator (Ulam played poker)

Photograph Source: GALE FORCE Archive


McStas – Farhi – ILL/CS – May 2014 - 3/32
Principles of Monte-Carlo methods
Use random number generators (play poker)

Explore a complex and large phase space (many parameters)

Integrates microscopic random events into measurable quantities
not a usual regular sampling integration 
n b
1 1 b−a
lim ∑
n→ ∞ n i=1, a<u <b
f ( u i )= ∫
b−a a
f ( u) du du→
n
i

Metropolis algorithm: model energy gap E as a probability
 
p  e­E/kT

Integrals converge faster than any other method (for d > 3)
when using enough independent events (central limit theorem)

F. James, Rep. Prog. Phys., Vol. 43 (1980) 1145.
McStas – Farhi – ILL/CS – May 2014 - 4/32
When to use Monte-Carlo methods ?

Dimensionality of phase space must be large (d > 5)

Overall complexity is beyond reasonable analytical methods

Each event can be computed easily and independently

MC is the 'lazy guy' method – think microscopic

Examples: 
Estimate  from a circle/square (“Buffon needle”)
Area under/inside a curve/volume (integration) Number of points for which
Molecular Dynamics { x2+y2  1, (x,y)  [0,1] }
Ratio circle/square → 
spin­system phase transitions (Ising model)
nuclear reactions
ray­tracing (light, particles)

McStas – Farhi – ILL/CS – May 2014 - 5/32


Implementing Monte-Carlo in softwares

Good random generator:
from thermal electronic noise (hardware)
or quasi­random generators => quasi­Monte­Carlo

We encounter a probability 0 < p < 1.

Crude Monte­Carlo (yes/no choice): 
We shoot n events  [0,1] 
We keep events that satisfy  < p
np events → low statistics
Importance sampling (fuzzy choice – event weighting): 
Keep n events, no more random number...
But associate a weight p to each of them (we set  = p)
Retain statistical accuracy (1/√n)

McStas – Farhi – ILL/CS – May 2014 - 6/32


Some Monte-carlo softwares

Each time physics takes place (scattering, absorption, ...) random choices
are made.

Light ray-tracing: PoV-RAY and others ...

Nuclear reactor simulations (neutron transport):


MCNP, Tripoli, GEANT4, FLUKA

Neutron Ray-Tracing propagation:


McStas <www.mcstas.org>, Vitess, Restrax, NISP, IDEAS
Neutrons are described as (r, v, s, t), and are transported along models.
Propagation simply uses Newton rules, incl. gravitation.

X-ray tracing
Shadow, McXtrace

McStas – Farhi – ILL/CS – May 2014 - 7/32


The McStas European project

Flexible, general simulation utility for neutron scattering experiments.

Original design for Monte Carlo Simulation of triple axis spectrometers.


Developed at RISØ and ILL (started 1998).
Mainly funded by EU (FP 4-7): 2.5+1 people full time, plus projects.
Open source, GPL2. Works on all systems, binaries for Linux, Win$, MacOSX

Most widely used code in its ecological niche (compared to other similar codes)..

A few hundred users worldwide (238 registered)


many contributors (community based).
Has been used to model most existing and future
neutron scattering instruments.

[email protected] mailing list


<www.mcstas.org> [email protected] developer contact
McStas – Farhi – ILL/CS – May 2014 - 8/32
Simulating instrument: what for ?

A Triple-Axis
M
M A A Spectrometer (IN20)

S
S

Design new instruments
Optimize existing instruments (flux/resolution)
Optimize usage of existing instruments (better experiments)
Get accustomed with the instruments before coming at the ILL
Measure the instrument effects on the simulated 'ideal' sample signal
Estimate complex effects like :
absorption, multiple scattering, geometry, resolution function...
Compare virtual experiments with real ones, possibly during exp.

McStas – Farhi – ILL/CS – May 2014 - 9/32


McStas: basic mechanism McStas

McStas – Farhi – ILL/CS – May 2014 - 10/32


McStas: basic mechanism McStas

n
Neutron ray/package:

Weight (p): # neutrons (left) in the package


Coordinates (x,y,z)
Velocity (vx,vy,vz)
Spin (sx,sy,sz), Time (t)

McStas – Farhi – ILL/CS – May 2014 - 11/32


McStas: basic mechanism McStas

n
Components: Here the neutron physics
(Bragg law) happen, neutron weight
adjusted according to scattering
probabilities etc (Monte Carlo is here).

λ=2 d sin θ

McStas – Farhi – ILL/CS – May 2014 - 12/32


McStas: basic mechanism McStas

n
Instrument: positioning +
transformation between sequential
component coordinate systems, e.g.
neutron source, crystal, detector.

McStas – Farhi – ILL/CS – May 2014 - 13/32


McStas: available components to model instruments

Sources (neutrons)
Continuous (reactor), Pulsed

Moving optics
Choppers (disk and Fermi), velocity selectors, phase space transformers

Static optics
Guides, mirrors, benders, lenses, collimators, slits, filters, monochromators

Samples/materials
Single crystals, liquids, gas, polymers, colloid

Detectors
Histogram and event monitors, gas detectors

Total 135 components, 110+ examples, manuals, tutorials...

McStas – Farhi – ILL/CS – May 2014 - 14/32


McStas: grammar

Instruments are defined from a text file. General syntax is based upon C.
Basic syntax:

DEFINE INSTRUMENT name(parameter1=value1, …)

DECLARE %{ /* global variables */


%}

INITIALIZE %{ /* code executed when starting */


%}

TRACE /* sequence executed for each neutron event */


COMPONENT InstanceName=component(parameters...)
AT (position) RELATIVE reference
ROTATED (orientation) RELATIVE reference
...
END

McStas – Farhi – ILL/CS – May 2014 - 15/32


Virtual experiments: definition

Virtual experiments
=
Instrument simulation

Realistic Sample model
=
Neutron flight simulator

and then we play with it without breaking the instrument and sample.

●E. Farhi et al, J. of Comp. Phys. 228 (2009) 5251.


●E. Farhi and P. Willendrup, Collection SFN 12 (2011) 303.

●E. Farhi et al., J. Neut. Res., 17 (2014) 63.

McStas – Farhi – ILL/CS – May 2014 - 16/32


McStas: available sample components

Most instrument components are 'easy' to simulate. The samples are often
more complex.

Scattering Input Coherent Incoherent Multiple


Process Elastic Inelastic Elastic Inelastic
PowderN |F2(q)|,abc, Powder X
Single_crystal |F2(hkl)|,abc, Crystal X X
Isotropic_Sqw S(q,w), Isotropic X X X X
Incoherent  X QuasiE
Sans_sphere R colloid

McStas – Farhi – ILL/CS – May 2014 - 17/32


Isotropic_Sqw: liquids, gas, glass, polymers, ...
See Egelstaff or H. Fischer, Rev. Prog. Phys. 69 (2006) 233

Neutronist's Mantra
Holy Book (Squires)
Effective cross section
for scattered intensity
V.F. Sears. Adv. Phys., 24 (1975) 1

We like to play games


in (q,) space

Effective cross section


in (q,) space

Probability to interact p=e−  x

Scattering distribution S(q,) with importance sampling to


scatter preferably where S is large

McStas – Farhi – ILL/CS – May 2014 - 18/32


Obtaining S(q, )

The dynamical structure factor S(q,w) can be obtained from experiments,


assuming a proper data reduction, or from MD.

Detector efficiency,
Experiments normalization, LAMP →q;t→
(TOF, TAS) transmission
(multiple scattering) FullProf

NAMD, DL_POLY
Molecular Inter-atomic
Dynamics potential u(r)

F =−∇ ur =m  nMoldyn S(Q,)


R, v S(Q)
.nc → .cdl → .sqw F2(hkl)
Ab-initio
(VASP) Pseudo-potential

VASP, CASTEP
McStas – Farhi – ILL/CS – May 2014 - 19/32
Benefits from a virtual experiment

Benefits:
The resolution from the instrument is implicitly convolved with the sample,
without analytical integration
The 'spurious' effects from the instrument can be included
Treat absorption in the sample (self attenuation=2nd extinction)
Treat coherent/incoherent scattering
May include multiple scattering (depends on the sample component)
May model the measurement background

Requirements:
Need as accurate instrument description as possible
Use proper sample component/kernel
Give accurate data to the sample component (experiment, MD, …)
Be critical regarding the results (it's so easy to get rubbish)

McStas – Farhi – ILL/CS – May 2014 - 20/32


Guided tour
(On line demo)

A simple pre-assembled powder diffractometer

McStas – Farhi – ILL/CS – May 2014 - 21/32


Using McStas: a diffractometer: opening

I now focus on a short live-demo using McStas.

1- Start McStas: double click Or type 'mcgui'


in the Dash

2- The McGUI main interface appears (Shazam !).

3- Select the Neutron site/Templates/templateDIFF.

4- Click the Edit button. The Help menu gives


access to the manuals and the component library.

5- The instrument description is shown. This is a


text file, with a dedicated grammar, which lists the
instrument component sequence. Some portions of
C code can be embedded.

6- In this example, the Sample is a PowderN


component (line 174).
McStas – Farhi – ILL/CS – May 2014 - 22/32
Using McStas: a diffractometer: simulating

7- Click the Run button (next to Edit). This builds the instrument.
8- Click again the Run button. A dialogue appears. It is possible here to
change the instrument parameters (wavelength, sample, ...).
9- Press Start. This takes 1 min.
10- Press the Plot button (below Run).
All histogram monitors defined in the
instrument are displayed. Data files are
pure text, stored in a directory.

11- Comments about the results ?

12- Click again Run, and select


Mode=Trace, Neutron count=100,
Format=VRML
Then press Start. A 3D view of the instrument appears.
Change back Format=PGPLOT

McStas – Farhi – ILL/CS – May 2014 - 23/32


Using McStas: a diffractometer: scanning

13- To speed-up execution (½), select menu


File/Simulation/Configuration and check box 'Apply
compiler flags'. Linux/MacOSX can use multi-core.
14- Perform a scan of the wavelength with:
lambda=0.5,3
#steps:20 Format=PGPLOT
15- Get a (free) coffee during execution (10 min).
16- Press the Plot button. Integral of monitors vs. lambda is
shown.
17- Comments about Lambda and the Banana monitors ?
Look in the templateDIFF.instr file (Edit button) for these
monitors in order to see what they do and where they are.
Choosing the right neutron wavelength is essential in a
neutron scattering experiment.

McStas – Farhi – ILL/CS – May 2014 - 24/32


The return of the tutorial

Changing a diffractometer into a spectrometer


Water structure and dynamics
Experiments and Simulations

McStas – Farhi – ILL/CS – May 2014 - 25/32


Mission: Impossible

Your mission Jim, should you decide to accept it

In this tutorial, we shall


re-use the previous diffractometer,
change its sample component in order to handle liquids,
add monitors in order to separate coherent, incoherent and multiple scattering
contributions.

Finally, water structure and dynamics from a NAMD trajectory will be


compared to an experiment with both light and heavy water.

McStas – Farhi – ILL/CS – May 2014 - 26/32


Mission 1: Prepare the liquid

In this step, we change PowderN into Isotropic_Sqw (for liquids)


1. Start McStas and select the templateDIFF instrument as seen earlier.
2. Click the Edit button and identify where the Sample=PowderN is.
3. From the Help menu, open the Component Library Index
4. Look for the Isotropic_Sqw component in section [samples]
5. Following that instructive novel reading, infer what should replace the
PowderN(...) call.
6. Keep the SPLIT keyword and use Sqw_coh=Powder
7. Check the general syntax of the modified Sample instance
8. Save the instrument, press Run and pray...
9. Launch the simulation with the same sample Al2O3_sapphire.laz
10. You should obtain about the same result as before... what is the
difference ?

Diffraction pattern

McStas – Farhi – ILL/CS – May 2014 - 27/32


Mission 2: Keep coherent

In this step we allow handling of both coherent and incoherent


1. Change parameter Powder to coh in the DEFINE INSTRUMENT line.
2. Add as well a parameter string inc=”NULL”
3. Go down to the Sample and add Sqw_inc=inc as Isotropic_Sqw parameter.
4. Change here Powder to coh as well.
“Houston we have a problem”
We have 2 sets of S(q,) data: from experiments where coherent and
incoherent are superposed, or from MD where we have access to the two
contributions. If we use a total S(q,), then the cross section must be the
total scattering one. We must then be able to specify explicitly these
values when needed (else leave them to 0 as default).
5. Add sigma_coh=0, sigma_inc=0 to the DEFINE INSTRUMENT line.
6. Add sigma_coh=sigma_coh, sigma_inc=sigma_inc to the Isotropic_Sqw(...)
7. Run the instrument with the provided MD files (NAMD):
Sqw_coh=H2O_liq_290_coh.sqw, Sqw_inc=H2O_liq_290_inc.sqw

McStas – Farhi – ILL/CS – May 2014 - 28/32


Mission 3: Experiment is the real stuff

In this step we run a simulation with experimental S(q,w)


1. An experiment done in April 2011 provided total S(q,w) for water. To use it
we need to use one of the scattering channels (coh or inc), and inactivate the
other channel.
2. Run a new simulation with Sqw_coh=H2O_liq_300_tot.sqw, sigma_inc=-1
3. Does the experimental structure factor S(q) match the MD one ?

S(q) Water, IN4 =1.1 Angs S(q,w)


McStas – Farhi – ILL/CS – May 2014 - 29/32
Mission 4: Turning into a spectrometer

In this step we buy an energy selective detector (cheap here)


1. Add energy monitoring to the BananaTheta monitor
options=”banana, angle limits=[5 160], energy limits=[0 50]”, bins=300
2. That's all ! Run again the MD and experimental S(q,w) simulations
3. Do they match (roughly)

INC

COH

Water, MD
McStas – Farhi – ILL/CS – May 2014 - 30/32
Mission 5: Monitoring multiple scattering

In this step we select multiple scattering events


1. We define a 'flag' to raise when a multiple scattering event is found. Add:
“double scattering_order;” in the DECLARE section.
2. We set this flag to the number of scattering events found in the Sample.
Change its EXTEND block content to
if (!SCATTERED) ABSORB; 
else scattering_order = SCATTERED;
3. We create a new monitor, sensitive to multiple scattering, after the
BananaTheta one:
COMPONENT BananaThetaMulti=COPY(Diff_BananaTheta)
WHEN (scattering_order > 1)
AT (0,0,0) RELATIVE PREVIOUS
4. That's all ! Run again the MD and experimental S(q,w) simulations
5. Does the experimental dynamic structure factor S(q,w) match the MD one ?
6. How much multiple scattering occurs in this water sample ( =1 cm) ?

McStas – Farhi – ILL/CS – May 2014 - 31/32


Mission 6: Heavy stuff

In this step we use heavy water


1. Use the NAMD heavy water data
Sqw_coh=D2O_liq_290_coh.sqw, Sqw_inc=D2O_liq_290_inc.sqw
5. Use the experimental heavy water S(q,w)
coh=D2O_liq_300_tot.sqw, sigma_coh=19.5, sigma_inc=-1
6. Does this improves multiple scattering ?
7. Does this reveals better the structural and dynamical information ?

S(q,w)
S(q)
Heavy Water, IN4 =1.1 Angs
McStas – Farhi – ILL/CS – May 2014 - 32/32

You might also like