Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,32 +8,37 @@ from gradio_moleculeview import moleculeview
|
|
| 8 |
|
| 9 |
import cellscape
|
| 10 |
|
| 11 |
-
def predict(input_mol, style, contour_level, view_str, chains):
|
| 12 |
-
# write view to file
|
| 13 |
-
with open("view_matrix", "w") as f:
|
| 14 |
-
f.write(json.loads(view_str))
|
| 15 |
-
|
| 16 |
-
chain_str = ""
|
| 17 |
-
chain_dict = json.loads(chains)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
<button id="copyPngBtn" style="padding:4px;border:1px solid gray;margin:3px">Copy PNG to Clipboard</button>
|
| 38 |
|
| 39 |
<!-- Buttons for Download -->
|
|
@@ -127,10 +132,41 @@ document.getElementById('copyPngBtn').addEventListener('click', copyPngToClipboa
|
|
| 127 |
document.getElementById('downloadSvgBtn').addEventListener('click', downloadSvg);
|
| 128 |
document.getElementById('downloadPngBtn').addEventListener('click', downloadPng);
|
| 129 |
</script>
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
-
|
| 133 |
-
return f.read().replace("<svg", "<svg id='svgElement'")+html_output, "pdb_opt.svg"
|
| 134 |
|
| 135 |
|
| 136 |
|
|
|
|
| 8 |
|
| 9 |
import cellscape
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
def html_output(input_file):
|
| 13 |
+
with open(input_file, "r") as f:
|
| 14 |
+
svg = f.read().replace("<svg", "<svg id='svgElement'")
|
| 15 |
+
|
| 16 |
+
x = (
|
| 17 |
+
"""<!DOCTYPE html>
|
| 18 |
+
<html>
|
| 19 |
+
<head>
|
| 20 |
+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
| 21 |
+
<style>
|
| 22 |
+
body{
|
| 23 |
+
font-family:sans-serif
|
| 24 |
+
}
|
| 25 |
+
.mol-container {
|
| 26 |
+
width: 100%;
|
| 27 |
+
height: 600px;
|
| 28 |
+
position: relative;
|
| 29 |
+
}
|
| 30 |
+
.mol-container select{
|
| 31 |
+
background-image:None;
|
| 32 |
+
}
|
| 33 |
+
</style>
|
| 34 |
|
| 35 |
+
</head>
|
| 36 |
+
<body>
|
| 37 |
+
|
| 38 |
+
"""
|
| 39 |
+
+ svg
|
| 40 |
+
+ """
|
| 41 |
+
<button id="copySvgBtn" style="padding:4px;border:1px solid gray;margin:3px">Copy SVG to Clipboard</button>
|
| 42 |
<button id="copyPngBtn" style="padding:4px;border:1px solid gray;margin:3px">Copy PNG to Clipboard</button>
|
| 43 |
|
| 44 |
<!-- Buttons for Download -->
|
|
|
|
| 132 |
document.getElementById('downloadSvgBtn').addEventListener('click', downloadSvg);
|
| 133 |
document.getElementById('downloadPngBtn').addEventListener('click', downloadPng);
|
| 134 |
</script>
|
| 135 |
+
|
| 136 |
+
</body></html>"""
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
return f"""<iframe style="width: 100%; height: 600px" name="result" allow="midi; geolocation; microphone; camera;
|
| 140 |
+
display-capture; encrypted-media;" sandbox="allow-modals allow-forms
|
| 141 |
+
allow-scripts allow-same-origin allow-popups
|
| 142 |
+
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
| 143 |
+
allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
|
| 144 |
+
|
| 145 |
+
def predict(input_mol, style, contour_level, view_str, chains):
|
| 146 |
+
# write view to file
|
| 147 |
+
with open("view_matrix", "w") as f:
|
| 148 |
+
f.write(json.loads(view_str))
|
| 149 |
+
|
| 150 |
+
chain_str = ""
|
| 151 |
+
chain_dict = json.loads(chains)
|
| 152 |
+
|
| 153 |
+
# sort keys in dict and add colors to chain_str
|
| 154 |
+
for chain in sorted(chain_dict.keys()):
|
| 155 |
+
chain_str += f" '{chain_dict[chain]}'"
|
| 156 |
+
if style == "Goodsell3D":
|
| 157 |
+
os.system(f"cellscape cartoon --pdb {input_mol.name} --outline residue --color_by chain --depth_shading --depth_lines --colors {chain_str} --depth flat --back_outline --view view_matrix --save outline_all.svg")
|
| 158 |
+
elif style == "Contour":
|
| 159 |
+
os.system(f"cellscape cartoon --pdb {input_mol.name} --outline chain --color_by chain --depth_contour_interval {contour_level} --colors {chain_str} --depth contours --back_outline --view view_matrix --save outline_all.svg")
|
| 160 |
+
else:
|
| 161 |
+
os.system(f"cellscape cartoon --pdb {input_mol.name} --outline chain --colors {chain_str} --depth flat --back_outline --view view_matrix --save outline_all.svg")
|
| 162 |
+
|
| 163 |
+
#read content of file
|
| 164 |
+
print(os.stat("outline_all.svg").st_size / (1024 * 1024))
|
| 165 |
+
os.system("inkscape outline_all.svg --actions='select-all;path-simplify;export-plain-svg' --export-filename pdb_opt.svg")
|
| 166 |
+
print(os.stat("outline_all.svg").st_size / (1024 * 1024))
|
| 167 |
+
|
| 168 |
|
| 169 |
+
return html_output("outline_all.svg"), "pdb_opt.svg"
|
|
|
|
| 170 |
|
| 171 |
|
| 172 |
|