Robo2000 commited on
Commit
b39394e
1 Parent(s): 6e5b287

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +186 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import ipywidgets
3
+ import py3Dmol
4
+
5
+
6
+ from rdkit import Chem
7
+ from rdkit.Chem import Draw
8
+ from PIL import Image
9
+ from rdkit import Chem
10
+ from rdkit.Chem import AllChem
11
+ from ipywidgets import interact,fixed,IntSlider
12
+ import streamlit as st
13
+ import streamlit.components.v1 as components
14
+ import py3Dmol
15
+ from rdkit import Chem
16
+ from rdkit.Chem import Draw
17
+ from rdkit.Chem import AllChem
18
+
19
+
20
+ def smi2conf(smiles):
21
+ '''Convert SMILES to rdkit.Mol with 3D coordinates'''
22
+ mol = Chem.MolFromSmiles(smiles)
23
+ if mol is not None:
24
+ mol = Chem.AddHs(mol)
25
+ AllChem.EmbedMolecule(mol)
26
+ AllChem.MMFFOptimizeMolecule(mol, maxIters=200)
27
+ return mol
28
+ else:
29
+ return None
30
+
31
+ def MolTo3DView(mol, size=(300, 300), style="stick", surface=False, opacity=0.5):
32
+ """Draw molecule in 3D
33
+
34
+ Args:
35
+ ----
36
+ mol: rdMol, molecule to show
37
+ size: tuple(int, int), canvas size
38
+ style: str, type of drawing molecule
39
+ style can be 'line', 'stick', 'sphere', 'carton'
40
+ surface, bool, display SAS
41
+ opacity, float, opacity of surface, range 0.0-1.0
42
+ Return:
43
+ ----
44
+ viewer: py3Dmol.view, a class for constructing embedded 3Dmol.js views in ipython notebooks.
45
+ """
46
+ assert style in ('line', 'stick', 'sphere', 'carton')
47
+ mblock = Chem.MolToMolBlock(mol)
48
+ viewer = py3Dmol.view(width=size[0], height=size[1])
49
+ viewer.addModel(mblock, 'mol')
50
+ viewer.setStyle({style:{}})
51
+ if surface:
52
+ viewer.addSurface(py3Dmol.SAS, {'opacity': opacity})
53
+ viewer.zoomTo()
54
+ return viewer
55
+
56
+ def MakeMolecule(name, ingredients):
57
+ st.write(name, ": ", ingredients)
58
+ m = Chem.MolFromSmiles(ingredients)
59
+ im=Draw.MolToImage(m)
60
+ st.image(im)
61
+
62
+ def conf_viewer(idx):
63
+ mol = confs[idx]
64
+ return MolTo3DView(mol).show()
65
+
66
+ def style_selector(idx, s):
67
+ conf = confs[idx]
68
+ return MolTo3DView(conf, style=s).show()
69
+
70
+ @interact
71
+ def smi2viewer(smi='CC=O'):
72
+ try:
73
+ conf = smi2conf(smi)
74
+ return MolTo3DView(conf).show()
75
+ except:
76
+ return None
77
+
78
+ 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'
79
+ conf = smi2conf(smi)
80
+ viewer = MolTo3DView(conf, size=(600, 300), style='sphere')
81
+ viewer.show()
82
+
83
+ #compound_smiles = 'c1cc(C(=O)O)c(OC(=O)C)cc1'
84
+ #m = Chem.MolFromSmiles(compound_smiles)
85
+ #im=Draw.MolToImage(m)
86
+ #st.image(im)
87
+
88
+
89
+ viewer = MolTo3DView(conf, size=(600, 300), style='sphere')
90
+ viewer.show()
91
+
92
+ 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',
93
+ 'CC(NCCNCC1=CC=C(OCC2=C(C)C(C3=CC=CC=C3)=CC=C2)N=C1OC)=O',
94
+ 'Cc1c(COc2cc(OCc3cccc(c3)C#N)c(CN3C[C@H](O)C[C@H]3C(O)=O)cc2Cl)cccc1-c1ccc2OCCOc2c1',
95
+ 'CCCCC(=O)NCCCCC(=O)NCCCCCC(=O)[O-]',
96
+ "CC(NCCNCC1=CC=C(OCC2=C(C)C(C3=CC=CC=C3)=CC=C2)N=C1OC)=O"]
97
+
98
+ confs = [smi2conf(s) for s in smis]
99
+
100
+
101
+ st.title('⚛️🧬Molecule Modeler🧬⚛️')
102
+
103
+
104
+
105
+ def show(smi, style='stick'):
106
+ mol = Chem.MolFromSmiles(smi)
107
+ mol = Chem.AddHs(mol)
108
+ AllChem.EmbedMolecule(mol)
109
+ AllChem.MMFFOptimizeMolecule(mol, maxIters=200)
110
+ mblock = Chem.MolToMolBlock(mol)
111
+
112
+ view = py3Dmol.view(width=400, height=400)
113
+ view.addModel(mblock, 'mol')
114
+ view.setStyle({style:{}})
115
+ view.zoomTo()
116
+ view.show()
117
+ view.render()
118
+ t =view.js()
119
+ f = open('viz.html', 'w')
120
+ f.write(t.startjs)
121
+ f.write(t.endjs)
122
+ f.close()
123
+
124
+ compound_smiles=st.text_input('SMILES please','CCCCC(=O)NCCCCC(=O)NCCCCCC(=O)[O-]')
125
+ m = Chem.MolFromSmiles(compound_smiles)
126
+
127
+ #Draw.MolToFile(m,'mol.png')
128
+
129
+ show(compound_smiles)
130
+ HtmlFile = open("viz.html", 'r', encoding='utf-8')
131
+ source_code = HtmlFile.read()
132
+ c1,c2=st.columns(2)
133
+ with c1:
134
+ st.write('⚛️🧬Chemical Graph 3D SMILES🧬⚛️:')
135
+ with c2:
136
+ components.html(source_code, height = 400,width=400)
137
+
138
+ MakeMolecule("COVID-19 Antiviral Remdesivir GS5734", "CCC(CC)COC(=O)[C@H](C)N[P@](=O)(OC[C@@H]1[C@H]([C@H]([C@](O1)(C#N)C2=CC=C3N2N=CN=C3N)O)O)OC4=CC=CC=C4")
139
+ MakeMolecule("Ritonavir", "CC(C)C1=NC(=CS1)CN(C)C(=O)N[C@@H](C(C)C)C(=O)N[C@@H](CC2=CC=CC=C2)C[C@@H]([C@H](CC3=CC=CC=C3)NC(=O)OCC4=CN=CS4)O")
140
+ MakeMolecule("Chloroquine", "CCN(CC)CCCC(C)NC1=C2C=CC(=CC2=NC=C1)Cl")
141
+ MakeMolecule("Fingolimod", "CCCCCCCCC1=CC=C(C=C1)CCC(CO)(CO)N")
142
+ MakeMolecule("N4-Hydroxycytidine", "C1=CN(C(=O)N=C1NO)[C@H]2[C@@H]([C@@H]([C@H](O2)CO)O)O")
143
+ MakeMolecule("Favipiravir", "C1=C(N=C(C(=O)N1)C(=O)N)F")
144
+
145
+ st.write('Asthma Inhaler Medications:')
146
+ st.write('Option 1: Symbicort @ Budesonide 160 mcg with Formoterol Fumurate Dihydrate 4.5 mcg')
147
+ st.write('Option 2: Dulera @ Mometasone 200 mcg with Formoterol Fumurate Dihydrate 5 mcg')
148
+ st.write('Symbicort - https://pubchem.ncbi.nlm.nih.gov/#query=Symbicort - Isomeric SMILES: CCCC1O[C@@H]2C[C@H]3[C@@H]4CCC5=CC(=O)C=C[C@@]5([C@H]4[C@H](C[C@@]3([C@@]2(O1)C(=O)CO)C)O)C.C[C@@H](CC1=CC=C(C=C1)OC)NC[C@H](C2=CC(=C(C=C2)O)NC=O)O')
149
+ st.write('Dulera - https://pubchem.ncbi.nlm.nih.gov/#query=Dulera - Isomeric SMILES: C[C@@H]1C[C@H]2[C@@H]3CCC4=CC(=O)C=C[C@@]4([C@]3([C@H](C[C@@]2([C@]1(C(=O)CCl)OC(=O)C5=CC=CO5)C)O)Cl)C.C[C@H](CC1=CC=C(C=C1)OC)NC[C@@H](C2=CC(=C(C=C2)O)NC=O)O.C[C@H](CC1=CC=C(C=C1)OC)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)C)N1C=CC(=NC1=O)N)O")
153
+
154
+ st.write('Info about SMILES: https://archive.epa.gov/med/med_archive_03/web/html/smiles.html')
155
+ st.write('Learn about it at Wikipedia: https://en.wikipedia.org/wiki/Simplified_molecular-input_line-entry_system')
156
+ st.write('Search for any compound on PubChem at National Library of Medicine: https://pubchem.ncbi.nlm.nih.gov/#query=vitamin%20e')
157
+
158
+
159
+
160
+ MakeMolecule("Ibuprofen", "CC(C)CC1=CC=C(C=C1)C(C)C(=O)O")
161
+ MakeMolecule("LSD", "CCN(CC)C(=O)[C@H]1CN([C@@H]2CC3=CNC4=CC=CC(=C34)C2=C1)C")
162
+
163
+ MakeMolecule("Ethanol", "CCO")
164
+ MakeMolecule("Acetic acid", "CC(=O)O")
165
+ MakeMolecule("Cyclohexane", "C1CCCCC1")
166
+ MakeMolecule("Pyridine", "c1cnccc1")
167
+ MakeMolecule("Nicotine", "CN1CCC[C@H]1c2cccnc2")
168
+
169
+
170
+ MakeMolecule("Helium", "[3He]")
171
+ MakeMolecule("Hydrogen", "[H]")
172
+ MakeMolecule("Caffeine", "CN1C=NC2=C1C(=O)N(C(=O)N2C)C")
173
+ MakeMolecule("Sugar", "C([C@@H]1[C@H]([C@@H]([C@H]([C@H](O1)O[C@]2([C@H]([C@@H]([C@H](O2)CO)O)O)CO)O)O)O)O")
174
+ MakeMolecule("Dinitrogen", "N#N")
175
+ MakeMolecule("Methyl isocyanate (MIC)", "CN=C=O")
176
+ MakeMolecule("Copper(II) sulfate", "[Cu+2].[O-]S(=O)(=O)[O-]")
177
+ MakeMolecule("Flavopereirin (C17H15N2)", "CCc(c1)ccc2[n+]1ccc3c2[nH]c4c3cccc4 CCc1c[n+]2ccc3c4ccccc4[nH]c3c2cc1")
178
+ MakeMolecule("Glucose (β-D-glucopyranose) (C6H12O6)", "OC[C@@H](O1)[C@@H](O)[C@H](O)[C@@H](O)[C@H](O)1")
179
+ MakeMolecule("Thiamine (vitamin B1, C12H17N4OS+)", "OCCc1c(C)[n+](cs1)Cc2cnc(C)nc2N")
180
+ MakeMolecule("cephalostatin-1", "CC(C)(O1)C[C@@H](O)[C@@]1(O2)[C@@H](C)[C@@H]3CC=C4[C@]3(C2)C(=O)C[C@H]5[C@H]4CC[C@@H](C6)[C@]5(C)Cc(n7)c6nc(C[C@@]89(C))c7C[C@@H]8CC[C@@H]%10[C@@H]9C[C@@H](O)[C@@]%11(C)C%10=C[C@H](O%12)[C@]%11(O)[C@H](C)[C@]%12(O%13)[C@H](O)C[C@@]%13(C)CO")
181
+ MakeMolecule("Vitamin E", "CC(C)CCC[C@@H](C)CCC[C@@H](C)CCC [C@]1(C)CCc2c(C)c(O)c(C)c(C)c2O1")
182
+ MakeMolecule("Vitamin K2", "CC1=C(C(=O)C2=CC=CC=C2C1=O)CC=C(C)CCC=C(C)CCC=C(C)CCC=C(C)C")
183
+ MakeMolecule("Vitamin K1", "CC(C)CCCC(C)CCCC(C)CCCC(=CCC12C(=O)C3=CC=CC=C3C(=O)C1(O2)C)C")
184
+ MakeMolecule("Vitamin D3", "C[C@@H]([C@@H]1C2([C@H](/C(=C/C=C/3\C(=C)CCC(C3)O)/CCC2)CC1)C)CCCC(C)C.C[C@@H]([C@@H]1C2([C@H](/C(=C/C=C/3\C(=C)CCC(C3)O)/CCC2)CC1)C)CCCC(C)C")
185
+
186
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ py3Dmol
2
+ rdkit-pypi
3
+ Pillow
4
+ ipywidgets