-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostinstall.py
More file actions
executable file
·218 lines (169 loc) · 6.32 KB
/
Copy pathpostinstall.py
File metadata and controls
executable file
·218 lines (169 loc) · 6.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/env python3
"""
Post-installation script for Protein Hunter MCP.
Run this after `uv sync`:
uv run postinstall.py
"""
import os
import subprocess
import sys
import tempfile
from pathlib import Path
def create_pip_wrapper() -> Path:
"""
Create a temporary pip wrapper that redirects to uv pip.
Returns:
Path to the temporary directory containing the wrapper.
"""
print("🔧 Creating pip wrapper for uv...")
wrapper_dir = Path(tempfile.mkdtemp(prefix="uv_pip_wrapper_"))
pip_wrapper = wrapper_dir / "pip"
# Create a wrapper script that calls uv pip
pip_wrapper.write_text(
"""#!/bin/bash
exec uv pip "$@"
""",
encoding="utf-8",
)
pip_wrapper.chmod(0o755)
print(f"✅ Created pip wrapper at {pip_wrapper}")
return wrapper_dir
def install_pyrosetta() -> None:
"""Install PyRosetta using the pip wrapper to redirect to uv pip."""
print("\n⏳ Installing PyRosetta (this may take a while)...")
wrapper_dir = create_pip_wrapper()
old_path = os.environ.get("PATH", "")
# Prepend wrapper directory to PATH
os.environ["PATH"] = f"{wrapper_dir}:{old_path}"
try:
import pyrosetta_installer
pyrosetta_installer.install_pyrosetta()
print("✅ PyRosetta installed successfully!")
except Exception as e:
print(f"❌ Error installing PyRosetta: {e}")
sys.exit(1)
finally:
# Restore original PATH
os.environ["PATH"] = old_path
# Clean up wrapper directory
try:
for file in wrapper_dir.iterdir():
file.unlink()
wrapper_dir.rmdir()
except Exception as e:
print(f"⚠️ Warning: Could not clean up wrapper directory: {e}")
def download_boltz_weights() -> None:
"""Download Boltz weights and dependencies."""
print("\n⬇️ Downloading Boltz weights and dependencies...")
try:
from boltz.main import download_boltz2
cache = Path.home() / ".boltz"
cache.mkdir(parents=True, exist_ok=True)
download_boltz2(cache)
print("✅ Boltz weights downloaded successfully!")
except Exception as e:
print(f"❌ Error downloading Boltz weights: {e}")
sys.exit(1)
def download_file(url: str, output_path: Path) -> None:
"""Download a file from URL to output_path."""
import urllib.request
urllib.request.urlretrieve(url, output_path)
def setup_ligandmpnn() -> None:
"""Setup LigandMPNN model parameters if directory exists."""
ligandmpnn_dir = Path("Protein-Hunter/LigandMPNN")
if not ligandmpnn_dir.exists():
print("\n⚠️ LigandMPNN directory not found, skipping...")
return
print("\n🧬 Setting up LigandMPNN...")
model_params_dir = ligandmpnn_dir / "model_params"
model_params_dir.mkdir(parents=True, exist_ok=True)
# Model weights to download (from get_model_params.sh)
base_url = "https://files.ipd.uw.edu/pub/ligandmpnn"
models = [
# Original ProteinMPNN weights
"proteinmpnn_v_48_002.pt",
"proteinmpnn_v_48_010.pt",
"proteinmpnn_v_48_020.pt",
"proteinmpnn_v_48_030.pt",
# LigandMPNN with num_edges=32; atom_context_num=25
"ligandmpnn_v_32_005_25.pt",
"ligandmpnn_v_32_010_25.pt",
"ligandmpnn_v_32_020_25.pt",
"ligandmpnn_v_32_030_25.pt",
# Per residue label membrane ProteinMPNN
"per_residue_label_membrane_mpnn_v_48_020.pt",
# Global label membrane ProteinMPNN
"global_label_membrane_mpnn_v_48_020.pt",
# SolubleMPNN
"solublempnn_v_48_002.pt",
"solublempnn_v_48_010.pt",
"solublempnn_v_48_020.pt",
"solublempnn_v_48_030.pt",
# LigandMPNN for side-chain packing
"ligandmpnn_sc_v_32_002_16.pt",
]
print(f" Downloading {len(models)} model files...")
try:
for model_file in models:
output_path = model_params_dir / model_file
if output_path.exists():
print(f" ⏭️ {model_file} (already exists)")
continue
url = f"{base_url}/{model_file}"
print(f" ⬇️ {model_file}...")
download_file(url, output_path)
print("✅ LigandMPNN model parameters downloaded!")
except Exception as e:
print(f"❌ Error setting up LigandMPNN: {e}")
sys.exit(1)
def setup_dalphaball() -> None:
"""Make DAlphaBall.gcc executable."""
dalphaball_path = Path("Protein-Hunter/utils/DAlphaBall.gcc")
if not dalphaball_path.exists():
print("\n⚠️ DAlphaBall.gcc not found, skipping...")
return
print("\n🔧 Making DAlphaBall.gcc executable...")
try:
dalphaball_path.chmod(0o755)
print("✅ DAlphaBall.gcc is now executable!")
except Exception as e:
print(f"❌ Error making DAlphaBall.gcc executable: {e}")
sys.exit(1)
def verify_installations() -> None:
"""Verify that key packages are importable."""
print("\n🔍 Verifying installations...")
packages = [
"boltz",
"chai_lab",
"pyrosetta",
]
failed = []
for package in packages:
try:
__import__(package)
print(f" ✅ {package}")
except ImportError:
print(f" ❌ {package} (import failed)")
failed.append(package)
if failed:
print(f"\n⚠️ Warning: Some packages failed to import: {', '.join(failed)}")
print(" This may be expected for some optional components.")
def main() -> None:
"""Run all post-installation steps."""
print("🚀 Running Protein Hunter MCP post-installation...\n")
# Step 1: Download Boltz weights
download_boltz_weights()
# Step 2: Install PyRosetta with pip wrapper
install_pyrosetta()
# Step 3: Setup LigandMPNN (if available)
setup_ligandmpnn()
# Step 4: Make DAlphaBall.gcc executable
setup_dalphaball()
# Step 5: Verify installations
verify_installations()
print("\n🎉 Post-installation complete!")
print("\n📝 Next steps:")
print(" 1. Verify all packages imported correctly above")
print(" 2. Start using the MCP server")
if __name__ == "__main__":
main()