UNPKG

molstar

Version:

A comprehensive macromolecular library.

241 lines 16.5 kB
"use strict"; /** * Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.StructureFocusRepresentation = exports.StructureFocusRepresentationTags = void 0; var tslib_1 = require("tslib"); var interactions_1 = require("../../../../mol-model-props/computed/representations/interactions"); var interaction_type_1 = require("../../../../mol-model-props/computed/themes/interaction-type"); var structure_1 = require("../../../../mol-model/structure"); var structure_representation_params_1 = require("../../../../mol-plugin-state/helpers/structure-representation-params"); var transforms_1 = require("../../../../mol-plugin-state/transforms"); var behavior_1 = require("../../../behavior"); var builder_1 = require("../../../../mol-script/language/builder"); var mol_state_1 = require("../../../../mol-state"); var size_1 = require("../../../../mol-theme/size"); var param_definition_1 = require("../../../../mol-util/param-definition"); var commands_1 = require("../../../commands"); var StructureFocusRepresentationParams = function (plugin) { var reprParams = transforms_1.StateTransforms.Representation.StructureRepresentation3D.definition.params(void 0, plugin); return { expandRadius: param_definition_1.ParamDefinition.Numeric(5, { min: 1, max: 10, step: 1 }), targetParams: param_definition_1.ParamDefinition.Group(reprParams, { label: 'Target', customDefault: (0, structure_representation_params_1.createStructureRepresentationParams)(plugin, void 0, { type: 'ball-and-stick', size: 'physical', typeParams: { sizeFactor: 0.26, alpha: 0.51 } }) }), surroundingsParams: param_definition_1.ParamDefinition.Group(reprParams, { label: 'Surroundings', customDefault: (0, structure_representation_params_1.createStructureRepresentationParams)(plugin, void 0, { type: 'ball-and-stick', size: 'physical', typeParams: { sizeFactor: 0.16 } }) }), nciParams: param_definition_1.ParamDefinition.Group(reprParams, { label: 'Non-covalent Int.', customDefault: (0, structure_representation_params_1.createStructureRepresentationParams)(plugin, void 0, { type: interactions_1.InteractionsRepresentationProvider, color: interaction_type_1.InteractionTypeColorThemeProvider, size: size_1.SizeTheme.BuiltIn.uniform }) }), components: param_definition_1.ParamDefinition.MultiSelect(FocusComponents, param_definition_1.ParamDefinition.arrayToOptions(FocusComponents)), excludeTargetFromSurroundings: param_definition_1.ParamDefinition.Boolean(false, { label: 'Exclude Target', description: 'Exclude the focus "target" from the surroudings component.' }), ignoreHydrogens: param_definition_1.ParamDefinition.Boolean(false) }; }; var FocusComponents = ['target', 'surroundings', 'interactions']; var StructureFocusRepresentationTags; (function (StructureFocusRepresentationTags) { StructureFocusRepresentationTags["TargetSel"] = "structure-focus-target-sel"; StructureFocusRepresentationTags["TargetRepr"] = "structure-focus-target-repr"; StructureFocusRepresentationTags["SurrSel"] = "structure-focus-surr-sel"; StructureFocusRepresentationTags["SurrRepr"] = "structure-focus-surr-repr"; StructureFocusRepresentationTags["SurrNciRepr"] = "structure-focus-surr-nci-repr"; })(StructureFocusRepresentationTags = exports.StructureFocusRepresentationTags || (exports.StructureFocusRepresentationTags = {})); var TagSet = new Set([StructureFocusRepresentationTags.TargetSel, StructureFocusRepresentationTags.TargetRepr, StructureFocusRepresentationTags.SurrSel, StructureFocusRepresentationTags.SurrRepr, StructureFocusRepresentationTags.SurrNciRepr]); var StructureFocusRepresentationBehavior = /** @class */ (function (_super) { (0, tslib_1.__extends)(StructureFocusRepresentationBehavior, _super); function StructureFocusRepresentationBehavior() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.currentSource = void 0; return _this; } Object.defineProperty(StructureFocusRepresentationBehavior.prototype, "surrLabel", { get: function () { return "[Focus] Surroundings (" + this.params.expandRadius + " \u00C5)"; }, enumerable: false, configurable: true }); StructureFocusRepresentationBehavior.prototype.getReprParams = function (reprParams) { return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, this.params.targetParams), { type: { name: reprParams.type.name, params: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, reprParams.type.params), { ignoreHydrogens: this.params.ignoreHydrogens }) } }); }; StructureFocusRepresentationBehavior.prototype.ensureShape = function (cell) { var _a; var state = this.plugin.state.data, tree = state.tree; var builder = state.build(); var refs = mol_state_1.StateSelection.findUniqueTagsInSubtree(tree, cell.transform.ref, TagSet); // Selections if (!refs[StructureFocusRepresentationTags.TargetSel]) { refs[StructureFocusRepresentationTags.TargetSel] = builder .to(cell) .apply(transforms_1.StateTransforms.Model.StructureSelectionFromBundle, { bundle: structure_1.StructureElement.Bundle.Empty, label: '[Focus] Target' }, { tags: StructureFocusRepresentationTags.TargetSel }).ref; } if (!refs[StructureFocusRepresentationTags.SurrSel]) { refs[StructureFocusRepresentationTags.SurrSel] = builder .to(cell) .apply(transforms_1.StateTransforms.Model.StructureSelectionFromExpression, { expression: builder_1.MolScriptBuilder.struct.generator.empty(), label: this.surrLabel }, { tags: StructureFocusRepresentationTags.SurrSel }).ref; } var components = this.params.components; // Representations if (components.indexOf('target') >= 0 && !refs[StructureFocusRepresentationTags.TargetRepr]) { refs[StructureFocusRepresentationTags.TargetRepr] = builder .to(refs[StructureFocusRepresentationTags.TargetSel]) .apply(transforms_1.StateTransforms.Representation.StructureRepresentation3D, this.getReprParams(this.params.targetParams), { tags: StructureFocusRepresentationTags.TargetRepr }).ref; } if (components.indexOf('surroundings') >= 0 && !refs[StructureFocusRepresentationTags.SurrRepr]) { refs[StructureFocusRepresentationTags.SurrRepr] = builder .to(refs[StructureFocusRepresentationTags.SurrSel]) .apply(transforms_1.StateTransforms.Representation.StructureRepresentation3D, this.getReprParams(this.params.surroundingsParams), { tags: StructureFocusRepresentationTags.SurrRepr }).ref; } if (components.indexOf('interactions') >= 0 && !refs[StructureFocusRepresentationTags.SurrNciRepr] && cell.obj && interactions_1.InteractionsRepresentationProvider.isApplicable((_a = cell.obj) === null || _a === void 0 ? void 0 : _a.data)) { refs[StructureFocusRepresentationTags.SurrNciRepr] = builder .to(refs[StructureFocusRepresentationTags.SurrSel]) .apply(transforms_1.StateTransforms.Representation.StructureRepresentation3D, this.params.nciParams, { tags: StructureFocusRepresentationTags.SurrNciRepr }).ref; } return { state: state, builder: builder, refs: refs }; }; StructureFocusRepresentationBehavior.prototype.clear = function (root) { var state = this.plugin.state.data; this.currentSource = void 0; var foci = state.select(mol_state_1.StateSelection.Generators.byRef(root).subtree().withTag(StructureFocusRepresentationTags.TargetSel)); var surrs = state.select(mol_state_1.StateSelection.Generators.byRef(root).subtree().withTag(StructureFocusRepresentationTags.SurrSel)); if (foci.length === 0 && surrs.length === 0) return; var update = state.build(); var bundle = structure_1.StructureElement.Bundle.Empty; for (var _i = 0, foci_1 = foci; _i < foci_1.length; _i++) { var f = foci_1[_i]; update.to(f).update(transforms_1.StateTransforms.Model.StructureSelectionFromBundle, function (old) { return ((0, tslib_1.__assign)((0, tslib_1.__assign)({}, old), { bundle: bundle })); }); } var expression = builder_1.MolScriptBuilder.struct.generator.empty(); for (var _a = 0, surrs_1 = surrs; _a < surrs_1.length; _a++) { var s = surrs_1[_a]; update.to(s).update(transforms_1.StateTransforms.Model.StructureSelectionFromExpression, function (old) { return ((0, tslib_1.__assign)((0, tslib_1.__assign)({}, old), { expression: expression })); }); } return commands_1.PluginCommands.State.Update(this.plugin, { state: state, tree: update, options: { doNotLogTiming: true, doNotUpdateCurrent: true } }); }; StructureFocusRepresentationBehavior.prototype.focus = function (sourceLoci) { return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { var parent, loci, residueLoci, residueBundle, target, surroundings, _a, state, builder, refs; var _this = this; return (0, tslib_1.__generator)(this, function (_b) { switch (_b.label) { case 0: parent = this.plugin.helpers.substructureParent.get(sourceLoci.structure); if (!parent || !parent.obj) return [2 /*return*/]; this.currentSource = sourceLoci; loci = structure_1.StructureElement.Loci.remap(sourceLoci, parent.obj.data); residueLoci = structure_1.StructureElement.Loci.extendToWholeResidues(loci); residueBundle = structure_1.StructureElement.Bundle.fromLoci(residueLoci); target = structure_1.StructureElement.Bundle.toExpression(residueBundle); surroundings = builder_1.MolScriptBuilder.struct.modifier.includeSurroundings({ 0: target, radius: this.params.expandRadius, 'as-whole-residues': true }); if (this.params.excludeTargetFromSurroundings) { surroundings = builder_1.MolScriptBuilder.struct.modifier.exceptBy({ 0: surroundings, by: target }); } _a = this.ensureShape(parent), state = _a.state, builder = _a.builder, refs = _a.refs; builder.to(refs[StructureFocusRepresentationTags.TargetSel]).update(transforms_1.StateTransforms.Model.StructureSelectionFromBundle, function (old) { return ((0, tslib_1.__assign)((0, tslib_1.__assign)({}, old), { bundle: residueBundle })); }); builder.to(refs[StructureFocusRepresentationTags.SurrSel]).update(transforms_1.StateTransforms.Model.StructureSelectionFromExpression, function (old) { return ((0, tslib_1.__assign)((0, tslib_1.__assign)({}, old), { expression: surroundings, label: _this.surrLabel })); }); return [4 /*yield*/, commands_1.PluginCommands.State.Update(this.plugin, { state: state, tree: builder, options: { doNotLogTiming: true, doNotUpdateCurrent: true } })]; case 1: _b.sent(); return [2 /*return*/]; } }); }); }; StructureFocusRepresentationBehavior.prototype.register = function (ref) { var _this = this; this.subscribeObservable(this.plugin.managers.structure.focus.behaviors.current, function (entry) { if (entry) _this.focus(entry.loci); else _this.clear(mol_state_1.StateTransform.RootRef); }); }; StructureFocusRepresentationBehavior.prototype.update = function (params) { return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { var old, state, builder, all, components, hasComponent, _i, _a, repr, _b, _c, repr, _d, _e, repr; return (0, tslib_1.__generator)(this, function (_f) { switch (_f.label) { case 0: old = this.params; this.params = params; if (old.excludeTargetFromSurroundings !== params.excludeTargetFromSurroundings) { if (this.currentSource) { this.focus(this.currentSource); } return [2 /*return*/, true]; } state = this.plugin.state.data; builder = state.build(); all = mol_state_1.StateSelection.Generators.root.subtree(); components = this.params.components; hasComponent = components.indexOf('target') >= 0; for (_i = 0, _a = state.select(all.withTag(StructureFocusRepresentationTags.TargetRepr)); _i < _a.length; _i++) { repr = _a[_i]; if (!hasComponent) builder.delete(repr.transform.ref); else builder.to(repr).update(this.getReprParams(this.params.targetParams)); } hasComponent = components.indexOf('surroundings') >= 0; for (_b = 0, _c = state.select(all.withTag(StructureFocusRepresentationTags.SurrRepr)); _b < _c.length; _b++) { repr = _c[_b]; if (!hasComponent) builder.delete(repr.transform.ref); else builder.to(repr).update(this.getReprParams(this.params.surroundingsParams)); } hasComponent = components.indexOf('interactions') >= 0; for (_d = 0, _e = state.select(all.withTag(StructureFocusRepresentationTags.SurrNciRepr)); _d < _e.length; _d++) { repr = _e[_d]; if (!hasComponent) builder.delete(repr.transform.ref); else builder.to(repr).update(this.params.nciParams); } return [4 /*yield*/, commands_1.PluginCommands.State.Update(this.plugin, { state: state, tree: builder, options: { doNotLogTiming: true, doNotUpdateCurrent: true } })]; case 1: _f.sent(); if (params.expandRadius !== old.expandRadius) { if (this.currentSource) { this.focus(this.currentSource); } return [2 /*return*/, true]; } return [2 /*return*/, true]; } }); }); }; return StructureFocusRepresentationBehavior; }(behavior_1.PluginBehavior.WithSubscribers)); exports.StructureFocusRepresentation = behavior_1.PluginBehavior.create({ name: 'create-structure-focus-representation', display: { name: 'Structure Focus Representation' }, category: 'interaction', ctor: StructureFocusRepresentationBehavior, params: function (_, plugin) { return StructureFocusRepresentationParams(plugin); } }); //# sourceMappingURL=structure-focus-representation.js.map