Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -6,29 +6,6 @@ from scripts.download import download_and_clean_pdb
|
|
| 6 |
from scripts.generator import run_broteinshake_generator
|
| 7 |
from scripts.refine import polish_design
|
| 8 |
|
| 9 |
-
import subprocess
|
| 10 |
-
import sys
|
| 11 |
-
|
| 12 |
-
def install_dependencies():
|
| 13 |
-
"""Forces installation of missing physics/bio libraries on Hugging Face."""
|
| 14 |
-
try:
|
| 15 |
-
import Bio
|
| 16 |
-
import openmm
|
| 17 |
-
print("✅ Dependencies already present.")
|
| 18 |
-
except ImportError:
|
| 19 |
-
print("🔧 Installing missing dependencies... this may take a minute.")
|
| 20 |
-
# Install biopython specifically
|
| 21 |
-
subprocess.check_call([sys.executable, "-m", "pip", "install", "biopython"])
|
| 22 |
-
# If openmm is missing, we try to grab the pip-compatible version
|
| 23 |
-
subprocess.check_call([sys.executable, "-m", "pip", "install", "openmm"])
|
| 24 |
-
print("✅ Installation complete.")
|
| 25 |
-
|
| 26 |
-
install_dependencies()
|
| 27 |
-
|
| 28 |
-
# NOW you can import your other scripts
|
| 29 |
-
from Bio.PDB import PDBParser
|
| 30 |
-
# ... rest of your code ...
|
| 31 |
-
|
| 32 |
# --- HELPER FUNCTIONS ---
|
| 33 |
|
| 34 |
def extract_best_sequence(fasta_file: str) -> str:
|
|
@@ -90,18 +67,23 @@ def run_part1(pdb_id, fixed_chains, variable_chains):
|
|
| 90 |
return "", f"Error in Part 1: {str(e)}"
|
| 91 |
|
| 92 |
def run_part2(pdb_id, uploaded_esm_file):
|
| 93 |
-
"""Aligns the ESM-folded PDB
|
| 94 |
try:
|
| 95 |
if uploaded_esm_file is None:
|
| 96 |
-
return None, "Please upload the PDB
|
| 97 |
|
| 98 |
-
#
|
| 99 |
-
|
| 100 |
-
final_pdb_path, rmsd_val = polish_design(pdb_id, uploaded_esm_file)
|
| 101 |
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
except Exception as e:
|
| 104 |
-
return None, f"Error
|
| 105 |
|
| 106 |
# --- GRADIO INTERFACE ---
|
| 107 |
|
|
@@ -124,17 +106,18 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 124 |
|
| 125 |
gen_btn.click(run_part1, inputs=[pdb_input, f_chains, v_chains], outputs=[fa_output, status1])
|
| 126 |
|
| 127 |
-
# TAB 2:
|
| 128 |
-
with gr.Tab("2. Structural
|
| 129 |
-
gr.Markdown("
|
| 130 |
with gr.Row():
|
| 131 |
esm_upload = gr.File(label="Upload ESM-Folded PDB", file_types=[".pdb"])
|
| 132 |
-
refined_download = gr.File(label="Download
|
| 133 |
|
| 134 |
-
|
|
|
|
| 135 |
status2 = gr.Textbox(label="Validation Report", interactive=False)
|
| 136 |
|
| 137 |
-
|
| 138 |
|
| 139 |
# Launch the app
|
| 140 |
if __name__ == "__main__":
|
|
|
|
| 6 |
from scripts.generator import run_broteinshake_generator
|
| 7 |
from scripts.refine import polish_design
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# --- HELPER FUNCTIONS ---
|
| 10 |
|
| 11 |
def extract_best_sequence(fasta_file: str) -> str:
|
|
|
|
| 67 |
return "", f"Error in Part 1: {str(e)}"
|
| 68 |
|
| 69 |
def run_part2(pdb_id, uploaded_esm_file):
|
| 70 |
+
"""Aligns the ESM-folded PDB to the target structure."""
|
| 71 |
try:
|
| 72 |
if uploaded_esm_file is None:
|
| 73 |
+
return None, "⚠️ Please upload the PDB from ESM Atlas first."
|
| 74 |
|
| 75 |
+
# Call the new lightweight Biopython-only script
|
| 76 |
+
final_pdb_path, rmsd_val = polish_design(pdb_id, uploaded_esm_file.name)
|
|
|
|
| 77 |
|
| 78 |
+
# Update the report to focus on Backbone Alignment
|
| 79 |
+
report = (
|
| 80 |
+
f"✅ Validation Successful!\n"
|
| 81 |
+
f"🎯 RMSD: {rmsd_val:.3f} Å\n"
|
| 82 |
+
f"🧬 Status: High-Precision Backbone Match"
|
| 83 |
+
)
|
| 84 |
+
return final_pdb_path, report
|
| 85 |
except Exception as e:
|
| 86 |
+
return None, f"❌ Error: {str(e)}"
|
| 87 |
|
| 88 |
# --- GRADIO INTERFACE ---
|
| 89 |
|
|
|
|
| 106 |
|
| 107 |
gen_btn.click(run_part1, inputs=[pdb_input, f_chains, v_chains], outputs=[fa_output, status1])
|
| 108 |
|
| 109 |
+
# TAB 2: STRUCTURAL VALIDATION
|
| 110 |
+
with gr.Tab("2. Structural Validation"):
|
| 111 |
+
gr.Markdown("### Align Designed Shuttle to Human Receptor")
|
| 112 |
with gr.Row():
|
| 113 |
esm_upload = gr.File(label="Upload ESM-Folded PDB", file_types=[".pdb"])
|
| 114 |
+
refined_download = gr.File(label="Download Aligned Lead (.pdb)")
|
| 115 |
|
| 116 |
+
# Change the button text to match our new approach
|
| 117 |
+
validate_btn = gr.Button("✨ Run Structural Alignment", variant="primary")
|
| 118 |
status2 = gr.Textbox(label="Validation Report", interactive=False)
|
| 119 |
|
| 120 |
+
validate_btn.click(run_part2, inputs=[pdb_input, esm_upload], outputs=[refined_download, status2])
|
| 121 |
|
| 122 |
# Launch the app
|
| 123 |
if __name__ == "__main__":
|