drugflow-molstar 0.2.0 → 0.2.2

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 (113) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +15 -15
  3. package/build/drugflow-molstar-component-0.2.2.js +25 -0
  4. package/build/drugflow-molstar-light.css +1 -1
  5. package/build/{drugflow-molstar-plugin-0.2.0.js → drugflow-molstar-plugin-0.2.2.js} +2 -2
  6. package/lib/alphafold-transparency.d.ts +6 -6
  7. package/lib/alphafold-transparency.js +153 -153
  8. package/lib/app/molstar/lib/apps/docking-viewer/index.html +37 -0
  9. package/lib/app/molstar/lib/apps/viewer/embedded.html +44 -0
  10. package/lib/app/molstar/lib/apps/viewer/favicon.ico +0 -0
  11. package/lib/app/molstar/lib/apps/viewer/index.html +110 -0
  12. package/lib/app/molstar/lib/examples/alpha-orbitals/index.html +73 -0
  13. package/lib/app/molstar/lib/examples/basic-wrapper/index.html +138 -0
  14. package/lib/app/molstar/lib/examples/lighting/index.html +89 -0
  15. package/lib/app/molstar/lib/examples/proteopedia-wrapper/index.html +237 -0
  16. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/base.scss +33 -0
  17. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/components/controls-base.scss +334 -0
  18. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/components/controls.scss +419 -0
  19. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/components/help.scss +27 -0
  20. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/components/line-graph.scss +68 -0
  21. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/components/log.scss +100 -0
  22. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/components/misc.scss +644 -0
  23. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/components/sequence.scss +126 -0
  24. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/components/slider.scss +166 -0
  25. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/components/tasks.scss +99 -0
  26. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/components/toast.scss +84 -0
  27. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/components/transformer.scss +164 -0
  28. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/components/viewport.scss +128 -0
  29. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/layout/common.scss +72 -0
  30. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/layout/controls-landscape.scss +90 -0
  31. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/layout/controls-outside.scss +99 -0
  32. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/layout/controls-portrait.scss +109 -0
  33. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/layout.scss +41 -0
  34. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/logo.scss +13 -0
  35. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/normalize.scss +210 -0
  36. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/ui.scss +41 -0
  37. package/lib/app/molstar/lib/mol-plugin-ui/skin/base/variables.scss +86 -0
  38. package/lib/app/molstar/lib/mol-plugin-ui/skin/blue.scss +2 -0
  39. package/lib/app/molstar/lib/mol-plugin-ui/skin/colors/blue.scss +24 -0
  40. package/lib/app/molstar/lib/mol-plugin-ui/skin/colors/dark.scss +24 -0
  41. package/lib/app/molstar/lib/mol-plugin-ui/skin/colors/light.scss +30 -0
  42. package/lib/app/molstar/lib/mol-plugin-ui/skin/dark.scss +2 -0
  43. package/lib/app/molstar/lib/mol-plugin-ui/skin/light.scss +2 -0
  44. package/lib/custom-events.d.ts +4 -4
  45. package/lib/custom-events.js +56 -56
  46. package/lib/domain-annotations/behavior.d.ts +5 -5
  47. package/lib/domain-annotations/behavior.js +49 -49
  48. package/lib/domain-annotations/color.d.ts +10 -10
  49. package/lib/domain-annotations/color.js +78 -78
  50. package/lib/domain-annotations/prop.d.ts +35 -35
  51. package/lib/domain-annotations/prop.js +160 -160
  52. package/lib/drugflow-molstar-component-build-0.1.2.js +4268 -0
  53. package/lib/drugflow-molstar-component-build-0.1.2.js.LICENSE.txt +24 -0
  54. package/lib/drugflow-molstar-component-build-0.1.2.js.map +1 -0
  55. package/lib/drugflow-molstar-component-build-0.1.3.js +2 -0
  56. package/lib/drugflow-molstar-component-build-0.1.3.js.LICENSE.txt +24 -0
  57. package/lib/drugflow-molstar-component-build-0.1.4.js +2 -0
  58. package/lib/drugflow-molstar-component-build-0.1.4.js.LICENSE.txt +24 -0
  59. package/lib/drugflow-molstar-component-build-0.1.6.js +2 -0
  60. package/lib/drugflow-molstar-component-build-0.1.6.js.LICENSE.txt +24 -0
  61. package/lib/drugflow-molstar-component-build-0.2.2.js +2 -0
  62. package/lib/drugflow-molstar-component-build-0.2.2.js.LICENSE.txt +24 -0
  63. package/lib/helpers.d.ts +82 -81
  64. package/lib/helpers.js +278 -278
  65. package/lib/index.d.ts +1 -1
  66. package/lib/index.js +1274 -1239
  67. package/lib/labels.d.ts +2 -2
  68. package/lib/labels.js +42 -42
  69. package/lib/loci-details.d.ts +27 -27
  70. package/lib/loci-details.js +128 -128
  71. package/lib/pdbe-molstar-component-build-3.1.2.js +2 -0
  72. package/lib/pdbe-molstar-component-build-3.1.2.js.LICENSE.txt +24 -0
  73. package/lib/sifts-mapping.d.ts +16 -16
  74. package/lib/sifts-mapping.js +83 -83
  75. package/lib/sifts-mappings-behaviour.d.ts +5 -5
  76. package/lib/sifts-mappings-behaviour.js +64 -64
  77. package/lib/spec.d.ts +76 -76
  78. package/lib/spec.js +105 -105
  79. package/lib/subscribe-events.d.ts +1 -1
  80. package/lib/subscribe-events.js +194 -194
  81. package/lib/superposition-export.d.ts +4 -4
  82. package/lib/superposition-export.js +152 -152
  83. package/lib/superposition-focus-representation.d.ts +16 -16
  84. package/lib/superposition-focus-representation.js +153 -153
  85. package/lib/superposition-sifts-mapping.d.ts +22 -22
  86. package/lib/superposition-sifts-mapping.js +159 -159
  87. package/lib/superposition.d.ts +18 -18
  88. package/lib/superposition.js +794 -794
  89. package/lib/ui/alphafold-superposition.d.ts +56 -56
  90. package/lib/ui/alphafold-superposition.js +178 -178
  91. package/lib/ui/alphafold-tranparency.d.ts +22 -22
  92. package/lib/ui/alphafold-tranparency.js +65 -65
  93. package/lib/ui/annotation-controls.d.ts +24 -24
  94. package/lib/ui/annotation-controls.js +166 -166
  95. package/lib/ui/export-superposition.d.ts +6 -6
  96. package/lib/ui/export-superposition.js +71 -71
  97. package/lib/ui/pdbe-left-panel.d.ts +18 -18
  98. package/lib/ui/pdbe-left-panel.js +167 -167
  99. package/lib/ui/pdbe-screenshot-controls.d.ts +20 -20
  100. package/lib/ui/pdbe-screenshot-controls.js +101 -101
  101. package/lib/ui/pdbe-structure-controls.d.ts +17 -17
  102. package/lib/ui/pdbe-structure-controls.js +70 -70
  103. package/lib/ui/pdbe-viewport-controls.d.ts +6 -6
  104. package/lib/ui/pdbe-viewport-controls.js +56 -56
  105. package/lib/ui/segment-tree.d.ts +18 -18
  106. package/lib/ui/segment-tree.js +804 -804
  107. package/lib/ui/superposition-components.d.ts +10 -10
  108. package/lib/ui/superposition-components.js +435 -435
  109. package/lib/ui/superposition-viewport.d.ts +5 -5
  110. package/lib/ui/superposition-viewport.js +23 -23
  111. package/package.json +79 -79
  112. /package/build/{drugflow-molstar-0.2.0.css → drugflow-molstar-0.2.2.css} +0 -0
  113. /package/build/{drugflow-molstar-plugin-0.2.0.js.LICENSE.txt → drugflow-molstar-plugin-0.2.2.js.LICENSE.txt} +0 -0
package/lib/index.js CHANGED
@@ -1,1239 +1,1274 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var spec_1 = require("./spec");
5
- var commands_1 = require("Molstar/mol-plugin/commands");
6
- var mol_state_1 = require("Molstar/mol-state");
7
- var loci_1 = require("Molstar/mol-model/loci");
8
- var rx_event_helper_1 = require("Molstar/mol-util/rx-event-helper");
9
- var helpers_1 = require("./helpers");
10
- var pdbe_structure_controls_1 = require("./ui/pdbe-structure-controls");
11
- var pdbe_viewport_controls_1 = require("./ui/pdbe-viewport-controls");
12
- var mol_state_2 = require("Molstar/mol-state");
13
- var structure_focus_representation_1 = require("Molstar/mol-plugin/behavior/dynamic/selection/structure-focus-representation");
14
- var spec_2 = require("Molstar/mol-plugin/spec");
15
- var transformers_1 = require("Molstar/mol-plugin/behavior/dynamic/volume-streaming/transformers");
16
- var structure_representation_params_1 = require("Molstar/mol-plugin-state/helpers/structure-representation-params");
17
- var subscribe_events_1 = require("./subscribe-events");
18
- var pdbe_left_panel_1 = require("./ui/pdbe-left-panel");
19
- var superposition_1 = require("./superposition");
20
- var custom_events_1 = require("./custom-events");
21
- var assets_1 = require("Molstar/mol-util/assets");
22
- var config_1 = require("Molstar/mol-plugin/config");
23
- var color_1 = require("Molstar/mol-util/color/color");
24
- var component_1 = require("Molstar/mol-plugin-state/manager/structure/component");
25
- var param_definition_1 = require("Molstar/mol-util/param-definition");
26
- var behavior_1 = require("./domain-annotations/behavior");
27
- var pdbe_1 = require("Molstar/extensions/pdbe");
28
- var behavior_2 = require("Molstar/extensions/model-archive/quality-assessment/behavior");
29
- var structure_overpaint_1 = require("Molstar/mol-plugin-state/helpers/structure-overpaint");
30
- var superposition_focus_representation_1 = require("./superposition-focus-representation");
31
- var superposition_viewport_1 = require("./ui/superposition-viewport");
32
- var representation_1 = require("Molstar/mol-plugin/behavior/dynamic/representation");
33
- var camera_1 = require("molstar/lib/mol-plugin/behavior/dynamic/camera");
34
- var mp4_export_1 = require("Molstar/extensions/mp4-export");
35
- var geo_export_1 = require("Molstar/extensions/geo-export");
36
- var element_symbol_1 = require("Molstar/mol-theme/color/element-symbol");
37
- var model_index_1 = require("Molstar/mol-plugin-state/animation/built-in/model-index");
38
- var camera_spin_1 = require("Molstar/mol-plugin-state/animation/built-in/camera-spin");
39
- var state_snapshots_1 = require("Molstar/mol-plugin-state/animation/built-in/state-snapshots");
40
- var state_interpolation_1 = require("Molstar/mol-plugin-state/animation/built-in/state-interpolation");
41
- var spin_structure_1 = require("Molstar/mol-plugin-state/animation/built-in/spin-structure");
42
- var camera_rock_1 = require("Molstar/mol-plugin-state/animation/built-in/camera-rock");
43
- var assembly_unwind_1 = require("Molstar/mol-plugin-state/animation/built-in/assembly-unwind");
44
- var builder_1 = require("molstar/lib/mol-script/language/builder");
45
- var names_1 = require("molstar/lib/mol-util/color/names");
46
- var units_visual_1 = require("molstar/lib/mol-repr/structure/units-visual");
47
- var param_definition_2 = require("molstar/lib/mol-util/param-definition");
48
- var representation_2 = require("molstar/lib/mol-repr/structure/representation");
49
- var structure_selection_query_1 = require("molstar/lib/mol-plugin-state/helpers/structure-selection-query");
50
- var representation_3 = require("molstar/lib/mol-repr/representation");
51
- var box_1 = require("molstar/lib/mol-geo/geometry/mesh/builder/box");
52
- var mesh_builder_1 = require("molstar/lib/mol-geo/geometry/mesh/mesh-builder");
53
- var linear_algebra_1 = require("molstar/lib/mol-math/linear-algebra");
54
- var int_1 = require("molstar/lib/mol-data/int");
55
- var location_iterator_1 = require("molstar/lib/mol-geo/util/location-iterator");
56
- var location_1 = require("molstar/lib/mol-model/location");
57
- var loci_2 = require("molstar/lib/mol-model/loci");
58
- var structure_1 = require("molstar/lib/mol-model/structure");
59
- var mol_task_1 = require("molstar/lib/mol-task");
60
- require('Molstar/mol-plugin-ui/skin/dark.scss');
61
- var PDBeMolstarPlugin = /** @class */ (function () {
62
- function PDBeMolstarPlugin() {
63
- var _this = this;
64
- this._ev = rx_event_helper_1.RxEventHelper.create();
65
- this.events = {
66
- loadComplete: this._ev()
67
- };
68
- this.assemblyRef = '';
69
- this.isHighlightColorUpdated = false;
70
- this.isSelectedColorUpdated = false;
71
- this.get_quick_querys = function (structure, pdb_string) {
72
- var ligand_queries = _this.get_ligand_queries(pdb_string);
73
- var chain_queries = _this.get_chain_queries(structure.data);
74
- var pocket_queries = _this.get_pocket_queries(ligand_queries, 5);
75
- var water = structure_selection_query_1.StructureSelectionQueries.water;
76
- return {
77
- ligands: ligand_queries,
78
- chains: chain_queries,
79
- pockets: pocket_queries,
80
- water: [water]
81
- };
82
- };
83
- this.get_pocket_queries = function (ligand_queries, radius) {
84
- // 同名的ligand_query会被合并
85
- var queries = [];
86
- for (var i = 0; i < ligand_queries.length; i++) {
87
- var label = _this.get_ligand_query_name(ligand_queries[i]);
88
- var core = builder_1.MolScriptBuilder.struct.generator.atomGroups({
89
- 'residue-test': builder_1.MolScriptBuilder.core.set.has([builder_1.MolScriptBuilder.set.apply(builder_1.MolScriptBuilder, [label]), builder_1.MolScriptBuilder.ammp('auth_comp_id')])
90
- });
91
- var surrounding = builder_1.MolScriptBuilder.struct.modifier.union([
92
- builder_1.MolScriptBuilder.struct.modifier.exceptBy({
93
- 0: builder_1.MolScriptBuilder.struct.modifier.includeSurroundings({
94
- 0: core,
95
- radius: radius,
96
- 'as-whole-residues': true
97
- }),
98
- by: core
99
- })
100
- ]);
101
- var ligand_expand_q = (0, structure_selection_query_1.StructureSelectionQuery)('Surrounding Residues (5 \u212B) of ' + label, surrounding, {
102
- description: 'Select residues within 5 \u212B of ' + label,
103
- category: structure_selection_query_1.StructureSelectionCategory.Manipulate,
104
- referencesCurrent: true
105
- });
106
- queries.push({ query: ligand_expand_q, expression: surrounding, label: label });
107
- }
108
- return queries;
109
- };
110
- this.ownResidueQuery = function (chain_name, residue_name_list, residue_id, category, priority) {
111
- if (priority === void 0) {
112
- priority = 0;
113
- }
114
- var description = '[' + residue_name_list[0] + ']|' + chain_name + ':' + residue_name_list[0] + ':' + residue_id;
115
- return (0, structure_selection_query_1.StructureSelectionQuery)(description, builder_1.MolScriptBuilder.struct.modifier.union([
116
- builder_1.MolScriptBuilder.struct.generator.atomGroups({
117
- 'chain-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.ammp('auth_asym_id'), chain_name]),
118
- 'residue-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.ammp('auth_seq_id'), Number(residue_id)])
119
- // 'residue-test-comp': MS.core.set.has([MS.set.apply(MS, residue_name_list), MS.ammp('auth_comp_id')])
120
- })
121
- ]), { category: category, priority: priority, description: description });
122
- };
123
- this.applyVisualParams = function () {
124
- var TagRefs = {
125
- 'structure-component-static-polymer': 'polymer',
126
- 'structure-component-static-ligand': 'het',
127
- 'structure-component-static-branched': 'carbs',
128
- 'structure-component-static-water': 'water',
129
- 'structure-component-static-coarse': 'coarse',
130
- 'non-standard': 'nonStandard'
131
- };
132
- var componentGroups = _this.plugin.managers.structure.hierarchy.currentComponentGroups;
133
- componentGroups.forEach(function (compGrp) {
134
- var _c;
135
- var compGrpIndex = compGrp.length - 1;
136
- var key = compGrp[compGrpIndex].key;
137
- var rm = false;
138
- if (key && _this.initParams.hideStructure) {
139
- var structType = TagRefs[key];
140
- if (structType && ((_c = _this.initParams.hideStructure) === null || _c === void 0 ? void 0 : _c.indexOf(structType)) > -1)
141
- rm = true;
142
- }
143
- if (rm) {
144
- _this.plugin.managers.structure.hierarchy.remove([compGrp[compGrpIndex]]);
145
- }
146
- if (!rm && _this.initParams.visualStyle) {
147
- if (compGrp[compGrpIndex] && compGrp[compGrpIndex].representations) {
148
- compGrp[compGrpIndex].representations.forEach(function (rep) {
149
- var currentParams = (0, structure_representation_params_1.createStructureRepresentationParams)(_this.plugin, void 0, { type: _this.initParams.visualStyle });
150
- _this.plugin.managers.structure.component.updateRepresentations([compGrp[compGrpIndex]], rep, currentParams);
151
- });
152
- }
153
- }
154
- });
155
- };
156
- this.canvas = {
157
- toggleControls: function (isVisible) {
158
- if (typeof isVisible === 'undefined')
159
- isVisible = !_this.plugin.layout.state.showControls;
160
- commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { showControls: isVisible } });
161
- },
162
- toggleExpanded: function (isExpanded) {
163
- if (typeof isExpanded === 'undefined')
164
- isExpanded = !_this.plugin.layout.state.isExpanded;
165
- commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { isExpanded: isExpanded } });
166
- },
167
- setBgColor: function (color) {
168
- if (!color)
169
- return;
170
- _this.canvas.applySettings({ color: color });
171
- },
172
- applySettings: function (settings) {
173
- if (!settings)
174
- return;
175
- var rendererParams = {};
176
- if (settings.color)
177
- rendererParams['backgroundColor'] = color_1.Color.fromRgb(settings.color.r, settings.color.g, settings.color.b);
178
- if (settings.lighting)
179
- rendererParams['style'] = { name: settings.lighting };
180
- var renderer = _this.plugin.canvas3d.props.renderer;
181
- commands_1.PluginCommands.Canvas3D.SetSettings(_this.plugin, { settings: { renderer: tslib_1.__assign(tslib_1.__assign({}, renderer), rendererParams) } });
182
- },
183
- toggleSelect: function (isSelect) {
184
- _this.plugin.selectionMode = !isSelect;
185
- }
186
- };
187
- this.visual = {
188
- highlight: function (params) {
189
- var loci = _this.getLociForParams(params.data, params.structureNumber);
190
- if (loci_1.Loci.isEmpty(loci))
191
- return;
192
- if (params.color) {
193
- _this.visual.setColor({ highlight: params.color });
194
- }
195
- _this.plugin.managers.interactivity.lociHighlights.highlightOnly({ loci: loci });
196
- if (params.focus)
197
- _this.plugin.managers.camera.focusLoci(loci);
198
- },
199
- clearHighlight: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
200
- return tslib_1.__generator(this, function (_c) {
201
- this.plugin.managers.interactivity.lociHighlights.highlightOnly({ loci: loci_1.EmptyLoci });
202
- if (this.isHighlightColorUpdated)
203
- this.visual.reset({ highlightColor: true });
204
- return [2 /*return*/];
205
- });
206
- }); },
207
- hideSelect: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
208
- var sel, components, _i, sel_1, s;
209
- return tslib_1.__generator(this, function (_c) {
210
- sel = this.plugin.managers.structure.hierarchy.getStructuresWithSelection();
211
- components = [];
212
- for (_i = 0, sel_1 = sel; _i < sel_1.length; _i++) {
213
- s = sel_1[_i];
214
- components.push.apply(components, s.components);
215
- }
216
- if (components.length === 0)
217
- return [2 /*return*/];
218
- this.plugin.managers.structure.component.modifyByCurrentSelection(components, 'subtract');
219
- return [2 /*return*/];
220
- });
221
- }); },
222
- showSelect: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
223
- var sel, components, _i, sel_1, s;
224
- return tslib_1.__generator(this, function (_c) {
225
- sel = this.plugin.managers.structure.hierarchy.getStructuresWithSelection();
226
- components = [];
227
- for (_i = 0, sel_1 = sel; _i < sel_1.length; _i++) {
228
- s = sel_1[_i];
229
- components.push.apply(components, s.components);
230
- }
231
- if (components.length === 0)
232
- return [2 /*return*/];
233
- this.plugin.managers.structure.component.modifyByCurrentSelection(components, 'union');
234
- console.log(components);
235
- return [2 /*return*/];
236
- });
237
- }); },
238
- changeProps: function (val) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
239
- return tslib_1.__generator(this, function (_c) {
240
- //todo 切换选中粒度
241
- this.plugin.managers.interactivity.setProps({ granularity: val });
242
- return [2 /*return*/];
243
- });
244
- }); },
245
- select: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
246
- var _c, _d, param, loci, repr, defaultParams, defaultValues, values, structures, updatedStructureData, comps, lastCompsIndex, recentRepComp, uniformColor, e_1_1;
247
- var e_1, _e;
248
- return tslib_1.__generator(this, function (_f) {
249
- switch (_f.label) {
250
- case 0:
251
- _f.trys.push([0, 7, 8, 13]);
252
- _c = tslib_1.__asyncValues(params.data);
253
- _f.label = 1;
254
- case 1: return [4 /*yield*/, _c.next()];
255
- case 2:
256
- if (!(_d = _f.sent(), !_d.done)) return [3 /*break*/, 6];
257
- param = _d.value;
258
- loci = this.getLociForParams([param], params.structureNumber);
259
- if (loci_1.Loci.isEmpty(loci))
260
- return [2 /*return*/];
261
- // set default selection color to minimise change display
262
- // this.visual.setColor({select: param.color ? param.color : { r:255, g:112, b:3}});
263
- // apply selection
264
- this.plugin.managers.interactivity.lociSelects.selectOnly({ loci: loci });
265
- if (!(param.sideChain || param.representation)) return [3 /*break*/, 4];
266
- repr = 'ball-and-stick';
267
- if (param.representation)
268
- repr = param.representation;
269
- defaultParams = component_1.StructureComponentManager.getAddParams(this.plugin, { allowNone: false, hideSelection: true, checkExisting: true });
270
- defaultValues = param_definition_1.ParamDefinition.getDefaultValues(defaultParams);
271
- defaultValues.options = { label: 'selection-by-script', checkExisting: params.structureNumber ? false : true };
272
- values = tslib_1.__assign(tslib_1.__assign({}, defaultValues), { representation: repr });
273
- structures = this.plugin.managers.structure.hierarchy.getStructuresWithSelection();
274
- return [4 /*yield*/, this.plugin.managers.structure.component.add(values, structures)];
275
- case 3:
276
- _f.sent();
277
- // Apply uniform theme
278
- if (param.representationColor) {
279
- updatedStructureData = this.plugin.managers.structure.hierarchy.current.structures;
280
- if (params.structureNumber) {
281
- updatedStructureData = [this.plugin.managers.structure.hierarchy.current.structures[params.structureNumber - 1]];
282
- }
283
- comps = updatedStructureData[0].components;
284
- lastCompsIndex = comps.length - 1;
285
- recentRepComp = [comps[lastCompsIndex]];
286
- uniformColor = param.representationColor ? this.normalizeColor(param.representationColor) : color_1.Color.fromRgb(255, 112, 3);
287
- this.plugin.managers.structure.component.updateRepresentationsTheme(recentRepComp, { color: 'uniform', colorParams: { value: uniformColor } });
288
- }
289
- params.addedRepr = true;
290
- _f.label = 4;
291
- case 4:
292
- // focus loci
293
- if (param.focus)
294
- this.plugin.managers.camera.focusLoci(loci);
295
- _f.label = 5;
296
- case 5: return [3 /*break*/, 1];
297
- case 6: return [3 /*break*/, 13];
298
- case 7:
299
- e_1_1 = _f.sent();
300
- e_1 = { error: e_1_1 };
301
- return [3 /*break*/, 13];
302
- case 8:
303
- _f.trys.push([8, , 11, 12]);
304
- if (!(_d && !_d.done && (_e = _c.return))) return [3 /*break*/, 10];
305
- return [4 /*yield*/, _e.call(_c)];
306
- case 9:
307
- _f.sent();
308
- _f.label = 10;
309
- case 10: return [3 /*break*/, 12];
310
- case 11:
311
- if (e_1) throw e_1.error;
312
- return [7 /*endfinally*/];
313
- case 12: return [7 /*endfinally*/];
314
- case 13:
315
- // reset selection color
316
- this.visual.reset({ selectColor: true });
317
- // save selection params to optimise clear
318
- this.selectedParams = params;
319
- return [2 /*return*/];
320
- }
321
- });
322
- }); },
323
- clearSelection: function (structureNumber) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
324
- var structIndex, selReprCells, _c, _d, c, selReprCells_1, selReprCells_1_1, selReprCell, e_2_1;
325
- var e_2, _e;
326
- return tslib_1.__generator(this, function (_f) {
327
- switch (_f.label) {
328
- case 0:
329
- structIndex = structureNumber ? structureNumber - 1 : 0;
330
- this.plugin.managers.interactivity.lociSelects.deselectAll();
331
- // reset theme to default
332
- if (this.selectedParams && this.selectedParams.nonSelectedColor) {
333
- this.visual.reset({ theme: true });
334
- }
335
- // remove overpaints
336
- return [4 /*yield*/, (0, structure_overpaint_1.clearStructureOverpaint)(this.plugin, this.plugin.managers.structure.hierarchy.current.structures[structIndex].components)];
337
- case 1:
338
- // remove overpaints
339
- _f.sent();
340
- if (!(this.selectedParams && this.selectedParams.addedRepr)) return [3 /*break*/, 15];
341
- selReprCells = [];
342
- for (_c = 0, _d = this.plugin.managers.structure.hierarchy.current.structures[structIndex].components; _c < _d.length; _c++) {
343
- c = _d[_c];
344
- if (c.cell && c.cell.params && c.cell.params.values && c.cell.params.values.label === 'selection-by-script')
345
- selReprCells.push(c.cell);
346
- }
347
- if (!(selReprCells.length > 0)) return [3 /*break*/, 15];
348
- _f.label = 2;
349
- case 2:
350
- _f.trys.push([2, 8, 9, 14]);
351
- selReprCells_1 = tslib_1.__asyncValues(selReprCells);
352
- _f.label = 3;
353
- case 3: return [4 /*yield*/, selReprCells_1.next()];
354
- case 4:
355
- if (!(selReprCells_1_1 = _f.sent(), !selReprCells_1_1.done)) return [3 /*break*/, 7];
356
- selReprCell = selReprCells_1_1.value;
357
- return [4 /*yield*/, commands_1.PluginCommands.State.RemoveObject(this.plugin, { state: selReprCell.parent, ref: selReprCell.transform.ref })];
358
- case 5:
359
- _f.sent();
360
- _f.label = 6;
361
- case 6: return [3 /*break*/, 3];
362
- case 7: return [3 /*break*/, 14];
363
- case 8:
364
- e_2_1 = _f.sent();
365
- e_2 = { error: e_2_1 };
366
- return [3 /*break*/, 14];
367
- case 9:
368
- _f.trys.push([9, , 12, 13]);
369
- if (!(selReprCells_1_1 && !selReprCells_1_1.done && (_e = selReprCells_1.return))) return [3 /*break*/, 11];
370
- return [4 /*yield*/, _e.call(selReprCells_1)];
371
- case 10:
372
- _f.sent();
373
- _f.label = 11;
374
- case 11: return [3 /*break*/, 13];
375
- case 12:
376
- if (e_2) throw e_2.error;
377
- return [7 /*endfinally*/];
378
- case 13: return [7 /*endfinally*/];
379
- case 14:
380
- ;
381
- _f.label = 15;
382
- case 15:
383
- this.selectedParams = undefined;
384
- return [2 /*return*/];
385
- }
386
- });
387
- }); },
388
- update: function (options, fullLoad) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
389
- var param, settings, dataSource;
390
- return tslib_1.__generator(this, function (_c) {
391
- if (!options)
392
- return [2 /*return*/];
393
- // for(let param in this.initParams){
394
- // if(options[param]) this.initParams[param] = options[param];
395
- // }
396
- this.initParams = tslib_1.__assign({}, spec_1.DefaultParams);
397
- for (param in spec_1.DefaultParams) {
398
- if (typeof options[param] !== 'undefined')
399
- this.initParams[param] = options[param];
400
- }
401
- if (!this.initParams.moleculeId && !this.initParams.customData)
402
- return [2 /*return*/, false];
403
- if (this.initParams.customData && this.initParams.customData.url && !this.initParams.customData.format)
404
- return [2 /*return*/, false];
405
- this.plugin.customState.initParams = this.initParams;
406
- // Set background colour
407
- if (this.initParams.bgColor || this.initParams.lighting) {
408
- settings = {};
409
- if (this.initParams.bgColor)
410
- settings.color = this.initParams.bgColor;
411
- if (this.initParams.lighting)
412
- settings.lighting = this.initParams.lighting;
413
- this.canvas.applySettings(settings);
414
- }
415
- dataSource = this.getMoleculeSrcUrl();
416
- if (dataSource) {
417
- this.load({ url: dataSource.url, format: dataSource.format, assemblyId: this.initParams.assemblyId, isBinary: dataSource.isBinary }, fullLoad);
418
- }
419
- return [2 /*return*/];
420
- });
421
- }); },
422
- visibility: function (data) {
423
- if (!data)
424
- return;
425
- var refMap = {
426
- polymer: 'structure-component-static-polymer',
427
- het: 'structure-component-static-ligand',
428
- water: 'structure-component-static-water',
429
- carbs: 'structure-component-static-branched',
430
- maps: 'volume-streaming-info'
431
- };
432
- for (var visual in data) {
433
- var tagName = refMap[visual];
434
- var componentRef = mol_state_2.StateSelection.findTagInSubtree(_this.plugin.state.data.tree, mol_state_1.StateTransform.RootRef, tagName);
435
- if (componentRef) {
436
- var compVisual = _this.plugin.state.data.select(componentRef)[0];
437
- if (compVisual && compVisual.obj) {
438
- var currentlyVisible = (compVisual.state && compVisual.state.isHidden) ? false : true;
439
- if (data[visual] !== currentlyVisible) {
440
- commands_1.PluginCommands.State.ToggleVisibility(_this.plugin, { state: _this.state, ref: componentRef });
441
- }
442
- }
443
- }
444
- }
445
- },
446
- toggleSpin: function (isSpinning, resetCamera) {
447
- if (!_this.plugin.canvas3d)
448
- return;
449
- var trackball = _this.plugin.canvas3d.props.trackball;
450
- var toggleSpinParam = trackball.animate.name === 'spin' ? { name: 'off', params: {} } : { name: 'spin', params: { speed: 1 } };
451
- if (typeof isSpinning !== 'undefined') {
452
- toggleSpinParam = { name: 'off', params: {} };
453
- if (isSpinning)
454
- toggleSpinParam = { name: 'spin', params: { speed: 1 } };
455
- }
456
- commands_1.PluginCommands.Canvas3D.SetSettings(_this.plugin, { settings: { trackball: tslib_1.__assign(tslib_1.__assign({}, trackball), { animate: toggleSpinParam }) } });
457
- if (resetCamera)
458
- commands_1.PluginCommands.Camera.Reset(_this.plugin, {});
459
- },
460
- focus: function (params, structureNumber) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
461
- var loci;
462
- return tslib_1.__generator(this, function (_c) {
463
- loci = this.getLociForParams(params, structureNumber);
464
- this.plugin.managers.camera.focusLoci(loci);
465
- return [2 /*return*/];
466
- });
467
- }); },
468
- setColor: function (param) {
469
- if (!_this.plugin.canvas3d)
470
- return;
471
- var renderer = _this.plugin.canvas3d.props.renderer;
472
- var rParam = {};
473
- if (param.highlight)
474
- rParam['highlightColor'] = _this.normalizeColor(param.highlight);
475
- if (param.select)
476
- rParam['selectColor'] = _this.normalizeColor(param.select);
477
- commands_1.PluginCommands.Canvas3D.SetSettings(_this.plugin, { settings: { renderer: tslib_1.__assign(tslib_1.__assign({}, renderer), rParam) } });
478
- if (rParam.highlightColor)
479
- _this.isHighlightColorUpdated = true;
480
- },
481
- reset: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
482
- var defaultTheme_1, componentGroups, renderer, rParam;
483
- var _this = this;
484
- return tslib_1.__generator(this, function (_c) {
485
- switch (_c.label) {
486
- case 0:
487
- if (!params.camera) return [3 /*break*/, 2];
488
- return [4 /*yield*/, commands_1.PluginCommands.Camera.Reset(this.plugin, { durationMs: 250 })];
489
- case 1:
490
- _c.sent();
491
- _c.label = 2;
492
- case 2:
493
- if (params.theme) {
494
- defaultTheme_1 = { color: this.initParams.alphafoldView ? 'plddt-confidence' : 'default' };
495
- componentGroups = this.plugin.managers.structure.hierarchy.currentComponentGroups;
496
- componentGroups.forEach(function (compGrp) {
497
- _this.plugin.managers.structure.component.updateRepresentationsTheme(compGrp, defaultTheme_1);
498
- });
499
- }
500
- if (params.highlightColor || params.selectColor) {
501
- if (!this.plugin.canvas3d)
502
- return [2 /*return*/];
503
- renderer = this.plugin.canvas3d.props.renderer;
504
- rParam = {};
505
- if (params.highlightColor)
506
- rParam['highlightColor'] = this.defaultRendererProps.highlightColor;
507
- if (params.selectColor)
508
- rParam['selectColor'] = this.defaultRendererProps.selectColor;
509
- commands_1.PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: { renderer: tslib_1.__assign(tslib_1.__assign({}, renderer), rParam) } });
510
- if (rParam.highlightColor)
511
- this.isHighlightColorUpdated = false;
512
- }
513
- return [2 /*return*/];
514
- }
515
- });
516
- }); }
517
- };
518
- this.ArbitrarySphereVisuals = {
519
- 'arbitrary-sphere': function (ctx, getParams) { return (0, representation_2.UnitsRepresentation)('Arbitrary sphere mesh', ctx, getParams, _this.ArbitrarySphereVisual); }
520
- };
521
- this.ArbitrarySphereParams = tslib_1.__assign(tslib_1.__assign({}, units_visual_1.UnitsMeshParams), { x: param_definition_2.ParamDefinition.Numeric(0), y: param_definition_2.ParamDefinition.Numeric(0), z: param_definition_2.ParamDefinition.Numeric(0), l1: param_definition_2.ParamDefinition.Numeric(1), l2: param_definition_2.ParamDefinition.Numeric(1), l3: param_definition_2.ParamDefinition.Numeric(1) });
522
- this.ArbitrarySphereVisual = function (materialId) {
523
- return (0, units_visual_1.UnitsMeshVisual)({
524
- defaultProps: param_definition_2.ParamDefinition.getDefaultValues(_this.ArbitrarySphereParams),
525
- createGeometry: _this.createArbitrarySphereMesh,
526
- createLocationIterator: function (structureGroup) {
527
- return (0, location_iterator_1.LocationIterator)(1, structureGroup.group.units.length, 1, function () { return location_1.NullLocation; });
528
- },
529
- getLoci: function (pickingId, structureGroup, id) {
530
- var objectId = pickingId.objectId;
531
- if (objectId !== id)
532
- return loci_1.EmptyLoci;
533
- return (0, loci_2.DataLoci)('arbitrary-sphere-data-loci', void 0, [0], void 0, function () { return "Yo, I'm a sphere!"; });
534
- },
535
- eachLocation: function (loci, structureGroup, apply) {
536
- if (loci.kind === 'data-loci' && loci.tag === 'arbitrary-sphere-data-loci') {
537
- return apply(int_1.Interval.ofBounds(0, 1));
538
- }
539
- return false;
540
- },
541
- setUpdateState: function (state, newProps, currentProps) {
542
- state.createGeometry = (newProps.x !== currentProps.x ||
543
- newProps.y !== currentProps.y ||
544
- newProps.z !== currentProps.z ||
545
- newProps.l1 !== currentProps.l1 ||
546
- newProps.l2 !== currentProps.l2 ||
547
- newProps.l3 !== currentProps.l3);
548
- }
549
- }, materialId);
550
- };
551
- this.ConfalPyramidsRepresentation = function (ctx, getParams) {
552
- return representation_3.Representation.createMulti('Confal Pyramids', ctx, getParams, representation_2.StructureRepresentationStateBuilder, _this.ArbitrarySphereVisuals);
553
- };
554
- this.ArbitrarySphereRepresentationProvider = (0, representation_2.StructureRepresentationProvider)({
555
- name: 'arbitrary-sphere',
556
- label: 'Arbitrary sphere',
557
- description: 'Displays an arbitrary sphere at given coordinates',
558
- factory: this.ConfalPyramidsRepresentation,
559
- getParams: function (ctx, structure) { return param_definition_2.ParamDefinition.clone(_this.ArbitrarySphereParams); },
560
- defaultValues: param_definition_2.ParamDefinition.getDefaultValues(this.ArbitrarySphereParams),
561
- defaultColorTheme: { name: 'uniform' },
562
- defaultSizeTheme: { name: 'uniform' },
563
- isApplicable: function (structure) { return true; }
564
- });
565
- this.createArbitrarySphereMesh = function (ctx, unit, structure, theme, props, mesh) {
566
- var mb = mesh_builder_1.MeshBuilder.createState(16, 16, mesh);
567
- mb.currentGroup = 0;
568
- var min = (0, linear_algebra_1.Vec3)();
569
- var max = (0, linear_algebra_1.Vec3)();
570
- min[0] = props.x - (props.l1 / 2);
571
- min[1] = props.y - (props.l2 / 2);
572
- min[2] = props.z - (props.l3 / 2);
573
- max[0] = props.x + (props.l1 / 2);
574
- max[1] = props.y + (props.l2 / 2);
575
- max[2] = props.z + (props.l3 / 2);
576
- // addSphere(mb, position, props.radius, 2)
577
- (0, box_1.addBoundingBox)(mb, { min: min, max: max }, 0.1, 1, 1);
578
- return mesh_builder_1.MeshBuilder.getMesh(mb);
579
- };
580
- }
581
- PDBeMolstarPlugin.prototype.render = function (target, options) {
582
- var _c;
583
- return tslib_1.__awaiter(this, void 0, void 0, function () {
584
- var param, defaultPDBeSpec, pdbePluginSpec, _d, settings, dataSource;
585
- return tslib_1.__generator(this, function (_e) {
586
- switch (_e.label) {
587
- case 0:
588
- if (!options)
589
- return [2 /*return*/];
590
- this.initParams = tslib_1.__assign({}, spec_1.DefaultParams);
591
- for (param in spec_1.DefaultParams) {
592
- if (typeof options[param] !== 'undefined')
593
- this.initParams[param] = options[param];
594
- }
595
- defaultPDBeSpec = (0, spec_1.DefaultPluginUISpec)();
596
- pdbePluginSpec = {
597
- actions: tslib_1.__spreadArray([], defaultPDBeSpec.actions || [], true),
598
- behaviors: tslib_1.__spreadArray([], defaultPDBeSpec.behaviors, true),
599
- animations: tslib_1.__spreadArray([], defaultPDBeSpec.animations || [], true),
600
- customParamEditors: defaultPDBeSpec.customParamEditors,
601
- config: defaultPDBeSpec.config
602
- };
603
- if (!this.initParams.ligandView && !this.initParams.superposition && this.initParams.selectInteraction) {
604
- pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(structure_focus_representation_1.StructureFocusRepresentation));
605
- }
606
- if (this.initParams.superposition) {
607
- pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(superposition_focus_representation_1.SuperpositionFocusRepresentation), spec_2.PluginSpec.Behavior(behavior_2.MAQualityAssessment, { autoAttach: true, showTooltip: true }));
608
- }
609
- // Add custom properties
610
- if (this.initParams.domainAnnotation) {
611
- pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(behavior_1.PDBeDomainAnnotations, { autoAttach: true, showTooltip: false }));
612
- }
613
- if (this.initParams.validationAnnotation) {
614
- pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(pdbe_1.PDBeStructureQualityReport, { autoAttach: true, showTooltip: false }));
615
- }
616
- pdbePluginSpec.layout = {
617
- initial: {
618
- isExpanded: this.initParams.landscape ? false : this.initParams.expanded,
619
- showControls: !this.initParams.hideControls
620
- }
621
- };
622
- pdbePluginSpec.components = {
623
- controls: {
624
- left: pdbe_left_panel_1.LeftPanelControls,
625
- // right: DefaultStructureTools,
626
- top: 'none',
627
- bottom: 'none'
628
- },
629
- viewport: {
630
- controls: pdbe_viewport_controls_1.PDBeViewportControls,
631
- view: this.initParams.superposition ? superposition_viewport_1.SuperpostionViewport : void 0
632
- },
633
- remoteState: 'none',
634
- structureTools: this.initParams.superposition ? pdbe_structure_controls_1.PDBeSuperpositionStructureTools : this.initParams.ligandView ? pdbe_structure_controls_1.PDBeLigandViewStructureTools : pdbe_structure_controls_1.PDBeStructureTools
635
- };
636
- if (this.initParams.alphafoldView) {
637
- pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(behavior_2.MAQualityAssessment, { autoAttach: true, showTooltip: true }));
638
- }
639
- if (this.initParams.sequencePanel) {
640
- if ((_c = pdbePluginSpec.components.controls) === null || _c === void 0 ? void 0 : _c.top)
641
- delete pdbePluginSpec.components.controls.top;
642
- }
643
- pdbePluginSpec.config = [
644
- [
645
- config_1.PluginConfig.Structure.DefaultRepresentationPresetParams,
646
- {
647
- theme: {
648
- globalName: (this.initParams.alphafoldView) ? 'plddt-confidence' : undefined,
649
- carbonColor: { name: 'element-symbol', params: {} },
650
- focus: {
651
- name: 'element-symbol',
652
- params: { carbonColor: { name: 'element-symbol', params: {} } }
653
- }
654
- }
655
- }
656
- ]
657
- ];
658
- element_symbol_1.ElementSymbolColorThemeParams.carbonColor.defaultValue = { name: 'element-symbol', params: {} };
659
- // Add animation props
660
- if (!this.initParams.ligandView && !this.initParams.superposition) {
661
- pdbePluginSpec['animations'] = [model_index_1.AnimateModelIndex, camera_spin_1.AnimateCameraSpin, camera_rock_1.AnimateCameraRock, state_snapshots_1.AnimateStateSnapshots, assembly_unwind_1.AnimateAssemblyUnwind, spin_structure_1.AnimateStructureSpin, state_interpolation_1.AnimateStateInterpolation];
662
- pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(mp4_export_1.Mp4Export));
663
- pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(geo_export_1.GeometryExport));
664
- }
665
- if (this.initParams.hideCanvasControls) {
666
- if (this.initParams.hideCanvasControls.indexOf('expand') > -1)
667
- pdbePluginSpec.config.push([config_1.PluginConfig.Viewport.ShowExpand, false]);
668
- if (this.initParams.hideCanvasControls.indexOf('selection') > -1)
669
- pdbePluginSpec.config.push([config_1.PluginConfig.Viewport.ShowSelectionMode, false]);
670
- if (this.initParams.hideCanvasControls.indexOf('animation') > -1)
671
- pdbePluginSpec.config.push([config_1.PluginConfig.Viewport.ShowAnimation, false]);
672
- }
673
- ;
674
- if (this.initParams.landscape && pdbePluginSpec.layout && pdbePluginSpec.layout.initial)
675
- pdbePluginSpec.layout.initial['controlsDisplay'] = 'landscape';
676
- if (this.initParams.reactive && pdbePluginSpec.layout && pdbePluginSpec.layout.initial)
677
- pdbePluginSpec.layout.initial['controlsDisplay'] = 'reactive';
678
- // override default event bindings
679
- if (this.initParams.selectBindings) {
680
- pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(representation_1.SelectLoci, { bindings: this.initParams.selectBindings }));
681
- }
682
- if (this.initParams.focusBindings) {
683
- pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(camera_1.FocusLoci, { bindings: this.initParams.focusBindings }));
684
- }
685
- this.targetElement = typeof target === 'string' ? document.getElementById(target) : target;
686
- // Create/ Initialise Plugin
687
- _d = this;
688
- return [4 /*yield*/, (0, spec_1.createPluginUI)(this.targetElement, pdbePluginSpec)];
689
- case 1:
690
- // Create/ Initialise Plugin
691
- _d.plugin = _e.sent();
692
- this.plugin.customState.initParams = tslib_1.__assign({}, this.initParams);
693
- this.plugin.customState.events = {
694
- segmentUpdate: this._ev(),
695
- superpositionInit: this._ev(),
696
- isBusy: this._ev()
697
- };
698
- // Set background colour
699
- if (this.initParams.bgColor || this.initParams.lighting) {
700
- settings = {};
701
- if (this.initParams.bgColor)
702
- settings.color = this.initParams.bgColor;
703
- if (this.initParams.lighting)
704
- settings.lighting = this.initParams.lighting;
705
- this.canvas.applySettings(settings);
706
- }
707
- // Set selection granularity
708
- if (this.initParams.granularity) {
709
- this.plugin.managers.interactivity.setProps({ granularity: this.initParams.granularity });
710
- }
711
- // Set default highlight and selection colors
712
- if (this.initParams.highlightColor || this.initParams.selectColor) {
713
- this.visual.setColor({ highlight: this.initParams.highlightColor, select: this.initParams.selectColor });
714
- }
715
- // Save renderer defaults
716
- this.defaultRendererProps = tslib_1.__assign({}, this.plugin.canvas3d.props.renderer);
717
- if (this.initParams.superposition) {
718
- // Set left panel tab
719
- this.plugin.behaviors.layout.leftPanelTabName.next('segments');
720
- // Initialise superposition
721
- (0, superposition_1.initSuperposition)(this.plugin);
722
- }
723
- else {
724
- // Collapse left panel and set left panel tab to none
725
- commands_1.PluginCommands.Layout.Update(this.plugin, { state: { regionState: tslib_1.__assign(tslib_1.__assign({}, this.plugin.layout.state.regionState), { left: 'collapsed' }) } });
726
- this.plugin.behaviors.layout.leftPanelTabName.next('none');
727
- dataSource = this.getMoleculeSrcUrl();
728
- if (dataSource) {
729
- this.load({ url: dataSource.url, format: dataSource.format, assemblyId: this.initParams.assemblyId, isBinary: dataSource.isBinary, pdb_string: dataSource.pdb_string });
730
- }
731
- // Binding to other PDB Component events
732
- if (this.initParams.subscribeEvents) {
733
- (0, subscribe_events_1.subscribeToComponentEvents)(this);
734
- }
735
- // Event handling
736
- custom_events_1.CustomEvents.add(this.plugin, this.targetElement);
737
- }
738
- this.plugin.representation.structure.registry.add(this.ArbitrarySphereRepresentationProvider);
739
- return [2 /*return*/];
740
- }
741
- });
742
- });
743
- };
744
- PDBeMolstarPlugin.prototype.getMoleculeSrcUrl = function () {
745
- var supportedFormats = ['mmcif', 'pdb', 'sdf'];
746
- var id = this.initParams.moleculeId;
747
- // if(!id && !this.initParams.customData){
748
- // throw new Error(`Mandatory parameters missing!`);
749
- // }
750
- var query = 'full';
751
- var sep = '?';
752
- if (this.initParams.ligandView) {
753
- var queryParams = ['data_source=pdb-h'];
754
- if (!this.initParams.ligandView.label_comp_id_list) {
755
- if (this.initParams.ligandView.label_comp_id) {
756
- queryParams.push('label_comp_id=' + this.initParams.ligandView.label_comp_id);
757
- }
758
- else if (this.initParams.ligandView.auth_seq_id) {
759
- queryParams.push('auth_seq_id=' + this.initParams.ligandView.auth_seq_id);
760
- }
761
- if (this.initParams.ligandView.auth_asym_id)
762
- queryParams.push('auth_asym_id=' + this.initParams.ligandView.auth_asym_id);
763
- }
764
- query = 'residueSurroundings?' + queryParams.join('&');
765
- sep = '&';
766
- }
767
- var url = "".concat(this.initParams.pdbeUrl, "model-server/v1/").concat(id, "/").concat(query).concat(sep, "encoding=").concat(this.initParams.encoding).concat(this.initParams.lowPrecisionCoords ? '&lowPrecisionCoords=1' : '');
768
- var isBinary = this.initParams.encoding === 'bcif' ? true : false;
769
- var format = 'mmcif';
770
- var pdb_string = undefined;
771
- if (this.initParams.customData) {
772
- if (!this.initParams.customData.url && !this.initParams.customData.pdb_string) {
773
- throw new Error("Provide all custom data parameters");
774
- }
775
- if (!this.initParams.customData.format) {
776
- throw new Error("Provide all custom data parameters");
777
- }
778
- url = this.initParams.customData.url;
779
- format = this.initParams.customData.format;
780
- if (format === 'cif' || format === 'bcif')
781
- format = 'mmcif';
782
- // Validate supported format
783
- if (supportedFormats.indexOf(format) === -1) {
784
- throw new Error("".concat(format, " not supported."));
785
- }
786
- pdb_string = this.initParams.customData.pdb_string;
787
- isBinary = this.initParams.customData.binary ? this.initParams.customData.binary : false;
788
- }
789
- else {
790
- console.log('no custom data');
791
- return undefined;
792
- }
793
- return {
794
- url: url,
795
- format: format,
796
- isBinary: isBinary,
797
- pdb_string: pdb_string
798
- };
799
- };
800
- Object.defineProperty(PDBeMolstarPlugin.prototype, "state", {
801
- get: function () {
802
- return this.plugin.state.data;
803
- },
804
- enumerable: false,
805
- configurable: true
806
- });
807
- PDBeMolstarPlugin.prototype.add_mouse_event = function (func) {
808
- this.plugin.behaviors.interaction.click.subscribe(function (e) {
809
- func(e);
810
- });
811
- };
812
- PDBeMolstarPlugin.prototype.add_shape = function (structure, params) {
813
- // params: {x: -10, y: -11, z: 10, radius: 8}
814
- Object.assign(params, { color: names_1.ColorNames.orange });
815
- return this.plugin.builders.structure.representation.addRepresentation(structure, {
816
- type: 'arbitrary-sphere',
817
- typeParams: params,
818
- colorParams: { value: params.color }
819
- });
820
- };
821
- PDBeMolstarPlugin.prototype.remove_shape = function (selector) {
822
- var _c, _d;
823
- selector.obj.data.repr.destroy();
824
- (_c = this.plugin.canvas3d) === null || _c === void 0 ? void 0 : _c.remove(selector.obj.data.repr);
825
- (_d = this.plugin.canvas3d) === null || _d === void 0 ? void 0 : _d.update();
826
- };
827
- PDBeMolstarPlugin.prototype.get_ligand_queries = function (pdb_string) {
828
- var ligand_info_list = this.parse_ligand_info(pdb_string);
829
- var queries = [];
830
- try {
831
- for (var i = 0; i < ligand_info_list.length; i++) {
832
- queries.push(this.ownResidueQuery(ligand_info_list[i].chain_name, [ligand_info_list[i].residue_name], ligand_info_list[i].residue_id, 'Ligand/Non-standard Residue', 200));
833
- }
834
- return queries;
835
- }
836
- catch (e) {
837
- console.error('e', e);
838
- }
839
- };
840
- PDBeMolstarPlugin.prototype.get_chain_queries = function (s) {
841
- var uniqueEntities = new Map();
842
- var l = structure_1.StructureElement.Location.create();
843
- l.structure = s;
844
- for (var _a = 0, _b = s.unitSymmetryGroups; _a < _b.length; _a++) {
845
- var ug = _b[_a];
846
- l.unit = ug.units[0];
847
- l.element = ug.elements[0];
848
- var entityType = structure_1.StructureProperties.entity.type(l);
849
- if (entityType === 'polymer' || entityType === 'branched') {
850
- var description = structure_1.StructureProperties.entity.pdbx_description(l);
851
- uniqueEntities.set(description.join(', '), description);
852
- }
853
- }
854
- var queries = [];
855
- uniqueEntities.forEach(function (names, label) {
856
- var description = ''.concat(label);
857
- var expression = builder_1.MolScriptBuilder.struct.modifier.union([
858
- builder_1.MolScriptBuilder.struct.generator.atomGroups({
859
- 'entity-test': builder_1.MolScriptBuilder.core.list.equal([builder_1.MolScriptBuilder.list.apply(builder_1.MolScriptBuilder, names), builder_1.MolScriptBuilder.ammp('entityDescription')])
860
- })
861
- ]);
862
- var query = (0, structure_selection_query_1.StructureSelectionQuery)(''.concat(label), expression, { category: 'Polymer/Carbohydrate Entities', priority: 300, description: description });
863
- queries.push({ query: query, expression: expression, label: label });
864
- });
865
- return queries;
866
- };
867
- PDBeMolstarPlugin.prototype.get_ligand_query_name = function (query) {
868
- var label = query.label;
869
- var match = label.match(/\[(.*?)\]/);
870
- var extracted = match ? match[1] : null;
871
- return extracted;
872
- };
873
- PDBeMolstarPlugin.prototype.change_repr = function (selector, params, state) {
874
- var _c, _d;
875
- if (params === void 0) { params = undefined; }
876
- if (state === void 0) { state = undefined; }
877
- return tslib_1.__awaiter(this, void 0, void 0, function () {
878
- var s, e_3;
879
- return tslib_1.__generator(this, function (_e) {
880
- switch (_e.label) {
881
- case 0:
882
- s = selector;
883
- if (!params) return [3 /*break*/, 4];
884
- if (selector.obj.data.repr) {
885
- selector.obj.data.repr.destroy();
886
- (_c = this.plugin.canvas3d) === null || _c === void 0 ? void 0 : _c.update();
887
- }
888
- _e.label = 1;
889
- case 1:
890
- _e.trys.push([1, 3, , 4]);
891
- return [4 /*yield*/, this.plugin.builders.structure.representation.addRepresentation(selector, params)];
892
- case 2:
893
- s = _e.sent();
894
- return [3 /*break*/, 4];
895
- case 3:
896
- e_3 = _e.sent();
897
- console.log(e_3);
898
- return [3 /*break*/, 4];
899
- case 4:
900
- if (state) {
901
- s.obj.data.repr.setState(state);
902
- }
903
- (_d = this.plugin.canvas3d) === null || _d === void 0 ? void 0 : _d.update();
904
- return [2 /*return*/, s];
905
- }
906
- });
907
- });
908
- };
909
- PDBeMolstarPlugin.prototype.add_repr_on_select_expression = function (structure, select_expression, label, params) {
910
- if (params === void 0) { params = { type: 'ball-and-stick' }; }
911
- return tslib_1.__awaiter(this, void 0, void 0, function () {
912
- var selector, new_selector;
913
- return tslib_1.__generator(this, function (_c) {
914
- switch (_c.label) {
915
- case 0: return [4 /*yield*/, this.plugin.builders.structure.tryCreateComponentFromExpression(structure, select_expression, label)];
916
- case 1:
917
- selector = _c.sent();
918
- return [4 /*yield*/, this.plugin.builders.structure.representation.addRepresentation(selector, params)];
919
- case 2:
920
- new_selector = _c.sent();
921
- return [2 /*return*/, new_selector];
922
- }
923
- });
924
- });
925
- };
926
- PDBeMolstarPlugin.prototype.highlight_and_focuson_query = function (structure, query) {
927
- var _this = this;
928
- var data = structure.data;
929
- if (!data)
930
- return;
931
- this.plugin.runTask(mol_task_1.Task.create('Structure Selection', function (runtime) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
932
- var selection, loci;
933
- return tslib_1.__generator(this, function (_c) {
934
- switch (_c.label) {
935
- case 0: return [4 /*yield*/, query.getSelection(this.plugin, runtime, structure.data)];
936
- case 1:
937
- selection = _c.sent();
938
- loci = structure_1.StructureSelection.toLociWithSourceUnits(selection);
939
- this.plugin.managers.interactivity.lociHighlights.highlightOnly({ loci: loci });
940
- this.plugin.managers.camera.focusLoci(loci);
941
- return [2 /*return*/];
942
- }
943
- });
944
- }); }));
945
- };
946
- PDBeMolstarPlugin.prototype.createLigandStructure = function (isBranched) {
947
- var e_4, _c;
948
- var _d;
949
- return tslib_1.__awaiter(this, void 0, void 0, function () {
950
- var _e, _f, comp, e_4_1, structure, ligandQuery, ligandVis, ligandSurr, ligRef, cell, ligLoci;
951
- var _this = this;
952
- return tslib_1.__generator(this, function (_g) {
953
- switch (_g.label) {
954
- case 0:
955
- if (this.assemblyRef === '')
956
- return [2 /*return*/];
957
- _g.label = 1;
958
- case 1:
959
- _g.trys.push([1, 7, 8, 13]);
960
- _e = tslib_1.__asyncValues(this.plugin.managers.structure.hierarchy.currentComponentGroups);
961
- _g.label = 2;
962
- case 2: return [4 /*yield*/, _e.next()];
963
- case 3:
964
- if (!(_f = _g.sent(), !_f.done)) return [3 /*break*/, 6];
965
- comp = _f.value;
966
- return [4 /*yield*/, commands_1.PluginCommands.State.RemoveObject(this.plugin, { state: comp[0].cell.parent, ref: comp[0].cell.transform.ref, removeParentGhosts: true })];
967
- case 4:
968
- _g.sent();
969
- _g.label = 5;
970
- case 5: return [3 /*break*/, 2];
971
- case 6: return [3 /*break*/, 13];
972
- case 7:
973
- e_4_1 = _g.sent();
974
- e_4 = { error: e_4_1 };
975
- return [3 /*break*/, 13];
976
- case 8:
977
- _g.trys.push([8, , 11, 12]);
978
- if (!(_f && !_f.done && (_c = _e.return))) return [3 /*break*/, 10];
979
- return [4 /*yield*/, _c.call(_e)];
980
- case 9:
981
- _g.sent();
982
- _g.label = 10;
983
- case 10: return [3 /*break*/, 12];
984
- case 11:
985
- if (e_4) throw e_4.error;
986
- return [7 /*endfinally*/];
987
- case 12: return [7 /*endfinally*/];
988
- case 13:
989
- structure = this.state.select(this.assemblyRef)[0];
990
- if (isBranched) {
991
- ligandQuery = helpers_1.LigandView.branchedQuery((_d = this.initParams.ligandView) === null || _d === void 0 ? void 0 : _d.label_comp_id_list);
992
- }
993
- else {
994
- ligandQuery = helpers_1.LigandView.query(this.initParams.ligandView);
995
- }
996
- return [4 /*yield*/, this.plugin.builders.structure.tryCreateComponentFromExpression(structure, ligandQuery.core, 'pivot', { label: 'Ligand' })];
997
- case 14:
998
- ligandVis = _g.sent();
999
- if (!ligandVis) return [3 /*break*/, 16];
1000
- return [4 /*yield*/, this.plugin.builders.structure.representation.addRepresentation(ligandVis, { type: 'ball-and-stick', color: 'element-symbol', colorParams: { carbonColor: { name: 'element-symbol', params: {} } }, size: 'uniform', sizeParams: { value: 2.5 } }, { tag: 'ligand-vis' })];
1001
- case 15:
1002
- _g.sent();
1003
- _g.label = 16;
1004
- case 16: return [4 /*yield*/, this.plugin.builders.structure.tryCreateComponentFromExpression(structure, ligandQuery.surroundings, 'rest', { label: 'Surroundings' })];
1005
- case 17:
1006
- ligandSurr = _g.sent();
1007
- if (!ligandSurr) return [3 /*break*/, 19];
1008
- return [4 /*yield*/, this.plugin.builders.structure.representation.addRepresentation(ligandSurr, { type: 'ball-and-stick', color: 'element-symbol', colorParams: { carbonColor: { name: 'element-symbol', params: {} } }, size: 'uniform', sizeParams: { value: 0.8 } })];
1009
- case 18:
1010
- _g.sent();
1011
- _g.label = 19;
1012
- case 19:
1013
- ligRef = mol_state_2.StateSelection.findTagInSubtree(this.plugin.state.data.tree, mol_state_1.StateTransform.RootRef, 'ligand-vis');
1014
- if (!ligRef)
1015
- return [2 /*return*/];
1016
- cell = this.plugin.state.data.cells.get(ligRef);
1017
- if (cell) {
1018
- ligLoci = cell.obj.data.repr.getLoci();
1019
- this.plugin.managers.structure.focus.setFromLoci(ligLoci);
1020
- setTimeout(function () {
1021
- var _c;
1022
- // focus-add is not handled in camera behavior, doing it here
1023
- var current = (_c = _this.plugin.managers.structure.focus.current) === null || _c === void 0 ? void 0 : _c.loci;
1024
- if (current)
1025
- _this.plugin.managers.camera.focusLoci(current);
1026
- }, 500);
1027
- }
1028
- return [2 /*return*/];
1029
- }
1030
- });
1031
- });
1032
- };
1033
- PDBeMolstarPlugin.prototype.load = function (_c, fullLoad) {
1034
- var url = _c.url, _d = _c.format, format = _d === void 0 ? 'mmcif' : _d, _e = _c.isBinary, isBinary = _e === void 0 ? false : _e, _f = _c.assemblyId, assemblyId = _f === void 0 ? '' : _f, _g = _c.pdb_string, pdb_string = _g === void 0 ? '' : _g;
1035
- if (fullLoad === void 0) { fullLoad = true; }
1036
- return tslib_1.__awaiter(this, void 0, void 0, function () {
1037
- var isHetView, downloadOptions, isBranchedView, data, trajectory, _h, _j, pivotIndex, pivot, asm, defaultMapParams, pdbeMapParams;
1038
- return tslib_1.__generator(this, function (_k) {
1039
- switch (_k.label) {
1040
- case 0:
1041
- if (fullLoad)
1042
- this.clear();
1043
- isHetView = this.initParams.ligandView ? true : false;
1044
- downloadOptions = void 0;
1045
- isBranchedView = false;
1046
- if (this.initParams.ligandView && this.initParams.ligandView.label_comp_id_list) {
1047
- isBranchedView = true;
1048
- downloadOptions = { body: JSON.stringify(this.initParams.ligandView.label_comp_id_list), headers: [['Content-type', 'application/json']] };
1049
- }
1050
- data = null;
1051
- if (!pdb_string) return [3 /*break*/, 2];
1052
- return [4 /*yield*/, this.plugin.builders.data.rawData({ data: pdb_string }, { state: { isGhost: true } })];
1053
- case 1:
1054
- data = _k.sent();
1055
- return [3 /*break*/, 4];
1056
- case 2: return [4 /*yield*/, this.plugin.builders.data.download({ url: assets_1.Asset.Url(url, downloadOptions), isBinary: isBinary }, { state: { isGhost: true } })];
1057
- case 3:
1058
- data = _k.sent();
1059
- _k.label = 4;
1060
- case 4: return [4 /*yield*/, this.plugin.builders.structure.parseTrajectory(data, format)];
1061
- case 5:
1062
- trajectory = _k.sent();
1063
- _h = this;
1064
- return [4 /*yield*/, this.plugin.builders.structure.createModel(trajectory)];
1065
- case 6:
1066
- _h.model = _k.sent();
1067
- _j = this;
1068
- return [4 /*yield*/, this.plugin.builders.structure.createStructure(this.model, { name: 'model', params: {} })];
1069
- case 7:
1070
- _j.structure = _k.sent();
1071
- if (!!isHetView) return [3 /*break*/, 9];
1072
- return [4 /*yield*/, this.plugin.builders.structure.hierarchy.applyPreset(trajectory, this.initParams.defaultPreset, {
1073
- structure: assemblyId ? (assemblyId === 'preferred') ? void 0 : { name: 'assembly', params: { id: assemblyId } } : { name: 'model', params: {} },
1074
- showUnitcell: false,
1075
- representationPreset: 'auto'
1076
- })];
1077
- case 8:
1078
- _k.sent();
1079
- if (this.initParams.hideStructure || this.initParams.visualStyle) {
1080
- this.applyVisualParams();
1081
- }
1082
- _k.label = 9;
1083
- case 9:
1084
- // show selection if param is set
1085
- if (this.initParams.selection) {
1086
- this.visual.select(this.initParams.selection);
1087
- }
1088
- pivotIndex = this.plugin.managers.structure.hierarchy.selection.structures.length - 1;
1089
- pivot = this.plugin.managers.structure.hierarchy.selection.structures[pivotIndex];
1090
- if (pivot && pivot.cell.parent)
1091
- this.assemblyRef = pivot.cell.transform.ref;
1092
- if (!this.initParams.loadMaps) return [3 /*break*/, 11];
1093
- if (this.assemblyRef === '')
1094
- return [2 /*return*/];
1095
- asm = this.state.select(this.assemblyRef)[0].obj;
1096
- defaultMapParams = transformers_1.InitVolumeStreaming.createDefaultParams(asm, this.plugin);
1097
- pdbeMapParams = helpers_1.PDBeVolumes.mapParams(defaultMapParams, this.initParams.mapSettings, '');
1098
- if (!pdbeMapParams) return [3 /*break*/, 11];
1099
- return [4 /*yield*/, this.plugin.runTask(this.state.applyAction(transformers_1.InitVolumeStreaming, pdbeMapParams, this.assemblyRef))];
1100
- case 10:
1101
- _k.sent();
1102
- if (pdbeMapParams.method !== 'em' && !this.initParams.ligandView)
1103
- helpers_1.PDBeVolumes.displayUsibilityMessage(this.plugin);
1104
- _k.label = 11;
1105
- case 11:
1106
- if (!isHetView) return [3 /*break*/, 13];
1107
- return [4 /*yield*/, this.createLigandStructure(isBranchedView)];
1108
- case 12:
1109
- _k.sent();
1110
- _k.label = 13;
1111
- case 13:
1112
- this.events.loadComplete.next(true);
1113
- return [2 /*return*/];
1114
- }
1115
- });
1116
- });
1117
- };
1118
- PDBeMolstarPlugin.prototype.getLociForParams = function (params, structureNumber) {
1119
- var assemblyRef = this.assemblyRef;
1120
- if (structureNumber) {
1121
- assemblyRef = this.plugin.managers.structure.hierarchy.current.structures[structureNumber - 1].cell.transform.ref;
1122
- }
1123
- if (assemblyRef === '')
1124
- return loci_1.EmptyLoci;
1125
- var data = this.plugin.state.data.select(assemblyRef)[0].obj.data;
1126
- if (!data)
1127
- return loci_1.EmptyLoci;
1128
- return helpers_1.QueryHelper.getInteractivityLoci(params, data);
1129
- };
1130
- PDBeMolstarPlugin.prototype.getLociByPLDDT = function (score, structureNumber) {
1131
- var assemblyRef = this.assemblyRef;
1132
- if (structureNumber) {
1133
- assemblyRef = this.plugin.managers.structure.hierarchy.current.structures[structureNumber - 1].cell.transform.ref;
1134
- }
1135
- if (assemblyRef === '')
1136
- return loci_1.EmptyLoci;
1137
- var data = this.plugin.state.data.select(assemblyRef)[0].obj.data;
1138
- if (!data)
1139
- return loci_1.EmptyLoci;
1140
- return helpers_1.AlphafoldView.getLociByPLDDT(score, data);
1141
- };
1142
- PDBeMolstarPlugin.prototype.normalizeColor = function (colorVal, defaultColor) {
1143
- var color = color_1.Color.fromRgb(170, 170, 170);
1144
- try {
1145
- if (typeof colorVal.r !== 'undefined') {
1146
- color = color_1.Color.fromRgb(colorVal.r, colorVal.g, colorVal.b);
1147
- }
1148
- else if (colorVal[0] === '#') {
1149
- color = (0, color_1.Color)(Number("0x".concat(colorVal.substr(1))));
1150
- }
1151
- else {
1152
- color = (0, color_1.Color)(colorVal);
1153
- }
1154
- }
1155
- catch (e) {
1156
- if (defaultColor)
1157
- color = defaultColor;
1158
- }
1159
- return color;
1160
- };
1161
- PDBeMolstarPlugin.prototype.clear = function () {
1162
- return tslib_1.__awaiter(this, void 0, void 0, function () {
1163
- return tslib_1.__generator(this, function (_c) {
1164
- this.plugin.clear();
1165
- this.assemblyRef = '';
1166
- this.selectedParams = void 0;
1167
- this.isHighlightColorUpdated = false;
1168
- this.isSelectedColorUpdated = false;
1169
- return [2 /*return*/];
1170
- });
1171
- });
1172
- };
1173
- PDBeMolstarPlugin.prototype.parse_ligand_info = function (pdb_string) {
1174
- // 解析所有的配体信息
1175
- // chain_name
1176
- // name
1177
- // count
1178
- var ret_list = [];
1179
- var lines = pdb_string.split('\n');
1180
- var ligand_dict = {};
1181
- for (var _c = 0, lines_1 = lines; _c < lines_1.length; _c++) {
1182
- var line = lines_1[_c];
1183
- if (line.startsWith('HETATM')) {
1184
- var ligand_name = line.substr(17, 3).trim();
1185
- if (ligand_name === 'HOH') {
1186
- continue;
1187
- }
1188
- var residue_id = line.substr(22, 5).trim();
1189
- var chain_name = line.substr(21, 1).trim();
1190
- var x = line.substr(30, 8).trim();
1191
- var y = line.substr(38, 8).trim();
1192
- var z = line.substr(46, 8).trim();
1193
- if (ligand_dict[chain_name + ':' + ligand_name] === undefined) {
1194
- ligand_dict[chain_name + ':' + ligand_name] = {
1195
- 'chain_name': chain_name,
1196
- 'name': chain_name + ':' + ligand_name + ':' + residue_id,
1197
- 'residue_name': ligand_name,
1198
- 'residue_id': residue_id,
1199
- 'count': 1,
1200
- 'show_option': true,
1201
- 'coords': [[Number(x), Number(y), Number(z)]]
1202
- };
1203
- }
1204
- else {
1205
- ligand_dict[chain_name + ':' + ligand_name].count += 1;
1206
- ligand_dict[chain_name + ':' + ligand_name].coords.push([Number(x), Number(y), Number(z)]);
1207
- }
1208
- }
1209
- }
1210
- for (var key in ligand_dict) {
1211
- var max_min_dict = this.calc_max_min(ligand_dict[key]);
1212
- ligand_dict[key]['max_min_coord'] = max_min_dict;
1213
- ret_list.push(ligand_dict[key]);
1214
- }
1215
- return ret_list;
1216
- };
1217
- PDBeMolstarPlugin.prototype.calc_max_min = function (ligand_dict) {
1218
- var coords = ligand_dict.coords;
1219
- var x_list = [];
1220
- var y_list = [];
1221
- var z_list = [];
1222
- for (var _c = 0, coords_1 = coords; _c < coords_1.length; _c++) {
1223
- var coord = coords_1[_c];
1224
- x_list.push(coord[0]);
1225
- y_list.push(coord[1]);
1226
- z_list.push(coord[2]);
1227
- }
1228
- return {
1229
- 'max_x': Math.max.apply(Math, x_list),
1230
- 'min_x': Math.min.apply(Math, x_list),
1231
- 'max_y': Math.max.apply(Math, y_list),
1232
- 'min_y': Math.min.apply(Math, y_list),
1233
- 'max_z': Math.max.apply(Math, z_list),
1234
- 'min_z': Math.min.apply(Math, z_list)
1235
- };
1236
- };
1237
- return PDBeMolstarPlugin;
1238
- }());
1239
- window.PDBeMolstarPlugin = PDBeMolstarPlugin;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ var spec_1 = require("./spec");
5
+ var commands_1 = require("Molstar/mol-plugin/commands");
6
+ var mol_state_1 = require("Molstar/mol-state");
7
+ var loci_1 = require("Molstar/mol-model/loci");
8
+ var rx_event_helper_1 = require("Molstar/mol-util/rx-event-helper");
9
+ var helpers_1 = require("./helpers");
10
+ var pdbe_structure_controls_1 = require("./ui/pdbe-structure-controls");
11
+ var pdbe_viewport_controls_1 = require("./ui/pdbe-viewport-controls");
12
+ var mol_state_2 = require("Molstar/mol-state");
13
+ var structure_focus_representation_1 = require("Molstar/mol-plugin/behavior/dynamic/selection/structure-focus-representation");
14
+ var spec_2 = require("Molstar/mol-plugin/spec");
15
+ var transformers_1 = require("Molstar/mol-plugin/behavior/dynamic/volume-streaming/transformers");
16
+ var structure_representation_params_1 = require("Molstar/mol-plugin-state/helpers/structure-representation-params");
17
+ var subscribe_events_1 = require("./subscribe-events");
18
+ var pdbe_left_panel_1 = require("./ui/pdbe-left-panel");
19
+ var superposition_1 = require("./superposition");
20
+ var custom_events_1 = require("./custom-events");
21
+ var assets_1 = require("Molstar/mol-util/assets");
22
+ var config_1 = require("Molstar/mol-plugin/config");
23
+ var color_1 = require("Molstar/mol-util/color/color");
24
+ var component_1 = require("Molstar/mol-plugin-state/manager/structure/component");
25
+ var param_definition_1 = require("Molstar/mol-util/param-definition");
26
+ var behavior_1 = require("./domain-annotations/behavior");
27
+ var pdbe_1 = require("Molstar/extensions/pdbe");
28
+ var behavior_2 = require("Molstar/extensions/model-archive/quality-assessment/behavior");
29
+ var structure_overpaint_1 = require("Molstar/mol-plugin-state/helpers/structure-overpaint");
30
+ var superposition_focus_representation_1 = require("./superposition-focus-representation");
31
+ var superposition_viewport_1 = require("./ui/superposition-viewport");
32
+ var representation_1 = require("Molstar/mol-plugin/behavior/dynamic/representation");
33
+ var camera_1 = require("molstar/lib/mol-plugin/behavior/dynamic/camera");
34
+ var mp4_export_1 = require("Molstar/extensions/mp4-export");
35
+ var geo_export_1 = require("Molstar/extensions/geo-export");
36
+ var element_symbol_1 = require("Molstar/mol-theme/color/element-symbol");
37
+ var model_index_1 = require("Molstar/mol-plugin-state/animation/built-in/model-index");
38
+ var camera_spin_1 = require("Molstar/mol-plugin-state/animation/built-in/camera-spin");
39
+ var state_snapshots_1 = require("Molstar/mol-plugin-state/animation/built-in/state-snapshots");
40
+ var state_interpolation_1 = require("Molstar/mol-plugin-state/animation/built-in/state-interpolation");
41
+ var spin_structure_1 = require("Molstar/mol-plugin-state/animation/built-in/spin-structure");
42
+ var camera_rock_1 = require("Molstar/mol-plugin-state/animation/built-in/camera-rock");
43
+ var assembly_unwind_1 = require("Molstar/mol-plugin-state/animation/built-in/assembly-unwind");
44
+ var builder_1 = require("molstar/lib/mol-script/language/builder");
45
+ var names_1 = require("molstar/lib/mol-util/color/names");
46
+ var units_visual_1 = require("molstar/lib/mol-repr/structure/units-visual");
47
+ var param_definition_2 = require("molstar/lib/mol-util/param-definition");
48
+ var representation_2 = require("molstar/lib/mol-repr/structure/representation");
49
+ var structure_selection_query_1 = require("molstar/lib/mol-plugin-state/helpers/structure-selection-query");
50
+ var representation_3 = require("molstar/lib/mol-repr/representation");
51
+ var box_1 = require("molstar/lib/mol-geo/geometry/mesh/builder/box");
52
+ var mesh_builder_1 = require("molstar/lib/mol-geo/geometry/mesh/mesh-builder");
53
+ var linear_algebra_1 = require("molstar/lib/mol-math/linear-algebra");
54
+ var int_1 = require("molstar/lib/mol-data/int");
55
+ var location_iterator_1 = require("molstar/lib/mol-geo/util/location-iterator");
56
+ var location_1 = require("molstar/lib/mol-model/location");
57
+ var loci_2 = require("molstar/lib/mol-model/loci");
58
+ var structure_1 = require("molstar/lib/mol-model/structure");
59
+ var mol_task_1 = require("molstar/lib/mol-task");
60
+ require('Molstar/mol-plugin-ui/skin/dark.scss');
61
+ var PDBeMolstarPlugin = /** @class */ (function () {
62
+ function PDBeMolstarPlugin() {
63
+ var _this = this;
64
+ this._ev = rx_event_helper_1.RxEventHelper.create();
65
+ this.events = {
66
+ loadComplete: this._ev()
67
+ };
68
+ this.assemblyRef = '';
69
+ this.isHighlightColorUpdated = false;
70
+ this.isSelectedColorUpdated = false;
71
+ this.get_quick_querys = function (structure, pdb_string) {
72
+ var ligand_queries = _this.get_ligand_queries(pdb_string);
73
+ var chain_queries = _this.get_chain_queries(pdb_string);
74
+ var pocket_queries = _this.get_pocket_queries(ligand_queries, 5);
75
+ var water = structure_selection_query_1.StructureSelectionQueries.water;
76
+ return {
77
+ ligands: ligand_queries,
78
+ chains: chain_queries,
79
+ pockets: pocket_queries,
80
+ water: [water]
81
+ };
82
+ };
83
+ this.get_pocket_queries = function (ligand_queries, radius) {
84
+ // 同名的ligand_query会被合并
85
+ var queries = [];
86
+ for (var i = 0; i < ligand_queries.length; i++) {
87
+ var label = _this.get_ligand_query_name(ligand_queries[i]);
88
+ var core = builder_1.MolScriptBuilder.struct.generator.atomGroups({
89
+ 'residue-test': builder_1.MolScriptBuilder.core.set.has([builder_1.MolScriptBuilder.set.apply(builder_1.MolScriptBuilder, [label]), builder_1.MolScriptBuilder.ammp('auth_comp_id')])
90
+ });
91
+ var surrounding = builder_1.MolScriptBuilder.struct.modifier.union([
92
+ builder_1.MolScriptBuilder.struct.modifier.exceptBy({
93
+ 0: builder_1.MolScriptBuilder.struct.modifier.includeSurroundings({
94
+ 0: core,
95
+ radius: radius,
96
+ 'as-whole-residues': true
97
+ }),
98
+ by: core
99
+ })
100
+ ]);
101
+ var ligand_expand_q = (0, structure_selection_query_1.StructureSelectionQuery)('Surrounding Residues (5 \u212B) of ' + label, surrounding, {
102
+ description: 'Select residues within 5 \u212B of ' + label,
103
+ category: structure_selection_query_1.StructureSelectionCategory.Manipulate,
104
+ referencesCurrent: true
105
+ });
106
+ queries.push({ query: ligand_expand_q, expression: surrounding, label: label });
107
+ }
108
+ return queries;
109
+ };
110
+ this.ownResidueQuery = function (chain_name, residue_name_list, residue_id, category, priority) {
111
+ if (priority === void 0) {
112
+ priority = 0;
113
+ }
114
+ var description = '[' + residue_name_list[0] + ']|' + chain_name + ':' + residue_name_list[0] + ':' + residue_id;
115
+ return (0, structure_selection_query_1.StructureSelectionQuery)(description, builder_1.MolScriptBuilder.struct.modifier.union([
116
+ builder_1.MolScriptBuilder.struct.generator.atomGroups({
117
+ 'chain-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.ammp('auth_asym_id'), chain_name]),
118
+ 'residue-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.ammp('auth_seq_id'), Number(residue_id)])
119
+ // 'residue-test-comp': MS.core.set.has([MS.set.apply(MS, residue_name_list), MS.ammp('auth_comp_id')])
120
+ })
121
+ ]), { category: category, priority: priority, description: description });
122
+ };
123
+ this.applyVisualParams = function () {
124
+ var TagRefs = {
125
+ 'structure-component-static-polymer': 'polymer',
126
+ 'structure-component-static-ligand': 'het',
127
+ 'structure-component-static-branched': 'carbs',
128
+ 'structure-component-static-water': 'water',
129
+ 'structure-component-static-coarse': 'coarse',
130
+ 'non-standard': 'nonStandard'
131
+ };
132
+ var componentGroups = _this.plugin.managers.structure.hierarchy.currentComponentGroups;
133
+ componentGroups.forEach(function (compGrp) {
134
+ var _a;
135
+ var compGrpIndex = compGrp.length - 1;
136
+ var key = compGrp[compGrpIndex].key;
137
+ var rm = false;
138
+ if (key && _this.initParams.hideStructure) {
139
+ var structType = TagRefs[key];
140
+ if (structType && ((_a = _this.initParams.hideStructure) === null || _a === void 0 ? void 0 : _a.indexOf(structType)) > -1)
141
+ rm = true;
142
+ }
143
+ if (rm) {
144
+ _this.plugin.managers.structure.hierarchy.remove([compGrp[compGrpIndex]]);
145
+ }
146
+ if (!rm && _this.initParams.visualStyle) {
147
+ if (compGrp[compGrpIndex] && compGrp[compGrpIndex].representations) {
148
+ compGrp[compGrpIndex].representations.forEach(function (rep) {
149
+ var currentParams = (0, structure_representation_params_1.createStructureRepresentationParams)(_this.plugin, void 0, { type: _this.initParams.visualStyle });
150
+ _this.plugin.managers.structure.component.updateRepresentations([compGrp[compGrpIndex]], rep, currentParams);
151
+ });
152
+ }
153
+ }
154
+ });
155
+ };
156
+ this.canvas = {
157
+ toggleControls: function (isVisible) {
158
+ if (typeof isVisible === 'undefined')
159
+ isVisible = !_this.plugin.layout.state.showControls;
160
+ commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { showControls: isVisible } });
161
+ },
162
+ toggleExpanded: function (isExpanded) {
163
+ if (typeof isExpanded === 'undefined')
164
+ isExpanded = !_this.plugin.layout.state.isExpanded;
165
+ commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { isExpanded: isExpanded } });
166
+ },
167
+ setBgColor: function (color) {
168
+ if (!color)
169
+ return;
170
+ _this.canvas.applySettings({ color: color });
171
+ },
172
+ applySettings: function (settings) {
173
+ if (!settings)
174
+ return;
175
+ var rendererParams = {};
176
+ if (settings.color)
177
+ rendererParams['backgroundColor'] = color_1.Color.fromRgb(settings.color.r, settings.color.g, settings.color.b);
178
+ if (settings.lighting)
179
+ rendererParams['style'] = { name: settings.lighting };
180
+ var renderer = _this.plugin.canvas3d.props.renderer;
181
+ commands_1.PluginCommands.Canvas3D.SetSettings(_this.plugin, { settings: { renderer: tslib_1.__assign(tslib_1.__assign({}, renderer), rendererParams) } });
182
+ },
183
+ toggleSelect: function (isSelect) {
184
+ _this.plugin.selectionMode = !isSelect;
185
+ }
186
+ };
187
+ this.visual = {
188
+ highlight: function (params) {
189
+ var loci = _this.getLociForParams(params.data, params.structureNumber);
190
+ if (loci_1.Loci.isEmpty(loci))
191
+ return;
192
+ if (params.color) {
193
+ _this.visual.setColor({ highlight: params.color });
194
+ }
195
+ _this.plugin.managers.interactivity.lociHighlights.highlightOnly({ loci: loci });
196
+ if (params.focus)
197
+ _this.plugin.managers.camera.focusLoci(loci);
198
+ },
199
+ clearHighlight: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
200
+ return tslib_1.__generator(this, function (_a) {
201
+ this.plugin.managers.interactivity.lociHighlights.highlightOnly({ loci: loci_1.EmptyLoci });
202
+ if (this.isHighlightColorUpdated)
203
+ this.visual.reset({ highlightColor: true });
204
+ return [2 /*return*/];
205
+ });
206
+ }); },
207
+ hideSelect: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
208
+ var sel, components, _i, sel_1, s;
209
+ return tslib_1.__generator(this, function (_a) {
210
+ sel = this.plugin.managers.structure.hierarchy.getStructuresWithSelection();
211
+ components = [];
212
+ for (_i = 0, sel_1 = sel; _i < sel_1.length; _i++) {
213
+ s = sel_1[_i];
214
+ components.push.apply(components, s.components);
215
+ }
216
+ if (components.length === 0)
217
+ return [2 /*return*/];
218
+ this.plugin.managers.structure.component.modifyByCurrentSelection(components, 'subtract');
219
+ return [2 /*return*/];
220
+ });
221
+ }); },
222
+ showSelect: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
223
+ var sel, components, _i, sel_1, s;
224
+ return tslib_1.__generator(this, function (_a) {
225
+ sel = this.plugin.managers.structure.hierarchy.getStructuresWithSelection();
226
+ components = [];
227
+ for (_i = 0, sel_1 = sel; _i < sel_1.length; _i++) {
228
+ s = sel_1[_i];
229
+ components.push.apply(components, s.components);
230
+ }
231
+ if (components.length === 0)
232
+ return [2 /*return*/];
233
+ this.plugin.managers.structure.component.modifyByCurrentSelection(components, 'union');
234
+ console.log(components);
235
+ return [2 /*return*/];
236
+ });
237
+ }); },
238
+ changeProps: function (val) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
239
+ return tslib_1.__generator(this, function (_a) {
240
+ //todo 切换选中粒度
241
+ this.plugin.managers.interactivity.setProps({ granularity: val });
242
+ return [2 /*return*/];
243
+ });
244
+ }); },
245
+ select: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
246
+ var _a, _b, param, loci, repr, defaultParams, defaultValues, values, structures, updatedStructureData, comps, lastCompsIndex, recentRepComp, uniformColor, e_1_1;
247
+ var e_1, _c;
248
+ return tslib_1.__generator(this, function (_d) {
249
+ switch (_d.label) {
250
+ case 0:
251
+ _d.trys.push([0, 7, 8, 13]);
252
+ _a = tslib_1.__asyncValues(params.data);
253
+ _d.label = 1;
254
+ case 1: return [4 /*yield*/, _a.next()];
255
+ case 2:
256
+ if (!(_b = _d.sent(), !_b.done)) return [3 /*break*/, 6];
257
+ param = _b.value;
258
+ loci = this.getLociForParams([param], params.structureNumber);
259
+ if (loci_1.Loci.isEmpty(loci))
260
+ return [2 /*return*/];
261
+ // set default selection color to minimise change display
262
+ // this.visual.setColor({select: param.color ? param.color : { r:255, g:112, b:3}});
263
+ // apply selection
264
+ this.plugin.managers.interactivity.lociSelects.selectOnly({ loci: loci });
265
+ if (!(param.sideChain || param.representation)) return [3 /*break*/, 4];
266
+ repr = 'ball-and-stick';
267
+ if (param.representation)
268
+ repr = param.representation;
269
+ defaultParams = component_1.StructureComponentManager.getAddParams(this.plugin, { allowNone: false, hideSelection: true, checkExisting: true });
270
+ defaultValues = param_definition_1.ParamDefinition.getDefaultValues(defaultParams);
271
+ defaultValues.options = { label: 'selection-by-script', checkExisting: params.structureNumber ? false : true };
272
+ values = tslib_1.__assign(tslib_1.__assign({}, defaultValues), { representation: repr });
273
+ structures = this.plugin.managers.structure.hierarchy.getStructuresWithSelection();
274
+ return [4 /*yield*/, this.plugin.managers.structure.component.add(values, structures)];
275
+ case 3:
276
+ _d.sent();
277
+ // Apply uniform theme
278
+ if (param.representationColor) {
279
+ updatedStructureData = this.plugin.managers.structure.hierarchy.current.structures;
280
+ if (params.structureNumber) {
281
+ updatedStructureData = [this.plugin.managers.structure.hierarchy.current.structures[params.structureNumber - 1]];
282
+ }
283
+ comps = updatedStructureData[0].components;
284
+ lastCompsIndex = comps.length - 1;
285
+ recentRepComp = [comps[lastCompsIndex]];
286
+ uniformColor = param.representationColor ? this.normalizeColor(param.representationColor) : color_1.Color.fromRgb(255, 112, 3);
287
+ this.plugin.managers.structure.component.updateRepresentationsTheme(recentRepComp, { color: 'uniform', colorParams: { value: uniformColor } });
288
+ }
289
+ params.addedRepr = true;
290
+ _d.label = 4;
291
+ case 4:
292
+ // focus loci
293
+ if (param.focus)
294
+ this.plugin.managers.camera.focusLoci(loci);
295
+ _d.label = 5;
296
+ case 5: return [3 /*break*/, 1];
297
+ case 6: return [3 /*break*/, 13];
298
+ case 7:
299
+ e_1_1 = _d.sent();
300
+ e_1 = { error: e_1_1 };
301
+ return [3 /*break*/, 13];
302
+ case 8:
303
+ _d.trys.push([8, , 11, 12]);
304
+ if (!(_b && !_b.done && (_c = _a.return))) return [3 /*break*/, 10];
305
+ return [4 /*yield*/, _c.call(_a)];
306
+ case 9:
307
+ _d.sent();
308
+ _d.label = 10;
309
+ case 10: return [3 /*break*/, 12];
310
+ case 11:
311
+ if (e_1) throw e_1.error;
312
+ return [7 /*endfinally*/];
313
+ case 12: return [7 /*endfinally*/];
314
+ case 13:
315
+ // reset selection color
316
+ this.visual.reset({ selectColor: true });
317
+ // save selection params to optimise clear
318
+ this.selectedParams = params;
319
+ return [2 /*return*/];
320
+ }
321
+ });
322
+ }); },
323
+ clearSelection: function (structureNumber) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
324
+ var structIndex, selReprCells, _a, _b, c, selReprCells_1, selReprCells_1_1, selReprCell, e_2_1;
325
+ var e_2, _c;
326
+ return tslib_1.__generator(this, function (_d) {
327
+ switch (_d.label) {
328
+ case 0:
329
+ structIndex = structureNumber ? structureNumber - 1 : 0;
330
+ this.plugin.managers.interactivity.lociSelects.deselectAll();
331
+ // reset theme to default
332
+ if (this.selectedParams && this.selectedParams.nonSelectedColor) {
333
+ this.visual.reset({ theme: true });
334
+ }
335
+ // remove overpaints
336
+ return [4 /*yield*/, (0, structure_overpaint_1.clearStructureOverpaint)(this.plugin, this.plugin.managers.structure.hierarchy.current.structures[structIndex].components)];
337
+ case 1:
338
+ // remove overpaints
339
+ _d.sent();
340
+ if (!(this.selectedParams && this.selectedParams.addedRepr)) return [3 /*break*/, 15];
341
+ selReprCells = [];
342
+ for (_a = 0, _b = this.plugin.managers.structure.hierarchy.current.structures[structIndex].components; _a < _b.length; _a++) {
343
+ c = _b[_a];
344
+ if (c.cell && c.cell.params && c.cell.params.values && c.cell.params.values.label === 'selection-by-script')
345
+ selReprCells.push(c.cell);
346
+ }
347
+ if (!(selReprCells.length > 0)) return [3 /*break*/, 15];
348
+ _d.label = 2;
349
+ case 2:
350
+ _d.trys.push([2, 8, 9, 14]);
351
+ selReprCells_1 = tslib_1.__asyncValues(selReprCells);
352
+ _d.label = 3;
353
+ case 3: return [4 /*yield*/, selReprCells_1.next()];
354
+ case 4:
355
+ if (!(selReprCells_1_1 = _d.sent(), !selReprCells_1_1.done)) return [3 /*break*/, 7];
356
+ selReprCell = selReprCells_1_1.value;
357
+ return [4 /*yield*/, commands_1.PluginCommands.State.RemoveObject(this.plugin, { state: selReprCell.parent, ref: selReprCell.transform.ref })];
358
+ case 5:
359
+ _d.sent();
360
+ _d.label = 6;
361
+ case 6: return [3 /*break*/, 3];
362
+ case 7: return [3 /*break*/, 14];
363
+ case 8:
364
+ e_2_1 = _d.sent();
365
+ e_2 = { error: e_2_1 };
366
+ return [3 /*break*/, 14];
367
+ case 9:
368
+ _d.trys.push([9, , 12, 13]);
369
+ if (!(selReprCells_1_1 && !selReprCells_1_1.done && (_c = selReprCells_1.return))) return [3 /*break*/, 11];
370
+ return [4 /*yield*/, _c.call(selReprCells_1)];
371
+ case 10:
372
+ _d.sent();
373
+ _d.label = 11;
374
+ case 11: return [3 /*break*/, 13];
375
+ case 12:
376
+ if (e_2) throw e_2.error;
377
+ return [7 /*endfinally*/];
378
+ case 13: return [7 /*endfinally*/];
379
+ case 14:
380
+ ;
381
+ _d.label = 15;
382
+ case 15:
383
+ this.selectedParams = undefined;
384
+ return [2 /*return*/];
385
+ }
386
+ });
387
+ }); },
388
+ update: function (options, fullLoad) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
389
+ var param, settings, dataSource;
390
+ return tslib_1.__generator(this, function (_a) {
391
+ if (!options)
392
+ return [2 /*return*/];
393
+ // for(let param in this.initParams){
394
+ // if(options[param]) this.initParams[param] = options[param];
395
+ // }
396
+ this.initParams = tslib_1.__assign({}, spec_1.DefaultParams);
397
+ for (param in spec_1.DefaultParams) {
398
+ if (typeof options[param] !== 'undefined')
399
+ this.initParams[param] = options[param];
400
+ }
401
+ if (!this.initParams.moleculeId && !this.initParams.customData)
402
+ return [2 /*return*/, false];
403
+ if (this.initParams.customData && this.initParams.customData.url && !this.initParams.customData.format)
404
+ return [2 /*return*/, false];
405
+ this.plugin.customState.initParams = this.initParams;
406
+ // Set background colour
407
+ if (this.initParams.bgColor || this.initParams.lighting) {
408
+ settings = {};
409
+ if (this.initParams.bgColor)
410
+ settings.color = this.initParams.bgColor;
411
+ if (this.initParams.lighting)
412
+ settings.lighting = this.initParams.lighting;
413
+ this.canvas.applySettings(settings);
414
+ }
415
+ dataSource = this.getMoleculeSrcUrl();
416
+ if (dataSource) {
417
+ this.load({ url: dataSource.url, format: dataSource.format, assemblyId: this.initParams.assemblyId, isBinary: dataSource.isBinary }, fullLoad);
418
+ }
419
+ return [2 /*return*/];
420
+ });
421
+ }); },
422
+ visibility: function (data) {
423
+ if (!data)
424
+ return;
425
+ var refMap = {
426
+ polymer: 'structure-component-static-polymer',
427
+ het: 'structure-component-static-ligand',
428
+ water: 'structure-component-static-water',
429
+ carbs: 'structure-component-static-branched',
430
+ maps: 'volume-streaming-info'
431
+ };
432
+ for (var visual in data) {
433
+ var tagName = refMap[visual];
434
+ var componentRef = mol_state_2.StateSelection.findTagInSubtree(_this.plugin.state.data.tree, mol_state_1.StateTransform.RootRef, tagName);
435
+ if (componentRef) {
436
+ var compVisual = _this.plugin.state.data.select(componentRef)[0];
437
+ if (compVisual && compVisual.obj) {
438
+ var currentlyVisible = (compVisual.state && compVisual.state.isHidden) ? false : true;
439
+ if (data[visual] !== currentlyVisible) {
440
+ commands_1.PluginCommands.State.ToggleVisibility(_this.plugin, { state: _this.state, ref: componentRef });
441
+ }
442
+ }
443
+ }
444
+ }
445
+ },
446
+ toggleSpin: function (isSpinning, resetCamera) {
447
+ if (!_this.plugin.canvas3d)
448
+ return;
449
+ var trackball = _this.plugin.canvas3d.props.trackball;
450
+ var toggleSpinParam = trackball.animate.name === 'spin' ? { name: 'off', params: {} } : { name: 'spin', params: { speed: 1 } };
451
+ if (typeof isSpinning !== 'undefined') {
452
+ toggleSpinParam = { name: 'off', params: {} };
453
+ if (isSpinning)
454
+ toggleSpinParam = { name: 'spin', params: { speed: 1 } };
455
+ }
456
+ commands_1.PluginCommands.Canvas3D.SetSettings(_this.plugin, { settings: { trackball: tslib_1.__assign(tslib_1.__assign({}, trackball), { animate: toggleSpinParam }) } });
457
+ if (resetCamera)
458
+ commands_1.PluginCommands.Camera.Reset(_this.plugin, {});
459
+ },
460
+ focus: function (params, structureNumber) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
461
+ var loci;
462
+ return tslib_1.__generator(this, function (_a) {
463
+ loci = this.getLociForParams(params, structureNumber);
464
+ this.plugin.managers.camera.focusLoci(loci);
465
+ return [2 /*return*/];
466
+ });
467
+ }); },
468
+ setColor: function (param) {
469
+ if (!_this.plugin.canvas3d)
470
+ return;
471
+ var renderer = _this.plugin.canvas3d.props.renderer;
472
+ var rParam = {};
473
+ if (param.highlight)
474
+ rParam['highlightColor'] = _this.normalizeColor(param.highlight);
475
+ if (param.select)
476
+ rParam['selectColor'] = _this.normalizeColor(param.select);
477
+ commands_1.PluginCommands.Canvas3D.SetSettings(_this.plugin, { settings: { renderer: tslib_1.__assign(tslib_1.__assign({}, renderer), rParam) } });
478
+ if (rParam.highlightColor)
479
+ _this.isHighlightColorUpdated = true;
480
+ },
481
+ reset: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
482
+ var defaultTheme_1, componentGroups, renderer, rParam;
483
+ var _this = this;
484
+ return tslib_1.__generator(this, function (_a) {
485
+ switch (_a.label) {
486
+ case 0:
487
+ if (!params.camera) return [3 /*break*/, 2];
488
+ return [4 /*yield*/, commands_1.PluginCommands.Camera.Reset(this.plugin, { durationMs: 250 })];
489
+ case 1:
490
+ _a.sent();
491
+ _a.label = 2;
492
+ case 2:
493
+ if (params.theme) {
494
+ defaultTheme_1 = { color: this.initParams.alphafoldView ? 'plddt-confidence' : 'default' };
495
+ componentGroups = this.plugin.managers.structure.hierarchy.currentComponentGroups;
496
+ componentGroups.forEach(function (compGrp) {
497
+ _this.plugin.managers.structure.component.updateRepresentationsTheme(compGrp, defaultTheme_1);
498
+ });
499
+ }
500
+ if (params.highlightColor || params.selectColor) {
501
+ if (!this.plugin.canvas3d)
502
+ return [2 /*return*/];
503
+ renderer = this.plugin.canvas3d.props.renderer;
504
+ rParam = {};
505
+ if (params.highlightColor)
506
+ rParam['highlightColor'] = this.defaultRendererProps.highlightColor;
507
+ if (params.selectColor)
508
+ rParam['selectColor'] = this.defaultRendererProps.selectColor;
509
+ commands_1.PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: { renderer: tslib_1.__assign(tslib_1.__assign({}, renderer), rParam) } });
510
+ if (rParam.highlightColor)
511
+ this.isHighlightColorUpdated = false;
512
+ }
513
+ return [2 /*return*/];
514
+ }
515
+ });
516
+ }); }
517
+ };
518
+ this.ArbitrarySphereVisuals = {
519
+ 'arbitrary-sphere': function (ctx, getParams) { return (0, representation_2.UnitsRepresentation)('Arbitrary sphere mesh', ctx, getParams, _this.ArbitrarySphereVisual); }
520
+ };
521
+ this.ArbitrarySphereParams = tslib_1.__assign(tslib_1.__assign({}, units_visual_1.UnitsMeshParams), { x: param_definition_2.ParamDefinition.Numeric(0), y: param_definition_2.ParamDefinition.Numeric(0), z: param_definition_2.ParamDefinition.Numeric(0), l1: param_definition_2.ParamDefinition.Numeric(1), l2: param_definition_2.ParamDefinition.Numeric(1), l3: param_definition_2.ParamDefinition.Numeric(1) });
522
+ this.ArbitrarySphereVisual = function (materialId) {
523
+ return (0, units_visual_1.UnitsMeshVisual)({
524
+ defaultProps: param_definition_2.ParamDefinition.getDefaultValues(_this.ArbitrarySphereParams),
525
+ createGeometry: _this.createArbitrarySphereMesh,
526
+ createLocationIterator: function (structureGroup) {
527
+ return (0, location_iterator_1.LocationIterator)(1, structureGroup.group.units.length, 1, function () { return location_1.NullLocation; });
528
+ },
529
+ getLoci: function (pickingId, structureGroup, id) {
530
+ var objectId = pickingId.objectId;
531
+ if (objectId !== id)
532
+ return loci_1.EmptyLoci;
533
+ return (0, loci_2.DataLoci)('arbitrary-sphere-data-loci', void 0, [0], void 0, function () { return "Yo, I'm a sphere!"; });
534
+ },
535
+ eachLocation: function (loci, structureGroup, apply) {
536
+ if (loci.kind === 'data-loci' && loci.tag === 'arbitrary-sphere-data-loci') {
537
+ return apply(int_1.Interval.ofBounds(0, 1));
538
+ }
539
+ return false;
540
+ },
541
+ setUpdateState: function (state, newProps, currentProps) {
542
+ state.createGeometry = (newProps.x !== currentProps.x ||
543
+ newProps.y !== currentProps.y ||
544
+ newProps.z !== currentProps.z ||
545
+ newProps.l1 !== currentProps.l1 ||
546
+ newProps.l2 !== currentProps.l2 ||
547
+ newProps.l3 !== currentProps.l3);
548
+ }
549
+ }, materialId);
550
+ };
551
+ this.ConfalPyramidsRepresentation = function (ctx, getParams) {
552
+ return representation_3.Representation.createMulti('Confal Pyramids', ctx, getParams, representation_2.StructureRepresentationStateBuilder, _this.ArbitrarySphereVisuals);
553
+ };
554
+ this.ArbitrarySphereRepresentationProvider = (0, representation_2.StructureRepresentationProvider)({
555
+ name: 'arbitrary-sphere',
556
+ label: 'Arbitrary sphere',
557
+ description: 'Displays an arbitrary sphere at given coordinates',
558
+ factory: this.ConfalPyramidsRepresentation,
559
+ getParams: function (ctx, structure) { return param_definition_2.ParamDefinition.clone(_this.ArbitrarySphereParams); },
560
+ defaultValues: param_definition_2.ParamDefinition.getDefaultValues(this.ArbitrarySphereParams),
561
+ defaultColorTheme: { name: 'uniform' },
562
+ defaultSizeTheme: { name: 'uniform' },
563
+ isApplicable: function (structure) { return true; }
564
+ });
565
+ this.createArbitrarySphereMesh = function (ctx, unit, structure, theme, props, mesh) {
566
+ var mb = mesh_builder_1.MeshBuilder.createState(16, 16, mesh);
567
+ mb.currentGroup = 0;
568
+ var min = (0, linear_algebra_1.Vec3)();
569
+ var max = (0, linear_algebra_1.Vec3)();
570
+ min[0] = props.x - (props.l1 / 2);
571
+ min[1] = props.y - (props.l2 / 2);
572
+ min[2] = props.z - (props.l3 / 2);
573
+ max[0] = props.x + (props.l1 / 2);
574
+ max[1] = props.y + (props.l2 / 2);
575
+ max[2] = props.z + (props.l3 / 2);
576
+ // addSphere(mb, position, props.radius, 2)
577
+ (0, box_1.addBoundingBox)(mb, { min: min, max: max }, 0.1, 1, 1);
578
+ return mesh_builder_1.MeshBuilder.getMesh(mb);
579
+ };
580
+ }
581
+ PDBeMolstarPlugin.prototype.render = function (target, options) {
582
+ var _a;
583
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
584
+ var param, defaultPDBeSpec, pdbePluginSpec, _b, settings, dataSource;
585
+ return tslib_1.__generator(this, function (_c) {
586
+ switch (_c.label) {
587
+ case 0:
588
+ if (!options)
589
+ return [2 /*return*/];
590
+ this.initParams = tslib_1.__assign({}, spec_1.DefaultParams);
591
+ for (param in spec_1.DefaultParams) {
592
+ if (typeof options[param] !== 'undefined')
593
+ this.initParams[param] = options[param];
594
+ }
595
+ defaultPDBeSpec = (0, spec_1.DefaultPluginUISpec)();
596
+ pdbePluginSpec = {
597
+ actions: tslib_1.__spreadArray([], defaultPDBeSpec.actions || [], true),
598
+ behaviors: tslib_1.__spreadArray([], defaultPDBeSpec.behaviors, true),
599
+ animations: tslib_1.__spreadArray([], defaultPDBeSpec.animations || [], true),
600
+ customParamEditors: defaultPDBeSpec.customParamEditors,
601
+ config: defaultPDBeSpec.config
602
+ };
603
+ if (!this.initParams.ligandView && !this.initParams.superposition && this.initParams.selectInteraction) {
604
+ pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(structure_focus_representation_1.StructureFocusRepresentation));
605
+ }
606
+ if (this.initParams.superposition) {
607
+ pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(superposition_focus_representation_1.SuperpositionFocusRepresentation), spec_2.PluginSpec.Behavior(behavior_2.MAQualityAssessment, { autoAttach: true, showTooltip: true }));
608
+ }
609
+ // Add custom properties
610
+ if (this.initParams.domainAnnotation) {
611
+ pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(behavior_1.PDBeDomainAnnotations, { autoAttach: true, showTooltip: false }));
612
+ }
613
+ if (this.initParams.validationAnnotation) {
614
+ pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(pdbe_1.PDBeStructureQualityReport, { autoAttach: true, showTooltip: false }));
615
+ }
616
+ pdbePluginSpec.layout = {
617
+ initial: {
618
+ isExpanded: this.initParams.landscape ? false : this.initParams.expanded,
619
+ showControls: !this.initParams.hideControls
620
+ }
621
+ };
622
+ pdbePluginSpec.components = {
623
+ controls: {
624
+ left: pdbe_left_panel_1.LeftPanelControls,
625
+ // right: DefaultStructureTools,
626
+ top: 'none',
627
+ bottom: 'none'
628
+ },
629
+ viewport: {
630
+ controls: pdbe_viewport_controls_1.PDBeViewportControls,
631
+ view: this.initParams.superposition ? superposition_viewport_1.SuperpostionViewport : void 0
632
+ },
633
+ remoteState: 'none',
634
+ structureTools: this.initParams.superposition ? pdbe_structure_controls_1.PDBeSuperpositionStructureTools : this.initParams.ligandView ? pdbe_structure_controls_1.PDBeLigandViewStructureTools : pdbe_structure_controls_1.PDBeStructureTools
635
+ };
636
+ if (this.initParams.alphafoldView) {
637
+ pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(behavior_2.MAQualityAssessment, { autoAttach: true, showTooltip: true }));
638
+ }
639
+ if (this.initParams.sequencePanel) {
640
+ if ((_a = pdbePluginSpec.components.controls) === null || _a === void 0 ? void 0 : _a.top)
641
+ delete pdbePluginSpec.components.controls.top;
642
+ }
643
+ pdbePluginSpec.config = [
644
+ [
645
+ config_1.PluginConfig.Structure.DefaultRepresentationPresetParams,
646
+ {
647
+ theme: {
648
+ globalName: (this.initParams.alphafoldView) ? 'plddt-confidence' : undefined,
649
+ carbonColor: { name: 'element-symbol', params: {} },
650
+ focus: {
651
+ name: 'element-symbol',
652
+ params: { carbonColor: { name: 'element-symbol', params: {} } }
653
+ }
654
+ }
655
+ }
656
+ ]
657
+ ];
658
+ element_symbol_1.ElementSymbolColorThemeParams.carbonColor.defaultValue = { name: 'element-symbol', params: {} };
659
+ // Add animation props
660
+ if (!this.initParams.ligandView && !this.initParams.superposition) {
661
+ pdbePluginSpec['animations'] = [model_index_1.AnimateModelIndex, camera_spin_1.AnimateCameraSpin, camera_rock_1.AnimateCameraRock, state_snapshots_1.AnimateStateSnapshots, assembly_unwind_1.AnimateAssemblyUnwind, spin_structure_1.AnimateStructureSpin, state_interpolation_1.AnimateStateInterpolation];
662
+ pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(mp4_export_1.Mp4Export));
663
+ pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(geo_export_1.GeometryExport));
664
+ }
665
+ if (this.initParams.hideCanvasControls) {
666
+ if (this.initParams.hideCanvasControls.indexOf('expand') > -1)
667
+ pdbePluginSpec.config.push([config_1.PluginConfig.Viewport.ShowExpand, false]);
668
+ if (this.initParams.hideCanvasControls.indexOf('selection') > -1)
669
+ pdbePluginSpec.config.push([config_1.PluginConfig.Viewport.ShowSelectionMode, false]);
670
+ if (this.initParams.hideCanvasControls.indexOf('animation') > -1)
671
+ pdbePluginSpec.config.push([config_1.PluginConfig.Viewport.ShowAnimation, false]);
672
+ }
673
+ ;
674
+ if (this.initParams.landscape && pdbePluginSpec.layout && pdbePluginSpec.layout.initial)
675
+ pdbePluginSpec.layout.initial['controlsDisplay'] = 'landscape';
676
+ if (this.initParams.reactive && pdbePluginSpec.layout && pdbePluginSpec.layout.initial)
677
+ pdbePluginSpec.layout.initial['controlsDisplay'] = 'reactive';
678
+ // override default event bindings
679
+ if (this.initParams.selectBindings) {
680
+ pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(representation_1.SelectLoci, { bindings: this.initParams.selectBindings }));
681
+ }
682
+ if (this.initParams.focusBindings) {
683
+ pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(camera_1.FocusLoci, { bindings: this.initParams.focusBindings }));
684
+ }
685
+ this.targetElement = typeof target === 'string' ? document.getElementById(target) : target;
686
+ // Create/ Initialise Plugin
687
+ _b = this;
688
+ return [4 /*yield*/, (0, spec_1.createPluginUI)(this.targetElement, pdbePluginSpec)];
689
+ case 1:
690
+ // Create/ Initialise Plugin
691
+ _b.plugin = _c.sent();
692
+ this.plugin.customState.initParams = tslib_1.__assign({}, this.initParams);
693
+ this.plugin.customState.events = {
694
+ segmentUpdate: this._ev(),
695
+ superpositionInit: this._ev(),
696
+ isBusy: this._ev()
697
+ };
698
+ // Set background colour
699
+ if (this.initParams.bgColor || this.initParams.lighting) {
700
+ settings = {};
701
+ if (this.initParams.bgColor)
702
+ settings.color = this.initParams.bgColor;
703
+ if (this.initParams.lighting)
704
+ settings.lighting = this.initParams.lighting;
705
+ this.canvas.applySettings(settings);
706
+ }
707
+ // Set selection granularity
708
+ if (this.initParams.granularity) {
709
+ this.plugin.managers.interactivity.setProps({ granularity: this.initParams.granularity });
710
+ }
711
+ // Set default highlight and selection colors
712
+ if (this.initParams.highlightColor || this.initParams.selectColor) {
713
+ this.visual.setColor({ highlight: this.initParams.highlightColor, select: this.initParams.selectColor });
714
+ }
715
+ // Save renderer defaults
716
+ this.defaultRendererProps = tslib_1.__assign({}, this.plugin.canvas3d.props.renderer);
717
+ if (this.initParams.superposition) {
718
+ // Set left panel tab
719
+ this.plugin.behaviors.layout.leftPanelTabName.next('segments');
720
+ // Initialise superposition
721
+ (0, superposition_1.initSuperposition)(this.plugin);
722
+ }
723
+ else {
724
+ // Collapse left panel and set left panel tab to none
725
+ commands_1.PluginCommands.Layout.Update(this.plugin, { state: { regionState: tslib_1.__assign(tslib_1.__assign({}, this.plugin.layout.state.regionState), { left: 'collapsed' }) } });
726
+ this.plugin.behaviors.layout.leftPanelTabName.next('none');
727
+ dataSource = this.getMoleculeSrcUrl();
728
+ if (dataSource) {
729
+ this.load({ url: dataSource.url, format: dataSource.format, assemblyId: this.initParams.assemblyId, isBinary: dataSource.isBinary, pdb_string: dataSource.pdb_string });
730
+ }
731
+ // Binding to other PDB Component events
732
+ if (this.initParams.subscribeEvents) {
733
+ (0, subscribe_events_1.subscribeToComponentEvents)(this);
734
+ }
735
+ // Event handling
736
+ custom_events_1.CustomEvents.add(this.plugin, this.targetElement);
737
+ }
738
+ this.plugin.representation.structure.registry.add(this.ArbitrarySphereRepresentationProvider);
739
+ return [2 /*return*/];
740
+ }
741
+ });
742
+ });
743
+ };
744
+ PDBeMolstarPlugin.prototype.getMoleculeSrcUrl = function () {
745
+ var supportedFormats = ['mmcif', 'pdb', 'sdf'];
746
+ var id = this.initParams.moleculeId;
747
+ // if(!id && !this.initParams.customData){
748
+ // throw new Error(`Mandatory parameters missing!`);
749
+ // }
750
+ var query = 'full';
751
+ var sep = '?';
752
+ if (this.initParams.ligandView) {
753
+ var queryParams = ['data_source=pdb-h'];
754
+ if (!this.initParams.ligandView.label_comp_id_list) {
755
+ if (this.initParams.ligandView.label_comp_id) {
756
+ queryParams.push('label_comp_id=' + this.initParams.ligandView.label_comp_id);
757
+ }
758
+ else if (this.initParams.ligandView.auth_seq_id) {
759
+ queryParams.push('auth_seq_id=' + this.initParams.ligandView.auth_seq_id);
760
+ }
761
+ if (this.initParams.ligandView.auth_asym_id)
762
+ queryParams.push('auth_asym_id=' + this.initParams.ligandView.auth_asym_id);
763
+ }
764
+ query = 'residueSurroundings?' + queryParams.join('&');
765
+ sep = '&';
766
+ }
767
+ var url = "".concat(this.initParams.pdbeUrl, "model-server/v1/").concat(id, "/").concat(query).concat(sep, "encoding=").concat(this.initParams.encoding).concat(this.initParams.lowPrecisionCoords ? '&lowPrecisionCoords=1' : '');
768
+ var isBinary = this.initParams.encoding === 'bcif' ? true : false;
769
+ var format = 'mmcif';
770
+ var pdb_string = undefined;
771
+ if (this.initParams.customData) {
772
+ if (!this.initParams.customData.url && !this.initParams.customData.pdb_string) {
773
+ throw new Error("Provide all custom data parameters");
774
+ }
775
+ if (!this.initParams.customData.format) {
776
+ throw new Error("Provide all custom data parameters");
777
+ }
778
+ url = this.initParams.customData.url;
779
+ format = this.initParams.customData.format;
780
+ if (format === 'cif' || format === 'bcif')
781
+ format = 'mmcif';
782
+ // Validate supported format
783
+ if (supportedFormats.indexOf(format) === -1) {
784
+ throw new Error("".concat(format, " not supported."));
785
+ }
786
+ pdb_string = this.initParams.customData.pdb_string;
787
+ isBinary = this.initParams.customData.binary ? this.initParams.customData.binary : false;
788
+ }
789
+ else {
790
+ console.log('no custom data');
791
+ return undefined;
792
+ }
793
+ return {
794
+ url: url,
795
+ format: format,
796
+ isBinary: isBinary,
797
+ pdb_string: pdb_string
798
+ };
799
+ };
800
+ Object.defineProperty(PDBeMolstarPlugin.prototype, "state", {
801
+ get: function () {
802
+ return this.plugin.state.data;
803
+ },
804
+ enumerable: false,
805
+ configurable: true
806
+ });
807
+ PDBeMolstarPlugin.prototype.add_mouse_event = function (func) {
808
+ this.plugin.behaviors.interaction.click.subscribe(function (e) {
809
+ func(e);
810
+ });
811
+ };
812
+ PDBeMolstarPlugin.prototype.add_shape = function (structure, params) {
813
+ // params: {x: -10, y: -11, z: 10, radius: 8}
814
+ Object.assign(params, { color: names_1.ColorNames.orange });
815
+ return this.plugin.builders.structure.representation.addRepresentation(structure, {
816
+ type: 'arbitrary-sphere',
817
+ typeParams: params,
818
+ colorParams: { value: params.color }
819
+ });
820
+ };
821
+ PDBeMolstarPlugin.prototype.remove_shape = function (selector) {
822
+ var _a, _b;
823
+ selector.obj.data.repr.destroy();
824
+ (_a = this.plugin.canvas3d) === null || _a === void 0 ? void 0 : _a.remove(selector.obj.data.repr);
825
+ (_b = this.plugin.canvas3d) === null || _b === void 0 ? void 0 : _b.update();
826
+ };
827
+ PDBeMolstarPlugin.prototype.get_ligand_queries = function (pdb_string) {
828
+ var ligand_info_list = this.parse_ligand_info(pdb_string);
829
+ var queries = [];
830
+ try {
831
+ for (var i = 0; i < ligand_info_list.length; i++) {
832
+ queries.push(this.ownResidueQuery(ligand_info_list[i].chain_name, [ligand_info_list[i].residue_name], ligand_info_list[i].residue_id, 'Ligand/Non-standard Residue', 200));
833
+ }
834
+ return queries;
835
+ }
836
+ catch (e) {
837
+ console.error('e', e);
838
+ }
839
+ };
840
+ PDBeMolstarPlugin.prototype.ownChainQuery = function (chain_name, category, priority) {
841
+ if (priority === void 0) {
842
+ priority = 0;
843
+ }
844
+ var description = chain_name;
845
+ return (0, structure_selection_query_1.StructureSelectionQuery)(description, builder_1.MolScriptBuilder.struct.modifier.union([
846
+ builder_1.MolScriptBuilder.struct.generator.atomGroups({
847
+ 'chain-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.ammp('auth_asym_id'), chain_name]),
848
+ })
849
+ ]), { category: category, priority: priority, description: description });
850
+ };
851
+ PDBeMolstarPlugin.prototype.get_chain_queries = function (pdb_string) {
852
+ var chain_info_list = this.parse_chain_info(pdb_string);
853
+ var queries = [];
854
+ try {
855
+ for (var i = 0; i < chain_info_list.length; i++) {
856
+ queries.push(this.ownChainQuery(chain_info_list[i].chain_main_name, 'Chain', 200));
857
+ }
858
+ return queries;
859
+ }
860
+ catch (e) {
861
+ console.error('e', e);
862
+ return queries;
863
+ }
864
+ };
865
+ PDBeMolstarPlugin.prototype.get_ligand_query_name = function (query) {
866
+ var label = query.label;
867
+ var match = label.match(/\[(.*?)\]/);
868
+ var extracted = match ? match[1] : null;
869
+ return extracted;
870
+ };
871
+ PDBeMolstarPlugin.prototype.change_repr = function (selector, params, state) {
872
+ var _a, _b;
873
+ if (params === void 0) { params = undefined; }
874
+ if (state === void 0) { state = undefined; }
875
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
876
+ var s, e_3;
877
+ return tslib_1.__generator(this, function (_c) {
878
+ switch (_c.label) {
879
+ case 0:
880
+ s = selector;
881
+ if (!params) return [3 /*break*/, 4];
882
+ if (selector.obj.data.repr) {
883
+ selector.obj.data.repr.destroy();
884
+ (_a = this.plugin.canvas3d) === null || _a === void 0 ? void 0 : _a.update();
885
+ }
886
+ _c.label = 1;
887
+ case 1:
888
+ _c.trys.push([1, 3, , 4]);
889
+ return [4 /*yield*/, this.plugin.builders.structure.representation.addRepresentation(selector, params)];
890
+ case 2:
891
+ s = _c.sent();
892
+ return [3 /*break*/, 4];
893
+ case 3:
894
+ e_3 = _c.sent();
895
+ console.log(e_3);
896
+ return [3 /*break*/, 4];
897
+ case 4:
898
+ if (state) {
899
+ s.obj.data.repr.setState(state);
900
+ }
901
+ (_b = this.plugin.canvas3d) === null || _b === void 0 ? void 0 : _b.update();
902
+ return [2 /*return*/, s];
903
+ }
904
+ });
905
+ });
906
+ };
907
+ PDBeMolstarPlugin.prototype.add_repr_on_select_expression = function (structure, select_expression, label, params, comp) {
908
+ if (params === void 0) { params = { type: 'ball-and-stick' }; }
909
+ if (comp === void 0) { comp = undefined; }
910
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
911
+ var component, repr_selector;
912
+ return tslib_1.__generator(this, function (_a) {
913
+ switch (_a.label) {
914
+ case 0:
915
+ component = undefined;
916
+ if (!!comp) return [3 /*break*/, 2];
917
+ return [4 /*yield*/, this.plugin.builders.structure.tryCreateComponentFromExpression(structure, select_expression, label, { 'label': label })];
918
+ case 1:
919
+ component = _a.sent();
920
+ return [3 /*break*/, 3];
921
+ case 2:
922
+ component = comp;
923
+ _a.label = 3;
924
+ case 3: return [4 /*yield*/, this.plugin.builders.structure.representation.addRepresentation(component, params)];
925
+ case 4:
926
+ repr_selector = _a.sent();
927
+ if (!comp) {
928
+ return [2 /*return*/, { 'comp': component, 'selector': repr_selector }];
929
+ }
930
+ else {
931
+ return [2 /*return*/, { 'comp': undefined, 'selector': repr_selector }];
932
+ }
933
+ return [2 /*return*/];
934
+ }
935
+ });
936
+ });
937
+ };
938
+ PDBeMolstarPlugin.prototype.highlight_and_focuson_query = function (structure, query) {
939
+ var _this = this;
940
+ var data = structure.data;
941
+ if (!data)
942
+ return;
943
+ this.plugin.runTask(mol_task_1.Task.create('Structure Selection', function (runtime) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
944
+ var selection, loci;
945
+ return tslib_1.__generator(this, function (_a) {
946
+ switch (_a.label) {
947
+ case 0: return [4 /*yield*/, query.getSelection(this.plugin, runtime, structure.data)];
948
+ case 1:
949
+ selection = _a.sent();
950
+ loci = structure_1.StructureSelection.toLociWithSourceUnits(selection);
951
+ this.plugin.managers.interactivity.lociHighlights.highlightOnly({ loci: loci });
952
+ this.plugin.managers.camera.focusLoci(loci);
953
+ return [2 /*return*/];
954
+ }
955
+ });
956
+ }); }));
957
+ };
958
+ PDBeMolstarPlugin.prototype.createLigandStructure = function (isBranched) {
959
+ var e_4, _a;
960
+ var _b;
961
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
962
+ var _c, _d, comp, e_4_1, structure, ligandQuery, ligandVis, ligandSurr, ligRef, cell, ligLoci;
963
+ var _this = this;
964
+ return tslib_1.__generator(this, function (_e) {
965
+ switch (_e.label) {
966
+ case 0:
967
+ if (this.assemblyRef === '')
968
+ return [2 /*return*/];
969
+ _e.label = 1;
970
+ case 1:
971
+ _e.trys.push([1, 7, 8, 13]);
972
+ _c = tslib_1.__asyncValues(this.plugin.managers.structure.hierarchy.currentComponentGroups);
973
+ _e.label = 2;
974
+ case 2: return [4 /*yield*/, _c.next()];
975
+ case 3:
976
+ if (!(_d = _e.sent(), !_d.done)) return [3 /*break*/, 6];
977
+ comp = _d.value;
978
+ return [4 /*yield*/, commands_1.PluginCommands.State.RemoveObject(this.plugin, { state: comp[0].cell.parent, ref: comp[0].cell.transform.ref, removeParentGhosts: true })];
979
+ case 4:
980
+ _e.sent();
981
+ _e.label = 5;
982
+ case 5: return [3 /*break*/, 2];
983
+ case 6: return [3 /*break*/, 13];
984
+ case 7:
985
+ e_4_1 = _e.sent();
986
+ e_4 = { error: e_4_1 };
987
+ return [3 /*break*/, 13];
988
+ case 8:
989
+ _e.trys.push([8, , 11, 12]);
990
+ if (!(_d && !_d.done && (_a = _c.return))) return [3 /*break*/, 10];
991
+ return [4 /*yield*/, _a.call(_c)];
992
+ case 9:
993
+ _e.sent();
994
+ _e.label = 10;
995
+ case 10: return [3 /*break*/, 12];
996
+ case 11:
997
+ if (e_4) throw e_4.error;
998
+ return [7 /*endfinally*/];
999
+ case 12: return [7 /*endfinally*/];
1000
+ case 13:
1001
+ structure = this.state.select(this.assemblyRef)[0];
1002
+ if (isBranched) {
1003
+ ligandQuery = helpers_1.LigandView.branchedQuery((_b = this.initParams.ligandView) === null || _b === void 0 ? void 0 : _b.label_comp_id_list);
1004
+ }
1005
+ else {
1006
+ ligandQuery = helpers_1.LigandView.query(this.initParams.ligandView);
1007
+ }
1008
+ return [4 /*yield*/, this.plugin.builders.structure.tryCreateComponentFromExpression(structure, ligandQuery.core, 'pivot', { label: 'Ligand' })];
1009
+ case 14:
1010
+ ligandVis = _e.sent();
1011
+ if (!ligandVis) return [3 /*break*/, 16];
1012
+ return [4 /*yield*/, this.plugin.builders.structure.representation.addRepresentation(ligandVis, { type: 'ball-and-stick', color: 'element-symbol', colorParams: { carbonColor: { name: 'element-symbol', params: {} } }, size: 'uniform', sizeParams: { value: 2.5 } }, { tag: 'ligand-vis' })];
1013
+ case 15:
1014
+ _e.sent();
1015
+ _e.label = 16;
1016
+ case 16: return [4 /*yield*/, this.plugin.builders.structure.tryCreateComponentFromExpression(structure, ligandQuery.surroundings, 'rest', { label: 'Surroundings' })];
1017
+ case 17:
1018
+ ligandSurr = _e.sent();
1019
+ if (!ligandSurr) return [3 /*break*/, 19];
1020
+ return [4 /*yield*/, this.plugin.builders.structure.representation.addRepresentation(ligandSurr, { type: 'ball-and-stick', color: 'element-symbol', colorParams: { carbonColor: { name: 'element-symbol', params: {} } }, size: 'uniform', sizeParams: { value: 0.8 } })];
1021
+ case 18:
1022
+ _e.sent();
1023
+ _e.label = 19;
1024
+ case 19:
1025
+ ligRef = mol_state_2.StateSelection.findTagInSubtree(this.plugin.state.data.tree, mol_state_1.StateTransform.RootRef, 'ligand-vis');
1026
+ if (!ligRef)
1027
+ return [2 /*return*/];
1028
+ cell = this.plugin.state.data.cells.get(ligRef);
1029
+ if (cell) {
1030
+ ligLoci = cell.obj.data.repr.getLoci();
1031
+ this.plugin.managers.structure.focus.setFromLoci(ligLoci);
1032
+ setTimeout(function () {
1033
+ var _a;
1034
+ // focus-add is not handled in camera behavior, doing it here
1035
+ var current = (_a = _this.plugin.managers.structure.focus.current) === null || _a === void 0 ? void 0 : _a.loci;
1036
+ if (current)
1037
+ _this.plugin.managers.camera.focusLoci(current);
1038
+ }, 500);
1039
+ }
1040
+ return [2 /*return*/];
1041
+ }
1042
+ });
1043
+ });
1044
+ };
1045
+ PDBeMolstarPlugin.prototype.load = function (_a, fullLoad) {
1046
+ 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, _e = _a.pdb_string, pdb_string = _e === void 0 ? '' : _e, _f = _a.if_render, if_render = _f === void 0 ? true : _f;
1047
+ if (fullLoad === void 0) { fullLoad = true; }
1048
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1049
+ var isHetView, downloadOptions, isBranchedView, data, trajectory, _g, _h, asm, defaultMapParams, pdbeMapParams, pivotIndex, pivot;
1050
+ return tslib_1.__generator(this, function (_j) {
1051
+ switch (_j.label) {
1052
+ case 0:
1053
+ if (fullLoad)
1054
+ this.clear();
1055
+ isHetView = this.initParams.ligandView ? true : false;
1056
+ downloadOptions = void 0;
1057
+ isBranchedView = false;
1058
+ if (this.initParams.ligandView && this.initParams.ligandView.label_comp_id_list) {
1059
+ isBranchedView = true;
1060
+ downloadOptions = { body: JSON.stringify(this.initParams.ligandView.label_comp_id_list), headers: [['Content-type', 'application/json']] };
1061
+ }
1062
+ data = null;
1063
+ if (!pdb_string) return [3 /*break*/, 2];
1064
+ return [4 /*yield*/, this.plugin.builders.data.rawData({ data: pdb_string }, { state: { isGhost: true } })];
1065
+ case 1:
1066
+ data = _j.sent();
1067
+ return [3 /*break*/, 4];
1068
+ case 2: return [4 /*yield*/, this.plugin.builders.data.download({ url: assets_1.Asset.Url(url, downloadOptions), isBinary: isBinary }, { state: { isGhost: true } })];
1069
+ case 3:
1070
+ data = _j.sent();
1071
+ _j.label = 4;
1072
+ case 4: return [4 /*yield*/, this.plugin.builders.structure.parseTrajectory(data, format)];
1073
+ case 5:
1074
+ trajectory = _j.sent();
1075
+ _g = this;
1076
+ return [4 /*yield*/, this.plugin.builders.structure.createModel(trajectory)];
1077
+ case 6:
1078
+ _g.model = _j.sent();
1079
+ _h = this;
1080
+ return [4 /*yield*/, this.plugin.builders.structure.createStructure(this.model, { name: 'model', params: {} })];
1081
+ case 7:
1082
+ _h.structure = _j.sent();
1083
+ if (!if_render) return [3 /*break*/, 13];
1084
+ if (!!isHetView) return [3 /*break*/, 9];
1085
+ return [4 /*yield*/, this.plugin.builders.structure.hierarchy.applyPreset(trajectory, this.initParams.defaultPreset, {
1086
+ structure: assemblyId ? (assemblyId === 'preferred') ? void 0 : { name: 'assembly', params: { id: assemblyId } } : { name: 'model', params: {} },
1087
+ showUnitcell: false,
1088
+ representationPreset: 'auto'
1089
+ })];
1090
+ case 8:
1091
+ _j.sent();
1092
+ if (this.initParams.hideStructure || this.initParams.visualStyle) {
1093
+ this.applyVisualParams();
1094
+ }
1095
+ _j.label = 9;
1096
+ case 9:
1097
+ // show selection if param is set
1098
+ if (this.initParams.selection) {
1099
+ this.visual.select(this.initParams.selection);
1100
+ }
1101
+ if (!this.initParams.loadMaps) return [3 /*break*/, 11];
1102
+ if (this.assemblyRef === '')
1103
+ return [2 /*return*/];
1104
+ asm = this.state.select(this.assemblyRef)[0].obj;
1105
+ defaultMapParams = transformers_1.InitVolumeStreaming.createDefaultParams(asm, this.plugin);
1106
+ pdbeMapParams = helpers_1.PDBeVolumes.mapParams(defaultMapParams, this.initParams.mapSettings, '');
1107
+ if (!pdbeMapParams) return [3 /*break*/, 11];
1108
+ return [4 /*yield*/, this.plugin.runTask(this.state.applyAction(transformers_1.InitVolumeStreaming, pdbeMapParams, this.assemblyRef))];
1109
+ case 10:
1110
+ _j.sent();
1111
+ if (pdbeMapParams.method !== 'em' && !this.initParams.ligandView)
1112
+ helpers_1.PDBeVolumes.displayUsibilityMessage(this.plugin);
1113
+ _j.label = 11;
1114
+ case 11:
1115
+ if (!isHetView) return [3 /*break*/, 13];
1116
+ return [4 /*yield*/, this.createLigandStructure(isBranchedView)];
1117
+ case 12:
1118
+ _j.sent();
1119
+ _j.label = 13;
1120
+ case 13:
1121
+ pivotIndex = this.plugin.managers.structure.hierarchy.selection.structures.length - 1;
1122
+ pivot = this.plugin.managers.structure.hierarchy.selection.structures[pivotIndex];
1123
+ if (pivot && pivot.cell.parent)
1124
+ this.assemblyRef = pivot.cell.transform.ref;
1125
+ this.events.loadComplete.next(true);
1126
+ return [2 /*return*/];
1127
+ }
1128
+ });
1129
+ });
1130
+ };
1131
+ PDBeMolstarPlugin.prototype.getLociForParams = function (params, structureNumber) {
1132
+ var assemblyRef = this.assemblyRef;
1133
+ if (structureNumber) {
1134
+ assemblyRef = this.plugin.managers.structure.hierarchy.current.structures[structureNumber - 1].cell.transform.ref;
1135
+ }
1136
+ if (assemblyRef === '')
1137
+ return loci_1.EmptyLoci;
1138
+ var data = this.plugin.state.data.select(assemblyRef)[0].obj.data;
1139
+ if (!data)
1140
+ return loci_1.EmptyLoci;
1141
+ return helpers_1.QueryHelper.getInteractivityLoci(params, data);
1142
+ };
1143
+ PDBeMolstarPlugin.prototype.getLociByPLDDT = function (score, structureNumber) {
1144
+ var assemblyRef = this.assemblyRef;
1145
+ if (structureNumber) {
1146
+ assemblyRef = this.plugin.managers.structure.hierarchy.current.structures[structureNumber - 1].cell.transform.ref;
1147
+ }
1148
+ if (assemblyRef === '')
1149
+ return loci_1.EmptyLoci;
1150
+ var data = this.plugin.state.data.select(assemblyRef)[0].obj.data;
1151
+ if (!data)
1152
+ return loci_1.EmptyLoci;
1153
+ return helpers_1.AlphafoldView.getLociByPLDDT(score, data);
1154
+ };
1155
+ PDBeMolstarPlugin.prototype.normalizeColor = function (colorVal, defaultColor) {
1156
+ var color = color_1.Color.fromRgb(170, 170, 170);
1157
+ try {
1158
+ if (typeof colorVal.r !== 'undefined') {
1159
+ color = color_1.Color.fromRgb(colorVal.r, colorVal.g, colorVal.b);
1160
+ }
1161
+ else if (colorVal[0] === '#') {
1162
+ color = (0, color_1.Color)(Number("0x".concat(colorVal.substr(1))));
1163
+ }
1164
+ else {
1165
+ color = (0, color_1.Color)(colorVal);
1166
+ }
1167
+ }
1168
+ catch (e) {
1169
+ if (defaultColor)
1170
+ color = defaultColor;
1171
+ }
1172
+ return color;
1173
+ };
1174
+ PDBeMolstarPlugin.prototype.clear = function () {
1175
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1176
+ return tslib_1.__generator(this, function (_a) {
1177
+ this.plugin.clear();
1178
+ this.assemblyRef = '';
1179
+ this.selectedParams = void 0;
1180
+ this.isHighlightColorUpdated = false;
1181
+ this.isSelectedColorUpdated = false;
1182
+ return [2 /*return*/];
1183
+ });
1184
+ });
1185
+ };
1186
+ PDBeMolstarPlugin.prototype.parse_ligand_info = function (pdb_string) {
1187
+ // 解析所有的配体信息
1188
+ // chain_name
1189
+ // name
1190
+ // count
1191
+ var ret_list = [];
1192
+ var lines = pdb_string.split('\n');
1193
+ var ligand_dict = {};
1194
+ for (var _a = 0, lines_1 = lines; _a < lines_1.length; _a++) {
1195
+ var line = lines_1[_a];
1196
+ if (line.startsWith('HETATM')) {
1197
+ var ligand_name = line.substr(17, 3).trim();
1198
+ if (ligand_name === 'HOH') {
1199
+ continue;
1200
+ }
1201
+ var residue_id = line.substr(22, 5).trim();
1202
+ var chain_name = line.substr(21, 1).trim();
1203
+ var x = line.substr(30, 8).trim();
1204
+ var y = line.substr(38, 8).trim();
1205
+ var z = line.substr(46, 8).trim();
1206
+ if (ligand_dict[chain_name + ':' + ligand_name + ':' + residue_id] === undefined) {
1207
+ ligand_dict[chain_name + ':' + ligand_name + ':' + residue_id] = {
1208
+ 'chain_name': chain_name,
1209
+ 'name': chain_name + ':' + ligand_name + ':' + residue_id,
1210
+ 'residue_name': ligand_name,
1211
+ 'residue_id': residue_id,
1212
+ 'count': 1,
1213
+ 'show_option': true,
1214
+ 'coords': [[Number(x), Number(y), Number(z)]]
1215
+ };
1216
+ }
1217
+ else {
1218
+ ligand_dict[chain_name + ':' + ligand_name + ':' + residue_id].count += 1;
1219
+ ligand_dict[chain_name + ':' + ligand_name + ':' + residue_id].coords.push([Number(x), Number(y), Number(z)]);
1220
+ }
1221
+ }
1222
+ }
1223
+ for (var key in ligand_dict) {
1224
+ var max_min_dict = this.calc_max_min(ligand_dict[key]);
1225
+ ligand_dict[key]['max_min_coord'] = max_min_dict;
1226
+ ret_list.push(ligand_dict[key]);
1227
+ }
1228
+ return ret_list;
1229
+ };
1230
+ PDBeMolstarPlugin.prototype.parse_chain_info = function (pdb_string) {
1231
+ // 解析所有的链信息
1232
+ var lines = pdb_string.split('\n');
1233
+ // 获得链中的residue信息
1234
+ var chain_dict = {};
1235
+ for (var _a = 0, lines_2 = lines; _a < lines_2.length; _a++) {
1236
+ var line = lines_2[_a];
1237
+ if (line.startsWith('ATOM')) {
1238
+ var residue_name = line.substr(17, 3).trim();
1239
+ var chain_name = line.substr(21, 1).trim();
1240
+ if (chain_dict[chain_name] === undefined) {
1241
+ chain_dict[chain_name] = [];
1242
+ }
1243
+ chain_dict[chain_name].push(residue_name);
1244
+ }
1245
+ }
1246
+ var ret_list = [];
1247
+ for (var chain_name in chain_dict) {
1248
+ ret_list.push({ 'chain_full_name': chain_name, 'chain_main_name': chain_name, 'chain_cont': chain_dict[chain_name] });
1249
+ }
1250
+ return ret_list;
1251
+ };
1252
+ PDBeMolstarPlugin.prototype.calc_max_min = function (ligand_dict) {
1253
+ var coords = ligand_dict.coords;
1254
+ var x_list = [];
1255
+ var y_list = [];
1256
+ var z_list = [];
1257
+ for (var _a = 0, coords_1 = coords; _a < coords_1.length; _a++) {
1258
+ var coord = coords_1[_a];
1259
+ x_list.push(coord[0]);
1260
+ y_list.push(coord[1]);
1261
+ z_list.push(coord[2]);
1262
+ }
1263
+ return {
1264
+ 'max_x': Math.max.apply(Math, x_list),
1265
+ 'min_x': Math.min.apply(Math, x_list),
1266
+ 'max_y': Math.max.apply(Math, y_list),
1267
+ 'min_y': Math.min.apply(Math, y_list),
1268
+ 'max_z': Math.max.apply(Math, z_list),
1269
+ 'min_z': Math.min.apply(Math, z_list)
1270
+ };
1271
+ };
1272
+ return PDBeMolstarPlugin;
1273
+ }());
1274
+ window.PDBeMolstarPlugin = PDBeMolstarPlugin;