42Cummer commited on
Commit
ef184f7
·
verified ·
1 Parent(s): 91a5709

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -36
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 and resolves clashes."""
94
  try:
95
  if uploaded_esm_file is None:
96
- return None, "Please upload the PDB file you downloaded from ESM Atlas."
97
 
98
- # Gradio saves the upload to a temp path
99
- # We pass that path to your refinement script
100
- final_pdb_path, rmsd_val = polish_design(pdb_id, uploaded_esm_file)
101
 
102
- return final_pdb_path, f"Lead Candidate Validated! \nRMSD: {rmsd_val:.3f} Å \nClashes: 0 (OpenMM Optimized)"
 
 
 
 
 
 
103
  except Exception as e:
104
- return None, f"Error in Part 2: {str(e)}"
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: PHYSICS VALIDATION
128
- with gr.Tab("2. Structural Refinement"):
129
- gr.Markdown("Upload the PDB you folded on ESM Atlas to perform alignment and clash resolution.")
130
  with gr.Row():
131
  esm_upload = gr.File(label="Upload ESM-Folded PDB", file_types=[".pdb"])
132
- refined_download = gr.File(label="Download Refined Lead Candidate")
133
 
134
- refine_btn = gr.Button("Refine & Resolve Clashes", variant="primary")
 
135
  status2 = gr.Textbox(label="Validation Report", interactive=False)
136
 
137
- refine_btn.click(run_part2, inputs=[pdb_input, esm_upload], outputs=[refined_download, status2])
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__":