UNPKG

pdbe-molstar

Version:
40 lines (39 loc) 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PDBeLociLabelProvider = void 0; const structure_1 = require("molstar/lib/mol-model/structure"); const behavior_1 = require("molstar/lib/mol-plugin/behavior"); const label_1 = require("molstar/lib/mol-theme/label"); const plugin_custom_state_1 = require("./plugin-custom-state"); exports.PDBeLociLabelProvider = behavior_1.PluginBehavior.create({ name: 'pdbe-loci-label-provider', category: 'interaction', ctor: class { register() { this.ctx.managers.lociLabels.addProvider(this.f); } unregister() { this.ctx.managers.lociLabels.removeProvider(this.f); } constructor(ctx) { this.ctx = ctx; this.f = { label: (loci) => { const superpositionView = (0, plugin_custom_state_1.PluginCustomState)(this.ctx).initParams.superposition; const label = []; if (!superpositionView && structure_1.StructureElement.Loci.is(loci) && loci.elements.length === 1) { const entityNames = new Set(); for (const { unit: u } of loci.elements) { const l = structure_1.StructureElement.Location.create(loci.structure, u, u.elements[0]); const name = structure_1.StructureProperties.entity.pdbx_description(l).join(', '); entityNames.add(name); } if (entityNames.size === 1) entityNames.forEach(name => label.push(name)); } label.push((0, label_1.lociLabel)(loci)); return label.filter(l => !!l).join('</br>'); }, group: (label) => label.toString().replace(/Model [0-9]+/g, 'Models'), priority: 100, }; } }, display: { name: 'Provide PDBe Loci Label' }, });