code: def reorder_distance(p_atoms, q_atoms, p_coord, q_coord):
      
  
      # Find unique atoms
      unique_atoms = np.unique(p_atoms)
  
      # generate full view from q shape to fill in atom view on the fly
      view_reorder = np.zeros(q_atoms.shape, dtype=int)
  
      for atom in unique_atoms:
  
          p_atom_idx, = np.where(p_atoms == atom)
          q_atom_idx, = np.where(q_atoms == atom)
  
          A_coord = p_coord[p_atom_idx]
          B_coord = q_coord[q_atom_idx]
  
          # Calculate distance from each atom to centroid
          A_norms = np.linalg.norm(A_coord, axis=1)
          B_norms = np.linalg.norm(B_coord, axis=1)
  
          reorder_indices_A = np.argsort(A_norms)
          reorder_indices_B = np.argsort(B_norms)
  
          # Project the order of P onto Q
          translator = np.argsort(reorder_indices_A)
          view = reorder_indices_B[translator]
          view_reorder[p_atom_idx] = q_atom_idx[view]
  
      return view_reorder
docs: Re-orders the input atom list and xyz coordinates by atom type and then by
      distance of each atom from the centroid.
  
      Parameters
      ----------
      atoms : array
          (N,1) matrix, where N is points holding the atoms' names
      coord : array
          (N,D) matrix, where N is points and D is dimension
  
      Returns
      -------
      atoms_reordered : array
          (N,1) matrix, where N is points holding the ordered atoms' names
      coords_reordered : array
          (N,D) matrix, where N is points and D is dimension (rows re-ordered)