2 **This Module requires numpy**
4 This module contains functions to analyze trajectories, mainly
5 similiraty measures baed on RMSDS and pairwise distances.
7 Author: Niklaus Johner (niklaus.johner@unibas.ch)
12 from ost
import LogError
33 vec2[i]=v/float(count)
34 for i
in range(1,n+1):
44 vec2[-i]=v/float(count)
45 for i
in range(n,len(vec2)-n):
50 vec2[i]=v/float(2.*n+1.)
55 From here on the module needs numpy
60 This function calculates a matrix M such that M[i,j] is the
61 RMSD (calculated on **sele**) between frames i and j of the trajectory **t**
64 :param t: the trajectory
65 :param sele: the selection used for alignment and RMSD calculation
66 :param first: the first frame of t to be used
67 :param last: the last frame of t to be used
68 :type t: :class:`~ost.mol.CoordGroupHandle`
69 :type sele: :class:`~ost.mol.EntityView`
70 :type first: :class:`int`
71 :type last: :class:`int`
73 :return: Returns a numpy N\ :subscript:`frames`\ xN\ :subscript:`frames` matrix,
74 where N\ :subscript:`frames` is the number of frames.
78 if last==-1:last=t.GetFrameCount()
80 rmsd_matrix=npy.identity(n_frames)
81 for i
in range(n_frames):
91 LogError(
"Function needs numpy, but I could not import it.")
97 This function calculates the distances between any pair of atoms in **sele**
98 with sequence separation larger than **seq_sep** from a trajectory **t**.
99 It return a matrix containing one line for each atom pair and N\ :subscript:`frames` columns, where
100 N\ :subscript:`frames` is the number of frames in the trajectory.
102 :param t: the trajectory
103 :param sele: the selection used to determine the atom pairs
104 :param first: the first frame of t to be used
105 :param last: the last frame of t to be used
106 :param seq_sep: The minimal sequence separation between atom pairs
107 :type t: :class:`~ost.mol.CoordGroupHandle`
108 :type sele: :class:`~ost.mol.EntityView`
109 :type first: :class:`int`
110 :type last: :class:`int`
111 :type seq_sep: :class:`int`
113 :return: a numpy N\ :subscript:`pairs`\ xN\ :subscript:`frames` matrix.
117 if last==-1:last=t.GetFrameCount()
120 for i,a1
in enumerate(sele.atoms):
121 for j,a2
in enumerate(sele.atoms):
122 if not j-i<seq_sep:n_var+=1
125 dist_matrix=npy.zeros(n_frames*n_var)
126 dist_matrix=dist_matrix.reshape(n_var,n_frames)
128 for i,a1
in enumerate(sele.atoms):
129 for j,a2
in enumerate(sele.atoms):
130 if j-i<seq_sep:
continue
135 LogError(
"Function needs numpy, but I could not import it.")
140 This function calculates an distance matrix M(N\ :subscript:`frames`\ xN\ :subscript:`frames`\ ) from
141 the pairwise distances matrix D(N\ :subscript:`pairs`\ xN\ :subscript:`frames`\ ), where
142 N\ :subscript:`frames` is the number of frames in the trajectory
143 and N\ :subscript:`pairs` the number of atom pairs.
144 M[i,j] is the distance between frame i and frame j
145 calculated as a p-norm of the differences in distances
146 from the two frames (distance-RMSD for p=2).
148 :param distances: a pairwise distance matrix as obtained from
149 :py:func:`~mol.alg.trajectory_analysis.PairwiseDistancesFromTraj`
150 :param p: exponent used for the p-norm.
152 :return: a numpy N\ :subscript:`frames`\ xN\ :subscript:`frames` matrix, where N\ :subscript:`frames`
153 is the number of frames.
157 n1=distances.shape[0]
158 n2=distances.shape[1]
159 dist_mat=npy.identity(n2)
163 d=(((abs(distances[:,i]-distances[:,j])**p).sum())/float(n1))**(1./p)
168 LogError(
"Function needs numpy, but I could not import it.")
173 This function calculates the distance RMSD from a trajectory.
174 The distances selected for the calculation are all the distances
175 between pair of atoms from residues that are at least **seq_sep** apart
176 in the sequence and that are smaller than **radius** in **ref_sel**.
177 The number and order of atoms in **ref_sele** and **sele** should be the same.
179 :param t: the trajectory
180 :param sele: the selection used to calculate the distance RMSD
181 :param ref_sele: the reference selection used to determine the atom pairs and reference distances
182 :param radius: the upper limit of distances in ref_sele considered for the calculation
183 :param seq_sep: the minimal sequence separation between atom pairs considered for the calculation
184 :param average: use the average distance in the trajectory as reference instead of the distance obtained from ref_sele
185 :param first: the first frame of t to be used
186 :param last: the last frame of t to be used
188 :type t: :class:`~ost.mol.CoordGroupHandle`
189 :type sele: :class:`~ost.mol.EntityView`
190 :type ref_sele: :class:`~ost.mol.EntityView`
191 :type radius: :class:`float`
192 :type average: :class:`bool`
193 :type first: :class:`int`
194 :type last: :class:`int`
195 :type seq_sep: :class:`int`
197 :return: a numpy vecor dist_rmsd(N\ :subscript:`frames`).
199 if not sele.GetAtomCount()==ref_sele.GetAtomCount():
200 print 'Not same number of atoms in the two views'
204 if last==-1:last=t.GetFrameCount()
206 dist_rmsd=npy.zeros(n_frames)
208 for i,a1
in enumerate(ref_sele.atoms):
209 for j,a2
in enumerate(ref_sele.atoms):
215 if c1==c2
and abs(r2.GetNumber().num-r1.GetNumber().num)<seq_sep:
continue
216 d=ost.geom.Distance(a1.pos,a2.pos)
221 if average:d=npy.mean(d_traj)
222 for k,el
in enumerate(d_traj):
223 dist_rmsd[k]+=(el-d)**2.0
225 return (dist_rmsd/float(pair_count))**0.5
227 LogError(
"Function needs numpy, but I could not import it.")
232 This function calcultes the distance between each pair of atoms
233 in **sele**, averaged over the trajectory **t**.
235 :param t: the trajectory
236 :param sele: the selection used to determine the atom pairs
237 :param first: the first frame of t to be used
238 :param last: the last frame of t to be used
239 :type t: :class:`~ost.mol.CoordGroupHandle`
240 :type sele: :class:`~ost.mol.EntityView`
241 :type first: :class:`int`
242 :type last: :class:`int`
244 :return: a numpy N\ :subscript:`pairs`\ xN\ :subscript:`pairs` matrix, where N\ :subscript:`pairs`
245 is the number of atom pairs in **sele**.
250 LogError(
"Function needs numpy, but I could not import it.")
252 n_atoms=sele.GetAtomCount()
253 M=npy.zeros([n_atoms,n_atoms])
254 for i,a1
in enumerate(sele.atoms):
255 for j,a2
in enumerate(sele.atoms):