Spaces:
Build error
Build error
| import streamlit as st | |
| from rdkit import Chem | |
| from rdkit.Chem import AllChem, Draw | |
| def visualize_molecule(mol_smiles): | |
| # Create a molecule using SMILES notation | |
| mol = Chem.MolFromSmiles(mol_smiles) | |
| # Add hydrogen atoms | |
| mol = Chem.AddHs(mol) | |
| # Generate 2D coordinates for the molecule | |
| AllChem.Compute2DCoords(mol) | |
| return mol | |
| # Streamlit App | |
| st.title('Molecular Structure Visualization') | |
| st.write("By Jishnu Setia") | |
| # Input molecule SMILES string | |
| 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 | |
| # Visualize the molecule | |
| if mol_smiles: | |
| mol = visualize_molecule(mol_smiles) | |
| img = Draw.MolToImage(mol, size=(700, 400)) | |
| st.image(img) | |
| # Add space | |
| st.write(" ") | |
| # Instructions for SMILES notation | |
| st.markdown("<h2>SMILES (Simplified Molecular Input Line Entry System)</h2>", unsafe_allow_html=True) | |
| st.write("SMILES is a string format for representing molecular structures.") | |
| st.write("You can represent various features using specific characters in SMILES notation:") | |
| st.write("- Single bonds: Use '-' between atoms (e.g., 'CC' for ethane)") | |
| st.write("- Double bonds: Use '=' between atoms (e.g., 'C=C' for ethene)") | |
| st.write("- Triple bonds: Use '#' between atoms (e.g., 'C#C' for ethyne)") | |
| st.write("- Benzene: Use 'c1ccccc1' (or 'C1=CC=CC=C1') for a benzene ring") | |
| st.write("- Compounds: Combine individual SMILES strings with '.' (e.g., 'CCO.Cl' for ethanol and chlorine)") | |
| st.write("- Ionic compounds: Use square brackets (e.g., '[Na]Br' for sodium bromide)") | |
| st.write("- Ions only: Use the SMILES notation of the ion (e.g., '[Na+]' for sodium ion)") | |