JishnuSetia commited on
Commit
4a0047a
·
verified ·
1 Parent(s): 79bddb9

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from rdkit import Chem
3
+ from rdkit.Chem import AllChem, Draw
4
+
5
+ def visualize_molecule(mol_smiles):
6
+ # Create a molecule using SMILES notation
7
+ mol = Chem.MolFromSmiles(mol_smiles)
8
+
9
+ # Add hydrogen atoms
10
+ mol = Chem.AddHs(mol)
11
+
12
+ # Generate 2D coordinates for the molecule
13
+ AllChem.Compute2DCoords(mol)
14
+
15
+ return mol
16
+
17
+ # Streamlit App
18
+ st.title('Molecular Structure Visualization')
19
+ st.write("By Jishnu Setia")
20
+
21
+ # Input molecule SMILES string
22
+ mol_smiles = st.text_input('Enter molecule SMILES:', 'CCl.O.Br.Cl.C=C.C#C.[Na]Br.[Na]Cl.[Na+].[Br-].c1ccccc1.c1c(O)c(I)c(F)c(Br)c1(Cl)') # Default: Sodium ion
23
+
24
+ # Visualize the molecule
25
+ if mol_smiles:
26
+ mol = visualize_molecule(mol_smiles)
27
+ img = Draw.MolToImage(mol, size=(700, 400))
28
+ st.image(img)
29
+
30
+ # Add space
31
+ st.write(" ")
32
+
33
+ # Instructions for SMILES notation
34
+ st.markdown("<h2>SMILES (Simplified Molecular Input Line Entry System)</h2>", unsafe_allow_html=True)
35
+ st.write("SMILES is a string format for representing molecular structures.")
36
+ st.write("You can represent various features using specific characters in SMILES notation:")
37
+ st.write("- Single bonds: Use '-' between atoms (e.g., 'CC' for ethane)")
38
+ st.write("- Double bonds: Use '=' between atoms (e.g., 'C=C' for ethene)")
39
+ st.write("- Triple bonds: Use '#' between atoms (e.g., 'C#C' for ethyne)")
40
+ st.write("- Benzene: Use 'c1ccccc1' (or 'C1=CC=CC=C1') for a benzene ring")
41
+ st.write("- Compounds: Combine individual SMILES strings with '.' (e.g., 'CCO.Cl' for ethanol and chlorine)")
42
+ st.write("- Ionic compounds: Use square brackets (e.g., '[Na]Br' for sodium bromide)")
43
+ st.write("- Ions only: Use the SMILES notation of the ion (e.g., '[Na+]' for sodium ion)")