You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"- Become familiar with the use of RDKit to draw 2D molecular structures\n",
28
+
"- Use both SMILES strings and molecule files as input to create RDKit molecule objects"
29
+
],
30
+
"metadata": {
31
+
"id": "Lck-NAtqxj-h"
32
+
}
33
+
},
34
+
{
35
+
"cell_type": "markdown",
36
+
"source": [
37
+
"# Drawing molecules with RDKit\n",
38
+
"\n",
39
+
"RDKit is a free, massively powerful library of cheminformatics tools. An overview of the RDKit package (and its full documentation) can be accessed here https://www.rdkit.org/docs/Overview.html\n",
40
+
"\n",
41
+
"\n",
42
+
"The RDKit Python library makes drawing molecules simple. It requires two steps:\n",
43
+
"\n",
44
+
"\n",
45
+
"1. Create a molecule object that RDKit can operate on\n",
46
+
"2. Use the Draw function in RDKit's chemistry module to create the 2D image corresponding to the molecule object\n",
47
+
"\n",
48
+
"In order to do this, we must first tell Python to import the requires functionality from the RDKit package. Then, we are free to build our molecule and plot it.\n",
49
+
"\n",
50
+
"\n",
51
+
"# SMILES\n",
52
+
"Here we specify the molecular structure using the Simplified Molecular Input Line Entry System (SMILES) notation.\n",
53
+
"\n",
54
+
"Inspect, then run the following code to draw the benzene molecule."
55
+
],
56
+
"metadata": {
57
+
"id": "1p_TIbTe1msT"
58
+
}
59
+
},
60
+
{
61
+
"cell_type": "code",
62
+
"source": [
63
+
"from rdkit import Chem\n",
64
+
"from rdkit.Chem import Draw\n",
65
+
"m1 = Chem.MolFromSmiles('c1ccccc1')\n",
66
+
"Draw.MolToImage(m1)"
67
+
],
68
+
"metadata": {
69
+
"id": "mge9eDGA0A4M"
70
+
},
71
+
"execution_count": null,
72
+
"outputs": []
73
+
},
74
+
{
75
+
"cell_type": "markdown",
76
+
"source": [
77
+
"Here, we create a molecule object using the `MolFromSmiles()` function. RDKit reads the SMILES string and creates a 2D representation of the corresponding molecule. This is stored in the variable `m`.\n",
78
+
"\n",
79
+
"Once we have the `m` object, we can perform many different operations on it with RDKit, but here we focus on drawing the molecular structure. To do this we use the second import statement to give us access to RDKit's drawing functions.\n",
80
+
"\n",
81
+
"The function that we use in this example, `Draw.MolToImage()`, draws the molecular structure to the screen. However, you could also save your image to a file using the `Draw.MolToFile()` function for later insertion into e.g. Word documents."
82
+
],
83
+
"metadata": {
84
+
"id": "1x0gHFxK64ui"
85
+
}
86
+
},
87
+
{
88
+
"cell_type": "markdown",
89
+
"source": [
90
+
"By editing the SMILES string, we can alter the structure contained in the RDKit molecule object, and therefore the output image.\n",
91
+
"\n",
92
+
"Let's create toluene - you can do this by simply adding another carbon to the SMILES string.\n",
93
+
"\n",
94
+
"Note, however, that we are adding a capital C. In SMILES notation, capital \"C\" denotes an aliphatic sp$^3$ carbon and lowercase \"c\" gives an aromatic sp$^2$ carbon."
95
+
],
96
+
"metadata": {
97
+
"id": "31Z-vyOx3Sf5"
98
+
}
99
+
},
100
+
{
101
+
"cell_type": "code",
102
+
"source": [
103
+
"from rdkit import Chem\n",
104
+
"from rdkit.Chem import Draw\n",
105
+
"m = Chem.MolFromSmiles('c1ccccc1C')\n",
106
+
"Draw.MolToImage(m)"
107
+
],
108
+
"metadata": {
109
+
"id": "S1Bo_RJb1VTP"
110
+
},
111
+
"execution_count": null,
112
+
"outputs": []
113
+
},
114
+
{
115
+
"cell_type": "markdown",
116
+
"source": [
117
+
"Similarly, we can change our benzene example to give us pyridine by replacing a ring carbon with nitrogen. We use a lowercase \"n\" because the pyridine nitrogen is also sp$^2$/aromatic."
118
+
],
119
+
"metadata": {
120
+
"id": "Kz6LvoP95fsF"
121
+
}
122
+
},
123
+
{
124
+
"cell_type": "code",
125
+
"source": [
126
+
"from rdkit import Chem\n",
127
+
"from rdkit.Chem import Draw\n",
128
+
"m = Chem.MolFromSmiles('n1ccccc1')\n",
129
+
"Draw.MolToImage(m)"
130
+
],
131
+
"metadata": {
132
+
"id": "UKNsFba00tcK"
133
+
},
134
+
"execution_count": null,
135
+
"outputs": []
136
+
},
137
+
{
138
+
"cell_type": "markdown",
139
+
"source": [
140
+
"For simple molecules, editing the SMILES string by hand is fairly straightforward. This is not really the case for \"interesting\" molecules. In such cases, one alternative is to use an online source to obtain the SMILES for your molecule.\n",
141
+
"\n",
142
+
"The PubChem service (https://pubchem.ncbi.nlm.nih.gov/) is particularly useful for this. In the following example, PubChem was searched for \"asprin\". The entry for this compound contains the corresponding SMILES string, which was used here.\n",
143
+
"\n",
144
+
"NOTE: An alternative SMILES format is used here that explicitly shows the position of double bonds (denoted \"=\"), so no distinction is made between aromatic and aliphatic atoms. You can read more about SMILES grammar at http://opensmiles.org/opensmiles.html"
"An alternative input method to the SMILES strings, above, uses external files containing information on the elemental makup of the molecule in question and its geometry/bonding.\n",
170
+
"\n",
171
+
"RDKit can read several molecule file formats, but the next example uses a file in the \"MOL\" format."
172
+
],
173
+
"metadata": {
174
+
"id": "wO8MNehOGFQS"
175
+
}
176
+
},
177
+
{
178
+
"cell_type": "code",
179
+
"execution_count": null,
180
+
"metadata": {
181
+
"id": "yFv3z0gfxehq",
182
+
"collapsed": true
183
+
},
184
+
"outputs": [],
185
+
"source": [
186
+
"from rdkit import Chem\n",
187
+
"from rdkit.Chem import Draw\n",
188
+
"m = Chem.MolFromMolFile('Asprin.mol')\n",
189
+
"Draw.MolToImage(m)"
190
+
]
191
+
},
192
+
{
193
+
"cell_type": "markdown",
194
+
"source": [
195
+
"NOTE: The orientation of the the asprin molecule is different because the order of the atoms in the .mol file is different from that given in the SMILES string. This means the \"starting\" atom for the drawing changes."
196
+
],
197
+
"metadata": {
198
+
"id": "EydaQBa6TbGX"
199
+
}
200
+
},
201
+
{
202
+
"cell_type": "markdown",
203
+
"source": [
204
+
"# Practice\n",
205
+
"Search PubChem for the data on paracetamol. Copy the SMILES string and edit/run the following Python code to draw the paracetamol molecule.\n",
206
+
"\n",
207
+
"Remember to put the SMILES string in quotes."
208
+
],
209
+
"metadata": {
210
+
"id": "_0ed7gxW_sTz"
211
+
}
212
+
},
213
+
{
214
+
"cell_type": "code",
215
+
"source": [
216
+
"from rdkit import Chem\n",
217
+
"from rdkit.Chem import Draw\n",
218
+
"m = Chem.MolFromSmiles()\n",
219
+
"Draw.MolToImage(m)"
220
+
],
221
+
"metadata": {
222
+
"id": "DwMYZFi4ACs-"
223
+
},
224
+
"execution_count": null,
225
+
"outputs": []
226
+
},
227
+
{
228
+
"cell_type": "markdown",
229
+
"source": [
230
+
"# TODO:\n",
231
+
"- Clarify different SMILES formats (or simply tidy them up to use a single format - probably better for introductory students)\n",
232
+
"- Add examples using structure files as input instead of SMILES for more complex molecules to show limitations of 2D depiction (then add 3D images?)"
0 commit comments