-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDeepSNUPI.py
More file actions
210 lines (181 loc) · 12.1 KB
/
Copy pathDeepSNUPI.py
File metadata and controls
210 lines (181 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
"""
@author: Truong Quoc Chien (chientrq92@gmail.com)
"""
import torch
from src import *
from PIL import Image
import streamlit as st
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
device_name = "GPU" if torch.cuda.is_available() else "CPU"
image = Image.open('cover.PNG')
# APP TITLE
st.set_page_config(layout="wide")
app_title = '<p style="font-size: 40px;">Deep SNUPI</p>'
st.markdown(app_title, unsafe_allow_html=True)
st.sidebar.subheader("PICK TOOLS")
select = st.sidebar.selectbox("DROP-DOWN",["ABOUT", "GNN predict"], key='1')
input = None
clicked_predict = None
clicked_refine = None
# OPTION 1 ABOUT
if select == "ABOUT":
st.image(image)
st.text("Computational analysis of nucleic acids structures using Graph Neural Networks")
st.text("Simulation-Driven Structure Design Laboratory, Seoul National University")
st.write('\n')
st.markdown('<p style="font-size: 32px;">Dna Origami Graph Neural Networks</p>', unsafe_allow_html=True)
st.text("Deep SNUPI is a graph neural networks model to predict the three-dimensional shape of DNA origami assemblies.")
st.text("It was trained by hybrid data-driven and physics-informed approach.")
#OPTION 2 ENSEMBLE MODEL PREDICT
elif select == "GNN predict":
# File upload
col1, col2 = st.columns(2)
col1.write("###")
col1.markdown("Please select input samples or upload your own input files")
input_type = col1.selectbox('Input options',(None, "Upload input", "Input samples"))
dna = None
# select samples from dataset
if input_type == "Input samples":
user_input = False
col1.markdown("👈 Click the arrow on left to select processed input data")
select_processed_file = st.sidebar.selectbox( 'Input samples',
(None,
"DX_Honeycomb_42bp",
"DX_Cross_63bp",
"DX_Arrowhead_63bp",
"DX_Annulus_42bp",
"DX_Sided_Polygon_126bp",
"2006_Rothemund_square",
"2009_Nature_railedbridge",
"2009_Science_Spiral_JY",
"2012_NAR_32hb_21xx",
"2012_NAR_32hb_42xx",
"2012_NAR_32hb_63xx",
"2012_NAR_32hb_84xx",
"2012_NAR_A",
"2012_NAR_S",
"2017_NatComm_10_L3R1_2hb_168ds",
"2019_ACS_Nano_Spring_01_6HB",
"2019_ACS_Nano_Spring_02_12HB",
"2019_ACS_Nano_Spring_03_24HB",
"2019_ACSnano_C_08_A01_6hb_twisted_1IH0L6_nBT_14B",
"2019_NAR_8_2INS_FLEX_2",
"2020_AngChem_8SQ_All_02T",
"2020_NatComm_TwistTower_TWCR_mod_delBPHJ",
"2021_ACSnano_Sq_10HB_Hollow_13_1id_3gap_twcorr",
"2021_ACSnano_Sq_12HB_0id_0gap_twcorr_scaffconn",
"Gyroelon_Penta_Pyramid_6HB_42bp",
"Triang_Bipyramid_6HB_126bp",
"Penta_Bipyramid_6HB_42bp",
"Square_Gyrobicupola_6HB_42bp",
"2009_JACS_8Layer",
"2009_NAR_6x10",
"2009_Nature_genie_bottle",
"2009_Science_bent_60",
"2009_Science_gear_90",
"2017_Nature_Triangle",
"2017_Nature_V_22_55",
"2017_Nature_V_Emboss_01",
"2017_NatComm_L3_420ds",
"2017_NatComm_M1_2hb_252ds",
"2017_NatComm_M1M3_2hb_252ds",
"2017_NatComm_M1M3_2hb_168ds",
"2017_NatComm_M2R1_2hb_12nt",
"2017_NatComm_L3R1_2hb_triangle",
"2017_NatComm_M2_315ds_75deg",
"2017_NatComm_M2_441ds_120deg",
"2018_NatComm_Curved_Q",
"2019_NAR_2_Flexible",
"2019_ACSNano_12SQ",
"2019_ACSNano_Ins_H0L6_02",
"2019_ACSNano_Ins_H0L6_18",
"2019_ACSNano_Ins_H6L0_04",
"2019_ACSNano_Ins_H3L3_06",
"2019_ACSNano_Tetrahedron_84bp",
"2019_ACSNano_Cube_84bp",
"2019_ACSNano_Cubeocta_84bp",
"2019_ACSNano_Trunc_Tetra_63bp",
"2019_ACSNano_Triang_Bipyramid_63bp",
"2019_ACSNano_Penta_Bipyramid_105bp",
"2019_ACSNano_Rhom_Dodeca_63bp",
"2019_ACSNano_Tria_Tetra_84bp",
"2019_ACSNano_Twisted_Tri_Prism_42bp",
"2019_SciAdv_04_Wheel_DX_73bp",
"2019_SciAdv_06_Rhombic_Tiling_DX_42bp",
"2019_SciAdv_13_Hexagonal_Tiling_DX_63bp",
"2019_SciAdv_14_Prismatic_Penta_Tiling_DX_52bp",
"2019_SciAdv_16_4_Sided_Polygon_DX_73bp",
"2019_SciAdv_16_4_Sided_Polygon_DX_105bp",
"2019_SciAdv_17_5_Sided_Polygon_DX_73bp",
"2019_SciAdv_18_6_Sided_Polygon_DX_115bp",
"2019_SciAdv_19_L_Shape_42bp_DX_52bp",
"2020_NatComm_Pointer_v2",
"2020_NatComm_Dumbell_v2",
"2020_NatComm_HB_v3",
"2020_NatComm_6HBv3",
"2020_AngChem_8SQ_08T",
"2021_ACSNano_Sq_12HB_2gap",
))
if select_processed_file is not None:
file_name = select_processed_file
dna = get_input("./dataset/origami/snupi_input_samples/" + select_processed_file)
# select upload data from users
elif input_type == "Upload input":
file_upload = col1.expander(label="Upload a design file")
uploaded_file = file_upload.file_uploader("(Please upload your own input file from SNUPI)")
col1.markdown('***')
# Save it as temp file
dna = None
user_input = True
file_name = None
if uploaded_file:
user_input = True
try:
temp_filename = "./dataset/user_input/temp.mat"
with open(temp_filename, "wb") as f:
f.write(uploaded_file.getbuffer())
dna = get_input(temp_filename)
except:
temp_filename = "./dataset/user_input/temp.pt"
with open(temp_filename, "wb") as f:
f.write(uploaded_file.getbuffer())
dna = torch.load(temp_filename).to("cpu")
file_name = uploaded_file.name
num_refine_steps = st.sidebar.number_input('Number of self-refinement steps', min_value=200, max_value=1000, step=100)
if dna is not None:
# Initial evaluation structural energies
PE_init, SE_init, EE_init = total_PE(dna.x, dna)
# visualize initial configuration
fig_init = draw_DnaOrigami(dna, dna.x[:,0:6], SE_init, EE_init)
fig_init.update_layout(height=400)
col2.plotly_chart(fig_init, use_container_width=True, height=400)
# Trial prediction Trial prediction by Ensemble model
clicked_predict = st.button('Predict')
clicked_refinement = st.button('Predict with Self-refinement (GPU recommend)')
y_trial, rmsd_trial, best_model_name, runtime = get_model_prediction(dna, user_input, file_name=file_name, device=device)
# trial prediction
if clicked_predict:
st.write("Prediction on " + device_name)
PE_trial, SE_trial, EE_trial = total_PE(y_trial, dna)
print("Best model performance: " + best_model_name)
print("Init : Strain energy = %.2e[pNnm] | elec. energy = %.2e[pNnm]" %(SE_init, EE_init))
print("Trial : Strain energy = %.2e[pNnm] | elec. energy = %.2e[pNnm]" %(SE_trial, EE_trial))
fig_trial = draw_DnaOrigami(dna, y_trial[:, 0:6], SE_trial, EE_trial)
fig_trial.update_layout(height=800)
st.write("Predicted configuration: (runtime = %.1fs)" %(runtime))
st.plotly_chart(fig_trial, use_container_width=True, height=800)
if clicked_refinement:
st.write("Self-refinement processing on " + device_name)
try:
y_refine, rmsd_refine, run_time = self_refinement(dna, best_model_name, lr=5e-5, num_steps=num_refine_steps,
file_name=file_name, device=device)
except:
y_refine, rmsd_refine, run_time = self_refinement(dna, best_model_name, num_steps=num_refine_steps, file_name=file_name, device='cpu')
st.write("Refinement configuration: (runtime = %.1fs)" %(run_time))
PE_refine, SE_refine, EE_refine = total_PE(y_refine, dna)
fig_refine = draw_DnaOrigami(dna, y_refine[:,0:6], SE_refine, EE_refine)
fig_refine.update_layout(height=800)
print("Best model performance: " + best_model_name)
print("Init : Strain energy = %.2e[pNnm] | elec. energy = %.2e[pNnm]" %(SE_init, EE_init))
print("Refine: Strain energy = %.2e[pNnm] | elec. energy = %.2e[pNnm]" %(SE_refine, EE_refine))
st.plotly_chart(fig_refine, use_container_width=True, height=800)