pdbe-molstar 3.10.0 → 3.11.0

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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * pdbe-molstar
3
- * @version 3.10.0
3
+ * @version 3.11.0
4
4
  * @link https://github.com/PDBeurope/pdbe-molstar
5
5
  * @license Apache 2.0
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * pdbe-molstar
3
- * @version 3.10.0
3
+ * @version 3.11.0
4
4
  * @link https://github.com/PDBeurope/pdbe-molstar
5
5
  * @license Apache 2.0
6
6
  */
package/lib/helpers.d.ts CHANGED
@@ -11,6 +11,7 @@ import { Expression } from 'molstar/lib/mol-script/language/expression';
11
11
  import { Overpaint } from 'molstar/lib/mol-theme/overpaint';
12
12
  import { Color } from 'molstar/lib/mol-util/color';
13
13
  import { AnyColor, InitParams } from './spec';
14
+ import { Transparency } from 'molstar/lib/mol-theme/transparency';
14
15
  export type SupportedFormats = 'mmcif' | 'bcif' | 'cif' | 'pdb' | 'sdf';
15
16
  export interface LoadParams {
16
17
  url: string;
@@ -179,9 +180,14 @@ export declare function normalizeColor(colorVal: AnyColor | null | undefined, de
179
180
  /** Apply overpaint to every representation of every component in a structure.
180
181
  * Excludes representations created as "added representations" by `PDBeMolstarPlugin.visual.select`. */
181
182
  export declare function applyOverpaint(plugin: PluginContext, structRef: StructureRef, overpaintLayers: Overpaint.BundleLayer[]): Promise<void>;
183
+ /** Apply transparency to every representation of every component in a structure.
184
+ * Excludes representations created as "added representations" by `PDBeMolstarPlugin.visual.select`. */
185
+ export declare function applyTransparency(plugin: PluginContext, structRef: StructureRef, transparencyLayers: Transparency.BundleLayer[]): Promise<void>;
182
186
  export declare const Tags: {
183
187
  /** Tag needed for `clearStructureOverpaint`; defined in src/mol-plugin-state/helpers/structure-overpaint.ts but private */
184
188
  readonly Overpaint: "overpaint-controls";
189
+ /** Tag needed for `clearStructureTransparency`; defined in src/mol-plugin-state/helpers/structure-transparency.ts but private */
190
+ readonly Transparency: "transparency-controls";
185
191
  /** Marks structure components added by `select` */
186
192
  readonly AddedComponent: "pdbe-molstar.added-component";
187
193
  };
package/lib/helpers.js CHANGED
@@ -8,6 +8,7 @@ exports.combineUrl = combineUrl;
8
8
  exports.addDefaults = addDefaults;
9
9
  exports.normalizeColor = normalizeColor;
10
10
  exports.applyOverpaint = applyOverpaint;
11
+ exports.applyTransparency = applyTransparency;
11
12
  exports.getComponentTypeFromTags = getComponentTypeFromTags;
12
13
  exports.distinct = distinct;
13
14
  exports.groupElements = groupElements;
@@ -524,9 +525,39 @@ function applyOverpaint(plugin, structRef, overpaintLayers) {
524
525
  yield update.commit();
525
526
  });
526
527
  }
528
+ /** Apply transparency to every representation of every component in a structure.
529
+ * Excludes representations created as "added representations" by `PDBeMolstarPlugin.visual.select`. */
530
+ function applyTransparency(plugin, structRef, transparencyLayers) {
531
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
532
+ var _a;
533
+ if (transparencyLayers.length === 0)
534
+ return;
535
+ const update = plugin.build();
536
+ for (const component of structRef.components) {
537
+ if ((_a = component.cell.transform.tags) === null || _a === void 0 ? void 0 : _a.includes(exports.Tags.AddedComponent))
538
+ continue;
539
+ for (const repr of component.representations) {
540
+ const currentTransparency = plugin.state.data.select(mol_state_1.StateSelection.Generators
541
+ .ofTransformer(transforms_1.StateTransforms.Representation.TransparencyStructureRepresentation3DFromBundle, repr.cell.transform.ref)
542
+ .withTag(exports.Tags.Transparency));
543
+ if (currentTransparency.length === 0) {
544
+ // Create a new transparency
545
+ update.to(repr.cell.transform.ref).apply(transforms_1.StateTransforms.Representation.TransparencyStructureRepresentation3DFromBundle, { layers: transparencyLayers }, { tags: exports.Tags.Transparency });
546
+ }
547
+ else {
548
+ // Add layers to existing transparency
549
+ update.to(currentTransparency[0]).update(old => ({ layers: old.layers.concat(transparencyLayers) }));
550
+ }
551
+ }
552
+ }
553
+ yield update.commit();
554
+ });
555
+ }
527
556
  exports.Tags = {
528
557
  /** Tag needed for `clearStructureOverpaint`; defined in src/mol-plugin-state/helpers/structure-overpaint.ts but private */
529
558
  Overpaint: 'overpaint-controls',
559
+ /** Tag needed for `clearStructureTransparency`; defined in src/mol-plugin-state/helpers/structure-transparency.ts but private */
560
+ Transparency: 'transparency-controls',
530
561
  /** Marks structure components added by `select` */
531
562
  AddedComponent: 'pdbe-molstar.added-component',
532
563
  };
package/lib/viewer.d.ts CHANGED
@@ -135,30 +135,36 @@ export declare class PDBeMolstarPlugin {
135
135
  /** Remove any current highlight and reset the highlight color to its default value. */
136
136
  clearHighlight: () => Promise<void>;
137
137
  /** Color the parts of the structure defined by `data`. Color the rest of the structure in `nonSelectedColor` if provided.
138
+ * If any items in `data` contain `opacity`, set opacity accordingly, set opacity to `nonSelectedOpacity` (or 1) for the rest of the structure.
138
139
  * If any items in `data` contain `focus`, zoom to the union of these items.
139
140
  * If any items in `data` contain `sideChain` or `representation`, add extra representations to them (colored in `representationColor` if provided).
140
141
  * If `structureNumber` is provided, apply to the specified structure (numbered from 1!); otherwise apply to all loaded structures.
141
- * Remove any previously added coloring and extra representations, unless `keepColors` and/or `keepRepresentations` is set. */
142
+ * Remove any previously added coloring, opacity, and/or extra representations, unless `keepColors`, `keepOpacity`, and/or `keepRepresentations` is set. */
142
143
  select: (params: {
143
144
  data: (QueryParam & {
144
145
  color?: AnyColor;
146
+ opacity?: number;
145
147
  sideChain?: boolean;
146
148
  representation?: string;
147
- representationColor?: any;
149
+ representationColor?: AnyColor;
150
+ representationOpacity?: number;
148
151
  focus?: boolean;
149
152
  })[];
150
153
  nonSelectedColor?: AnyColor;
154
+ nonSelectedOpacity?: number;
151
155
  structureId?: string;
152
156
  structureNumber?: number;
153
157
  keepColors?: boolean;
158
+ keepOpacity?: boolean;
154
159
  keepRepresentations?: boolean;
155
160
  }) => Promise<void>;
156
161
  /** Remove any coloring and extra representations previously added by the `select` method.
157
162
  * `structureNumberOrId` is either index (numbered from 1!) or the ID that was provided when loading the structure;
158
163
  * if not provided, will apply to all loaded structures.
159
- * If `keepColors`, current residue coloring is preserved. If `keepRepresentations`, current added representations are preserved. */
164
+ * If `keepColors`, current residue coloring is preserved. If `keepOpacity`, current residue opacity is preserved. If `keepRepresentations`, current added representations are preserved. */
160
165
  clearSelection: (structureNumberOrId?: number | string, options?: {
161
166
  keepColors?: boolean;
167
+ keepOpacity?: boolean;
162
168
  keepRepresentations?: boolean;
163
169
  }) => Promise<void>;
164
170
  /** Color the parts of sequence in the sequence panel defined by `data`. Color the rest of the sequence in `nonSelectedColor` if provided.
@@ -233,6 +239,16 @@ export declare class PDBeMolstarPlugin {
233
239
  SupportedVersion: number;
234
240
  fromMVSJ(mvsjString: string): MVSData;
235
241
  toMVSJ(mvsData: MVSData, space?: string | number): string;
242
+ toMVSX(mvsData: MVSData, options?: {
243
+ assets?: {
244
+ [uri: string]: Uint8Array<ArrayBuffer> | string;
245
+ };
246
+ baseUri?: string;
247
+ skipExternal?: boolean;
248
+ cache?: {
249
+ [absoluteUri: string]: Uint8Array<ArrayBuffer> | string;
250
+ };
251
+ }): Promise<Uint8Array<ArrayBuffer>>;
236
252
  isValid(mvsData: MVSData, options?: {
237
253
  noExtra?: boolean;
238
254
  }): boolean;
package/lib/viewer.js CHANGED
@@ -23,6 +23,7 @@ const state_interpolation_1 = require("molstar/lib/mol-plugin-state/animation/bu
23
23
  const state_snapshots_1 = require("molstar/lib/mol-plugin-state/animation/built-in/state-snapshots");
24
24
  const structure_overpaint_1 = require("molstar/lib/mol-plugin-state/helpers/structure-overpaint");
25
25
  const structure_representation_params_1 = require("molstar/lib/mol-plugin-state/helpers/structure-representation-params");
26
+ const structure_transparency_1 = require("molstar/lib/mol-plugin-state/helpers/structure-transparency");
26
27
  const objects_1 = require("molstar/lib/mol-plugin-state/objects");
27
28
  const transforms_1 = require("molstar/lib/mol-plugin-state/transforms");
28
29
  const model_1 = require("molstar/lib/mol-plugin-state/transforms/model");
@@ -214,14 +215,15 @@ class PDBeMolstarPlugin {
214
215
  }
215
216
  }),
216
217
  /** Color the parts of the structure defined by `data`. Color the rest of the structure in `nonSelectedColor` if provided.
218
+ * If any items in `data` contain `opacity`, set opacity accordingly, set opacity to `nonSelectedOpacity` (or 1) for the rest of the structure.
217
219
  * If any items in `data` contain `focus`, zoom to the union of these items.
218
220
  * If any items in `data` contain `sideChain` or `representation`, add extra representations to them (colored in `representationColor` if provided).
219
221
  * If `structureNumber` is provided, apply to the specified structure (numbered from 1!); otherwise apply to all loaded structures.
220
- * Remove any previously added coloring and extra representations, unless `keepColors` and/or `keepRepresentations` is set. */
222
+ * Remove any previously added coloring, opacity, and/or extra representations, unless `keepColors`, `keepOpacity`, and/or `keepRepresentations` is set. */
221
223
  select: (params) => tslib_1.__awaiter(this, void 0, void 0, function* () {
222
224
  var _a, _b, _c, _d;
223
225
  const structureNumberOrId = (_a = params.structureId) !== null && _a !== void 0 ? _a : params.structureNumber;
224
- yield this.visual.clearSelection(structureNumberOrId, { keepColors: params.keepColors, keepRepresentations: params.keepRepresentations });
226
+ yield this.visual.clearSelection(structureNumberOrId, { keepColors: params.keepColors, keepOpacity: params.keepOpacity, keepRepresentations: params.keepRepresentations });
225
227
  // Structure list to apply selection
226
228
  const structures = this.getStructures(structureNumberOrId);
227
229
  // Filter selection items that apply added representations
@@ -260,22 +262,52 @@ class PDBeMolstarPlugin {
260
262
  }
261
263
  }
262
264
  yield (0, helpers_1.applyOverpaint)(this.plugin, struct.structureRef, overpaintLayers);
265
+ // Apply opacity to the main representation
266
+ const transparencyLayers = selections
267
+ .filter(s => s.param.opacity !== undefined)
268
+ .map(s => ({
269
+ bundle: s.bundle,
270
+ value: 1 - s.param.opacity,
271
+ }));
272
+ if (params.nonSelectedOpacity !== undefined) {
273
+ const wholeStructBundle = this.getBundle([{}], struct.number);
274
+ if (wholeStructBundle) {
275
+ transparencyLayers.unshift({
276
+ bundle: wholeStructBundle,
277
+ value: 1 - params.nonSelectedOpacity,
278
+ });
279
+ }
280
+ }
281
+ yield (0, helpers_1.applyTransparency)(this.plugin, struct.structureRef, transparencyLayers);
263
282
  // Add extra representations
264
283
  for (const repr in addedReprParams) {
265
284
  const bundle = this.getBundle(addedReprParams[repr], struct.number);
266
285
  if (!bundle)
267
286
  continue;
268
- const overpaintLayers = selections.filter(s => s.param.representationColor).map(s => ({
287
+ const update = this.plugin.build();
288
+ const addedRepr = update.to(struct.structureRef.cell)
289
+ .apply(model_1.StructureComponent, { type: { name: 'bundle', params: bundle }, label: repr }, { tags: helpers_1.Tags.AddedComponent })
290
+ .apply(representation_1.StructureRepresentation3D, (0, structure_representation_params_1.createStructureRepresentationParams)(this.plugin, (_d = struct.structureRef.cell.obj) === null || _d === void 0 ? void 0 : _d.data, { type: repr }));
291
+ const overpaintLayers = selections
292
+ .filter(s => s.param.representationColor)
293
+ .map(s => ({
269
294
  bundle: s.bundle,
270
295
  color: (0, helpers_1.normalizeColor)(s.param.representationColor),
271
296
  clear: false,
272
297
  }));
273
- yield this.plugin.build()
274
- .to(struct.structureRef.cell)
275
- .apply(model_1.StructureComponent, { type: { name: 'bundle', params: bundle }, label: repr }, { tags: helpers_1.Tags.AddedComponent })
276
- .apply(representation_1.StructureRepresentation3D, (0, structure_representation_params_1.createStructureRepresentationParams)(this.plugin, (_d = struct.structureRef.cell.obj) === null || _d === void 0 ? void 0 : _d.data, { type: repr }))
277
- .apply(transforms_1.StateTransforms.Representation.OverpaintStructureRepresentation3DFromBundle, { layers: overpaintLayers }, { tags: helpers_1.Tags.Overpaint })
278
- .commit();
298
+ if (overpaintLayers.length > 0) {
299
+ addedRepr.apply(transforms_1.StateTransforms.Representation.OverpaintStructureRepresentation3DFromBundle, { layers: overpaintLayers }, { tags: helpers_1.Tags.Overpaint });
300
+ }
301
+ const transparencyLayers = selections
302
+ .filter(s => s.param.representationOpacity !== undefined)
303
+ .map(s => ({
304
+ bundle: s.bundle,
305
+ value: 1 - s.param.representationOpacity,
306
+ }));
307
+ if (transparencyLayers.length > 0) {
308
+ addedRepr.apply(transforms_1.StateTransforms.Representation.TransparencyStructureRepresentation3DFromBundle, { layers: transparencyLayers }, { tags: helpers_1.Tags.Transparency });
309
+ }
310
+ yield update.commit();
279
311
  // Track that reprs have been added (for later clearSelection)
280
312
  this.addedReprs[struct.number] = true;
281
313
  }
@@ -288,7 +320,7 @@ class PDBeMolstarPlugin {
288
320
  /** Remove any coloring and extra representations previously added by the `select` method.
289
321
  * `structureNumberOrId` is either index (numbered from 1!) or the ID that was provided when loading the structure;
290
322
  * if not provided, will apply to all loaded structures.
291
- * If `keepColors`, current residue coloring is preserved. If `keepRepresentations`, current added representations are preserved. */
323
+ * If `keepColors`, current residue coloring is preserved. If `keepOpacity`, current residue opacity is preserved. If `keepRepresentations`, current added representations are preserved. */
292
324
  clearSelection: (structureNumberOrId, options) => tslib_1.__awaiter(this, void 0, void 0, function* () {
293
325
  // Structure list to apply to
294
326
  const structures = this.getStructures(structureNumberOrId);
@@ -298,6 +330,10 @@ class PDBeMolstarPlugin {
298
330
  const componentsToClear = struct.structureRef.components.filter(c => { var _a; return !((_a = c.cell.transform.tags) === null || _a === void 0 ? void 0 : _a.includes(helpers_1.Tags.AddedComponent)); });
299
331
  yield (0, structure_overpaint_1.clearStructureOverpaint)(this.plugin, componentsToClear);
300
332
  }
333
+ if (!(options === null || options === void 0 ? void 0 : options.keepOpacity)) {
334
+ const componentsToClear = struct.structureRef.components.filter(c => { var _a; return !((_a = c.cell.transform.tags) === null || _a === void 0 ? void 0 : _a.includes(helpers_1.Tags.AddedComponent)); });
335
+ yield (0, structure_transparency_1.clearStructureTransparency)(this.plugin, componentsToClear);
336
+ }
301
337
  // Remove added reprs
302
338
  if (!(options === null || options === void 0 ? void 0 : options.keepRepresentations)) {
303
339
  if (this.addedReprs[struct.number]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdbe-molstar",
3
- "version": "3.10.0",
3
+ "version": "3.11.0",
4
4
  "description": "Molstar implementation for PDBe",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "repository": {
28
28
  "type": "git",
29
- "url": "git+https://github.com/PDBeurope/pdbe-molstar.git"
29
+ "url": "git+https://github.com/molstar/pdbe-molstar.git"
30
30
  },
31
31
  "keywords": [
32
32
  "Molstar",
@@ -41,9 +41,9 @@
41
41
  ],
42
42
  "license": "Apache-2.0",
43
43
  "bugs": {
44
- "url": "https://github.com/PDBeurope/pdbe-molstar/issues"
44
+ "url": "https://github.com/molstar/pdbe-molstar/issues"
45
45
  },
46
- "homepage": "https://github.com/PDBeurope/pdbe-molstar#readme",
46
+ "homepage": "https://github.com/molstar/pdbe-molstar#readme",
47
47
  "devDependencies": {
48
48
  "@babel/core": "^7.17.10",
49
49
  "@babel/plugin-transform-runtime": "^7.17.10",
@@ -80,7 +80,7 @@
80
80
  "d3-scale": "^4.0.2",
81
81
  "d3-selection": "^3.0.0",
82
82
  "lit": "^3.1.1",
83
- "molstar": "5.6.1",
83
+ "molstar": "5.7.0",
84
84
  "path-browserify": "^1.0.1",
85
85
  "stream-browserify": "^3.0.0",
86
86
  "vm-browserify": "^1.1.2"