Fetching 3D conformers of small molecules from PubChem
Small molecules can be fetched from PubChem with fetch and database="pubchem". The code is either a compound CID or a compound name, and the compound’s 3D conformer is downloaded as an .sdf file, with its hydrogens and bonds. Like other downloads, the file is cached and reused on later fetches.
Setup
import molecularnodes as mncanvas = mn.Canvas(mn.scene.Cycles(samples=32), resolution=(800, 600), transparent=True)
/home/brady/actions-runner/_work/MolecularNodes/MolecularNodes/molecularnodes/nodes/_utils.py:4: FutureWarning: `databpy.nodes` is deprecated and will be removed in databpy 0.14.0. Node groups are handled by nodebpy (https://pypi.org/project/nodebpy/).
from databpy.nodes import append_from_blend, get_output, swap_tree
Fetch by CID or Name
A code made only of digits is a CID, anything else is looked up by name. Aspirin is CID 2244, so both of these fetch the same structure.
Each fetched molecule is its own object, so it can be moved to sit beside the others in a grid. Combine their views with + to frame all of them at once.
PubChem only computes 3D conformers for compounds that are a single molecule (not a salt or mixture), have at most 50 non-hydrogen atoms and 15 rotatable bonds, contain only H, C, N, O, F, Si, P, S, Cl, Br and I, use only atom types the MMFF94s force field recognises, and have at most five undefined stereocentres (Kim et al. 2013). For any other compound the fetch raises an error rather than falling back to a flat 2D structure. Heme is one of them because of its iron, while its metal-free ring, protoporphyrin IX, has a 3D conformer.
from molecularnodes.download import FileDownloadPDBErrortry: mn.Molecule.fetch("heme", database="pubchem")except FileDownloadPDBError as e:print(e)
PubChem has no 3D conformer for 'heme', or no such compound. PubChem only computes 3D conformers for single molecules (not salts or mixtures) of at most 50 heavy atoms and 15 rotatable bonds, made only of H, C, N, O, F, Si, P, S, Cl, Br and I (so no metals).