Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 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 | 1x 1x 57x 57x 1x 1x 57x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 65x 1x 1x 64x 64x 64x 65x 61x 61x 61x 61x 61x 65x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 131x 131x 1x 1x 1x 3x 1x 1x 1x 1x 2x 2x 2x 2x 1x 1x 1x 60x 60x 60x 60x 60x 60x 60x 58x 58x 2x 2x 58x 58x 57x 57x 60x 60x 56x 60x 1x 60x 55x 55x 56x 56x 56x 60x 54x 54x 54x 60x 60x 1x 1x 1x 18x 18x 18x 18x 6x 6x 12x 12x 1x 1x 1x 12x 12x 3x 3x 9x 9x 9x 9x 26x 26x 26x 26x 9x 9x 9x 8x 1x 12x 1x 1x 1x 9x 8x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 1x 1x 7x 7x 7x 7x 1x 1x 7x 6x 7x 5x 5x 7x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 1x 1x 1x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { HttpStatus } from '@/constants/httpStatus';
import { LRUCache } from 'lru-cache';
/**
* Configuration options for the Cactus client cache.
* @source
*/
interface CactusCacheOptions {
/** Maximum number of items to store in the cache */
max?: number;
/** Time to live for cached items in milliseconds */
ttl?: number;
/** Whether to enable caching (default: true) */
enabled?: boolean;
}
/**
* The endpoints available in the Cactus API.
*
* @see https://cactus.nci.nih.gov/chemical/structure
* @source
*/
type CactusEndpoint =
| 'inchi'
| 'stdinchikey'
| 'stdinchi'
| 'smiles'
| 'ficts'
| 'ficus'
| 'uuuuu'
| 'hashisy'
| 'file?format=sdf'
| 'names'
| 'iupac_name'
| 'cas'
| 'chemspider_id'
| 'image'
| 'twirl'
| 'mw'
| 'formula'
| 'h_bond_donor_count'
| 'h_bond_acceptor_count'
| 'h_bond_center_count'
| 'rule_of_5_violation_count'
| 'rotor_count'
| 'effective_rotor_count'
| 'ring_count'
| 'ringsys_count'
| 'inchikey';
function assertIsStringResponse(response: unknown): asserts response is string {
if (typeof response !== 'string') {
throw new Error(`Invalid response: ${response}`, { cause: response });
}
}
/**
* A client for the Cactus Chemical Identifier Resolver API.
*
* This class provides methods to retrieve various chemical information including
* names, structures, properties, and identifiers from the NCI Cactus service.
*
* API Documentation: https://cactus.nci.nih.gov/chemical/structure_documentation
*
* This service works as a resolver for different chemical structure identifiers and allows one to convert a given
* structure identifier into another representation or structure identifier. You can either use the [web form of
* the resolver](https://cactus.nci.nih.gov/chemical/structure) or the following simple URL API scheme:
*
* ```
* http:///chemical/structure/"structure identifier"/"representation"
* ```
*
* The service returns the requested new structure representation with a corresponding MIME-Type specification (in
* most cases MIME-Type: "text/plain"). If a requested URL is not resolvable for the service an HTML 404 status message
* is returned. In the (unlikely) case of an error, an HTML 500 status message is generated.
*
* @category Utils
* @example
* ```typescript
* const cactus = new Cactus("aspirin");
* const names = await cactus.getNames();
* console.log(names); // ["aspirin", "acetylsalicylic acid", ...]
* ```
* @source
*/
export class Cactus {
/** Chemical name */
private name: string;
/** Whether to enable caching */
private cacheEnabled: boolean = true;
/** Base URL */
private readonly baseURL: string = 'https://cactus.nci.nih.gov/chemical/structure';
/** Whether to return responses in XML format */
private formatXML: boolean = false;
/** Cache */
private cache?: LRUCache<string, string>;
/** Static cache shared across all Cactus instances */
private static globalCache: LRUCache<string, string> = new LRUCache({
max: 1000,
ttl: 1000 * 60 * 60, // 1 hour
});
/**
* Creates a new Cactus instance for the specified chemical.
*
* @param name - The chemical name, formula, or identifier to query
* @param formatXML - Whether to return responses in XML format
* @param cacheOptions - Optional cache configuration
* @throws Error When no chemical name is provided
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const ethanol = new Cactus("C2H5OH", false, { max: 500, ttl: 1800000 });
* const caffeine = new Cactus("58-08-2", false, { enabled: false }); // Disable caching
* ```
* @source
*/
constructor(name: string, formatXML: boolean = false, cacheOptions: CactusCacheOptions = {}) {
if (!name) {
throw new Error('Chemical name is required');
}
this.name = name;
this.formatXML = formatXML;
this.cacheEnabled = cacheOptions.enabled !== false; // Default to true
if (this.cacheEnabled) {
this.cache = new LRUCache({
max: cacheOptions.max ?? 100,
ttl: cacheOptions.ttl ?? 1000 * 60 * 30, // 30 minutes default
});
}
}
/**
* Sets the format of the response to XML.
*
* @param formatXML - Whether to return responses in XML format
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* aspirin.setFormatXML(true);
* const names = await aspirin.getNames();
* // Returns: XML response
* ```
* @source
*/
public setFormatXML(formatXML: boolean): void {
this.formatXML = formatXML;
}
/**
* Clears the instance cache.
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* await aspirin.getNames(); // This will be cached
* aspirin.clearCache(); // Clear the cache
* await aspirin.getNames(); // This will make a new request
* ```
* @source
*/
public clearCache(): void {
this.cache?.clear();
}
/**
* Clears the global cache shared across all Cactus instances.
*
* @example
* ```typescript
* const aspirin1 = new Cactus("aspirin");
* const aspirin2 = new Cactus("aspirin");
* await aspirin1.getNames(); // Cached globally
* await aspirin2.getNames(); // Uses cached result
* Cactus.clearGlobalCache(); // Clear global cache
* await aspirin2.getNames(); // Makes new request
* ```
* @source
*/
public static clearGlobalCache(): void {
Cactus.globalCache.clear();
}
/**
* Gets cache statistics for debugging purposes.
*
* @returns Object containing cache statistics
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* await aspirin.getNames();
* const stats = aspirin.getCacheStats();
* console.log(stats); // { size: 1 }
* ```
* @source
*/
public getCacheStats(): { size: number } {
if (!this.cache) {
return {
size: 0,
};
}
return {
size: this.cache.size,
};
}
/**
* Queries the specified endpoint and returns the response text.
* Uses caching to avoid duplicate requests for the same URL.
*
* @param endpoint - The endpoint to query
* @returns Promise resolving to the response text or undefined if the request fails
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const names = await aspirin.queryEndpoint("names");
* // Returns: "2-acetyloxybenzoic acid\n2-Acetoxybenzoic acid\n50-78-2\n11126-35-5\n11126-37-7\n..."
* aspirin.setFormatXML(true);
* const names = await aspirin.queryEndpoint("names");
* // Returns:
* <request string="aspirin" representation="names">
* <data id="1" resolver="name_by_cir" string_class="chemical name (CIR)" notation="Aspirin">
* <item id="1" classification="pubchem_iupac_name">2-acetyloxybenzoic acid</item>
* <item id="2" classification="pubchem_iupac_openeye_name">2-Acetoxybenzoic acid</item>
* <item id="3" classification="pubchem_generic_registry_name">50-78-2</item>
* <item id="7" classification="pubchem_generic_registry_name">26914-13-6</item>
* <item id="8" classification="pubchem_generic_registry_name">98201-60-6</item>
* <item id="9" classification="pubchem_substance_synonym">NCGC00090977-04</item>
* <item id="10" classification="pubchem_substance_synonym">KBioSS_002272</item>
* <item id="11" classification="pubchem_substance_synonym">SBB015069</item>
* ...
* </data>
* </request>
* ```
* @source
*/
private async queryEndpoint(endpoint: CactusEndpoint): Promise<string | Blob> {
// Encode the identifier so structure inputs (e.g. SMILES, which contain
// "#", "/", "+") don't break the URL path. The endpoint is a fixed,
// URL-safe token (it may carry its own query string) and is left as-is.
let url = `${this.baseURL}/${encodeURIComponent(this.name)}/${endpoint}`;
if (this.formatXML) url += `/xml`;
// Check cache first
if (this.cacheEnabled) {
const cachedResult = this.cache?.get(url) ?? Cactus.globalCache.get(url);
if (cachedResult !== undefined) {
return cachedResult;
}
}
const response = await fetch(url);
const resp = response.clone();
const headers = resp.headers;
const contentType = headers.get('content-type') || 'text/plain';
if (response.status !== HttpStatus.OK) return '';
let result: string | Blob | undefined;
if (contentType.startsWith('image/')) {
result = await response.blob();
} else if (contentType.startsWith('text/plain') || contentType.startsWith('text/xml')) {
result = await response.text();
}
// Cache the result. result is narrowed to string | Blob here; the
// LRUCache is string-typed and in practice only text results reach this
// path, so the assertion is safe and preserves existing caching behavior.
if (this.cacheEnabled && result !== undefined) {
this.cache?.set(url, result as string);
Cactus.globalCache.set(url, result as string);
}
return result ?? '';
}
/**
* Retrieves all known names for the chemical.
*
* @returns Promise resolving to an array of chemical names
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const names = await aspirin.getNames();
* // Returns: [
* // '2-acetyloxybenzoic acid',
* // '2-Acetoxybenzoic acid',
* // '50-78-2',
* // '11126-35-5',
* // '11126-37-7',
* // ...
* // ]
* ```
* @source
*/
async getNames(): Promise<string[] | undefined> {
const result = await this.queryEndpoint('names');
assertIsStringResponse(result);
const results = result.split('\n').filter((name) => !!name);
if (results.length === 0) {
return undefined;
}
return results;
}
/**
* Filters the names from output of this.getNames() to those that are most likely to
* be used in common chemical nomenclature. Parenthetical and bracketed qualifiers are stripped
* first (e.g. "Aspirin (JP15/USP)" or "Acetylsalicylsaure [German]" become "Aspirin"/
* "Acetylsalicylsaure"), then names are kept only if they contain alpha characters and spaces
* (no digits, dashes, etc.), de-duplicated, and ranked.
*
* @param limit - The maximum number of names to return (default: 4)
* @returns Promise resolving to an array of chemical names
* @remarks This method is not guaranteed to return the most simple names. It is a best effort to filter out
* names that are not likely to be used in common chemical nomenclature. The results are also not sorted in
* any meaningful way.
*
* For example, when searching other names for Aspirin (e.g. "2-Acetoxybenzenecarboxylic acid"), CACTUS
* returns the recognizable name only as "Aspirin (JP15/USP)". Stripping the parenthetical qualifier
* recovers the plain "Aspirin" so it can rank alongside the other simple names.
*
* @todo Implement a better way to sort these and return only the values that are most likely to yield search
* results.
*
* @example
* ```typescript
* const aspirin = new Cactus("2-Acetoxybenzenecarboxylic acid");
* const simpleNames = await aspirin.getSimpleNames(3);
* // Returns: ["Adiro", "Aspec", "Aspro"]
* ```
* @source
*/
async getSimpleNames(limit: number = 4): Promise<string[] | undefined> {
const names = await this.getNames();
if (!names || names.length === 0) {
return undefined;
}
// Strip parenthetical and bracketed qualifiers (e.g. "Aspirin (JP15/USP)" -> "Aspirin",
// "Acetylsalicylsaure [German]" -> "Acetylsalicylsaure") before filtering, so an otherwise-
// simple name isn't discarded just because it carries a trailing tag.
const cleaned = names.map((name) =>
name
.replace(/\([^)]*\)|\[[^\]]*\]/g, '')
.replace(/\s+/g, ' ')
.trim(),
);
const simpleNames = cleaned.filter((name) => /^([a-zA-Z][a-z\s]*)$/.test(name));
const uniqueNames = [...new Set(simpleNames)];
return uniqueNames.length > 0
? uniqueNames.sort((a, b) => a.length - b.length).slice(0, limit)
: undefined;
}
/**
* Retrieves the SMILES notation for the chemical.
*
* @returns Promise resolving to the SMILES string
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const smiles = await aspirin.getSmiles();
* // Returns: "CC(=O)Oc1ccccc1C(O)=O"
* ```
* @source
*/
async getSmiles(): Promise<string> {
const result = await this.queryEndpoint('smiles');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the InChI identifier for the chemical.
*
* @returns Promise resolving to the InChI string
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const inchi = await aspirin.getInchi();
* // Returns: "InChI=1/C9H8O4/c1-6(10)13-8-5-3-2-4-7(8)9(11)12/h2-5H,1H3,(H,11,12)/f/h11H"
* ```
* @source
*/
async getInchi(): Promise<string> {
const result = await this.queryEndpoint('inchi');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the InChI Key for the chemical.
*
* @returns Promise resolving to the InChI Key string
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const inchiKey = await aspirin.getInchiKey();
* // Returns: "BSYNRYMUTXBXSQ-UHFFFAOYSA-N"
* ```
* @source
*/
async getInchiKey(): Promise<string> {
const result = await this.queryEndpoint('inchikey');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the FICTS identifier for the chemical.
*
* @returns Promise resolving to the FICTS string
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const ficts = await aspirin.getFicts();
* // Returns: "FICTS identifier string"
* ```
* @source
*/
async getFicts(): Promise<string> {
const result = await this.queryEndpoint('ficts');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the FICUS identifier for the chemical.
*
* @returns Promise resolving to the FICUS string
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const ficus = await aspirin.getFicus();
* // Returns: "FICUS identifier string"
* ```
* @source
*/
async getFicus(): Promise<string> {
const result = await this.queryEndpoint('ficus');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the UUUUU identifier for the chemical.
*
* This "uuuuu identifier" is a hashcode representation of a chemical structure that considers the basic molecular
* connectivity, disregarding features like counterions or stereochemistry.
*
* @returns Promise resolving to the UUUUU string
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const uuuuu = await aspirin.getUuuuu();
* // Returns: "UUUUU identifier string"
* ```
* @source
*/
async getUuuuu(): Promise<string> {
const result = await this.queryEndpoint('uuuuu');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the HASHISY identifier for the chemical.
*
* This "hashisy identifier" is a hashcode representation of a chemical structure that considers the basic molecular
* connectivity, disregarding features like counterions or stereochemistry.
*
* @returns Promise resolving to the HASHISY string
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const hashisy = await aspirin.getHASHISY();
* // Returns: "Cactvs HASHISY identifier string"
* ```
* @source
*/
async getHASHISY(): Promise<string> {
const result = await this.queryEndpoint('hashisy');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves a chemical structure file in the specified format.
*
* @param format - The file format (e.g., "sdf", "jme", "mol", "pdb")
* @param removeHydrogens - Whether to remove hydrogen atoms from the structure
* @returns Promise resolving to the file content as a string
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const sdfFile = await aspirin.getFile("sdf");
* const molFile = await aspirin.getFile("mol", true); // Remove hydrogens
* ```
* @source
*/
async getFile(format: string, removeHydrogens: boolean = false): Promise<string> {
let url = `${this.baseURL}/${this.name}/file?format=${format}`;
if (removeHydrogens) {
url += `&operator=remove_hydrogens`;
}
// Check cache first
if (this.cacheEnabled) {
const cachedResult = this.cache?.get(url) ?? Cactus.globalCache.get(url);
if (cachedResult !== undefined) {
return cachedResult;
}
}
const response = await fetch(url);
if (response.status !== HttpStatus.OK) return '';
const result = await response.text();
// Cache the result
if (this.cacheEnabled && result !== undefined) {
this.cache?.set(url, result);
Cactus.globalCache.set(url, result);
}
return result;
}
/**
* Retrieves the chemical structure in SDF (Structure Data File) format.
*
* @returns Promise resolving to the SDF file content
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const sdf = await aspirin.getFileSDF();
* // Returns SDF format structure data
* ```
* @source
*/
async getFileSDF(): Promise<string> {
return this.getFile('sdf');
}
/**
* Retrieves the chemical structure in JME (Java Molecular Editor) format.
*
* @returns Promise resolving to the JME format string
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const jme = await aspirin.getFileJME();
* // Returns JME format structure data
* ```
* @source
*/
async getFileJME(): Promise<string> {
return this.getFile('jme');
}
/**
* Retrieves the IUPAC name for the chemical.
*
* @returns Promise resolving to the IUPAC name
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const iupacName = await aspirin.getIUPACName();
* // Returns: "2-acetyloxybenzoic acid"
* ```
* @source
*/
async getIUPACName(): Promise<string | undefined> {
const result = await this.queryEndpoint('iupac_name');
assertIsStringResponse(result);
return result === '' ? undefined : result;
}
/**
* Retrieves the CAS registry number for the chemical.
*
* @returns Promise resolving to the CAS number
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const cas = await aspirin.getCAS();
* // Returns: [
* // '50-78-2',
* // '11126-35-5',
* // '11126-37-7',
* // '2349-94-2',
* // '26914-13-6',
* // '98201-60-6'
* // ]
* ```
* @source
*/
async getCAS(): Promise<string[]> {
const result = await this.queryEndpoint('cas');
assertIsStringResponse(result);
return result.split('\n');
}
/**
* Retrieves the ChemSpider ID for the chemical.
*
* @returns Promise resolving to the ChemSpider ID
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const chemspiderId = await aspirin.getChemspiderID();
* // Returns: "2157"
* ```
* @source
*/
async getChemspiderID(): Promise<string> {
const result = await this.queryEndpoint('chemspider_id');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the standardized InChI Key for the chemical.
*
* @returns Promise resolving to the standardized InChI Key
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const stdInchiKey = await aspirin.getStdinchiKey();
* // Returns: "BSYNRYMUTXBXSQ-UHFFFAOYSA-N"
* ```
* @source
*/
async getStdinchiKey(): Promise<string> {
const result = await this.queryEndpoint('stdinchikey');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the standardized InChI for the chemical.
*
* @returns Promise resolving to the standardized InChI
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const stdInchi = await aspirin.getStdinchi();
* // Returns: "InChI=1S/C9H8O4/c1-6(10)13-8-5-3-2-4-7(8)9(11)12/h2-5H,1H3,(H,11,12)"
* ```
* @source
*/
async getStdinchi(): Promise<string> {
const result = await this.queryEndpoint('stdinchi');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves a chemical structure image.
*
* @returns Promise resolving to the image data
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const image = await aspirin.getImage();
* // Returns image data (typically PNG format)
* ```
* @source
*/
async getImage(): Promise<Blob | undefined> {
const result = await this.queryEndpoint('image');
if (result && typeof result === 'object' && result instanceof Blob) {
return result;
}
return undefined;
}
/**
* Retrieves the TWIRL identifier for the chemical.
*
* @returns Promise resolving to the TWIRL string
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const twirl = await aspirin.getTwirl();
* // Returns the embedable HTML for a TwirlyMol (3D) model of the chemical
* ```
* @source
*/
async getTwirl(): Promise<string> {
const result = await this.queryEndpoint('twirl');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the molecular weight of the chemical.
*
* @returns Promise resolving to the molecular weight as a string
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const mw = await aspirin.getMW();
* // Returns: "180.1598"
* ```
* @source
*/
async getMW(): Promise<string> {
const result = await this.queryEndpoint('mw');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the molecular formula of the chemical.
*
* @returns Promise resolving to the molecular formula
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const formula = await aspirin.getFormula();
* // Returns: "C9H8O4"
* ```
* @source
*/
async getFormula(): Promise<string> {
const result = await this.queryEndpoint('formula');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the number of hydrogen bond donors in the chemical.
*
* @returns Promise resolving to the hydrogen bond donor count
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const hbondDonors = await aspirin.getHbondDonorCount();
* // Returns: "1"
* ```
* @source
*/
async getHbondDonorCount(): Promise<string> {
const result = await this.queryEndpoint('h_bond_donor_count');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the number of hydrogen bond acceptors in the chemical.
*
* @returns Promise resolving to the hydrogen bond acceptor count
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const hbondAcceptors = await aspirin.getHbondAcceptorCount();
* // Returns: "4"
* ```
* @source
*/
async getHbondAcceptorCount(): Promise<string> {
const result = await this.queryEndpoint('h_bond_acceptor_count');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the number of hydrogen bond centers in the chemical.
*
* @returns Promise resolving to the hydrogen bond center count
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const hbondCenters = await aspirin.getHbondCenterCount();
* // Returns: "4"
* ```
* @source
*/
async getHbondCenterCount(): Promise<string> {
const result = await this.queryEndpoint('h_bond_center_count');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the number of Lipinski's Rule of Five violations.
*
* @returns Promise resolving to the Rule of Five violation count
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const ruleOf5Violations = await aspirin.getRuleOf5ViolationCount();
* // Returns: "0" (aspirin follows all rules)
* ```
* @source
*/
async getRuleOf5ViolationCount(): Promise<string> {
const result = await this.queryEndpoint('rule_of_5_violation_count');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the number of rotatable bonds in the chemical.
*
* @returns Promise resolving to the rotatable bond count
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const rotors = await aspirin.getRotorCount();
* // Returns: "3"
* ```
* @source
*/
async getRotorCount(): Promise<string> {
const result = await this.queryEndpoint('rotor_count');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the effective number of rotatable bonds in the chemical.
*
* @returns Promise resolving to the effective rotatable bond count
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const effectiveRotors = await aspirin.getEffectiveRotorCount();
* // Returns: "3.0"
* ```
* @source
*/
async getEffectiveRotorCount(): Promise<string> {
const result = await this.queryEndpoint('effective_rotor_count');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the number of rings in the chemical structure.
*
* @returns Promise resolving to the ring count
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const rings = await aspirin.getRingCount();
* // Returns: "1" (benzene ring)
* ```
* @source
*/
async getRingCount(): Promise<string> {
const result = await this.queryEndpoint('ring_count');
assertIsStringResponse(result);
return result;
}
/**
* Retrieves the number of ring systems in the chemical structure.
*
* @returns Promise resolving to the ring system count
*
* @example
* ```typescript
* const aspirin = new Cactus("aspirin");
* const ringSystems = await aspirin.getRingsysCount();
* // Returns: "1" (single ring system)
* ```
* @source
*/
async getRingsysCount(): Promise<string> {
const result = await this.queryEndpoint('ringsys_count');
assertIsStringResponse(result);
return result;
}
}
|