Spaces:
Sleeping
Sleeping
Krzysztof Gwozdz commited on
Commit ·
a6788ca
1
Parent(s): ca6cdff
v0.4.0: add backbone PDB download + 3D viewer link
Browse files- Predict now also rebuilds backbone PDB via alphadynamics.trajectory_to_pdb
- New File output: Download backbone PDB (50-frame subsample)
- Diagnostic: Rg + end-to-end distance shown alongside basin populations
- Link to online 3Dmol viewer at GitHub Pages
app.py
CHANGED
|
@@ -215,14 +215,35 @@ def predict(sequence: str, n_ensemble: int, rollout_steps: int):
|
|
| 215 |
model_name="ad_transfer_v2_clean",
|
| 216 |
)
|
| 217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
fig = make_ramachandran_figure(traj, sequence)
|
| 219 |
info = (
|
| 220 |
f"### `{sequence}` — {len(sequence)} residue{'s' if len(sequence) > 1 else ''}\n\n"
|
| 221 |
f"**{n_ensemble}** trajectories × **{rollout_steps}** steps "
|
| 222 |
f"= **{n_ensemble * rollout_steps * len(sequence):,}** torsion samples\n\n"
|
| 223 |
+ basin_table_md(traj)
|
|
|
|
| 224 |
)
|
| 225 |
-
return fig, info, str(out_path)
|
| 226 |
|
| 227 |
|
| 228 |
# ----------------------------------------------------------------------------
|
|
@@ -302,13 +323,19 @@ with gr.Blocks(title="AlphaDynamics") as demo:
|
|
| 302 |
predict_btn = gr.Button("Predict torsion dynamics 🚀", variant="primary")
|
| 303 |
info_md = gr.Markdown(label="Basin populations")
|
| 304 |
file_out = gr.File(label="Download trajectory (.npz)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
with gr.Column(scale=2):
|
| 306 |
plot_out = gr.Plot(label="Ramachandran density")
|
| 307 |
|
| 308 |
predict_btn.click(
|
| 309 |
fn=predict,
|
| 310 |
inputs=[seq_input, n_ens_input, rs_input],
|
| 311 |
-
outputs=[plot_out, info_md, file_out],
|
| 312 |
)
|
| 313 |
|
| 314 |
gr.Examples(
|
|
|
|
| 215 |
model_name="ad_transfer_v2_clean",
|
| 216 |
)
|
| 217 |
|
| 218 |
+
# Generate backbone PDB (NEW v0.4.0)
|
| 219 |
+
try:
|
| 220 |
+
from alphadynamics import trajectory_to_pdb, trajectory_diagnostics
|
| 221 |
+
pdb_path = Path(tempfile.gettempdir()) / f"alphadynamics_{sequence}_backbone.pdb"
|
| 222 |
+
# Use ensemble member 0, subsample to 50 frames for fast download
|
| 223 |
+
member = traj[0]
|
| 224 |
+
if len(member) > 50:
|
| 225 |
+
idx = np.linspace(0, len(member) - 1, 50).astype(int)
|
| 226 |
+
member = member[idx]
|
| 227 |
+
trajectory_to_pdb(member, sequence, str(pdb_path))
|
| 228 |
+
diag = trajectory_diagnostics(member)
|
| 229 |
+
diag_md = (
|
| 230 |
+
f"\n\n**3D backbone diagnostics** (Cα-only, 50 frames):\n"
|
| 231 |
+
f"- Radius of gyration: {diag['rg_mean']:.2f} ± {diag['rg_std']:.2f} Å\n"
|
| 232 |
+
f"- End-to-end distance: {diag['end_to_end_mean']:.2f} ± {diag['end_to_end_std']:.2f} Å"
|
| 233 |
+
)
|
| 234 |
+
except Exception as e:
|
| 235 |
+
pdb_path = None
|
| 236 |
+
diag_md = f"\n\n*(PDB rebuild unavailable: {e})*"
|
| 237 |
+
|
| 238 |
fig = make_ramachandran_figure(traj, sequence)
|
| 239 |
info = (
|
| 240 |
f"### `{sequence}` — {len(sequence)} residue{'s' if len(sequence) > 1 else ''}\n\n"
|
| 241 |
f"**{n_ensemble}** trajectories × **{rollout_steps}** steps "
|
| 242 |
f"= **{n_ensemble * rollout_steps * len(sequence):,}** torsion samples\n\n"
|
| 243 |
+ basin_table_md(traj)
|
| 244 |
+
+ diag_md
|
| 245 |
)
|
| 246 |
+
return fig, info, str(out_path), str(pdb_path) if pdb_path else None
|
| 247 |
|
| 248 |
|
| 249 |
# ----------------------------------------------------------------------------
|
|
|
|
| 323 |
predict_btn = gr.Button("Predict torsion dynamics 🚀", variant="primary")
|
| 324 |
info_md = gr.Markdown(label="Basin populations")
|
| 325 |
file_out = gr.File(label="Download trajectory (.npz)")
|
| 326 |
+
pdb_out = gr.File(label="Download backbone PDB (NEW v0.4.0)")
|
| 327 |
+
gr.Markdown(
|
| 328 |
+
"💡 **3D viewer:** open the downloaded `.pdb` in "
|
| 329 |
+
"[PyMOL](https://pymol.org/) / VMD / ChimeraX, or browse online at "
|
| 330 |
+
"[krisss0mecom.github.io/AlphaDynamics/examples/3d_movie_demo](https://krisss0mecom.github.io/AlphaDynamics/examples/3d_movie_demo/viewer.html)"
|
| 331 |
+
)
|
| 332 |
with gr.Column(scale=2):
|
| 333 |
plot_out = gr.Plot(label="Ramachandran density")
|
| 334 |
|
| 335 |
predict_btn.click(
|
| 336 |
fn=predict,
|
| 337 |
inputs=[seq_input, n_ens_input, rs_input],
|
| 338 |
+
outputs=[plot_out, info_md, file_out, pdb_out],
|
| 339 |
)
|
| 340 |
|
| 341 |
gr.Examples(
|