awacke1 commited on
Commit
13d9c1a
·
1 Parent(s): 0382306

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +99 -0
app.py CHANGED
@@ -1,7 +1,26 @@
1
  import streamlit as st
 
2
  from rdkit import Chem
3
  from rdkit.Chem import Draw
4
  from PIL import Image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  compound_smiles = 'c1cc(C(=O)O)c(OC(=O)C)cc1'
7
  m = Chem.MolFromSmiles(compound_smiles)
@@ -20,3 +39,83 @@ MakeMolecule("Acetic acid", "CC(=O)O")
20
  MakeMolecule("Cyclohexane", "C1CCCCC1")
21
  MakeMolecule("Pyridine", "c1cnccc1")
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import py3Dmol
3
  from rdkit import Chem
4
  from rdkit.Chem import Draw
5
  from PIL import Image
6
+ from rdkit import Chem
7
+ from rdkit.Chem import AllChem
8
+
9
+ def smi2conf(smiles):
10
+ '''Convert SMILES to rdkit.Mol with 3D coordinates'''
11
+ mol = Chem.MolFromSmiles(smiles)
12
+ if mol is not None:
13
+ mol = Chem.AddHs(mol)
14
+ AllChem.EmbedMolecule(mol)
15
+ AllChem.MMFFOptimizeMolecule(mol, maxIters=200)
16
+ return mol
17
+ else:
18
+ return None
19
+
20
+ smi = 'COc3nc(OCc2ccc(C#N)c(c1ccc(C(=O)O)cc1)c2P(=O)(O)O)ccc3C[NH2+]CC(I)NC(=O)C(F)(Cl)Br'
21
+ conf = smi2conf(smi)
22
+ viewer = MolTo3DView(conf, size=(600, 300), style='sphere')
23
+ viewer.show()
24
 
25
  compound_smiles = 'c1cc(C(=O)O)c(OC(=O)C)cc1'
26
  m = Chem.MolFromSmiles(compound_smiles)
 
39
  MakeMolecule("Cyclohexane", "C1CCCCC1")
40
  MakeMolecule("Pyridine", "c1cnccc1")
41
 
42
+
43
+ def MolTo3DView(mol, size=(300, 300), style="stick", surface=False, opacity=0.5):
44
+ """Draw molecule in 3D
45
+
46
+ Args:
47
+ ----
48
+ mol: rdMol, molecule to show
49
+ size: tuple(int, int), canvas size
50
+ style: str, type of drawing molecule
51
+ style can be 'line', 'stick', 'sphere', 'carton'
52
+ surface, bool, display SAS
53
+ opacity, float, opacity of surface, range 0.0-1.0
54
+ Return:
55
+ ----
56
+ viewer: py3Dmol.view, a class for constructing embedded 3Dmol.js views in ipython notebooks.
57
+ """
58
+ assert style in ('line', 'stick', 'sphere', 'carton')
59
+ mblock = Chem.MolToMolBlock(mol)
60
+ viewer = py3Dmol.view(width=size[0], height=size[1])
61
+ viewer.addModel(mblock, 'mol')
62
+ viewer.setStyle({style:{}})
63
+ if surface:
64
+ viewer.addSurface(py3Dmol.SAS, {'opacity': opacity})
65
+ viewer.zoomTo()
66
+ return viewer
67
+
68
+ viewer = MolTo3DView(conf, size=(600, 300), style='sphere')
69
+ viewer.show()
70
+
71
+ from ipywidgets import interact,fixed,IntSlider
72
+ import ipywidgets
73
+
74
+ smis = [ 'COc3nc(OCc2ccc(C#N)c(c1ccc(C(=O)O)cc1)c2P(=O)(O)O)ccc3C[NH2+]CC(I)NC(=O)C(F)(Cl)Br',
75
+ 'CC(NCCNCC1=CC=C(OCC2=C(C)C(C3=CC=CC=C3)=CC=C2)N=C1OC)=O',
76
+ 'Cc1c(COc2cc(OCc3cccc(c3)C#N)c(CN3C[C@H](O)C[C@H]3C(O)=O)cc2Cl)cccc1-c1ccc2OCCOc2c1',
77
+ 'CCCCC(=O)NCCCCC(=O)NCCCCCC(=O)[O-]',
78
+ "CC(NCCNCC1=CC=C(OCC2=C(C)C(C3=CC=CC=C3)=CC=C2)N=C1OC)=O"]
79
+
80
+ confs = [smi2conf(s) for s in smis]
81
+
82
+ def conf_viewer(idx):
83
+ mol = confs[idx]
84
+ return MolTo3DView(mol).show()
85
+
86
+ interact(conf_viewer, idx=ipywidgets.IntSlider(min=0,max=len(class_0_list)-1, step=1))
87
+
88
+ from ipywidgets import interact,fixed,IntSlider
89
+ import ipywidgets
90
+
91
+ smis = [ 'COc3nc(OCc2ccc(C#N)c(c1ccc(C(=O)O)cc1)c2P(=O)(O)O)ccc3C[NH2+]CC(I)NC(=O)C(F)(Cl)Br',
92
+ 'CC(NCCNCC1=CC=C(OCC2=C(C)C(C3=CC=CC=C3)=CC=C2)N=C1OC)=O',
93
+ 'Cc1c(COc2cc(OCc3cccc(c3)C#N)c(CN3C[C@H](O)C[C@H]3C(O)=O)cc2Cl)cccc1-c1ccc2OCCOc2c1',
94
+ 'CCCCC(=O)NCCCCC(=O)NCCCCCC(=O)[O-]',
95
+ "CC(NCCNCC1=CC=C(OCC2=C(C)C(C3=CC=CC=C3)=CC=C2)N=C1OC)=O"]
96
+
97
+ confs = [smi2conf(s) for s in smis]
98
+
99
+ def style_selector(idx, s):
100
+ conf = confs[idx]
101
+ return MolTo3DView(conf, style=s).show()
102
+
103
+ interact(style_selector,
104
+ idx=ipywidgets.IntSlider(min=0,max=len(class_0_list)-1, step=1),
105
+ s=ipywidgets.Dropdown(
106
+ options=['line', 'stick', 'sphere'],
107
+ value='line',
108
+ description='Style:'))
109
+
110
+
111
+
112
+ @interact
113
+ def smi2viewer(smi='CC=O'):
114
+ try:
115
+ conf = smi2conf(smi)
116
+ return MolTo3DView(conf).show()
117
+ except:
118
+ return None
119
+
120
+
121
+