Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,69 @@ from proteins_viz import *
|
|
5 |
import gradio as gr
|
6 |
import spaces
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def convert_outputs_to_pdb(outputs):
|
9 |
final_atom_positions = atom14_to_atom37(outputs["positions"][-1], outputs)
|
10 |
outputs = {k: v.to("cpu").numpy() for k, v in outputs.items()}
|
@@ -50,18 +113,19 @@ def fold_protein(test_protein):
|
|
50 |
with open("output_structure.pdb", "w") as f:
|
51 |
f.write("".join(pdb))
|
52 |
image = take_care("output_structure.pdb")
|
53 |
-
|
|
|
54 |
|
55 |
iface = gr.Interface(
|
56 |
title="everything-ai-proteinfold",
|
57 |
fn=fold_protein,
|
58 |
inputs=gr.Textbox(
|
59 |
label="Protein Sequence",
|
60 |
-
info="Find sequences examples below, and complete examples with images at: https://github.com/AstraBert/proteinviz/tree/main/examples.md; if you input a sequence, you're gonna get the static image and the
|
61 |
lines=5,
|
62 |
value=f"Paste or write amino-acidic sequence here",
|
63 |
),
|
64 |
-
outputs=[gr.Image(label="Protein static image"), gr.
|
65 |
examples=[
|
66 |
"MVHLTPEEKSAVTALWGKVNVDEVGGEALGRLLVVYPWTQRFFESFGDLSTPDAVMGNPKVKAHGKKVLGAFSDGLAHLDNLKGTFATLSELHCDKLHVDPENFRLLGNVLVCVLAHHFGKEFTPPVQAAYQKVVAGVANALAHKYH",
|
67 |
"MTEYKLVVVGAGGVGKSALTIQLIQNHFVDEYDPTIEDSYRKQVVIDGETCLLDILDTAGQEEYSAMRDQYMRTGEGFLCVFAINNTKSFEDIHQYREQIKRVKDSDDVPMVLVGNKCDLAARTVESRQAQDLARSYGIPYIETSAKTRQGVEDAFYTLVREIRQHKLRKLNPPDESGPGCMSCKCVLS",
|
|
|
5 |
import gradio as gr
|
6 |
import spaces
|
7 |
|
8 |
+
def read_mol(molpath):
|
9 |
+
with open(molpath, "r") as fp:
|
10 |
+
lines = fp.readlines()
|
11 |
+
mol = ""
|
12 |
+
for l in lines:
|
13 |
+
mol += l
|
14 |
+
return mol
|
15 |
+
|
16 |
+
|
17 |
+
def molecule(input_pdb):
|
18 |
+
|
19 |
+
mol = read_mol(input_pdb)
|
20 |
+
|
21 |
+
x = (
|
22 |
+
"""<!DOCTYPE html>
|
23 |
+
<html>
|
24 |
+
<head>
|
25 |
+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
26 |
+
<style>
|
27 |
+
body{
|
28 |
+
font-family:sans-serif
|
29 |
+
}
|
30 |
+
.mol-container {
|
31 |
+
width: 100%;
|
32 |
+
height: 600px;
|
33 |
+
position: relative;
|
34 |
+
}
|
35 |
+
.mol-container select{
|
36 |
+
background-image:None;
|
37 |
+
}
|
38 |
+
</style>
|
39 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js" integrity="sha512-STof4xm1wgkfm7heWqFJVn58Hm3EtS31XFaagaa8VMReCXAkQnJZ+jEy8PCC/iT18dFy95WcExNHFTqLyp72eQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
40 |
+
<script src="https://3Dmol.csb.pitt.edu/build/3Dmol-min.js"></script>
|
41 |
+
</head>
|
42 |
+
<body>
|
43 |
+
<div id="container" class="mol-container"></div>
|
44 |
+
|
45 |
+
<script>
|
46 |
+
let pdb = `"""
|
47 |
+
+ mol
|
48 |
+
+ """`
|
49 |
+
|
50 |
+
$(document).ready(function () {
|
51 |
+
let element = $("#container");
|
52 |
+
let config = { backgroundColor: "white" };
|
53 |
+
let viewer = $3Dmol.createViewer(element, config);
|
54 |
+
viewer.addModel(pdb, "pdb");
|
55 |
+
viewer.getModel(0).setStyle({}, { cartoon: { colorscheme:"whiteCarbon" } });
|
56 |
+
viewer.zoomTo();
|
57 |
+
viewer.render();
|
58 |
+
viewer.zoom(0.8, 2000);
|
59 |
+
})
|
60 |
+
</script>
|
61 |
+
</body></html>"""
|
62 |
+
)
|
63 |
+
|
64 |
+
return f"""<iframe style="width: 100%; height: 600px" name="result" allow="midi; geolocation; microphone; camera;
|
65 |
+
display-capture; encrypted-media;" sandbox="allow-modals allow-forms
|
66 |
+
allow-scripts allow-same-origin allow-popups
|
67 |
+
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
68 |
+
allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
|
69 |
+
|
70 |
+
|
71 |
def convert_outputs_to_pdb(outputs):
|
72 |
final_atom_positions = atom14_to_atom37(outputs["positions"][-1], outputs)
|
73 |
outputs = {k: v.to("cpu").numpy() for k, v in outputs.items()}
|
|
|
113 |
with open("output_structure.pdb", "w") as f:
|
114 |
f.write("".join(pdb))
|
115 |
image = take_care("output_structure.pdb")
|
116 |
+
html = molecule("output_structure.pdb")
|
117 |
+
return image, html
|
118 |
|
119 |
iface = gr.Interface(
|
120 |
title="everything-ai-proteinfold",
|
121 |
fn=fold_protein,
|
122 |
inputs=gr.Textbox(
|
123 |
label="Protein Sequence",
|
124 |
+
info="Find sequences examples below, and complete examples with images at: https://github.com/AstraBert/proteinviz/tree/main/examples.md; if you input a sequence, you're gonna get the static image and the 3D model to explore and play with",
|
125 |
lines=5,
|
126 |
value=f"Paste or write amino-acidic sequence here",
|
127 |
),
|
128 |
+
outputs=[gr.Image(label="Protein static image"), gr.HTML(label="Protein 3D model")],
|
129 |
examples=[
|
130 |
"MVHLTPEEKSAVTALWGKVNVDEVGGEALGRLLVVYPWTQRFFESFGDLSTPDAVMGNPKVKAHGKKVLGAFSDGLAHLDNLKGTFATLSELHCDKLHVDPENFRLLGNVLVCVLAHHFGKEFTPPVQAAYQKVVAGVANALAHKYH",
|
131 |
"MTEYKLVVVGAGGVGKSALTIQLIQNHFVDEYDPTIEDSYRKQVVIDGETCLLDILDTAGQEEYSAMRDQYMRTGEGFLCVFAINNTKSFEDIHQYREQIKRVKDSDDVPMVLVGNKCDLAARTVESRQAQDLARSYGIPYIETSAKTRQGVEDAFYTLVREIRQHKLRKLNPPDESGPGCMSCKCVLS",
|