/
query.py
827 lines (697 loc) · 25.8 KB
/
query.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
# This source code is part of the Biotite package and is distributed
# under the 3-Clause BSD License. Please see 'LICENSE.rst' for further
# information.
__name__ = "biotite.database.pubchem"
__author__ = "Patrick Kunzmann"
__all__ = ["Query", "NameQuery", "SmilesQuery", "InchiQuery", "InchiKeyQuery",
"FormulaQuery", "SuperstructureQuery", "SubstructureQuery",
"SimilarityQuery", "IdentityQuery",
"search"]
import copy
import abc
import collections
import requests
from .error import parse_error_details
from .throttle import ThrottleStatus
from ..error import RequestError
from ...structure.io.mol.file import MOLFile
_base_url = "https://pubchem.ncbi.nlm.nih.gov/rest/pug/"
class Query(metaclass=abc.ABCMeta):
"""
A search query for the *PubChem* REST API.
Unlike most other database interfaces in *Biotite*, multiple queries
cannot be combined using logical operators.
This is the abstract base class for all queries.
"""
@abc.abstractmethod
def get_input_url_path(self):
"""
Get the *input* part of the request URL.
Returns
-------
get_input_url_path : str
The *input* part of the request URL.
Must not contain slash characters at the beginning and end
of the string.
"""
pass
def get_params(self):
"""
Get the POST payload for this query.
Returns
-------
params : dict (str -> object)
The payload.
"""
return {}
def get_files(self):
"""
Get the POST file payload for this query.
Returns
-------
params : dict (str -> object)
The file payload.
"""
return {}
class NameQuery(Query):
"""
A query that searches for compounds with the given name.
The name of the compound must match the given name completely,
but synonyms of the compound name are also considered.
Parameters
----------
name : str
The compound name to be searched.
Examples
--------
>>> print(search(NameQuery("Alanine")))
[5950, ..., ..., ...]
"""
def __init__(self, name):
self._name = name
def get_input_url_path(self):
return "compound/name"
def get_params(self):
return {"name": self._name}
class SmilesQuery(Query):
"""
A query that searches for compounds with a given
*Simplified Molecular Input Line Entry Specification* (*SMILES*)
string.
Parameters
----------
smiles : str
The *SMILES* string.
Examples
--------
>>> print(search(SmilesQuery("CCCC")))
[7843]
"""
def __init__(self, smiles):
self._smiles = smiles
def get_input_url_path(self):
return "compound/smiles"
def get_params(self):
return {"smiles": self._smiles}
class InchiQuery(Query):
"""
A query that searches for compounds with a given
*International Chemical Identifier* (*InChI*) string.
Parameters
----------
inchi : str
The *InChI* string.
Examples
--------
>>> print(search(InchiQuery("InChI=1S/C4H10/c1-3-4-2/h3-4H2,1-2H3")))
[7843]
"""
def __init__(self, inchi):
self._inchi = inchi
def get_input_url_path(self):
return "compound/inchi"
def get_params(self):
return {"inchi": self._inchi}
class InchiKeyQuery(Query):
"""
A query that searches for compounds with a given
*International Chemical Identifier* (*InChI*) key.
Parameters
----------
inchi_key : str
The *InChI* key.
Examples
--------
>>> print(search(InchiKeyQuery("IJDNQMDRQITEOD-UHFFFAOYSA-N")))
[7843]
"""
def __init__(self, inchi_key):
self._inchi_key = inchi_key
def get_input_url_path(self):
return "compound/inchikey"
def get_params(self):
return {"inchikey": self._inchi_key}
class FormulaQuery(Query):
"""
A query that searches for compounds with the given molecular
formula.
The formula can also be created from an :class:`AtomArray` using
the :meth:`from_atoms()` method.
Parameters
----------
formula : str
The molecular formula, i.e. each capitalized element with its
count in the compound concatenated into a single string.
allow_other_elements : bool, optional
If set to true, compounds with additional elements, not present
in the molecular formula, will also match.
number : int, optional
The maximum number of matches that this query may return.
By default, the *PubChem* default value is used, which can be
considered unlimited.
Examples
--------
>>> print(search(FormulaQuery("C4H10", number=5)))
[7843, ..., ..., ..., ...]
>>> atom_array = residue("ALA")
>>> print(search(FormulaQuery.from_atoms(atom_array, number=5)))
[5950, ..., ..., ..., ...]
"""
def __init__(self, formula, allow_other_elements=False, number=None):
self._formula = formula
self._allow_other_elements = allow_other_elements
self._number = number
@staticmethod
def from_atoms(atoms, allow_other_elements=False, number=None):
"""
Create the query from an the given structure by using its
molecular formula.
Parameters
----------
atoms : AtomArray or AtomArrayStack
The structure to take the molecular formula from.
allow_other_elements : bool, optional
If set to true, compounds with additional elements, not
present in the molecular formula, will also match.
number : int, optional
The maximum number of matches that this query may return.
By default, the *PubChem* default value is used, which can
be considered unlimited.
"""
element_counter = collections.Counter(atoms.element)
formula = ""
# C and H come first in molecular formula
if "C" in element_counter:
formula += _format_element("C", element_counter["C"])
del element_counter["C"]
if "H" in element_counter:
formula += _format_element("H", element_counter["H"])
del element_counter["H"]
# All other elements follow in alphabetical order
sorted_elements = sorted(element_counter.keys())
for element in sorted_elements:
formula += _format_element(element, element_counter[element])
return FormulaQuery(formula, allow_other_elements, number)
def get_input_url_path(self):
# The 'fastformula' service seems not to accept the formula
# in the parameter section of the request
return f"compound/fastformula/{self._formula}"
def get_params(self):
params = {"AllowOtherElements": self._allow_other_elements}
# Only set maximum number, if provided by the user
# The PubChem default value for this might change over time
if self._number is not None:
params["MaxRecords"] = self._number
return params
def _format_element(element, count):
if count == 1:
return element.capitalize()
else:
return element.capitalize() + str(count)
class StructureQuery(Query, metaclass=abc.ABCMeta):
"""
Abstract superclass for all structure based searches.
This class handles structure inputs and option formatting.
Exactly one of the input structure parameters `smiles`, `smarts`,
`inchi`, `sdf` or `cid` must be given.
Parameters
----------
smiles : str, optional
The query *SMILES* string.
smarts : str, optional
The query *SMARTS* pattern.
inchi : str, optional
The query *InChI* string.
sdf : str, optional
A query structure as SDF formatted string.
Usually :meth:`from_atoms()` is used to create the SDF from an
:class:`AtomArray`.
cid : int, optional
The query structure given as CID.
number : int, optional
The maximum number of matches that this query may return.
By default, the *PubChem* default value is used, which can
be considered unlimited.
"""
_query_keys = ("smiles", "smarts", "inchi", "sdf", "cid")
def __init__(self, **kwargs):
query_key_found = False
for query_key in StructureQuery._query_keys:
if query_key in kwargs:
if not query_key_found:
self._query_key = query_key
self._query_val = kwargs[query_key]
# Delete parameter from kwargs for later check for
# unused (invalid) parameters
del kwargs[query_key]
query_key_found = True
else:
# A query key was already found,
# duplicates are not allowed
raise TypeError(
"Only one of 'smiles', 'smarts', 'inchi', 'sdf' or "
"'cid' may be given"
)
if not query_key_found:
raise TypeError(
"Expected exactly one of 'smiles', 'smarts', 'inchi', 'sdf' "
"or 'cid'")
if "number" in kwargs:
self._number = kwargs["number"]
del kwargs["number"]
else:
self._number = None
# If there are still remaining parameters that were not handled
# by this superclass or the inheriting class, they are invalid
for key in kwargs:
raise TypeError(f"'{key}' is an invalid keyword argument")
@classmethod
def from_atoms(cls, atoms, *args, **kwargs):
"""
Create a query using the given query structure.
Parameters
----------
atoms : AtomArray or AtomArrayStack
The query structure.
**kwargs : dict, optional
See the constructor for additional options.
"""
mol_file = MOLFile()
mol_file.set_structure(atoms)
# Every MOL string with "$$$$" is a valid SDF string
# Important: USE MS-style new lines
return cls(
*args,
sdf = "\r\n".join(mol_file.lines) + "\r\n$$$$\r\n",
**kwargs
)
def get_input_url_path(self):
input_string = f"compound/{self.search_type()}/{self._query_key}"
if self._query_key == "cid":
# Put CID in URL and not in POST payload,
# as PubChem is confused otherwise
input_string += "/" + str(self._query_val)
return input_string
def get_params(self):
if self._query_key not in ("cid", "sdf"):
# CID is in URL
# SDF is given as file
params = {self._query_key: self._query_val}
else:
params = {}
# Only set maximum number, if provided by the user
# The PubChem default value for this might change over time
if self._number is not None:
params["MaxRecords"] = self._number
for key, val in self.search_options().items():
# Convert 'snake case' Python parameters
# to 'camel case' request parameters
key = "".join([word.capitalize() for word in key.split("_")])
params[key] = val
return params
def get_files(self):
# Multi-line SDF string requires payload as file
if self._query_key == "sdf":
return {"sdf": self._query_val}
else:
return {}
@abc.abstractmethod
def search_type(self):
"""
Get the type of performed search for the request input part.
PROTECTED: Override when inheriting.
Returns
-------
search_type : str
The search type for the input part, i.e. the part directly
after ``compound/``.
"""
pass
def search_options(self):
"""
Get additional options for the POST options.
PROTECTED: Override when inheriting.
Returns
-------
options : dict (str -> object)
They keys are automatically converted from *snake case* to
*camel case* required by the request parameters.
"""
return {}
class SuperOrSubstructureQuery(StructureQuery, metaclass=abc.ABCMeta):
"""
Abstract superclass for super- and substructure searches.
This class handles specific options for these searches.
Exactly one of the input structure parameters `smiles`, `smarts`,
`inchi`, `sdf` or `cid` must be given.
Parameters
----------
smiles : str, optional
The query *SMILES* string.
smarts : str, optional
The query *SMARTS* pattern.
inchi : str, optional
The query *InChI* string.
sdf : str, optional
A query structure as SDF formatted string.
Usually :meth:`from_atoms()` is used to create the SDF from an
:class:`AtomArray`.
cid : int, optional
The query structure given as CID.
number : int, optional
The maximum number of matches that this query may return.
By default, the *PubChem* default value is used, which can
be considered unlimited.
match_charges : bool, optional
If set to true, atoms must match the specified charge.
(Default: False)
match_tautomers : bool, optional
If set to true, allow match to tautomers of the given structure.
(Default: False)
rings_not_embedded : bool, optional
If set to true, rings may not be embedded in a larger system.
(Default: False)
single_double_bonds_match : bool, optional
If set to true, single or double bonds match aromatic bonds.
(Default: True)
chains_match_rings : bool, optional
If set to true, chain bonds in the query may match rings in
hits.
(Default: True)
strip_hydrogen : bool, optional
If set to true, remove any explicit hydrogens before searching.
(Default: False)
stereo : {'ignore', 'exact', 'relative', 'nonconflicting'}, optional
How to handle stereo.
(Default: 'ignore')
Notes
-----
Optional parameter descriptions are taken from the *PubChem* REST
API
`documentation <https://pubchem.ncbi.nlm.nih.gov/docs/pug-rest#section=Substructure-Superstructure>`_.
"""
_option_defaults = {
"match_charges" : False,
"match_tautomers" : False,
"rings_not_embedded" : False,
"single_double_bonds_match" : True,
"chains_match_rings" : True,
"strip_hydrogen" : False,
"stereo" : "ignore",
}
def __init__(self, **kwargs):
self._options = copy.copy(SuperOrSubstructureQuery._option_defaults)
for option, value in kwargs.items():
if option in SuperOrSubstructureQuery._option_defaults.keys():
self._options[option] = value
del kwargs[option]
super().__init__(**kwargs)
def search_options(self):
return self._options
class SuperstructureQuery(SuperOrSubstructureQuery):
"""
A query that searches for all structures, where the given
input structure is a superstructure.
In other words, this query matches substructures of the input
structure.
Exactly one of the input structure parameters `smiles`, `smarts`,
`inchi`, `sdf` or `cid` must be given.
Parameters
----------
smiles : str, optional
The query *SMILES* string.
smarts : str, optional
The query *SMARTS* pattern.
inchi : str, optional
The query *InChI* string.
sdf : str, optional
A query structure as SDF formatted string.
Usually :meth:`from_atoms()` is used to create the SDF from an
:class:`AtomArray`.
cid : int, optional
The query structure given as CID.
number : int, optional
The maximum number of matches that this query may return.
By default, the *PubChem* default value is used, which can
be considered unlimited.
match_charges : bool, optional
If set to true, atoms must match the specified charge.
(Default: False)
match_tautomers : bool, optional
If set to true, allow match to tautomers of the given structure.
(Default: False)
rings_not_embedded : bool, optional
If set to true, rings may not be embedded in a larger system.
(Default: False)
single_double_bonds_match : bool, optional
If set to true, single or double bonds match aromatic bonds.
(Default: True)
chains_match_rings : bool, optional
If set to true, chain bonds in the query may match rings in
hits.
(Default: True)
strip_hydrogen : bool, optional
If set to true, remove any explicit hydrogens before searching.
(Default: False)
stereo : {'ignore', 'exact', 'relative', 'nonconflicting'}, optional
How to handle stereo.
(Default: 'ignore')
Notes
-----
Optional parameter descriptions are taken from the *PubChem* REST
API
`documentation <https://pubchem.ncbi.nlm.nih.gov/docs/pug-rest#section=Substructure-Superstructure>`_.
Examples
--------
>>> # CID of alanine
>>> print(search(SuperstructureQuery(cid=5950, number=5)))
[1032, ..., ..., ..., ...]
>>> # AtomArray of alanine
>>> atom_array = residue("ALA")
>>> print(search(SuperstructureQuery.from_atoms(atom_array, number=5)))
[1032, ..., ..., ..., ...]
"""
def search_type(self):
return "fastsuperstructure"
class SubstructureQuery(SuperOrSubstructureQuery):
"""
A query that searches for all structures, where the given
input structure is a substructure.
In other words, this query matches superstructures of the input
structure.
Exactly one of the input structure parameters `smiles`, `smarts`,
`inchi`, `sdf` or `cid` must be given.
Parameters
----------
smiles : str, optional
The query *SMILES* string.
smarts : str, optional
The query *SMARTS* pattern.
inchi : str, optional
The query *InChI* string.
sdf : str, optional
A query structure as SDF formatted string.
Usually :meth:`from_atoms()` is used to create the SDF from an
:class:`AtomArray`.
cid : int, optional
The query structure given as CID.
number : int, optional
The maximum number of matches that this query may return.
By default, the *PubChem* default value is used, which can
be considered unlimited.
match_charges : bool, optional
If set to true, atoms must match the specified charge.
(Default: False)
match_tautomers : bool, optional
If set to true, allow match to tautomers of the given structure.
(Default: False)
rings_not_embedded : bool, optional
If set to true, rings may not be embedded in a larger system.
(Default: False)
single_double_bonds_match : bool, optional
If set to true, single or double bonds match aromatic bonds.
(Default: True)
chains_match_rings : bool, optional
If set to true, chain bonds in the query may match rings in
hits.
(Default: True)
strip_hydrogen : bool, optional
If set to true, remove any explicit hydrogens before searching.
(Default: False)
stereo : {'ignore', 'exact', 'relative', 'nonconflicting'}, optional
How to handle stereo.
(Default: 'ignore')
Notes
-----
Optional parameter descriptions are taken from the *PubChem* REST
API
`documentation <https://pubchem.ncbi.nlm.nih.gov/docs/pug-rest#section=Substructure-Superstructure>`_.
Examples
--------
>>> # CID of alanine
>>> print(search(SubstructureQuery(cid=5950, number=5)))
[5950, ..., ..., ..., ...]
>>> # AtomArray of alanine
>>> atom_array = residue("ALA")
>>> print(search(SubstructureQuery.from_atoms(atom_array, number=5)))
[5950, ..., ..., ..., ...]
"""
def search_type(self):
return "fastsubstructure"
class SimilarityQuery(StructureQuery):
"""
A query that searches for all structures similar to the given
input structure.
Exactly one of the input structure parameters `smiles`, `smarts`,
`inchi`, `sdf` or `cid` must be given.
Parameters
----------
threshold : float, optional
The minimum required *Tanimoto* similarity for a match.
Must be between 0 (no similarity) and 1 (complete match).
conformation_based : bool, optional
If set to true, the similarity is computed based on the
3D conformation.
By default, only the elements and bonds between the atoms are
considered for similarity computation.
smiles : str, optional
The query *SMILES* string.
smarts : str, optional
The query *SMARTS* pattern.
inchi : str, optional
The query *InChI* string.
sdf : str, optional
A query structure as SDF formatted string.
Usually :meth:`from_atoms()` is used to create the SDF from an
:class:`AtomArray`.
cid : int, optional
The query structure given as CID.
number : int, optional
The maximum number of matches that this query may return.
By default, the *PubChem* default value is used, which can
be considered unlimited.
Notes
-----
The conformation based similarity measure uses *shape-Tanimoto* and
*color-Tanimoto* scores :footcite:`Kim2018`.
References
----------
.. footbibliography::
Examples
--------
>>> # CID of alanine
>>> print(search(SimilarityQuery(cid=5950, threshold=1.0, number=5)))
[5950, ..., ..., ..., ...]
>>> # AtomArray of alanine
>>> atom_array = residue("ALA")
>>> print(search(SimilarityQuery.from_atoms(atom_array, threshold=1.0, number=5)))
[5950, ..., ..., ..., ...]
"""
def __init__(self, threshold=0.9, conformation_based=False, **kwargs):
self._threshold = threshold
self._conformation_based = conformation_based
super().__init__(**kwargs)
def search_type(self):
dim = "3d" if self._conformation_based else "2d"
return f"fastsimilarity_{dim}"
def search_options(self):
return {"threshold" : int(round(self._threshold * 100))}
class IdentityQuery(StructureQuery):
"""
A query that searches for all structures that are identical to the
given input structure.
Exactly one of the input structure parameters `smiles`, `smarts`, `inchi`,
`sdf` or `cid` must be given.
Parameters
----------
identity_type : {'same_connectivity', 'same_tautomer', 'same_stereo', 'same_isotope', 'same_stereo_isotope', 'nonconflicting_stereo', 'same_isotope_nonconflicting_stereo'}, optional
The type of identity search.
smiles : str, optional
The query *SMILES* string.
smarts : str, optional
The query *SMARTS* pattern.
inchi : str, optional
The query *InChI* string.
sdf : str, optional
A query structure as SDF formatted string.
Usually :meth:`from_atoms()` is used to create the SDF from an
:class:`AtomArray`.
cid : int, optional
The query structure given as CID.
number : int, optional
The maximum number of matches that this query may return.
By default, the *PubChem* default value is used, which can
be considered unlimited.
Examples
--------
>>> # CID of alanine
>>> print(search(IdentityQuery(cid=5950)))
[5950]
>>> # AtomArray of alanine
>>> atom_array = residue("ALA")
>>> print(search(IdentityQuery.from_atoms(atom_array)))
[5950]
"""
def __init__(self, identity_type="same_stereo_isotope", **kwargs):
self._identity_type = identity_type
super().__init__(**kwargs)
def search_type(self):
return "fastidentity"
def get_params(self):
# Use 'get_params()' instead of 'search_options()', since the
# parameter 'identity_type' in the REST API is *snake case*
# -> Conversion to *camel case* is undesirable
params = super().get_params()
params["identity_type"] = self._identity_type
return params
def search(query, throttle_threshold=0.5, return_throttle_status=False):
"""
Get all CIDs that meet the given query requirements,
via the PubChem REST API.
This function requires an internet connection.
Parameters
----------
query : Query
The search query.
throttle_threshold : float or None, optional
A value between 0 and 1.
If the load of either the request time or count exceeds this
value the execution is halted.
See :class:`ThrottleStatus` for more information.
If ``None`` is given, the execution is never halted.
return_throttle_status : float, optional
If set to true, the :class:`ThrottleStatus` is also returned.
Returns
-------
ids : list of int
List of all compound IDs (CIDs) that meet the query requirement.
throttle_status : ThrottleStatus
The :class:`ThrottleStatus` obtained from the server response.
This can be used for custom request throttling, for example.
Only returned, if `return_throttle_status` is set to true.
Examples
--------
>>> print(search(NameQuery("Alanine")))
[5950, ..., ..., ...]
"""
# Use POST to be compatible with the larger payloads
# of structure searches
if query.get_files():
files = {key: file for key, file in query.get_files().items()}
else:
files = None
r = requests.post(
_base_url + query.get_input_url_path() + "/cids/TXT",
data=query.get_params(),
files=files
)
if not r.ok:
raise RequestError(parse_error_details(r.text))
throttle_status = ThrottleStatus.from_response(r)
if throttle_threshold is not None:
throttle_status.wait_if_busy(throttle_threshold)
cids = [int(cid) for cid in r.text.splitlines()]
if return_throttle_status:
return cids, throttle_status
else:
return cids