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