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,656 @@
1
+ # -*- coding: utf-8 -*-
2
+ """The 'hdANM' 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 'hdANM' object documentation and the publication for details.
6
+
7
+ Citation::
8
+
9
+ Pranav M. Khade, Domenico Scaramozzino, Ambuj Kumar, Giuseppe Lacidogna, Alberto Carpinteri, Robert L. Jernigan, hdANM: a new comprehensive dynamics model for protein hinges, Biophysical Journal, 2021, https://doi.org/10.1016/j.bpj.2021.10.017
10
+
11
+ About .hng File:
12
+ - hdANM requires the information about hinges and domains in the .hng format.
13
+ - Each column in the .hng file is tab delimited.
14
+ - Each row in the .hng file follows collowing pattern:
15
+
16
+ Filename_ChainID Domain/HingeId ResidueStartPosition:ResidueEndPosition
17
+
18
+ Example of .hng file for PDBID 1EXR::
19
+
20
+ 1EXR_A D1 1:70
21
+ 1EXR_A H1 70:90
22
+ 1EXR_A D2 90:148
23
+
24
+ Above format means that there are two domains (D1 and D2) separated by a hinge (H1). D1 stretches from residue 1 to 70; D2 stretches from 90 to 148 and hinge H1 is in the middle.
25
+
26
+ Example::
27
+
28
+ from packman.anm import hdANM
29
+ help( hdANM )
30
+
31
+ Notes:
32
+ * Tutorial: https://py-packman.readthedocs.io/en/latest/tutorials/hdANM.html#tutorials-hdanm
33
+
34
+ Todo:
35
+ * Finish optimizing the performance.
36
+ * Add publication details in the Notes
37
+ * Make sure that parameter to the ANM is changed from [float] to packman.molecule.atom
38
+
39
+ Authors:
40
+ * Pranav Khade(https://github.com/Pranavkhade)
41
+ """
42
+
43
+ from .. import molecule, Atom, Model, Protein
44
+ from ..constants import amino_acid_molecular_weight
45
+ from ..constants import atomic_weight
46
+ from ..utilities import load_hinge
47
+
48
+ import numpy
49
+ import itertools
50
+
51
+ from scipy.linalg import eig as scipy_eig
52
+ '''
53
+ ##################################################################################################
54
+ # hd-ANM #
55
+ ##################################################################################################
56
+ '''
57
+
58
+ class hdANM:
59
+ """This class contains the functions essential to carry out the Hinge-Domain-Anisotropic Network Model and Compliance analysis.
60
+
61
+ Notes:
62
+ * Tutorial:
63
+ * For more details about the parameters for compliance, or to site this, read the following paper:
64
+
65
+ Todo:
66
+ * Read individual functions to know
67
+
68
+ Args:
69
+ atoms ([packman.molecule.Atom]) : Two dimentional array of atoms.
70
+ hng_file (string) : .hng filename and path. (Contains the information about hinge and domains on the protein)
71
+ gamma (float, optional) : Spring Constant Value. Defaults to 1.0.
72
+ dr (float, optional) : Distance Cutoff. Defaults to 15.0.
73
+ power (int, optional) : Power of distance (mainly useful in non-parametric mode). Defaults to 0.
74
+ pf (None, optional) : Parameter free model?. Defaults to None.
75
+
76
+ Raises:
77
+ Exception: [description]
78
+ Exception: [description]
79
+ Exception: [description]
80
+ """
81
+
82
+ def __init__(self, atoms , hng_file , gamma=1.0, dr=15.0, power=0, pf=None):
83
+ self.gamma = gamma
84
+ self.dr = dr
85
+ self.power = power
86
+ self.pf = pf
87
+ self.atoms = atoms
88
+ self.HNGinfo = load_hinge(hng_file)
89
+ self.RT_eigen_vectors = None
90
+
91
+ #Coords are in the same order as the atoms
92
+ self.coords = numpy.array([i.get_location() for i in atoms])
93
+ if self.pf != None and self.pf <= 0:
94
+ raise Exception("pf value cannot be zero or negative")
95
+ if self.gamma <= 0:
96
+ raise Exception("gamma value cannot be zero or negative")
97
+ if self.dr <= 0:
98
+ raise Exception("distance cutoff value cannot be zero or negative")
99
+
100
+ ##To Verify that the hessian is same as ANM (Part 1/2)
101
+ #self.calculate_hessian()
102
+
103
+
104
+ '''Get Functions'''
105
+ def get_hessian(self):
106
+ """Get the Hessian Matrix of the hd-ANM model.
107
+
108
+ Notes:
109
+ * Make sure that the hdANM().calculate_hessian() is called before calling this function. (will return None otherwise)
110
+
111
+ Returns:
112
+ numpy.ndarray: Hessian matrix if successful; None otherwise
113
+ """
114
+ return self.hessian
115
+
116
+ def get_eigenvalues(self):
117
+ """Get the Eigenvalues obtained by decomposing the Hessian Matrix of the hd-ANM model.
118
+
119
+ Notes:
120
+ * Make sure that the hdANM().calculate_hessian() and ANM().calculate_decomposition() is called before calling this function. (will return None otherwise)
121
+
122
+ Returns:
123
+ numpy.ndarray: Eigenvalues if successful; None otherwise
124
+ """
125
+ return self.eigen_values
126
+
127
+ def get_eigenvectors(self):
128
+ """Get the Eigenvectors obtained by decomposing the Hessian Matrix of the hd-ANM model.
129
+
130
+ Notes:
131
+ * Make sure that the hdANM().calculate_hessian() and hdANM().calculate_decomposition() is called before calling this function. (will return None otherwise)
132
+
133
+ Returns:
134
+ numpy.ndarray: Eigenvectors if successful; None otherwise
135
+ """
136
+ return self.eigen_vectors
137
+
138
+ def get_RT_eigen_vectors(self):
139
+ """Get the Reverse Transformed vectors from the hdANM eigenvectors.
140
+
141
+ Reverse transformed means that the hdANM eigenvector of dimension: 6D+3H x 6D+3H (D: Number of domains; H: Number of hinge atoms) are converted to 3N x 6D+3H (N: Number of atoms)
142
+
143
+ Note:
144
+ - It was refered as 'exploded vector' utill version 1.3.3
145
+
146
+ Returns:
147
+ numpy.ndarray: Reverse Transformed Vector if successful; None otherwise
148
+ """
149
+ return self.RT_eigen_vectors
150
+
151
+ def get_fluctuations(self):
152
+ """Get the Fluctuations obtained from Eigenvectors and Eigenvalues
153
+
154
+ Notes:
155
+ * Make sure that the hdANM().calculate_hessian(), hdANM().calculate_decomposition() and hdANM().calculate_fluctuations() is called before calling this function. (will return None otherwise)
156
+
157
+ Returns:
158
+ numpy.ndarray: Fluctuations if successful; None otherwise
159
+ """
160
+ return self.fluctuations
161
+
162
+ def get_hessian_pseudoinverse(self,n_modes="all"):
163
+ """Get the Pseudoinverse of the hdANM model.
164
+
165
+ Returns:
166
+ numpy.ndarray: Pseudoinverse if successul; None otherwise
167
+ """
168
+ try:
169
+ return self.hessian_pseudoinverse
170
+ except:
171
+ self.calculate_hessian_pseudoinverse(n_modes=n_modes)
172
+ return self.hessian_pseudoinverse
173
+
174
+ def get_crosscorrelation_matrix(self,n_modes="all"):
175
+ try:
176
+ return self.crosscorrelation_matrix
177
+ except:
178
+ self.calculate_cross_correlation(n_modes=n_modes)
179
+ return self.crosscorrelation_matrix
180
+
181
+ def get_hessian_block(self,Index1,Index2):
182
+ """Calculate Hij (Hessian matrix component) using equation . ()
183
+
184
+ Notes:
185
+
186
+ Returns:
187
+ numpy.ndarray: Hij if successful; None otherwise
188
+ """
189
+ i=self.coords[Index1]
190
+ j=self.coords[Index2]
191
+ dist_ij = numpy.linalg.norm(j-i)
192
+
193
+ if(Index1!=Index2 and dist_ij<=self.dr):
194
+ return numpy.array(
195
+ [ [ (j[0]-i[0])*(j[0]-i[0]) , (j[0]-i[0])*(j[1]-i[1]) , (j[0]-i[0])*(j[2]-i[2]) ] ,
196
+ [ (j[1]-i[1])*(j[0]-i[0]) , (j[1]-i[1])*(j[1]-i[1]) , (j[1]-i[1])*(j[2]-i[2]) ] ,
197
+ [ (j[2]-i[2])*(j[0]-i[0]) , (j[2]-i[2])*(j[1]-i[1]) , (j[2]-i[2])*(j[2]-i[2]) ] ]
198
+ ) * ( -self.gamma/(dist_ij**2) )
199
+ elif(Index1!=Index2 and dist_ij>self.dr):
200
+ return numpy.zeros((3,3))
201
+ elif(Index1==Index2):
202
+ diag = numpy.zeros((3,3))
203
+ for numk,k in enumerate(self.coords):
204
+ dist_ik = numpy.linalg.norm(k-i)
205
+ if(dist_ik<=self.dr and Index1!=numk):
206
+ diag=numpy.add(diag,
207
+ numpy.array(
208
+ [ [ (k[0]-i[0])*(k[0]-i[0]) , (k[0]-i[0])*(k[1]-i[1]) , (k[0]-i[0])*(k[2]-i[2]) ] ,
209
+ [ (k[1]-i[1])*(k[0]-i[0]) , (k[1]-i[1])*(k[1]-i[1]) , (k[1]-i[1])*(k[2]-i[2]) ] ,
210
+ [ (k[2]-i[2])*(k[0]-i[0]) , (k[2]-i[2])*(k[1]-i[1]) , (k[2]-i[2])*(k[2]-i[2]) ] ]
211
+ ) * ( -self.gamma/(dist_ik**2) )
212
+ )
213
+ return -diag
214
+
215
+ #To Verify that the hessian is same as ANM (Part 2/2)
216
+ #print(Index1,Index2,dist_ij,'\n',self.get_hessian()[Index1*3:Index1*3+3,Index2*3:Index2*3+3],"\n####\n")
217
+ #return self.get_hessian()[Index1*3:Index1*3+3,Index2*3:Index2*3+3]
218
+
219
+
220
+ '''Calculate Functions'''
221
+ #Discontinued (But kept for testing)
222
+ '''
223
+ def calculate_hessian(self):
224
+ """Build the Hessian Matrix of the ANM model.
225
+
226
+ This is an essential step for hdANM
227
+
228
+ Notes:
229
+ * Hessian matrix is built; use ANM().get_hessian() to obtain the hessian matrix.
230
+ """
231
+ n_atoms=len(self.coords)
232
+ hessian=numpy.zeros((n_atoms*3, n_atoms*3), float)
233
+ distance_mat=numpy.ones((n_atoms*3, n_atoms*3), float)
234
+ for i in range(len(self.coords)):
235
+ diff = self.coords[i+1:, :] - self.coords[i]
236
+ squared_diff = diff**2
237
+ for j, s_ij in enumerate(squared_diff.sum(1)):
238
+ if s_ij <= self.dr**2:
239
+ diff_coords = diff[j]
240
+ j = j + i + 1
241
+ derivative = numpy.outer(diff_coords, diff_coords)*(float(-self.gamma)/numpy.sqrt(s_ij)**(2+self.power))
242
+ hessian[i*3:i*3+3, j*3:j*3+3] = derivative
243
+ hessian[j*3:j*3+3, i*3:i*3+3] = derivative
244
+ hessian[i*3:i*3+3, i*3:i*3+3] = hessian[i*3:i*3+3, i*3:i*3+3] - derivative
245
+ hessian[j*3:j*3+3, j*3:j*3+3] = hessian[j*3:j*3+3, j*3:j*3+3] - derivative
246
+ #abs added to avoid negative numbers
247
+ d = numpy.sqrt(s_ij)
248
+ lobj = [[d,d,d],[d,d,d], [d,d,d]]
249
+ dmat = numpy.array(lobj)
250
+ distance_mat[i*3:i*3+3, j*3:j*3+3] = dmat
251
+
252
+ if self.pf != None:
253
+ hessian = numpy.divide(hessian, distance_mat)
254
+
255
+ #Class Change
256
+ self.hessian=hessian
257
+ return True
258
+ '''
259
+
260
+ def calculate_decomposition(self, include_mass=True):
261
+ """Decompose the Hessian Matrix of the hdANM model.
262
+
263
+ Args:
264
+ include_mass (bool): Amino Acid Residue mass/Atomic mass should be (True) or shouldn't be (False) included for the decomposition. Defaults to True
265
+
266
+ Note:
267
+ - Eigen values and Eigen Vectors are calculated. use hdANM().get_eigenvalues() and hdANM().get_eigenvectors() to obtain them.
268
+ - Currently only molecular weight is included in case of Amino Acid Residue(coarse grained) mass.
269
+ - Mass of the Amino Acid Residues/Atoms can be found in /packman/constants/Constants.py
270
+ ie...
271
+ from packman.constants import amino_acid_molecular_weight
272
+ from packman.constants import atomic_weigh
273
+ """
274
+ if(include_mass):
275
+ self.eigen_values, self.eigen_vectors= scipy_eig(self.domain_hessian,self.domain_mass_matrix)
276
+
277
+ idx = self.eigen_values.argsort()
278
+ self.eigen_values = self.eigen_values[idx]
279
+ self.eigen_vectors = self.eigen_vectors[:,idx]
280
+ else:
281
+ self.eigen_values, self.eigen_vectors = numpy.linalg.eigh(self.domain_hessian)
282
+ return True
283
+
284
+
285
+ def calculate_hessian(self,mass_type='unit'):
286
+ """Build the Hessian Matrix of the hdANM model.
287
+
288
+ This is the most essential step for hdANM. It picks up blocks from ANM hessian matrix and puts it in the format described in the paper.
289
+
290
+ Args:
291
+ mass_type (unit/atom/residue): Whether to use unit (1), atomic weights or residue mass for the mass matrix.
292
+
293
+ Notes:
294
+ * Possible argument removal for the decomposition function
295
+ * use hdANM().domain_hessian, hdANM().domain_mass_matrix and hdANM().domain_info to access output of this function
296
+ * Mass of the Amino Acid Residues/Atoms can be found in /packman/constants/Constants.py
297
+ ie...
298
+ from packman.constants import amino_acid_molecular_weight
299
+ from packman.constants import atomic_weigh
300
+ """
301
+ all_mass_types=['unit','atom','residue']
302
+ #Error Handling
303
+ if(mass_type not in all_mass_types):
304
+ print('Provide correct \'mass_type\' parameter. See help for more details')
305
+
306
+
307
+ for i in self.atoms:
308
+ for j in self.HNGinfo:
309
+ HNGrange = self.HNGinfo[j]
310
+ IDs = j.split('_')
311
+ if( HNGrange[0] <= i.get_parent().get_id() <= HNGrange[1] and IDs[1] == i.get_parent().get_parent().get_id() ):
312
+ i.get_parent().set_domain_id( IDs[-1].strip() )
313
+
314
+ #Domain groups stores the atom index(of self.atoms) with Domain ID as a key (D5: [1,2] domain 5 with atom index 1 and 2 )
315
+ DomainGroups={}
316
+ for numi,i in enumerate(self.atoms):
317
+ try:
318
+ DomainGroups[i.get_domain_id()].append(numi)
319
+ except:
320
+ DomainGroups[i.get_domain_id()]=[]
321
+ DomainGroups[i.get_domain_id()].append(numi)
322
+
323
+ #HHH
324
+ HingeAtoms=[]
325
+ Domains=[] #Used in HHD
326
+ for i in DomainGroups.keys():
327
+ if(i[0]=='H'):
328
+ HingeAtoms.extend(DomainGroups[i])
329
+ if(i[0]=='D'):
330
+ Domains.append(i)
331
+ HHH=numpy.zeros((len(HingeAtoms)*3,len(HingeAtoms)*3))
332
+ for numi,i in enumerate(HingeAtoms):
333
+ for numj,j in enumerate(HingeAtoms):
334
+ HHH[numi*3:numi*3+3,numj*3:numj*3+3]=self.get_hessian_block(i,j)
335
+
336
+
337
+ #HHD (Scheduled to be paralalysed)
338
+ DomainInfo={}
339
+ HHD=numpy.zeros((len(HingeAtoms)*3,len(Domains)*6))
340
+ for numd,d in enumerate(Domains):
341
+ COM=numpy.average([self.coords[i] for i in DomainGroups[d]] , 0)
342
+ DomainInfo[d]=(numd,COM)
343
+ for numi,i in enumerate(HingeAtoms):
344
+ HHDijd_sum=HHDijd=numpy.zeros((3,6))
345
+ for j in DomainGroups[d]:
346
+ HHDijd=numpy.zeros((3,6))
347
+ HHDijd[0:3,0:3]=self.get_hessian_block(i,j)
348
+
349
+ HHDijd[0,3:]= [ -HHDijd[0][1]*(self.coords[j][2]-COM[2]) + HHDijd[0][2]*(self.coords[j][1]-COM[1]) , HHDijd[0][0]*(self.coords[j][2]-COM[2]) - HHDijd[0][2]*(self.coords[j][0]-COM[0]) , -HHDijd[0][0]*(self.coords[j][1]-COM[1]) + HHDijd[0][1]*(self.coords[j][0]-COM[0])]
350
+ HHDijd[1,3:]= [ -HHDijd[1][1]*(self.coords[j][2]-COM[2]) + HHDijd[1][2]*(self.coords[j][1]-COM[1]) , HHDijd[1][0]*(self.coords[j][2]-COM[2]) - HHDijd[1][2]*(self.coords[j][0]-COM[0]) , -HHDijd[1][0]*(self.coords[j][1]-COM[1]) + HHDijd[1][1]*(self.coords[j][0]-COM[0])]
351
+ HHDijd[2,3:]= [ -HHDijd[2][1]*(self.coords[j][2]-COM[2]) + HHDijd[2][2]*(self.coords[j][1]-COM[1]) , HHDijd[2][0]*(self.coords[j][2]-COM[2]) - HHDijd[2][2]*(self.coords[j][0]-COM[0]) , -HHDijd[2][0]*(self.coords[j][1]-COM[1]) + HHDijd[2][1]*(self.coords[j][0]-COM[0])]
352
+ HHDijd_sum=numpy.add(HHDijd_sum,HHDijd)
353
+ HHD[numi*3:(numi*3)+3,numd*6:((numd*6)+6)]=HHDijd_sum
354
+
355
+
356
+ #HDH
357
+ HDH=HHD.T
358
+
359
+ #HDD
360
+ HDD=numpy.zeros((6*len(Domains),6*len(Domains)))
361
+ for numd,Dd in enumerate(Domains):
362
+ for nume,De in enumerate(Domains):
363
+ HDdDe=numpy.zeros((6,6))
364
+ Dd_COM=numpy.average([self.coords[i] for i in DomainGroups[Dd]] , 0)
365
+ De_COM=numpy.average([self.coords[i] for i in DomainGroups[De]] , 0)
366
+ for i in DomainGroups[Dd]:
367
+ for j in DomainGroups[De]:
368
+ HDDij=self.get_hessian_block(i,j)
369
+ HDdDe_iter=numpy.zeros((6,6))
370
+ #F_Delta
371
+ HDdDe_iter[0:3,0:3]=HDDij
372
+ #F_Phi
373
+ HDdDe_iter[0,3:]= [ -HDDij[0][1]*(self.coords[j][2]-De_COM[2]) + HDDij[0][2]*(self.coords[j][1]-De_COM[1]) , HDDij[0][0]*(self.coords[j][2]-De_COM[2]) - HDDij[0][2]*(self.coords[j][0]-De_COM[0]) , -HDDij[0][0]*(self.coords[j][1]-De_COM[1]) + HDDij[0][1]*(self.coords[j][0]-De_COM[0])]
374
+ HDdDe_iter[1,3:]= [ -HDDij[1][1]*(self.coords[j][2]-De_COM[2]) + HDDij[1][2]*(self.coords[j][1]-De_COM[1]) , HDDij[1][0]*(self.coords[j][2]-De_COM[2]) - HDDij[1][2]*(self.coords[j][0]-De_COM[0]) , -HDDij[1][0]*(self.coords[j][1]-De_COM[1]) + HDDij[1][1]*(self.coords[j][0]-De_COM[0])]
375
+ HDdDe_iter[2,3:]= [ -HDDij[2][1]*(self.coords[j][2]-De_COM[2]) + HDDij[2][2]*(self.coords[j][1]-De_COM[1]) , HDDij[2][0]*(self.coords[j][2]-De_COM[2]) - HDDij[2][2]*(self.coords[j][0]-De_COM[0]) , -HDDij[2][0]*(self.coords[j][1]-De_COM[1]) + HDDij[2][1]*(self.coords[j][0]-De_COM[0])]
376
+ #Torque_Delta
377
+ HDdDe_iter[3,0:3]= [ -HDDij[1][0]*(self.coords[i][2]-Dd_COM[2]) + HDDij[2][0]*(self.coords[i][1]-Dd_COM[1]) , -HDDij[1][1]*(self.coords[i][2]-Dd_COM[2]) + HDDij[2][1]*(self.coords[i][1]-Dd_COM[1]) , -HDDij[1][2]*(self.coords[i][2]-Dd_COM[2]) + HDDij[2][2]*(self.coords[i][1]-Dd_COM[1])]
378
+ HDdDe_iter[4,0:3]= [ HDDij[0][0]*(self.coords[i][2]-Dd_COM[2]) - HDDij[2][0]*(self.coords[i][0]-Dd_COM[0]) , HDDij[0][1]*(self.coords[i][2]-Dd_COM[2]) - HDDij[2][1]*(self.coords[i][0]-Dd_COM[0]) , HDDij[0][2]*(self.coords[i][2]-Dd_COM[2]) - HDDij[2][2]*(self.coords[i][0]-Dd_COM[0])]
379
+ HDdDe_iter[5,0:3]= [ -HDDij[0][0]*(self.coords[i][1]-Dd_COM[1]) + HDDij[1][0]*(self.coords[i][0]-Dd_COM[0]) , -HDDij[0][1]*(self.coords[i][1]-Dd_COM[1]) + HDDij[1][1]*(self.coords[i][0]-Dd_COM[0]) , -HDDij[0][2]*(self.coords[i][1]-Dd_COM[1]) + HDDij[1][2]*(self.coords[i][0]-Dd_COM[0])]
380
+ #Torque_Phi
381
+ HDdDe_iter[3,3:]= [ HDDij[1][1]*(self.coords[i][2]-Dd_COM[2])*(self.coords[j][2]-De_COM[2]) - HDDij[1][2]*(self.coords[i][2]-Dd_COM[2])*(self.coords[j][1]-De_COM[1]) - HDDij[2][1]*(self.coords[i][1]-Dd_COM[1])*(self.coords[j][2]-De_COM[2]) + HDDij[2][2]*(self.coords[i][1]-Dd_COM[1])*(self.coords[j][1]-De_COM[1]) , -HDDij[1][0]*(self.coords[i][2]-Dd_COM[2])*(self.coords[j][2]-De_COM[2]) + HDDij[1][2]*(self.coords[i][2]-Dd_COM[2])*(self.coords[j][0]-De_COM[0]) + HDDij[2][0]*(self.coords[i][1]-Dd_COM[1])*(self.coords[j][2]-De_COM[2]) - HDDij[2][2]*(self.coords[i][1]-Dd_COM[1])*(self.coords[j][0]-De_COM[0]) , HDDij[1][0]*(self.coords[i][2]-Dd_COM[2])*(self.coords[j][1]-De_COM[1]) - HDDij[1][1]*(self.coords[i][2]-Dd_COM[2])*(self.coords[j][0]-De_COM[0]) - HDDij[2][0]*(self.coords[i][1]-Dd_COM[1])*(self.coords[j][1]-De_COM[1]) + HDDij[2][1]*(self.coords[i][1]-Dd_COM[1])*(self.coords[j][0]-De_COM[0]) ]
382
+ HDdDe_iter[4,3:]=[ -HDDij[0][1]*(self.coords[i][2]-Dd_COM[2])*(self.coords[j][2]-De_COM[2]) + HDDij[0][2]*(self.coords[i][2]-Dd_COM[2])*(self.coords[j][1]-De_COM[1]) + HDDij[2][1]*(self.coords[i][0]-Dd_COM[0])*(self.coords[j][2]-De_COM[2]) - HDDij[2][2]*(self.coords[i][0]-Dd_COM[0])*(self.coords[j][1]-De_COM[1]) , HDDij[0][0]*(self.coords[i][2]-Dd_COM[2])*(self.coords[j][2]-De_COM[2]) - HDDij[0][2]*(self.coords[i][2]-Dd_COM[2])*(self.coords[j][0]-De_COM[0]) - HDDij[2][0]*(self.coords[i][0]-Dd_COM[0])*(self.coords[j][2]-De_COM[2]) + HDDij[2][2]*(self.coords[i][0]-Dd_COM[0])*(self.coords[j][0]-De_COM[0]) , -HDDij[0][0]*(self.coords[i][2]-Dd_COM[2])*(self.coords[j][1]-De_COM[1]) + HDDij[0][1]*(self.coords[i][2]-Dd_COM[2])*(self.coords[j][0]-De_COM[0]) + HDDij[2][0]*(self.coords[i][0]-Dd_COM[0])*(self.coords[j][1]-De_COM[1]) - HDDij[2][1]*(self.coords[i][0]-Dd_COM[0])*(self.coords[j][0]-De_COM[0]) ]
383
+ HDdDe_iter[5,3:]=[ HDDij[0][1]*(self.coords[i][1]-Dd_COM[1])*(self.coords[j][2]-De_COM[2]) - HDDij[0][2]*(self.coords[i][1]-Dd_COM[1])*(self.coords[j][1]-De_COM[1]) - HDDij[1][1]*(self.coords[i][0]-Dd_COM[0])*(self.coords[j][2]-De_COM[2]) + HDDij[1][2]*(self.coords[i][0]-Dd_COM[0])*(self.coords[j][1]-De_COM[1]) , -HDDij[0][0]*(self.coords[i][1]-Dd_COM[1])*(self.coords[j][2]-De_COM[2]) + HDDij[0][2]*(self.coords[i][1]-Dd_COM[1])*(self.coords[j][0]-De_COM[0]) + HDDij[1][0]*(self.coords[i][0]-Dd_COM[0])*(self.coords[j][2]-De_COM[2]) - HDDij[1][2]*(self.coords[i][0]-Dd_COM[0])*(self.coords[j][0]-De_COM[0]) , HDDij[0][0]*(self.coords[i][1]-Dd_COM[1])*(self.coords[j][1]-De_COM[1]) - HDDij[0][1]*(self.coords[i][1]-Dd_COM[1])*(self.coords[j][0]-De_COM[0]) - HDDij[1][0]*(self.coords[i][0]-Dd_COM[0])*(self.coords[j][1]-De_COM[1]) + HDDij[1][1]*(self.coords[i][0]-Dd_COM[0])*(self.coords[j][0]-De_COM[0]) ]
384
+ HDdDe=numpy.add(HDdDe,HDdDe_iter)
385
+ HDD[numd*6:(numd*6)+6 , nume*6:(nume*6)+6]=HDdDe
386
+
387
+
388
+ #Reconstruction
389
+ new_dim=6*len(Domains)+3*len(HingeAtoms)
390
+ H_new=numpy.zeros((new_dim,new_dim))
391
+ H_new[0:6*len(Domains), 0:6*len(Domains)]=HDD
392
+ H_new[0:6*len(Domains), 6*len(Domains):]=HDH
393
+ H_new[6*len(Domains): ,0:6*len(Domains)]=HHD
394
+ H_new[6*len(Domains):,6*len(Domains):]=HHH
395
+
396
+ #Mass Matrix
397
+ M=numpy.zeros((H_new.shape))
398
+
399
+ #MHH
400
+ if(mass_type == 'unit'):
401
+ M[6*len(Domains):,6*len(Domains):]=numpy.identity(len(HingeAtoms)*3)
402
+ elif(mass_type == 'atom'):
403
+ try:
404
+ lst= [atomic_weight[self.atoms[i].get_element()] for i in HingeAtoms]
405
+ lst= list(itertools.chain.from_iterable(itertools.repeat(x, 3) for x in lst))
406
+ numpy.fill_diagonal( M[6*len(Domains):,6*len(Domains):] , lst )
407
+ except:
408
+ print('Unknown atom or the atomic weight not available in packman.constants')
409
+ elif(mass_type == 'residue'):
410
+ try:
411
+ lst= [amino_acid_molecular_weight[self.atoms[i].get_parent().get_name()] for i in HingeAtoms]
412
+ lst= list(itertools.chain.from_iterable(itertools.repeat(x, 3) for x in lst))
413
+ numpy.fill_diagonal( M[6*len(Domains):,6*len(Domains):] , lst )
414
+ except:
415
+ print('Unknown Amino Acid encountered or molecular weight not available in packman.constants')
416
+
417
+ #MDD (Scheduled to be paralalysed)
418
+ for numd,d in enumerate(Domains):
419
+ #F-Delta
420
+ domain_block=numpy.zeros((6,6))
421
+ if(mass_type == 'unit'):
422
+ numpy.fill_diagonal( domain_block[0:3,0:3] , len(DomainGroups[d]) )
423
+ elif(mass_type == 'atom'):
424
+ DomainMass = numpy.sum( [atomic_weight[self.atoms[i].get_element()] for i in DomainGroups[d]] )
425
+ numpy.fill_diagonal( domain_block[0:3,0:3] , DomainMass )
426
+ elif(mass_type == 'residue'):
427
+ DomainMass = numpy.sum( [amino_acid_molecular_weight[self.atoms[i].get_parent().get_name()] for i in DomainGroups[d]] )
428
+ numpy.fill_diagonal( domain_block[0:3,0:3] , DomainMass )
429
+
430
+ #Torque_Phi
431
+ COM=DomainInfo[d][1]
432
+ for numi,i in enumerate(DomainGroups[d]):
433
+ MDdDd_local=numpy.array(
434
+ [
435
+ [ (self.coords[i][2]-COM[2])**2+(self.coords[i][1]-COM[1])**2 , -(self.coords[i][1]-COM[1])*(self.coords[i][0]-COM[0]) , -(self.coords[i][0]-COM[0])*(self.coords[i][2]-COM[2]) ],
436
+ [ -(self.coords[i][1]-COM[1])*(self.coords[i][0]-COM[0]) , (self.coords[i][2]-COM[2])**2+(self.coords[i][0]-COM[0])**2 , -(self.coords[i][1]-COM[1])*(self.coords[i][2]-COM[2]) ],
437
+ [ -(self.coords[i][0]-COM[0])*(self.coords[i][2]-COM[2]) , -(self.coords[i][1]-COM[1])*(self.coords[i][2]-COM[2]) , (self.coords[i][0]-COM[0])**2+(self.coords[i][1]-COM[1])**2 ],
438
+ ])
439
+
440
+ #Maybe remove if conditions later, create separate functions for improving the speed
441
+ if(mass_type == 'unit'):
442
+ domain_block[3:,3:]=numpy.add(domain_block[3:,3:],MDdDd_local)
443
+ elif(mass_type == 'atom'):
444
+ MDdDd_local = MDdDd_local * atomic_weight[self.atoms[i].get_element()]
445
+ domain_block[3:,3:]=numpy.add(domain_block[3:,3:],MDdDd_local)
446
+ elif(mass_type == 'residue'):
447
+ MDdDd_local = MDdDd_local * amino_acid_molecular_weight[self.atoms[i].get_parent().get_name()]
448
+ domain_block[3:,3:]=numpy.add(domain_block[3:,3:],MDdDd_local)
449
+
450
+ M[numd*6:(numd*6)+6 , numd*6:(numd*6)+6]=domain_block
451
+
452
+ self.domain_hessian, self.domain_mass_matrix, self.domain_info = H_new, M, DomainInfo #DomainInfo is saved to check the sequence in which H_new is formed
453
+ return True
454
+
455
+ def calculate_RT_eigen_vectors(self):
456
+ """Calculate the reverse transformed vectors from the hdANM eigenvectors.
457
+
458
+ Reverse transformed means that the hdANM eigenvector of dimension: 6D+3H x 6D+3H (D: Number of domains; H: Number of hinge atoms) are converted to 3N x 6D+3H (N: Number of atoms)
459
+
460
+ Note:
461
+ - It was refered as 'exploded vector' utill version 1.3.3
462
+ """
463
+ x0 = numpy.array([i.get_location() for i in self.atoms])
464
+ d0 = [i.get_domain_id() for i in self.atoms]
465
+
466
+ exploded_vectors=numpy.zeros((len(x0)*3, len(self.eigen_values) ))
467
+
468
+ for mode_number in range(0,self.eigen_vectors.shape[1],1):
469
+ new_column=[]
470
+ HingeResidue=0
471
+ for numi,i in enumerate(x0):
472
+ if(d0[numi][0]=='D'):
473
+ D_delta_phi= self.eigen_vectors[:,mode_number][self.domain_info[d0[numi]][0]*6 : (self.domain_info[d0[numi]][0]*6)+6]
474
+ D_COM=self.domain_info[d0[numi]][1]
475
+ new_x= ( D_delta_phi[0] + (D_delta_phi[4]*(i[2]-D_COM[2])) - (D_delta_phi[5]*(i[1]-D_COM[1])) )
476
+ new_y= ( D_delta_phi[1] + (D_delta_phi[3]*(i[2]-D_COM[2])) - (D_delta_phi[5]*(i[0]-D_COM[0])) )
477
+ new_z= ( D_delta_phi[2] + (D_delta_phi[3]*(i[1]-D_COM[1])) - (D_delta_phi[4]*(i[0]-D_COM[0])) )
478
+ if(d0[numi][0]=='H'):
479
+ delta=self.eigen_vectors[:,mode_number][6*len(self.domain_info):][HingeResidue*3:(HingeResidue*3)+3]
480
+ new_x=delta[0]
481
+ new_y=delta[1]
482
+ new_z=delta[2]
483
+ HingeResidue+=1
484
+ new_column.extend([new_x,new_y,new_z])
485
+ exploded_vectors[:,mode_number]=numpy.array(new_column)
486
+
487
+ self.RT_eigen_vectors = exploded_vectors
488
+ return True
489
+
490
+ def calculate_fluctuations(self):
491
+ """Calculate the Fluctuations of the hd-ANM model.
492
+
493
+ The fluctualtions/ theoretical b-factors are calculated using this method.
494
+
495
+ Note:
496
+ - Fluctuations are calculated. use hdANM().get_fluctuations() to obtain the fluctuations.
497
+ - Endmode needs to be put in the code if and when required.
498
+ - hdANM().fluctuations stores the output of this function.
499
+ """
500
+ x0 = numpy.array([i.get_location() for i in self.atoms])
501
+
502
+ if(self.RT_eigen_vectors == None):
503
+ self.calculate_RT_eigen_vectors()
504
+
505
+ exploded_vectors = self.RT_eigen_vectors
506
+ exploded_vectors = exploded_vectors.T
507
+
508
+ mode_bfactors=[]
509
+ for numi,i in enumerate(self.eigen_values[6:]):
510
+ evec_row=exploded_vectors[numi+6]
511
+ mode_bfactors.append([ float(evec_row[j]**2 + evec_row[j+1]**2 + evec_row[j+2]**2)/i for j in range(0,len(x0)*3,3)])
512
+
513
+ mode_bfactors=numpy.array(mode_bfactors)
514
+ self.fluctuations = [numpy.sum(i) for i in mode_bfactors.T]
515
+ return True
516
+
517
+ def calculate_hessian_pseudoinverse(self, n_modes="all"):
518
+ """Calculate the hessian pseudoinverse for the hd-ANM modes
519
+
520
+ Pseudoinverse is calculated using this methd. Please note that first 6 rigid modes are eliminated in this calculation.
521
+
522
+ Note:
523
+ - Can be called on demand or can be called from get method automatically (Needs thinking)
524
+ """
525
+
526
+
527
+ if(self.RT_eigen_vectors == None):
528
+ self.calculate_RT_eigen_vectors()
529
+ EVec=self.get_RT_eigen_vectors().T
530
+ if(n_modes=="all"):
531
+ self.hessian_pseudoinverse = numpy.matmul( numpy.matmul( EVec[6:].transpose() , numpy.diag(1/self.get_eigenvalues()[6:]) ) , EVec[6:] )
532
+ else:
533
+ self.hessian_pseudoinverse = numpy.matmul( numpy.matmul( EVec[6:6+n_modes].transpose() , numpy.diag(1/self.get_eigenvalues()[6:6+n_modes]) ) , EVec[6:6+n_modes] )
534
+
535
+ def calculate_cross_correlation( self, n_modes = "all" ):
536
+ """Calculate the cross correlation matrix for the hdANM modes.
537
+
538
+ Crosscorrelation matrix is generated for all modes by default. Please change the n_modes parameter to restrict modes.
539
+
540
+ Args:
541
+ - n_modes (int): Number of modes that need to be considered to calculate the cross correlation matrix.
542
+ """
543
+ self.calculate_hessian_pseudoinverse(n_modes=n_modes)
544
+
545
+ self.crosscorrelation_matrix = numpy.zeros( (len(self.atoms), len(self.atoms)) )
546
+ for i in range(0,len(self.atoms)):
547
+ for j in range(0,len(self.atoms)):
548
+ trace_H_inv_ij = numpy.trace( self.get_hessian_pseudoinverse()[i*3:i*3+3,j*3:j*3+3] )
549
+ trace_H_inv_ii = numpy.trace( self.get_hessian_pseudoinverse()[i*3:i*3+3,i*3:i*3+3] )
550
+ trace_H_inv_jj = numpy.trace( self.get_hessian_pseudoinverse()[j*3:j*3+3,j*3:j*3+3] )
551
+
552
+ self.crosscorrelation_matrix[i][j] = trace_H_inv_ij / numpy.sqrt( trace_H_inv_ii*trace_H_inv_jj )
553
+
554
+ def calculate_movie(self, mode_number, scale=1.5, n=20, extrapolation="curvilinear", ftype='cif'):
555
+ """This function generates the dynamic 3D projection of the normal modes obtained using hd-ANM. The 3D projection can be linearly extrapolated or curvilinearly extrapolated depending on the choices. The first frame is the original structure and the projection progresses in positive (+) direction, returning to original structure and then in negative direction (-) again returning to the original structure.
556
+
557
+ Args:
558
+ mode_number (int) : Mode number. (first non-rigid mode is 6th)
559
+ scale (float) : Multiplier; extent to which mode will be extrapolated. Defaults to 1.5
560
+ n (int) : Number of frames in output (should be =>8 and ideally multiple of 4) Defaults to 20
561
+ extrapolation (linear/curvilinear) : Extrapolation method Defaults to "curvilinear"
562
+ ftype (string) : Extension of the output file (.cif / .pdb)
563
+
564
+ Note:
565
+ - Scale and n parameters should be redesigned.
566
+ - direction is the variable which be allow user to explore only positive or only negative direction of the modes.
567
+
568
+ Returns:
569
+ True if successful; false otherwise.
570
+ """
571
+
572
+ x0=numpy.array([i.get_location() for i in self.atoms])
573
+ d0=[i.get_domain_id() for i in self.atoms]
574
+ new_coords=[]
575
+
576
+ if(extrapolation=="linear"):
577
+ movement = [ numpy.sin(k*(1.0/float(n))*2*numpy.pi) for k in range(0,n+1,1) ]
578
+ ModelsOfTheProtein = []
579
+ for j in movement:
580
+ HingeResidue=0
581
+ AtomsOfTheFrame = {}
582
+ for numi,i in enumerate(x0):
583
+ if(d0[numi][0]=='D'):
584
+ D_delta_phi= self.eigen_vectors[:,mode_number][self.domain_info[d0[numi]][0]*6 : (self.domain_info[d0[numi]][0]*6)+6]
585
+ D_COM=self.domain_info[d0[numi]][1]
586
+ new_x=i[0]+scale*j* ( D_delta_phi[0] + (D_delta_phi[4]*(i[2]-D_COM[2])) - (D_delta_phi[5]*(i[1]-D_COM[1])) )
587
+ new_y=i[1]+scale*j* ( D_delta_phi[1] + (D_delta_phi[3]*(i[2]-D_COM[2])) - (D_delta_phi[5]*(i[0]-D_COM[0])) )
588
+ new_z=i[2]+scale*j* ( D_delta_phi[2] + (D_delta_phi[3]*(i[1]-D_COM[1])) - (D_delta_phi[4]*(i[0]-D_COM[0])) )
589
+ if(d0[numi][0]=='H'):
590
+ delta=self.eigen_vectors[:,mode_number][6*len(self.domain_info):][HingeResidue*3:(HingeResidue*3)+3]
591
+ new_x=i[0]+scale*j*delta[0]
592
+ new_y=i[1]+scale*j*delta[1]
593
+ new_z=i[2]+scale*j*delta[2]
594
+ HingeResidue+=1
595
+ new_x , new_y, new_z = new_x.real , new_y.real , new_z.real
596
+ new_coords.append([new_x,new_y,new_z])
597
+ currentatm = Atom(self.atoms[numi].get_id() , self.atoms[numi].get_name(), numpy.array([new_x,new_y,new_z]), self.atoms[numi].get_occupancy(), self.atoms[numi].get_bfactor(), self.atoms[numi].get_element(),self.atoms[numi].get_charge(), self.atoms[numi].get_parent() )
598
+ AtomsOfTheFrame[numi] = currentatm
599
+
600
+ ModelsOfTheProtein.append( Model(j, AtomsOfTheFrame, None, None, None, None) )
601
+
602
+ Annotations = self.atoms[0].get_parent().get_parent().get_parent().get_parent().get_data()
603
+ prot = Protein(str(mode_number), ModelsOfTheProtein)
604
+ prot.set_data(Annotations)
605
+ prot.write_structure( str(mode_number)+'.'+ftype )
606
+
607
+
608
+ elif(extrapolation=="curvilinear"):
609
+ movement = [ numpy.sin(k*(1.0/float(n))*2*numpy.pi) for k in range(0,n+1,1) ]
610
+ ModelsOfTheProtein = []
611
+ for j in movement:
612
+ HingeResidue=0
613
+ AtomsOfTheFrame = {}
614
+ for numi,i in enumerate(x0):
615
+ if(d0[numi][0]=='D'):
616
+ D_delta_phi= self.eigen_vectors[:,mode_number][self.domain_info[d0[numi]][0]*6 : (self.domain_info[d0[numi]][0]*6)+6]
617
+ #D_mu= D_delta_phi[3:]
618
+ Q_D_n=numpy.linalg.norm(D_delta_phi[3:])
619
+ D_mu=D_delta_phi[3:] / Q_D_n
620
+ D_COM=self.domain_info[d0[numi]][1]
621
+ #D_delta_phi[0] is questionable ; D_delta_phi[3:] is also questionable
622
+ new_x= D_COM[0]+ scale*j*D_delta_phi[0] \
623
+ + ( numpy.cos(scale*j*Q_D_n)+ D_mu[0]**2 * (1-numpy.cos(scale*j*Q_D_n)) ) * (i[0] -D_COM[0]) \
624
+ + ( D_mu[0]*D_mu[1]*(1-numpy.cos(scale*j*Q_D_n)) - D_mu[2]*numpy.sin(scale*j*Q_D_n) ) * (i[1] -D_COM[1]) \
625
+ + ( D_mu[0]*D_mu[2]*(1-numpy.cos(scale*j*Q_D_n)) + D_mu[1]*numpy.sin(scale*j*Q_D_n) ) * (i[2] -D_COM[2])
626
+
627
+ new_y= D_COM[1]+ scale*j*D_delta_phi[1] \
628
+ + ( D_mu[0]*D_mu[1]*(1-numpy.cos(scale*j*Q_D_n)) + D_mu[2]*numpy.sin(scale*j*Q_D_n) ) * (i[0] -D_COM[0]) \
629
+ + ( numpy.cos(scale*j*Q_D_n)+D_mu[1]**2 * (1-numpy.cos(scale*j*Q_D_n)) ) * (i[1] -D_COM[1]) \
630
+ + ( D_mu[1]*D_mu[2]*(1-numpy.cos(scale*j*Q_D_n)) - D_mu[0]*numpy.sin(scale*j*Q_D_n) ) * (i[2] -D_COM[2])
631
+
632
+ new_z= D_COM[2]+ scale*j*D_delta_phi[2] \
633
+ + ( D_mu[0]*D_mu[2]*(1-numpy.cos(scale*j*Q_D_n)) - D_mu[1]*numpy.sin(scale*j*Q_D_n) ) * (i[0] -D_COM[0]) \
634
+ + ( D_mu[1]*D_mu[2]*(1-numpy.cos(scale*j*Q_D_n)) + D_mu[0]*numpy.sin(scale*j*Q_D_n) ) * (i[1] -D_COM[1]) \
635
+ + ( numpy.cos(scale*j*Q_D_n)+ D_mu[2]**2 * (1-numpy.cos(scale*j*Q_D_n)) ) * (i[2] -D_COM[2])
636
+
637
+
638
+ if(d0[numi][0]=='H'):
639
+ delta=self.eigen_vectors[:,mode_number][6*len(self.domain_info):][HingeResidue*3:(HingeResidue*3)+3]
640
+ new_x=i[0]+scale*j*delta[0]
641
+ new_y=i[1]+scale*j*delta[1]
642
+ new_z=i[2]+scale*j*delta[2]
643
+ HingeResidue+=1
644
+ new_x , new_y, new_z = new_x.real , new_y.real , new_z.real
645
+ new_coords.append([new_x,new_y,new_z])
646
+ currentatm = Atom(self.atoms[numi].get_id() , self.atoms[numi].get_name(), numpy.array([new_x,new_y,new_z]), self.atoms[numi].get_occupancy(), self.atoms[numi].get_bfactor(), self.atoms[numi].get_element(),self.atoms[numi].get_charge(), self.atoms[numi].get_parent() )
647
+ AtomsOfTheFrame[numi] = currentatm
648
+
649
+ ModelsOfTheProtein.append( Model(j, AtomsOfTheFrame, None, None, None, None) )
650
+
651
+ Annotations = self.atoms[0].get_parent().get_parent().get_parent().get_parent().get_data()
652
+ prot = Protein(str(mode_number), ModelsOfTheProtein)
653
+ prot.set_data(Annotations)
654
+ prot.write_structure( str(mode_number)+'.'+ftype )
655
+
656
+ return True