In [1]:
Copied!
from provesid import (
PubChemAPI,
PubChemView,
NCIChemicalIdentifierResolver,
CASCommonChem,
CheMBL,
ZeroPM,
)
from provesid.pubchem import CompoundProperties
print("PROVESID imports succeeded")
from provesid import (
PubChemAPI,
PubChemView,
NCIChemicalIdentifierResolver,
CASCommonChem,
CheMBL,
ZeroPM,
)
from provesid.pubchem import CompoundProperties
print("PROVESID imports succeeded")
PROVESID imports succeeded
2. Online lookup with PubChem¶
In [2]:
Copied!
pc = PubChemAPI()
cids = pc.get_cids_by_name("aspirin")
print("Top aspirin CID candidates:", cids[:5])
aspirin_cid = cids[0]
basic = pc.get_basic_compound_info(aspirin_cid)
print("CID:", aspirin_cid)
print("Title:", basic.get("Title"))
print("MolecularFormula:", basic.get("MolecularFormula"))
pc = PubChemAPI()
cids = pc.get_cids_by_name("aspirin")
print("Top aspirin CID candidates:", cids[:5])
aspirin_cid = cids[0]
basic = pc.get_basic_compound_info(aspirin_cid)
print("CID:", aspirin_cid)
print("Title:", basic.get("Title"))
print("MolecularFormula:", basic.get("MolecularFormula"))
Top aspirin CID candidates: [2244, 1983, 9871508, 56842252, 145904]
CID: 2244 Title: None MolecularFormula: C9H8O4
3. Targeted properties from PubChem¶
In [3]:
Copied!
props = pc.get_compound_properties(
aspirin_cid,
[
CompoundProperties.MOLECULAR_WEIGHT,
CompoundProperties.MOLECULAR_FORMULA,
CompoundProperties.INCHIKEY,
],
include_synonyms=False,
)
print("MolecularWeight:", props.get("MolecularWeight"))
print("MolecularFormula:", props.get("MolecularFormula"))
print("InChIKey:", props.get("InChIKey"))
props = pc.get_compound_properties(
aspirin_cid,
[
CompoundProperties.MOLECULAR_WEIGHT,
CompoundProperties.MOLECULAR_FORMULA,
CompoundProperties.INCHIKEY,
],
include_synonyms=False,
)
print("MolecularWeight:", props.get("MolecularWeight"))
print("MolecularFormula:", props.get("MolecularFormula"))
print("InChIKey:", props.get("InChIKey"))
MolecularWeight: 180.16 MolecularFormula: C9H8O4 InChIKey: BSYNRYMUTXBXSQ-UHFFFAOYSA-N
4. Experimental property table with PubChemView¶
In [4]:
Copied!
pv = PubChemView()
boiling_table = pv.get_property_table(aspirin_cid, "Boiling Point")
print("Rows:", len(boiling_table))
print(boiling_table.head(3))
pv = PubChemView()
boiling_table = pv.get_property_table(aspirin_cid, "Boiling Point")
print("Rows:", len(boiling_table))
print(boiling_table.head(3))
Rows: 4
CID StringWithMarkup ExperimentalValue Unit \
0 2244 284 °F at 760 mmHg (decomposes) (NTP, 1992) 284 °F
1 2244 NaN NaN
2 2244 284 °F (decomposes) 284 °F
Temperature Conditions FullReference
0 None None CAMEO Chemicals | ACETYLSALICYLIC ACID | CAMEO...
1 None None DrugBank | Acetylsalicylic acid | The DrugBank...
2 None None Occupational Safety and Health Administration ...
5. Identifier conversion with NCI resolver¶
In [5]:
Copied!
resolver = NCIChemicalIdentifierResolver()
smiles = resolver.resolve("aspirin", "smiles")
inchi = resolver.resolve(smiles, "stdinchi")
print("SMILES:", smiles)
print("InChI prefix:", inchi[:20])
resolver = NCIChemicalIdentifierResolver()
smiles = resolver.resolve("aspirin", "smiles")
inchi = resolver.resolve(smiles, "stdinchi")
print("SMILES:", smiles)
print("InChI prefix:", inchi[:20])
SMILES: CC(=O)Oc1ccccc1C(O)=O InChI prefix: InChI=1S/C9H8O4/c1-6
6. CAS Common Chemistry lookup¶
In [6]:
Copied!
try:
ccc = CASCommonChem()
water = ccc.cas_to_detail("7732-18-5")
print("Name:", water.get("name"))
print("Formula:", water.get("molecularFormula"))
print("CAS:", water.get("rn"))
except Exception as exc:
print("CAS Common Chemistry example skipped:", exc)
try:
ccc = CASCommonChem()
water = ccc.cas_to_detail("7732-18-5")
print("Name:", water.get("name"))
print("Formula:", water.get("molecularFormula"))
print("CAS:", water.get("rn"))
except Exception as exc:
print("CAS Common Chemistry example skipped:", exc)
CAS Common Chemistry example skipped: API key is required for CAS Common Chemistry API v2.0.
Options:
1. Provide api_key parameter: CASCommonChem(api_key='your-key')
2. Provide api_key_file parameter: CASCommonChem(api_key_file='path/to/key.txt')
3. Set persistent API key: from provesid.config import set_cas_api_key; set_cas_api_key('your-key')
4. Set environment variable: CCC_API_KEY or CAS_API_KEY
7. Offline-first classes (local database interfaces)¶
In [7]:
Copied!
# These classes are local/offline interfaces that can auto-download datasets.
# auto_download=False lets this quickstart remain lightweight when datasets
# are not yet present on disk.
for cls in (CheMBL, ZeroPM):
try:
_ = cls(auto_download=False)
print(f"{cls.__name__}: local dataset is available")
except Exception as exc:
print(f"{cls.__name__}: dataset not yet available ({exc.__class__.__name__})")
# These classes are local/offline interfaces that can auto-download datasets.
# auto_download=False lets this quickstart remain lightweight when datasets
# are not yet present on disk.
for cls in (CheMBL, ZeroPM):
try:
_ = cls(auto_download=False)
print(f"{cls.__name__}: local dataset is available")
except Exception as exc:
print(f"{cls.__name__}: dataset not yet available ({exc.__class__.__name__})")
CheMBL: local dataset is available ZeroPM: local dataset is available