molstar
Version:
A comprehensive macromolecular library.
123 lines • 7.17 kB
JavaScript
"use strict";
/**
* Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Interactions = void 0;
var tslib_1 = require("tslib");
var behavior_1 = require("../../../behavior");
var param_definition_1 = require("../../../../../mol-util/param-definition");
var interactions_1 = require("../../../../../mol-model-props/computed/interactions");
var mol_state_1 = require("../../../../../mol-state");
var objects_1 = require("../../../../../mol-plugin-state/objects");
var element_1 = require("../../../../../mol-model/structure/structure/element");
var int_1 = require("../../../../../mol-data/int");
var common_1 = require("../../../../../mol-model-props/computed/interactions/common");
var array_1 = require("../../../../../mol-util/array");
var interaction_type_1 = require("../../../../../mol-model-props/computed/themes/interaction-type");
var interactions_2 = require("../../../../../mol-model-props/computed/representations/interactions");
exports.Interactions = behavior_1.PluginBehavior.create({
name: 'computed-interactions-prop',
category: 'custom-props',
display: { name: 'Interactions' },
ctor: /** @class */ (function (_super) {
(0, tslib_1.__extends)(class_1, _super);
function class_1() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.provider = interactions_1.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 = element_1.StructureElement.Loci.remap(loci, s);
if (l.elements.length !== 1)
continue;
var e = l.elements[0];
if (int_1.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 = int_1.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((0, common_1.featureTypeLabel)(type));
if (group)
groupLabels.push((0, common_1.featureGroupLabel)(group));
}
if (typeLabels.length)
label.push("<small>Types</small> " + typeLabels.join(', '));
if (groupLabels.length)
label.push("<small>Groups</small> " + groupLabels.join(', '));
if (label.length)
labels.push("Interaction Feature: " + 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(mol_state_1.StateSelection.Generators.ofType(objects_1.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)
(0, array_1.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(interaction_type_1.InteractionTypeColorThemeProvider);
this.ctx.managers.lociLabels.addProvider(this.labelProvider);
this.ctx.representation.structure.registry.add(interactions_2.InteractionsRepresentationProvider);
};
class_1.prototype.unregister = function () {
this.ctx.customStructureProperties.unregister(this.provider.descriptor.name);
this.ctx.representation.structure.themes.colorThemeRegistry.remove(interaction_type_1.InteractionTypeColorThemeProvider);
this.ctx.managers.lociLabels.removeProvider(this.labelProvider);
this.ctx.representation.structure.registry.remove(interactions_2.InteractionsRepresentationProvider);
};
return class_1;
}(behavior_1.PluginBehavior.Handler)),
params: function () { return ({
autoAttach: param_definition_1.ParamDefinition.Boolean(false),
showTooltip: param_definition_1.ParamDefinition.Boolean(true)
}); }
});
//# sourceMappingURL=interactions.js.map