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,470 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""The 'Molecule' 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 'Model' object documentation for details.
|
|
6
|
+
|
|
7
|
+
Citation:
|
|
8
|
+
Pranav M Khade, Robert L Jernigan, PACKMAN-Molecule: Python Toolbox for Structural Bioinformatics, Bioinformatics Advances, 2022;, vbac007, https://doi.org/10.1093/bioadv/vbac007
|
|
9
|
+
|
|
10
|
+
Example::
|
|
11
|
+
|
|
12
|
+
from packman.molecule import Model
|
|
13
|
+
help( Model )
|
|
14
|
+
|
|
15
|
+
Todo:
|
|
16
|
+
* Finish writing up the documentation.
|
|
17
|
+
* Finish error handling.
|
|
18
|
+
* Finish optimizing the performance.
|
|
19
|
+
|
|
20
|
+
Authors:
|
|
21
|
+
* Pranav Khade(https://github.com/Pranavkhade)
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
import numpy
|
|
25
|
+
import logging
|
|
26
|
+
|
|
27
|
+
from .protein import Protein
|
|
28
|
+
from .model import Model
|
|
29
|
+
|
|
30
|
+
from .chain import Chain
|
|
31
|
+
from .residue import Residue
|
|
32
|
+
from .atom import Atom
|
|
33
|
+
|
|
34
|
+
from .hetmol import HetMol
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
'''
|
|
38
|
+
##################################################################################################
|
|
39
|
+
# File Load #
|
|
40
|
+
##################################################################################################
|
|
41
|
+
'''
|
|
42
|
+
|
|
43
|
+
def load_pdb(filename):
|
|
44
|
+
"""
|
|
45
|
+
Load the PDB (.pdb) file into the 'Protein' Object.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
Models=[]
|
|
49
|
+
AllAnnotations = []
|
|
50
|
+
start=0
|
|
51
|
+
|
|
52
|
+
fh=open(filename).read()
|
|
53
|
+
|
|
54
|
+
frames=fh.split('\nMODEL')
|
|
55
|
+
|
|
56
|
+
if(len(frames)>1):
|
|
57
|
+
start=1
|
|
58
|
+
else:
|
|
59
|
+
start=0
|
|
60
|
+
for FrameNumber,frame in enumerate(frames[start:]):
|
|
61
|
+
#Map
|
|
62
|
+
AllAtoms={}
|
|
63
|
+
AllResidues={}
|
|
64
|
+
AllChains={}
|
|
65
|
+
|
|
66
|
+
AllHetAtoms={}
|
|
67
|
+
AllHetMols={}
|
|
68
|
+
|
|
69
|
+
lines=frame.split('\n')
|
|
70
|
+
for _ in lines:
|
|
71
|
+
if(_[0:4]=='ATOM'):
|
|
72
|
+
#NOTE: MAPS CAN BE REMOVED SAFELY
|
|
73
|
+
#Chain Defined
|
|
74
|
+
ChainID=_[21]
|
|
75
|
+
if(ChainID not in AllChains.keys()):AllChains[ChainID]=Chain(ChainID)
|
|
76
|
+
|
|
77
|
+
#Residue Defined
|
|
78
|
+
ResidueNumber=int(_[22:26].strip())
|
|
79
|
+
ResidueName=_[17:20]
|
|
80
|
+
if(str(ResidueNumber)+ChainID not in AllResidues.keys()):AllResidues[str(ResidueNumber)+ChainID]=Residue(ResidueNumber,ResidueName,AllChains[ChainID])
|
|
81
|
+
|
|
82
|
+
#Residue Added to the chain
|
|
83
|
+
AllChains[ChainID].__setitem__(ResidueNumber,AllResidues[str(ResidueNumber)+ChainID],Type='Residue')
|
|
84
|
+
|
|
85
|
+
#Atom Defined
|
|
86
|
+
id=int(_[6:11])
|
|
87
|
+
AtomName=_[12:16].strip()
|
|
88
|
+
Coordinates=numpy.array([float(_[30:38]),float(_[38:46]),float(_[46:54])])
|
|
89
|
+
Occupancy=float(_[54:60])
|
|
90
|
+
bfactor=float(_[60:66])
|
|
91
|
+
Element=_[76:78].strip()
|
|
92
|
+
Charge=_[78:80]
|
|
93
|
+
AllAtoms[id]=Atom(id,AtomName,Coordinates,Occupancy,bfactor,Element,Charge,AllResidues[str(ResidueNumber)+ChainID])
|
|
94
|
+
|
|
95
|
+
#Atom added to the residue
|
|
96
|
+
AllResidues[str(ResidueNumber)+ChainID].__setitem__(id,AllAtoms[id])
|
|
97
|
+
|
|
98
|
+
#What to do with these?
|
|
99
|
+
AlternateLocationIndicator=_[16]
|
|
100
|
+
CodeForInsertions=_[26]
|
|
101
|
+
SegmentIdentifier=_[72:76]
|
|
102
|
+
elif(_[0:6]=='HETATM'):
|
|
103
|
+
ChainID=_[21]
|
|
104
|
+
if(ChainID not in AllChains.keys()):AllChains[ChainID]=Chain(ChainID)
|
|
105
|
+
|
|
106
|
+
#HetMol Defined
|
|
107
|
+
HetMolNumber=int(_[22:26].strip())
|
|
108
|
+
HetMolName=_[17:20]
|
|
109
|
+
if(str(HetMolNumber)+ChainID not in AllHetMols.keys()):AllHetMols[str(HetMolNumber)+ChainID]=HetMol(HetMolNumber,HetMolName,AllChains[ChainID])
|
|
110
|
+
|
|
111
|
+
#HetMol Added to the chain
|
|
112
|
+
AllChains[ChainID].__setitem__(HetMolNumber,AllHetMols[str(HetMolNumber)+ChainID],Type='HetMol')
|
|
113
|
+
|
|
114
|
+
#HetAtom Defined
|
|
115
|
+
AtomID=int(_[6:11])
|
|
116
|
+
AtomName=_[12:16].strip()
|
|
117
|
+
Coordinates=numpy.array([float(_[30:38]),float(_[38:46]),float(_[46:54])])
|
|
118
|
+
Occupancy=float(_[54:60])
|
|
119
|
+
bfactor=float(_[60:66])
|
|
120
|
+
Element=_[76:78].strip()
|
|
121
|
+
Charge=_[78:80]
|
|
122
|
+
AllHetAtoms[AtomID]=Atom(AtomID,AtomName,Coordinates,Occupancy,bfactor,Element,Charge,AllHetMols[str(HetMolNumber)+ChainID])
|
|
123
|
+
|
|
124
|
+
#HetAtom added to the residue
|
|
125
|
+
AllHetMols[str(HetMolNumber)+ChainID].__setitem__(AtomID,AllHetAtoms[AtomID])
|
|
126
|
+
|
|
127
|
+
#What to do with these?
|
|
128
|
+
AlternateLocationIndicator=_[16]
|
|
129
|
+
CodeForInsertions=_[26]
|
|
130
|
+
SegmentIdentifier=_[72:76]
|
|
131
|
+
else:
|
|
132
|
+
AllAnnotations.append(_)
|
|
133
|
+
|
|
134
|
+
Models.append(Model(FrameNumber,AllAtoms,AllResidues,AllChains,AllHetAtoms,AllHetMols))
|
|
135
|
+
for i in AllChains:AllChains[i].set_parent(Models[FrameNumber])
|
|
136
|
+
|
|
137
|
+
if(len(Models)>2):
|
|
138
|
+
#NMR
|
|
139
|
+
logging.warning('Multiple models/frames are detected (B-factor field is now a calculated parameter, i.e., the scalar standard deviation of the atom location of all frames)')
|
|
140
|
+
All_Coords=[]
|
|
141
|
+
for i in Models:
|
|
142
|
+
All_Coords.append(numpy.array([j.get_location() for j in i.get_atoms()]))
|
|
143
|
+
All_Coords=numpy.array(All_Coords)
|
|
144
|
+
|
|
145
|
+
flattened_std=[]
|
|
146
|
+
for i in range(0,All_Coords.shape[1]):
|
|
147
|
+
xyz_var=0
|
|
148
|
+
for j in All_Coords[:,i].T:
|
|
149
|
+
xyz_var=xyz_var+numpy.var(j)
|
|
150
|
+
flattened_std.append(numpy.sqrt(xyz_var))
|
|
151
|
+
|
|
152
|
+
for i in Models:
|
|
153
|
+
for numj,j in enumerate(i.get_atoms()):
|
|
154
|
+
j.set_bfactor(flattened_std[numj])
|
|
155
|
+
|
|
156
|
+
prot = Protein(filename,Models)
|
|
157
|
+
prot.set_data(AllAnnotations)
|
|
158
|
+
#Setting parent to the model object
|
|
159
|
+
for i in prot: i.set_parent(prot)
|
|
160
|
+
return prot
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def load_cif(filename):
|
|
164
|
+
"""
|
|
165
|
+
Load the CIF (.cif) file into the 'Protein' Object.
|
|
166
|
+
"""
|
|
167
|
+
|
|
168
|
+
#Global Variables
|
|
169
|
+
AllChains = []
|
|
170
|
+
AllResidues = []
|
|
171
|
+
AllAtoms = []
|
|
172
|
+
|
|
173
|
+
AllHetMols = []
|
|
174
|
+
AllHetAtoms =[]
|
|
175
|
+
|
|
176
|
+
AllAnnotations = []
|
|
177
|
+
|
|
178
|
+
sections = open(filename,'r').read().split('loop_\n')
|
|
179
|
+
for section in sections:
|
|
180
|
+
for subsection in section.split('#'):
|
|
181
|
+
column_indices = {}
|
|
182
|
+
column_names = {}
|
|
183
|
+
for n_line, line in enumerate(subsection.split('\n')):
|
|
184
|
+
try:
|
|
185
|
+
_ = line.split()
|
|
186
|
+
|
|
187
|
+
# When the data is next to the columm description
|
|
188
|
+
if(line[0] == '_' and len(_) > 1):
|
|
189
|
+
AllAnnotations.append(line.strip())
|
|
190
|
+
|
|
191
|
+
# When the data columns are below the description section
|
|
192
|
+
elif(line[0] == '_' and len(_) == 1):
|
|
193
|
+
AllAnnotations.append(line.strip())
|
|
194
|
+
column_indices[n_line] = line.strip()
|
|
195
|
+
column_names[line.strip()] = n_line
|
|
196
|
+
|
|
197
|
+
else:
|
|
198
|
+
#All the molecule objects are built here
|
|
199
|
+
if(_[0] == 'ATOM'):
|
|
200
|
+
#Initiate Model Number
|
|
201
|
+
FrameNumber = int(_[ column_names['_atom_site.pdbx_PDB_model_num'] ])
|
|
202
|
+
|
|
203
|
+
#Initiate Chain (Frame number, Chain)
|
|
204
|
+
ChainID = _[ column_names['_atom_site.label_asym_id'] ]
|
|
205
|
+
try:
|
|
206
|
+
if( ChainID not in AllChains[FrameNumber-1].keys() ): AllChains[FrameNumber-1][ChainID] = Chain(ChainID)
|
|
207
|
+
except:
|
|
208
|
+
AllChains.append( {} )
|
|
209
|
+
AllChains[FrameNumber-1][ChainID] = Chain(ChainID)
|
|
210
|
+
|
|
211
|
+
#Initiate Residue (Use one of two ids, if both are absent, think of something in future)
|
|
212
|
+
try:
|
|
213
|
+
ResidueNumber = int( _[ column_names['_atom_site.label_seq_id'] ] )
|
|
214
|
+
except:
|
|
215
|
+
ResidueNumber = int( _[ column_names['_atom_site.auth_seq_id'] ] )
|
|
216
|
+
|
|
217
|
+
ResidueName = _[ column_names['_atom_site.label_comp_id'] ]
|
|
218
|
+
try:
|
|
219
|
+
if( str(ResidueNumber)+ChainID not in AllResidues[FrameNumber-1].keys() ): AllResidues[FrameNumber-1][str(ResidueNumber)+ChainID] = Residue( ResidueNumber, ResidueName, AllChains[FrameNumber-1][ChainID] )
|
|
220
|
+
except:
|
|
221
|
+
AllResidues.append( {} )
|
|
222
|
+
AllResidues[FrameNumber-1][str(ResidueNumber)+ChainID] = Residue( ResidueNumber, ResidueName, AllChains[FrameNumber-1][ChainID] )
|
|
223
|
+
|
|
224
|
+
#Initiate Atom
|
|
225
|
+
AtomID = int(_[ column_names['_atom_site.id'] ])
|
|
226
|
+
AtomName = _[ column_names['_atom_site.label_atom_id'] ]
|
|
227
|
+
Coordinates = numpy.array( [ float(_[ column_names['_atom_site.Cartn_x'] ]), float(_[ column_names['_atom_site.Cartn_y'] ]), float(_[ column_names['_atom_site.Cartn_z'] ]) ] )
|
|
228
|
+
Occupancy = float(_[ column_names['_atom_site.occupancy'] ])
|
|
229
|
+
bfactor = float(_[ column_names['_atom_site.B_iso_or_equiv'] ])
|
|
230
|
+
Element = _[ column_names['_atom_site.type_symbol'] ]
|
|
231
|
+
Charge = _[ column_names['_atom_site.pdbx_formal_charge'] ]
|
|
232
|
+
|
|
233
|
+
#If particular atom is already present, dont add it again; alternate id must be present (_atom_site.label_alt_id)
|
|
234
|
+
try:
|
|
235
|
+
if( AllResidues[FrameNumber-1][str(ResidueNumber)+ChainID].get_atom(AtomName)!= None ):
|
|
236
|
+
continue
|
|
237
|
+
except Exception as e:
|
|
238
|
+
#Alternate atom exists
|
|
239
|
+
None
|
|
240
|
+
|
|
241
|
+
try:
|
|
242
|
+
AllAtoms[FrameNumber-1][AtomID] = Atom(AtomID,AtomName,Coordinates,Occupancy,bfactor,Element,Charge, AllResidues[FrameNumber-1][str(ResidueNumber)+ChainID] )
|
|
243
|
+
except:
|
|
244
|
+
AllAtoms.append( {} )
|
|
245
|
+
AllAtoms[FrameNumber-1][AtomID] = Atom(AtomID,AtomName,Coordinates,Occupancy,bfactor,Element,Charge, AllResidues[FrameNumber-1][str(ResidueNumber)+ChainID] )
|
|
246
|
+
|
|
247
|
+
#Connect objects to each other to create a tree (Ideally should not happen every iteration)
|
|
248
|
+
#Residue Added to the chain
|
|
249
|
+
AllChains[FrameNumber-1][ChainID].__setitem__( ResidueNumber, AllResidues[FrameNumber-1][str(ResidueNumber)+ChainID], Type='Residue' )
|
|
250
|
+
#Atom added to the residue
|
|
251
|
+
AllResidues[FrameNumber-1][str(ResidueNumber)+ChainID].__setitem__( AtomID, AllAtoms[FrameNumber-1][AtomID] )
|
|
252
|
+
|
|
253
|
+
#Heteroatoms
|
|
254
|
+
elif(_[0] == 'HETATM'):
|
|
255
|
+
#Initiate Model Number
|
|
256
|
+
FrameNumber = int(_[ column_names['_atom_site.pdbx_PDB_model_num'] ])
|
|
257
|
+
|
|
258
|
+
#Initiate Chain (Frame number, Chain)
|
|
259
|
+
ChainID = _[ column_names['_atom_site.label_asym_id'] ]
|
|
260
|
+
try:
|
|
261
|
+
if( ChainID not in AllChains[FrameNumber-1].keys() ): AllChains[FrameNumber-1][ChainID] = Chain(ChainID)
|
|
262
|
+
except:
|
|
263
|
+
AllChains.append( {} )
|
|
264
|
+
AllChains[FrameNumber-1][ChainID] = Chain(ChainID)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
#Initiate HetMol (In case there is absense of ids, line number becomes residue id)
|
|
268
|
+
try:
|
|
269
|
+
HetMolNumber = int( _[ column_names['_atom_site.label_seq_id'] ] )
|
|
270
|
+
except:
|
|
271
|
+
try:
|
|
272
|
+
HetMolNumber = int( _[ column_names['_atom_site.auth_seq_id'] ] )
|
|
273
|
+
except:
|
|
274
|
+
HetMolNumber = n_line
|
|
275
|
+
|
|
276
|
+
HetMolName = _[ column_names['_atom_site.label_comp_id'] ]
|
|
277
|
+
try:
|
|
278
|
+
if( str(HetMolNumber)+ChainID not in AllHetMols[FrameNumber-1].keys() ): AllHetMols[FrameNumber-1][str(HetMolNumber)+ChainID] = HetMol( HetMolNumber, HetMolName, AllChains[FrameNumber-1][ChainID] )
|
|
279
|
+
except:
|
|
280
|
+
AllHetMols.append( {} )
|
|
281
|
+
AllHetMols[FrameNumber-1][str(HetMolNumber)+ChainID] = HetMol( HetMolNumber, HetMolName, AllChains[FrameNumber-1][ChainID] )
|
|
282
|
+
|
|
283
|
+
#Initiate Atom
|
|
284
|
+
AtomID = int(_[ column_names['_atom_site.id'] ])
|
|
285
|
+
AtomName = _[ column_names['_atom_site.label_atom_id'] ]
|
|
286
|
+
Coordinates = numpy.array( [ float(_[ column_names['_atom_site.Cartn_x'] ]), float(_[ column_names['_atom_site.Cartn_y'] ]), float(_[ column_names['_atom_site.Cartn_z'] ]) ] )
|
|
287
|
+
Occupancy = float(_[ column_names['_atom_site.occupancy'] ])
|
|
288
|
+
bfactor = float(_[ column_names['_atom_site.B_iso_or_equiv'] ])
|
|
289
|
+
Element = _[ column_names['_atom_site.type_symbol'] ]
|
|
290
|
+
Charge = _[ column_names['_atom_site.pdbx_formal_charge'] ]
|
|
291
|
+
|
|
292
|
+
#If particular atom is already present, dont add it again; alternate id must be present (_atom_site.label_alt_id)
|
|
293
|
+
try:
|
|
294
|
+
if( AllHetMols[FrameNumber-1][str(HetMolNumber)+ChainID].get_atom(AtomName)!= None ):
|
|
295
|
+
continue
|
|
296
|
+
except Exception as e:
|
|
297
|
+
#Alternate atom exists
|
|
298
|
+
None
|
|
299
|
+
|
|
300
|
+
try:
|
|
301
|
+
AllHetAtoms[FrameNumber-1][AtomID] = Atom(AtomID,AtomName,Coordinates,Occupancy,bfactor,Element,Charge, AllHetMols[FrameNumber-1][str(HetMolNumber)+ChainID] )
|
|
302
|
+
except:
|
|
303
|
+
AllHetAtoms.append( {} )
|
|
304
|
+
AllHetAtoms[FrameNumber-1][AtomID] = Atom(AtomID,AtomName,Coordinates,Occupancy,bfactor,Element,Charge, AllHetMols[FrameNumber-1][str(HetMolNumber)+ChainID] )
|
|
305
|
+
|
|
306
|
+
#Connect objects to each other to create a tree (Ideally should not happen every iteration)
|
|
307
|
+
#HetMol Added to the chain
|
|
308
|
+
AllChains[FrameNumber-1][ChainID].__setitem__( HetMolNumber, AllHetMols[FrameNumber-1][str(HetMolNumber)+ChainID], Type='HetMol' )
|
|
309
|
+
#Atom added to the HetMol
|
|
310
|
+
AllHetMols[FrameNumber-1][str(HetMolNumber)+ChainID].__setitem__( AtomID, AllHetAtoms[FrameNumber-1][AtomID] )
|
|
311
|
+
|
|
312
|
+
#Annotations additions
|
|
313
|
+
else:
|
|
314
|
+
AllAnnotations.append( line.strip() )
|
|
315
|
+
#This is when we will develop more annotation objects in future
|
|
316
|
+
#for n_cols, cols in enumerate( line.split() ):
|
|
317
|
+
# try:
|
|
318
|
+
# subsection_data[ column_indices[n_cols] ].append(cols)
|
|
319
|
+
# except:
|
|
320
|
+
# subsection_data[ column_indices[n_cols] ] = []
|
|
321
|
+
# subsection_data[ column_indices[n_cols] ].append(cols)
|
|
322
|
+
except Exception as e:
|
|
323
|
+
None
|
|
324
|
+
try:
|
|
325
|
+
if(AllAnnotations[-1]!='#'): AllAnnotations.append('#')
|
|
326
|
+
except:
|
|
327
|
+
logging.info('Annotations are missing from the mmCIF file.')
|
|
328
|
+
AllAnnotations.append('loop_')
|
|
329
|
+
|
|
330
|
+
total_models = max([len(AllAtoms),len(AllHetAtoms)])
|
|
331
|
+
|
|
332
|
+
AllModels = []
|
|
333
|
+
for i in range(0,total_models):
|
|
334
|
+
#In case protein part is missing
|
|
335
|
+
try:
|
|
336
|
+
current_atoms = AllAtoms[i]
|
|
337
|
+
current_residues = AllResidues[i]
|
|
338
|
+
except:
|
|
339
|
+
current_atoms = [None]
|
|
340
|
+
current_residues = [None]
|
|
341
|
+
|
|
342
|
+
#In case the hetatoms are not present at all
|
|
343
|
+
try:
|
|
344
|
+
current_hetatms = AllHetAtoms[i]
|
|
345
|
+
current_hetmols = AllHetMols[i]
|
|
346
|
+
except:
|
|
347
|
+
current_hetatms = [None]
|
|
348
|
+
current_hetmols = [None]
|
|
349
|
+
|
|
350
|
+
#In case the chains are missing
|
|
351
|
+
try:
|
|
352
|
+
current_chains = AllChains[i]
|
|
353
|
+
except:
|
|
354
|
+
current_chains = [None]
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
AllModels.append( Model(i+1, current_atoms, current_residues, current_chains, current_hetatms, current_hetmols) )
|
|
358
|
+
for j in AllModels[i].get_chains(): j.set_parent(AllModels[i])
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
if(len(AllModels)>2):
|
|
362
|
+
#NMR
|
|
363
|
+
logging.warning('Multiple models/frames are detected (B-factor field is now a calculated parameter, i.e., the scalar standard deviation of the atom location of all frames)')
|
|
364
|
+
All_Coords=[]
|
|
365
|
+
for i in AllModels:
|
|
366
|
+
All_Coords.append(numpy.array([j.get_location() for j in i.get_atoms()]))
|
|
367
|
+
All_Coords=numpy.array(All_Coords)
|
|
368
|
+
|
|
369
|
+
flattened_std=[]
|
|
370
|
+
for i in range(0,All_Coords.shape[1]):
|
|
371
|
+
xyz_var=0
|
|
372
|
+
for j in All_Coords[:,i].T:
|
|
373
|
+
xyz_var=xyz_var+numpy.var(j)
|
|
374
|
+
flattened_std.append(numpy.sqrt(xyz_var))
|
|
375
|
+
|
|
376
|
+
for i in AllModels:
|
|
377
|
+
for numj,j in enumerate(i.get_atoms()):
|
|
378
|
+
j.set_bfactor(flattened_std[numj])
|
|
379
|
+
|
|
380
|
+
prot = Protein( filename, AllModels )
|
|
381
|
+
prot.set_data(AllAnnotations)
|
|
382
|
+
#Setting parent to the model object
|
|
383
|
+
for i in prot:
|
|
384
|
+
i.set_parent(prot)
|
|
385
|
+
try:
|
|
386
|
+
i.calculate_bonds()
|
|
387
|
+
except:
|
|
388
|
+
logging.warning('Model.calculate_bonds() failed for MODEL: '+str(i.get_id()))
|
|
389
|
+
return prot
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
'''
|
|
393
|
+
##################################################################################################
|
|
394
|
+
# Entry #
|
|
395
|
+
##################################################################################################
|
|
396
|
+
'''
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def load_structure(filename, ftype = 'cif'):
|
|
400
|
+
"""Load a Molecule from a file.
|
|
401
|
+
|
|
402
|
+
This class helps user to load the 3D structure of the protein onto a packman.molecule.Protein object.
|
|
403
|
+
|
|
404
|
+
Example::
|
|
405
|
+
|
|
406
|
+
from packman import molecule
|
|
407
|
+
molecule.download_structure('1prw')
|
|
408
|
+
molecule.load_structure('1prw.cif')
|
|
409
|
+
|
|
410
|
+
Args:
|
|
411
|
+
filename (str) : Name of the input file
|
|
412
|
+
ftype (str) : Format name ('cif' or 'pdb'); Default: cif
|
|
413
|
+
|
|
414
|
+
Returns:
|
|
415
|
+
packman.molecule.Protein: Protein object containing all the information about the Protein
|
|
416
|
+
"""
|
|
417
|
+
try:
|
|
418
|
+
possible_ftype = filename.split('.')[1]
|
|
419
|
+
if(possible_ftype == 'cif' or possible_ftype == 'pdb'):
|
|
420
|
+
ftype = possible_ftype
|
|
421
|
+
except:
|
|
422
|
+
None
|
|
423
|
+
|
|
424
|
+
if(ftype == 'cif'):
|
|
425
|
+
return load_cif(filename)
|
|
426
|
+
elif(ftype == 'pdb'):
|
|
427
|
+
return load_pdb(filename)
|
|
428
|
+
else:
|
|
429
|
+
print('Please provide appropriate "ftype" argument. (cif/pdb).')
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
'''
|
|
433
|
+
##################################################################################################
|
|
434
|
+
# Download #
|
|
435
|
+
##################################################################################################
|
|
436
|
+
'''
|
|
437
|
+
|
|
438
|
+
def download_structure(pdbid,save_name=None,ftype='cif'):
|
|
439
|
+
"""This class helps user to download the 3D structure of the protein and save it on a disk.
|
|
440
|
+
|
|
441
|
+
Example::
|
|
442
|
+
|
|
443
|
+
from packman import molecule
|
|
444
|
+
molecule.download_structure('1prw')
|
|
445
|
+
|
|
446
|
+
Args:
|
|
447
|
+
pdbid (str) : A Unique 4 Letter PDB ID (eg.. 1PRW)
|
|
448
|
+
save_name (str) : Save name of the downloaded file (extension will be added automatically depending on the ftype argument).
|
|
449
|
+
ftype (str) : Format name ('.cif' or '.pdb')
|
|
450
|
+
"""
|
|
451
|
+
import urllib.request as ur
|
|
452
|
+
|
|
453
|
+
if(ftype=='cif'):
|
|
454
|
+
response=ur.urlopen('https://files.rcsb.org/view/'+pdbid+'.cif')
|
|
455
|
+
elif(ftype=='pdb'):
|
|
456
|
+
response=ur.urlopen('https://files.rcsb.org/view/'+pdbid+'.pdb')
|
|
457
|
+
else:
|
|
458
|
+
print('Please provide appropriate "ftype" argument. (cif/pdb).')
|
|
459
|
+
|
|
460
|
+
if(save_name==None):
|
|
461
|
+
try:
|
|
462
|
+
open(pdbid+'.'+ftype,'wb').write(response.read())
|
|
463
|
+
except(IOError):
|
|
464
|
+
None
|
|
465
|
+
else:
|
|
466
|
+
try:
|
|
467
|
+
open(save_name+'.'+ftype,'wb').write(response.read())
|
|
468
|
+
except(IOError):
|
|
469
|
+
None
|
|
470
|
+
return True
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""The 'Protein' 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 'Protein' object documentation for details.
|
|
6
|
+
|
|
7
|
+
Citation:
|
|
8
|
+
Pranav M Khade, Robert L Jernigan, PACKMAN-Molecule: Python Toolbox for Structural Bioinformatics, Bioinformatics Advances, 2022;, vbac007, https://doi.org/10.1093/bioadv/vbac007
|
|
9
|
+
|
|
10
|
+
Example::
|
|
11
|
+
|
|
12
|
+
from packman.molecule import Protein
|
|
13
|
+
help( Protein )
|
|
14
|
+
|
|
15
|
+
Note:
|
|
16
|
+
* Top in the hierarchy
|
|
17
|
+
|
|
18
|
+
Todo:
|
|
19
|
+
* Finish writing up the documentation.
|
|
20
|
+
* Finish error handling.
|
|
21
|
+
* Finish optimizing the performance.
|
|
22
|
+
|
|
23
|
+
Authors:
|
|
24
|
+
* Pranav Khade(https://github.com/Pranavkhade)
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from numpy import around
|
|
28
|
+
|
|
29
|
+
class Protein():
|
|
30
|
+
"""This class contains the information about the 'Protein' object (packman.molecule.Protein).
|
|
31
|
+
|
|
32
|
+
This class contains all the information available about the Protein and stores everything in itself. The Protein class is the highest in the hierarchy of the 'molecule' API classes.
|
|
33
|
+
the order of hierarchy being: Protein> Model> Chain> Residue> Atom. This class is also the component of the 'molecule' module API.
|
|
34
|
+
Please read the Tutorials and Documentation for more details.
|
|
35
|
+
|
|
36
|
+
Note:
|
|
37
|
+
* Please refer to the [https://web.archive.org/web/20080905024351/http://www.wwpdb.org/docs.html] for the description of the arguments.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
id (int) : Protein ID
|
|
42
|
+
name (str) : Protein Name
|
|
43
|
+
Models ([packman.molecule.Model]): Protein models/frames of the structure. (NMR files usually have multiple conformers of the same protein)
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(self,id,Models):
|
|
47
|
+
self.__id=id
|
|
48
|
+
self.__Models=Models
|
|
49
|
+
self.__Data = None
|
|
50
|
+
|
|
51
|
+
#Get Functions
|
|
52
|
+
def __getitem__(self,ModelNumber):
|
|
53
|
+
return self.__Models[ModelNumber]
|
|
54
|
+
|
|
55
|
+
def get_id(self):
|
|
56
|
+
"""Get the ID for the Protein object.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
String if successful, None otherwise.
|
|
60
|
+
"""
|
|
61
|
+
return self.__id
|
|
62
|
+
|
|
63
|
+
def get_data(self):
|
|
64
|
+
"""Get the misc data (other than coordinates) from the file.
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
Array of Strings
|
|
68
|
+
"""
|
|
69
|
+
return self.__Data
|
|
70
|
+
|
|
71
|
+
#Set functions
|
|
72
|
+
def set_data(self,data):
|
|
73
|
+
"""Set the misc data (other than coordiantes) to the Protein object.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
data (array): Array of String
|
|
77
|
+
|
|
78
|
+
Note:
|
|
79
|
+
- All the properties are planned to be put in specific format to achieve complete interformat conversion.
|
|
80
|
+
"""
|
|
81
|
+
self.__Data = data
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
#Wite Functions
|
|
85
|
+
def write_pdb(self,filename):
|
|
86
|
+
"""Write a PDB (.pdb) file from the Protein object.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
filename (str): Name of the output file user wishes to assign.
|
|
90
|
+
"""
|
|
91
|
+
open(filename,'w').write('')
|
|
92
|
+
fh=open(filename,'a')
|
|
93
|
+
#Annotations
|
|
94
|
+
try:
|
|
95
|
+
for i in self.get_data():
|
|
96
|
+
fh.write(i+'\n')
|
|
97
|
+
except:
|
|
98
|
+
None
|
|
99
|
+
#Atoms part
|
|
100
|
+
for num_,_ in enumerate(self):
|
|
101
|
+
fh.write("Model\t"+str(num_)+'\n')
|
|
102
|
+
for i in _.get_atoms():
|
|
103
|
+
fh.write("ATOM %5s %-4s %3s %1s%4s %8s%8s%8s%6s%6s %-4s%2s%2s\n"%(i.get_id(), i.get_name(), i.get_parent().get_name(), i.get_parent().get_parent().get_id(), i.get_parent().get_id(), around(i.get_location()[0],decimals=3).real, around(i.get_location()[1],decimals=3).real, around(i.get_location()[2],decimals=3).real, i.get_occupancy(), round(i.get_bfactor(),2), '', i.get_element(), ''))
|
|
104
|
+
fh.write("ENDMDL\n")
|
|
105
|
+
fh.flush()
|
|
106
|
+
fh.close()
|
|
107
|
+
return True
|
|
108
|
+
|
|
109
|
+
def write_cif(self,filename):
|
|
110
|
+
"""Write a PDBx/mmCIF (.cif) file from the Protein object.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
filename (str): Name of the output file user wishes to assign.
|
|
114
|
+
"""
|
|
115
|
+
#Annotations
|
|
116
|
+
open(filename,'w').write('')
|
|
117
|
+
fh=open(filename,'a')
|
|
118
|
+
if(self.__Data != None):
|
|
119
|
+
for i in self.__Data:
|
|
120
|
+
try:
|
|
121
|
+
fh.write(i+'\n')
|
|
122
|
+
except:
|
|
123
|
+
None
|
|
124
|
+
fh.write('#\nloop_\n')
|
|
125
|
+
#'_atom_site.group_PDB', '_atom_site.id', '_atom_site.type_symbol', '_atom_site.label_atom_id', '_atom_site.label_alt_id', '_atom_site.label_comp_id', '_atom_site.label_asym_id', '_atom_site.label_entity_id', '_atom_site.label_seq_id', '_atom_site.pdbx_PDB_ins_code', '_atom_site.Cartn_x', '_atom_site.Cartn_y', '_atom_site.Cartn_z', '_atom_site.occupancy', '_atom_site.B_iso_or_equiv', '_atom_site.pdbx_formal_charge', '_atom_site.auth_seq_id', '_atom_site.auth_comp_id', '_atom_site.auth_asym_id', '_atom_site.auth_atom_id', '_atom_site.pdbx_PDB_model_num'
|
|
126
|
+
cols = ['_atom_site.group_PDB', '_atom_site.id', '_atom_site.type_symbol', '_atom_site.label_atom_id', '_atom_site.label_alt_id', '_atom_site.label_comp_id', '_atom_site.label_asym_id', '_atom_site.label_entity_id', '_atom_site.label_seq_id', '_atom_site.pdbx_PDB_ins_code', '_atom_site.Cartn_x', '_atom_site.Cartn_y', '_atom_site.Cartn_z', '_atom_site.occupancy', '_atom_site.B_iso_or_equiv', '_atom_site.pdbx_formal_charge', '_atom_site.auth_seq_id', '_atom_site.auth_comp_id', '_atom_site.auth_asym_id', '_atom_site.auth_atom_id', '_atom_site.pdbx_PDB_model_num']
|
|
127
|
+
|
|
128
|
+
for i in cols:
|
|
129
|
+
fh.write(i+'\n')
|
|
130
|
+
|
|
131
|
+
for num_,_ in enumerate(self):
|
|
132
|
+
for i in _.get_atoms():
|
|
133
|
+
fh.write("ATOM\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n"%( i.get_id(), i.get_element(), i.get_name(), '.' , i.get_parent().get_name(), i.get_parent().get_parent().get_id() , '1', i.get_parent().get_id(), '?', around(i.get_location()[0],decimals=3).real, around(i.get_location()[1],decimals=3).real, around(i.get_location()[2],decimals=3).real, i.get_occupancy(), round(i.get_bfactor(),2), i.get_charge(), i.get_parent().get_id(), i.get_parent().get_name(), i.get_parent().get_parent().get_id(), i.get_name(), num_+1 ) )
|
|
134
|
+
|
|
135
|
+
fh.flush()
|
|
136
|
+
fh.close()
|
|
137
|
+
|
|
138
|
+
return True
|
|
139
|
+
|
|
140
|
+
def write_structure(self,filename,ftype='cif'):
|
|
141
|
+
"""Write the 'Protein' object to the file.
|
|
142
|
+
|
|
143
|
+
CIF file format is default because it has more advantages over PDB format and PDB format is 'frozen'. Please read following for more information::
|
|
144
|
+
https://www.wwpdb.org/documentation/file-formats-and-the-pdb
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
filename (str): Name of the output file user wishes to assign.
|
|
148
|
+
ftype (str): Format for the file (pdb / cif)
|
|
149
|
+
"""
|
|
150
|
+
try:
|
|
151
|
+
ftype = filename.split('.')[1]
|
|
152
|
+
except:
|
|
153
|
+
None
|
|
154
|
+
|
|
155
|
+
if(ftype == 'cif'):
|
|
156
|
+
self.write_cif(filename)
|
|
157
|
+
elif(ftype == 'pdb'):
|
|
158
|
+
self.write_pdb(filename)
|
|
159
|
+
else:
|
|
160
|
+
raise Exception('Please provide appropriate "ftype" argument. (cif/pdb).')
|
|
161
|
+
|
|
162
|
+
return True
|