def read_trajectory(self, fn): """ Reads a trr-trajectory, resolves periodic boundary conditions with L{PbcResolver} and calculates internal coordinates. @param fn: filename of a gromacs trr trajectory. @return: L{InternalArray} """ required_atoms = set(sum([c.atoms for c in self], ())) atoms_start = min(required_atoms) atoms_end = max(required_atoms) + 1 f_trr = TrrFile(fn) (frames_x, frames_box) = f_trr.read_frames(atoms_start, atoms_end, read_boxes=True) f_trr.close() pbc = PbcResolver(frames_box) def dx_provider(atom1, atom2): ai = frames_x[:, atom1 - atoms_start, :] aj = frames_x[:, atom2 - atoms_start, :] return (pbc.rvec_sub(ai, aj)) array = np.column_stack([c.from_externals(dx_provider) for c in self]) return (InternalArray(self, array))
def main(): if(len(sys.argv) != 3): print("Takes a trr-trajectory and converts it into a mat-file for matlab.") print("Usage: trr2mat.py <trr-input-file> <mat-output-file>") sys.exit(1) trr_fn = sys.argv[1] mat_fn = sys.argv[2] print("Opening: %s"%trr_fn) f = TrrFile(trr_fn) data = f.read_frames() f.close() print("Loaded trr-file with shape: "+str(data.shape)) print("Writing: %s"%mat_fn) savemat(mat_fn, {"trr":data})
def read_trajectory(self, fn): """ Reads a trr-trajectory, resolves periodic boundary conditions with L{PbcResolver} and calculates internal coordinates. @param fn: filename of a gromacs trr trajectory. @return: L{InternalArray} """ required_atoms = set(sum([c.atoms for c in self], () )) atoms_start = min(required_atoms) atoms_end = max(required_atoms) + 1 f_trr = TrrFile(fn) (frames_x, frames_box) = f_trr.read_frames(atoms_start, atoms_end, read_boxes=True) f_trr.close() pbc = PbcResolver(frames_box) def dx_provider(atom1, atom2): ai = frames_x[:,atom1-atoms_start,:] aj = frames_x[:,atom2-atoms_start,:] return(pbc.rvec_sub(ai, aj)) array = np.column_stack([ c.from_externals(dx_provider) for c in self ]) return( InternalArray(self, array) )