Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -93,21 +93,111 @@ smis = [ 'COc3nc(OCc2ccc(C#N)c(c1ccc(C(=O)O)cc1)c2P(=O)(O)O)ccc3C[NH2+]CC(I)NC(=
|
|
93 |
"CC(NCCNCC1=CC=C(OCC2=C(C)C(C3=CC=CC=C3)=CC=C2)N=C1OC)=O"]
|
94 |
|
95 |
confs = [smi2conf(s) for s in smis]
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
confs = [smi2conf(s) for s in smis]
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
"CC(NCCNCC1=CC=C(OCC2=C(C)C(C3=CC=CC=C3)=CC=C2)N=C1OC)=O"]
|
94 |
|
95 |
confs = [smi2conf(s) for s in smis]
|
96 |
+
import streamlit as st
|
97 |
+
import streamlit.components.v1 as components
|
98 |
+
import py3Dmol
|
99 |
+
from rdkit import Chem
|
100 |
+
from rdkit.Chem import Draw
|
101 |
+
from rdkit.Chem import AllChem
|
102 |
|
103 |
+
st.title('SMILES + RDKit + Py3DMOL :smiley:')
|
104 |
+
def show(smi, style='stick'):
|
105 |
+
mol = Chem.MolFromSmiles(smi)
|
106 |
+
mol = Chem.AddHs(mol)
|
107 |
+
AllChem.EmbedMolecule(mol)
|
108 |
+
AllChem.MMFFOptimizeMolecule(mol, maxIters=200)
|
109 |
+
mblock = Chem.MolToMolBlock(mol)
|
|
|
|
|
110 |
|
111 |
+
view = py3Dmol.view(width=400, height=400)
|
112 |
+
view.addModel(mblock, 'mol')
|
113 |
+
view.setStyle({style:{}})
|
114 |
+
view.zoomTo()
|
115 |
+
view.show()
|
116 |
+
view.render()
|
117 |
+
t =view.js()
|
118 |
+
f = open('viz.html', 'w')
|
119 |
+
f.write(t.startjs)
|
120 |
+
f.write(t.endjs)
|
121 |
+
f.close()
|
122 |
+
|
123 |
+
compound_smiles=st.text_input('SMILES please','CC')
|
124 |
+
m = Chem.MolFromSmiles(compound_smiles)
|
125 |
|
126 |
+
Draw.MolToFile(m,'mol.png')
|
127 |
+
|
128 |
+
|
129 |
+
show(compound_smiles)
|
130 |
+
HtmlFile = open("viz.html", 'r', encoding='utf-8')
|
131 |
+
source_code = HtmlFile.read()
|
132 |
+
c1,c2=st.beta_columns(2)
|
133 |
+
with c1:
|
134 |
+
st.write('Molecule :coffee:')
|
135 |
+
st.image('mol.png')
|
136 |
+
with c2:
|
137 |
+
components.html(source_code, height = 400,width=400)
|
138 |
+
|
139 |
+
################ Sidebar ####################
|
140 |
+
with st.sidebar.beta_expander('Rule One (Atoms and Bonds)'):
|
141 |
+
st.markdown('''
|
142 |
+
## Atoms
|
143 |
+
|If |then |
|
144 |
+
|----|----|
|
145 |
+
| Non-aromatic atoms |Uper case letters |
|
146 |
+
| Aromatic atoms |lower case letters |
|
147 |
+
|Atomic symbols has more than one letter | The second is lower case |
|
148 |
+
## Bonds
|
149 |
+
| Bond type| Bond symbol |
|
150 |
+
|---|---|
|
151 |
+
|Simple | - |
|
152 |
+
|Double|=|
|
153 |
+
|Triple|#|
|
154 |
+
|Aromatic|*|
|
155 |
+
| Disconnected structures|. |
|
156 |
+
### Example:
|
157 |
+
CC 👉 There is a non-aromatic carbon attached to another non-aromatic carbon by a single bond.
|
158 |
+
🛑 A bond between two lower case atom symbols is *aromatic*.
|
159 |
+
''')
|
160 |
+
|
161 |
+
with st.sidebar.beta_expander('Rule Two (Simple Chains)'):
|
162 |
+
st.markdown('''
|
163 |
+
## Simple chains
|
164 |
+
* Structures are hydrogen suppresed (Molecules represented without hydrogens)
|
165 |
+
* If enough bonds are not identified by the user, the system will assume that connections
|
166 |
+
are satisfied by hidrogens.
|
167 |
+
* The user can explicitly identify hydrogen bonds, but if so the interpreter will assume that all of them are fully identified.
|
168 |
+
Note:
|
169 |
+
|
170 |
+
*Because SMILES allows entry of all elements in the periodic table,
|
171 |
+
and also utilizes hydrogen suppression, the user should be aware of chemicals with two letters
|
172 |
+
that could be misinterpreted by the computer. For example, 'Sc' could be interpreted as a **sulfur**
|
173 |
+
atom connected to an aromatic **carbon** by a single bond, or it could be the symbol for **scandium**.
|
174 |
+
The SMILES interpreter gives priority to the interpretation of a single bond connecting a sulfur atom and an aromatic carbon.
|
175 |
+
To identify scandium the user should enter [Sc]*.
|
176 |
+
''')
|
177 |
+
|
178 |
+
with st.sidebar.beta_expander('Rule Three (Branches)'):
|
179 |
+
st.markdown('''
|
180 |
+
## Branches
|
181 |
+
* A branch from a chain is specified by placing the SMILES symbol(s) for the branch between parenthesis.
|
182 |
+
* The string in parentheses is placed directly after the symbol for the atom to which it is connected.
|
183 |
+
* If it is connected by a double or triple bond, the bond symbol immediately follows the left parenthesis.
|
184 |
+
''')
|
185 |
+
|
186 |
+
with st.sidebar.beta_expander('Rule Four (Rings)'):
|
187 |
+
st.markdown('''
|
188 |
+
## Rings
|
189 |
+
* SMILES allows a user to identify ring structures by using numbers to identify the opening and closing ring atom.
|
190 |
+
For example, in C1CCCCC1, the first carbon has a number '1' which connects by a single bond with the last carbon which also has a number '1'.
|
191 |
+
The resulting structure is cyclohexane. Chemicals that have multiple rings may be identified by using different numbers for each ring.
|
192 |
+
* If a double, single, or aromatic bond is used for the ring closure, the bond symbol is placed before the ring closure number.
|
193 |
+
''')
|
194 |
+
|
195 |
+
with st.sidebar.beta_expander('Rule Five (Charged atoms)'):
|
196 |
+
st.markdown('''
|
197 |
+
## Charged atoms
|
198 |
+
Charges on an atom can be used to override the knowledge regarding valence that is built into SMILES software.
|
199 |
+
The format for identifying a charged atom consists of the atom followed by brackets which enclose the charge on the atom.
|
200 |
+
The number of charges may be explicitly stated ({-1}) or not ({-}).
|
201 |
+
''')
|
202 |
+
st.sidebar.markdown('Original Author: José Manuel Nápoles ([@napoles3d](https://twitter.com/napoles3D)). Find original app in https://share.streamlit.io/napoles-uach/st_smiles/main/smiles.py')
|
203 |
+
st.sidebar.write('Info about SMILES: https://archive.epa.gov/med/med_archive_03/web/html/smiles.html')
|