"""Query the local PubChem cache table if available."""

import emzed

pubchem = None
try:
    pubchem = emzed.db.pubchem
except IOError as exc:
    print("local PubChem cache not available")
    print("run emzed.db.update_pubchem() once to download it")
    print(f"details: {exc}")

if pubchem is not None:
    print(f"loaded local pubchem table with {len(pubchem)} rows")
    print()

    # Example: lookup compounds by molecular formula (caffeine).
    hits = pubchem.filter(pubchem.mf == "C8H10N4O2").sort_by("cid")
    view = hits.extract_columns("cid", "mf", "mw", "iupac", "is_in_kegg", "is_in_hmdb")
    print(view[:5])
