translate_atom.m

Contents

Version

2.11

Contact

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

Examples

  1. atom = translate_molid(atom,[x y z]) % Basic input variables
  2. atom = translate_molid(atom,[x y z],'all') % Will translate 'all'
  3. atom = translate_molid(atom,[x y z],'SOL') % Will only translate the resname SOL
function atom = translate_atom(atom,trans_vec,varargin)

nAtoms=size([atom.x],2);

if nargin>2
    Resname=varargin(1);
else
    Resname='all';
end

if strcmp(Resname,'all')
    ind_resname=1:nAtoms;
elseif strcmp(Resname,'All')
    ind_resname=1:nAtoms;
elseif strcmp(Resname,'ALL')
    ind_resname=1:nAtoms;
else
    ind_resname=find(strcmpi([atom.resname],Resname));
end

if size(trans_vec,1)==1
    x_shift=num2cell([atom(ind_resname).x]+trans_vec(1)); [atom(ind_resname).x]=deal(x_shift{:});

    y_shift=num2cell([atom(ind_resname).y]+trans_vec(2)); [atom(ind_resname).y]=deal(y_shift{:});

    z_shift=num2cell([atom(ind_resname).z]+trans_vec(3)); [atom(ind_resname).z]=deal(z_shift{:});
else
    x_shift=num2cell([atom(ind_resname).x]+trans_vec(:,1)');[atom(ind_resname).x]=deal(x_shift{:});

    y_shift=num2cell([atom(ind_resname).y]+trans_vec(:,2)'); [atom(ind_resname).y]=deal(y_shift{:});

    z_shift=num2cell([atom(ind_resname).z]+trans_vec(:,3)'); [atom(ind_resname).z]=deal(z_shift{:});
end

% assignin('caller','atom',atom);
assignin('caller','XYZ_data',[[atom.x]' [atom.y]' [atom.z]']);
assignin('caller','XYZ_labels',[atom.type]');