diff --git a/modules/mol/alg/pymod/trajectory_analysis.py b/modules/mol/alg/pymod/trajectory_analysis.py index 5e8c452b74c43fbf15247a4da70dd8c613d6a846..c236032051edd9eee2069f02c26eb3f5b71f5532 100644 --- a/modules/mol/alg/pymod/trajectory_analysis.py +++ b/modules/mol/alg/pymod/trajectory_analysis.py @@ -4,7 +4,8 @@ Some functions for analyzing trajectories Author: Niklaus Johner """ -from ost import * +import ost.mol.alg +from ost import LogError import os def smooth(vec,n): @@ -46,3 +47,38 @@ def smooth(vec,n): return vec2 +""" +From here on the module needs numpy +""" + +def RMSD_Matrix_From_Traj(t,sele,first=0,last=-1): + """ + This function calculates a matrix M such that M[i,j] is the + RMSD of the EntityView sele between frames i and j of the trajectory t + aligned on sele. + Its inputs are: + t : the trajectory (CoordGroupHandle) + sele : the EntityView used for alignment and RMSD calculation + first=0 : the first frame of t to be used + last=-1 : the last frame of t to be used + Returns a numpy NxN matrix, where n is the number of frames. + """ + try: + import numpy as npy + if last==-1:last=t.GetFrameCount() + n_frames=last-first + rmsd_matrix=npy.identity(n_frames) + for i in range(n_frames): + t=ost.mol.alg.SuperposeFrames(t,sele,begin=first,end=last,ref=i) + eh=t.GetEntity() + t.CopyFrame(i) + rmsd_matrix[i,:]=ost.mol.alg.AnalyzeRMSD(t,sele,sele) + if i==0: + last=last-first + first=0 + return rmsd_matrix + except ImportError: + LogError("Function needs numpy, but I could not import it.") + raise + +