amep.pbc.distance_matrix#

amep.pbc.distance_matrix(coords: ndarray, box_boundary: ndarray, other: ndarray | None = None, pbc: bool = True, maxdist: float = 1.122) ndarray#

Calculates the distance matrix. Distances larger than maxdist are ignored and set to zero in the distance matrix. Note that this method requires a large amount of RAM. If there is not enough RAM available, use the amep.pbc.distance_matrix_parallel method.

Parameters:
  • coords (numpy.ndarray) – Coordinates of the particles as array of shape (N,3).

  • box_boundary (np.ndarray of shape (3,2)) – Boundary of the simulation box in the form of np.array([[xmin, xmax], [ymin, ymax], [zmin, zmax]]).

  • other (numpy.ndarray, optional) – Other coordinates to which the pairwise distances are calculated as array of shape (N_other,3). If None, coords is used. The default is None.

  • pbc (bool, optional) – If True, periodic boundary conditions are considered. The default is True.

  • maxdist (float, optional) – Maxmimum distance to consider. Always use the smallest suitable value saves a lot computation time. The default is 1.122.

Returns:

d – Distance matrix of shape (N,N_other).

Return type:

np.ndarray

Examples

Create a simple test setup:

>>> import amep
>>> import numpy as np
>>> coords = np.array([[1,0,0], [4,0,0], [-2,0,0], [4.5,0,0]])
>>> box_boundary = np.array([[-5,5],[-5,5],[-0.5,0.5]])
>>> box = box_boundary[:,1] - box_boundary[:,0]
>>> fig, axs = amep.plot.new(figsize=(3,3))
>>> axs.grid(visible=True)
>>> amep.plot.particles(axs, coords, box_boundary, 0.25)
>>> amep.plot.box(axs, box_boundary)
>>> axs.set_xlabel(r'$x$')
>>> axs.set_ylabel(r'$y$')
>>> fig.savefig('./figures/pbc/pbc-distance_matrix.png')
>>>
../_images/pbc-distance_matrix.png

Calculate the distance matrix without periodic boundary conditions:

>>> D = amep.pbc.distance_matrix(
...     coords, box_boundary, pbc=False, maxdist=5
... )
>>> print(D)
[[0.  3.  3.  3.5]
 [3.  0.  0.  0.5]
 [3.  0.  0.  0. ]
 [3.5 0.5 0.  0. ]]
>>>

Calculate the distance matrix with periodic boundary conditions:

>>> D = amep.pbc.distance_matrix(
...     coords, box_boundary, pbc=True, maxdist=5
... )
>>> print(D)
[[0.  3.  3.  3.5]
 [3.  0.  4.  0.5]
 [3.  4.  0.  3.5]
 [3.5 0.5 3.5 0. ]]
>>>

Calculate the distance matrix for other_coords:

>>> D = amep.pbc.distance_matrix(
...     coords, box_boundary, other=coords[:2],
...     pbc=True, maxdist=5
... )
>>> print(D)
[[0.  3. ]
 [3.  0. ]
 [3.  4. ]
 [3.5 0.5]]
>>>