Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ def run_diffdock_inference(protein_pdb_content, ligand_smiles_string):
|
|
| 11 |
"""
|
| 12 |
Performs molecular docking analysis using RDKit for binding affinity estimation.
|
| 13 |
This is a lightweight alternative to full DiffDock that works on free CPU tier.
|
|
|
|
| 14 |
"""
|
| 15 |
try:
|
| 16 |
# Validate ligand input (protein is optional for drug-likeness analysis)
|
|
@@ -77,32 +78,36 @@ def run_diffdock_inference(protein_pdb_content, ligand_smiles_string):
|
|
| 77 |
# Clamp score between 0 and 1
|
| 78 |
confidence_score = max(0.0, min(1.0, confidence_score))
|
| 79 |
|
| 80 |
-
#
|
| 81 |
result = {
|
| 82 |
"success": True,
|
| 83 |
-
"diffdock_confidence_score": round(confidence_score, 4),
|
| 84 |
-
"hardware_allocation": "HF_FREE_CPU_TIER",
|
| 85 |
"molecular_properties": {
|
| 86 |
-
"molecular_weight": round(mw, 2),
|
| 87 |
-
"logP": round(logp, 2),
|
| 88 |
"h_bond_donors": int(hbd),
|
| 89 |
"h_bond_acceptors": int(hba),
|
| 90 |
-
"tpsa": round(tpsa, 2),
|
| 91 |
"rotatable_bonds": int(rotatable_bonds),
|
| 92 |
"lipinski_compliant": bool(lipinski_pass)
|
| 93 |
},
|
| 94 |
-
"note": "RDKit-based drug-likeness scoring (lightweight alternative to DiffDock)"
|
| 95 |
}
|
| 96 |
-
|
|
|
|
|
|
|
| 97 |
|
| 98 |
except Exception as runtime_fault:
|
| 99 |
-
#
|
| 100 |
result = {
|
| 101 |
"success": False,
|
| 102 |
"error_log": str(runtime_fault)[:200],
|
| 103 |
-
"diffdock_confidence_score": -1.0
|
| 104 |
}
|
| 105 |
-
|
|
|
|
|
|
|
| 106 |
|
| 107 |
# 🌐 FastAPI app for custom endpoints
|
| 108 |
app = FastAPI()
|
|
@@ -140,7 +145,12 @@ with gr.Blocks(title="GSS DiffDock Engine") as demo:
|
|
| 140 |
submit_btn = gr.Button("Analyze Drug Candidate", variant="primary")
|
| 141 |
|
| 142 |
with gr.Column():
|
| 143 |
-
output_json = gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
submit_btn.click(
|
| 146 |
fn=run_diffdock_inference,
|
|
|
|
| 11 |
"""
|
| 12 |
Performs molecular docking analysis using RDKit for binding affinity estimation.
|
| 13 |
This is a lightweight alternative to full DiffDock that works on free CPU tier.
|
| 14 |
+
Returns a JSON-serializable dictionary.
|
| 15 |
"""
|
| 16 |
try:
|
| 17 |
# Validate ligand input (protein is optional for drug-likeness analysis)
|
|
|
|
| 78 |
# Clamp score between 0 and 1
|
| 79 |
confidence_score = max(0.0, min(1.0, confidence_score))
|
| 80 |
|
| 81 |
+
# Build result with explicit JSON-serializable types
|
| 82 |
result = {
|
| 83 |
"success": True,
|
| 84 |
+
"diffdock_confidence_score": float(round(confidence_score, 4)),
|
| 85 |
+
"hardware_allocation": str("HF_FREE_CPU_TIER"),
|
| 86 |
"molecular_properties": {
|
| 87 |
+
"molecular_weight": float(round(mw, 2)),
|
| 88 |
+
"logP": float(round(logp, 2)),
|
| 89 |
"h_bond_donors": int(hbd),
|
| 90 |
"h_bond_acceptors": int(hba),
|
| 91 |
+
"tpsa": float(round(tpsa, 2)),
|
| 92 |
"rotatable_bonds": int(rotatable_bonds),
|
| 93 |
"lipinski_compliant": bool(lipinski_pass)
|
| 94 |
},
|
| 95 |
+
"note": str("RDKit-based drug-likeness scoring (lightweight alternative to DiffDock)")
|
| 96 |
}
|
| 97 |
+
|
| 98 |
+
# Return JSON string to bypass Gradio's JsonData wrapper
|
| 99 |
+
return json.dumps(result)
|
| 100 |
|
| 101 |
except Exception as runtime_fault:
|
| 102 |
+
# Build error result with explicit JSON-serializable types
|
| 103 |
result = {
|
| 104 |
"success": False,
|
| 105 |
"error_log": str(runtime_fault)[:200],
|
| 106 |
+
"diffdock_confidence_score": float(-1.0)
|
| 107 |
}
|
| 108 |
+
|
| 109 |
+
# Return JSON string to bypass Gradio's JsonData wrapper
|
| 110 |
+
return json.dumps(result)
|
| 111 |
|
| 112 |
# 🌐 FastAPI app for custom endpoints
|
| 113 |
app = FastAPI()
|
|
|
|
| 145 |
submit_btn = gr.Button("Analyze Drug Candidate", variant="primary")
|
| 146 |
|
| 147 |
with gr.Column():
|
| 148 |
+
output_json = gr.Textbox(
|
| 149 |
+
label="Analysis Result (JSON)",
|
| 150 |
+
lines=20,
|
| 151 |
+
max_lines=30,
|
| 152 |
+
show_copy_button=True
|
| 153 |
+
)
|
| 154 |
|
| 155 |
submit_btn.click(
|
| 156 |
fn=run_diffdock_inference,
|