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.
76 if not align_sele:align_sele=sele
79 if last==-1:last=t.GetFrameCount()
81 rmsd_matrix=npy.identity(n_frames)
82 for i
in range(n_frames):
93 LogError(
"Function needs numpy, but I could not import it.")
99 This function calculates the distances between any pair of atoms in **sele**
100 with sequence separation larger than **seq_sep** from a trajectory **t**.
101 It return a matrix containing one line for each atom pair and N\\ :subscript:`frames` columns, where
102 N\\ :subscript:`frames` is the number of frames in the trajectory.
104 :param t: the trajectory
105 :param sele: the selection used to determine the atom pairs
106 :param first: the first frame of t to be used
107 :param last: the last frame of t to be used
108 :param seq_sep: The minimal sequence separation between atom pairs
109 :type t: :class:`~ost.mol.CoordGroupHandle`
110 :type sele: :class:`~ost.mol.EntityView`
111 :type first: :class:`int`
112 :type last: :class:`int`
113 :type seq_sep: :class:`int`
115 :return: a numpy N\\ :subscript:`pairs`\\ xN\\ :subscript:`frames` matrix.
119 if last==-1:last=t.GetFrameCount()
122 for i,a1
in enumerate(sele.atoms):
123 for j,a2
in enumerate(sele.atoms):
124 if not j-i<seq_sep:n_var+=1
127 dist_matrix=npy.zeros(n_frames*n_var)
128 dist_matrix=dist_matrix.reshape(n_var,n_frames)
130 for i,a1
in enumerate(sele.atoms):
131 for j,a2
in enumerate(sele.atoms):
132 if j-i<seq_sep:
continue
137 LogError(
"Function needs numpy, but I could not import it.")
142 This function calculates an distance matrix M(N\\ :subscript:`frames`\\ xN\\ :subscript:`frames`\\ ) from
143 the pairwise distances matrix D(N\\ :subscript:`pairs`\\ xN\\ :subscript:`frames`\\ ), where
144 N\\ :subscript:`frames` is the number of frames in the trajectory
145 and N\\ :subscript:`pairs` the number of atom pairs.
146 M[i,j] is the distance between frame i and frame j
147 calculated as a p-norm of the differences in distances
148 from the two frames (distance-RMSD for p=2).
150 :param distances: a pairwise distance matrix as obtained from
151 :py:func:`~mol.alg.trajectory_analysis.PairwiseDistancesFromTraj`
152 :param p: exponent used for the p-norm.
154 :return: a numpy N\\ :subscript:`frames`\\ xN\\ :subscript:`frames` matrix, where N\\ :subscript:`frames`
155 is the number of frames.
159 n1=distances.shape[0]
160 n2=distances.shape[1]
161 dist_mat=npy.identity(n2)
165 d=(((abs(distances[:,i]-distances[:,j])**p).sum())/float(n1))**(1./p)
170 LogError(
"Function needs numpy, but I could not import it.")
175 This function calculates the distance RMSD from a trajectory.
176 The distances selected for the calculation are all the distances
177 between pair of atoms from residues that are at least **seq_sep** apart
178 in the sequence and that are smaller than **radius** in **ref_sel**.
179 The number and order of atoms in **ref_sele** and **sele** should be the same.
181 :param t: the trajectory
182 :param sele: the selection used to calculate the distance RMSD
183 :param ref_sele: the reference selection used to determine the atom pairs and reference distances
184 :param radius: the upper limit of distances in ref_sele considered for the calculation
185 :param seq_sep: the minimal sequence separation between atom pairs considered for the calculation
186 :param average: use the average distance in the trajectory as reference instead of the distance obtained from ref_sele
187 :param first: the first frame of t to be used
188 :param last: the last frame of t to be used
190 :type t: :class:`~ost.mol.CoordGroupHandle`
191 :type sele: :class:`~ost.mol.EntityView`
192 :type ref_sele: :class:`~ost.mol.EntityView`
193 :type radius: :class:`float`
194 :type average: :class:`bool`
195 :type first: :class:`int`
196 :type last: :class:`int`
197 :type seq_sep: :class:`int`
199 :return: a numpy vecor dist_rmsd(N\\ :subscript:`frames`).
201 if not sele.GetAtomCount()==ref_sele.GetAtomCount():
202 print(
'Not same number of atoms in the two views')
206 if last==-1:last=t.GetFrameCount()
208 dist_rmsd=npy.zeros(n_frames)
210 for i,a1
in enumerate(ref_sele.atoms):
211 for j,a2
in enumerate(ref_sele.atoms):
217 if c1==c2
and abs(r2.GetNumber().num-r1.GetNumber().num)<seq_sep:
continue
218 d=ost.geom.Distance(a1.pos,a2.pos)
223 if average:d=npy.mean(d_traj)
224 for k,el
in enumerate(d_traj):
225 dist_rmsd[k]+=(el-d)**2.0
227 return (dist_rmsd/float(pair_count))**0.5
229 LogError(
"Function needs numpy, but I could not import it.")
234 This function calcultes the distance between each pair of atoms
235 in **sele**, averaged over the trajectory **t**.
237 :param t: the trajectory
238 :param sele: the selection used to determine the atom pairs
239 :param first: the first frame of t to be used
240 :param last: the last frame of t to be used
241 :type t: :class:`~ost.mol.CoordGroupHandle`
242 :type sele: :class:`~ost.mol.EntityView`
243 :type first: :class:`int`
244 :type last: :class:`int`
246 :return: a numpy N\\ :subscript:`pairs`\\ xN\\ :subscript:`pairs` matrix, where N\\ :subscript:`pairs`
247 is the number of atom pairs in **sele**.
252 LogError(
"Function needs numpy, but I could not import it.")
254 n_atoms=sele.GetAtomCount()
255 M=npy.zeros([n_atoms,n_atoms])
256 for i,a1
in enumerate(sele.atoms):
257 for j,a2
in enumerate(sele.atoms):
268 LogError(
"Function needs numpy, but I could not import it.")
270 n_atoms=sele.GetAtomCount()
271 M=npy.zeros([n_atoms,n_atoms])
272 for i,a1
in enumerate(sele.atoms):
273 for j,a2
in enumerate(sele.atoms):
281 if initial_sele:current_sele=initial_sele
282 else: current_sele=sele
283 for i
in range(iterations):
287 current_sele=ost.mol.CreateViewFromAtoms(al)
def IterativeSuperposition
def DistanceMatrixFromPairwiseDistances
Real DLLEXPORT_OST_MOL_ALG AnalyzeRMSF(const CoordGroupHandle &traj, const EntityView &selection, int from=0, int to=-1, unsigned int stride=1)
CoordGroupHandle DLLEXPORT_OST_MOL_ALG SuperposeFrames(CoordGroupHandle &cg, EntityView &sel, EntityView &ref_view, int begin=0, int end=-1)
returns a superposed version of coord group, superposed on a reference view
std::vector< Real > DLLEXPORT_OST_MOL_ALG AnalyzeRMSD(const CoordGroupHandle &traj, const EntityView &reference_view, const EntityView &sele, unsigned int stride=1)
def PairwiseDistancesFromTraj
def RMSD_Matrix_From_Traj
std::vector< Real > DLLEXPORT_OST_MOL_ALG AnalyzeDistanceBetwAtoms(const CoordGroupHandle &traj, const AtomHandle &a1, const AtomHandle &a2, unsigned int stride=1)
def AverageDistanceMatrixFromTraj
def AnalyzeDistanceFluctuationMatrix