amep.utils.in_box#

amep.utils.in_box(coords: ndarray, box_boundary: ndarray, values: ndarray | None = None, reverse: bool = False, indices: bool = False) ndarray#

Returns all coordinates in coords that are in the given simulation box boundaries (including the boundary).

Parameters:
  • coords (np.ndarray) – Coordinate frame.

  • 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]]).

  • values (np.ndarray, optional) – Array of shape (N,p), where N is the number of particles and p the number of values per particle. The default is None.

  • reverse (bool, optional) – If True, coordinates outside the specified region are returned. The default is False.

  • indices (bool, optional) – If True, also particle indices are returned. The default is False.

Returns:

  • values (np.ndarray) – Values inside the box.

  • ind (np.ndarray) – Particle indices inside the box (only if indices is True).

Examples

>>> import amep
>>> traj = amep.load.traj("../examples/data/lammps.h5amep")
>>> frame = traj[-1]
>>> box = np.array([[40, 60], [40, 60], [-0.5, 0.5]])
>>> inside, idxin = amep.utils.in_box(
...     frame.coords(), box, indices=True
... )
>>> outside, idxout = amep.utils.in_box(
...     frame.coords(), box, reverse=True, indices=True
... )
>>> fig, axs = amep.plot.new(figsize=(3,3))
>>> amep.plot.particles(
...     axs, inside, frame.box, frame.radius()[idxin],
...     set_ax_limits = False, color='orange'
... )
>>> amep.plot.particles(
...     axs, outside, frame.box, frame.radius()[idxout],
...     set_ax_limits = False
... )
>>> amep.plot.box(axs, frame.box)
>>> amep.plot.box(axs, box)
>>> axs.set_xlabel(r'$x$')
>>> axs.set_ylabel(r'$y$')
>>> fig.savefig('./figures/utils/utils-in_box.png')
>>>
../_images/utils-in_box.png