Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -15,7 +15,6 @@ Website: https://bioprime.one
|
|
| 15 |
"""
|
| 16 |
|
| 17 |
import gradio as gr
|
| 18 |
-
import py3Dmol
|
| 19 |
import requests
|
| 20 |
import json
|
| 21 |
import hashlib
|
|
@@ -184,33 +183,64 @@ def fetch_pdb_structure(pdb_id: str) -> Optional[str]:
|
|
| 184 |
|
| 185 |
|
| 186 |
def create_3d_viewer(pdb_content: str, binding_site: dict = None, style: str = "cartoon") -> str:
|
| 187 |
-
"""Create 3D molecular viewer HTML."""
|
| 188 |
-
|
| 189 |
-
view.addModel(pdb_content, "pdb")
|
| 190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
if style == "cartoon":
|
| 192 |
-
|
| 193 |
elif style == "surface":
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
| 196 |
elif style == "stick":
|
| 197 |
-
|
| 198 |
elif style == "sphere":
|
| 199 |
-
|
|
|
|
|
|
|
| 200 |
|
| 201 |
-
#
|
|
|
|
| 202 |
if binding_site:
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
|
| 216 |
def generate_docking_result(target_id: str, compound_ids: List[str]) -> Tuple[str, str, str]:
|
|
|
|
| 15 |
"""
|
| 16 |
|
| 17 |
import gradio as gr
|
|
|
|
| 18 |
import requests
|
| 19 |
import json
|
| 20 |
import hashlib
|
|
|
|
| 183 |
|
| 184 |
|
| 185 |
def create_3d_viewer(pdb_content: str, binding_site: dict = None, style: str = "cartoon") -> str:
|
| 186 |
+
"""Create 3D molecular viewer HTML with embedded 3Dmol.js library."""
|
| 187 |
+
import html
|
|
|
|
| 188 |
|
| 189 |
+
# Escape PDB content for JavaScript
|
| 190 |
+
pdb_escaped = html.escape(pdb_content).replace('\n', '\\n').replace('\r', '').replace("'", "\\'")
|
| 191 |
+
|
| 192 |
+
# Build style configuration
|
| 193 |
if style == "cartoon":
|
| 194 |
+
style_js = "viewer.setStyle({}, {cartoon: {color: 'spectrum'}});"
|
| 195 |
elif style == "surface":
|
| 196 |
+
style_js = """
|
| 197 |
+
viewer.setStyle({}, {cartoon: {color: 'spectrum'}});
|
| 198 |
+
viewer.addSurface($3Dmol.SAS, {opacity: 0.7, color: 'white'});
|
| 199 |
+
"""
|
| 200 |
elif style == "stick":
|
| 201 |
+
style_js = "viewer.setStyle({}, {stick: {colorscheme: 'Jmol'}});"
|
| 202 |
elif style == "sphere":
|
| 203 |
+
style_js = "viewer.setStyle({}, {sphere: {colorscheme: 'Jmol', scale: 0.3}});"
|
| 204 |
+
else:
|
| 205 |
+
style_js = "viewer.setStyle({}, {cartoon: {color: 'spectrum'}});"
|
| 206 |
|
| 207 |
+
# Binding site sphere
|
| 208 |
+
binding_site_js = ""
|
| 209 |
if binding_site:
|
| 210 |
+
binding_site_js = f"""
|
| 211 |
+
viewer.addSphere({{
|
| 212 |
+
center: {{x: {binding_site['x']}, y: {binding_site['y']}, z: {binding_site['z']}}},
|
| 213 |
+
radius: 8,
|
| 214 |
+
color: 'red',
|
| 215 |
+
opacity: 0.3
|
| 216 |
+
}});
|
| 217 |
+
"""
|
| 218 |
+
|
| 219 |
+
# Generate unique ID for the viewer
|
| 220 |
+
import random
|
| 221 |
+
viewer_id = f"viewer_{random.randint(100000, 999999)}"
|
| 222 |
+
|
| 223 |
+
html_content = f'''
|
| 224 |
+
<div style="width: 100%; display: flex; justify-content: center;">
|
| 225 |
+
<div id="{viewer_id}" style="width: 700px; height: 500px; position: relative; border-radius: 12px; overflow: hidden; background: #1a1a2e;"></div>
|
| 226 |
+
</div>
|
| 227 |
+
<script src="https://3dmol.org/build/3Dmol-min.js"></script>
|
| 228 |
+
<script>
|
| 229 |
+
(function() {{
|
| 230 |
+
var pdbData = '{pdb_escaped}';
|
| 231 |
+
var element = document.getElementById('{viewer_id}');
|
| 232 |
+
var config = {{ backgroundColor: '0x1a1a2e' }};
|
| 233 |
+
var viewer = $3Dmol.createViewer(element, config);
|
| 234 |
+
viewer.addModel(pdbData, "pdb");
|
| 235 |
+
{style_js}
|
| 236 |
+
{binding_site_js}
|
| 237 |
+
viewer.zoomTo();
|
| 238 |
+
viewer.render();
|
| 239 |
+
}})();
|
| 240 |
+
</script>
|
| 241 |
+
'''
|
| 242 |
+
|
| 243 |
+
return html_content
|
| 244 |
|
| 245 |
|
| 246 |
def generate_docking_result(target_id: str, compound_ids: List[str]) -> Tuple[str, str, str]:
|