How to calculate diffraction image for a given lattice? I have seen a lot of diffraction patterns such as this, taken from Wikipedia. I know how these images are measured, but I do not know how you can calculate (predict) a diffraction pattern for a specific lattice.
The structure factor for a monatomic system is given as
$$
S(\mathbf{q}) = \frac{1}{N}\sum\limits_{j=1}^{N}\sum\limits_{k=1}^{N}\mathrm{e}^{-i\mathbf{q}(\mathbf{r}_j - \mathbf{r}_k)},
$$
where $\mathbf{q}$ is the scattering vector and $\mathbf{r}_j$ the position of atom (or lattice point) $j$. The scattering vector $\mathbf{q}$ is given as $\mathbf{q} = \mathbf{k}_2 - \mathbf{k}_1$, where $\mathbf{k}_1$ is the incoming and $\mathbf{k}_2$ is the scattered beam. The amplitude $\lvert\mathbf{q}\rvert = \frac{4\pi}{\lambda}\sin\theta$ depends on the angle $\theta$ between the incoming and scattered beam.
For an isotropic system such as an amorphous solid, a polycrystal or in powder diffraction, one typically averages over all possible directions of $\mathbf{q}$. The so-calculated static structure factor is the Fourier transform of the radial distribution function. However, if I want to calculate the 2d diffraction pattern, I can't average over all possible directions of $\mathbf{q}$.


*

*Which value of $\mathbf{q}$ should be used? Does it matter?

*I read that $S(\mathbf{q})$ is the Fourier transform of the lattice (the reciprocal lattice). But the Fourier transform of a 3d lattice is three dimensional. How do I obtain the 2d diffraction pattern?


Related: This question on to calculate the 1d diffraction pattern.
 A: Let's first elaborate on your premises, which are not general enough in practice. A crystal is the repeat by translation of a so-called unit cell. In the most general case, this unit cell is a parallelepiped defined by three non-colinear vectors $\renewcommand{\vec}[1]{\mathbf{#1}}(\vec{a},\vec{b},\vec{c})$ and the translations to consider are $\vec{T}_{mnp}=m\vec{a}+n\vec{b}+p\vec{c}$ for integers $m,n,p$. We can then denote $F(\vec{q})$ the complex amplitude of the wave diffracted by one unit cell: if we consider only elastic scattering, this is the Fourier transform of the electron density inside the unit cell. Then the diffraction by the entire crystal, made of $M, N, P$ unit cells along $\vec{a}, \vec{b}, \vec{c}$ respectively reads
$$S(\vec{q})=\sum_{m=-M}^M\sum_{n=-N}^N\sum_{p=-P}^P F(\vec{q})\exp {i2\pi\vec{q}\cdot \vec{T}_{mnp}}.$$
Then introducing
$$\begin{aligned}
h&=\vec{a}\cdot\vec{q}\\
k&=\vec{b}\cdot\vec{q}\\
l&=\vec{c}\cdot\vec{q}\\
\end{aligned}$$
we get
$$S(\vec{q}) = F(\vec{q})
\underbrace{\frac{\sin\pi h (2M+1)}{\sin\pi h}}_{D_M(h)}
\underbrace{\frac{\sin\pi k (2N+1)}{\sin\pi k}}_{D_N(k)}
\underbrace{\frac{\sin\pi l (2P+1)}{\sin\pi l}}_{D_P(l)}
$$
The main characteristic of the function $D_K(r)$ for a large value of $K$ is that it has very strong and sharp peaks for integers value of $r$. As a result, the diffracted wave exhibit sharp peaks for integers $h,k,l$. If we then introduce the the basis $(\vec{a}^*, \vec{b}^*, \vec{c}^*)$ dual to $(\vec{a},\vec{b},\vec{c})$,
$$\vec{a}^* = \frac{\vec{b}\times\vec{c}}{V},$$
and circular permutations of $a$, $b$ and $c$, where $V=\det(\vec{a},\vec{b},\vec{c})$ is the volume of the unit cell, then
$$\vec{q}=h\vec{a}^*+k\vec{b}^*+l\vec{c}^*=\vec{q}_{hkl},$$
and therefore the sharp peaks lie on a lattice whose unit cell is defined by $(\vec{a}^*, \vec{b}^*, \vec{c}^*)$, the so-called reciprocal lattice.
Now that the proper framework has been laid out, I can move on to answer your question. Consider a plane passing through the reciprocal lattice. Any $\vec{q}_{hkl}$ close enough to the plane will result in some diffracted intensity around the projection of $\vec{q}_{hkl}$ onto the plane. In a real experiment, the plane would be the surface of a CCD for example. That detector surface would be moved of course but the reciprocal lattice would be moved too, i.e.  $(\vec{a}^*, \vec{b}^*, \vec{c}^*)$ would be moved, because the crystal would be rotated, and the incident X-ray beam would also see its direction changed. Thus the position of that plane I was discussing becomes a rather complex function of the relative position of the detector, the crystal and the source but we don't really need to go into that complexity unless you want to model an actual experimental setup. For a general simulation, it suffices to simply move that plane. The most "beautiful" diffraction patterns would of course be obtained by choosing a plane passing through a subset of $\vec{q}_{hkl}$'s. For example, the plane containing all $\vec{q}_{hk0}$ for any integer $h,k$.
