Tonic commited on
Commit
9b5ec9d
·
unverified ·
1 Parent(s): 48b33b5

add steric clash results and fix visualization

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -243,7 +243,10 @@ def visualize_after_pred(protein: ESMProtein, aligned: ESMProtein):
243
  viewer.setStyle({"model": -1}, {"cartoon": {"color": "lightgreen"}})
244
  viewer.zoomTo()
245
 
246
- return viewer.render()
 
 
 
247
 
248
  def protein_to_pdb(protein: ESMProtein):
249
  pdb_str = ""
@@ -283,13 +286,13 @@ def prediction_visualization(pdb_file, num_runs: int, noise_level: float, num_fr
283
  def run_prediction(pdb_file, num_runs, noise_level, num_frames, progress=gr.Progress()):
284
  try:
285
  if pdb_file is None:
286
- return "Please upload a PDB file.", "No file uploaded"
287
 
288
  progress(0, desc="Starting prediction")
289
  view_data, crmsd_text = prediction_visualization(pdb_file, num_runs, noise_level, num_frames, progress)
290
- steric_clash_text, norm_steric_clas_text = calculate_clashes_for_pdb(pdb_file)
291
  if view_data is None:
292
- return "No successful predictions were made. Try adjusting the parameters or check the PDB file.", crmsd_text
293
 
294
  progress(0.9, desc="Rendering visualization")
295
  html_content = f"""
@@ -306,7 +309,8 @@ def run_prediction(pdb_file, num_runs, noise_level, num_frames, progress=gr.Prog
306
  </div>
307
  """
308
  progress(1.0, desc="Completed")
309
- return html_content, crmsd_text, steric_clash_text, norm_steric_clas_text
 
310
  except Exception as e:
311
  error_message = str(e)
312
  stack_trace = traceback.format_exc()
@@ -317,8 +321,8 @@ def run_prediction(pdb_file, num_runs, noise_level, num_frames, progress=gr.Prog
317
  <h4>Stack Trace:</h4>
318
  <pre>{stack_trace}</pre>
319
  </div>
320
- """, "Error occurred"
321
-
322
  def create_demo():
323
  with gr.Blocks() as demo:
324
  gr.Markdown("# Protein Structure Prediction and Visualization with Noise and MD Frames")
@@ -334,13 +338,16 @@ def create_demo():
334
  with gr.Column(scale=2):
335
  visualization = gr.HTML(label="3D Visualization")
336
  alignment_result = gr.Textbox(label="Alignment Result")
 
 
337
 
338
  run_button.click(
339
  fn=run_prediction,
340
  inputs=[pdb_file, num_runs, noise_level, num_frames],
341
- outputs=[visualization, alignment_result]
342
  )
343
 
 
344
  gr.Markdown("""
345
  ## How to use
346
  1. Upload a PDB file using the file uploader.
 
243
  viewer.setStyle({"model": -1}, {"cartoon": {"color": "lightgreen"}})
244
  viewer.zoomTo()
245
 
246
+ return {
247
+ "pdb": protein_to_pdb(protein) + protein_to_pdb(aligned),
248
+ "style": {"cartoon": {"color": "spectrum"}}
249
+ }
250
 
251
  def protein_to_pdb(protein: ESMProtein):
252
  pdb_str = ""
 
286
  def run_prediction(pdb_file, num_runs, noise_level, num_frames, progress=gr.Progress()):
287
  try:
288
  if pdb_file is None:
289
+ return "Please upload a PDB file.", "No file uploaded", "", ""
290
 
291
  progress(0, desc="Starting prediction")
292
  view_data, crmsd_text = prediction_visualization(pdb_file, num_runs, noise_level, num_frames, progress)
293
+ steric_clash_text, norm_steric_clash_text = calculate_clashes_for_pdb(pdb_file)
294
  if view_data is None:
295
+ return "No successful predictions were made. Try adjusting the parameters or check the PDB file.", crmsd_text, steric_clash_text, norm_steric_clash_text
296
 
297
  progress(0.9, desc="Rendering visualization")
298
  html_content = f"""
 
309
  </div>
310
  """
311
  progress(1.0, desc="Completed")
312
+ return html_content, crmsd_text, steric_clash_text, norm_steric_clash_text
313
+
314
  except Exception as e:
315
  error_message = str(e)
316
  stack_trace = traceback.format_exc()
 
321
  <h4>Stack Trace:</h4>
322
  <pre>{stack_trace}</pre>
323
  </div>
324
+ """, "Error occurred", "", ""
325
+
326
  def create_demo():
327
  with gr.Blocks() as demo:
328
  gr.Markdown("# Protein Structure Prediction and Visualization with Noise and MD Frames")
 
338
  with gr.Column(scale=2):
339
  visualization = gr.HTML(label="3D Visualization")
340
  alignment_result = gr.Textbox(label="Alignment Result")
341
+ steric_clash_result = gr.Textbox(label="Steric Clash Result")
342
+ norm_steric_clash_result = gr.Textbox(label="Normalized Steric Clash Result")
343
 
344
  run_button.click(
345
  fn=run_prediction,
346
  inputs=[pdb_file, num_runs, noise_level, num_frames],
347
+ outputs=[visualization, alignment_result, steric_clash_result, norm_steric_clash_result]
348
  )
349
 
350
+
351
  gr.Markdown("""
352
  ## How to use
353
  1. Upload a PDB file using the file uploader.