-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathselect.js
75 lines (64 loc) · 1.88 KB
/
select.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
requirejs.config({
'baseUrl' : 'src' ,
// uncomment the following commented-out block to test the contatenated,
// minified PV version. Grunt needs to be run before for this to work.
/*
paths : {
pv : '/js/bio-pv.min'
}
*/
});
// on purpose outside of the require block, so we can inspect the viewer object
// from the JavaScript console.
var viewer;
var pv;
require(['pv'], function(PV) {
pv = PV;
viewer = pv.Viewer(document.getElementById('viewer'), {
width : 'auto', height: 'auto', antialias : true,
outline : true, quality : 'medium', style : 'hemilight',
selectionColor : 'red',
background : '#333', animateTime: 500, doubleClick : null
});
viewer.options('selectionColor', '#f00');
pv.io.fetchPdb('/pdbs/1crn.pdb', function(s) {
viewer.on('viewerReady', function() {
var go = viewer.spheres('crambin', s, { showRelated: '1'});
go.setSelection(go.select({rnumRange : [15,20]}));
viewer.autoZoom();
});
});
document.addEventListener('keypress', function(ev) {
if (ev.charCode === 13) {
var allSelections = [];
viewer.forEach(function(go) {
if (go.selection !== undefined) {
allSelections.push(go.selection());
}
});
viewer.fitTo(allSelections);
}
});
viewer.on('click', function(picked, ev) {
if (picked === null || picked.target() === null) {
return;
}
if (picked.node().structure === undefined) {
return;
}
var extendSelection = ev.shiftKey;
var sel;
if (extendSelection) {
var sel = picked.node().selection();
} else {
var sel = picked.node().structure().createEmptyView();
}
if (!sel.removeAtom(picked.target(), true)) {
// in case atom was not part of the view, we have to add it, because it
// wasn't selected before. Otherwise removeAtom took care of it.
sel.addAtom(picked.target());
}
picked.node().setSelection(sel);
viewer.requestRedraw();
});
});