Created
May 19, 2021 07:24
-
-
Save greglandrum/0c8b80825826392a6519af7519862baf to your computer and use it in GitHub Desktop.
atom coordinates in images.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "from rdkit import Chem\nfrom rdkit import Geometry\nfrom rdkit.Chem import Draw\nfrom rdkit.Chem import rdDepictor", | |
"execution_count": 6, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "m = Chem.MolFromSmiles('CCCOC')\nrdDepictor.Compute2DCoords(m)\nd2d = Draw.MolDraw2DCairo(350,300)\nd2d.DrawMolecule(m)\nd2d.FinishDrawing()\nd2d.WriteDrawingText('foo.png')\n\nconf = m.GetConformer()\n\n# we can get the draw location of atom coordinates directly with atom indices:\nfor i in range(m.GetNumAtoms()):\n p = conf.GetAtomPosition(i)\n drawp = d2d.GetDrawCoords(i)\n print('Mol coords:','%.3f,%.3f'%(p.x,p.y),\"Draw coords: \",'%.3f,%.3f'%(drawp.x,drawp.y) )", | |
"execution_count": 10, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "Mol coords: -2.598,-0.300 Draw coords: 15.909,179.472\nMol coords: -1.299,0.450 Draw coords: 95.455,133.546\nMol coords: 0.000,-0.300 Draw coords: 175.000,179.472\nMol coords: 1.299,0.450 Draw coords: 254.545,133.546\nMol coords: 2.598,-0.300 Draw coords: 334.091,179.472\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# it's also possible to translate arbitrary point locations from molecule coords into draw coords:\nprint(list(d2d.GetDrawCoords(Geometry.Point2D(0.0,0.0))))", | |
"execution_count": 12, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "[174.99999999999997, 161.10164986855384]\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python38264bitrdkitblogconda8e387449f04349d3a22f66dc2550acf5", | |
"display_name": "Python 3.8.2 64-bit ('rdkit_blog': conda)", | |
"language": "python" | |
}, | |
"toc": { | |
"nav_menu": {}, | |
"number_sections": true, | |
"sideBar": true, | |
"skip_h1_title": false, | |
"base_numbering": 1, | |
"title_cell": "Table of Contents", | |
"title_sidebar": "Contents", | |
"toc_cell": false, | |
"toc_position": {}, | |
"toc_section_display": true, | |
"toc_window_display": false | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.9.4", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "atom coordinates in images.ipynb", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment