import_trr.m
- This function imports an trr file using Evan's scripts, see below
- This function uses trr2matlab + readGmx2Matlab to read gromacs .trr trajectory files
- into the variable 'traj'. Note that trr2matlab can output both coordinates, velocities and forces
- if they exist in the .trr file
- Please report problems/bugs to michael.holmboe@umu.se
- Can varargin be used for stride?
Contents
Examples
- traj = import_trr(traj.trr)
- traj = import_trr(traj.trr,varargin)
function traj = import_trrv2(filenametrr,varargin)
disp('Found .trr file, will use the Evans excellent readGmx2Matlab and trr2matlab functions');
disp('See http://se.mathworks.com/matlabcentral/fileexchange/33312-convert-gromacs-v-4-5-trajectory-files-into-matlab-matrix')
disp(' ')
disp(' ')
disp('Note that in princple both coords, velocities, forces could be imported, and that stride can be used')
disp('Look into Evans readGmx2Matlab and trr2matlab functions for options')
writeX=0;writeV=0;writeF=0;
if nargin==1
trr2matlab(filenametrr,'x');
else
evalstr=eval("strcat('trr2matlab(filenametrr')");
if sum(strcmp(varargin, 'x')) > 0
x='''x''';
evalstr=eval("strcat(evalstr,'comma',x)");
writeX = true;
end
if sum(strcmp(varargin, 'v')) > 0
v='''v''';
evalstr=eval("strcat(evalstr,'comma',v)");
writeV = true;
end
if sum(strcmp(varargin, 'f')) > 0
f='''f''';
evalstr=eval("strcat(evalstr,'comma',f)");
writeF = true;
end
evalstr=strcat(evalstr,')');
evalstr=strrep(evalstr,'comma',',');
eval(evalstr);
end
if (writeX+writeV+writeF)==0
[trj] = readGmx2Matlab('xdata.binary');
nAtoms=trj.num_atoms;
nFrames=trj.num_frames;
timestep=trj.time_step;
xdata=(reshape(trj.trajectory(:,1,:)*10,nAtoms,nFrames)).';
ydata=(reshape(trj.trajectory(:,2,:)*10,nAtoms,nFrames)).';
zdata=(reshape(trj.trajectory(:,3,:)*10,nAtoms,nFrames)).';
traj=zeros(size(xdata,1),size(xdata,2)*3);
traj(:,1:3:end)=xdata;
traj(:,2:3:end)=ydata;
traj(:,3:3:end)=zdata;
delete('./#*'); delete('./temp*');
assignin('caller','traj',traj)
delete('./#*'); delete('./temp*');
end
if writeF>0
[trj] = readGmx2Matlab('fdata.binary');
nAtoms=trj.num_atoms;
nFrames=trj.num_frames;
timestep=trj.time_step;
fxdata=(reshape(trj.trajectory(:,1,:)*10,nAtoms,nFrames)).';
fydata=(reshape(trj.trajectory(:,2,:)*10,nAtoms,nFrames)).';
fzdata=(reshape(trj.trajectory(:,3,:)*10,nAtoms,nFrames)).';
ftraj=zeros(size(fxdata,1),size(fxdata,2)*3);
ftraj(:,1:3:end)=fxdata;
ftraj(:,2:3:end)=fydata;
ftraj(:,3:3:end)=fzdata;
delete('./#*'); delete('./temp*');
assignin('caller','ftraj',ftraj);
end
if writeV>0
[trj] = readGmx2Matlab('vdata.binary');
nAtoms=trj.num_atoms;
nFrames=trj.num_frames;
timestep=trj.time_step;
vxdata=(reshape(trj.trajectory(:,1,:)*10,nAtoms,nFrames)).';
vydata=(reshape(trj.trajectory(:,2,:)*10,nAtoms,nFrames)).';
vzdata=(reshape(trj.trajectory(:,3,:)*10,nAtoms,nFrames)).';
vtraj=zeros(size(vxdata,1),size(vxdata,2)*3);
vtraj(:,1:3:end)=vxdata;
vtraj(:,2:3:end)=vydata;
vtraj(:,3:3:end)=vzdata;
delete('./#*'); delete('./temp*');
assignin('caller','vtraj',vtraj);
end
if writeX>0
[trj] = readGmx2Matlab('xdata.binary');
nAtoms=trj.num_atoms;
nFrames=trj.num_frames;
timestep=trj.time_step;
xdata=(reshape(trj.trajectory(:,1,:)*10,nAtoms,nFrames)).';
ydata=(reshape(trj.trajectory(:,2,:)*10,nAtoms,nFrames)).';
zdata=(reshape(trj.trajectory(:,3,:)*10,nAtoms,nFrames)).';
traj=zeros(size(xdata,1),size(xdata,2)*3);
traj(:,1:3:end)=xdata;
traj(:,2:3:end)=ydata;
traj(:,3:3:end)=zdata;
delete('./#*'); delete('./temp*');
assignin('caller','traj',traj);
end
clear trj
trj.nAtoms=nAtoms;
trj.nFrames=nFrames;
trj.timestep=timestep;
assignin('caller','trj',trj);
assignin('caller','Box_dim',Box_dim);