I am running a NVT TIP3P simulation of water with 125 molecules of water in a 16-by-16-16 angstrom box with periodic boundary conditions on LAMMPS, with a time-step of 1 fs for 10 ps.
Once the simulation runs, I extract the positions of these particles at each time-step into a .lammpstrj file, then process the data in python to evaluate the dipole moment of my ensemble.
To evaluate dielectric constant $\epsilon$, I will make use of the following relation: $$ \epsilon = 1+\frac{4\pi}{3k_bT} \left( \langle |M|^2\rangle-\langle |M| \rangle ^2 \right)$$
From classical electrodynamics, we know that $$\mathbf{M} = \sum_{i=1}^N q_i \mathbf{r}_i$$
My question is, can I still apply this formula to evaluate dipole moment when I have periodic boundary conditions? Because of periodic boundary conditions, one portion of a molecule might be on one side of the box, while the other portion is on the other side of the box, and this I think leads to artificially large fluctuations, because the molecules are flickering on the edge of the box.
Given the position and charge of each atom in your simulation with periodic boundary conditions, what is the most effective algorithm to evaluate the dielectric constant?