Skip to content

Instantly share code, notes, and snippets.

@greglandrum
Created June 4, 2019 14:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save greglandrum/e8c61b8594b1348b5a57e4319df37011 to your computer and use it in GitHub Desktop.
Save greglandrum/e8c61b8594b1348b5a57e4319df37011 to your computer and use it in GitHub Desktop.
Taka_ConstrainedEmbedding.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "Inspired by: https://iwatobipen.wordpress.com/2019/06/04/constrain-embedding-with-mcs-as-a-core-rdkit-chemoinformatics/"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "from rdkit import Chem\nfrom rdkit.Chem import AllChem\nfrom rdkit.Chem import rdFMCS\nfrom rdkit.Chem.Draw import IPythonConsole\nIPythonConsole.ipython_3d = True",
"execution_count": 1,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "mol1 = Chem.MolFromSmiles('CCc1ccccc1')\nmol2 = Chem.MolFromSmiles('CCc1nnccc1')\nmcs = rdFMCS.FindMCS([mol1, mol2])\nprint(mcs.smartsString)\nmcs_mol = Chem.MolFromSmarts(mcs.smartsString)",
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": "[#6]-[#6]-[#6]:[#6]:[#6]:[#6]\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "AllChem.EmbedMolecule(mol1)",
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 3,
"data": {
"text/plain": "0"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "core = Chem.RWMol(AllChem.ReplaceSidechains(mol1,mcs_mol))\n# remove the dummy atoms that creates. We know that they are the highest numbered atoms:\nfor aidx in range(core.GetNumAtoms(),mcs_mol.GetNumAtoms(),-1):\n core.RemoveAtom(aidx-1)\ncore.GetNumConformers()",
"execution_count": 4,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 4,
"data": {
"text/plain": "1"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "_=AllChem.ConstrainedEmbed(mol2,core)",
"execution_count": 5,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "print(Chem.MolToMolBlock(mol1))\nprint(Chem.MolToMolBlock(mol2))",
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"text": "\n RDKit 3D\n\n 8 8 0 0 0 0 0 0 0 0999 V2000\n 2.7975 0.0839 0.7058 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1.9966 0.0409 -0.5636 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.5291 0.0093 -0.2802 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.0984 -1.2078 -0.1315 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.4446 -1.2253 0.1282 C 0 0 0 0 0 0 0 0 0 0 0 0\n -2.1521 -0.0544 0.2377 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.4891 1.1401 0.0826 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.1390 1.2133 -0.1791 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0\n 2 3 1 0\n 3 4 2 0\n 4 5 1 0\n 5 6 2 0\n 6 7 1 0\n 7 8 2 0\n 8 3 1 0\nM END\n\n\n RDKit 3D\n\n 8 8 0 0 0 0 0 0 0 0999 V2000\n 2.7972 0.0849 0.7132 C 0 0 0 0 0 0 0 0 0 0 0 0\n 2.0013 0.0551 -0.5760 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.5443 0.0073 -0.2790 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.1738 1.1566 -0.1708 N 0 0 0 0 0 0 0 0 0 0 0 0\n -1.4845 1.1340 0.0822 N 0 0 0 0 0 0 0 0 0 0 0 0\n -2.1546 -0.0385 0.2385 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.4628 -1.2423 0.1318 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.0973 -1.2199 -0.1320 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0\n 2 3 1 0\n 3 4 2 0\n 4 5 1 0\n 5 6 2 0\n 6 7 1 0\n 7 8 2 0\n 8 3 1 0\nM END\n\n",
"name": "stdout"
}
]
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.7.2",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"gist": {
"id": "e8c61b8594b1348b5a57e4319df37011",
"data": {
"description": "Taka_ConstrainedEmbedding.ipynb",
"public": true
}
},
"_draft": {
"nbviewer_url": "https://gist.github.com/e8c61b8594b1348b5a57e4319df37011"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment