-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
642 lines (549 loc) · 19.8 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en" style="margin: 0px; padding: 0px; width: 100%; height: 100%">
<head>
<title>NGL - embedded</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
canvas {
background-color: #18141E !important;
}
</style>
</head>
<body style="width:100vw;height:100vh">
<label for="fileSelector">
Choose local PDB file:
</label>
<input type="file" accept=".pdb" id="fileSelector" onChange="onFileChange()"/>
<div id="viewport"
style="height: 100%; margin: 0px; padding: 0px; background-color:#18141E">
</div>
<script src="ngl.js"></script>
<script>
var assemblySelect;
var baseCheckbox;
var chainAnnotCheckbox;
var font_style = "11px arial,sans-serif";
var ionCheckbox;
var ligandAnnotCheckbox;
var ligandCheckbox;
var ligandsurfCheckbox;
var resLabelsCheckbox;
var sidechainsSelect;
var stage;
var structureSelect;
var waterCheckbox;
function onFileChange() {
const fileSelector = document.getElementById("fileSelector");
const files = fileSelector.files;
if (files.length == 1) {
const pdbFile = files[0];
loadStructure(pdbFile);
}
}
function loadStructure(pdbFile) {
try {
let el = document.getElementById("viewport");
el.innerHTML = "";
stage = new NGL.Stage("viewport");
//let stringBlob = new Blob([pdbText], { type: 'text/plain' });
stage.loadFile(pdbFile, { ext: "pdb" }).then(function (o) {
o.addRepresentation("cartoon", {
sele: "polymer",
name: "polymer",
assembly: "AU"
}); // pass schemeId here
// add solvent molecules to viewer
o.addRepresentation("ball+stick", {
name: "water",
sele: "water",
colorScheme: "element"
});
// add ion molecules to viewer
o.addRepresentation("spacefill", {
name: "ion",
sele: "ion",
colorScheme: "element"
});
// add nucleic acids and base pairs to viewer, if applicable
o.addRepresentation("ribbon", {
name: "nucleic",
sele: "nucleic",
colorScheme: "element"
});
o.addRepresentation("base", {
name: "base"
});
// add ligand to viewer, if applicable
o.addRepresentation("ball+stick", {
name: "ligand",
sele: "ligand",
colorScheme: "element"
});
o.addRepresentation("surface", {
name: "ligand_surf",
sele: "ligand",
surfaceType: "av",
smooth: 2,
probeRadius: 1.4,
scaleFactor: 2.0,
flatShaded: false,
opacity: 0.1,
lowResolution: false,
colorValue: "gray"
});
o.autoView();
});
function createElement(name, properties, style) {
var elem = document.createElement(name);
Object.assign(elem, properties);
Object.assign(elem.style, style);
return elem;
};
function addElement(elem) {
Object.assign(elem.style, {
position: "absolute",
zIndex: 10
});
stage.viewer.container.appendChild(elem);
};
function createSelect(options, properties, style) {
var select = createElement("select", properties, style);
options.forEach(function (d) {
select.add(createElement("option", {
value: d[0], text: d[1]
}));
});
return select;
};
var assemblyText = createElement("span", {
innerText: "Assembly Representation Style",
}, { top: "40px", left: "16px", color: "white" }
);
addElement(assemblyText);
assemblyText.style.font = font_style;
assemblySelect = createSelect([
["AU", "Asymmetric Unit"],
["BU1", "Bioassembly 1"],
["BU2", "Bioassembly 2"],
["UNITCELL", "Unitcell"],
["SUPERCELL", "Supercell"]
], {
title: "Change assembly representation style",
onchange: function (e) {
stage.eachComponent(function (o) {
o.removeAllRepresentations();
o.addRepresentation(structureSelect.value, {
sele: "polymer",
name: "polymer",
assembly: e.target.value
}); // pass schemeId here
// add solvent molecules to viewer
var water_toggle = o.addRepresentation("ball+stick", {
name: "water",
sele: "water",
assembly: e.target.value,
colorScheme: "element"
});
water_toggle.setVisibility(waterCheckbox.checked);
// add ion molecules to viewer
var ion_toggle = o.addRepresentation("spacefill", {
name: "ion",
sele: "ion",
assembly: e.target.value,
colorScheme: "element"
});
ion_toggle.setVisibility(ionCheckbox.checked);
// add nucleic acids and base pairs to viewer, if applicable
o.addRepresentation("ribbon", {
name: "nucleic",
sele: "nucleic",
assembly: e.target.value,
colorScheme: "element"
});
var base_toggle = o.addRepresentation("base", {
name: "base",
assembly: e.target.value
});
base_toggle.setVisibility(baseCheckbox.checked);
// add ligand to viewer, if applicable
var ligand_toggle = o.addRepresentation("ball+stick", {
name: "ligand",
sele: "ligand",
assembly: e.target.value,
colorScheme: "element"
});
ligand_toggle.setVisibility(ligandCheckbox.checked);
var ligandsurf_toggle = o.addRepresentation("surface", {
name: "ligand_surf",
sele: "ligand",
assembly: e.target.value,
surfaceType: "av",
smooth: 2,
probeRadius: 1.4,
scaleFactor: 2.0,
flatShaded: false,
opacity: 0.1,
lowResolution: false,
colorValue: "gray"
});
ligandsurf_toggle.setVisibility(ligandsurfCheckbox.checked);
// add labels to residues
o.structure.eachChain(function (cp) {
var res_label = o.addRepresentation("label", {
name: "res_label",
sele: ".CA",
assembly: e.target.value,
color: "element",
labelType: "format",
//labelFormat: "" + cp.entity.description + " %(resname)s%(resno)s"
labelFormat: "%(resname)s%(resno)s"
});
res_label.setVisibility(resLabelsCheckbox.checked);
}, new NGL.Selection("polymer"));
// get all sidechain atoms around ligand
var selection = new NGL.Selection("ligand");
var radius = sidechainsSelect.value;
// get first (and only) loaded component: protein-ligand system
var system = this.stage.compList[0];
// store current selection, we will need it later
var prevSele = system.selection.string;
// set selection to desired ligand
system.setSelection("{selection}");
// select all atoms within selected distance from the ligand
var around = system.structure.getAtomSetWithinSelection(selection, radius);
// extend selection so it includes full residues
var around_complete = system.structure.getAtomSetWithinGroup(around);
// update selection to include only sidechain atoms
var sidechain_sele = "(" + around_complete.toSeleString() + ") and not ligand";
// add representation for selected atoms
system.addRepresentation("ball+stick", {
name: "sidechains",
sele: sidechain_sele,
assembly: e.target.value,
colorScheme: "element"
});
system.setSelection(prevSele);
});
stage.autoView();
}
}, { top: "55px", left: "16px" });
addElement(assemblySelect);
assemblySelect.style.font = font_style;
var structureText = createElement("span", {
innerText: "Structure Representation Style",
}, { top: "80px", left: "16px", color: "white" }
);
addElement(structureText);
structureText.style.font = font_style;
structureSelect = createSelect([
["cartoon", "Cartoon"],
["backbone", "Backbone"],
["licorice", "Licorice"],
["ribbon", "Ribbon"],
["tube", "Tube"]
], {
title: "Change structure representation style",
onchange: function (e) {
stage.getRepresentationsByName("polymer").dispose();
stage.eachComponent(function (o) {
o.addRepresentation(e.target.value, {
sele: "polymer",
name: "polymer",
assembly: assemblySelect.value
}); // pass schemeId here
});
}
}, { top: "95px", left: "16px" });
addElement(structureSelect);
structureSelect.style.font = font_style;
chainAnnotCheckbox = createElement("input", {
type: "checkbox",
title: "Show/hide chain annotations",
checked: false,
onchange: function (e) {
if (console.log) console.log(e.target.checked);
stage.eachComponent(function (o) {
o.removeAllAnnotations();
// add annotations to chains
var ap = o.structure.getAtomProxy();
o.structure.eachChain(function (cp) {
ap.index = cp.atomOffset + Math.floor(cp.atomCount / 2);
//var chain_annot = o.addAnnotation(ap.positionToVector3(), cp.entity.description);
var chain_annot = o.addAnnotation(ap.positionToVector3(), "" + cp.entity.description + " {MOLECULE " + cp.chainid + "}");
chain_annot.setVisibility(e.target.checked);
}, new NGL.Selection("polymer"));
// add annotations to ligands
o.structure.eachChain(function (cp) {
ap.index = cp.atomOffset + Math.floor(cp.atomCount / 2);
//var ligand_annot = o.addAnnotation(ap.positionToVector3(), cp.entity.description);
var ligand_annot = o.addAnnotation(ap.positionToVector3(), "" + cp.entity.description + " {MOLECULE " + (cp.chainid - 1) + "}");
ligand_annot.setVisibility(ligandAnnotCheckbox.checked);
}, new NGL.Selection("ligand"));
});
}
}, { top: "140px", left: "12px" }
);
addElement(chainAnnotCheckbox);
var chainAnnot = createElement("span",
{ innerText: "Chain Annotations" },
{ top: "143px", left: "32px", color: "white" }
);
addElement(chainAnnot);
chainAnnot.style.font = font_style;
ligandAnnotCheckbox = createElement("input", {
type: "checkbox",
title: "Show/hide ligand and ion annotations",
checked: false,
onchange: function (e) {
if (console.log) console.log(e.target.checked);
stage.eachComponent(function (o) {
o.removeAllAnnotations();
// add annotations to chains
var ap = o.structure.getAtomProxy();
o.structure.eachChain(function (cp) {
ap.index = cp.atomOffset + Math.floor(cp.atomCount / 2);
//chain_annot = o.addAnnotation(ap.positionToVector3(), cp.entity.description);
var chain_annot = o.addAnnotation(ap.positionToVector3(), "" + cp.entity.description + " {MOLECULE " + cp.chainid + "}");
chain_annot.setVisibility(chainAnnotCheckbox.checked);
}, new NGL.Selection("polymer"));
// add annotations to ligands
o.structure.eachChain(function (cp) {
ap.index = cp.atomOffset + Math.floor(cp.atomCount / 2);
//ligand_annot = o.addAnnotation(ap.positionToVector3(), cp.entity.description);
var ligand_annot = o.addAnnotation(ap.positionToVector3(), "" + cp.entity.description + " {MOLECULE " + (cp.chainid - 1) + "}");
ligand_annot.setVisibility(e.target.checked);
}, new NGL.Selection("ligand"));
});
}
}, { top: "160px", left: "12px" }
);
addElement(ligandAnnotCheckbox);
var ligandAnnot = createElement("span",
{ innerText: "Ligand & Ion Annotations" },
{ top: "163px", left: "32px", color: "white" }
);
addElement(ligandAnnot);
ligandAnnot.style.font = font_style;
resLabelsCheckbox = createElement("input", {
type: "checkbox",
title: "Show/hide residue labels",
checked: false,
onchange: function (e) {
if (console.log) console.log(e.target.checked);
stage.getRepresentationsByName("res_label").dispose();
stage.eachComponent(function (o) {
// add labels to residues
o.structure.eachChain(function (cp) {
var res_label = o.addRepresentation("label", {
name: "res_label",
sele: ".CA",
assembly: assemblySelect.value,
color: "element",
labelType: "format",
//labelFormat: "(" + cp.entity.description + ") %(resname)s%(resno)s"
labelFormat: "%(resname)s%(resno)s"
});
res_label.setVisibility(e.target.checked);
}, new NGL.Selection("polymer"));
});
}
}, { top: "180px", left: "12px" }
);
addElement(resLabelsCheckbox);
var resLabels = createElement("span",
{ innerText: "Residue Labels" },
{ top: "183px", left: "32px", color: "white" }
);
addElement(resLabels);
resLabels.style.font = font_style;
baseCheckbox = createElement("input", {
type: "checkbox",
title: "Show/hide base pairs",
checked: true,
onchange: function (e) {
if (console.log) console.log(e.target.checked);
stage.getRepresentationsByName("base").setVisibility(e.target.checked);
}
}, { top: "220px", left: "12px" }
);
addElement(baseCheckbox);
var basePairs = createElement("span",
{ innerText: "Base Pairs" },
{ top: "223px", left: "32px", color: "white" }
);
addElement(basePairs);
basePairs.style.font = font_style;
ionCheckbox = createElement("input", {
type: "checkbox",
title: "Show/hide ions",
checked: true,
onchange: function (e) {
if (console.log) console.log(e.target.checked);
stage.getRepresentationsByName("ion").setVisibility(e.target.checked);
}
}, { top: "240px", left: "12px" }
);
addElement(ionCheckbox);
var Ions = createElement("span",
{ innerText: "Ions" },
{ top: "243px", left: "32px", color: "white" }
);
addElement(Ions);
Ions.style.font = font_style;
ligandCheckbox = createElement("input", {
type: "checkbox",
title: "Show/hide molecular ligand representations",
checked: true,
onchange: function (e) {
if (console.log) console.log(e.target.checked);
stage.getRepresentationsByName("ligand").setVisibility(e.target.checked);
}
}, { top: "260px", left: "12px" }
);
addElement(ligandCheckbox);
var Ligand = createElement("span",
{ innerText: "Ligands" },
{ top: "263px", left: "32px", color: "white" }
);
addElement(Ligand);
Ligand.style.font = font_style;
ligandsurfCheckbox = createElement("input", {
type: "checkbox",
title: "Show/hide surface ligand representations",
checked: true,
onchange: function (e) {
if (console.log) console.log(e.target.checked);
stage.getRepresentationsByName("ligand_surf").setVisibility(e.target.checked);
}
}, { top: "280px", left: "12px" }
);
addElement(ligandsurfCheckbox);
var ligandSurf = createElement("span",
{ innerText: "Ligand Surfaces" },
{ top: "283px", left: "32px", color: "white" }
);
addElement(ligandSurf);
ligandSurf.style.font = font_style;
waterCheckbox = createElement("input", {
type: "checkbox",
title: "Show/hide water molecules",
checked: true,
onchange: function (e) {
if (console.log) console.log(e.target.checked);
stage.getRepresentationsByName("water").setVisibility(e.target.checked);
}
}, { top: "300px", left: "12px" }
);
addElement(waterCheckbox);
var Water = createElement("span",
{ innerText: "Water" },
{ top: "303px", left: "32px", color: "white" }
);
addElement(Water);
Water.style.font = font_style;
var sidechainsText = createElement("span", {
innerText: "Sidechains Around Ligands",
}, { top: "340px", left: "16px", color: "white" }
);
addElement(sidechainsText);
sidechainsText.style.font = font_style;
sidechainsSelect = createSelect([
["0", "None"],
["5", "Within 5 Å"],
["10", "Within 10 Å"],
["15", "Within 15 Å"],
["20", "Within 20 Å"]
], {
title: "Show residues around ligands within selected radius",
onchange: function (e) {
stage.getRepresentationsByName("sidechains").dispose();
stage.eachComponent(function () {
// get all sidechain atoms around ligand
var selection = new NGL.Selection("ligand");
var radius = e.target.value;
// get first (and only) loaded component: protein-ligand system
var system = this.stage.compList[0];
// store current selection, we will need it later
var prevSele = system.selection.string;
// set selection to desired ligand
system.setSelection("{selection}");
// select all atoms within selected distance from the ligand
var around = system.structure.getAtomSetWithinSelection(selection, radius);
// extend selection so it includes full residues
var around_complete = system.structure.getAtomSetWithinGroup(around);
// update selection to include only sidechain atoms
var sidechain_sele = "(" + around_complete.toSeleString() + ") and not ligand";
// add representation for selected atoms
system.addRepresentation("ball+stick", {
name: "sidechains",
sele: sidechain_sele,
assembly: assemblySelect.value,
colorScheme: "element"
});
system.setSelection(prevSele);
});
}
}, { top: "355px", left: "16px" });
addElement(sidechainsSelect);
sidechainsSelect.style.font = font_style;
var centerButton = createElement("input", {
type: "button",
title: "Reset structure position to default",
value: "Auto Center + Zoom",
onclick: function () {
stage.autoView();
}
}, { top: "740px", left: "16px" }
);
addElement(centerButton);
centerButton.style.font = font_style;
var screenshotButton = createElement("input", {
type: "button",
title: "Take screenshot and download PNG",
value: "Screenshot",
onclick: function () {
stage.makeImage({
factor: 1,
antialias: false,
trim: false,
transparent: false
}).then(function (blob) {
NGL.download(blob, "ngl-viewer-screenshot.png")
});
}
}, { top: "740px", left: "138px" }
);
addElement(screenshotButton);
screenshotButton.style.font = font_style;
var rockButton = createElement("input", {
type: "button",
title: "Toggle rock on/off along y-axis",
value: "Rock",
onclick: function () {
stage.toggleRock();
}
}, { top: "740px", left: "217px" }
);
addElement(rockButton);
rockButton.style.font = font_style;
var spinButton = createElement("input", {
type: "button",
title: "Toggle spin on/off along y-axis",
value: "Spin",
onclick: function () {
stage.toggleSpin();
}
}, { top: "740px", left: "265px" }
);
addElement(spinButton);
spinButton.style.font = font_style;
return true;
} catch (error) {
console.log(error);
return false;
}
}
</script>
</body>
</html>