py-packman 1.4.0__zip

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. Program Files/Python39/Lib/site-packages/packman/__init__.py +18 -0
  2. Program Files/Python39/Lib/site-packages/packman/__main__.py +4 -0
  3. Program Files/Python39/Lib/site-packages/packman/__pycache__/__init__.cpython-39.pyc +0 -0
  4. Program Files/Python39/Lib/site-packages/packman/__pycache__/__main__.cpython-39.pyc +0 -0
  5. Program Files/Python39/Lib/site-packages/packman/anm/__init__.py +25 -0
  6. Program Files/Python39/Lib/site-packages/packman/anm/__pycache__/__init__.cpython-39.pyc +0 -0
  7. Program Files/Python39/Lib/site-packages/packman/anm/__pycache__/anm.cpython-39.pyc +0 -0
  8. Program Files/Python39/Lib/site-packages/packman/anm/__pycache__/hd_anm.cpython-39.pyc +0 -0
  9. Program Files/Python39/Lib/site-packages/packman/anm/anm.py +317 -0
  10. Program Files/Python39/Lib/site-packages/packman/anm/hd_anm.py +656 -0
  11. Program Files/Python39/Lib/site-packages/packman/apps/__init__.py +25 -0
  12. Program Files/Python39/Lib/site-packages/packman/apps/__pycache__/__init__.cpython-39.pyc +0 -0
  13. Program Files/Python39/Lib/site-packages/packman/apps/__pycache__/calculate_entropy.cpython-39.pyc +0 -0
  14. Program Files/Python39/Lib/site-packages/packman/apps/__pycache__/dci.cpython-39.pyc +0 -0
  15. Program Files/Python39/Lib/site-packages/packman/apps/__pycache__/hdanm.cpython-39.pyc +0 -0
  16. Program Files/Python39/Lib/site-packages/packman/apps/__pycache__/predict_hinge.cpython-39.pyc +0 -0
  17. Program Files/Python39/Lib/site-packages/packman/apps/calculate_entropy.py +60 -0
  18. Program Files/Python39/Lib/site-packages/packman/apps/dci.py +323 -0
  19. Program Files/Python39/Lib/site-packages/packman/apps/hdanm.py +47 -0
  20. Program Files/Python39/Lib/site-packages/packman/apps/predict_hinge.py +375 -0
  21. Program Files/Python39/Lib/site-packages/packman/bin/GUI.py +709 -0
  22. Program Files/Python39/Lib/site-packages/packman/bin/PACKMAN.py +154 -0
  23. Program Files/Python39/Lib/site-packages/packman/bin/__init__.py +27 -0
  24. Program Files/Python39/Lib/site-packages/packman/bin/__pycache__/GUI.cpython-39.pyc +0 -0
  25. Program Files/Python39/Lib/site-packages/packman/bin/__pycache__/PACKMAN.cpython-39.pyc +0 -0
  26. Program Files/Python39/Lib/site-packages/packman/bin/__pycache__/__init__.cpython-39.pyc +0 -0
  27. Program Files/Python39/Lib/site-packages/packman/bin/logo.ico +0 -0
  28. Program Files/Python39/Lib/site-packages/packman/constants/Constants.py +236 -0
  29. Program Files/Python39/Lib/site-packages/packman/constants/__init__.py +3 -0
  30. Program Files/Python39/Lib/site-packages/packman/constants/__pycache__/Constants.cpython-39.pyc +0 -0
  31. Program Files/Python39/Lib/site-packages/packman/constants/__pycache__/__init__.cpython-39.pyc +0 -0
  32. Program Files/Python39/Lib/site-packages/packman/entropy/__init__.py +12 -0
  33. Program Files/Python39/Lib/site-packages/packman/entropy/__pycache__/__init__.cpython-39.pyc +0 -0
  34. Program Files/Python39/Lib/site-packages/packman/entropy/__pycache__/entropy.cpython-39.pyc +0 -0
  35. Program Files/Python39/Lib/site-packages/packman/entropy/entropy.py +155 -0
  36. Program Files/Python39/Lib/site-packages/packman/geometry/__init__.py +17 -0
  37. Program Files/Python39/Lib/site-packages/packman/geometry/__pycache__/__init__.cpython-39.pyc +0 -0
  38. Program Files/Python39/Lib/site-packages/packman/geometry/__pycache__/geometry.cpython-39.pyc +0 -0
  39. Program Files/Python39/Lib/site-packages/packman/geometry/geometry.py +112 -0
  40. Program Files/Python39/Lib/site-packages/packman/molecule/__init__.py +45 -0
  41. Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/__init__.cpython-39.pyc +0 -0
  42. Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/annotations.cpython-39.pyc +0 -0
  43. Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/atom.cpython-39.pyc +0 -0
  44. Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/bond.cpython-39.pyc +0 -0
  45. Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/chain.cpython-39.pyc +0 -0
  46. Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/hetmol.cpython-39.pyc +0 -0
  47. Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/model.cpython-39.pyc +0 -0
  48. Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/molecule.cpython-39.pyc +0 -0
  49. Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/protein.cpython-39.pyc +0 -0
  50. Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/residue.cpython-39.pyc +0 -0
  51. Program Files/Python39/Lib/site-packages/packman/molecule/annotations.py +92 -0
  52. Program Files/Python39/Lib/site-packages/packman/molecule/atom.py +332 -0
  53. Program Files/Python39/Lib/site-packages/packman/molecule/bond.py +186 -0
  54. Program Files/Python39/Lib/site-packages/packman/molecule/chain.py +323 -0
  55. Program Files/Python39/Lib/site-packages/packman/molecule/hetmol.py +224 -0
  56. Program Files/Python39/Lib/site-packages/packman/molecule/model.py +703 -0
  57. Program Files/Python39/Lib/site-packages/packman/molecule/molecule.py +470 -0
  58. Program Files/Python39/Lib/site-packages/packman/molecule/protein.py +162 -0
  59. Program Files/Python39/Lib/site-packages/packman/molecule/residue.py +322 -0
  60. Program Files/Python39/Lib/site-packages/packman/tests/__init__.py +4 -0
  61. Program Files/Python39/Lib/site-packages/packman/tests/__pycache__/__init__.cpython-39.pyc +0 -0
  62. Program Files/Python39/Lib/site-packages/packman/tests/anm/__init__.py +0 -0
  63. Program Files/Python39/Lib/site-packages/packman/tests/anm/__pycache__/__init__.cpython-39.pyc +0 -0
  64. Program Files/Python39/Lib/site-packages/packman/tests/anm/__pycache__/test_anm.cpython-39.pyc +0 -0
  65. Program Files/Python39/Lib/site-packages/packman/tests/anm/test_anm.py +52 -0
  66. Program Files/Python39/Lib/site-packages/packman/tests/data/1prw.hng +3 -0
  67. Program Files/Python39/Lib/site-packages/packman/tests/data/1prw.pdb +1871 -0
  68. Program Files/Python39/Lib/site-packages/packman/tests/data/4hla.cif +5058 -0
  69. Program Files/Python39/Lib/site-packages/packman/tests/data/__init__.py +0 -0
  70. Program Files/Python39/Lib/site-packages/packman/tests/data/__pycache__/__init__.cpython-39.pyc +0 -0
  71. Program Files/Python39/Lib/site-packages/packman/tests/entropy/__init__.py +0 -0
  72. Program Files/Python39/Lib/site-packages/packman/tests/entropy/__pycache__/__init__.cpython-39.pyc +0 -0
  73. Program Files/Python39/Lib/site-packages/packman/tests/entropy/__pycache__/test_entropy.cpython-39.pyc +0 -0
  74. Program Files/Python39/Lib/site-packages/packman/tests/entropy/test_entropy.py +30 -0
  75. Program Files/Python39/Lib/site-packages/packman/tests/molecule/__init__.py +0 -0
  76. Program Files/Python39/Lib/site-packages/packman/tests/molecule/__pycache__/__init__.cpython-39.pyc +0 -0
  77. Program Files/Python39/Lib/site-packages/packman/tests/molecule/__pycache__/test_molecule.cpython-39.pyc +0 -0
  78. Program Files/Python39/Lib/site-packages/packman/tests/molecule/test_molecule.py +95 -0
  79. Program Files/Python39/Lib/site-packages/packman/utilities/__init__.py +1 -0
  80. Program Files/Python39/Lib/site-packages/packman/utilities/__pycache__/__init__.cpython-39.pyc +0 -0
  81. Program Files/Python39/Lib/site-packages/packman/utilities/__pycache__/utilities.cpython-39.pyc +0 -0
  82. Program Files/Python39/Lib/site-packages/packman/utilities/utilities.py +180 -0
  83. Program Files/Python39/Lib/site-packages/py_packman-1.4.0-py3.9.egg-info/PKG-INFO +86 -0
  84. Program Files/Python39/Lib/site-packages/py_packman-1.4.0-py3.9.egg-info/SOURCES.txt +51 -0
  85. Program Files/Python39/Lib/site-packages/py_packman-1.4.0-py3.9.egg-info/dependency_links.txt +1 -0
  86. Program Files/Python39/Lib/site-packages/py_packman-1.4.0-py3.9.egg-info/entry_points.txt +3 -0
  87. Program Files/Python39/Lib/site-packages/py_packman-1.4.0-py3.9.egg-info/requires.txt +5 -0
  88. Program Files/Python39/Lib/site-packages/py_packman-1.4.0-py3.9.egg-info/top_level.txt +1 -0
  89. Program Files/Python39/Scripts/packman-script.py +33 -0
  90. Program Files/Python39/Scripts/packman.exe +0 -0
@@ -0,0 +1,375 @@
1
+ # -*- coding: utf-8 -*-
2
+ """The 'predict_hinge' object host file.
3
+
4
+ This is file information, not the class information. This information is only for the API developers.
5
+ Please read the 'predict_hinge' object documentation for details.
6
+
7
+ Example::
8
+
9
+ from packman.apps import predict_hinge
10
+ help( predict_hinge )
11
+
12
+ Todo:
13
+ * Finish writing up the documentation.
14
+ * Finish error handling.
15
+ * Move the marked functions to the geometry module
16
+ * Clear and annotate the subclasses properly
17
+ * Annotate 'error', 'cross'
18
+ * Finish optimizing the performance.
19
+ * Convert GetExample() functions to get_example() to make it uniform with rest of the API.
20
+
21
+ Authors:
22
+ * Pranav Khade(https://github.com/Pranavkhade)
23
+ """
24
+
25
+ import numpy
26
+ import functools
27
+ import logging
28
+
29
+ from networkx import eccentricity
30
+
31
+ from scipy.stats import mode
32
+ from scipy.optimize import minimize
33
+
34
+ from sklearn.cluster import KMeans
35
+ from mlxtend.evaluate import permutation_test
36
+ from itertools import groupby, count
37
+
38
+ from ..molecule import Hinge
39
+ from ..utilities import WriteOBJ
40
+ from ..geometry import AlphaShape
41
+
42
+
43
+ def predict_hinge(atoms, outputfile, Alpha=float('Inf'),method='alpha_shape',filename='Output.pdb',MinimumHingeLength=5,nclusters=4):
44
+ """This function is used to carry out hinge prediction given the parameters.
45
+
46
+ Notes:
47
+ * The packman.bin.PACKMAN uses this function
48
+
49
+ * Ideally, the alpha values should be scanned from 0 to 10 to obtain conclusively repetative hinges (Use '' for this purpose)
50
+
51
+ * Please refer to the following paper for the details on the algorithm and citation:
52
+ Pranav M. Khade, Ambuj Kumar, Robert L. Jernigan, Characterizing and Predicting Protein Hinges for Mechanistic Insight,
53
+ Journal of Molecular Biology, Volume 432, Issue 2, 2020, Pages 508-522, ISSN 0022-2836, https://doi.org/10.1016/j.jmb.2019.11.018.
54
+ (http://www.sciencedirect.com/science/article/pii/S0022283619306837)
55
+
56
+ * Tutorial Link: https://py-packman.readthedocs.io/en/latest/tutorials/hinge_predict.html#tutorials-predict-hinge
57
+
58
+ * The predicted hinges are stored in packman.molecule.Chain object as an packman.molecule.Hinge object.
59
+
60
+ Todo:
61
+ * Add reference to the function in the description which scans multiple alpha values for conclusive hinges.
62
+
63
+ Args:
64
+ atoms ([packman.molecule.Atom]) : PACKMAN uses backbone atoms of the protein. However, any number and type of atoms can be used (Alpha value range will change)
65
+ outputfile (file) : Output File.
66
+ Alpha (float, optional) : Please refer to the paper for this parameter. Defaults to float('Inf').
67
+ method (str, optional) : Please refer to the paper for this parameter. Defaults to 'alpha_shape'.
68
+ filename (str, optional) : Please refer to the paper for this parameter. Defaults to 'Output.pdb'.
69
+ MinimumHingeLength (int, optional): Please refer to the paper for this parameter. Defaults to 5.
70
+ nclusters (int, optional) : Please refer to the paper for this parameter. Defaults to 4.
71
+
72
+ Returns:
73
+ alpha_shape : The Alpha Shape (Subset of Delaunay Tesselations)
74
+ """
75
+ if(method=='alpha_shape'):
76
+
77
+ def get_statistics(atoms,SelectedHingeResidues,filename='Output'):
78
+ """This sub-method is used to get the statistical data on the hinges and print it into a file.
79
+
80
+ Notes:
81
+ * * Function level: 1 (1 being top)
82
+ * Do something about the output file
83
+
84
+ Args:
85
+ atoms ([packman.molecule.Atom]) : Set of atoms. (Read parent method description)
86
+ SelectedHingeResidues ([packman.molecule.Residue]): Predicted hinge residues.
87
+ filename (str, optional) : Output file name. Defaults to 'Output'.
88
+
89
+ Returns:
90
+ [p-value, stats] (float): p-value of the predicted hinge, statistics of the hinge (in that order)
91
+ """
92
+ hinge_atoms=[i.get_backbone() for i in SelectedHingeResidues]
93
+ hinge_atoms=[item for sublist in hinge_atoms for item in sublist]
94
+ non_hinge_atoms=list(set([i for i in atoms])-set(hinge_atoms))
95
+ all_atoms_bfactor=[i.get_bfactor() for i in atoms]
96
+ hinge_atoms_bfactor=[i.get_bfactor() for i in hinge_atoms]
97
+ non_hinge_atoms_bfactor=[i.get_bfactor() for i in non_hinge_atoms]
98
+
99
+ return_stats=[]
100
+
101
+ outputfile.write('\nSTATISTICS\n\t\tN\tMin\tMax\tMean\tMode\tMedian\tSTDDev\n')
102
+ return_stats.append(['','N','Min','Max','Mean','Mode','Median','STDDev'])
103
+ outputfile.write('Total '+'\t'+str(len(all_atoms_bfactor))+'\t'+str(numpy.min(all_atoms_bfactor))+'\t'+str(numpy.max(all_atoms_bfactor))+'\t'+str(numpy.mean(all_atoms_bfactor))+'\t'+str(mode(all_atoms_bfactor)[0][0])+'\t'+str(numpy.median(all_atoms_bfactor))+'\t'+str(numpy.std(all_atoms_bfactor))+'\n')
104
+ return_stats.append(['Total',len(all_atoms_bfactor),numpy.min(all_atoms_bfactor),numpy.max(all_atoms_bfactor),numpy.mean(all_atoms_bfactor),mode(all_atoms_bfactor)[0][0],numpy.median(all_atoms_bfactor),numpy.std(all_atoms_bfactor)])
105
+ outputfile.write('Hinge '+'\t'+str(len(hinge_atoms_bfactor))+'\t'+str(numpy.min(hinge_atoms_bfactor))+'\t'+str(numpy.max(hinge_atoms_bfactor))+'\t'+str(numpy.mean(hinge_atoms_bfactor))+'\t'+str(mode(hinge_atoms_bfactor)[0][0])+'\t'+str(numpy.median(hinge_atoms_bfactor))+'\t'+str(numpy.std(hinge_atoms_bfactor))+'\n')
106
+ return_stats.append(['Hinge',len(hinge_atoms_bfactor),numpy.min(hinge_atoms_bfactor),numpy.max(hinge_atoms_bfactor),numpy.mean(hinge_atoms_bfactor),mode(hinge_atoms_bfactor)[0][0],numpy.median(hinge_atoms_bfactor),numpy.std(hinge_atoms_bfactor)])
107
+ outputfile.write('NonHinge'+'\t'+str(len(non_hinge_atoms_bfactor))+'\t'+str(numpy.min(non_hinge_atoms_bfactor))+'\t'+str(numpy.max(non_hinge_atoms_bfactor))+'\t'+str(numpy.mean(non_hinge_atoms_bfactor))+'\t'+str(mode(non_hinge_atoms_bfactor)[0][0])+'\t'+str(numpy.median(non_hinge_atoms_bfactor))+'\t'+str(numpy.std(non_hinge_atoms_bfactor))+'\n')
108
+ return_stats.append(['NonHinge',len(non_hinge_atoms_bfactor),numpy.min(non_hinge_atoms_bfactor),numpy.max(non_hinge_atoms_bfactor),numpy.mean(non_hinge_atoms_bfactor),mode(non_hinge_atoms_bfactor)[0][0],numpy.median(non_hinge_atoms_bfactor),numpy.std(non_hinge_atoms_bfactor)])
109
+
110
+ p_value = permutation_test(hinge_atoms_bfactor, non_hinge_atoms_bfactor,method='approximate',num_rounds=10000,seed=0)
111
+ outputfile.write('\np-value:\t'+str(p_value)+'\n')
112
+ return p_value,return_stats
113
+
114
+ def get_leastsquareplane(atoms,HingeResidues,HingePlane):
115
+ """This sub-function gives the Least Square Plane equation of the given atoms.
116
+
117
+ This plane is currently gives us an idea about the possible direction of the movement of the hinge residues (See figures in the publication)
118
+
119
+ Todo:
120
+ * Change the name of the parameter HingePlane (It is misleading)
121
+
122
+ Notes:
123
+ * Function level: 1 (1 being top)
124
+ * Possibly will be moved to geometry module later.
125
+ * Check the output file for this equation. The instructions to visualize this plane are given at the end of the file.
126
+
127
+ Args:
128
+ atoms ([packman.molecule.Atom]) : Set of atoms. (Read parent method description)
129
+ HingeResidues ([packman.molecule.Residue]): Predicted hinge residues.
130
+ HingePlane (int) : Index of the HingePlane
131
+
132
+ Returns:
133
+ [a,b,c,d]: Four coefficients essential to define the plane in 3D space.
134
+ """
135
+ hinge_points=[item.get_location() for sublist in [i.get_backbone() for i in HingeResidues] for item in sublist]
136
+ HingeAtoms=[item for sublist in [i.get_backbone() for i in HingeResidues] for item in sublist]
137
+ NonHingeAtoms=[i.get_location() for i in atoms if i not in HingeAtoms]
138
+
139
+ #Zipping the values
140
+ hinge_xs,hinge_ys,hinge_zs = zip(*hinge_points)
141
+ XS,YS,ZS=zip(*NonHingeAtoms)
142
+
143
+ def project_points(x, y, z, a, b, c):
144
+ """Project the points on a given plane
145
+
146
+ Projects the points with coordinates x, y, z onto the plane
147
+ defined by a*x + b*y + c*z = 1
148
+
149
+ Todo:
150
+ * Explain the returning variables properly
151
+
152
+ Notes:
153
+ * Function level: 2 (1 being top)
154
+ * Possibly will be moved to the geometry module
155
+
156
+ Args:
157
+ x (float): X-coordinate of the point to be projected on the plane.
158
+ y (float): Y-coordinate of the point to be projected on the plane.
159
+ z (float): Z-coordinate of the point to be projected on the plane.
160
+ a (float): X-component of the plane.
161
+ b (float): Y-component of the plane.
162
+ c (float): Z-component of the plane.
163
+
164
+ Returns:
165
+ Neccesary information to project the points on the given plane.
166
+ """
167
+ vector_norm = a*a + b*b + c*c
168
+ normal_vector = numpy.array([a, b, c]) / numpy.sqrt(vector_norm)
169
+ point_in_plane = numpy.array([a, b, c]) / vector_norm
170
+ points = numpy.column_stack((x, y, z))
171
+ points_from_point_in_plane = points - point_in_plane
172
+ proj_onto_normal_vector = numpy.dot(points_from_point_in_plane,normal_vector)
173
+ proj_onto_plane = (points_from_point_in_plane - proj_onto_normal_vector[:, None]*normal_vector)
174
+ return point_in_plane + proj_onto_plane
175
+
176
+ def FitPlane(points):
177
+ """Plane fitting algorithm given the points.
178
+
179
+ Notes:
180
+ * Function level: 2 (1 being top)
181
+
182
+ Args:
183
+ points ([float]): Two dimentional array of 3D points
184
+
185
+ Returns:
186
+ [a,b,c,d] (float) : Numbers essential to define the Least Square Plane equation
187
+ """
188
+ xs,ys,zs = zip(*points)
189
+ def plane(x, y, params):
190
+ """Plane Object
191
+
192
+ Args:
193
+ x ([type]): [description]
194
+ y ([type]): [description]
195
+ params ([type]): [description]
196
+
197
+ Returns:
198
+ [float]: Equation of the plane
199
+ """
200
+ a = params[0]
201
+ b = params[1]
202
+ c = params[2]
203
+ z = a*x + b*y + c
204
+ return z
205
+
206
+ def error(params, points):
207
+ """Get the error
208
+
209
+ Args:
210
+ params ([type]): [description]
211
+ points ([type]): [description]
212
+
213
+ Returns:
214
+ [type]: [description]
215
+ """
216
+ result = 0
217
+ for (x,y,z) in points:
218
+ plane_z = plane(x, y, params)
219
+ diff = abs(plane_z - z)
220
+ result += diff**2
221
+ return result
222
+
223
+ def cross(a, b):
224
+ """Get cross
225
+
226
+ Args:
227
+ a ([type]): [description]
228
+ b ([type]): [description]
229
+
230
+ Returns:
231
+ [type]: [description]
232
+ """
233
+ return [a[1]*b[2] - a[2]*b[1],
234
+ a[2]*b[0] - a[0]*b[2],
235
+ a[0]*b[1] - a[1]*b[0]]
236
+
237
+ fun = functools.partial(error, points=points)
238
+ params0 = [0, 0, 0]
239
+ res = minimize(fun, params0)
240
+
241
+ a = res.x[0]
242
+ b = res.x[1]
243
+ c = res.x[2]
244
+
245
+ point = numpy.array([0.0, 0.0, c])
246
+ normal = numpy.array(cross([1,0,a], [0,1,b]))
247
+ d = -point.dot(normal)
248
+
249
+ xx, yy = numpy.meshgrid([min(xs),max(xs)], [min(ys),max(ys)])
250
+ z = (-normal[0] * xx - normal[1] * yy - d) * 1. /normal[2]
251
+
252
+ #Three points on the plane
253
+ p1=numpy.array([numpy.mean(xx[0]),numpy.mean(yy[:,0]),numpy.mean(z)])
254
+ p2=numpy.array([xx[0][0], yy[0][1], z[0][0]])
255
+ p3=numpy.array([xx[0][1], yy[0][0], z[0][1]])
256
+ p4=numpy.array([xx[1][0], yy[1][1], z[1][0]])
257
+
258
+ #Two vectors in the plane
259
+ v1=p3-p1
260
+ v2=p2-p1
261
+
262
+ #vector normal to the plane
263
+ cp = numpy.cross(v1, v2)
264
+ a, b, c = cp
265
+
266
+ # This evaluates a * x3 + b * y3 + c * z3 which equals d
267
+ d = numpy.dot(cp, p3)
268
+ a,b,c,d=a/d,b/d,c/d,d/d
269
+ #outputfile.write('The equation is {0}x + {1}y + {2}z = {3}'.format(a, b, c, d))
270
+
271
+ #Plane in PyMol
272
+ outputfile.write('import plane\n')
273
+ outputfile.write('plane.make_plane_points(name=\'HingePlane'+ str(HingePlane) +'\', l1='+str(list(p4))+', l2='+str(list(p2))+', l3='+str(list(p3))+', center=False, makepseudo=False)'+'\n')
274
+ outputfile.write('set cgo_transparency, 0.35, HingePlane'+str(HingePlane)+'\n')
275
+ return a,b,c,d
276
+
277
+ a,b,c,d=FitPlane(hinge_points)
278
+ projected=project_points(hinge_xs,hinge_ys,hinge_zs,a,b,c)
279
+ return projected
280
+
281
+ #Alpha shape bit
282
+ alpha_shape, ProteinGraph = AlphaShape( atoms, Alpha, get_graph = True )
283
+
284
+ centrality = eccentricity(ProteinGraph)
285
+ centrality_sorted_with_keys = numpy.array([float(centrality[j]) for j in sorted([i for i in centrality.keys()])]).reshape(-1, 1)
286
+
287
+ #Cluster (4 is like a resolution here)
288
+ km=KMeans(n_clusters=nclusters)
289
+ km.fit(centrality_sorted_with_keys)
290
+ central_nodes=numpy.argwhere(km.labels_==numpy.argmin(km.cluster_centers_)).T[0]
291
+ HingeResidues=list(set([atoms[i].get_parent() for i in central_nodes]))
292
+ HingeResiduesID=[i.get_id() for i in HingeResidues]
293
+ SortedHingeResidues=[x for _,x in sorted(zip(HingeResiduesID,HingeResidues))]
294
+ HingeResiduesID=[i.get_id() for i in SortedHingeResidues]
295
+
296
+ PredictedHinges=[]
297
+ for i,j in groupby(HingeResiduesID,lambda n, c=count(): n-next(c)):
298
+ Local_Hinge=[k for k in j]
299
+ if(len(Local_Hinge)>MinimumHingeLength):
300
+ PredictedHinges.append(SortedHingeResidues[HingeResiduesID.index(Local_Hinge[0]):HingeResiduesID.index(Local_Hinge[-1])+1])
301
+
302
+ #Print part
303
+ Hinges=[]
304
+ Chains=','.join(list(set([i.get_parent().get_id() for i in SortedHingeResidues])))
305
+ outputfile.write('Filename= '+str(filename)+'\t| Chain(s)= '+Chains+'\t| AlphaValue= '+str(Alpha)+'\t| MinimumHingeLength= '+str(MinimumHingeLength)+'\t| EccentricityClusters= '+str(nclusters)+ '\n')
306
+ outputfile.write('Hindge Residues(Predicted):\n')
307
+ for numi,i in enumerate(PredictedHinges):
308
+ #Assigning domain IDs
309
+ for _ in i:_.set_domain_id('FL'+str(numi))
310
+ #Molecule.Hinge(numi,elements,stats,p)
311
+ outputfile.write('\nHinge #'+str(numi+1)+'\nResidues: '+i[0].get_name()+'-'+str(i[0].get_id()) +' to '+i[-1].get_name()+'-'+str(i[-1].get_id())+'\n')
312
+ p_value,hstats=get_statistics(atoms,i,filename=filename)
313
+ outputfile.write('\nPymol Terminal Commands for Visualizing:\ncolor blue, resi '+str(i[0].get_id())+':'+str(i[-1].get_id())+'\n')
314
+ get_leastsquareplane(atoms,i,numi+1)
315
+ outputfile.write("#--------------------------------------------------#\n")
316
+ #HingeObject
317
+ Hinges.append( Hinge(numi,Alpha,i,hstats,p_value))
318
+
319
+ #Assigning domain IDs
320
+ AllChainResidues = [i for i in HingeResidues[0].get_parent().get_residues()]
321
+ #If sorting is needed
322
+ DomainNumber, flag = 0, True
323
+ for i in AllChainResidues:
324
+ if(i.get_domain_id() == None):
325
+ i.set_domain_id('DM'+str(DomainNumber))
326
+ flag=True
327
+ elif(i.get_domain_id()[:2] == 'FL' and flag):
328
+ DomainNumber+=1
329
+ flag=False
330
+
331
+ AllChainResidues[0].get_parent().set_hinges(Hinges)
332
+ return alpha_shape
333
+
334
+ def hinge_cli(args,mol):
335
+ """Command-line Interface for the 'hinge' command. Please check the packman.bin.PACKMAN file for more details.
336
+
337
+ This function is for the CLI and not an integral function for the API.
338
+
339
+ Args:
340
+ args (parser.parse_args()) : The arguments that were passed by the user to the PACKMAN-hinge app.
341
+ mol (packman.molecule.Protein) : The 'Protein' object for the anaylsis.
342
+ """
343
+
344
+ def print_footnotes(outputfile):
345
+ """Add footnotes to the output file.
346
+
347
+ Args:
348
+ outputfile (file): The file to which the footnotes will be written.
349
+ """
350
+ outputfile.write('Footnotes:\n\nSTATISTICS Section Legend:\nN: Number of residues\nMin: Minimum B-factor value\nMax: Maximum B-factor value\nMean: Mean B-factor value\nMode: Mode B-factor value\nMedian: Median B-factor value\nSTDDev: Standard Deviation of the B-factor values\n')
351
+ outputfile.write('\nRMSF Plane Visualization:\nDownload plane.py file from https://pymolwiki.org/index.php/Plane_Wizard and place it in the PyMol working directory if the RMSF plane needs to be visualized.\n')
352
+ return True
353
+
354
+ try:
355
+ if(args.chain):
356
+ Backbone = [item for sublist in mol[0][args.chain].get_backbone() for item in sublist]
357
+ alpha_shape= predict_hinge(Backbone, args.outputfile, Alpha=float(args.alpha), filename=args.filename,nclusters=args.e_clusters,MinimumHingeLength=args.minhnglen)
358
+ if(args.generateobj is not None):
359
+ WriteOBJ(Backbone, alpha_shape, args.generateobj)
360
+ else:
361
+ for i in mol[0].get_chains():
362
+ try:
363
+ Backbone = [item for sublist in mol[0][i.get_id()].get_backbone() for item in sublist]
364
+ alpha_shape = predict_hinge(Backbone, args.outputfile, Alpha=float(args.alpha), filename=args.filename,nclusters=args.e_clusters,MinimumHingeLength=args.minhnglen)
365
+ except:
366
+ logging.warning('Chain '+str(i.get_id())+' has none/missing backbone atoms to calculate the hinge.')
367
+ finally:
368
+ print_footnotes(args.outputfile)
369
+ args.outputfile.flush()
370
+ args.logfile.flush()
371
+
372
+ if(args.generateobj is not None):
373
+ args.generateobj.flush()
374
+
375
+ return True