neurosnap.database.pubchem module#
PubChem compound lookup and similarity-search helpers.
- class neurosnap.database.pubchem.PubChemCompound(cid, name, smiles, molecular_formula, molecular_weight)[source]#
Bases:
objectMinimal PubChem compound record.
- Variables:
cid – PubChem Compound Identifier.
name – Preferred IUPAC name (or the best available record title).
smiles – Isomeric SMILES, falling back to the connectivity SMILES.
molecular_formula – Hill-notation molecular formula.
molecular_weight – Molecular weight in g/mol.
- class neurosnap.database.pubchem.PubChemHit(query, cid, rank, name, smiles, molecular_formula, molecular_weight, similarity)[source]#
Bases:
objectA single compound returned by a PubChem similarity search.
- Variables:
query – SMILES string the hit was found for.
cid – PubChem Compound Identifier.
rank – PubChem’s 1-based similarity rank for the hit.
name – Preferred IUPAC name (or the best available record title).
smiles – Isomeric SMILES, falling back to the connectivity SMILES.
molecular_formula – Hill-notation molecular formula.
molecular_weight – Molecular weight in g/mol.
similarity – Local RDKit Morgan/Tanimoto score in the
0-1range.
- neurosnap.database.pubchem.fetch_pubchem_sdfs(cids, *, prefer_3d=True, timeout=30)[source]#
Download SDF records for one or more PubChem CIDs.
Records are retrieved in batches. When
prefer_3dis set, 3D conformers are requested first and any CID without a 3D record falls back to its 2D record.- Parameters:
- Return type:
- Returns:
Dictionary mapping each resolved CID to its SDF record text.
- neurosnap.database.pubchem.get_pubchem_compound(query, *, timeout=30)[source]#
Fetch a PubChem compound by name or Compound Identifier (CID).
- Parameters:
- Return type:
- Returns:
The resolved
PubChemCompoundrecord.- Raises:
ValueError – If the compound cannot be found or its record is incomplete.
- neurosnap.database.pubchem.search_pubchem_similar(smiles, *, threshold=0.9, max_records=100, timeout=30)[source]#
Find PubChem compounds structurally similar to a query SMILES.
Results are ordered by the local RDKit Tanimoto score (descending) while retaining PubChem’s own similarity rank for each hit. The local score uses RDKit Morgan fingerprints and approximates PubChem’s ranking; the two fingerprints are not identical.
- Parameters:
- Return type:
- Returns:
A list of
PubChemHitrecords, possibly empty.- Raises:
ValueError – If
smilesis empty or cannot be parsed.