Generating X-ray diffraction patterns from atomic coordinates I have a list of atomic coordinates for a periodic system as a result of a molecular dynamics simulation. I want to use those coordinates and predict what it's 1D diffraction pattern looks like.
The approach I am taking is to generate a 2D cross section and then radially integrate it to get the 1D pattern. To do so, I am using the following equation taken from the reference cited at the bottom (I know this is a very computationally slow approach but I want to understand the theory right before I get fancy with FFTs):
I(ks) $\propto$ |F(q)|2 $\propto$ |$\sum_{j=1}^{N} Z_jexp(i\mathbf{q} \cdot \mathbf{r}_j)|^2$
$\mathbf{k}_s$ is the elastically scattered wavevector
$\mathbf{q}$ is the reciprocal lattice vector
$\mathbf{r}_j$ is  the atomic coordinate
$Z_j$ is the atomic number of the jth atom
N is the number of atoms in the system
$\mathbf{k}_s$ can also be represented as $\mathbf{k}_s$ = $\mathbf{k}_0$ + $\mathbf{q}$ where $\mathbf{k}_0$ is the wavevector incident on the crystal 
Applying the equation correctly is where I must be going wrong. Here is my approach:  
I chose $\mathbf{k}_0$ to be (0, 0, 1). To get $\mathbf{k}_s$ I found and normalized the vector pointing from the sample to each pixel on the detector (shown in the picture below -- the right hand picture is a simplified detector with each pixel represented by a grey box). This lets me solve for $\mathbf{q}$ which I can then plug into the above equation.
 
Calculating the intensity for each pixel from the combined contributions of all atoms results in a 2D plot which I can then integrate. I get peaks but they don't make sense. Perhaps someone can shed light on what I am doing wrong. I am almost certain it has to do with $\mathbf{q}$.
References: J. Phys.:Condense. Matter 20(2008)505203
 A: (this is not really an answer to the question, but perhaps it'll be helpful)
Starting from the equation in question:
$$ I(\mathbf{k_s}) \propto |F(\mathbf{q})|^2 \propto |\sum_{j=1}^{N} Z_j \exp(i\mathbf{q} \cdot \mathbf{r}_j)|^2$$
we can write $|F(\mathbf{q})|^2$ as $F(\mathbf{q})F^*(\mathbf{q})$, i.e.
$$I(\mathbf{k_s}) \propto \sum_{j=1}^{N} Z_j \exp(i\mathbf{q} \cdot \mathbf{r}_j) \sum_{j=1}^{N} Z_j^* \exp(-i\mathbf{q} \cdot \mathbf{r}_j)$$
and assuming that $Z_j$ has no imaginary part:
$$I(\mathbf{k_s}) \propto \sum_{j=1}^{N} \sum_{k=1}^{N} Z_j Z_k \exp(-i\mathbf{q} \cdot \mathbf{r}_{jk})$$
where $\mathbf{r}_{jk} \equiv \mathbf{r}_j - \mathbf{r}_k$.
The question suggested that the sample is a single crystal, but let's instead assume a polycrystalline sample (Debye–Scherrer geometry).
The sample is made of many, many crystallites in different orientations.
To emulate it we average the equation above over all possible directions of $\mathbf{q}$.
And after some integration we get surprisingly simple result:
$$\left\langle \exp(-i\mathbf{q} \cdot \mathbf{r}_{jk}) \right\rangle =  \frac{\sin(qr_{jk})}{qr_{jk}}$$
(no vectors on the right, only absolute values).
This result was obtained by P. Debye about 100 years ago.
It's the usual way of calculating powder diffraction patterns from atomistic models.
