MATLAB Examples

reorder_atom.m

  • This function reorders the atoms in an atom struct. Useful for creating
  • united-atom structures from all-atom structures, by simply ignoring the
  • non-polar H's from the original list of atoms. There can be multiple
  • molecules/residues in the atom struct but note that the script
  • assumes there is only one type.
  • atom ist the atom struct
  • atomlist is just a [1xn] array of n index numbers with a new order
  • Tested 01/11/2017
  • Please report bugs to michael.holmboe@umu.se

Contents

Examples

  • reorder_atom(atom,[1 3 4 5 6 7 8 10])
  • reorder_atom(atom,[27 26 23 20 17 14 11 8 5 1])
function atom = reorder_atom(atom,atomlist)

nResidues=max([atom.molid]); % How many residues do we have?
nResidueatoms_prev=sum([atom.molid]==1); % How many atoms per residue did we have initially?
nResidueatoms_current=length(atomlist); % How many atoms per residue did will we output?
nAtoms=length(atomlist)*nResidues; % How many atoms in total will we output? Can be lower than the initial number

newatom=atom(1:nAtoms); % Create an atom struct to overwrite
for i=1:nResidues
    newatom(1+(i-1)*nResidueatoms_current:i*nResidueatoms_current)=atom(atomlist+(i-1)*nResidueatoms_prev);
end

atom=newatom;

% Write the new structure to a .gro file
write_atom_gro(newatom,Box_dim,'reordered.gro')