biotite 1.1.0__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of biotite might be problematic. Click here for more details.

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.cp313-win_amd64.pyd +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.cp313-win_amd64.pyd +0 -0
  61. biotite/sequence/align/kmeralphabet.pyx +595 -0
  62. biotite/sequence/align/kmersimilarity.cp313-win_amd64.pyd +0 -0
  63. biotite/sequence/align/kmersimilarity.pyx +233 -0
  64. biotite/sequence/align/kmertable.cp313-win_amd64.pyd +0 -0
  65. biotite/sequence/align/kmertable.pyx +3411 -0
  66. biotite/sequence/align/localgapped.cp313-win_amd64.pyd +0 -0
  67. biotite/sequence/align/localgapped.pyx +892 -0
  68. biotite/sequence/align/localungapped.cp313-win_amd64.pyd +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.cp313-win_amd64.pyd +0 -0
  164. biotite/sequence/align/multiple.pyx +620 -0
  165. biotite/sequence/align/pairwise.cp313-win_amd64.pyd +0 -0
  166. biotite/sequence/align/pairwise.pyx +587 -0
  167. biotite/sequence/align/permutation.cp313-win_amd64.pyd +0 -0
  168. biotite/sequence/align/permutation.pyx +313 -0
  169. biotite/sequence/align/primes.txt +821 -0
  170. biotite/sequence/align/selector.cp313-win_amd64.pyd +0 -0
  171. biotite/sequence/align/selector.pyx +954 -0
  172. biotite/sequence/align/statistics.py +264 -0
  173. biotite/sequence/align/tracetable.cp313-win_amd64.pyd +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.cp313-win_amd64.pyd +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.cp313-win_amd64.pyd +0 -0
  227. biotite/sequence/phylo/nj.pyx +221 -0
  228. biotite/sequence/phylo/tree.cp313-win_amd64.pyd +0 -0
  229. biotite/sequence/phylo/tree.pyx +1169 -0
  230. biotite/sequence/phylo/upgma.cp313-win_amd64.pyd +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.cp313-win_amd64.pyd +0 -0
  249. biotite/structure/bonds.pyx +1972 -0
  250. biotite/structure/box.py +588 -0
  251. biotite/structure/celllist.cp313-win_amd64.pyd +0 -0
  252. biotite/structure/celllist.pyx +849 -0
  253. biotite/structure/chains.py +314 -0
  254. biotite/structure/charges.cp313-win_amd64.pyd +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.cp313-win_amd64.pyd +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.cp313-win_amd64.pyd +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.cp313-win_amd64.pyd +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,16 @@
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.database"
6
+ __author__ = "Patrick Kunzmann"
7
+ __all__ = ["RequestError"]
8
+
9
+
10
+ class RequestError(Exception):
11
+ """
12
+ Indicates that the database returned a response with an error
13
+ message or other malformed content.
14
+ """
15
+
16
+ pass
@@ -0,0 +1,21 @@
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
+ A subpackage for searching and downloading files from the *PubChem*
7
+ database.
8
+ Although *PubChem* is part of *NCBI Entrez*,
9
+ :mod:`biotite.database.entrez` is only capable of accessing
10
+ meta-information from *PubChem*.
11
+ This subpackage, on the other hand, supports searching *PubChem*
12
+ compounds based on chemical information and is able to download
13
+ structure records.
14
+ """
15
+
16
+ __name__ = "biotite.database.pubchem"
17
+ __author__ = "Patrick Kunzmann"
18
+
19
+ from .download import *
20
+ from .query import *
21
+ from .throttle import *
@@ -0,0 +1,258 @@
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.database.pubchem"
6
+ __author__ = "Patrick Kunzmann"
7
+ __all__ = ["fetch", "fetch_property"]
8
+
9
+ import io
10
+ import numbers
11
+ import os
12
+ from os.path import getsize, isdir, isfile, join
13
+ import requests
14
+ from biotite.database.error import RequestError
15
+ from biotite.database.pubchem.error import parse_error_details
16
+ from biotite.database.pubchem.throttle import ThrottleStatus
17
+
18
+ _base_url = "https://pubchem.ncbi.nlm.nih.gov/rest/pug/"
19
+ _binary_formats = ["png", "asnb"]
20
+
21
+
22
+ def fetch(
23
+ cids,
24
+ format="sdf",
25
+ target_path=None,
26
+ as_structural_formula=False,
27
+ overwrite=False,
28
+ verbose=False,
29
+ throttle_threshold=0.5,
30
+ return_throttle_status=False,
31
+ ):
32
+ """
33
+ Download structure files from *PubChem* in various formats.
34
+
35
+ This function requires an internet connection.
36
+
37
+ Parameters
38
+ ----------
39
+ cids : int or iterable object or int
40
+ A single compound ID (CID) or a list of CIDs of the structure(s)
41
+ to be downloaded.
42
+ format : {'sdf', 'asnt' 'asnb', 'xml', 'json', 'jsonp', 'png'}
43
+ The format of the files to be downloaded.
44
+ as_structural_formula : bool, optional
45
+ If set to true, the structural formula is download instead of
46
+ an 3D conformer.
47
+ This means that coordinates lie in th xy-plane and represent
48
+ the positions atoms would have an a structural formula
49
+ representation.
50
+ target_path : str, optional
51
+ The target directory of the downloaded files.
52
+ By default, the file content is stored in a file-like object
53
+ (:class:`StringIO` or :class:`BytesIO`, respectively).
54
+ overwrite : bool, optional
55
+ If true, existing files will be overwritten.
56
+ Otherwise the respective file will only be downloaded, if the
57
+ file does not exist yet in the specified target directory or if
58
+ the file is empty.
59
+ verbose: bool, optional
60
+ If set to true, the function will output the download progress.
61
+ throttle_threshold : float or None, optional
62
+ A value between 0 and 1.
63
+ If the load of either the request time or count exceeds this
64
+ value the execution is halted.
65
+ See :class:`ThrottleStatus` for more information.
66
+ If ``None`` is given, the execution is never halted.
67
+ return_throttle_status : float, optional
68
+ If set to true, the :class:`ThrottleStatus` of the final request
69
+ is also returned.
70
+
71
+ Returns
72
+ -------
73
+ files : str or StringIO or BytesIO or list of (str or StringIO or BytesIO)
74
+ The file path(s) to the downloaded files.
75
+ If a single CID was given in `cids`,
76
+ a single string is returned. If a list (or other iterable
77
+ object) was given, a list of strings is returned.
78
+ If no `target_path` was given, the file contents are stored in
79
+ either :class:`StringIO` or :class:`BytesIO` objects.
80
+ throttle_status : ThrottleStatus
81
+ The :class:`ThrottleStatus` obtained from the server response.
82
+ If multiple CIDs are requested, the :class:`ThrottleStatus` of
83
+ of the final response is returned.
84
+ This can be used for custom request throttling, for example.
85
+ Only returned, if `return_throttle_status` is set to true.
86
+
87
+ Examples
88
+ --------
89
+
90
+ >>> import os.path
91
+ >>> file = fetch(2244, "sdf", path_to_directory)
92
+ >>> print(os.path.basename(file))
93
+ 2244.sdf
94
+ >>> files = fetch([2244, 5950], "sdf", path_to_directory)
95
+ >>> print([os.path.basename(file) for file in files])
96
+ ['2244.sdf', '5950.sdf']
97
+ """
98
+ # If only a single CID is present,
99
+ # put it into a single element list
100
+ if isinstance(cids, numbers.Integral):
101
+ cids = [cids]
102
+ single_element = True
103
+ else:
104
+ single_element = False
105
+ # Create the target folder, if not existing
106
+ if target_path is not None and not isdir(target_path):
107
+ os.makedirs(target_path)
108
+
109
+ files = []
110
+ for i, cid in enumerate(cids):
111
+ # Prevent IDs as strings, this could be a common error, as other
112
+ # database interfaces of Biotite use string IDs
113
+ if isinstance(cid, str):
114
+ raise TypeError("CIDs must be given as integers, not as string")
115
+ # Verbose output
116
+ if verbose:
117
+ print(f"Fetching file {i+1:d} / {len(cids):d} ({cid})...", end="\r")
118
+
119
+ # Fetch file from database
120
+ if target_path is not None:
121
+ file = join(target_path, str(cid) + "." + format)
122
+ else:
123
+ # 'file = None' -> store content in a file-like object
124
+ file = None
125
+
126
+ if file is None or not isfile(file) or getsize(file) == 0 or overwrite:
127
+ record_type = "2d" if as_structural_formula else "3d"
128
+ r = requests.get(
129
+ _base_url + f"compound/cid/{cid}/{format.upper()}",
130
+ params={"record_type": record_type},
131
+ )
132
+ if not r.ok:
133
+ raise RequestError(parse_error_details(r.text))
134
+
135
+ if format.lower() in _binary_formats:
136
+ content = r.content
137
+ else:
138
+ content = r.text
139
+
140
+ if file is None:
141
+ if format in _binary_formats:
142
+ file = io.BytesIO(content)
143
+ else:
144
+ file = io.StringIO(content)
145
+ else:
146
+ mode = "wb+" if format in _binary_formats else "w+"
147
+ with open(file, mode) as f:
148
+ f.write(content)
149
+
150
+ throttle_status = ThrottleStatus.from_response(r)
151
+ if throttle_threshold is not None:
152
+ throttle_status.wait_if_busy(throttle_threshold)
153
+
154
+ files.append(file)
155
+ if verbose:
156
+ print("\nDone")
157
+ # If input was a single ID, return only a single path
158
+ if single_element:
159
+ return_value = files[0]
160
+ else:
161
+ return_value = files
162
+ if return_throttle_status:
163
+ return return_value, throttle_status
164
+ else:
165
+ return return_value
166
+
167
+
168
+ def fetch_property(cids, name, throttle_threshold=0.5, return_throttle_status=False):
169
+ """
170
+ Download the given property for the given CID(s).
171
+
172
+ This function requires an internet connection.
173
+
174
+ Parameters
175
+ ----------
176
+ cids : int or iterable object or int
177
+ A single compound ID (CID) or a list of CIDs to get the property
178
+ for.
179
+ name : str
180
+ The name of the desired property.
181
+ Valid properties are given in the *PubChem* REST API
182
+ `documentation <https://pubchem.ncbi.nlm.nih.gov/docs/pug-rest#section=Compound-Property-Tables>`_.
183
+ throttle_threshold : float or None, optional
184
+ A value between 0 and 1.
185
+ If the load of either the request time or count exceeds this
186
+ value the execution is halted.
187
+ See :class:`ThrottleStatus` for more information.
188
+ If ``None`` is given, the execution is never halted.
189
+ return_throttle_status : float, optional
190
+ If set to true, the :class:`ThrottleStatus` of the final request
191
+ is also returned.
192
+
193
+ Returns
194
+ -------
195
+ property : str or list of str
196
+ The requested property for each given CID.
197
+ If a single CID was given in `cids`,
198
+ a single string is returned.
199
+ If a list (or other iterable
200
+ object) was given, a list of strings is returned.
201
+ throttle_status : ThrottleStatus
202
+ The :class:`ThrottleStatus` obtained from the server response.
203
+ This can be used for custom request throttling, for example.
204
+ Only returned, if `return_throttle_status` is set to true.
205
+
206
+ Examples
207
+ --------
208
+
209
+ >>> butane_cids = np.array(search(FormulaQuery("C4H10")))
210
+ >>> # Filter natural isotopes...
211
+ >>> n_iso = np.array(fetch_property(butane_cids, "IsotopeAtomCount"), dtype=int)
212
+ >>> # ...and neutral compounds
213
+ >>> charge = np.array(fetch_property(butane_cids, "Charge"), dtype=int)
214
+ >>> butane_cids = butane_cids[(n_iso == 0) & (charge == 0)]
215
+ >>> print(sorted(butane_cids.tolist()))
216
+ [6360, 7843, 18402699, 19029854, 19048342, 157632982, 158271732, 158934736, 161295599, 161897780]
217
+ >>> # Get the IUPAC names for each compound
218
+ >>> iupac_names = fetch_property(butane_cids, "IUPACName")
219
+ >>> # Compounds with multiple molecules use ';' as separator
220
+ >>> print(iupac_names)
221
+ ['butane', '2-methylpropane', 'methane;prop-1-ene', 'ethane;ethene', 'cyclopropane;methane', 'cyclobutane;molecular hydrogen', 'acetylene;methane', 'carbanide;propane', 'carbanylium;propane', 'methylcyclopropane;molecular hydrogen']
222
+ """
223
+ # If only a single CID is present,
224
+ # put it into a single element list
225
+ if isinstance(cids, numbers.Integral):
226
+ cids = [cids]
227
+ single_element = True
228
+ else:
229
+ single_element = False
230
+
231
+ # Property names may only contain letters and numbers
232
+ if not name.isalnum():
233
+ raise ValueError(f"Property '{name}' contains invalid characters")
234
+
235
+ # Use TXT format instead of CSV to avoid issues with ',' characters
236
+ # within table elements
237
+ r = requests.post(
238
+ _base_url + f"compound/cid/property/{name}/TXT",
239
+ data={"cid": ",".join([str(cid) for cid in cids])},
240
+ )
241
+ if not r.ok:
242
+ raise RequestError(parse_error_details(r.text))
243
+ throttle_status = ThrottleStatus.from_response(r)
244
+ if throttle_threshold is not None:
245
+ throttle_status.wait_if_busy(throttle_threshold)
246
+
247
+ # Each line contains the property for one CID
248
+ properties = r.text.splitlines()
249
+
250
+ # If input was a single ID, return only a single value
251
+ if single_element:
252
+ return_value = properties[0]
253
+ else:
254
+ return_value = properties
255
+ if return_throttle_status:
256
+ return return_value, throttle_status
257
+ else:
258
+ return return_value
@@ -0,0 +1,20 @@
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.database.pubchem"
6
+ __author__ = "Patrick Kunzmann"
7
+ __all__ = ["parse_error_details"]
8
+
9
+
10
+ def parse_error_details(response_text):
11
+ """
12
+ Parse the ``Detail: ...`` or alternatively ``Message: ...`` part of
13
+ an error response.
14
+ """
15
+ for message_line_indicator in ["Detail: ", "Message: "]:
16
+ for line in response_text.splitlines():
17
+ if line.startswith(message_line_indicator):
18
+ return line[len(message_line_indicator) :]
19
+ # No 'Detail: ...' or 'Message: ' line found
20
+ return "Unknown error"