GotThatData commited on
Commit
d0325f0
·
verified ·
1 Parent(s): c916cff

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +665 -0
app.py ADDED
@@ -0,0 +1,665 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ BioPrime Molecular Docking Demo
3
+ ================================
4
+ Interactive demo showcasing AI-powered molecular docking for drug discovery.
5
+
6
+ Features:
7
+ - 3D protein structure visualization
8
+ - Compound library selection
9
+ - Docking simulation with binding energy results
10
+ - BSV blockchain verification display
11
+
12
+ Powered by: Origin Neural AI Docking Engine
13
+ Sponsored by: Smartledger Solutions, Origin Neural AI, Bryan Daugherty
14
+ Website: https://bioprime.one
15
+ """
16
+
17
+ import gradio as gr
18
+ import py3Dmol
19
+ import requests
20
+ import json
21
+ import hashlib
22
+ import random
23
+ from datetime import datetime
24
+ from typing import Optional, Dict, List, Tuple
25
+ import time
26
+
27
+ # =============================================================================
28
+ # Configuration
29
+ # =============================================================================
30
+
31
+ BIOPRIME_API = "https://bioprime.one/api/v1"
32
+ RCSB_PDB_URL = "https://files.rcsb.org/download"
33
+
34
+ # Demo targets with sponsored research campaigns
35
+ DEMO_TARGETS = [
36
+ {
37
+ "id": "melanoma",
38
+ "name": "BRAF V600E - Melanoma",
39
+ "pdb": "4MNE",
40
+ "sponsor": "Bryan Daugherty",
41
+ "disease": "Melanoma",
42
+ "description": "Mutated BRAF kinase found in ~50% of melanomas, target for vemurafenib-like inhibitors.",
43
+ "binding_site": {"x": 25.0, "y": 5.0, "z": 15.0},
44
+ "color": "#FF6B6B"
45
+ },
46
+ {
47
+ "id": "diabetes",
48
+ "name": "DPP-4 - Type 2 Diabetes",
49
+ "pdb": "2ONC",
50
+ "sponsor": "Bryan Daugherty",
51
+ "disease": "Type 2 Diabetes",
52
+ "description": "Dipeptidyl peptidase-4, target for incretin-based diabetes medications like sitagliptin.",
53
+ "binding_site": {"x": 35.0, "y": 40.0, "z": 45.0},
54
+ "color": "#4ECDC4"
55
+ },
56
+ {
57
+ "id": "covid",
58
+ "name": "COVID-19 Main Protease",
59
+ "pdb": "6LU7",
60
+ "sponsor": "BioPrime Community",
61
+ "disease": "COVID-19",
62
+ "description": "SARS-CoV-2 main protease (Mpro), essential for viral replication. Target for Paxlovid.",
63
+ "binding_site": {"x": -10.8, "y": 35.2, "z": 63.4},
64
+ "color": "#9B59B6"
65
+ },
66
+ {
67
+ "id": "hiv",
68
+ "name": "HIV-1 Protease",
69
+ "pdb": "1HVR",
70
+ "sponsor": "Origin Neural AI",
71
+ "disease": "HIV/AIDS",
72
+ "description": "Critical enzyme for HIV replication, target for protease inhibitor antiretroviral drugs.",
73
+ "binding_site": {"x": -6.2, "y": 20.1, "z": 41.8},
74
+ "color": "#E74C3C"
75
+ },
76
+ {
77
+ "id": "lung",
78
+ "name": "EGFR Kinase - Lung Cancer",
79
+ "pdb": "1M17",
80
+ "sponsor": "Smartledger & Origin Neural AI",
81
+ "disease": "Non-small Cell Lung Cancer",
82
+ "description": "Epidermal growth factor receptor, key target in NSCLC therapy. Target for erlotinib.",
83
+ "binding_site": {"x": 40.5, "y": 0.6, "z": 56.0},
84
+ "color": "#3498DB"
85
+ },
86
+ {
87
+ "id": "breast",
88
+ "name": "CDK4/6 - Breast Cancer",
89
+ "pdb": "5L2I",
90
+ "sponsor": "Smartledger",
91
+ "disease": "Breast Cancer",
92
+ "description": "Cyclin-dependent kinase 4/6 inhibitor target for hormone-receptor positive breast cancer.",
93
+ "binding_site": {"x": 15.0, "y": 25.0, "z": 35.0},
94
+ "color": "#E91E63"
95
+ },
96
+ ]
97
+
98
+ # Demo compound library
99
+ COMPOUND_LIBRARY = [
100
+ {"id": "aspirin", "name": "Aspirin", "smiles": "CC(=O)OC1=CC=CC=C1C(=O)O", "mw": 180.16, "category": "Anti-inflammatory"},
101
+ {"id": "ibuprofen", "name": "Ibuprofen", "smiles": "CC(C)CC1=CC=C(C=C1)C(C)C(=O)O", "mw": 206.29, "category": "Anti-inflammatory"},
102
+ {"id": "caffeine", "name": "Caffeine", "smiles": "CN1C=NC2=C1C(=O)N(C(=O)N2C)C", "mw": 194.19, "category": "Stimulant"},
103
+ {"id": "paracetamol", "name": "Acetaminophen", "smiles": "CC(=O)NC1=CC=C(O)C=C1", "mw": 151.16, "category": "Analgesic"},
104
+ {"id": "metformin", "name": "Metformin", "smiles": "CN(C)C(=N)NC(=N)N", "mw": 129.17, "category": "Antidiabetic"},
105
+ {"id": "atorvastatin", "name": "Atorvastatin", "smiles": "CC(C)C1=C(C(=C(N1CCC(CC(CC(=O)O)O)O)C2=CC=C(C=C2)F)C3=CC=CC=C3)C(=O)NC4=CC=CC=C4", "mw": 558.64, "category": "Statin"},
106
+ {"id": "nirmatrelvir", "name": "Nirmatrelvir", "smiles": "CC1(CC1)C(=O)NC(CC2CCNC2=O)C(=O)NC(CC(F)(F)F)C#N", "mw": 499.53, "category": "Antiviral (COVID-19)"},
107
+ {"id": "oseltamivir", "name": "Oseltamivir", "smiles": "CCOC(=O)C1=CC(OC(CC)CC)C(NC(C)=O)C(N)C1", "mw": 312.41, "category": "Antiviral (Flu)"},
108
+ {"id": "remdesivir", "name": "Remdesivir", "smiles": "CCC(CC)COC(=O)C(C)NP(=O)(OCC1C(C(C(O1)N2C=CC(=O)NC2=O)O)O)OC3=CC=CC=C3", "mw": 602.58, "category": "Antiviral"},
109
+ {"id": "sitagliptin", "name": "Sitagliptin", "smiles": "NC(CC(=O)N1CCN2C(C1)=NN=C2C(F)(F)F)CC1=C(F)C=C(F)C(F)=C1F", "mw": 407.31, "category": "Antidiabetic (DPP-4)"},
110
+ {"id": "vemurafenib", "name": "Vemurafenib", "smiles": "CCCS(=O)(=O)NC1=CC=C(C=C1)C2=NC(=C(S2)C3=CC(=NC=C3)NC4=CC=C(C=C4)Cl)C#N", "mw": 489.93, "category": "Kinase Inhibitor (Melanoma)"},
111
+ {"id": "erlotinib", "name": "Erlotinib", "smiles": "COCCOC1=C(C=C2C(=C1)C(=NC=N2)NC3=CC(=C(C=C3)F)Cl)OCCOC", "mw": 393.44, "category": "EGFR Inhibitor"},
112
+ ]
113
+
114
+ # Pre-computed docking results (simulated but realistic)
115
+ PRECOMPUTED_RESULTS = {
116
+ "melanoma": {
117
+ "vemurafenib": -9.8,
118
+ "erlotinib": -7.2,
119
+ "caffeine": -4.1,
120
+ "aspirin": -5.3,
121
+ "ibuprofen": -5.8,
122
+ },
123
+ "diabetes": {
124
+ "sitagliptin": -10.2,
125
+ "metformin": -6.8,
126
+ "caffeine": -4.5,
127
+ "aspirin": -4.9,
128
+ "ibuprofen": -5.1,
129
+ },
130
+ "covid": {
131
+ "nirmatrelvir": -8.9,
132
+ "remdesivir": -7.6,
133
+ "caffeine": -5.2,
134
+ "aspirin": -4.8,
135
+ "oseltamivir": -6.4,
136
+ },
137
+ "hiv": {
138
+ "remdesivir": -7.8,
139
+ "oseltamivir": -6.2,
140
+ "caffeine": -4.3,
141
+ "aspirin": -4.5,
142
+ "atorvastatin": -6.9,
143
+ },
144
+ "lung": {
145
+ "erlotinib": -9.4,
146
+ "vemurafenib": -7.1,
147
+ "caffeine": -4.0,
148
+ "aspirin": -4.7,
149
+ "atorvastatin": -6.5,
150
+ },
151
+ "breast": {
152
+ "atorvastatin": -7.3,
153
+ "erlotinib": -6.8,
154
+ "caffeine": -4.2,
155
+ "aspirin": -4.4,
156
+ "metformin": -5.1,
157
+ },
158
+ }
159
+
160
+ # =============================================================================
161
+ # Helper Functions
162
+ # =============================================================================
163
+
164
+ def fetch_pdb_structure(pdb_id: str) -> Optional[str]:
165
+ """Fetch PDB structure from RCSB."""
166
+ try:
167
+ # Try BioPrime API first
168
+ response = requests.get(f"{BIOPRIME_API}/docking/demo/pdb/{pdb_id}", timeout=10)
169
+ if response.status_code == 200:
170
+ data = response.json()
171
+ return data.get("pdb_content", data.get("pdb_data", None))
172
+ except:
173
+ pass
174
+
175
+ # Fallback to RCSB
176
+ try:
177
+ response = requests.get(f"{RCSB_PDB_URL}/{pdb_id}.pdb", timeout=10)
178
+ if response.status_code == 200:
179
+ return response.text
180
+ except:
181
+ pass
182
+
183
+ return None
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
+ view = py3Dmol.view(width=700, height=500)
189
+ view.addModel(pdb_content, "pdb")
190
+
191
+ if style == "cartoon":
192
+ view.setStyle({'cartoon': {'color': 'spectrum'}})
193
+ elif style == "surface":
194
+ view.setStyle({'cartoon': {'color': 'spectrum'}})
195
+ view.addSurface(py3Dmol.SAS, {'opacity': 0.7, 'color': 'white'})
196
+ elif style == "stick":
197
+ view.setStyle({'stick': {'colorscheme': 'Jmol'}})
198
+ elif style == "sphere":
199
+ view.setStyle({'sphere': {'colorscheme': 'Jmol', 'scale': 0.3}})
200
+
201
+ # Highlight binding site if provided
202
+ if binding_site:
203
+ view.addSphere({
204
+ 'center': {'x': binding_site['x'], 'y': binding_site['y'], 'z': binding_site['z']},
205
+ 'radius': 8,
206
+ 'color': 'red',
207
+ 'opacity': 0.3
208
+ })
209
+
210
+ view.zoomTo()
211
+ view.spin(False)
212
+
213
+ return view._make_html()
214
+
215
+
216
+ def generate_docking_result(target_id: str, compound_ids: List[str]) -> Tuple[str, str, str]:
217
+ """
218
+ Simulate docking and return results.
219
+ Returns: (results_text, binding_chart_data, receipt)
220
+ """
221
+ target = next((t for t in DEMO_TARGETS if t["id"] == target_id), None)
222
+ if not target:
223
+ return "Target not found", "", ""
224
+
225
+ results = []
226
+ precomputed = PRECOMPUTED_RESULTS.get(target_id, {})
227
+
228
+ for comp_id in compound_ids:
229
+ compound = next((c for c in COMPOUND_LIBRARY if c["id"] == comp_id), None)
230
+ if not compound:
231
+ continue
232
+
233
+ # Use precomputed or generate realistic random
234
+ if comp_id in precomputed:
235
+ energy = precomputed[comp_id]
236
+ else:
237
+ # Generate realistic binding energy based on molecular weight
238
+ base_energy = -4.0 - (compound["mw"] / 100)
239
+ energy = round(base_energy + random.uniform(-1.5, 1.5), 2)
240
+
241
+ results.append({
242
+ "compound": compound["name"],
243
+ "smiles": compound["smiles"],
244
+ "energy": energy,
245
+ "mw": compound["mw"],
246
+ "category": compound["category"]
247
+ })
248
+
249
+ # Sort by binding energy (more negative = better)
250
+ results.sort(key=lambda x: x["energy"])
251
+
252
+ # Generate results text
253
+ results_text = f"""
254
+ ## Docking Results for {target['name']}
255
+
256
+ **Target Disease:** {target['disease']}
257
+ **Sponsor:** {target['sponsor']}
258
+ **PDB ID:** {target['pdb']}
259
+
260
+ ---
261
+
262
+ ### Top Binding Compounds
263
+
264
+ | Rank | Compound | Binding Energy | Category |
265
+ |------|----------|----------------|----------|
266
+ """
267
+
268
+ for i, r in enumerate(results[:10], 1):
269
+ emoji = "🏆" if i == 1 else "🥈" if i == 2 else "🥉" if i == 3 else " "
270
+ results_text += f"| {emoji} {i} | **{r['compound']}** | {r['energy']:.2f} kcal/mol | {r['category']} |\n"
271
+
272
+ results_text += f"""
273
+ ---
274
+
275
+ ### Interpretation
276
+
277
+ - **Best Hit:** {results[0]['compound']} with {results[0]['energy']:.2f} kcal/mol
278
+ - **Binding energies < -7 kcal/mol** indicate strong binding potential
279
+ - **Binding energies < -9 kcal/mol** suggest drug-like affinity
280
+
281
+ ---
282
+
283
+ *Powered by Origin Neural AI Docking Engine*
284
+ *Results simulated for demonstration - actual BioPrime uses GPU-accelerated physics*
285
+ """
286
+
287
+ # Generate chart data
288
+ chart_labels = [r["compound"][:12] for r in results[:8]]
289
+ chart_values = [abs(r["energy"]) for r in results[:8]]
290
+
291
+ chart_html = f"""
292
+ <div style="background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); padding: 20px; border-radius: 12px; margin-top: 10px;">
293
+ <h3 style="color: #4ECDC4; margin-bottom: 15px; text-align: center;">Binding Affinity Comparison</h3>
294
+ <div style="display: flex; align-items: flex-end; justify-content: space-around; height: 200px; padding: 10px;">
295
+ """
296
+
297
+ max_val = max(chart_values) if chart_values else 1
298
+ colors = ["#FF6B6B", "#4ECDC4", "#45B7D1", "#96CEB4", "#FFEAA7", "#DDA0DD", "#98D8C8", "#F7DC6F"]
299
+
300
+ for i, (label, val) in enumerate(zip(chart_labels, chart_values)):
301
+ height = int((val / max_val) * 150)
302
+ color = colors[i % len(colors)]
303
+ chart_html += f"""
304
+ <div style="display: flex; flex-direction: column; align-items: center; width: 60px;">
305
+ <span style="color: white; font-size: 11px; margin-bottom: 5px;">-{val:.1f}</span>
306
+ <div style="width: 40px; height: {height}px; background: {color}; border-radius: 4px 4px 0 0;"></div>
307
+ <span style="color: #888; font-size: 9px; margin-top: 5px; text-align: center; word-wrap: break-word; width: 55px;">{label}</span>
308
+ </div>
309
+ """
310
+
311
+ chart_html += """
312
+ </div>
313
+ <p style="color: #666; font-size: 11px; text-align: center; margin-top: 10px;">Binding Energy (kcal/mol) - Higher bars = stronger binding</p>
314
+ </div>
315
+ """
316
+
317
+ # Generate blockchain receipt
318
+ job_id = f"DEMO-{target_id.upper()}-{hashlib.md5(str(compound_ids).encode()).hexdigest()[:8]}"
319
+ data_hash = hashlib.sha256(json.dumps(results, sort_keys=True).encode()).hexdigest()
320
+
321
+ receipt = generate_demo_receipt(
322
+ job_id=job_id,
323
+ target_name=target['name'],
324
+ compounds_screened=len(compound_ids),
325
+ top_hits=len(results),
326
+ best_energy=results[0]['energy'] if results else 0,
327
+ data_hash=data_hash
328
+ )
329
+
330
+ return results_text, chart_html, receipt
331
+
332
+
333
+ def generate_demo_receipt(job_id: str, target_name: str, compounds_screened: int,
334
+ top_hits: int, best_energy: float, data_hash: str) -> str:
335
+ """Generate a demo blockchain receipt."""
336
+ timestamp = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
337
+ demo_txid = f"demo_{hashlib.md5(data_hash.encode()).hexdigest()[:48]}"
338
+
339
+ receipt = f"""
340
+ ╔══════════════════════════════════════════════════════════════════════════╗
341
+ ║ BIOPRIME DISCOVERY CERTIFICATE ║
342
+ ║ [DEMO - NOT ON CHAIN] ║
343
+ ╠══════════════════════════════════════════════════════════════════════════╣
344
+ ║ ║
345
+ ║ JOB ID: {job_id:<57} ║
346
+ ║ TARGET: {target_name[:47]:<57} ║
347
+ ║ ║
348
+ ╠══════════════════════════════════════════════════════════════════════════╣
349
+ ║ SCREENING RESULTS ║
350
+ ╠══════════════════════════════════════════════════════════════════════════╣
351
+ ║ ║
352
+ ║ Compounds Screened: {compounds_screened:<45} ║
353
+ ║ Top Poses Generated: {top_hits:<45} ║
354
+ ║ Best Binding Energy: {best_energy:.2f} kcal/mol{' ':<36} ║
355
+ ║ ║
356
+ ╠══════════════════════════════════════════════════════════════════════════╣
357
+ ║ VERIFICATION DETAILS ║
358
+ ╠══════════════════════════════════════════════════════════════════════════╣
359
+ ║ ║
360
+ ║ Timestamp: {timestamp:<53} ║
361
+ ║ Data Hash: sha256:{data_hash[:49]:<46} ║
362
+ ║ ║
363
+ ╠══════════════════════════════════════════════════════════════════════════╣
364
+ ║ BLOCKCHAIN VERIFICATION ║
365
+ ╠══════════════════════════════════════════════════════════════════════════╣
366
+ ║ ║
367
+ ║ Network: BSV (Bitcoin SV) - Demo Mode ║
368
+ ║ Status: Demo certificate - not anchored to blockchain ║
369
+ ║ ║
370
+ ║ For real blockchain-verified results, visit: ║
371
+ ║ https://bioprime.one ║
372
+ ║ ║
373
+ ╠══════════════════════════════════════════════════════════════════════════╣
374
+ ║ ║
375
+ ║ BioPrime anchors real docking results to the BSV blockchain for ║
376
+ ║ immutable proof of discovery. Sign up to run verified experiments. ║
377
+ ║ ║
378
+ ║ ━━━ bioprime.one ━━━ ║
379
+ ║ ║
380
+ ╚══════════════════════════════════════════════════════════════════════════╝
381
+ """
382
+ return receipt.strip()
383
+
384
+
385
+ # =============================================================================
386
+ # Gradio Interface
387
+ # =============================================================================
388
+
389
+ def view_protein(target_name: str, view_style: str) -> Tuple[str, str]:
390
+ """View selected protein structure."""
391
+ target = next((t for t in DEMO_TARGETS if t["name"] == target_name), None)
392
+ if not target:
393
+ return "<p>Please select a target</p>", ""
394
+
395
+ pdb_content = fetch_pdb_structure(target["pdb"])
396
+ if not pdb_content:
397
+ return f"<p style='color: red;'>Failed to fetch PDB structure for {target['pdb']}</p>", ""
398
+
399
+ viewer_html = create_3d_viewer(pdb_content, target.get("binding_site"), view_style.lower())
400
+
401
+ info_html = f"""
402
+ <div style="background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%); padding: 20px; border-radius: 12px; color: white;">
403
+ <h3 style="color: {target['color']}; margin-bottom: 10px;">{target['name']}</h3>
404
+ <p><strong>PDB ID:</strong> <a href="https://www.rcsb.org/structure/{target['pdb']}" target="_blank" style="color: #4ECDC4;">{target['pdb']}</a></p>
405
+ <p><strong>Disease:</strong> {target['disease']}</p>
406
+ <p><strong>Sponsor:</strong> {target['sponsor']}</p>
407
+ <p style="margin-top: 10px; color: #aaa;">{target['description']}</p>
408
+ <div style="margin-top: 15px; padding: 10px; background: rgba(78, 205, 196, 0.1); border-radius: 8px; border-left: 3px solid #4ECDC4;">
409
+ <p style="font-size: 12px; color: #4ECDC4; margin: 0;">
410
+ 💡 The red sphere indicates the active binding site where drug candidates interact with the protein.
411
+ </p>
412
+ </div>
413
+ </div>
414
+ """
415
+
416
+ return viewer_html, info_html
417
+
418
+
419
+ def run_docking(target_name: str, compounds: List[str], progress=gr.Progress()) -> Tuple[str, str, str]:
420
+ """Run docking simulation."""
421
+ if not target_name:
422
+ return "Please select a target protein", "", ""
423
+ if not compounds:
424
+ return "Please select at least one compound", "", ""
425
+
426
+ target = next((t for t in DEMO_TARGETS if t["name"] == target_name), None)
427
+ if not target:
428
+ return "Invalid target", "", ""
429
+
430
+ # Get compound IDs from names
431
+ compound_ids = []
432
+ for comp_name in compounds:
433
+ comp = next((c for c in COMPOUND_LIBRARY if c["name"] == comp_name), None)
434
+ if comp:
435
+ compound_ids.append(comp["id"])
436
+
437
+ # Simulate docking progress
438
+ progress(0, desc="Initializing docking engine...")
439
+ time.sleep(0.5)
440
+
441
+ progress(0.2, desc="Loading protein structure...")
442
+ time.sleep(0.3)
443
+
444
+ progress(0.4, desc="Preparing compound library...")
445
+ time.sleep(0.3)
446
+
447
+ progress(0.6, desc="Running molecular docking...")
448
+ time.sleep(0.5)
449
+
450
+ progress(0.8, desc="Analyzing binding poses...")
451
+ time.sleep(0.3)
452
+
453
+ progress(0.95, desc="Generating results...")
454
+ results_text, chart_html, receipt = generate_docking_result(target["id"], compound_ids)
455
+
456
+ progress(1.0, desc="Complete!")
457
+
458
+ return results_text, chart_html, receipt
459
+
460
+
461
+ # Create the Gradio interface
462
+ with gr.Blocks(
463
+ title="BioPrime Molecular Docking Demo",
464
+ theme=gr.themes.Base(
465
+ primary_hue="teal",
466
+ secondary_hue="purple",
467
+ neutral_hue="slate",
468
+ font=gr.themes.GoogleFont("Inter")
469
+ ),
470
+ css="""
471
+ .gradio-container {
472
+ max-width: 1400px !important;
473
+ background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%) !important;
474
+ }
475
+ .gr-button-primary {
476
+ background: linear-gradient(135deg, #4ECDC4 0%, #44A08D 100%) !important;
477
+ }
478
+ .header-text {
479
+ text-align: center;
480
+ color: white;
481
+ }
482
+ footer {display: none !important;}
483
+ """
484
+ ) as demo:
485
+
486
+ # Header
487
+ gr.HTML("""
488
+ <div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 12px; margin-bottom: 20px;">
489
+ <h1 style="color: white; margin: 0; font-size: 2.5em;">🧬 BioPrime</h1>
490
+ <p style="color: rgba(255,255,255,0.9); margin: 10px 0 0 0; font-size: 1.2em;">
491
+ AI-Powered Molecular Docking for Drug Discovery
492
+ </p>
493
+ <p style="color: rgba(255,255,255,0.7); margin: 5px 0 0 0;">
494
+ 10,000x Faster • $5 per Million Compounds • Blockchain-Verified Results
495
+ </p>
496
+ </div>
497
+ """)
498
+
499
+ with gr.Tabs():
500
+ # Tab 1: Interactive Docking Demo
501
+ with gr.TabItem("🔬 Try Docking", id="docking"):
502
+ gr.Markdown("""
503
+ ### Dock Drug Candidates Against Disease Targets
504
+ Select a protein target and compounds to simulate molecular docking. See binding energies and get a blockchain-ready certificate.
505
+ """)
506
+
507
+ with gr.Row():
508
+ with gr.Column(scale=1):
509
+ target_dropdown = gr.Dropdown(
510
+ choices=[t["name"] for t in DEMO_TARGETS],
511
+ label="🎯 Select Disease Target",
512
+ info="Choose from sponsored research targets"
513
+ )
514
+
515
+ compound_select = gr.CheckboxGroup(
516
+ choices=[c["name"] for c in COMPOUND_LIBRARY],
517
+ label="💊 Select Compounds to Test",
518
+ info="Choose multiple compounds for screening"
519
+ )
520
+
521
+ dock_btn = gr.Button("🚀 Run Docking Simulation", variant="primary", size="lg")
522
+
523
+ gr.HTML("""
524
+ <div style="margin-top: 15px; padding: 15px; background: rgba(78, 205, 196, 0.1); border-radius: 8px; border: 1px solid rgba(78, 205, 196, 0.3);">
525
+ <h4 style="color: #4ECDC4; margin: 0 0 10px 0;">💡 Quick Start</h4>
526
+ <ol style="color: #aaa; margin: 0; padding-left: 20px; font-size: 13px;">
527
+ <li>Select <strong>BRAF V600E - Melanoma</strong></li>
528
+ <li>Check <strong>Vemurafenib</strong> (the actual drug!)</li>
529
+ <li>Add a few other compounds to compare</li>
530
+ <li>Click Run Docking</li>
531
+ </ol>
532
+ </div>
533
+ """)
534
+
535
+ with gr.Column(scale=2):
536
+ results_md = gr.Markdown("*Results will appear here after docking...*")
537
+ chart_html = gr.HTML()
538
+
539
+ with gr.Accordion("📜 Blockchain Certificate (Demo)", open=False):
540
+ receipt_text = gr.Code(label="Discovery Certificate", language=None, lines=30)
541
+
542
+ dock_btn.click(
543
+ fn=run_docking,
544
+ inputs=[target_dropdown, compound_select],
545
+ outputs=[results_md, chart_html, receipt_text]
546
+ )
547
+
548
+ # Tab 2: 3D Protein Viewer
549
+ with gr.TabItem("🔮 3D Protein Viewer", id="viewer"):
550
+ gr.Markdown("""
551
+ ### Explore Protein Structures in 3D
552
+ Visualize the molecular targets for drug discovery. The red sphere indicates the binding site.
553
+ """)
554
+
555
+ with gr.Row():
556
+ with gr.Column(scale=1):
557
+ viewer_target = gr.Dropdown(
558
+ choices=[t["name"] for t in DEMO_TARGETS],
559
+ label="🎯 Select Protein",
560
+ value=DEMO_TARGETS[0]["name"]
561
+ )
562
+
563
+ view_style = gr.Radio(
564
+ choices=["Cartoon", "Surface", "Stick", "Sphere"],
565
+ value="Cartoon",
566
+ label="🎨 Visualization Style"
567
+ )
568
+
569
+ view_btn = gr.Button("👁️ View Structure", variant="primary")
570
+
571
+ target_info = gr.HTML()
572
+
573
+ with gr.Column(scale=2):
574
+ viewer_output = gr.HTML(
575
+ value="<div style='height: 500px; display: flex; align-items: center; justify-content: center; color: #666; background: #1a1a2e; border-radius: 12px;'><p>Select a protein and click 'View Structure'</p></div>"
576
+ )
577
+
578
+ view_btn.click(
579
+ fn=view_protein,
580
+ inputs=[viewer_target, view_style],
581
+ outputs=[viewer_output, target_info]
582
+ )
583
+
584
+ # Tab 3: About BioPrime
585
+ with gr.TabItem("ℹ️ About", id="about"):
586
+ gr.Markdown("""
587
+ ## About BioPrime Network
588
+
589
+ BioPrime is a **decentralized molecular docking platform** that makes drug discovery accessible to everyone.
590
+
591
+ ### Key Features
592
+
593
+ | Feature | Traditional | BioPrime |
594
+ |---------|-------------|----------|
595
+ | Speed | Days-Weeks | Minutes |
596
+ | Cost | $10,000+ | $5/million |
597
+ | Verification | Manual | Blockchain |
598
+ | Access | Limited | Open |
599
+
600
+ ### How It Works
601
+
602
+ 1. **Submit** - Upload your protein target or select from our library
603
+ 2. **Screen** - Our Origin Neural AI engine docks millions of compounds
604
+ 3. **Discover** - Get ranked binding poses with energy scores
605
+ 4. **Verify** - Results anchored to BSV blockchain for immutable proof
606
+
607
+ ### Sponsored Research Campaigns
608
+
609
+ BioPrime features sponsored research targets where community members can contribute to drug discovery:
610
+
611
+ - **Bryan Daugherty** - Melanoma (BRAF V600E), Type 2 Diabetes (DPP-4)
612
+ - **Smartledger** - Breast Cancer (CDK4/6)
613
+ - **Origin Neural AI** - HIV-1 Protease
614
+ - **Greg Ward** - Tuberculosis, Dengue Fever
615
+ - **Shawn Ryan** - Alzheimer's, Parkinson's
616
+
617
+ ### Technology Stack
618
+
619
+ - **Docking Engine**: Origin Neural AI (GPU-accelerated)
620
+ - **Blockchain**: BSV (Bitcoin SV) for immutable verification
621
+ - **Backend**: FastAPI, Python
622
+ - **Frontend**: React, TypeScript
623
+
624
+ ---
625
+
626
+ ### Get Started
627
+
628
+ **🌐 Visit [bioprime.one](https://bioprime.one) to run real docking experiments!**
629
+
630
+ - Sign up for free (10 free credits)
631
+ - Screen up to 1 million compounds per job
632
+ - Get blockchain-verified discovery certificates
633
+ - Participate in sponsored research campaigns
634
+
635
+ ---
636
+
637
+ <div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 12px;">
638
+ <p style="color: white; font-size: 1.2em; margin: 0;">
639
+ <strong>Ready to discover the next breakthrough drug?</strong>
640
+ </p>
641
+ <p style="color: rgba(255,255,255,0.8); margin: 10px 0 0 0;">
642
+ <a href="https://bioprime.one" target="_blank" style="color: #4ECDC4; text-decoration: none; font-size: 1.3em;">
643
+ 🚀 Launch BioPrime →
644
+ </a>
645
+ </p>
646
+ </div>
647
+ """)
648
+
649
+ # Footer
650
+ gr.HTML("""
651
+ <div style="text-align: center; padding: 20px; margin-top: 20px; border-top: 1px solid rgba(255,255,255,0.1);">
652
+ <p style="color: #666; margin: 0;">
653
+ <a href="https://bioprime.one" target="_blank" style="color: #4ECDC4;">bioprime.one</a> •
654
+ <a href="https://twitter.com/BioPrimeNetwork" target="_blank" style="color: #4ECDC4;">@BioPrimeNetwork</a> •
655
+ <a href="https://github.com/bioprime-network" target="_blank" style="color: #4ECDC4;">GitHub</a>
656
+ </p>
657
+ <p style="color: #444; margin: 5px 0 0 0; font-size: 12px;">
658
+ Powered by Origin Neural AI • Blockchain verification on BSV
659
+ </p>
660
+ </div>
661
+ """)
662
+
663
+
664
+ if __name__ == "__main__":
665
+ demo.launch()