UNPKG

pdbe-molstar-3dbionotes

Version:
802 lines 46.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var spec_1 = require("./spec"); var commands_1 = require("Molstar/mol-plugin/commands"); var mol_state_1 = require("Molstar/mol-state"); var loci_1 = require("Molstar/mol-model/loci"); var rx_event_helper_1 = require("Molstar/mol-util/rx-event-helper"); var helpers_1 = require("./helpers"); var pdbe_structure_controls_1 = require("./ui/pdbe-structure-controls"); var pdbe_viewport_controls_1 = require("./ui/pdbe-viewport-controls"); var mol_state_2 = require("Molstar/mol-state"); var structure_focus_representation_1 = require("Molstar/mol-plugin/behavior/dynamic/selection/structure-focus-representation"); var spec_2 = require("Molstar/mol-plugin/spec"); var transformers_1 = require("Molstar/mol-plugin/behavior/dynamic/volume-streaming/transformers"); var structure_representation_params_1 = require("Molstar/mol-plugin-state/helpers/structure-representation-params"); var subscribe_events_1 = require("./subscribe-events"); var pdbe_left_panel_1 = require("./ui/pdbe-left-panel"); var superposition_1 = require("./superposition"); var custom_events_1 = require("./custom-events"); var assets_1 = require("Molstar/mol-util/assets"); var config_1 = require("Molstar/mol-plugin/config"); var color_1 = require("Molstar/mol-util/color/color"); var component_1 = require("Molstar/mol-plugin-state/manager/structure/component"); var param_definition_1 = require("Molstar/mol-util/param-definition"); var behavior_1 = require("./domain-annotations/behavior"); var pdbe_1 = require("Molstar/extensions/pdbe"); var built_in_1 = require("Molstar/mol-plugin-state/animation/built-in"); var structure_overpaint_1 = require("Molstar/mol-plugin-state/helpers/structure-overpaint"); var element_symbol_1 = require("Molstar/mol-theme/color/element-symbol"); var superposition_focus_representation_1 = require("./superposition-focus-representation"); var superposition_viewport_1 = require("./ui/superposition-viewport"); require('Molstar/mol-plugin-ui/skin/dark.scss'); // Override carbon by chain-id theme default element_symbol_1.ElementSymbolColorThemeParams.carbonByChainId.defaultValue = false; var PDBeMolstarPlugin = /** @class */ (function () { function PDBeMolstarPlugin() { var _this = this; this._ev = rx_event_helper_1.RxEventHelper.create(); this.events = { loadComplete: this._ev() }; this.assemblyRef = ''; this.isHighlightColorUpdated = false; this.isSelectedColorUpdated = false; this.applyVisualParams = function () { var TagRefs = { 'structure-component-static-polymer': 'polymer', 'structure-component-static-ligand': 'het', 'structure-component-static-branched': 'carbs', 'structure-component-static-water': 'water', 'structure-component-static-coarse': 'coarse', 'non-standard': 'nonStandard' }; var componentGroups = _this.plugin.managers.structure.hierarchy.currentComponentGroups; componentGroups.forEach(function (compGrp) { var _a; var key = compGrp[0].key; var rm = false; if (key && _this.initParams.hideStructure) { var structType = TagRefs[key]; if (structType && ((_a = _this.initParams.hideStructure) === null || _a === void 0 ? void 0 : _a.indexOf(structType)) > -1) rm = true; } if (rm) { _this.plugin.managers.structure.hierarchy.remove(compGrp); } if (!rm && _this.initParams.visualStyle) { if (compGrp[0] && compGrp[0].representations) { compGrp[0].representations.forEach(function (rep) { var currentParams = structure_representation_params_1.createStructureRepresentationParams(_this.plugin, void 0, { type: _this.initParams.visualStyle }); _this.plugin.managers.structure.component.updateRepresentations(compGrp, rep, currentParams); }); } } }); }; this.canvas = { toggleControls: function (isVisible) { if (typeof isVisible === 'undefined') isVisible = !_this.plugin.layout.state.showControls; commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { showControls: isVisible } }); }, toggleExpanded: function (isExpanded) { if (typeof isExpanded === 'undefined') isExpanded = !_this.plugin.layout.state.isExpanded; commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { isExpanded: isExpanded } }); }, setBgColor: function (color) { if (!color) return; var renderer = _this.plugin.canvas3d.props.renderer; commands_1.PluginCommands.Canvas3D.SetSettings(_this.plugin, { settings: { renderer: tslib_1.__assign(tslib_1.__assign({}, renderer), { backgroundColor: color_1.Color.fromRgb(color.r, color.g, color.b) }) } }); }, }; this.visual = { highlight: function (params) { var loci = _this.getLociForParams(params.data); if (loci_1.Loci.isEmpty(loci)) return; if (params.color) { _this.visual.setColor({ highlight: params.color }); } _this.plugin.managers.interactivity.lociHighlights.highlightOnly({ loci: loci }); if (params.focus) _this.plugin.managers.camera.focusLoci(loci); }, clearHighlight: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { this.plugin.managers.interactivity.lociHighlights.highlightOnly({ loci: loci_1.EmptyLoci }); if (this.isHighlightColorUpdated) this.visual.reset({ highlightColor: true }); return [2 /*return*/]; }); }); }, select: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () { var _a, _b, s, e_1_1, _c, _d, param, loci, themeParams, colorValue, repr, defaultParams, defaultValues, values, structures, comps, lastCompsIndex, recentRepComp, uniformColor, e_2_1; var e_1, _e, e_2, _f; return tslib_1.__generator(this, function (_g) { switch (_g.label) { case 0: if (!this.selectedParams) return [3 /*break*/, 2]; return [4 /*yield*/, this.visual.clearSelection()]; case 1: _g.sent(); _g.label = 2; case 2: if (!params.nonSelectedColor) return [3 /*break*/, 15]; _g.label = 3; case 3: _g.trys.push([3, 9, 10, 15]); _a = tslib_1.__asyncValues(this.plugin.managers.structure.hierarchy.current.structures); _g.label = 4; case 4: return [4 /*yield*/, _a.next()]; case 5: if (!(_b = _g.sent(), !_b.done)) return [3 /*break*/, 8]; s = _b.value; return [4 /*yield*/, this.plugin.managers.structure.component.updateRepresentationsTheme(s.components, { color: 'uniform', colorParams: { value: this.normalizeColor(params.nonSelectedColor) } })]; case 6: _g.sent(); _g.label = 7; case 7: return [3 /*break*/, 4]; case 8: return [3 /*break*/, 15]; case 9: e_1_1 = _g.sent(); e_1 = { error: e_1_1 }; return [3 /*break*/, 15]; case 10: _g.trys.push([10, , 13, 14]); if (!(_b && !_b.done && (_e = _a.return))) return [3 /*break*/, 12]; return [4 /*yield*/, _e.call(_a)]; case 11: _g.sent(); _g.label = 12; case 12: return [3 /*break*/, 14]; case 13: if (e_1) throw e_1.error; return [7 /*endfinally*/]; case 14: return [7 /*endfinally*/]; case 15: _g.trys.push([15, 23, 24, 29]); _c = tslib_1.__asyncValues(params.data); _g.label = 16; case 16: return [4 /*yield*/, _c.next()]; case 17: if (!(_d = _g.sent(), !_d.done)) return [3 /*break*/, 22]; param = _d.value; loci = this.getLociForParams([param]); if (loci_1.Loci.isEmpty(loci)) return [2 /*return*/]; // set default selection color to minimise change display this.visual.setColor({ select: param.color ? param.color : { r: 255, g: 112, b: 3 } }); // apply selection this.plugin.managers.interactivity.lociSelects.selectOnly({ loci: loci }); themeParams = component_1.StructureComponentManager.getThemeParams(this.plugin, this.plugin.managers.structure.component.pivotStructure); colorValue = param_definition_1.ParamDefinition.getDefaultValues(themeParams); colorValue.action.params = { color: param.color ? this.normalizeColor(param.color) : color_1.Color.fromRgb(255, 112, 3), opacity: 1 }; return [4 /*yield*/, this.plugin.managers.structure.component.applyTheme(colorValue, this.plugin.managers.structure.hierarchy.current.structures)]; case 18: _g.sent(); if (!(param.sideChain || param.representation)) return [3 /*break*/, 20]; repr = 'ball-and-stick'; if (param.representation) repr = param.representation; defaultParams = component_1.StructureComponentManager.getAddParams(this.plugin, { allowNone: false, hideSelection: true, checkExisting: true }); defaultValues = param_definition_1.ParamDefinition.getDefaultValues(defaultParams); defaultValues.options = { label: 'selection-by-script', checkExisting: true }; values = tslib_1.__assign(tslib_1.__assign({}, defaultValues), { representation: repr }); structures = this.plugin.managers.structure.hierarchy.getStructuresWithSelection(); return [4 /*yield*/, this.plugin.managers.structure.component.add(values, structures)]; case 19: _g.sent(); // Apply uniform theme if (param.representationColor) { comps = this.plugin.managers.structure.hierarchy.current.structures[0].components; lastCompsIndex = comps.length - 1; recentRepComp = [comps[lastCompsIndex]]; uniformColor = param.representationColor ? this.normalizeColor(param.representationColor) : color_1.Color.fromRgb(255, 112, 3); this.plugin.managers.structure.component.updateRepresentationsTheme(recentRepComp, { color: 'uniform', colorParams: { value: uniformColor } }); } params.addedRepr = true; _g.label = 20; case 20: // focus loci if (param.focus) this.plugin.managers.camera.focusLoci(loci); // remove selection this.plugin.managers.interactivity.lociSelects.deselect({ loci: loci }); _g.label = 21; case 21: return [3 /*break*/, 16]; case 22: return [3 /*break*/, 29]; case 23: e_2_1 = _g.sent(); e_2 = { error: e_2_1 }; return [3 /*break*/, 29]; case 24: _g.trys.push([24, , 27, 28]); if (!(_d && !_d.done && (_f = _c.return))) return [3 /*break*/, 26]; return [4 /*yield*/, _f.call(_c)]; case 25: _g.sent(); _g.label = 26; case 26: return [3 /*break*/, 28]; case 27: if (e_2) throw e_2.error; return [7 /*endfinally*/]; case 28: return [7 /*endfinally*/]; case 29: // reset selection color this.visual.reset({ selectColor: true }); // save selection params to optimise clear this.selectedParams = params; return [2 /*return*/]; } }); }); }, clearSelection: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { var selReprCells, _i, _a, c, selReprCells_1, selReprCells_1_1, selReprCell, e_3_1; var e_3, _b; return tslib_1.__generator(this, function (_c) { switch (_c.label) { case 0: this.plugin.managers.interactivity.lociSelects.deselectAll(); // reset theme to default if (this.selectedParams && this.selectedParams.nonSelectedColor) { this.visual.reset({ theme: true }); } // remove overpaints return [4 /*yield*/, structure_overpaint_1.clearStructureOverpaint(this.plugin, this.plugin.managers.structure.hierarchy.current.structures[0].components)]; case 1: // remove overpaints _c.sent(); if (!(this.selectedParams && this.selectedParams.addedRepr)) return [3 /*break*/, 15]; selReprCells = []; for (_i = 0, _a = this.plugin.managers.structure.hierarchy.current.structures[0].components; _i < _a.length; _i++) { c = _a[_i]; if (c.cell && c.cell.params && c.cell.params.values && c.cell.params.values.label === 'selection-by-script') selReprCells.push(c.cell); } if (!(selReprCells.length > 0)) return [3 /*break*/, 15]; _c.label = 2; case 2: _c.trys.push([2, 8, 9, 14]); selReprCells_1 = tslib_1.__asyncValues(selReprCells); _c.label = 3; case 3: return [4 /*yield*/, selReprCells_1.next()]; case 4: if (!(selReprCells_1_1 = _c.sent(), !selReprCells_1_1.done)) return [3 /*break*/, 7]; selReprCell = selReprCells_1_1.value; return [4 /*yield*/, commands_1.PluginCommands.State.RemoveObject(this.plugin, { state: selReprCell.parent, ref: selReprCell.transform.ref })]; case 5: _c.sent(); _c.label = 6; case 6: return [3 /*break*/, 3]; case 7: return [3 /*break*/, 14]; case 8: e_3_1 = _c.sent(); e_3 = { error: e_3_1 }; return [3 /*break*/, 14]; case 9: _c.trys.push([9, , 12, 13]); if (!(selReprCells_1_1 && !selReprCells_1_1.done && (_b = selReprCells_1.return))) return [3 /*break*/, 11]; return [4 /*yield*/, _b.call(selReprCells_1)]; case 10: _c.sent(); _c.label = 11; case 11: return [3 /*break*/, 13]; case 12: if (e_3) throw e_3.error; return [7 /*endfinally*/]; case 13: return [7 /*endfinally*/]; case 14: ; _c.label = 15; case 15: this.selectedParams = undefined; return [2 /*return*/]; } }); }); }, update: function (options, fullLoad) { return tslib_1.__awaiter(_this, void 0, void 0, function () { var param, dataSource; return tslib_1.__generator(this, function (_a) { if (!options) return [2 /*return*/]; // for(let param in this.initParams){ // if(options[param]) this.initParams[param] = options[param]; // } this.initParams = tslib_1.__assign({}, spec_1.DefaultParams); for (param in spec_1.DefaultParams) { if (typeof options[param] !== 'undefined') this.initParams[param] = options[param]; } if (!this.initParams.moleculeId && !this.initParams.customData) return [2 /*return*/, false]; if (this.initParams.customData && this.initParams.customData.url && !this.initParams.customData.format) return [2 /*return*/, false]; this.plugin.customState.initParams = this.initParams; // Set background colour if (this.initParams.bgColor) { this.canvas.setBgColor(this.initParams.bgColor); } dataSource = this.getMoleculeSrcUrl(); if (dataSource) { this.load({ url: dataSource.url, format: dataSource.format, assemblyId: this.initParams.assemblyId, isBinary: dataSource.isBinary }, fullLoad); } return [2 /*return*/]; }); }); }, visibility: function (data) { if (!data) return; var refMap = { polymer: 'structure-component-static-polymer', het: 'structure-component-static-ligand', water: 'structure-component-static-water', carbs: 'structure-component-static-branched', maps: 'volume-streaming-info' }; for (var visual in data) { var tagName = refMap[visual]; var componentRef = mol_state_2.StateSelection.findTagInSubtree(_this.plugin.state.data.tree, mol_state_1.StateTransform.RootRef, tagName); if (componentRef) { var compVisual = _this.plugin.state.data.select(componentRef)[0]; if (compVisual && compVisual.obj) { var currentlyVisible = (compVisual.state && compVisual.state.isHidden) ? false : true; if (data[visual] !== currentlyVisible) { commands_1.PluginCommands.State.ToggleVisibility(_this.plugin, { state: _this.state, ref: componentRef }); } } } } }, toggleSpin: function (isSpinning, resetCamera) { if (!_this.plugin.canvas3d) return; var trackball = _this.plugin.canvas3d.props.trackball; if (typeof isSpinning === 'undefined') isSpinning = !trackball.spin; commands_1.PluginCommands.Canvas3D.SetSettings(_this.plugin, { settings: { trackball: tslib_1.__assign(tslib_1.__assign({}, trackball), { spin: isSpinning }) } }); if (resetCamera) commands_1.PluginCommands.Camera.Reset(_this.plugin, {}); }, focus: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () { var loci; return tslib_1.__generator(this, function (_a) { loci = this.getLociForParams(params); this.plugin.managers.camera.focusLoci(loci); return [2 /*return*/]; }); }); }, setColor: function (param) { if (!_this.plugin.canvas3d) return; var renderer = _this.plugin.canvas3d.props.renderer; var rParam = {}; if (param.highlight) rParam['highlightColor'] = _this.normalizeColor(param.highlight); if (param.select) rParam['selectColor'] = _this.normalizeColor(param.select); commands_1.PluginCommands.Canvas3D.SetSettings(_this.plugin, { settings: { renderer: tslib_1.__assign(tslib_1.__assign({}, renderer), rParam) } }); if (rParam.highlightColor) _this.isHighlightColorUpdated = true; }, reset: function (params) { return tslib_1.__awaiter(_this, void 0, void 0, function () { var componentGroups, renderer, rParam; var _this = this; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: if (!params.camera) return [3 /*break*/, 2]; return [4 /*yield*/, commands_1.PluginCommands.Camera.Reset(this.plugin, { durationMs: 250 })]; case 1: _a.sent(); _a.label = 2; case 2: if (params.theme) { componentGroups = this.plugin.managers.structure.hierarchy.currentComponentGroups; componentGroups.forEach(function (compGrp) { _this.plugin.managers.structure.component.updateRepresentationsTheme(compGrp, { color: 'default' }); }); } if (params.highlightColor || params.selectColor) { if (!this.plugin.canvas3d) return [2 /*return*/]; renderer = this.plugin.canvas3d.props.renderer; rParam = {}; if (params.highlightColor) rParam['highlightColor'] = this.defaultRendererProps.highlightColor; if (params.selectColor) rParam['selectColor'] = this.defaultRendererProps.selectColor; commands_1.PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: { renderer: tslib_1.__assign(tslib_1.__assign({}, renderer), rParam) } }); if (rParam.highlightColor) this.isHighlightColorUpdated = false; } return [2 /*return*/]; } }); }); } }; } PDBeMolstarPlugin.prototype.render = function (target, options) { if (!options) return; this.initParams = tslib_1.__assign({}, spec_1.DefaultParams); for (var param in spec_1.DefaultParams) { if (typeof options[param] !== 'undefined') this.initParams[param] = options[param]; } if (!this.initParams.moleculeId && !this.initParams.customData) return false; if (this.initParams.customData && this.initParams.customData.url && !this.initParams.customData.format) return false; // Set PDBe Plugin Spec var pdbePluginSpec = { actions: tslib_1.__spreadArrays(spec_1.DefaultPluginSpec.actions), behaviors: tslib_1.__spreadArrays(spec_1.DefaultPluginSpec.behaviors), animations: tslib_1.__spreadArrays(spec_1.DefaultPluginSpec.animations || []), customParamEditors: spec_1.DefaultPluginSpec.customParamEditors, config: spec_1.DefaultPluginSpec.config }; if (!this.initParams.ligandView && !this.initParams.superposition && this.initParams.selectInteraction) { pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(structure_focus_representation_1.StructureFocusRepresentation)); } if (this.initParams.superposition) { var displaySurroundings = true; // if(this.initParams.superpositionParams && this.initParams.superpositionParams.ligandView) displaySurroundings = false; if (displaySurroundings) pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(superposition_focus_representation_1.SuperpositionFocusRepresentation)); } // Add custom properties if (this.initParams.domainAnnotation) { pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(behavior_1.PDBeDomainAnnotations, { autoAttach: true, showTooltip: false })); } if (this.initParams.validationAnnotation) { pdbePluginSpec.behaviors.push(spec_2.PluginSpec.Behavior(pdbe_1.PDBeStructureQualityReport, { autoAttach: true, showTooltip: false })); } pdbePluginSpec.layout = { initial: { isExpanded: this.initParams.landscape ? false : this.initParams.expanded, showControls: !this.initParams.hideControls }, controls: { left: pdbe_left_panel_1.LeftPanelControls, // right: DefaultStructureTools, top: 'none', bottom: 'none' } }; pdbePluginSpec.components = { viewport: { controls: pdbe_viewport_controls_1.PDBeViewportControls, view: this.initParams.superposition ? superposition_viewport_1.SuperpostionViewport : void 0 }, remoteState: 'none', structureTools: this.initParams.superposition ? pdbe_structure_controls_1.PDBeSuperpositionStructureTools : this.initParams.ligandView ? pdbe_structure_controls_1.PDBeLigandViewStructureTools : pdbe_structure_controls_1.PDBeStructureTools }; pdbePluginSpec.config = [ [config_1.PluginConfig.Structure.DefaultRepresentationPresetParams, { theme: { carbonByChainId: false, focus: { name: 'element-symbol', params: { carbonByChainId: false } } } }] ]; // Add animation props if (!this.initParams.ligandView && !this.initParams.superposition) { pdbePluginSpec['animations'] = [built_in_1.AnimateModelIndex]; } if (this.initParams.hideCanvasControls) { // let hideCanvasControls: any = []; if (this.initParams.hideCanvasControls.indexOf('expand') > -1) pdbePluginSpec.config.push([config_1.PluginConfig.Viewport.ShowExpand, false]); if (this.initParams.hideCanvasControls.indexOf('selection') > -1) pdbePluginSpec.config.push([config_1.PluginConfig.Viewport.ShowSelectionMode, false]); if (this.initParams.hideCanvasControls.indexOf('animation') > -1) pdbePluginSpec.config.push([config_1.PluginConfig.Viewport.ShowAnimation, false]); // pdbePluginSpec.config = hideCanvasControls; } ; if (this.initParams.landscape && pdbePluginSpec.layout && pdbePluginSpec.layout.initial) pdbePluginSpec.layout.initial['controlsDisplay'] = 'landscape'; this.targetElement = typeof target === 'string' ? document.getElementById(target) : target; // Create/ Initialise Plugin this.plugin = spec_1.createPlugin(this.targetElement, pdbePluginSpec); this.plugin.customState.initParams = tslib_1.__assign({}, this.initParams); this.plugin.customState.events = { segmentUpdate: this._ev(), superpositionInit: this._ev(), isBusy: this._ev() }; // Set background colour if (this.initParams.bgColor) { this.canvas.setBgColor(this.initParams.bgColor); } // Set selection granularity if (this.initParams.granularity) { this.plugin.managers.interactivity.setProps({ granularity: this.initParams.granularity }); } // Set default highlight and selection colors if (this.initParams.highlightColor || this.initParams.selectColor) { this.visual.setColor({ highlight: this.initParams.highlightColor, select: this.initParams.selectColor }); } // Save renderer defaults this.defaultRendererProps = tslib_1.__assign({}, this.plugin.canvas3d.props.renderer); if (this.initParams.superposition) { // Set left panel tab this.plugin.behaviors.layout.leftPanelTabName.next('segments'); // Initialise superposition superposition_1.initSuperposition(this.plugin); } else { // Collapse left panel commands_1.PluginCommands.Layout.Update(this.plugin, { state: { regionState: tslib_1.__assign(tslib_1.__assign({}, this.plugin.layout.state.regionState), { left: 'collapsed' }) } }); // Load Molecule CIF or coordQuery and Parse var dataSource = this.getMoleculeSrcUrl(); if (dataSource) { this.load({ url: dataSource.url, format: dataSource.format, assemblyId: this.initParams.assemblyId, isBinary: dataSource.isBinary }); } // Binding to other PDB Component events if (this.initParams.subscribeEvents) { subscribe_events_1.subscribeToComponentEvents(this); } // Event handling custom_events_1.CustomEvents.add(this.plugin, this.targetElement); } }; PDBeMolstarPlugin.prototype.getMoleculeSrcUrl = function () { var supportedFormats = ['mmcif', 'pdb', 'sdf']; var id = this.initParams.moleculeId; if (!id && !this.initParams.customData) { throw new Error("Mandatory parameters missing!"); } var query = 'full'; var sep = '?'; if (this.initParams.ligandView) { var queryParams = ['data_source=pdb-h']; if (!this.initParams.ligandView.label_comp_id_list) { if (this.initParams.ligandView.label_comp_id) { queryParams.push('label_comp_id=' + this.initParams.ligandView.label_comp_id); } else if (this.initParams.ligandView.auth_seq_id) { queryParams.push('auth_seq_id=' + this.initParams.ligandView.auth_seq_id); } if (this.initParams.ligandView.auth_asym_id) queryParams.push('auth_asym_id=' + this.initParams.ligandView.auth_asym_id); } query = 'residueSurroundings?' + queryParams.join('&'); sep = '&'; } var url = this.initParams.pdbeUrl + "model-server/v1/" + id + "/" + query + sep + "encoding=" + this.initParams.encoding + (this.initParams.lowPrecisionCoords ? '&lowPrecisionCoords=1' : ''); var isBinary = this.initParams.encoding === 'bcif' ? true : false; var format = 'mmcif'; if (this.initParams.customData) { if (!this.initParams.customData.url || !this.initParams.customData.format) { throw new Error("Provide all custom data parameters"); } url = this.initParams.customData.url; format = this.initParams.customData.format; if (format === 'cif' || format === 'bcif') format = 'mmcif'; // Validate supported format if (supportedFormats.indexOf(format) === -1) { throw new Error(format + " not supported."); } isBinary = this.initParams.customData.binary ? this.initParams.customData.binary : false; } return { url: url, format: format, isBinary: isBinary }; }; Object.defineProperty(PDBeMolstarPlugin.prototype, "state", { get: function () { return this.plugin.state.data; }, enumerable: false, configurable: true }); PDBeMolstarPlugin.prototype.createLigandStructure = function (isBranched) { var e_4, _a; var _b; return tslib_1.__awaiter(this, void 0, void 0, function () { var _c, _d, comp, e_4_1, structure, ligandQuery, ligandVis, ligandSurr, ligRef, cell, ligLoci; var _this = this; return tslib_1.__generator(this, function (_e) { switch (_e.label) { case 0: if (this.assemblyRef === '') return [2 /*return*/]; _e.label = 1; case 1: _e.trys.push([1, 7, 8, 13]); _c = tslib_1.__asyncValues(this.plugin.managers.structure.hierarchy.currentComponentGroups); _e.label = 2; case 2: return [4 /*yield*/, _c.next()]; case 3: if (!(_d = _e.sent(), !_d.done)) return [3 /*break*/, 6]; comp = _d.value; return [4 /*yield*/, commands_1.PluginCommands.State.RemoveObject(this.plugin, { state: comp[0].cell.parent, ref: comp[0].cell.transform.ref, removeParentGhosts: true })]; case 4: _e.sent(); _e.label = 5; case 5: return [3 /*break*/, 2]; case 6: return [3 /*break*/, 13]; case 7: e_4_1 = _e.sent(); e_4 = { error: e_4_1 }; return [3 /*break*/, 13]; case 8: _e.trys.push([8, , 11, 12]); if (!(_d && !_d.done && (_a = _c.return))) return [3 /*break*/, 10]; return [4 /*yield*/, _a.call(_c)]; case 9: _e.sent(); _e.label = 10; case 10: return [3 /*break*/, 12]; case 11: if (e_4) throw e_4.error; return [7 /*endfinally*/]; case 12: return [7 /*endfinally*/]; case 13: structure = this.state.select(this.assemblyRef)[0]; if (isBranched) { ligandQuery = helpers_1.LigandView.branchedQuery((_b = this.initParams.ligandView) === null || _b === void 0 ? void 0 : _b.label_comp_id_list); } else { ligandQuery = helpers_1.LigandView.query(this.initParams.ligandView); } return [4 /*yield*/, this.plugin.builders.structure.tryCreateComponentFromExpression(structure, ligandQuery.core, 'pivot', { label: 'Ligand' })]; case 14: ligandVis = _e.sent(); if (!ligandVis) return [3 /*break*/, 16]; return [4 /*yield*/, this.plugin.builders.structure.representation.addRepresentation(ligandVis, { type: 'ball-and-stick', color: 'element-symbol', colorParams: { carbonByChainId: false }, size: 'uniform', sizeParams: { value: 2.5 } }, { tag: 'ligand-vis' })]; case 15: _e.sent(); _e.label = 16; case 16: return [4 /*yield*/, this.plugin.builders.structure.tryCreateComponentFromExpression(structure, ligandQuery.surroundings, 'rest', { label: 'Surroundings' })]; case 17: ligandSurr = _e.sent(); if (!ligandSurr) return [3 /*break*/, 19]; return [4 /*yield*/, this.plugin.builders.structure.representation.addRepresentation(ligandSurr, { type: 'ball-and-stick', color: 'element-symbol', colorParams: { carbonByChainId: false }, size: 'uniform', sizeParams: { value: 0.8 } })]; case 18: _e.sent(); _e.label = 19; case 19: ligRef = mol_state_2.StateSelection.findTagInSubtree(this.plugin.state.data.tree, mol_state_1.StateTransform.RootRef, 'ligand-vis'); if (!ligRef) return [2 /*return*/]; cell = this.plugin.state.data.cells.get(ligRef); if (cell) { ligLoci = cell.obj.data.repr.getLoci(); this.plugin.managers.structure.focus.setFromLoci(ligLoci); setTimeout(function () { var _a; // focus-add is not handled in camera behavior, doing it here var current = (_a = _this.plugin.managers.structure.focus.current) === null || _a === void 0 ? void 0 : _a.loci; if (current) _this.plugin.managers.camera.focusLoci(current); }, 500); } return [2 /*return*/]; } }); }); }; PDBeMolstarPlugin.prototype.load = function (_a, fullLoad) { 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; if (fullLoad === void 0) { fullLoad = true; } return tslib_1.__awaiter(this, void 0, void 0, function () { var isHetView, downloadOptions, isBranchedView, data, trajectory, model, pivotIndex, pivot, asm, defaultMapParams, pdbeMapParams; return tslib_1.__generator(this, function (_e) { switch (_e.label) { case 0: if (fullLoad) this.clear(); isHetView = this.initParams.ligandView ? true : false; downloadOptions = void 0; isBranchedView = false; if (this.initParams.ligandView && this.initParams.ligandView.label_comp_id_list) { isBranchedView = true; downloadOptions = { body: JSON.stringify(this.initParams.ligandView.label_comp_id_list), headers: [['Content-type', 'application/json']] }; } return [4 /*yield*/, this.plugin.builders.data.download({ url: assets_1.Asset.Url(url, downloadOptions), isBinary: isBinary }, { state: { isGhost: true } })]; case 1: data = _e.sent(); return [4 /*yield*/, this.plugin.builders.structure.parseTrajectory(data, format)]; case 2: trajectory = _e.sent(); if (!!isHetView) return [3 /*break*/, 4]; return [4 /*yield*/, this.plugin.builders.structure.hierarchy.applyPreset(trajectory, 'default', { structure: assemblyId ? (assemblyId === 'preferred') ? void 0 : { name: 'assembly', params: { id: assemblyId } } : { name: 'model', params: {} }, showUnitcell: false, representationPreset: 'auto' })]; case 3: _e.sent(); if (this.initParams.hideStructure || this.initParams.visualStyle) { this.applyVisualParams(); } return [3 /*break*/, 7]; case 4: return [4 /*yield*/, this.plugin.builders.structure.createModel(trajectory)]; case 5: model = _e.sent(); return [4 /*yield*/, this.plugin.builders.structure.createStructure(model, { name: 'model', params: {} })]; case 6: _e.sent(); _e.label = 7; case 7: // show selection if param is set if (this.initParams.selection) { this.visual.select(this.initParams.selection); } pivotIndex = this.plugin.managers.structure.hierarchy.selection.structures.length - 1; pivot = this.plugin.managers.structure.hierarchy.selection.structures[pivotIndex]; if (pivot && pivot.cell.parent) this.assemblyRef = pivot.cell.transform.ref; if (!this.initParams.loadMaps) return [3 /*break*/, 9]; if (this.assemblyRef === '') return [2 /*return*/]; asm = this.state.select(this.assemblyRef)[0].obj; defaultMapParams = transformers_1.InitVolumeStreaming.createDefaultParams(asm, this.plugin); pdbeMapParams = helpers_1.PDBeVolumes.mapParams(defaultMapParams, this.initParams.mapSettings, ''); if (!pdbeMapParams) return [3 /*break*/, 9]; return [4 /*yield*/, this.plugin.runTask(this.state.applyAction(transformers_1.InitVolumeStreaming, pdbeMapParams, this.assemblyRef))]; case 8: _e.sent(); if (pdbeMapParams.method !== 'em' && !this.initParams.ligandView) helpers_1.PDBeVolumes.displayUsibilityMessage(this.plugin); _e.label = 9; case 9: if (!isHetView) return [3 /*break*/, 11]; return [4 /*yield*/, this.createLigandStructure(isBranchedView)]; case 10: _e.sent(); _e.label = 11; case 11: this.events.loadComplete.next(true); return [2 /*return*/]; } }); }); }; PDBeMolstarPlugin.prototype.getLociForParams = function (params) { if (this.assemblyRef === '') return loci_1.EmptyLoci; var data = this.plugin.state.data.select(this.assemblyRef)[0].obj.data; if (!data) return loci_1.EmptyLoci; return helpers_1.QueryHelper.getInteractivityLoci(params, data); }; PDBeMolstarPlugin.prototype.normalizeColor = function (colorVal, defaultColor) { var color = color_1.Color.fromRgb(170, 170, 170); try { if (colorVal.r) { color = color_1.Color.fromRgb(colorVal.r, colorVal.g, colorVal.b); } else if (colorVal[0] === '#') { color = color_1.Color(Number("0x" + colorVal.substr(1))); } else { color = color_1.Color(colorVal); } } catch (e) { if (defaultColor) color = defaultColor; } return color; }; PDBeMolstarPlugin.prototype.clear = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { this.plugin.clear(); this.assemblyRef = ''; this.selectedParams = void 0; this.isHighlightColorUpdated = false; this.isSelectedColorUpdated = false; return [2 /*return*/]; }); }); }; return PDBeMolstarPlugin; }()); window.PDBeMolstarPlugin = PDBeMolstarPlugin; //# sourceMappingURL=index.js.map