S0udy commited on
Commit
bb21d51
·
verified ·
1 Parent(s): 7bed39a

Upload 5 files

Browse files
Files changed (5) hide show
  1. app.py +187 -0
  2. data/favicon.png +0 -0
  3. data/logo.png +0 -0
  4. environment_backup.yml +10 -0
  5. requirements.txt +20 -0
app.py ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit_ketcher import st_ketcher
3
+ from rdkit import Chem
4
+ from rdkit.Chem import Draw, AllChem, rdDetermineBonds, Descriptors
5
+
6
+ import py3Dmol
7
+ from stmol import showmol
8
+ from io import StringIO
9
+ import sys
10
+ import subprocess
11
+ import time
12
+ import streamlit_shadcn_ui as ui
13
+ import streamlit_shadcn_ui as ui
14
+
15
+ from PIL import Image
16
+
17
+
18
+ try:
19
+ # from openbabel import OBMol, OBConversion
20
+ import openbabel
21
+ except ModuleNotFoundError as e:
22
+ subprocess.Popen([f'{sys.executable} -m pip install --global-option=build_ext --global-option="-I/usr/include/openbabel3" --global-option="-L/usr/lib/openbabel" openbabel==2.4.1'], shell=True)
23
+ subprocess.Popen([f'{sys.executable} -m pip install --global-option=build_ext --global-option="-I/home/appuser/include/openbabel3" --global-option="-L/home/appuser/lib/openbabel" openbabel==2.4.1'], shell=True)
24
+ subprocess.Popen([f'{sys.executable} -m pip install --global-option=build_ext --global-option="-I/home/appuser/usr/include/openbabel3" --global-option="-L/home/appuser/usr/lib/openbabel" openbabel==2.4.1'], shell=True)
25
+ # wait for subprocess to install package before running your actual code below
26
+ #print('openbabel python not importing')
27
+ time.sleep(90)
28
+
29
+ from openbabel import pybel
30
+
31
+
32
+ st.set_page_config(page_title="CHEMVERTINA", page_icon="data/favicon.png", layout="centered")
33
+ st.logo("data/banner.png")
34
+
35
+
36
+ Titlelogo = Image.open('data/banner.png')
37
+ st.image(Titlelogo)
38
+
39
+
40
+ st.write("### **:gray[Your] :rainbow[Molecule] :gray[playground]**")
41
+ st.markdown((":gray[Visualize and Convert your] :rainbow[Molecule]"))
42
+
43
+ supported_input_formats = ['xyz', 'cif', 'pdb','mol', 'mol2','sdf', 'tmol', 'poscar','cub','cube','mcif','mmcif', 'pwscf','smi']
44
+ supported_output_formats = ['cif', 'tmol', 'xyz', 'sdf','pdb','smiles', 'cube','mcif','mmcif','mdl','mol','mol2','smi',]
45
+
46
+ data = '''12
47
+
48
+ C 1.525098 0.401299 -0.169919
49
+ C 1.267282 -0.890923 -0.090842
50
+ S -0.375869 -1.429467 -0.350672
51
+ C -1.364069 -0.186583 -0.232712
52
+ C -0.787332 1.146673 0.059053
53
+ O 0.519018 1.327928 -0.452149
54
+ H 2.534310 0.743140 -0.012656
55
+ H 2.085372 -1.592058 0.136539
56
+ H -0.704143 -2.346960 0.640753
57
+ H -2.462024 -0.305561 -0.365090
58
+ H -0.753918 1.233523 1.179450
59
+ H -1.483725 1.898990 -0.341753
60
+ '''
61
+
62
+ # st.components.v1.iframe("https://pubchem.ncbi.nlm.nih.gov/periodic-table/#view=table&embed=true", width=800, height=800, scrolling=True)
63
+ col1, col2 = st.columns(2)
64
+ col1.write('## Input Molecule')
65
+ input_format = col1.selectbox('Firstly, select the input file format',
66
+ supported_input_formats, )
67
+
68
+ input_text_area = col1.empty()
69
+ uploaded_file = col1.file_uploader("or Choose a file from your local data")
70
+ if uploaded_file is not None:
71
+ # To read file as bytes:
72
+ bytes_data = uploaded_file.getvalue()
73
+
74
+ #uploaded_file_name = uploaded_file.name.split(".")
75
+ #input_up_format = uploaded_file_name[-1]
76
+
77
+
78
+ # To convert to a string based IO:
79
+ stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
80
+
81
+ # To read file as string:
82
+ string_data = stringio.read()
83
+ placeholder_xyz_str = string_data
84
+ input_geom_str = input_text_area.text_area(label='Enter the contents of the source file here', value = placeholder_xyz_str, placeholder = 'Put your text here', height=400)
85
+
86
+ elif uploaded_file is None:
87
+
88
+ input_geom_str = input_text_area.text_area(label='Secondly, paste the file contents here', value = data, placeholder = 'Paste the contents of your file here', height=400, key = 'input_text_area')
89
+ # # Get rid of empty lines
90
+ # input_geom_str = os.linesep.join([s for s in input_geom_str.splitlines() if s])
91
+
92
+ mol = pybel.readstring(input_format, input_geom_str)
93
+ # mol.make3D()
94
+
95
+
96
+
97
+ ## OUTPUT ##
98
+ col2.write('## Output')
99
+ output_format = col2.selectbox('Select the output file format',
100
+ supported_output_formats)
101
+ output_geom_str = mol.write(output_format)
102
+ col2.text_area(label='Converted file structure', value=output_geom_str, height=400)
103
+ col2.download_button(
104
+ label="Download the output",
105
+ data=output_geom_str,
106
+ file_name='your_new_output.'+output_format,
107
+ mime='text/csv',)
108
+
109
+ st.divider()
110
+
111
+ st.subheader("Visualization Scene")
112
+ col3, col4 = st.columns(2)
113
+
114
+
115
+ def vis_your_molecule():
116
+ newviewer = py3Dmol.view(width=400, height=400)
117
+ structure_for_visualization = ''
118
+ try:
119
+ mol = pybel.readstring(input_format, input_geom_str)
120
+ # mol.make3D()
121
+
122
+ structure_for_visualization = mol.write('xyz')
123
+ except Exception as e:
124
+ print('There was a problem with the conversion', e)
125
+
126
+ newviewer.addModel(structure_for_visualization, 'xyz')
127
+ newviewer.setBackgroundColor(bcolor2)
128
+
129
+ newviewer.setStyle(stylemd2)
130
+ newviewer.setViewStyle({"style": "outline", "color": "#CA86FF", "width": 0.05})
131
+
132
+ if spin2:
133
+ newviewer.spin(True)
134
+ else:
135
+ newviewer.spin(False)
136
+
137
+ if box2:
138
+ newviewer.addBox({'center': {'x': 0,'y': 0,'z': 0},
139
+ # 'dimensions': {'w': 1, 'h': 1, 'd': 1}, # scalars
140
+ 'dimensions': {'w': {'x': 8, 'y': 8, 'z': 0}, #[1, 1, 0], #np.array([1,1,0]),
141
+ 'h': {'x': 8, 'y': -8, 'z': 0}, # [1, -1, 0], #np.array([1,-1,0]),
142
+ 'd': {'x': 0, 'y': 0, 'z': 8}, # [0, 0, 1], #np.array([0,0,1]),
143
+ },
144
+ 'color': '#C791FB',
145
+ 'alpha': 0.5,
146
+ })
147
+ else:
148
+ pass
149
+
150
+ showmol(newviewer,height=400,width=400)
151
+
152
+ with col3:
153
+
154
+ st.markdown("Select your Model!")
155
+ styles3d2 = {"Line Model": {"line": {}},
156
+ "Cross Model": {"cross":{}},
157
+ "Stick Model": {"stick": {}, "sphere": {"scale": 0}},
158
+ "Ball and Stick Model": {"stick": {}, "sphere": {"scale": 0.3}},
159
+ "CPK Model": {"sphere": {}}
160
+ }
161
+ list_style2 = ['Line', 'Cross', 'Stick', 'Ball and Stick', 'CPK']
162
+ value2 = ui.tabs(options=list_style2, default_value='Line', key="flowers")
163
+
164
+ spin2 = st.toggle('Animate', value=False, key=5)
165
+ box2 = st.toggle('Show Box', value=False, key=6)
166
+ bcolor2 = st.color_picker('Pick Background Color', '#323232', key=7)
167
+
168
+ def stylem2(value2):
169
+ if value2 == list_style2[0]:
170
+ value4 = styles3d2["Line Model"]
171
+ elif value2 == list_style2[1]:
172
+ value4 = styles3d2["Cross Model"]
173
+ elif value2 == list_style2[2]:
174
+ value4 = styles3d2["Stick Model"]
175
+ elif value2 == list_style2[3]:
176
+ value4 = styles3d2["Ball and Stick Model"]
177
+ elif value2 == list_style2[4]:
178
+ value4 = styles3d2["CPK Model"]
179
+ return value4
180
+
181
+
182
+ stylemd2 = stylem2(value2)
183
+
184
+
185
+
186
+ with col4:
187
+ vis_your_molecule()
data/favicon.png ADDED
data/logo.png ADDED
environment_backup.yml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ name: streamlit-conda-minimal
2
+ channels:
3
+ - conda-forge
4
+ - anaconda
5
+ dependencies:
6
+ - streamlit
7
+ - openbabel
8
+ - py3Dmol
9
+ - ipython
10
+
requirements.txt ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ datamol==0.12.2
2
+
3
+ matplotlib==3.7.1
4
+ medchem==2.0.3
5
+
6
+ numpy==1.24.3
7
+ pandas==1.5.3
8
+ Pillow==9.4.0
9
+ py3Dmol==2.0.4
10
+ pyperclip==1.8.2
11
+ rdkit==2023.9.1
12
+ st_speckmol==0.0.6
13
+ stmol==0.0.9
14
+ streamlit
15
+ streamlit_ketcher==0.0.1
16
+ streamlit_scrollable_textbox==0.0.3
17
+ streamlit_shadcn_ui==0.1.18
18
+ ipython_genutils==0.1.0
19
+ openbabel-wheel
20
+ ipython