UNPKG

molstar

Version:

A comprehensive macromolecular library.

139 lines 7.88 kB
"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.AccessibleSurfaceArea = void 0; var tslib_1 = require("tslib"); var behavior_1 = require("../../../behavior"); var param_definition_1 = require("../../../../../mol-util/param-definition"); var accessible_surface_area_1 = require("../../../../../mol-model-props/computed/accessible-surface-area"); var accessible_surface_area_2 = require("../../../../../mol-model-props/computed/themes/accessible-surface-area"); var int_1 = require("../../../../../mol-data/int"); var array_1 = require("../../../../../mol-util/array"); var compiler_1 = require("../../../../../mol-script/runtime/query/compiler"); var structure_selection_query_1 = require("../../../../../mol-plugin-state/helpers/structure-selection-query"); var builder_1 = require("../../../../../mol-script/language/builder"); exports.AccessibleSurfaceArea = behavior_1.PluginBehavior.create({ name: 'computed-accessible-surface-area-prop', category: 'custom-props', display: { name: 'Accessible Surface Area' }, 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 = accessible_surface_area_1.AccessibleSurfaceAreaProvider; _this.labelProvider = { label: function (loci) { if (!_this.params.showTooltip) return; return accessibleSurfaceAreaLabel(loci); } }; return _this; } 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 () { compiler_1.DefaultQueryRuntimeTable.addCustomProp(this.provider.descriptor); this.ctx.customStructureProperties.register(this.provider, this.params.autoAttach); this.ctx.representation.structure.themes.colorThemeRegistry.add(accessible_surface_area_2.AccessibleSurfaceAreaColorThemeProvider); this.ctx.managers.lociLabels.addProvider(this.labelProvider); this.ctx.query.structure.registry.add(isBuried); this.ctx.query.structure.registry.add(isAccessible); }; class_1.prototype.unregister = function () { compiler_1.DefaultQueryRuntimeTable.removeCustomProp(this.provider.descriptor); this.ctx.customStructureProperties.unregister(this.provider.descriptor.name); this.ctx.representation.structure.themes.colorThemeRegistry.remove(accessible_surface_area_2.AccessibleSurfaceAreaColorThemeProvider); this.ctx.managers.lociLabels.removeProvider(this.labelProvider); this.ctx.query.structure.registry.remove(isBuried); this.ctx.query.structure.registry.remove(isAccessible); }; return class_1; }(behavior_1.PluginBehavior.Handler)), params: function () { return ({ autoAttach: param_definition_1.ParamDefinition.Boolean(false), showTooltip: param_definition_1.ParamDefinition.Boolean(true) }); } }); // function accessibleSurfaceAreaLabel(loci) { if (loci.kind === 'element-loci') { if (loci.elements.length === 0) return; var accessibleSurfaceArea = accessible_surface_area_1.AccessibleSurfaceAreaProvider.get(loci.structure).value; if (!accessibleSurfaceArea || loci.structure.customPropertyDescriptors.hasReference(accessible_surface_area_1.AccessibleSurfaceAreaProvider.descriptor)) return; var getSerialIndex_1 = loci.structure.root.serialMapping.getSerialIndex; var area_1 = accessibleSurfaceArea.area, serialResidueIndex_1 = accessibleSurfaceArea.serialResidueIndex; var seen_1 = new Set(); var cummulativeArea_1 = 0; var _loop_1 = function (indices, unit) { var elements = unit.elements; int_1.OrderedSet.forEach(indices, function (idx) { var rSI = serialResidueIndex_1[getSerialIndex_1(unit, elements[idx])]; if (rSI !== -1 && !seen_1.has(rSI)) { cummulativeArea_1 += area_1[rSI]; seen_1.add(rSI); } }); }; for (var _i = 0, _a = loci.elements; _i < _a.length; _i++) { var _b = _a[_i], indices = _b.indices, unit = _b.unit; _loop_1(indices, unit); } if (seen_1.size === 0) return; var residueCount = "<small>(" + seen_1.size + " " + (seen_1.size > 1 ? 'Residues sum' : 'Residue') + ")</small>"; return "Accessible Surface Area " + residueCount + ": " + cummulativeArea_1.toFixed(2) + " \u212B<sup>2</sup>"; } else if (loci.kind === 'structure-loci') { var accessibleSurfaceArea = accessible_surface_area_1.AccessibleSurfaceAreaProvider.get(loci.structure).value; if (!accessibleSurfaceArea || loci.structure.customPropertyDescriptors.hasReference(accessible_surface_area_1.AccessibleSurfaceAreaProvider.descriptor)) return; return "Accessible Surface Area <small>(Whole Structure)</small>: " + (0, array_1.arraySum)(accessibleSurfaceArea.area).toFixed(2) + " \u212B<sup>2</sup>"; } } // var isBuried = (0, structure_selection_query_1.StructureSelectionQuery)('Buried Protein Residues', builder_1.MolScriptBuilder.struct.modifier.union([ builder_1.MolScriptBuilder.struct.modifier.wholeResidues([ builder_1.MolScriptBuilder.struct.modifier.union([ builder_1.MolScriptBuilder.struct.generator.atomGroups({ 'chain-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.ammp('objectPrimitive'), 'atomistic']), 'residue-test': accessible_surface_area_1.AccessibleSurfaceAreaSymbols.isBuried.symbol(), }) ]) ]) ]), { description: 'Select buried protein residues.', category: structure_selection_query_1.StructureSelectionCategory.Residue, ensureCustomProperties: function (ctx, structure) { return accessible_surface_area_1.AccessibleSurfaceAreaProvider.attach(ctx, structure); } }); var isAccessible = (0, structure_selection_query_1.StructureSelectionQuery)('Accessible Protein Residues', builder_1.MolScriptBuilder.struct.modifier.union([ builder_1.MolScriptBuilder.struct.modifier.wholeResidues([ builder_1.MolScriptBuilder.struct.modifier.union([ builder_1.MolScriptBuilder.struct.generator.atomGroups({ 'chain-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.ammp('objectPrimitive'), 'atomistic']), 'residue-test': accessible_surface_area_1.AccessibleSurfaceAreaSymbols.isAccessible.symbol(), }) ]) ]) ]), { description: 'Select accessible protein residues.', category: structure_selection_query_1.StructureSelectionCategory.Residue, ensureCustomProperties: function (ctx, structure) { return accessible_surface_area_1.AccessibleSurfaceAreaProvider.attach(ctx, structure); } }); //# sourceMappingURL=accessible-surface-area.js.map