-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpropdb.html
More file actions
1242 lines (1042 loc) · 39.9 KB
/
Copy pathpropdb.html
File metadata and controls
1242 lines (1042 loc) · 39.9 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" />
<title>ProPDB — amrqhz</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/3Dmol/1.6.3/3Dmol-min.js"></script>
<link rel="icon" href="Group 84.svg">
<meta name="theme-color" content="e0004b">
<!-- Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-4M9T82SQS9"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-4M9T82SQS9');
</script>
<style>
:root{
--g : #e0004b;
--radius:12px;
--muted:#9aa6b2;
--accent-grad: linear-gradient(90deg,#6ee7b7,#39a6ff);
--bg: linear-gradient(180deg,#071421,#091428);
--card: rgba(11,18,32,0.78);
--text:#e6eef6;
--control-bg: rgba(255,255,255,0.02);
/* --btn-bg: linear-gradient(90deg,#6ee7b7,#39a6ff); */
--btn-bg: #d1d1d1;
}
html,body{height:100%; margin:0; font-family:Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial; color:var(--text); background:var(--bg);}
.app {
display: grid;
grid-template-columns: 320px 1fr;
gap: 16px;
height: 100vh;
padding: 16px;
box-sizing: border-box;
}
@media (max-width: 900px) {
.app {
grid-template-columns: 1fr;
height: 100vh;
height: 100dvh;
padding: 0;
gap: 0;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
overflow: hidden;
}
.hamburger-btn {
display: flex;
}
.sidebar {
position: fixed;
left: 0;
top: 0;
width: 250px;
height: 100vh;
height: 100dvh;
overflow-y: auto;
transform: translateX(-100%);
transition: transform 0.3s ease;
z-index: 1000;
box-shadow: 5px 0 20px rgba(0,0,0,0.5);
}
.sidebar.active {
transform: translateX(0);
}
.overlay {
display: none;
position: fixed;
inset: 0;
background: rgba(0,0,0,0.5);
z-index: 999;
}
.overlay.active {
display: block;
}
.viewer-wrap {
width: 100%;
height: 100%;
overflow: hidden;
border-radius: 0;
}
#viewer {
width: 100%;
height: 100%;
overflow: auto;
}
}
/* Desktop: hide hamburger */
@media (min-width: 901px) {
.hamburger-btn { display: none !important; }
.overlay { display: none !important; }
}
/* Scrollbar styling */
.sidebar::-webkit-scrollbar {
width: 7px;
}
.sidebar::-webkit-scrollbar-track {
background: var(--card);
border-radius: var(--radius);
}
.sidebar::-webkit-scrollbar-thumb {
background: rgba(110,231,183,0.4);
border-radius: var(--radius);
}
.sidebar::-webkit-scrollbar-thumb:hover {
background: rgba(110,231,183,0.6);
}
/* Sidebar */
.sidebar { background:var(--card); border-radius:var(--radius); padding:16px; display:flex; flex-direction:column; gap:12px; box-shadow:0 10px 30px rgba(133, 133, 133, 0.6); border:1px solid rgba(255,255,255,0.02); overflow-y: auto; }
.brand { display:flex; gap:10px; align-items:center; background-color: #d1d1d1; border-radius: 12px; justify-content: center;}
.logo img { width:45px; height:39px; margin-top: 10px; }
.title { font-size:1.05rem; font-weight:700; }
.subtitle { color:var(--muted); font-size:0.86rem; }
.control { background:var(--control-bg); padding:12px; border-radius:10px; border:1px solid rgba(255,255,255,0.02); }
.control small{ display:block; color:var(--muted); margin-bottom:6px; font-size:0.86rem; }
.row { display:flex; gap:8px; align-items:center; }
input[type="text"], select, .small-input { width:100%; padding:9px 10px; border-radius:8px; border:1px solid rgba(255,255,255,0.06); background:transparent; color:inherit; outline:none; font-size:0.95rem; box-sizing:border-box; }
input[type="file"] { color:var(--muted); }
.btn { padding:9px 12px; border-radius:10px; border:0; cursor:pointer; font-weight:700; background:var(--btn-bg); color:#02121a; box-shadow:0 8px 18px rgba(44,187,150,0.08); }
.btn.ghost { background:transparent; color:var(--text); border:1px solid rgba(255,255,255,0.06); font-weight:600; }
.btn.small { padding:7px 8px; font-size:0.92rem; border-radius:8px; }
.hamburger-btn {
position: fixed;
top: 18px;
left: 18px;
width: 47px;
height: 51px;
background: var(--btn-bg);
border: none;
border-radius: 10px;
cursor: pointer;
z-index: 1001;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
gap: 5px;
}
.hamburger-btn span {
width: 24px;
height: 2px;
background: #02121a;
border-radius: 2px;
transition: all 0.3s ease;
}
.hamburger-btn.active span:nth-child(1) {
transform: rotate(45deg) translate(8px, 8px);
}
.hamburger-btn.active span:nth-child(2) {
opacity: 0;
}
.hamburger-btn.active span:nth-child(3) {
transform: rotate(-45deg) translate(8px, -8px);
}
/* Viewer */
.viewer-wrap { border-radius:var(--radius); overflow:hidden; position:relative; display:flex; flex-direction:column; box-shadow:0 10px 30px rgba(133, 133, 133, 0.6); border:1px solid rgba(255,255,255,0.02); }
#viewer { flex:1; min-height:420px; background:transparent; }
.floating-panel { position:absolute; right:10px; bottom:10px; background:var(--control-bg) ; padding:12px; border-radius:12px; min-width:100px; color:var(--muted);font-size: 12px;}
.muted { color:var(--muted); }
.loading-overlay { position:absolute; inset:0; display:none; align-items:center; justify-content:center; z-index:80; background:linear-gradient(180deg, rgba(2,6,23,0.65), rgba(2,6,23,0.45)); font-weight:700; color:var(--muted); }
.loading-card { text-align:center; padding:16px; border-radius:10px; background: rgba(0,0,0,0.35); border:1px solid rgba(255,255,255,0.03); }
.help-overlay { position:fixed; inset:0; display:none; align-items:center; justify-content:center; z-index:90; background: rgba(2,6,23,0.6); }
.help-card { background:var(--card); padding:18px; border-radius:10px; width:500px; max-width:95%; color:var(--text); }
.footer { font-size:0.70rem; color:var(--muted); text-align:center; padding:8px; font-family: monospace;}
.footer a { color:var(--muted); text-decoration:none; transition:color 150ms ease; }
.footer a:hover { color:var(--text); }
.footer span { opacity:0.5; }
.residue-letter {
font-family: monospace;
padding: 2px 5px;
border-radius: 4px;
cursor: default;
color: #fafafa;
}
.residue-letter:hover {
background: rgb(255, 255, 255);
color: #091428;
}
/* Residue box scrollbar */
#residue-box {
scrollbar-width: thin; /* Firefox */
scrollbar-color: #6ee7b7 transparent;
}
/* Chrome, Edge, Safari */
#residue-box::-webkit-scrollbar {
width: 6px;
}
#residue-box::-webkit-scrollbar-track {
background: transparent;
}
#residue-box::-webkit-scrollbar-thumb {
background-color: rgba(110,231,183,0.45);
border-radius: 6px;
}
#residue-box::-webkit-scrollbar-thumb:hover {
background-color: rgba(110,231,183,0.7);
}
/* smooth */
.control, .btn, select, input[type="text"]{ transition: all 150ms ease; }
.btn:hover{ transform:translateY(-1px); }
</style>
</head>
<body>
<div class="app" id="app">
<button class="hamburger-btn" id="hamburger-btn">
<span></span>
<span></span>
<span></span>
</button>
<div class="overlay" id="overlay"></div>
<aside class="sidebar" id="sidebar" aria-label="Controls">
<div class="brand">
<div class="logo">
<img src="Group 84.svg" alt="Pro pdb logo">
</div>
<div>
<div class="title" style="color: #071421;">ProPDB</div>
</div>
</div>
<div class="control" id="load-control">
<small>Load (local or RCSB)</small>
<input id="file-input" type="file" accept=".pdb,.ent,.cif,.mmcif,.sdf,.mol2" style="margin: 10px 0 10px 0;"/>
<div style="height:10px;"></div>
<div class="row">
<input id="pdbid" type="text" placeholder="PDB ID (e.g. 6hdf)" />
<button id="fetch-btn" class="btn small">Fetch</button>
</div>
<div style="height:8px;"></div>
<div id="load-status" class="muted" style="margin: 10px 0 10px 0;">Ready</div>
</div>
<div class="control" id="basic-info-control">
<small>Structure info</small>
<div id="basic-info" class="muted" style="line-height:1.6;">
No structure loaded.
</div>
</div>
<div class="control" id="representation-control">
<small>Main representation</small>
<select id="rep-select" class="small-input" style="background-color: #091428;">
<option value="cartoon">Cartoon / Ribbon</option>
<option value="line">Line</option>
<option value="stick">Stick</option>
<option value="sphere">Sphere (CPK)</option>
<option value="surface">Surface</option>
<option value="cartoon+stick">Cartoon + Ligands</option>
</select>
<div style="height:8px;"></div>
<small>Coloring</small>
<select id="color-select" class="small-input" style="background-color: #091428;">
<option value="spectrum">Spectrum</option>
<option value="chain">By chain</option>
<option value="residue">By residue</option>
<option value="element">By element (CPK)</option>
<option value="secondary">By secondary structure</option>
<option value="uniform">Uniform (gray)</option>
</select>
</div>
<div class="control" id="residue-control">
<small>Residue selection</small>
<select id="chain-select" class="small-input" style="background-color:#091428;">
<option value="all">All chains</option>
</select>
<div style="height:8px;"></div>
<div class="row">
<input id="resi-start" type="number" placeholder="Start" class="small-input" />
<input id="resi-end" type="number" placeholder="End" class="small-input" />
</div>
<div style="height:8px;"></div>
<div class="row" style="justify-content: center; align-items: center;">
<button id="apply-residue" class="btn small">Apply</button>
<button id="clear-residue" class="btn small">Clear</button>
</div>
<div class="control" style="margin-top: 1rem;">
<small>Residues</small>
<div id="residue-box" style="
font-family: monospace;
font-size: 12px;
line-height: 1.6;
white-space: pre-wrap;
max-height: 180px;
overflow-y: auto;">No structure loaded.</div>
</div>
</div>
<div class="control" id="ligand-control">
<small>Ligand selection</small>
<select id="ligand-dropdown" class="small-input" style="background-color: #091428;">
<option value="none">None</option>
<option value="all">All ligands</option>
</select>
<div style="height:8px;"></div>
<small>Ligand style</small>
<select id="lig-style" class="small-input" style="background-color: #091428;">
<option value="stick">Stick</option>
</select>
<div style="height:8px;"></div>
<small>Ligand color</small>
<select id="lig-color" class="small-input" style="background-color: #091428;" >
<option value="element">CPK (element)</option>
<option value="uniform">Uniform (yellow)</option>
<option value="chain">By chain</option>
</select>
</div>
<!-- if i want to show the binding site i should uncomment this section-->
<!-- <div class="control" id="binding-site-control">
<small>Binding site</small>
<label style="display:flex; align-items:center; gap:8px;">
<input id="show-pocket" type="checkbox">
<span class="muted">Show binding pocket</span>
</label>
<div style="height:8px;"></div>
<small>Distance (Å)</small>
<input id="pocket-distance" type="number" value="4" min="2" max="8" step="0.5" class="small-input" style="background-color:#091428;">
</div> -->
<div class="control" id="render-control">
<small>Rendering & tools</small>
<div class="row" style="margin-top:8px;">
<button id="center-btn" class="btn ghost small">Center</button>
<button id="reset-btn" class="btn ghost small">Reset</button>
<button id="spin-btn" class="btn ghost small">Spin</button>
</div>
<div style="height:8px;"></div>
<button id="snapshot-btn" class="btn small">Snapshot</button>
<div style="height:8px;"></div>
<label style="display:flex; align-items:center; gap:8px; cursor:pointer;">
<input id="transparent-bg" type="checkbox">
<span class="muted" style="font-size: 14px;">Transparent background</span>
</label>
<div style="height:8px;"></div>
<!-- <div class="muted">Tip: C = center, R = reset, S = snapshot</div> -->
</div>
<div class="control footer">
<a href="https://github.com/amrqhz" title="GitHub">GitHub</a>
<span>•</span>
<a href="#" title="Documentation">Docs</a>
<span>•</span>
<a href="https://telegram.me/amrqhz" title="Contact">Contact</a>
<span>•</span>
<span>by amrqhz</span>
</div>
<div class="control" style="margin-bottom: 2rem;">
<small style="text-align: center;font-family: monospace;">for more info contact with me</small>
<p>👀 Total Visitors: <span id="visitors"></span></p>
</div>
</aside>
<main class="viewer-wrap" aria-label="Viewer">
<div id="viewer"></div>
<div class="loading-overlay" id="loading">
<div class="loading-card">
Loading...
<div id="loading-info" class="muted" style="margin-top:8px; font-weight:400;"></div>
</div>
</div>
<div class="floating-panel" id="floating-panel">
<div style="font-weight:300; margin-bottom:6px;">Selection</div>
<div id="selection-list" class="muted">No atoms selected.</div>
<div id="measure-info" class="muted" style="margin-top:8px;">Click two atoms to measure distance (Å).</div>
</div>
</main>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
fetch('https://abacus.jasoncameron.dev/hit/amrqhz.github.io/propdb-visits')
.then(response => response.json())
.then(data => {
document.getElementById('visitors').innerText = data.value;
})
.catch(error => {
console.error('Error fetching visitor count:', error);
document.getElementById('visitors').innerText = 'N/A';
});
});
// Helper
const el = id => document.getElementById(id);
// Hamburger menu
const hamburger = el('hamburger-btn');
const sidebar = el('sidebar');
const overlay = el('overlay');
const DEFAULT_BG = 0x071421;
let currentBgColor = DEFAULT_BG;
const AA_3_TO_1 = {
ALA:'A', ARG:'R', ASN:'N', ASP:'D',
CYS:'C', GLU:'E', GLN:'Q', GLY:'G',
HIS:'H', ILE:'I', LEU:'L', LYS:'K',
MET:'M', PHE:'F', PRO:'P', SER:'S',
THR:'T', TRP:'W', TYR:'Y', VAL:'V'
};
const AA_FULL = {
ALA:'Alanine', ARG:'Arginine', ASN:'Asparagine', ASP:'Aspartate',
CYS:'Cysteine', GLU:'Glutamate', GLN:'Glutamine', GLY:'Glycine',
HIS:'Histidine', ILE:'Isoleucine', LEU:'Leucine', LYS:'Lysine',
MET:'Methionine', PHE:'Phenylalanine', PRO:'Proline', SER:'Serine',
THR:'Threonine', TRP:'Tryptophan', TYR:'Tyrosine', VAL:'Valine'
};
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
sidebar.classList.toggle('active');
overlay.classList.toggle('active');
});
overlay.addEventListener('click', () => {
hamburger.classList.remove('active');
sidebar.classList.remove('active');
overlay.classList.remove('active');
});
// Close sidebar when a link/control is used on mobile
document.querySelectorAll('.control select, .control button').forEach(el => {
el.addEventListener('click', () => {
if(window.innerWidth <= 900) {
hamburger.classList.remove('active');
sidebar.classList.remove('active');
overlay.classList.remove('active');
}
});
});
// Viewer & state
const viewerDiv = el('viewer');
viewerDiv.style.height = 'calc(100dvh - 48px)';
const viewer = $3Dmol.createViewer(viewerDiv, { defaultcolors: $3Dmol.rasmolElementColors, backgroundColor: DEFAULT_BG, antialias:true });
let currentModel = null;
let selectedAtoms = [];
let spinInterval = null;
let spinUsingAPI = false;
let ligandGroups = [];
let cachedResidues = null;
// Loading helper
function showLoading(text){
el('loading-info').textContent = text || '';
el('loading').style.display = 'flex';
}
function hideLoading(){ el('loading').style.display = 'none'; }
// Format guess
function guessFormat(name){
if(!name) return 'pdb';
const s = name.toLowerCase();
if(s.endsWith('.cif')||s.endsWith('.mmcif')) return 'mmcif';
if(s.endsWith('.sdf')) return 'sdf';
return 'pdb';
}
async function fetchBasicPDBInfo(pdbId) {
const infoDiv = el('basic-info');
infoDiv.innerHTML = 'Fetching structure info…';
try {
/* --- 1. ENTRY DATA (resolution + entity IDs) --- */
const entryRes = await fetch(
`https://data.rcsb.org/rest/v1/core/entry/${pdbId}`
);
if (!entryRes.ok) throw new Error('Entry not found');
const entry = await entryRes.json();
/* Resolution */
const resolution =
entry.rcsb_entry_info?.resolution_combined?.[0]
? `${entry.rcsb_entry_info.resolution_combined[0]} Å`
: 'N/A';
const entityIds = entry.rcsb_entry_container_identifiers?.polymer_entity_ids || [];
/* --- 2. POLYMER ENTITY DATA (organism + mutation) --- */
const organismSet = new Set();
let mutation = 'No';
for (const entId of entityIds) {
const entRes = await fetch(
`https://data.rcsb.org/rest/v1/core/polymer_entity/${pdbId}/${entId}`
);
if (!entRes.ok) continue;
const ent = await entRes.json();
/* Organism */
(ent.rcsb_entity_source_organism || []).forEach(o => {
if (o.ncbi_scientific_name) {
organismSet.add(o.ncbi_scientific_name);
}
});
/* Mutation */
if (
ent.entity_poly?.rcsb_mutation_count &&
ent.entity_poly.rcsb_mutation_count > 0
) {
mutation = 'Yes';
}
}
const organism =
organismSet.size > 0 ? [...organismSet].join(', ') : 'N/A';
/* --- 3. UI UPDATE --- */
infoDiv.innerHTML = `
<strong>Resolution:</strong> ${resolution}<br/>
<strong>Organism:</strong> ${organism}<br/>
<strong>Mutation(s):</strong> ${mutation}
`;
} catch (err) {
console.error(err);
infoDiv.innerHTML = `
<strong>Resolution:</strong> N/A<br/>
<strong>Organism:</strong> N/A<br/>
<strong>Mutation(s):</strong> N/A
`;
}
}
// Utility: group ligands (hetflag true) by resn+resi+chain
function detectLigands(model){
ligandGroups = [];
if(!model) return ligandGroups;
const hetAtoms = model.selectedAtoms({hetflag:true});
if(!hetAtoms || hetAtoms.length === 0) return ligandGroups;
const ignoreResn = [
'HOH','WAT','H2O','NA','CL','MG','CA','K','ZN','MN','CU','CO','FE','SO4','PO4',
'ACT','DMS','MPD','PEG','NAG','GOL','EDO','IPA','TRS'
];
const map = {};
for(const a of hetAtoms){
const resn = a.resn.trim().toUpperCase();
if(ignoreResn.includes(resn)) continue;
const key = `${resn} ${a.chain}:${a.resi}`;
if(!map[key]) map[key] = {resn:a.resn, chain:a.chain, resi:a.resi, atoms:[]};
map[key].atoms.push(a);
}
for(const k of Object.keys(map)){
if(map[k].atoms.length < 6) delete map[k];
}
ligandGroups = Object.values(map).sort((a,b)=>a.id?.localeCompare?.(b.id) || 0);
ligandGroups.forEach(g => g.id = `${g.resn} ${g.chain}:${g.resi}`);
return ligandGroups;
}
function populateChainDropdown() {
const sel = el('chain-select');
sel.innerHTML = '<option value="all">All chains</option>';
if (!currentModel) return;
const atoms = currentModel.selectedAtoms({ hetflag: false });
const chains = [...new Set(atoms.map(a => a.chain).filter(Boolean))];
chains.forEach(c => {
const opt = document.createElement('option');
opt.value = c;
opt.textContent = `Chain ${c}`;
sel.appendChild(opt);
});
}
// Populate ligand dropdown
function populateLigandDropdown(){
const dd = el('ligand-dropdown');
const prev = dd.value;
dd.innerHTML = '';
const optNone = document.createElement('option'); optNone.value='none'; optNone.textContent='None';
const optAll = document.createElement('option'); optAll.value='all'; optAll.textContent='All ligands';
dd.appendChild(optNone);
dd.appendChild(optAll);
for(const g of ligandGroups){
const o = document.createElement('option');
o.value = JSON.stringify({resn:g.resn, chain:g.chain, resi:g.resi});
o.textContent = g.id;
dd.appendChild(o);
}
if([...''].includes(prev)){ dd.value = prev; }
}
// Clear selection markers and labels
function clearSelection(){
selectedAtoms.forEach(a=>{ if(a._selLabel) viewer.removeLabel(a._selLabel); });
selectedAtoms = [];
viewer.removeAllShapes('selection_spheres');
viewer.removeAllShapes('measure_cylinders');
el('selection-list').innerHTML = 'No atoms selected.';
el('measure-info').textContent = 'Click two atoms to measure distance (Å).';
viewer.render();
}
// Apply main representation & re-style ligands according to dropdown
function applyRepresentation(){
if(!currentModel) return;
const rep = el('rep-select').value;
const colorSel = el('color-select').value;
viewer.setStyle({}, {});
const mainColor = mapColor(colorSel);
if(rep === 'cartoon' || rep === 'cartoon+stick'){
viewer.setStyle({hetflag:false}, {cartoon:{color: mainColor}});
} else if(rep === 'line'){
viewer.setStyle({hetflag:false}, {line:{}});
} else if(rep === 'stick'){
viewer.setStyle({hetflag:false}, {stick:{radius:0.14, colorscheme: mainColor}});
} else if(rep === 'sphere'){
viewer.setStyle({hetflag:false}, {sphere:{scale:0.35, color: mainColor}});
} else if(rep === 'surface'){
viewer.setStyle({hetflag:false}, {surface:{opacity:0.90, color: mainColor}});
}
// applyBindingSite();
applyLigandStyle();
viewer.zoomTo();
viewer.render();
}
function applyResidueSelection() {
if (!currentModel) return;
const chain = el('chain-select').value;
const start = parseInt(el('resi-start').value);
const end = parseInt(el('resi-end').value);
const focusSel = {};
if (chain !== 'all') focusSel.chain = chain;
if (!isNaN(start) && !isNaN(end) && end >= start) {
// create an array of residue numbers
focusSel.resi = [];
for (let i = start; i <= end; i++) focusSel.resi.push(i);
}
/* 1️⃣ Dim protein only */
viewer.setStyle({hetflag:false}, {
cartoon: { color: '#64748b', opacity: 0.45 }
});
/* 2️⃣ Highlight focused region */
viewer.setStyle(focusSel, {
cartoon: { color: '#ef4444', opacity: 1.0 },
});
/* 3️⃣ Keep ligands visible */
applyLigandStyle();
// viewer.zoomTo(focusSel);
viewer.render();
}
function clearResidueSelection() {
el('chain-select').value = 'all';
el('resi-start').value = '';
el('resi-end').value = '';
applyRepresentation();
}
function mapColor(sel){
if(sel==='chain') return 'chain';
if(sel==='residue') return 'residue';
if(sel==='spectrum') return 'spectrum';
if(sel==='element') return 'element';
if(sel==='secondary') return 'spectrum';
if(sel==='uniform') return 'grey';
return 'spectrum';
}
// Apply ligand style based on dropdown selection
function applyLigandStyle(){
if(!currentModel) return;
const ligSel = el('ligand-dropdown').value;
const style = el('lig-style').value;
const colorOpt = el('lig-color').value;
viewer.setStyle({hetflag:true}, {});
let colorStrategy = 'element';
if(colorOpt === 'element') colorStrategy = 'element';
else if(colorOpt === 'uniform') colorStrategy = 'grey';
else if(colorOpt === 'chain') colorStrategy = 'chain';
if(ligSel === 'none'){
viewer.render();
return;
}
if(ligSel === 'all'){
if(style === 'stick'){
viewer.setStyle({hetflag:true}, {stick:{radius:0.18, colorscheme: colorStrategy}});
} else if(style === 'sphere'){
viewer.setStyle({hetflag:true}, {sphere:{scale:0.38, color: colorStrategy}});
} else if(style === 'surface'){
viewer.setStyle({hetflag:true}, {surface:{opacity:0.95, color: colorStrategy}});
}
} else {
let selObj = null;
try { selObj = JSON.parse(ligSel); } catch(e){ selObj = null; }
if(selObj){
const selFilter = {resn: selObj.resn, chain: selObj.chain, resi: selObj.resi};
if(style === 'stick'){
viewer.setStyle(selFilter, {stick:{radius:0.18, colorscheme: colorStrategy}});
} else if(style === 'sphere'){
viewer.setStyle(selFilter, {sphere:{scale:0.38, color: colorStrategy}});
} else if(style === 'surface'){
viewer.setStyle(selFilter, {surface:{opacity:0.95, color: colorStrategy}});
}
}
}
viewer.render();
}
// function extractResidueSequence(model) {
// const atoms = model.selectedAtoms({ hetflag: false });
// const chains = {};
// atoms.forEach(a => {
// if (!a.chain || !a.resi) return;
// if (!chains[a.chain]) chains[a.chain] = {};
// // one entry per residue
// if (!chains[a.chain][a.resi]) {
// chains[a.chain][a.resi] = a.resn;
// }
// });
// return chains;
// }
function extractResidues(model) {
const atoms = model.selectedAtoms({ hetflag:false });
const chains = {};
atoms.forEach(a => {
if (!a.chain || !a.resi) return;
if (!chains[a.chain]) chains[a.chain] = {};
if (!chains[a.chain][a.resi]) {
chains[a.chain][a.resi] = {
resn: a.resn,
resi: a.resi
};
}
});
return chains;
}
function renderResidueBoxForChain(chain) {
const box = document.getElementById('residue-box');
if (!cachedResidues) {
box.textContent = 'No structure loaded.';
return;
}
box.innerHTML = '';
const chainsToShow =
chain === 'all'
? Object.keys(cachedResidues).sort()
: [chain];
chainsToShow.forEach(c => {
const residues = cachedResidues[c];
if (!residues) return;
const title = document.createElement('div');
title.innerHTML = `<strong>Chain ${c}</strong>`;
box.appendChild(title);
const line = document.createElement('div');
line.style.display = 'flex';
line.style.flexWrap = 'wrap';
line.style.gap = '6px';
line.style.marginBottom = '12px';
Object.values(residues)
.sort((a,b)=>a.resi-b.resi)
.forEach(r => {
const span = document.createElement('span');
span.className = 'residue-letter';
span.textContent = AA_3_TO_1[r.resn] || 'X';
span.dataset.resn = r.resn;
span.dataset.resi = r.resi;
span.dataset.chain = c;
line.appendChild(span);
});
box.appendChild(line);
});
}
const tooltip = document.createElement('div');
tooltip.style.position = 'fixed';
tooltip.style.padding = '6px 8px';
tooltip.style.background = 'rgba(0,0,0,0.85)';
tooltip.style.color = 'white';
tooltip.style.fontSize = '15px';
tooltip.style.borderRadius = '6px';
tooltip.style.pointerEvents = 'select';
tooltip.style.display = 'none';
tooltip.style.zIndex = 100;
tooltip.style.transition = 'opacity 1.5s ease';
document.body.appendChild(tooltip);
document.addEventListener('mouseover', e => {
const el = e.target;
if (!el.classList.contains('residue-letter')) return;
const resn = el.dataset.resn;
const resi = el.dataset.resi;
tooltip.textContent = `${AA_FULL[resn] || resn} ${resi}`;
tooltip.style.display = 'block';
});
document.addEventListener('mousemove', e => {
tooltip.style.left = e.clientX + 15 + 'px';
tooltip.style.top = e.clientY + 15 + 'px';
});
document.addEventListener('mouseout', e => {
if (e.target.classList.contains('residue-letter')) {
tooltip.style.display = 'none';
}
});
// function renderResidueBox(model) {
// const box = document.getElementById('residue-box');
// if (!model) {
// box.textContent = 'No structure loaded.';
// return;
// }
// const chains = extractResidueSequence(model);
// let output = '';
// Object.keys(chains).sort().forEach(chain => {
// const residues = Object.keys(chains[chain])
// .sort((a,b) => a - b)
// .map(resi => chains[chain][resi])
// .join(' ');
// output += `Chain ${chain}:\n${residues}\n\n`;
// });
// box.textContent = output.trim();
// }
// function applyBindingSite() {
// if (!currentModel) return;
// if (!el('show-pocket').checked) {
// // viewer.removeAllSurfaces();
// viewer.render();
// return;
// }
// const dist = parseFloat(el('pocket-distance').value) || 4;
// const ligSel = el('ligand-dropdown').value;
// if (ligSel === 'none') return;
// viewer.removeAllSurfaces();
// let ligandSelection;
// if (ligSel === 'all') {
// ligandSelection = { hetflag: true };
// } else {
// try {
// const o = JSON.parse(ligSel);
// ligandSelection = { resn: o.resn, chain: o.chain, resi: o.resi };
// } catch {
// return;
// }
// }
// // Pocket residues (protein only)
// viewer.setStyle(
// {
// hetflag: false,
// within: { distance: dist, sel: ligandSelection }
// },
// {
// stick: { radius: 0.2, colorscheme: 'residue' }
// }
// );
// // Optional pocket surface
// viewer.addSurface(
// $3Dmol.SurfaceType.MS,
// {
// opacity: 0.65,
// color: 'white'
// },
// {
// hetflag: false,
// within: { distance: dist, sel: ligandSelection }
// }
// );
// viewer.render();
// }
// Load model from string (pdb or mmcif)
function loadModelFromString(txt, fmt, sourceLabel){
showLoading('Parsing & rendering...');
el('load-status').textContent = 'Loading ' + (sourceLabel||'file') + ' ...';
viewer.clear();
currentModel = null;
ligandGroups = [];
populateLigandDropdown();