pdbe-molstar 3.2.1-beta.1 → 3.2.1-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +1 -1
  2. package/build/pdbe-molstar-component.js +2 -2
  3. package/build/pdbe-molstar-light.css +2 -2
  4. package/build/pdbe-molstar-plugin.js +2 -2
  5. package/build/pdbe-molstar-plugin.js.LICENSE.txt +1 -1
  6. package/build/pdbe-molstar.css +2 -2
  7. package/lib/alphafold-transparency.d.ts +3 -3
  8. package/lib/alphafold-transparency.js +10 -11
  9. package/lib/custom-events.d.ts +1 -1
  10. package/lib/custom-events.js +1 -1
  11. package/lib/domain-annotations/behavior.d.ts +1 -1
  12. package/lib/domain-annotations/behavior.js +3 -3
  13. package/lib/domain-annotations/color.d.ts +3 -3
  14. package/lib/domain-annotations/color.js +4 -4
  15. package/lib/domain-annotations/prop.d.ts +6 -6
  16. package/lib/domain-annotations/prop.js +7 -7
  17. package/lib/extensions/foldseek.d.ts +1 -1
  18. package/lib/extensions/foldseek.js +2 -2
  19. package/lib/helpers.d.ts +20 -13
  20. package/lib/helpers.js +49 -11
  21. package/lib/index(light).d.ts +4 -179
  22. package/lib/index(light).js +6 -1234
  23. package/lib/index.d.ts +4 -179
  24. package/lib/index.js +6 -1234
  25. package/lib/labels.d.ts +1 -1
  26. package/lib/labels.js +3 -3
  27. package/lib/loci-details.d.ts +2 -2
  28. package/lib/loci-details.js +3 -3
  29. package/lib/plugin-custom-state.d.ts +6 -9
  30. package/lib/sifts-mapping.d.ts +3 -3
  31. package/lib/sifts-mapping.js +4 -4
  32. package/lib/sifts-mappings-behaviour.d.ts +1 -1
  33. package/lib/sifts-mappings-behaviour.js +10 -10
  34. package/lib/spec.d.ts +36 -11
  35. package/lib/spec.js +38 -7
  36. package/lib/{overlay.scss → styles/index.scss} +11 -0
  37. package/lib/superposition-export.d.ts +1 -1
  38. package/lib/superposition-export.js +7 -7
  39. package/lib/superposition-focus-representation.d.ts +3 -3
  40. package/lib/superposition-focus-representation.js +8 -8
  41. package/lib/superposition-sifts-mapping.d.ts +5 -5
  42. package/lib/superposition-sifts-mapping.js +3 -3
  43. package/lib/superposition.d.ts +7 -4
  44. package/lib/superposition.js +147 -184
  45. package/lib/ui/alphafold-superposition.d.ts +4 -4
  46. package/lib/ui/alphafold-superposition.js +8 -8
  47. package/lib/ui/alphafold-tranparency.d.ts +2 -2
  48. package/lib/ui/alphafold-tranparency.js +4 -4
  49. package/lib/ui/annotation-controls.d.ts +1 -1
  50. package/lib/ui/annotation-controls.js +7 -7
  51. package/lib/ui/annotation-row-controls.d.ts +2 -2
  52. package/lib/ui/annotation-row-controls.js +3 -3
  53. package/lib/ui/export-superposition.d.ts +1 -1
  54. package/lib/ui/export-superposition.js +9 -9
  55. package/lib/ui/pdbe-left-panel.d.ts +8 -8
  56. package/lib/ui/pdbe-left-panel.js +26 -47
  57. package/lib/ui/pdbe-screenshot-controls.d.ts +2 -2
  58. package/lib/ui/pdbe-screenshot-controls.js +7 -7
  59. package/lib/ui/pdbe-structure-controls.d.ts +1 -1
  60. package/lib/ui/pdbe-structure-controls.js +8 -8
  61. package/lib/ui/pdbe-viewport-controls.d.ts +1 -1
  62. package/lib/ui/pdbe-viewport-controls.js +4 -2
  63. package/lib/ui/segment-tree.d.ts +4 -4
  64. package/lib/ui/segment-tree.js +12 -32
  65. package/lib/ui/superposition-components.d.ts +1 -1
  66. package/lib/ui/superposition-components.js +8 -8
  67. package/lib/ui/superposition-viewport.d.ts +1 -1
  68. package/lib/ui/superposition-viewport.js +5 -5
  69. package/lib/ui/symmetry-annotation-controls.d.ts +6 -6
  70. package/lib/ui/symmetry-annotation-controls.js +6 -6
  71. package/lib/viewer.d.ts +178 -0
  72. package/lib/viewer.js +1286 -0
  73. package/package.json +4 -4
package/lib/viewer.js ADDED
@@ -0,0 +1,1286 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PDBeMolstarPlugin = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var geo_export_1 = require("molstar/lib/extensions/geo-export");
6
+ var behavior_1 = require("molstar/lib/extensions/model-archive/quality-assessment/behavior");
7
+ var mp4_export_1 = require("molstar/lib/extensions/mp4-export");
8
+ var behavior_2 = require("molstar/lib/extensions/mvs/behavior");
9
+ var custom_tooltips_prop_1 = require("molstar/lib/extensions/mvs/components/custom-tooltips-prop");
10
+ var pdbe_1 = require("molstar/lib/extensions/pdbe");
11
+ var behavior_3 = require("molstar/lib/extensions/rcsb/assembly-symmetry/behavior");
12
+ var loci_1 = require("molstar/lib/mol-model/loci");
13
+ var structure_1 = require("molstar/lib/mol-model/structure");
14
+ var assembly_unwind_1 = require("molstar/lib/mol-plugin-state/animation/built-in/assembly-unwind");
15
+ var camera_rock_1 = require("molstar/lib/mol-plugin-state/animation/built-in/camera-rock");
16
+ var camera_spin_1 = require("molstar/lib/mol-plugin-state/animation/built-in/camera-spin");
17
+ var model_index_1 = require("molstar/lib/mol-plugin-state/animation/built-in/model-index");
18
+ var spin_structure_1 = require("molstar/lib/mol-plugin-state/animation/built-in/spin-structure");
19
+ var state_interpolation_1 = require("molstar/lib/mol-plugin-state/animation/built-in/state-interpolation");
20
+ var state_snapshots_1 = require("molstar/lib/mol-plugin-state/animation/built-in/state-snapshots");
21
+ var structure_overpaint_1 = require("molstar/lib/mol-plugin-state/helpers/structure-overpaint");
22
+ var structure_representation_params_1 = require("molstar/lib/mol-plugin-state/helpers/structure-representation-params");
23
+ var objects_1 = require("molstar/lib/mol-plugin-state/objects");
24
+ var transforms_1 = require("molstar/lib/mol-plugin-state/transforms");
25
+ var model_1 = require("molstar/lib/mol-plugin-state/transforms/model");
26
+ var representation_1 = require("molstar/lib/mol-plugin-state/transforms/representation");
27
+ var react18_1 = require("molstar/lib/mol-plugin-ui/react18");
28
+ var camera_1 = require("molstar/lib/mol-plugin/behavior/dynamic/camera");
29
+ var representation_2 = require("molstar/lib/mol-plugin/behavior/dynamic/representation");
30
+ var structure_focus_representation_1 = require("molstar/lib/mol-plugin/behavior/dynamic/selection/structure-focus-representation");
31
+ var transformers_1 = require("molstar/lib/mol-plugin/behavior/dynamic/volume-streaming/transformers");
32
+ var commands_1 = require("molstar/lib/mol-plugin/commands");
33
+ var config_1 = require("molstar/lib/mol-plugin/config");
34
+ var layout_1 = require("molstar/lib/mol-plugin/layout");
35
+ var spec_1 = require("molstar/lib/mol-plugin/spec");
36
+ var mol_state_1 = require("molstar/lib/mol-state");
37
+ var element_symbol_1 = require("molstar/lib/mol-theme/color/element-symbol");
38
+ var assets_1 = require("molstar/lib/mol-util/assets");
39
+ var color_1 = require("molstar/lib/mol-util/color/color");
40
+ var rx_event_helper_1 = require("molstar/lib/mol-util/rx-event-helper");
41
+ var custom_events_1 = require("./custom-events");
42
+ var behavior_4 = require("./domain-annotations/behavior");
43
+ var Foldseek = tslib_1.__importStar(require("./extensions/foldseek"));
44
+ var helpers_1 = require("./helpers");
45
+ var overlay_1 = require("./overlay");
46
+ var plugin_custom_state_1 = require("./plugin-custom-state");
47
+ var spec_2 = require("./spec");
48
+ var spec_from_html_1 = require("./spec-from-html");
49
+ var subscribe_events_1 = require("./subscribe-events");
50
+ var superposition_1 = require("./superposition");
51
+ var superposition_focus_representation_1 = require("./superposition-focus-representation");
52
+ var pdbe_left_panel_1 = require("./ui/pdbe-left-panel");
53
+ var pdbe_structure_controls_1 = require("./ui/pdbe-structure-controls");
54
+ var pdbe_viewport_controls_1 = require("./ui/pdbe-viewport-controls");
55
+ var superposition_viewport_1 = require("./ui/superposition-viewport");
56
+ var PDBeMolstarPlugin = /** @class */ (function () {
57
+ function PDBeMolstarPlugin() {
58
+ var _this = this;
59
+ this._ev = rx_event_helper_1.RxEventHelper.create();
60
+ this.events = {
61
+ loadComplete: this._ev()
62
+ };
63
+ this.assemblyRef = '';
64
+ this.isHighlightColorUpdated = false;
65
+ this.isSelectedColorUpdated = false;
66
+ /** Keeps track of representations added by `.visual.select` for each structure. */
67
+ this.addedReprs = {};
68
+ /** Maps structure IDs (assigned when loading) to cell refs. */
69
+ this.structureRefMap = new Map();
70
+ /** Helper methods related to canvas and layout */
71
+ this.canvas = {
72
+ /** Set canvas background color. */
73
+ setBgColor: function (color) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
74
+ return tslib_1.__generator(this, function (_a) {
75
+ switch (_a.label) {
76
+ case 0:
77
+ if (!color)
78
+ return [2 /*return*/];
79
+ return [4 /*yield*/, this.canvas.applySettings({ color: color })];
80
+ case 1:
81
+ _a.sent();
82
+ return [2 /*return*/];
83
+ }
84
+ });
85
+ }); },
86
+ /** Set controls panel visibility. Without `isVisible` parameter, toggle controls panel visibility. */
87
+ toggleControls: function (isVisible) {
88
+ if (typeof isVisible === 'undefined')
89
+ isVisible = !_this.plugin.layout.state.showControls;
90
+ commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { showControls: isVisible } });
91
+ },
92
+ /** Set full-screen mode on or off. Without `isExpanded` parameter, toggle full-screen mode. */
93
+ toggleExpanded: function (isExpanded) {
94
+ if (typeof isExpanded === 'undefined')
95
+ isExpanded = !_this.plugin.layout.state.isExpanded;
96
+ commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { isExpanded: isExpanded } });
97
+ },
98
+ applySettings: function (settings) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
99
+ var renderer;
100
+ return tslib_1.__generator(this, function (_a) {
101
+ switch (_a.label) {
102
+ case 0:
103
+ if (!settings)
104
+ return [2 /*return*/];
105
+ if (!this.plugin.canvas3d)
106
+ return [2 /*return*/];
107
+ renderer = tslib_1.__assign({}, this.plugin.canvas3d.props.renderer);
108
+ if (settings.color) {
109
+ renderer.backgroundColor = (0, helpers_1.normalizeColor)(settings.color);
110
+ }
111
+ if (settings.lighting) {
112
+ renderer.style = { name: settings.lighting }; // I don't think this does anything and I don't see how it could ever have worked
113
+ }
114
+ return [4 /*yield*/, commands_1.PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: { renderer: renderer } })];
115
+ case 1:
116
+ _a.sent();
117
+ return [2 /*return*/];
118
+ }
119
+ });
120
+ }); },
121
+ };
122
+ /** Helper methods related to 3D visuals */
123
+ this.visual = {
124
+ /** Change the visibility of individual entity visuals */
125
+ visibility: function (data) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
126
+ var _a, _b, _c, _i, visual, requiredVisibility, tags, _d, tags_1, tag, componentRef, compVisual, currentlyVisible;
127
+ var _e;
128
+ return tslib_1.__generator(this, function (_f) {
129
+ switch (_f.label) {
130
+ case 0:
131
+ if (!data)
132
+ return [2 /*return*/];
133
+ _a = data;
134
+ _b = [];
135
+ for (_c in _a)
136
+ _b.push(_c);
137
+ _i = 0;
138
+ _f.label = 1;
139
+ case 1:
140
+ if (!(_i < _b.length)) return [3 /*break*/, 6];
141
+ _c = _b[_i];
142
+ if (!(_c in _a)) return [3 /*break*/, 5];
143
+ visual = _c;
144
+ requiredVisibility = data[visual];
145
+ if (requiredVisibility === undefined)
146
+ return [3 /*break*/, 5];
147
+ tags = (_e = helpers_1.StructureComponentTags[visual]) !== null && _e !== void 0 ? _e : [];
148
+ _d = 0, tags_1 = tags;
149
+ _f.label = 2;
150
+ case 2:
151
+ if (!(_d < tags_1.length)) return [3 /*break*/, 5];
152
+ tag = tags_1[_d];
153
+ componentRef = mol_state_1.StateSelection.findTagInSubtree(this.plugin.state.data.tree, mol_state_1.StateTransform.RootRef, tag);
154
+ if (!componentRef) return [3 /*break*/, 4];
155
+ compVisual = this.plugin.state.data.select(componentRef)[0];
156
+ if (!(compVisual && compVisual.obj)) return [3 /*break*/, 4];
157
+ currentlyVisible = !(compVisual.state && compVisual.state.isHidden);
158
+ if (!(currentlyVisible !== requiredVisibility)) return [3 /*break*/, 4];
159
+ return [4 /*yield*/, commands_1.PluginCommands.State.ToggleVisibility(this.plugin, { state: this.state, ref: componentRef })];
160
+ case 3:
161
+ _f.sent();
162
+ _f.label = 4;
163
+ case 4:
164
+ _d++;
165
+ return [3 /*break*/, 2];
166
+ case 5:
167
+ _i++;
168
+ return [3 /*break*/, 1];
169
+ case 6: return [2 /*return*/];
170
+ }
171
+ });
172
+ }); },
173
+ /** Change the visibility of a structure.
174
+ * `structureNumberOrId` is either index (numbered from 1!) or the ID that was provided when loading the structure.
175
+ * If `visibility` is undefined, toggle current visibility state. */
176
+ structureVisibility: function (structureNumberOrId, visibility) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
177
+ var struct, currentVisibility;
178
+ return tslib_1.__generator(this, function (_a) {
179
+ switch (_a.label) {
180
+ case 0:
181
+ struct = this.getStructure(structureNumberOrId);
182
+ if (!struct) {
183
+ console.error("Cannot change visibility of structure ".concat(structureNumberOrId, ": structure not found."));
184
+ return [2 /*return*/];
185
+ }
186
+ currentVisibility = !struct.cell.state.isHidden;
187
+ if (!(visibility !== currentVisibility)) return [3 /*break*/, 2];
188
+ return [4 /*yield*/, commands_1.PluginCommands.State.ToggleVisibility(this.plugin, { state: this.state, ref: struct.cell.transform.ref })];
189
+ case 1:
190
+ _a.sent();
191
+ _a.label = 2;
192
+ case 2: return [2 /*return*/];
193
+ }
194
+ });
195
+ }); },
196
+ /** With `isSpinning` parameter, switch visual rotation on or off. Without `isSpinning` parameter, toggle rotation. If `resetCamera`, also reset the camera zoom. */
197
+ toggleSpin: function (isSpinning, resetCamera) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
198
+ var trackball, toggleSpinParam;
199
+ return tslib_1.__generator(this, function (_a) {
200
+ switch (_a.label) {
201
+ case 0:
202
+ if (!this.plugin.canvas3d)
203
+ return [2 /*return*/];
204
+ trackball = this.plugin.canvas3d.props.trackball;
205
+ toggleSpinParam = trackball.animate.name === 'spin' ? { name: 'off', params: {} } : { name: 'spin', params: { speed: 1 } };
206
+ if (typeof isSpinning !== 'undefined') {
207
+ toggleSpinParam = { name: 'off', params: {} };
208
+ if (isSpinning)
209
+ toggleSpinParam = { name: 'spin', params: { speed: 1 } };
210
+ }
211
+ return [4 /*yield*/, commands_1.PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: { trackball: tslib_1.__assign(tslib_1.__assign({}, trackball), { animate: toggleSpinParam }) } })];
212
+ case 1:
213
+ _a.sent();
214
+ if (!resetCamera) return [3 /*break*/, 3];
215
+ return [4 /*yield*/, commands_1.PluginCommands.Camera.Reset(this.plugin, {})];
216
+ case 2:
217
+ _a.sent();
218
+ _a.label = 3;
219
+ case 3: return [2 /*return*/];
220
+ }
221
+ });
222
+ }); },
223
+ /** Focus (zoom) on the part of the structure defined by `selection`.
224
+ * If `selection` contains more items, focus on the union of those.
225
+ * If `structureNumber` is provided, use the specified structure (numbered from 1!); otherwise use the last added structure. */
226
+ focus: function (selection, structureNumber) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
227
+ var loci;
228
+ return tslib_1.__generator(this, function (_a) {
229
+ loci = this.getLociForParams(selection, structureNumber);
230
+ this.plugin.managers.camera.focusLoci(loci);
231
+ return [2 /*return*/];
232
+ });
233
+ }); },
234
+ /** Trigger highlight on the part of the structure defined by `data`
235
+ * (this will look the same as when the user hovers over a part of the structure).
236
+ * If `focus`, also zoom on the highlighted part.
237
+ * If `structureNumber` is provided, use the specified structure (numbered from 1!); otherwise use the last added structure. */
238
+ highlight: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
239
+ var loci;
240
+ return tslib_1.__generator(this, function (_a) {
241
+ switch (_a.label) {
242
+ case 0:
243
+ loci = this.getLociForParams(params.data, params.structureNumber);
244
+ if (loci_1.Loci.isEmpty(loci))
245
+ return [2 /*return*/];
246
+ if (!params.color) return [3 /*break*/, 2];
247
+ return [4 /*yield*/, this.visual.setColor({ highlight: params.color })];
248
+ case 1:
249
+ _a.sent();
250
+ _a.label = 2;
251
+ case 2:
252
+ this.plugin.managers.interactivity.lociHighlights.highlightOnly({ loci: loci });
253
+ if (params.focus)
254
+ this.plugin.managers.camera.focusLoci(loci);
255
+ return [2 /*return*/];
256
+ }
257
+ });
258
+ }); },
259
+ /** Remove any current highlight and reset the highlight color to its default value. */
260
+ clearHighlight: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
261
+ return tslib_1.__generator(this, function (_a) {
262
+ switch (_a.label) {
263
+ case 0:
264
+ this.plugin.managers.interactivity.lociHighlights.highlightOnly({ loci: loci_1.EmptyLoci });
265
+ if (!this.isHighlightColorUpdated) return [3 /*break*/, 2];
266
+ return [4 /*yield*/, this.visual.reset({ highlightColor: true })];
267
+ case 1:
268
+ _a.sent();
269
+ _a.label = 2;
270
+ case 2: return [2 /*return*/];
271
+ }
272
+ });
273
+ }); },
274
+ /** Color the parts of the structure defined by `data`. Color the rest of the structure in `nonSelectedColor` if provided.
275
+ * If any items in `data` contain `focus`, zoom to the union of these items.
276
+ * If any items in `data` contain `sideChain` or `representation`, add extra representations to them (colored in `representationColor` if provided).
277
+ * If `structureNumber` is provided, apply to the specified structure (numbered from 1!); otherwise apply to all loaded structures.
278
+ * Remove any previously added coloring and extra representations, unless `keepColors` and/or `keepRepresentations` is set. */
279
+ select: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
280
+ var structureNumberOrId, structures, addedReprParams, _i, _a, param, repr, DefaultSelectColor, focusLoci, _b, structures_1, struct, selections, _c, selections_1, selection, overpaintLayers, wholeStructBundle, _d, _e, _f, _g, repr, bundle, overpaintLayers_1;
281
+ var _h, _j, _k, _l;
282
+ return tslib_1.__generator(this, function (_m) {
283
+ switch (_m.label) {
284
+ case 0:
285
+ structureNumberOrId = (_h = params.structureId) !== null && _h !== void 0 ? _h : params.structureNumber;
286
+ return [4 /*yield*/, this.visual.clearSelection(structureNumberOrId, { keepColors: params.keepColors, keepRepresentations: params.keepRepresentations })];
287
+ case 1:
288
+ _m.sent();
289
+ structures = this.getStructures(structureNumberOrId);
290
+ addedReprParams = {};
291
+ for (_i = 0, _a = params.data; _i < _a.length; _i++) {
292
+ param = _a[_i];
293
+ repr = (_j = param.representation) !== null && _j !== void 0 ? _j : (param.sideChain ? 'ball-and-stick' : undefined);
294
+ if (repr) {
295
+ ((_k = addedReprParams[repr]) !== null && _k !== void 0 ? _k : (addedReprParams[repr] = [])).push(param);
296
+ }
297
+ }
298
+ DefaultSelectColor = color_1.Color.fromRgb(255, 112, 3);
299
+ focusLoci = [];
300
+ _b = 0, structures_1 = structures;
301
+ _m.label = 2;
302
+ case 2:
303
+ if (!(_b < structures_1.length)) return [3 /*break*/, 8];
304
+ struct = structures_1[_b];
305
+ selections = this.getSelections(params.data, struct.number);
306
+ for (_c = 0, selections_1 = selections; _c < selections_1.length; _c++) {
307
+ selection = selections_1[_c];
308
+ if (selection.param.focus) {
309
+ focusLoci.push(selection.loci);
310
+ }
311
+ }
312
+ overpaintLayers = selections
313
+ .filter(function (s) { return s.param.color !== null; })
314
+ .map(function (s) { return ({
315
+ bundle: s.bundle,
316
+ color: s.param.color ? (0, helpers_1.normalizeColor)(s.param.color) : DefaultSelectColor,
317
+ clear: false,
318
+ }); });
319
+ if (params.nonSelectedColor) {
320
+ wholeStructBundle = this.getBundle([{}], struct.number);
321
+ if (wholeStructBundle) {
322
+ overpaintLayers.unshift({
323
+ bundle: wholeStructBundle,
324
+ color: (0, helpers_1.normalizeColor)(params.nonSelectedColor),
325
+ clear: false,
326
+ });
327
+ }
328
+ }
329
+ return [4 /*yield*/, (0, helpers_1.applyOverpaint)(this.plugin, struct.structureRef, overpaintLayers)];
330
+ case 3:
331
+ _m.sent();
332
+ _d = addedReprParams;
333
+ _e = [];
334
+ for (_f in _d)
335
+ _e.push(_f);
336
+ _g = 0;
337
+ _m.label = 4;
338
+ case 4:
339
+ if (!(_g < _e.length)) return [3 /*break*/, 7];
340
+ _f = _e[_g];
341
+ if (!(_f in _d)) return [3 /*break*/, 6];
342
+ repr = _f;
343
+ bundle = this.getBundle(addedReprParams[repr], struct.number);
344
+ if (!bundle)
345
+ return [3 /*break*/, 6];
346
+ overpaintLayers_1 = selections.filter(function (s) { return s.param.representationColor; }).map(function (s) { return ({
347
+ bundle: s.bundle,
348
+ color: (0, helpers_1.normalizeColor)(s.param.representationColor),
349
+ clear: false,
350
+ }); });
351
+ return [4 /*yield*/, this.plugin.build()
352
+ .to(struct.structureRef.cell)
353
+ .apply(model_1.StructureComponent, { type: { name: 'bundle', params: bundle }, label: repr }, { tags: helpers_1.Tags.AddedComponent })
354
+ .apply(representation_1.StructureRepresentation3D, (0, structure_representation_params_1.createStructureRepresentationParams)(this.plugin, (_l = struct.structureRef.cell.obj) === null || _l === void 0 ? void 0 : _l.data, { type: repr }))
355
+ .apply(transforms_1.StateTransforms.Representation.OverpaintStructureRepresentation3DFromBundle, { layers: overpaintLayers_1 }, { tags: helpers_1.Tags.Overpaint })
356
+ .commit()];
357
+ case 5:
358
+ _m.sent();
359
+ // Track that reprs have been added (for later clearSelection)
360
+ this.addedReprs[struct.number] = true;
361
+ _m.label = 6;
362
+ case 6:
363
+ _g++;
364
+ return [3 /*break*/, 4];
365
+ case 7:
366
+ _b++;
367
+ return [3 /*break*/, 2];
368
+ case 8:
369
+ // Apply focus
370
+ if (focusLoci.length > 0) {
371
+ this.plugin.managers.camera.focusLoci(focusLoci);
372
+ }
373
+ return [2 /*return*/];
374
+ }
375
+ });
376
+ }); },
377
+ /** Remove any coloring and extra representations previously added by the `select` method.
378
+ * If `structureNumber` is provided, apply to the specified structure (numbered from 1!); otherwise apply to all loaded structures.
379
+ * If `keepColors`, current residue coloring is preserved. If `keepRepresentations`, current added representations are preserved. */
380
+ clearSelection: function (structureNumberOrId, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
381
+ var structures, _i, structures_2, struct, componentsToClear, componentsToDelete, update, _a, componentsToDelete_1, comp;
382
+ return tslib_1.__generator(this, function (_b) {
383
+ switch (_b.label) {
384
+ case 0:
385
+ structures = this.getStructures(structureNumberOrId);
386
+ _i = 0, structures_2 = structures;
387
+ _b.label = 1;
388
+ case 1:
389
+ if (!(_i < structures_2.length)) return [3 /*break*/, 6];
390
+ struct = structures_2[_i];
391
+ if (!!(options === null || options === void 0 ? void 0 : options.keepColors)) return [3 /*break*/, 3];
392
+ componentsToClear = struct.structureRef.components.filter(function (c) { var _a; return !((_a = c.cell.transform.tags) === null || _a === void 0 ? void 0 : _a.includes(helpers_1.Tags.AddedComponent)); });
393
+ return [4 /*yield*/, (0, structure_overpaint_1.clearStructureOverpaint)(this.plugin, componentsToClear)];
394
+ case 2:
395
+ _b.sent();
396
+ _b.label = 3;
397
+ case 3:
398
+ if (!!(options === null || options === void 0 ? void 0 : options.keepRepresentations)) return [3 /*break*/, 5];
399
+ if (!this.addedReprs[struct.number]) return [3 /*break*/, 5];
400
+ componentsToDelete = struct.structureRef.components.filter(function (comp) { var _a; return (_a = comp.cell.transform.tags) === null || _a === void 0 ? void 0 : _a.includes(helpers_1.Tags.AddedComponent); });
401
+ update = this.plugin.build();
402
+ for (_a = 0, componentsToDelete_1 = componentsToDelete; _a < componentsToDelete_1.length; _a++) {
403
+ comp = componentsToDelete_1[_a];
404
+ update.delete(comp.cell.transform.ref);
405
+ }
406
+ return [4 /*yield*/, update.commit()];
407
+ case 4:
408
+ _b.sent();
409
+ delete this.addedReprs[struct.number];
410
+ _b.label = 5;
411
+ case 5:
412
+ _i++;
413
+ return [3 /*break*/, 1];
414
+ case 6: return [2 /*return*/];
415
+ }
416
+ });
417
+ }); },
418
+ /** Add interactive tooltips to parts of the structure. The added tooltips will be shown on a separate line in the tooltip box.
419
+ * Repeated call to this function removes any previously added tooltips.
420
+ * `structureNumber` counts from 1; if not provided, tooltips will be applied to all loaded structures.
421
+ * Example: `await this.visual.tooltips({ data: [{ struct_asym_id: 'A', tooltip: 'Chain A' }, { struct_asym_id: 'B', tooltip: 'Chain B' }] });`. */
422
+ tooltips: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
423
+ var structures, _loop_1, this_1, _i, structures_3, struct;
424
+ var _a;
425
+ return tslib_1.__generator(this, function (_b) {
426
+ switch (_b.label) {
427
+ case 0:
428
+ structures = this.getStructures((_a = params.structureId) !== null && _a !== void 0 ? _a : params.structureNumber);
429
+ _loop_1 = function (struct) {
430
+ var selections, customTooltipProps, structRef, customPropsCells;
431
+ return tslib_1.__generator(this, function (_c) {
432
+ switch (_c.label) {
433
+ case 0:
434
+ selections = this_1.getSelections(params.data, struct.number);
435
+ customTooltipProps = {
436
+ tooltips: selections.map(function (s) { var _a; return ({ text: (_a = s.param.tooltip) !== null && _a !== void 0 ? _a : '', selector: { name: 'bundle', params: s.bundle } }); }),
437
+ };
438
+ structRef = struct.structureRef.cell.transform.ref;
439
+ customPropsCells = this_1.plugin.state.data.select(mol_state_1.StateSelection.Generators.ofTransformer(model_1.CustomStructureProperties, structRef));
440
+ if (!(customPropsCells.length === 0)) return [3 /*break*/, 2];
441
+ return [4 /*yield*/, this_1.plugin.build().to(structRef).apply(model_1.CustomStructureProperties).commit()];
442
+ case 1:
443
+ _c.sent();
444
+ customPropsCells = this_1.plugin.state.data.select(mol_state_1.StateSelection.Generators.ofTransformer(model_1.CustomStructureProperties, structRef));
445
+ _c.label = 2;
446
+ case 2: return [4 /*yield*/, this_1.plugin.build().to(customPropsCells[0]).update(function (old) {
447
+ var _a;
448
+ return ({
449
+ properties: tslib_1.__assign(tslib_1.__assign({}, old.properties), (_a = {}, _a[custom_tooltips_prop_1.CustomTooltipsProvider.descriptor.name] = customTooltipProps, _a)),
450
+ autoAttach: old.autoAttach.includes(custom_tooltips_prop_1.CustomTooltipsProvider.descriptor.name) ?
451
+ old.autoAttach
452
+ : tslib_1.__spreadArray(tslib_1.__spreadArray([], old.autoAttach, true), [custom_tooltips_prop_1.CustomTooltipsProvider.descriptor.name], false),
453
+ });
454
+ }).commit()];
455
+ case 3:
456
+ _c.sent();
457
+ return [2 /*return*/];
458
+ }
459
+ });
460
+ };
461
+ this_1 = this;
462
+ _i = 0, structures_3 = structures;
463
+ _b.label = 1;
464
+ case 1:
465
+ if (!(_i < structures_3.length)) return [3 /*break*/, 4];
466
+ struct = structures_3[_i];
467
+ return [5 /*yield**/, _loop_1(struct)];
468
+ case 2:
469
+ _b.sent();
470
+ _b.label = 3;
471
+ case 3:
472
+ _i++;
473
+ return [3 /*break*/, 1];
474
+ case 4: return [2 /*return*/];
475
+ }
476
+ });
477
+ }); },
478
+ /** Remove any custom tooltips added by the `tooltips` method. */
479
+ clearTooltips: function (structureNumberOrId) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
480
+ return tslib_1.__generator(this, function (_a) {
481
+ switch (_a.label) {
482
+ case 0: return [4 /*yield*/, this.visual.tooltips({ data: [], structureId: structureNumberOrId })];
483
+ case 1:
484
+ _a.sent();
485
+ return [2 /*return*/];
486
+ }
487
+ });
488
+ }); },
489
+ /** Set highlight and/or selection color.
490
+ * Highlight color is used when the user hovers over a part of the structure or when applying the `highlight` method.
491
+ * Selection color is used when creating selections with Selection Mode (the mouse cursor icon) and is not related to the color used by the `select` method. */
492
+ setColor: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
493
+ var renderer, marking;
494
+ return tslib_1.__generator(this, function (_a) {
495
+ switch (_a.label) {
496
+ case 0:
497
+ if (!this.plugin.canvas3d)
498
+ return [2 /*return*/];
499
+ if (!params.highlight && !params.select)
500
+ return [2 /*return*/];
501
+ renderer = tslib_1.__assign({}, this.plugin.canvas3d.props.renderer);
502
+ marking = tslib_1.__assign({}, this.plugin.canvas3d.props.marking);
503
+ if (params.highlight) {
504
+ renderer.highlightColor = (0, helpers_1.normalizeColor)(params.highlight);
505
+ marking.highlightEdgeColor = color_1.Color.darken((0, helpers_1.normalizeColor)(params.highlight), 1);
506
+ this.isHighlightColorUpdated = true;
507
+ }
508
+ if (params.select) {
509
+ renderer.selectColor = (0, helpers_1.normalizeColor)(params.select);
510
+ marking.selectEdgeColor = color_1.Color.darken((0, helpers_1.normalizeColor)(params.select), 1);
511
+ this.isSelectedColorUpdated = true;
512
+ }
513
+ return [4 /*yield*/, commands_1.PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: { renderer: renderer, marking: marking } })];
514
+ case 1:
515
+ _a.sent();
516
+ return [2 /*return*/];
517
+ }
518
+ });
519
+ }); },
520
+ /** Reset various settings to defaults:
521
+ * `camera` resets camera position (i.e. zooms on the whole scene).
522
+ * `theme` resets color theme for visual representations.
523
+ * `highlightColor` and `selectColor` reset colors previously set by the `setColor` method. */
524
+ reset: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
525
+ var defaultTheme, componentGroups, _i, componentGroups_1, compGrp, renderer, marking;
526
+ return tslib_1.__generator(this, function (_a) {
527
+ switch (_a.label) {
528
+ case 0:
529
+ if (!params.camera) return [3 /*break*/, 2];
530
+ return [4 /*yield*/, commands_1.PluginCommands.Camera.Reset(this.plugin, { durationMs: 250 })];
531
+ case 1:
532
+ _a.sent();
533
+ _a.label = 2;
534
+ case 2:
535
+ if (!params.theme) return [3 /*break*/, 6];
536
+ defaultTheme = { color: this.defaultColorTheme() };
537
+ componentGroups = this.plugin.managers.structure.hierarchy.currentComponentGroups;
538
+ _i = 0, componentGroups_1 = componentGroups;
539
+ _a.label = 3;
540
+ case 3:
541
+ if (!(_i < componentGroups_1.length)) return [3 /*break*/, 6];
542
+ compGrp = componentGroups_1[_i];
543
+ return [4 /*yield*/, this.plugin.managers.structure.component.updateRepresentationsTheme(compGrp, defaultTheme)];
544
+ case 4:
545
+ _a.sent();
546
+ _a.label = 5;
547
+ case 5:
548
+ _i++;
549
+ return [3 /*break*/, 3];
550
+ case 6:
551
+ if (!(params.highlightColor || params.selectColor)) return [3 /*break*/, 8];
552
+ if (!this.plugin.canvas3d)
553
+ return [2 /*return*/];
554
+ renderer = tslib_1.__assign({}, this.plugin.canvas3d.props.renderer);
555
+ marking = tslib_1.__assign({}, this.plugin.canvas3d.props.marking);
556
+ if (params.highlightColor) {
557
+ renderer.highlightColor = this.defaultRendererProps.highlightColor;
558
+ marking.highlightEdgeColor = this.defaultMarkingProps.highlightEdgeColor;
559
+ this.isHighlightColorUpdated = false;
560
+ }
561
+ if (params.selectColor) {
562
+ renderer.selectColor = this.defaultRendererProps.selectColor;
563
+ marking.selectEdgeColor = this.defaultMarkingProps.selectEdgeColor;
564
+ this.isSelectedColorUpdated = false;
565
+ }
566
+ return [4 /*yield*/, commands_1.PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: { renderer: renderer, marking: marking } })];
567
+ case 7:
568
+ _a.sent();
569
+ _a.label = 8;
570
+ case 8: return [2 /*return*/];
571
+ }
572
+ });
573
+ }); },
574
+ /** Change parameters of the plugin instance.
575
+ * Can be used to load a different structure.
576
+ * If `fullLoad`, remove currently loaded structure before loading the new one;
577
+ * otherwise add the new structure to existing structures. */
578
+ update: function (options, fullLoad) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
579
+ var validationIssues, dataSource;
580
+ return tslib_1.__generator(this, function (_a) {
581
+ switch (_a.label) {
582
+ case 0:
583
+ console.debug('Updating PDBeMolstarPlugin instance with options:', options);
584
+ // Validate options
585
+ if (!options) {
586
+ console.error('Missing `options` argument to `PDBeMolstarPlugin.visual.update');
587
+ return [2 /*return*/, false];
588
+ }
589
+ validationIssues = (0, spec_2.validateInitParams)(options);
590
+ if (validationIssues) {
591
+ console.error('Invalid PDBeMolstarPlugin options:', options);
592
+ return [2 /*return*/, false];
593
+ }
594
+ this.initParams = (0, helpers_1.addDefaults)(options, spec_2.DefaultParams);
595
+ if (!this.initParams.moleculeId && !this.initParams.customData)
596
+ return [2 /*return*/, false];
597
+ if (this.initParams.customData && this.initParams.customData.url && !this.initParams.customData.format)
598
+ return [2 /*return*/, false];
599
+ (0, plugin_custom_state_1.PluginCustomState)(this.plugin).initParams = this.initParams;
600
+ // Show/hide buttons in the viewport control panel
601
+ this.plugin.config.set(config_1.PluginConfig.Viewport.ShowExpand, !this.initParams.hideCanvasControls.includes('expand'));
602
+ this.plugin.config.set(config_1.PluginConfig.Viewport.ShowSelectionMode, !this.initParams.hideCanvasControls.includes('selection'));
603
+ this.plugin.config.set(config_1.PluginConfig.Viewport.ShowAnimation, !this.initParams.hideCanvasControls.includes('animation'));
604
+ this.plugin.config.set(config_1.PluginConfig.Viewport.ShowControls, !this.initParams.hideCanvasControls.includes('controlToggle'));
605
+ this.plugin.config.set(config_1.PluginConfig.Viewport.ShowSettings, !this.initParams.hideCanvasControls.includes('controlInfo'));
606
+ if (!(this.initParams.bgColor || this.initParams.lighting)) return [3 /*break*/, 2];
607
+ return [4 /*yield*/, this.canvas.applySettings({ color: this.initParams.bgColor, lighting: this.initParams.lighting })];
608
+ case 1:
609
+ _a.sent();
610
+ _a.label = 2;
611
+ case 2:
612
+ dataSource = this.getMoleculeSrcUrl();
613
+ if (!dataSource) return [3 /*break*/, 4];
614
+ return [4 /*yield*/, this.load({ url: dataSource.url, format: dataSource.format, assemblyId: this.initParams.assemblyId, isBinary: dataSource.isBinary }, fullLoad)];
615
+ case 3:
616
+ _a.sent();
617
+ _a.label = 4;
618
+ case 4: return [2 /*return*/, true];
619
+ }
620
+ });
621
+ }); },
622
+ };
623
+ }
624
+ /** Extract InitParams from attributes of an HTML element */
625
+ PDBeMolstarPlugin.initParamsFromHtmlAttributes = function (element) {
626
+ return (0, spec_from_html_1.initParamsFromHtmlAttributes)(element);
627
+ };
628
+ PDBeMolstarPlugin.prototype.render = function (target, options) {
629
+ var _a, _b, _c, _d, _e, _f;
630
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
631
+ var validationIssues, pdbePluginSpec, _g, dataSource;
632
+ return tslib_1.__generator(this, function (_h) {
633
+ switch (_h.label) {
634
+ case 0:
635
+ console.debug('Rendering PDBeMolstarPlugin instance with options:', options);
636
+ // Validate options
637
+ if (!options) {
638
+ console.error('Missing `options` argument to `PDBeMolstarPlugin.render');
639
+ return [2 /*return*/];
640
+ }
641
+ validationIssues = (0, spec_2.validateInitParams)(options);
642
+ if (validationIssues) {
643
+ console.error('Invalid PDBeMolstarPlugin options:', options);
644
+ return [2 /*return*/];
645
+ }
646
+ this.initParams = (0, helpers_1.addDefaults)(options, spec_2.DefaultParams);
647
+ pdbePluginSpec = (0, spec_2.DefaultPluginUISpec)();
648
+ (_a = pdbePluginSpec.config) !== null && _a !== void 0 ? _a : (pdbePluginSpec.config = []);
649
+ pdbePluginSpec.behaviors.push(spec_1.PluginSpec.Behavior(behavior_2.MolViewSpec));
650
+ if (!this.initParams.ligandView && !this.initParams.superposition && this.initParams.selectInteraction) {
651
+ pdbePluginSpec.behaviors.push(spec_1.PluginSpec.Behavior(structure_focus_representation_1.StructureFocusRepresentation));
652
+ }
653
+ if (this.initParams.superposition) {
654
+ pdbePluginSpec.behaviors.push(spec_1.PluginSpec.Behavior(superposition_focus_representation_1.SuperpositionFocusRepresentation), spec_1.PluginSpec.Behavior(behavior_1.MAQualityAssessment, { autoAttach: true, showTooltip: true }));
655
+ }
656
+ // Add custom properties
657
+ if (this.initParams.domainAnnotation) {
658
+ pdbePluginSpec.behaviors.push(spec_1.PluginSpec.Behavior(behavior_4.PDBeDomainAnnotations, { autoAttach: true, showTooltip: false }));
659
+ }
660
+ if (this.initParams.validationAnnotation) {
661
+ pdbePluginSpec.behaviors.push(spec_1.PluginSpec.Behavior(pdbe_1.PDBeStructureQualityReport, { autoAttach: true, showTooltip: false }));
662
+ }
663
+ if (this.initParams.symmetryAnnotation) {
664
+ pdbePluginSpec.behaviors.push(spec_1.PluginSpec.Behavior(behavior_3.RCSBAssemblySymmetry));
665
+ pdbePluginSpec.config.push([behavior_3.RCSBAssemblySymmetryConfig.DefaultServerType, 'pdbe'], [behavior_3.RCSBAssemblySymmetryConfig.DefaultServerUrl, 'https://www.ebi.ac.uk/pdbe/aggregated-api/pdb/symmetry'], [behavior_3.RCSBAssemblySymmetryConfig.ApplyColors, false]);
666
+ }
667
+ pdbePluginSpec.layout = {
668
+ initial: {
669
+ isExpanded: this.initParams.expanded,
670
+ showControls: !this.initParams.hideControls,
671
+ regionState: {
672
+ left: this.initParams.leftPanel ? 'full' : 'hidden',
673
+ right: this.initParams.rightPanel ? 'full' : 'hidden',
674
+ top: this.initParams.sequencePanel ? 'full' : 'hidden',
675
+ bottom: this.initParams.logPanel ? 'full' : 'hidden',
676
+ },
677
+ controlsDisplay: this.initParams.reactive ? 'reactive' : this.initParams.landscape ? 'landscape' : layout_1.PluginLayoutStateParams.controlsDisplay.defaultValue,
678
+ }
679
+ };
680
+ pdbePluginSpec.components = {
681
+ controls: {
682
+ left: pdbe_left_panel_1.PDBeLeftPanelControls,
683
+ },
684
+ viewport: {
685
+ controls: pdbe_viewport_controls_1.PDBeViewportControls,
686
+ view: this.initParams.superposition ? superposition_viewport_1.SuperpostionViewport : void 0
687
+ },
688
+ remoteState: 'none',
689
+ structureTools: this.initParams.superposition ? pdbe_structure_controls_1.PDBeSuperpositionStructureTools : this.initParams.ligandView ? pdbe_structure_controls_1.PDBeLigandViewStructureTools : pdbe_structure_controls_1.PDBeStructureTools
690
+ };
691
+ if (this.initParams.alphafoldView) {
692
+ pdbePluginSpec.behaviors.push(spec_1.PluginSpec.Behavior(behavior_1.MAQualityAssessment, { autoAttach: true, showTooltip: true }));
693
+ }
694
+ pdbePluginSpec.config.push([config_1.PluginConfig.Structure.DefaultRepresentationPresetParams, {
695
+ theme: {
696
+ globalName: (this.initParams.alphafoldView) ? 'plddt-confidence' : undefined,
697
+ carbonColor: { name: 'element-symbol', params: {} },
698
+ focus: {
699
+ name: 'element-symbol',
700
+ params: { carbonColor: { name: 'element-symbol', params: {} } }
701
+ }
702
+ }
703
+ }]);
704
+ element_symbol_1.ElementSymbolColorThemeParams.carbonColor.defaultValue = { name: 'element-symbol', params: {} };
705
+ // Add animation props
706
+ if (!this.initParams.ligandView && !this.initParams.superposition) {
707
+ pdbePluginSpec.animations = [model_index_1.AnimateModelIndex, camera_spin_1.AnimateCameraSpin, camera_rock_1.AnimateCameraRock, state_snapshots_1.AnimateStateSnapshots, assembly_unwind_1.AnimateAssemblyUnwind, spin_structure_1.AnimateStructureSpin, state_interpolation_1.AnimateStateInterpolation];
708
+ pdbePluginSpec.behaviors.push(spec_1.PluginSpec.Behavior(mp4_export_1.Mp4Export));
709
+ pdbePluginSpec.behaviors.push(spec_1.PluginSpec.Behavior(geo_export_1.GeometryExport));
710
+ }
711
+ if (this.initParams.hideCanvasControls.includes('expand'))
712
+ pdbePluginSpec.config.push([config_1.PluginConfig.Viewport.ShowExpand, false]);
713
+ if (this.initParams.hideCanvasControls.includes('selection'))
714
+ pdbePluginSpec.config.push([config_1.PluginConfig.Viewport.ShowSelectionMode, false]);
715
+ if (this.initParams.hideCanvasControls.includes('animation'))
716
+ pdbePluginSpec.config.push([config_1.PluginConfig.Viewport.ShowAnimation, false]);
717
+ if (this.initParams.hideCanvasControls.includes('controlToggle'))
718
+ pdbePluginSpec.config.push([config_1.PluginConfig.Viewport.ShowControls, false]);
719
+ if (this.initParams.hideCanvasControls.includes('controlInfo'))
720
+ pdbePluginSpec.config.push([config_1.PluginConfig.Viewport.ShowSettings, false]);
721
+ // override default event bindings
722
+ if (this.initParams.selectBindings) {
723
+ pdbePluginSpec.behaviors.push(spec_1.PluginSpec.Behavior(representation_2.SelectLoci, { bindings: this.initParams.selectBindings }));
724
+ }
725
+ if (this.initParams.focusBindings) {
726
+ pdbePluginSpec.behaviors.push(spec_1.PluginSpec.Behavior(camera_1.FocusLoci, { bindings: this.initParams.focusBindings }));
727
+ }
728
+ this.targetElement = typeof target === 'string' ? document.getElementById(target) : target;
729
+ this.targetElement.viewerInstance = this;
730
+ // Create/ Initialise Plugin
731
+ _g = this;
732
+ return [4 /*yield*/, (0, react18_1.createPluginUI)(this.targetElement, pdbePluginSpec)];
733
+ case 1:
734
+ // Create/ Initialise Plugin
735
+ _g.plugin = _h.sent();
736
+ (0, plugin_custom_state_1.PluginCustomState)(this.plugin).initParams = tslib_1.__assign({}, this.initParams);
737
+ (0, plugin_custom_state_1.PluginCustomState)(this.plugin).events = {
738
+ segmentUpdate: this._ev(),
739
+ superpositionInit: this._ev(),
740
+ isBusy: this._ev()
741
+ };
742
+ // Set background colour
743
+ if (this.initParams.bgColor || this.initParams.lighting) {
744
+ this.canvas.applySettings({ color: this.initParams.bgColor, lighting: this.initParams.lighting });
745
+ }
746
+ // Set selection granularity
747
+ if (this.initParams.granularity) {
748
+ this.plugin.managers.interactivity.setProps({ granularity: this.initParams.granularity });
749
+ }
750
+ // Set default highlight and selection colors
751
+ if (this.initParams.highlightColor || this.initParams.selectColor) {
752
+ this.visual.setColor({ highlight: this.initParams.highlightColor, select: this.initParams.selectColor });
753
+ }
754
+ // Save renderer defaults
755
+ this.defaultRendererProps = tslib_1.__assign({}, this.plugin.canvas3d.props.renderer);
756
+ this.defaultMarkingProps = tslib_1.__assign({}, this.plugin.canvas3d.props.marking);
757
+ if (this.initParams.superposition) {
758
+ // Set left panel tab
759
+ this.plugin.behaviors.layout.leftPanelTabName.next('segments');
760
+ // Initialise superposition
761
+ if (this.initParams.loadingOverlay) {
762
+ new overlay_1.LoadingOverlay(this.targetElement, { resize: (_c = (_b = this.plugin) === null || _b === void 0 ? void 0 : _b.canvas3d) === null || _c === void 0 ? void 0 : _c.resized, hide: this.events.loadComplete }).show();
763
+ }
764
+ (0, superposition_1.initSuperposition)(this.plugin, this.events.loadComplete);
765
+ }
766
+ else {
767
+ // Set left panel tab to none (collapses the panel if visible)
768
+ this.plugin.behaviors.layout.leftPanelTabName.next('none');
769
+ dataSource = this.getMoleculeSrcUrl();
770
+ if (dataSource) {
771
+ if (this.initParams.loadingOverlay) {
772
+ new overlay_1.LoadingOverlay(this.targetElement, { resize: (_e = (_d = this.plugin) === null || _d === void 0 ? void 0 : _d.canvas3d) === null || _e === void 0 ? void 0 : _e.resized, hide: this.events.loadComplete }).show();
773
+ }
774
+ this.load({
775
+ url: dataSource.url,
776
+ format: dataSource.format,
777
+ assemblyId: this.initParams.assemblyId,
778
+ isBinary: dataSource.isBinary,
779
+ progressMessage: "Loading ".concat((_f = this.initParams.moleculeId) !== null && _f !== void 0 ? _f : '', " ..."),
780
+ id: 'main',
781
+ });
782
+ }
783
+ // Binding to other PDB Component events
784
+ if (this.initParams.subscribeEvents) {
785
+ (0, subscribe_events_1.subscribeToComponentEvents)(this);
786
+ }
787
+ // Event handling
788
+ custom_events_1.CustomEvents.add(this.plugin, this.targetElement);
789
+ }
790
+ return [2 /*return*/];
791
+ }
792
+ });
793
+ });
794
+ };
795
+ PDBeMolstarPlugin.prototype.getMoleculeSrcUrl = function () {
796
+ if (this.initParams.customData) {
797
+ var _a = this.initParams.customData, url = _a.url, format = _a.format, binary = _a.binary;
798
+ if (!url || !format) {
799
+ throw new Error("Provide all custom data parameters");
800
+ }
801
+ if (format === 'cif' || format === 'bcif')
802
+ format = 'mmcif';
803
+ // Validate supported format
804
+ var supportedFormats = ['mmcif', 'pdb', 'sdf'];
805
+ if (!supportedFormats.includes(format)) {
806
+ throw new Error("".concat(format, " not supported."));
807
+ }
808
+ return {
809
+ url: url,
810
+ format: format,
811
+ isBinary: binary,
812
+ };
813
+ }
814
+ if (this.initParams.moleculeId) {
815
+ var request = { pdbId: this.initParams.moleculeId, queryType: 'full', queryParams: {} };
816
+ if (this.initParams.ligandView) {
817
+ request.queryType = 'residueSurroundings';
818
+ request.queryParams['data_source'] = 'pdb-h';
819
+ if (!this.initParams.ligandView.label_comp_id_list) {
820
+ request.queryParams['label_comp_id'] = this.initParams.ligandView.label_comp_id;
821
+ request.queryParams['auth_seq_id'] = this.initParams.ligandView.auth_seq_id;
822
+ request.queryParams['auth_asym_id'] = this.initParams.ligandView.auth_asym_id;
823
+ }
824
+ }
825
+ return {
826
+ url: (0, helpers_1.getStructureUrl)(this.initParams, request),
827
+ format: 'mmcif',
828
+ isBinary: this.initParams.encoding === 'bcif',
829
+ };
830
+ }
831
+ throw new Error("Mandatory parameters missing! (customData or moleculeId must be defined)");
832
+ };
833
+ Object.defineProperty(PDBeMolstarPlugin.prototype, "state", {
834
+ get: function () {
835
+ return this.plugin.state.data;
836
+ },
837
+ enumerable: false,
838
+ configurable: true
839
+ });
840
+ PDBeMolstarPlugin.prototype.createLigandStructure = function (isBranched) {
841
+ var _a, e_1, _b, _c;
842
+ var _d, _e;
843
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
844
+ var _f, _g, _h, comp, e_1_1, structure, ligandQuery, ligandVis, ligandSurr, ligRef, cell, repr, ligLoci, current;
845
+ return tslib_1.__generator(this, function (_j) {
846
+ switch (_j.label) {
847
+ case 0:
848
+ if (this.assemblyRef === '')
849
+ return [2 /*return*/];
850
+ _j.label = 1;
851
+ case 1:
852
+ _j.trys.push([1, 9, 10, 15]);
853
+ _f = true, _g = tslib_1.__asyncValues(this.plugin.managers.structure.hierarchy.currentComponentGroups);
854
+ _j.label = 2;
855
+ case 2: return [4 /*yield*/, _g.next()];
856
+ case 3:
857
+ if (!(_h = _j.sent(), _a = _h.done, !_a)) return [3 /*break*/, 8];
858
+ _c = _h.value;
859
+ _f = false;
860
+ _j.label = 4;
861
+ case 4:
862
+ _j.trys.push([4, , 6, 7]);
863
+ comp = _c;
864
+ return [4 /*yield*/, commands_1.PluginCommands.State.RemoveObject(this.plugin, { state: comp[0].cell.parent, ref: comp[0].cell.transform.ref, removeParentGhosts: true })];
865
+ case 5:
866
+ _j.sent();
867
+ return [3 /*break*/, 7];
868
+ case 6:
869
+ _f = true;
870
+ return [7 /*endfinally*/];
871
+ case 7: return [3 /*break*/, 2];
872
+ case 8: return [3 /*break*/, 15];
873
+ case 9:
874
+ e_1_1 = _j.sent();
875
+ e_1 = { error: e_1_1 };
876
+ return [3 /*break*/, 15];
877
+ case 10:
878
+ _j.trys.push([10, , 13, 14]);
879
+ if (!(!_f && !_a && (_b = _g.return))) return [3 /*break*/, 12];
880
+ return [4 /*yield*/, _b.call(_g)];
881
+ case 11:
882
+ _j.sent();
883
+ _j.label = 12;
884
+ case 12: return [3 /*break*/, 14];
885
+ case 13:
886
+ if (e_1) throw e_1.error;
887
+ return [7 /*endfinally*/];
888
+ case 14: return [7 /*endfinally*/];
889
+ case 15:
890
+ structure = this.state.select(this.assemblyRef)[0];
891
+ if (isBranched) {
892
+ ligandQuery = helpers_1.LigandView.branchedQuery((_d = this.initParams.ligandView) === null || _d === void 0 ? void 0 : _d.label_comp_id_list);
893
+ }
894
+ else {
895
+ ligandQuery = helpers_1.LigandView.query(this.initParams.ligandView);
896
+ }
897
+ return [4 /*yield*/, this.plugin.builders.structure.tryCreateComponentFromExpression(structure, ligandQuery.core, 'pivot', { label: 'Ligand' })];
898
+ case 16:
899
+ ligandVis = _j.sent();
900
+ if (!ligandVis) return [3 /*break*/, 18];
901
+ return [4 /*yield*/, this.plugin.builders.structure.representation.addRepresentation(ligandVis, { type: 'ball-and-stick', color: 'element-symbol', colorParams: { carbonColor: { name: 'element-symbol', params: {} } }, size: 'uniform', sizeParams: { value: 2.5 } }, { tag: 'ligand-vis' })];
902
+ case 17:
903
+ _j.sent();
904
+ _j.label = 18;
905
+ case 18: return [4 /*yield*/, this.plugin.builders.structure.tryCreateComponentFromExpression(structure, ligandQuery.surroundings, 'rest', { label: 'Surroundings' })];
906
+ case 19:
907
+ ligandSurr = _j.sent();
908
+ if (!ligandSurr) return [3 /*break*/, 21];
909
+ return [4 /*yield*/, this.plugin.builders.structure.representation.addRepresentation(ligandSurr, { type: 'ball-and-stick', color: 'element-symbol', colorParams: { carbonColor: { name: 'element-symbol', params: {} } }, size: 'uniform', sizeParams: { value: 0.8 } })];
910
+ case 20:
911
+ _j.sent();
912
+ _j.label = 21;
913
+ case 21:
914
+ ligRef = mol_state_1.StateSelection.findTagInSubtree(this.plugin.state.data.tree, mol_state_1.StateTransform.RootRef, 'ligand-vis');
915
+ if (!ligRef)
916
+ return [2 /*return*/];
917
+ cell = this.plugin.state.data.cells.get(ligRef);
918
+ if (cell === null || cell === void 0 ? void 0 : cell.obj) {
919
+ repr = cell.obj.data.repr;
920
+ ligLoci = repr.getAllLoci()[0];
921
+ this.plugin.managers.structure.focus.setFromLoci(ligLoci);
922
+ current = (_e = this.plugin.managers.structure.focus.current) === null || _e === void 0 ? void 0 : _e.loci;
923
+ if (current)
924
+ this.plugin.managers.camera.focusLoci(current);
925
+ }
926
+ return [2 /*return*/];
927
+ }
928
+ });
929
+ });
930
+ };
931
+ PDBeMolstarPlugin.prototype.load = function (_a, fullLoad) {
932
+ var url = _a.url, _b = _a.format, format = _b === void 0 ? 'mmcif' : _b, _c = _a.isBinary, isBinary = _c === void 0 ? false : _c, _d = _a.assemblyId, assemblyId = _d === void 0 ? '' : _d, progressMessage = _a.progressMessage, id = _a.id;
933
+ if (fullLoad === void 0) { fullLoad = true; }
934
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
935
+ var _this = this;
936
+ return tslib_1.__generator(this, function (_e) {
937
+ switch (_e.label) {
938
+ case 0: return [4 /*yield*/, (0, helpers_1.runWithProgressMessage)(this.plugin, progressMessage, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
939
+ var success, isHetView, downloadOptions, isBranchedView, data_1, trajectory, structRef, model, structure, pivotIndex, pivot, asm, defaultMapParams, pdbeMapParams;
940
+ return tslib_1.__generator(this, function (_a) {
941
+ switch (_a.label) {
942
+ case 0:
943
+ success = false;
944
+ _a.label = 1;
945
+ case 1:
946
+ _a.trys.push([1, , 18, 19]);
947
+ if (!fullLoad) return [3 /*break*/, 3];
948
+ return [4 /*yield*/, this.clear()];
949
+ case 2:
950
+ _a.sent();
951
+ _a.label = 3;
952
+ case 3:
953
+ isHetView = this.initParams.ligandView ? true : false;
954
+ downloadOptions = void 0;
955
+ isBranchedView = false;
956
+ if (this.initParams.ligandView && this.initParams.ligandView.label_comp_id_list) {
957
+ isBranchedView = true;
958
+ downloadOptions = { body: JSON.stringify(this.initParams.ligandView.label_comp_id_list), headers: [['Content-type', 'application/json']] };
959
+ }
960
+ return [4 /*yield*/, this.plugin.builders.data.download({ url: assets_1.Asset.Url(url, downloadOptions), isBinary: isBinary }, { state: { isGhost: true } })];
961
+ case 4:
962
+ data_1 = _a.sent();
963
+ return [4 /*yield*/, this.plugin.builders.structure.parseTrajectory(data_1, format)];
964
+ case 5:
965
+ trajectory = _a.sent();
966
+ structRef = void 0;
967
+ if (!!isHetView) return [3 /*break*/, 10];
968
+ return [4 /*yield*/, this.plugin.builders.structure.hierarchy.applyPreset(trajectory, this.initParams.defaultPreset, {
969
+ structure: assemblyId ? (assemblyId === 'preferred') ? void 0 : { name: 'assembly', params: { id: assemblyId } } : { name: 'model', params: {} },
970
+ showUnitcell: false,
971
+ representationPreset: 'auto'
972
+ })];
973
+ case 6:
974
+ _a.sent();
975
+ structRef = this.plugin.state.data.selectQ(function (q) { return q.byRef(data_1.ref).subtree().ofType(objects_1.PluginStateObject.Molecule.Structure); })[0].transform.ref;
976
+ if (!(this.initParams.hideStructure.length > 0 || this.initParams.visualStyle)) return [3 /*break*/, 9];
977
+ return [4 /*yield*/, this.deleteStructureComponents(structRef, this.initParams.hideStructure)];
978
+ case 7:
979
+ _a.sent();
980
+ return [4 /*yield*/, this.applyVisualStyles(structRef, this.initParams.visualStyle)];
981
+ case 8:
982
+ _a.sent();
983
+ _a.label = 9;
984
+ case 9: return [3 /*break*/, 13];
985
+ case 10: return [4 /*yield*/, this.plugin.builders.structure.createModel(trajectory)];
986
+ case 11:
987
+ model = _a.sent();
988
+ return [4 /*yield*/, this.plugin.builders.structure.createStructure(model, { name: 'model', params: {} })];
989
+ case 12:
990
+ structure = _a.sent();
991
+ structRef = structure.ref;
992
+ _a.label = 13;
993
+ case 13:
994
+ if (id) {
995
+ this.structureRefMap.set(id, structRef);
996
+ }
997
+ // show selection if param is set
998
+ if (this.initParams.selection) {
999
+ this.visual.select(this.initParams.selection);
1000
+ }
1001
+ pivotIndex = this.plugin.managers.structure.hierarchy.selection.structures.length - 1;
1002
+ pivot = this.plugin.managers.structure.hierarchy.selection.structures[pivotIndex];
1003
+ if (pivot && pivot.cell.parent)
1004
+ this.assemblyRef = pivot.cell.transform.ref;
1005
+ if (!this.initParams.loadMaps) return [3 /*break*/, 15];
1006
+ if (this.assemblyRef === '')
1007
+ return [2 /*return*/];
1008
+ asm = this.state.select(this.assemblyRef)[0].obj;
1009
+ defaultMapParams = transformers_1.InitVolumeStreaming.createDefaultParams(asm, this.plugin);
1010
+ pdbeMapParams = helpers_1.PDBeVolumes.mapParams(defaultMapParams, this.initParams.mapSettings, '');
1011
+ if (!pdbeMapParams) return [3 /*break*/, 15];
1012
+ return [4 /*yield*/, this.plugin.runTask(this.state.applyAction(transformers_1.InitVolumeStreaming, pdbeMapParams, this.assemblyRef))];
1013
+ case 14:
1014
+ _a.sent();
1015
+ if (pdbeMapParams.method !== 'em' && !this.initParams.ligandView)
1016
+ helpers_1.PDBeVolumes.displayUsibilityMessage(this.plugin);
1017
+ _a.label = 15;
1018
+ case 15:
1019
+ if (!isHetView) return [3 /*break*/, 17];
1020
+ return [4 /*yield*/, this.createLigandStructure(isBranchedView)];
1021
+ case 16:
1022
+ _a.sent();
1023
+ _a.label = 17;
1024
+ case 17:
1025
+ success = true;
1026
+ return [3 /*break*/, 19];
1027
+ case 18:
1028
+ this.events.loadComplete.next(success);
1029
+ return [7 /*endfinally*/];
1030
+ case 19: return [2 /*return*/];
1031
+ }
1032
+ });
1033
+ }); })];
1034
+ case 1:
1035
+ _e.sent();
1036
+ return [2 /*return*/];
1037
+ }
1038
+ });
1039
+ });
1040
+ };
1041
+ /** Remove loaded structure(s).
1042
+ * `structureNumberOrId` is either index (numbered from 1!) or the ID that was provided when loading the structure.
1043
+ * If `structureNumberOrId` is undefined, remove all structures.
1044
+ * You will likely need to call `await this.visual.reset({ camera: true })` afterwards. */
1045
+ PDBeMolstarPlugin.prototype.deleteStructure = function (structureNumberOrId) {
1046
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1047
+ var structs, _loop_2, this_2, _i, structs_1, struct;
1048
+ return tslib_1.__generator(this, function (_a) {
1049
+ switch (_a.label) {
1050
+ case 0:
1051
+ structs = this.getStructures(structureNumberOrId);
1052
+ if (structureNumberOrId !== undefined && structs.length === 0) {
1053
+ console.error("Cannot delete structure: there is no structure with number or id ".concat(structureNumberOrId, "."));
1054
+ }
1055
+ _loop_2 = function (struct) {
1056
+ var dataNode;
1057
+ return tslib_1.__generator(this, function (_b) {
1058
+ switch (_b.label) {
1059
+ case 0:
1060
+ dataNode = this_2.plugin.state.data.selectQ(function (q) { return q.byRef(struct.structureRef.cell.transform.ref).ancestorOfType([objects_1.PluginStateObject.Data.String, objects_1.PluginStateObject.Data.Binary]); })[0];
1061
+ if (!dataNode) return [3 /*break*/, 2];
1062
+ return [4 /*yield*/, this_2.plugin.build().delete(dataNode).commit()];
1063
+ case 1:
1064
+ _b.sent();
1065
+ _b.label = 2;
1066
+ case 2: return [2 /*return*/];
1067
+ }
1068
+ });
1069
+ };
1070
+ this_2 = this;
1071
+ _i = 0, structs_1 = structs;
1072
+ _a.label = 1;
1073
+ case 1:
1074
+ if (!(_i < structs_1.length)) return [3 /*break*/, 4];
1075
+ struct = structs_1[_i];
1076
+ return [5 /*yield**/, _loop_2(struct)];
1077
+ case 2:
1078
+ _a.sent();
1079
+ _a.label = 3;
1080
+ case 3:
1081
+ _i++;
1082
+ return [3 /*break*/, 1];
1083
+ case 4: return [2 /*return*/];
1084
+ }
1085
+ });
1086
+ });
1087
+ };
1088
+ /** Apply representations to structure components based on `styles`, also removing any existing representations.
1089
+ * Components not included in `styles` will keep their representations.
1090
+ * E.g. `styles={polymer:'putty',nonStandard:'ball-and-stick'}` - apply only putty to polymer, only ball-and-stick to non-standard residues, leave other components untouched.
1091
+ * E.g. `styles='ball-and-stick'` - apply only ball-and-stick to all components. */
1092
+ PDBeMolstarPlugin.prototype.applyVisualStyles = function (structureRef, styles) {
1093
+ var _a, _b, _c, _d;
1094
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1095
+ var components, compStyles, _loop_3, this_3, _i, components_1, comp;
1096
+ return tslib_1.__generator(this, function (_e) {
1097
+ switch (_e.label) {
1098
+ case 0:
1099
+ if (styles === undefined)
1100
+ return [2 /*return*/];
1101
+ components = this.plugin.state.data.selectQ(function (q) { return q.byRef(structureRef).subtree().withTransformer(model_1.StructureComponent); });
1102
+ compStyles = (0, spec_2.resolveVisualStyleSpec)(styles);
1103
+ _loop_3 = function (comp) {
1104
+ var compType, compStyle, update, existingReprs, _f, existingReprs_1, repr, newReprProps, newRepr;
1105
+ return tslib_1.__generator(this, function (_g) {
1106
+ switch (_g.label) {
1107
+ case 0:
1108
+ compType = (0, helpers_1.getComponentTypeFromTags)((_a = comp.obj) === null || _a === void 0 ? void 0 : _a.tags);
1109
+ if (compType === undefined)
1110
+ return [2 /*return*/, "continue"];
1111
+ compStyle = compStyles[compType];
1112
+ if (compStyle === undefined)
1113
+ return [2 /*return*/, "continue"];
1114
+ update = this_3.plugin.build();
1115
+ existingReprs = this_3.plugin.state.data.selectQ(function (q) { return q.byValue(comp).subtree().withTransformer(representation_1.StructureRepresentation3D); });
1116
+ for (_f = 0, existingReprs_1 = existingReprs; _f < existingReprs_1.length; _f++) {
1117
+ repr = existingReprs_1[_f];
1118
+ update.delete(repr);
1119
+ }
1120
+ newReprProps = (0, structure_representation_params_1.createStructureRepresentationParams)(this_3.plugin, (_b = comp.obj) === null || _b === void 0 ? void 0 : _b.data, tslib_1.__assign({ color: this_3.defaultColorTheme() }, compStyle));
1121
+ return [4 /*yield*/, update.to(comp).apply(representation_1.StructureRepresentation3D, newReprProps).commit()];
1122
+ case 1:
1123
+ newRepr = _g.sent();
1124
+ if (!(((_d = (_c = newRepr.cell) === null || _c === void 0 ? void 0 : _c.params) === null || _d === void 0 ? void 0 : _d.values.type.name) !== compStyle.type)) return [3 /*break*/, 3];
1125
+ return [4 /*yield*/, this_3.plugin.build().delete(newRepr).commit()];
1126
+ case 2:
1127
+ _g.sent(); // sometimes Molstar applies different repr type than requested (especially for water), we must remove such unwanted reprs
1128
+ _g.label = 3;
1129
+ case 3: return [2 /*return*/];
1130
+ }
1131
+ });
1132
+ };
1133
+ this_3 = this;
1134
+ _i = 0, components_1 = components;
1135
+ _e.label = 1;
1136
+ case 1:
1137
+ if (!(_i < components_1.length)) return [3 /*break*/, 4];
1138
+ comp = components_1[_i];
1139
+ return [5 /*yield**/, _loop_3(comp)];
1140
+ case 2:
1141
+ _e.sent();
1142
+ _e.label = 3;
1143
+ case 3:
1144
+ _i++;
1145
+ return [3 /*break*/, 1];
1146
+ case 4: return [2 /*return*/];
1147
+ }
1148
+ });
1149
+ });
1150
+ };
1151
+ PDBeMolstarPlugin.prototype.defaultColorTheme = function () {
1152
+ return this.initParams.alphafoldView ? 'plddt-confidence' : 'default';
1153
+ };
1154
+ /** Remove all structure components of the given structure which correspond to any component type listed in `deleteComponents`. */
1155
+ PDBeMolstarPlugin.prototype.deleteStructureComponents = function (structureRef, deleteComponents) {
1156
+ var _a, _b;
1157
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1158
+ var comps, deleteTags, update, _i, comps_1, comp, tags, remove;
1159
+ return tslib_1.__generator(this, function (_c) {
1160
+ switch (_c.label) {
1161
+ case 0:
1162
+ comps = this.plugin.state.data.selectQ(function (q) { return q.byRef(structureRef).subtree().withTransformer(model_1.StructureComponent); });
1163
+ deleteTags = deleteComponents.flatMap(function (comp) { var _a; return (_a = helpers_1.StructureComponentTags[comp]) !== null && _a !== void 0 ? _a : []; });
1164
+ update = this.plugin.build();
1165
+ for (_i = 0, comps_1 = comps; _i < comps_1.length; _i++) {
1166
+ comp = comps_1[_i];
1167
+ tags = (_b = (_a = comp.obj) === null || _a === void 0 ? void 0 : _a.tags) !== null && _b !== void 0 ? _b : [];
1168
+ remove = tags.some(function (tag) { return deleteTags.includes(tag); });
1169
+ if (remove) {
1170
+ update.delete(comp);
1171
+ }
1172
+ }
1173
+ return [4 /*yield*/, update.commit()];
1174
+ case 1:
1175
+ _c.sent();
1176
+ return [2 /*return*/];
1177
+ }
1178
+ });
1179
+ });
1180
+ };
1181
+ /** Get loci corresponding to a selection within a structure.
1182
+ * If `params` contains more items, return loci for the union of the selections.
1183
+ * If `structureNumber` is provided, use the specified structure (numbered from 1!); otherwise use the last added structure. */
1184
+ PDBeMolstarPlugin.prototype.getLociForParams = function (params, structureNumber) {
1185
+ var assemblyRef = this.assemblyRef;
1186
+ if (structureNumber) {
1187
+ assemblyRef = this.plugin.managers.structure.hierarchy.current.structures[structureNumber - 1].cell.transform.ref;
1188
+ }
1189
+ if (assemblyRef === '')
1190
+ return loci_1.EmptyLoci;
1191
+ var data = this.plugin.state.data.select(assemblyRef)[0].obj.data;
1192
+ if (!data)
1193
+ return loci_1.EmptyLoci;
1194
+ return helpers_1.QueryHelper.getInteractivityLoci(params, data);
1195
+ };
1196
+ PDBeMolstarPlugin.prototype.getLociByPLDDT = function (score, structureNumber) {
1197
+ var assemblyRef = this.assemblyRef;
1198
+ if (structureNumber) {
1199
+ assemblyRef = this.plugin.managers.structure.hierarchy.current.structures[structureNumber - 1].cell.transform.ref;
1200
+ }
1201
+ if (assemblyRef === '')
1202
+ return loci_1.EmptyLoci;
1203
+ var data = this.plugin.state.data.select(assemblyRef)[0].obj.data;
1204
+ if (!data)
1205
+ return loci_1.EmptyLoci;
1206
+ return helpers_1.AlphafoldView.getLociByPLDDT(score, data);
1207
+ };
1208
+ /** For each item in params, get loci and bundle */
1209
+ PDBeMolstarPlugin.prototype.getSelections = function (params, structNumber) {
1210
+ var result = [];
1211
+ for (var _i = 0, params_1 = params; _i < params_1.length; _i++) {
1212
+ var param = params_1[_i];
1213
+ var loci = this.getLociForParams([param], structNumber);
1214
+ if (loci_1.Loci.isEmpty(loci) || !structure_1.StructureElement.Loci.is(loci))
1215
+ continue;
1216
+ var bundle = structure_1.StructureElement.Bundle.fromLoci(loci);
1217
+ result.push({ param: param, loci: loci, bundle: bundle });
1218
+ }
1219
+ return result;
1220
+ };
1221
+ PDBeMolstarPlugin.prototype.getBundle = function (params, structNumber) {
1222
+ var loci = this.getLociForParams(params, structNumber);
1223
+ if (loci_1.Loci.isEmpty(loci) || !structure_1.StructureElement.Loci.is(loci))
1224
+ return undefined;
1225
+ return structure_1.StructureElement.Bundle.fromLoci(loci);
1226
+ };
1227
+ PDBeMolstarPlugin.prototype.normalizeColor = function (colorVal, defaultColor) {
1228
+ if (defaultColor === void 0) { defaultColor = color_1.Color.fromRgb(170, 170, 170); }
1229
+ return (0, helpers_1.normalizeColor)(colorVal, defaultColor);
1230
+ };
1231
+ /** Get structure ref for a structure with given `structureNumberOrId`.
1232
+ * `structureNumberOrId` is either index (numbered from 1!) or the ID that was provided when loading the structure.
1233
+ * If `structureNumberOrId` is undefined, return refs for all loaded structures. */
1234
+ PDBeMolstarPlugin.prototype.getStructures = function (structureNumberOrId) {
1235
+ var allStructures = this.plugin.managers.structure.hierarchy.current.structures.map(function (structureRef, i) { return ({ structureRef: structureRef, number: i + 1 }); });
1236
+ if (typeof structureNumberOrId === 'number') {
1237
+ var theStructure = allStructures[structureNumberOrId - 1];
1238
+ return theStructure ? [theStructure] : [];
1239
+ }
1240
+ else if (typeof structureNumberOrId === 'string') {
1241
+ var structRef_1 = this.structureRefMap.get(structureNumberOrId);
1242
+ if (structRef_1 === undefined) {
1243
+ return [];
1244
+ }
1245
+ var found = allStructures.find(function (s) { return s.structureRef.cell.transform.ref === structRef_1; });
1246
+ if (found) {
1247
+ return [found];
1248
+ }
1249
+ else {
1250
+ this.structureRefMap.delete(structureNumberOrId); // remove outdated record
1251
+ return [];
1252
+ }
1253
+ }
1254
+ else {
1255
+ return allStructures;
1256
+ }
1257
+ };
1258
+ /** Get StructureRef for a structure with given `structureNumberOrId`.
1259
+ * `structureNumberOrId` is either index (numbered from 1!) or the ID that was provided when loading the structure. */
1260
+ PDBeMolstarPlugin.prototype.getStructure = function (structureNumberOrId) {
1261
+ var _a;
1262
+ return (_a = this.getStructures(structureNumberOrId)[0]) === null || _a === void 0 ? void 0 : _a.structureRef;
1263
+ };
1264
+ PDBeMolstarPlugin.prototype.clear = function () {
1265
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1266
+ return tslib_1.__generator(this, function (_a) {
1267
+ switch (_a.label) {
1268
+ case 0: return [4 /*yield*/, this.plugin.clear()];
1269
+ case 1:
1270
+ _a.sent();
1271
+ this.assemblyRef = '';
1272
+ this.addedReprs = {};
1273
+ this.isHighlightColorUpdated = false;
1274
+ this.isSelectedColorUpdated = false;
1275
+ return [2 /*return*/];
1276
+ }
1277
+ });
1278
+ });
1279
+ };
1280
+ /** Helper functions related to specific views or use cases */
1281
+ PDBeMolstarPlugin.extensions = {
1282
+ foldseek: Foldseek,
1283
+ };
1284
+ return PDBeMolstarPlugin;
1285
+ }());
1286
+ exports.PDBeMolstarPlugin = PDBeMolstarPlugin;