biotite 1.0.1__cp312-cp312-macosx_11_0_arm64.whl → 1.2.0__cp312-cp312-macosx_11_0_arm64.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.

Files changed (177) hide show
  1. biotite/application/application.py +3 -3
  2. biotite/application/autodock/app.py +1 -1
  3. biotite/application/blast/webapp.py +1 -1
  4. biotite/application/clustalo/app.py +1 -1
  5. biotite/application/dssp/app.py +13 -3
  6. biotite/application/localapp.py +36 -2
  7. biotite/application/msaapp.py +10 -10
  8. biotite/application/muscle/app3.py +5 -18
  9. biotite/application/muscle/app5.py +5 -5
  10. biotite/application/sra/app.py +0 -5
  11. biotite/application/util.py +22 -2
  12. biotite/application/viennarna/rnaalifold.py +8 -8
  13. biotite/application/viennarna/rnaplot.py +9 -3
  14. biotite/application/viennarna/util.py +1 -1
  15. biotite/application/webapp.py +1 -1
  16. biotite/database/afdb/__init__.py +12 -0
  17. biotite/database/afdb/download.py +191 -0
  18. biotite/database/entrez/dbnames.py +10 -0
  19. biotite/database/entrez/download.py +9 -10
  20. biotite/database/entrez/key.py +1 -1
  21. biotite/database/entrez/query.py +5 -4
  22. biotite/database/pubchem/download.py +6 -6
  23. biotite/database/pubchem/error.py +10 -0
  24. biotite/database/pubchem/query.py +12 -23
  25. biotite/database/rcsb/download.py +3 -2
  26. biotite/database/rcsb/query.py +8 -9
  27. biotite/database/uniprot/check.py +22 -17
  28. biotite/database/uniprot/download.py +3 -6
  29. biotite/database/uniprot/query.py +4 -5
  30. biotite/file.py +14 -2
  31. biotite/interface/__init__.py +19 -0
  32. biotite/interface/openmm/__init__.py +16 -0
  33. biotite/interface/openmm/state.py +93 -0
  34. biotite/interface/openmm/system.py +227 -0
  35. biotite/interface/pymol/__init__.py +198 -0
  36. biotite/interface/pymol/cgo.py +346 -0
  37. biotite/interface/pymol/convert.py +185 -0
  38. biotite/interface/pymol/display.py +267 -0
  39. biotite/interface/pymol/object.py +1226 -0
  40. biotite/interface/pymol/shapes.py +178 -0
  41. biotite/interface/pymol/startup.py +169 -0
  42. biotite/interface/rdkit/__init__.py +15 -0
  43. biotite/interface/rdkit/mol.py +490 -0
  44. biotite/interface/version.py +71 -0
  45. biotite/interface/warning.py +19 -0
  46. biotite/sequence/align/__init__.py +0 -4
  47. biotite/sequence/align/alignment.py +49 -14
  48. biotite/sequence/align/banded.cpython-312-darwin.so +0 -0
  49. biotite/sequence/align/banded.pyx +26 -26
  50. biotite/sequence/align/cigar.py +2 -2
  51. biotite/sequence/align/kmeralphabet.cpython-312-darwin.so +0 -0
  52. biotite/sequence/align/kmeralphabet.pyx +19 -2
  53. biotite/sequence/align/kmersimilarity.cpython-312-darwin.so +0 -0
  54. biotite/sequence/align/kmertable.cpython-312-darwin.so +0 -0
  55. biotite/sequence/align/kmertable.pyx +58 -48
  56. biotite/sequence/align/localgapped.cpython-312-darwin.so +0 -0
  57. biotite/sequence/align/localgapped.pyx +47 -47
  58. biotite/sequence/align/localungapped.cpython-312-darwin.so +0 -0
  59. biotite/sequence/align/localungapped.pyx +10 -10
  60. biotite/sequence/align/matrix.py +284 -57
  61. biotite/sequence/align/matrix_data/3Di.mat +24 -0
  62. biotite/sequence/align/matrix_data/PB.license +21 -0
  63. biotite/sequence/align/matrix_data/PB.mat +18 -0
  64. biotite/sequence/align/multiple.cpython-312-darwin.so +0 -0
  65. biotite/sequence/align/pairwise.cpython-312-darwin.so +0 -0
  66. biotite/sequence/align/pairwise.pyx +35 -35
  67. biotite/sequence/align/permutation.cpython-312-darwin.so +0 -0
  68. biotite/sequence/align/selector.cpython-312-darwin.so +0 -0
  69. biotite/sequence/align/selector.pyx +2 -2
  70. biotite/sequence/align/statistics.py +1 -1
  71. biotite/sequence/align/tracetable.cpython-312-darwin.so +0 -0
  72. biotite/sequence/alphabet.py +5 -2
  73. biotite/sequence/annotation.py +19 -13
  74. biotite/sequence/codec.cpython-312-darwin.so +0 -0
  75. biotite/sequence/codon.py +1 -2
  76. biotite/sequence/graphics/alignment.py +25 -39
  77. biotite/sequence/graphics/color_schemes/3di_flower.json +48 -0
  78. biotite/sequence/graphics/color_schemes/pb_flower.json +2 -1
  79. biotite/sequence/graphics/colorschemes.py +44 -11
  80. biotite/sequence/graphics/dendrogram.py +4 -2
  81. biotite/sequence/graphics/features.py +2 -2
  82. biotite/sequence/graphics/logo.py +10 -12
  83. biotite/sequence/io/fasta/convert.py +1 -2
  84. biotite/sequence/io/fasta/file.py +1 -1
  85. biotite/sequence/io/fastq/file.py +3 -3
  86. biotite/sequence/io/genbank/file.py +3 -3
  87. biotite/sequence/io/genbank/sequence.py +2 -0
  88. biotite/sequence/io/gff/convert.py +1 -1
  89. biotite/sequence/io/gff/file.py +1 -2
  90. biotite/sequence/phylo/nj.cpython-312-darwin.so +0 -0
  91. biotite/sequence/phylo/tree.cpython-312-darwin.so +0 -0
  92. biotite/sequence/phylo/upgma.cpython-312-darwin.so +0 -0
  93. biotite/sequence/profile.py +105 -29
  94. biotite/sequence/search.py +0 -1
  95. biotite/sequence/seqtypes.py +136 -8
  96. biotite/sequence/sequence.py +1 -2
  97. biotite/setup_ccd.py +197 -0
  98. biotite/structure/__init__.py +6 -3
  99. biotite/structure/alphabet/__init__.py +25 -0
  100. biotite/structure/alphabet/encoder.py +332 -0
  101. biotite/structure/alphabet/encoder_weights_3di.kerasify +0 -0
  102. biotite/structure/alphabet/i3d.py +109 -0
  103. biotite/structure/alphabet/layers.py +86 -0
  104. biotite/structure/alphabet/pb.license +21 -0
  105. biotite/structure/alphabet/pb.py +170 -0
  106. biotite/structure/alphabet/unkerasify.py +128 -0
  107. biotite/structure/atoms.py +163 -66
  108. biotite/structure/basepairs.py +26 -26
  109. biotite/structure/bonds.cpython-312-darwin.so +0 -0
  110. biotite/structure/bonds.pyx +79 -25
  111. biotite/structure/box.py +19 -21
  112. biotite/structure/celllist.cpython-312-darwin.so +0 -0
  113. biotite/structure/celllist.pyx +83 -67
  114. biotite/structure/chains.py +5 -37
  115. biotite/structure/charges.cpython-312-darwin.so +0 -0
  116. biotite/structure/compare.py +420 -13
  117. biotite/structure/density.py +1 -1
  118. biotite/structure/dotbracket.py +27 -28
  119. biotite/structure/filter.py +8 -8
  120. biotite/structure/geometry.py +74 -127
  121. biotite/structure/hbond.py +17 -19
  122. biotite/structure/info/__init__.py +1 -0
  123. biotite/structure/info/atoms.py +24 -15
  124. biotite/structure/info/bonds.py +12 -6
  125. biotite/structure/info/ccd.py +125 -34
  126. biotite/structure/info/{ccd/components.bcif → components.bcif} +0 -0
  127. biotite/structure/info/groups.py +62 -19
  128. biotite/structure/info/masses.py +9 -6
  129. biotite/structure/info/misc.py +15 -22
  130. biotite/structure/info/radii.py +92 -22
  131. biotite/structure/info/standardize.py +4 -4
  132. biotite/structure/integrity.py +4 -6
  133. biotite/structure/io/general.py +2 -2
  134. biotite/structure/io/gro/file.py +8 -9
  135. biotite/structure/io/mol/convert.py +1 -1
  136. biotite/structure/io/mol/ctab.py +33 -28
  137. biotite/structure/io/mol/mol.py +1 -1
  138. biotite/structure/io/mol/sdf.py +80 -53
  139. biotite/structure/io/pdb/convert.py +4 -3
  140. biotite/structure/io/pdb/file.py +85 -25
  141. biotite/structure/io/pdb/hybrid36.cpython-312-darwin.so +0 -0
  142. biotite/structure/io/pdbqt/file.py +36 -36
  143. biotite/structure/io/pdbx/__init__.py +1 -0
  144. biotite/structure/io/pdbx/bcif.py +54 -15
  145. biotite/structure/io/pdbx/cif.py +92 -66
  146. biotite/structure/io/pdbx/component.py +15 -4
  147. biotite/structure/io/pdbx/compress.py +321 -0
  148. biotite/structure/io/pdbx/convert.py +410 -75
  149. biotite/structure/io/pdbx/encoding.cpython-312-darwin.so +0 -0
  150. biotite/structure/io/pdbx/encoding.pyx +98 -17
  151. biotite/structure/io/trajfile.py +9 -6
  152. biotite/structure/io/util.py +38 -0
  153. biotite/structure/mechanics.py +0 -1
  154. biotite/structure/molecules.py +141 -156
  155. biotite/structure/pseudoknots.py +7 -13
  156. biotite/structure/repair.py +2 -4
  157. biotite/structure/residues.py +13 -24
  158. biotite/structure/rings.py +335 -0
  159. biotite/structure/sasa.cpython-312-darwin.so +0 -0
  160. biotite/structure/sasa.pyx +2 -1
  161. biotite/structure/segments.py +69 -11
  162. biotite/structure/sequence.py +0 -1
  163. biotite/structure/sse.py +0 -2
  164. biotite/structure/superimpose.py +74 -62
  165. biotite/structure/tm.py +581 -0
  166. biotite/structure/transform.py +12 -25
  167. biotite/structure/util.py +76 -4
  168. biotite/version.py +9 -4
  169. biotite/visualize.py +111 -1
  170. {biotite-1.0.1.dist-info → biotite-1.2.0.dist-info}/METADATA +6 -2
  171. {biotite-1.0.1.dist-info → biotite-1.2.0.dist-info}/RECORD +173 -143
  172. biotite/structure/info/ccd/README.rst +0 -8
  173. biotite/structure/info/ccd/amino_acids.txt +0 -1663
  174. biotite/structure/info/ccd/carbohydrates.txt +0 -1135
  175. biotite/structure/info/ccd/nucleotides.txt +0 -798
  176. {biotite-1.0.1.dist-info → biotite-1.2.0.dist-info}/WHEEL +0 -0
  177. {biotite-1.0.1.dist-info → biotite-1.2.0.dist-info}/licenses/LICENSE.rst +0 -0
@@ -0,0 +1,267 @@
1
+ __name__ = "biotite.interface.pymol"
2
+ __author__ = "Patrick Kunzmann"
3
+ __all__ = ["TimeoutError", "RenderError", "show", "play"]
4
+
5
+ import datetime
6
+ import shutil
7
+ import subprocess
8
+ import tempfile
9
+ import time
10
+ from os import remove
11
+ from os.path import getsize, join
12
+ from biotite.interface.pymol.startup import get_and_set_pymol_instance
13
+
14
+ _INTERVAL = 0.1
15
+
16
+
17
+ class TimeoutError(Exception):
18
+ """
19
+ Exception that is raised after time limit expiry in :func:`show()`.
20
+ """
21
+
22
+ pass
23
+
24
+
25
+ class RenderError(Exception):
26
+ """
27
+ Exception that is raised when ``imagemagick`` or ``ffmpeg`` fails.
28
+ """
29
+
30
+ pass
31
+
32
+
33
+ def show(size=None, use_ray=False, timeout=60.0, pymol_instance=None):
34
+ """
35
+ Render an image of the *PyMOL* session and display it in the current
36
+ *Jupyter* notebook.
37
+
38
+ Note that this function works only in a *Jupyter* notebook.
39
+
40
+ Parameters
41
+ ----------
42
+ size : tuple of (int, int), optional
43
+ The width and height of the rendered image in pixels.
44
+ By default, the size of the current *PyMOL* viewport is used.
45
+ use_ray : bool, optional
46
+ If set to true, the a ray-traced image is created.
47
+ This will also increase the rendering time.
48
+ timeout : float
49
+ The number of seconds to wait for image output from *PyMOL*.
50
+ pymol_instance : module or SingletonPyMOL or PyMOL, optional
51
+ If *PyMOL* is used in library mode, the :class:`PyMOL`
52
+ or :class:`SingletonPyMOL` object is given here.
53
+ If otherwise *PyMOL* is used in GUI mode, the :mod:`pymol`
54
+ module is given.
55
+ By default the currently active *PyMOL* instance is used.
56
+ If no *PyMOL* instance is currently running,
57
+ *PyMOL* is started in library mode.
58
+
59
+ Raises
60
+ ------
61
+ TimeoutError
62
+ If no image was created after expiry of the `timeout` limit.
63
+
64
+ Notes
65
+ -----
66
+ Internally uses the *PyMOL* ``png`` command.
67
+ """
68
+ try:
69
+ from IPython.display import Image
70
+ except ImportError:
71
+ raise ImportError("IPython is not installed")
72
+
73
+ pymol_instance = get_and_set_pymol_instance(pymol_instance)
74
+ cmd = pymol_instance.cmd
75
+
76
+ if size is None:
77
+ width = 0
78
+ height = 0
79
+ else:
80
+ width, height = size
81
+
82
+ image_file = tempfile.NamedTemporaryFile(
83
+ delete=False, prefix="biotite_", suffix=".png"
84
+ )
85
+ # Close directly and cleanup later
86
+ # This is necessary, as Windows does not allow writing opened files
87
+ image_file.close()
88
+
89
+ start_time = datetime.datetime.now()
90
+ cmd.png(image_file.name, width, height, ray=int(use_ray))
91
+ while True:
92
+ # After 'timeout' seconds the loop exits with an error
93
+ if (datetime.datetime.now() - start_time).total_seconds() > timeout:
94
+ raise TimeoutError("No PNG image was output within the expected time limit")
95
+ # Check if PyMOL has already written image data to file
96
+ if getsize(image_file.name) > 0:
97
+ break
98
+ time.sleep(_INTERVAL)
99
+
100
+ with open(image_file.name, "rb") as f:
101
+ image_data = f.read()
102
+ remove(image_file.name)
103
+ return Image(image_data, embed=True, metadata={"source": "PyMOL"})
104
+
105
+
106
+ def play(
107
+ size=None, fps=30, format="gif", html_attributes="controls", pymol_instance=None
108
+ ):
109
+ """
110
+ Render an video of the *PyMOL* video frames and display it in the current
111
+ *Jupyter* notebook.
112
+
113
+ Note that this function works only in a *Jupyter* notebook.
114
+
115
+ Parameters
116
+ ----------
117
+ size : tuple of (int, int), optional
118
+ The width and height of the rendered video in pixels.
119
+ By default, the size of the current *PyMOL* viewport is used.
120
+ fps : int
121
+ The number of frames per second.
122
+ format : {"gif", "mp4"}, optional
123
+ The format of the rendered video.
124
+ By default, a GIF is created.
125
+ html_attributes : str, optional
126
+ The HTML attributes that are passed to the ``<video>`` tag.
127
+ Only used, if ``format="mp4"``.
128
+ pymol_instance : module or SingletonPyMOL or PyMOL, optional
129
+ If *PyMOL* is used in library mode, the :class:`PyMOL`
130
+ or :class:`SingletonPyMOL` object is given here.
131
+ If otherwise *PyMOL* is used in GUI mode, the :mod:`pymol`
132
+ module is given.
133
+ By default the currently active *PyMOL* instance is used.
134
+ If no *PyMOL* instance is currently running,
135
+ *PyMOL* is started in library mode.
136
+
137
+ Notes
138
+ -----
139
+ Internally uses the *PyMOL* ``mpng`` command.
140
+ This function requires either the ``ffmpeg`` (``gif`` or ``mp4``)
141
+ or ``imagemagick`` (``gif``) command line tool to be installed.
142
+ """
143
+ try:
144
+ from IPython.display import Image, Video
145
+ except ImportError:
146
+ raise ImportError("IPython is not installed")
147
+
148
+ pymol_instance = get_and_set_pymol_instance(pymol_instance)
149
+ cmd = pymol_instance.cmd
150
+
151
+ if size is None:
152
+ width = 0
153
+ height = 0
154
+ else:
155
+ width, height = size
156
+
157
+ with tempfile.TemporaryDirectory(prefix="biotite_") as frame_dir:
158
+ # Must use ray tracing, as no window is created
159
+ # Otherwise PyMOL raises 'MoviePNG-Error: Missing rendered image.'
160
+ cmd.mpng(join(frame_dir, "img_"), mode=2, width=width, height=height)
161
+ video_data = _create_video(frame_dir, fps, format)
162
+
163
+ if format == "mp4":
164
+ return Video(
165
+ video_data,
166
+ embed=True,
167
+ mimetype="video/mp4",
168
+ html_attributes=html_attributes,
169
+ )
170
+ else:
171
+ return Image(video_data, embed=True, metadata={"source": "PyMOL"})
172
+
173
+
174
+ def _create_video(input_dir, fps, format):
175
+ """
176
+ Create a video from the images in the given directory using ``ffmpeg```
177
+ or ``imagemagick``.
178
+
179
+ Parameters
180
+ ----------
181
+ input_dir : str
182
+ The directory containing the frames to be concatenated into a video.
183
+ The images are consumed in lexographical order.
184
+ fps : int
185
+ The number of frames per second.
186
+ format : {"gif", "mp4"}
187
+ The format of the video.
188
+
189
+ Returns
190
+ -------
191
+ video : bytes
192
+ The video data.
193
+ """
194
+ if format == "gif":
195
+ # GIFs created with 'imagemagick' have less artifacts
196
+ if _is_installed("magick"):
197
+ return _create_gif_with_imagemagick(input_dir, fps)
198
+ elif _is_installed("ffmpeg"):
199
+ return _create_video_with_ffmpeg(input_dir, fps, format)
200
+ else:
201
+ raise RenderError("Neither 'imagemagick' nor 'ffmpeg' is installed")
202
+ elif format == "mp4":
203
+ if _is_installed("ffmpeg"):
204
+ return _create_video_with_ffmpeg(input_dir, fps, format)
205
+ else:
206
+ raise RenderError("'ffmpeg' is not installed")
207
+
208
+
209
+ def _create_gif_with_imagemagick(input_dir, fps):
210
+ # See https://usage.imagemagick.org/anim_basics/ for reference
211
+ completed_process = subprocess.run(
212
+ [
213
+ "magick",
214
+ # GIFs require a multiple of a hundredth of a second to work properly
215
+ "-delay", str(int(100 / fps)),
216
+ # Make animation loop infinitely
217
+ "-loop", "0",
218
+ # Do not overlay images
219
+ "-dispose", "Previous",
220
+ join(input_dir, "*.png"),
221
+ # Decrease GIF size
222
+ "-layers", "Optimize",
223
+ "GIF:-",
224
+ ],
225
+ capture_output=True,
226
+ ) # fmt: skip
227
+ if completed_process.returncode != 0:
228
+ raise RenderError(completed_process.stderr.decode())
229
+ return completed_process.stdout
230
+
231
+
232
+ def _create_video_with_ffmpeg(input_dir, fps, format):
233
+ # 'input_dir' is a temporary directory anyway
234
+ video_path = join(input_dir, f"video.{format}")
235
+ completed_process = subprocess.run(
236
+ [
237
+ "ffmpeg",
238
+ "-i", join(input_dir, "img_%04d.png"),
239
+ "-r", str(fps),
240
+ # Must be set to obtain a non-corrupted video
241
+ "-pix_fmt", "yuv420p",
242
+ video_path,
243
+ ],
244
+ capture_output=True,
245
+ ) # fmt: skip
246
+ if completed_process.returncode != 0:
247
+ raise RenderError(completed_process.stderr.decode())
248
+ with open(video_path, "rb") as f:
249
+ video_data = f.read()
250
+ return video_data
251
+
252
+
253
+ def _is_installed(program):
254
+ """
255
+ Check whether the given program is installed.
256
+
257
+ Parameters
258
+ ----------
259
+ program : str
260
+ The name of the program to check.
261
+
262
+ Returns
263
+ -------
264
+ installed : bool
265
+ True, if the program is installed, false otherwise.
266
+ """
267
+ return shutil.which(program) is not None