Spaces:
Sleeping
Sleeping
Commit
·
cf82ed6
1
Parent(s):
42a84f9
Update
Browse files- st_openbabel_demo.py +42 -0
st_openbabel_demo.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import tempfile
|
4 |
+
|
5 |
+
from openbabel import pybel
|
6 |
+
from st_table_select_cell import st_table_select_cell
|
7 |
+
|
8 |
+
st.header("Openbabel test")
|
9 |
+
st.write("Select a molecul to visualize:")
|
10 |
+
|
11 |
+
# Open data in sdf format:
|
12 |
+
molecules = pybel.readfile("sdf","demo.sdf")
|
13 |
+
|
14 |
+
|
15 |
+
# Convert to a list of molecules:
|
16 |
+
moleculeList = []
|
17 |
+
for item in molecules:
|
18 |
+
moleculeList.append(item)
|
19 |
+
|
20 |
+
# Prepare a dataframe:
|
21 |
+
data = pd.DataFrame({'Molecules':["molecule "+str(i) for i in range(len(moleculeList))]})
|
22 |
+
|
23 |
+
col1, col2 = st.columns(2)
|
24 |
+
|
25 |
+
with col1:
|
26 |
+
# Show table and get user selected cell:
|
27 |
+
selectedCell = st_table_select_cell(data)
|
28 |
+
if selectedCell != False:
|
29 |
+
|
30 |
+
# Visualize a molecule using a temporary file:
|
31 |
+
file = tempfile.NamedTemporaryFile(suffix = ".png", delete = True)
|
32 |
+
|
33 |
+
st.write(str("temporary file name is " + file.name))
|
34 |
+
|
35 |
+
moleculeList[int(selectedCell["rowId"])].draw(show = False, filename = file.name)
|
36 |
+
|
37 |
+
st.image(file.name, caption="Visualization")
|
38 |
+
|
39 |
+
with col2:
|
40 |
+
st.write("Select a subgraph:")
|
41 |
+
|
42 |
+
st.write("To be done.")
|