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.
- Program Files/Python39/Lib/site-packages/packman/__init__.py +18 -0
- Program Files/Python39/Lib/site-packages/packman/__main__.py +4 -0
- Program Files/Python39/Lib/site-packages/packman/__pycache__/__init__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/__pycache__/__main__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/anm/__init__.py +25 -0
- Program Files/Python39/Lib/site-packages/packman/anm/__pycache__/__init__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/anm/__pycache__/anm.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/anm/__pycache__/hd_anm.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/anm/anm.py +317 -0
- Program Files/Python39/Lib/site-packages/packman/anm/hd_anm.py +656 -0
- Program Files/Python39/Lib/site-packages/packman/apps/__init__.py +25 -0
- Program Files/Python39/Lib/site-packages/packman/apps/__pycache__/__init__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/apps/__pycache__/calculate_entropy.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/apps/__pycache__/dci.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/apps/__pycache__/hdanm.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/apps/__pycache__/predict_hinge.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/apps/calculate_entropy.py +60 -0
- Program Files/Python39/Lib/site-packages/packman/apps/dci.py +323 -0
- Program Files/Python39/Lib/site-packages/packman/apps/hdanm.py +47 -0
- Program Files/Python39/Lib/site-packages/packman/apps/predict_hinge.py +375 -0
- Program Files/Python39/Lib/site-packages/packman/bin/GUI.py +709 -0
- Program Files/Python39/Lib/site-packages/packman/bin/PACKMAN.py +154 -0
- Program Files/Python39/Lib/site-packages/packman/bin/__init__.py +27 -0
- Program Files/Python39/Lib/site-packages/packman/bin/__pycache__/GUI.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/bin/__pycache__/PACKMAN.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/bin/__pycache__/__init__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/bin/logo.ico +0 -0
- Program Files/Python39/Lib/site-packages/packman/constants/Constants.py +236 -0
- Program Files/Python39/Lib/site-packages/packman/constants/__init__.py +3 -0
- Program Files/Python39/Lib/site-packages/packman/constants/__pycache__/Constants.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/constants/__pycache__/__init__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/entropy/__init__.py +12 -0
- Program Files/Python39/Lib/site-packages/packman/entropy/__pycache__/__init__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/entropy/__pycache__/entropy.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/entropy/entropy.py +155 -0
- Program Files/Python39/Lib/site-packages/packman/geometry/__init__.py +17 -0
- Program Files/Python39/Lib/site-packages/packman/geometry/__pycache__/__init__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/geometry/__pycache__/geometry.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/geometry/geometry.py +112 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/__init__.py +45 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/__init__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/annotations.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/atom.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/bond.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/chain.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/hetmol.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/model.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/molecule.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/protein.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/__pycache__/residue.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/annotations.py +92 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/atom.py +332 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/bond.py +186 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/chain.py +323 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/hetmol.py +224 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/model.py +703 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/molecule.py +470 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/protein.py +162 -0
- Program Files/Python39/Lib/site-packages/packman/molecule/residue.py +322 -0
- Program Files/Python39/Lib/site-packages/packman/tests/__init__.py +4 -0
- Program Files/Python39/Lib/site-packages/packman/tests/__pycache__/__init__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/tests/anm/__init__.py +0 -0
- Program Files/Python39/Lib/site-packages/packman/tests/anm/__pycache__/__init__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/tests/anm/__pycache__/test_anm.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/tests/anm/test_anm.py +52 -0
- Program Files/Python39/Lib/site-packages/packman/tests/data/1prw.hng +3 -0
- Program Files/Python39/Lib/site-packages/packman/tests/data/1prw.pdb +1871 -0
- Program Files/Python39/Lib/site-packages/packman/tests/data/4hla.cif +5058 -0
- Program Files/Python39/Lib/site-packages/packman/tests/data/__init__.py +0 -0
- Program Files/Python39/Lib/site-packages/packman/tests/data/__pycache__/__init__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/tests/entropy/__init__.py +0 -0
- Program Files/Python39/Lib/site-packages/packman/tests/entropy/__pycache__/__init__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/tests/entropy/__pycache__/test_entropy.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/tests/entropy/test_entropy.py +30 -0
- Program Files/Python39/Lib/site-packages/packman/tests/molecule/__init__.py +0 -0
- Program Files/Python39/Lib/site-packages/packman/tests/molecule/__pycache__/__init__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/tests/molecule/__pycache__/test_molecule.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/tests/molecule/test_molecule.py +95 -0
- Program Files/Python39/Lib/site-packages/packman/utilities/__init__.py +1 -0
- Program Files/Python39/Lib/site-packages/packman/utilities/__pycache__/__init__.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/utilities/__pycache__/utilities.cpython-39.pyc +0 -0
- Program Files/Python39/Lib/site-packages/packman/utilities/utilities.py +180 -0
- Program Files/Python39/Lib/site-packages/py_packman-1.4.0-py3.9.egg-info/PKG-INFO +86 -0
- Program Files/Python39/Lib/site-packages/py_packman-1.4.0-py3.9.egg-info/SOURCES.txt +51 -0
- Program Files/Python39/Lib/site-packages/py_packman-1.4.0-py3.9.egg-info/dependency_links.txt +1 -0
- Program Files/Python39/Lib/site-packages/py_packman-1.4.0-py3.9.egg-info/entry_points.txt +3 -0
- Program Files/Python39/Lib/site-packages/py_packman-1.4.0-py3.9.egg-info/requires.txt +5 -0
- Program Files/Python39/Lib/site-packages/py_packman-1.4.0-py3.9.egg-info/top_level.txt +1 -0
- Program Files/Python39/Scripts/packman-script.py +33 -0
- Program Files/Python39/Scripts/packman.exe +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Author: Pranav Khade, Iowa State University
|
|
3
|
+
# Please read the project licence file for the Copyrights.
|
|
4
|
+
|
|
5
|
+
"""The 'packman.apps' module is a collection of applications built on packman.molecule API.
|
|
6
|
+
|
|
7
|
+
Notes:
|
|
8
|
+
* Current apps list: - predict_hinge : A program to predict the hinge on the molecule given the atoms and relevent parameters
|
|
9
|
+
|
|
10
|
+
Example::
|
|
11
|
+
* Review the packman.bin.PACKMAN.py file for the app use.
|
|
12
|
+
|
|
13
|
+
Todo:
|
|
14
|
+
* Add new features
|
|
15
|
+
* Use ``sphinx.ext.todo`` extension
|
|
16
|
+
* Clean the code
|
|
17
|
+
* Redesign print statements
|
|
18
|
+
* Add Tutorial Link
|
|
19
|
+
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from .predict_hinge import predict_hinge, hinge_cli
|
|
23
|
+
from .hdanm import hdanm_cli
|
|
24
|
+
from .calculate_entropy import entropy_cli
|
|
25
|
+
from .dci import DCI, dci_cli
|
|
Binary file
|
Program Files/Python39/Lib/site-packages/packman/apps/__pycache__/calculate_entropy.cpython-39.pyc
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
Program Files/Python39/Lib/site-packages/packman/apps/__pycache__/predict_hinge.cpython-39.pyc
ADDED
|
Binary file
|
|
@@ -0,0 +1,60 @@
|
|
|
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 calculate_entropy
|
|
10
|
+
help( calculate_entropy )
|
|
11
|
+
|
|
12
|
+
Authors:
|
|
13
|
+
* Pranav Khade(https://github.com/Pranavkhade)
|
|
14
|
+
"""
|
|
15
|
+
from ..molecule import download_structure
|
|
16
|
+
from ..molecule import load_structure
|
|
17
|
+
from ..entropy import PackingEntropy
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import logging
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def entropy_cli(args,mol):
|
|
25
|
+
"""Command-line Interface for the 'entropy' command. Please check the packman.bin.PACKMAN file for more details.
|
|
26
|
+
|
|
27
|
+
This function is for the CLI and not an integral function for the API.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
args (parser.parse_args()) : The arguments that were passed by the user to the PACKMAN-hinge app.
|
|
31
|
+
mol (packman.molecule.Protein) : The 'Protein' object for the anaylsis.
|
|
32
|
+
"""
|
|
33
|
+
try:
|
|
34
|
+
input_chains = args.chains.split(',')
|
|
35
|
+
except:
|
|
36
|
+
input_chains = None
|
|
37
|
+
|
|
38
|
+
if(args.type=='PackingEntropy'):
|
|
39
|
+
args.outputfile.write('Frame\tChain\tResidueID\tResidueName\tPackingEntropy\n')
|
|
40
|
+
for i in mol:
|
|
41
|
+
try:
|
|
42
|
+
result = PackingEntropy(i.get_atoms(),chains=input_chains,probe_size=args.probe_size,onspherepoints=args.onspherepoints)
|
|
43
|
+
except:
|
|
44
|
+
logging.error('Please check the parameters.')
|
|
45
|
+
exit()
|
|
46
|
+
|
|
47
|
+
for j in i.get_residues():
|
|
48
|
+
try:
|
|
49
|
+
args.outputfile.write( str(i.get_id())+'\t'+str(j.get_parent().get_id())+'\t'+str(j.get_id())+'\t'+str(j.get_name())+'\t'+str(j.get_entropy('PackingEntropy'))+'\n' )
|
|
50
|
+
except:
|
|
51
|
+
None
|
|
52
|
+
try:
|
|
53
|
+
args.outputfile.write('Total (Frame '+str(i.get_id())+')\t'+str(result.get_total_entropy())+'\n' )
|
|
54
|
+
except:
|
|
55
|
+
None
|
|
56
|
+
args.outputfile.flush()
|
|
57
|
+
args.outputfile.close()
|
|
58
|
+
else:
|
|
59
|
+
logging.error('Please provide a valid entropy type (-type option). (Options: 1. PackingEntropy )')
|
|
60
|
+
return True
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""The 'DCI' object host file.
|
|
4
|
+
This is file information, not the class information. This information is only for the API developers.
|
|
5
|
+
Please read the 'DCI' object documentation for details.
|
|
6
|
+
Example::
|
|
7
|
+
from packman.apps import DCI
|
|
8
|
+
help( DCI )
|
|
9
|
+
Notes:
|
|
10
|
+
* Tutorial:
|
|
11
|
+
* For more details about the parameters for compliance, or to site this, read the following paper:
|
|
12
|
+
Todo:
|
|
13
|
+
* Finish writing up the documentation.
|
|
14
|
+
* Finish optimizing the performance.
|
|
15
|
+
Authors:
|
|
16
|
+
* Ambuj Kumar (ambuj@iastate.edu)
|
|
17
|
+
* Pranav Khade (https://github.com/Pranavkhade)
|
|
18
|
+
"""
|
|
19
|
+
import logging
|
|
20
|
+
|
|
21
|
+
import numpy
|
|
22
|
+
from sklearn.metrics import calinski_harabasz_score as chs
|
|
23
|
+
from scipy.cluster.hierarchy import ward, fcluster
|
|
24
|
+
|
|
25
|
+
from ..anm import ANM
|
|
26
|
+
from ..molecule import Protein
|
|
27
|
+
|
|
28
|
+
class DCI():
|
|
29
|
+
"""This class contains the code for DCI analysis.
|
|
30
|
+
|
|
31
|
+
Notes:
|
|
32
|
+
* Tutorial:
|
|
33
|
+
* Webserver:
|
|
34
|
+
* Publication:
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
mol (packman.molecule.Protein) : Structure in the 'Protein' object.
|
|
38
|
+
cutoff (float) : GNM distance cutoff. Default set to 7.5
|
|
39
|
+
chain (string) : Protein chain id. Default is set to using all chains.
|
|
40
|
+
n_com (int) : Number of communities to generate. Default the program will explore best possible cluster numbers for the given data.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def __init__(self, mol, cutoff = 7.0, chain = None, n_com = None):
|
|
44
|
+
self.molObj = mol
|
|
45
|
+
assert type( self.molObj ) == Protein, "mol should be a packman.molecule.Protein object."
|
|
46
|
+
|
|
47
|
+
if chain:
|
|
48
|
+
self.atoms = [i for i in self.molObj[0][chain].get_calpha()]
|
|
49
|
+
collect_resi = [i.get_atoms() for i in self.molObj[0][chain].get_residues() if i.get_calpha() != None]
|
|
50
|
+
else:
|
|
51
|
+
self.atoms = [i for i in self.molObj[0].get_calpha()]
|
|
52
|
+
collect_resi = [i.get_atoms() for i in self.molObj[0].get_residues() if i.get_calpha() != None]
|
|
53
|
+
|
|
54
|
+
if n_com:
|
|
55
|
+
if (n_com < 2) or (n_com > len(self.atoms)):
|
|
56
|
+
raise ValueError("Value of n_com should be 2 or greater but less than or equal to the maximum number of residues in the protein")
|
|
57
|
+
|
|
58
|
+
if cutoff <= 0:
|
|
59
|
+
raise ValueError("Value of cutoff can only be a positive integer")
|
|
60
|
+
|
|
61
|
+
self.cutoff = cutoff
|
|
62
|
+
self.coords = numpy.array([x.get_location() for x in self.atoms])
|
|
63
|
+
self.pdbid = mol.get_id()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
self.calculate_kirchoff()
|
|
67
|
+
self.calculate_decomposition()
|
|
68
|
+
self.calculate_crosscorrelation()
|
|
69
|
+
dist_mat = 1-self.C
|
|
70
|
+
|
|
71
|
+
#Global vars
|
|
72
|
+
self.store_communities = dict()
|
|
73
|
+
self.store_score = dict()
|
|
74
|
+
|
|
75
|
+
if n_com:
|
|
76
|
+
self.get_n_communities(dist_mat, n_com)
|
|
77
|
+
else:
|
|
78
|
+
self.calculate_cluster(dist_mat)
|
|
79
|
+
|
|
80
|
+
#Get functions
|
|
81
|
+
def get_labels(self, community_obj):
|
|
82
|
+
"""Get the dictionary of individual cluster labels for each residue.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
community_obj ([int]) : Output from hierarchical clustering.
|
|
86
|
+
"""
|
|
87
|
+
res_store = dict()
|
|
88
|
+
for label, atm in zip(community_obj, self.atoms):
|
|
89
|
+
|
|
90
|
+
try:
|
|
91
|
+
res_store[label]
|
|
92
|
+
except:
|
|
93
|
+
res_store[label] = list()
|
|
94
|
+
|
|
95
|
+
res_store[label].append(str(atm.get_parent().get_id())+atm.get_parent().get_parent().get_id())
|
|
96
|
+
|
|
97
|
+
return res_store
|
|
98
|
+
|
|
99
|
+
def get_range(self, iterable):
|
|
100
|
+
"""Get the consequent numbers in the list.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
iterable ([int]) : Array containing iterable.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
first, last (int,int) : First and Last element of the consequent numbers.
|
|
107
|
+
"""
|
|
108
|
+
first = last = iterable[0]
|
|
109
|
+
for n in iterable[1:]:
|
|
110
|
+
if n - 1 == last:
|
|
111
|
+
last = n
|
|
112
|
+
else:
|
|
113
|
+
yield first, last
|
|
114
|
+
first = last = n
|
|
115
|
+
yield first, last
|
|
116
|
+
|
|
117
|
+
def get_n_communities(self, dist_mat, n):
|
|
118
|
+
"""Get the number of communities
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
dist_mat (numpy.array) : Crosscorelation based euclidean distance.
|
|
122
|
+
n (int) : Number of desired community.
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
label ([int]) : Label assigned to each residue.
|
|
126
|
+
"""
|
|
127
|
+
Data = numpy.triu(dist_mat)
|
|
128
|
+
Z = ward(Data)
|
|
129
|
+
label = fcluster(Z, n, criterion='maxclust')
|
|
130
|
+
self.store_communities[n] = label
|
|
131
|
+
self.store_score[n] = 'user-key'
|
|
132
|
+
return label
|
|
133
|
+
|
|
134
|
+
def get_cluster_labels(self):
|
|
135
|
+
"""Get the cluster label of the 'most optimal' community (Read the paper for more details)
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
best_community ([int]) : cluster label of the 'most optimal' community
|
|
139
|
+
"""
|
|
140
|
+
return self.best_community
|
|
141
|
+
|
|
142
|
+
def get_crosscorrelation(self):
|
|
143
|
+
"""Get the cross-correlation.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
C (numpy.array) : Cross-correlation matrix.
|
|
147
|
+
"""
|
|
148
|
+
return self.C
|
|
149
|
+
|
|
150
|
+
def get_communities(self):
|
|
151
|
+
"""Get all the communities generated using DCI.
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
store_comminities (dict) : List of communities with number of communities as a key.
|
|
155
|
+
"""
|
|
156
|
+
return self.store_communities
|
|
157
|
+
|
|
158
|
+
#Calculate functions
|
|
159
|
+
def calculate_kirchoff(self, gamma = 1.0):
|
|
160
|
+
"""Calculate the Gaussian Network Model (GNM) Kirchoff Matrix.
|
|
161
|
+
|
|
162
|
+
The matrix is stored in the self.GNM_MAT variable.
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
True if successful; None otherwise.
|
|
166
|
+
"""
|
|
167
|
+
n_atoms=len(self.coords)
|
|
168
|
+
self.GNM_MAT=numpy.zeros((n_atoms, n_atoms), float)
|
|
169
|
+
for i in range(len(self.coords)):
|
|
170
|
+
diff = self.coords[i+1:, :] - self.coords[i]
|
|
171
|
+
squared_diff = diff**2
|
|
172
|
+
for j, s_ij in enumerate(squared_diff.sum(1)):
|
|
173
|
+
if s_ij <= self.cutoff**2:
|
|
174
|
+
diff_coords = diff[j]
|
|
175
|
+
j = j + i + 1
|
|
176
|
+
self.GNM_MAT[i, j] = -gamma
|
|
177
|
+
self.GNM_MAT[j, i] = -gamma
|
|
178
|
+
self.GNM_MAT[i, i] = self.GNM_MAT[i, i] + gamma
|
|
179
|
+
self.GNM_MAT[j, j] = self.GNM_MAT[j, j] + gamma
|
|
180
|
+
return True
|
|
181
|
+
|
|
182
|
+
def calculate_decomposition(self):
|
|
183
|
+
"""Eigen decomposition calculation.
|
|
184
|
+
|
|
185
|
+
Access the eigen values and eigen vectors with self.eigen_values and self.eigen_vectors
|
|
186
|
+
|
|
187
|
+
Returns:
|
|
188
|
+
True if successful; None otherwise.
|
|
189
|
+
"""
|
|
190
|
+
self.eigen_values, self.eigen_vectors = numpy.linalg.eigh(self.GNM_MAT)
|
|
191
|
+
return True
|
|
192
|
+
|
|
193
|
+
def calculate_crosscorrelation(self):
|
|
194
|
+
"""Calculate the cross-correlation. (Read the paper for more details)
|
|
195
|
+
|
|
196
|
+
Returns:
|
|
197
|
+
True if successful; None otherwise.
|
|
198
|
+
"""
|
|
199
|
+
n = len(self.atoms)
|
|
200
|
+
EVec=self.eigen_vectors.T
|
|
201
|
+
self.hessian_inv= numpy.matmul( numpy.matmul( EVec[1:].transpose() , numpy.diag(1/self.eigen_values[1:]) ) , EVec[1:] )
|
|
202
|
+
self.C = numpy.zeros((n , n))
|
|
203
|
+
for i in range(n):
|
|
204
|
+
for j in range(n):
|
|
205
|
+
self.C[i, j] = float(self.hessian_inv[i, j])/numpy.sqrt(self.hessian_inv[i, i]*self.hessian_inv[j, j])
|
|
206
|
+
|
|
207
|
+
return True
|
|
208
|
+
|
|
209
|
+
def calculate_windows(self, iterable):
|
|
210
|
+
"""Yield range of consecutive numbers.
|
|
211
|
+
|
|
212
|
+
Internal Function. (printing operation)
|
|
213
|
+
"""
|
|
214
|
+
store_chain = dict()
|
|
215
|
+
for i in sorted(iterable):
|
|
216
|
+
try:
|
|
217
|
+
store_chain[i[-1]]
|
|
218
|
+
except:
|
|
219
|
+
store_chain[i[-1]] = list()
|
|
220
|
+
|
|
221
|
+
store_chain[i[-1]].append(int(i[:-1]))
|
|
222
|
+
|
|
223
|
+
for chain_key, in_iterable in store_chain.items():
|
|
224
|
+
store_chain[chain_key] = list(self.get_range(sorted(list(set(in_iterable)))))
|
|
225
|
+
|
|
226
|
+
return store_chain
|
|
227
|
+
|
|
228
|
+
def calculate_cluster(self, dist_mat, max_iter=21):
|
|
229
|
+
"""Calculates the best possible communities/clusters.
|
|
230
|
+
|
|
231
|
+
self.store_score calculated CH score for every clustering number. (Read the paper for more details)
|
|
232
|
+
|
|
233
|
+
Args:
|
|
234
|
+
dist_mat (numpy.array) : 1 - cross-correlation matrix.
|
|
235
|
+
max_iter (int) : Maximum number of iterations for cluster counts.
|
|
236
|
+
|
|
237
|
+
Returns:
|
|
238
|
+
True if successful; None otherwise.
|
|
239
|
+
"""
|
|
240
|
+
best_score = 0
|
|
241
|
+
dist_mat = numpy.sqrt(2*(dist_mat))
|
|
242
|
+
Data = numpy.triu(dist_mat)
|
|
243
|
+
Z = ward(Data)
|
|
244
|
+
self.store_score = dict()
|
|
245
|
+
for i in range(2, max_iter):
|
|
246
|
+
label = fcluster(Z, i, criterion='maxclust')
|
|
247
|
+
self.store_communities[i] = label
|
|
248
|
+
score = chs(dist_mat, label)
|
|
249
|
+
self.store_score[i] = score
|
|
250
|
+
if score > best_score:
|
|
251
|
+
self.best_community = label
|
|
252
|
+
best_score = score
|
|
253
|
+
|
|
254
|
+
self.store_score = dict(sorted(self.store_score.items(), key=lambda item: item[1])[::-1])
|
|
255
|
+
return True
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def calculate_CH_plot(self):
|
|
259
|
+
"""Calculate CH plot for the cluster numbers.
|
|
260
|
+
|
|
261
|
+
File is saved as pdbid_CH_Score.png in the present working directory. Please check the filename for invalid characters if there are errors.
|
|
262
|
+
|
|
263
|
+
Returns:
|
|
264
|
+
True if successful; None otherwise.
|
|
265
|
+
"""
|
|
266
|
+
import matplotlib.pyplot as plt
|
|
267
|
+
|
|
268
|
+
lists = sorted(self.store_score.items()) # sorted by key, return a list of tuples
|
|
269
|
+
x, y = zip(*lists) # unpack a list of pairs into two tuples
|
|
270
|
+
plt.xlabel('Community count', fontsize=14)
|
|
271
|
+
plt.ylabel('CH Score', fontsize=12)
|
|
272
|
+
plt.plot([int(i) for i in x], y)
|
|
273
|
+
plt.xticks(x)
|
|
274
|
+
plt.savefig(self.pdbid+'_CH_Score.png')
|
|
275
|
+
return True
|
|
276
|
+
|
|
277
|
+
def calcualte_pymol_commands( self, output_file ):
|
|
278
|
+
"""Write all the communities in py-mol importable format.
|
|
279
|
+
|
|
280
|
+
Args:
|
|
281
|
+
output_file (file) : output file.
|
|
282
|
+
|
|
283
|
+
Returns:
|
|
284
|
+
True if successful; None otherwise.
|
|
285
|
+
"""
|
|
286
|
+
|
|
287
|
+
with output_file as fp:
|
|
288
|
+
fp.write('Please check the generated plot fore the best CH score and corresponding community count.\n')
|
|
289
|
+
for key, dynamic_community in self.store_communities.items():
|
|
290
|
+
fp.write("#############################################################\n\n")
|
|
291
|
+
fp.write("Number of communities - %s\n" %(len(list(set(dynamic_community)))))
|
|
292
|
+
fp.write("CH Score - %s\n" %self.store_score[key])
|
|
293
|
+
clust = self.get_labels(dynamic_community)
|
|
294
|
+
|
|
295
|
+
for key, val in clust.items():
|
|
296
|
+
clust[key] = self.calculate_windows(val)
|
|
297
|
+
|
|
298
|
+
for key, val in clust.items():
|
|
299
|
+
fp.write("----------------------------------------------------------\n\n")
|
|
300
|
+
fp.write("cluster %s\n\n" %key)
|
|
301
|
+
for inkey, inval in val.items():
|
|
302
|
+
statement = "select resi "
|
|
303
|
+
for dat in inval:
|
|
304
|
+
if isinstance(dat, int):
|
|
305
|
+
statement = statement + "+" + str(dat)
|
|
306
|
+
else:
|
|
307
|
+
resi = list(range(dat[0], dat[1]+1))
|
|
308
|
+
for res in resi:
|
|
309
|
+
statement = statement + "+" + str(res)
|
|
310
|
+
|
|
311
|
+
fp.write("%s and chain %s\n" %(statement, inkey))
|
|
312
|
+
fp.write("----------------------------------------------------------\n\n")
|
|
313
|
+
return True
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def dci_cli(args,mol):
|
|
317
|
+
chain = args.chain
|
|
318
|
+
cutoff = args.cutoff
|
|
319
|
+
n_com = args.n_com
|
|
320
|
+
|
|
321
|
+
model = DCI( mol, cutoff = cutoff, chain = chain, n_com = n_com )
|
|
322
|
+
model.calcualte_pymol_commands( args.outputfile )
|
|
323
|
+
return True
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import numpy
|
|
2
|
+
import tarfile
|
|
3
|
+
import tempfile
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
from ..anm import hdANM
|
|
7
|
+
|
|
8
|
+
def hdanm_cli(args,mol):
|
|
9
|
+
|
|
10
|
+
#Load the Hinge Information
|
|
11
|
+
chain = args.chain
|
|
12
|
+
dr = float(args.dr)
|
|
13
|
+
power = float(args.power)
|
|
14
|
+
|
|
15
|
+
if(chain is not None):
|
|
16
|
+
calpha=[i for i in mol[0][chain].get_calpha() if i is not None]
|
|
17
|
+
else:
|
|
18
|
+
calpha=[i for i in mol[0].get_calpha() if i is not None]
|
|
19
|
+
|
|
20
|
+
Model = hdANM(calpha,dr=dr,power=power,hng_file=args.hngfile)
|
|
21
|
+
Model.calculate_hessian(mass_type=args.mass)
|
|
22
|
+
Model.calculate_decomposition()
|
|
23
|
+
|
|
24
|
+
def generate_output():
|
|
25
|
+
numpy.savetxt("eigenvalues.csv", Model.get_eigenvalues(), delimiter=",")
|
|
26
|
+
numpy.savetxt("eigenvectors.csv", Model.get_eigenvectors(), delimiter=",")
|
|
27
|
+
|
|
28
|
+
for i in range(6,6+args.modes,1):
|
|
29
|
+
Model.calculate_movie(i,scale=args.scale,n=args.frames)
|
|
30
|
+
|
|
31
|
+
if args.make_tar:
|
|
32
|
+
|
|
33
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
34
|
+
with open(args.outputfile.name, 'wb') as output_wb:
|
|
35
|
+
|
|
36
|
+
os.chdir(tmpdir)
|
|
37
|
+
|
|
38
|
+
generate_output()
|
|
39
|
+
|
|
40
|
+
tar = tarfile.open(mode="w:gz", fileobj=output_wb)
|
|
41
|
+
_, _, filenames = next(os.walk(tmpdir))
|
|
42
|
+
for name in filenames:
|
|
43
|
+
tar.add(name)
|
|
44
|
+
tar.close()
|
|
45
|
+
|
|
46
|
+
else:
|
|
47
|
+
generate_output()
|