-
Notifications
You must be signed in to change notification settings - Fork 0
/
ligand-viewer.js
1173 lines (1100 loc) · 26.2 KB
/
ligand-viewer.js
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
const gradient = [
0xff0932,
0xfb4309,
0xf7a209,
0xe9f408,
0x88f008,
0x2aed07,
0x07e940,
0x07e599,
0x06d5e2,
0x067ade,
0x001d66
];
let ligand_sele = "";
// set stage for html
const stage = new NGL.Stage("viewport");
NGL.DatasourceRegistry.add("data", new NGL.StaticDatasource("data/"));
// set background to white
stage.setParameters({
backgroundColor: "white"
});
// add element to stage's viewer container
let leftbar = document.createElement("div");
Object.assign(leftbar, {
id: 'leftbar'
})
Object.assign(leftbar.style, {
position: "absolute",
overflowY: 'auto',
height: '100%',
top: "0px",
left: "12px",
zIndex: 10
});
stage.viewer.container.appendChild(leftbar);
function addElement() {
for (i = 0; i < arguments.length; i++) {
leftbar.appendChild(arguments[i]);
}
leftbar.appendChild(document.createElement("br"));
}
// Handle window resizing
window.addEventListener(
"resize",
function(event) {
stage.handleResize();
},
false
);
// create element
function createElement(name, properties, style) {
var el = document.createElement(name);
Object.assign(el, properties);
Object.assign(el.style, style);
return el;
}
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;
}
function createFileButton(label, properties, style) {
var input = createElement(
"input",
Object.assign(
{
type: "file"
},
properties
),
{ display: "none" }
);
addElement(input);
var button = createElement(
"input",
{
value: label,
type: "button",
className: 'butt',
onclick: function() {
input.click();
}
},
style
);
return button;
}
// create tooltip element and add to document body
var tooltip = document.createElement("div");
Object.assign(tooltip.style, {
display: "none",
position: "fixed",
zIndex: 10,
pointerEvents: "none",
backgroundColor: "rgba( 0, 0, 0, 0.6 )",
color: "lightgrey",
padding: "8px",
fontFamily: "sans-serif"
});
document.body.appendChild(tooltip);
// remove default hoverPick mouse action
stage.mouseControls.remove("hoverPick");
// listen to `hovered` signal to move tooltip around and change its text
stage.signals.hovered.add(function(pickingProxy) {
if (pickingProxy) {
if (pickingProxy.atom || pickingProxy.bond) {
var atom = pickingProxy.atom || pickingProxy.closestBondAtom;
var vm = atom.structure.data["@valenceModel"];
if (vm && vm.idealValence) {
tooltip.innerHTML = `${pickingProxy.getLabel()}<br/>
<hr/>
Atom: ${atom.qualifiedName()}<br/>
ideal valence: ${vm.idealValence[atom.index]}<br/>
ideal geometry: ${vm.idealGeometry[atom.index]}<br/>
implicit charge: ${vm.implicitCharge[atom.index]}<br/>
formal charge: ${
atom.formalCharge === null ? "?" : atom.formalCharge
}<br/>
aromatic: ${atom.aromatic ? "true" : "false"}<br/>
`;
} else if (vm && vm.charge) {
tooltip.innerHTML = `${pickingProxy.getLabel()}<br/>
<hr/>
Atom: ${atom.qualifiedName()}<br/>
Index: ${atom.index}<br/>
vm charge: ${vm.charge[atom.index]}<br/>
vm implicitH: ${vm.implicitH[atom.index]}<br/>
vm totalH: ${vm.totalH[atom.index]}<br/>
vm geom: ${vm.idealGeometry[atom.index]}</br>
formal charge: ${
atom.formalCharge === null ? "?" : atom.formalCharge
}<br/>
aromatic: ${atom.aromatic ? "true" : "false"}<br/>
`;
} else {
tooltip.innerHTML = `${pickingProxy.getLabel()}`;
}
} else {
tooltip.innerHTML = `${pickingProxy.getLabel()}`;
}
var mp = pickingProxy.mouse.position;
tooltip.style.bottom = window.innerHeight - mp.y + 3 + "px";
tooltip.style.left = mp.x + 3 + "px";
tooltip.style.display = "block";
} else {
tooltip.style.display = "none";
}
});
stage.signals.clicked.add(function(pickingProxy) {
if (pickingProxy && (pickingProxy.atom || pickingProxy.bond)) {
console.log(pickingProxy.atom || pickingProxy.closestBondAtom);
}
});
var ligandSele = "(( not polymer or hetero ) and not ( water or ion ))";
var pocketRadius = 0;
var pocketRadiusClipFactor = 1;
var cartoonRepr,
backboneRepr,
spacefillRepr,
neighborRepr,
ligandRepr,
contactRepr,
pocketRepr,
labelRepr;
var struc;
var neighborSele;
function loadStructure(input) {
struc = undefined;
stage.setFocus(0);
stage.removeAllComponents();
ligandSelect.innerHTML = "";
clipNearRange.value = 0;
clipRadiusRange.value = 100;
pocketOpacityRange.value = 0;
cartoonCheckbox.checked = false;
backboneCheckbox.checked = false;
hydrophobicCheckbox.checked = false;
hydrogenBondCheckbox.checked = true;
weakHydrogenBondCheckbox.checked = false;
waterHydrogenBondCheckbox.checked = true;
backboneHydrogenBondCheckbox.checked = true;
halogenBondCheckbox.checked = true;
metalInteractionCheckbox.checked = true;
saltBridgeCheckbox.checked = true;
cationPiCheckbox.checked = true;
piStackingCheckbox.checked = true;
return stage.loadFile(input).then(function(o) {
struc = o;
setLigandOptions();
setChainOptions();
setResidueOptions();
o.autoView();
cartoonRepr = o.addRepresentation("cartoon", {
visible: false
});
backboneRepr = o.addRepresentation("backbone", {
visible: true,
colorValue: "lightgrey",
radiusScale: 2
});
spacefillRepr = o.addRepresentation("spacefill", {
sele: ligandSele,
visible: true
});
neighborRepr = o.addRepresentation("ball+stick", {
sele: "none",
aspectRatio: 1.1,
colorValue: "lightgrey",
multipleBond: "symmetric"
});
ligandRepr = o.addRepresentation("ball+stick", {
multipleBond: "symmetric",
colorValue: "grey",
sele: "none",
aspectRatio: 1.2,
radiusScale: 2.5
});
contactRepr = o.addRepresentation("contact", {
sele: "none",
radiusSize: 0.07,
weakHydrogenBond: false,
waterHydrogenBond: false,
backboneHydrogenBond: true
});
pocketRepr = o.addRepresentation("surface", {
sele: "none",
lazy: true,
visibility: true,
clipNear: 0,
opaqueBack: false,
opacity: 0.0,
color: "hydrophobicity",
roughness: 1.0,
surfaceType: "av"
});
ETRepr = o.addRepresentation("hyperball", {
sele: "none",
color: 0x00ffffff,
opacity: 0.5
});
labelRepr = o.addRepresentation("label", {
sele: "none",
color: "#333333",
yOffset: 0.2,
zOffset: 2.0,
attachment: "bottom-center",
showBorder: true,
borderColor: "lightgrey",
borderWidth: 0.25,
disablePicking: true,
radiusType: "size",
radiusSize: 0.8,
labelType: "residue",
labelGrouping: "residue"
});
});
}
// get list of ligands
function setLigandOptions() {
ligandSelect.innerHTML = "";
var options = [["", "select ligand"]];
struc.structure.eachResidue(function(rp) {
if (rp.isWater()) return;
var sele = "";
if (rp.resno !== undefined) sele += rp.resno;
if (rp.inscode) sele += "^" + rp.inscode;
if (rp.chain) sele += ":" + rp.chainname;
var name = (rp.resname ? "[" + rp.resname + "]" : "") + sele;
if (rp.entity !== undefined) {
if (rp.entity.description) name += " (" + rp.entity.description + ")"};
options.push([sele, name]);
}, new NGL.Selection(ligandSele));
options.forEach(function(d) {
ligandSelect.add(
createElement("option", {
value: d[0],
text: d[1]
})
);
});
}
// get list of chains
function setChainOptions() {
chainSelect.innerHTML = "";
var options = [["", "select chain"]];
struc.structure.eachChain(function(cp) {
var name = cp.chainname;
if (cp.entity !== undefined) {
if (cp.entity.description) name += " (" + cp.entity.description + ")"};
options.push([cp.chainname, name]);
}, new NGL.Selection("polymer"));
options.forEach(function(d) {
chainSelect.add(
createElement("option", {
value: d[0],
text: d[1]
})
);
});
}
// get list of residues
function setResidueOptions(chain) {
residueSelect.innerHTML = "";
var options = [["", "select residue"]];
if (chain) {
struc.structure.eachResidue(function(rp) {
var sele = "";
if (rp.resno !== undefined) sele += rp.resno;
if (rp.inscode) sele += "^" + rp.inscode;
if (rp.chain) sele += ":" + rp.chainname;
var name = (rp.resname ? "[" + rp.resname + "]" : "") + sele;
options.push([sele, name]);
}, new NGL.Selection("polymer and :" + chain));
}
options.forEach(function(d) {
residueSelect.add(
createElement("option", {
value: d[0],
text: d[1]
})
);
});
}
// add load structure button to load custom structure
var loadStructureButton = createFileButton("load structure", {
accept: ".pdb,.cif,.ent,.gz,.mol2",
onchange: function(e) {
if (e.target.files[0]) {
loadStructure(e.target.files[0]);
}
}
});
addElement(loadStructureButton);
// load from PDB code
var loadPdbidText = createElement("span", {
innerText: "load pdb id"
});
var loadPdbidInput = createElement("input", {
type: "text",
title: "press enter to load pdbid",
onkeypress: function(e) {
if (e.keyCode === 13) {
e.preventDefault();
pdbid = e.target.value.toLowerCase();
ET = getET(pdbid);
loadStructure("rcsb://" + e.target.value);
}
}
}, {width: '120px'});
addElement(loadPdbidText);
addElement(loadPdbidInput);
// show full structure button
function showFull() {
ligandSelect.value = "";
backboneRepr.setParameters({ radiusScale: 2 });
backboneRepr.setVisibility(true);
spacefillRepr.setVisibility(true);
ligandRepr.setVisibility(false);
neighborRepr.setVisibility(false);
contactRepr.setVisibility(false);
pocketRepr.setVisibility(false);
labelRepr.setVisibility(false);
struc.autoView();
}
var fullButton = createElement(
"input",
{
value: "full structure",
className: 'butt',
type: "button",
onclick: showFull
},
{ left: "12px" }
);
addElement(fullButton);
// show ligand based on selection
function showLigand(sele) {
// sele is ligandSele
var s = struc.structure; // structureComponenet from ngl
var withinSele = s.getAtomSetWithinSelection(
new NGL.Selection(sele),
LIGAND_RADIUS
); // select ligand and get atoms in ligands
var withinGroup = s.getAtomSetWithinGroup(withinSele);
var expandedSele = withinGroup.toSeleString(); // expand selection to include neighboring residues?
// neighborSele = '(' + expandedSele + ') and not (' + sele + ')'
neighborSele = expandedSele;
var sview = s.getView(new NGL.Selection(sele)); // get view of ligand
pocketRadius =
Math.max(sview.boundingBox.getSize(new NGL.Vector3()).length() / 2, 2) + 5; // get pocket size?
var withinSele2 = s.getAtomSetWithinSelection(
new NGL.Selection(sele),
pocketRadius + 2
);
var neighborSele2 =
"(" + withinSele2.toSeleString() + ") and not (" + sele + ") and polymer";
backboneRepr.setParameters({ radiusScale: 0.2 });
backboneRepr.setVisibility(backboneCheckbox.checked);
spacefillRepr.setVisibility(false);
ligandRepr.setVisibility(true);
neighborRepr.setVisibility(true);
contactRepr.setVisibility(true);
pocketRepr.setVisibility(true);
labelRepr.setVisibility(labelCheckbox.checked);
ligandRepr.setSelection(sele);
neighborRepr.setSelection(
"(" + neighborSele + ") and (not water)"
);
contactRepr.setSelection("(" + expandedSele + ") and (not water)");
pocketRepr.setSelection(neighborSele2);
pocketRepr.setParameters({
clipRadius: pocketRadius * pocketRadiusClipFactor,
clipCenter: sview.center
});
labelRepr.setSelection("(" + neighborSele + ") and not (water or ion)");
ETRepr.setVisibility(etCheckbox.checked);
var s = struc.structure; // structureComponenet from ngl
neighborSele =
"(" + expandedSele + ") and not (water or ion) and not (" + sele + ")";
ETRepr.setSelection(neighborSele);
ET.then(function(rank) {
ETRepr.setParameters({
color: NGL.ColormakerRegistry.addScheme(function() {
this.atomColor = function(atom) {
return gradient[rank[atom.resno]];
};
})
});
});
struc.autoView(expandedSele);
}
// select ligand
var ligandSelect = createSelect(
[],
{
onchange: function(e) {
residueSelect.value = "";
var sele = e.target.value;
if (!sele) {
showFull();
} else {
ligand_sele = sele;
showLigand(sele);
}
}
},
{width: "130px" }
);
addElement(ligandSelect);
// select chain
var chainSelect = createSelect(
[],
{
onchange: function(e) {
ligandSelect.value = "";
residueSelect.value = "";
setResidueOptions(e.target.value);
}
},
{width: "130px" }
);
addElement(chainSelect);
// select residue
var residueSelect = createSelect(
[],
{
onchange: function(e) {
ligandSelect.value = "";
var sele = e.target.value;
if (!sele) {
showFull();
} else {
ligand_sele = sele;
showLigand(sele);
}
}
},
{width: "130px" }
);
addElement(residueSelect);
addElement()
// ligand radius slider
addElement(
createElement(
"span",
{
innerText: "ligand radius"
},
{color: "grey" }
)
);
var ligandRadiusRange = createElement(
"input",
{
type: "range",
value: 5,
min: 1,
max: 30,
step: 1
}
);
ligandRadiusRange.oninput = function(e) {
LIGAND_RADIUS = parseInt(e.target.value);
showLigand(ligand_sele);
};
addElement(ligandRadiusRange);
// carton checkbox
var cartoonCheckbox = createElement("input", {
type: "checkbox",
checked: false,
onchange: function(e) {
cartoonRepr.setVisibility(e.target.checked);
}
});
addElement(
cartoonCheckbox,
createElement(
"span",
{
innerText: "cartoon"
},
{ color: "grey" }
)
);
// backbone checkbox
var backboneCheckbox = createElement("input", {
type: "checkbox",
checked: false,
onchange: function(e) {
backboneRepr.setVisibility(e.target.checked);
}
});
addElement(
backboneCheckbox,
createElement(
"span",
{
innerText: "backbone"
},
{ color: "grey" }
)
);
// label checkbox
var labelCheckbox = createElement("input", {
type: "checkbox",
checked: true,
onchange: function(e) {
labelRepr.setVisibility(e.target.checked);
}
});
addElement(
labelCheckbox,
createElement(
"span",
{
innerText: "label"
},
{ color: "grey" }
)
);
// ET checkbox
var etCheckbox = createElement("input", {
type: "checkbox",
checked: true,
onchange: function(e) {
ETRepr.setVisibility(e.target.checked);
}
});
addElement(
etCheckbox,
createElement(
"span",
{
innerText: "ET"
},
{ color: "grey" }
)
);
function interactionOptions() {
var options = document.getElementById('interaction')
if (this.value == "Interaction options ▼") {
this.value = "Interaction options ►";
options.style.display = "none";
} else {
this.value = "Interaction options ▼";
options.style.display = "block";
}
}
var interactionButton = createElement(
'input',
{
type: 'button',
value: 'Interaction options ►',
className: 'butt',
onclick: interactionOptions
}
)
addElement(interactionButton)
// pocket near clipping
var interaction = document.createElement('div');
Object.assign(interaction,
{
id: 'interaction',
className: 'collapsible'
})
leftbar.appendChild(interaction)
function addElementInter() {
for (i = 0; i < arguments.length; i++) {
interaction.appendChild(arguments[i]);
}
interaction.appendChild(document.createElement("br"));
}
// hydrophobic interaction checkbox
var hydrophobicCheckbox = createElement(
"input",
{
type: "checkbox",
checked: false,
onchange: function(e) {
contactRepr.setParameters({ hydrophobic: e.target.checked });
}
},
{ left: "12px" }
);
addElementInter(
hydrophobicCheckbox,
createElement(
"span",
{
innerText: "hydrophobic"
},
{ color: "grey" }
)
);
// hydrogen bond checkbox
var hydrogenBondCheckbox = createElement("input", {
type: "checkbox",
checked: false,
onchange: function(e) {
contactRepr.setParameters({ hydrogenBond: e.target.checked });
}
});
addElementInter(
hydrogenBondCheckbox,
createElement(
"span",
{
innerText: "hbond"
},
{ color: "grey" }
)
);
// weak hydrogen bond checkbox
var weakHydrogenBondCheckbox = createElement("input", {
type: "checkbox",
checked: false,
onchange: function(e) {
contactRepr.setParameters({ weakHydrogenBond: e.target.checked });
}
});
addElementInter(
weakHydrogenBondCheckbox,
createElement(
"span",
{
innerText: "weak hbond"
},
{ color: "grey" }
)
);
// water hydrogen bond checkbox
var waterHydrogenBondCheckbox = createElement("input", {
type: "checkbox",
checked: false,
onchange: function(e) {
contactRepr.setParameters({ waterHydrogenBond: e.target.checked });
}
});
addElementInter(
waterHydrogenBondCheckbox,
createElement(
"span",
{
innerText: "water-water hbond"
},
{ color: "grey" }
)
);
// backbone hydrogen bond checkbox
var backboneHydrogenBondCheckbox = createElement("input", {
type: "checkbox",
checked: false,
onchange: function(e) {
contactRepr.setParameters({ backboneHydrogenBond: e.target.checked });
}
});
addElementInter(
backboneHydrogenBondCheckbox,
createElement(
"span",
{
innerText: "backbone-backbone hbond"
},
{ color: "grey" }
)
);
// halogen bond checkbox
var halogenBondCheckbox = createElement("input", {
type: "checkbox",
checked: true,
onchange: function(e) {
contactRepr.setParameters({ halogenBond: e.target.checked });
}
});
addElementInter(
halogenBondCheckbox,
createElement(
"span",
{
innerText: "halogen bond"
},
{ color: "grey" }
)
);
// metal interaction checkbox
var metalInteractionCheckbox = createElement("input", {
type: "checkbox",
checked: true,
onchange: function(e) {
contactRepr.setParameters({ metalComplex: e.target.checked });
}
});
addElementInter(
metalInteractionCheckbox,
createElement(
"span",
{
innerText: "metal interaction"
},
{ color: "grey" }
)
);
// ionic interaction checkbox
var ionicInteractionCheckbox = createElement('input', {
type: 'checkbox',
checked: true,
onchange: function (e) {
contactRepr.setParameters({ ionicInteraction: e.target.checked })
}
})
addElementInter(ionicInteractionCheckbox, createElement('span', {
innerText: 'ionic interaction'
}, { color: 'grey' }))
// metal coordination checkbox
var metalCoordinationCheckbox = createElement('input', {
type: 'checkbox',
checked: true,
onchange: function (e) {
contactRepr.setParameters({ metalCoordination: e.target.checked })
}
})
addElementInter(metalCoordinationCheckbox, createElement('span', {
innerText: 'metal coordination'
}, { color: 'grey' }))
// saltbridge checkbox
var saltBridgeCheckbox = createElement("input", {
type: "checkbox",
checked: true,
onchange: function(e) {
contactRepr.setParameters({ saltBridge: e.target.checked });
}
});
addElementInter(
saltBridgeCheckbox,
createElement(
"span",
{
innerText: "salt bridge"
},
{ color: "grey" }
)
);
//cation-pi checkbox
var cationPiCheckbox = createElement("input", {
type: "checkbox",
checked: true,
onchange: function(e) {
contactRepr.setParameters({ cationPi: e.target.checked });
}
});
addElementInter(
cationPiCheckbox,
createElement(
"span",
{
innerText: "cation-pi"
},
{ color: "grey" }
)
);
// pi-stacking checkbox
var piStackingCheckbox = createElement("input", {
type: "checkbox",
checked: true,
onchange: function(e) {
contactRepr.setParameters({ piStacking: e.target.checked });
}
});
addElementInter(
piStackingCheckbox,
createElement(
"span",
{
innerText: "pi-stacking"
},
{ color: "grey" }
),
createElement("br")
);
function pocketOptions() {
var options = document.getElementById('pocket')
if (this.value == "show pocket options ▼") {
this.value = "show pocket options ►"
options.style.display = "none";
} else {
this.value = "show pocket options ▼"
options.style.display = "block";
}
}
var pocketButton = createElement(
'input',
{
type: 'button',
value: 'show pocket options ►',
className: 'butt',
onclick: pocketOptions
}
)
addElement(pocketButton)
// pocket near clipping
var pocket = document.createElement('div');
Object.assign(pocket,
{
id: 'pocket',
className: 'collapsible'
})
leftbar.appendChild(pocket)
function addElementPocket() {
for (i = 0; i < arguments.length; i++) {
pocket.appendChild(arguments[i]);
}
pocket.appendChild(document.createElement("br"));
}
addElementPocket(
createElement(
"span",
{
innerText: "pocket near clipping"
},
{ color: "grey" }
)
);
var clipNearRange = createElement(
"input",
{
type: "range",
value: 0,
min: 0,
max: 10000,
step: 1,
className: 'pocket'
}
);
clipNearRange.oninput = function(e) {
var sceneRadius =
stage.viewer.boundingBox.getSize(new NGL.Vector3()).length() / 2;
var f = pocketRadius / sceneRadius;
var v = parseFloat(e.target.value) / 10000; // must be between 0 and 1
var c = 0.5 - f / 2 + v * f;
pocketRepr.setParameters({
clipNear: c * 100 // must be between 0 and 100
});
};
addElementPocket(clipNearRange);
// pocket radius
addElementPocket(
createElement(
"span",
{
innerText: "pocket radius clipping",
className: 'pocket'
},
{color: "grey" }
)
);
var clipRadiusRange = createElement(
"input",
{
type: "range",
value: 100,
min: 1,
max: 100,
step: 1,
className: 'pocket'
},
{ left: "12px" }
);
clipRadiusRange.oninput = function(e) {
pocketRadiusClipFactor = parseFloat(e.target.value) / 100;
pocketRepr.setParameters({
clipRadius: pocketRadius * pocketRadiusClipFactor
});
};
addElementPocket(clipRadiusRange);
// pocket opacity slider
addElementPocket(
createElement(
"span",
{
innerText: "pocket opacity",
className: 'pocket'
},
{color: "grey" }
)
);
var pocketOpacityRange = createElement(
"input",
{
type: "range",
value: 90,
min: 0,
max: 100,
step: 1,