mdtraj.compute_neighbors¶
- mdtraj.compute_neighbors(traj, cutoff, query_indices, haystack_indices=None, periodic=True)¶
Find (spatially) neighboring atoms in a trajectory.
Given a set of query_indices representing and a distance cutoff, compute the indices of all atoms whose distance to 1 or more of the query points is less than cutoff.
- Parameters:
traj (md.Trajectory) – An MDTraj trajectory
cutoff (float) – Distance cutoff to define ‘neighboring’
query_indices (np.ndarray, shape=(n_query_indices,), dtype=int) – The matching atoms are those that are within cutoff of one or more of the atoms with indices in query_indices.
haystack_indices (np.ndarray, shape=(n_query_indices,), dtype=int, optional) – If supplied, restrict the search to only those atoms in haystack_indices.
periodic (bool) – If periodic is True and the trajectory contains unitcell information, we will compute distances under the minimum image convention.
- Returns:
matches – List of arrays, of length n_frames. Each item in the list is a 1D array of the indices of the matching atoms.
- Return type:
list of np.ndarray, shape=(n_matches,), dtype=int