ChemInformant.cheminfo_api module#
Provides simple, cached, validated functions for retrieving chemical information from PubChem, including ambiguity handling and batch retrieval.
- info(name_or_cid)[source]#
Retrieves comprehensive, validated details for a single compound. Attempts to return partial data even if some underlying fetches fail.
- Parameters:
name_or_cid (
Union
[str
,int
]) – The compound name (str) or PubChem CID (int).- Returns:
A Pydantic model instance with the compound information.
- Return type:
- Raises:
NotFoundError – If the compound identifier cannot be resolved initially.
AmbiguousIdentifierError – If the name maps to multiple CIDs initially.
ValueError – If an invalid CID (<1) is provided initially.
TypeError – If the input type is incorrect initially.
Exception – Potentially Pydantic validation errors if data is severely malformed.
- cid(name_or_cid)[source]#
Gets the PubChem CID. Returns single CID if unambiguous, None otherwise or if not found.
- cas(name_or_cid)[source]#
Gets the CAS number. Returns None if not found, ambiguous, or fetch failed.
- unii(name_or_cid)[source]#
Gets the UNII code. Returns None if not found, ambiguous, or fetch failed.
- form(name_or_cid)[source]#
Gets the Molecular Formula. Returns None if not found, ambiguous, or fetch failed.
- wgt(name_or_cid)[source]#
Gets the Molecular Weight as float. Returns None if not found, ambiguous, or fetch failed.
- smi(name_or_cid)[source]#
Gets the Canonical SMILES. Returns None if not found, ambiguous, or fetch failed.
- iup(name_or_cid)[source]#
Gets the IUPAC Name. Returns None if not found, ambiguous, or fetch failed.
- dsc(name_or_cid)[source]#
Gets the description. Returns None if not found, ambiguous, or fetch failed.
- syn(name_or_cid)[source]#
Gets the list of synonyms. Returns empty list ([]) if not found, ambiguous, or fetch failed.
- get_multiple_compounds(identifiers)[source]#
Retrieves data for multiple compounds efficiently using batch requests where possible.
- Parameters:
identifiers (
List
[Union
[str
,int
]]) – A list of compound names (str) or PubChem CIDs (int).- Return type:
- Returns:
A dictionary where keys are the original identifiers from the input list, and values are either a CompoundData object upon success, or an Exception (NotFoundError, AmbiguousIdentifierError, ValueError, TypeError, etc.) indicating failure for that specific identifier.