{ "cells": [ { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2016.09.4\n", "Tue Mar 28 08:30:39 2017\n" ] } ], "source": [ "import glob\n", "import py3Dmol\n", "\n", "from rdkit import Chem\n", "from rdkit.Chem import AllChem\n", "from rdkit.Chem import Draw\n", "from rdkit import rdBase\n", "from rdkit.Chem import rdMolAlign\n", "print(rdBase.rdkitVersion)\n", "import os,time\n", "print( time.asctime())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First let's reproduce the visualization from [this notebook](http://nbviewer.jupyter.org/github/greglandrum/rdkit_blog/blob/master/notebooks/Trying%20py3Dmol.ipynb)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "(8, 6, 7, 5, 4, 3, 2, 12, 11, 10, 9)\n" ] }, { "data": { "text/html": [ "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = Chem.AddHs(Chem.MolFromSmiles('COc1ccc2[C@H](O)[C@@H](COc2c1)N3CCC(O)(CC3)c4ccc(F)cc4'))\n", "print(m)\n", "AllChem.EmbedMultipleConfs(m,useExpTorsionAnglePrefs=True,useBasicKnowledge=True)\n", "mb = Chem.MolToMolBlock(m)\n", "\n", "core = m.GetSubstructMatch(Chem.MolFromSmiles('C1C(O)c2ccccc2OC1'))\n", "print(core)\n", "\n", "AllChem.AlignMolConformers(m,atomIds=core)\n", "\n", "p = py3Dmol.view(width=400,height=400)\n", "for conf in m.GetConformers():\n", " mb = Chem.MolToMolBlock(m,confId=conf.GetId())\n", " p.addModel(mb,'sdf')\n", "p.setStyle({'stick':{'radius':0.1}})\n", "p.setBackgroundColor('0xeeeeee')\n", "p.zoomTo()\n", "p.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now: examples which do not work:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* read conformers from file:" ] }, { "cell_type": "code", "execution_count": 100, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# create a list of all structures to be aligned\n", "allmol = []\n", "# conformers:\n", "suppl = Chem.SDMolSupplier('/home/gosia/work/work_on_gitlab/icho/calcs/m1/rdkit/result_smiles_new.sdf')\n", "# crystal:\n", "reference = Chem.SDMolSupplier('/home/gosia/work/work_on_gitlab/icho/calcs/m1/balloon/m1_crystal.sdf')[0]\n", "# add reference structure to the list (crystal geom):\n", "allmol.append(reference)\n", "for mol in suppl:\n", " allmol.append(mol)" ] }, { "cell_type": "code", "execution_count": 101, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# find \"core\":\n", "m = Chem.AddHs(Chem.MolFromSmiles('O=C1NCCNC(=O)c2nc(C(=O)NCCNC(=O)c3nc1ccc3)ccc2'))\n", "core = m.GetSubstructMatch(Chem.MolFromSmiles('n1ccccc1'))" ] }, { "cell_type": "code", "execution_count": 102, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# align:\n", "for mol in allmol:\n", " AllChem.AlignMolConformers(mol,atomIds=core)" ] }, { "cell_type": "code", "execution_count": 103, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 103, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# view:\n", "p = py3Dmol.view(width=400,height=400)\n", "p.removeAllModels()\n", "for mol in allmol: \n", " mb = Chem.MolToMolBlock(mol)\n", " p.addModel(mb,'sdf') \n", "p.setStyle({'stick':{'radius':'0.15'}})\n", "p.setBackgroundColor('0xeeeeee')\n", "p.zoomTo()\n", "p.show()" ] }, { "cell_type": "code", "execution_count": 104, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Heavy Atom RMS: 3.604550104229233e-07\n", "Heavy Atom RMS: 1.461877955872602\n", "Heavy Atom RMS: 1.4214730604414139\n", "Heavy Atom RMS: 1.8999303358326163\n", "Heavy Atom RMS: 1.4813288602775967\n", "Heavy Atom RMS: 1.4248638894808567\n", "Heavy Atom RMS: 1.5474857037372614\n", "Heavy Atom RMS: 1.4688621809782134\n", "Heavy Atom RMS: 1.4939359811879294\n", "Heavy Atom RMS: 1.4176054292304114\n" ] } ], "source": [ "# calculate RMSD /check that/:\n", "for mol in allmol:\n", " # note that the first structure on \"allmol_m1_rdkit\" list is the crystal structure, \n", " # so the RMSD value calculated for the first structure (with respect to the crystal) will be 0 or almost 0\n", " print(\"Heavy Atom RMS:\",AllChem.GetBestRMS(Chem.RemoveHs(mol),Chem.RemoveHs(reference)))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "the reference structure is not aligned with the rest, yet RMSD between the first mol and reference is very small (btw i wonder why not 0), as if earlier \"Align\" did not work." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* generate conformers \"on the fly\":" ] }, { "cell_type": "code", "execution_count": 105, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# find \"core\":\n", "m = Chem.AddHs(Chem.MolFromSmiles('O=C1NCCNC(=O)c2nc(C(=O)NCCNC(=O)c3nc1ccc3)ccc2'))\n", "core = m.GetSubstructMatch(Chem.MolFromSmiles('n1ccccc1'))" ] }, { "cell_type": "code", "execution_count": 107, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[, , , , , , , , , , ]\n" ] } ], "source": [ "# create conformers, optimize their geometries and create a list of all structures to be aligned:\n", "allmol = []\n", "allmol.append(reference)\n", "\n", "confs = AllChem.EmbedMultipleConfs(m,10,randomSeed=1)\n", "\n", "# open a file to store conformers - this is because i don't know how else i can getconformers as \"Mol\" and not as \"Conf\"\n", "w = Chem.SDWriter(\"test.sdf\")\n", "for conf in confs:\n", " _ = AllChem.UFFOptimizeMolecule(m,confId=conf)\n", " energy=AllChem.UFFGetMoleculeForceField(m,confId=conf).CalcEnergy()\n", " m.SetProp('ENERGY', '{0:.2f}'.format(energy))\n", " w.write(m, confId = conf) \n", "w.close()\n", "\n", "# load the file\n", "suppl = Chem.SDMolSupplier('test.sdf')\n", "for s in suppl:\n", " allmol.append(s)\n", "print(allmol)" ] }, { "cell_type": "code", "execution_count": 108, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 108, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# view:\n", "p = py3Dmol.view(width=400,height=400)\n", "p.removeAllModels()\n", "for mol in allmol: \n", " mb = Chem.MolToMolBlock(mol)\n", " p.addModel(mb,'sdf') \n", "p.setStyle({'stick':{'radius':'0.15'}})\n", "p.setBackgroundColor('0xeeeeee')\n", "p.zoomTo()\n", "p.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "again the reference structure is not aligned" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.3" } }, "nbformat": 4, "nbformat_minor": 2 }