Spaces:
Running
on
Zero
Running
on
Zero
attempt to fix the visualizer
Browse files
app.py
CHANGED
@@ -236,17 +236,14 @@ def visualize_after_pred(protein: ESMProtein, aligned: ESMProtein):
|
|
236 |
if aligned is None:
|
237 |
return None
|
238 |
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
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 = ""
|
@@ -289,28 +286,25 @@ def run_prediction(pdb_file, num_runs, noise_level, num_frames, progress=gr.Prog
|
|
289 |
return "Please upload a PDB file.", "No file uploaded", "", ""
|
290 |
|
291 |
progress(0, desc="Starting prediction")
|
292 |
-
|
293 |
steric_clash_text, norm_steric_clash_text = calculate_clashes_for_pdb(pdb_file)
|
294 |
-
if
|
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"""
|
299 |
-
<
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
viewer.addModel({json.dumps(view_data['pdb'])}, "pdb");
|
305 |
-
viewer.setStyle({{}}, {json.dumps(view_data['style'])});
|
306 |
-
viewer.zoomTo();
|
307 |
-
viewer.render();
|
308 |
-
</script>
|
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()
|
|
|
236 |
if aligned is None:
|
237 |
return None
|
238 |
|
239 |
+
view = py3Dmol.view(width=800, height=600)
|
240 |
+
view.addModel(protein_to_pdb(protein), "pdb")
|
241 |
+
view.setStyle({"cartoon": {"color": "lightgrey"}})
|
242 |
+
view.addModel(protein_to_pdb(aligned), "pdb")
|
243 |
+
view.setStyle({"model": -1}, {"cartoon": {"color": "lightgreen"}})
|
244 |
+
view.zoomTo()
|
245 |
|
246 |
+
return view
|
|
|
|
|
|
|
247 |
|
248 |
def protein_to_pdb(protein: ESMProtein):
|
249 |
pdb_str = ""
|
|
|
286 |
return "Please upload a PDB file.", "No file uploaded", "", ""
|
287 |
|
288 |
progress(0, desc="Starting prediction")
|
289 |
+
view, crmsd_text = prediction_visualization(pdb_file, num_runs, noise_level, num_frames, progress)
|
290 |
steric_clash_text, norm_steric_clash_text = calculate_clashes_for_pdb(pdb_file)
|
291 |
+
if view is None:
|
292 |
return "No successful predictions were made. Try adjusting the parameters or check the PDB file.", crmsd_text, steric_clash_text, norm_steric_clash_text
|
293 |
|
294 |
progress(0.9, desc="Rendering visualization")
|
295 |
+
|
296 |
+
# Convert the py3Dmol view to HTML
|
297 |
+
view_html = view._make_html().replace("'", '"')
|
298 |
html_content = f"""
|
299 |
+
<iframe style="width: 100%; height: 600px;" name="result" allow="midi; geolocation; microphone; camera;
|
300 |
+
display-capture; encrypted-media;" sandbox="allow-modals allow-forms
|
301 |
+
allow-scripts allow-same-origin allow-popups
|
302 |
+
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
303 |
+
allowpaymentrequest="" frameborder="0" srcdoc='<!DOCTYPE html><html>{view_html}</html>'></iframe>
|
|
|
|
|
|
|
|
|
|
|
|
|
304 |
"""
|
305 |
+
|
306 |
progress(1.0, desc="Completed")
|
307 |
return html_content, crmsd_text, steric_clash_text, norm_steric_clash_text
|
|
|
308 |
except Exception as e:
|
309 |
error_message = str(e)
|
310 |
stack_trace = traceback.format_exc()
|