molstar
Version:
A comprehensive macromolecular library.
120 lines (119 loc) • 6.89 kB
JavaScript
/**
* Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { __extends } from "tslib";
import { PluginBehavior } from '../../../behavior';
import { ParamDefinition as PD } from '../../../../../mol-util/param-definition';
import { InteractionsProvider } from '../../../../../mol-model-props/computed/interactions';
import { StateSelection } from '../../../../../mol-state';
import { PluginStateObject } from '../../../../../mol-plugin-state/objects';
import { StructureElement } from '../../../../../mol-model/structure/structure/element';
import { OrderedSet } from '../../../../../mol-data/int';
import { featureGroupLabel, featureTypeLabel } from '../../../../../mol-model-props/computed/interactions/common';
import { arraySetAdd } from '../../../../../mol-util/array';
import { InteractionTypeColorThemeProvider } from '../../../../../mol-model-props/computed/themes/interaction-type';
import { InteractionsRepresentationProvider } from '../../../../../mol-model-props/computed/representations/interactions';
export var Interactions = PluginBehavior.create({
name: 'computed-interactions-prop',
category: 'custom-props',
display: { name: 'Interactions' },
ctor: /** @class */ (function (_super) {
__extends(class_1, _super);
function class_1() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.provider = InteractionsProvider;
_this.labelProvider = {
label: function (loci) {
if (!_this.params.showTooltip)
return void 0;
switch (loci.kind) {
case 'element-loci':
if (loci.elements.length === 0)
return void 0;
var labels = [];
var structures = _this.getStructures(loci.structure);
for (var _i = 0, structures_1 = structures; _i < structures_1.length; _i++) {
var s = structures_1[_i];
var interactions = _this.provider.get(s).value;
if (!interactions)
continue;
var l = StructureElement.Loci.remap(loci, s);
if (l.elements.length !== 1)
continue;
var e = l.elements[0];
if (OrderedSet.size(e.indices) !== 1)
continue;
var features = interactions.unitsFeatures.get(e.unit.id);
if (!features)
continue;
var typeLabels = [];
var groupLabels = [];
var label = [];
var idx = OrderedSet.start(e.indices);
var types = features.types, groups = features.groups, _a = features.elementsIndex, indices = _a.indices, offsets = _a.offsets;
for (var i = offsets[idx], il = offsets[idx + 1]; i < il; ++i) {
var f = indices[i];
var type = types[f];
var group = groups[f];
if (type)
typeLabels.push(featureTypeLabel(type));
if (group)
groupLabels.push(featureGroupLabel(group));
}
if (typeLabels.length)
label.push("<small>Types</small> ".concat(typeLabels.join(', ')));
if (groupLabels.length)
label.push("<small>Groups</small> ".concat(groupLabels.join(', ')));
if (label.length)
labels.push("Interaction Feature: ".concat(label.join(' | ')));
}
return labels.length ? labels.join('<br/>') : undefined;
default: return void 0;
}
}
};
return _this;
}
class_1.prototype.getStructures = function (structure) {
var structures = [];
var root = this.ctx.helpers.substructureParent.get(structure);
if (root) {
var state = this.ctx.state.data;
var selections = state.select(StateSelection.Generators.ofType(PluginStateObject.Molecule.Structure, root.transform.ref));
for (var _i = 0, selections_1 = selections; _i < selections_1.length; _i++) {
var s = selections_1[_i];
if (s.obj)
arraySetAdd(structures, s.obj.data);
}
}
return structures;
};
class_1.prototype.update = function (p) {
var updated = (this.params.autoAttach !== p.autoAttach ||
this.params.showTooltip !== p.showTooltip);
this.params.autoAttach = p.autoAttach;
this.params.showTooltip = p.showTooltip;
this.ctx.customStructureProperties.setDefaultAutoAttach(this.provider.descriptor.name, this.params.autoAttach);
return updated;
};
class_1.prototype.register = function () {
this.ctx.customStructureProperties.register(this.provider, this.params.autoAttach);
this.ctx.representation.structure.themes.colorThemeRegistry.add(InteractionTypeColorThemeProvider);
this.ctx.managers.lociLabels.addProvider(this.labelProvider);
this.ctx.representation.structure.registry.add(InteractionsRepresentationProvider);
};
class_1.prototype.unregister = function () {
this.ctx.customStructureProperties.unregister(this.provider.descriptor.name);
this.ctx.representation.structure.themes.colorThemeRegistry.remove(InteractionTypeColorThemeProvider);
this.ctx.managers.lociLabels.removeProvider(this.labelProvider);
this.ctx.representation.structure.registry.remove(InteractionsRepresentationProvider);
};
return class_1;
}(PluginBehavior.Handler)),
params: function () { return ({
autoAttach: PD.Boolean(false),
showTooltip: PD.Boolean(true)
}); }
});