neurosnap.database package#
Database and remote-search helpers.
- class neurosnap.database.CCD(code, name, smiles, type)[source]#
Bases:
objectMinimal Chemical Component Dictionary entry.
- Variables:
code – CCD identifier, typically 1-5 characters.
name – Human-readable component name.
smiles – SMILES string for the component (technically canonicalized but the canonicalization algorithm used by wwPDB is inconsistent with that of RDkit).
type – CCD component type.
- smiles_canonical()[source]#
Return the RDKit-canonicalized SMILES string for this CCD entry.
- Return type:
- to_mol()[source]#
Return an RDKit molecule parsed from the canonical SMILES string.
- Return type:
- Returns:
RDKit molecule for the CCD entry.
- Raises:
ValueError – If the stored canonical SMILES cannot be parsed.
- class neurosnap.database.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.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.fetch_accessions(accessions, batch_size=150)[source]#
Fetch sequences corresponding to a list of UniProt accession numbers.
This function queries UniParc first and then UniProtKB for any missing accessions. Accessions are processed in batches to handle large lists efficiently.
- Parameters:
- Return type:
- Returns:
Dictionary mapping accession numbers to protein sequences. Missing accessions are assigned
None.- Raises:
requests.exceptions.HTTPError – If an API request fails.
- neurosnap.database.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.fetch_uniprot(uniprot_id, head=False)[source]#
Fetch a UniProtKB or UniParc FASTA entry by identifier.
- Parameters:
- Return type:
- Returns:
Truewhenheadis enabled and the accession exists, otherwise the fetched protein sequence.- Raises:
Exception – If the accession is not found in UniProtKB or UniParc.
ValueError – If the returned FASTA does not contain exactly one sequence.
- neurosnap.database.foldseek_search(structure, mode='3diaa', databases=None, max_retries=10, retry_interval=5, output_format='json')[source]#
Perform a protein structure search using the Foldseek API.
- Parameters:
structure (
Union[Structure,StructureEnsemble,StructureStack,str,Path]) – A Neurosnap structure container or a path to a PDB file.mode (
str) – Search mode. Must be one of"3diaa"or"tm-align".databases (
Optional[List[str]]) – Databases to search. Defaults to Foldseek’s common public structure databases.max_retries (
int) – Maximum number of retries when polling job status.retry_interval (
int) – Seconds between job-status polls.output_format (
str) – Output format, either"json"or"dataframe".
- Return type:
Union[str,DataFrame]- Returns:
Search results in the requested format.
- Raises:
RuntimeError – If job submission or retrieval fails.
TimeoutError – If the job does not complete before retries are exhausted.
ValueError – If
output_formatis invalid.
- neurosnap.database.get_ccd(code, *, cache_path='~/.cache/neurosnap/ccd_entries.json', overwrite=False, max_age_days=7, timeout=30)[source]#
Return a CCD entry by its component code.
- neurosnap.database.get_ccd_canonical_aa(ccd, *, standard=True, cache_path='~/.cache/neurosnap/ccd_entries.json', overwrite=False, max_age_days=7, timeout=30)[source]#
Return the most similar canonical or standard amino acid for a CCD entry.
If the input CCD code already has an explicit amino-acid mapping in the amino-acid residue tables, that mapping is reused directly. Otherwise, the CCD entry is compared against canonical amino-acid CCD entries using RDKit Morgan fingerprints and the highest-similarity amino acid is returned. Selenium-containing residues are also compared after conservative selenium-to-sulfur normalization so common analogs such as MSE can map to their sulfur parent without being hard-coded into the amino-acid constants.
- Parameters:
standard (
bool) – IfTrue(default), collapse results to the 20 standard amino acids. IfFalse, allow all canonical residues, includingSECandPYL.cache_path (
str) – Local cache file path for the CCD JSON payload.overwrite (
bool) – IfTrue, force a fresh CCD payload download.max_age_days (
int) – Maximum accepted payload age in days.timeout (
int) – HTTP timeout in seconds for CCD payload downloads.
- Return type:
- Returns:
The best-matching amino-acid record under the requested mode.
- Raises:
ValueError – If the CCD code is unknown or its SMILES cannot be parsed.
- neurosnap.database.get_ccd_entries(*, cache_path='~/.cache/neurosnap/ccd_entries.json', overwrite=False, max_age_days=7, timeout=30)[source]#
Fetch and cache CCD metadata entries.
The CCD payload is cached locally and refreshed when the cached payload exceeds
max_age_daysbased on its embeddedcreated_attimestamp.- Parameters:
- Return type:
- Returns:
Dictionary mapping CCD code to
CCD.
- neurosnap.database.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.run_blast(sequence, email, matrix='BLOSUM62', alignments=250, scores=250, evalue=10.0, filter=False, gapalign=True, database='uniprotkb_refprotswissprot', output_format=None, output_path=None, return_df=True)[source]#
Submit a BLASTP job to the EBI service and optionally return hits as a dataframe.
- Return type:
Optional[DataFrame]
- neurosnap.database.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.