cat_atom.m

filename='md_'
nSim=167;
atom0=import_atom(strcat(filename,'0.gro'));
traj=zeros(nSim,3*size(atom,2));
frame=zeros(1,3*size(atom,2));
All_Box_dim=zeros(nSim,9);
frames1=[0:nSim];frames2=[];%121:240];
frames=sort([frames1 frames2]);

% traj=zeros(70,3*size(atom,2));
% frame=zeros(1,3*size(atom,2));
% All_Box_dim=zeros(70,9);
% frames=[0:1:70];
n=0;
for i=[1:numel(frames)]
   i
   j=frames(i)
    try
        if j>240 % To add extra copies of the final frame
            n=240;
        else
            n=j;
        end
      atom=import_atom_gro(strcat(filename,num2str(n),'.gro'));
      tempnum=3*size(atom,2);
      Xdata=XYZ_data(:,1);
      Ydata=XYZ_data(:,2);

      Zdata=XYZ_data(:,3)-XYZ_data(1,3)+1; % Shift the lattice up a bit..
      Zdata(Zdata>Box_dim(3))=Zdata(Zdata>Box_dim(3))-Box_dim(3);
      Zdata(Zdata<0)=Zdata(Zdata<0)+Box_dim(3);

      frame(1:3:tempnum)=Xdata; %0;
      frame(2:3:tempnum)=Ydata;
      frame(3:3:tempnum)=Zdata;
      traj(j+1,1:tempnum)=frame(1,1:tempnum);
      All_Box_dim(j+1,1:numel(Box_dim))=Box_dim;
   catch
       disp('No frame')
   end
end

traj=traj(frames+1,:);
Box_dim=All_Box_dim(frames+1,:);
if sum(Box_dim(:,9))==0
    Box_dim=Box_dim(:,1:3);
else
    Box_dim=Box_dim;
end

write_gro_traj(atom0,traj,Box_dim,'3D_all.gro')