Spaces:
Sleeping
Sleeping
- src/streamlit_app.py +23 -39
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,24 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
"
|
| 28 |
-
"y": y,
|
| 29 |
-
"idx": indices,
|
| 30 |
-
"rand": np.random.randn(num_points),
|
| 31 |
-
})
|
| 32 |
-
|
| 33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
| 34 |
-
.mark_point(filled=True)
|
| 35 |
-
.encode(
|
| 36 |
-
x=alt.X("x", axis=None),
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from rdkit import Chem
|
| 3 |
+
from rdkit.Chem import Draw
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import io
|
| 6 |
+
# Streamlit app title
|
| 7 |
+
st.title("Molecule 2D Visualization")
|
| 8 |
+
# Input for SMILES string
|
| 9 |
+
smiles = st.text_input("Enter a SMILES string:", "CCCCC[C@H](CC(=O)NO)C(=O)N[C@H](C(=O)N1CCC[C@H]1CO)C(C)C")
|
| 10 |
+
if smiles:
|
| 11 |
+
try:
|
| 12 |
+
# Generate RDKit molecule from SMILES
|
| 13 |
+
mol = Chem.MolFromSmiles(smiles)
|
| 14 |
+
if mol:
|
| 15 |
+
# Draw molecule to an image
|
| 16 |
+
img = Draw.MolToImage(mol, size=(1000, 1000))
|
| 17 |
+
# Display the image in Streamlit
|
| 18 |
+
st.image(img, caption="2D Molecule Structure", use_container_width=True)
|
| 19 |
+
else:
|
| 20 |
+
st.error("Invalid SMILES string. Please try again.")
|
| 21 |
+
except Exception as e:
|
| 22 |
+
st.error(f"An error occurred: {e}")
|
| 23 |
+
else:
|
| 24 |
+
st.info("Please enter a SMILES string to visualize the molecule.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|