jbrowse-plugin-protein3d 1.17.0 → 1.19.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.
Files changed (67) hide show
  1. package/dist/LaunchProteinViewExtensionPoint/normalizeLaunch.js +2 -0
  2. package/dist/ProteinView/loadStructureData.js +37 -3
  3. package/dist/ProteinView/model.js +57 -2
  4. package/dist/ProteinView/molstarExports.js +1 -0
  5. package/dist/ProteinView/sessionHighlights.js +77 -6
  6. package/dist/ProteinView/structureLoader.js +15 -1
  7. package/dist/ProteinView/structureModel.js +55 -0
  8. package/dist/ProteinView/structurePipeline.js +19 -4
  9. package/dist/chunks/{LaunchProteinViewDialog-A73NNW5K.js → LaunchProteinViewDialog-HRFTOC5J.js} +2 -2
  10. package/dist/chunks/{ProteinView-JRTWVFRV.js → ProteinView-LRXHYDUX.js} +2 -2
  11. package/dist/chunks/{chunk-R64WXKZQ.js → chunk-2WVGTHER.js} +1 -1
  12. package/dist/chunks/chunk-2WVGTHER.js.map +7 -0
  13. package/dist/chunks/chunk-5GU3CILX.js +2 -0
  14. package/dist/chunks/chunk-BODQWG2Y.js +2 -0
  15. package/dist/chunks/chunk-BODQWG2Y.js.map +7 -0
  16. package/dist/chunks/{chunk-DIM277D5.js → chunk-QLQJD3V3.js} +2 -2
  17. package/dist/chunks/chunk-VYZTOKY4.js +2 -0
  18. package/dist/chunks/chunk-VYZTOKY4.js.map +7 -0
  19. package/dist/chunks/{launchAnnotationView-VEXOWETU.js → launchAnnotationView-GMDHI3BV.js} +2 -2
  20. package/dist/chunks/{launchProteinView-MCB653LS.js → launchProteinView-JJACBMFY.js} +2 -2
  21. package/dist/chunks/{launchViewUtils-IQVRMEU6.js → launchViewUtils-2D7BDHQX.js} +2 -2
  22. package/dist/chunks/model-5Z2JAB7P.js +2 -0
  23. package/dist/chunks/model-5Z2JAB7P.js.map +7 -0
  24. package/dist/chunks/{molstarExports-PDICWFG7.js → molstarExports-LMHXWTUT.js} +18 -18
  25. package/dist/jbrowse-plugin-protein3d.esm.js +1 -1
  26. package/dist/jbrowse-plugin-protein3d.esm.js.map +1 -1
  27. package/dist/test_data/gene.js +2 -2
  28. package/dist/test_data/molstarPlugin.js +5 -1
  29. package/dist/test_data/molstarStructure.js +29 -2
  30. package/dist/version.js +1 -1
  31. package/package.json +1 -1
  32. package/src/LaunchProteinViewExtensionPoint/normalizeLaunch.ts +2 -0
  33. package/src/ProteinView/loadStructureData.ts +62 -5
  34. package/src/ProteinView/model.test.ts +36 -0
  35. package/src/ProteinView/model.ts +64 -4
  36. package/src/ProteinView/molstarExports.ts +1 -0
  37. package/src/ProteinView/proteinViewSpec.ts +3 -0
  38. package/src/ProteinView/sessionHighlights.test.ts +11 -2
  39. package/src/ProteinView/sessionHighlights.ts +110 -6
  40. package/src/ProteinView/structureLoader.test.ts +63 -0
  41. package/src/ProteinView/structureLoader.ts +21 -1
  42. package/src/ProteinView/structureModel.test.ts +43 -0
  43. package/src/ProteinView/structureModel.ts +60 -1
  44. package/src/ProteinView/structurePipeline.test.ts +89 -1
  45. package/src/ProteinView/structurePipeline.ts +33 -2
  46. package/src/__snapshots__/mappings.test.ts.snap +0 -451
  47. package/src/mappings.test.ts +13 -21
  48. package/src/test_data/gene.ts +2 -2
  49. package/src/test_data/molstarPlugin.ts +7 -3
  50. package/src/test_data/molstarStructure.ts +47 -2
  51. package/src/version.ts +1 -1
  52. package/dist/chunks/chunk-5K2DARPA.js +0 -2
  53. package/dist/chunks/chunk-5K2DARPA.js.map +0 -7
  54. package/dist/chunks/chunk-NOFPQXHZ.js +0 -2
  55. package/dist/chunks/chunk-NOFPQXHZ.js.map +0 -7
  56. package/dist/chunks/chunk-R64WXKZQ.js.map +0 -7
  57. package/dist/chunks/chunk-UTDQGJCS.js +0 -2
  58. package/dist/chunks/model-C3TFTHNF.js +0 -2
  59. package/dist/chunks/model-C3TFTHNF.js.map +0 -7
  60. /package/dist/chunks/{LaunchProteinViewDialog-A73NNW5K.js.map → LaunchProteinViewDialog-HRFTOC5J.js.map} +0 -0
  61. /package/dist/chunks/{ProteinView-JRTWVFRV.js.map → ProteinView-LRXHYDUX.js.map} +0 -0
  62. /package/dist/chunks/{chunk-UTDQGJCS.js.map → chunk-5GU3CILX.js.map} +0 -0
  63. /package/dist/chunks/{chunk-DIM277D5.js.map → chunk-QLQJD3V3.js.map} +0 -0
  64. /package/dist/chunks/{launchAnnotationView-VEXOWETU.js.map → launchAnnotationView-GMDHI3BV.js.map} +0 -0
  65. /package/dist/chunks/{launchProteinView-MCB653LS.js.map → launchProteinView-JJACBMFY.js.map} +0 -0
  66. /package/dist/chunks/{launchViewUtils-IQVRMEU6.js.map → launchViewUtils-2D7BDHQX.js.map} +0 -0
  67. /package/dist/chunks/{molstarExports-PDICWFG7.js.map → molstarExports-LMHXWTUT.js.map} +0 -0
@@ -11,6 +11,7 @@ const STRUCTURE_KEY_ROLES = {
11
11
  pairwiseAlignment: 'setting',
12
12
  alignmentImported: 'setting',
13
13
  hidden: 'setting',
14
+ assembly: 'setting',
14
15
  feature: 'launchWide',
15
16
  userProvidedTranscriptSequence: 'launchWide',
16
17
  connectedViewId: 'launchWide',
@@ -119,6 +120,7 @@ function readStructure(fields, at, warnings) {
119
120
  pairwiseAlignment: read('pairwiseAlignment', isPairwiseAlignment, '{ consensus, alns: [{ id, seq }, { id, seq }] }'),
120
121
  alignmentImported: read('alignmentImported', isBoolean, 'true or false'),
121
122
  hidden: read('hidden', isBoolean, 'true or false'),
123
+ assembly: read('assembly', isString, 'a string'),
122
124
  feature: read('feature', isFeature, 'a feature object'),
123
125
  userProvidedTranscriptSequence: read('userProvidedTranscriptSequence', isString, 'a string'),
124
126
  connectedViewId: read('connectedViewId', isString, 'a string'),
@@ -30,6 +30,37 @@ function experimentalMethods(source, molstar) {
30
30
  ...(original ? pdbExperimentalMethods(original, molstar) : []),
31
31
  ];
32
32
  }
33
+ function oligomericDetails(model, { MmcifFormat }) {
34
+ const source = model.sourceData;
35
+ if (!MmcifFormat.is(source)) {
36
+ return new Map();
37
+ }
38
+ const { id, oligomeric_details, _rowCount } = source.data.db.pdbx_struct_assembly;
39
+ const details = new Map();
40
+ for (let i = 0; i < _rowCount; i++) {
41
+ const value = oligomeric_details.value(i);
42
+ if (value) {
43
+ details.set(id.value(i), value);
44
+ }
45
+ }
46
+ return details;
47
+ }
48
+ function structureAssemblies(model, molstar) {
49
+ const details = oligomericDetails(model, molstar);
50
+ const chains = new Set(Array.from(model.atomicHierarchy.chains.label_asym_id.toArray()));
51
+ return (molstar.ModelSymmetry.Provider.get(model)?.assemblies ?? []).map(({ id, operatorGroups }) => {
52
+ const [group, ...rest] = operatorGroups;
53
+ const asymIds = new Set(group?.asymIds ?? chains);
54
+ return {
55
+ id,
56
+ oligomericDetails: details.get(id),
57
+ wholeModel: rest.length === 0 &&
58
+ group?.operators.length === 1 &&
59
+ group.operators[0].isIdentity &&
60
+ [...chains].every(c => asymIds.has(c)),
61
+ };
62
+ });
63
+ }
33
64
  /**
34
65
  * Loads a structure (from inline data or a URL) into the given Molstar plugin
35
66
  * and pulls out its per-chain sequences and per-residue confidence. Pure with
@@ -37,15 +68,18 @@ function experimentalMethods(source, molstar) {
37
68
  * callers own the decision of whether/where to store the result.
38
69
  */
39
70
  export async function loadStructureData({ structure, plugin, }) {
40
- const { data, url } = structure;
41
- const { model, structures: molstarStructures, modelIds, } = await loadStructure({ plugin, data: data || undefined, url });
71
+ const { data, url, assembly } = structure;
72
+ const { model, structures: molstarStructures, modelIds, } = await loadStructure({ plugin, data: data || undefined, url, assembly });
73
+ const molstar = await loadMolstar();
42
74
  // An experimental entry's B-factors are not confidence: read as pLDDT they
43
75
  // invert, drawing a well-ordered residue as "very low".
44
- const experimental = experimentalMethods(model?.obj?.data.sourceData, await loadMolstar()).some(m => m !== 'THEORETICAL MODEL');
76
+ const experimental = experimentalMethods(model?.obj?.data.sourceData, molstar).some(m => m !== 'THEORETICAL MODEL');
45
77
  return {
46
78
  entities: model ? extractEntities(model) : undefined,
47
79
  confidence: model && !experimental ? extractPerResidueConfidence(model) : undefined,
48
80
  molstarStructures,
49
81
  modelIds,
82
+ assemblies: model?.obj ? structureAssemblies(model.obj.data, molstar) : [],
83
+ assembly,
50
84
  };
51
85
  }
@@ -15,7 +15,7 @@ import { checkedColor, colorOfScheme } from './proteinColor';
15
15
  import { defaultDisplayName } from './proteinViewSpec';
16
16
  import { removeMolstarStructure } from './removeStructure';
17
17
  import { reportPluginFailure } from './reportPluginFailure';
18
- import { syncSessionHighlightMarks } from './sessionHighlights';
18
+ import { fitLabelDepths, syncSessionHighlightMarks } from './sessionHighlights';
19
19
  import { showLoading } from './showLoading';
20
20
  import { readStoredSettings, storeSetting, withStoredSettings, } from './storedSettings';
21
21
  import { makeStructureLoader } from './structureLoader';
@@ -62,6 +62,35 @@ const BEHAVIOR_SETTINGS = [
62
62
  ['showHighlight', 'Highlight aligned residues'],
63
63
  ['zoomToBaseLevel', 'Zoom to base level on click'],
64
64
  ];
65
+ function assemblyItems(structure) {
66
+ return structure.assemblyChoices.map(({ value, label, checked }) => ({
67
+ label,
68
+ type: 'radio',
69
+ checked,
70
+ onClick: () => {
71
+ structure.setAssembly(value);
72
+ },
73
+ }));
74
+ }
75
+ // A structure with one way to build it offers no choice; with several
76
+ // structures open, each choice sits under its structure's name.
77
+ function assemblyMenu(structures) {
78
+ const choosable = structures.filter(s => s.assemblyChoices.length > 1);
79
+ const [only] = choosable;
80
+ return only === undefined
81
+ ? []
82
+ : [
83
+ {
84
+ label: 'Assembly',
85
+ subMenu: structures.length === 1
86
+ ? assemblyItems(only)
87
+ : choosable.map(s => ({
88
+ label: s.label,
89
+ subMenu: assemblyItems(s),
90
+ })),
91
+ },
92
+ ];
93
+ }
65
94
  /**
66
95
  * #stateModel Protein3dViewPlugin
67
96
  * extends
@@ -346,9 +375,34 @@ function stateModelFactory() {
346
375
  }))
347
376
  : []);
348
377
  if (plugin && structures.length > 0) {
349
- syncSessionHighlightMarks({ plugin, structures }).catch(reportPluginFailure(self, plugin));
378
+ syncSessionHighlightMarks({ plugin, structures })
379
+ .then(() => fitLabelDepths(plugin))
380
+ .catch(reportPluginFailure(self, plugin));
350
381
  }
351
382
  }));
383
+ // A label's depth follows the camera, once it settles
384
+ let stopFollowingCamera;
385
+ addDisposer(self, () => stopFollowingCamera?.());
386
+ addDisposer(self, autorun(() => {
387
+ stopFollowingCamera?.();
388
+ stopFollowingCamera = undefined;
389
+ const plugin = self.molstarPluginContext;
390
+ const camera = plugin?.canvas3d?.camera;
391
+ if (!plugin || !camera) {
392
+ return;
393
+ }
394
+ let timer;
395
+ const subscription = camera.stateChanged.subscribe(() => {
396
+ clearTimeout(timer);
397
+ timer = setTimeout(() => {
398
+ fitLabelDepths(plugin).catch(reportPluginFailure(self, plugin));
399
+ }, 200);
400
+ });
401
+ stopFollowingCamera = () => {
402
+ clearTimeout(timer);
403
+ subscription.unsubscribe();
404
+ };
405
+ }));
352
406
  addDisposer(self, autorun(() => {
353
407
  const plugin = self.molstarPluginContext;
354
408
  for (const s of self.structures) {
@@ -522,6 +576,7 @@ function stateModelFactory() {
522
576
  },
523
577
  ]
524
578
  : []),
579
+ ...assemblyMenu(self.structures),
525
580
  {
526
581
  label: 'Clear selection',
527
582
  onClick: () => {
@@ -6,6 +6,7 @@ export { ProteinBackboneAtoms } from 'molstar/lib/mol-model/structure/model/type
6
6
  export { tmAlign } from 'molstar/lib/mol-model/structure/structure/util/tm-align';
7
7
  export { MmcifFormat } from 'molstar/lib/mol-model-formats/structure/mmcif';
8
8
  export { PdbFormat } from 'molstar/lib/mol-model-formats/structure/pdb';
9
+ export { ModelSymmetry } from 'molstar/lib/mol-model-formats/structure/property/symmetry';
9
10
  export { setSubtreeVisibility } from 'molstar/lib/mol-plugin/behavior/static/state';
10
11
  export { PluginCommands } from 'molstar/lib/mol-plugin/commands';
11
12
  export { PluginConfig } from 'molstar/lib/mol-plugin/config';
@@ -21,6 +21,15 @@ export const LABEL_CORNERS = [
21
21
  'top-left',
22
22
  'bottom-right',
23
23
  ];
24
+ /**
25
+ * How far a label moves toward the camera: the most that keeps it inside a
26
+ * sphere of `radius`, for a residue `depth` in front of its centre. Given the
27
+ * residue's distance from the centre in place of its depth, it holds from
28
+ * any side
29
+ */
30
+ export function labelOffsetZ(radius, depth) {
31
+ return Math.max(0, radius - depth);
32
+ }
24
33
  /**
25
34
  * Label text in Å, in proportion to the structure, so a label reads at about
26
35
  * one size whether the structure is one domain or a complex on DNA
@@ -86,6 +95,28 @@ export async function syncSessionHighlightMarks({ plugin, structures, }) {
86
95
  }
87
96
  return undefined;
88
97
  };
98
+ // how far a residue's atoms on `chain` sit from the structure's centre, on
99
+ // average
100
+ const distanceFromCentre = (structure, chain, labelSeqIds) => {
101
+ const { center } = structure.boundary.sphere;
102
+ const l = StructureElement.Location.create(structure);
103
+ const p = [0, 0, 0];
104
+ let sum = 0;
105
+ let n = 0;
106
+ for (const unit of structure.units) {
107
+ l.unit = unit;
108
+ for (const element of Array.from(unit.elements)) {
109
+ l.element = element;
110
+ if (SP.chain.label_asym_id(l) === chain &&
111
+ labelSeqIds.has(SP.residue.label_seq_id(l))) {
112
+ unit.conformation.position(element, p);
113
+ sum += Math.hypot(p[0] - center[0], p[1] - center[1], p[2] - center[2]);
114
+ n++;
115
+ }
116
+ }
117
+ }
118
+ return n > 0 ? sum / n : 0;
119
+ };
89
120
  const update = plugin.state.data.build();
90
121
  const existing = plugin.state.data.select(StateSelection.Generators.root.subtree().withTag(SESSION_HIGHLIGHTS_TAG));
91
122
  for (const cell of existing) {
@@ -152,15 +183,55 @@ export async function syncSessionHighlightMarks({ plugin, structures, }) {
152
183
  background: true,
153
184
  backgroundColor: Color(0xffffff),
154
185
  backgroundOpacity: 0.85,
155
- // toward the camera by the structure's radius, past
156
- // everything the structure draws: Mol* depth-tests text, so
157
- // a label behind a helix or a DNA strand would hide. The
158
- // parameter's 10 Å bound is the UI's; the shader takes any
159
- // distance, and the camera sits outside the bounding sphere
160
- offsetZ: radius,
186
+ // safe from any side until fitLabelDepths knows the camera
187
+ offsetZ: labelOffsetZ(radius, distanceFromCentre(molstarStructure, chain, new Set(labelSeqIds))),
161
188
  }, { tags: [SESSION_HIGHLIGHTS_TAG] });
162
189
  }
163
190
  }
164
191
  }
165
192
  await update.commit();
166
193
  }
194
+ /**
195
+ * Move each session-highlight label toward the camera as far as the near
196
+ * clipping plane allows. Mol* depth-tests text, so a label behind a helix or
197
+ * a DNA strand would hide, and Mol* puts the near plane at the front of the
198
+ * camera's radius, so a label pushed past it disappears. The distance depends
199
+ * on which side the camera faces, so the view calls this when the camera
200
+ * settles. The parameter's 10 Å bound is the UI's; the shader takes any
201
+ * distance.
202
+ */
203
+ export async function fitLabelDepths(plugin) {
204
+ const camera = plugin.canvas3d?.camera;
205
+ if (!camera) {
206
+ return;
207
+ }
208
+ const { StateSelection, StateTransforms, StructureElement } = await loadMolstar();
209
+ const labels = plugin.state.data.select(StateSelection.Generators.root
210
+ .subtree()
211
+ .withTag(SESSION_HIGHLIGHTS_TAG)
212
+ .withTransformer(StateTransforms.Representation.StructureSelectionsLabel3D));
213
+ const { position, target, radius } = camera.state;
214
+ const toCamera = [0, 1, 2].map(k => position[k] - target[k]);
215
+ const length = Math.hypot(...toCamera) || 1;
216
+ const update = plugin.state.data.build();
217
+ let changed = false;
218
+ for (const cell of labels) {
219
+ const parent = plugin.state.data.cells.get(plugin.state.data.tree.transforms.get(cell.transform.ref).parent);
220
+ const selections = parent?.obj?.data;
221
+ const loci = selections?.[0]?.loci;
222
+ const params = cell.transform.params;
223
+ if (!loci || !params) {
224
+ continue;
225
+ }
226
+ const { center } = StructureElement.Loci.getBoundary(loci).sphere;
227
+ const depth = [0, 1, 2].reduce((sum, k) => sum + (center[k] - target[k]) * toCamera[k], 0) / length;
228
+ const offsetZ = labelOffsetZ(radius - params.textSize, depth);
229
+ if (Math.abs(offsetZ - params.offsetZ) > 1) {
230
+ update.to(cell).update({ ...params, offsetZ });
231
+ changed = true;
232
+ }
233
+ }
234
+ if (changed) {
235
+ await update.commit();
236
+ }
237
+ }
@@ -19,7 +19,10 @@ import { removeMolstarStructure } from './removeStructure';
19
19
  * awaiting has its result discarded rather than written into a torn-down
20
20
  * plugin;
21
21
  * - if the plugin was merely swapped (e.g. a view remount), the structure is
22
- * reloaded into the current plugin so it isn't left stranded unloaded.
22
+ * reloaded into the current plugin so it isn't left stranded unloaded;
23
+ * - a loaded structure whose `assembly` no longer matches the one it was
24
+ * built with leaves Mol* and loads again, so every reaction keyed on its
25
+ * Mol* structures reaches the new chains.
23
26
  */
24
27
  export function makeStructureLoader(host, fetchModels = fetchAlphaFoldModels) {
25
28
  const loadingIn = new Map();
@@ -134,10 +137,21 @@ export function makeStructureLoader(host, fetchModels = fetchAlphaFoldModels) {
134
137
  }
135
138
  });
136
139
  }
140
+ function unloadOtherAssembly(structure, plugin) {
141
+ const { molstarStructure } = structure;
142
+ structure.setLoadedToMolstar(false);
143
+ removeMolstarStructure({ plugin, molstarStructure }).catch((e) => {
144
+ console.error(e);
145
+ });
146
+ }
137
147
  return function loadPendingStructures() {
138
148
  const { structures, molstarPluginContext } = host;
139
149
  if (molstarPluginContext) {
140
150
  for (const structure of structures) {
151
+ if (structure.loadedToMolstar &&
152
+ structure.assembly !== structure.loadedAssembly) {
153
+ unloadOtherAssembly(structure, molstarPluginContext);
154
+ }
141
155
  if (!structure.loadedToMolstar &&
142
156
  loadingIn.get(structure) !== molstarPluginContext &&
143
157
  failedIn.get(structure) !== molstarPluginContext) {
@@ -17,6 +17,7 @@ import { RESIDUE_COLORS } from './residueColors';
17
17
  import { positionRangeRuns, rangeList, residueRuns, transcriptRuns, } from './residueRanges';
18
18
  import { kyteDoolittleScores, mapResidueValuesToColumns } from './residueTracks';
19
19
  import { sessionHighlightResidues } from './sessionHighlights';
20
+ import { DEPOSITED_MODEL } from './structurePipeline';
20
21
  import { structureUniProt } from './structureUniProt';
21
22
  import { assemblyNaming, errorMessage } from './util';
22
23
  import { makeVariantEffectLoader } from './variantEffectLoader';
@@ -120,6 +121,14 @@ const Structure = types
120
121
  * carry on, so showing it again needs no reload.
121
122
  */
122
123
  hidden: types.optional(types.boolean, false),
124
+ /**
125
+ * #property
126
+ * What Mol* builds from the file: absent for the entry's first biological
127
+ * assembly (Mol*'s default), an assembly id such as `'2'` for another, or
128
+ * `'deposited'` for the deposited model, every chain the file holds. An
129
+ * NMR ensemble builds each model whole whatever this says.
130
+ */
131
+ assembly: types.maybe(types.string),
123
132
  })
124
133
  .volatile(() => ({
125
134
  /**
@@ -213,6 +222,17 @@ const Structure = types
213
222
  * included; see interactionPosition.
214
223
  */
215
224
  molstarModelIds: new Array(),
225
+ /**
226
+ * #volatile
227
+ * The biological assemblies the loaded entry lists
228
+ */
229
+ assemblies: new Array(),
230
+ /**
231
+ * #volatile
232
+ * The `assembly` the current load was built with; the loader rebuilds the
233
+ * structure when it differs from `assembly`.
234
+ */
235
+ loadedAssembly: undefined,
216
236
  /**
217
237
  * #volatile
218
238
  * Range of alignment positions to highlight (e.g., when hovering a protein feature)
@@ -291,6 +311,8 @@ const Structure = types
291
311
  self.structureConfidence = data.confidence;
292
312
  self.molstarStructures = data.molstarStructures ?? [];
293
313
  self.molstarModelIds = data.modelIds ?? new Array();
314
+ self.assemblies = data.assemblies ?? [];
315
+ self.loadedAssembly = data.assembly;
294
316
  },
295
317
  /**
296
318
  * #action
@@ -445,6 +467,15 @@ const Structure = types
445
467
  setHidden(hidden) {
446
468
  self.hidden = hidden;
447
469
  },
470
+ /**
471
+ * #action
472
+ * Rebuilds the structure from another assembly or the deposited model.
473
+ * The default, the first assembly, is stored as absent.
474
+ */
475
+ setAssembly(assembly) {
476
+ const first = self.assemblies[0]?.id ?? DEPOSITED_MODEL;
477
+ self.assembly = assembly === first ? undefined : assembly;
478
+ },
448
479
  /**
449
480
  * #action
450
481
  */
@@ -484,6 +515,30 @@ const Structure = types
484
515
  get mappedStructureSeq() {
485
516
  return this.mappedEntity?.seq;
486
517
  },
518
+ /**
519
+ * #getter
520
+ * What `assembly` may be set to, with the entry's assemblies first and
521
+ * the deposited model last unless an assembly already is it. Empty for an
522
+ * ensemble, which ignores `assembly`.
523
+ */
524
+ get assemblyChoices() {
525
+ const { assemblies, molstarStructures } = self;
526
+ if (molstarStructures.length !== 1) {
527
+ return [];
528
+ }
529
+ const current = self.assembly ?? assemblies[0]?.id ?? DEPOSITED_MODEL;
530
+ const choices = assemblies.map(({ id, oligomericDetails }) => ({
531
+ value: id,
532
+ label: `Assembly ${id}${oligomericDetails ? ` (${oligomericDetails})` : ''}`,
533
+ }));
534
+ if (!assemblies.some(a => a.wholeModel)) {
535
+ choices.push({
536
+ value: DEPOSITED_MODEL,
537
+ label: 'Deposited model (every chain)',
538
+ });
539
+ }
540
+ return choices.map(c => ({ ...c, checked: c.value === current }));
541
+ },
487
542
  /**
488
543
  * #getter
489
544
  * The structure's name in the UI: PDB id, AlphaFold accession, else file
@@ -33,6 +33,16 @@ export async function parseStructureTrajectory({ plugin, data, url, }) {
33
33
  }
34
34
  return trajectory;
35
35
  }
36
+ /** The `assembly` value that builds the deposited model, every chain the file
37
+ * holds, rather than one of the entry's biological assemblies. */
38
+ export const DEPOSITED_MODEL = 'deposited';
39
+ function rootStructure(assembly) {
40
+ return assembly === undefined
41
+ ? undefined
42
+ : assembly === DEPOSITED_MODEL
43
+ ? { name: 'model', params: {} }
44
+ : { name: 'assembly', params: { id: assembly } };
45
+ }
36
46
  // The 'all-models' preset hands back { model, structure } through the default
37
47
  // preset for a single-model trajectory, { models, structures } for an
38
48
  // ensemble, and {} if the trajectory vanished.
@@ -68,9 +78,14 @@ async function removeWater(plugin, structures) {
68
78
  * addresses only the first leaves the other nineteen behind. They come from
69
79
  * the preset rather than `hierarchy.current.structures`, which also holds every
70
80
  * other load's.
81
+ *
82
+ * A single-model file falls through to Mol*'s default preset, which takes the
83
+ * `structure` param: absent, it builds the first assembly. An ensemble builds
84
+ * each model whole and ignores it.
71
85
  */
72
- async function applyStructurePreset(plugin, trajectory, source) {
73
- const preset = await plugin.builders.structure.hierarchy.applyPreset(trajectory, 'all-models', { useDefaultIfSingleModel: true });
86
+ async function applyStructurePreset(plugin, trajectory, source, assembly) {
87
+ const params = { useDefaultIfSingleModel: true, structure: rootStructure(assembly) };
88
+ const preset = await plugin.builders.structure.hierarchy.applyPreset(trajectory, 'all-models', params);
74
89
  const { models, structures } = presetOutput(preset);
75
90
  await removeWater(plugin, structures);
76
91
  const loaded = structures.flatMap(s => (s.obj ? [s.obj.data] : []));
@@ -84,7 +99,7 @@ async function applyStructurePreset(plugin, trajectory, source) {
84
99
  };
85
100
  }
86
101
  /** Load a structure from its text or its url, as the view shows one. */
87
- export async function loadStructure({ plugin, data, url, }) {
102
+ export async function loadStructure({ plugin, data, url, assembly, }) {
88
103
  const trajectory = await parseStructureTrajectory({ plugin, data, url });
89
- return applyStructurePreset(plugin, trajectory, url ?? 'the structure data');
104
+ return applyStructurePreset(plugin, trajectory, url ?? 'the structure data', assembly);
90
105
  }