SEARCH_CHEMICAL
This function resolves an input identifier through the chemical metadata search engine and returns a concise text summary of the matched compound.
It supports names, CAS numbers, InChI, InChIKey, PubChem-formatted IDs, and SMILES-style lookups accepted by the underlying library.
Excel Usage
=SEARCH_CHEMICAL(ID, autoload, cache)
ID(str, required): Chemical identifier to resolve (name, CAS, InChI, InChIKey, PubChem format, or SMILES).autoload(bool, optional, default: false): Whether to load additional databanks when no immediate match is found (-).cache(bool, optional, default: true): Whether to cache search results for faster repeated lookups (-).
Returns (str): Text representation of resolved chemical metadata.
Example 1: Search water by common name
Inputs:
| ID |
|---|
| water |
Excel formula:
=SEARCH_CHEMICAL("water")
Expected output:
"<ChemicalMetadata, name=water, formula=H2O, smiles=O, MW=18.0153>"
Example 2: Search ethanol by InChI
Inputs:
| ID |
|---|
| InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3 |
Excel formula:
=SEARCH_CHEMICAL("InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3")
Expected output:
"<ChemicalMetadata, name=ethanol, formula=C2H6O, smiles=CCO, MW=46.0684>"
Example 3: Search ethanol by PubChem identifier
Inputs:
| ID |
|---|
| pubchem=702 |
Excel formula:
=SEARCH_CHEMICAL("pubchem=702")
Expected output:
"<ChemicalMetadata, name=ethanol, formula=C2H6O, smiles=CCO, MW=46.0684>"
Example 4: Search decane by SMILES
Inputs:
| ID |
|---|
| CCCCCCCCCC |
Excel formula:
=SEARCH_CHEMICAL("CCCCCCCCCC")
Expected output:
"<ChemicalMetadata, name=decane, formula=C10H22, smiles=CCCCCCCCCC, MW=142.282>"
Python Code
Show Code
from chemicals.identifiers import search_chemical as chemicals_search_chemical
def search_chemical(ID, autoload=False, cache=True):
"""
Resolve a chemical identifier and return a compact metadata summary.
See: https://chemicals.readthedocs.io/chemicals.identifiers.html
This example function is provided as-is without any representation of accuracy.
Args:
ID (str): Chemical identifier to resolve (name, CAS, InChI, InChIKey, PubChem format, or SMILES).
autoload (bool, optional): Whether to load additional databanks when no immediate match is found (-). Default is False.
cache (bool, optional): Whether to cache search results for faster repeated lookups (-). Default is True.
Returns:
str: Text representation of resolved chemical metadata.
"""
try:
result = chemicals_search_chemical(ID=ID, autoload=autoload, cache=cache)
return str(result)
except Exception as e:
return f"Error: {str(e)}"