annotate rpviz/smile2picture.py @ 30:0ad6fda90f41 draft default tip

planemo upload commit f74fd52b330cc7460d98121b9bb78c08ca915d1e
author pablocarb
date Thu, 29 Aug 2019 06:59:58 -0400
parents fe78fd6b315a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
1 # -*- coding: utf-8 -*-
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
2 """
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
3 Created on Fri May 31 13:29:59 2019
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
4
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
5 @author: anael
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
6 """
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
7
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
8 from __future__ import print_function
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
9 from rdkit import Chem
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
10 from rdkit.Chem import rdDepictor
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
11 from rdkit.Chem.Draw import rdMolDraw2D
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
12
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
13
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
14 def picture(smile):
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
15 image={}
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
16 for i in smile :
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
17 mol = Chem.MolFromSmiles(smile[i])
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
18 rdDepictor.Compute2DCoords(mol)
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
19 drawer = rdMolDraw2D.MolDraw2DSVG(200,200)
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
20 drawer.DrawMolecule(mol)
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
21 drawer.FinishDrawing()
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
22 svg = drawer.GetDrawingText()
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
23 image[i]=svg.split("?>\n")[1]
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
24 return(image)
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
25
fe78fd6b315a planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
pablocarb
parents:
diff changeset
26