amep.utils.in_circle#
- amep.utils.in_circle(coords: ndarray, radius: float, center: ndarray = array([0, 0, 0]), values: ndarray | None = None, reverse: bool = False, indices: bool = False) ndarray | tuple[ndarray, ndarray] #
Returns the coordinates/values for only particles inside or outside a circular/spherical region of a given radius and centered around a given center position.
- Parameters:
coords (np.ndarray) – Particle coordinates.
radius (float) – Radius of the spherical/circular region.
center (np.ndarray, optional) – Center of the region. The default is np.array([0,0,0]).
values (np.ndarray, optional) – Per-particle values/vectors to return. The default is None.
reverse (bool) – If True, particle values for particles outside the region are returned. The default is False.
indices (bool) – If True, particle indices are also returned. The default is False.
- Returns:
values (np.ndarray) – Values for particles in or outside the region.
ind (np.ndarray) – Particle indices.
Examples
>>> import amep >>> traj = amep.load.traj("../examples/data/lammps.h5amep") >>> frame = traj[-1] >>> center = frame.box.mean(axis=1) >>> R = 25 >>> inside, idxin = amep.utils.in_circle( ... frame.coords(), R, indices=True, center=center ... ) >>> outside, idxout = amep.utils.in_circle( ... frame.coords(), R, reverse=True, ... indices=True, center=center ... ) >>> 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) >>> angle = np.linspace(0, 2*np.pi, 150) >>> x = R*np.cos(angle) + center[0] >>> y = R*np.sin(angle) + center[1] >>> axs.plot(x, y, c='k', lw=2, marker='') >>> axs.set_xlabel(r'$x$') >>> axs.set_ylabel(r'$y$') >>> fig.savefig('./figures/utils/utils-in_circle.png') >>>