biotite 1.1.0__cp313-cp313-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 (332) hide show
  1. biotite/__init__.py +18 -0
  2. biotite/application/__init__.py +69 -0
  3. biotite/application/application.py +276 -0
  4. biotite/application/autodock/__init__.py +12 -0
  5. biotite/application/autodock/app.py +500 -0
  6. biotite/application/blast/__init__.py +14 -0
  7. biotite/application/blast/alignment.py +92 -0
  8. biotite/application/blast/webapp.py +428 -0
  9. biotite/application/clustalo/__init__.py +12 -0
  10. biotite/application/clustalo/app.py +223 -0
  11. biotite/application/dssp/__init__.py +12 -0
  12. biotite/application/dssp/app.py +159 -0
  13. biotite/application/localapp.py +342 -0
  14. biotite/application/mafft/__init__.py +12 -0
  15. biotite/application/mafft/app.py +116 -0
  16. biotite/application/msaapp.py +363 -0
  17. biotite/application/muscle/__init__.py +13 -0
  18. biotite/application/muscle/app3.py +227 -0
  19. biotite/application/muscle/app5.py +163 -0
  20. biotite/application/sra/__init__.py +18 -0
  21. biotite/application/sra/app.py +452 -0
  22. biotite/application/tantan/__init__.py +12 -0
  23. biotite/application/tantan/app.py +199 -0
  24. biotite/application/util.py +57 -0
  25. biotite/application/viennarna/__init__.py +18 -0
  26. biotite/application/viennarna/rnaalifold.py +310 -0
  27. biotite/application/viennarna/rnafold.py +254 -0
  28. biotite/application/viennarna/rnaplot.py +206 -0
  29. biotite/application/viennarna/util.py +77 -0
  30. biotite/application/webapp.py +76 -0
  31. biotite/copyable.py +71 -0
  32. biotite/database/__init__.py +23 -0
  33. biotite/database/entrez/__init__.py +15 -0
  34. biotite/database/entrez/check.py +60 -0
  35. biotite/database/entrez/dbnames.py +91 -0
  36. biotite/database/entrez/download.py +229 -0
  37. biotite/database/entrez/key.py +44 -0
  38. biotite/database/entrez/query.py +262 -0
  39. biotite/database/error.py +16 -0
  40. biotite/database/pubchem/__init__.py +21 -0
  41. biotite/database/pubchem/download.py +258 -0
  42. biotite/database/pubchem/error.py +20 -0
  43. biotite/database/pubchem/query.py +830 -0
  44. biotite/database/pubchem/throttle.py +98 -0
  45. biotite/database/rcsb/__init__.py +13 -0
  46. biotite/database/rcsb/download.py +159 -0
  47. biotite/database/rcsb/query.py +964 -0
  48. biotite/database/uniprot/__init__.py +13 -0
  49. biotite/database/uniprot/check.py +40 -0
  50. biotite/database/uniprot/download.py +129 -0
  51. biotite/database/uniprot/query.py +293 -0
  52. biotite/file.py +232 -0
  53. biotite/sequence/__init__.py +84 -0
  54. biotite/sequence/align/__init__.py +203 -0
  55. biotite/sequence/align/alignment.py +680 -0
  56. biotite/sequence/align/banded.cpython-313-darwin.so +0 -0
  57. biotite/sequence/align/banded.pyx +652 -0
  58. biotite/sequence/align/buckets.py +71 -0
  59. biotite/sequence/align/cigar.py +425 -0
  60. biotite/sequence/align/kmeralphabet.cpython-313-darwin.so +0 -0
  61. biotite/sequence/align/kmeralphabet.pyx +595 -0
  62. biotite/sequence/align/kmersimilarity.cpython-313-darwin.so +0 -0
  63. biotite/sequence/align/kmersimilarity.pyx +233 -0
  64. biotite/sequence/align/kmertable.cpython-313-darwin.so +0 -0
  65. biotite/sequence/align/kmertable.pyx +3411 -0
  66. biotite/sequence/align/localgapped.cpython-313-darwin.so +0 -0
  67. biotite/sequence/align/localgapped.pyx +892 -0
  68. biotite/sequence/align/localungapped.cpython-313-darwin.so +0 -0
  69. biotite/sequence/align/localungapped.pyx +279 -0
  70. biotite/sequence/align/matrix.py +622 -0
  71. biotite/sequence/align/matrix_data/3Di.mat +24 -0
  72. biotite/sequence/align/matrix_data/BLOSUM100.mat +31 -0
  73. biotite/sequence/align/matrix_data/BLOSUM30.mat +31 -0
  74. biotite/sequence/align/matrix_data/BLOSUM35.mat +31 -0
  75. biotite/sequence/align/matrix_data/BLOSUM40.mat +31 -0
  76. biotite/sequence/align/matrix_data/BLOSUM45.mat +31 -0
  77. biotite/sequence/align/matrix_data/BLOSUM50.mat +31 -0
  78. biotite/sequence/align/matrix_data/BLOSUM50_13p.mat +25 -0
  79. biotite/sequence/align/matrix_data/BLOSUM50_14.3.mat +25 -0
  80. biotite/sequence/align/matrix_data/BLOSUM50_5.0.mat +25 -0
  81. biotite/sequence/align/matrix_data/BLOSUM55.mat +31 -0
  82. biotite/sequence/align/matrix_data/BLOSUM60.mat +31 -0
  83. biotite/sequence/align/matrix_data/BLOSUM62.mat +31 -0
  84. biotite/sequence/align/matrix_data/BLOSUM62_13p.mat +25 -0
  85. biotite/sequence/align/matrix_data/BLOSUM62_14.3.mat +25 -0
  86. biotite/sequence/align/matrix_data/BLOSUM62_5.0.mat +25 -0
  87. biotite/sequence/align/matrix_data/BLOSUM65.mat +31 -0
  88. biotite/sequence/align/matrix_data/BLOSUM70.mat +31 -0
  89. biotite/sequence/align/matrix_data/BLOSUM75.mat +31 -0
  90. biotite/sequence/align/matrix_data/BLOSUM80.mat +31 -0
  91. biotite/sequence/align/matrix_data/BLOSUM85.mat +31 -0
  92. biotite/sequence/align/matrix_data/BLOSUM90.mat +31 -0
  93. biotite/sequence/align/matrix_data/BLOSUMN.mat +31 -0
  94. biotite/sequence/align/matrix_data/CorBLOSUM49_5.0.mat +25 -0
  95. biotite/sequence/align/matrix_data/CorBLOSUM57_13p.mat +25 -0
  96. biotite/sequence/align/matrix_data/CorBLOSUM57_14.3.mat +25 -0
  97. biotite/sequence/align/matrix_data/CorBLOSUM61_5.0.mat +25 -0
  98. biotite/sequence/align/matrix_data/CorBLOSUM66_13p.mat +25 -0
  99. biotite/sequence/align/matrix_data/CorBLOSUM67_14.3.mat +25 -0
  100. biotite/sequence/align/matrix_data/DAYHOFF.mat +32 -0
  101. biotite/sequence/align/matrix_data/GONNET.mat +26 -0
  102. biotite/sequence/align/matrix_data/IDENTITY.mat +25 -0
  103. biotite/sequence/align/matrix_data/MATCH.mat +25 -0
  104. biotite/sequence/align/matrix_data/NUC.mat +25 -0
  105. biotite/sequence/align/matrix_data/PAM10.mat +34 -0
  106. biotite/sequence/align/matrix_data/PAM100.mat +34 -0
  107. biotite/sequence/align/matrix_data/PAM110.mat +34 -0
  108. biotite/sequence/align/matrix_data/PAM120.mat +34 -0
  109. biotite/sequence/align/matrix_data/PAM130.mat +34 -0
  110. biotite/sequence/align/matrix_data/PAM140.mat +34 -0
  111. biotite/sequence/align/matrix_data/PAM150.mat +34 -0
  112. biotite/sequence/align/matrix_data/PAM160.mat +34 -0
  113. biotite/sequence/align/matrix_data/PAM170.mat +34 -0
  114. biotite/sequence/align/matrix_data/PAM180.mat +34 -0
  115. biotite/sequence/align/matrix_data/PAM190.mat +34 -0
  116. biotite/sequence/align/matrix_data/PAM20.mat +34 -0
  117. biotite/sequence/align/matrix_data/PAM200.mat +34 -0
  118. biotite/sequence/align/matrix_data/PAM210.mat +34 -0
  119. biotite/sequence/align/matrix_data/PAM220.mat +34 -0
  120. biotite/sequence/align/matrix_data/PAM230.mat +34 -0
  121. biotite/sequence/align/matrix_data/PAM240.mat +34 -0
  122. biotite/sequence/align/matrix_data/PAM250.mat +34 -0
  123. biotite/sequence/align/matrix_data/PAM260.mat +34 -0
  124. biotite/sequence/align/matrix_data/PAM270.mat +34 -0
  125. biotite/sequence/align/matrix_data/PAM280.mat +34 -0
  126. biotite/sequence/align/matrix_data/PAM290.mat +34 -0
  127. biotite/sequence/align/matrix_data/PAM30.mat +34 -0
  128. biotite/sequence/align/matrix_data/PAM300.mat +34 -0
  129. biotite/sequence/align/matrix_data/PAM310.mat +34 -0
  130. biotite/sequence/align/matrix_data/PAM320.mat +34 -0
  131. biotite/sequence/align/matrix_data/PAM330.mat +34 -0
  132. biotite/sequence/align/matrix_data/PAM340.mat +34 -0
  133. biotite/sequence/align/matrix_data/PAM350.mat +34 -0
  134. biotite/sequence/align/matrix_data/PAM360.mat +34 -0
  135. biotite/sequence/align/matrix_data/PAM370.mat +34 -0
  136. biotite/sequence/align/matrix_data/PAM380.mat +34 -0
  137. biotite/sequence/align/matrix_data/PAM390.mat +34 -0
  138. biotite/sequence/align/matrix_data/PAM40.mat +34 -0
  139. biotite/sequence/align/matrix_data/PAM400.mat +34 -0
  140. biotite/sequence/align/matrix_data/PAM410.mat +34 -0
  141. biotite/sequence/align/matrix_data/PAM420.mat +34 -0
  142. biotite/sequence/align/matrix_data/PAM430.mat +34 -0
  143. biotite/sequence/align/matrix_data/PAM440.mat +34 -0
  144. biotite/sequence/align/matrix_data/PAM450.mat +34 -0
  145. biotite/sequence/align/matrix_data/PAM460.mat +34 -0
  146. biotite/sequence/align/matrix_data/PAM470.mat +34 -0
  147. biotite/sequence/align/matrix_data/PAM480.mat +34 -0
  148. biotite/sequence/align/matrix_data/PAM490.mat +34 -0
  149. biotite/sequence/align/matrix_data/PAM50.mat +34 -0
  150. biotite/sequence/align/matrix_data/PAM500.mat +34 -0
  151. biotite/sequence/align/matrix_data/PAM60.mat +34 -0
  152. biotite/sequence/align/matrix_data/PAM70.mat +34 -0
  153. biotite/sequence/align/matrix_data/PAM80.mat +34 -0
  154. biotite/sequence/align/matrix_data/PAM90.mat +34 -0
  155. biotite/sequence/align/matrix_data/PB.license +21 -0
  156. biotite/sequence/align/matrix_data/PB.mat +18 -0
  157. biotite/sequence/align/matrix_data/RBLOSUM52_5.0.mat +25 -0
  158. biotite/sequence/align/matrix_data/RBLOSUM59_13p.mat +25 -0
  159. biotite/sequence/align/matrix_data/RBLOSUM59_14.3.mat +25 -0
  160. biotite/sequence/align/matrix_data/RBLOSUM64_5.0.mat +25 -0
  161. biotite/sequence/align/matrix_data/RBLOSUM69_13p.mat +25 -0
  162. biotite/sequence/align/matrix_data/RBLOSUM69_14.3.mat +25 -0
  163. biotite/sequence/align/multiple.cpython-313-darwin.so +0 -0
  164. biotite/sequence/align/multiple.pyx +620 -0
  165. biotite/sequence/align/pairwise.cpython-313-darwin.so +0 -0
  166. biotite/sequence/align/pairwise.pyx +587 -0
  167. biotite/sequence/align/permutation.cpython-313-darwin.so +0 -0
  168. biotite/sequence/align/permutation.pyx +313 -0
  169. biotite/sequence/align/primes.txt +821 -0
  170. biotite/sequence/align/selector.cpython-313-darwin.so +0 -0
  171. biotite/sequence/align/selector.pyx +954 -0
  172. biotite/sequence/align/statistics.py +264 -0
  173. biotite/sequence/align/tracetable.cpython-313-darwin.so +0 -0
  174. biotite/sequence/align/tracetable.pxd +64 -0
  175. biotite/sequence/align/tracetable.pyx +370 -0
  176. biotite/sequence/alphabet.py +555 -0
  177. biotite/sequence/annotation.py +830 -0
  178. biotite/sequence/codec.cpython-313-darwin.so +0 -0
  179. biotite/sequence/codec.pyx +155 -0
  180. biotite/sequence/codon.py +477 -0
  181. biotite/sequence/codon_tables.txt +202 -0
  182. biotite/sequence/graphics/__init__.py +33 -0
  183. biotite/sequence/graphics/alignment.py +1115 -0
  184. biotite/sequence/graphics/color_schemes/3di_flower.json +48 -0
  185. biotite/sequence/graphics/color_schemes/autumn.json +51 -0
  186. biotite/sequence/graphics/color_schemes/blossom.json +51 -0
  187. biotite/sequence/graphics/color_schemes/clustalx_dna.json +11 -0
  188. biotite/sequence/graphics/color_schemes/clustalx_protein.json +28 -0
  189. biotite/sequence/graphics/color_schemes/flower.json +51 -0
  190. biotite/sequence/graphics/color_schemes/jalview_buried.json +31 -0
  191. biotite/sequence/graphics/color_schemes/jalview_hydrophobicity.json +31 -0
  192. biotite/sequence/graphics/color_schemes/jalview_prop_helix.json +31 -0
  193. biotite/sequence/graphics/color_schemes/jalview_prop_strand.json +31 -0
  194. biotite/sequence/graphics/color_schemes/jalview_prop_turn.json +31 -0
  195. biotite/sequence/graphics/color_schemes/jalview_taylor.json +28 -0
  196. biotite/sequence/graphics/color_schemes/jalview_zappo.json +28 -0
  197. biotite/sequence/graphics/color_schemes/ocean.json +51 -0
  198. biotite/sequence/graphics/color_schemes/pb_flower.json +40 -0
  199. biotite/sequence/graphics/color_schemes/rainbow_dna.json +11 -0
  200. biotite/sequence/graphics/color_schemes/rainbow_protein.json +30 -0
  201. biotite/sequence/graphics/color_schemes/spring.json +51 -0
  202. biotite/sequence/graphics/color_schemes/sunset.json +51 -0
  203. biotite/sequence/graphics/color_schemes/wither.json +51 -0
  204. biotite/sequence/graphics/colorschemes.py +170 -0
  205. biotite/sequence/graphics/dendrogram.py +229 -0
  206. biotite/sequence/graphics/features.py +544 -0
  207. biotite/sequence/graphics/logo.py +104 -0
  208. biotite/sequence/graphics/plasmid.py +712 -0
  209. biotite/sequence/io/__init__.py +12 -0
  210. biotite/sequence/io/fasta/__init__.py +22 -0
  211. biotite/sequence/io/fasta/convert.py +284 -0
  212. biotite/sequence/io/fasta/file.py +265 -0
  213. biotite/sequence/io/fastq/__init__.py +19 -0
  214. biotite/sequence/io/fastq/convert.py +117 -0
  215. biotite/sequence/io/fastq/file.py +507 -0
  216. biotite/sequence/io/genbank/__init__.py +17 -0
  217. biotite/sequence/io/genbank/annotation.py +269 -0
  218. biotite/sequence/io/genbank/file.py +573 -0
  219. biotite/sequence/io/genbank/metadata.py +336 -0
  220. biotite/sequence/io/genbank/sequence.py +171 -0
  221. biotite/sequence/io/general.py +201 -0
  222. biotite/sequence/io/gff/__init__.py +26 -0
  223. biotite/sequence/io/gff/convert.py +128 -0
  224. biotite/sequence/io/gff/file.py +450 -0
  225. biotite/sequence/phylo/__init__.py +36 -0
  226. biotite/sequence/phylo/nj.cpython-313-darwin.so +0 -0
  227. biotite/sequence/phylo/nj.pyx +221 -0
  228. biotite/sequence/phylo/tree.cpython-313-darwin.so +0 -0
  229. biotite/sequence/phylo/tree.pyx +1169 -0
  230. biotite/sequence/phylo/upgma.cpython-313-darwin.so +0 -0
  231. biotite/sequence/phylo/upgma.pyx +164 -0
  232. biotite/sequence/profile.py +567 -0
  233. biotite/sequence/search.py +118 -0
  234. biotite/sequence/seqtypes.py +713 -0
  235. biotite/sequence/sequence.py +374 -0
  236. biotite/setup_ccd.py +197 -0
  237. biotite/structure/__init__.py +133 -0
  238. biotite/structure/alphabet/__init__.py +25 -0
  239. biotite/structure/alphabet/encoder.py +332 -0
  240. biotite/structure/alphabet/encoder_weights_3di.kerasify +0 -0
  241. biotite/structure/alphabet/i3d.py +110 -0
  242. biotite/structure/alphabet/layers.py +86 -0
  243. biotite/structure/alphabet/pb.license +21 -0
  244. biotite/structure/alphabet/pb.py +171 -0
  245. biotite/structure/alphabet/unkerasify.py +122 -0
  246. biotite/structure/atoms.py +1554 -0
  247. biotite/structure/basepairs.py +1404 -0
  248. biotite/structure/bonds.cpython-313-darwin.so +0 -0
  249. biotite/structure/bonds.pyx +1972 -0
  250. biotite/structure/box.py +588 -0
  251. biotite/structure/celllist.cpython-313-darwin.so +0 -0
  252. biotite/structure/celllist.pyx +849 -0
  253. biotite/structure/chains.py +314 -0
  254. biotite/structure/charges.cpython-313-darwin.so +0 -0
  255. biotite/structure/charges.pyx +520 -0
  256. biotite/structure/compare.py +274 -0
  257. biotite/structure/density.py +109 -0
  258. biotite/structure/dotbracket.py +214 -0
  259. biotite/structure/error.py +39 -0
  260. biotite/structure/filter.py +590 -0
  261. biotite/structure/geometry.py +655 -0
  262. biotite/structure/graphics/__init__.py +13 -0
  263. biotite/structure/graphics/atoms.py +243 -0
  264. biotite/structure/graphics/rna.py +295 -0
  265. biotite/structure/hbond.py +428 -0
  266. biotite/structure/info/__init__.py +24 -0
  267. biotite/structure/info/atom_masses.json +121 -0
  268. biotite/structure/info/atoms.py +81 -0
  269. biotite/structure/info/bonds.py +149 -0
  270. biotite/structure/info/ccd.py +202 -0
  271. biotite/structure/info/components.bcif +0 -0
  272. biotite/structure/info/groups.py +131 -0
  273. biotite/structure/info/masses.py +121 -0
  274. biotite/structure/info/misc.py +138 -0
  275. biotite/structure/info/radii.py +197 -0
  276. biotite/structure/info/standardize.py +186 -0
  277. biotite/structure/integrity.py +215 -0
  278. biotite/structure/io/__init__.py +29 -0
  279. biotite/structure/io/dcd/__init__.py +13 -0
  280. biotite/structure/io/dcd/file.py +67 -0
  281. biotite/structure/io/general.py +243 -0
  282. biotite/structure/io/gro/__init__.py +14 -0
  283. biotite/structure/io/gro/file.py +344 -0
  284. biotite/structure/io/mol/__init__.py +20 -0
  285. biotite/structure/io/mol/convert.py +112 -0
  286. biotite/structure/io/mol/ctab.py +415 -0
  287. biotite/structure/io/mol/header.py +120 -0
  288. biotite/structure/io/mol/mol.py +149 -0
  289. biotite/structure/io/mol/sdf.py +914 -0
  290. biotite/structure/io/netcdf/__init__.py +13 -0
  291. biotite/structure/io/netcdf/file.py +64 -0
  292. biotite/structure/io/pdb/__init__.py +20 -0
  293. biotite/structure/io/pdb/convert.py +307 -0
  294. biotite/structure/io/pdb/file.py +1290 -0
  295. biotite/structure/io/pdb/hybrid36.cpython-313-darwin.so +0 -0
  296. biotite/structure/io/pdb/hybrid36.pyx +242 -0
  297. biotite/structure/io/pdbqt/__init__.py +15 -0
  298. biotite/structure/io/pdbqt/convert.py +113 -0
  299. biotite/structure/io/pdbqt/file.py +688 -0
  300. biotite/structure/io/pdbx/__init__.py +23 -0
  301. biotite/structure/io/pdbx/bcif.py +656 -0
  302. biotite/structure/io/pdbx/cif.py +1075 -0
  303. biotite/structure/io/pdbx/component.py +245 -0
  304. biotite/structure/io/pdbx/compress.py +321 -0
  305. biotite/structure/io/pdbx/convert.py +1745 -0
  306. biotite/structure/io/pdbx/encoding.cpython-313-darwin.so +0 -0
  307. biotite/structure/io/pdbx/encoding.pyx +1031 -0
  308. biotite/structure/io/trajfile.py +693 -0
  309. biotite/structure/io/trr/__init__.py +13 -0
  310. biotite/structure/io/trr/file.py +43 -0
  311. biotite/structure/io/xtc/__init__.py +13 -0
  312. biotite/structure/io/xtc/file.py +43 -0
  313. biotite/structure/mechanics.py +73 -0
  314. biotite/structure/molecules.py +352 -0
  315. biotite/structure/pseudoknots.py +628 -0
  316. biotite/structure/rdf.py +245 -0
  317. biotite/structure/repair.py +304 -0
  318. biotite/structure/residues.py +572 -0
  319. biotite/structure/sasa.cpython-313-darwin.so +0 -0
  320. biotite/structure/sasa.pyx +322 -0
  321. biotite/structure/segments.py +178 -0
  322. biotite/structure/sequence.py +111 -0
  323. biotite/structure/sse.py +308 -0
  324. biotite/structure/superimpose.py +689 -0
  325. biotite/structure/transform.py +530 -0
  326. biotite/structure/util.py +168 -0
  327. biotite/version.py +16 -0
  328. biotite/visualize.py +265 -0
  329. biotite-1.1.0.dist-info/METADATA +190 -0
  330. biotite-1.1.0.dist-info/RECORD +332 -0
  331. biotite-1.1.0.dist-info/WHEEL +4 -0
  332. biotite-1.1.0.dist-info/licenses/LICENSE.rst +30 -0
@@ -0,0 +1,693 @@
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"
6
+ __author__ = "Patrick Kunzmann"
7
+ __all__ = ["TrajectoryFile"]
8
+
9
+ import abc
10
+ import itertools
11
+ import numpy as np
12
+ from biotite.file import File
13
+ from biotite.structure.atoms import AtomArray, AtomArrayStack, from_template
14
+
15
+
16
+ class TrajectoryFile(File, metaclass=abc.ABCMeta):
17
+ """
18
+ This file class represents a trajectory file interfacing a
19
+ trajectory file class from `biotraj`.
20
+
21
+ A trajectory file stores atom coordinates over multiple (time)
22
+ frames. The file formats are usually binary and involve sometimes
23
+ heavy compression, so that a large number of frames can be stored
24
+ in relatively small space.
25
+
26
+ Notes
27
+ -----
28
+ When extracting data from the file, only a reference to the
29
+ data arrays stored in this file are created.
30
+ The same is true, when setting data in the file.
31
+ Therefore, it is strongly recommended to make a copy of the
32
+ respective array, if the array is modified.
33
+ """
34
+
35
+ def __init__(self):
36
+ super().__init__()
37
+ self._coord = None
38
+ self._time = None
39
+ self._box = None
40
+ self._model_count = None
41
+
42
+ @classmethod
43
+ def read(
44
+ cls, file_name, start=None, stop=None, step=None, atom_i=None, chunk_size=None
45
+ ):
46
+ """
47
+ Read a trajectory file.
48
+
49
+ A trajectory file can be seen as a file representation of an
50
+ :class:`AtomArrayStack`.
51
+ Therefore, `start`, `stop` and `step` represent slice parameters
52
+ of the index of the first dimension and
53
+ `atom_i` represents an index array for the second dimension.
54
+
55
+ Parameters
56
+ ----------
57
+ file_name : str or Path
58
+ The path of the file to be read.
59
+ Any other file-like object cannot be used.
60
+ start : int, optional
61
+ The frame index, where file parsing is started. If no value
62
+ is given, parsing starts at the first frame.
63
+ The index starts at 0.
64
+ stop : int, optional
65
+ The exclusive frame index, where file parsing ends.
66
+ If no value is given, parsing stops after the last frame.
67
+ The index starts at 0.
68
+ step : int, optional
69
+ If this value is set, the function reads only every n-th
70
+ frame from the file.
71
+ atom_i : ndarray, dtype=int, optional
72
+ If this parameter is set, only the atoms at the given
73
+ indices are read from each frame.
74
+ chunk_size : int, optional
75
+ If this parameter is set, the trajectory is read in chunks:
76
+ Only the number of frames specified by this parameter are
77
+ read at once.
78
+ The resulting chunks of frames are automatically
79
+ concatenated, after all chunks are collected.
80
+ Use this parameter, if a :class:`MemoryError` is raised
81
+ when a trajectory file is read.
82
+ Although lower values can decrease the memory consumption of
83
+ reading trajectories, they also increase the computation
84
+ time.
85
+
86
+ Returns
87
+ -------
88
+ file_object : TrajectoryFile
89
+ The parsed trajectory file.
90
+ """
91
+ file = cls()
92
+
93
+ if chunk_size is not None:
94
+ if chunk_size < 1:
95
+ raise ValueError("Chunk size must be greater than 0")
96
+ # Chunk size must be a multiple of step size to ensure that
97
+ # the step distance at the chunk border is the same as
98
+ # within a chunk
99
+ # -> round chunk size up to a multiple of step size
100
+ if step is not None and chunk_size % step != 0:
101
+ chunk_size = ((chunk_size // step) + 1) * step
102
+
103
+ traj_type = cls.traj_type()
104
+ with traj_type(str(file_name), "r") as f:
105
+ if start is None:
106
+ start = 0
107
+ # Discard atoms before start
108
+ if start != 0:
109
+ if chunk_size is None or chunk_size > start:
110
+ f.read(n_frames=start, stride=None, atom_indices=atom_i)
111
+ else:
112
+ TrajectoryFile._read_chunk_wise(
113
+ f, start, None, atom_i, chunk_size, discard=True
114
+ )
115
+
116
+ # The upcoming frames are saved
117
+ # Calculate the amount of frames to be read
118
+ if stop is None:
119
+ n_frames = None
120
+ else:
121
+ n_frames = stop - start
122
+ if step is not None and n_frames is not None:
123
+ # Divide number of frames by 'step' in order to convert
124
+ # 'step' into 'stride'
125
+ # Since the 0th frame is always included,
126
+ # the number of frames is decremented before division
127
+ # and incremented afterwards again
128
+ n_frames = ((n_frames - 1) // step) + 1
129
+
130
+ # Read frames
131
+ if chunk_size is None:
132
+ result = f.read(n_frames, stride=step, atom_indices=atom_i)
133
+ else:
134
+ result = TrajectoryFile._read_chunk_wise(
135
+ f, n_frames, step, atom_i, chunk_size, discard=False
136
+ )
137
+
138
+ # nm to Angstrom
139
+ coord, box, time = cls.process_read_values(result)
140
+ file.set_coord(coord)
141
+ file.set_box(box)
142
+ file.set_time(time)
143
+
144
+ return file
145
+
146
+ @classmethod
147
+ def read_iter(
148
+ cls, file_name, start=None, stop=None, step=None, atom_i=None, stack_size=None
149
+ ):
150
+ """
151
+ Create an iterator over each frame of the given trajectory file
152
+ in the selected range.
153
+
154
+ Parameters
155
+ ----------
156
+ file_name : str or Path
157
+ The path of the file to be read.
158
+ Any other file-like object cannot be used.
159
+ start : int, optional
160
+ The frame index, where file parsing is started. If no value
161
+ is given, parsing starts at the first frame.
162
+ The index starts at 0.
163
+ stop : int, optional
164
+ The exclusive frame index, where file parsing ends.
165
+ If no value is given, parsing stops at the end of file.
166
+ The index starts at 0.
167
+ step : int, optional
168
+ If this value is set, the function reads only every n-th
169
+ frame from the file.
170
+ atom_i : ndarray, dtype=int, optional
171
+ If this parameter is set, only the atoms at the given
172
+ indices are read from each frame.
173
+ stack_size : int, optional
174
+ If this parameter is set, the given number of frames *m* are
175
+ read at once.
176
+ As result an additional dimension is added to the return
177
+ values.
178
+ If the number of frames is not a multiple of `stack_size`,
179
+ the final stack is smaller than `stack_size`.
180
+
181
+ Yields
182
+ ------
183
+ coord : ndarray, dtype=float32, shape=(n,3) or shape=(m,n,3)
184
+ The atom coordinates in the current frame or stack.
185
+ box : ndarray, dtype=float32, shape=(3,3) or shape=(m,3,3) or None
186
+ The box vectors of the current frame or stack.
187
+ time : float or ndarray, dtype=float32, shape=(n,) or None
188
+ The simulation time of the current frame or stack in *ps*.
189
+
190
+ See also
191
+ --------
192
+ read_iter_structure
193
+
194
+ Notes
195
+ -----
196
+ The `step` parameter does currently not work for *DCD* files.
197
+ """
198
+ traj_type = cls.traj_type()
199
+ with traj_type(str(file_name), "r") as f:
200
+ if start is None:
201
+ start = 0
202
+ # Discard atoms before start
203
+ if start != 0:
204
+ f.read(n_frames=start, stride=None, atom_indices=atom_i)
205
+
206
+ # The upcoming frames are read
207
+ # Calculate the amount of frames to be read
208
+ if stop is None:
209
+ n_frames = None
210
+ else:
211
+ n_frames = stop - start
212
+ if step is not None and n_frames is not None:
213
+ # Divide number of frames by 'step' in order to convert
214
+ # 'step' into 'stride'
215
+ # Since the 0th frame is always included,
216
+ # the number of frames is decremented before division
217
+ # and incremented afterwards again
218
+ n_frames = ((n_frames - 1) // step) + 1
219
+
220
+ # Read frames
221
+ if stack_size is None:
222
+ remaining_frames = n_frames
223
+ while remaining_frames is None or remaining_frames > 0:
224
+ result = f.read(1, stride=step, atom_indices=atom_i)
225
+ if len(result[0]) == 0:
226
+ # Empty array was read
227
+ # -> no frames left -> stop iteration
228
+ break
229
+ coord, box, time = cls.process_read_values(result)
230
+ # Only one frame
231
+ # -> only one element in first dimension
232
+ # -> remove first dimension
233
+ coord = coord[0]
234
+ box = box[0] if box is not None else None
235
+ time = float(time[0]) if time is not None else None
236
+ yield coord, box, time
237
+ if remaining_frames is not None:
238
+ remaining_frames -= 1
239
+
240
+ else:
241
+ remaining_frames = n_frames
242
+ while remaining_frames is None or remaining_frames > 0:
243
+ n_frames = (
244
+ min(remaining_frames, stack_size)
245
+ if remaining_frames is not None
246
+ else stack_size
247
+ )
248
+ result = f.read(n_frames, stride=step, atom_indices=atom_i)
249
+ if len(result[0]) == 0:
250
+ # Empty array was read
251
+ # -> no frames left -> stop iteration
252
+ break
253
+ coord, box, time = cls.process_read_values(result)
254
+ yield coord, box, time
255
+ if remaining_frames is not None:
256
+ remaining_frames -= stack_size
257
+
258
+ @classmethod
259
+ def read_iter_structure(
260
+ cls,
261
+ file_name,
262
+ template,
263
+ start=None,
264
+ stop=None,
265
+ step=None,
266
+ atom_i=None,
267
+ stack_size=None,
268
+ ):
269
+ """
270
+ Create an iterator over each frame of the given trajectory file
271
+ in the selected range.
272
+
273
+ In contrast to :func:`read_iter()`, this function creates an
274
+ iterator over the structure as :class:`AtomArray`.
275
+ Since trajectory files usually only contain atom coordinate
276
+ information and no topology information, this method requires
277
+ a template atom array or stack. This template can be acquired
278
+ for example from a PDB file, which is associated with the
279
+ trajectory file.
280
+
281
+ Parameters
282
+ ----------
283
+ file_name : str or Path
284
+ The path of the file to be read.
285
+ Any other file-like object cannot be used.
286
+ template : AtomArray or AtomArrayStack
287
+ The template array or stack, where the atom annotation data
288
+ is taken from.
289
+ start : int, optional
290
+ The frame index, where file parsing is started. If no value
291
+ is given, parsing starts at the first frame.
292
+ The index starts at 0.
293
+ stop : int, optional
294
+ The exclusive frame index, where file parsing ends.
295
+ If no value is given, parsing stops at the end of file.
296
+ The index starts at 0.
297
+ step : int, optional
298
+ If this value is set, the function reads only every n-th
299
+ frame from the file.
300
+ atom_i : ndarray, dtype=int, optional
301
+ If this parameter is set, only the atoms at the given
302
+ indices are read from each frame in the file.
303
+ stack_size : int, optional
304
+ If this parameter is set, multiple frames are combined into
305
+ an :class:`AtomArrayStack`.
306
+ The number of frames in the :class:`AtomArrayStack` is
307
+ determined by this parameter.
308
+ If the number of frames is not a multiple of `stack_size`,
309
+ the final stack is smaller than `stack_size`.
310
+
311
+ Yields
312
+ ------
313
+ structure : AtomArray or AtomArrayStack
314
+ The structure of the current frame as :class:`AtomArray`.
315
+ If `stack_size` is set, multiple frames are returned as
316
+ :class:`AtomArrayStack`.
317
+
318
+ See also
319
+ --------
320
+ read_iter
321
+
322
+ Notes
323
+ -----
324
+ This iterator creates a new copy of the given template for every
325
+ frame
326
+ (or stack of frames, if `stack_size` is set).
327
+ If a higher efficiency is required, please use the
328
+ :func:`read_iter()` function.
329
+
330
+ The `step` parameter does currently not work for *DCD* files.
331
+ """
332
+ if isinstance(template, AtomArrayStack):
333
+ template = template[0]
334
+ elif not isinstance(template, AtomArray):
335
+ raise TypeError(
336
+ f"An 'AtomArray' or 'AtomArrayStack' is expected as template, "
337
+ f"not '{type(template).__name__}'"
338
+ )
339
+
340
+ for coord, box, _ in cls.read_iter(
341
+ file_name, start, stop, step, atom_i, stack_size
342
+ ):
343
+ if stack_size is None:
344
+ frame = template.copy()
345
+ frame.coord = coord
346
+ frame.box = box
347
+ yield frame
348
+ else:
349
+ yield from_template(template, coord, box)
350
+
351
+ def write(self, file_name):
352
+ """
353
+ Write the content into a trajectory file.
354
+
355
+ Parameters
356
+ ----------
357
+ file_name : str or Path
358
+ The path of the file to be read.
359
+ Any other file-like object cannot be used.
360
+ """
361
+ traj_type = self.traj_type()
362
+ param = self.prepare_write_values(self._coord, self._box, self._time)
363
+ with traj_type(str(file_name), "w") as f:
364
+ f.write(**param)
365
+
366
+ @classmethod
367
+ def write_iter(cls, file_name, coord, box=None, time=None):
368
+ """
369
+ Iterate over the given `coord` and write each item into
370
+ the file specified by `file_name`.
371
+
372
+ In contrast to :meth:`write()`, the data is not stored in an
373
+ intermediate :class:`TrajectoryFile`, but is directly written
374
+ to the file.
375
+ Hence, this class method may save a large amount of memory if
376
+ a large file should be written, if `coord` are provided as
377
+ generator.
378
+
379
+ Parameters
380
+ ----------
381
+ file_name : str or Path
382
+ The path of the file to be read.
383
+ Any other file-like object cannot be used.
384
+ coord : generator or array-like of ndarray, shape=(n,3), dtype=float
385
+ The atom coordinates for each frame.
386
+ box : generator or array-like of ndarray, shape=(3,3), dtype=float, optional
387
+ The three box vectors for each frame.
388
+ time : generator or array-like of float, optional
389
+ The simulation time in *ps* for each frame.
390
+
391
+ Notes
392
+ -----
393
+ The `time` parameter has no effect for *DCD* files.
394
+ """
395
+ if box is None:
396
+ box = itertools.repeat(None)
397
+ if time is None:
398
+ time = itertools.repeat(None)
399
+
400
+ traj_type = cls.traj_type()
401
+ with traj_type(str(file_name), "w") as f:
402
+ for c, b, t in zip(coord, box, time):
403
+ if c.ndim != 2:
404
+ raise IndexError(
405
+ f"Expected ndarray with 2 dimensions, got {c.ndim}"
406
+ )
407
+ # Add new dimension of length one
408
+ # for compatibility with 'prepare_write_values()'
409
+ c = c[np.newaxis, :]
410
+ if b is not None:
411
+ b = np.expand_dims(b, axis=0)
412
+ if t is not None:
413
+ t = np.expand_dims(t, axis=0)
414
+ param = cls.prepare_write_values(c, b, t)
415
+ f.write(**param)
416
+
417
+ def get_coord(self):
418
+ """
419
+ Extract only the atom coordinates from the trajectory file.
420
+
421
+ Returns
422
+ -------
423
+ coord : ndarray, dtype=float, shape=(m,n,3)
424
+ The coordinates stored in the trajectory file.
425
+ """
426
+ return self._coord
427
+
428
+ def get_time(self):
429
+ """
430
+ Get the simlation time in *ps* values for each frame.
431
+
432
+ Returns
433
+ -------
434
+ time : ndarray, dtype=float, shape=(m,)
435
+ A one dimensional array containing the time values for the
436
+ frames, that were read from the file.
437
+ """
438
+ return self._time
439
+
440
+ def get_box(self):
441
+ """
442
+ Get the box vectors for each frame.
443
+
444
+ Returns
445
+ -------
446
+ box : ndarray, dtype=float, shape=(m,3,3)
447
+ An array containing the box dimensions for the
448
+ frames, that were read from the file.
449
+ """
450
+ return self._box
451
+
452
+ def set_coord(self, coord):
453
+ """
454
+ Set the atom coordinates in the trajectory file.
455
+
456
+ Parameters
457
+ ----------
458
+ coord : ndarray, dtype=float, shape=(m,n,3)
459
+ The coordinates to be set.
460
+ """
461
+ self._check_model_count(coord)
462
+ self._coord = coord
463
+
464
+ def set_time(self, time):
465
+ """
466
+ Set the simulation time of each frame in the trajectory file.
467
+
468
+ Parameters
469
+ ----------
470
+ time : ndarray, dtype=float, shape=(m,)
471
+ The simulation time in *ps* to be set.
472
+ """
473
+ self._check_model_count(time)
474
+ self._time = time
475
+
476
+ def set_box(self, box):
477
+ """
478
+ Set the periodic box vectors of each frame in the trajectory
479
+ file.
480
+
481
+ Parameters
482
+ ----------
483
+ time : ndarray, dtype=float, shape=(m,3,3)
484
+ The box vectors to be set.
485
+ """
486
+ self._check_model_count(box)
487
+ self._box = box
488
+
489
+ def get_structure(self, template):
490
+ """
491
+ Convert the trajectory file content into an
492
+ :class:`AtomArrayStack`.
493
+
494
+ Since trajectory files usually only contain atom coordinate
495
+ information and no topology information, this method requires
496
+ a template atom array or stack. This template can be acquired
497
+ for example from a PDB file, which is associated with the
498
+ trajectory file.
499
+
500
+ Parameters
501
+ ----------
502
+ template : AtomArray or AtomArrayStack
503
+ The template array or stack, where the atom annotation data
504
+ is taken from.
505
+
506
+ Returns
507
+ -------
508
+ array_stack : AtomArrayStack
509
+ A stack containing the annontation arrays from `template`
510
+ but the coordinates and the simulation boxes from the
511
+ trajectory file.
512
+ """
513
+ return from_template(template, self.get_coord(), self.get_box())
514
+
515
+ def set_structure(self, structure, time=None):
516
+ """
517
+ Write an atom array (stack) into the trajectory file object.
518
+
519
+ The topology information (chain, residue, etc.) is not saved in
520
+ the file.
521
+
522
+ Parameters
523
+ ----------
524
+ structure : AtomArray or AtomArrayStack
525
+ The structure to be put into the trajectory file.
526
+ time : ndarray, dtype=float, shape=(n,), optional
527
+ The simulation time for each frame in `structure`.
528
+ """
529
+ coord = structure.coord
530
+ box = structure.box
531
+ if coord.ndim == 2:
532
+ coord = coord[np.newaxis, :, :]
533
+ if box is not None and box.ndim == 2:
534
+ box = box[np.newaxis, :, :]
535
+ self.set_coord(coord)
536
+ if box is not None:
537
+ self.set_box(box)
538
+ if time is not None:
539
+ self.set_time(time)
540
+
541
+ def copy(self):
542
+ """
543
+ This operation is not implemented for trajectory files.
544
+
545
+ Raises
546
+ ------
547
+ NotImplementedError
548
+ """
549
+ raise NotImplementedError("Copying is not implemented " "for trajectory files")
550
+
551
+ @classmethod
552
+ @abc.abstractmethod
553
+ def traj_type(cls):
554
+ """
555
+ The ``biotraj`` files class to be used.
556
+
557
+ PROTECTED: Override when inheriting.
558
+
559
+ Returns
560
+ -------
561
+ class
562
+ An ``biotraj`` subclass of :class:`TrajectoryFile`.
563
+ """
564
+ pass
565
+
566
+ @classmethod
567
+ @abc.abstractmethod
568
+ def process_read_values(cls, read_values):
569
+ """
570
+ Convert the return value of the `read()` method of the
571
+ respective :class:`biotraj.TrajectoryFile` into coordinates,
572
+ simulation box and simulation time.
573
+
574
+ PROTECTED: Override when inheriting.
575
+
576
+ Parameters
577
+ ----------
578
+ read_values : tuple
579
+ The return value of the respective
580
+ :func:`biotraj.TrajectoryFile.read()` method.
581
+
582
+ Returns
583
+ -------
584
+ coord : ndarray, dtype=float, shape=(m,n,3)
585
+ The atom coordinates in Å for each frame.
586
+ box : ndarray, dtype=float, shape=(m,3,3) or None
587
+ The box vectors in Å for each frame.
588
+ time : ndarray, dtype=float, shape=(m,) or None
589
+ The simulation time in ps for each frame.
590
+ """
591
+ pass
592
+
593
+ @classmethod
594
+ @abc.abstractmethod
595
+ def prepare_write_values(cls, coord, box, time):
596
+ """
597
+ Convert the `coord`, `box` and `time` attribute into a
598
+ dictionary that is given as *kwargs* to the respective
599
+ :func:`biotraj.TrajectoryFile.write()` method.
600
+
601
+ PROTECTED: Override when inheriting.
602
+
603
+ Parameters
604
+ ----------
605
+ coord : ndarray, dtype=float, shape=(m,n,3)
606
+ The atom coordinates in Å for each frame.
607
+ box : ndarray, dtype=float, shape=(m,3,3)
608
+ The box vectors in Å for each frame.
609
+ time : ndarray, dtype=float, shape=(m,)
610
+ The simulation time in ps for each frame.
611
+
612
+ Returns
613
+ -------
614
+ parameters : dict
615
+ This dictionary is given as *kwargs* parameter to the
616
+ respective :func:`biotraj.TrajectoryFile.write()` method.
617
+ """
618
+ pass
619
+
620
+ def _check_model_count(self, array):
621
+ """
622
+ Check if the amount of models in the given array is equal to
623
+ the amount of models in the file.
624
+ If not, raise an exception.
625
+ If the amount of models in the file is not set yet, set it with
626
+ the amount of models in the array.
627
+ """
628
+ if array is None:
629
+ return
630
+ if self._model_count is None:
631
+ self._model_count = len(array)
632
+ else:
633
+ if self._model_count != len(array):
634
+ raise ValueError(
635
+ f"{len(array)} models were given, "
636
+ f"but the file contains {self._model_count} models"
637
+ )
638
+
639
+ @staticmethod
640
+ def _read_chunk_wise(file, n_frames, step, atom_i, chunk_size, discard=False):
641
+ """
642
+ Similar to :func:`read()`, just for chunk-wise reading of the
643
+ trajectory.
644
+
645
+ `n_frames` is already the actual number of frames in the output
646
+ arrays, i.e. the original number was divided by `step`.
647
+ """
648
+ chunks = []
649
+ remaining_frames = n_frames
650
+ # If n_frames is None, this is condition is never False
651
+ # -> break out of loop when read chunk is empty (see below)
652
+ while remaining_frames != 0:
653
+ if remaining_frames is not None:
654
+ n = min(remaining_frames, chunk_size)
655
+ else:
656
+ n = chunk_size
657
+ try:
658
+ chunk = file.read(n_frames=n, stride=step, atom_indices=atom_i)
659
+ except ValueError as e:
660
+ # biotraj raises exception because no coordinates can be
661
+ # concatenated
662
+ # -> all frames have been read
663
+ # -> stop reading chunks
664
+ if str(e) != "need at least one array to concatenate":
665
+ raise
666
+ else:
667
+ break
668
+ if len(chunk[0]) == 0:
669
+ # Coordinates have a length of 0
670
+ # -> all frames have been read
671
+ # -> stop reading chunks
672
+ break
673
+ if not discard:
674
+ chunks.append(chunk)
675
+ if remaining_frames is not None:
676
+ remaining_frames -= n
677
+
678
+ if not discard:
679
+ # Assemble the chunks into contiguous arrays
680
+ # for each value (coord, box, time)
681
+ result = [None] * len(chunks[0])
682
+ # Iterate over all values in the result tuple
683
+ # and concatenate the corresponding value from each chunk,
684
+ # if the value is not None
685
+ # The amount of values is determined from the first chunk
686
+ for i in range(len(chunks[0])):
687
+ if chunks[0][i] is not None:
688
+ result[i] = np.concatenate([chunk[i] for chunk in chunks])
689
+ else:
690
+ result[i] = None
691
+ return tuple(result)
692
+ else:
693
+ return None
@@ -0,0 +1,13 @@
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 trajectories in the
7
+ uncompressed *Gromacs* TRR format.
8
+ """
9
+
10
+ __name__ = "biotite.structure.io.trr"
11
+ __author__ = "Patrick Kunzmann"
12
+
13
+ from .file import *