+++
title = "2D lattice"
weight = 20
+++

## 2D lattice

{{< figscg src="/img/draw/SquareLattice_setup.jpg" width="400px" class="center">}}

### 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.

{{< figscg src="/img/draw/lattice2d.svg" width="250px" class="center">}}

### Structure constructors

The structure for an infinite 2D lattice is created from a particle and a
lattice object:

```python
lattice = ba.BasicLattice2D(length_a, length_b, alpha, xi)
structure = ba.Crystal2D(particle, lattice)
```

To account for finite-size effects, and to give the simulated Bragg peaks a
finite width, attach a peak profile as described below.

The finite 2D lattice model is computed by explicit summation over
contributions from all unit cells. The lattice is constructed by one of the
following:

```python
ba.BasicLattice2D(length_a, length_b, alpha, xi)
ba.SquareLattice2D(length, xi)
ba.HexagonalLattice2D(length, xi)
```

Then the finite structure is constructed by

```python
structure = ba.FiniteCrystal2D(particle, 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 accounts for the finite size of the sample, the crystalline
domain, or the scattering volume. It contributes a multiplicative factor
$h(\mathbf{r})$ to the correlation function in real space that lets it 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 over 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.

{{< figscg src="/img/draw/decay2lattice.svg" width="280px" class="center">}}

Decay functions for the one-dimensional case are explained in the
[grating](/ref/sample/struct/2d/grating) section. Decay functions for
two-dimensional lattices work similarly, but require two length parameters and
an orientation. 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:

```python
ba.Profile2DCauchy(omega_x, omega_y, gamma)
ba.Profile2DGauss(omega_x, omega_y, gamma)
ba.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](https://jugit.fz-juelich.de/mlz/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
(&ge; 1000 nm).

### Setting the decay function

The decay function is attached to a lattice structure by the
`setDecayFunction` method:

```python
lattice = ba.BasicLattice2D(20*nm, 20*nm, 120*deg, 0)
structure = ba.Crystal2D(particle, lattice)
profile = ba.Profile2DCauchy(1000*nm, 1000*nm, 0*deg)
structure.setDecayFunction(profile)
```

### Particle density

The particle density is determined from the 2D lattice parameters. There is no
separate particle-density setting for `Crystal2D` or `FiniteCrystal2D`.

### Examples and extensions

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