-
Notifications
You must be signed in to change notification settings - Fork 33
/
index.html
279 lines (237 loc) · 10.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<title>PDBe Molstar</title>
<!-- Molstar CSS & JS -->
<link rel="stylesheet" type="text/css" href="build/pdbe-molstar.css">
<script type="text/javascript" src="build/pdbe-molstar-plugin.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
padding: 30px;
}
h2 {
margin-bottom: 20px;
}
h3 {
margin-bottom: 2px;
}
h4 {
margin-top: 6px;
margin-bottom: 2px;
}
h4:first-child {
margin-top: 0px;
}
.content {
display: flex;
flex-wrap: wrap-reverse;
gap: 30px;
}
.controlsSection {
width: 300px;
}
.controlBox {
border: 1px solid lightgray;
padding: 10px;
margin-bottom: 20px;
}
#myViewer {
width: 450px;
height: 450px;
position: relative;
}
button {
margin-right: 8px;
margin-bottom: 8px;
padding: 1px;
padding-inline: 4px;
}
button:last-child {
margin-bottom: 0px;
}
</style>
</head>
<body>
<h2>PDBe Molstar</h2>
<div class="content">
<div class="controlsSection">
<h3>Canvas/ layout methods</h3>
<div class="controlBox">
<h4>Set Background</h4>
<button onclick="viewerInstance.canvas.setBgColor('white')">White</button>
<button onclick="viewerInstance.canvas.setBgColor('black')">Black</button>
<h4>Toggle controls menu</h4>
<button onclick="viewerInstance.canvas.toggleControls(false)">Hide</button>
<button onclick="viewerInstance.canvas.toggleControls(true)">Show</button>
<button onclick="viewerInstance.canvas.toggleControls()">Toggle</button>
<h4>Toggle Fullscreen</h4>
<button onclick="viewerInstance.canvas.toggleExpanded(true)">Show Fullscreen</button>
</div>
<h3>Visual Methods</h3>
<div class="controlBox">
<h4>Change representation visibility</h4>
<button onclick="viewerInstance.visual.visibility({ water: false })">Hide Water Visual</button>
<button onclick="viewerInstance.visual.visibility({ water: true })">Show Water Visual</button>
<h4>Toggle Spin</h4>
<button onclick="viewerInstance.visual.toggleSpin(true)">Rotate</button>
<button onclick="viewerInstance.visual.toggleSpin(false)">Stop</button>
<button onclick="viewerInstance.visual.toggleSpin()">Toggle</button>
<h4>Focus</h4>
<button onclick="viewerInstance.visual.focus([{ struct_asym_id: 'A', start_residue_number: 14, end_residue_number: 18 }])">
Focus on Chain A:14-18
</button>
<h4>Highlight</h4>
<button onclick="viewerInstance.visual.highlight({ data: [{ struct_asym_id: 'A', start_residue_number: 14, end_residue_number: 18 }], color: '#ffff00' })">
Highlight Chain A:14-18
</button>
<button onclick="viewerInstance.visual.clearHighlight()">
Clear Highlight
</button>
<h4>Selection</h4>
<button onclick="viewerInstance.visual.select({ data: [{ struct_asym_id: 'A', color: '#ffff00', focus: true }] })">
Select & Focus on Chain A
</button>
<br>
<button onclick="viewerInstance.visual.select({ data: [{ struct_asym_id: 'B', color: '#ffff00', focus: true }]})">
Select & Focus on Chain B
</button>
<br>
<button onclick="viewerInstance.visual.select({ data: [{ struct_asym_id: 'B', start_residue_number: 1, end_residue_number: 6, color: '#ffff00' }]})">
Select Chain B:1-6
</button>
<br>
<button onclick="viewerInstance.visual.select({ data: [
{ struct_asym_id: 'B', start_residue_number: 1, end_residue_number: 6, color: '#ffff00' },
{ struct_asym_id: 'B', start_residue_number: 15, end_residue_number: 20, color: '#88ff00' }]})">
Select Chain B:1-6, B:15-20
</button>
<br>
<button onclick="viewerInstance.visual.select({ data: [
{ struct_asym_id: 'B', start_residue_number: 1, end_residue_number: 6, color: '#ffff00', sideChain: true },
{ struct_asym_id: 'B', start_residue_number: 15, end_residue_number: 20, color: '#88ff00', representation: 'spacefill', representationColor: '#ff00ff' }]})">
</button>
<br>
<button onclick="viewerInstance.visual.select({ data: [{ uniprot_accession: 'P02070', start_uniprot_residue_number: 122, end_uniprot_residue_number: 142, color: '#ff00ff' }], nonSelectedColor: '#ffffff' })">
Select Uniprot
</button>
<br>
<button onclick="viewerInstance.visual.clearSelection()">
Clear Selection
</button>
<h4>Set highlight / selection colour</h4>
<button onclick="viewerInstance.visual.setColor({ highlight: '#ffff00' })">
Yellow highlight
</button>
<button onclick="viewerInstance.visual.reset({ highlightColor: true })">
Reset
</button>
<br>
<button onclick="viewerInstance.visual.setColor({ select: '#ff0000' })">
Red selection
</button>
<button onclick="viewerInstance.visual.reset({ selectColor: true })">
Reset
</button>
<h4>Custom tooltips</h4>
<button onclick="viewerInstance.visual.tooltips({ data: [
{ struct_asym_id: 'A', tooltip: 'Custom tooltip for chain A' },
{ struct_asym_id: 'B', tooltip: 'Custom tooltip for chain B' },
{ struct_asym_id: 'C', tooltip: 'Custom tooltip for chain C' },
{ struct_asym_id: 'D', tooltip: 'Custom tooltip for chain D' },
] });">
Add tooltips
</button>
<button onclick="viewerInstance.visual.clearTooltips();">
Clear
</button>
<h4>Reset Visual</h4>
<button onclick="viewerInstance.visual.reset({ camera: true })">
Camera
</button>
<button onclick="viewerInstance.visual.reset({ theme: true })">
Theme
</button>
<button onclick="viewerInstance.visual.reset({ camera: true, theme: true })">
Camera & Theme
</button>
<h4>Update data</h4>
<button onclick="viewerInstance.visual.update({ moleculeId: '1cbs' }, false)">
Update (add)
</button>
<button onclick="viewerInstance.visual.update({ moleculeId: '1cbs' }, true)">
Update (replace)
</button>
</div>
<div>
<h3>Options</h3>
<div class="controlBox">
<pre id="options"></pre>
</div>
</div>
</div>
<div class="viewerSection">
<h3>PDBe Mol* JS Plugin Demo</h3>
<!-- Molstar container -->
<div id="myViewer"></div>
</div>
</div>
<script>
function getJsonParam(paramName) {
const paramString = new URL(window.location).searchParams.get(paramName);
const param = JSON.parse(paramString);
return param ?? undefined;
}
/** Load CSS with a different skin (theme) */
function loadSkin(skin) {
if (skin) {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = `build/pdbe-molstar-${skin}.css`;
document.getElementsByTagName('head')[0].appendChild(link);
}
}
// Create plugin instance
const viewerInstance = new PDBeMolstarPlugin();
// Set default options (Checkout available options list in the documentation)
const defaultOptions = {
moleculeId: '1hda',
// expanded: true,
// loadMaps: true,
// bgColor: 'white',
// hideControls: true,
// domainAnnotation: true,
// validationAnnotation: true,
// symmetryAnnotation: true,
// subscribeEvents: true,
// loadingOverlay: true,
// hideCanvasControls: ['expand', 'selection', 'animation', 'controlToggle', 'controlInfo']
};
const options = { ...defaultOptions, ...getJsonParam('options') };
const optionsDiv = document.getElementById('options');
optionsDiv.innerHTML = JSON.stringify(options, undefined, 2).replace(/"(\w+)":/g, '$1:');
// Get element from HTML/Template to place the viewer
const viewerContainer = document.getElementById('myViewer');
// Call render method to display the 3D view
viewerInstance.render(viewerContainer, options);
const selectData = getJsonParam('select');
if (selectData) {
viewerInstance.events.loadComplete.subscribe(() => viewerInstance.visual.select(selectData));
}
loadSkin(getJsonParam('skin'));
const size = getJsonParam('size');
if (size) viewerContainer.setAttribute('style', `width: ${size[0]}px; height: ${size[1]}px;`);
// document.addEventListener('PDB.molstar.mouseover', (e) => {
// //do something on event
// console.log(e)
// });
</script>
</body>
</html>