

Periodic boundary conditions are a common approach in molecular simulation to simulate large systems. This is achieved by considering our simulation box to be one of an infinite grid of identical copies. When atoms cross one side of the box, they reappear on the other side.
Visualising these simulations comes with certain challenges. The first of which is if a bond goes across one of the boundaries, it will instead take the long way around and stretch across the box. The second issue is the teleportation of atoms as they leave one side and reappear on the other.
When designing visualisation in virtual reality, we aim to minimise these discontinuities as they are jarring and unphysical.
Avoiding Overlong Bonds
We can address the issue of bond lengths by using the minimum image convention – if atom A is bonded to atom B, then we should consider it to be bonded to the closest copy of B, whether that be in the main unit cell or one of the neighbouring cells.


Though we no longer have bonds that stretch across the whole cell, we have a new issue — these bonds are now just pointing into empty space outside of the box. We would also expect that if a bond is now crossing over one boundary, it should then appear across the opposing side.
Duplicating Objects
When the atoms or bonds cross the boundaries, they should logically appear on the other side. Just as some of the shapes we are drawing are emerging out of our box, their virtual copies in neighbouring unit cells will start to enter. We therefore should duplicate any object crossing a boundary, and draw it again on the other side of the box.


Clipping Into The Box
While now we have all the objects that should lie in the box, they also stick out of the sides. We can prevent this by cropping them inside and only rendering the parts of each atom and bond that actually lie within the bounds of the box.


Bringing It Together
Altogether, this approach