"""Determine the atoms and sum up the occurences of sp3 hybridized atoms.
This Jupyter notebook was written and tested for Python 3.9.2,
RDKit 2020.09.4, and Jupyter-notebook 6.2.0 in Linux Debian 11 / bullseye,
branch testing on August 8th, 2021."""
from rdkit import Chem
from rdkit.Chem.Draw import IPythonConsole
from rdkit.Chem import Draw
from rdkit.Chem import rdDepictor
from rdkit.Chem.Draw import rdMolDraw2D
from IPython.display import SVG
IPythonConsole.ipython_useSVG=True
def mol_with_atom_index(mol):
for atom in mol.GetAtoms():
atom.SetAtomMapNum(atom.GetIdx())
return mol
mol = Chem.MolFromSmiles("COc(cccc1)c1Nc1nnc(CC(Nc(cc2)ccc2OC(F)(F)F)=O)s1")
mol = mol_with_atom_index(mol)
mc = Chem.Mol(mol.ToBinary())
drawer = rdMolDraw2D.MolDraw2DSVG(450, 200)
drawer.DrawMolecule(mc)
drawer.FinishDrawing()
svg = drawer.GetDrawingText()
display(SVG(svg.replace('svg:','')))
# eventually report the assigned hybridizations
sp3_counter = 0
for atom in mol.GetAtoms():
from_data = str("{:2} {:2} {} {}".format(atom.GetIdx(),
atom.GetSymbol(),
atom.GetTotalNumHs(),
atom.GetHybridization()))
if str(atom.GetHybridization()) == str("SP3"):
retain = " ".join([from_data, "*"])
sp3_counter += 1
else:
retain = from_data
print(retain)
print("RDKit assigns {} atoms with SP3 hybridization".format(sp3_counter))
0 C 3 SP3 * 1 O 0 SP2 2 C 0 SP2 3 C 1 SP2 4 C 1 SP2 5 C 1 SP2 6 C 1 SP2 7 C 0 SP2 8 N 1 SP2 9 C 0 SP2 10 N 0 SP2 11 N 0 SP2 12 C 0 SP2 13 C 2 SP3 * 14 C 0 SP2 15 N 1 SP2 16 C 0 SP2 17 C 1 SP2 18 C 1 SP2 19 C 1 SP2 20 C 1 SP2 21 C 0 SP2 22 O 0 SP2 23 C 0 SP3 * 24 F 0 SP3 * 25 F 0 SP3 * 26 F 0 SP3 * 27 O 0 SP2 28 S 0 SP2 RDKit assigns 6 atoms with SP3 hybridization