# Structure factor calculation for non-cubic lattices

I have an equilibrated trajectory from a molecular dynamics simulation and I would like to calculate the structure factor using the atomic positions. I think I am able to do it right for cubic lattices that I have been testing on. It is essentially just the discrete fourier transform of the atomic positions weighted by their atomic form factors.

I am having trouble figuring out the right way to perform the calculation for my actual simulated system which is simulated in a monoclinic unit cell. I believe the first step is to apply a transformation to the unit cell that shifts all of the atoms into an orthorhombic box of the same volume. This makes the atomic positions skewed, but the periodicity is such that I can apply a discrete fourier transform to it directly. After that, I'm not sure about the right way to transform the structure factor so it represents that of the actual unit cell.

The common (at least in my field...) definition for the structure factor is

$$S({\vec q}) = \frac{1}{\sum_{j}b_j^2} \sum_{j} \sum_{k} b_j b_k \mathrm{e}^{-i{\vec q}\cdot({\vec r}_j - {\vec r}_k)}$$

where the sums runs over all the atoms in the system and the $\lbrace b \rbrace$ coefficients are the atomic form factors. I guess this is the definition you are using. As far as I know, the formal definition above is always valid, regardless of the shape of the simulation box. What changes is how the distance between two atoms is handled. Indeed, if the simulation box is a cuboid, ${\vec r}_{jk} \equiv {\vec r}_j - {\vec r}_k$ can be computed with or without applying periodic boundary conditions and the results will not change[1]. By contrast, I suspect that with non-cubic boxes ${\vec r}_{jk}$ must be computed by taking into account the specific periodic boundary conditions.

[1]In finite volumes ${\vec q} = 2\pi (\frac{l}{L_x}, \frac{m}{L_y}, \frac{n}{L_z})$, where $L_x$, $L_y$ and $L_z$ are the lengths of the simulation box edges and $l$, $m$ and $n$ are integer numbers. Then, the PBC-corrected distance between particles $j$ and $k$ can be written as ${\vec r}^{PBC}_{jk} \equiv {\vec r}_j - {\vec r}_k - \Delta {\vec r}_{jk}$, where $\Delta {\vec r}_{jk} = (aL_x, bL_y, cL_z)$ with $a$, $b$ and $c$ being three integer numbers. It follows that

$${\vec q}\cdot{\vec r}^{PBC}_{jk} = {\vec q}\cdot{\vec r}_{jk} + 2\pi K$$

where $K = la + mb + nc$ is again an integer number. Consequently,

$$\mathrm{e}^{-i{\vec q}\cdot{\vec r}^{PBC}_{jk}} = \mathrm{e}^{-i{\vec q}\cdot{\vec r}_{jk}}$$