amep.pbc.fold#

amep.pbc.fold(coords, box_boundary)#

Applies periodic boundary conditions to the given coordinates, i.e. folds the coordinates back into the box if they are not inside the box.

Parameters:
  • coords (np.ndarray) – Coordinate frame 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]]).

Returns:

base – Folded coordinate frame.

Return type:

np.ndarray

Examples

>>> import amep
>>> import numpy as np
>>> box_boundary = np.array([[-5,5],[-5,5],[-1,1]])
>>> unwrapped = np.array([[9,0,0], [-8,-3,0],[1,6,0],[0,-13,0]])
>>> center = np.zeros(3)
>>> fold = amep.pbc.fold(unwrapped, box_boundary)
>>> fig, axs = amep.plot.new(figsize=(3,3))
>>> amep.plot.box(axs, box_boundary, color='k', ls='--')
>>> colors = ['blue', 'green', 'gray', 'orange']
>>> for i,c in enumerate(colors):
...     axs.scatter(
...         unwrapped[i,0], unwrapped[i,1],
...         s=50, facecolors='none', edgecolors=c
...     )
...     axs.scatter(
...         fold[i,0], fold[i,1], s=50, facecolor=c
...     )
>>> axs.scatter(
...     -100, -100, s=50, facecolors='none',
...     edgecolors='k', label='unwrapped'
... )
>>> axs.scatter(
...     -100, -100, s=50, facecolors='k',
...     edgecolors='k', label='fold back'
... )
>>> axs.set_xlim(-10,10)
>>> axs.set_ylim(-15,10)
>>> axs.legend()
>>> axs.set_xlabel(r'$x$')
>>> axs.set_ylabel(r'$y$')
>>> fig.savefig('./figures/pbc/pbc-fold.png')
>>>
../_images/pbc-fold.png