biotite 0.41.1__cp311-cp311-macosx_10_16_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of biotite might be problematic. Click here for more details.
- biotite/__init__.py +19 -0
- biotite/application/__init__.py +43 -0
- biotite/application/application.py +265 -0
- biotite/application/autodock/__init__.py +12 -0
- biotite/application/autodock/app.py +505 -0
- biotite/application/blast/__init__.py +14 -0
- biotite/application/blast/alignment.py +83 -0
- biotite/application/blast/webapp.py +421 -0
- biotite/application/clustalo/__init__.py +12 -0
- biotite/application/clustalo/app.py +238 -0
- biotite/application/dssp/__init__.py +12 -0
- biotite/application/dssp/app.py +152 -0
- biotite/application/localapp.py +306 -0
- biotite/application/mafft/__init__.py +12 -0
- biotite/application/mafft/app.py +122 -0
- biotite/application/msaapp.py +374 -0
- biotite/application/muscle/__init__.py +13 -0
- biotite/application/muscle/app3.py +254 -0
- biotite/application/muscle/app5.py +171 -0
- biotite/application/sra/__init__.py +18 -0
- biotite/application/sra/app.py +456 -0
- biotite/application/tantan/__init__.py +12 -0
- biotite/application/tantan/app.py +222 -0
- biotite/application/util.py +59 -0
- biotite/application/viennarna/__init__.py +18 -0
- biotite/application/viennarna/rnaalifold.py +304 -0
- biotite/application/viennarna/rnafold.py +269 -0
- biotite/application/viennarna/rnaplot.py +187 -0
- biotite/application/viennarna/util.py +72 -0
- biotite/application/webapp.py +77 -0
- biotite/copyable.py +71 -0
- biotite/database/__init__.py +23 -0
- biotite/database/entrez/__init__.py +15 -0
- biotite/database/entrez/check.py +61 -0
- biotite/database/entrez/dbnames.py +89 -0
- biotite/database/entrez/download.py +223 -0
- biotite/database/entrez/key.py +44 -0
- biotite/database/entrez/query.py +223 -0
- biotite/database/error.py +15 -0
- biotite/database/pubchem/__init__.py +21 -0
- biotite/database/pubchem/download.py +260 -0
- biotite/database/pubchem/error.py +20 -0
- biotite/database/pubchem/query.py +827 -0
- biotite/database/pubchem/throttle.py +99 -0
- biotite/database/rcsb/__init__.py +13 -0
- biotite/database/rcsb/download.py +167 -0
- biotite/database/rcsb/query.py +959 -0
- biotite/database/uniprot/__init__.py +13 -0
- biotite/database/uniprot/check.py +32 -0
- biotite/database/uniprot/download.py +134 -0
- biotite/database/uniprot/query.py +209 -0
- biotite/file.py +251 -0
- biotite/sequence/__init__.py +73 -0
- biotite/sequence/align/__init__.py +49 -0
- biotite/sequence/align/alignment.py +658 -0
- biotite/sequence/align/banded.cpython-311-darwin.so +0 -0
- biotite/sequence/align/banded.pyx +652 -0
- biotite/sequence/align/buckets.py +69 -0
- biotite/sequence/align/cigar.py +434 -0
- biotite/sequence/align/kmeralphabet.cpython-311-darwin.so +0 -0
- biotite/sequence/align/kmeralphabet.pyx +574 -0
- biotite/sequence/align/kmersimilarity.cpython-311-darwin.so +0 -0
- biotite/sequence/align/kmersimilarity.pyx +233 -0
- biotite/sequence/align/kmertable.cpython-311-darwin.so +0 -0
- biotite/sequence/align/kmertable.pyx +3400 -0
- biotite/sequence/align/localgapped.cpython-311-darwin.so +0 -0
- biotite/sequence/align/localgapped.pyx +892 -0
- biotite/sequence/align/localungapped.cpython-311-darwin.so +0 -0
- biotite/sequence/align/localungapped.pyx +279 -0
- biotite/sequence/align/matrix.py +405 -0
- biotite/sequence/align/matrix_data/BLOSUM100.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM30.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM35.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM40.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM45.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM50.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM50_13p.mat +25 -0
- biotite/sequence/align/matrix_data/BLOSUM50_14.3.mat +25 -0
- biotite/sequence/align/matrix_data/BLOSUM50_5.0.mat +25 -0
- biotite/sequence/align/matrix_data/BLOSUM55.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM60.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM62.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM62_13p.mat +25 -0
- biotite/sequence/align/matrix_data/BLOSUM62_14.3.mat +25 -0
- biotite/sequence/align/matrix_data/BLOSUM62_5.0.mat +25 -0
- biotite/sequence/align/matrix_data/BLOSUM65.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM70.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM75.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM80.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM85.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM90.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUMN.mat +31 -0
- biotite/sequence/align/matrix_data/CorBLOSUM49_5.0.mat +25 -0
- biotite/sequence/align/matrix_data/CorBLOSUM57_13p.mat +25 -0
- biotite/sequence/align/matrix_data/CorBLOSUM57_14.3.mat +25 -0
- biotite/sequence/align/matrix_data/CorBLOSUM61_5.0.mat +25 -0
- biotite/sequence/align/matrix_data/CorBLOSUM66_13p.mat +25 -0
- biotite/sequence/align/matrix_data/CorBLOSUM67_14.3.mat +25 -0
- biotite/sequence/align/matrix_data/DAYHOFF.mat +32 -0
- biotite/sequence/align/matrix_data/GONNET.mat +26 -0
- biotite/sequence/align/matrix_data/IDENTITY.mat +25 -0
- biotite/sequence/align/matrix_data/MATCH.mat +25 -0
- biotite/sequence/align/matrix_data/NUC.mat +25 -0
- biotite/sequence/align/matrix_data/PAM10.mat +34 -0
- biotite/sequence/align/matrix_data/PAM100.mat +34 -0
- biotite/sequence/align/matrix_data/PAM110.mat +34 -0
- biotite/sequence/align/matrix_data/PAM120.mat +34 -0
- biotite/sequence/align/matrix_data/PAM130.mat +34 -0
- biotite/sequence/align/matrix_data/PAM140.mat +34 -0
- biotite/sequence/align/matrix_data/PAM150.mat +34 -0
- biotite/sequence/align/matrix_data/PAM160.mat +34 -0
- biotite/sequence/align/matrix_data/PAM170.mat +34 -0
- biotite/sequence/align/matrix_data/PAM180.mat +34 -0
- biotite/sequence/align/matrix_data/PAM190.mat +34 -0
- biotite/sequence/align/matrix_data/PAM20.mat +34 -0
- biotite/sequence/align/matrix_data/PAM200.mat +34 -0
- biotite/sequence/align/matrix_data/PAM210.mat +34 -0
- biotite/sequence/align/matrix_data/PAM220.mat +34 -0
- biotite/sequence/align/matrix_data/PAM230.mat +34 -0
- biotite/sequence/align/matrix_data/PAM240.mat +34 -0
- biotite/sequence/align/matrix_data/PAM250.mat +34 -0
- biotite/sequence/align/matrix_data/PAM260.mat +34 -0
- biotite/sequence/align/matrix_data/PAM270.mat +34 -0
- biotite/sequence/align/matrix_data/PAM280.mat +34 -0
- biotite/sequence/align/matrix_data/PAM290.mat +34 -0
- biotite/sequence/align/matrix_data/PAM30.mat +34 -0
- biotite/sequence/align/matrix_data/PAM300.mat +34 -0
- biotite/sequence/align/matrix_data/PAM310.mat +34 -0
- biotite/sequence/align/matrix_data/PAM320.mat +34 -0
- biotite/sequence/align/matrix_data/PAM330.mat +34 -0
- biotite/sequence/align/matrix_data/PAM340.mat +34 -0
- biotite/sequence/align/matrix_data/PAM350.mat +34 -0
- biotite/sequence/align/matrix_data/PAM360.mat +34 -0
- biotite/sequence/align/matrix_data/PAM370.mat +34 -0
- biotite/sequence/align/matrix_data/PAM380.mat +34 -0
- biotite/sequence/align/matrix_data/PAM390.mat +34 -0
- biotite/sequence/align/matrix_data/PAM40.mat +34 -0
- biotite/sequence/align/matrix_data/PAM400.mat +34 -0
- biotite/sequence/align/matrix_data/PAM410.mat +34 -0
- biotite/sequence/align/matrix_data/PAM420.mat +34 -0
- biotite/sequence/align/matrix_data/PAM430.mat +34 -0
- biotite/sequence/align/matrix_data/PAM440.mat +34 -0
- biotite/sequence/align/matrix_data/PAM450.mat +34 -0
- biotite/sequence/align/matrix_data/PAM460.mat +34 -0
- biotite/sequence/align/matrix_data/PAM470.mat +34 -0
- biotite/sequence/align/matrix_data/PAM480.mat +34 -0
- biotite/sequence/align/matrix_data/PAM490.mat +34 -0
- biotite/sequence/align/matrix_data/PAM50.mat +34 -0
- biotite/sequence/align/matrix_data/PAM500.mat +34 -0
- biotite/sequence/align/matrix_data/PAM60.mat +34 -0
- biotite/sequence/align/matrix_data/PAM70.mat +34 -0
- biotite/sequence/align/matrix_data/PAM80.mat +34 -0
- biotite/sequence/align/matrix_data/PAM90.mat +34 -0
- biotite/sequence/align/matrix_data/RBLOSUM52_5.0.mat +25 -0
- biotite/sequence/align/matrix_data/RBLOSUM59_13p.mat +25 -0
- biotite/sequence/align/matrix_data/RBLOSUM59_14.3.mat +25 -0
- biotite/sequence/align/matrix_data/RBLOSUM64_5.0.mat +25 -0
- biotite/sequence/align/matrix_data/RBLOSUM69_13p.mat +25 -0
- biotite/sequence/align/matrix_data/RBLOSUM69_14.3.mat +25 -0
- biotite/sequence/align/multiple.cpython-311-darwin.so +0 -0
- biotite/sequence/align/multiple.pyx +620 -0
- biotite/sequence/align/pairwise.cpython-311-darwin.so +0 -0
- biotite/sequence/align/pairwise.pyx +587 -0
- biotite/sequence/align/permutation.cpython-311-darwin.so +0 -0
- biotite/sequence/align/permutation.pyx +305 -0
- biotite/sequence/align/primes.txt +821 -0
- biotite/sequence/align/selector.cpython-311-darwin.so +0 -0
- biotite/sequence/align/selector.pyx +956 -0
- biotite/sequence/align/statistics.py +265 -0
- biotite/sequence/align/tracetable.cpython-311-darwin.so +0 -0
- biotite/sequence/align/tracetable.pxd +64 -0
- biotite/sequence/align/tracetable.pyx +370 -0
- biotite/sequence/alphabet.py +566 -0
- biotite/sequence/annotation.py +829 -0
- biotite/sequence/codec.cpython-311-darwin.so +0 -0
- biotite/sequence/codec.pyx +155 -0
- biotite/sequence/codon.py +466 -0
- biotite/sequence/codon_tables.txt +202 -0
- biotite/sequence/graphics/__init__.py +33 -0
- biotite/sequence/graphics/alignment.py +1034 -0
- biotite/sequence/graphics/color_schemes/autumn.json +51 -0
- biotite/sequence/graphics/color_schemes/blossom.json +51 -0
- biotite/sequence/graphics/color_schemes/clustalx_dna.json +11 -0
- biotite/sequence/graphics/color_schemes/clustalx_protein.json +28 -0
- biotite/sequence/graphics/color_schemes/flower.json +51 -0
- biotite/sequence/graphics/color_schemes/jalview_buried.json +31 -0
- biotite/sequence/graphics/color_schemes/jalview_hydrophobicity.json +31 -0
- biotite/sequence/graphics/color_schemes/jalview_prop_helix.json +31 -0
- biotite/sequence/graphics/color_schemes/jalview_prop_strand.json +31 -0
- biotite/sequence/graphics/color_schemes/jalview_prop_turn.json +31 -0
- biotite/sequence/graphics/color_schemes/jalview_taylor.json +28 -0
- biotite/sequence/graphics/color_schemes/jalview_zappo.json +28 -0
- biotite/sequence/graphics/color_schemes/ocean.json +51 -0
- biotite/sequence/graphics/color_schemes/pb_flower.json +39 -0
- biotite/sequence/graphics/color_schemes/rainbow_dna.json +11 -0
- biotite/sequence/graphics/color_schemes/rainbow_protein.json +30 -0
- biotite/sequence/graphics/color_schemes/spring.json +51 -0
- biotite/sequence/graphics/color_schemes/sunset.json +51 -0
- biotite/sequence/graphics/color_schemes/wither.json +51 -0
- biotite/sequence/graphics/colorschemes.py +139 -0
- biotite/sequence/graphics/dendrogram.py +184 -0
- biotite/sequence/graphics/features.py +510 -0
- biotite/sequence/graphics/logo.py +110 -0
- biotite/sequence/graphics/plasmid.py +661 -0
- biotite/sequence/io/__init__.py +12 -0
- biotite/sequence/io/fasta/__init__.py +22 -0
- biotite/sequence/io/fasta/convert.py +273 -0
- biotite/sequence/io/fasta/file.py +278 -0
- biotite/sequence/io/fastq/__init__.py +19 -0
- biotite/sequence/io/fastq/convert.py +120 -0
- biotite/sequence/io/fastq/file.py +551 -0
- biotite/sequence/io/genbank/__init__.py +17 -0
- biotite/sequence/io/genbank/annotation.py +277 -0
- biotite/sequence/io/genbank/file.py +575 -0
- biotite/sequence/io/genbank/metadata.py +324 -0
- biotite/sequence/io/genbank/sequence.py +172 -0
- biotite/sequence/io/general.py +192 -0
- biotite/sequence/io/gff/__init__.py +26 -0
- biotite/sequence/io/gff/convert.py +133 -0
- biotite/sequence/io/gff/file.py +434 -0
- biotite/sequence/phylo/__init__.py +36 -0
- biotite/sequence/phylo/nj.cpython-311-darwin.so +0 -0
- biotite/sequence/phylo/nj.pyx +221 -0
- biotite/sequence/phylo/tree.cpython-311-darwin.so +0 -0
- biotite/sequence/phylo/tree.pyx +1169 -0
- biotite/sequence/phylo/upgma.cpython-311-darwin.so +0 -0
- biotite/sequence/phylo/upgma.pyx +164 -0
- biotite/sequence/profile.py +456 -0
- biotite/sequence/search.py +116 -0
- biotite/sequence/seqtypes.py +556 -0
- biotite/sequence/sequence.py +374 -0
- biotite/structure/__init__.py +132 -0
- biotite/structure/atoms.py +1455 -0
- biotite/structure/basepairs.py +1415 -0
- biotite/structure/bonds.cpython-311-darwin.so +0 -0
- biotite/structure/bonds.pyx +1933 -0
- biotite/structure/box.py +592 -0
- biotite/structure/celllist.cpython-311-darwin.so +0 -0
- biotite/structure/celllist.pyx +849 -0
- biotite/structure/chains.py +298 -0
- biotite/structure/charges.cpython-311-darwin.so +0 -0
- biotite/structure/charges.pyx +520 -0
- biotite/structure/compare.py +274 -0
- biotite/structure/density.py +114 -0
- biotite/structure/dotbracket.py +216 -0
- biotite/structure/error.py +31 -0
- biotite/structure/filter.py +585 -0
- biotite/structure/geometry.py +697 -0
- biotite/structure/graphics/__init__.py +13 -0
- biotite/structure/graphics/atoms.py +226 -0
- biotite/structure/graphics/rna.py +282 -0
- biotite/structure/hbond.py +409 -0
- biotite/structure/info/__init__.py +25 -0
- biotite/structure/info/atom_masses.json +121 -0
- biotite/structure/info/atoms.py +82 -0
- biotite/structure/info/bonds.py +145 -0
- biotite/structure/info/ccd/README.rst +8 -0
- biotite/structure/info/ccd/amino_acids.txt +1663 -0
- biotite/structure/info/ccd/carbohydrates.txt +1135 -0
- biotite/structure/info/ccd/components.bcif +0 -0
- biotite/structure/info/ccd/nucleotides.txt +798 -0
- biotite/structure/info/ccd.py +95 -0
- biotite/structure/info/groups.py +90 -0
- biotite/structure/info/masses.py +123 -0
- biotite/structure/info/misc.py +144 -0
- biotite/structure/info/radii.py +197 -0
- biotite/structure/info/standardize.py +196 -0
- biotite/structure/integrity.py +268 -0
- biotite/structure/io/__init__.py +30 -0
- biotite/structure/io/ctab.py +72 -0
- biotite/structure/io/dcd/__init__.py +13 -0
- biotite/structure/io/dcd/file.py +65 -0
- biotite/structure/io/general.py +257 -0
- biotite/structure/io/gro/__init__.py +14 -0
- biotite/structure/io/gro/file.py +343 -0
- biotite/structure/io/mmtf/__init__.py +21 -0
- biotite/structure/io/mmtf/assembly.py +214 -0
- biotite/structure/io/mmtf/convertarray.cpython-311-darwin.so +0 -0
- biotite/structure/io/mmtf/convertarray.pyx +341 -0
- biotite/structure/io/mmtf/convertfile.cpython-311-darwin.so +0 -0
- biotite/structure/io/mmtf/convertfile.pyx +501 -0
- biotite/structure/io/mmtf/decode.cpython-311-darwin.so +0 -0
- biotite/structure/io/mmtf/decode.pyx +152 -0
- biotite/structure/io/mmtf/encode.cpython-311-darwin.so +0 -0
- biotite/structure/io/mmtf/encode.pyx +183 -0
- biotite/structure/io/mmtf/file.py +233 -0
- biotite/structure/io/mol/__init__.py +20 -0
- biotite/structure/io/mol/convert.py +115 -0
- biotite/structure/io/mol/ctab.py +414 -0
- biotite/structure/io/mol/header.py +116 -0
- biotite/structure/io/mol/mol.py +193 -0
- biotite/structure/io/mol/sdf.py +916 -0
- biotite/structure/io/netcdf/__init__.py +13 -0
- biotite/structure/io/netcdf/file.py +63 -0
- biotite/structure/io/npz/__init__.py +20 -0
- biotite/structure/io/npz/file.py +152 -0
- biotite/structure/io/pdb/__init__.py +20 -0
- biotite/structure/io/pdb/convert.py +293 -0
- biotite/structure/io/pdb/file.py +1240 -0
- biotite/structure/io/pdb/hybrid36.cpython-311-darwin.so +0 -0
- biotite/structure/io/pdb/hybrid36.pyx +242 -0
- biotite/structure/io/pdbqt/__init__.py +15 -0
- biotite/structure/io/pdbqt/convert.py +107 -0
- biotite/structure/io/pdbqt/file.py +640 -0
- biotite/structure/io/pdbx/__init__.py +23 -0
- biotite/structure/io/pdbx/bcif.py +648 -0
- biotite/structure/io/pdbx/cif.py +1032 -0
- biotite/structure/io/pdbx/component.py +246 -0
- biotite/structure/io/pdbx/convert.py +1597 -0
- biotite/structure/io/pdbx/encoding.cpython-311-darwin.so +0 -0
- biotite/structure/io/pdbx/encoding.pyx +950 -0
- biotite/structure/io/pdbx/legacy.py +267 -0
- biotite/structure/io/tng/__init__.py +13 -0
- biotite/structure/io/tng/file.py +46 -0
- biotite/structure/io/trajfile.py +710 -0
- biotite/structure/io/trr/__init__.py +13 -0
- biotite/structure/io/trr/file.py +46 -0
- biotite/structure/io/xtc/__init__.py +13 -0
- biotite/structure/io/xtc/file.py +46 -0
- biotite/structure/mechanics.py +75 -0
- biotite/structure/molecules.py +353 -0
- biotite/structure/pseudoknots.py +642 -0
- biotite/structure/rdf.py +243 -0
- biotite/structure/repair.py +253 -0
- biotite/structure/residues.py +562 -0
- biotite/structure/resutil.py +178 -0
- biotite/structure/sasa.cpython-311-darwin.so +0 -0
- biotite/structure/sasa.pyx +322 -0
- biotite/structure/sequence.py +112 -0
- biotite/structure/sse.py +327 -0
- biotite/structure/superimpose.py +727 -0
- biotite/structure/transform.py +504 -0
- biotite/structure/util.py +98 -0
- biotite/temp.py +86 -0
- biotite/version.py +16 -0
- biotite/visualize.py +251 -0
- biotite-0.41.1.dist-info/METADATA +187 -0
- biotite-0.41.1.dist-info/RECORD +340 -0
- biotite-0.41.1.dist-info/WHEEL +4 -0
- biotite-0.41.1.dist-info/licenses/LICENSE.rst +30 -0
|
@@ -0,0 +1,260 @@
|
|
|
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 numbers
|
|
10
|
+
import requests
|
|
11
|
+
from os.path import isdir, isfile, join, getsize
|
|
12
|
+
import os
|
|
13
|
+
import io
|
|
14
|
+
import numpy as np
|
|
15
|
+
from .throttle import ThrottleStatus
|
|
16
|
+
from .error import parse_error_details
|
|
17
|
+
from ..error import RequestError
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
_base_url = "https://pubchem.ncbi.nlm.nih.gov/rest/pug/"
|
|
21
|
+
_binary_formats = ["png", "asnb"]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def fetch(cids, format="sdf", target_path=None, as_structural_formula=False,
|
|
25
|
+
overwrite=False, verbose=False,
|
|
26
|
+
throttle_threshold=0.5, return_throttle_status=False):
|
|
27
|
+
"""
|
|
28
|
+
Download structure files from *PubChem* in various formats.
|
|
29
|
+
|
|
30
|
+
This function requires an internet connection.
|
|
31
|
+
|
|
32
|
+
Parameters
|
|
33
|
+
----------
|
|
34
|
+
cids : int or iterable object or int
|
|
35
|
+
A single compound ID (CID) or a list of CIDs of the structure(s)
|
|
36
|
+
to be downloaded.
|
|
37
|
+
format : {'sdf', 'asnt' 'asnb', 'xml', 'json', 'jsonp', 'png'}
|
|
38
|
+
The format of the files to be downloaded.
|
|
39
|
+
as_structural_formula : bool, optional
|
|
40
|
+
If set to true, the structural formula is download instead of
|
|
41
|
+
an 3D conformer.
|
|
42
|
+
This means that coordinates lie in th xy-plane and represent
|
|
43
|
+
the positions atoms would have an a structural formula
|
|
44
|
+
representation.
|
|
45
|
+
target_path : str, optional
|
|
46
|
+
The target directory of the downloaded files.
|
|
47
|
+
By default, the file content is stored in a file-like object
|
|
48
|
+
(:class:`StringIO` or :class:`BytesIO`, respectively).
|
|
49
|
+
overwrite : bool, optional
|
|
50
|
+
If true, existing files will be overwritten.
|
|
51
|
+
Otherwise the respective file will only be downloaded, if the
|
|
52
|
+
file does not exist yet in the specified target directory or if
|
|
53
|
+
the file is empty.
|
|
54
|
+
verbose: bool, optional
|
|
55
|
+
If set to true, the function will output the download progress.
|
|
56
|
+
throttle_threshold : float or None, optional
|
|
57
|
+
A value between 0 and 1.
|
|
58
|
+
If the load of either the request time or count exceeds this
|
|
59
|
+
value the execution is halted.
|
|
60
|
+
See :class:`ThrottleStatus` for more information.
|
|
61
|
+
If ``None`` is given, the execution is never halted.
|
|
62
|
+
return_throttle_status : float, optional
|
|
63
|
+
If set to true, the :class:`ThrottleStatus` of the final request
|
|
64
|
+
is also returned.
|
|
65
|
+
|
|
66
|
+
Returns
|
|
67
|
+
-------
|
|
68
|
+
files : str or StringIO or BytesIO or list of (str or StringIO or BytesIO)
|
|
69
|
+
The file path(s) to the downloaded files.
|
|
70
|
+
If a single CID was given in `cids`,
|
|
71
|
+
a single string is returned. If a list (or other iterable
|
|
72
|
+
object) was given, a list of strings is returned.
|
|
73
|
+
If no `target_path` was given, the file contents are stored in
|
|
74
|
+
either :class:`StringIO` or :class:`BytesIO` objects.
|
|
75
|
+
throttle_status : ThrottleStatus
|
|
76
|
+
The :class:`ThrottleStatus` obtained from the server response.
|
|
77
|
+
If multiple CIDs are requested, the :class:`ThrottleStatus` of
|
|
78
|
+
of the final response is returned.
|
|
79
|
+
This can be used for custom request throttling, for example.
|
|
80
|
+
Only returned, if `return_throttle_status` is set to true.
|
|
81
|
+
|
|
82
|
+
Examples
|
|
83
|
+
--------
|
|
84
|
+
|
|
85
|
+
>>> import os.path
|
|
86
|
+
>>> file = fetch(2244, "sdf", path_to_directory)
|
|
87
|
+
>>> print(os.path.basename(file))
|
|
88
|
+
2244.sdf
|
|
89
|
+
>>> files = fetch([2244, 5950], "sdf", path_to_directory)
|
|
90
|
+
>>> print([os.path.basename(file) for file in files])
|
|
91
|
+
['2244.sdf', '5950.sdf']
|
|
92
|
+
"""
|
|
93
|
+
# If only a single CID is present,
|
|
94
|
+
# put it into a single element list
|
|
95
|
+
if isinstance(cids, numbers.Integral):
|
|
96
|
+
cids = [cids]
|
|
97
|
+
single_element = True
|
|
98
|
+
else:
|
|
99
|
+
single_element = False
|
|
100
|
+
# Create the target folder, if not existing
|
|
101
|
+
if target_path is not None and not isdir(target_path):
|
|
102
|
+
os.makedirs(target_path)
|
|
103
|
+
|
|
104
|
+
files = []
|
|
105
|
+
for i, cid in enumerate(cids):
|
|
106
|
+
# Prevent IDs as strings, this could be a common error, as other
|
|
107
|
+
# database interfaces of Biotite use string IDs
|
|
108
|
+
if isinstance(cid, str):
|
|
109
|
+
raise TypeError("CIDs must be given as integers, not as string")
|
|
110
|
+
# Verbose output
|
|
111
|
+
if verbose:
|
|
112
|
+
print(f"Fetching file {i+1:d} / {len(cids):d} ({cid})...",
|
|
113
|
+
end="\r")
|
|
114
|
+
|
|
115
|
+
# Fetch file from database
|
|
116
|
+
if target_path is not None:
|
|
117
|
+
file = join(target_path, str(cid) + "." + format)
|
|
118
|
+
else:
|
|
119
|
+
# 'file = None' -> store content in a file-like object
|
|
120
|
+
file = None
|
|
121
|
+
|
|
122
|
+
if file is None \
|
|
123
|
+
or not isfile(file) \
|
|
124
|
+
or getsize(file) == 0 \
|
|
125
|
+
or overwrite:
|
|
126
|
+
record_type = "2d" if as_structural_formula else "3d"
|
|
127
|
+
r = requests.get(
|
|
128
|
+
_base_url + f"compound/cid/{cid}/{format.upper()}",
|
|
129
|
+
params={"record_type": record_type}
|
|
130
|
+
)
|
|
131
|
+
if not r.ok:
|
|
132
|
+
raise RequestError(parse_error_details(r.text))
|
|
133
|
+
|
|
134
|
+
if format.lower() in _binary_formats:
|
|
135
|
+
content = r.content
|
|
136
|
+
else:
|
|
137
|
+
content = r.text
|
|
138
|
+
|
|
139
|
+
if file is None:
|
|
140
|
+
if format in _binary_formats:
|
|
141
|
+
file = io.BytesIO(content)
|
|
142
|
+
else:
|
|
143
|
+
file = io.StringIO(content)
|
|
144
|
+
else:
|
|
145
|
+
mode = "wb+" if format in _binary_formats else "w+"
|
|
146
|
+
with open(file, mode) as f:
|
|
147
|
+
f.write(content)
|
|
148
|
+
|
|
149
|
+
throttle_status = ThrottleStatus.from_response(r)
|
|
150
|
+
if throttle_threshold is not None:
|
|
151
|
+
throttle_status.wait_if_busy(throttle_threshold)
|
|
152
|
+
|
|
153
|
+
files.append(file)
|
|
154
|
+
if verbose:
|
|
155
|
+
print("\nDone")
|
|
156
|
+
# If input was a single ID, return only a single path
|
|
157
|
+
if single_element:
|
|
158
|
+
return_value = files[0]
|
|
159
|
+
else:
|
|
160
|
+
return_value = files
|
|
161
|
+
if return_throttle_status:
|
|
162
|
+
return return_value, throttle_status
|
|
163
|
+
else:
|
|
164
|
+
return return_value
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def fetch_property(cids, name,
|
|
168
|
+
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(
|
|
234
|
+
f"Property '{name}' contains invalid characters"
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
# Use TXT format instead of CSV to avoid issues with ',' characters
|
|
238
|
+
# within table elements
|
|
239
|
+
r = requests.post(
|
|
240
|
+
_base_url + f"compound/cid/property/{name}/TXT",
|
|
241
|
+
data={"cid": ','.join([str(cid) for cid in cids])}
|
|
242
|
+
)
|
|
243
|
+
if not r.ok:
|
|
244
|
+
raise RequestError(parse_error_details(r.text))
|
|
245
|
+
throttle_status = ThrottleStatus.from_response(r)
|
|
246
|
+
if throttle_threshold is not None:
|
|
247
|
+
throttle_status.wait_if_busy(throttle_threshold)
|
|
248
|
+
|
|
249
|
+
# Each line contains the property for one CID
|
|
250
|
+
properties = r.text.splitlines()
|
|
251
|
+
|
|
252
|
+
# If input was a single ID, return only a single value
|
|
253
|
+
if single_element:
|
|
254
|
+
return_value = properties[0]
|
|
255
|
+
else:
|
|
256
|
+
return_value = properties
|
|
257
|
+
if return_throttle_status:
|
|
258
|
+
return return_value, throttle_status
|
|
259
|
+
else:
|
|
260
|
+
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"
|