Commit
·
49ea493
1
Parent(s):
5c36d93
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import streamlit.components.v1 as components
|
3 |
+
import py3Dmol
|
4 |
+
from rdkit import Chem
|
5 |
+
from rdkit.Chem import Draw
|
6 |
+
from rdkit.Chem import AllChem
|
7 |
+
|
8 |
+
st.title('SMILES + RDKit + Py3DMOL :smiley:')
|
9 |
+
def show(smi, style='stick'):
|
10 |
+
mol = Chem.MolFromSmiles(smi)
|
11 |
+
mol = Chem.AddHs(mol)
|
12 |
+
AllChem.EmbedMolecule(mol)
|
13 |
+
AllChem.MMFFOptimizeMolecule(mol, maxIters=200)
|
14 |
+
mblock = Chem.MolToMolBlock(mol)
|
15 |
+
|
16 |
+
view = py3Dmol.view(width=400, height=400)
|
17 |
+
view.addModel(mblock, 'mol')
|
18 |
+
view.setStyle({style:{}})
|
19 |
+
view.zoomTo()
|
20 |
+
view.show()
|
21 |
+
view.render()
|
22 |
+
t =view.js()
|
23 |
+
f = open('viz.html', 'w')
|
24 |
+
f.write(t.startjs)
|
25 |
+
f.write(t.endjs)
|
26 |
+
f.close()
|
27 |
+
|
28 |
+
compound_smiles=st.text_input('SMILES please','CC')
|
29 |
+
m = Chem.MolFromSmiles(compound_smiles)
|
30 |
+
|
31 |
+
Draw.MolToFile(m,'mol.png')
|
32 |
+
|
33 |
+
|
34 |
+
show(compound_smiles)
|
35 |
+
HtmlFile = open("viz.html", 'r', encoding='utf-8')
|
36 |
+
source_code = HtmlFile.read()
|
37 |
+
c1,c2=st.columns(2)
|
38 |
+
with c1:
|
39 |
+
st.write('Molecule :coffee:')
|
40 |
+
st.image('mol.png')
|
41 |
+
with c2:
|
42 |
+
components.html(source_code, height = 400,width=400)
|
43 |
+
|
44 |
+
################ Sidebar ####################
|
45 |
+
with st.sidebar.expander('Rule One (Atoms and Bonds)'):
|
46 |
+
st.markdown('''
|
47 |
+
## Atoms
|
48 |
+
|If |then |
|
49 |
+
|----|----|
|
50 |
+
| Non-aromatic atoms |Uper case letters |
|
51 |
+
| Aromatic atoms |lower case letters |
|
52 |
+
|Atomic symbols has more than one letter | The second is lower case |
|
53 |
+
## Bonds
|
54 |
+
| Bond type| Bond symbol |
|
55 |
+
|---|---|
|
56 |
+
|Simple | - |
|
57 |
+
|Double|=|
|
58 |
+
|Triple|#|
|
59 |
+
|Aromatic|*|
|
60 |
+
| Disconnected structures|. |
|
61 |
+
### Example:
|
62 |
+
CC 👉 There is a non-aromatic carbon attached to another non-aromatic carbon by a single bond.
|
63 |
+
🛑 A bond between two lower case atom symbols is *aromatic*.
|
64 |
+
''')
|
65 |
+
|
66 |
+
with st.sidebar.expander('Rule Two (Simple Chains)'):
|
67 |
+
st.markdown('''
|
68 |
+
## Simple chains
|
69 |
+
* Structures are hydrogen suppresed (Molecules represented without hydrogens)
|
70 |
+
* If enough bonds are not identified by the user, the system will assume that connections
|
71 |
+
are satisfied by hidrogens.
|
72 |
+
* The user can explicitly identify hydrogen bonds, but if so the interpreter will assume that all of them are fully identified.
|
73 |
+
Note:
|
74 |
+
|
75 |
+
*Because SMILES allows entry of all elements in the periodic table,
|
76 |
+
and also utilizes hydrogen suppression, the user should be aware of chemicals with two letters
|
77 |
+
that could be misinterpreted by the computer. For example, 'Sc' could be interpreted as a **sulfur**
|
78 |
+
atom connected to an aromatic **carbon** by a single bond, or it could be the symbol for **scandium**.
|
79 |
+
The SMILES interpreter gives priority to the interpretation of a single bond connecting a sulfur atom and an aromatic carbon.
|
80 |
+
To identify scandium the user should enter [Sc]*.
|
81 |
+
''')
|
82 |
+
|
83 |
+
with st.sidebar.expander('Rule Three (Branches)'):
|
84 |
+
st.markdown('''
|
85 |
+
## Branches
|
86 |
+
* A branch from a chain is specified by placing the SMILES symbol(s) for the branch between parenthesis.
|
87 |
+
* The string in parentheses is placed directly after the symbol for the atom to which it is connected.
|
88 |
+
* If it is connected by a double or triple bond, the bond symbol immediately follows the left parenthesis.
|
89 |
+
''')
|
90 |
+
|
91 |
+
with st.sidebar.expander('Rule Four (Rings)'):
|
92 |
+
st.markdown('''
|
93 |
+
## Rings
|
94 |
+
* SMILES allows a user to identify ring structures by using numbers to identify the opening and closing ring atom.
|
95 |
+
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'.
|
96 |
+
The resulting structure is cyclohexane. Chemicals that have multiple rings may be identified by using different numbers for each ring.
|
97 |
+
* If a double, single, or aromatic bond is used for the ring closure, the bond symbol is placed before the ring closure number.
|
98 |
+
''')
|
99 |
+
|
100 |
+
with st.sidebar.expander('Rule Five (Charged atoms)'):
|
101 |
+
st.markdown('''
|
102 |
+
## Charged atoms
|
103 |
+
Charges on an atom can be used to override the knowledge regarding valence that is built into SMILES software.
|
104 |
+
The format for identifying a charged atom consists of the atom followed by brackets which enclose the charge on the atom.
|
105 |
+
The number of charges may be explicitly stated ({-1}) or not ({-}).
|
106 |
+
''')
|
107 |
+
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')
|
108 |
+
st.sidebar.write('Info about SMILES: https://archive.epa.gov/med/med_archive_03/web/html/smiles.html')
|