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:

CompoundData

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.

Return type:

Optional[int]

Parameters:

name_or_cid (str | int)

cas(name_or_cid)[source]#

Gets the CAS number. Returns None if not found, ambiguous, or fetch failed.

Return type:

Optional[str]

Parameters:

name_or_cid (str | int)

unii(name_or_cid)[source]#

Gets the UNII code. Returns None if not found, ambiguous, or fetch failed.

Return type:

Optional[str]

Parameters:

name_or_cid (str | int)

form(name_or_cid)[source]#

Gets the Molecular Formula. Returns None if not found, ambiguous, or fetch failed.

Return type:

Optional[str]

Parameters:

name_or_cid (str | int)

wgt(name_or_cid)[source]#

Gets the Molecular Weight as float. Returns None if not found, ambiguous, or fetch failed.

Return type:

Optional[float]

Parameters:

name_or_cid (str | int)

smi(name_or_cid)[source]#

Gets the Canonical SMILES. Returns None if not found, ambiguous, or fetch failed.

Return type:

Optional[str]

Parameters:

name_or_cid (str | int)

iup(name_or_cid)[source]#

Gets the IUPAC Name. Returns None if not found, ambiguous, or fetch failed.

Return type:

Optional[str]

Parameters:

name_or_cid (str | int)

dsc(name_or_cid)[source]#

Gets the description. Returns None if not found, ambiguous, or fetch failed.

Return type:

Optional[str]

Parameters:

name_or_cid (str | int)

syn(name_or_cid)[source]#

Gets the list of synonyms. Returns empty list ([]) if not found, ambiguous, or fetch failed.

Return type:

List[str]

Parameters:

name_or_cid (str | int)

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:

Dict[Union[str, int], Union[CompoundData, Exception]]

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.