ChEBI¶
Online: the ChEBI 2.0 REST service. The offline client is
ChebiSDF. See the
ChEBI tutorial.
provesid.chebi
¶
ChEBI (Chemical Entities of Biological Interest) API interface.
This module provides a Python interface to the ChEBI 2.0 REST API for retrieving
chemical compound information from the ChEBI database. Offline access through
ChEBI's SDF release is ChebiSDF, in
provesid.chebi_sdf.
API documentation: https://www.ebi.ac.uk/chebi/backend/api/docs/
Author: USEtox team Date: August 2025
Attributes¶
CHEBI_MIN_INTERVAL
module-attribute
¶
Seconds between two requests to ChEBI from this process. EBI publishes no per-IP figure for the ChEBI 2.0 API, so this is politeness rather than a quoted limit: ten requests a second is well inside what a walk over an ontology subtree needs.
Classes¶
ChEBIError
¶
Bases: ServiceError
Custom exception for ChEBI API errors.
Also the base for the two more specific failures below, so a caller that catches this one keeps catching everything --- which is what every method in this module does internally before returning None.
Examples:
>>> issubclass(ChEBINotFoundError, ChEBIError)
True
Source code in src/provesid/chebi.py
30 31 32 33 34 35 36 37 38 39 40 41 42 | |
ChEBINotFoundError
¶
Bases: ChEBIError, NotFoundError
ChEBI answered, and its answer was that there is no such record.
A statement about the data rather than the request, so it is never retried.
Examples:
>>> issubclass(ChEBINotFoundError, NotFoundError)
True
Source code in src/provesid/chebi.py
45 46 47 48 49 50 51 52 53 54 55 | |
ChEBITimeoutError
¶
Bases: ChEBIError, ServiceTimeoutError
Every attempt timed out or the connection could not be made.
Examples:
>>> issubclass(ChEBITimeoutError, ServiceTimeoutError)
True
Source code in src/provesid/chebi.py
58 59 60 61 62 63 64 65 66 | |
ChEBI
¶
Interface for the ChEBI 2.0 (Chemical Entities of Biological Interest) REST API.
The ChEBI database is a freely available dictionary of molecular entities focused on 'small' chemical compounds. This class provides methods to search for and retrieve compound information from the ChEBI 2.0 API.
Attributes:
| Name | Type | Description |
|---|---|---|
base_url |
str
|
Base URL for ChEBI 2.0 API |
timeout |
int
|
Request timeout in seconds |
session |
Session
|
HTTP session for connection pooling |
Every method needs the network. Lookups that fail return None (or an
empty collection) after logging a warning, rather than raising; the
offline alternative for records, names and structures is
ChebiSDF.
Examples:
>>> chebi = ChEBI()
>>> compound = chebi.get_compound(15377)
>>> print(compound['name'])
water
Source code in src/provesid/chebi.py
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 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 | |
Methods:¶
__init__(timeout=30)
¶
Initialize ChEBI 2.0 API client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
int
|
Request timeout in seconds (default: 30) |
30
|
Examples:
>>> ChEBI(timeout=60)
ChEBI(base_url='https://www.ebi.ac.uk/chebi/backend/api/public', timeout=60)
Source code in src/provesid/chebi.py
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 | |
get_compound(chebi_id, *, only_ontology_parents=False, only_ontology_children=False)
¶
Retrieve information about a single compound.
Endpoint: GET /compound/{chebi_id}/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chebi_id
|
Union[int, str]
|
ChEBI ID (with or without |
required |
only_ontology_parents
|
bool
|
If True, return only ontology parents. |
False
|
only_ontology_children
|
bool
|
If True, return only ontology children. |
False
|
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Any]]
|
dict with compound data, or None if not found. |
Examples:
>>> chebi = ChEBI()
>>> water = chebi.get_compound(15377)
>>> water['name'], water['chebi_accession']
('water', 'CHEBI:15377')
Source code in src/provesid/chebi.py
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 | |
get_compounds(chebi_ids)
¶
Retrieve information about one or more compounds in a single call.
Endpoint: POST /compounds/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chebi_ids
|
List[Union[int, str]]
|
List of ChEBI IDs. |
required |
Returns:
| Type | Description |
|---|---|
Optional[Any]
|
API response, or None on error: a dict keyed by |
Examples:
>>> chebi = ChEBI()
>>> results = chebi.get_compounds(["CHEBI:15377", "CHEBI:15365"])
>>> {key: entry["data"]["name"] for key, entry in results.items()}
{'CHEBI:15377': 'water', 'CHEBI:15365': 'acetylsalicylic acid'}
>>> chebi.get_compounds([999999999])["CHEBI:999999999"]["exists"]
False
Source code in src/provesid/chebi.py
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 | |
search(term, *, page=1, size=15)
¶
General text search (Elasticsearch-backed).
Endpoint: GET /es_search/
You can search by ChEBI name, brand name, IUPAC name, synonym, InChIKey, formula, SMILES, InChI, CAS number, database cross-reference IDs, PubMed IDs, and more.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
term
|
str
|
Search term (name, SMILES, InChIKey, CAS, formula, …). |
required |
page
|
int
|
Page number for pagination (default 1). |
1
|
size
|
int
|
Page size (default 15). |
15
|
Returns:
| Type | Description |
|---|---|
Optional[Any]
|
Search results dict, or None on error: |
Examples:
>>> chebi = ChEBI()
>>> results = chebi.search("paracetamol")
>>> results["results"][0]["_source"]["chebi_accession"]
'CHEBI:46195'
Source code in src/provesid/chebi.py
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 | |
search_by_name(search_text, *, page=1, size=15)
¶
Search ChEBI by compound name (convenience wrapper around
search).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search_text
|
str
|
Text to search for. |
required |
page
|
int
|
Page number for pagination (default 1). |
1
|
size
|
int
|
Page size (default 15). |
15
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
list of matching entity dicts (may be empty): the |
Examples:
>>> hits = ChEBI().search_by_name("paracetamol", size=2)
>>> [(hit["_source"]["chebi_accession"], hit["_source"]["name"]) for hit in hits]
[('CHEBI:46195', 'paracetamol'), ('CHEBI:74529', 'antidote to paracetamol poisoning')]
Source code in src/provesid/chebi.py
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 | |
advanced_search(specification, *, three_star_only=True, has_structure=None, page=1, size=15, download=False)
¶
Perform an advanced compound search using specification objects.
Endpoint: POST /advanced_search/
Seven specification types are supported (combine with and_specification,
or_specification, but_not_specification):
ontology_specificationformula_specificationmass_specificationmonoisotopicmass_specificationcharge_specificationdatabase_name_specificationtext_search_specification
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
specification
|
Dict[str, Any]
|
Request body following the |
required |
three_star_only
|
bool
|
Only include 3-star compounds (default True). |
True
|
has_structure
|
Optional[bool]
|
Filter by structure availability (None = no filter). |
None
|
page
|
int
|
Page number (default 1). |
1
|
size
|
int
|
Page size (default 15). |
15
|
download
|
bool
|
Return results in download format (default False). |
False
|
Returns:
| Type | Description |
|---|---|
Optional[Any]
|
API response dict/list, or None on error. |
Examples:
>>> chebi = ChEBI()
>>> results = chebi.advanced_search({
... "formula_specification": {
... "and_specification": [{"term": "C6H12O7"}]
... }
... }, three_star_only=False)
>>> results["total"]
15
Source code in src/provesid/chebi.py
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 | |
get_sources_list()
¶
Retrieve the list of available database sources for advanced search.
Endpoint: GET /advanced_search/sources_list
Returns:
| Type | Description |
|---|---|
Optional[Any]
|
Sources information, or None on error: a list of
|
Examples:
>>> ChEBI().get_sources_list()[:2]
[{'prefix': 'agr', 'name': 'Agricola'}, {'prefix': 'pesticides', 'name': "Alan Wood's Pesticides"}]
Source code in src/provesid/chebi.py
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | |
get_ontology_parents(chebi_id)
¶
Get the ontology parents of a compound.
Endpoint: GET /ontology/parents/{chebi_id}/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chebi_id
|
Union[int, str]
|
ChEBI ID (with or without |
required |
Returns:
| Type | Description |
|---|---|
Optional[Any]
|
Ontology parent data, or None on error: the compound's |
Examples:
>>> parents = ChEBI().get_ontology_parents(15377)
>>> first = parents["ontology_relations"]["outgoing_relations"][0]
>>> first["relation_type"], first["final_id"]
('has role', 75772)
Source code in src/provesid/chebi.py
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 | |
get_ontology_children(chebi_id)
¶
Get the ontology children of a compound.
Endpoint: GET /ontology/children/{chebi_id}/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chebi_id
|
Union[int, str]
|
ChEBI ID (with or without |
required |
Returns:
| Type | Description |
|---|---|
Optional[Any]
|
Ontology children data, or None on error: as for
|
Examples:
>>> children = ChEBI().get_ontology_children(15377)
>>> children["ontology_relations"]["incoming_relations"][0]["init_name"]
'methane clathrate'
Source code in src/provesid/chebi.py
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 | |
get_all_ontology_children_in_path(relation, entity, *, three_star_only=True, has_structure=None, page=1, size=15, download=False)
¶
Search all compounds in the ontology matching a relation and entity.
Endpoint: GET /ontology/all_children_in_path/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
relation
|
str
|
Ontology relation type (e.g. |
required |
entity
|
Union[int, str]
|
ChEBI ID of the entity to find children of. |
required |
three_star_only
|
bool
|
Only include 3-star compounds (default True). |
True
|
has_structure
|
Optional[bool]
|
Filter by structure availability. |
None
|
page
|
int
|
Page number (default 1). |
1
|
size
|
int
|
Page size (default 15). |
15
|
download
|
bool
|
Return results in download format. |
False
|
Returns:
| Type | Description |
|---|---|
Optional[Any]
|
API response, or None on error. |
Examples:
>>> chebi = ChEBI()
>>> # Get all compounds that are alcohols
>>> results = chebi.get_all_ontology_children_in_path(
... relation="is_a", entity="CHEBI:30879"
... )
>>> results["total"]
4029
Source code in src/provesid/chebi.py
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 | |
get_compound_structure(chebi_id, *, width=300, height=300)
¶
Get the default SVG structure for a compound.
Endpoint: GET /compound/{id}/structure/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chebi_id
|
Union[int, str]
|
ChEBI ID (numeric, the primary key of the compound). |
required |
width
|
int
|
Width of the SVG (default 300). |
300
|
height
|
int
|
Height of the SVG (default 300). |
300
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Raw SVG string, or None on error. |
Examples:
>>> ChEBI().get_compound_structure(15377)[:21]
"<?xml version='1.0' e"
Source code in src/provesid/chebi.py
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 | |
get_structure(structure_id, *, width=300, height=300)
¶
Get raw SVG contents of a structure by its primary key.
Endpoint: GET /structure/{id}/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure_id
|
int
|
Primary key of the structure. |
required |
width
|
int
|
Width of the SVG (default 300). |
300
|
height
|
int
|
Height of the SVG (default 300). |
300
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Raw SVG string, or None on error. |
Examples:
>>> chebi = ChEBI()
>>> structure_id = chebi.get_compound(15377)["default_structure"]["id"]
>>> structure_id, chebi.get_structure(structure_id)[:5]
(2018, '<?xml')
Source code in src/provesid/chebi.py
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 | |
get_molfile(compound_id)
¶
Download the Mol file for a compound's default structure.
Endpoint: GET /molfile/{id}/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compound_id
|
int
|
Primary key of the compound. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Mol file contents as string, or None on error. |
Examples:
>>> molfile = ChEBI().get_molfile(15377)
>>> molfile.splitlines()[3][:6]
' 3 2'
Source code in src/provesid/chebi.py
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 | |
structure_search(smiles, search_type='connectivity', *, similarity=None, three_star_only=True, page=1, size=15, download=False)
¶
Search compounds by chemical structure.
Endpoint: GET /structure_search/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
smiles
|
str
|
Molecule structure in SMILES representation. |
required |
search_type
|
str
|
One of |
'connectivity'
|
similarity
|
Optional[float]
|
Similarity threshold for similarity search (0.4–1.0). |
None
|
three_star_only
|
bool
|
Only include 3-star compounds (default True). |
True
|
page
|
int
|
Page number (default 1). |
1
|
size
|
int
|
Page size (default 15). |
15
|
download
|
bool
|
Return in download format. |
False
|
Returns:
| Type | Description |
|---|---|
Optional[Any]
|
Search results, or None on error. |
Examples:
>>> chebi = ChEBI()
>>> results = chebi.structure_search("CCO", "connectivity")
>>> results["total"]
2
Source code in src/provesid/chebi.py
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 | |
calculate_avg_mass(structure)
¶
Calculate the average mass from a structure (a molfile).
Endpoint: POST /structure-calculations/avg-mass/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
str
|
A molfile. ChEBI does not accept SMILES here. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The average mass as text, e.g. |
Examples:
>>> chebi = ChEBI()
>>> from rdkit import Chem
>>> molfile = Chem.MolToMolBlock(Chem.MolFromSmiles("CCO"))
>>> chebi.calculate_avg_mass(molfile)
'46.069'
Source code in src/provesid/chebi.py
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 | |
calculate_avg_mass_from_formula(formula)
¶
Calculate the average mass from a molecular formula.
Endpoint: POST /structure-calculations/avg-mass/from-formula/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str
|
A molecular formula, e.g. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The average mass as text, or None on error (a structure ChEBI cannot parse is HTTP 400, logged). |
Examples:
>>> chebi = ChEBI()
>>> chebi.calculate_avg_mass_from_formula('C2H6O')
'46.069'
Source code in src/provesid/chebi.py
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 | |
calculate_mol_formula(structure)
¶
Calculate the molecular formula from a structure (a molfile).
Endpoint: POST /structure-calculations/mol-formula/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
str
|
A molfile. ChEBI does not accept SMILES here. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The formula as text, or None on error (a structure ChEBI cannot parse is HTTP 400, logged). |
Examples:
>>> chebi = ChEBI()
>>> from rdkit import Chem
>>> molfile = Chem.MolToMolBlock(Chem.MolFromSmiles("CCO"))
>>> chebi.calculate_mol_formula(molfile)
'C2H6O'
Source code in src/provesid/chebi.py
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 | |
calculate_monoisotopic_mass(structure)
¶
Calculate the monoisotopic mass from a structure (a molfile).
Endpoint: POST /structure-calculations/monoisotopic-mass/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
str
|
A molfile. ChEBI does not accept SMILES here. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The monoisotopic mass as text, or None on error (a structure ChEBI cannot parse is HTTP 400, logged). |
Examples:
>>> chebi = ChEBI()
>>> from rdkit import Chem
>>> molfile = Chem.MolToMolBlock(Chem.MolFromSmiles("CCO"))
>>> chebi.calculate_monoisotopic_mass(molfile)
'46.041864812'
Source code in src/provesid/chebi.py
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 | |
calculate_monoisotopic_mass_from_formula(formula)
¶
Calculate the monoisotopic mass from a molecular formula.
Endpoint: POST /structure-calculations/monoisotopic-mass/from-formula/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str
|
A molecular formula, e.g. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The monoisotopic mass as text, or None on error (a structure ChEBI cannot parse is HTTP 400, logged). |
Examples:
>>> chebi = ChEBI()
>>> chebi.calculate_monoisotopic_mass_from_formula('C2H6O')
'46.041864812'
Source code in src/provesid/chebi.py
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 | |
calculate_net_charge(structure)
¶
Calculate the net charge from a structure (a molfile).
Endpoint: POST /structure-calculations/net-charge/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
str
|
A molfile. ChEBI does not accept SMILES here. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The net charge as text, e.g. |
Examples:
>>> chebi = ChEBI()
>>> from rdkit import Chem
>>> molfile = Chem.MolToMolBlock(Chem.MolFromSmiles("CCO"))
>>> chebi.calculate_net_charge(molfile)
'0'
Source code in src/provesid/chebi.py
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 | |
depict_structure(structure, *, width=300, height=300, transparent_bg=False)
¶
Generate a PNG depiction of a structure using Indigo.
Endpoint: POST /structure-calculations/depict-indigo/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
str
|
Structure in SMILES or molfile format. |
required |
width
|
int
|
Image width in pixels (default 300). |
300
|
height
|
int
|
Image height in pixels (default 300). |
300
|
transparent_bg
|
bool
|
Use transparent background (default False). |
False
|
Returns:
| Type | Description |
|---|---|
Optional[bytes]
|
PNG image data as bytes, or None on error. |
Examples:
>>> png = ChEBI().depict_structure("CCO")
>>> png[:4]
b'PNG'
Source code in src/provesid/chebi.py
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 | |
batch_get_compounds(chebi_ids, pause_time=0.1)
¶
Retrieve compound info for multiple ChEBI IDs one-by-one.
For small batches prefer
get_compounds which uses the
bulk endpoint. This method calls
get_compound in a loop with an
optional pause between requests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chebi_ids
|
List[Union[int, str]]
|
List of ChEBI IDs. |
required |
pause_time
|
float
|
Seconds to pause between requests (default 0.1). |
0.1
|
Returns:
| Type | Description |
|---|---|
Dict[str, Dict[str, Any]]
|
dict mapping |
Examples:
>>> found = ChEBI().batch_get_compounds([15377, 15365])
>>> {key: record["name"] for key, record in found.items()}
{'CHEBI:15377': 'water', 'CHEBI:15365': 'acetylsalicylic acid'}
Source code in src/provesid/chebi.py
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | |
__repr__()
¶
String representation of ChEBI client.
Source code in src/provesid/chebi.py
1035 1036 1037 | |
Functions:¶
get_chebi_entity(chebi_id)
¶
Convenience function to get ChEBI compound information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chebi_id
|
Union[int, str]
|
ChEBI ID (with or without |
required |
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Any]]
|
dict with compound data, or None if not found. |
Examples:
>>> from provesid import get_chebi_entity
>>> water = get_chebi_entity(15377)
>>> water["default_structure"]["smiles"]
'[H]O[H]'
Source code in src/provesid/chebi.py
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 | |
search_chebi(search_text, max_results=10)
¶
Convenience function to search ChEBI by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search_text
|
str
|
Text to search for. |
required |
max_results
|
int
|
Maximum number of results to return. |
10
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
list of matching entity dicts. |
Examples:
>>> from provesid import search_chebi
>>> results = search_chebi("paracetamol", max_results=1)
>>> results[0]["_source"]["name"]
'paracetamol'
Source code in src/provesid/chebi.py
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 | |