tagirshin commited on
Commit
2d13a08
1 Parent(s): 4a0267b

fixed progress bar

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -91,7 +91,7 @@ def on_generation_progress(ga):
91
  global ga_progress
92
  global ga_bar
93
  ga_progress = ga_progress + 1
94
- ga_bar.progress(ga_progress // num_generations * 100, text=ga_progress_text)
95
 
96
 
97
  @st.cache_data
@@ -120,11 +120,6 @@ def load_data(batch_size):
120
 
121
  st.title('Inverse QSAR of Tubulin with VQGAE')
122
 
123
- batch_size = 200
124
- X, Y, rf_model, vqgae_model, ordering_model = load_data(batch_size)
125
-
126
- assert X.shape == (603, 4096)
127
-
128
  with st.sidebar:
129
  with st.form("my_form"):
130
  num_generations = st.slider(
@@ -195,11 +190,14 @@ with st.sidebar:
195
  )
196
  # 2/3 of num_parents_mating
197
  use_ordering_score = st.toggle('Use ordering score', value=True)
198
-
199
  random_seed = int(st.number_input("Random seed", value=42, placeholder="Type a number..."))
200
  submit = st.form_submit_button('Start optimisation')
201
 
202
  if submit:
 
 
 
203
  ga_instance = pygad.GA(
204
  fitness_func=fitness_func_batch,
205
  on_generation=on_generation_progress,
@@ -244,8 +242,8 @@ if submit:
244
  rescoring_progress_text = "Rescoring obtained solutions"
245
  rescoring_bar = st.progress(0, text=rescoring_progress_text)
246
  total_rescoring_steps = len(unique_solutions) // batch_size + 1
247
- for i in range(total_rescoring_steps):
248
- vqgae_latents = unique_solutions[i * batch_size: (i + 1) * batch_size]
249
  frag_counts = np.array(vqgae_latents)
250
  rf_scores = rf_model.predict_proba(frag_counts)[:, 1]
251
  similarity_scores = tanimoto_kernel(frag_counts, X).max(-1)
@@ -255,7 +253,7 @@ if submit:
255
  frag_inds = frag_counts_to_inds(frag_counts, max_atoms=51)
256
  _, ordering_scores = restore_order(frag_inds, ordering_model)
257
  scores["ordering_score"].extend(ordering_scores)
258
- rescoring_bar.progress(i // total_rescoring_steps, text=rescoring_progress_text)
259
  sc_df = pd.DataFrame(scores)
260
  rescoring_bar.empty()
261
 
@@ -276,8 +274,8 @@ if submit:
276
  decoding_progress_text = "Decoding chosen solutions"
277
  decoding_bar = st.progress(0, text=decoding_progress_text)
278
  total_decoding_steps = gen_frag_inds.shape[0] // batch_size + 1
279
- for i in range(total_decoding_steps):
280
- inputs = gen_frag_inds[i * batch_size: (i + 1) * batch_size]
281
  canon_order_inds, scores = restore_order(
282
  frag_inds=inputs,
283
  ordering_model=ordering_model,
@@ -290,7 +288,7 @@ if submit:
290
  results["smiles"].extend([str(molecule) for molecule in molecules])
291
  results["ordering_score"].extend(scores)
292
  results["validity"].extend([1 if i else 0 for i in validity])
293
- decoding_bar.progress(i // total_decoding_steps, text=rescoring_progress_text)
294
  gen_stats = pd.DataFrame(results)
295
  decoding_bar.empty()
296
  full_stats = pd.concat([gen_stats, chosen_gen[["similarity_score", "rf_score"]].reset_index(), ], axis=1, ignore_index=False)
 
91
  global ga_progress
92
  global ga_bar
93
  ga_progress = ga_progress + 1
94
+ ga_bar.progress(ga_progress / num_generations, text=ga_progress_text)
95
 
96
 
97
  @st.cache_data
 
120
 
121
  st.title('Inverse QSAR of Tubulin with VQGAE')
122
 
 
 
 
 
 
123
  with st.sidebar:
124
  with st.form("my_form"):
125
  num_generations = st.slider(
 
190
  )
191
  # 2/3 of num_parents_mating
192
  use_ordering_score = st.toggle('Use ordering score', value=True)
193
+ batch_size = int(st.number_input("Random seed", value=200, placeholder="Type a number..."))
194
  random_seed = int(st.number_input("Random seed", value=42, placeholder="Type a number..."))
195
  submit = st.form_submit_button('Start optimisation')
196
 
197
  if submit:
198
+ X, Y, rf_model, vqgae_model, ordering_model = load_data(batch_size)
199
+ assert X.shape == (603, 4096)
200
+
201
  ga_instance = pygad.GA(
202
  fitness_func=fitness_func_batch,
203
  on_generation=on_generation_progress,
 
242
  rescoring_progress_text = "Rescoring obtained solutions"
243
  rescoring_bar = st.progress(0, text=rescoring_progress_text)
244
  total_rescoring_steps = len(unique_solutions) // batch_size + 1
245
+ for rescoring_step in range(total_rescoring_steps):
246
+ vqgae_latents = unique_solutions[rescoring_step * batch_size: (rescoring_step + 1) * batch_size]
247
  frag_counts = np.array(vqgae_latents)
248
  rf_scores = rf_model.predict_proba(frag_counts)[:, 1]
249
  similarity_scores = tanimoto_kernel(frag_counts, X).max(-1)
 
253
  frag_inds = frag_counts_to_inds(frag_counts, max_atoms=51)
254
  _, ordering_scores = restore_order(frag_inds, ordering_model)
255
  scores["ordering_score"].extend(ordering_scores)
256
+ rescoring_bar.progress(rescoring_step / total_rescoring_steps, text=rescoring_progress_text)
257
  sc_df = pd.DataFrame(scores)
258
  rescoring_bar.empty()
259
 
 
274
  decoding_progress_text = "Decoding chosen solutions"
275
  decoding_bar = st.progress(0, text=decoding_progress_text)
276
  total_decoding_steps = gen_frag_inds.shape[0] // batch_size + 1
277
+ for decoding_step in range(total_decoding_steps):
278
+ inputs = gen_frag_inds[decoding_step * batch_size: (decoding_step + 1) * batch_size]
279
  canon_order_inds, scores = restore_order(
280
  frag_inds=inputs,
281
  ordering_model=ordering_model,
 
288
  results["smiles"].extend([str(molecule) for molecule in molecules])
289
  results["ordering_score"].extend(scores)
290
  results["validity"].extend([1 if i else 0 for i in validity])
291
+ decoding_bar.progress(decoding_step / total_decoding_steps, text=decoding_progress_text)
292
  gen_stats = pd.DataFrame(results)
293
  decoding_bar.empty()
294
  full_stats = pd.concat([gen_stats, chosen_gen[["similarity_score", "rf_score"]].reset_index(), ], axis=1, ignore_index=False)