OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
structure_analysis.py
Go to the documentation of this file.
1 """
2 Some functions for analyzing structures
3 
4 Author: Niklaus Johner (Niklaus.Johner@unibas.ch)
5 """
6 import os
7 import ost
8 
10  """
11  This function returns a CoordFrame from an EntityHandle
12 
13  :param eh:
14  :type eh: :class:`~ost.mol.EntityHandle`
15 
16  :return: :class:`ost.mol.CoordFrame`
17  """
18  return ost.mol.CreateCoordFrame(eh.GetAtomPosList(ordered_by_index=True))
19 
20 def GetDistanceBetwCenterOfMass(sele1,sele2):
21  """
22  This function calculates the distance between the centers of mass
23  of **sele1** and **sele2**, two selections from the same Entity.
24 
25  :param sele1:
26  :param sele2:
27  :type sele1: :class:`~ost.mol.EntityView`
28  :type sele2: :class:`~ost.mol.EntityView`
29 
30  :return: :class:`float`
31  """
32  if not sele1.IsValid() and sele2.IsValid():
33  print 'invalid view'
34  return
35  eh=sele1.GetHandle()
36  if not eh==sele2.GetHandle():
37  print 'The two views must be from the same entity'
38  return
39  f=GetFrameFromEntity(eh)
40  return f.GetDistanceBetwCenterOfMass(sele1,sele2)
41 
42 def GetMinDistanceBetweenViews(sele1,sele2):
43  """
44  This function calculates the minimal distance between
45  **sele1** and **sele2**, two selections from the same Entity.
46 
47  :param sele1:
48  :param sele2:
49  :type sele1: :class:`~ost.mol.EntityView`
50  :type sele2: :class:`~ost.mol.EntityView`
51 
52  :return: :class:`float`
53  """
54  if not sele1.IsValid() and sele2.IsValid():
55  print 'invalid view'
56  return
57  eh=sele1.GetHandle()
58  if not eh==sele2.GetHandle():
59  print 'The two views must be from the same entity'
60  return
61  f=GetFrameFromEntity(eh)
62  return f.GetMinDistance(sele1,sele2)
63 
65  """
66  This function calculates the minimal distance between **sele2** and
67  the center of mass of **sele1**, two selections from the same Entity.
68 
69  :param sele1: The selection from which the center of mass is taken
70  :param sele2:
71  :type sele1: :class:`~ost.mol.EntityView`
72  :type sele2: :class:`~ost.mol.EntityView`
73 
74  :return: distance (\ :class:`float`\ )
75  """
76  if not sele1.IsValid() and sele2.IsValid():
77  print 'invalid view'
78  return
79  eh=sele1.GetHandle()
80  if not eh==sele2.GetHandle():
81  print 'The two views must be from the same entity'
82  return
83  f=GetFrameFromEntity(eh)
84  return f.GetMinDistBetwCenterOfMassAndView(sele1,sele2)
85 
86 
88  """
89  This function calculates the content of alpha helix in a view.
90  All residues in the view have to ordered and adjacent (no gaps allowed)
91 
92  :param sele1:
93  :type sele1: :class:`~ost.mol.EntityView`
94 
95  :return: :class:`float`
96  """
97  if not sele1.IsValid():
98  print 'invalid view'
99  return
100  eh=sele1.GetHandle()
101  f=GetFrameFromEntity(eh)
102  return f.GetAlphaHelixContent(sele1)
103 
104 
106  """
107  This function calculates the best fit line to the atoms in **sele1**.
108 
109  :param sele1:
110  :type sele1: :class:`~ost.mol.EntityView`
111 
112  :return: :class:`~ost.geom.Line3`
113  """
114  if not sele1.IsValid():
115  print 'invalid view'
116  return
117  eh=sele1.GetHandle()
118  f=GetFrameFromEntity(eh)
119  return f.GetODRLine(sele1)
120 
122  """
123  This function calculates the best fit plane to the atoms in **sele1**.
124 
125  :param sele1:
126  :type sele1: :class:`~ost.mol.EntityView`
127 
128  :return: :class:`~ost.geom.Plane`
129  """
130  if not sele1.IsValid():
131  print 'invalid view'
132  return
133  eh=sele1.GetHandle()
134  f=GetFrameFromEntity(eh)
135  return f.GetODRPlane(sele1)
136 
138  """
139  This function calculates the best fit cylinder to the CA atoms in **sele1**,
140  and returns its axis. Residues should be ordered correctly
141  in **sele1**.
142 
143  :param sele1:
144  :type sele1: :class:`~ost.mol.EntityView`
145 
146  :return: :class:`~ost.geom.Line3`
147  """
148  if not sele1.IsValid():
149  print 'invalid view'
150  return
151  eh=sele1.GetHandle()
152  f=GetFrameFromEntity(eh)
153  return f.FitCylinder(sele1)
154 
155 
157  """
158  This function calculates the pairwise distance differences between two selections (\ :class:`~ost.mol.EntityView`\ ).
159  The two selections should have the same number of atoms
160  It returns an NxN DistanceDifferenceMatrix M (where N is the number of atoms in sele1)
161  where M[i,j]=||(sele2.atoms[i].pos-sele2.atoms[j].pos)||-||(sele1.atoms[i].pos-sele1.atoms[j].pos)||
162 
163  :param sele1:
164  :param sele2:
165  :type sele1: :class:`~ost.mol.EntityView`
166  :type sele2: :class:`~ost.mol.EntityView`
167 
168  :return: NxN numpy matrix
169  """
170  try:import numpy as npy
171  except ImportError:
172  LogError("Function needs numpy, but I could not import it.")
173  raise
174  if not sele1.IsValid() and sele2.IsValid():
175  print 'invalid view'
176  return
177  if not sele1.GetAtomCount()==sele2.GetAtomCount():
178  print 'The two views must have the same number of atoms'
179  return
180  n_atoms=sele1.GetAtomCount()
181  M=npy.zeros([n_atoms,n_atoms])
182  for i,a1 in enumerate(sele1.atoms):
183  for j,a2 in enumerate(sele2.atoms):
184  if i>=j:continue
185  d1=geom.Distance(a1.pos,a2.pos)
186  d2=geom.Distance(sele2.atoms[i].pos,sele2.atoms[j].pos)
187  M[i,j]=d2-d1
188  M[j,i]=d2-d1
189  return M
190 
191