2 Some functions for analyzing trajectories
9 from ost
import LogError
30 vec2[i]=v/float(count)
31 for i
in range(1,n+1):
41 vec2[-i]=v/float(count)
42 for i
in range(n,len(vec2)-n):
47 vec2[i]=v/float(2.*n+1.)
52 From here on the module needs numpy
57 This function calculates a matrix M such that M[i,j] is the
58 RMSD of the EntityView sele between frames i and j of the trajectory t
61 t : the trajectory (CoordGroupHandle)
62 sele : the EntityView used for alignment and RMSD calculation
63 first=0 : the first frame of t to be used
64 last=-1 : the last frame of t to be used
65 Returns a numpy NxN matrix, where n is the number of frames.
69 if last==-1:last=t.GetFrameCount()
71 rmsd_matrix=npy.identity(n_frames)
72 for i
in range(n_frames):
82 LogError(
"Function needs numpy, but I could not import it.")
88 This function calculates the distances between any pair of atoms in the
89 EntityView sele with sequence separation larger than seq_sep from a trajectory t.
90 It return a matrix containing one line for each atom pair and N columns, where
91 N is the length of the trajectory.
93 t : the trajectory (CoordGroupHandle)
94 sele : the EntityView used to determine the atom pairs
95 first=0 : the first frame of t to be used
96 last=-1 : the last frame of t to be used
97 seq_sep=1 : The minimal sequence separation between
98 Returns a numpy NpairsxNframes matrix.
102 if last==-1:last=t.GetFrameCount()
105 for i,a1
in enumerate(sele.atoms):
106 for j,a2
in enumerate(sele.atoms):
107 if not j-i<seq_sep:n_var+=1
110 dist_matrix=npy.zeros(n_frames*n_var)
111 dist_matrix=dist_matrix.reshape(n_var,n_frames)
113 for i,a1
in enumerate(sele.atoms):
114 for j,a2
in enumerate(sele.atoms):
115 if j-i<seq_sep:
continue
120 LogError(
"Function needs numpy, but I could not import it.")
125 This function calculates an distance matrix M(NxN) from
126 the pairwise distances matrix D(MxN), where N is the number
127 of frames in the trajectory and M the number of atom pairs.
128 M[i,j] is the distance between frame i and frame j
129 calculated as a p-norm of the differences in distances
130 from the two frames (distance-RMSD for p=2).
132 distances : a pairwise distance matrix as obtained from PairwiseDistancesFromTraj()
133 Returns a numpy NxN matrix, where N is the number of frames.
137 n1=distances.shape[0]
138 n2=distances.shape[1]
139 dist_mat=npy.identity(n2)
143 d=(((abs(distances[:,i]-distances[:,j])**p).sum())/float(n1))**(1./p)
148 LogError(
"Function needs numpy, but I could not import it.")
153 This function calculates the distance RMSD from a trajectory.
154 The distances selected for the calculation are all the distances
155 between pair of atoms that from residues that are at least seq_sep apart
156 in the sequence and that are smaller than radius in ref_sel.
157 The number and order of atoms in ref_sele and sele should be the same.
159 t : the trajectory (CoordGroupHandle)
160 sele : the EntityView used to determine the distances from t
161 radius=7 : the upper limit of distances in ref_sele considered for the calculation
162 seq_sep=4 : The minimal sequence separation between atom pairs considered for the calculation
163 average=false : use the average distance in the trajectory as reference instead of the distance obtained from ref_sele
164 first=0 : the first frame of t to be used
165 last=-1 : the last frame of t to be used
166 Returns a numpy vecor dist_rmsd(Nframes).
168 if not sele.GetAtomCount()==ref_sele.GetAtomCount():
169 print 'Not same number of atoms in the two views'
173 if last==-1:last=t.GetFrameCount()
175 dist_rmsd=npy.zeros(n_frames)
177 for i,a1
in enumerate(ref_sele.atoms):
178 for j,a2
in enumerate(ref_sele.atoms):
184 if c1==c2
and abs(r2.GetNumber().num-r1.GetNumber().num)<seq_sep:
continue
185 d=ost.geom.Distance(a1.pos,a2.pos)
190 if average:d=npy.mean(d_traj)
191 for k,el
in enumerate(d_traj):
192 dist_rmsd[k]+=(el-d)**2.0
194 return (dist_rmsd/float(pair_count))**0.5
196 LogError(
"Function needs numpy, but I could not import it.")