pdbe-molstar
Version:
Molstar implementation for PDBe
121 lines (120 loc) • 7.38 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SuperpositionFocusRepresentation = exports.SuperpositionFocusRepresentationTags = void 0;
const tslib_1 = require("tslib");
const structure_1 = require("molstar/lib/mol-model/structure");
const structure_representation_params_1 = require("molstar/lib/mol-plugin-state/helpers/structure-representation-params");
const transforms_1 = require("molstar/lib/mol-plugin-state/transforms");
const behavior_1 = require("molstar/lib/mol-plugin/behavior");
const commands_1 = require("molstar/lib/mol-plugin/commands");
const builder_1 = require("molstar/lib/mol-script/language/builder");
const mol_state_1 = require("molstar/lib/mol-state");
const param_definition_1 = require("molstar/lib/mol-util/param-definition");
const loci_details_1 = require("./loci-details");
const SuperpositionFocusRepresentationParams = (plugin) => {
const reprParams = transforms_1.StateTransforms.Representation.StructureRepresentation3D.definition.params(undefined, 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: (0, structure_representation_params_1.createStructureRepresentationParams)(plugin, undefined, { 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 = SuperpositionFocusRepresentationTags = {}));
const TagSet = new Set([SuperpositionFocusRepresentationTags.SurrSel, SuperpositionFocusRepresentationTags.SurrRepr]);
class SuperpositionFocusRepresentationBehavior extends behavior_1.PluginBehavior.WithSubscribers {
get surrLabel() { return `[Focus] Surroundings (${this.params.expandRadius} Å)`; }
ensureShape(cell) {
const state = this.plugin.state.data, tree = state.tree;
const builder = state.build();
const 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, builder, refs };
}
clear(root) {
const state = this.plugin.state.data;
const surrs = state.select(mol_state_1.StateSelection.Generators.byRef(root).subtree().withTag(SuperpositionFocusRepresentationTags.SurrSel));
if (surrs.length === 0)
return;
const update = state.build();
const expression = builder_1.MolScriptBuilder.struct.generator.empty();
for (const s of surrs) {
update.to(s).update(transforms_1.StateTransforms.Model.StructureSelectionFromExpression, old => (Object.assign(Object.assign({}, old), { expression })));
}
return commands_1.PluginCommands.State.Update(this.plugin, { state, tree: update, options: { doNotLogTiming: true, doNotUpdateCurrent: true } });
}
focus(sourceLoci) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const parent = this.plugin.helpers.substructureParent.get(sourceLoci.structure);
if (!parent || !parent.obj)
return;
const loci = structure_1.StructureElement.Loci.remap(sourceLoci, parent.obj.data);
const residueLoci = structure_1.StructureElement.Loci.extendToWholeResidues(loci);
const residueBundle = structure_1.StructureElement.Bundle.fromLoci(residueLoci);
const target = structure_1.StructureElement.Bundle.toExpression(residueBundle);
let surroundings = builder_1.MolScriptBuilder.struct.modifier.includeSurroundings({
0: target,
radius: this.params.expandRadius,
'as-whole-residues': true,
});
const lociDeatils = (0, loci_details_1.lociDetails)(sourceLoci);
if (!lociDeatils) {
surroundings = builder_1.MolScriptBuilder.struct.modifier.exceptBy({
0: surroundings,
by: target,
});
}
const { state, builder, refs } = this.ensureShape(parent);
builder.to(refs[SuperpositionFocusRepresentationTags.SurrSel]).update(transforms_1.StateTransforms.Model.StructureSelectionFromExpression, old => (Object.assign(Object.assign({}, old), { expression: surroundings, label: this.surrLabel })));
yield commands_1.PluginCommands.State.Update(this.plugin, { state, tree: builder, options: { doNotLogTiming: true, doNotUpdateCurrent: true } });
});
}
register(ref) {
this.subscribeObservable(this.plugin.managers.structure.focus.behaviors.current, (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);
});
}
update(params) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const old = this.params;
this.params = params;
const state = this.plugin.state.data;
const builder = state.build();
const all = mol_state_1.StateSelection.Generators.root.subtree();
for (const repr of state.select(all.withTag(SuperpositionFocusRepresentationTags.SurrRepr))) {
builder.to(repr).update(this.params.surroundingsParams);
}
yield commands_1.PluginCommands.State.Update(this.plugin, { state, tree: builder, options: { doNotLogTiming: true, doNotUpdateCurrent: true } });
if (params.expandRadius !== old.expandRadius)
yield this.clear(mol_state_1.StateTransform.RootRef);
return true;
});
}
}
exports.SuperpositionFocusRepresentation = behavior_1.PluginBehavior.create({
name: 'create-superposition-focus-representation',
display: { name: 'Superposition Focus Representation' },
category: 'interaction',
ctor: SuperpositionFocusRepresentationBehavior,
params: (_, plugin) => SuperpositionFocusRepresentationParams(plugin),
});