## 1D lattice

In this example we simulate the scattering from infinite 1D repetition of rectangular patches (rectangular grating). This is done by using the interference function of a 1D lattice together with very long boxes.

- By-default, the axis of the one-dimensional lattice coincides with the $x$-axis of the reference cartesian frame, so it coinsides with the beam direction.
- Long boxes are placed along a one-dimensional lattice on top of substrate, the lattice_length parameter corresponds to the grating period.
- The size of boxes is initially chosen to form a grating which is perpendicular to the beam (long side of the box is along $y$-axis).
- Keep in mind that `length`, `width`, `height` in the `Box(length, width, height)` constructor correspond to the directions in the $x,y,z$ axes, in that order, so to achieve the desired setup we use the values: `length`= $10$ nm, `width`= $10000$ nm, `height`= $10$ nm.
- The whole grating is rotated at the end by an angle of $45^{\circ}$ with respect to the beam axis. This is achieved by rotating both the 1D lattice and the long boxes (see lines 25 and 34).
- To avoid the problem of rapidly oscillating form factors of long boxes (see this example for more details), the simulation is performed in monte carlo integration mode.

Real-space model

Sketch

Scattering intensity

auto/Examples/scatter2d/Interference1DLattice.py

## Explanation

A one dimensional lattice can be viewed as a chain of particles placed at regular intervals on a single axis. The plot below represents one possible use case, where infinitely long (or very long) boxes are placed at nodes of a 1d lattice to form a grating.

See the BornAgain user manual (Chapter 3.4.1, One Dimensional Lattice) for details about the theory.

### Interference1DLattice constructor

The interference function is created using its constructor

    Interference1DLattice(length, xi)
    """
    length   : lattice constant, in nanometers
    xi       : rotation of the lattice with respect to the x-axis, in radians
    """

`Length` is the length of the lattice basis vector `a` expressed in nanometers (see plot below). `xi` ($\xi$) is the angle defining the lattice orientation. It is taken as the angle between the basis vector of the lattice and the x-axis of the Cartesian coordinate system. It is defined in radians and set to 0 by default.

When the beam azimuthal angle $\varphi_f$ is zero, the beam direction coincides with x-axis. In this case, the $\xi$ angle can be considered as the lattice rotation with respect to the beam.

### Position variance

The position variance parameter `Var`, as depicted on the top plot, allows to introduce uncertainty for each particle position around the lattice point by applying a corresponding Debye-Waller factor.

It can be set using the `setPositionVariance(value)` method, where `value` is given in $nm^2$.

    lattice = Interference1DLattice(100*nm, 0.0*deg)
    lattice.setPositionVariance(0.1)

By default the variance is set to zero.

### Decay function

To account for finite size effects of the lattice, a decay function should be assigned to the interference function. This function encodes the loss of coherent scattering from lattice points with increasing distance between them. The origin of this loss of coherence could be attributed to the coherence length of the beam or to the domain structure of the lattice.

In the picture below a one dimensional lattice is represented in real space as a probability density function for finding a particle at a given coordinate on the x-axis. In the presence of a decay function, this density can be given as $\sum F_{decay}(x)\cdot\delta(x-na)$.

The Fourier transform of this distribution $P(x)$ provides the scattering amplitude in reciprocal space. An exponential decay law in real space with the decay length $\lambda$ will give a Cauchy distribution with characteristic width $1/\lambda$ in reciprocal space, as shown below.

The decay function can be set using the setDecayFunction(decay) method of the 1D interference function.

    iff = Interference1DLattice(10.0*nm)
    iff.setDecayFunction(FTDecayFunction1DCauchy(1000.0*nm))

### List of decay functions

BornAgain supports four types of one-dimensional decay functions.

- `FTDecayFunction1DCauchy(decay_length)`

One-dimensional Cauchy decay function in reciprocal space, corresponds to $exp(-|x|/\lambda)$ in real space.

- `FTDecayFunction1DGauss(decay_length)`

One-dimensional Gauss decay function in reciprocal space, corresponds to $exp(-x^2/(2*\lambda^2))$ in real space.

- `FTDecayFunction1DTriangle(decay_length)`

One-dimensional triangle decay function in reciprocal space, corresponds to $1-|x|/\lambda$, if $|x|<\lambda$, in real space.

- `FTDecayFunction1DVoigt(decay_length, eta)`

One-dimensional pseudo-Voigt decay function in reciprocal space, corresponds to $eta*Gauss + (1-eta)*Cauchy$.

The parameter $\lambda$ (decay length) is given in nanometers, it is used to set the characteristic length scale at which loss of coherence takes place. In the case of the pseudo-Voigt distribution an additional dimensionless parameter `eta` is used to balance between the Gaussian and Cauchy profiles.

### Particle Density

During the simulation setup the particle density has to be explicitely specified by the user for correct normalization of overall intensity. This is done by using the `ParticleLayout.setParticleDensity(density)` method. The density parameter is given here in “number of particles per square nanometer”.

### Lattice rotation in details

In this paragraph we would like to clarify the relation between the lattice orientation and the orientation of the particles forming the lattice.

The rotation of the lattice doesn’t change the orientation of the particles with respect to the beam direction.

### Setup 1

For example, we would like to create a grating: a repetition of rectangular patches perpendicular to the beam, as shown on the plot (view from the top of the sample).

The long side of boxes is aligned along y-axes of the reference plane, the lattice axis coincides with the beam direction, the long side of the boxes is perpendicular to the beam.

To achieve such a setup, the following code should be used.

    layout = ba.ParticleLayout()

    box = ba.Particle(material, ba.Box(10*nm, 1000*nm, 10*nm))
    layout.addParticle(box)
    layout.setInterference(ba.Interference1DLattice(40*nm))

### Setup 2

If we rotate the lattice by a certain amount, the orientation of the boxes stays the same, but the effective grating period gets smaller. The setup and code are shown below.

    box = ba.Particle(material, ba.Box(10*nm, 1000*nm, 10*nm))
    layout.addParticle(box)
    layout.setInterference(ba.Interference1DLattice(40*nm, 30.0*deg))

### Setup 3

If we want to preserve the grating period and make our boxes rotate with respect to the beam, a separate rotation should be applied.

    box = ba.Particle(material, ba.Box(10*nm, 1000*nm, 10*nm))
    box.setRotation(ba.RotationZ(30.0*deg))
    layout.addParticle(box)
    layout.setInterference(ba.Interference1DLattice(40*nm, 30.0*deg))

- Introduction
  - Functionality overview
  - Architectural overview

- Install or build
  - Install Python
    - Python on Linux
    - Python on Windows
    - Python on Mac
    - Python modules
  - Install BornAgain
    - Linux
    - Windows
    - MacOS
    - Development snapshot
  - Build BornAgain
    - Unix
      - Install third-party software
      - Get the source
      - Build and install BornAgain
      - Run a first simulation
    - Windows

- Graphical user interface
  - Quick Start
  - GUI overview
  - Fitting in the GUI

- Python scripting
  - Run a script
  - Understand the syntax
  - Fitting
  - Upgrading

- Reference
  - Simulation model
    - Simulation classes
      - Specular
        - Example
      - Scattering
        - Examples
          - GISAS
          - without DWBA terms
          - with specular peak
          - SAS
          - Polarized SANS
          - Monte-Carlo
      - Off-specular
        - Off-specular
      - Depth probe
        - Examples
          - Thin film
          - Transmitted modulus
          - Resonator
    - Common settings
      - Background
      - Options
        - Monte-Carlo
        - # threads
        - Average materials
        - Include specular
      - Progress monitor
  - Instrument model
    - Beam
      - Footprint
      - Beam divergence
    - Scan
      - TOF reflectometry
      - TOF resolution
      - Beam Angular Spread
      - Beam Wavelength Spread
    - Detectors
      - SphericalDetector
      - 2d detector resolution
      - Offspec detector
    - Neutron polarization
      - Spin asymmetry example
    - Examples
      - 2D detector resolution
      - Neutron polarization
        - Magnetic layer
        - Ditto, realistic instrument
        - Polarized scattering
  - Sample model
    - Materials
      - Magnetization
    - Sample
      - Layer
      - LayerStack
      - Layout
    - Roughness
      - Interface model
      - Transient
      - Cross-correlation
      - Examples
        - GISAS
        - Reflectivity
    - Particles
      - Form factor
        - Hard particles
          - Bipyramid4
          - Box
          - CantellatedCube
          - Cone
          - Cylinder
          - Dodecahedron
          - EllipsoidalCylinder
          - HemiEllipsoid
          - HorizontalCylinder
          - Icosahedron
          - PlatonicOctahedron
          - PlatonicTetrahedron
          - Prism3
          - Prism6
          - Pyramid2
          - Pyramid3
          - Pyramid4
          - Pyramid6
          - Sphere
          - SphericalSegment
          - Spheroid
          - SpheroidalSegment
          - TruncatedCube
        - Ripples
          - Bar ripple
          - Cosine ripple
          - Sawtooth ripple
        - Soft particles
          - FuzzySphere
          - Gauss
        - Custom formfactor
      - Composite particles
        - Core and shell
        - Compound particle
        - Mesocrystal
      - Examples
        - Compound particle
        - Core and shell
        - Crossing an interface
        - Mesocrystal
        - Rotation example
        - Dense cylinders
        - Dense hemispheres
        - Uncorrelated mixture
        - Polydispersity
    - Particle assemblies
      - Grating
        - 1D lattice
        - Cosine ripples in a lattice
        - Triangular ripples in a lattice
      - 2D lattice
        - Square lattice
        - Lattice orientation distribution
        - Finite square lattice
        - Lattice with basis
        - Multi-layer lattice
        - Position variance
      - Radial paracrystal
      - 2D paracrystal
      - Others
        - Size-distribution model: decoupling approximation
        - Size-distribution model: local monodisperse approximation
        - Size-distribution model: size-spacing coupling approximation
  - Model modifiers
    - Rotation
    - Distributions
  - Data types
    - Class Datafield
      - Export
      - Find intensity peaks
    - SLD profile
      - SLD profile with rough interfaces
      - SLD profile with a sliced particle layer
  - Plotting
    - Functions
    - Configuration
    - Heat map
    - LaTeX markup
    - Export
    - Plot axes in different units
  - Fitting
    - Data import
      - TIFF
    - Minimizer settings
    - Multiple datasets
    - Examples
      - Fitting with masks
      - Custom objective function
      - Fitting along slices
      - GISAS 2D fits
      - Experiment at GALAXI
      - Find background
      - Minimizer settings
      - Bayesian Sampling
      - Consecutive fitting
      - Considering uncertainties
      - External minimizer
      - External minimizer: plotting
      - Simultaneous fit of two datasets
      - Spin asymmetry fit example
      - Reflectometry: Fit Pt layer
      - Reflectometry: Fit honeycomb

- Literature
  - Babonneau2010
  - Babonneau2013
  - Croset2021
  - Lazzari2002
  - Lazzari2006
  - Pospelov2020
  - Renaud2009
  - Sears1992
  - Wuttke2021

- How to
  - Get announcements
  - Solve known problems
    - Set Python environmental variables under Windows
  - Request help or report bugs
  - Cite BornAgain

- Developers' corner
  - Configure
    - Build
    - Pyenv
  - Develop
    - Manual checks
    - Debug
    - Webdoc
    - Code analyses
  - Release
    - Manual GUI test