Tengo Gzirishvili Claude Sonnet 4.6 commited on
Commit
20cdca4
·
1 Parent(s): ee2eecc

Fix AlphaFold viewer showing nothing (stale model version + silent 404)

Browse files

Root cause: AlphaFold-DB bumped its model version DB-wide (v4 → v6), so the
hardcoded …AF-{acc}-F1-model_v4.pdb URLs now 404. And Mol*'s
loadStructureFromUrl does NOT throw on a 404 — it loads the XML error body,
ends up with zero structures, removes our loading overlay, and silently
leaves an empty viewer. Net effect: "won't show predicted models."

Verified empirically: v4 → HTTP 404; AlphaFold's prediction API
(/api/prediction/{acc}, CORS-enabled) reports latestVersion 6; loading the
v6 .pdb yields 1 structure in the Mol* hierarchy.

Fix (both the directed-evolution embed and the CRISPR M5 cut-site viewer):
- _afResolveModelUrl(): pull the accession out of whatever URL we were given
and resolve the CURRENT file URL from the AlphaFold API (falls back to the
given URL on any error). Future-proof against the next version bump.
- _afHasStructure(): after loadStructureFromUrl, assert a structure actually
landed in the hierarchy; if not, throw so the catch surfaces a real message
instead of a blank box.
- Server fallback URLs bumped v4 → v6 (resolve.py, server.py); test updated.

Cache-buster → v=20260530-alphafold-fix.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

dee/core/resolve.py CHANGED
@@ -155,7 +155,9 @@ def resolve_uniprot(organism: str, gene_symbol: str) -> Dict:
155
  return {
156
  "ok": True,
157
  "uniprot": acc,
158
- "alphafold_url": f"https://alphafold.ebi.ac.uk/files/AF-{acc}-F1-model_v4.pdb",
 
 
159
  "alphafold_page": f"https://alphafold.ebi.ac.uk/entry/{acc}",
160
  }
161
 
 
155
  return {
156
  "ok": True,
157
  "uniprot": acc,
158
+ # Fallback URL only — the client re-resolves the current model version
159
+ # via the AlphaFold prediction API (the DB bumps versions: v4→v6→…).
160
+ "alphafold_url": f"https://alphafold.ebi.ac.uk/files/AF-{acc}-F1-model_v6.pdb",
161
  "alphafold_page": f"https://alphafold.ebi.ac.uk/entry/{acc}",
162
  }
163
 
dee/server.py CHANGED
@@ -340,8 +340,11 @@ def _run_blast(job: BlastJob, protein: str) -> None:
340
  # UniProt accession when available — gates the
341
  # AlphaFold-DB structure embed on the frontend.
342
  "uniprot": uniprot,
 
 
 
343
  "alphafold_url": (
344
- f"https://alphafold.ebi.ac.uk/files/AF-{uniprot}-F1-model_v4.pdb"
345
  if uniprot else None
346
  ),
347
  "alphafold_page": (
 
340
  # UniProt accession when available — gates the
341
  # AlphaFold-DB structure embed on the frontend.
342
  "uniprot": uniprot,
343
+ # Fallback URL only — the client re-resolves the current
344
+ # model version via the AlphaFold prediction API
345
+ # (the DB bumps versions over time: v4 → v6 → …).
346
  "alphafold_url": (
347
+ f"https://alphafold.ebi.ac.uk/files/AF-{uniprot}-F1-model_v6.pdb"
348
  if uniprot else None
349
  ),
350
  "alphafold_page": (
dee/static/app.js CHANGED
@@ -2437,9 +2437,36 @@ function renderIdentifyResult(data) {
2437
  if (afHit) mountAlphaFoldViewer(afHit);
2438
  }
2439
 
2440
- // Mol* viewer mount. Loads the AlphaFold .pdb file from the EBI CDN and
2441
- // renders it inside #alphafoldViewer. We wait for the molstar global to
2442
- // appear (script is loaded async) before mounting.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2443
  async function mountAlphaFoldViewer(hit) {
2444
  const host = document.getElementById('alphafoldViewer');
2445
  if (!host) return;
@@ -2474,9 +2501,11 @@ async function mountAlphaFoldViewer(hit) {
2474
  // Match our app's dark viewer background.
2475
  backgroundColor: { r: 14, g: 20, b: 27 },
2476
  });
2477
- await viewer.loadStructureFromUrl(pdbUrl, 'pdb');
2478
- // Mol* mounts a loading overlay; once the structure has loaded the
2479
- // overlay disappears, but our custom one is in a sibling node — wipe it.
 
 
2480
  const overlay = host.querySelector('.alphafold-loading');
2481
  if (overlay) overlay.remove();
2482
  } catch (err) {
@@ -4466,7 +4495,9 @@ if (_quitBtn) {
4466
  viewportShowExpand: true, viewportShowSelectionMode: false, viewportShowAnimation: false,
4467
  pdbProvider: 'pdbe', emdbProvider: 'pdbe', backgroundColor: { r: 14, g: 20, b: 27 },
4468
  });
4469
- await viewer.loadStructureFromUrl(pdbUrl, 'pdb');
 
 
4470
  const ov = host.querySelector('.alphafold-loading'); if (ov) ov.remove();
4471
  _highlightResidue(molstar, viewer, residue);
4472
  } catch (err) {
 
2437
  if (afHit) mountAlphaFoldViewer(afHit);
2438
  }
2439
 
2440
+ // AlphaFold-DB bumps its model version DB-wide over time (…v4 → v6 → …), so
2441
+ // any hardcoded "model_vN" URL eventually 404s. Critically, Mol*'s
2442
+ // loadStructureFromUrl does NOT throw on a 404 — it loads the error body,
2443
+ // ends up with zero structures, removes the loading overlay, and silently
2444
+ // shows an empty viewer ("won't show predicted models"). So we resolve the
2445
+ // CURRENT file URL from AlphaFold's prediction API using the accession
2446
+ // embedded in whatever URL we were handed, with the original as fallback.
2447
+ // CORS-enabled; works from inside the /app/ iframe.
2448
+ async function _afResolveModelUrl(url) {
2449
+ try {
2450
+ const m = (url || '').match(/AF-([A-Za-z0-9]+)-F\d+/);
2451
+ if (!m) return url;
2452
+ const r = await fetch('https://alphafold.ebi.ac.uk/api/prediction/' + m[1]);
2453
+ if (!r.ok) return url;
2454
+ const j = await r.json();
2455
+ const e = (j && j[0]) || {};
2456
+ return e.pdbUrl || e.cifUrl || url;
2457
+ } catch (_) { return url; }
2458
+ }
2459
+ function _afFormat(url) { return /\.cif(\?|$)/i.test(url || '') ? 'mmcif' : 'pdb'; }
2460
+ // True only if a structure actually made it into the hierarchy — guards the
2461
+ // silent-404 case above so we can surface a real message instead of a blank.
2462
+ function _afHasStructure(viewer) {
2463
+ try { return (viewer.plugin.managers.structure.hierarchy.current.structures.length || 0) > 0; }
2464
+ catch (_) { return false; }
2465
+ }
2466
+
2467
+ // Mol* viewer mount. Loads the AlphaFold model from the EBI CDN and renders
2468
+ // it inside #alphafoldViewer. We wait for the molstar global to appear
2469
+ // (script is loaded async) before mounting.
2470
  async function mountAlphaFoldViewer(hit) {
2471
  const host = document.getElementById('alphafoldViewer');
2472
  if (!host) return;
 
2501
  // Match our app's dark viewer background.
2502
  backgroundColor: { r: 14, g: 20, b: 27 },
2503
  });
2504
+ const realUrl = await _afResolveModelUrl(pdbUrl);
2505
+ await viewer.loadStructureFromUrl(realUrl, _afFormat(realUrl));
2506
+ // Mol* doesn't throw on a 404 — confirm a structure actually loaded.
2507
+ if (!_afHasStructure(viewer)) throw new Error('AlphaFold model unavailable for this entry.');
2508
+ // Our custom loading overlay is a sibling node — wipe it now.
2509
  const overlay = host.querySelector('.alphafold-loading');
2510
  if (overlay) overlay.remove();
2511
  } catch (err) {
 
4495
  viewportShowExpand: true, viewportShowSelectionMode: false, viewportShowAnimation: false,
4496
  pdbProvider: 'pdbe', emdbProvider: 'pdbe', backgroundColor: { r: 14, g: 20, b: 27 },
4497
  });
4498
+ const realUrl = await _afResolveModelUrl(pdbUrl);
4499
+ await viewer.loadStructureFromUrl(realUrl, _afFormat(realUrl));
4500
+ if (!_afHasStructure(viewer)) throw new Error('AlphaFold model unavailable for this entry.');
4501
  const ov = host.querySelector('.alphafold-loading'); if (ov) ov.remove();
4502
  _highlightResidue(molstar, viewer, residue);
4503
  } catch (err) {
dee/static/index.html CHANGED
@@ -22,7 +22,7 @@
22
  <!-- ?v= query bumps invalidate browser + iframe asset caches when app.css /
23
  app.js change. Bump these numbers whenever you ship a frontend update —
24
  without them, users keep getting the stale file for up to a week. -->
25
- <link rel="stylesheet" href="/static/app.css?v=20260530-toggle-left" />
26
  <link rel="icon" type="image/svg+xml" href="/static/favicon.svg?v=2" />
27
  <link rel="apple-touch-icon" href="/static/favicon.svg?v=2" />
28
  <!-- Mol* (PDBe) viewer for AlphaFold structure embed. Loaded async; the
@@ -1164,6 +1164,6 @@
1164
  <!-- Cloning reference data must load before app.js so the Designer
1165
  can read VECTORS / ENZYMES / CLONING_METHODS / TAGS / LINKERS. -->
1166
  <script src="/static/cloning_db.js?v=20260530-ui-polish" defer></script>
1167
- <script src="/static/app.js?v=20260530-toggle-left" defer></script>
1168
  </body>
1169
  </html>
 
22
  <!-- ?v= query bumps invalidate browser + iframe asset caches when app.css /
23
  app.js change. Bump these numbers whenever you ship a frontend update —
24
  without them, users keep getting the stale file for up to a week. -->
25
+ <link rel="stylesheet" href="/static/app.css?v=20260530-alphafold-fix" />
26
  <link rel="icon" type="image/svg+xml" href="/static/favicon.svg?v=2" />
27
  <link rel="apple-touch-icon" href="/static/favicon.svg?v=2" />
28
  <!-- Mol* (PDBe) viewer for AlphaFold structure embed. Loaded async; the
 
1164
  <!-- Cloning reference data must load before app.js so the Designer
1165
  can read VECTORS / ENZYMES / CLONING_METHODS / TAGS / LINKERS. -->
1166
  <script src="/static/cloning_db.js?v=20260530-ui-polish" defer></script>
1167
+ <script src="/static/app.js?v=20260530-alphafold-fix" defer></script>
1168
  </body>
1169
  </html>
tests/test_resolve.py CHANGED
@@ -137,7 +137,7 @@ def test_resolve_uniprot_ok(monkeypatch):
137
  monkeypatch.setattr(E, "_http_get_json", _json)
138
  out = R.resolve_uniprot("human", "TP53")
139
  assert out["ok"] and out["uniprot"] == "P04637"
140
- assert out["alphafold_url"] == "https://alphafold.ebi.ac.uk/files/AF-P04637-F1-model_v4.pdb"
141
  assert out["alphafold_page"] == "https://alphafold.ebi.ac.uk/entry/P04637"
142
  assert "organism_id%3A9606" in captured["url"] and "reviewed%3Atrue" in captured["url"]
143
 
 
137
  monkeypatch.setattr(E, "_http_get_json", _json)
138
  out = R.resolve_uniprot("human", "TP53")
139
  assert out["ok"] and out["uniprot"] == "P04637"
140
+ assert out["alphafold_url"] == "https://alphafold.ebi.ac.uk/files/AF-P04637-F1-model_v6.pdb"
141
  assert out["alphafold_page"] == "https://alphafold.ebi.ac.uk/entry/P04637"
142
  assert "organism_id%3A9606" in captured["url"] and "reviewed%3Atrue" in captured["url"]
143