[SciPy-User] Distance matrix with periodic boundary conditions
Wed Nov 17 10:12:39 CST 2010
I am trying to analyze some simulation results calculated with periodic
boundary conditions (PBC). Calculating the distance matrix between
particles is time consuming with python, and I wanted to use
scipy.spatial.distance.pdist. However I need to impose PBC, which means
that the vector between two particles has to be calculated like this:
r = r2 - r1
r = r - box*np.round(r/box)
where r1 and r2 are arrays with x,y,z positions of each pair of
particles. That needs to be corrected before calculating the distance
(the module of that vector).
I implemented the distance matrix calculation with cython and got
considerable speed-ups, but I wonder if I am reinventing the wheel and
this is already (better) implemented in some scipy module.
More information about the SciPy-User