UNPKG

pdbe-molstar-3dbionotes

Version:
154 lines 9.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SuperpositionFocusRepresentation = exports.SuperpositionFocusRepresentationTags = void 0; var tslib_1 = require("tslib"); var structure_1 = require("Molstar/mol-model/structure"); var structure_representation_params_1 = require("Molstar/mol-plugin-state/helpers/structure-representation-params"); var transforms_1 = require("Molstar/mol-plugin-state/transforms"); var behavior_1 = require("Molstar/mol-plugin/behavior"); var builder_1 = require("Molstar/mol-script/language/builder"); var mol_state_1 = require("Molstar/mol-state"); var param_definition_1 = require("Molstar/mol-util/param-definition"); var commands_1 = require("Molstar/mol-plugin/commands"); var loci_details_1 = require("./loci-details"); var SuperpositionFocusRepresentationParams = 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 }), surroundingsParams: param_definition_1.ParamDefinition.Group(reprParams, { label: 'Surroundings', customDefault: structure_representation_params_1.createStructureRepresentationParams(plugin, void 0, { type: 'ball-and-stick', size: 'physical', typeParams: { sizeFactor: 0.16 }, sizeParams: { scale: 0.3 } }) }) }; }; var SuperpositionFocusRepresentationTags; (function (SuperpositionFocusRepresentationTags) { SuperpositionFocusRepresentationTags["SurrSel"] = "superposition-focus-surr-sel"; SuperpositionFocusRepresentationTags["SurrRepr"] = "superposition-focus-surr-repr"; })(SuperpositionFocusRepresentationTags = exports.SuperpositionFocusRepresentationTags || (exports.SuperpositionFocusRepresentationTags = {})); var TagSet = new Set([SuperpositionFocusRepresentationTags.SurrSel, SuperpositionFocusRepresentationTags.SurrRepr]); var SuperpositionFocusRepresentationBehavior = /** @class */ (function (_super) { tslib_1.__extends(SuperpositionFocusRepresentationBehavior, _super); function SuperpositionFocusRepresentationBehavior() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(SuperpositionFocusRepresentationBehavior.prototype, "surrLabel", { get: function () { return "[Focus] Surroundings (" + this.params.expandRadius + " \u00C5)"; }, enumerable: false, configurable: true }); SuperpositionFocusRepresentationBehavior.prototype.ensureShape = function (cell) { 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[SuperpositionFocusRepresentationTags.SurrSel]) { refs[SuperpositionFocusRepresentationTags.SurrSel] = builder .to(cell) .apply(transforms_1.StateTransforms.Model.StructureSelectionFromExpression, { expression: builder_1.MolScriptBuilder.struct.generator.empty(), label: this.surrLabel }, { tags: SuperpositionFocusRepresentationTags.SurrSel }).ref; } // Representations if (!refs[SuperpositionFocusRepresentationTags.SurrRepr]) { refs[SuperpositionFocusRepresentationTags.SurrRepr] = builder .to(refs[SuperpositionFocusRepresentationTags.SurrSel]) .apply(transforms_1.StateTransforms.Representation.StructureRepresentation3D, this.params.surroundingsParams, { tags: SuperpositionFocusRepresentationTags.SurrRepr }).ref; } return { state: state, builder: builder, refs: refs }; }; SuperpositionFocusRepresentationBehavior.prototype.clear = function (root) { var state = this.plugin.state.data; var surrs = state.select(mol_state_1.StateSelection.Generators.byRef(root).subtree().withTag(SuperpositionFocusRepresentationTags.SurrSel)); if (surrs.length === 0) return; var update = state.build(); var expression = builder_1.MolScriptBuilder.struct.generator.empty(); for (var _i = 0, surrs_1 = surrs; _i < surrs_1.length; _i++) { var s = surrs_1[_i]; update.to(s).update(transforms_1.StateTransforms.Model.StructureSelectionFromExpression, function (old) { return (tslib_1.__assign(tslib_1.__assign({}, old), { expression: expression })); }); } return commands_1.PluginCommands.State.Update(this.plugin, { state: state, tree: update, options: { doNotLogTiming: true, doNotUpdateCurrent: true } }); }; SuperpositionFocusRepresentationBehavior.prototype.focus = function (sourceLoci) { return tslib_1.__awaiter(this, void 0, void 0, function () { var parent, loci, residueLoci, residueBundle, target, surroundings, lociDeatils, _a, state, builder, refs; var _this = this; return 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*/]; 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 }); lociDeatils = loci_details_1.lociDetails(sourceLoci); if (!lociDeatils) { 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[SuperpositionFocusRepresentationTags.SurrSel]).update(transforms_1.StateTransforms.Model.StructureSelectionFromExpression, function (old) { return (tslib_1.__assign(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*/]; } }); }); }; SuperpositionFocusRepresentationBehavior.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(StateTransform.RootRef); _this.clear(mol_state_1.StateTransform.RootRef); if (entry) _this.focus(entry.loci); }); }; SuperpositionFocusRepresentationBehavior.prototype.update = function (params) { return tslib_1.__awaiter(this, void 0, void 0, function () { var old, state, builder, all, _i, _a, repr; return tslib_1.__generator(this, function (_b) { switch (_b.label) { case 0: old = this.params; this.params = params; state = this.plugin.state.data; builder = state.build(); all = mol_state_1.StateSelection.Generators.root.subtree(); for (_i = 0, _a = state.select(all.withTag(SuperpositionFocusRepresentationTags.SurrRepr)); _i < _a.length; _i++) { repr = _a[_i]; builder.to(repr).update(this.params.surroundingsParams); } return [4 /*yield*/, commands_1.PluginCommands.State.Update(this.plugin, { state: state, tree: builder, options: { doNotLogTiming: true, doNotUpdateCurrent: true } })]; case 1: _b.sent(); if (!(params.expandRadius !== old.expandRadius)) return [3 /*break*/, 3]; return [4 /*yield*/, this.clear(mol_state_1.StateTransform.RootRef)]; case 2: _b.sent(); _b.label = 3; case 3: return [2 /*return*/, true]; } }); }); }; return SuperpositionFocusRepresentationBehavior; }(behavior_1.PluginBehavior.WithSubscribers)); exports.SuperpositionFocusRepresentation = behavior_1.PluginBehavior.create({ name: 'create-superposition-focus-representation', display: { name: 'Superposition Focus Representation' }, category: 'interaction', ctor: SuperpositionFocusRepresentationBehavior, params: function (_, plugin) { return SuperpositionFocusRepresentationParams(plugin); } }); //# sourceMappingURL=superposition-focus-representation.js.map