-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniversal.html
More file actions
5664 lines (5138 loc) · 273 KB
/
universal.html
File metadata and controls
5664 lines (5138 loc) · 273 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LIVIA — Prediction Analysis</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<!-- Mol* loaded inside iframe, not here -->
<link rel="stylesheet" href="css/livia.css?v=20260604">
<style>
/* ── Page-specific styles for Universal ── */
.step-link { color: #2471A3; text-decoration: none; }
.step-link:hover { text-decoration: underline; }
/* Drop zone */
.drop-zone { border: 2px dashed #ccc; border-radius: 12px; padding: 2.5rem; text-align: center; cursor: pointer; transition: all 0.2s; color: #888; }
.drop-zone:hover, .drop-zone.dragover { border-color: #2471A3; background: #eaf2f8; color: #2471A3; }
.drop-zone.has-file { border-color: #27ae60; background: #eafaf1; color: #27ae60; }
.drop-zone-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.drop-zone-text { font-size: 0.9rem; }
.drop-zone-filename { font-weight: 700; font-size: 1rem; margin-top: 0.3rem; }
/* Status */
.status { font-size: 0.85rem; color: #666; min-height: 1.5rem; margin-top: 0.8rem; }
.status.loading { color: #2471A3; }
.status.error { color: #c0392b; }
.status.success { color: #27ae60; }
/* Page-specific button styles */
.btn-primary { margin-top: 0.8rem; }
.example-btn { background: white; color: #2471A3; border: 1px solid #ccc; border-radius: 6px; padding: 0.3rem 0.7rem; font-size: 0.82rem; cursor: pointer; transition: all 0.2s; }
.example-btn:hover { background: #eaf2f8; border-color: #2471A3; }
.btn-row { display: flex; gap: 0.5rem; margin-top: 0.8rem; }
.btn-download.cif { background: white; color: #E67E22; border-color: #E67E22; }
.btn-download.cif:hover { background: #fef5ec; }
/* Platform badge */
.platform-badge { display: inline-block; padding: 0.25rem 0.8rem; border-radius: 6px; font-size: 0.82rem; font-weight: 700; margin-top: 0.5rem; }
.platform-badge.alphafold3 { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.platform-badge.colabfold { background: #e3f2fd; color: #1565c0; border: 1px solid #90caf9; }
.platform-badge.boltz { background: #fce4ec; color: #c62828; border: 1px solid #ef9a9a; }
.platform-badge.chai { background: #fff3e0; color: #e65100; border: 1px solid #ffcc80; }
.platform-badge.openfold { background: #f3e5f5; color: #6a1b9a; border: 1px solid #ce93d8; }
.platform-badge.protenix-v2 { background: #e0f7fa; color: #006064; border: 1px solid #80deea; }
.platform-badge.esmfold2,
.platform-badge.esmfold2_native { background: #fff9c4; color: #5d4037; border: 1px solid #ffe082; }
.platform-badge.generic { background: #f5f5f5; color: #616161; border: 1px solid #bdbdbd; }
/* Page-specific overrides */
.preset-strip { display: flex; width: 60px; height: 12px; border-radius: 3px; overflow: hidden; flex-shrink: 0; }
.preset-strip span { flex: 1; }
.script-preview { font-size: 0.72rem; line-height: 1.4; }
.metrics-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
/* Mol* viewer overrides */
#viewer3d-container .msp-plugin { position: relative !important; }
#viewer3d-container .msp-layout-expanded { transform: none !important; position: relative !important; }
#viewer3d-container .msp-plugin .msp-btn-row-group,
#viewer3d-container .msp-plugin .msp-viewport-controls,
#viewer3d-container .msp-plugin .msp-highlight-info,
#viewer3d-container .msp-plugin .msp-sequence,
#viewer3d-container .msp-plugin .msp-left-panel-controls { display: none !important; }
.warning-box { background: #fff8e1; border-left: 4px solid #f9a825; padding: 0.8rem 1rem; border-radius: 0 8px 8px 0; font-size: 0.85rem; color: #795548; margin-bottom: 1rem; }
/* Map rows */
.map-row { display: flex; gap: 0.4rem; flex-wrap: nowrap; margin-bottom: 0.8rem; }
.map-item { text-align: center; }
.map-item canvas { border-radius: 4px; display: block; }
.map-item .map-label { font-size: 0.75rem; color: #666; margin-bottom: 0.2rem; }
.colorbar-row { display: flex; flex-direction: column; align-items: center; margin-top: 0.5rem; }
.colorbar-row canvas { border-radius: 3px; }
.colorbar-labels { display: flex; justify-content: space-between; width: 300px; font-size: 0.72rem; color: #888; margin-top: 2px; }
.colorbar-labels span:nth-child(2) { color: #555; font-weight: 500; }
.data-table tr.avg-row { font-weight: 600; border-top: 2px solid #999; }
.help-content {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1.5rem;
padding-left: 2.3rem;
}
.help-col h4 { font-size: 0.9rem; color: #1a5276; margin-bottom: 0.5rem; }
.help-col ol { padding-left: 1.2rem; font-size: 0.85rem; color: #555; line-height: 1.7; }
.help-col a { color: #2471A3; text-decoration: none; }
.help-col a:hover { text-decoration: underline; }
.help-table { font-size: 0.85rem; }
.help-table td { padding: 0.25rem 0.5rem 0.25rem 0; vertical-align: top; color: #555; }
.ref-list { list-style: none; padding: 0; font-size: 0.85rem; }
.ref-list li { margin-bottom: 0.3rem; color: #555; }
.ref-list a { color: #2471A3; text-decoration: none; font-weight: 600; }
.ref-list a:hover { text-decoration: underline; }
.color-presets { display: flex; flex-direction: column; gap: 0.4rem; }
.preset {
display: flex;
align-items: center;
gap: 0.6rem;
padding: 0.35rem 0.5rem;
border-radius: 6px;
cursor: pointer;
transition: background 0.2s;
}
.preset:hover { background: #f0f0f0; }
@media (max-width: 768px) {
.map-row { flex-wrap: wrap; justify-content: center; }
canvas { max-width: 100%; height: auto; }
.colorbar-labels { width: 100%; max-width: 300px; }
}
</style>
</head>
<body>
<div class="header">
<div class="container">
<h1><span style="color:#2471A3;">LIVIA</span> — Prediction Analysis</h1>
<p>Analyze predictions from AlphaFold-Multimer, AlphaFold3, ColabFold, Boltz-1/2, Chai-1, OpenFold3, Protenix-v2, and ESMFold2</p>
<div class="header-links">
<a href="index.html">Home</a>
<a href="universal.html" class="active">Prediction Analysis</a>
<a href="flypredictome.html">FlyPredictome</a>
<a href="ortholog_predictome.html">Ortholog Interactome</a>
<a href="dimer.html">AFDB Dimer</a>
<a href="monomer.html">AFDB Monomer Subdomain</a>
<a href="tutorials.html">Tutorials</a>
<a href="about.html">About</a>
<a href="bookmarklet.html" style="background:#2471A3; color:white; border-color:#2471A3; font-weight:600;">Bookmarklet ★</a>
<a href="https://github.com/flyark/LIVIA" target="_blank">GitHub</a>
</div>
</div>
</div>
<div class="container">
<!-- Step 1: Upload -->
<div class="card">
<div class="step-header">Upload Prediction Files <span style="font-weight:400; font-size:0.8rem; color:#888;">(upload your prediction files — all analysis runs locally in your browser)</span></div>
<div class="drop-zone" id="drop-zone">
<div class="drop-zone-icon">📦</div>
<div class="drop-zone-text">Drop prediction files or folders here (.zip, .gz, .xz, .cif, .pdb, .json, .npz, .npy) or click to browse</div>
<div class="drop-zone-filename" id="file-name"></div>
</div>
<input type="file" id="file-input" accept=".zip,.gz,.xz,.cif,.pdb,.json,.npz,.npy,.pkl" multiple style="display:none">
<input type="file" id="folder-input" webkitdirectory style="display:none">
<div style="display:flex; gap:0.5rem; margin-top:0.8rem;">
<button class="btn btn-primary" style="flex:1; margin:0;" onclick="document.getElementById('file-input').click()">Select Files</button>
<button class="btn btn-primary" style="flex:1; margin:0; background:#1a5276;" onclick="document.getElementById('folder-input').click()">Select Folder</button>
</div>
<div id="platform-detected" style="margin-top:0.5rem;"></div>
<div id="prediction-selector" style="display:none; margin-top:0.8rem;">
<label>Multiple predictions/ranks found — select one:</label>
<select id="prediction-select" style="padding:0.5rem 0.8rem; border:2px solid #e0e0e0; border-radius:8px; font-size:0.9rem; width:100%; margin-top:0.3rem;"></select>
</div>
<div class="btn-row">
<button class="btn btn-primary" id="btn-process" onclick="processFiles()" disabled>Process</button>
<div style="margin-top:0.8rem;">
<div style="display:flex; gap:0.5rem; flex-wrap:wrap; align-items:center;">
<span style="color:#888; font-size:0.82rem;">p53–MDM2 examples:</span>
<button onclick="loadExample('colabfold')" class="example-btn">ColabFold (8 MB)</button>
<button onclick="loadExample('alphafold3')" class="example-btn">AlphaFold3 (5 MB)</button>
<button onclick="loadExample('boltz2')" class="example-btn">Boltz-2 (26 MB)</button>
<button onclick="loadExample('chai-1')" class="example-btn">Chai-1 (63 MB)</button>
<button onclick="loadExample('openfold3')" class="example-btn">OpenFold3 (33 MB)</button>
<button onclick="loadExample('protenix-v2')" class="example-btn">Protenix-v2 (21 MB)</button>
<button onclick="loadExample('esmfold2')" class="example-btn">ESMFold2 (2 MB)</button>
</div>
<div style="font-size:0.72rem; color:#aaa; margin-top:0.3rem;">AlphaFold3 predicted via <a href="https://alphafoldserver.com" target="_blank" style="color:#aaa;">AlphaFold Server</a>. ColabFold, Boltz-2, Chai-1, OpenFold3, and Protenix-v2 predicted via <a href="https://www.tamarind.bio" target="_blank" style="color:#aaa;">Tamarind Bio</a>. ESMFold2 predicted via <a href="https://biohub.ai" target="_blank" style="color:#aaa;">biohub API</a>.</div>
<div style="margin-top:0.6rem; padding:0.5rem 0.8rem; background:#eaf2f8; border-radius:6px; font-size:0.8rem; color:#555;">
For batch analysis, use <code style="background:#d6e9f8; padding:0.1rem 0.3rem; border-radius:3px; font-size:0.75rem;">lis.py</code> (PPI scoring) and <code style="background:#d6e9f8; padding:0.1rem 0.3rem; border-radius:3px; font-size:0.75rem;">lis_to_cxc.py</code> (ChimeraX script generation) from <a href="https://github.com/flyark/AFM-LIS" target="_blank" style="color:#2471A3; font-weight:600;">AFM-LIS</a>.
</div>
</div>
</div>
<div class="status" id="status"></div>
</div>
<!-- Error -->
<div class="error-msg" id="error-msg"></div>
<!-- Results -->
<div class="results" id="results">
<!-- Interaction Analysis Summary -->
<div class="card result-card">
<div style="display:flex; align-items:center; gap:1rem; flex-wrap:wrap;">
<h2 id="result-title" style="margin-bottom:0;">Interaction Analysis Summary</h2>
<a style="font-size:0.8rem; color:#2471A3; cursor:pointer; text-decoration:none; border-bottom:1px dashed #2471A3;" onclick="downloadCSV()">↓ Download CSV</a>
</div>
<div class="info-box">Click a row to switch models. This updates all visualizations and the script below.</div>
<input type="hidden" id="seed-select" value="0">
<div style="overflow-x:auto;">
<table class="data-table" id="pairs-table">
<thead><tr><th>Rank/Model</th><th>Pair</th><th>iLIS</th><th>iLIA</th><th>iLISA</th><th>ipSAE</th><th>actifpTM</th><th>ipTM</th><th>LIS</th><th>cLIS</th><th>LIR (i/j)</th><th>cLIR (i/j)</th></tr></thead>
<tbody id="pairs-tbody"></tbody>
</table>
</div>
<div style="margin-top:0.6rem; font-size:0.75rem; color:#999; line-height:1.8;">
<div style="display:flex; gap:0.8rem; flex-wrap:wrap; align-items:center;">
<strong style="min-width:90px;">iLIS:</strong>
<span><span style="color:#6B21A8; font-weight:700;">≥0.551</span> (1% FPR)</span>
<span><span style="color:#0e8a6e; font-weight:700;">≥0.339</span> (5% FPR)</span>
<span><span style="color:#bf8700; font-weight:700;">≥0.223</span> (10% FPR)</span>
<span><span style="color:#8b949e; font-weight:700;"><0.223</span> (below threshold)</span>
</div>
<div style="display:flex; gap:0.8rem; flex-wrap:wrap; align-items:center;">
<strong style="min-width:90px;">iLIS (average):</strong>
<span><span style="color:#6B21A8; font-weight:700;">≥0.303</span> (1% FPR)</span>
<span><span style="color:#0e8a6e; font-weight:700;">≥0.120</span> (5% FPR)</span>
<span><span style="color:#bf8700; font-weight:700;">≥0.073</span> (10% FPR)</span>
<span><span style="color:#8b949e; font-weight:700;"><0.073</span> (below threshold)</span>
</div>
<div>Thresholds based on large-scale Y2H reference sets in yeast, fly, and human predicted using ColabFold. See <a href="https://doi.org/10.64898/2026.04.14.718529" target="_blank" style="color:#2471A3;">Kim et al., 2026</a>, for iLIS benchmark details. Different platforms may require different thresholds.</div>
</div>
</div>
<!-- Score Matrix (iLIS / iLIA) -->
<div class="card result-card" id="score-matrix-card" style="display:none;">
<h2>Score Matrix</h2>
<div style="font-size:0.82rem; color:#888; margin-bottom:0.5rem;">
Lower-left: iLIS (Oranges). Upper-right: iLIA (Greens). Diagonal: self.
</div>
<div class="map-row" id="score-matrix-row"></div>
</div>
<!-- PAE Maps -->
<div class="card result-card">
<h2>Predicted Aligned Error (PAE) Maps</h2>
<div class="map-row" id="pae-row"></div>
<div class="colorbar-row">
<canvas id="colorbar-pae" width="300" height="14"></canvas>
<div class="colorbar-labels"><span>0</span><span>Predicted Aligned Error (Å)</span><span>30</span></div>
</div>
</div>
<!-- LIS Maps -->
<div class="card result-card">
<h2>Local Interaction Score (LIS) Maps <span style="font-weight:400; font-size:0.8rem; color:#888;">(PAE ≤ 12 Å)</span></h2>
<div class="map-row" id="lis-row"></div>
<div class="colorbar-row">
<canvas id="colorbar-lis" width="300" height="14"></canvas>
<div class="colorbar-labels"><span>0</span><span>Local Interaction Score (LIS)</span><span>1</span></div>
</div>
</div>
<!-- cLIS Maps -->
<div class="card result-card">
<h2>contact Local Interaction Score (cLIS) Maps <span style="font-weight:400; font-size:0.8rem; color:#888;">(PAE ≤ 12 Å & Cβ ≤ 8 Å)</span></h2>
<div class="map-row" id="clis-row"></div>
<div class="colorbar-row">
<canvas id="colorbar-clis" width="300" height="14"></canvas>
<div class="colorbar-labels"><span>0</span><span>contact Local Interaction Score (cLIS)</span><span>1</span></div>
</div>
</div>
<!-- Sequence Viewer -->
<div class="card result-card" id="seq-viewer-card" style="display:none;">
<h2>Sequence Viewer <span class="model-badge" id="seq-model-badge"></span></h2>
<div style="font-size:0.82rem; color:#888; margin-bottom:0.5rem;">
Light background = LIR (PAE ≤ 12 Å). Dark background with white text = cLIR (PAE ≤ 12 Å & Cβ ≤ 8 Å). Each chain uses its own color.
</div>
<div id="seq-viewer" style="font-family:'SF Mono','Fira Code',monospace; overflow-x:auto;"></div>
</div>
<!-- Linear Contact Map (2-chain linear) -->
<div class="card result-card" id="contact-map-card" style="display:none;">
<h2>Linear Contact Map <span class="model-badge" id="contact-model-badge"></span></h2>
<div style="font-size:0.82rem; color:#888; margin-bottom:0.5rem;">
Lines connect cLIR residue pairs within Cβ distance in the 3D structure. Color gradient from chain A to chain B.
</div>
<canvas id="contact-canvas"></canvas>
</div>
<!-- Circular Contact Map (multi-chain) -->
<div class="card result-card" id="chord-card" style="display:none;">
<h2>Circular Contact Map <span class="model-badge" id="chord-model-badge"></span></h2>
<div style="font-size:0.82rem; color:#888; margin-bottom:0.5rem;">
Arcs represent chains. Lines connect cLIR residue pairs in physical contact across all chain pairs.
</div>
<div style="display:flex; justify-content:center; gap:2rem; flex-wrap:wrap;">
<div style="text-align:center;">
<canvas id="chord-canvas"></canvas>
<div style="font-size:0.75rem; color:#999; margin-top:0.25rem;">Selected Model</div>
</div>
<div id="chord-all-wrap" style="text-align:center;">
<canvas id="chord-canvas-all"></canvas>
<div style="font-size:0.75rem; color:#999; margin-top:0.25rem;">All Models Combined</div>
</div>
</div>
</div>
<!-- 3D Structure Viewer -->
<div class="card result-card" id="viewer3d-card" style="display:none;">
<h2>3D Structure Viewer <span class="model-badge" id="viewer3d-model-badge"></span></h2>
<div style="font-size:0.82rem; color:#888; margin-bottom:0.5rem;">
Interactive 3D preview powered by <a href="https://molstar.org" target="_blank" style="color:#2471A3;">Mol*</a> (<a href="https://doi.org/10.1093/nar/gkab314" target="_blank" style="color:#2471A3;">Sehnal et al. 2021</a>). LIR regions shown as cartoons; cLIR residues highlighted. Drag to rotate, scroll to zoom. <span style="color:#999;">If the viewer appears empty, refresh the page.</span>
</div>
<div id="chain-toggle-bar" style="display:none; align-items:center; gap:0.4rem; margin-bottom:0.5rem; flex-wrap:wrap; font-size:0.82rem; color:#555;">
<span>Chains shown in 3D & chord:</span>
<div id="chain-toggle-buttons" style="display:flex; gap:0.25rem; flex-wrap:wrap;"></div>
<button id="chain-toggle-reset" onclick="resetChainVisibility()" style="padding:0.2rem 0.55rem; border:1px solid #ddd; border-radius:4px; background:#f8f9fa; cursor:pointer; font-size:0.75rem; color:#555;">Reset</button>
</div>
<iframe id="viewer3d-frame" style="width:100%; height:660px; border:1px solid #e0e0e0; border-radius:8px; background:#fff;" sandbox="allow-scripts allow-same-origin allow-downloads" allowfullscreen></iframe>
<div style="text-align:right; margin-top:0.3rem;">
<button onclick="document.getElementById('viewer3d-frame').requestFullscreen()" style="padding:0.25rem 0.6rem; border:1px solid #ddd; border-radius:4px; background:#f8f9fa; cursor:pointer; font-size:0.78rem; color:#555;">Fullscreen</button>
</div>
</div>
<!-- Script -->
<div class="card result-card" id="script-card">
<h2>Visualization Script <span class="model-badge" id="script-model-badge"></span></h2>
<div style="margin-bottom:1rem;">
<label>Local Interaction Residue (LIR) Display</label>
<div style="display:flex; align-items:baseline; gap:0.6rem; margin-bottom:0.5rem; font-size:0.85rem; color:#555; flex-wrap:wrap;">
<span>Fill gaps ≤</span>
<input type="number" id="gap-fill-input" value="10" min="0" max="200" style="width:55px; padding:0.3rem 0.4rem; border:2px solid #e0e0e0; border-radius:6px; font-size:0.85rem; text-align:center;">
<span>residues</span>
<span style="color:#ccc;">|</span>
<span>Min segment ≥</span>
<input type="number" id="min-segment-input" value="3" min="1" max="50" style="width:55px; padding:0.3rem 0.4rem; border:2px solid #e0e0e0; border-radius:6px; font-size:0.85rem; text-align:center;">
<span>residues</span>
<button class="btn btn-primary" style="font-size:0.82rem; padding:0.25rem 0.8rem; height:32px;" onclick="updateGapFill()">Apply</button>
</div>
<div style="font-size:0.78rem; color:#999; margin-bottom:0.5rem;">Gap filling bridges short breaks for continuous cartoon. Min segment removes isolated LIR fragments shorter than the threshold.</div>
<label style="display:flex; align-items:center; gap:0.3rem; font-size:0.85rem; color:#555; cursor:pointer; user-select:none; margin-bottom:0.3rem;">
<input type="checkbox" class="show-complete-cb" onchange="toggleShowComplete(this)"> Show complete structure <span style="font-size:0.78rem; color:#999;">(display all residues instead of LIR only)</span>
</label>
<label style="display:flex; align-items:center; gap:0.3rem; font-size:0.85rem; color:#555; cursor:pointer; user-select:none; margin-bottom:1rem; padding-left:1.2rem;">
<input type="checkbox" class="gray-nonlir-cb" onchange="toggleGrayNonLir(this)"> Gray non-LIR <span style="font-size:0.78rem; color:#999;">(color non-interacting residues gray)</span>
</label>
<label>Cutoffs</label>
<div style="display:flex; gap:1.5rem; margin-bottom:1rem; flex-wrap:wrap;">
<div>
<span style="font-size:0.85rem; color:#555;">PAE cutoff (Å):</span>
<input type="number" id="pae-cutoff" value="12" min="1" max="30" step="1" style="width:60px; padding:0.3rem; border:2px solid #e0e0e0; border-radius:6px; font-size:0.9rem;">
</div>
<div>
<span style="font-size:0.85rem; color:#555;">Cβ cutoff (Å):</span>
<input type="number" id="cb-cutoff" value="8" min="1" max="20" step="1" style="width:60px; padding:0.3rem; border:2px solid #e0e0e0; border-radius:6px; font-size:0.9rem;">
</div>
</div>
<label class="two-chain-only">Presets — gradient (LIR light, cLIR dark)</label>
<div class="presets-row two-chain-only">
<div class="preset-chip active" onclick="applyPreset('#80CBC4','#00897B','#FFAB91','#E64A19',this)"><div class="preset-strip"><span style="background:#80CBC4"></span><span style="background:#00897B"></span><span style="background:#E64A19"></span><span style="background:#FFAB91"></span></div>Teal / Coral</div>
<div class="preset-chip" onclick="applyPreset('#b3d4e8','#2471A3','#f5cba7','#E67E22',this)"><div class="preset-strip"><span style="background:#b3d4e8"></span><span style="background:#2471A3"></span><span style="background:#E67E22"></span><span style="background:#f5cba7"></span></div>Blue / Orange</div>
<div class="preset-chip" onclick="applyPreset('#d1c4e9','#5e35b1','#fff3b0','#f9a825',this)"><div class="preset-strip"><span style="background:#d1c4e9"></span><span style="background:#5e35b1"></span><span style="background:#f9a825"></span><span style="background:#fff3b0"></span></div>Purple / Gold</div>
<div class="preset-chip" onclick="applyPreset('#cfd8dc','#546e7a','#f8bbd0','#c2185b',this)"><div class="preset-strip"><span style="background:#cfd8dc"></span><span style="background:#546e7a"></span><span style="background:#c2185b"></span><span style="background:#f8bbd0"></span></div>Slate / Rose</div>
<div class="preset-chip" onclick="applyPreset('#c5cae9','#303f9f','#ffe0b2','#e65100',this)"><div class="preset-strip"><span style="background:#c5cae9"></span><span style="background:#303f9f"></span><span style="background:#e65100"></span><span style="background:#ffe0b2"></span></div>Indigo / Tangerine</div>
<div class="preset-chip" onclick="applyPreset('#a8d5ba','#2e7d32','#ef9a9a','#c62828',this)"><div class="preset-strip"><span style="background:#a8d5ba"></span><span style="background:#2e7d32"></span><span style="background:#c62828"></span><span style="background:#ef9a9a"></span></div>Green / Red</div>
</div>
<label style="margin-top:0.5rem" class="two-chain-only">Presets — high contrast (all 4 colors distinct)</label>
<div class="presets-row two-chain-only">
<div class="preset-chip" onclick="applyPreset('#4DD0E1','#1A237E','#FFAB91','#B71C1C',this)"><div class="preset-strip"><span style="background:#4DD0E1"></span><span style="background:#1A237E"></span><span style="background:#B71C1C"></span><span style="background:#FFAB91"></span></div>Cyan / Navy / Peach / Crimson</div>
<div class="preset-chip" onclick="applyPreset('#81D4FA','#283593','#EF9A9A','#C62828',this)"><div class="preset-strip"><span style="background:#81D4FA"></span><span style="background:#283593"></span><span style="background:#C62828"></span><span style="background:#EF9A9A"></span></div>Sky / Indigo / Salmon / Red</div>
<div class="preset-chip" onclick="applyPreset('#AED581','#1B5E20','#FFD54F','#B71C1C',this)"><div class="preset-strip"><span style="background:#AED581"></span><span style="background:#1B5E20"></span><span style="background:#B71C1C"></span><span style="background:#FFD54F"></span></div>Lime / Forest / Gold / Maroon</div>
<div class="preset-chip" onclick="applyPreset('#80CBC4','#004D40','#FFCC80','#BF360C',this)"><div class="preset-strip"><span style="background:#80CBC4"></span><span style="background:#004D40"></span><span style="background:#BF360C"></span><span style="background:#FFCC80"></span></div>Mint / DarkTeal / Apricot / Burnt</div>
<div class="preset-chip" onclick="applyPreset('#CE93D8','#4A148C','#FFF176','#E65100',this)"><div class="preset-strip"><span style="background:#CE93D8"></span><span style="background:#4A148C"></span><span style="background:#E65100"></span><span style="background:#FFF176"></span></div>Orchid / Purple / Yellow / Fire</div>
<div class="preset-chip" onclick="applyPreset('#BBDEFB','#0D47A1','#A5D6A7','#F4511E',this)"><div class="preset-strip"><span style="background:#BBDEFB"></span><span style="background:#0D47A1"></span><span style="background:#F4511E"></span><span style="background:#A5D6A7"></span></div>Blue / Navy / Sage / Ember</div>
</div>
<label style="margin-top:0.5rem" class="two-chain-only">Presets — solid</label>
<div class="presets-row two-chain-only">
<div class="preset-chip" onclick="applyPreset('#00897B','#00897B','#E64A19','#E64A19',this)"><div class="preset-strip"><span style="background:#00897B"></span><span style="background:#00897B"></span><span style="background:#E64A19"></span><span style="background:#E64A19"></span></div>Teal / Coral</div>
<div class="preset-chip" onclick="applyPreset('#2471A3','#2471A3','#E67E22','#E67E22',this)"><div class="preset-strip"><span style="background:#2471A3"></span><span style="background:#2471A3"></span><span style="background:#E67E22"></span><span style="background:#E67E22"></span></div>Blue / Orange</div>
<div class="preset-chip" onclick="applyPreset('#5e35b1','#5e35b1','#f9a825','#f9a825',this)"><div class="preset-strip"><span style="background:#5e35b1"></span><span style="background:#5e35b1"></span><span style="background:#f9a825"></span><span style="background:#f9a825"></span></div>Purple / Gold</div>
<div class="preset-chip" onclick="applyPreset('#6A9EC6','#6A9EC6','#D4A76A','#D4A76A',this)"><div class="preset-strip"><span style="background:#6A9EC6"></span><span style="background:#6A9EC6"></span><span style="background:#D4A76A"></span><span style="background:#D4A76A"></span></div>Steel / Wheat</div>
<div class="preset-chip" onclick="applyPreset('#6495ED','#6495ED','#FF6347','#FF6347',this)"><div class="preset-strip"><span style="background:#6495ED"></span><span style="background:#6495ED"></span><span style="background:#FF6347"></span><span style="background:#FF6347"></span></div>Cornflower / Tomato</div>
</div>
<label style="margin-top:0.5rem; display:none" id="multichain-presets-label">Presets — multi-chain (auto-assigned per chain)</label>
<div class="presets-row" id="multichain-presets" style="display:none"></div>
<label style="margin-top:0.5rem">Presets — coloring modes</label>
<div class="presets-row">
<div class="preset-chip" onclick="applyCxcPreset('plddt',this)"><div class="preset-strip"><span style="background:#0053D6"></span><span style="background:#65CBF3"></span><span style="background:#FFDB13"></span><span style="background:#FF7D45"></span></div>pLDDT</div>
<div class="preset-chip" onclick="applyCxcPreset('bychain',this)"><div class="preset-strip"><span style="background:#6495ED"></span><span style="background:#FF6347"></span><span style="background:#90EE90"></span><span style="background:#DDA0DD"></span></div>bychain</div>
<div class="preset-chip" onclick="applyCxcPreset('bypolymer',this)"><div class="preset-strip"><span style="background:#87CEEB"></span><span style="background:#FFA07A"></span><span style="background:#98FB98"></span><span style="background:#DDA0DD"></span></div>bypolymer</div>
</div>
<label style="margin-top:1rem" id="two-chain-colors-label">Color Scheme</label>
<div class="color-section" id="two-chain-colors">
<div class="color-group">
<h3>Chain A (Protein 1)</h3>
<div class="color-pair">
<input type="color" id="color-lir-a" value="#80CBC4">
<div><div class="color-label">LIR</div><div class="color-hex" id="hex-lir-a">#80CBC4</div></div>
</div>
<div class="color-pair">
<input type="color" id="color-clir-a" value="#00897B">
<div><div class="color-label">cLIR</div><div class="color-hex" id="hex-clir-a">#00897B</div></div>
</div>
</div>
<div class="color-group">
<h3>Chain B (Protein 2)</h3>
<div class="color-pair">
<input type="color" id="color-lir-b" value="#FFAB91">
<div><div class="color-label">LIR</div><div class="color-hex" id="hex-lir-b">#FFAB91</div></div>
</div>
<div class="color-pair">
<input type="color" id="color-clir-b" value="#E64A19">
<div><div class="color-label">cLIR</div><div class="color-hex" id="hex-clir-b">#E64A19</div></div>
</div>
</div>
</div>
<div style="display:flex; align-items:center; gap:0.8rem; margin-top:0.5rem;">
<div class="color-preview-strip" id="color-strip" style="flex:1; margin:0;">
<div style="background:#80CBC4"></div><div style="background:#00897B"></div><div style="background:#E64A19"></div><div style="background:#FFAB91"></div>
</div>
<button onclick="swapColors()" style="padding:0.3rem 0.8rem; border:2px solid #e0e0e0; border-radius:6px; background:white; cursor:pointer; font-size:0.82rem; color:#666; white-space:nowrap;">Swap A ↔ B</button>
</div>
</div>
<hr style="border:none; border-top:1px solid #e0e0e0; margin-bottom:1rem;">
<div class="input-tabs" style="margin-bottom:0.8rem;">
<button class="input-tab active" data-tab="chimerax" onclick="switchScriptTab('chimerax')">ChimeraX</button>
<button class="input-tab" data-tab="pymol" onclick="switchScriptTab('pymol')">PyMOL</button>
</div>
<div class="script-preview" id="script-preview"></div>
<div class="download-row">
<a class="btn-download cxc" id="dl-script" download>↓ Download <span id="dl-script-ext">.cxc</span></a>
<a class="btn-download cif" id="dl-structure" download>↓ Download structure</a>
<a class="btn-download cxc" id="dl-all-chains" style="background:#1a5276; border-color:#1a5276;" onclick="downloadAllChains()">↓ Download All Chains .cxc</a>
<button class="btn-download" id="btn-copy" style="background:white; color:#2471A3; border:2px solid #2471A3; cursor:pointer;" onclick="copyScript()">Copy to Clipboard</button>
</div>
<div class="info-box" style="margin-top:1rem;">Place the script and structure files in the same folder, then open the script in ChimeraX or PyMOL. "All Chains" shows every chain with LIR regions, colored by chain.</div>
</div>
<!-- Per-Residue pLDDT & Intra-chain LIS -->
<div class="card result-card" id="per-residue-card" style="display:none;">
<h2>Per-Residue Intra-chain LIS & pLDDT <span class="model-badge" id="perresidue-model-badge"></span></h2>
<div style="font-size:0.82rem; color:#888; margin-bottom:0.5rem;">
Per-residue metrics for each chain across all models. Selected model as solid line; other models as light traces; average as dashed line.
</div>
<div id="per-residue-charts"></div>
</div>
</div>
<!-- How to Use -->
<div class="card">
<div class="step-header">How to Use <a href="about.html" style="font-size:0.8rem; font-weight:400; color:#2471A3;">(Full guide)</a></div>
<div style="display:grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap:1.5rem; padding-left:2.3rem;">
<div>
<h4 style="font-size:0.9rem; color:#1a5276; margin-bottom:0.5rem;">Quick Start</h4>
<ol style="padding-left:1.2rem; font-size:0.85rem; color:#555; line-height:1.7;" start="0">
<li>Run a prediction on any supported platform</li>
<li>Download/export the results</li>
<li>Drop the files above — the platform is auto-detected</li>
<li>Click <strong>Process</strong> to calculate AFM-LIS metrics</li>
<li>Click a chain pair in the table to generate a ChimeraX script</li>
<li>Download the script (.cxc or .pml) and structure file, place in the same folder</li>
</ol>
<h4 style="font-size:0.9rem; color:#1a5276; margin-top:0.8rem; margin-bottom:0.5rem;">Platform-Specific Tips</h4>
<ul style="padding-left:1.2rem; font-size:0.82rem; color:#555; line-height:1.7;">
<li><strong>AlphaFold3</strong>: Drop the zip from <a href="https://alphafoldserver.com" target="_blank" style="color:#2471A3;">AlphaFold Server</a> directly</li>
<li><strong>ColabFold</strong>: Upload the output folder or select individual _unrelaxed_rank_*.pdb and _scores_rank_*.json files</li>
<li><strong>Boltz-1/2</strong>: Upload output folder containing .cif, confidence_*.json, and pae_*.npz files</li>
<li><strong>Chai-1</strong>: Upload output folder with pred.model_idx_*.cif and scores files</li>
<li><strong>OpenFold</strong>: Upload .cif with *_full_data*.json files</li>
<li><strong>Generic</strong>: Any .cif/.pdb with a PAE JSON file (predicted_aligned_error field)</li>
</ul>
</div>
<div>
<h4 style="font-size:0.9rem; color:#1a5276; margin-bottom:0.5rem;"><a href="https://github.com/flyark/AFM-LIS" target="_blank" style="color:#2471A3; text-decoration:underline;">AFM-LIS</a> Metrics (<a href="https://doi.org/10.1101/2024.02.19.580970" target="_blank" style="color:#2471A3;">Kim et al. 2024</a>; <a href="https://doi.org/10.64898/2026.04.14.718529" target="_blank" style="color:#2471A3;">Kim et al. 2026</a>)</h4>
<table style="font-size:0.85rem;">
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>iLIS</strong></td><td style="padding:0.25rem 0; color:#555;">integrated LIS — √(LIS × cLIS)</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>iLIA</strong></td><td style="padding:0.25rem 0; color:#555;">integrated LIA — √(LIA × cLIA), geometric mean of interface area counts</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>iLISA</strong></td><td style="padding:0.25rem 0; color:#555;">integrated LISA — iLIS × iLIA, overall binding strength</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>LIS</strong></td><td style="padding:0.25rem 0; color:#555;">Local Interaction Score — normalized PAE confidence (0–1)</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>cLIS</strong></td><td style="padding:0.25rem 0; color:#555;">contact-filtered LIS — restricted to direct contacts</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>LIR</strong></td><td style="padding:0.25rem 0; color:#555;">Local Interaction Residues (PAE ≤ 12 Å)</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>cLIR</strong></td><td style="padding:0.25rem 0; color:#555;">contact-filtered LIR (PAE ≤ 12 Å & Cβ ≤ 8 Å)</td></tr>
</table>
<h4 style="font-size:0.9rem; color:#1a5276; margin-top:0.8rem; margin-bottom:0.5rem;">Confidence Metrics (from prediction platform)</h4>
<table style="font-size:0.85rem;">
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>ipTM</strong></td><td style="padding:0.25rem 0; color:#555;">interface predicted TM-score — global interface confidence from the prediction model</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>ipSAE</strong></td><td style="padding:0.25rem 0; color:#555;">interaction prediction Score from Aligned Errors (<a href="https://doi.org/10.1101/2025.02.10.637595" target="_blank" style="color:#2471A3;">Dunbrack, 2025</a>)</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>actifpTM</strong></td><td style="padding:0.25rem 0; color:#555;">actual interface pTM (<a href="https://doi.org/10.1093/bioinformatics/btaf107" target="_blank" style="color:#2471A3;">Varga et al., 2025</a>)</td></tr>
</table>
<p style="font-size:0.78rem; color:#888; margin-top:0.4rem; line-height:1.4;">PAE (Predicted Aligned Error) measures how confidently the model predicts the relative position of two residues — lower values indicate higher confidence.</p>
</div>
</div>
</div>
<div class="footer">
<a href="https://github.com/flyark/LIVIA" target="_blank">LIVIA GitHub</a> · <a href="https://github.com/flyark/AFM-LIS" target="_blank">AFM-LIS GitHub</a>
<br>
<a href="https://doi.org/10.64898/2026.05.01.721633" target="_blank">Kim & Perrimon (2026)</a>
<br>
Ah-Ram Kim · Harvard Medical School
</div>
</div>
<script src="js/livia-core.js"></script>
<script src="js/livia-scripts.js"></script>
<script src="js/livia-viewer.js"></script>
<script src="js/livia-colors.js"></script>
<script>
// ── Callbacks for shared modules ──
onColorChange = () => { const sel = document.querySelector('#pairs-tbody tr.selected'); if (sel) sel.click(); };
onScriptTabSwitch = () => { updateScriptPreview(); };
document.addEventListener('DOMContentLoaded', initColorPickers);
// ============================================================================
// GLOBAL STATE
// ============================================================================
let uniState = {
platform: null, // 'alphafold3', 'colabfold', 'boltz', 'chai', 'openfold', 'generic'
loadedFiles: {}, // filename -> ArrayBuffer or string
loadedZip: null, // JSZip instance if zip
predictions: [], // [{name, structureFile, structureText, pae, confidenceScores, format}]
selectedIdx: 0,
results: null,
modelData: [],
modelPairs: [],
avgResults: null,
chainNames: null,
chainSizes: null,
chainTypes: null,
nTotal: 0,
structureContents: {}, // idx -> text
structureFilenames: {}, // idx -> filename
structureFormat: 'cif', // 'cif' or 'pdb'
multiChainColors: null,
cxcColorMode: '',
hiddenChains: new Set(), // chain names toggled off — hides them in 3D viewer + chord
};
let viewer3dBlobUrl = null; // blob URL for current iframe page
let viewer3dStructText = null; // cached structure text — postMessage fast-path detection
let viewer3dWarmedUp = false; // iframe was pre-loaded at page entry with placeholder structure
function updateScriptPreview() {
if (!uniState.currentPairResult) return;
const v = uniState.currentPairResult;
const colors = {
lir_a: document.getElementById('color-lir-a')?.value || '#80CBC4',
clir_a: document.getElementById('color-clir-a')?.value || '#00897B',
lir_b: document.getElementById('color-lir-b')?.value || '#FFAB91',
clir_b: document.getElementById('color-clir-b')?.value || '#E64A19',
};
const seedVal = document.getElementById('seed-select')?.value || '0';
const useIdx = seedVal === 'avg' ? Object.keys(uniState.structureFilenames || {})[0] : seedVal;
const structFilename = (uniState.structureFilenames || {})[useIdx] || 'structure.cif';
const isPymol = scriptMode === 'pymol';
const visScript = isPymol ? generatePml(v, structFilename, colors) : generateCxc(v, structFilename, colors);
const scriptExt = isPymol ? '.pml' : '.cxc';
document.getElementById('script-preview').innerHTML = highlightCxc(visScript);
const scriptBlob = new Blob([visScript], { type: 'text/plain' });
const dlScript = document.getElementById('dl-script');
if (dlScript) {
dlScript.href = URL.createObjectURL(scriptBlob);
const name = (v.ci || 'A') + '_' + (v.cj || 'B');
dlScript.download = name + '_interface' + scriptExt;
}
const extEl = document.getElementById('dl-script-ext');
if (extEl) extEl.textContent = scriptExt;
}
// ============================================================================
// NPZ PARSER
// ============================================================================
async function parseNpz(arrayBuffer) {
const zip = await JSZip.loadAsync(arrayBuffer);
const result = {};
for (const [name, file] of Object.entries(zip.files)) {
if (name.endsWith('.npy')) {
const buf = await file.async('arraybuffer');
result[name.replace('.npy', '')] = parseNpy(buf);
}
}
return result;
}
function parseNpy(buffer) {
const view = new DataView(buffer);
// Magic: \x93NUMPY
const major = view.getUint8(6);
let headerLen, headerOffset;
if (major >= 2) {
headerLen = view.getUint32(8, true);
headerOffset = 12;
} else {
headerLen = view.getUint16(8, true);
headerOffset = 10;
}
const headerStr = new TextDecoder().decode(new Uint8Array(buffer, headerOffset, headerLen));
const dataOffset = headerOffset + headerLen;
// Parse dtype
const descrMatch = headerStr.match(/'descr':\s*'([^']+)'/);
const descr = descrMatch ? descrMatch[1] : '<f4';
// Parse shape
const shapeMatch = headerStr.match(/'shape':\s*\(([^)]*)\)/);
if (!shapeMatch) return [];
const shapeParts = shapeMatch[1].split(',').map(s => s.trim()).filter(s => s.length > 0);
const shape = shapeParts.map(s => parseInt(s));
// Determine element type and size
let elementSize = 4;
let isFloat = true;
if (descr.includes('f8') || descr.includes('float64')) { elementSize = 8; isFloat = true; }
else if (descr.includes('f4') || descr.includes('float32')) { elementSize = 4; isFloat = true; }
else if (descr.includes('f2') || descr.includes('float16')) { elementSize = 2; isFloat = true; }
const littleEndian = descr.startsWith('<') || descr.startsWith('|');
// Read data
const totalElements = shape.reduce((a, b) => a * b, 1);
const values = new Float64Array(totalElements);
for (let i = 0; i < totalElements; i++) {
const offset = dataOffset + i * elementSize;
if (elementSize === 8) {
values[i] = view.getFloat64(offset, littleEndian);
} else if (elementSize === 4) {
values[i] = view.getFloat32(offset, littleEndian);
} else if (elementSize === 2) {
// float16 approximation
const h = view.getUint16(offset, littleEndian);
const s = (h >> 15) & 1;
const e = (h >> 10) & 0x1F;
const f = h & 0x3FF;
if (e === 0) values[i] = (s ? -1 : 1) * Math.pow(2, -14) * (f / 1024);
else if (e === 31) values[i] = f ? NaN : (s ? -Infinity : Infinity);
else values[i] = (s ? -1 : 1) * Math.pow(2, e - 15) * (1 + f / 1024);
}
}
// Convert to 2D array if shape has 2 dimensions
if (shape.length === 2) {
const [rows, cols] = shape;
const arr = [];
for (let i = 0; i < rows; i++) {
arr.push(Array.from(values.slice(i * cols, (i + 1) * cols)));
}
return arr;
}
// 1D
if (shape.length === 1) {
return Array.from(values);
}
// 3D+ return flat
return { shape, data: Array.from(values) };
}
// ============================================================================
// DROP ZONE
const EXAMPLES = {
'alphafold3': { file: 'alphafold3_p53_mdm2.zip', label: 'p53–MDM2 (AlphaFold3)', size: '5 MB' },
'colabfold': { file: 'colabfold_p53_mdm2.zip', label: 'p53–MDM2 (ColabFold)', size: '8 MB' },
'boltz2': { file: 'boltz2_p53_mdm2.zip', label: 'p53–MDM2 (Boltz-2)', size: '26 MB' },
'chai-1': { file: 'chai-1_p53_mdm2.zip', label: 'p53–MDM2 (Chai-1)', size: '63 MB' },
'openfold3': { file: 'openfold3_p53_mdm2.zip', label: 'p53–MDM2 (OpenFold3)', size: '33 MB' },
'protenix-v2': { file: 'protenix-v2_p53_mdm2.zip', label: 'p53–MDM2 (Protenix-v2)', size: '21 MB' },
'esmfold2': { file: 'esmfold2_p53_mdm2.zip', label: 'p53–MDM2 (ESMFold2)', size: '2 MB' },
};
async function loadExample(platform) {
const ex = EXAMPLES[platform];
if (!ex) return;
setStatus(`Downloading ${ex.label} (${ex.size})...`, 'loading');
try {
const localUrl = `examples/${ex.file}`;
const remoteUrl = `https://flyark.github.io/LIVIA/examples/${ex.file}`;
let resp;
try { resp = await fetch(localUrl); } catch (e) { resp = null; }
if (!resp || !resp.ok) resp = await fetch(remoteUrl);
if (!resp.ok) throw new Error('Failed to download example file');
const blob = await resp.blob();
const file = new File([blob], ex.file, { type: 'application/zip' });
await handleInputFiles([file]);
} catch (e) {
setStatus('Could not load example: ' + e.message, 'error');
}
}
// ============================================================================
const dropZone = document.getElementById('drop-zone');
const fileInput = document.getElementById('file-input');
const folderInput = document.getElementById('folder-input');
dropZone.addEventListener('click', () => fileInput.click());
dropZone.addEventListener('dragover', e => { e.preventDefault(); dropZone.classList.add('dragover'); });
dropZone.addEventListener('dragleave', () => dropZone.classList.remove('dragover'));
dropZone.addEventListener('drop', async e => {
e.preventDefault();
dropZone.classList.remove('dragover');
// Try reading directory entries (works on http://, may fail on file://)
let handledViaEntries = false;
try {
const items = e.dataTransfer.items;
if (items && items.length > 0) {
const entries = [];
for (let i = 0; i < items.length; i++) {
try {
const getEntry = items[i].webkitGetAsEntry || items[i].getAsEntry;
const entry = getEntry && getEntry.call(items[i]);
if (entry) entries.push(entry);
} catch (_) { /* entry API not available */ }
}
const hasDir = entries.some(en => en.isDirectory);
if (hasDir) {
setStatus('Reading folder contents...', 'loading');
const allFiles = [];
async function readDir(dirEntry, path) {
const reader = dirEntry.createReader();
let batch;
do {
batch = await new Promise(resolve => {
reader.readEntries(
entries => resolve(entries),
() => resolve([])
);
});
for (const en of batch) {
try {
if (en.isFile) {
const file = await new Promise((res, rej) => en.file(f => res(f), rej));
Object.defineProperty(file, 'webkitRelativePath', { value: path + '/' + file.name });
allFiles.push(file);
} else if (en.isDirectory) {
await readDir(en, path + '/' + en.name);
}
} catch (fileErr) {
console.warn('Skipping file:', path, fileErr);
}
}
} while (batch.length > 0);
}
for (const en of entries) {
if (en.isDirectory) await readDir(en, en.name);
else {
try { const file = await new Promise((r, j) => en.file(f => r(f), j)); allFiles.push(file); }
catch (_) {}
}
}
if (allFiles.length > 0) {
handleInputFiles(allFiles);
handledViaEntries = true;
}
} else if (entries.length > 0) {
// Dropped files (not directories) — resolve via entries
const allFiles = [];
for (const en of entries) {
if (en.isFile) {
try { const file = await new Promise((r, j) => en.file(f => r(f), j)); allFiles.push(file); }
catch (_) {}
}
}
if (allFiles.length > 0) {
handleInputFiles(allFiles);
handledViaEntries = true;
}
}
}
} catch (err) {
console.warn('Entry API failed, falling back to files:', err);
}
// Fallback: use e.dataTransfer.files (always works for individual files, not for folders on file://)
if (!handledViaEntries) {
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
handleInputFiles(e.dataTransfer.files);
} else {
setStatus('Folder drop requires a local server (python3 -m http.server). Use "Select Folder" button instead, or drop individual files.', 'error');
}
}
});
fileInput.addEventListener('change', e => { if (e.target.files.length) handleInputFiles(e.target.files); });
folderInput.addEventListener('change', e => { if (e.target.files.length) handleInputFiles(e.target.files); });
// Store all pending files for multi-job selection
let pendingJobs = null;
async function handleInputFiles(fileList) {
// Disable Process immediately — large zips take seconds to load, and a premature
// click would run processFiles with platform=null (fallback: generic, wrong PAE source).
document.getElementById('btn-process').disabled = true;
uniState.loadedFiles = {};
uniState.loadedZip = null;
uniState.predictions = [];
uniState.platform = null;
uniState.results = null;
uniState.modelData = [];
uniState.modelPairs = [];
uniState.avgResults = null;
uniState.chainNames = null;
uniState.chainSizes = null;
uniState.chainTypes = null;
uniState.nTotal = 0;
uniState.structureContents = {};
uniState.structureFilenames = {};
uniState.structureFormat = 'cif';
uniState.multiChainColors = null;
uniState.currentPairResult = null;
uniState.hiddenChains = new Set();
pendingJobs = null;
// Clear drop-zone label so a fresh drop overwrites the previous folder name
const fnEl = document.getElementById('file-name');
if (fnEl) fnEl.textContent = '';
// Clear prediction selector from previous upload
const predSelect = document.getElementById('prediction-select');
if (predSelect) predSelect.innerHTML = '';
const predSelector = document.getElementById('prediction-selector');
if (predSelector) predSelector.style.display = 'none';
const files = Array.from(fileList);
const isFolder = files[0]?.webkitRelativePath?.includes('/');
const folderName = isFolder ? files[0].webkitRelativePath.split('/')[0] : null;
// Detect if parent folder contains multiple prediction jobs (subfolders/zips)
if (isFolder) {
const topDir = folderName;
// Get unique second-level directories and zip files
const subItems = new Set();
for (const f of files) {
const parts = f.webkitRelativePath.split('/');
if (parts.length >= 3) subItems.add(parts[1]); // subfolder name
else if (parts.length === 2 && f.name.endsWith('.zip')) subItems.add(f.name.replace('.zip', ''));
}
// Remove duplicates where both folder and zip exist (prefer folder)
const folderNames = new Set();
for (const f of files) {
const parts = f.webkitRelativePath.split('/');
if (parts.length >= 3) folderNames.add(parts[1]);
}
const jobs = [...subItems].filter(name => {
// Skip if it's a zip name but folder with same name exists
const hasFolder = folderNames.has(name);
const isZipOnly = !hasFolder && files.some(f => f.name === name + '.zip');
return hasFolder || isZipOnly;
}).filter(n => n !== 'msas' && n !== 'templates' && !n.endsWith('.md'));
if (jobs.length > 1) {
// Multiple jobs — show selector (sorted naturally: 001 < 002 < 010 < 020 …)
jobs.sort((a, b) => a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' }));
setStatus(`Found ${jobs.length} predictions. Select one:`, 'loading');
dropZone.classList.add('has-file');
document.getElementById('file-name').textContent = `${topDir}/ (${jobs.length} predictions)`;
pendingJobs = { files, jobs, folderName: topDir };
showJobSelector(jobs);
return;
}
}
// Single job — load directly
await loadFilesIntoState(files, isFolder, folderName);
// Auto-detect platform
const platform = detectPlatform();
uniState.platform = platform;
showPlatformBadge(platform);
// Check for .pkl files (AF2) — warn user
const hasPkl = Array.from(fileList || []).some(f => f.name.endsWith('.pkl'));
const pklWarning = hasPkl ? ' Note: .pkl files detected — PAE data must be converted to JSON first (use: python -c "import pickle,json,sys; d=pickle.load(open(sys.argv[1],\'rb\')); json.dump([{\'predicted_aligned_error\':d[\'predicted_aligned_error\'].tolist()}],open(sys.argv[2],\'w\'))" result_model_1.pkl pae_model_1.json)' : '';
document.getElementById('btn-process').disabled = false;
setStatus(`Detected: ${platformLabel(platform)}. Analyzing…${pklWarning}`);
// Auto-process so the user doesn't need a second click after drop/select.
processFiles();
}
function showJobSelector(jobs) {
const existing = document.getElementById('job-selector');
if (existing) existing.remove();
const div = document.createElement('div');
div.id = 'job-selector';
div.style.cssText = 'display:flex; gap:0.4rem; flex-wrap:wrap; margin-top:0.5rem; align-items:center;';
const label = document.createElement('span');
label.style.cssText = 'font-size:0.82rem; color:#555; font-weight:600;';
label.textContent = 'Select prediction:';
div.appendChild(label);
for (const job of jobs) {
const btn = document.createElement('button');
btn.className = 'example-btn';
btn.dataset.job = job;
btn.textContent = job;
btn.onclick = () => selectJob(job);
div.appendChild(btn);
}
const dropArea = document.getElementById('drop-zone') || document.querySelector('.card');
dropArea.parentNode.insertBefore(div, dropArea.nextSibling);
}
async function selectJob(jobName) {
if (!pendingJobs) return;
const { files, folderName } = pendingJobs;
// Highlight selected button, keep selector visible
const sel = document.getElementById('job-selector');
if (sel) {
sel.querySelectorAll('button').forEach(b => {
b.style.background = b.dataset.job === jobName ? '#2471A3' : '';
b.style.color = b.dataset.job === jobName ? 'white' : '';
});
}
// Filter files to only this job's subfolder or zip
const jobFiles = files.filter(f => {
const path = f.webkitRelativePath || f.name;
const parts = path.split('/');
// Subfolder match: topDir/jobName/file.cif
if (parts.length >= 3 && parts[1] === jobName) return true;
// Zip at second level: topDir/jobName.zip
if (parts.length === 2 && f.name === jobName + '.zip') return true;
// Zip at root level (no webkitRelativePath subfolder): jobName.zip
if (parts.length <= 2 && f.name === jobName + '.zip') return true;
return false;
});
setStatus(`Loading ${jobName}...`, 'loading');
document.getElementById('file-name').textContent = `${folderName}/${jobName}`;
uniState.loadedFiles = {};
uniState.loadedZip = null;
uniState.results = null;
uniState.modelData = [];
uniState.modelPairs = [];
uniState.avgResults = null;
uniState.chainNames = null;
uniState.chainSizes = null;
uniState.chainTypes = null;
uniState.nTotal = 0;
uniState.structureContents = {};
uniState.structureFilenames = {};
uniState.multiChainColors = null;
uniState.currentPairResult = null;
uniState.hiddenChains = new Set();
await loadFilesIntoState(jobFiles, true, folderName);
const nFiles = Object.keys(uniState.loadedFiles).length;
if (nFiles === 0) {
setStatus(`No prediction files found in ${jobName}. Try another.`, 'error');
return;
}
const platform = detectPlatform();
uniState.platform = platform;
showPlatformBadge(platform);
document.getElementById('btn-process').disabled = false;
setStatus(`Loaded ${jobName}: ${nFiles} files (${platformLabel(platform)}). Analyzing…`, 'success');
// Auto-process: skip the extra "Process" click after selecting a prediction.
processFiles();
}
async function loadFilesIntoState(files, isFolder, folderName) {
// Check if all files are zips
const zipFiles = files.filter(f => f.name.endsWith('.zip'));
const nonZipFiles = files.filter(f => !f.name.endsWith('.zip') && !f.name.endsWith('.md'));
if (zipFiles.length > 0 && nonZipFiles.length === 0) {
setStatus(`Reading ${zipFiles.length} zip file(s)...`, 'loading');
for (const zipFile of zipFiles) {
const zip = await JSZip.loadAsync(await zipFile.arrayBuffer());
if (!uniState.loadedZip) uniState.loadedZip = zip;
for (const [path, entry] of Object.entries(zip.files)) {
if (entry.dir || path.startsWith('__MACOSX') || path.includes('/__MACOSX/')) continue;
const fname = path.split('/').pop();
if (!fname) continue;
if (fname.endsWith('.cif') || fname.endsWith('.pdb') || fname.endsWith('.json')) {
uniState.loadedFiles[path] = await entry.async('string');
} else if (fname.endsWith('.npz') || fname.endsWith('.npy')) {
uniState.loadedFiles[path] = await entry.async('arraybuffer');
}
}
}
dropZone.classList.add('has-file');
if (!document.getElementById('file-name').textContent.includes('/'))
document.getElementById('file-name').textContent = zipFiles.length === 1 ? zipFiles[0].name : `${zipFiles.length} zip files`;
} else {
setStatus('Reading files...', 'loading');
for (const file of files) {
const path = file.webkitRelativePath || file.name;
if (path.includes('__MACOSX') || path.includes('/msas/') || path.includes('/templates/')) continue;
if (file.name.endsWith('.cif') || file.name.endsWith('.pdb') || file.name.endsWith('.json')) {
uniState.loadedFiles[path] = await file.text();
} else if (file.name.endsWith('.npz') || file.name.endsWith('.npy')) {
uniState.loadedFiles[path] = await file.arrayBuffer();
} else if (file.name.endsWith('.gz')) {
try {
const ds = new DecompressionStream('gzip');
const decompressed = file.stream().pipeThrough(ds);
const reader = decompressed.getReader();
const chunks = [];
while (true) {
const { done, value } = await reader.read();
if (done) break;
chunks.push(value);
}
const blob = new Blob(chunks);
// Preserve folder path from the dropped path, not just file.name
const innerPath = path.replace(/\.gz$/, '');
if (innerPath.endsWith('.cif') || innerPath.endsWith('.pdb') || innerPath.endsWith('.json')) {
uniState.loadedFiles[innerPath] = await blob.text();
} else if (innerPath.endsWith('.npz') || innerPath.endsWith('.npy')) {
uniState.loadedFiles[innerPath] = await blob.arrayBuffer();
}
} catch (e) {
console.warn('Could not decompress .gz file:', file.name, e);
}
} else if (file.name.endsWith('.xz')) {
try {
// Load xz-decompress library (WASM-based, handles XZ/LZMA2 format)
if (!window['xz-decompress']) {
await new Promise((resolve, reject) => {
const s = document.createElement('script');