closest_atom.m

Contents

Function arguments

Version

2.11

Contact

Please report problems/bugs to michael.holmboe@umu.se

Examples

  1. atom1 = closest_atom(atom1,atom2,Box_dim)
  2. atom1 = closest_atom(atom1,atom2,Box_dim,nMolId)
function atom1 = closest_atom(atom1,atom2,Box_dim,varargin)

atom1=update_atom(atom1);

if nargin==3
    nMolId=max([atom1.molid]);
else
    nMolId=varargin{1};
end

dist_matrix = dist_matrix_atom(atom1,atom2,Box_dim);

dist_tot=[];
for i=1:max([atom1.molid])
    dist_matrix_temp=dist_matrix([atom1.molid]==i,:);
    dist_ave=median(median(dist_matrix_temp));
    dist_tot=[dist_tot dist_ave];
end
[dist_tot,indMolId]=sort(dist_tot);
indMolId=indMolId(1:nMolId);

ind=[];
for i=1:numel(indMolId)
    ind=[ind find([atom1.molid]==indMolId(i))];
end

atom1=atom1(ind);

atom1=update_atom(atom1);