## 2D lattice

### Lattice geometry

We consider a 2d Bravais lattice that is specified by lattice constants $a$ and $b$, by the angle $\alpha$ between the lattice vectors $\mathbf{a}$ and $\mathbf{b}$, and by the angle $\xi$ between $\mathbf{a}$ and the $x$ axis of the instrument frame.

### Interference function constructors

The interference function for an infinite 2d lattice is created using its constructor

    Interference2DLattice(length_a, length_b, alpha, xi=0)

To account for finite-size effects, and to give the simulated Bragg peaks a finite width, it is necessary to attach a peak profile (decay function), as described below.

The structure factor of the finite 2d lattice model is computed by explicit summation over contribution from all unit cells. The 2d lattice is constructed by one of the following:

    BasicLattice2D(length_a, length_b, alpha, xi)
    SquareLattice2D(length, xi)
    HexagonalLattice2D(length, xi)

Then the interference function is constructed by

    InterferenceFinite2DLattice(lattice, Na, Nb)

where the integer arguments $N_a$ and $N_b$ are the numbers of unit cells in lattice directions $\mathbf{a}$ and $\mathbf{b}$.

### Decay function (peak profile)

The decay function, which should be assigned to the interference function, accounts for the finite size of the sample or the crystalline domain or the scattering volume. It contributes a multiplicative factor $h(\mathbf{r})$ to the correlation function in real space that lets them decay for $r$. Equivalently, its Fourier transform $H(\mathbf{q})$ is convolved with the structure factor of the ideal, infinite lattice, $$S_0(\mathbf{q}) = \rho \sum_i c_i \delta(\mathbf{q} - \mathbf{q}_i),$$ where the sum runs of reciprocal lattice points, resulting in $$S(\mathbf{q}) = \rho \sum_i c_i H(\mathbf{q} - \mathbf{q}_i).$$ That is, each Bragg peak gets the same smooth profile $H(\mathbf{q})$ instead of the infinitely sharp delta function.

Decay functions for the one-dimensional case are explained in the grating section. Decay functions for two-dimensional lattices work similarly, but require two length parameters and an orientation to be defined. The lengths $\omega_x$ and $\omega_y$ refer to the principal axes of an ellipsis that is rotated by an angle $\gamma$ with respect to the coordinate axes $x$, $y$.

BornAgain supports three two-dimensional decay functions:

    Profile2DCauchy(omega_x, omega_y, gamma)
    Profile2DGauss(omega_x, omega_y, gamma)
    Profile2DVoigt(omega_x, omega_y, gamma, eta)

The Cauchy distribution is in physics better known as the Lorentzian profile. The Voigt distribution is computed as the true convolution of a Gaussian and a Lorentzian, using our numeric library libcerf. The dimensionless parameter `eta`=$\eta$ may take values between 0 (Lorentian) and 1 (Gaussian).

### Recommended decay lengths

Decay lengths should be much larger than the lattice constants. Otherwise the model becomes physically questionable, and computation times increase a lot. Typical values for meaningful decay lengths are in the micrometer range (≥ 1000 nm).

### Setting the decay function

The decay function is attached to an interference function by the `setDecayFunction` method, which should be called after the interference function is constructed:

    iff = Interference2DLattice(20*nm, 20*nm, 120*deg)
    profile = Profile2DCauchy(1000*nm, 1000*nm, 0*deg)
    iff.setDecayFunction(profile)

### Particle density

The computational kernel provides an automatic calculation of particle densities using the parameters of the 2D lattice. This means that the user’s setting of the particle density via the `ParticleLayout.setParticleDensity()` method (which is a required step in the case of a 1D interference function and radial paracrystal initialization) is ignored.

### Examples and extensions

- Simple square lattice, a square lattice of cylinders, rotated with respect to the instrument $x$, $y$ frame;
- Orientional distribution, the same lattice, with incoherent average over different orientations $\xi$;
- Finite square lattice, the same lattice, back to fixed orientation, now with a finite number of unit cells;
- Unit cell with basis, if there is more than one particle in the unit cell;
- Two lattice layers, described by a 2d lattice with 3d basis;
- Position variance: fluctuations of particle position of around lattice points, resulting in a prefactor of Debye-Waller type.

- 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