pdbe-molstar 3.2.0-beta.4 → 3.2.1-beta.1

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.
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Tags = exports.PDBeMolstarPlugin = void 0;
3
+ exports.PDBeMolstarPlugin = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var geo_export_1 = require("Molstar/extensions/geo-export");
6
6
  var behavior_1 = require("Molstar/extensions/model-archive/quality-assessment/behavior");
@@ -20,6 +20,7 @@ var state_interpolation_1 = require("Molstar/mol-plugin-state/animation/built-in
20
20
  var state_snapshots_1 = require("Molstar/mol-plugin-state/animation/built-in/state-snapshots");
21
21
  var structure_overpaint_1 = require("Molstar/mol-plugin-state/helpers/structure-overpaint");
22
22
  var structure_representation_params_1 = require("Molstar/mol-plugin-state/helpers/structure-representation-params");
23
+ var objects_1 = require("Molstar/mol-plugin-state/objects");
23
24
  var transforms_1 = require("Molstar/mol-plugin-state/transforms");
24
25
  var model_1 = require("Molstar/mol-plugin-state/transforms/model");
25
26
  var representation_1 = require("Molstar/mol-plugin-state/transforms/representation");
@@ -40,6 +41,7 @@ var names_1 = require("Molstar/mol-util/color/names");
40
41
  var rx_event_helper_1 = require("Molstar/mol-util/rx-event-helper");
41
42
  var custom_events_1 = require("./custom-events");
42
43
  var behavior_4 = require("./domain-annotations/behavior");
44
+ var Foldseek = tslib_1.__importStar(require("./extensions/foldseek"));
43
45
  var helpers_1 = require("./helpers");
44
46
  var overlay_1 = require("./overlay");
45
47
  var plugin_custom_state_1 = require("./plugin-custom-state");
@@ -66,13 +68,15 @@ var PDBeMolstarPlugin = /** @class */ (function () {
66
68
  this.isSelectedColorUpdated = false;
67
69
  /** Keeps track of representations added by `.visual.select` for each structure. */
68
70
  this.addedReprs = {};
71
+ /** Maps structure IDs (assigned when loading) to cell refs. */
72
+ this.structureRefMap = new Map();
69
73
  this.applyVisualParams = function () {
70
74
  var _a;
71
75
  var componentGroups = _this.plugin.managers.structure.hierarchy.currentComponentGroups;
72
76
  var _loop_1 = function (compGroup) {
73
77
  var compRef = compGroup[compGroup.length - 1];
74
78
  var tag = (_a = compRef.key) !== null && _a !== void 0 ? _a : '';
75
- var remove = _this.initParams.hideStructure.some(function (type) { var _a; return (_a = StructureComponentTags[type]) === null || _a === void 0 ? void 0 : _a.includes(tag); });
79
+ var remove = _this.initParams.hideStructure.some(function (type) { var _a; return (_a = helpers_1.StructureComponentTags[type]) === null || _a === void 0 ? void 0 : _a.includes(tag); });
76
80
  if (remove) {
77
81
  _this.plugin.managers.structure.hierarchy.remove([compRef]);
78
82
  }
@@ -90,17 +94,9 @@ var PDBeMolstarPlugin = /** @class */ (function () {
90
94
  _loop_1(compGroup);
91
95
  }
92
96
  };
97
+ /** Helper methods related to canvas and layout */
93
98
  this.canvas = {
94
- toggleControls: function (isVisible) {
95
- if (typeof isVisible === 'undefined')
96
- isVisible = !_this.plugin.layout.state.showControls;
97
- commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { showControls: isVisible } });
98
- },
99
- toggleExpanded: function (isExpanded) {
100
- if (typeof isExpanded === 'undefined')
101
- isExpanded = !_this.plugin.layout.state.isExpanded;
102
- commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { isExpanded: isExpanded } });
103
- },
99
+ /** Set canvas background color. */
104
100
  setBgColor: function (color) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
105
101
  return tslib_1.__generator(this, function (_a) {
106
102
  switch (_a.label) {
@@ -114,6 +110,18 @@ var PDBeMolstarPlugin = /** @class */ (function () {
114
110
  }
115
111
  });
116
112
  }); },
113
+ /** Set controls panel visibility. Without `isVisible` parameter, toggle controls panel visibility. */
114
+ toggleControls: function (isVisible) {
115
+ if (typeof isVisible === 'undefined')
116
+ isVisible = !_this.plugin.layout.state.showControls;
117
+ commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { showControls: isVisible } });
118
+ },
119
+ /** Set full-screen mode on or off. Without `isExpanded` parameter, toggle full-screen mode. */
120
+ toggleExpanded: function (isExpanded) {
121
+ if (typeof isExpanded === 'undefined')
122
+ isExpanded = !_this.plugin.layout.state.isExpanded;
123
+ commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { isExpanded: isExpanded } });
124
+ },
117
125
  applySettings: function (settings) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
118
126
  var renderer;
119
127
  return tslib_1.__generator(this, function (_a) {
@@ -138,54 +146,187 @@ var PDBeMolstarPlugin = /** @class */ (function () {
138
146
  });
139
147
  }); },
140
148
  };
149
+ /** Helper methods related to 3D visuals */
141
150
  this.visual = {
142
- highlight: function (params) {
143
- var loci = _this.getLociForParams(params.data, params.structureNumber);
144
- if (loci_1.Loci.isEmpty(loci))
145
- return;
146
- if (params.color) {
147
- _this.visual.setColor({ highlight: params.color });
148
- }
149
- _this.plugin.managers.interactivity.lociHighlights.highlightOnly({ loci: loci });
150
- if (params.focus)
151
- _this.plugin.managers.camera.focusLoci(loci);
152
- },
153
- clearHighlight: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
151
+ /** Change the visibility of individual entity visuals */
152
+ visibility: function (data) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
153
+ var _a, _b, _c, _i, visual, requiredVisibility, tags, _d, tags_1, tag, componentRef, compVisual, currentlyVisible;
154
+ var _e;
155
+ return tslib_1.__generator(this, function (_f) {
156
+ switch (_f.label) {
157
+ case 0:
158
+ if (!data)
159
+ return [2 /*return*/];
160
+ _a = data;
161
+ _b = [];
162
+ for (_c in _a)
163
+ _b.push(_c);
164
+ _i = 0;
165
+ _f.label = 1;
166
+ case 1:
167
+ if (!(_i < _b.length)) return [3 /*break*/, 6];
168
+ _c = _b[_i];
169
+ if (!(_c in _a)) return [3 /*break*/, 5];
170
+ visual = _c;
171
+ requiredVisibility = data[visual];
172
+ if (requiredVisibility === undefined)
173
+ return [3 /*break*/, 5];
174
+ tags = (_e = helpers_1.StructureComponentTags[visual]) !== null && _e !== void 0 ? _e : [];
175
+ _d = 0, tags_1 = tags;
176
+ _f.label = 2;
177
+ case 2:
178
+ if (!(_d < tags_1.length)) return [3 /*break*/, 5];
179
+ tag = tags_1[_d];
180
+ componentRef = mol_state_1.StateSelection.findTagInSubtree(this.plugin.state.data.tree, mol_state_1.StateTransform.RootRef, tag);
181
+ if (!componentRef) return [3 /*break*/, 4];
182
+ compVisual = this.plugin.state.data.select(componentRef)[0];
183
+ if (!(compVisual && compVisual.obj)) return [3 /*break*/, 4];
184
+ currentlyVisible = !(compVisual.state && compVisual.state.isHidden);
185
+ if (!(currentlyVisible !== requiredVisibility)) return [3 /*break*/, 4];
186
+ return [4 /*yield*/, commands_1.PluginCommands.State.ToggleVisibility(this.plugin, { state: this.state, ref: componentRef })];
187
+ case 3:
188
+ _f.sent();
189
+ _f.label = 4;
190
+ case 4:
191
+ _d++;
192
+ return [3 /*break*/, 2];
193
+ case 5:
194
+ _i++;
195
+ return [3 /*break*/, 1];
196
+ case 6: return [2 /*return*/];
197
+ }
198
+ });
199
+ }); },
200
+ /** Change the visibility of a structure.
201
+ * `structureNumberOrId` is either index (numbered from 1!) or the ID that was provided when loading the structure.
202
+ * If `visibility` is undefined, toggle current visibility state. */
203
+ structureVisibility: function (structureNumberOrId, visibility) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
204
+ var struct, currentVisibility;
205
+ return tslib_1.__generator(this, function (_a) {
206
+ switch (_a.label) {
207
+ case 0:
208
+ struct = this.getStructure(structureNumberOrId);
209
+ if (!struct) {
210
+ console.error("Cannot change visibility of structure ".concat(structureNumberOrId, ": structure not found."));
211
+ return [2 /*return*/];
212
+ }
213
+ currentVisibility = !struct.cell.state.isHidden;
214
+ if (!(visibility !== currentVisibility)) return [3 /*break*/, 2];
215
+ return [4 /*yield*/, commands_1.PluginCommands.State.ToggleVisibility(this.plugin, { state: this.state, ref: struct.cell.transform.ref })];
216
+ case 1:
217
+ _a.sent();
218
+ _a.label = 2;
219
+ case 2: return [2 /*return*/];
220
+ }
221
+ });
222
+ }); },
223
+ /** With `isSpinning` parameter, switch visual rotation on or off. Without `isSpinning` parameter, toggle rotation. If `resetCamera`, also reset the camera zoom. */
224
+ toggleSpin: function (isSpinning, resetCamera) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
225
+ var trackball, toggleSpinParam;
154
226
  return tslib_1.__generator(this, function (_a) {
155
- this.plugin.managers.interactivity.lociHighlights.highlightOnly({ loci: loci_1.EmptyLoci });
156
- if (this.isHighlightColorUpdated)
157
- this.visual.reset({ highlightColor: true });
227
+ switch (_a.label) {
228
+ case 0:
229
+ if (!this.plugin.canvas3d)
230
+ return [2 /*return*/];
231
+ trackball = this.plugin.canvas3d.props.trackball;
232
+ toggleSpinParam = trackball.animate.name === 'spin' ? { name: 'off', params: {} } : { name: 'spin', params: { speed: 1 } };
233
+ if (typeof isSpinning !== 'undefined') {
234
+ toggleSpinParam = { name: 'off', params: {} };
235
+ if (isSpinning)
236
+ toggleSpinParam = { name: 'spin', params: { speed: 1 } };
237
+ }
238
+ return [4 /*yield*/, commands_1.PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: { trackball: tslib_1.__assign(tslib_1.__assign({}, trackball), { animate: toggleSpinParam }) } })];
239
+ case 1:
240
+ _a.sent();
241
+ if (!resetCamera) return [3 /*break*/, 3];
242
+ return [4 /*yield*/, commands_1.PluginCommands.Camera.Reset(this.plugin, {})];
243
+ case 2:
244
+ _a.sent();
245
+ _a.label = 3;
246
+ case 3: return [2 /*return*/];
247
+ }
248
+ });
249
+ }); },
250
+ /** Focus (zoom) on the part of the structure defined by `selection`.
251
+ * If `selection` contains more items, focus on the union of those.
252
+ * If `structureNumber` is provided, use the specified structure (numbered from 1!); otherwise use the last added structure. */
253
+ focus: function (selection, structureNumber) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
254
+ var loci;
255
+ return tslib_1.__generator(this, function (_a) {
256
+ loci = this.getLociForParams(selection, structureNumber);
257
+ this.plugin.managers.camera.focusLoci(loci);
158
258
  return [2 /*return*/];
159
259
  });
160
260
  }); },
161
- /** `structureNumber` counts from 1; if not provided, select will be applied to all loaded structures.
162
- * Use `keepColors` and/or `keepRepresentations` to preserve currently active selection.
163
- */
261
+ /** Trigger highlight on the part of the structure defined by `data`
262
+ * (this will look the same as when the user hovers over a part of the structure).
263
+ * If `focus`, also zoom on the highlighted part.
264
+ * If `structureNumber` is provided, use the specified structure (numbered from 1!); otherwise use the last added structure. */
265
+ highlight: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
266
+ var loci;
267
+ return tslib_1.__generator(this, function (_a) {
268
+ switch (_a.label) {
269
+ case 0:
270
+ loci = this.getLociForParams(params.data, params.structureNumber);
271
+ if (loci_1.Loci.isEmpty(loci))
272
+ return [2 /*return*/];
273
+ if (!params.color) return [3 /*break*/, 2];
274
+ return [4 /*yield*/, this.visual.setColor({ highlight: params.color })];
275
+ case 1:
276
+ _a.sent();
277
+ _a.label = 2;
278
+ case 2:
279
+ this.plugin.managers.interactivity.lociHighlights.highlightOnly({ loci: loci });
280
+ if (params.focus)
281
+ this.plugin.managers.camera.focusLoci(loci);
282
+ return [2 /*return*/];
283
+ }
284
+ });
285
+ }); },
286
+ /** Remove any current highlight and reset the highlight color to its default value. */
287
+ clearHighlight: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
288
+ return tslib_1.__generator(this, function (_a) {
289
+ switch (_a.label) {
290
+ case 0:
291
+ this.plugin.managers.interactivity.lociHighlights.highlightOnly({ loci: loci_1.EmptyLoci });
292
+ if (!this.isHighlightColorUpdated) return [3 /*break*/, 2];
293
+ return [4 /*yield*/, this.visual.reset({ highlightColor: true })];
294
+ case 1:
295
+ _a.sent();
296
+ _a.label = 2;
297
+ case 2: return [2 /*return*/];
298
+ }
299
+ });
300
+ }); },
301
+ /** Color the parts of the structure defined by `data`. Color the rest of the structure in `nonSelectedColor` if provided.
302
+ * If any items in `data` contain `focus`, zoom to the union of these items.
303
+ * If any items in `data` contain `sideChain` or `representation`, add extra representations to them (colored in `representationColor` if provided).
304
+ * If `structureNumber` is provided, apply to the specified structure (numbered from 1!); otherwise apply to all loaded structures.
305
+ * Remove any previously added coloring and extra representations, unless `keepColors` and/or `keepRepresentations` is set. */
164
306
  select: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
165
- var 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;
307
+ 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;
166
308
  var _this = this;
167
- var _h, _j, _k;
168
- return tslib_1.__generator(this, function (_l) {
169
- switch (_l.label) {
170
- case 0: return [4 /*yield*/, this.visual.clearSelection(params.structureNumber, { keepColors: params.keepColors, keepRepresentations: params.keepRepresentations })];
309
+ var _h, _j, _k, _l;
310
+ return tslib_1.__generator(this, function (_m) {
311
+ switch (_m.label) {
312
+ case 0:
313
+ structureNumberOrId = (_h = params.structureId) !== null && _h !== void 0 ? _h : params.structureNumber;
314
+ return [4 /*yield*/, this.visual.clearSelection(structureNumberOrId, { keepColors: params.keepColors, keepRepresentations: params.keepRepresentations })];
171
315
  case 1:
172
- _l.sent();
173
- structures = this.plugin.managers.structure.hierarchy.current.structures.map(function (structureRef, i) { return ({ structureRef: structureRef, number: i + 1 }); });
174
- if (params.structureNumber !== undefined) {
175
- structures = [structures[params.structureNumber - 1]];
176
- }
316
+ _m.sent();
317
+ structures = this.getStructures(structureNumberOrId);
177
318
  addedReprParams = {};
178
319
  for (_i = 0, _a = params.data; _i < _a.length; _i++) {
179
320
  param = _a[_i];
180
- repr = (_h = param.representation) !== null && _h !== void 0 ? _h : (param.sideChain ? 'ball-and-stick' : undefined);
321
+ repr = (_j = param.representation) !== null && _j !== void 0 ? _j : (param.sideChain ? 'ball-and-stick' : undefined);
181
322
  if (repr) {
182
- ((_j = addedReprParams[repr]) !== null && _j !== void 0 ? _j : (addedReprParams[repr] = [])).push(param);
323
+ ((_k = addedReprParams[repr]) !== null && _k !== void 0 ? _k : (addedReprParams[repr] = [])).push(param);
183
324
  }
184
325
  }
185
326
  DefaultSelectColor = color_1.Color.fromRgb(255, 112, 3);
186
327
  focusLoci = [];
187
328
  _b = 0, structures_1 = structures;
188
- _l.label = 2;
329
+ _m.label = 2;
189
330
  case 2:
190
331
  if (!(_b < structures_1.length)) return [3 /*break*/, 8];
191
332
  struct = structures_1[_b];
@@ -215,13 +356,13 @@ var PDBeMolstarPlugin = /** @class */ (function () {
215
356
  }
216
357
  return [4 /*yield*/, (0, helpers_1.applyOverpaint)(this.plugin, struct.structureRef, overpaintLayers)];
217
358
  case 3:
218
- _l.sent();
359
+ _m.sent();
219
360
  _d = addedReprParams;
220
361
  _e = [];
221
362
  for (_f in _d)
222
363
  _e.push(_f);
223
364
  _g = 0;
224
- _l.label = 4;
365
+ _m.label = 4;
225
366
  case 4:
226
367
  if (!(_g < _e.length)) return [3 /*break*/, 7];
227
368
  _f = _e[_g];
@@ -237,15 +378,15 @@ var PDBeMolstarPlugin = /** @class */ (function () {
237
378
  }); });
238
379
  return [4 /*yield*/, this.plugin.build()
239
380
  .to(struct.structureRef.cell)
240
- .apply(model_1.StructureComponent, { type: { name: 'bundle', params: bundle }, label: repr }, { tags: exports.Tags.AddedComponent })
241
- .apply(representation_1.StructureRepresentation3D, (0, structure_representation_params_1.createStructureRepresentationParams)(this.plugin, (_k = struct.structureRef.cell.obj) === null || _k === void 0 ? void 0 : _k.data, { type: repr }))
242
- .apply(transforms_1.StateTransforms.Representation.OverpaintStructureRepresentation3DFromBundle, { layers: overpaintLayers_1 }, { tags: exports.Tags.Overpaint })
381
+ .apply(model_1.StructureComponent, { type: { name: 'bundle', params: bundle }, label: repr }, { tags: helpers_1.Tags.AddedComponent })
382
+ .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 }))
383
+ .apply(transforms_1.StateTransforms.Representation.OverpaintStructureRepresentation3DFromBundle, { layers: overpaintLayers_1 }, { tags: helpers_1.Tags.Overpaint })
243
384
  .commit()];
244
385
  case 5:
245
- _l.sent();
386
+ _m.sent();
246
387
  // Track that reprs have been added (for later clearSelection)
247
388
  this.addedReprs[struct.number] = true;
248
- _l.label = 6;
389
+ _m.label = 6;
249
390
  case 6:
250
391
  _g++;
251
392
  return [3 /*break*/, 4];
@@ -261,25 +402,22 @@ var PDBeMolstarPlugin = /** @class */ (function () {
261
402
  }
262
403
  });
263
404
  }); },
264
- /** Clear any currently active "selection" (i.e. colored residues and added representations via `select`).
265
- * `structureNumber` counts from 1; if not provided, clearSelection will be applied to all loaded structures.
266
- * If `keepColors`, curent residue coloring is preserved. If `keepRepresentations`, current added representations are preserved. */
267
- clearSelection: function (structureNumber, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
405
+ /** Remove any coloring and extra representations previously added by the `select` method.
406
+ * If `structureNumber` is provided, apply to the specified structure (numbered from 1!); otherwise apply to all loaded structures.
407
+ * If `keepColors`, current residue coloring is preserved. If `keepRepresentations`, current added representations are preserved. */
408
+ clearSelection: function (structureNumberOrId, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
268
409
  var structures, _i, structures_2, struct, componentsToClear, componentsToDelete, update, _a, componentsToDelete_1, comp;
269
410
  return tslib_1.__generator(this, function (_b) {
270
411
  switch (_b.label) {
271
412
  case 0:
272
- structures = this.plugin.managers.structure.hierarchy.current.structures.map(function (structureRef, i) { return ({ structureRef: structureRef, number: i + 1 }); });
273
- if (structureNumber !== undefined) {
274
- structures = [structures[structureNumber - 1]];
275
- }
413
+ structures = this.getStructures(structureNumberOrId);
276
414
  _i = 0, structures_2 = structures;
277
415
  _b.label = 1;
278
416
  case 1:
279
417
  if (!(_i < structures_2.length)) return [3 /*break*/, 6];
280
418
  struct = structures_2[_i];
281
419
  if (!!(options === null || options === void 0 ? void 0 : options.keepColors)) return [3 /*break*/, 3];
282
- componentsToClear = struct.structureRef.components.filter(function (c) { var _a; return !((_a = c.cell.transform.tags) === null || _a === void 0 ? void 0 : _a.includes(exports.Tags.AddedComponent)); });
420
+ 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)); });
283
421
  return [4 /*yield*/, (0, structure_overpaint_1.clearStructureOverpaint)(this.plugin, componentsToClear)];
284
422
  case 2:
285
423
  _b.sent();
@@ -287,7 +425,7 @@ var PDBeMolstarPlugin = /** @class */ (function () {
287
425
  case 3:
288
426
  if (!!(options === null || options === void 0 ? void 0 : options.keepRepresentations)) return [3 /*break*/, 5];
289
427
  if (!this.addedReprs[struct.number]) return [3 /*break*/, 5];
290
- componentsToDelete = struct.structureRef.components.filter(function (comp) { var _a; return (_a = comp.cell.transform.tags) === null || _a === void 0 ? void 0 : _a.includes(exports.Tags.AddedComponent); });
428
+ 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); });
291
429
  update = this.plugin.build();
292
430
  for (_a = 0, componentsToDelete_1 = componentsToDelete; _a < componentsToDelete_1.length; _a++) {
293
431
  comp = componentsToDelete_1[_a];
@@ -305,148 +443,99 @@ var PDBeMolstarPlugin = /** @class */ (function () {
305
443
  }
306
444
  });
307
445
  }); },
308
- update: function (options, fullLoad) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
309
- var validationIssues, dataSource;
310
- return tslib_1.__generator(this, function (_a) {
311
- switch (_a.label) {
312
- case 0:
313
- console.debug('Updating PDBeMolstarPlugin instance with options:', options);
314
- // Validate options
315
- if (!options) {
316
- console.error('Missing `options` argument to `PDBeMolstarPlugin.visual.update');
317
- return [2 /*return*/];
318
- }
319
- validationIssues = (0, spec_2.validateInitParams)(options);
320
- if (validationIssues) {
321
- console.error('Invalid PDBeMolstarPlugin options:', options);
322
- return [2 /*return*/];
323
- }
324
- this.initParams = (0, helpers_1.addDefaults)(options, spec_2.DefaultParams);
325
- if (!this.initParams.moleculeId && !this.initParams.customData)
326
- return [2 /*return*/, false];
327
- if (this.initParams.customData && this.initParams.customData.url && !this.initParams.customData.format)
328
- return [2 /*return*/, false];
329
- (0, plugin_custom_state_1.PluginCustomState)(this.plugin).initParams = this.initParams;
330
- // Show/hide buttons in the viewport control panel
331
- this.plugin.config.set(config_1.PluginConfig.Viewport.ShowExpand, !this.initParams.hideCanvasControls.includes('expand'));
332
- this.plugin.config.set(config_1.PluginConfig.Viewport.ShowSelectionMode, !this.initParams.hideCanvasControls.includes('selection'));
333
- this.plugin.config.set(config_1.PluginConfig.Viewport.ShowAnimation, !this.initParams.hideCanvasControls.includes('animation'));
334
- this.plugin.config.set(config_1.PluginConfig.Viewport.ShowControls, !this.initParams.hideCanvasControls.includes('controlToggle'));
335
- this.plugin.config.set(config_1.PluginConfig.Viewport.ShowSettings, !this.initParams.hideCanvasControls.includes('controlInfo'));
336
- if (!(this.initParams.bgColor || this.initParams.lighting)) return [3 /*break*/, 2];
337
- return [4 /*yield*/, this.canvas.applySettings({ color: this.initParams.bgColor, lighting: this.initParams.lighting })];
338
- case 1:
339
- _a.sent();
340
- _a.label = 2;
341
- case 2:
342
- dataSource = this.getMoleculeSrcUrl();
343
- if (!dataSource) return [3 /*break*/, 4];
344
- return [4 /*yield*/, this.load({ url: dataSource.url, format: dataSource.format, assemblyId: this.initParams.assemblyId, isBinary: dataSource.isBinary }, fullLoad)];
345
- case 3:
346
- _a.sent();
347
- _a.label = 4;
348
- case 4: return [2 /*return*/];
349
- }
350
- });
351
- }); },
352
- visibility: function (data) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
353
- var _a, _b, _c, _i, visual, tags, _d, tags_1, tag, componentRef, compVisual, currentlyVisible;
354
- var _e;
355
- return tslib_1.__generator(this, function (_f) {
356
- switch (_f.label) {
446
+ /** Add interactive tooltips to parts of the structure. The added tooltips will be shown on a separate line in the tooltip box.
447
+ * Repeated call to this function removes any previously added tooltips.
448
+ * `structureNumber` counts from 1; if not provided, tooltips will be applied to all loaded structures.
449
+ * Example: `await this.visual.tooltips({ data: [{ struct_asym_id: 'A', tooltip: 'Chain A' }, { struct_asym_id: 'B', tooltip: 'Chain B' }] });`. */
450
+ tooltips: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
451
+ var structures, _loop_2, this_1, _i, structures_3, struct;
452
+ var _a;
453
+ return tslib_1.__generator(this, function (_b) {
454
+ switch (_b.label) {
357
455
  case 0:
358
- if (!data)
359
- return [2 /*return*/];
360
- _a = data;
361
- _b = [];
362
- for (_c in _a)
363
- _b.push(_c);
364
- _i = 0;
365
- _f.label = 1;
456
+ structures = this.getStructures((_a = params.structureId) !== null && _a !== void 0 ? _a : params.structureNumber);
457
+ _loop_2 = function (struct) {
458
+ var selections, customTooltipProps, structRef, customPropsCells;
459
+ return tslib_1.__generator(this, function (_c) {
460
+ switch (_c.label) {
461
+ case 0:
462
+ selections = this_1.getSelections(params.data, struct.number);
463
+ customTooltipProps = {
464
+ tooltips: selections.map(function (s) { var _a; return ({ text: (_a = s.param.tooltip) !== null && _a !== void 0 ? _a : '', selector: { name: 'bundle', params: s.bundle } }); }),
465
+ };
466
+ structRef = struct.structureRef.cell.transform.ref;
467
+ customPropsCells = this_1.plugin.state.data.select(mol_state_1.StateSelection.Generators.ofTransformer(model_1.CustomStructureProperties, structRef));
468
+ if (!(customPropsCells.length === 0)) return [3 /*break*/, 2];
469
+ return [4 /*yield*/, this_1.plugin.build().to(structRef).apply(model_1.CustomStructureProperties).commit()];
470
+ case 1:
471
+ _c.sent();
472
+ customPropsCells = this_1.plugin.state.data.select(mol_state_1.StateSelection.Generators.ofTransformer(model_1.CustomStructureProperties, structRef));
473
+ _c.label = 2;
474
+ case 2: return [4 /*yield*/, this_1.plugin.build().to(customPropsCells[0]).update(function (old) {
475
+ var _a;
476
+ return ({
477
+ properties: tslib_1.__assign(tslib_1.__assign({}, old.properties), (_a = {}, _a[custom_tooltips_prop_1.CustomTooltipsProvider.descriptor.name] = customTooltipProps, _a)),
478
+ autoAttach: old.autoAttach.includes(custom_tooltips_prop_1.CustomTooltipsProvider.descriptor.name) ?
479
+ old.autoAttach
480
+ : tslib_1.__spreadArray(tslib_1.__spreadArray([], old.autoAttach, true), [custom_tooltips_prop_1.CustomTooltipsProvider.descriptor.name], false),
481
+ });
482
+ }).commit()];
483
+ case 3:
484
+ _c.sent();
485
+ return [2 /*return*/];
486
+ }
487
+ });
488
+ };
489
+ this_1 = this;
490
+ _i = 0, structures_3 = structures;
491
+ _b.label = 1;
366
492
  case 1:
367
- if (!(_i < _b.length)) return [3 /*break*/, 6];
368
- _c = _b[_i];
369
- if (!(_c in _a)) return [3 /*break*/, 5];
370
- visual = _c;
371
- tags = (_e = StructureComponentTags[visual]) !== null && _e !== void 0 ? _e : [];
372
- _d = 0, tags_1 = tags;
373
- _f.label = 2;
493
+ if (!(_i < structures_3.length)) return [3 /*break*/, 4];
494
+ struct = structures_3[_i];
495
+ return [5 /*yield**/, _loop_2(struct)];
374
496
  case 2:
375
- if (!(_d < tags_1.length)) return [3 /*break*/, 5];
376
- tag = tags_1[_d];
377
- componentRef = mol_state_1.StateSelection.findTagInSubtree(this.plugin.state.data.tree, mol_state_1.StateTransform.RootRef, tag);
378
- if (!componentRef) return [3 /*break*/, 4];
379
- compVisual = this.plugin.state.data.select(componentRef)[0];
380
- if (!(compVisual && compVisual.obj)) return [3 /*break*/, 4];
381
- currentlyVisible = (compVisual.state && compVisual.state.isHidden) ? false : true;
382
- if (!(data[visual] !== currentlyVisible)) return [3 /*break*/, 4];
383
- return [4 /*yield*/, commands_1.PluginCommands.State.ToggleVisibility(this.plugin, { state: this.state, ref: componentRef })];
497
+ _b.sent();
498
+ _b.label = 3;
384
499
  case 3:
385
- _f.sent();
386
- _f.label = 4;
387
- case 4:
388
- _d++;
389
- return [3 /*break*/, 2];
390
- case 5:
391
500
  _i++;
392
501
  return [3 /*break*/, 1];
393
- case 6: return [2 /*return*/];
502
+ case 4: return [2 /*return*/];
394
503
  }
395
504
  });
396
505
  }); },
397
- toggleSpin: function (isSpinning, resetCamera) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
398
- var trackball, toggleSpinParam;
506
+ /** Remove any custom tooltips added by the `tooltips` method. */
507
+ clearTooltips: function (structureNumberOrId) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
399
508
  return tslib_1.__generator(this, function (_a) {
400
509
  switch (_a.label) {
401
- case 0:
402
- if (!this.plugin.canvas3d)
403
- return [2 /*return*/];
404
- trackball = this.plugin.canvas3d.props.trackball;
405
- toggleSpinParam = trackball.animate.name === 'spin' ? { name: 'off', params: {} } : { name: 'spin', params: { speed: 1 } };
406
- if (typeof isSpinning !== 'undefined') {
407
- toggleSpinParam = { name: 'off', params: {} };
408
- if (isSpinning)
409
- toggleSpinParam = { name: 'spin', params: { speed: 1 } };
410
- }
411
- return [4 /*yield*/, commands_1.PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: { trackball: tslib_1.__assign(tslib_1.__assign({}, trackball), { animate: toggleSpinParam }) } })];
510
+ case 0: return [4 /*yield*/, this.visual.tooltips({ data: [], structureId: structureNumberOrId })];
412
511
  case 1:
413
512
  _a.sent();
414
- if (!resetCamera) return [3 /*break*/, 3];
415
- return [4 /*yield*/, commands_1.PluginCommands.Camera.Reset(this.plugin, {})];
416
- case 2:
417
- _a.sent();
418
- _a.label = 3;
419
- case 3: return [2 /*return*/];
513
+ return [2 /*return*/];
420
514
  }
421
515
  });
422
516
  }); },
423
- focus: function (params, structureNumber) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
424
- var loci;
425
- return tslib_1.__generator(this, function (_a) {
426
- loci = this.getLociForParams(params, structureNumber);
427
- this.plugin.managers.camera.focusLoci(loci);
428
- return [2 /*return*/];
429
- });
430
- }); },
431
- setColor: function (param) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
517
+ /** Set highlight and/or selection color.
518
+ * Highlight color is used when the user hovers over a part of the structure or when applying the `highlight` method.
519
+ * 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. */
520
+ setColor: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
432
521
  var renderer, marking;
433
522
  return tslib_1.__generator(this, function (_a) {
434
523
  switch (_a.label) {
435
524
  case 0:
436
525
  if (!this.plugin.canvas3d)
437
526
  return [2 /*return*/];
438
- if (!param.highlight && !param.select)
527
+ if (!params.highlight && !params.select)
439
528
  return [2 /*return*/];
440
529
  renderer = tslib_1.__assign({}, this.plugin.canvas3d.props.renderer);
441
530
  marking = tslib_1.__assign({}, this.plugin.canvas3d.props.marking);
442
- if (param.highlight) {
443
- renderer.highlightColor = this.normalizeColor(param.highlight);
444
- marking.highlightEdgeColor = color_1.Color.darken(this.normalizeColor(param.highlight), 1);
531
+ if (params.highlight) {
532
+ renderer.highlightColor = this.normalizeColor(params.highlight);
533
+ marking.highlightEdgeColor = color_1.Color.darken(this.normalizeColor(params.highlight), 1);
445
534
  this.isHighlightColorUpdated = true;
446
535
  }
447
- if (param.select) {
448
- renderer.selectColor = this.normalizeColor(param.select);
449
- marking.selectEdgeColor = color_1.Color.darken(this.normalizeColor(param.select), 1);
536
+ if (params.select) {
537
+ renderer.selectColor = this.normalizeColor(params.select);
538
+ marking.selectEdgeColor = color_1.Color.darken(this.normalizeColor(params.select), 1);
450
539
  this.isSelectedColorUpdated = true;
451
540
  }
452
541
  return [4 /*yield*/, commands_1.PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: { renderer: renderer, marking: marking } })];
@@ -456,6 +545,10 @@ var PDBeMolstarPlugin = /** @class */ (function () {
456
545
  }
457
546
  });
458
547
  }); },
548
+ /** Reset various settings to defaults:
549
+ * `camera` resets camera position (i.e. zooms on the whole scene).
550
+ * `theme` resets color theme for visual representations.
551
+ * `highlightColor` and `selectColor` reset colors previously set by the `setColor` method. */
459
552
  reset: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
460
553
  var defaultTheme, componentGroups, _i, componentGroups_2, compGrp, renderer, marking;
461
554
  return tslib_1.__generator(this, function (_a) {
@@ -506,76 +599,51 @@ var PDBeMolstarPlugin = /** @class */ (function () {
506
599
  }
507
600
  });
508
601
  }); },
509
- /** Add interactive tooltips to parts of the structure. The added tooltips will be shown on a separate line in the tooltip box.
510
- * Repeated call to this function removes any previously added tooltips.
511
- * `structureNumber` counts from 1; if not provided, tooltips will be applied to all loaded structures.
512
- * Example: `await this.visual.tooltips({ data: [{ struct_asym_id: 'A', tooltip: 'Chain A' }, { struct_asym_id: 'B', tooltip: 'Chain B' }] });`. */
513
- tooltips: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
514
- var structures, _loop_2, this_1, _i, structures_3, struct;
602
+ /** Change parameters of the plugin instance.
603
+ * Can be used to load a different structure.
604
+ * If `fullLoad`, remove currently loaded structure before loading the new one;
605
+ * otherwise add the new structure to existing structures. */
606
+ update: function (options, fullLoad) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
607
+ var validationIssues, dataSource;
515
608
  return tslib_1.__generator(this, function (_a) {
516
609
  switch (_a.label) {
517
610
  case 0:
518
- structures = this.plugin.managers.structure.hierarchy.current.structures.map(function (structureRef, i) { return ({ structureRef: structureRef, number: i + 1 }); });
519
- if (params.structureNumber !== undefined) {
520
- structures = [structures[params.structureNumber - 1]];
611
+ console.debug('Updating PDBeMolstarPlugin instance with options:', options);
612
+ // Validate options
613
+ if (!options) {
614
+ console.error('Missing `options` argument to `PDBeMolstarPlugin.visual.update');
615
+ return [2 /*return*/, false];
521
616
  }
522
- _loop_2 = function (struct) {
523
- var selections, customTooltipProps, structRef, customPropsCells;
524
- return tslib_1.__generator(this, function (_b) {
525
- switch (_b.label) {
526
- case 0:
527
- selections = this_1.getSelections(params.data, struct.number);
528
- customTooltipProps = {
529
- tooltips: selections.map(function (s) { var _a; return ({ text: (_a = s.param.tooltip) !== null && _a !== void 0 ? _a : '', selector: { name: 'bundle', params: s.bundle } }); }),
530
- };
531
- structRef = struct.structureRef.cell.transform.ref;
532
- customPropsCells = this_1.plugin.state.data.select(mol_state_1.StateSelection.Generators.ofTransformer(model_1.CustomStructureProperties, structRef));
533
- if (!(customPropsCells.length === 0)) return [3 /*break*/, 2];
534
- return [4 /*yield*/, this_1.plugin.build().to(structRef).apply(model_1.CustomStructureProperties).commit()];
535
- case 1:
536
- _b.sent();
537
- customPropsCells = this_1.plugin.state.data.select(mol_state_1.StateSelection.Generators.ofTransformer(model_1.CustomStructureProperties, structRef));
538
- _b.label = 2;
539
- case 2: return [4 /*yield*/, this_1.plugin.build().to(customPropsCells[0]).update(function (old) {
540
- var _a;
541
- return ({
542
- properties: tslib_1.__assign(tslib_1.__assign({}, old.properties), (_a = {}, _a[custom_tooltips_prop_1.CustomTooltipsProvider.descriptor.name] = customTooltipProps, _a)),
543
- autoAttach: old.autoAttach.includes(custom_tooltips_prop_1.CustomTooltipsProvider.descriptor.name) ?
544
- old.autoAttach
545
- : tslib_1.__spreadArray(tslib_1.__spreadArray([], old.autoAttach, true), [custom_tooltips_prop_1.CustomTooltipsProvider.descriptor.name], false),
546
- });
547
- }).commit()];
548
- case 3:
549
- _b.sent();
550
- return [2 /*return*/];
551
- }
552
- });
553
- };
554
- this_1 = this;
555
- _i = 0, structures_3 = structures;
556
- _a.label = 1;
617
+ validationIssues = (0, spec_2.validateInitParams)(options);
618
+ if (validationIssues) {
619
+ console.error('Invalid PDBeMolstarPlugin options:', options);
620
+ return [2 /*return*/, false];
621
+ }
622
+ this.initParams = (0, helpers_1.addDefaults)(options, spec_2.DefaultParams);
623
+ if (!this.initParams.moleculeId && !this.initParams.customData)
624
+ return [2 /*return*/, false];
625
+ if (this.initParams.customData && this.initParams.customData.url && !this.initParams.customData.format)
626
+ return [2 /*return*/, false];
627
+ (0, plugin_custom_state_1.PluginCustomState)(this.plugin).initParams = this.initParams;
628
+ // Show/hide buttons in the viewport control panel
629
+ this.plugin.config.set(config_1.PluginConfig.Viewport.ShowExpand, !this.initParams.hideCanvasControls.includes('expand'));
630
+ this.plugin.config.set(config_1.PluginConfig.Viewport.ShowSelectionMode, !this.initParams.hideCanvasControls.includes('selection'));
631
+ this.plugin.config.set(config_1.PluginConfig.Viewport.ShowAnimation, !this.initParams.hideCanvasControls.includes('animation'));
632
+ this.plugin.config.set(config_1.PluginConfig.Viewport.ShowControls, !this.initParams.hideCanvasControls.includes('controlToggle'));
633
+ this.plugin.config.set(config_1.PluginConfig.Viewport.ShowSettings, !this.initParams.hideCanvasControls.includes('controlInfo'));
634
+ if (!(this.initParams.bgColor || this.initParams.lighting)) return [3 /*break*/, 2];
635
+ return [4 /*yield*/, this.canvas.applySettings({ color: this.initParams.bgColor, lighting: this.initParams.lighting })];
557
636
  case 1:
558
- if (!(_i < structures_3.length)) return [3 /*break*/, 4];
559
- struct = structures_3[_i];
560
- return [5 /*yield**/, _loop_2(struct)];
561
- case 2:
562
637
  _a.sent();
563
- _a.label = 3;
638
+ _a.label = 2;
639
+ case 2:
640
+ dataSource = this.getMoleculeSrcUrl();
641
+ if (!dataSource) return [3 /*break*/, 4];
642
+ return [4 /*yield*/, this.load({ url: dataSource.url, format: dataSource.format, assemblyId: this.initParams.assemblyId, isBinary: dataSource.isBinary }, fullLoad)];
564
643
  case 3:
565
- _i++;
566
- return [3 /*break*/, 1];
567
- case 4: return [2 /*return*/];
568
- }
569
- });
570
- }); },
571
- /** Remove any tooltips added by `this.visual.tooltips`. */
572
- clearTooltips: function (structureNumber) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
573
- return tslib_1.__generator(this, function (_a) {
574
- switch (_a.label) {
575
- case 0: return [4 /*yield*/, this.visual.tooltips({ data: [], structureNumber: structureNumber })];
576
- case 1:
577
644
  _a.sent();
578
- return [2 /*return*/];
645
+ _a.label = 4;
646
+ case 4: return [2 /*return*/, true];
579
647
  }
580
648
  });
581
649
  }); },
@@ -735,7 +803,14 @@ var PDBeMolstarPlugin = /** @class */ (function () {
735
803
  if (this.initParams.loadingOverlay) {
736
804
  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();
737
805
  }
738
- this.load({ url: dataSource.url, format: dataSource.format, assemblyId: this.initParams.assemblyId, isBinary: dataSource.isBinary, progressMessage: "Loading ".concat((_f = this.initParams.moleculeId) !== null && _f !== void 0 ? _f : '', " ...") });
806
+ this.load({
807
+ url: dataSource.url,
808
+ format: dataSource.format,
809
+ assemblyId: this.initParams.assemblyId,
810
+ isBinary: dataSource.isBinary,
811
+ progressMessage: "Loading ".concat((_f = this.initParams.moleculeId) !== null && _f !== void 0 ? _f : '', " ..."),
812
+ id: 'main',
813
+ });
739
814
  }
740
815
  // Binding to other PDB Component events
741
816
  if (this.initParams.subscribeEvents) {
@@ -886,14 +961,14 @@ var PDBeMolstarPlugin = /** @class */ (function () {
886
961
  });
887
962
  };
888
963
  PDBeMolstarPlugin.prototype.load = function (_a, fullLoad) {
889
- 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;
964
+ 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;
890
965
  if (fullLoad === void 0) { fullLoad = true; }
891
966
  return tslib_1.__awaiter(this, void 0, void 0, function () {
892
967
  var _this = this;
893
968
  return tslib_1.__generator(this, function (_e) {
894
969
  switch (_e.label) {
895
970
  case 0: return [4 /*yield*/, (0, helpers_1.runWithProgressMessage)(this.plugin, progressMessage, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
896
- var success, isHetView, downloadOptions, isBranchedView, data, trajectory, model, pivotIndex, pivot, asm, defaultMapParams, pdbeMapParams;
971
+ var success, isHetView, downloadOptions, isBranchedView, data_1, trajectory, structRef, model, structure, pivotIndex, pivot, asm, defaultMapParams, pdbeMapParams;
897
972
  return tslib_1.__generator(this, function (_a) {
898
973
  switch (_a.label) {
899
974
  case 0:
@@ -916,10 +991,11 @@ var PDBeMolstarPlugin = /** @class */ (function () {
916
991
  }
917
992
  return [4 /*yield*/, this.plugin.builders.data.download({ url: assets_1.Asset.Url(url, downloadOptions), isBinary: isBinary }, { state: { isGhost: true } })];
918
993
  case 4:
919
- data = _a.sent();
920
- return [4 /*yield*/, this.plugin.builders.structure.parseTrajectory(data, format)];
994
+ data_1 = _a.sent();
995
+ return [4 /*yield*/, this.plugin.builders.structure.parseTrajectory(data_1, format)];
921
996
  case 5:
922
997
  trajectory = _a.sent();
998
+ structRef = void 0;
923
999
  if (!!isHetView) return [3 /*break*/, 7];
924
1000
  return [4 /*yield*/, this.plugin.builders.structure.hierarchy.applyPreset(trajectory, this.initParams.defaultPreset, {
925
1001
  structure: assemblyId ? (assemblyId === 'preferred') ? void 0 : { name: 'assembly', params: { id: assemblyId } } : { name: 'model', params: {} },
@@ -928,6 +1004,7 @@ var PDBeMolstarPlugin = /** @class */ (function () {
928
1004
  })];
929
1005
  case 6:
930
1006
  _a.sent();
1007
+ structRef = this.plugin.state.data.selectQ(function (q) { return q.byRef(data_1.ref).subtree().ofType(objects_1.PluginStateObject.Molecule.Structure); })[0].transform.ref;
931
1008
  if (this.initParams.hideStructure.length > 0 || this.initParams.visualStyle) {
932
1009
  this.applyVisualParams();
933
1010
  }
@@ -937,9 +1014,13 @@ var PDBeMolstarPlugin = /** @class */ (function () {
937
1014
  model = _a.sent();
938
1015
  return [4 /*yield*/, this.plugin.builders.structure.createStructure(model, { name: 'model', params: {} })];
939
1016
  case 9:
940
- _a.sent();
1017
+ structure = _a.sent();
1018
+ structRef = structure.ref;
941
1019
  _a.label = 10;
942
1020
  case 10:
1021
+ if (id) {
1022
+ this.structureRefMap.set(id, structRef);
1023
+ }
943
1024
  // show selection if param is set
944
1025
  if (this.initParams.selection) {
945
1026
  this.visual.select(this.initParams.selection);
@@ -984,6 +1065,56 @@ var PDBeMolstarPlugin = /** @class */ (function () {
984
1065
  });
985
1066
  });
986
1067
  };
1068
+ /** Remove loaded structure(s).
1069
+ * `structureNumberOrId` is either index (numbered from 1!) or the ID that was provided when loading the structure.
1070
+ * If `structureNumberOrId` is undefined, remove all structures.
1071
+ * You will likely need to call `await this.visual.reset({ camera: true })` afterwards. */
1072
+ PDBeMolstarPlugin.prototype.deleteStructure = function (structureNumberOrId) {
1073
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1074
+ var structs, _loop_3, this_2, _i, structs_1, struct;
1075
+ return tslib_1.__generator(this, function (_a) {
1076
+ switch (_a.label) {
1077
+ case 0:
1078
+ structs = this.getStructures(structureNumberOrId);
1079
+ if (structureNumberOrId !== undefined && structs.length === 0) {
1080
+ console.error("Cannot delete structure: there is no structure with number or id ".concat(structureNumberOrId, "."));
1081
+ }
1082
+ _loop_3 = function (struct) {
1083
+ var dataNode;
1084
+ return tslib_1.__generator(this, function (_b) {
1085
+ switch (_b.label) {
1086
+ case 0:
1087
+ 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];
1088
+ if (!dataNode) return [3 /*break*/, 2];
1089
+ return [4 /*yield*/, this_2.plugin.build().delete(dataNode).commit()];
1090
+ case 1:
1091
+ _b.sent();
1092
+ _b.label = 2;
1093
+ case 2: return [2 /*return*/];
1094
+ }
1095
+ });
1096
+ };
1097
+ this_2 = this;
1098
+ _i = 0, structs_1 = structs;
1099
+ _a.label = 1;
1100
+ case 1:
1101
+ if (!(_i < structs_1.length)) return [3 /*break*/, 4];
1102
+ struct = structs_1[_i];
1103
+ return [5 /*yield**/, _loop_3(struct)];
1104
+ case 2:
1105
+ _a.sent();
1106
+ _a.label = 3;
1107
+ case 3:
1108
+ _i++;
1109
+ return [3 /*break*/, 1];
1110
+ case 4: return [2 /*return*/];
1111
+ }
1112
+ });
1113
+ });
1114
+ };
1115
+ /** Get loci corresponding to a selection within a structure.
1116
+ * If `params` contains more items, return loci for the union of the selections.
1117
+ * If `structureNumber` is provided, use the specified structure (numbered from 1!); otherwise use the last added structure. */
987
1118
  PDBeMolstarPlugin.prototype.getLociForParams = function (params, structureNumber) {
988
1119
  var assemblyRef = this.assemblyRef;
989
1120
  if (structureNumber) {
@@ -1029,7 +1160,7 @@ var PDBeMolstarPlugin = /** @class */ (function () {
1029
1160
  };
1030
1161
  PDBeMolstarPlugin.prototype.normalizeColor = function (colorVal, defaultColor) {
1031
1162
  var _a, _b, _c;
1032
- defaultColor !== null && defaultColor !== void 0 ? defaultColor : (defaultColor = color_1.Color.fromRgb(170, 170, 170));
1163
+ if (defaultColor === void 0) { defaultColor = color_1.Color.fromRgb(170, 170, 170); }
1033
1164
  try {
1034
1165
  if (colorVal === undefined || colorVal === null)
1035
1166
  return defaultColor;
@@ -1047,6 +1178,39 @@ var PDBeMolstarPlugin = /** @class */ (function () {
1047
1178
  }
1048
1179
  return defaultColor;
1049
1180
  };
1181
+ /** Get structure ref for a structure with given `structureNumberOrId`.
1182
+ * `structureNumberOrId` is either index (numbered from 1!) or the ID that was provided when loading the structure.
1183
+ * If `structureNumberOrId` is undefined, return refs for all loaded structures. */
1184
+ PDBeMolstarPlugin.prototype.getStructures = function (structureNumberOrId) {
1185
+ var allStructures = this.plugin.managers.structure.hierarchy.current.structures.map(function (structureRef, i) { return ({ structureRef: structureRef, number: i + 1 }); });
1186
+ if (typeof structureNumberOrId === 'number') {
1187
+ var theStructure = allStructures[structureNumberOrId - 1];
1188
+ return theStructure ? [theStructure] : [];
1189
+ }
1190
+ else if (typeof structureNumberOrId === 'string') {
1191
+ var structRef_1 = this.structureRefMap.get(structureNumberOrId);
1192
+ if (structRef_1 === undefined) {
1193
+ return [];
1194
+ }
1195
+ var found = allStructures.find(function (s) { return s.structureRef.cell.transform.ref === structRef_1; });
1196
+ if (found) {
1197
+ return [found];
1198
+ }
1199
+ else {
1200
+ this.structureRefMap.delete(structureNumberOrId); // remove outdated record
1201
+ return [];
1202
+ }
1203
+ }
1204
+ else {
1205
+ return allStructures;
1206
+ }
1207
+ };
1208
+ /** Get StructureRef for a structure with given `structureNumberOrId`.
1209
+ * `structureNumberOrId` is either index (numbered from 1!) or the ID that was provided when loading the structure. */
1210
+ PDBeMolstarPlugin.prototype.getStructure = function (structureNumberOrId) {
1211
+ var _a;
1212
+ return (_a = this.getStructures(structureNumberOrId)[0]) === null || _a === void 0 ? void 0 : _a.structureRef;
1213
+ };
1050
1214
  PDBeMolstarPlugin.prototype.clear = function () {
1051
1215
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1052
1216
  return tslib_1.__generator(this, function (_a) {
@@ -1063,22 +1227,11 @@ var PDBeMolstarPlugin = /** @class */ (function () {
1063
1227
  });
1064
1228
  });
1065
1229
  };
1230
+ /** Helper functions related to specific views or use cases */
1231
+ PDBeMolstarPlugin.extensions = {
1232
+ foldseek: Foldseek,
1233
+ };
1066
1234
  return PDBeMolstarPlugin;
1067
1235
  }());
1068
1236
  exports.PDBeMolstarPlugin = PDBeMolstarPlugin;
1069
- exports.Tags = {
1070
- /** Tag needed for `clearStructureOverpaint`; defined in src/mol-plugin-state/helpers/structure-overpaint.ts but private */
1071
- Overpaint: 'overpaint-controls',
1072
- /** Marks structure components added by `select` */
1073
- AddedComponent: 'pdbe-molstar.added-component',
1074
- };
1075
- var StructureComponentTags = {
1076
- polymer: ['structure-component-static-polymer'],
1077
- het: ['structure-component-static-ligand', 'structure-component-static-ion'],
1078
- water: ['structure-component-static-water'],
1079
- carbs: ['structure-component-static-branched'],
1080
- nonStandard: ['structure-component-static-non-standard'],
1081
- coarse: ['structure-component-static-coarse'],
1082
- maps: ['volume-streaming-info'],
1083
- };
1084
1237
  window.PDBeMolstarPlugin = PDBeMolstarPlugin;