biotite 0.41.2__cp310-cp310-win_amd64.whl → 1.0.1__cp310-cp310-win_amd64.whl
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.
Potentially problematic release.
This version of biotite might be problematic. Click here for more details.
- biotite/__init__.py +2 -3
- biotite/application/__init__.py +1 -1
- biotite/application/application.py +20 -10
- biotite/application/autodock/__init__.py +1 -1
- biotite/application/autodock/app.py +74 -79
- biotite/application/blast/__init__.py +1 -1
- biotite/application/blast/alignment.py +19 -10
- biotite/application/blast/webapp.py +92 -85
- biotite/application/clustalo/__init__.py +1 -1
- biotite/application/clustalo/app.py +46 -61
- biotite/application/dssp/__init__.py +1 -1
- biotite/application/dssp/app.py +8 -11
- biotite/application/localapp.py +62 -60
- biotite/application/mafft/__init__.py +1 -1
- biotite/application/mafft/app.py +16 -22
- biotite/application/msaapp.py +78 -89
- biotite/application/muscle/__init__.py +1 -1
- biotite/application/muscle/app3.py +50 -64
- biotite/application/muscle/app5.py +23 -31
- biotite/application/sra/__init__.py +1 -1
- biotite/application/sra/app.py +64 -68
- biotite/application/tantan/__init__.py +1 -1
- biotite/application/tantan/app.py +22 -45
- biotite/application/util.py +7 -9
- biotite/application/viennarna/rnaalifold.py +34 -28
- biotite/application/viennarna/rnafold.py +24 -39
- biotite/application/viennarna/rnaplot.py +36 -21
- biotite/application/viennarna/util.py +17 -12
- biotite/application/webapp.py +13 -14
- biotite/copyable.py +13 -13
- biotite/database/__init__.py +1 -1
- biotite/database/entrez/__init__.py +1 -1
- biotite/database/entrez/check.py +2 -3
- biotite/database/entrez/dbnames.py +7 -5
- biotite/database/entrez/download.py +55 -49
- biotite/database/entrez/key.py +1 -1
- biotite/database/entrez/query.py +62 -23
- biotite/database/error.py +2 -1
- biotite/database/pubchem/__init__.py +1 -1
- biotite/database/pubchem/download.py +43 -45
- biotite/database/pubchem/error.py +2 -2
- biotite/database/pubchem/query.py +34 -31
- biotite/database/pubchem/throttle.py +3 -4
- biotite/database/rcsb/__init__.py +1 -1
- biotite/database/rcsb/download.py +44 -52
- biotite/database/rcsb/query.py +85 -80
- biotite/database/uniprot/check.py +6 -3
- biotite/database/uniprot/download.py +6 -11
- biotite/database/uniprot/query.py +115 -31
- biotite/file.py +12 -31
- biotite/sequence/__init__.py +3 -3
- biotite/sequence/align/__init__.py +2 -2
- biotite/sequence/align/alignment.py +99 -90
- biotite/sequence/align/banded.cp310-win_amd64.pyd +0 -0
- biotite/sequence/align/buckets.py +12 -10
- biotite/sequence/align/cigar.py +43 -52
- biotite/sequence/align/kmeralphabet.cp310-win_amd64.pyd +0 -0
- biotite/sequence/align/kmeralphabet.pyx +55 -51
- biotite/sequence/align/kmersimilarity.cp310-win_amd64.pyd +0 -0
- biotite/sequence/align/kmertable.cp310-win_amd64.pyd +0 -0
- biotite/sequence/align/kmertable.pyx +3 -2
- biotite/sequence/align/localgapped.cp310-win_amd64.pyd +0 -0
- biotite/sequence/align/localungapped.cp310-win_amd64.pyd +0 -0
- biotite/sequence/align/matrix.py +81 -82
- biotite/sequence/align/multiple.cp310-win_amd64.pyd +0 -0
- biotite/sequence/align/multiple.pyx +1 -1
- biotite/sequence/align/pairwise.cp310-win_amd64.pyd +0 -0
- biotite/sequence/align/permutation.cp310-win_amd64.pyd +0 -0
- biotite/sequence/align/permutation.pyx +12 -4
- biotite/sequence/align/selector.cp310-win_amd64.pyd +0 -0
- biotite/sequence/align/selector.pyx +52 -54
- biotite/sequence/align/statistics.py +32 -33
- biotite/sequence/align/tracetable.cp310-win_amd64.pyd +0 -0
- biotite/sequence/alphabet.py +51 -65
- biotite/sequence/annotation.py +78 -77
- biotite/sequence/codec.cp310-win_amd64.pyd +0 -0
- biotite/sequence/codon.py +90 -79
- biotite/sequence/graphics/__init__.py +1 -1
- biotite/sequence/graphics/alignment.py +184 -103
- biotite/sequence/graphics/colorschemes.py +10 -12
- biotite/sequence/graphics/dendrogram.py +79 -34
- biotite/sequence/graphics/features.py +133 -99
- biotite/sequence/graphics/logo.py +22 -28
- biotite/sequence/graphics/plasmid.py +229 -178
- biotite/sequence/io/fasta/__init__.py +1 -1
- biotite/sequence/io/fasta/convert.py +44 -33
- biotite/sequence/io/fasta/file.py +42 -55
- biotite/sequence/io/fastq/__init__.py +1 -1
- biotite/sequence/io/fastq/convert.py +11 -14
- biotite/sequence/io/fastq/file.py +68 -112
- biotite/sequence/io/genbank/__init__.py +2 -2
- biotite/sequence/io/genbank/annotation.py +12 -20
- biotite/sequence/io/genbank/file.py +74 -76
- biotite/sequence/io/genbank/metadata.py +74 -62
- biotite/sequence/io/genbank/sequence.py +13 -14
- biotite/sequence/io/general.py +39 -30
- biotite/sequence/io/gff/__init__.py +2 -2
- biotite/sequence/io/gff/convert.py +10 -15
- biotite/sequence/io/gff/file.py +81 -65
- biotite/sequence/phylo/__init__.py +1 -1
- biotite/sequence/phylo/nj.cp310-win_amd64.pyd +0 -0
- biotite/sequence/phylo/tree.cp310-win_amd64.pyd +0 -0
- biotite/sequence/phylo/upgma.cp310-win_amd64.pyd +0 -0
- biotite/sequence/profile.py +57 -28
- biotite/sequence/search.py +17 -15
- biotite/sequence/seqtypes.py +200 -164
- biotite/sequence/sequence.py +15 -17
- biotite/structure/__init__.py +3 -3
- biotite/structure/atoms.py +246 -236
- biotite/structure/basepairs.py +260 -271
- biotite/structure/bonds.cp310-win_amd64.pyd +0 -0
- biotite/structure/bonds.pyx +29 -32
- biotite/structure/box.py +67 -71
- biotite/structure/celllist.cp310-win_amd64.pyd +0 -0
- biotite/structure/chains.py +55 -39
- biotite/structure/charges.cp310-win_amd64.pyd +0 -0
- biotite/structure/compare.py +32 -32
- biotite/structure/density.py +13 -18
- biotite/structure/dotbracket.py +20 -22
- biotite/structure/error.py +10 -2
- biotite/structure/filter.py +83 -78
- biotite/structure/geometry.py +130 -119
- biotite/structure/graphics/atoms.py +60 -43
- biotite/structure/graphics/rna.py +81 -68
- biotite/structure/hbond.py +112 -93
- biotite/structure/info/__init__.py +0 -2
- biotite/structure/info/atoms.py +10 -11
- biotite/structure/info/bonds.py +41 -43
- biotite/structure/info/ccd.py +4 -5
- biotite/structure/info/groups.py +1 -3
- biotite/structure/info/masses.py +5 -10
- biotite/structure/info/misc.py +1 -1
- biotite/structure/info/radii.py +20 -20
- biotite/structure/info/standardize.py +15 -26
- biotite/structure/integrity.py +18 -71
- biotite/structure/io/__init__.py +3 -4
- biotite/structure/io/dcd/__init__.py +1 -1
- biotite/structure/io/dcd/file.py +22 -20
- biotite/structure/io/general.py +47 -61
- biotite/structure/io/gro/__init__.py +1 -1
- biotite/structure/io/gro/file.py +73 -72
- biotite/structure/io/mol/__init__.py +1 -1
- biotite/structure/io/mol/convert.py +8 -11
- biotite/structure/io/mol/ctab.py +37 -36
- biotite/structure/io/mol/header.py +14 -10
- biotite/structure/io/mol/mol.py +9 -53
- biotite/structure/io/mol/sdf.py +47 -50
- biotite/structure/io/netcdf/__init__.py +1 -1
- biotite/structure/io/netcdf/file.py +24 -23
- biotite/structure/io/pdb/__init__.py +1 -1
- biotite/structure/io/pdb/convert.py +32 -20
- biotite/structure/io/pdb/file.py +151 -172
- biotite/structure/io/pdb/hybrid36.cp310-win_amd64.pyd +0 -0
- biotite/structure/io/pdbqt/__init__.py +1 -1
- biotite/structure/io/pdbqt/convert.py +17 -11
- biotite/structure/io/pdbqt/file.py +128 -80
- biotite/structure/io/pdbx/__init__.py +1 -2
- biotite/structure/io/pdbx/bcif.py +36 -44
- biotite/structure/io/pdbx/cif.py +140 -110
- biotite/structure/io/pdbx/component.py +10 -16
- biotite/structure/io/pdbx/convert.py +260 -258
- biotite/structure/io/pdbx/encoding.cp310-win_amd64.pyd +0 -0
- biotite/structure/io/trajfile.py +90 -107
- biotite/structure/io/trr/__init__.py +1 -1
- biotite/structure/io/trr/file.py +12 -15
- biotite/structure/io/xtc/__init__.py +1 -1
- biotite/structure/io/xtc/file.py +11 -14
- biotite/structure/mechanics.py +9 -11
- biotite/structure/molecules.py +3 -4
- biotite/structure/pseudoknots.py +53 -67
- biotite/structure/rdf.py +23 -21
- biotite/structure/repair.py +137 -86
- biotite/structure/residues.py +26 -16
- biotite/structure/sasa.cp310-win_amd64.pyd +0 -0
- biotite/structure/{resutil.py → segments.py} +24 -23
- biotite/structure/sequence.py +10 -11
- biotite/structure/sse.py +100 -119
- biotite/structure/superimpose.py +39 -77
- biotite/structure/transform.py +97 -71
- biotite/structure/util.py +11 -13
- biotite/version.py +2 -2
- biotite/visualize.py +69 -55
- {biotite-0.41.2.dist-info → biotite-1.0.1.dist-info}/METADATA +6 -5
- biotite-1.0.1.dist-info/RECORD +322 -0
- biotite/structure/io/ctab.py +0 -72
- biotite/structure/io/mmtf/__init__.py +0 -21
- biotite/structure/io/mmtf/assembly.py +0 -214
- biotite/structure/io/mmtf/convertarray.cp310-win_amd64.pyd +0 -0
- biotite/structure/io/mmtf/convertarray.pyx +0 -341
- biotite/structure/io/mmtf/convertfile.cp310-win_amd64.pyd +0 -0
- biotite/structure/io/mmtf/convertfile.pyx +0 -501
- biotite/structure/io/mmtf/decode.cp310-win_amd64.pyd +0 -0
- biotite/structure/io/mmtf/decode.pyx +0 -152
- biotite/structure/io/mmtf/encode.cp310-win_amd64.pyd +0 -0
- biotite/structure/io/mmtf/encode.pyx +0 -183
- biotite/structure/io/mmtf/file.py +0 -233
- biotite/structure/io/npz/__init__.py +0 -20
- biotite/structure/io/npz/file.py +0 -152
- biotite/structure/io/pdbx/legacy.py +0 -267
- biotite/structure/io/tng/__init__.py +0 -13
- biotite/structure/io/tng/file.py +0 -46
- biotite/temp.py +0 -86
- biotite-0.41.2.dist-info/RECORD +0 -340
- {biotite-0.41.2.dist-info → biotite-1.0.1.dist-info}/WHEEL +0 -0
- {biotite-0.41.2.dist-info → biotite-1.0.1.dist-info}/licenses/LICENSE.rst +0 -0
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
# This source code is part of the Biotite package and is distributed
|
|
2
|
-
# under the 3-Clause BSD License. Please see 'LICENSE.rst' for further
|
|
3
|
-
# information.
|
|
4
|
-
|
|
5
|
-
__name__ = "biotite.structure.io.mmtf"
|
|
6
|
-
__author__ = "Patrick Kunzmann"
|
|
7
|
-
__all__ = ["encode_array"]
|
|
8
|
-
|
|
9
|
-
cimport cython
|
|
10
|
-
cimport numpy as np
|
|
11
|
-
|
|
12
|
-
import numpy as np
|
|
13
|
-
|
|
14
|
-
ctypedef np.int8_t int8
|
|
15
|
-
ctypedef np.int16_t int16
|
|
16
|
-
ctypedef np.int32_t int32
|
|
17
|
-
ctypedef np.uint8_t uint8
|
|
18
|
-
ctypedef np.uint16_t uint16
|
|
19
|
-
ctypedef np.uint32_t uint32
|
|
20
|
-
ctypedef np.uint64_t uint64
|
|
21
|
-
ctypedef np.float32_t float32
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def encode_array(np.ndarray array, int codec, int param):
|
|
25
|
-
# Pass-through: 32-bit floating-point number array
|
|
26
|
-
if codec == 1:
|
|
27
|
-
array = array.astype(np.float32, copy=False)
|
|
28
|
-
return array.astype(">f4").tobytes()
|
|
29
|
-
# Pass-through: 8-bit signed integer array
|
|
30
|
-
elif codec == 2:
|
|
31
|
-
array = array.astype(np.int8, copy=False)
|
|
32
|
-
return array.astype(">i1").tobytes()
|
|
33
|
-
# Pass-through: 16-bit signed integer array
|
|
34
|
-
elif codec == 3:
|
|
35
|
-
array = array.astype(np.int16, copy=False)
|
|
36
|
-
return array.astype(">i2").tobytes()
|
|
37
|
-
# Pass-through: 32-bit signed integer array
|
|
38
|
-
elif codec == 4:
|
|
39
|
-
array = array.astype(np.int32, copy=False)
|
|
40
|
-
return array.astype(">i4").tobytes()
|
|
41
|
-
# UTF8/ASCII fixed-length string array
|
|
42
|
-
elif codec == 5:
|
|
43
|
-
dtype = np.dtype("U" + str(param))
|
|
44
|
-
array = array.astype(dtype, copy=False)
|
|
45
|
-
return array.astype(np.dtype("S" + str(param))).tobytes()
|
|
46
|
-
# Run-length encoded character array
|
|
47
|
-
elif codec == 6:
|
|
48
|
-
array = array.astype("U1", copy=False)
|
|
49
|
-
array = _encode_run_length(np.frombuffer(array, dtype=np.int32))
|
|
50
|
-
return array.astype(">i4").tobytes()
|
|
51
|
-
# Run-length encoded 32-bit signed integer array
|
|
52
|
-
elif codec == 7:
|
|
53
|
-
array = array.astype(np.int32, copy=False)
|
|
54
|
-
return _encode_run_length(array).astype(">i4").tobytes()
|
|
55
|
-
# Delta & run-length encoded 32-bit signed integer array
|
|
56
|
-
elif codec == 8:
|
|
57
|
-
array = array.astype(np.int32, copy=False)
|
|
58
|
-
return _encode_run_length(_encode_delta(array)).astype(">i4").tobytes()
|
|
59
|
-
# Integer & run-length encoded 32-bit floating-point number array
|
|
60
|
-
elif codec == 9:
|
|
61
|
-
array = array.astype(np.float32, copy=False)
|
|
62
|
-
return _encode_run_length(
|
|
63
|
-
_encode_integer(param, array).astype(np.int32)
|
|
64
|
-
).astype(">i4").tobytes()
|
|
65
|
-
# Integer & delta encoded
|
|
66
|
-
# & two-byte-packed 32-bit floating-point number array
|
|
67
|
-
elif codec == 10:
|
|
68
|
-
array = array.astype(np.float32, copy=False)
|
|
69
|
-
return _encode_packed(
|
|
70
|
-
True, _encode_delta(
|
|
71
|
-
_encode_integer(param, array).astype(np.int32)
|
|
72
|
-
)
|
|
73
|
-
).astype(">i2").tobytes()
|
|
74
|
-
# Integer encoded 32-bit floating-point number array
|
|
75
|
-
elif codec == 11:
|
|
76
|
-
array = array.astype(np.float32, copy=False)
|
|
77
|
-
return _encode_integer(param, array).astype(">i2").tobytes()
|
|
78
|
-
# Integer & two-byte-packed 32-bit floating-point number array
|
|
79
|
-
elif codec == 12:
|
|
80
|
-
array = array.astype(np.float32, copy=False)
|
|
81
|
-
return _encode_packed(
|
|
82
|
-
True, _encode_integer(param, array).astype(np.int32)
|
|
83
|
-
).astype(">i2").tobytes()
|
|
84
|
-
# Integer & one-byte-packed 32-bit floating-point number array
|
|
85
|
-
elif codec == 13:
|
|
86
|
-
array = array.astype(np.float32, copy=False)
|
|
87
|
-
return _encode_packed(
|
|
88
|
-
False, _encode_integer(param, array).astype(np.int32)
|
|
89
|
-
).astype(">i1").tobytes()
|
|
90
|
-
# Two-byte-packed 32-bit signed integer array
|
|
91
|
-
elif codec == 14:
|
|
92
|
-
array = array.astype(np.int32, copy=False)
|
|
93
|
-
return _encode_packed(True, array).astype(">i2").tobytes()
|
|
94
|
-
# One-byte-packed 32-bit signed integer array
|
|
95
|
-
elif codec == 15:
|
|
96
|
-
array = array.astype(np.int32, copy=False)
|
|
97
|
-
return _encode_packed(False, array).astype(">i1").tobytes()
|
|
98
|
-
else:
|
|
99
|
-
raise ValueError(f"Unknown codec with ID {codec}")
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def _encode_delta(int32[:] array):
|
|
103
|
-
cdef int32[:] output = np.zeros(array.shape[0], np.int32)
|
|
104
|
-
output[0] = array[0]
|
|
105
|
-
cdef int i = 0
|
|
106
|
-
for i in range(1, array.shape[0]):
|
|
107
|
-
output[i] = array[i] - array[i-1]
|
|
108
|
-
return np.asarray(output)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
def _encode_run_length(int32[:] array):
|
|
112
|
-
# Pessimistic allocation of output array
|
|
113
|
-
# -> Run length is 1 for every element
|
|
114
|
-
cdef int32[:] output = np.zeros(array.shape[0] * 2, dtype=np.int32)
|
|
115
|
-
cdef int i=0, j=0
|
|
116
|
-
cdef int val = array[0]
|
|
117
|
-
cdef int run_length = 0
|
|
118
|
-
cdef int curr_val
|
|
119
|
-
for i in range(array.shape[0]):
|
|
120
|
-
curr_val = array[i]
|
|
121
|
-
if curr_val == val:
|
|
122
|
-
run_length += 1
|
|
123
|
-
else:
|
|
124
|
-
# New element -> Write element with run-length
|
|
125
|
-
output[j] = val
|
|
126
|
-
output[j+1] = run_length
|
|
127
|
-
j += 2
|
|
128
|
-
val = curr_val
|
|
129
|
-
run_length = 1
|
|
130
|
-
# Write last element
|
|
131
|
-
output[j] = val
|
|
132
|
-
output[j+1] = run_length
|
|
133
|
-
j += 2
|
|
134
|
-
# Trim to correct size
|
|
135
|
-
return np.asarray(output)[:j]
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
@cython.cdivision(True)
|
|
139
|
-
def _encode_packed(bint two_byte, int32[:] array):
|
|
140
|
-
cdef int min_val, max_val
|
|
141
|
-
cdef int i=0, j=0
|
|
142
|
-
if two_byte:
|
|
143
|
-
min_val = np.iinfo(np.int16).min
|
|
144
|
-
max_val = np.iinfo(np.int16).max
|
|
145
|
-
else:
|
|
146
|
-
min_val = np.iinfo(np.int8).min
|
|
147
|
-
max_val = np.iinfo(np.int8).max
|
|
148
|
-
# Get length of output array
|
|
149
|
-
# by summing up required length of each element
|
|
150
|
-
cdef int number
|
|
151
|
-
cdef int length = 0
|
|
152
|
-
for i in range(array.shape[0]):
|
|
153
|
-
number = array[i]
|
|
154
|
-
if number < 0:
|
|
155
|
-
length += number // min_val +1
|
|
156
|
-
elif number > 0:
|
|
157
|
-
length += number // max_val +1
|
|
158
|
-
else:
|
|
159
|
-
# e = 0
|
|
160
|
-
length += 1
|
|
161
|
-
# Fill output
|
|
162
|
-
cdef int16[:] output = np.zeros(length, dtype=np.int16)
|
|
163
|
-
cdef int remainder
|
|
164
|
-
j = 0
|
|
165
|
-
for i in range(array.shape[0]):
|
|
166
|
-
remainder = array[i]
|
|
167
|
-
if remainder < 0:
|
|
168
|
-
while remainder <= min_val:
|
|
169
|
-
remainder -= min_val
|
|
170
|
-
output[j] = min_val
|
|
171
|
-
j += 1
|
|
172
|
-
elif remainder > 0:
|
|
173
|
-
while remainder >= max_val:
|
|
174
|
-
remainder -= max_val
|
|
175
|
-
output[j] = max_val
|
|
176
|
-
j += 1
|
|
177
|
-
output[j] = remainder
|
|
178
|
-
j += 1
|
|
179
|
-
return np.asarray(output)
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
def _encode_integer(int divisor, np.ndarray array):
|
|
183
|
-
return np.multiply(array, divisor)
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
# This source code is part of the Biotite package and is distributed
|
|
2
|
-
# under the 3-Clause BSD License. Please see 'LICENSE.rst' for further
|
|
3
|
-
# information.
|
|
4
|
-
|
|
5
|
-
__name__ = "biotite.structure.io.mmtf"
|
|
6
|
-
__author__ = "Patrick Kunzmann"
|
|
7
|
-
__all__ = ["MMTFFile"]
|
|
8
|
-
|
|
9
|
-
import io
|
|
10
|
-
from collections.abc import MutableMapping
|
|
11
|
-
import struct
|
|
12
|
-
import copy
|
|
13
|
-
import numpy as np
|
|
14
|
-
import msgpack
|
|
15
|
-
import warnings
|
|
16
|
-
from ....file import File, is_binary, is_open_compatible
|
|
17
|
-
from ...error import BadStructureError
|
|
18
|
-
from .decode import decode_array
|
|
19
|
-
from .encode import encode_array
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class MMTFFile(File, MutableMapping):
|
|
23
|
-
"""
|
|
24
|
-
This class represents a MMTF file.
|
|
25
|
-
|
|
26
|
-
When reading a file, the *MessagePack* unpacker is used to create
|
|
27
|
-
a dictionary of the file content.
|
|
28
|
-
This dictionary is accessed by indexing the :class:`MMTFFile`
|
|
29
|
-
instance directly with the dictionary keys.
|
|
30
|
-
If the dictionary value is an encoded array, the value automatically
|
|
31
|
-
decoded.
|
|
32
|
-
Decoded arrays are always returned as :class:`ndarray` instances.
|
|
33
|
-
|
|
34
|
-
DEPRECATED: Use :class:`biotite.structure.io.pdbx.BinaryCIFFile`
|
|
35
|
-
instead.
|
|
36
|
-
|
|
37
|
-
Examples
|
|
38
|
-
--------
|
|
39
|
-
|
|
40
|
-
>>> import os.path
|
|
41
|
-
>>> mmtf_file = MMTFFile.read(os.path.join(path_to_structures, "1l2y.mmtf"))
|
|
42
|
-
>>> print(mmtf_file["title"])
|
|
43
|
-
NMR Structure of Trp-Cage Miniprotein Construct TC5b
|
|
44
|
-
>>> print(mmtf_file["chainNameList"])
|
|
45
|
-
['A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A'
|
|
46
|
-
'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A'
|
|
47
|
-
'A' 'A']
|
|
48
|
-
"""
|
|
49
|
-
|
|
50
|
-
def __init__(self):
|
|
51
|
-
warnings.warn(
|
|
52
|
-
"'MMTFFile' is deprecated, use 'BinaryCIFFile' instead",
|
|
53
|
-
DeprecationWarning
|
|
54
|
-
)
|
|
55
|
-
super().__init__()
|
|
56
|
-
self._content = {}
|
|
57
|
-
self._content["mmtfVersion"] = "1.0.0"
|
|
58
|
-
self._content["mmtfProducer"] = "UNKNOWN"
|
|
59
|
-
|
|
60
|
-
@classmethod
|
|
61
|
-
def read(self, file):
|
|
62
|
-
"""
|
|
63
|
-
Read a MMTF file.
|
|
64
|
-
|
|
65
|
-
Parameters
|
|
66
|
-
----------
|
|
67
|
-
file : file-like object or str
|
|
68
|
-
The file to be read.
|
|
69
|
-
Alternatively a file path can be supplied.
|
|
70
|
-
|
|
71
|
-
Returns
|
|
72
|
-
-------
|
|
73
|
-
file_object : MMTFFile
|
|
74
|
-
The parsed file.
|
|
75
|
-
"""
|
|
76
|
-
mmtf_file = MMTFFile()
|
|
77
|
-
# File name
|
|
78
|
-
if is_open_compatible(file):
|
|
79
|
-
with open(file, "rb") as f:
|
|
80
|
-
mmtf_file._content = msgpack.unpackb(
|
|
81
|
-
f.read(), use_list=True, raw=False
|
|
82
|
-
)
|
|
83
|
-
# File object
|
|
84
|
-
else:
|
|
85
|
-
if not is_binary(file):
|
|
86
|
-
raise TypeError("A file opened in 'binary' mode is required")
|
|
87
|
-
mmtf_file._content = msgpack.unpackb(
|
|
88
|
-
file.read(), use_list=True, raw=False
|
|
89
|
-
)
|
|
90
|
-
return mmtf_file
|
|
91
|
-
|
|
92
|
-
def write(self, file):
|
|
93
|
-
"""
|
|
94
|
-
Write contents into a MMTF file.
|
|
95
|
-
|
|
96
|
-
Parameters
|
|
97
|
-
----------
|
|
98
|
-
file : file-like object or str
|
|
99
|
-
The file to be written to.
|
|
100
|
-
Alternatively, a file path can be supplied.
|
|
101
|
-
"""
|
|
102
|
-
packed_bytes = msgpack.packb(
|
|
103
|
-
self._content, use_bin_type=True, default=_encode_numpy
|
|
104
|
-
)
|
|
105
|
-
if is_open_compatible(file):
|
|
106
|
-
with open(file, "wb") as f:
|
|
107
|
-
f.write(packed_bytes)
|
|
108
|
-
else:
|
|
109
|
-
if not is_binary(file):
|
|
110
|
-
raise TypeError("A file opened in 'binary' mode is required")
|
|
111
|
-
file.write(packed_bytes)
|
|
112
|
-
|
|
113
|
-
def __copy_fill__(self, clone):
|
|
114
|
-
super().__copy_fill__(clone)
|
|
115
|
-
clone._content = copy.deepcopy(self._content)
|
|
116
|
-
|
|
117
|
-
def get_codec(self, key):
|
|
118
|
-
"""
|
|
119
|
-
Obtain the codec ID of an MMTF encoded value.
|
|
120
|
-
|
|
121
|
-
Parameters
|
|
122
|
-
----------
|
|
123
|
-
key : str
|
|
124
|
-
The key for the potentially encoded value.
|
|
125
|
-
|
|
126
|
-
Returns
|
|
127
|
-
-------
|
|
128
|
-
codec : int or None
|
|
129
|
-
The codec ID. `None` if the value is not encoded.
|
|
130
|
-
"""
|
|
131
|
-
data = self._content[key]
|
|
132
|
-
if isinstance(data, bytes) and data[0] == 0:
|
|
133
|
-
codec = struct.unpack(">i", data[0:4])[0]
|
|
134
|
-
return codec
|
|
135
|
-
else:
|
|
136
|
-
return None
|
|
137
|
-
|
|
138
|
-
def get_length(self, key):
|
|
139
|
-
"""
|
|
140
|
-
Obtain the length of an MMTF encoded value.
|
|
141
|
-
|
|
142
|
-
Parameters
|
|
143
|
-
----------
|
|
144
|
-
key : str
|
|
145
|
-
The key for the potentially encoded value.
|
|
146
|
-
|
|
147
|
-
Returns
|
|
148
|
-
-------
|
|
149
|
-
codec : int or None
|
|
150
|
-
The length of the `bytes` array.
|
|
151
|
-
`None` if the value is not encoded.
|
|
152
|
-
"""
|
|
153
|
-
data = self._content[key]
|
|
154
|
-
if isinstance(data, bytes) and data[0] == 0:
|
|
155
|
-
length = struct.unpack(">i", data[4:8])[0]
|
|
156
|
-
return length
|
|
157
|
-
else:
|
|
158
|
-
return None
|
|
159
|
-
|
|
160
|
-
def get_param(self, key):
|
|
161
|
-
"""
|
|
162
|
-
Obtain the parameter of an MMTF encoded value.
|
|
163
|
-
|
|
164
|
-
Parameters
|
|
165
|
-
----------
|
|
166
|
-
key : str
|
|
167
|
-
The key for the potentially encoded value.
|
|
168
|
-
|
|
169
|
-
Returns
|
|
170
|
-
-------
|
|
171
|
-
codec : int or None
|
|
172
|
-
The parameter of the encoded value.
|
|
173
|
-
`None` if the value is not encoded.
|
|
174
|
-
"""
|
|
175
|
-
data = self._content[key]
|
|
176
|
-
if isinstance(data, bytes) and data[0] == 0:
|
|
177
|
-
param = struct.unpack(">i", data[8:12])[0]
|
|
178
|
-
return param
|
|
179
|
-
else:
|
|
180
|
-
return None
|
|
181
|
-
|
|
182
|
-
def set_array(self, key, array, codec, param=0):
|
|
183
|
-
length = len(array)
|
|
184
|
-
raw_bytes = encode_array(array, codec, param)
|
|
185
|
-
data = struct.pack(">i", codec) \
|
|
186
|
-
+ struct.pack(">i", length) \
|
|
187
|
-
+ struct.pack(">i", param) \
|
|
188
|
-
+ raw_bytes
|
|
189
|
-
self._content[key] = data
|
|
190
|
-
|
|
191
|
-
def __getitem__(self, key):
|
|
192
|
-
data = self._content[key]
|
|
193
|
-
if isinstance(data, bytes) and data[0] == 0:
|
|
194
|
-
# MMTF specific format -> requires decoding
|
|
195
|
-
codec = struct.unpack(">i", data[0:4 ])[0]
|
|
196
|
-
length = struct.unpack(">i", data[4:8 ])[0]
|
|
197
|
-
param = struct.unpack(">i", data[8:12])[0]
|
|
198
|
-
raw_bytes = data[12:]
|
|
199
|
-
return decode_array(codec, raw_bytes, param)
|
|
200
|
-
else:
|
|
201
|
-
return data
|
|
202
|
-
|
|
203
|
-
def __setitem__(self, key, item):
|
|
204
|
-
if isinstance(item, np.ndarray):
|
|
205
|
-
raise TypeError("Arrays that need to be encoded must be addeed "
|
|
206
|
-
"via 'set_array()'")
|
|
207
|
-
self._content[key] = item
|
|
208
|
-
|
|
209
|
-
def __delitem__(self, key):
|
|
210
|
-
del self._content[key]
|
|
211
|
-
|
|
212
|
-
def __iter__(self):
|
|
213
|
-
return self._content.__iter__()
|
|
214
|
-
|
|
215
|
-
def __len__(self):
|
|
216
|
-
return len(self._content)
|
|
217
|
-
|
|
218
|
-
def __contains__(self, item):
|
|
219
|
-
return item in self._content
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
def _encode_numpy(item):
|
|
223
|
-
"""
|
|
224
|
-
Convert NumPy scalar types to native Python types,
|
|
225
|
-
as *Msgpack* cannot handle NumPy types (e.g. float32).
|
|
226
|
-
|
|
227
|
-
The function is given to the Msgpack packer as value for the
|
|
228
|
-
`default` parameter.
|
|
229
|
-
"""
|
|
230
|
-
if isinstance(item, np.generic):
|
|
231
|
-
return item.item()
|
|
232
|
-
else:
|
|
233
|
-
raise TypeError(f"can not serialize '{type(item).__name__}' object")
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# This source code is part of the Biotite package and is distributed
|
|
2
|
-
# under the 3-Clause BSD License. Please see 'LICENSE.rst' for further
|
|
3
|
-
# information.
|
|
4
|
-
|
|
5
|
-
"""
|
|
6
|
-
This subpackage is used for reading and writing an :class:`AtomArray` or
|
|
7
|
-
:class:`AtomArrayStack` using the internal NPZ file format. This binary
|
|
8
|
-
format is used to store `NumPy` arrays. Since atom arrays and stacks are
|
|
9
|
-
completely built on `NumPy` arrays, this format is preferable for
|
|
10
|
-
Biotite internal usage due to fast I/O operations and preservation
|
|
11
|
-
of all atom annotation arrays.
|
|
12
|
-
|
|
13
|
-
DEPRECATED: Pickle data directly or use
|
|
14
|
-
:class:`biotite.structure.io.pdbx.BinaryCIFFile` instead.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
__name__ = "biotite.structure.io.npz"
|
|
18
|
-
__author__ = "Patrick Kunzmann"
|
|
19
|
-
|
|
20
|
-
from .file import *
|
biotite/structure/io/npz/file.py
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
# This source code is part of the Biotite package and is distributed
|
|
2
|
-
# under the 3-Clause BSD License. Please see 'LICENSE.rst' for further
|
|
3
|
-
# information.
|
|
4
|
-
|
|
5
|
-
__name__ = "biotite.structure.io.npz"
|
|
6
|
-
__author__ = "Patrick Kunzmann"
|
|
7
|
-
__all__ = ["NpzFile"]
|
|
8
|
-
|
|
9
|
-
import numpy as np
|
|
10
|
-
from ...atoms import Atom, AtomArray, AtomArrayStack
|
|
11
|
-
from ...bonds import BondList
|
|
12
|
-
from ....file import File, is_binary
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class NpzFile(File):
|
|
16
|
-
r"""
|
|
17
|
-
This class represents a NPZ file, the preferable format for
|
|
18
|
-
Biotite internal structure storage.
|
|
19
|
-
|
|
20
|
-
Internally the this class writes/reads all attribute arrays of an
|
|
21
|
-
:class:`AtomArray` or :class:`AtomArrayStack` using the *NumPy*
|
|
22
|
-
:func:`save()`/:func:`load()`
|
|
23
|
-
method. This format offers the fastest I/O operations and completely
|
|
24
|
-
preserves the content all atom annotation arrays.
|
|
25
|
-
|
|
26
|
-
DEPRECATED: Pickle data directly or use
|
|
27
|
-
:class:`biotite.structure.io.pdbx.BinaryCIFFile` instead.
|
|
28
|
-
|
|
29
|
-
Examples
|
|
30
|
-
--------
|
|
31
|
-
Load a \\*.npz file, modify the structure and save the new
|
|
32
|
-
structure into a new file:
|
|
33
|
-
|
|
34
|
-
>>> import os.path
|
|
35
|
-
>>> file = NpzFile.read(os.path.join(path_to_structures, "1l2y.npz"))
|
|
36
|
-
>>> array_stack = file.get_structure()
|
|
37
|
-
>>> array_stack_mod = rotate(array_stack, [1,2,3])
|
|
38
|
-
>>> file = NpzFile()
|
|
39
|
-
>>> file.set_structure(array_stack_mod)
|
|
40
|
-
>>> file.write(os.path.join(path_to_directory, "1l2y_mod.npz"))
|
|
41
|
-
|
|
42
|
-
"""
|
|
43
|
-
|
|
44
|
-
def __init__(self):
|
|
45
|
-
super().__init__()
|
|
46
|
-
self._data_dict = None
|
|
47
|
-
|
|
48
|
-
def __copy_fill__(self, clone):
|
|
49
|
-
super().__copy_fill__(clone)
|
|
50
|
-
if self._data_dict is not None:
|
|
51
|
-
for key, value in self._data_dict.items():
|
|
52
|
-
clone._data_dict[key] = np.copy(value)
|
|
53
|
-
|
|
54
|
-
@classmethod
|
|
55
|
-
def read(cls, file):
|
|
56
|
-
"""
|
|
57
|
-
Read a NPZ file.
|
|
58
|
-
|
|
59
|
-
Parameters
|
|
60
|
-
----------
|
|
61
|
-
file : file-like object or str
|
|
62
|
-
The file to be read.
|
|
63
|
-
Alternatively a file path can be supplied.
|
|
64
|
-
|
|
65
|
-
Returns
|
|
66
|
-
-------
|
|
67
|
-
file_object : NPZFile
|
|
68
|
-
The parsed file.
|
|
69
|
-
"""
|
|
70
|
-
npz_file = NpzFile()
|
|
71
|
-
# File name
|
|
72
|
-
if isinstance(file, str):
|
|
73
|
-
with open(file, "rb") as f:
|
|
74
|
-
npz_file._data_dict = dict(np.load(f, allow_pickle=False))
|
|
75
|
-
# File object
|
|
76
|
-
else:
|
|
77
|
-
if not is_binary(file):
|
|
78
|
-
raise TypeError("A file opened in 'binary' mode is required")
|
|
79
|
-
npz_file._data_dict = dict(np.load(file, allow_pickle=False))
|
|
80
|
-
return npz_file
|
|
81
|
-
|
|
82
|
-
def write(self, file):
|
|
83
|
-
"""
|
|
84
|
-
Write a NPZ file.
|
|
85
|
-
|
|
86
|
-
Parameters
|
|
87
|
-
----------
|
|
88
|
-
file : file-like object or str
|
|
89
|
-
The file to be read.
|
|
90
|
-
Alternatively, a file path can be supplied.
|
|
91
|
-
"""
|
|
92
|
-
if isinstance(file, str):
|
|
93
|
-
with open(file, "wb") as f:
|
|
94
|
-
np.savez(f, **self._data_dict)
|
|
95
|
-
else:
|
|
96
|
-
if not is_binary(file):
|
|
97
|
-
raise TypeError("A file opened in 'binary' mode is required")
|
|
98
|
-
np.savez(file, **self._data_dict)
|
|
99
|
-
|
|
100
|
-
def get_structure(self):
|
|
101
|
-
"""
|
|
102
|
-
Get an :class:`AtomArray` or :class:`AtomArrayStack` from the
|
|
103
|
-
file.
|
|
104
|
-
|
|
105
|
-
If this method returns an array or stack depends on which type
|
|
106
|
-
of object was used when the file was written.
|
|
107
|
-
|
|
108
|
-
Returns
|
|
109
|
-
-------
|
|
110
|
-
array : AtomArray or AtomArrayStack
|
|
111
|
-
The array or stack contained in this file.
|
|
112
|
-
"""
|
|
113
|
-
if self._data_dict is None:
|
|
114
|
-
raise ValueError("The structure of this file "
|
|
115
|
-
"has not been loaded or set yet")
|
|
116
|
-
coord = self._data_dict["coord"]
|
|
117
|
-
# The type of the structure is determined by the dimensionality
|
|
118
|
-
# of the 'coord' field
|
|
119
|
-
if len(coord.shape) == 3:
|
|
120
|
-
array = AtomArrayStack(coord.shape[0], coord.shape[1])
|
|
121
|
-
else:
|
|
122
|
-
array = AtomArray(coord.shape[0])
|
|
123
|
-
|
|
124
|
-
for key, value in self._data_dict.items():
|
|
125
|
-
if key == "coord":
|
|
126
|
-
array.coord = value
|
|
127
|
-
elif key == "bonds":
|
|
128
|
-
array.bonds = BondList(array.array_length(), value)
|
|
129
|
-
elif key == "box":
|
|
130
|
-
array.box = value
|
|
131
|
-
else:
|
|
132
|
-
array.set_annotation(key, value)
|
|
133
|
-
return array
|
|
134
|
-
|
|
135
|
-
def set_structure(self, array):
|
|
136
|
-
"""
|
|
137
|
-
Set the :class:`AtomArray` or :class:`AtomArrayStack` for the
|
|
138
|
-
file.
|
|
139
|
-
|
|
140
|
-
Parameters
|
|
141
|
-
----------
|
|
142
|
-
array : AtomArray or AtomArrayStack
|
|
143
|
-
The array or stack to be saved into this file.
|
|
144
|
-
"""
|
|
145
|
-
self._data_dict = {}
|
|
146
|
-
self._data_dict["coord"] = np.copy(array.coord)
|
|
147
|
-
if array.bonds is not None:
|
|
148
|
-
self._data_dict["bonds"] = array.bonds.as_array()
|
|
149
|
-
if array.box is not None:
|
|
150
|
-
self._data_dict["box"] = np.copy(array.box)
|
|
151
|
-
for annot in array.get_annotation_categories():
|
|
152
|
-
self._data_dict[annot] = np.copy(array.get_annotation(annot))
|